mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 04:04:16 +00:00
assign GarlicRoutingSession to stream
This commit is contained in:
parent
b6a3f64ee9
commit
17725acda2
48
Garlic.cpp
48
Garlic.cpp
@ -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");
|
||||||
@ -292,6 +292,22 @@ namespace garlic
|
|||||||
decryption->SetTagCount (1);
|
decryption->SetTagCount (1);
|
||||||
m_SessionTags[SessionTag(tag)] = decryption;
|
m_SessionTags[SessionTag(tag)] = decryption;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GarlicRoutingSession * GarlicRouting::GetRoutingSession (
|
||||||
|
const i2p::data::RoutingDestination& destination, int numTags)
|
||||||
|
{
|
||||||
|
auto it = m_Sessions.find (destination.GetIdentHash ());
|
||||||
|
GarlicRoutingSession * session = nullptr;
|
||||||
|
if (it != m_Sessions.end ())
|
||||||
|
session = it->second;
|
||||||
|
if (!session)
|
||||||
|
{
|
||||||
|
session = new GarlicRoutingSession (&destination, numTags);
|
||||||
|
std::unique_lock<std::mutex> l(m_SessionsMutex);
|
||||||
|
m_Sessions[destination.GetIdentHash ()] = session;
|
||||||
|
}
|
||||||
|
return session;
|
||||||
|
}
|
||||||
|
|
||||||
I2NPMessage * GarlicRouting::WrapSingleMessage (const i2p::data::RoutingDestination& destination, I2NPMessage * msg)
|
I2NPMessage * GarlicRouting::WrapSingleMessage (const i2p::data::RoutingDestination& destination, I2NPMessage * msg)
|
||||||
{
|
{
|
||||||
@ -301,25 +317,15 @@ namespace garlic
|
|||||||
I2NPMessage * GarlicRouting::WrapMessage (const i2p::data::RoutingDestination& destination,
|
I2NPMessage * GarlicRouting::WrapMessage (const i2p::data::RoutingDestination& destination,
|
||||||
I2NPMessage * msg, const i2p::data::LeaseSet * leaseSet)
|
I2NPMessage * msg, const i2p::data::LeaseSet * leaseSet)
|
||||||
{
|
{
|
||||||
auto it = m_Sessions.find (destination.GetIdentHash ());
|
auto session = GetRoutingSession (destination, leaseSet ? 32 : 0); // don't use tag if no LeaseSet
|
||||||
GarlicRoutingSession * session = nullptr;
|
return session->WrapSingleMessage (msg, leaseSet);
|
||||||
if (it != m_Sessions.end ())
|
|
||||||
session = it->second;
|
|
||||||
if (!session)
|
|
||||||
{
|
|
||||||
session = new GarlicRoutingSession (&destination, 32);
|
|
||||||
std::unique_lock<std::mutex> l(m_SessionsMutex);
|
|
||||||
m_Sessions[destination.GetIdentHash ()] = session;
|
|
||||||
}
|
|
||||||
|
|
||||||
I2NPMessage * ret = session->WrapSingleMessage (msg, leaseSet);
|
|
||||||
if (!session->GetNextTag ()) // tags have beed recreated
|
|
||||||
{
|
|
||||||
std::unique_lock<std::mutex> l(m_SessionsMutex);
|
|
||||||
m_CreatedSessions[session->GetFirstMsgID ()] = session;
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
{
|
{
|
||||||
|
5
Garlic.h
5
Garlic.h
@ -48,7 +48,6 @@ namespace garlic
|
|||||||
~GarlicRoutingSession ();
|
~GarlicRoutingSession ();
|
||||||
I2NPMessage * WrapSingleMessage (I2NPMessage * msg, const i2p::data::LeaseSet * leaseSet);
|
I2NPMessage * WrapSingleMessage (I2NPMessage * msg, const i2p::data::LeaseSet * leaseSet);
|
||||||
int GetNextTag () const { return m_NextTag; };
|
int GetNextTag () const { return m_NextTag; };
|
||||||
uint32_t GetFirstMsgID () const { return m_FirstMsgID; };
|
|
||||||
|
|
||||||
bool IsAcknowledged () const { return m_IsAcknowledged; };
|
bool IsAcknowledged () const { return m_IsAcknowledged; };
|
||||||
void SetAcknowledged (bool acknowledged) { m_IsAcknowledged = acknowledged; };
|
void SetAcknowledged (bool acknowledged) { m_IsAcknowledged = acknowledged; };
|
||||||
@ -66,7 +65,6 @@ namespace garlic
|
|||||||
|
|
||||||
const i2p::data::RoutingDestination * m_Destination;
|
const i2p::data::RoutingDestination * m_Destination;
|
||||||
uint8_t m_SessionKey[32];
|
uint8_t m_SessionKey[32];
|
||||||
uint32_t m_FirstMsgID; // first message ID
|
|
||||||
bool m_IsAcknowledged;
|
bool m_IsAcknowledged;
|
||||||
int m_NumTags, m_NextTag;
|
int m_NumTags, m_NextTag;
|
||||||
SessionTag * m_SessionTags; // m_NumTags*32 bytes
|
SessionTag * m_SessionTags; // m_NumTags*32 bytes
|
||||||
@ -104,10 +102,13 @@ namespace garlic
|
|||||||
void PostI2NPMsg (I2NPMessage * msg);
|
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
|
||||||
|
|
||||||
|
GarlicRoutingSession * GetRoutingSession (const i2p::data::RoutingDestination& destination, int numTags);
|
||||||
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,
|
||||||
I2NPMessage * msg, const i2p::data::LeaseSet * leaseSet = nullptr);
|
I2NPMessage * msg, const i2p::data::LeaseSet * leaseSet = nullptr);
|
||||||
|
|
||||||
|
void DeliveryStatusSent (GarlicRoutingSession * session, uint32_t msgID);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void Run ();
|
void Run ();
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
#include "Tunnel.h"
|
#include "Tunnel.h"
|
||||||
#include "Timestamp.h"
|
#include "Timestamp.h"
|
||||||
#include "CryptoConst.h"
|
#include "CryptoConst.h"
|
||||||
#include "Garlic.h"
|
|
||||||
#include "NetDb.h"
|
#include "NetDb.h"
|
||||||
#include "Streaming.h"
|
#include "Streaming.h"
|
||||||
|
|
||||||
@ -20,8 +19,8 @@ namespace stream
|
|||||||
Stream::Stream (boost::asio::io_service& service, StreamingDestination * local,
|
Stream::Stream (boost::asio::io_service& service, StreamingDestination * local,
|
||||||
const i2p::data::LeaseSet& remote): m_Service (service), m_SendStreamID (0),
|
const i2p::data::LeaseSet& remote): m_Service (service), m_SendStreamID (0),
|
||||||
m_SequenceNumber (0), m_LastReceivedSequenceNumber (-1), m_IsOpen (false),
|
m_SequenceNumber (0), m_LastReceivedSequenceNumber (-1), m_IsOpen (false),
|
||||||
m_LeaseSetUpdated (true), m_LocalDestination (local),
|
m_LeaseSetUpdated (true), m_LocalDestination (local), m_RemoteLeaseSet (&remote),
|
||||||
m_RemoteLeaseSet (&remote), m_CurrentOutboundTunnel (nullptr),
|
m_RoutingSession (nullptr), m_CurrentOutboundTunnel (nullptr),
|
||||||
m_ReceiveTimer (m_Service), m_ResendTimer (m_Service)
|
m_ReceiveTimer (m_Service), m_ResendTimer (m_Service)
|
||||||
{
|
{
|
||||||
m_RecvStreamID = i2p::context.GetRandomNumberGenerator ().GenerateWord32 ();
|
m_RecvStreamID = i2p::context.GetRandomNumberGenerator ().GenerateWord32 ();
|
||||||
@ -31,7 +30,7 @@ namespace stream
|
|||||||
Stream::Stream (boost::asio::io_service& service, StreamingDestination * local):
|
Stream::Stream (boost::asio::io_service& service, StreamingDestination * local):
|
||||||
m_Service (service), m_SendStreamID (0), m_SequenceNumber (0), m_LastReceivedSequenceNumber (-1),
|
m_Service (service), m_SendStreamID (0), m_SequenceNumber (0), m_LastReceivedSequenceNumber (-1),
|
||||||
m_IsOpen (false), m_LeaseSetUpdated (true), m_LocalDestination (local),
|
m_IsOpen (false), m_LeaseSetUpdated (true), m_LocalDestination (local),
|
||||||
m_RemoteLeaseSet (nullptr), m_CurrentOutboundTunnel (nullptr),
|
m_RemoteLeaseSet (nullptr), m_RoutingSession (nullptr), m_CurrentOutboundTunnel (nullptr),
|
||||||
m_ReceiveTimer (m_Service), m_ResendTimer (m_Service)
|
m_ReceiveTimer (m_Service), m_ResendTimer (m_Service)
|
||||||
{
|
{
|
||||||
m_RecvStreamID = i2p::context.GetRandomNumberGenerator ().GenerateWord32 ();
|
m_RecvStreamID = i2p::context.GetRandomNumberGenerator ().GenerateWord32 ();
|
||||||
@ -427,8 +426,9 @@ namespace stream
|
|||||||
std::vector<i2p::tunnel::TunnelMessageBlock> msgs;
|
std::vector<i2p::tunnel::TunnelMessageBlock> msgs;
|
||||||
for (auto it: packets)
|
for (auto it: packets)
|
||||||
{
|
{
|
||||||
auto msg = i2p::garlic::routing.WrapMessage (*m_RemoteLeaseSet,
|
auto msg = m_RoutingSession->WrapSingleMessage (
|
||||||
CreateDataMessage (this, it->GetBuffer (), it->GetLength ()), leaseSet);
|
CreateDataMessage (this, it->GetBuffer (), it->GetLength ()),
|
||||||
|
leaseSet);
|
||||||
msgs.push_back (i2p::tunnel::TunnelMessageBlock
|
msgs.push_back (i2p::tunnel::TunnelMessageBlock
|
||||||
{
|
{
|
||||||
i2p::tunnel::eDeliveryTypeTunnel,
|
i2p::tunnel::eDeliveryTypeTunnel,
|
||||||
@ -486,11 +486,13 @@ namespace stream
|
|||||||
if (!m_RemoteLeaseSet)
|
if (!m_RemoteLeaseSet)
|
||||||
{
|
{
|
||||||
m_RemoteLeaseSet = i2p::data::netdb.FindLeaseSet (m_RemoteIdentity.GetIdentHash ());
|
m_RemoteLeaseSet = i2p::data::netdb.FindLeaseSet (m_RemoteIdentity.GetIdentHash ());
|
||||||
if (!m_RemoteLeaseSet)
|
if (!m_RemoteLeaseSet)
|
||||||
LogPrint ("LeaseSet ", m_RemoteIdentity.GetIdentHash ().ToBase64 (), " not found");
|
LogPrint ("LeaseSet ", m_RemoteIdentity.GetIdentHash ().ToBase64 (), " not found");
|
||||||
}
|
}
|
||||||
if (m_RemoteLeaseSet)
|
if (m_RemoteLeaseSet)
|
||||||
{
|
{
|
||||||
|
if (!m_RoutingSession)
|
||||||
|
m_RoutingSession = i2p::garlic::routing.GetRoutingSession (*m_RemoteLeaseSet, 32);
|
||||||
auto leases = m_RemoteLeaseSet->GetNonExpiredLeases ();
|
auto leases = m_RemoteLeaseSet->GetNonExpiredLeases ();
|
||||||
if (!leases.empty ())
|
if (!leases.empty ())
|
||||||
{
|
{
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#include "LeaseSet.h"
|
#include "LeaseSet.h"
|
||||||
#include "I2NPProtocol.h"
|
#include "I2NPProtocol.h"
|
||||||
#include "TunnelPool.h"
|
#include "TunnelPool.h"
|
||||||
|
#include "Garlic.h"
|
||||||
|
|
||||||
namespace i2p
|
namespace i2p
|
||||||
{
|
{
|
||||||
@ -127,6 +128,7 @@ namespace stream
|
|||||||
StreamingDestination * m_LocalDestination;
|
StreamingDestination * m_LocalDestination;
|
||||||
i2p::data::IdentityEx m_RemoteIdentity;
|
i2p::data::IdentityEx m_RemoteIdentity;
|
||||||
const i2p::data::LeaseSet * m_RemoteLeaseSet;
|
const i2p::data::LeaseSet * m_RemoteLeaseSet;
|
||||||
|
i2p::garlic::GarlicRoutingSession * m_RoutingSession;
|
||||||
i2p::data::Lease m_CurrentRemoteLease;
|
i2p::data::Lease m_CurrentRemoteLease;
|
||||||
i2p::tunnel::OutboundTunnel * m_CurrentOutboundTunnel;
|
i2p::tunnel::OutboundTunnel * m_CurrentOutboundTunnel;
|
||||||
std::queue<Packet *> m_ReceiveQueue;
|
std::queue<Packet *> m_ReceiveQueue;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user