resuse instance of local destination upon restart

pull/102/head
orignal 10 years ago
parent eff0e13f31
commit a0f43d9772

@ -74,7 +74,8 @@ namespace stream
Stop ();
for (auto it: m_RemoteLeaseSets)
delete it.second;
if (m_Pool)
i2p::tunnel::tunnels.DeleteTunnelPool (m_Pool);
delete m_LeaseSet;
}
@ -98,10 +99,7 @@ namespace stream
m_Streams.clear ();
}
if (m_Pool)
{
i2p::tunnel::tunnels.DeleteTunnelPool (m_Pool);
m_Pool = nullptr;
}
i2p::tunnel::tunnels.StopTunnelPool (m_Pool);
m_IsRunning = false;
m_Service.stop ();
if (m_Thread)
@ -110,6 +108,7 @@ namespace stream
delete m_Thread;
m_Thread = 0;
}
m_Service.reset ();
}
void StreamingDestination::SendTunnelDataMsgs (const std::vector<i2p::tunnel::TunnelMessageBlock>& msgs)
@ -429,6 +428,11 @@ namespace stream
if (it != m_Destinations.end ())
{
LogPrint ("Local destination ", keys.GetPublic ().GetIdentHash ().ToBase32 (), ".b32.i2p exists");
if (!it->second->IsRunning ())
{
it->second->Start ();
return it->second;
}
return nullptr;
}
auto localDestination = new StreamingDestination (keys, isPublic);

@ -25,7 +25,8 @@ namespace stream
void Start ();
void Stop ();
bool IsRunning () const { return m_IsRunning; };
i2p::tunnel::TunnelPool * GetTunnelPool () const { return m_Pool; };
Stream * CreateNewOutgoingStream (const i2p::data::LeaseSet& remote);

@ -599,7 +599,7 @@ namespace stream
for (auto it1 : it->second.sockets)
delete it1;
it->second.sockets.clear ();
DeleteLocalDestination (it->second.localDestination);
it->second.localDestination->Stop ();
m_Sessions.erase (it);
}
}

@ -299,11 +299,24 @@ namespace tunnel
{
if (pool)
{
StopTunnelPool (pool);
m_Pools.erase (pool->GetLocalDestination ().GetIdentHash ());
for (auto it: m_PendingTunnels)
if (it.second->GetTunnelPool () == pool)
it.second->SetTunnelPool (nullptr);
delete pool;
}
}
void Tunnels::StopTunnelPool (TunnelPool * pool)
{
if (pool)
{
pool->SetActive (false);
pool->DetachTunnels ();
pool->SetDeleted ();
}
}
void Tunnels::AddTransitTunnel (TransitTunnel * tunnel)
{
std::unique_lock<std::mutex> l(m_TransitTunnelsMutex);
@ -536,22 +549,14 @@ namespace tunnel
void Tunnels::ManageTunnelPools ()
{
std::unique_lock<std::mutex> l(m_PoolsMutex);
for (auto it = m_Pools.begin (); it != m_Pools.end ();)
for (auto it: m_Pools)
{
TunnelPool * pool = it->second;
if (!pool->IsDeleted ())
TunnelPool * pool = it.second;
if (pool->IsActive ())
{
pool->CreateTunnels ();
pool->TestTunnels ();
it++;
}
else
{
it = m_Pools.erase (it);
for (auto it1: m_PendingTunnels)
if (it1.second->GetTunnelPool () == pool) it1.second->SetTunnelPool (nullptr);
delete pool;
}
}
}
@ -575,8 +580,10 @@ namespace tunnel
std::unique_lock<std::mutex> l(m_OutboundTunnelsMutex);
m_OutboundTunnels.push_back (newTunnel);
auto pool = newTunnel->GetTunnelPool ();
if (pool)
if (pool && pool->IsActive ())
pool->TunnelCreated (newTunnel);
else
newTunnel->SetTunnelPool (nullptr);
}
void Tunnels::AddInboundTunnel (InboundTunnel * newTunnel)
@ -590,7 +597,12 @@ namespace tunnel
CreateTunnel<OutboundTunnel> (newTunnel->GetTunnelConfig ()->Invert (), GetNextOutboundTunnel ());
}
else
pool->TunnelCreated (newTunnel);
{
if (pool->IsActive ())
pool->TunnelCreated (newTunnel);
else
newTunnel->SetTunnelPool (nullptr);
}
}

@ -131,6 +131,7 @@ namespace tunnel
TTunnel * CreateTunnel (TunnelConfig * config, OutboundTunnel * outboundTunnel = 0);
TunnelPool * CreateTunnelPool (i2p::garlic::GarlicDestination& localDestination, int numHops);
void DeleteTunnelPool (TunnelPool * pool);
void StopTunnelPool (TunnelPool * pool);
private:

@ -12,7 +12,7 @@ namespace tunnel
{
TunnelPool::TunnelPool (i2p::garlic::GarlicDestination& localDestination, int numHops, int numTunnels):
m_LocalDestination (localDestination), m_NumHops (numHops), m_NumTunnels (numTunnels),
m_IsDeleted (false)
m_IsActive (true)
{
}
@ -27,17 +27,20 @@ namespace tunnel
std::unique_lock<std::mutex> l(m_InboundTunnelsMutex);
for (auto it: m_InboundTunnels)
it->SetTunnelPool (nullptr);
m_InboundTunnels.clear ();
}
{
std::unique_lock<std::mutex> l(m_OutboundTunnelsMutex);
for (auto it: m_OutboundTunnels)
it->SetTunnelPool (nullptr);
m_OutboundTunnels.clear ();
}
m_Tests.clear ();
}
void TunnelPool::TunnelCreated (InboundTunnel * createdTunnel)
{
if (m_IsDeleted) return;
if (!m_IsActive) return;
{
std::unique_lock<std::mutex> l(m_InboundTunnelsMutex);
m_InboundTunnels.insert (createdTunnel);
@ -61,7 +64,7 @@ namespace tunnel
void TunnelPool::TunnelCreated (OutboundTunnel * createdTunnel)
{
if (m_IsDeleted) return;
if (!m_IsActive) return;
std::unique_lock<std::mutex> l(m_OutboundTunnelsMutex);
m_OutboundTunnels.insert (createdTunnel);
}

@ -48,8 +48,8 @@ namespace tunnel
void TestTunnels ();
void ProcessDeliveryStatus (I2NPMessage * msg);
bool IsDeleted () const { return m_IsDeleted; };
void SetDeleted () { m_IsDeleted = true; };
bool IsActive () const { return m_IsActive; };
void SetActive (bool isActive) { m_IsActive = isActive; };
void DetachTunnels ();
private:
@ -72,7 +72,7 @@ namespace tunnel
mutable std::mutex m_OutboundTunnelsMutex;
std::set<OutboundTunnel *, TunnelCreationTimeCmp> m_OutboundTunnels;
std::map<uint32_t, std::pair<OutboundTunnel *, InboundTunnel *> > m_Tests;
bool m_IsDeleted;
bool m_IsActive;
public:

Loading…
Cancel
Save