|
|
|
@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
|
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2013-2023, The PurpleI2P Project |
|
|
|
|
* Copyright (c) 2013-2024, The PurpleI2P Project |
|
|
|
|
* |
|
|
|
|
* This file is part of Purple i2pd project and licensed under BSD3 |
|
|
|
|
* |
|
|
|
@ -21,10 +21,7 @@ namespace i2p
@@ -21,10 +21,7 @@ namespace i2p
|
|
|
|
|
{ |
|
|
|
|
namespace tunnel |
|
|
|
|
{ |
|
|
|
|
TunnelEndpoint::~TunnelEndpoint () |
|
|
|
|
{ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TunnelEndpoint::HandleDecryptedTunnelDataMsg (std::shared_ptr<I2NPMessage> msg) |
|
|
|
|
{ |
|
|
|
|
m_NumReceivedBytes += TUNNEL_DATA_MSG_SIZE; |
|
|
|
@ -331,13 +328,13 @@ namespace tunnel
@@ -331,13 +328,13 @@ namespace tunnel
|
|
|
|
|
break; |
|
|
|
|
case eDeliveryTypeTunnel: |
|
|
|
|
if (!m_IsInbound) // outbound transit tunnel
|
|
|
|
|
i2p::transport::transports.SendMessage (msg.hash, i2p::CreateTunnelGatewayMsg (msg.tunnelID, msg.data)); |
|
|
|
|
SendMessageTo (msg.hash, i2p::CreateTunnelGatewayMsg (msg.tunnelID, msg.data)); |
|
|
|
|
else |
|
|
|
|
LogPrint (eLogError, "TunnelMessage: Delivery type 'tunnel' arrived from an inbound tunnel, dropped"); |
|
|
|
|
break; |
|
|
|
|
case eDeliveryTypeRouter: |
|
|
|
|
if (!m_IsInbound) // outbound transit tunnel
|
|
|
|
|
i2p::transport::transports.SendMessage (msg.hash, msg.data); |
|
|
|
|
i2p::transport::transports.SendMessage (msg.hash, msg.data); // send right away, because most likely it's single message
|
|
|
|
|
else // we shouldn't send this message. possible leakage
|
|
|
|
|
LogPrint (eLogError, "TunnelMessage: Delivery type 'router' arrived from an inbound tunnel, dropped"); |
|
|
|
|
break; |
|
|
|
@ -366,5 +363,36 @@ namespace tunnel
@@ -366,5 +363,36 @@ namespace tunnel
|
|
|
|
|
++it; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void TunnelEndpoint::SendMessageTo (const i2p::data::IdentHash& to, std::shared_ptr<i2p::I2NPMessage> msg) |
|
|
|
|
{ |
|
|
|
|
if (msg) |
|
|
|
|
{ |
|
|
|
|
if (!m_Sender && m_I2NPMsgs.empty ()) // first message
|
|
|
|
|
m_CurrentHash = to; |
|
|
|
|
else if (m_CurrentHash != to) // new target router
|
|
|
|
|
{ |
|
|
|
|
FlushI2NPMsgs (); // flush message to previous
|
|
|
|
|
if (m_Sender) m_Sender->Reset (); // reset sender
|
|
|
|
|
m_CurrentHash = to; // set new target router
|
|
|
|
|
} // otherwise add msg to the list for current target router
|
|
|
|
|
m_I2NPMsgs.push_back (msg); |
|
|
|
|
i2p::transport::transports.SendMessage (to, msg); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void TunnelEndpoint::FlushI2NPMsgs () |
|
|
|
|
{ |
|
|
|
|
if (!m_I2NPMsgs.empty ()) |
|
|
|
|
{ |
|
|
|
|
if (!m_Sender) m_Sender = std::make_unique<TunnelTransportSender>(); |
|
|
|
|
m_Sender->SendMessagesTo (m_CurrentHash, m_I2NPMsgs); // send and clear
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const i2p::data::IdentHash * TunnelEndpoint::GetCurrentHash () const |
|
|
|
|
{ |
|
|
|
|
return (m_Sender || !m_I2NPMsgs.empty ()) ? &m_CurrentHash : nullptr; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|