Browse Source

tunnel state

pull/93/head
orignal 10 years ago
parent
commit
72e689791c
  1. 15
      Tunnel.cpp
  2. 17
      Tunnel.h
  3. 23
      TunnelPool.cpp

15
Tunnel.cpp

@ -14,8 +14,8 @@ namespace i2p @@ -14,8 +14,8 @@ namespace i2p
namespace tunnel
{
Tunnel::Tunnel (TunnelConfig * config): m_Config (config), m_Pool (nullptr),
m_IsEstablished (false), m_IsFailed (false)
Tunnel::Tunnel (TunnelConfig * config):
m_Config (config), m_Pool (nullptr), m_State (eTunnelStatePending)
{
}
@ -111,7 +111,7 @@ namespace tunnel @@ -111,7 +111,7 @@ namespace tunnel
hop = hop->prev;
}
m_IsEstablished = true;
bool established = true;
hop = m_Config->GetFirstHop ();
while (hop)
{
@ -119,10 +119,10 @@ namespace tunnel @@ -119,10 +119,10 @@ namespace tunnel
LogPrint ("Ret code=", (int)record->ret);
if (record->ret)
// if any of participants declined the tunnel is not established
m_IsEstablished = false;
established = false;
hop = hop->next;
}
if (m_IsEstablished)
if (established)
{
// change reply keys to layer keys
hop = m_Config->GetFirstHop ();
@ -132,7 +132,8 @@ namespace tunnel @@ -132,7 +132,8 @@ namespace tunnel
hop = hop->next;
}
}
return m_IsEstablished;
if (established) m_State = eTunnelStateEstablished;
return established;
}
void Tunnel::EncryptTunnelMsg (I2NPMessage * tunnelMsg)
@ -148,7 +149,7 @@ namespace tunnel @@ -148,7 +149,7 @@ namespace tunnel
void InboundTunnel::HandleTunnelDataMsg (I2NPMessage * msg)
{
if (IsFailed ()) SetFailed (false); // incoming messages means a tunnel is alive
if (IsFailed ()) SetState (eTunnelStateEstablished); // incoming messages means a tunnel is alive
msg->from = this;
EncryptTunnelMsg (msg);
m_Endpoint.HandleDecryptedTunnelDataMsg (msg);

17
Tunnel.h

@ -23,6 +23,14 @@ namespace tunnel @@ -23,6 +23,14 @@ namespace tunnel
{
const int TUNNEL_EXPIRATION_TIMEOUT = 660; // 11 minutes
enum TunnelState
{
eTunnelStatePending,
eTunnelStateEstablished,
eTunnelStateTestFailed,
eTunnelStateFailed
};
class OutboundTunnel;
class InboundTunnel;
class Tunnel: public TunnelBase
@ -35,9 +43,10 @@ namespace tunnel @@ -35,9 +43,10 @@ namespace tunnel
void Build (uint32_t replyMsgID, OutboundTunnel * outboundTunnel = 0);
TunnelConfig * GetTunnelConfig () const { return m_Config; }
bool IsEstablished () const { return m_IsEstablished; };
bool IsFailed () const { return m_IsFailed; };
void SetFailed (bool failed) { m_IsFailed = failed; }
TunnelState GetState () const { return m_State; };
void SetState (TunnelState state) { m_State = state; };
bool IsEstablished () const { return m_State == eTunnelStateEstablished; };
bool IsFailed () const { return m_State == eTunnelStateFailed; };
TunnelPool * GetTunnelPool () const { return m_Pool; };
void SetTunnelPool (TunnelPool * pool) { m_Pool = pool; };
@ -53,7 +62,7 @@ namespace tunnel @@ -53,7 +62,7 @@ namespace tunnel
TunnelConfig * m_Config;
TunnelPool * m_Pool; // pool, tunnel belongs to, or null
bool m_IsEstablished, m_IsFailed;
TunnelState m_State;
};
class OutboundTunnel: public Tunnel

23
TunnelPool.cpp

@ -109,16 +109,26 @@ namespace tunnel @@ -109,16 +109,26 @@ namespace tunnel
for (auto it: m_Tests)
{
LogPrint ("Tunnel test ", (int)it.first, " failed");
// both outbound and inbound tunnels considered as invalid
// if test failed again with another tunnel we consider it failed
if (it.second.first)
{
it.second.first->SetFailed (true);
m_OutboundTunnels.erase (it.second.first);
if (it.second.first->GetState () == eTunnelStateTestFailed)
{
it.second.first->SetState (eTunnelStateFailed);
m_OutboundTunnels.erase (it.second.first);
}
else
it.second.first->SetState (eTunnelStateTestFailed);
}
if (it.second.second)
{
it.second.second->SetFailed (true);
m_InboundTunnels.erase (it.second.second);
if (it.second.second->GetState () == eTunnelStateTestFailed)
{
it.second.second->SetState (eTunnelStateFailed);
m_InboundTunnels.erase (it.second.second);
}
else
it.second.second->SetState (eTunnelStateTestFailed);
}
}
m_Tests.clear ();
@ -156,6 +166,9 @@ namespace tunnel @@ -156,6 +166,9 @@ namespace tunnel
{
LogPrint ("Tunnel test ", it->first, " successive. ", i2p::util::GetMillisecondsSinceEpoch () - be64toh (deliveryStatus->timestamp), " milliseconds");
m_Tests.erase (it);
// restore from test failed state if any
it->second.first->SetState (eTunnelStateEstablished);
it->second.second->SetState (eTunnelStateEstablished);
}
else
i2p::garlic::routing.HandleDeliveryStatusMessage (msg->GetPayload (), msg->GetLength ()); // TODO:

Loading…
Cancel
Save