From f76b014a5296d04875acac0ea59cddabcca84ac2 Mon Sep 17 00:00:00 2001 From: orignal Date: Sun, 13 Nov 2016 09:14:05 -0500 Subject: [PATCH] re-run PeerTest --- Transports.cpp | 19 ++++++++++++++++--- Transports.h | 6 ++++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Transports.cpp b/Transports.cpp index 358ca4c7..d41253d6 100644 --- a/Transports.cpp +++ b/Transports.cpp @@ -108,7 +108,8 @@ namespace transport Transports transports; Transports::Transports (): - m_IsOnline (true), m_IsRunning (false), m_Thread (nullptr), m_Work (m_Service), m_PeerCleanupTimer (m_Service), + m_IsOnline (true), m_IsRunning (false), m_Thread (nullptr), m_Work (m_Service), + m_PeerCleanupTimer (m_Service), m_PeerTestTimer (m_Service), m_NTCPServer (nullptr), m_SSUServer (nullptr), m_DHKeysPairSupplier (5), // 5 pre-generated keys m_TotalSentBytes(0), m_TotalReceivedBytes(0), m_InBandwidth (0), m_OutBandwidth (0), m_LastInBandwidthUpdateBytes (0), m_LastOutBandwidthUpdateBytes (0), m_LastBandwidthUpdateTime (0) @@ -168,11 +169,14 @@ namespace transport } m_PeerCleanupTimer.expires_from_now (boost::posix_time::seconds(5*SESSION_CREATION_TIMEOUT)); m_PeerCleanupTimer.async_wait (std::bind (&Transports::HandlePeerCleanupTimer, this, std::placeholders::_1)); + m_PeerTestTimer.expires_from_now (boost::posix_time::minutes(PEER_TEST_INTERVAL)); + m_PeerTestTimer.async_wait (std::bind (&Transports::HandlePeerTestTimer, this, std::placeholders::_1)); } void Transports::Stop () { m_PeerCleanupTimer.cancel (); + m_PeerTestTimer.cancel (); m_Peers.clear (); if (m_SSUServer) { @@ -546,8 +550,7 @@ namespace transport { if (RoutesRestricted()) return; if (m_SSUServer) - { - + { bool statusChanged = false; for (int i = 0; i < 5; i++) { @@ -688,6 +691,16 @@ namespace transport } } + void Transports::HandlePeerTestTimer (const boost::system::error_code& ecode) + { + if (ecode != boost::asio::error::operation_aborted) + { + PeerTest (); + m_PeerTestTimer.expires_from_now (boost::posix_time::minutes(PEER_TEST_INTERVAL)); + m_PeerTestTimer.async_wait (std::bind (&Transports::HandlePeerTestTimer, this, std::placeholders::_1)); + } + } + std::shared_ptr Transports::GetRandomPeer () const { if (m_Peers.empty ()) return nullptr; diff --git a/Transports.h b/Transports.h index 9ecfd719..1fe262a9 100644 --- a/Transports.h +++ b/Transports.h @@ -66,6 +66,7 @@ namespace transport }; const size_t SESSION_CREATION_TIMEOUT = 10; // in seconds + const int PEER_TEST_INTERVAL = 71; // in minutes const int MAX_NUM_DELAYED_MESSAGES = 50; class Transports { @@ -127,7 +128,8 @@ namespace transport void PostCloseSession (std::shared_ptr router); bool ConnectToPeer (const i2p::data::IdentHash& ident, Peer& peer); void HandlePeerCleanupTimer (const boost::system::error_code& ecode); - + void HandlePeerTestTimer (const boost::system::error_code& ecode); + void NTCPResolve (const std::string& addr, const i2p::data::IdentHash& ident); void HandleNTCPResolve (const boost::system::error_code& ecode, boost::asio::ip::tcp::resolver::iterator it, i2p::data::IdentHash ident, std::shared_ptr resolver); @@ -144,7 +146,7 @@ namespace transport std::thread * m_Thread; boost::asio::io_service m_Service; boost::asio::io_service::work m_Work; - boost::asio::deadline_timer m_PeerCleanupTimer; + boost::asio::deadline_timer m_PeerCleanupTimer, m_PeerTestTimer; NTCPServer * m_NTCPServer; SSUServer * m_SSUServer;