Browse Source

handle garlic's DeliveryStatus in the garlic thread

pull/93/head
orignal 10 years ago
parent
commit
eff3bb6ab1
  1. 37
      Garlic.cpp
  2. 7
      Garlic.h
  3. 7
      I2NPProtocol.cpp
  4. 4
      TunnelPool.cpp

37
Garlic.cpp

@ -325,13 +325,8 @@ namespace garlic
m_CreatedSessions[session->GetFirstMsgID ()] = session; m_CreatedSessions[session->GetFirstMsgID ()] = session;
return ret; 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 (); uint8_t * buf = msg->GetPayload ();
uint32_t length = be32toh (*(uint32_t *)buf); uint32_t length = be32toh (*(uint32_t *)buf);
@ -480,16 +475,18 @@ namespace garlic
} }
} }
void GarlicRouting::HandleDeliveryStatusMessage (uint8_t * buf, size_t len) void GarlicRouting::HandleDeliveryStatusMessage (I2NPMessage * msg)
{ {
I2NPDeliveryStatusMsg * msg = (I2NPDeliveryStatusMsg *)buf; I2NPDeliveryStatusMsg * deliveryStatus = (I2NPDeliveryStatusMsg *)msg->GetPayload ();
auto it = m_CreatedSessions.find (be32toh (msg->msgID)); uint32_t msgID = be32toh (deliveryStatus->msgID);
auto it = m_CreatedSessions.find (msgID);
if (it != m_CreatedSessions.end ()) if (it != m_CreatedSessions.end ())
{ {
it->second->SetAcknowledged (true); it->second->SetAcknowledged (true);
m_CreatedSessions.erase (it); m_CreatedSessions.erase (it);
LogPrint ("Garlic message ", be32toh (msg->msgID), " acknowledged"); LogPrint ("Garlic message ", msgID, " acknowledged");
} }
DeleteI2NPMessage (msg);
} }
void GarlicRouting::Start () void GarlicRouting::Start ()
@ -510,6 +507,11 @@ namespace garlic
} }
} }
void GarlicRouting::PostI2NPMsg (I2NPMessage * msg)
{
if (msg) m_Queue.Put (msg);
}
void GarlicRouting::Run () void GarlicRouting::Run ()
{ {
while (m_IsRunning) while (m_IsRunning)
@ -518,7 +520,20 @@ namespace garlic
{ {
I2NPMessage * msg = m_Queue.GetNext (); I2NPMessage * msg = m_Queue.GetNext ();
if (msg) 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) catch (std::exception& ex)
{ {

7
Garlic.h

@ -100,10 +100,8 @@ namespace garlic
void Start (); void Start ();
void Stop (); void Stop ();
void PostI2NPMsg (I2NPMessage * msg);
void AddSessionKey (const uint8_t * key, const uint8_t * tag); // one tag 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 * WrapSingleMessage (const i2p::data::RoutingDestination& destination, I2NPMessage * msg);
I2NPMessage * WrapMessage (const i2p::data::RoutingDestination& destination, I2NPMessage * WrapMessage (const i2p::data::RoutingDestination& destination,
@ -112,7 +110,8 @@ namespace garlic
private: private:
void Run (); 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 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); void HandleGarlicPayload (uint8_t * buf, size_t len, i2p::tunnel::InboundTunnel * from);

7
I2NPProtocol.cpp

@ -535,7 +535,7 @@ namespace i2p
break; break;
case eI2NPGarlic: case eI2NPGarlic:
LogPrint ("Garlic"); LogPrint ("Garlic");
i2p::garlic::routing.HandleGarlicMessage (msg); i2p::garlic::routing.PostI2NPMsg (msg);
break; break;
case eI2NPDatabaseStore: case eI2NPDatabaseStore:
case eI2NPDatabaseSearchReply: case eI2NPDatabaseSearchReply:
@ -548,10 +548,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
{ i2p::garlic::routing.PostI2NPMsg (msg);
i2p::garlic::routing.HandleDeliveryStatusMessage (msg->GetPayload (), msg->GetLength ());
DeleteI2NPMessage (msg);
}
break; break;
default: default:
HandleI2NPMessage (msg->GetBuffer (), msg->GetLength ()); HandleI2NPMessage (msg->GetBuffer (), msg->GetLength ());

4
TunnelPool.cpp

@ -169,10 +169,10 @@ namespace tunnel
it->second.second->SetState (eTunnelStateEstablished); it->second.second->SetState (eTunnelStateEstablished);
LogPrint ("Tunnel test ", it->first, " successive. ", i2p::util::GetMillisecondsSinceEpoch () - be64toh (deliveryStatus->timestamp), " milliseconds"); LogPrint ("Tunnel test ", it->first, " successive. ", i2p::util::GetMillisecondsSinceEpoch () - be64toh (deliveryStatus->timestamp), " milliseconds");
m_Tests.erase (it); m_Tests.erase (it);
DeleteI2NPMessage (msg);
} }
else else
i2p::garlic::routing.HandleDeliveryStatusMessage (msg->GetPayload (), msg->GetLength ()); // TODO: i2p::garlic::routing.PostI2NPMsg (msg);
DeleteI2NPMessage (msg);
} }
void TunnelPool::CreateInboundTunnel () void TunnelPool::CreateInboundTunnel ()

Loading…
Cancel
Save