Пример #1
1
        /* ===================================================== */   
        void handle_message( const connection_ptr& con, const message& m )
        { 
          try {
           chan_data& cdat = get_channel_data(con);
 
           ilog( "${msg_type}", ("msg_type", (bitname::message_type)m.msg_type ) );
           
           switch( (bitname::message_type)m.msg_type )
           {
               case name_inv_msg:
                 handle_name_inv( con, cdat, m.as<name_inv_message>() );
                 break;
               case block_inv_msg:
                 handle_block_inv( con, cdat, m.as<block_inv_message>() );
                 break;
               case get_name_inv_msg:
                 handle_get_name_inv( con, cdat, m.as<get_name_inv_message>() );
                 break;
               case get_headers_msg:
                 handle_get_headers( con, cdat, m.as<get_headers_message>() );
                 break;
               case get_block_msg:
                 handle_get_block( con, cdat, m.as<get_block_message>() );
                 break;
               case get_block_index_msg:
                 handle_get_block_index( con, cdat, m.as<get_block_index_message>() );
                 break;
               case get_name_header_msg:
                 handle_get_name( con, cdat, m.as<get_name_header_message>() );
                 break;
               case name_header_msg:
                 handle_name( con, cdat, m.as<name_header_message>() );
                 break;
               case block_index_msg:
                 handle_block_index( con, cdat, m.as<block_index_message>() );
                 break;
               case block_msg:
                 handle_block( con, cdat, m.as<block_message>() );
                 break;
               case headers_msg:
                 handle_headers( con, cdat, m.as<headers_message>() );
                 break;
               default:
                 FC_THROW_EXCEPTION( exception, "unknown bitname message type ${msg_type}", ("msg_type", m.msg_type ) );
           }
          } 
          catch ( fc::exception& e )
          {
            wlog( "${e}  ${from}", ("e",e.to_detail_string())("from",con->remote_endpoint()) );
          }
        }  // handle_message
Пример #2
0
	void on_accept(connection_ptr conn, error_code ec)
	{
		if (!ec)
		{
			connections_.insert(conn);

			std::cout<<"accept: "<<conn->remote_endpoint(ec)<<std::endl;

			conn->disconnected_signal().bind(&this_type::on_disconnected,this,conn.get());
			conn->received_request_header_signal().bind(&this_type::on_request,this,_1,conn.get());
			conn->received_data_signal().bind(&this_type::on_data,this,_1);
			conn->writable_signal().bind(&this_type::close_socket,this,conn.get());
		}

	}
Пример #3
0
          /* ===================================================== 
           *  When a new node connects it must locate the best block chain that extends the
           *  current known chain.  
           **/   
          void request_block_headers( const connection_ptr& con )
          { try {
              ilog( "requesting block headers from ${ep}", ("ep",con->remote_endpoint() ));
              chan_data& cdat = get_channel_data(con);
              if( cdat.requested_headers ) 
                  return;

              get_headers_message  request;
              const std::vector<name_id_type>& ids = _name_db.get_header_ids();
              uint32_t delta = 1;
              for( int32_t i = ids.size() - 1; i >= 0;  )
              {
                 request.locator_hashes.push_back(ids[i]);
                 i -= delta;
                 delta *= 2;
              }
              cdat.requested_headers = fc::time_point::now();
              con->send( network::message(request,_chan_id) );
          } FC_RETHROW_EXCEPTIONS( warn, "") }