Browse Source

handle drop of tunnel build message

pull/2014/head
orignal 11 months ago
parent
commit
ce35637866
  1. 14
      libi2pd/Tunnel.cpp
  2. 14
      libi2pd/Tunnel.h

14
libi2pd/Tunnel.cpp

@ -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 * This file is part of Purple i2pd project and licensed under BSD3
* *
@ -90,7 +90,13 @@ namespace tunnel
hop = hop->prev; hop = hop->prev;
} }
msg->FillI2NPMessageHeader (m_Config->IsShort () ? eI2NPShortTunnelBuild : eI2NPVariableTunnelBuild); msg->FillI2NPMessageHeader (m_Config->IsShort () ? eI2NPShortTunnelBuild : eI2NPVariableTunnelBuild);
auto s = shared_from_this ();
msg->onDrop = [s]()
{
LogPrint (eLogInfo, "I2NP: Tunnel ", s->GetTunnelID (), " request was not sent");
s->SetState (i2p::tunnel::eTunnelStateBuildFailed);
};
// send message // send message
if (outboundTunnel) if (outboundTunnel)
{ {
@ -246,7 +252,7 @@ namespace tunnel
{ {
if (IsFailed ()) SetState (eTunnelStateEstablished); // incoming messages means a tunnel is alive if (IsFailed ()) SetState (eTunnelStateEstablished); // incoming messages means a tunnel is alive
EncryptTunnelMsg (msg, msg); EncryptTunnelMsg (msg, msg);
msg->from = shared_from_this (); msg->from = GetSharedFromThis ();
m_Endpoint.HandleDecryptedTunnelDataMsg (msg); m_Endpoint.HandleDecryptedTunnelDataMsg (msg);
} }
@ -261,7 +267,7 @@ namespace tunnel
if (msg) if (msg)
{ {
m_NumReceivedBytes += msg->GetLength (); m_NumReceivedBytes += msg->GetLength ();
msg->from = shared_from_this (); msg->from = GetSharedFromThis ();
HandleI2NPMessage (msg); HandleI2NPMessage (msg);
} }
} }

14
libi2pd/Tunnel.h

@ -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 * This file is part of Purple i2pd project and licensed under BSD3
* *
@ -65,7 +65,8 @@ namespace tunnel
class OutboundTunnel; class OutboundTunnel;
class InboundTunnel; class InboundTunnel;
class Tunnel: public TunnelBase class Tunnel: public TunnelBase,
public std::enable_shared_from_this<Tunnel>
{ {
struct TunnelHop struct TunnelHop
{ {
@ -155,7 +156,7 @@ namespace tunnel
i2p::data::IdentHash m_EndpointIdentHash; i2p::data::IdentHash m_EndpointIdentHash;
}; };
class InboundTunnel: public Tunnel, public std::enable_shared_from_this<InboundTunnel> class InboundTunnel: public Tunnel
{ {
public: public:
@ -167,6 +168,13 @@ namespace tunnel
// override TunnelBase // override TunnelBase
void Cleanup () override { m_Endpoint.Cleanup (); }; void Cleanup () override { m_Endpoint.Cleanup (); };
protected:
std::shared_ptr<InboundTunnel> GetSharedFromThis ()
{
return std::static_pointer_cast<InboundTunnel>(shared_from_this ());
}
private: private:
TunnelEndpoint m_Endpoint; TunnelEndpoint m_Endpoint;

Loading…
Cancel
Save