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

Method process_block_message

libraries/net/node.cpp:3459–3513  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3457 }
3458 }
3459 void node_impl::process_block_message(peer_connection* originating_peer,
3460 const message& message_to_process,
3461 const message_hash_type& message_hash)
3462 {
3463 VERIFY_CORRECT_THREAD();
3464 // find out whether we requested this item while we were synchronizing or during normal operation
3465 // (it's possible that we request an item during normal operation and then get kicked into sync
3466 // mode before we receive and process the item. In that case, we should process the item as a normal
3467 // item to avoid confusing the sync code)
3468 graphene::net::block_message block_message_to_process(message_to_process.as<graphene::net::block_message>());
3469 auto item_iter = originating_peer->items_requested_from_peer.find(item_id(graphene::net::block_message_type, message_hash));
3470 if (item_iter != originating_peer->items_requested_from_peer.end())
3471 {
3472 originating_peer->items_requested_from_peer.erase(item_iter);
3473 process_block_during_normal_operation(originating_peer, block_message_to_process, message_hash);
3474 if (originating_peer->idle())
3475 trigger_fetch_items_loop();
3476 return;
3477 }
3478 else
3479 {
3480 // not during normal operation. see if we requested it during sync
3481 auto sync_item_iter = originating_peer->sync_items_requested_from_peer.find(item_id(graphene::net::block_message_type,
3482 block_message_to_process.block_id));
3483 if (sync_item_iter != originating_peer->sync_items_requested_from_peer.end())
3484 {
3485 originating_peer->sync_items_requested_from_peer.erase(sync_item_iter);
3486 _active_sync_requests.erase(block_message_to_process.block_id);
3487 process_block_during_sync(originating_peer, block_message_to_process, message_hash);
3488 if (originating_peer->idle())
3489 {
3490 // we have finished fetching a batch of items, so we either need to grab another batch of items
3491 // or we need to get another list of item ids.
3492 if (originating_peer->number_of_unfetched_item_ids > 0 &&
3493 originating_peer->ids_of_items_to_get.size() < GRAPHENE_NET_MIN_BLOCK_IDS_TO_PREFETCH)
3494 fetch_next_batch_of_item_ids_from_peer(originating_peer);
3495 else
3496 trigger_fetch_sync_items_loop();
3497 }
3498 return;
3499 }
3500 }
3501
3502 // if we get here, we didn't request the message, we must have a misbehaving peer
3503 wlog("received a block ${block_id} I didn't ask for from peer ${endpoint}, disconnecting from peer",
3504 ("endpoint", originating_peer->get_remote_endpoint())
3505 ("block_id", block_message_to_process.block_id));
3506 fc::exception detailed_error(FC_LOG_MESSAGE(error, "You sent me a block that I didn't ask for, block_id: ${block_id}",
3507 ("block_id", block_message_to_process.block_id)
3508 ("graphene_git_revision_sha", originating_peer->graphene_git_revision_sha)
3509 ("graphene_git_revision_unix_timestamp", originating_peer->graphene_git_revision_unix_timestamp)
3510 ("fc_git_revision_sha", originating_peer->fc_git_revision_sha)
3511 ("fc_git_revision_unix_timestamp", originating_peer->fc_git_revision_unix_timestamp)));
3512 disconnect_from_peer(originating_peer, "You sent me a block that I didn't ask for", true, detailed_error);
3513 }
3514
3515 void node_impl::on_current_time_request_message(peer_connection* originating_peer,
3516 const current_time_request_message& current_time_request_message_received)

Callers

nothing calls this directly

Calls 7

item_idClass · 0.85
eraseMethod · 0.80
idleMethod · 0.80
findMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45
get_remote_endpointMethod · 0.45

Tested by

no test coverage detected