From 59aa40e2b0590c35697138748fae9a24d5519232 Mon Sep 17 00:00:00 2001 From: orignal Date: Fri, 26 Dec 2014 21:06:24 -0500 Subject: [PATCH] wait until LeaseSet request complete instead timeout --- SAM.cpp | 24 +++++++++++------------- SAM.h | 6 ++---- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/SAM.cpp b/SAM.cpp index 102c0454..2b39ca28 100644 --- a/SAM.cpp +++ b/SAM.cpp @@ -325,9 +325,8 @@ namespace client Connect (*leaseSet); else { - m_Session->localDestination->RequestDestination (dest.GetIdentHash ()); - m_Timer.expires_from_now (boost::posix_time::seconds(SAM_CONNECT_TIMEOUT)); - m_Timer.async_wait (std::bind (&SAMSocket::HandleStreamDestinationRequestTimer, + m_Session->localDestination->RequestDestination (dest.GetIdentHash (), + std::bind (&SAMSocket::HandleLeaseSetRequestComplete, shared_from_this (), std::placeholders::_1, dest.GetIdentHash ())); } } @@ -345,18 +344,17 @@ namespace client SendMessageReply (SAM_STREAM_STATUS_OK, strlen(SAM_STREAM_STATUS_OK), false); } - void SAMSocket::HandleStreamDestinationRequestTimer (const boost::system::error_code& ecode, i2p::data::IdentHash ident) + void SAMSocket::HandleLeaseSetRequestComplete (bool success, i2p::data::IdentHash ident) { - if (!ecode) // timeout expired + const i2p::data::LeaseSet * leaseSet = nullptr; + if (success) // timeout expired + leaseSet = m_Session->localDestination->FindLeaseSet (ident); + if (leaseSet) + Connect (*leaseSet); + else { - auto leaseSet = m_Session->localDestination->FindLeaseSet (ident); - if (leaseSet) - Connect (*leaseSet); - else - { - LogPrint ("SAM destination to connect not found"); - SendMessageReply (SAM_STREAM_STATUS_CANT_REACH_PEER, strlen(SAM_STREAM_STATUS_CANT_REACH_PEER), true); - } + LogPrint ("SAM destination to connect not found"); + SendMessageReply (SAM_STREAM_STATUS_CANT_REACH_PEER, strlen(SAM_STREAM_STATUS_CANT_REACH_PEER), true); } } diff --git a/SAM.h b/SAM.h index 72a8ce3c..f38ddcdc 100644 --- a/SAM.h +++ b/SAM.h @@ -19,9 +19,7 @@ namespace i2p namespace client { const size_t SAM_SOCKET_BUFFER_SIZE = 4096; - const int SAM_SOCKET_CONNECTION_MAX_IDLE = 3600; // in seconds - const int SAM_CONNECT_TIMEOUT = 5; // in seconds - const int SAM_NAMING_LOOKUP_TIMEOUT = 5; // in seconds + const int SAM_SOCKET_CONNECTION_MAX_IDLE = 3600; // in seconds const int SAM_SESSION_READINESS_CHECK_INTERVAL = 20; // in seconds const char SAM_HANDSHAKE[] = "HELLO VERSION"; const char SAM_HANDSHAKE_REPLY[] = "HELLO REPLY RESULT=OK VERSION=%s\n"; @@ -107,7 +105,7 @@ namespace client void ExtractParams (char * buf, size_t len, std::map& params); void Connect (const i2p::data::LeaseSet& remote); - void HandleStreamDestinationRequestTimer (const boost::system::error_code& ecode, i2p::data::IdentHash ident); + void HandleLeaseSetRequestComplete (bool success, i2p::data::IdentHash ident); void SendNamingLookupReply (const i2p::data::LeaseSet * leaseSet); void SendNamingLookupReply (const i2p::data::IdentityEx& identity); void HandleSessionReadinessCheckTimer (const boost::system::error_code& ecode);