aboutsummaryrefslogtreecommitdiff
path: root/src/p2p
diff options
context:
space:
mode:
Diffstat (limited to 'src/p2p')
-rw-r--r--src/p2p/net_node.h3
-rw-r--r--src/p2p/net_node.inl22
-rw-r--r--src/p2p/network_throttle.cpp18
-rw-r--r--src/p2p/network_throttle.hpp7
-rw-r--r--src/p2p/p2p_protocol_defs.h8
5 files changed, 32 insertions, 26 deletions
diff --git a/src/p2p/net_node.h b/src/p2p/net_node.h
index 8798a52e0..ed00de731 100644
--- a/src/p2p/net_node.h
+++ b/src/p2p/net_node.h
@@ -61,8 +61,11 @@ namespace nodetool
template<class base_type>
struct p2p_connection_context_t: base_type //t_payload_net_handler::connection_context //public net_utils::connection_context_base
{
+ p2p_connection_context_t(): support_flags(0), m_in_timedsync(false) {}
+
peerid_type peer_id;
uint32_t support_flags;
+ bool m_in_timedsync;
};
template<class t_payload_net_handler>
diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl
index b23090c7d..3cd48ccf0 100644
--- a/src/p2p/net_node.inl
+++ b/src/p2p/net_node.inl
@@ -444,11 +444,11 @@ namespace nodetool
std::vector<std::vector<std::string>> dns_results;
dns_results.resize(m_seed_nodes_list.size());
- std::list<boost::thread*> dns_threads;
+ std::list<boost::thread> dns_threads;
uint64_t result_index = 0;
for (const std::string& addr_str : m_seed_nodes_list)
{
- boost::thread* th = new boost::thread([=, &dns_results, &addr_str]
+ boost::thread th = boost::thread([=, &dns_results, &addr_str]
{
MDEBUG("dns_threads[" << result_index << "] created for: " << addr_str);
// TODO: care about dnssec avail/valid
@@ -474,19 +474,19 @@ namespace nodetool
dns_results[result_index] = addr_list;
});
- dns_threads.push_back(th);
+ dns_threads.push_back(std::move(th));
++result_index;
}
MDEBUG("dns_threads created, now waiting for completion or timeout of " << CRYPTONOTE_DNS_TIMEOUT_MS << "ms");
boost::chrono::system_clock::time_point deadline = boost::chrono::system_clock::now() + boost::chrono::milliseconds(CRYPTONOTE_DNS_TIMEOUT_MS);
uint64_t i = 0;
- for (boost::thread* th : dns_threads)
+ for (boost::thread& th : dns_threads)
{
- if (! th->try_join_until(deadline))
+ if (! th.try_join_until(deadline))
{
MWARNING("dns_threads[" << i << "] timed out, sending interrupt");
- th->interrupt();
+ th.interrupt();
}
++i;
}
@@ -714,6 +714,14 @@ namespace nodetool
template<class t_payload_net_handler>
bool node_server<t_payload_net_handler>::send_stop_signal()
{
+ std::list<boost::uuids::uuid> connection_ids;
+ m_net_server.get_config_object().foreach_connection([&](const p2p_connection_context& cntxt) {
+ connection_ids.push_back(cntxt.m_connection_id);
+ return true;
+ });
+ for (const auto &connection_id: connection_ids)
+ m_net_server.get_config_object().close(connection_id);
+
m_payload_handler.stop();
m_net_server.send_stop_signal();
MDEBUG("[node] Stop signal sent");
@@ -1382,7 +1390,7 @@ namespace nodetool
}
crypto::public_key pk = AUTO_VAL_INIT(pk);
epee::string_tools::hex_to_pod(::config::P2P_REMOTE_DEBUG_TRUSTED_PUB_KEY, pk);
- crypto::hash h = tools::get_proof_of_trust_hash(tr);
+ crypto::hash h = get_proof_of_trust_hash(tr);
if(!crypto::check_signature(h, pk, tr.sign))
{
LOG_ERROR("check_trust failed: sign check failed");
diff --git a/src/p2p/network_throttle.cpp b/src/p2p/network_throttle.cpp
index a1b115617..74b20376d 100644
--- a/src/p2p/network_throttle.cpp
+++ b/src/p2p/network_throttle.cpp
@@ -77,28 +77,22 @@ int network_throttle_manager::xxx;
// ================================================================================================
// methods:
i_network_throttle & network_throttle_manager::get_global_throttle_in() {
- boost::call_once(m_once_get_global_throttle_in, [] { m_obj_get_global_throttle_in.reset(new network_throttle("in/all","<<< global-IN",10)); } );
- return * m_obj_get_global_throttle_in;
+ static network_throttle obj_get_global_throttle_in("in/all","<<< global-IN",10);
+ return obj_get_global_throttle_in;
}
-boost::once_flag network_throttle_manager::m_once_get_global_throttle_in;
-std::unique_ptr<i_network_throttle> network_throttle_manager::m_obj_get_global_throttle_in;
i_network_throttle & network_throttle_manager::get_global_throttle_inreq() {
- boost::call_once(m_once_get_global_throttle_inreq, [] { m_obj_get_global_throttle_inreq.reset(new network_throttle("inreq/all", "<== global-IN-REQ",10)); } );
- return * m_obj_get_global_throttle_inreq;
+ static network_throttle obj_get_global_throttle_inreq("inreq/all", "<== global-IN-REQ",10);
+ return obj_get_global_throttle_inreq;
}
-boost::once_flag network_throttle_manager::m_once_get_global_throttle_inreq;
-std::unique_ptr<i_network_throttle> network_throttle_manager::m_obj_get_global_throttle_inreq;
i_network_throttle & network_throttle_manager::get_global_throttle_out() {
- boost::call_once(m_once_get_global_throttle_out, [] { m_obj_get_global_throttle_out.reset(new network_throttle("out/all", ">>> global-OUT",10)); } );
- return * m_obj_get_global_throttle_out;
+ static network_throttle obj_get_global_throttle_out("out/all", ">>> global-OUT",10);
+ return obj_get_global_throttle_out;
}
-boost::once_flag network_throttle_manager::m_once_get_global_throttle_out;
-std::unique_ptr<i_network_throttle> network_throttle_manager::m_obj_get_global_throttle_out;
diff --git a/src/p2p/network_throttle.hpp b/src/p2p/network_throttle.hpp
index a1fd2db85..9853df5e1 100644
--- a/src/p2p/network_throttle.hpp
+++ b/src/p2p/network_throttle.hpp
@@ -111,13 +111,6 @@ class network_throttle_manager {
//protected:
public: // XXX
- // [[note1]]
- static boost::once_flag m_once_get_global_throttle_in;
- static boost::once_flag m_once_get_global_throttle_inreq; // [[note2]]
- static boost::once_flag m_once_get_global_throttle_out;
- static std::unique_ptr<i_network_throttle> m_obj_get_global_throttle_in;
- static std::unique_ptr<i_network_throttle> m_obj_get_global_throttle_inreq;
- static std::unique_ptr<i_network_throttle> m_obj_get_global_throttle_out;
static boost::mutex m_lock_get_global_throttle_in;
static boost::mutex m_lock_get_global_throttle_inreq;
diff --git a/src/p2p/p2p_protocol_defs.h b/src/p2p/p2p_protocol_defs.h
index 7bfe8746b..f38615def 100644
--- a/src/p2p/p2p_protocol_defs.h
+++ b/src/p2p/p2p_protocol_defs.h
@@ -442,6 +442,14 @@ namespace nodetool
#endif
+ inline crypto::hash get_proof_of_trust_hash(const nodetool::proof_of_trust& pot)
+ {
+ std::string s;
+ s.append(reinterpret_cast<const char*>(&pot.peer_id), sizeof(pot.peer_id));
+ s.append(reinterpret_cast<const char*>(&pot.time), sizeof(pot.time));
+ return crypto::cn_fast_hash(s.data(), s.size());
+ }
+
}