温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

EOS代码分析6 P2P主动握手过程

发布时间:2020-07-31 13:10:39 来源:网络 阅读:410 作者:chajiuke王超 栏目:安全技术

主动链接对端
connect( seed_node ); 链接peer节点
if (start_session( c )) { c->send_handshake (); //发送握手协议 }
c->send_handshake (); //初始化结构体,发送握手协议,协议最后要enqueue
handshake_initializer::populate
queue_write(); 发送缓冲过去[发送缓冲后,如何把缓冲发送过去?]

主动发送的握手数据内容
void
handshake_initializer::populate( handshake_message &hello) {
hello.network_version = net_version_base + net_version;
hello.chain_id = my_impl->chain_id; //系统选项可以设定
hello.node_id = my_impl->node_id;
hello.key = my_impl->get_authentication_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(0,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;
     }
  }

}

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI