MCPcopy Create free account
hub / github.com/cryptonomex/graphene / process_ordinary_message

Method process_ordinary_message

libraries/net/node.cpp:3779–3832  ·  view source on GitHub ↗

this handles any message we get that doesn't require any special processing. currently, this is any message other than block messages and p2p-specific messages. (transaction messages would be handled here, for example) this just passes the message to the client, and does the bookkeeping related to requesting and rebroadcasting the message.

Source from the content-addressed store, hash-verified

3777 // this just passes the message to the client, and does the bookkeeping
3778 // related to requesting and rebroadcasting the message.
3779 void node_impl::process_ordinary_message( peer_connection* originating_peer,
3780 const message& message_to_process, const message_hash_type& message_hash )
3781 {
3782 VERIFY_CORRECT_THREAD();
3783 fc::time_point message_receive_time = fc::time_point::now();
3784
3785 // only process it if we asked for it
3786 auto iter = originating_peer->items_requested_from_peer.find( item_id(message_to_process.msg_type, message_hash) );
3787 if( iter == originating_peer->items_requested_from_peer.end() )
3788 {
3789 wlog( "received a message I didn't ask for from peer ${endpoint}, disconnecting from peer",
3790 ( "endpoint", originating_peer->get_remote_endpoint() ) );
3791 fc::exception detailed_error( FC_LOG_MESSAGE(error, "You sent me a message that I didn't ask for, message_hash: ${message_hash}",
3792 ( "message_hash", message_hash ) ) );
3793 disconnect_from_peer( originating_peer, "You sent me a message that I didn't request", true, detailed_error );
3794 return;
3795 }
3796 else
3797 {
3798 originating_peer->items_requested_from_peer.erase( iter );
3799 if (originating_peer->idle())
3800 trigger_fetch_items_loop();
3801
3802 // Next: have the delegate process the message
3803 fc::time_point message_validated_time;
3804 try
3805 {
3806 if (message_to_process.msg_type == trx_message_type)
3807 {
3808 trx_message transaction_message_to_process = message_to_process.as<trx_message>();
3809 dlog("passing message containing transaction ${trx} to client", ("trx", transaction_message_to_process.trx.id()));
3810 _delegate->handle_transaction(transaction_message_to_process);
3811 }
3812 else
3813 _delegate->handle_message( message_to_process );
3814 message_validated_time = fc::time_point::now();
3815 }
3816 catch ( const fc::canceled_exception& )
3817 {
3818 throw;
3819 }
3820 catch ( const fc::exception& e )
3821 {
3822 wlog( "client rejected message sent by peer ${peer}, ${e}", ("peer", originating_peer->get_remote_endpoint() )("e", e) );
3823 // record it so we don't try to fetch this item again
3824 _recently_failed_items.insert(peer_connection::timestamped_item_id(item_id(message_to_process.msg_type, message_hash ), fc::time_point::now()));
3825 return;
3826 }
3827
3828 // finally, if the delegate validated the message, broadcast it to our other peers
3829 message_propagation_data propagation_data{message_receive_time, message_validated_time, originating_peer->node_id};
3830 broadcast( message_to_process, propagation_data );
3831 }
3832 }
3833
3834 void node_impl::start_synchronizing_with_peer( const peer_connection_ptr& peer )
3835 {

Callers

nothing calls this directly

Calls 11

nowFunction · 0.85
item_idClass · 0.85
timestamped_item_idClass · 0.85
eraseMethod · 0.80
idleMethod · 0.80
handle_transactionMethod · 0.80
handle_messageMethod · 0.80
findMethod · 0.45
endMethod · 0.45
get_remote_endpointMethod · 0.45
idMethod · 0.45

Tested by

no test coverage detected