Browse Source

don't create new tunnel message for encryption/decryption

pull/1698/head
orignal 3 years ago
parent
commit
1af9117b80
  1. 17
      libi2pd/TransitTunnel.cpp
  2. 8
      libi2pd/TransitTunnel.h
  3. 13
      libi2pd/Tunnel.cpp
  4. 4
      libi2pd/Tunnel.h
  5. 2
      libi2pd/TunnelBase.h

17
libi2pd/TransitTunnel.cpp

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright (c) 2013-2020, The PurpleI2P Project
* Copyright (c) 2013-2021, The PurpleI2P Project
*
* This file is part of Purple i2pd project and licensed under BSD3
*
@ -37,15 +37,14 @@ namespace tunnel @@ -37,15 +37,14 @@ namespace tunnel
{
}
void TransitTunnelParticipant::HandleTunnelDataMsg (std::shared_ptr<const i2p::I2NPMessage> tunnelMsg)
void TransitTunnelParticipant::HandleTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage>&& tunnelMsg)
{
auto newMsg = CreateEmptyTunnelDataMsg (false);
EncryptTunnelMsg (tunnelMsg, newMsg);
EncryptTunnelMsg (tunnelMsg, tunnelMsg);
m_NumTransmittedBytes += tunnelMsg->GetLength ();
htobe32buf (newMsg->GetPayload (), GetNextTunnelID ());
newMsg->FillI2NPMessageHeader (eI2NPTunnelData);
m_TunnelDataMsgs.push_back (newMsg);
htobe32buf (tunnelMsg->GetPayload (), GetNextTunnelID ());
tunnelMsg->FillI2NPMessageHeader (eI2NPTunnelData);
m_TunnelDataMsgs.push_back (tunnelMsg);
}
void TransitTunnelParticipant::FlushTunnelDataMsgs ()
@ -65,7 +64,7 @@ namespace tunnel @@ -65,7 +64,7 @@ namespace tunnel
LogPrint (eLogError, "TransitTunnel: We are not a gateway for ", GetTunnelID ());
}
void TransitTunnel::HandleTunnelDataMsg (std::shared_ptr<const i2p::I2NPMessage> tunnelMsg)
void TransitTunnel::HandleTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage>&& tunnelMsg)
{
LogPrint (eLogError, "TransitTunnel: Incoming tunnel message is not supported ", GetTunnelID ());
}
@ -85,7 +84,7 @@ namespace tunnel @@ -85,7 +84,7 @@ namespace tunnel
m_Gateway.SendBuffer ();
}
void TransitTunnelEndpoint::HandleTunnelDataMsg (std::shared_ptr<const i2p::I2NPMessage> tunnelMsg)
void TransitTunnelEndpoint::HandleTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage>&& tunnelMsg)
{
auto newMsg = CreateEmptyTunnelDataMsg (true);
EncryptTunnelMsg (tunnelMsg, newMsg);

8
libi2pd/TransitTunnel.h

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright (c) 2013-2020, The PurpleI2P Project
* Copyright (c) 2013-2021, The PurpleI2P Project
*
* This file is part of Purple i2pd project and licensed under BSD3
*
@ -35,7 +35,7 @@ namespace tunnel @@ -35,7 +35,7 @@ namespace tunnel
// implements TunnelBase
void SendTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage> msg);
void HandleTunnelDataMsg (std::shared_ptr<const i2p::I2NPMessage> tunnelMsg);
void HandleTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage>&& tunnelMsg);
void EncryptTunnelMsg (std::shared_ptr<const I2NPMessage> in, std::shared_ptr<I2NPMessage> out);
private:
@ -54,7 +54,7 @@ namespace tunnel @@ -54,7 +54,7 @@ namespace tunnel
~TransitTunnelParticipant ();
size_t GetNumTransmittedBytes () const { return m_NumTransmittedBytes; };
void HandleTunnelDataMsg (std::shared_ptr<const i2p::I2NPMessage> tunnelMsg);
void HandleTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage>&& tunnelMsg);
void FlushTunnelDataMsgs ();
private:
@ -95,7 +95,7 @@ namespace tunnel @@ -95,7 +95,7 @@ namespace tunnel
void Cleanup () { m_Endpoint.Cleanup (); }
void HandleTunnelDataMsg (std::shared_ptr<const i2p::I2NPMessage> tunnelMsg);
void HandleTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage>&& tunnelMsg);
size_t GetNumTransmittedBytes () const { return m_Endpoint.GetNumReceivedBytes (); }
private:

13
libi2pd/Tunnel.cpp

@ -243,13 +243,12 @@ namespace tunnel @@ -243,13 +243,12 @@ namespace tunnel
}
}
void InboundTunnel::HandleTunnelDataMsg (std::shared_ptr<const I2NPMessage> msg)
void InboundTunnel::HandleTunnelDataMsg (std::shared_ptr<I2NPMessage>&& msg)
{
if (IsFailed ()) SetState (eTunnelStateEstablished); // incoming messages means a tunnel is alive
auto newMsg = CreateEmptyTunnelDataMsg (true);
EncryptTunnelMsg (msg, newMsg);
newMsg->from = shared_from_this ();
m_Endpoint.HandleDecryptedTunnelDataMsg (newMsg);
EncryptTunnelMsg (msg, msg);
msg->from = shared_from_this ();
m_Endpoint.HandleDecryptedTunnelDataMsg (msg);
}
void InboundTunnel::Print (std::stringstream& s) const
@ -308,7 +307,7 @@ namespace tunnel @@ -308,7 +307,7 @@ namespace tunnel
m_Gateway.SendBuffer ();
}
void OutboundTunnel::HandleTunnelDataMsg (std::shared_ptr<const i2p::I2NPMessage> tunnelMsg)
void OutboundTunnel::HandleTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage>&& tunnelMsg)
{
LogPrint (eLogError, "Tunnel: incoming message for outbound tunnel ", GetTunnelID ());
}
@ -519,7 +518,7 @@ namespace tunnel @@ -519,7 +518,7 @@ namespace tunnel
if (tunnel)
{
if (typeID == eI2NPTunnelData)
tunnel->HandleTunnelDataMsg (msg);
tunnel->HandleTunnelDataMsg (std::move (msg));
else // tunnel gateway assumed
HandleTunnelGatewayMsg (tunnel, msg);
}

4
libi2pd/Tunnel.h

@ -132,7 +132,7 @@ namespace tunnel @@ -132,7 +132,7 @@ namespace tunnel
void Print (std::stringstream& s) const;
// implements TunnelBase
void HandleTunnelDataMsg (std::shared_ptr<const i2p::I2NPMessage> tunnelMsg);
void HandleTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage>&& tunnelMsg);
bool IsInbound() const { return false; }
@ -148,7 +148,7 @@ namespace tunnel @@ -148,7 +148,7 @@ namespace tunnel
public:
InboundTunnel (std::shared_ptr<const TunnelConfig> config): Tunnel (config), m_Endpoint (true) {};
void HandleTunnelDataMsg (std::shared_ptr<const I2NPMessage> msg);
void HandleTunnelDataMsg (std::shared_ptr<I2NPMessage>&& msg);
virtual size_t GetNumReceivedBytes () const { return m_Endpoint.GetNumReceivedBytes (); };
void Print (std::stringstream& s) const;
bool IsInbound() const { return true; }

2
libi2pd/TunnelBase.h

@ -47,7 +47,7 @@ namespace tunnel @@ -47,7 +47,7 @@ namespace tunnel
virtual ~TunnelBase () {};
virtual void Cleanup () {};
virtual void HandleTunnelDataMsg (std::shared_ptr<const i2p::I2NPMessage> tunnelMsg) = 0;
virtual void HandleTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage>&& tunnelMsg) = 0;
virtual void SendTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage> msg) = 0;
virtual void FlushTunnelDataMsgs () {};
virtual void EncryptTunnelMsg (std::shared_ptr<const I2NPMessage> in, std::shared_ptr<I2NPMessage> out) = 0;

Loading…
Cancel
Save