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

主动链接对端
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;
     }
  }

}

转载于:https://blog.51cto.com/13878196/2385385

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值