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

Method on_fetch_items_message

libraries/net/node.cpp:2719–2784  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2717 }
2718
2719 void node_impl::on_fetch_items_message(peer_connection* originating_peer, const fetch_items_message& fetch_items_message_received)
2720 {
2721 VERIFY_CORRECT_THREAD();
2722 dlog("received items request for ids ${ids} of type ${type} from peer ${endpoint}",
2723 ("ids", fetch_items_message_received.items_to_fetch)
2724 ("type", fetch_items_message_received.item_type)
2725 ("endpoint", originating_peer->get_remote_endpoint()));
2726
2727 fc::optional<message> last_block_message_sent;
2728
2729 std::list<message> reply_messages;
2730 for (const item_hash_t& item_hash : fetch_items_message_received.items_to_fetch)
2731 {
2732 try
2733 {
2734 message requested_message = _message_cache.get_message(item_hash);
2735 dlog("received item request for item ${id} from peer ${endpoint}, returning the item from my message cache",
2736 ("endpoint", originating_peer->get_remote_endpoint())
2737 ("id", requested_message.id()));
2738 reply_messages.push_back(requested_message);
2739 if (fetch_items_message_received.item_type == block_message_type)
2740 last_block_message_sent = requested_message;
2741 continue;
2742 }
2743 catch (fc::key_not_found_exception&)
2744 {
2745 // it wasn't in our local cache, that's ok ask the client
2746 }
2747
2748 item_id item_to_fetch(fetch_items_message_received.item_type, item_hash);
2749 try
2750 {
2751 message requested_message = _delegate->get_item(item_to_fetch);
2752 dlog("received item request from peer ${endpoint}, returning the item from delegate with id ${id} size ${size}",
2753 ("id", requested_message.id())
2754 ("size", requested_message.size)
2755 ("endpoint", originating_peer->get_remote_endpoint()));
2756 reply_messages.push_back(requested_message);
2757 if (fetch_items_message_received.item_type == block_message_type)
2758 last_block_message_sent = requested_message;
2759 continue;
2760 }
2761 catch (fc::key_not_found_exception&)
2762 {
2763 reply_messages.push_back(item_not_available_message(item_to_fetch));
2764 dlog("received item request from peer ${endpoint} but we don't have it",
2765 ("endpoint", originating_peer->get_remote_endpoint()));
2766 }
2767 }
2768
2769 // if we sent them a block, update our record of the last block they've seen accordingly
2770 if (last_block_message_sent)
2771 {
2772 graphene::net::block_message block = last_block_message_sent->as<graphene::net::block_message>();
2773 originating_peer->last_block_delegate_has_seen = block.block_id;
2774 originating_peer->last_block_time_delegate_has_seen = _delegate->get_block_time(block.block_id);
2775 }
2776

Callers

nothing calls this directly

Calls 9

item_idClass · 0.85
get_itemMethod · 0.80
get_block_timeMethod · 0.80
send_itemMethod · 0.80
get_remote_endpointMethod · 0.45
get_messageMethod · 0.45
idMethod · 0.45
send_messageMethod · 0.45

Tested by

no test coverage detected