mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 21:37:17 +01:00
common constructor for TunnelConfig
This commit is contained in:
parent
cbe58c8bb1
commit
3aab091e9f
42
Tunnel.cpp
42
Tunnel.cpp
|
@ -353,7 +353,10 @@ namespace tunnel
|
||||||
{
|
{
|
||||||
LogPrint ("Creating one hop outbound tunnel...");
|
LogPrint ("Creating one hop outbound tunnel...");
|
||||||
CreateTunnel<OutboundTunnel> (
|
CreateTunnel<OutboundTunnel> (
|
||||||
new TunnelConfig (i2p::data::netdb.GetRandomNTCPRouter (),
|
new TunnelConfig (std::vector<const i2p::data::RouterInfo *>
|
||||||
|
{
|
||||||
|
i2p::data::netdb.GetRandomNTCPRouter ()
|
||||||
|
},
|
||||||
inboundTunnel->GetTunnelConfig ()));
|
inboundTunnel->GetTunnelConfig ()));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -361,8 +364,11 @@ namespace tunnel
|
||||||
//OutboundTunnel * outboundTunnel = GetNextOutboundTunnel ();
|
//OutboundTunnel * outboundTunnel = GetNextOutboundTunnel ();
|
||||||
LogPrint ("Creating two hops outbound tunnel...");
|
LogPrint ("Creating two hops outbound tunnel...");
|
||||||
CreateTunnel<OutboundTunnel> (
|
CreateTunnel<OutboundTunnel> (
|
||||||
new TunnelConfig (i2p::data::netdb.GetRandomNTCPRouter (),
|
new TunnelConfig (std::vector<const i2p::data::RouterInfo *>
|
||||||
i2p::data::netdb.GetRandomNTCPRouter (),
|
{
|
||||||
|
i2p::data::netdb.GetRandomNTCPRouter (),
|
||||||
|
i2p::data::netdb.GetRandomNTCPRouter ()
|
||||||
|
},
|
||||||
inboundTunnel->GetTunnelConfig ())/*,
|
inboundTunnel->GetTunnelConfig ())/*,
|
||||||
outboundTunnel*/);
|
outboundTunnel*/);
|
||||||
}
|
}
|
||||||
|
@ -396,7 +402,11 @@ namespace tunnel
|
||||||
if (m_OutboundTunnels.empty () || m_InboundTunnels.size () < 3)
|
if (m_OutboundTunnels.empty () || m_InboundTunnels.size () < 3)
|
||||||
{
|
{
|
||||||
LogPrint ("Creating one hop inbound tunnel...");
|
LogPrint ("Creating one hop inbound tunnel...");
|
||||||
CreateTunnel<InboundTunnel> (new TunnelConfig (i2p::data::netdb.GetRandomNTCPRouter ()));
|
CreateTunnel<InboundTunnel> (
|
||||||
|
new TunnelConfig (std::vector<const i2p::data::RouterInfo *>
|
||||||
|
{
|
||||||
|
i2p::data::netdb.GetRandomNTCPRouter ()
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -404,9 +414,12 @@ namespace tunnel
|
||||||
LogPrint ("Creating two hops inbound tunnel...");
|
LogPrint ("Creating two hops inbound tunnel...");
|
||||||
auto router = outboundTunnel->GetTunnelConfig ()->GetFirstHop ()->router;
|
auto router = outboundTunnel->GetTunnelConfig ()->GetFirstHop ()->router;
|
||||||
CreateTunnel<InboundTunnel> (
|
CreateTunnel<InboundTunnel> (
|
||||||
new TunnelConfig (i2p::data::netdb.GetRandomNTCPRouter (),
|
new TunnelConfig (std::vector<const i2p::data::RouterInfo *>
|
||||||
router != &i2p::context.GetRouterInfo () ? router : i2p::data::netdb.GetRandomNTCPRouter ()),
|
{
|
||||||
outboundTunnel);
|
i2p::data::netdb.GetRandomNTCPRouter (),
|
||||||
|
router != &i2p::context.GetRouterInfo () ? router : i2p::data::netdb.GetRandomNTCPRouter ()
|
||||||
|
}),
|
||||||
|
outboundTunnel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -457,7 +470,10 @@ namespace tunnel
|
||||||
void Tunnels::CreateZeroHopsInboundTunnel ()
|
void Tunnels::CreateZeroHopsInboundTunnel ()
|
||||||
{
|
{
|
||||||
CreateTunnel<InboundTunnel> (
|
CreateTunnel<InboundTunnel> (
|
||||||
new TunnelConfig (&i2p::context.GetRouterInfo ()));
|
new TunnelConfig (std::vector<const i2p::data::RouterInfo *>
|
||||||
|
{
|
||||||
|
&i2p::context.GetRouterInfo ()
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
OutboundTunnel * Tunnels::CreateOneHopOutboundTestTunnel (InboundTunnel * replyTunnel)
|
OutboundTunnel * Tunnels::CreateOneHopOutboundTestTunnel (InboundTunnel * replyTunnel)
|
||||||
|
@ -471,7 +487,9 @@ namespace tunnel
|
||||||
if (peer)
|
if (peer)
|
||||||
{
|
{
|
||||||
const i2p::data::RouterInfo& router = peer->GetRemoteRouterInfo ();
|
const i2p::data::RouterInfo& router = peer->GetRemoteRouterInfo ();
|
||||||
return CreateTunnel<InboundTunnel> (new TunnelConfig (&router), outboundTunnel);
|
return CreateTunnel<InboundTunnel> (
|
||||||
|
new TunnelConfig (std::vector<const i2p::data::RouterInfo *>{&router}),
|
||||||
|
outboundTunnel);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
LogPrint ("No established peers");
|
LogPrint ("No established peers");
|
||||||
|
@ -490,7 +508,11 @@ namespace tunnel
|
||||||
{
|
{
|
||||||
const i2p::data::RouterInfo& router = peer->GetRemoteRouterInfo ();
|
const i2p::data::RouterInfo& router = peer->GetRemoteRouterInfo ();
|
||||||
return CreateTunnel<InboundTunnel> (
|
return CreateTunnel<InboundTunnel> (
|
||||||
new TunnelConfig (&router, &i2p::context.GetRouterInfo ()),
|
new TunnelConfig (std::vector<const i2p::data::RouterInfo *>
|
||||||
|
{
|
||||||
|
&router,
|
||||||
|
&i2p::context.GetRouterInfo ()
|
||||||
|
}),
|
||||||
outboundTunnel);
|
outboundTunnel);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <vector>
|
||||||
#include "RouterInfo.h"
|
#include "RouterInfo.h"
|
||||||
#include "RouterContext.h"
|
#include "RouterContext.h"
|
||||||
|
|
||||||
|
@ -83,34 +84,30 @@ namespace tunnel
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
TunnelConfig (const i2p::data::RouterInfo * peer, TunnelConfig * replyTunnelConfig = 0) // one hop
|
|
||||||
|
TunnelConfig (std::vector<const i2p::data::RouterInfo *> peers,
|
||||||
|
TunnelConfig * replyTunnelConfig = 0) // replyTunnelConfig=0 means inbound
|
||||||
{
|
{
|
||||||
m_FirstHop = new TunnelHopConfig (peer);
|
TunnelHopConfig * prev = nullptr;
|
||||||
m_LastHop = m_FirstHop;
|
for (auto it: peers)
|
||||||
|
{
|
||||||
|
auto hop = new TunnelHopConfig (it);
|
||||||
|
if (prev)
|
||||||
|
prev->SetNext (hop);
|
||||||
|
else
|
||||||
|
m_FirstHop = hop;
|
||||||
|
prev = hop;
|
||||||
|
}
|
||||||
|
m_LastHop = prev;
|
||||||
|
|
||||||
if (replyTunnelConfig) // outbound
|
if (replyTunnelConfig) // outbound
|
||||||
{
|
|
||||||
m_FirstHop->isGateway = false;
|
|
||||||
m_LastHop->SetReplyHop (replyTunnelConfig->GetFirstHop ());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
m_FirstHop->SetNextRouter (&i2p::context.GetRouterInfo ());
|
|
||||||
}
|
|
||||||
|
|
||||||
TunnelConfig (const i2p::data::RouterInfo * peer1, const i2p::data::RouterInfo * peer2, TunnelConfig * replyTunnelConfig = 0) // two hops
|
|
||||||
{
|
|
||||||
m_FirstHop = new TunnelHopConfig (peer1);
|
|
||||||
m_LastHop = new TunnelHopConfig (peer2);
|
|
||||||
m_FirstHop->SetNext (m_LastHop);
|
|
||||||
|
|
||||||
if (replyTunnelConfig)
|
|
||||||
{
|
{
|
||||||
m_FirstHop->isGateway = false;
|
m_FirstHop->isGateway = false;
|
||||||
m_LastHop->SetReplyHop (replyTunnelConfig->GetFirstHop ());
|
m_LastHop->SetReplyHop (replyTunnelConfig->GetFirstHop ());
|
||||||
}
|
}
|
||||||
else
|
else // inbound
|
||||||
m_LastHop->SetNextRouter (&i2p::context.GetRouterInfo ());
|
m_LastHop->SetNextRouter (&i2p::context.GetRouterInfo ());
|
||||||
}
|
}
|
||||||
|
|
||||||
~TunnelConfig ()
|
~TunnelConfig ()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue