|
|
|
@ -15,8 +15,7 @@ namespace client
@@ -15,8 +15,7 @@ namespace client
|
|
|
|
|
LeaseSetDestination::LeaseSetDestination (bool isPublic, const std::map<std::string, std::string> * params): |
|
|
|
|
m_IsRunning (false), m_Thread (nullptr), m_IsPublic (isPublic), |
|
|
|
|
m_PublishReplyToken (0), m_LastSubmissionTime (0), m_PublishConfirmationTimer (m_Service), |
|
|
|
|
m_PublishVerificationTimer (m_Service), m_PublishDelayTimer (m_Service), m_CleanupTimer (m_Service), |
|
|
|
|
m_ReadyCheckTimer(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; |
|
|
|
@ -119,9 +118,7 @@ namespace client
@@ -119,9 +118,7 @@ namespace client
|
|
|
|
|
m_CleanupTimer.async_wait (std::bind (&LeaseSetDestination::HandleCleanupTimer, |
|
|
|
|
shared_from_this (), std::placeholders::_1)); |
|
|
|
|
m_Thread = new std::thread (std::bind (&LeaseSetDestination::Run, shared_from_this ())); |
|
|
|
|
m_ReadyCheckTimer.expires_from_now(boost::posix_time::seconds (1)); |
|
|
|
|
m_ReadyCheckTimer.async_wait(std::bind(&LeaseSetDestination::HandleReadyCheckTimer, |
|
|
|
|
shared_from_this (), std::placeholders::_1)); |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
@ -135,7 +132,6 @@ namespace client
@@ -135,7 +132,6 @@ namespace client
|
|
|
|
|
m_CleanupTimer.cancel (); |
|
|
|
|
m_PublishConfirmationTimer.cancel (); |
|
|
|
|
m_PublishVerificationTimer.cancel (); |
|
|
|
|
m_ReadyCheckTimer.cancel (); |
|
|
|
|
|
|
|
|
|
m_IsRunning = false; |
|
|
|
|
if (m_Pool) |
|
|
|
@ -235,11 +231,6 @@ namespace client
@@ -235,11 +231,6 @@ namespace client
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void LeaseSetDestination::AddReadyCallback(ReadyCallback cb) |
|
|
|
|
{ |
|
|
|
|
m_ReadyCallbacks.push_back(cb); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void LeaseSetDestination::UpdateLeaseSet () |
|
|
|
|
{ |
|
|
|
|
int numTunnels = m_Pool->GetNumInboundTunnels () + 2; // 2 backup tunnels
|
|
|
|
@ -685,30 +676,6 @@ namespace client
@@ -685,30 +676,6 @@ namespace client
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void LeaseSetDestination::HandleReadyCheckTimer(const boost::system::error_code & ec) |
|
|
|
|
{ |
|
|
|
|
if (ec != boost::asio::error::operation_aborted) |
|
|
|
|
{ |
|
|
|
|
// TODO: locking ?
|
|
|
|
|
if(IsReady()) |
|
|
|
|
{ |
|
|
|
|
for (auto & itr : m_ReadyCallbacks) |
|
|
|
|
{ |
|
|
|
|
itr(ec); |
|
|
|
|
} |
|
|
|
|
m_ReadyCallbacks.clear(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
for (auto & itr : m_ReadyCallbacks) |
|
|
|
|
{ |
|
|
|
|
itr(ec); |
|
|
|
|
} |
|
|
|
|
m_ReadyCallbacks.clear(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void LeaseSetDestination::CleanupRemoteLeaseSets () |
|
|
|
|
{ |
|
|
|
|
auto ts = i2p::util::GetMillisecondsSinceEpoch (); |
|
|
|
@ -845,33 +812,20 @@ namespace client
@@ -845,33 +812,20 @@ namespace client
|
|
|
|
|
LogPrint (eLogError, "Destination: request callback is not specified in CreateStream"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if(IsReady()) |
|
|
|
|
{ |
|
|
|
|
auto leaseSet = FindLeaseSet (dest); |
|
|
|
|
if (leaseSet) |
|
|
|
|
streamRequestComplete(CreateStream (leaseSet, port)); |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
auto s = GetSharedFromThis (); |
|
|
|
|
RequestDestination (dest, |
|
|
|
|
[s, streamRequestComplete, port](std::shared_ptr<i2p::data::LeaseSet> ls) |
|
|
|
|
{ |
|
|
|
|
if (ls) |
|
|
|
|
streamRequestComplete(s->CreateStream (ls, port)); |
|
|
|
|
else |
|
|
|
|
streamRequestComplete (nullptr); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
auto leaseSet = FindLeaseSet (dest); |
|
|
|
|
if (leaseSet) |
|
|
|
|
streamRequestComplete(CreateStream (leaseSet, port)); |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
// call if tunnel is not ready
|
|
|
|
|
AddReadyCallback([&](const boost::system::error_code & ec) { |
|
|
|
|
if(ec) |
|
|
|
|
streamRequestComplete(nullptr); |
|
|
|
|
auto s = GetSharedFromThis (); |
|
|
|
|
RequestDestination (dest, |
|
|
|
|
[s, streamRequestComplete, port](std::shared_ptr<i2p::data::LeaseSet> ls) |
|
|
|
|
{ |
|
|
|
|
if (ls) |
|
|
|
|
streamRequestComplete(s->CreateStream (ls, port)); |
|
|
|
|
else |
|
|
|
|
CreateStream(streamRequestComplete, dest, port); |
|
|
|
|
}); |
|
|
|
|
streamRequestComplete (nullptr); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|