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

12
Garlic.h

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

2
TunnelPool.cpp

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

Loading…
Cancel
Save