EOS Code Analysis of 6 P2P active handshake process
Active link to the peer
Connect (seed_node); link peer node
If (start_session (c)) {c-> send_handshake (); / / send handshake protocol}
C-> send_handshake (); / / initialize the structure, send the handshake protocol, and finally enqueue the protocol.
Handshake_initializer::populate
Queue_write (); send buffer past [how to send buffer after sending buffer?]
Actively sent handshake data content
Void
Handshake_initializer::populate (handshake_message & hello) {
Hello.network_version = net_version_base + net_version
Hello.chain_id = my_impl- > chain_id; / / system options can be set
Hello.node_id = my_impl- > node_id
Hello.key = my_impl- > get_authentication_key (); / / Public key
Hello.time = std::chrono::system_clock::now (). Time_since_epoch (). Count ()
Hello.token = fc::sha256::hash (hello.time)
Hello.sig = my_impl- > sign_compact (hello.key, hello.token)
/ / If we couldn't sign, don't send a token.
If (hello.sig = = chain::signature_type ())
Hello.token = sha256 ()
Hello.p2p_address = my_impl- > p2p_address + "-" + hello.node_id.str (). Substr (0pr 7)
# if defined (APPLE)
Hello.os = "osx"
# elif defined (linux)
Hello.os = "linux"
# elif defined (_ MSC_VER)
Hello.os = "win32"
# else
Hello.os = "other"
# endif
Hello.agent = my_impl- > user_agent_name
Controller& cc = my_impl- > chain_plug- > chain (); hello.head_id = fc::sha256 (); hello.last_irreversible_block_id = fc::sha256 (); hello.head_num = cc.head_block_num (); hello.last_irreversible_block_num = cc.last_irreversible_block_num () If (hello.last_irreversible_block_num) {try {hello.last_irreversible_block_id = cc.get_block_id_for_num (hello.last_irreversible_block_num);} catch (const unknown_block_exception & ex) {ilog ("caught unkown_block"); hello.last_irreversible_block_num = 0 }} if (hello.head_num) {try {hello.head_id = cc.get_block_id_for_num (hello.head_num);} catch (const unknown_block_exception & ex) {hello.head_num = 0;}}
}