Browse Source

DeliveryStatus per garlic destination

pull/102/head
orignal 10 years ago
parent
commit
070a7fea2c
  1. 60
      Garlic.cpp
  2. 12
      Garlic.h
  3. 2
      TunnelPool.cpp

60
Garlic.cpp

@ -175,7 +175,7 @@ namespace garlic
if (size > 0) // successive? if (size > 0) // successive?
{ {
(*numCloves)++; (*numCloves)++;
routing.DeliveryStatusSent (this, msgID); m_Owner->DeliveryStatusSent (this, msgID);
} }
else else
LogPrint ("DeliveryStatus clove was not created"); LogPrint ("DeliveryStatus clove was not created");
@ -450,27 +450,13 @@ namespace garlic
return session; return session;
} }
GarlicRouting routing; void GarlicDestination::DeliveryStatusSent (GarlicRoutingSession * session, uint32_t msgID)
void GarlicRouting::DeliveryStatusSent (GarlicRoutingSession * session, uint32_t msgID)
{ {
std::unique_lock<std::mutex> l(m_CreatedSessionsMutex); std::unique_lock<std::mutex> l(m_CreatedSessionsMutex);
m_CreatedSessions[msgID] = session; m_CreatedSessions[msgID] = session;
} }
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::HandleDeliveryStatusMessage (I2NPMessage * msg) void GarlicDestination::HandleDeliveryStatusMessage (I2NPMessage * msg)
{ {
I2NPDeliveryStatusMsg * deliveryStatus = (I2NPDeliveryStatusMsg *)msg->GetPayload (); I2NPDeliveryStatusMsg * deliveryStatus = (I2NPDeliveryStatusMsg *)msg->GetPayload ();
uint32_t msgID = be32toh (deliveryStatus->msgID); uint32_t msgID = be32toh (deliveryStatus->msgID);
@ -483,8 +469,22 @@ namespace garlic
m_CreatedSessions.erase (it); m_CreatedSessions.erase (it);
LogPrint ("Garlic message ", msgID, " acknowledged"); LogPrint ("Garlic message ", msgID, " acknowledged");
} }
} }
DeleteI2NPMessage (msg); 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 () void GarlicRouting::Start ()
@ -517,21 +517,13 @@ namespace garlic
try try
{ {
I2NPMessage * msg = m_Queue.GetNext (); I2NPMessage * msg = m_Queue.GetNext ();
if (msg) if (msg->GetHeader ()->typeID == eI2NPGarlic)
{ HandleGarlicMessage (msg);
switch (msg->GetHeader ()->typeID) else
{ {
case eI2NPGarlic: LogPrint ("Garlic: unexpected message type ", msg->GetHeader ()->typeID);
HandleGarlicMessage (msg); i2p::HandleI2NPMessage (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)
{ {

12
Garlic.h

@ -91,6 +91,9 @@ namespace garlic
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 HandleGarlicMessage (I2NPMessage * msg);
void DeliveryStatusSent (GarlicRoutingSession * session, uint32_t msgID);
void HandleDeliveryStatusMessage (I2NPMessage * msg);
virtual const i2p::data::LeaseSet * GetLeaseSet () = 0; // TODO virtual const i2p::data::LeaseSet * GetLeaseSet () = 0; // TODO
private: private:
@ -106,6 +109,9 @@ namespace garlic
std::map<i2p::data::IdentHash, GarlicRoutingSession *> m_Sessions; std::map<i2p::data::IdentHash, GarlicRoutingSession *> m_Sessions;
// incoming // incoming
std::map<SessionTag, std::shared_ptr<i2p::crypto::CBCDecryption>> m_Tags; std::map<SessionTag, std::shared_ptr<i2p::crypto::CBCDecryption>> m_Tags;
// DeliveryStatus
std::mutex m_CreatedSessionsMutex;
std::map<uint32_t, GarlicRoutingSession *> m_CreatedSessions; // msgID -> session
}; };
class GarlicRouting class GarlicRouting
@ -119,22 +125,16 @@ namespace garlic
void Stop (); void Stop ();
void PostI2NPMsg (I2NPMessage * msg); void PostI2NPMsg (I2NPMessage * msg);
void DeliveryStatusSent (GarlicRoutingSession * session, uint32_t msgID);
private: private:
void Run (); void Run ();
void HandleGarlicMessage (I2NPMessage * msg); void HandleGarlicMessage (I2NPMessage * msg);
void HandleDeliveryStatusMessage (I2NPMessage * msg);
private: private:
bool m_IsRunning; bool m_IsRunning;
std::thread * m_Thread; std::thread * m_Thread;
i2p::util::Queue<I2NPMessage> m_Queue; i2p::util::Queue<I2NPMessage> m_Queue;
std::mutex m_CreatedSessionsMutex;
std::map<uint32_t, GarlicRoutingSession *> m_CreatedSessions; // msgID -> session
}; };
extern GarlicRouting routing; extern GarlicRouting routing;

2
TunnelPool.cpp

@ -221,7 +221,7 @@ namespace tunnel
DeleteI2NPMessage (msg); DeleteI2NPMessage (msg);
} }
else else
i2p::garlic::routing.PostI2NPMsg (msg); m_LocalDestination.HandleDeliveryStatusMessage (msg);
} }
const i2p::data::RouterInfo * TunnelPool::SelectNextHop (const i2p::data::RouterInfo * prevHop) const const i2p::data::RouterInfo * TunnelPool::SelectNextHop (const i2p::data::RouterInfo * prevHop) const

Loading…
Cancel
Save