|
|
@ -14,6 +14,7 @@ namespace client |
|
|
|
m_LocalDestination (localDestination ? localDestination : |
|
|
|
m_LocalDestination (localDestination ? localDestination : |
|
|
|
i2p::client::context.CreateNewLocalDestination (false, I2P_SERVICE_DEFAULT_KEY_TYPE)), |
|
|
|
i2p::client::context.CreateNewLocalDestination (false, I2P_SERVICE_DEFAULT_KEY_TYPE)), |
|
|
|
m_ReadyTimer(m_LocalDestination->GetService()), |
|
|
|
m_ReadyTimer(m_LocalDestination->GetService()), |
|
|
|
|
|
|
|
m_ReadyTimerTriggered(false), |
|
|
|
m_ConnectTimeout(0), |
|
|
|
m_ConnectTimeout(0), |
|
|
|
isUpdated (true) |
|
|
|
isUpdated (true) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -47,29 +48,25 @@ namespace client |
|
|
|
|
|
|
|
|
|
|
|
void I2PService::SetConnectTimeout(uint32_t timeout) |
|
|
|
void I2PService::SetConnectTimeout(uint32_t timeout) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if(timeout && !m_ConnectTimeout) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
TriggerReadyCheckTimer(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (m_ConnectTimeout && !timeout) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
m_ReadyTimer.cancel(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
m_ConnectTimeout = timeout; |
|
|
|
m_ConnectTimeout = timeout; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void I2PService::AddReadyCallback(ReadyCallback cb) |
|
|
|
void I2PService::AddReadyCallback(ReadyCallback cb) |
|
|
|
{ |
|
|
|
{ |
|
|
|
uint32_t now = i2p::util::GetSecondsSinceEpoch(); |
|
|
|
uint32_t now = i2p::util::GetSecondsSinceEpoch(); |
|
|
|
uint32_t tm = now + m_ConnectTimeout; |
|
|
|
uint32_t tm = (m_ConnectTimeout) ? now + m_ConnectTimeout : NEVER_TIMES_OUT; |
|
|
|
|
|
|
|
|
|
|
|
LogPrint(eLogDebug, "I2PService::AddReadyCallback() ", tm, " ", now); |
|
|
|
LogPrint(eLogDebug, "I2PService::AddReadyCallback() ", tm, " ", now); |
|
|
|
m_ReadyCallbacks.push_back({cb, tm}); |
|
|
|
m_ReadyCallbacks.push_back({cb, tm}); |
|
|
|
|
|
|
|
if (!m_ReadyTimerTriggered) TriggerReadyCheckTimer(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void I2PService::TriggerReadyCheckTimer() |
|
|
|
void I2PService::TriggerReadyCheckTimer() |
|
|
|
{ |
|
|
|
{ |
|
|
|
m_ReadyTimer.expires_from_now(boost::posix_time::seconds (1)); |
|
|
|
m_ReadyTimer.expires_from_now(boost::posix_time::seconds (1)); |
|
|
|
m_ReadyTimer.async_wait(std::bind(&I2PService::HandleReadyCheckTimer, this, std::placeholders::_1)); |
|
|
|
m_ReadyTimer.async_wait(std::bind(&I2PService::HandleReadyCheckTimer, this, std::placeholders::_1)); |
|
|
|
|
|
|
|
m_ReadyTimerTriggered = true; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void I2PService::HandleReadyCheckTimer(const boost::system::error_code &ec) |
|
|
|
void I2PService::HandleReadyCheckTimer(const boost::system::error_code &ec) |
|
|
@ -87,7 +84,7 @@ namespace client |
|
|
|
auto itr = m_ReadyCallbacks.begin(); |
|
|
|
auto itr = m_ReadyCallbacks.begin(); |
|
|
|
while(itr != m_ReadyCallbacks.end()) |
|
|
|
while(itr != m_ReadyCallbacks.end()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if(itr->second >= now) |
|
|
|
if(itr->second != NEVER_TIMES_OUT && now >= itr->second) |
|
|
|
{ |
|
|
|
{ |
|
|
|
itr->first(boost::asio::error::timed_out); |
|
|
|
itr->first(boost::asio::error::timed_out); |
|
|
|
itr = m_ReadyCallbacks.erase(itr); |
|
|
|
itr = m_ReadyCallbacks.erase(itr); |
|
|
@ -96,8 +93,10 @@ namespace client |
|
|
|
++itr; |
|
|
|
++itr; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if(!ec) |
|
|
|
if(!ec && m_ReadyCallbacks.size()) |
|
|
|
TriggerReadyCheckTimer(); |
|
|
|
TriggerReadyCheckTimer(); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
m_ReadyTimerTriggered = false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void I2PService::CreateStream (StreamRequestComplete streamRequestComplete, const std::string& dest, int port) { |
|
|
|
void I2PService::CreateStream (StreamRequestComplete streamRequestComplete, const std::string& dest, int port) { |
|
|
|