aboutsummaryrefslogtreecommitdiff
path: root/src/p2p
diff options
context:
space:
mode:
Diffstat (limited to 'src/p2p')
-rw-r--r--src/p2p/connection_basic.cpp10
-rw-r--r--src/p2p/connection_basic.hpp4
-rw-r--r--src/p2p/net_node.h3
-rw-r--r--src/p2p/net_node.inl22
-rw-r--r--src/p2p/network_throttle-detail.cpp8
-rw-r--r--src/p2p/network_throttle-detail.hpp2
-rw-r--r--src/p2p/network_throttle.cpp20
-rw-r--r--src/p2p/network_throttle.hpp11
-rw-r--r--src/p2p/p2p_protocol_defs.h10
9 files changed, 49 insertions, 41 deletions
diff --git a/src/p2p/connection_basic.cpp b/src/p2p/connection_basic.cpp
index df34379e2..d4fbc79e1 100644
--- a/src/p2p/connection_basic.cpp
+++ b/src/p2p/connection_basic.cpp
@@ -53,8 +53,8 @@
#include "syncobj.h"
-#include "../../contrib/epee/include/net/net_utils_base.h"
-#include "../../contrib/epee/include/misc_log_ex.h"
+#include "net/net_utils_base.h"
+#include "misc_log_ex.h"
#include <boost/lambda/bind.hpp>
#include <boost/lambda/lambda.hpp>
#include <boost/uuid/random_generator.hpp>
@@ -74,11 +74,11 @@
#include <boost/asio/basic_socket.hpp>
#include <boost/asio/ip/unicast.hpp>
-#include "../../contrib/epee/include/net/abstract_tcp_server2.h"
+#include "net/abstract_tcp_server2.h"
// TODO:
-#include "../../src/p2p/network_throttle-detail.hpp"
-#include "../../src/cryptonote_core/cryptonote_core.h"
+#include "network_throttle-detail.hpp"
+#include "cryptonote_core/cryptonote_core.h"
#undef MONERO_DEFAULT_LOG_CATEGORY
#define MONERO_DEFAULT_LOG_CATEGORY "net.p2p"
diff --git a/src/p2p/connection_basic.hpp b/src/p2p/connection_basic.hpp
index bea2df1cd..16de469a7 100644
--- a/src/p2p/connection_basic.hpp
+++ b/src/p2p/connection_basic.hpp
@@ -59,8 +59,8 @@
#include <memory>
-#include "../../contrib/epee/include/net/net_utils_base.h"
-#include "../../contrib/epee/include/syncobj.h"
+#include "net/net_utils_base.h"
+#include "syncobj.h"
namespace epee
{
diff --git a/src/p2p/net_node.h b/src/p2p/net_node.h
index 2e0243ec9..fb7cebde2 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 87d3df457..a977f17b7 100644
--- a/src/p2p/net_node.inl
+++ b/src/p2p/net_node.inl
@@ -452,11 +452,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
@@ -482,19 +482,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;
}
@@ -722,6 +722,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");
@@ -1390,7 +1398,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-detail.cpp b/src/p2p/network_throttle-detail.cpp
index 0747b6f36..1df48ee26 100644
--- a/src/p2p/network_throttle-detail.cpp
+++ b/src/p2p/network_throttle-detail.cpp
@@ -51,8 +51,8 @@
#include "syncobj.h"
-#include "../../contrib/epee/include/net/net_utils_base.h"
-#include "../../contrib/epee/include/misc_log_ex.h"
+#include "net/net_utils_base.h"
+#include "misc_log_ex.h"
#include <boost/lambda/bind.hpp>
#include <boost/lambda/lambda.hpp>
#include <boost/uuid/random_generator.hpp>
@@ -71,10 +71,10 @@
#include <boost/asio/basic_socket.hpp>
#include <boost/asio/ip/unicast.hpp>
-#include "../../contrib/epee/include/net/abstract_tcp_server2.h"
+#include "net/abstract_tcp_server2.h"
// TODO:
-#include "../../src/p2p/network_throttle-detail.hpp"
+#include "network_throttle-detail.hpp"
#undef MONERO_DEFAULT_LOG_CATEGORY
#define MONERO_DEFAULT_LOG_CATEGORY "net.throttle"
diff --git a/src/p2p/network_throttle-detail.hpp b/src/p2p/network_throttle-detail.hpp
index c514db450..27caa85d3 100644
--- a/src/p2p/network_throttle-detail.hpp
+++ b/src/p2p/network_throttle-detail.hpp
@@ -36,7 +36,7 @@
#ifndef INCLUDED_src_p2p_throttle_detail_hpp
#define INCLUDED_src_p2p_throttle_detail_hpp
-#include "../../src/p2p/network_throttle.hpp"
+#include "network_throttle.hpp"
namespace epee
{
diff --git a/src/p2p/network_throttle.cpp b/src/p2p/network_throttle.cpp
index 6d68f3286..74b20376d 100644
--- a/src/p2p/network_throttle.cpp
+++ b/src/p2p/network_throttle.cpp
@@ -54,7 +54,7 @@ Throttling work by:
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#include "../../src/p2p/network_throttle-detail.hpp"
+#include "network_throttle-detail.hpp"
namespace epee
{
@@ -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 a747cdd71..9853df5e1 100644
--- a/src/p2p/network_throttle.hpp
+++ b/src/p2p/network_throttle.hpp
@@ -54,8 +54,8 @@
#include "syncobj.h"
-#include "../../contrib/epee/include/net/net_utils_base.h"
-#include "../../contrib/epee/include/misc_log_ex.h"
+#include "net/net_utils_base.h"
+#include "misc_log_ex.h"
#include <boost/lambda/bind.hpp>
#include <boost/lambda/lambda.hpp>
#include <boost/uuid/random_generator.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 a471211a6..f38615def 100644
--- a/src/p2p/p2p_protocol_defs.h
+++ b/src/p2p/p2p_protocol_defs.h
@@ -35,7 +35,9 @@
#include "net/net_utils_base.h"
#include "misc_language.h"
#include "cryptonote_config.h"
+#ifdef ALLOW_DEBUG_COMMANDS
#include "crypto/crypto.h"
+#endif
namespace nodetool
{
@@ -440,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());
+ }
+
}