mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-11 17:37:53 +00:00
create different I2NP tunnel messages for endpoint and non-endpoint
This commit is contained in:
parent
12d6f03dc9
commit
25f63ac22a
@ -36,11 +36,21 @@ namespace i2p
|
|||||||
return std::make_shared<I2NPMessageBuffer<I2NP_MAX_SHORT_MESSAGE_SIZE> >();
|
return std::make_shared<I2NPMessageBuffer<I2NP_MAX_SHORT_MESSAGE_SIZE> >();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<I2NPMessage> NewI2NPTunnelMessage ()
|
std::shared_ptr<I2NPMessage> NewI2NPTunnelMessage (bool endpoint)
|
||||||
{
|
{
|
||||||
// should fit two tunnel message, enough for one garlic encrypted streaming packet
|
I2NPMessage * msg = nullptr;
|
||||||
auto msg = new I2NPMessageBuffer<2*i2p::tunnel::TUNNEL_DATA_MSG_SIZE + I2NP_HEADER_SIZE + 34>(); // reserved for alignment and NTCP 16 + 6 + 12
|
if (endpoint)
|
||||||
msg->Align (12);
|
{
|
||||||
|
// should fit two tunnel message + tunnel gateway header, enough for one garlic encrypted streaming packet
|
||||||
|
msg = new I2NPMessageBuffer<2*i2p::tunnel::TUNNEL_DATA_MSG_SIZE + I2NP_HEADER_SIZE + TUNNEL_GATEWAY_HEADER_SIZE + 28>(); // reserved for alignment and NTCP 16 + 6 + 6
|
||||||
|
msg->Align (6);
|
||||||
|
msg->offset += TUNNEL_GATEWAY_HEADER_SIZE; // reserve room for TunnelGateway header
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
msg = new I2NPMessageBuffer<i2p::tunnel::TUNNEL_DATA_MSG_SIZE + I2NP_HEADER_SIZE + 34>(); // reserved for alignment and NTCP 16 + 6 + 12
|
||||||
|
msg->Align (12);
|
||||||
|
}
|
||||||
return std::shared_ptr<I2NPMessage>(msg);
|
return std::shared_ptr<I2NPMessage>(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -692,7 +702,7 @@ namespace i2p
|
|||||||
|
|
||||||
std::shared_ptr<I2NPMessage> CreateTunnelDataMsg (const uint8_t * buf)
|
std::shared_ptr<I2NPMessage> CreateTunnelDataMsg (const uint8_t * buf)
|
||||||
{
|
{
|
||||||
auto msg = NewI2NPTunnelMessage ();
|
auto msg = NewI2NPTunnelMessage (false);
|
||||||
msg->Concat (buf, i2p::tunnel::TUNNEL_DATA_MSG_SIZE);
|
msg->Concat (buf, i2p::tunnel::TUNNEL_DATA_MSG_SIZE);
|
||||||
msg->FillI2NPMessageHeader (eI2NPTunnelData);
|
msg->FillI2NPMessageHeader (eI2NPTunnelData);
|
||||||
return msg;
|
return msg;
|
||||||
@ -700,7 +710,7 @@ namespace i2p
|
|||||||
|
|
||||||
std::shared_ptr<I2NPMessage> CreateTunnelDataMsg (uint32_t tunnelID, const uint8_t * payload)
|
std::shared_ptr<I2NPMessage> CreateTunnelDataMsg (uint32_t tunnelID, const uint8_t * payload)
|
||||||
{
|
{
|
||||||
auto msg = NewI2NPTunnelMessage ();
|
auto msg = NewI2NPTunnelMessage (false);
|
||||||
htobe32buf (msg->GetPayload (), tunnelID);
|
htobe32buf (msg->GetPayload (), tunnelID);
|
||||||
msg->len += 4; // tunnelID
|
msg->len += 4; // tunnelID
|
||||||
msg->Concat (payload, i2p::tunnel::TUNNEL_DATA_MSG_SIZE - 4);
|
msg->Concat (payload, i2p::tunnel::TUNNEL_DATA_MSG_SIZE - 4);
|
||||||
@ -708,9 +718,9 @@ namespace i2p
|
|||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<I2NPMessage> CreateEmptyTunnelDataMsg ()
|
std::shared_ptr<I2NPMessage> CreateEmptyTunnelDataMsg (bool endpoint)
|
||||||
{
|
{
|
||||||
auto msg = NewI2NPTunnelMessage ();
|
auto msg = NewI2NPTunnelMessage (endpoint);
|
||||||
msg->len += i2p::tunnel::TUNNEL_DATA_MSG_SIZE;
|
msg->len += i2p::tunnel::TUNNEL_DATA_MSG_SIZE;
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
@ -278,7 +278,7 @@ namespace tunnel
|
|||||||
|
|
||||||
std::shared_ptr<I2NPMessage> NewI2NPMessage ();
|
std::shared_ptr<I2NPMessage> NewI2NPMessage ();
|
||||||
std::shared_ptr<I2NPMessage> NewI2NPShortMessage ();
|
std::shared_ptr<I2NPMessage> NewI2NPShortMessage ();
|
||||||
std::shared_ptr<I2NPMessage> NewI2NPTunnelMessage ();
|
std::shared_ptr<I2NPMessage> NewI2NPTunnelMessage (bool endpoint);
|
||||||
std::shared_ptr<I2NPMessage> NewI2NPMessage (size_t len);
|
std::shared_ptr<I2NPMessage> NewI2NPMessage (size_t len);
|
||||||
|
|
||||||
std::shared_ptr<I2NPMessage> CreateI2NPMessage (I2NPMessageType msgType, const uint8_t * buf, size_t len, uint32_t replyMsgID = 0);
|
std::shared_ptr<I2NPMessage> CreateI2NPMessage (I2NPMessageType msgType, const uint8_t * buf, size_t len, uint32_t replyMsgID = 0);
|
||||||
@ -307,7 +307,7 @@ namespace tunnel
|
|||||||
|
|
||||||
std::shared_ptr<I2NPMessage> CreateTunnelDataMsg (const uint8_t * buf);
|
std::shared_ptr<I2NPMessage> CreateTunnelDataMsg (const uint8_t * buf);
|
||||||
std::shared_ptr<I2NPMessage> CreateTunnelDataMsg (uint32_t tunnelID, const uint8_t * payload);
|
std::shared_ptr<I2NPMessage> CreateTunnelDataMsg (uint32_t tunnelID, const uint8_t * payload);
|
||||||
std::shared_ptr<I2NPMessage> CreateEmptyTunnelDataMsg ();
|
std::shared_ptr<I2NPMessage> CreateEmptyTunnelDataMsg (bool endpoint);
|
||||||
|
|
||||||
std::shared_ptr<I2NPMessage> CreateTunnelGatewayMsg (uint32_t tunnelID, const uint8_t * buf, size_t len);
|
std::shared_ptr<I2NPMessage> CreateTunnelGatewayMsg (uint32_t tunnelID, const uint8_t * buf, size_t len);
|
||||||
std::shared_ptr<I2NPMessage> CreateTunnelGatewayMsg (uint32_t tunnelID, I2NPMessageType msgType,
|
std::shared_ptr<I2NPMessage> CreateTunnelGatewayMsg (uint32_t tunnelID, I2NPMessageType msgType,
|
||||||
|
@ -39,7 +39,7 @@ namespace tunnel
|
|||||||
|
|
||||||
void TransitTunnelParticipant::HandleTunnelDataMsg (std::shared_ptr<const i2p::I2NPMessage> tunnelMsg)
|
void TransitTunnelParticipant::HandleTunnelDataMsg (std::shared_ptr<const i2p::I2NPMessage> tunnelMsg)
|
||||||
{
|
{
|
||||||
auto newMsg = CreateEmptyTunnelDataMsg ();
|
auto newMsg = CreateEmptyTunnelDataMsg (false);
|
||||||
EncryptTunnelMsg (tunnelMsg, newMsg);
|
EncryptTunnelMsg (tunnelMsg, newMsg);
|
||||||
|
|
||||||
m_NumTransmittedBytes += tunnelMsg->GetLength ();
|
m_NumTransmittedBytes += tunnelMsg->GetLength ();
|
||||||
@ -87,7 +87,7 @@ namespace tunnel
|
|||||||
|
|
||||||
void TransitTunnelEndpoint::HandleTunnelDataMsg (std::shared_ptr<const i2p::I2NPMessage> tunnelMsg)
|
void TransitTunnelEndpoint::HandleTunnelDataMsg (std::shared_ptr<const i2p::I2NPMessage> tunnelMsg)
|
||||||
{
|
{
|
||||||
auto newMsg = CreateEmptyTunnelDataMsg ();
|
auto newMsg = CreateEmptyTunnelDataMsg (true);
|
||||||
EncryptTunnelMsg (tunnelMsg, newMsg);
|
EncryptTunnelMsg (tunnelMsg, newMsg);
|
||||||
|
|
||||||
LogPrint (eLogDebug, "TransitTunnel: handle msg for endpoint ", GetTunnelID ());
|
LogPrint (eLogDebug, "TransitTunnel: handle msg for endpoint ", GetTunnelID ());
|
||||||
|
@ -234,7 +234,7 @@ namespace tunnel
|
|||||||
void InboundTunnel::HandleTunnelDataMsg (std::shared_ptr<const I2NPMessage> msg)
|
void InboundTunnel::HandleTunnelDataMsg (std::shared_ptr<const I2NPMessage> msg)
|
||||||
{
|
{
|
||||||
if (IsFailed ()) SetState (eTunnelStateEstablished); // incoming messages means a tunnel is alive
|
if (IsFailed ()) SetState (eTunnelStateEstablished); // incoming messages means a tunnel is alive
|
||||||
auto newMsg = CreateEmptyTunnelDataMsg ();
|
auto newMsg = CreateEmptyTunnelDataMsg (true);
|
||||||
EncryptTunnelMsg (msg, newMsg);
|
EncryptTunnelMsg (msg, newMsg);
|
||||||
newMsg->from = shared_from_this ();
|
newMsg->from = shared_from_this ();
|
||||||
m_Endpoint.HandleDecryptedTunnelDataMsg (newMsg);
|
m_Endpoint.HandleDecryptedTunnelDataMsg (newMsg);
|
||||||
|
@ -126,9 +126,7 @@ namespace tunnel
|
|||||||
if (fragment + size < decrypted + TUNNEL_DATA_ENCRYPTED_SIZE)
|
if (fragment + size < decrypted + TUNNEL_DATA_ENCRYPTED_SIZE)
|
||||||
{
|
{
|
||||||
// this is not last message. we have to copy it
|
// this is not last message. we have to copy it
|
||||||
m_CurrentMessage.data = NewI2NPTunnelMessage ();
|
m_CurrentMessage.data = NewI2NPTunnelMessage (true);
|
||||||
m_CurrentMessage.data->offset += TUNNEL_GATEWAY_HEADER_SIZE; // reserve room for TunnelGateway header
|
|
||||||
m_CurrentMessage.data->len += TUNNEL_GATEWAY_HEADER_SIZE;
|
|
||||||
*(m_CurrentMessage.data) = *msg;
|
*(m_CurrentMessage.data) = *msg;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -215,7 +215,7 @@ namespace tunnel
|
|||||||
const auto& tunnelDataMsgs = m_Buffer.GetTunnelDataMsgs ();
|
const auto& tunnelDataMsgs = m_Buffer.GetTunnelDataMsgs ();
|
||||||
for (auto& tunnelMsg : tunnelDataMsgs)
|
for (auto& tunnelMsg : tunnelDataMsgs)
|
||||||
{
|
{
|
||||||
auto newMsg = CreateEmptyTunnelDataMsg ();
|
auto newMsg = CreateEmptyTunnelDataMsg (false);
|
||||||
m_Tunnel->EncryptTunnelMsg (tunnelMsg, newMsg);
|
m_Tunnel->EncryptTunnelMsg (tunnelMsg, newMsg);
|
||||||
htobe32buf (newMsg->GetPayload (), m_Tunnel->GetNextTunnelID ());
|
htobe32buf (newMsg->GetPayload (), m_Tunnel->GetNextTunnelID ());
|
||||||
newMsg->FillI2NPMessageHeader (eI2NPTunnelData);
|
newMsg->FillI2NPMessageHeader (eI2NPTunnelData);
|
||||||
|
Loading…
Reference in New Issue
Block a user