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.inl97
1 files changed, 87 insertions, 10 deletions
diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.inl b/src/cryptonote_protocol/cryptonote_protocol_handler.inl
index c1459cbb6..b33867e8b 100644
--- a/src/cryptonote_protocol/cryptonote_protocol_handler.inl
+++ b/src/cryptonote_protocol/cryptonote_protocol_handler.inl
@@ -2,7 +2,7 @@
/// @author rfree (current maintainer/user in monero.cc project - most of code is from CryptoNote)
/// @brief This is the original cryptonote protocol network-events handler, modified by us
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -72,7 +72,8 @@ namespace cryptonote
m_p2p(p_net_layout),
m_syncronized_connections_count(0),
m_synchronized(offline),
- m_stopping(false)
+ m_stopping(false),
+ m_no_sync(false)
{
if(!m_p2p)
@@ -231,6 +232,7 @@ namespace cryptonote
cnx.ip = cnx.host;
cnx.port = std::to_string(cntxt.m_remote_address.as<epee::net_utils::ipv4_network_address>().port());
}
+ cnx.rpc_port = cntxt.m_rpc_port;
std::stringstream peer_id_str;
peer_id_str << std::hex << std::setw(16) << peer_id;
@@ -268,6 +270,7 @@ namespace cryptonote
cnx.current_upload = cntxt.m_current_speed_up / 1024;
cnx.connection_id = epee::string_tools::pod_to_hex(cntxt.m_connection_id);
+ cnx.ssl = cntxt.m_ssl;
cnx.height = cntxt.m_remote_blockchain_height;
cnx.pruning_seed = cntxt.m_pruning_seed;
@@ -374,6 +377,13 @@ namespace cryptonote
m_core.set_target_blockchain_height((hshd.current_height));
}
MINFO(context << "Remote blockchain height: " << hshd.current_height << ", id: " << hshd.top_id);
+
+ if (m_no_sync)
+ {
+ context.m_state = cryptonote_connection_context::state_normal;
+ return true;
+ }
+
context.m_state = cryptonote_connection_context::state_synchronizing;
//let the socket to send response to handshake, but request callback, to let send request data after response
LOG_PRINT_CCONTEXT_L2("requesting callback");
@@ -417,7 +427,14 @@ namespace cryptonote
m_core.pause_mine();
std::vector<block_complete_entry> blocks;
blocks.push_back(arg.b);
- m_core.prepare_handle_incoming_blocks(blocks);
+ std::vector<block> pblocks;
+ if (!m_core.prepare_handle_incoming_blocks(blocks, pblocks))
+ {
+ LOG_PRINT_CCONTEXT_L1("Block verification failed: prepare_handle_incoming_blocks failed, dropping connection");
+ drop_connection(context, false, false);
+ m_core.resume_mine();
+ return 1;
+ }
for(auto tx_blob_it = arg.b.txs.begin(); tx_blob_it!=arg.b.txs.end();tx_blob_it++)
{
cryptonote::tx_verification_context tvc = AUTO_VAL_INIT(tvc);
@@ -433,7 +450,7 @@ namespace cryptonote
}
block_verification_context bvc = boost::value_initialized<block_verification_context>();
- m_core.handle_incoming_block(arg.b.block, bvc); // got block from handle_notify_new_block
+ m_core.handle_incoming_block(arg.b.block, pblocks.empty() ? NULL : &pblocks[0], bvc); // got block from handle_notify_new_block
if (!m_core.cleanup_handle_incoming_blocks(true))
{
LOG_PRINT_CCONTEXT_L0("Failure in cleanup_handle_incoming_blocks");
@@ -696,10 +713,16 @@ namespace cryptonote
std::vector<block_complete_entry> blocks;
blocks.push_back(b);
- m_core.prepare_handle_incoming_blocks(blocks);
+ std::vector<block> pblocks;
+ if (!m_core.prepare_handle_incoming_blocks(blocks, pblocks))
+ {
+ LOG_PRINT_CCONTEXT_L0("Failure in prepare_handle_incoming_blocks");
+ m_core.resume_mine();
+ return 1;
+ }
block_verification_context bvc = boost::value_initialized<block_verification_context>();
- m_core.handle_incoming_block(arg.b.block, bvc); // got block from handle_notify_new_block
+ m_core.handle_incoming_block(arg.b.block, pblocks.empty() ? NULL : &pblocks[0], bvc); // got block from handle_notify_new_block
if (!m_core.cleanup_handle_incoming_blocks(true))
{
LOG_PRINT_CCONTEXT_L0("Failure in cleanup_handle_incoming_blocks");
@@ -1173,10 +1196,21 @@ namespace cryptonote
}
}
- m_core.prepare_handle_incoming_blocks(blocks);
+ std::vector<block> pblocks;
+ if (!m_core.prepare_handle_incoming_blocks(blocks, pblocks))
+ {
+ LOG_ERROR_CCONTEXT("Failure in prepare_handle_incoming_blocks");
+ return 1;
+ }
+ if (!pblocks.empty() && pblocks.size() != blocks.size())
+ {
+ m_core.cleanup_handle_incoming_blocks();
+ LOG_ERROR_CCONTEXT("Internal error: blocks.size() != block_entry.txs.size()");
+ return 1;
+ }
uint64_t block_process_time_full = 0, transactions_process_time_full = 0;
- size_t num_txs = 0;
+ size_t num_txs = 0, blockidx = 0;
for(const block_complete_entry& block_entry: blocks)
{
if (m_stopping)
@@ -1228,7 +1262,7 @@ namespace cryptonote
TIME_MEASURE_START(block_process_time);
block_verification_context bvc = boost::value_initialized<block_verification_context>();
- m_core.handle_incoming_block(block_entry.block, bvc, false); // <--- process block
+ m_core.handle_incoming_block(block_entry.block, pblocks.empty() ? NULL : &pblocks[blockidx], bvc, false); // <--- process block
if(bvc.m_verifivation_failed)
{
@@ -1271,6 +1305,7 @@ namespace cryptonote
TIME_MEASURE_FINISH(block_process_time);
block_process_time_full += block_process_time;
+ ++blockidx;
} // each download block
@@ -1371,6 +1406,7 @@ skip:
{
m_idle_peer_kicker.do_call(boost::bind(&t_cryptonote_protocol_handler<t_core>::kick_idle_peers, this));
m_standby_checker.do_call(boost::bind(&t_cryptonote_protocol_handler<t_core>::check_standby_peers, this));
+ m_sync_search_checker.do_call(boost::bind(&t_cryptonote_protocol_handler<t_core>::update_sync_search, this));
return m_core.on_idle();
}
//------------------------------------------------------------------------------------------------------------------------
@@ -1400,6 +1436,47 @@ skip:
}
//------------------------------------------------------------------------------------------------------------------------
template<class t_core>
+ bool t_cryptonote_protocol_handler<t_core>::update_sync_search()
+ {
+ const uint64_t target = m_core.get_target_blockchain_height();
+ const uint64_t height = m_core.get_current_blockchain_height();
+ if (target > height) // if we're not synced yet, don't do it
+ return true;
+
+ MTRACE("Checking for outgoing syncing peers...");
+ unsigned n_syncing = 0, n_synced = 0;
+ boost::uuids::uuid last_synced_peer_id(boost::uuids::nil_uuid());
+ m_p2p->for_each_connection([&](cryptonote_connection_context& context, nodetool::peerid_type peer_id, uint32_t support_flags)->bool
+ {
+ if (!peer_id || context.m_is_income) // only consider connected outgoing peers
+ return true;
+ if (context.m_state == cryptonote_connection_context::state_synchronizing)
+ ++n_syncing;
+ if (context.m_state == cryptonote_connection_context::state_normal)
+ {
+ ++n_synced;
+ if (!context.m_anchor)
+ last_synced_peer_id = context.m_connection_id;
+ }
+ return true;
+ });
+ MTRACE(n_syncing << " syncing, " << n_synced << " synced");
+
+ // if we're at max out peers, and not enough are syncing
+ if (n_synced + n_syncing >= m_max_out_peers && n_syncing < P2P_DEFAULT_SYNC_SEARCH_CONNECTIONS_COUNT && last_synced_peer_id != boost::uuids::nil_uuid())
+ {
+ if (!m_p2p->for_connection(last_synced_peer_id, [&](cryptonote_connection_context& ctx, nodetool::peerid_type peer_id, uint32_t f)->bool{
+ MINFO(ctx << "dropping synced peer, " << n_syncing << " syncing, " << n_synced << " synced");
+ drop_connection(ctx, false, false);
+ return true;
+ }))
+ MDEBUG("Failed to find peer we wanted to drop");
+ }
+
+ return true;
+ }
+ //------------------------------------------------------------------------------------------------------------------------
+ template<class t_core>
bool t_cryptonote_protocol_handler<t_core>::check_standby_peers()
{
m_p2p->for_each_connection([&](cryptonote_connection_context& context, nodetool::peerid_type peer_id, uint32_t support_flags)->bool
@@ -2111,7 +2188,7 @@ skip:
MDEBUG("Attempting to conceal origin of tx via anonymity network connection(s)");
// no check for success, so tell core they're relayed unconditionally
- const bool pad_transactions = m_core.pad_transactions();
+ const bool pad_transactions = m_core.pad_transactions() || hide_tx_broadcast;
size_t bytes = pad_transactions ? 9 /* header */ + 4 /* 1 + 'txs' */ + tools::get_varint_data(arg.txs.size()).size() : 0;
for(auto tx_blob_it = arg.txs.begin(); tx_blob_it!=arg.txs.end(); ++tx_blob_it)
{