Skip to content

Commit

Permalink
Merge branch 'master' of github.com:cryptonomex/graphene
Browse files Browse the repository at this point in the history
  • Loading branch information
bytemaster committed Sep 23, 2015
2 parents 675f637 + 405a9e7 commit 2afe62f
Showing 1 changed file with 48 additions and 26 deletions.
74 changes: 48 additions & 26 deletions libraries/net/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ namespace graphene { namespace net { namespace detail {
> items_to_fetch_set_type;
unsigned _items_to_fetch_sequence_counter;
items_to_fetch_set_type _items_to_fetch; /// list of items we know another peer has and we want
peer_connection::timestamped_items_set_type _recently_failed_items; /// list of transactions we've recently pushed and had rejected by the delegate
// @}

/// used by the task that advertises inventory during normal operation
Expand Down Expand Up @@ -846,7 +847,7 @@ namespace graphene { namespace net { namespace detail {
}
catch ( const fc::exception& e )
{
wlog( "unexpected exception on close ${e}", ("e", e.to_detail_string() ) );
wlog( "unexpected exception on close ${e}", ("e", e) );
}
ilog( "done" );
}
Expand Down Expand Up @@ -965,7 +966,7 @@ namespace graphene { namespace net { namespace detail {
}
catch (const fc::exception& e)
{
elog("${e}", ("e", e.to_detail_string()));
elog("${e}", ("e", e));
}
}// while(!canceled)
}
Expand Down Expand Up @@ -1454,6 +1455,13 @@ namespace graphene { namespace net { namespace detail {
}
}

// this has nothing to do with updating the peer list, but we need to prune this list
// at regular intervals, this is a fine place to do it.
fc::time_point_sec oldest_failed_ids_to_keep(fc::time_point::now() - fc::minutes(15));
auto oldest_failed_ids_to_keep_iter = _recently_failed_items.get<peer_connection::timestamp_index>().lower_bound(oldest_failed_ids_to_keep);
auto begin_iter = _recently_failed_items.get<peer_connection::timestamp_index>().begin();
_recently_failed_items.get<peer_connection::timestamp_index>().erase(begin_iter, oldest_failed_ids_to_keep_iter);

if (!_node_is_shutting_down && !_fetch_updated_peer_lists_loop_done.canceled() )
_fetch_updated_peer_lists_loop_done = fc::schedule( [this](){ fetch_updated_peer_lists_loop(); },
fc::time_point::now() + fc::minutes(15),
Expand Down Expand Up @@ -2786,12 +2794,20 @@ namespace graphene { namespace net { namespace detail {
originating_peer->inventory_peer_advertised_to_us.insert(peer_connection::timestamped_item_id(advertised_item_id, fc::time_point::now()));
if (!we_requested_this_item_from_a_peer)
{
auto insert_result = _items_to_fetch.insert(prioritized_item_id(advertised_item_id, _items_to_fetch_sequence_counter++));
if (insert_result.second)
if (_recently_failed_items.find(item_id(item_ids_inventory_message_received.item_type, item_hash)) != _recently_failed_items.end())
{
dlog("adding item ${item_hash} from inventory message to our list of items to fetch",
dlog("not adding ${item_hash} to our list of items to fetch because we've recently fetched a copy and it failed to push",
("item_hash", item_hash));
trigger_fetch_items_loop();
}
else
{
auto insert_result = _items_to_fetch.insert(prioritized_item_id(advertised_item_id, _items_to_fetch_sequence_counter++));
if (insert_result.second)
{
dlog("adding item ${item_hash} from inventory message to our list of items to fetch",
("item_hash", item_hash));
trigger_fetch_items_loop();
}
}
}
}
Expand Down Expand Up @@ -2943,7 +2959,7 @@ namespace graphene { namespace net { namespace detail {
"allow us to switch to: ${e}",
("num", block_message_to_send.block.block_num())
("id", block_message_to_send.block_id)
("e", e.to_detail_string()));
("e", (fc::exception)e));
handle_message_exception = e;
discontinue_fetching_blocks_from_peer = true;
}
Expand Down Expand Up @@ -3696,7 +3712,7 @@ namespace graphene { namespace net { namespace detail {
fc::time_point message_receive_time = fc::time_point::now();

// only process it if we asked for it
auto iter = originating_peer->items_requested_from_peer.find( item_id(message_to_process.msg_type, message_hash ) );
auto iter = originating_peer->items_requested_from_peer.find( item_id(message_to_process.msg_type, message_hash) );
if( iter == originating_peer->items_requested_from_peer.end() )
{
wlog( "received a message I didn't ask for from peer ${endpoint}, disconnecting from peer",
Expand All @@ -3717,7 +3733,11 @@ namespace graphene { namespace net { namespace detail {
try
{
if (message_to_process.msg_type == trx_message_type)
_delegate->handle_transaction( message_to_process.as<trx_message>() );
{
trx_message transaction_message_to_process = message_to_process.as<trx_message>();
dlog("passing message containing transaction ${trx} to client", ("trx", transaction_message_to_process.trx.id()));
_delegate->handle_transaction(transaction_message_to_process);
}
else
_delegate->handle_message( message_to_process );
message_validated_time = fc::time_point::now();
Expand All @@ -3736,7 +3756,9 @@ namespace graphene { namespace net { namespace detail {
}
catch ( const fc::exception& e )
{
wlog( "client rejected message sent by peer ${peer}, ${e}", ("peer", originating_peer->get_remote_endpoint() )("e", e.to_string() ) );
wlog( "client rejected message sent by peer ${peer}, ${e}", ("peer", originating_peer->get_remote_endpoint() )("e", e) );
// record it so we don't try to fetch this item again
_recently_failed_items.insert(peer_connection::timestamped_item_id(item_id(message_to_process.msg_type, message_hash ), fc::time_point::now()));
return;
}

Expand Down Expand Up @@ -3787,7 +3809,7 @@ namespace graphene { namespace net { namespace detail {
}
catch ( const fc::exception& e )
{
wlog( "Exception thrown while closing P2P peer database, ignoring: ${e}", ("e",e) );
wlog( "Exception thrown while closing P2P peer database, ignoring: ${e}", ("e", e) );
}
catch (...)
{
Expand All @@ -3802,7 +3824,7 @@ namespace graphene { namespace net { namespace detail {
}
catch ( const fc::exception& e )
{
wlog( "Exception thrown while closing P2P TCP server, ignoring: ${e}", ("e",e) );
wlog( "Exception thrown while closing P2P TCP server, ignoring: ${e}", ("e", e) );
}
catch (...)
{
Expand All @@ -3816,7 +3838,7 @@ namespace graphene { namespace net { namespace detail {
}
catch ( const fc::exception& e )
{
wlog( "Exception thrown while terminating P2P accept loop, ignoring: ${e}", ("e",e) );
wlog( "Exception thrown while terminating P2P accept loop, ignoring: ${e}", ("e", e) );
}
catch (...)
{
Expand All @@ -3838,7 +3860,7 @@ namespace graphene { namespace net { namespace detail {
}
catch ( const fc::exception& e )
{
wlog( "Exception thrown while terminating P2P connect loop, ignoring: ${e}", ("e",e) );
wlog( "Exception thrown while terminating P2P connect loop, ignoring: ${e}", ("e", e) );
}
catch (...)
{
Expand All @@ -3856,7 +3878,7 @@ namespace graphene { namespace net { namespace detail {
}
catch ( const fc::exception& e )
{
wlog( "Exception thrown while terminating Process backlog of sync items task, ignoring: ${e}", ("e",e) );
wlog( "Exception thrown while terminating Process backlog of sync items task, ignoring: ${e}", ("e", e) );
}
catch (...)
{
Expand All @@ -3878,7 +3900,7 @@ namespace graphene { namespace net { namespace detail {
}
catch ( const fc::exception& e )
{
wlog("Exception thrown while terminating handle_message call #${count} task, ignoring: ${e}", ("e",e)("count", handle_message_call_count));
wlog("Exception thrown while terminating handle_message call #${count} task, ignoring: ${e}", ("e", e)("count", handle_message_call_count));
}
catch (...)
{
Expand All @@ -3901,7 +3923,7 @@ namespace graphene { namespace net { namespace detail {
}
catch ( const fc::exception& e )
{
wlog( "Exception thrown while terminating Fetch sync items loop, ignoring: ${e}", ("e",e) );
wlog( "Exception thrown while terminating Fetch sync items loop, ignoring: ${e}", ("e", e) );
}
catch (...)
{
Expand All @@ -3922,7 +3944,7 @@ namespace graphene { namespace net { namespace detail {
}
catch ( const fc::exception& e )
{
wlog( "Exception thrown while terminating Fetch items loop, ignoring: ${e}", ("e",e) );
wlog( "Exception thrown while terminating Fetch items loop, ignoring: ${e}", ("e", e) );
}
catch (...)
{
Expand All @@ -3943,7 +3965,7 @@ namespace graphene { namespace net { namespace detail {
}
catch ( const fc::exception& e )
{
wlog( "Exception thrown while terminating Advertise inventory loop, ignoring: ${e}", ("e",e) );
wlog( "Exception thrown while terminating Advertise inventory loop, ignoring: ${e}", ("e", e) );
}
catch (...)
{
Expand All @@ -3969,7 +3991,7 @@ namespace graphene { namespace net { namespace detail {
}
catch ( const fc::exception& e )
{
wlog( "Exception thrown while closing peer connection, ignoring: ${e}", ("e",e) );
wlog( "Exception thrown while closing peer connection, ignoring: ${e}", ("e", e) );
}
catch (...)
{
Expand All @@ -3994,7 +4016,7 @@ namespace graphene { namespace net { namespace detail {
}
catch ( const fc::exception& e )
{
wlog( "Exception thrown while terminating Delayed peer deletion task, ignoring: ${e}", ("e",e) );
wlog( "Exception thrown while terminating Delayed peer deletion task, ignoring: ${e}", ("e", e) );
}
catch (...)
{
Expand All @@ -4013,7 +4035,7 @@ namespace graphene { namespace net { namespace detail {
}
catch ( const fc::exception& e )
{
wlog( "Exception thrown while terminating Terminate inactive connections loop, ignoring: ${e}", ("e",e) );
wlog( "Exception thrown while terminating Terminate inactive connections loop, ignoring: ${e}", ("e", e) );
}
catch (...)
{
Expand All @@ -4027,7 +4049,7 @@ namespace graphene { namespace net { namespace detail {
}
catch ( const fc::exception& e )
{
wlog( "Exception thrown while terminating Fetch updated peer lists loop, ignoring: ${e}", ("e",e) );
wlog( "Exception thrown while terminating Fetch updated peer lists loop, ignoring: ${e}", ("e", e) );
}
catch (...)
{
Expand All @@ -4041,7 +4063,7 @@ namespace graphene { namespace net { namespace detail {
}
catch ( const fc::exception& e )
{
wlog( "Exception thrown while terminating Bandwidth monitor loop, ignoring: ${e}", ("e",e) );
wlog( "Exception thrown while terminating Bandwidth monitor loop, ignoring: ${e}", ("e", e) );
}
catch (...)
{
Expand All @@ -4055,7 +4077,7 @@ namespace graphene { namespace net { namespace detail {
}
catch ( const fc::exception& e )
{
wlog( "Exception thrown while terminating Dump node status task, ignoring: ${e}", ("e",e) );
wlog( "Exception thrown while terminating Dump node status task, ignoring: ${e}", ("e", e) );
}
catch (...)
{
Expand Down Expand Up @@ -5167,7 +5189,7 @@ namespace graphene { namespace net { namespace detail {
}
catch ( const fc::exception& e )
{
elog( "${r}", ("r",e.to_detail_string() ) );
elog( "${r}", ("r",e) );
}
destination_node->messages_to_deliver.pop();
}
Expand Down

0 comments on commit 2afe62f

Please sign in to comment.