mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-28 11:47:48 +02:00
handle garlic message in separate thread
This commit is contained in:
parent
6732ba21f9
commit
28cc50fece
3 changed files with 53 additions and 0 deletions
40
Garlic.cpp
40
Garlic.cpp
|
@ -263,6 +263,11 @@ namespace garlic
|
|||
}
|
||||
|
||||
void GarlicRouting::HandleGarlicMessage (I2NPMessage * msg)
|
||||
{
|
||||
if (msg) m_Queue.Put (msg);
|
||||
}
|
||||
|
||||
void GarlicRouting::ProcessGarlicMessage (I2NPMessage * msg)
|
||||
{
|
||||
uint8_t * buf = msg->GetPayload ();
|
||||
uint32_t length = be32toh (*(uint32_t *)buf);
|
||||
|
@ -411,5 +416,40 @@ namespace garlic
|
|||
LogPrint ("Garlic message ", be32toh (msg->msgID), " acknowledged");
|
||||
}
|
||||
}
|
||||
|
||||
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::Run ()
|
||||
{
|
||||
while (m_IsRunning)
|
||||
{
|
||||
try
|
||||
{
|
||||
I2NPMessage * msg = m_Queue.GetNext ();
|
||||
if (msg)
|
||||
ProcessGarlicMessage (msg);
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
LogPrint ("GarlicRouting: ", ex.what ());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue