exclude garlic thread

This commit is contained in:
orignal 2014-10-08 07:55:46 -04:00
parent 002ccdf2c7
commit 296b2d7372
4 changed files with 5 additions and 90 deletions

View File

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

View File

@ -472,64 +472,5 @@ namespace garlic
}
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 ());
}
}
}
}
}

View File

@ -113,31 +113,6 @@ namespace garlic
std::mutex m_CreatedSessionsMutex;
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;
}
}

View File

@ -561,7 +561,10 @@ namespace i2p
break;
case eI2NPGarlic:
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;
case eI2NPDatabaseStore:
case eI2NPDatabaseSearchReply:
@ -574,7 +577,7 @@ namespace i2p
if (msg->from && msg->from->GetTunnelPool ())
msg->from->GetTunnelPool ()->ProcessDeliveryStatus (msg);
else
DeleteI2NPMessage (msg);
i2p::context.HandleDeliveryStatusMessage (msg);
break;
default:
HandleI2NPMessage (msg->GetBuffer (), msg->GetLength ());