mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-02 11:04:00 +01:00
tunnel test
This commit is contained in:
parent
6066b7073f
commit
014e1c54eb
|
@ -425,11 +425,6 @@ namespace i2p
|
||||||
int size = be16toh (header->size);
|
int size = be16toh (header->size);
|
||||||
switch (header->typeID)
|
switch (header->typeID)
|
||||||
{
|
{
|
||||||
case eI2NPDeliveryStatus:
|
|
||||||
LogPrint ("DeliveryStatus");
|
|
||||||
// we assume DeliveryStatusMessage is sent with garlic only
|
|
||||||
i2p::garlic::routing.HandleDeliveryStatusMessage (buf, size);
|
|
||||||
break;
|
|
||||||
case eI2NPVariableTunnelBuild:
|
case eI2NPVariableTunnelBuild:
|
||||||
LogPrint ("VariableTunnelBuild");
|
LogPrint ("VariableTunnelBuild");
|
||||||
HandleVariableTunnelBuildMsg (msgID, buf, size);
|
HandleVariableTunnelBuildMsg (msgID, buf, size);
|
||||||
|
@ -461,6 +456,10 @@ namespace i2p
|
||||||
LogPrint ("TunnelGateway");
|
LogPrint ("TunnelGateway");
|
||||||
HandleTunnelGatewayMsg (msg);
|
HandleTunnelGatewayMsg (msg);
|
||||||
break;
|
break;
|
||||||
|
case eI2NPGarlic:
|
||||||
|
LogPrint ("Garlic");
|
||||||
|
i2p::garlic::routing.HandleGarlicMessage (msg);
|
||||||
|
break;
|
||||||
case eI2NPDatabaseStore:
|
case eI2NPDatabaseStore:
|
||||||
LogPrint ("DatabaseStore");
|
LogPrint ("DatabaseStore");
|
||||||
i2p::data::netdb.PostI2NPMsg (msg);
|
i2p::data::netdb.PostI2NPMsg (msg);
|
||||||
|
@ -468,11 +467,17 @@ namespace i2p
|
||||||
case eI2NPDatabaseSearchReply:
|
case eI2NPDatabaseSearchReply:
|
||||||
LogPrint ("DatabaseSearchReply");
|
LogPrint ("DatabaseSearchReply");
|
||||||
i2p::data::netdb.PostI2NPMsg (msg);
|
i2p::data::netdb.PostI2NPMsg (msg);
|
||||||
|
break;
|
||||||
|
case eI2NPDeliveryStatus:
|
||||||
|
LogPrint ("DeliveryStatus");
|
||||||
|
if (msg->from && msg->from->GetTunnelPool ())
|
||||||
|
msg->from->GetTunnelPool ()->ProcessDeliveryStatus (msg);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
i2p::garlic::routing.HandleDeliveryStatusMessage (msg->GetPayload (), msg->GetLength ());
|
||||||
|
DeleteI2NPMessage (msg);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case eI2NPGarlic:
|
|
||||||
LogPrint ("Garlic");
|
|
||||||
i2p::garlic::routing.HandleGarlicMessage (msg);
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
HandleI2NPMessage (msg->GetBuffer (), msg->GetLength ());
|
HandleI2NPMessage (msg->GetBuffer (), msg->GetLength ());
|
||||||
DeleteI2NPMessage (msg);
|
DeleteI2NPMessage (msg);
|
||||||
|
|
|
@ -502,7 +502,10 @@ namespace tunnel
|
||||||
void Tunnels::ManageTunnelPools ()
|
void Tunnels::ManageTunnelPools ()
|
||||||
{
|
{
|
||||||
for (auto& it: m_Pools)
|
for (auto& it: m_Pools)
|
||||||
|
{
|
||||||
it->CreateTunnels ();
|
it->CreateTunnels ();
|
||||||
|
it->TestTunnels ();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tunnels::PostTunnelData (I2NPMessage * msg)
|
void Tunnels::PostTunnelData (I2NPMessage * msg)
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
#include <cryptopp/dh.h>
|
#include <cryptopp/dh.h>
|
||||||
|
#include "I2PEndian.h"
|
||||||
#include "CryptoConst.h"
|
#include "CryptoConst.h"
|
||||||
#include "Tunnel.h"
|
#include "Tunnel.h"
|
||||||
#include "NetDb.h"
|
#include "NetDb.h"
|
||||||
#include "Timestamp.h"
|
#include "Timestamp.h"
|
||||||
#include "RouterContext.h"
|
#include "RouterContext.h"
|
||||||
|
#include "Garlic.h"
|
||||||
#include "TunnelPool.h"
|
#include "TunnelPool.h"
|
||||||
|
|
||||||
namespace i2p
|
namespace i2p
|
||||||
|
@ -48,6 +50,8 @@ namespace tunnel
|
||||||
void TunnelPool::TunnelExpired (OutboundTunnel * expiredTunnel)
|
void TunnelPool::TunnelExpired (OutboundTunnel * expiredTunnel)
|
||||||
{
|
{
|
||||||
m_OutboundTunnels.erase (expiredTunnel);
|
m_OutboundTunnels.erase (expiredTunnel);
|
||||||
|
if (expiredTunnel == m_LastOutboundTunnel)
|
||||||
|
m_LastOutboundTunnel = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<InboundTunnel *> TunnelPool::GetInboundTunnels (int num) const
|
std::vector<InboundTunnel *> TunnelPool::GetInboundTunnels (int num) const
|
||||||
|
@ -90,6 +94,43 @@ namespace tunnel
|
||||||
CreateOutboundTunnel ();
|
CreateOutboundTunnel ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TunnelPool::TestTunnels ()
|
||||||
|
{
|
||||||
|
auto& rnd = i2p::context.GetRandomNumberGenerator ();
|
||||||
|
for (auto it: m_Tests)
|
||||||
|
{
|
||||||
|
LogPrint ("Tunnel test ", (int)it.first, " failed");
|
||||||
|
// both outbound and inbound tunnels considered as invalid
|
||||||
|
TunnelExpired (it.second.first);
|
||||||
|
TunnelExpired (it.second.second);
|
||||||
|
}
|
||||||
|
m_Tests.clear ();
|
||||||
|
auto it1 = m_OutboundTunnels.begin ();
|
||||||
|
auto it2 = m_InboundTunnels.begin ();
|
||||||
|
while (it1 != m_OutboundTunnels.end () && it2 != m_InboundTunnels.end ())
|
||||||
|
{
|
||||||
|
uint32_t msgID = rnd.GenerateWord32 ();
|
||||||
|
m_Tests[msgID] = std::make_pair (*it1, *it2);
|
||||||
|
(*it1)->SendTunnelDataMsg ((*it2)->GetNextIdentHash (), (*it2)->GetNextTunnelID (),
|
||||||
|
CreateDeliveryStatusMsg (msgID));
|
||||||
|
it1++; it2++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TunnelPool::ProcessDeliveryStatus (I2NPMessage * msg)
|
||||||
|
{
|
||||||
|
I2NPDeliveryStatusMsg * deliveryStatus = (I2NPDeliveryStatusMsg *)msg->GetPayload ();
|
||||||
|
auto it = m_Tests.find (be32toh (deliveryStatus->msgID));
|
||||||
|
if (it != m_Tests.end ())
|
||||||
|
{
|
||||||
|
LogPrint ("Tunnel test ", it->first, " successive. ", i2p::util::GetMillisecondsSinceEpoch () - be64toh (deliveryStatus->timestamp), " milliseconds");
|
||||||
|
m_Tests.erase (it);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
i2p::garlic::routing.HandleDeliveryStatusMessage (msg->GetPayload (), msg->GetLength ()); // TODO:
|
||||||
|
DeleteI2NPMessage (msg);
|
||||||
|
}
|
||||||
|
|
||||||
void TunnelPool::CreateInboundTunnel ()
|
void TunnelPool::CreateInboundTunnel ()
|
||||||
{
|
{
|
||||||
OutboundTunnel * outboundTunnel = m_OutboundTunnels.size () > 0 ?
|
OutboundTunnel * outboundTunnel = m_OutboundTunnels.size () > 0 ?
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
#ifndef TUNNEL_POOL__
|
#ifndef TUNNEL_POOL__
|
||||||
#define TUNNEL_POOL__
|
#define TUNNEL_POOL__
|
||||||
|
|
||||||
|
#include <inttypes.h>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <utility>
|
||||||
#include "Identity.h"
|
#include "Identity.h"
|
||||||
#include "LeaseSet.h"
|
#include "LeaseSet.h"
|
||||||
#include "I2NPProtocol.h"
|
#include "I2NPProtocol.h"
|
||||||
|
@ -34,6 +36,9 @@ namespace tunnel
|
||||||
std::vector<InboundTunnel *> GetInboundTunnels (int num) const;
|
std::vector<InboundTunnel *> GetInboundTunnels (int num) const;
|
||||||
OutboundTunnel * GetNextOutboundTunnel ();
|
OutboundTunnel * GetNextOutboundTunnel ();
|
||||||
|
|
||||||
|
void TestTunnels ();
|
||||||
|
void ProcessDeliveryStatus (I2NPMessage * msg);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void CreateInboundTunnel ();
|
void CreateInboundTunnel ();
|
||||||
|
@ -46,6 +51,7 @@ namespace tunnel
|
||||||
int m_NumTunnels;
|
int m_NumTunnels;
|
||||||
std::set<InboundTunnel *, TunnelCreationTimeCmp> m_InboundTunnels; // recent tunnel appears first
|
std::set<InboundTunnel *, TunnelCreationTimeCmp> m_InboundTunnels; // recent tunnel appears first
|
||||||
std::set<OutboundTunnel *, TunnelCreationTimeCmp> m_OutboundTunnels;
|
std::set<OutboundTunnel *, TunnelCreationTimeCmp> m_OutboundTunnels;
|
||||||
|
std::map<uint32_t, std::pair<OutboundTunnel *, InboundTunnel *> > m_Tests;
|
||||||
OutboundTunnel * m_LastOutboundTunnel;
|
OutboundTunnel * m_LastOutboundTunnel;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue