mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
define the structs for c0c1 complex handshake
This commit is contained in:
parent
e6ca039dd6
commit
f0f4837a97
2 changed files with 137 additions and 3 deletions
|
@ -23,7 +23,11 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
|
||||
#include <srs_core_complex_handshake.hpp>
|
||||
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <srs_core_error.hpp>
|
||||
#include <srs_core_log.hpp>
|
||||
|
||||
SrsComplexHandshake::SrsComplexHandshake()
|
||||
{
|
||||
|
@ -33,9 +37,139 @@ SrsComplexHandshake::~SrsComplexHandshake()
|
|||
{
|
||||
}
|
||||
|
||||
int SrsComplexHandshake::handshake(SrsSocket& skt, char* c1)
|
||||
/**
|
||||
* 764bytes key结构
|
||||
* random-data: (offset)bytes
|
||||
* key-data: 128bytes
|
||||
* random-data: (764-offset-128-4)bytes
|
||||
* offset: 4bytes
|
||||
*/
|
||||
struct key_block
|
||||
{
|
||||
// (offset)bytes
|
||||
char* random0;
|
||||
int random0_size;
|
||||
|
||||
// 128bytes
|
||||
char key[128];
|
||||
|
||||
// (764-offset-128-4)bytes
|
||||
char* random1;
|
||||
int random1_size;
|
||||
|
||||
// 4bytes
|
||||
int32_t offset;
|
||||
};
|
||||
void srs_key_block_init(key_block* key)
|
||||
{
|
||||
}
|
||||
void srs_key_block_free(key_block* key)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* 764bytes digest结构
|
||||
* offset: 4bytes
|
||||
* random-data: (offset)bytes
|
||||
* digest-data: 32bytes
|
||||
* random-data: (764-4-offset-32)bytes
|
||||
*/
|
||||
struct digest_block
|
||||
{
|
||||
// 4bytes
|
||||
int32_t offset;
|
||||
|
||||
// (offset)bytes
|
||||
char* random0;
|
||||
int random0_size;
|
||||
|
||||
// 32bytes
|
||||
char digest[32];
|
||||
|
||||
// (764-4-offset-32)bytes
|
||||
char* random1;
|
||||
int random1_size;
|
||||
};
|
||||
void srs_digest_block_init(digest_block* digest)
|
||||
{
|
||||
}
|
||||
void srs_digest_block_free(digest_block* digest)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* c1s1 schema0
|
||||
* time: 4bytes
|
||||
* version: 4bytes
|
||||
* key: 764bytes
|
||||
* digest: 764bytes
|
||||
* c1s1 schema1
|
||||
* time: 4bytes
|
||||
* version: 4bytes
|
||||
* digest: 764bytes
|
||||
* key: 764bytes
|
||||
*/
|
||||
struct c1s1
|
||||
{
|
||||
enum schema_type {
|
||||
schema0 = 0,
|
||||
schema1 = 1
|
||||
};
|
||||
union block {
|
||||
key_block key;
|
||||
digest_block digest;
|
||||
};
|
||||
|
||||
// 4bytes
|
||||
int32_t time;
|
||||
// 4bytes
|
||||
int32_t version;
|
||||
// 764bytes
|
||||
// if schema0, use key
|
||||
// if schema1, use digest
|
||||
block block0;
|
||||
// 764bytes
|
||||
// if schema0, use digest
|
||||
// if schema1, use key
|
||||
block block1;
|
||||
|
||||
// the logic schema
|
||||
schema_type schema;
|
||||
|
||||
c1s1()
|
||||
{
|
||||
time = ::time(NULL);
|
||||
version = 0x00;
|
||||
|
||||
schema = c1s1::schema0;
|
||||
srs_key_block_init(&block0.key);
|
||||
srs_digest_block_init(&block1.digest);
|
||||
}
|
||||
virtual ~c1s1()
|
||||
{
|
||||
if (schema == c1s1::schema0) {
|
||||
srs_key_block_free(&block0.key);
|
||||
srs_digest_block_free(&block1.digest);
|
||||
} else {
|
||||
srs_digest_block_free(&block0.digest);
|
||||
srs_key_block_free(&block1.key);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int SrsComplexHandshake::handshake(SrsSocket& skt, char* _c1)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
static bool _random_initialized = false;
|
||||
if (!_random_initialized) {
|
||||
srand(0);
|
||||
_random_initialized = true;
|
||||
srs_trace("srand initialized the random.");
|
||||
}
|
||||
|
||||
c1s1 c1;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -45,14 +45,14 @@ public:
|
|||
public:
|
||||
/**
|
||||
* complex hanshake.
|
||||
* @c1, size of c1 must be 1536.
|
||||
* @_c1, size of c1 must be 1536.
|
||||
* @remark, user must free the c1.
|
||||
* @return user must:
|
||||
* continue connect app if success,
|
||||
* try simple handshake if error is ERROR_RTMP_TRY_SIMPLE_HS,
|
||||
* otherwise, disconnect
|
||||
*/
|
||||
virtual int handshake(SrsSocket& skt, char* c1);
|
||||
virtual int handshake(SrsSocket& skt, char* _c1);
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue