Skip to content

Commit

Permalink
handle garlic's DeliveryStatus in the garlic thread
Browse files Browse the repository at this point in the history
  • Loading branch information
orignal committed Aug 15, 2014
1 parent f741b14 commit eff3bb6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 22 deletions.
37 changes: 26 additions & 11 deletions Garlic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,13 +325,8 @@ namespace garlic
m_CreatedSessions[session->GetFirstMsgID ()] = session;
return ret;
}

void GarlicRouting::HandleGarlicMessage (I2NPMessage * msg)
{
if (msg) m_Queue.Put (msg);
}

void GarlicRouting::ProcessGarlicMessage (I2NPMessage * msg)
void GarlicRouting::HandleGarlicMessage (I2NPMessage * msg)
{
uint8_t * buf = msg->GetPayload ();
uint32_t length = be32toh (*(uint32_t *)buf);
Expand Down Expand Up @@ -480,16 +475,18 @@ namespace garlic
}
}

void GarlicRouting::HandleDeliveryStatusMessage (uint8_t * buf, size_t len)
void GarlicRouting::HandleDeliveryStatusMessage (I2NPMessage * msg)
{
I2NPDeliveryStatusMsg * msg = (I2NPDeliveryStatusMsg *)buf;
auto it = m_CreatedSessions.find (be32toh (msg->msgID));
I2NPDeliveryStatusMsg * deliveryStatus = (I2NPDeliveryStatusMsg *)msg->GetPayload ();
uint32_t msgID = be32toh (deliveryStatus->msgID);
auto it = m_CreatedSessions.find (msgID);
if (it != m_CreatedSessions.end ())
{
it->second->SetAcknowledged (true);
m_CreatedSessions.erase (it);
LogPrint ("Garlic message ", be32toh (msg->msgID), " acknowledged");
LogPrint ("Garlic message ", msgID, " acknowledged");
}
DeleteI2NPMessage (msg);
}

void GarlicRouting::Start ()
Expand All @@ -510,6 +507,11 @@ namespace garlic
}
}

void GarlicRouting::PostI2NPMsg (I2NPMessage * msg)
{
if (msg) m_Queue.Put (msg);
}

void GarlicRouting::Run ()
{
while (m_IsRunning)
Expand All @@ -518,7 +520,20 @@ namespace garlic
{
I2NPMessage * msg = m_Queue.GetNext ();
if (msg)
ProcessGarlicMessage (msg);
{
switch (msg->GetHeader ()->typeID)
{
case eI2NPGarlic:
HandleGarlicMessage (msg);
break;
case eI2NPDeliveryStatus:
HandleDeliveryStatusMessage (msg);
break;
default:
LogPrint ("Garlic: unexpected message type ", msg->GetHeader ()->typeID);
i2p::HandleI2NPMessage (msg);
}
}
}
catch (std::exception& ex)
{
Expand Down
7 changes: 3 additions & 4 deletions Garlic.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,8 @@ namespace garlic

void Start ();
void Stop ();
void PostI2NPMsg (I2NPMessage * msg);
void AddSessionKey (const uint8_t * key, const uint8_t * tag); // one tag

void HandleGarlicMessage (I2NPMessage * msg);
void HandleDeliveryStatusMessage (uint8_t * buf, size_t len);

I2NPMessage * WrapSingleMessage (const i2p::data::RoutingDestination& destination, I2NPMessage * msg);
I2NPMessage * WrapMessage (const i2p::data::RoutingDestination& destination,
Expand All @@ -112,7 +110,8 @@ namespace garlic
private:

void Run ();
void ProcessGarlicMessage (I2NPMessage * msg);
void HandleGarlicMessage (I2NPMessage * msg);
void HandleDeliveryStatusMessage (I2NPMessage * msg);
void HandleAESBlock (uint8_t * buf, size_t len, SessionDecryption * decryption, i2p::tunnel::InboundTunnel * from);
void HandleGarlicPayload (uint8_t * buf, size_t len, i2p::tunnel::InboundTunnel * from);

Expand Down
7 changes: 2 additions & 5 deletions I2NPProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ namespace i2p
break;
case eI2NPGarlic:
LogPrint ("Garlic");
i2p::garlic::routing.HandleGarlicMessage (msg);
i2p::garlic::routing.PostI2NPMsg (msg);
break;
case eI2NPDatabaseStore:
case eI2NPDatabaseSearchReply:
Expand All @@ -548,10 +548,7 @@ namespace i2p
if (msg->from && msg->from->GetTunnelPool ())
msg->from->GetTunnelPool ()->ProcessDeliveryStatus (msg);
else
{
i2p::garlic::routing.HandleDeliveryStatusMessage (msg->GetPayload (), msg->GetLength ());
DeleteI2NPMessage (msg);
}
i2p::garlic::routing.PostI2NPMsg (msg);
break;
default:
HandleI2NPMessage (msg->GetBuffer (), msg->GetLength ());
Expand Down
4 changes: 2 additions & 2 deletions TunnelPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,10 @@ namespace tunnel
it->second.second->SetState (eTunnelStateEstablished);
LogPrint ("Tunnel test ", it->first, " successive. ", i2p::util::GetMillisecondsSinceEpoch () - be64toh (deliveryStatus->timestamp), " milliseconds");
m_Tests.erase (it);
DeleteI2NPMessage (msg);
}
else
i2p::garlic::routing.HandleDeliveryStatusMessage (msg->GetPayload (), msg->GetLength ()); // TODO:
DeleteI2NPMessage (msg);
i2p::garlic::routing.PostI2NPMsg (msg);
}

void TunnelPool::CreateInboundTunnel ()
Expand Down

0 comments on commit eff3bb6

Please sign in to comment.