diff --git a/libi2pd/Destination.cpp b/libi2pd/Destination.cpp index 1bc7c139..2373659d 100644 --- a/libi2pd/Destination.cpp +++ b/libi2pd/Destination.cpp @@ -702,8 +702,11 @@ namespace client s->HandlePublishConfirmationTimer (boost::system::error_code(), 0); }); }; - uint64_t publishConfirmationTimeout = PUBLISH_CONFIRMATION_TIMEOUT + - (inbound->GetNumHops () + outbound->GetNumHops ())*(uint64_t)i2p::tunnel::HIGH_LATENCY_PER_HOP/1000LL; + uint64_t publishConfirmationTimeout = PUBLISH_CONFIRMATION_TIMEOUT; + publishConfirmationTimeout += inbound->LatencyIsKnown() ? (uint64_t)(inbound->GetMeanLatency())/1000LL : + inbound->GetNumHops ()*(uint64_t)(i2p::tunnel::HIGH_LATENCY_PER_HOP)/1000LL; + publishConfirmationTimeout += outbound->LatencyIsKnown() ? (uint64_t)(outbound->GetMeanLatency())/1000LL : + outbound->GetNumHops ()*(uint64_t)(i2p::tunnel::HIGH_LATENCY_PER_HOP)/1000LL; m_PublishConfirmationTimer.expires_after (std::chrono::milliseconds(publishConfirmationTimeout)); m_PublishConfirmationTimer.async_wait (std::bind (&LeaseSetDestination::HandlePublishConfirmationTimer, shared_from_this (), std::placeholders::_1, publishConfirmationTimeout)); @@ -907,16 +910,23 @@ namespace client nextFloodfill->GetIdentHash (), 0, msg } }); - request->requestTimeoutTimer.expires_after (std::chrono::milliseconds(LEASESET_REQUEST_TIMEOUT)); + + uint64_t requestLeaseSetTimeout = LEASESET_REQUEST_TIMEOUT; + requestLeaseSetTimeout += request->replyTunnel->LatencyIsKnown() ? (uint64_t)(request->replyTunnel->GetMeanLatency())/1000LL : + request->replyTunnel->GetNumHops ()*(uint64_t)(i2p::tunnel::HIGH_LATENCY_PER_HOP)/1000LL; + requestLeaseSetTimeout += request->outboundTunnel->LatencyIsKnown() ? (uint64_t)(request->outboundTunnel->GetMeanLatency())/1000LL : + request->outboundTunnel->GetNumHops ()*(uint64_t)(i2p::tunnel::HIGH_LATENCY_PER_HOP)/1000LL; + request->requestTimeoutTimer.expires_after (std::chrono::milliseconds(requestLeaseSetTimeout)); request->requestTimeoutTimer.async_wait (std::bind (&LeaseSetDestination::HandleRequestTimoutTimer, - shared_from_this (), std::placeholders::_1, dest)); + shared_from_this (), std::placeholders::_1, dest, requestLeaseSetTimeout)); } else return false; return true; } - void LeaseSetDestination::HandleRequestTimoutTimer (const boost::system::error_code& ecode, const i2p::data::IdentHash& dest) + void LeaseSetDestination::HandleRequestTimoutTimer (const boost::system::error_code& ecode, + const i2p::data::IdentHash& dest, uint64_t requestLeaseSetTimeout) { if (ecode != boost::asio::error::operation_aborted) { @@ -940,7 +950,7 @@ namespace client } else { - LogPrint (eLogWarning, "Destination: ", dest.ToBase64 (), " was not found within ", MAX_LEASESET_REQUEST_TIMEOUT, " seconds"); + LogPrint (eLogWarning, "Destination: ", dest.ToBase64 (), " was not found within ", requestLeaseSetTimeout, " seconds"); done = true; } diff --git a/libi2pd/Destination.h b/libi2pd/Destination.h index 4be0c3ce..6aeb61e4 100644 --- a/libi2pd/Destination.h +++ b/libi2pd/Destination.h @@ -45,7 +45,7 @@ namespace client const int PUBLISH_MIN_INTERVAL = 20; // in seconds const int PUBLISH_REGULAR_VERIFICATION_INTERNAL = 100; // in seconds periodically const int LEASESET_REQUEST_TIMEOUT = 1600; // in milliseconds - const int MAX_LEASESET_REQUEST_TIMEOUT = 12000; // in milliseconds + const int MAX_LEASESET_REQUEST_TIMEOUT = 17000; // in milliseconds const int DESTINATION_CLEANUP_TIMEOUT = 44; // in seconds const int DESTINATION_CLEANUP_TIMEOUT_VARIANCE = 30; // in seconds const unsigned int MAX_NUM_FLOODFILLS_PER_REQUEST = 7; @@ -202,7 +202,7 @@ namespace client void RequestLeaseSet (const i2p::data::IdentHash& dest, RequestComplete requestComplete, std::shared_ptr requestedBlindedKey = nullptr); bool SendLeaseSetRequest (const i2p::data::IdentHash& dest, std::shared_ptr nextFloodfill, std::shared_ptr request); void SendNextLeaseSetRequest (const i2p::data::IdentHash& key, std::shared_ptr request); - void HandleRequestTimoutTimer (const boost::system::error_code& ecode, const i2p::data::IdentHash& dest); + void HandleRequestTimoutTimer (const boost::system::error_code& ecode, const i2p::data::IdentHash& dest, uint64_t requestLeaseSetTimeout); void HandleCleanupTimer (const boost::system::error_code& ecode); void CleanupRemoteLeaseSets ();