aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_protocol/cryptonote_protocol_handler.inl
diff options
context:
space:
mode:
Diffstat (limited to 'src/cryptonote_protocol/cryptonote_protocol_handler.inl')
-rw-r--r--src/cryptonote_protocol/cryptonote_protocol_handler.inl59
1 files changed, 46 insertions, 13 deletions
diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.inl b/src/cryptonote_protocol/cryptonote_protocol_handler.inl
index 65377f990..51ade0221 100644
--- a/src/cryptonote_protocol/cryptonote_protocol_handler.inl
+++ b/src/cryptonote_protocol/cryptonote_protocol_handler.inl
@@ -60,7 +60,8 @@ namespace cryptonote
t_cryptonote_protocol_handler<t_core>::t_cryptonote_protocol_handler(t_core& rcore, nodetool::i_p2p_endpoint<connection_context>* p_net_layout):m_core(rcore),
m_p2p(p_net_layout),
m_syncronized_connections_count(0),
- m_synchronized(false)
+ m_synchronized(false),
+ m_stopping(false)
{
if(!m_p2p)
@@ -793,6 +794,11 @@ namespace cryptonote
size_t count = 0;
BOOST_FOREACH(const block_complete_entry& block_entry, arg.blocks)
{
+ if (m_stopping)
+ {
+ return 1;
+ }
+
++count;
block b;
if(!parse_and_validate_block_from_blob(block_entry.block, b))
@@ -857,6 +863,12 @@ namespace cryptonote
m_core.prepare_handle_incoming_blocks(arg.blocks);
BOOST_FOREACH(const block_complete_entry& block_entry, arg.blocks)
{
+ if (m_stopping)
+ {
+ m_core.cleanup_handle_incoming_blocks();
+ return 1;
+ }
+
// process transactions
TIME_MEASURE_START(transactions_process_time);
BOOST_FOREACH(auto& tx_blob, block_entry.txs)
@@ -1092,21 +1104,36 @@ namespace cryptonote
std::list<blobdata> fluffy_txs;
fluffy_arg.b = arg.b;
fluffy_arg.b.txs = fluffy_txs;
-
- m_p2p->for_each_connection([this, &arg, &fluffy_arg](connection_context& cntxt, nodetool::peerid_type peer_id, uint32_t support_flags)
+
+ // pre-serialize them
+ std::string fullBlob, fluffyBlob;
+ epee::serialization::store_t_to_binary(arg, fullBlob);
+ epee::serialization::store_t_to_binary(fluffy_arg, fluffyBlob);
+
+ // sort peers between fluffy ones and others
+ std::list<boost::uuids::uuid> fullConnections, fluffyConnections;
+ m_p2p->for_each_connection([this, &arg, &fluffy_arg, &exclude_context, &fullConnections, &fluffyConnections](connection_context& context, nodetool::peerid_type peer_id, uint32_t support_flags)
{
- if(m_core.get_testnet() && support_flags & P2P_SUPPORT_FLAG_FLUFFY_BLOCKS)
- {
- LOG_PRINT_YELLOW("PEER SUPPORTS FLUFFY BLOCKS - RELAYING THIN/COMPACT WHATEVER BLOCK", LOG_LEVEL_1);
- return post_notify<NOTIFY_NEW_FLUFFY_BLOCK>(fluffy_arg, cntxt);
- }
- else
+ if (peer_id && exclude_context.m_connection_id != context.m_connection_id)
{
- LOG_PRINT_YELLOW("PEER DOESN'T SUPPORT FLUFFY BLOCKS - RELAYING FULL BLOCK", LOG_LEVEL_1);
- return post_notify<NOTIFY_NEW_BLOCK>(arg, cntxt);
+ if(m_core.get_testnet() && (support_flags & P2P_SUPPORT_FLAG_FLUFFY_BLOCKS))
+ {
+ LOG_PRINT_CCONTEXT_YELLOW("PEER SUPPORTS FLUFFY BLOCKS - RELAYING THIN/COMPACT WHATEVER BLOCK", LOG_LEVEL_1);
+ fluffyConnections.push_back(context.m_connection_id);
+ }
+ else
+ {
+ LOG_PRINT_CCONTEXT_YELLOW("PEER DOESN'T SUPPORT FLUFFY BLOCKS - RELAYING FULL BLOCK", LOG_LEVEL_1);
+ fullConnections.push_back(context.m_connection_id);
+ }
}
+ return true;
});
-
+
+ // send fluffy ones first, we want to encourage people to run that
+ m_p2p->relay_notify_to_list(NOTIFY_NEW_FLUFFY_BLOCK::ID, fluffyBlob, fluffyConnections);
+ m_p2p->relay_notify_to_list(NOTIFY_NEW_BLOCK::ID, fullBlob, fullConnections);
+
return 1;
}
//------------------------------------------------------------------------------------------------------------------------
@@ -1131,5 +1158,11 @@ namespace cryptonote
(*logreq) << "log used" << std::endl;
return *logreq;
}
-
+ //------------------------------------------------------------------------------------------------------------------------
+ template<class t_core>
+ void t_cryptonote_protocol_handler<t_core>::stop()
+ {
+ m_stopping = true;
+ m_core.stop();
+ }
} // namespace