diff --git a/trunk/src/core/srs_core_complex_handshake.cpp b/trunk/src/core/srs_core_complex_handshake.cpp index 3594c8d8b..0966501fb 100755 --- a/trunk/src/core/srs_core_complex_handshake.cpp +++ b/trunk/src/core/srs_core_complex_handshake.cpp @@ -23,7 +23,11 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include +#include +#include + #include +#include 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; } diff --git a/trunk/src/core/srs_core_complex_handshake.hpp b/trunk/src/core/srs_core_complex_handshake.hpp index 20775cf09..5ed6c2df6 100755 --- a/trunk/src/core/srs_core_complex_handshake.hpp +++ b/trunk/src/core/srs_core_complex_handshake.hpp @@ -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 \ No newline at end of file