Browse Source

resuse instance of local destination upon restart

pull/102/head
orignal 10 years ago
parent
commit
a0f43d9772
  1. 14
      Destination.cpp
  2. 1
      Destination.h
  3. 2
      SAM.cpp
  4. 40
      Tunnel.cpp
  5. 1
      Tunnel.h
  6. 9
      TunnelPool.cpp
  7. 6
      TunnelPool.h

14
Destination.cpp

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

1
Destination.h

@ -25,6 +25,7 @@ namespace stream
void Start (); void Start ();
void Stop (); void Stop ();
bool IsRunning () const { return m_IsRunning; };
i2p::tunnel::TunnelPool * GetTunnelPool () const { return m_Pool; }; i2p::tunnel::TunnelPool * GetTunnelPool () const { return m_Pool; };

2
SAM.cpp

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

40
Tunnel.cpp

@ -299,8 +299,21 @@ namespace tunnel
{ {
if (pool) 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->DetachTunnels ();
pool->SetDeleted ();
} }
} }
@ -536,21 +549,13 @@ namespace tunnel
void Tunnels::ManageTunnelPools () void Tunnels::ManageTunnelPools ()
{ {
std::unique_lock<std::mutex> l(m_PoolsMutex); 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; TunnelPool * pool = it.second;
if (!pool->IsDeleted ()) if (pool->IsActive ())
{ {
pool->CreateTunnels (); pool->CreateTunnels ();
pool->TestTunnels (); 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); std::unique_lock<std::mutex> l(m_OutboundTunnelsMutex);
m_OutboundTunnels.push_back (newTunnel); m_OutboundTunnels.push_back (newTunnel);
auto pool = newTunnel->GetTunnelPool (); auto pool = newTunnel->GetTunnelPool ();
if (pool) if (pool && pool->IsActive ())
pool->TunnelCreated (newTunnel); pool->TunnelCreated (newTunnel);
else
newTunnel->SetTunnelPool (nullptr);
} }
void Tunnels::AddInboundTunnel (InboundTunnel * newTunnel) void Tunnels::AddInboundTunnel (InboundTunnel * newTunnel)
@ -590,7 +597,12 @@ namespace tunnel
CreateTunnel<OutboundTunnel> (newTunnel->GetTunnelConfig ()->Invert (), GetNextOutboundTunnel ()); CreateTunnel<OutboundTunnel> (newTunnel->GetTunnelConfig ()->Invert (), GetNextOutboundTunnel ());
} }
else else
pool->TunnelCreated (newTunnel); {
if (pool->IsActive ())
pool->TunnelCreated (newTunnel);
else
newTunnel->SetTunnelPool (nullptr);
}
} }

1
Tunnel.h

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

9
TunnelPool.cpp

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

6
TunnelPool.h

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

Loading…
Cancel
Save