Browse Source

exclude garlic thread

pull/102/head
orignal 10 years ago
parent
commit
296b2d7372
  1. 4
      Daemon.cpp
  2. 59
      Garlic.cpp
  3. 25
      Garlic.h
  4. 7
      I2NPProtocol.cpp

4
Daemon.cpp

@ -111,8 +111,6 @@ namespace i2p
LogPrint("Transports started"); LogPrint("Transports started");
i2p::tunnel::tunnels.Start(); i2p::tunnel::tunnels.Start();
LogPrint("Tunnels started"); LogPrint("Tunnels started");
i2p::garlic::routing.Start();
LogPrint("Routing started");
i2p::stream::StartStreaming(); i2p::stream::StartStreaming();
LogPrint("Streaming started"); LogPrint("Streaming started");
@ -164,8 +162,6 @@ namespace i2p
LogPrint("SOCKS Proxy stoped"); LogPrint("SOCKS Proxy stoped");
i2p::stream::StopStreaming(); i2p::stream::StopStreaming();
LogPrint("Streaming stoped"); LogPrint("Streaming stoped");
i2p::garlic::routing.Stop();
LogPrint("Routing stoped");
i2p::tunnel::tunnels.Stop(); i2p::tunnel::tunnels.Stop();
LogPrint("Tunnels stoped"); LogPrint("Tunnels stoped");
i2p::transports.Stop(); i2p::transports.Stop();

59
Garlic.cpp

@ -472,64 +472,5 @@ namespace garlic
} }
DeleteI2NPMessage (msg); DeleteI2NPMessage (msg);
} }
GarlicRouting routing;
void GarlicRouting::HandleGarlicMessage (I2NPMessage * msg)
{
auto pool = msg->from ? msg->from->GetTunnelPool () : nullptr;
if (pool)
pool->GetGarlicDestination ().HandleGarlicMessage (msg);
else
{
LogPrint ("Local destination doesn't exist");
DeleteI2NPMessage (msg);
}
}
void GarlicRouting::Start ()
{
m_IsRunning = true;
m_Thread = new std::thread (std::bind (&GarlicRouting::Run, this));
}
void GarlicRouting::Stop ()
{
m_IsRunning = false;
m_Queue.WakeUp ();
if (m_Thread)
{
m_Thread->join ();
delete m_Thread;
m_Thread = 0;
}
}
void GarlicRouting::PostI2NPMsg (I2NPMessage * msg)
{
if (msg) m_Queue.Put (msg);
}
void GarlicRouting::Run ()
{
while (m_IsRunning)
{
try
{
I2NPMessage * msg = m_Queue.GetNext ();
if (msg->GetHeader ()->typeID == eI2NPGarlic)
HandleGarlicMessage (msg);
else
{
LogPrint ("Garlic: unexpected message type ", msg->GetHeader ()->typeID);
i2p::HandleI2NPMessage (msg);
}
}
catch (std::exception& ex)
{
LogPrint ("GarlicRouting: ", ex.what ());
}
}
}
} }
} }

25
Garlic.h

@ -113,31 +113,6 @@ namespace garlic
std::mutex m_CreatedSessionsMutex; std::mutex m_CreatedSessionsMutex;
std::map<uint32_t, GarlicRoutingSession *> m_CreatedSessions; // msgID -> session std::map<uint32_t, GarlicRoutingSession *> m_CreatedSessions; // msgID -> session
}; };
class GarlicRouting
{
public:
GarlicRouting (): m_IsRunning (false), m_Thread (nullptr) {};
~GarlicRouting () {};
void Start ();
void Stop ();
void PostI2NPMsg (I2NPMessage * msg);
private:
void Run ();
void HandleGarlicMessage (I2NPMessage * msg);
private:
bool m_IsRunning;
std::thread * m_Thread;
i2p::util::Queue<I2NPMessage> m_Queue;
};
extern GarlicRouting routing;
} }
} }

7
I2NPProtocol.cpp

@ -561,7 +561,10 @@ namespace i2p
break; break;
case eI2NPGarlic: case eI2NPGarlic:
LogPrint ("Garlic"); LogPrint ("Garlic");
i2p::garlic::routing.PostI2NPMsg (msg); if (msg->from && msg->from->GetTunnelPool ())
msg->from->GetTunnelPool ()->GetGarlicDestination ().HandleGarlicMessage (msg);
else
i2p::context.HandleGarlicMessage (msg);
break; break;
case eI2NPDatabaseStore: case eI2NPDatabaseStore:
case eI2NPDatabaseSearchReply: case eI2NPDatabaseSearchReply:
@ -574,7 +577,7 @@ namespace i2p
if (msg->from && msg->from->GetTunnelPool ()) if (msg->from && msg->from->GetTunnelPool ())
msg->from->GetTunnelPool ()->ProcessDeliveryStatus (msg); msg->from->GetTunnelPool ()->ProcessDeliveryStatus (msg);
else else
DeleteI2NPMessage (msg); i2p::context.HandleDeliveryStatusMessage (msg);
break; break;
default: default:
HandleI2NPMessage (msg->GetBuffer (), msg->GetLength ()); HandleI2NPMessage (msg->GetBuffer (), msg->GetLength ());

Loading…
Cancel
Save