Browse Source

wait until LeaseSet request complete instead timeout

pull/120/head
orignal 10 years ago
parent
commit
59aa40e2b0
  1. 24
      SAM.cpp
  2. 6
      SAM.h

24
SAM.cpp

@ -325,9 +325,8 @@ namespace client @@ -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 @@ -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);
}
}

6
SAM.h

@ -19,9 +19,7 @@ namespace i2p @@ -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 @@ -107,7 +105,7 @@ namespace client
void ExtractParams (char * buf, size_t len, std::map<std::string, std::string>& 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);

Loading…
Cancel
Save