From 422f8b36607a81a3780d5857a5a7b1bba1cd1cbd Mon Sep 17 00:00:00 2001 From: orignal Date: Sun, 12 Feb 2017 20:52:46 -0500 Subject: [PATCH] publish with min interval of 20 seconds --- Destination.cpp | 21 +++++++++++++++++++-- Destination.h | 6 +++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/Destination.cpp b/Destination.cpp index ac812da4..06fcf6b3 100644 --- a/Destination.cpp +++ b/Destination.cpp @@ -14,8 +14,8 @@ namespace client { LeaseSetDestination::LeaseSetDestination (bool isPublic, const std::map * params): m_IsRunning (false), m_Thread (nullptr), m_IsPublic (isPublic), - m_PublishReplyToken (0), m_PublishConfirmationTimer (m_Service), - m_PublishVerificationTimer (m_Service), m_CleanupTimer (m_Service) + m_PublishReplyToken (0), m_LastSubmissionTime (0), m_PublishConfirmationTimer (m_Service), + m_PublishVerificationTimer (m_Service), m_PublishDelayTimer (m_Service), m_CleanupTimer (m_Service) { int inLen = DEFAULT_INBOUND_TUNNEL_LENGTH; int inQty = DEFAULT_INBOUND_TUNNELS_QUANTITY; @@ -426,6 +426,16 @@ namespace client LogPrint (eLogDebug, "Destination: Publishing LeaseSet is pending"); return; } + auto ts = i2p::util::GetSecondsSinceEpoch (); + if (ts < m_LastSubmissionTime + PUBLISH_MIN_INTERVAL) + { + LogPrint (eLogDebug, "Destination: Publishing LeaseSet is too fast. Wait for ", PUBLISH_MIN_INTERVAL, " seconds"); + m_PublishDelayTimer.cancel (); + m_PublishDelayTimer.expires_from_now (boost::posix_time::seconds(PUBLISH_MIN_INTERVAL)); + m_PublishDelayTimer.async_wait (std::bind (&LeaseSetDestination::HandlePublishDelayTimer, + shared_from_this (), std::placeholders::_1)); + return; + } auto outbound = m_Pool->GetNextOutboundTunnel (); if (!outbound) { @@ -453,6 +463,7 @@ namespace client m_PublishConfirmationTimer.async_wait (std::bind (&LeaseSetDestination::HandlePublishConfirmationTimer, shared_from_this (), std::placeholders::_1)); outbound->SendTunnelDataMsg (floodfill->GetIdentHash (), 0, msg); + m_LastSubmissionTime = ts; } void LeaseSetDestination::HandlePublishConfirmationTimer (const boost::system::error_code& ecode) @@ -498,6 +509,12 @@ namespace client } } + void LeaseSetDestination::HandlePublishDelayTimer (const boost::system::error_code& ecode) + { + if (ecode != boost::asio::error::operation_aborted) + Publish (); + } + bool LeaseSetDestination::RequestDestination (const i2p::data::IdentHash& dest, RequestComplete requestComplete) { if (!m_Pool || !IsReady ()) diff --git a/Destination.h b/Destination.h index 7a4e0b64..e077c016 100644 --- a/Destination.h +++ b/Destination.h @@ -30,6 +30,7 @@ namespace client const uint8_t PROTOCOL_TYPE_RAW = 18; const int PUBLISH_CONFIRMATION_TIMEOUT = 5; // in seconds const int PUBLISH_VERIFICATION_TIMEOUT = 10; // in seconds after successfull publish + const int PUBLISH_MIN_INTERVAL = 20; // in seconds const int PUBLISH_REGULAR_VERIFICATION_INTERNAL = 100; // in seconds periodically const int LEASESET_REQUEST_TIMEOUT = 5; // in seconds const int MAX_LEASESET_REQUEST_TIMEOUT = 40; // in seconds @@ -122,6 +123,7 @@ namespace client void Publish (); void HandlePublishConfirmationTimer (const boost::system::error_code& ecode); void HandlePublishVerificationTimer (const boost::system::error_code& ecode); + void HandlePublishDelayTimer (const boost::system::error_code& ecode); void HandleDatabaseStoreMessage (const uint8_t * buf, size_t len); void HandleDatabaseSearchReplyMessage (const uint8_t * buf, size_t len); void HandleDeliveryStatusMessage (std::shared_ptr msg); @@ -146,9 +148,11 @@ namespace client std::shared_ptr m_LeaseSet; bool m_IsPublic; uint32_t m_PublishReplyToken; + uint64_t m_LastSubmissionTime; // in seconds std::set m_ExcludedFloodfills; // for publishing - boost::asio::deadline_timer m_PublishConfirmationTimer, m_PublishVerificationTimer, m_CleanupTimer; + boost::asio::deadline_timer m_PublishConfirmationTimer, m_PublishVerificationTimer, + m_PublishDelayTimer, m_CleanupTimer; public: