Skip to content

Commit

Permalink
exclude garlic thread
Browse files Browse the repository at this point in the history
  • Loading branch information
orignal committed Oct 8, 2014
1 parent 002ccdf commit 296b2d7
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 90 deletions.
4 changes: 0 additions & 4 deletions Daemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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();
Expand Down
59 changes: 0 additions & 59 deletions Garlic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ());
}
}
}
}
}
25 changes: 0 additions & 25 deletions Garlic.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
7 changes: 5 additions & 2 deletions I2NPProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 ());
Expand Down

0 comments on commit 296b2d7

Please sign in to comment.