|
|
@ -15,7 +15,7 @@ namespace i2p |
|
|
|
namespace garlic |
|
|
|
namespace garlic |
|
|
|
{ |
|
|
|
{ |
|
|
|
GarlicRoutingSession::GarlicRoutingSession (const i2p::data::RoutingDestination * destination, int numTags): |
|
|
|
GarlicRoutingSession::GarlicRoutingSession (const i2p::data::RoutingDestination * destination, int numTags): |
|
|
|
m_Destination (destination), m_FirstMsgID (0), m_IsAcknowledged (false), m_NumTags (numTags), |
|
|
|
m_Destination (destination), m_IsAcknowledged (false), m_NumTags (numTags), |
|
|
|
m_NextTag (-1), m_SessionTags (0), m_TagsCreationTime (0), m_LocalLeaseSet (nullptr) |
|
|
|
m_NextTag (-1), m_SessionTags (0), m_TagsCreationTime (0), m_LocalLeaseSet (nullptr) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// create new session tags and session key
|
|
|
|
// create new session tags and session key
|
|
|
@ -31,7 +31,7 @@ namespace garlic |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
GarlicRoutingSession::GarlicRoutingSession (const uint8_t * sessionKey, const SessionTag& sessionTag): |
|
|
|
GarlicRoutingSession::GarlicRoutingSession (const uint8_t * sessionKey, const SessionTag& sessionTag): |
|
|
|
m_Destination (nullptr), m_FirstMsgID (0), m_IsAcknowledged (true), m_NumTags (1), m_NextTag (0), |
|
|
|
m_Destination (nullptr), m_IsAcknowledged (true), m_NumTags (1), m_NextTag (0), |
|
|
|
m_LocalLeaseSet (nullptr) |
|
|
|
m_LocalLeaseSet (nullptr) |
|
|
|
{ |
|
|
|
{ |
|
|
|
memcpy (m_SessionKey, sessionKey, 32); |
|
|
|
memcpy (m_SessionKey, sessionKey, 32); |
|
|
@ -175,7 +175,7 @@ namespace garlic |
|
|
|
if (size > 0) // successive?
|
|
|
|
if (size > 0) // successive?
|
|
|
|
{ |
|
|
|
{ |
|
|
|
(*numCloves)++; |
|
|
|
(*numCloves)++; |
|
|
|
m_FirstMsgID = msgID; |
|
|
|
routing.DeliveryStatusSent (this, msgID); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
LogPrint ("DeliveryStatus clove was not created"); |
|
|
|
LogPrint ("DeliveryStatus clove was not created"); |
|
|
@ -293,13 +293,8 @@ namespace garlic |
|
|
|
m_SessionTags[SessionTag(tag)] = decryption; |
|
|
|
m_SessionTags[SessionTag(tag)] = decryption; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
I2NPMessage * GarlicRouting::WrapSingleMessage (const i2p::data::RoutingDestination& destination, I2NPMessage * msg) |
|
|
|
GarlicRoutingSession * GarlicRouting::GetRoutingSession ( |
|
|
|
{ |
|
|
|
const i2p::data::RoutingDestination& destination, int numTags) |
|
|
|
return WrapMessage (destination, msg, nullptr); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
I2NPMessage * GarlicRouting::WrapMessage (const i2p::data::RoutingDestination& destination, |
|
|
|
|
|
|
|
I2NPMessage * msg, const i2p::data::LeaseSet * leaseSet) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
auto it = m_Sessions.find (destination.GetIdentHash ()); |
|
|
|
auto it = m_Sessions.find (destination.GetIdentHash ()); |
|
|
|
GarlicRoutingSession * session = nullptr; |
|
|
|
GarlicRoutingSession * session = nullptr; |
|
|
@ -307,18 +302,29 @@ namespace garlic |
|
|
|
session = it->second; |
|
|
|
session = it->second; |
|
|
|
if (!session) |
|
|
|
if (!session) |
|
|
|
{ |
|
|
|
{ |
|
|
|
session = new GarlicRoutingSession (&destination, 32); |
|
|
|
session = new GarlicRoutingSession (&destination, numTags); |
|
|
|
std::unique_lock<std::mutex> l(m_SessionsMutex); |
|
|
|
std::unique_lock<std::mutex> l(m_SessionsMutex); |
|
|
|
m_Sessions[destination.GetIdentHash ()] = session; |
|
|
|
m_Sessions[destination.GetIdentHash ()] = session; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return session; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
I2NPMessage * ret = session->WrapSingleMessage (msg, leaseSet); |
|
|
|
I2NPMessage * GarlicRouting::WrapSingleMessage (const i2p::data::RoutingDestination& destination, I2NPMessage * msg) |
|
|
|
if (!session->GetNextTag ()) // tags have beed recreated
|
|
|
|
{ |
|
|
|
{ |
|
|
|
return WrapMessage (destination, msg, nullptr); |
|
|
|
std::unique_lock<std::mutex> l(m_SessionsMutex); |
|
|
|
} |
|
|
|
m_CreatedSessions[session->GetFirstMsgID ()] = session; |
|
|
|
|
|
|
|
} |
|
|
|
I2NPMessage * GarlicRouting::WrapMessage (const i2p::data::RoutingDestination& destination, |
|
|
|
return ret; |
|
|
|
I2NPMessage * msg, const i2p::data::LeaseSet * leaseSet) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
auto session = GetRoutingSession (destination, leaseSet ? 32 : 0); // don't use tag if no LeaseSet
|
|
|
|
|
|
|
|
return session->WrapSingleMessage (msg, leaseSet); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GarlicRouting::DeliveryStatusSent (GarlicRoutingSession * session, uint32_t msgID) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
std::unique_lock<std::mutex> l(m_SessionsMutex); |
|
|
|
|
|
|
|
m_CreatedSessions[msgID] = session; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void GarlicRouting::HandleGarlicMessage (I2NPMessage * msg) |
|
|
|
void GarlicRouting::HandleGarlicMessage (I2NPMessage * msg) |
|
|
|