Skip to content

Commit

Permalink
DeliveryStatus per garlic destination
Browse files Browse the repository at this point in the history
  • Loading branch information
orignal committed Oct 8, 2014
1 parent fccadb7 commit 070a7fe
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 41 deletions.
60 changes: 26 additions & 34 deletions Garlic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand All @@ -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 ()
Expand Down Expand Up @@ -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)
{
Expand Down
12 changes: 6 additions & 6 deletions Garlic.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion TunnelPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 070a7fe

Please sign in to comment.