mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 13:27: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...");
|
||||
CreateTunnel<OutboundTunnel> (
|
||||
new TunnelConfig (i2p::data::netdb.GetRandomNTCPRouter (),
|
||||
new TunnelConfig (std::vector<const i2p::data::RouterInfo *>
|
||||
{
|
||||
i2p::data::netdb.GetRandomNTCPRouter ()
|
||||
},
|
||||
inboundTunnel->GetTunnelConfig ()));
|
||||
}
|
||||
else
|
||||
|
@ -361,8 +364,11 @@ namespace tunnel
|
|||
//OutboundTunnel * outboundTunnel = GetNextOutboundTunnel ();
|
||||
LogPrint ("Creating two hops outbound tunnel...");
|
||||
CreateTunnel<OutboundTunnel> (
|
||||
new TunnelConfig (i2p::data::netdb.GetRandomNTCPRouter (),
|
||||
i2p::data::netdb.GetRandomNTCPRouter (),
|
||||
new TunnelConfig (std::vector<const i2p::data::RouterInfo *>
|
||||
{
|
||||
i2p::data::netdb.GetRandomNTCPRouter (),
|
||||
i2p::data::netdb.GetRandomNTCPRouter ()
|
||||
},
|
||||
inboundTunnel->GetTunnelConfig ())/*,
|
||||
outboundTunnel*/);
|
||||
}
|
||||
|
@ -396,7 +402,11 @@ namespace tunnel
|
|||
if (m_OutboundTunnels.empty () || m_InboundTunnels.size () < 3)
|
||||
{
|
||||
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
|
||||
{
|
||||
|
@ -404,9 +414,12 @@ namespace tunnel
|
|||
LogPrint ("Creating two hops inbound tunnel...");
|
||||
auto router = outboundTunnel->GetTunnelConfig ()->GetFirstHop ()->router;
|
||||
CreateTunnel<InboundTunnel> (
|
||||
new TunnelConfig (i2p::data::netdb.GetRandomNTCPRouter (),
|
||||
router != &i2p::context.GetRouterInfo () ? router : i2p::data::netdb.GetRandomNTCPRouter ()),
|
||||
outboundTunnel);
|
||||
new TunnelConfig (std::vector<const i2p::data::RouterInfo *>
|
||||
{
|
||||
i2p::data::netdb.GetRandomNTCPRouter (),
|
||||
router != &i2p::context.GetRouterInfo () ? router : i2p::data::netdb.GetRandomNTCPRouter ()
|
||||
}),
|
||||
outboundTunnel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -457,7 +470,10 @@ namespace tunnel
|
|||
void Tunnels::CreateZeroHopsInboundTunnel ()
|
||||
{
|
||||
CreateTunnel<InboundTunnel> (
|
||||
new TunnelConfig (&i2p::context.GetRouterInfo ()));
|
||||
new TunnelConfig (std::vector<const i2p::data::RouterInfo *>
|
||||
{
|
||||
&i2p::context.GetRouterInfo ()
|
||||
}));
|
||||
}
|
||||
|
||||
OutboundTunnel * Tunnels::CreateOneHopOutboundTestTunnel (InboundTunnel * replyTunnel)
|
||||
|
@ -471,7 +487,9 @@ namespace tunnel
|
|||
if (peer)
|
||||
{
|
||||
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
|
||||
LogPrint ("No established peers");
|
||||
|
@ -490,7 +508,11 @@ namespace tunnel
|
|||
{
|
||||
const i2p::data::RouterInfo& router = peer->GetRemoteRouterInfo ();
|
||||
return CreateTunnel<InboundTunnel> (
|
||||
new TunnelConfig (&router, &i2p::context.GetRouterInfo ()),
|
||||
new TunnelConfig (std::vector<const i2p::data::RouterInfo *>
|
||||
{
|
||||
&router,
|
||||
&i2p::context.GetRouterInfo ()
|
||||
}),
|
||||
outboundTunnel);
|
||||
}
|
||||
else
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <inttypes.h>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include "RouterInfo.h"
|
||||
#include "RouterContext.h"
|
||||
|
||||
|
@ -83,34 +84,30 @@ namespace tunnel
|
|||
{
|
||||
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);
|
||||
m_LastHop = m_FirstHop;
|
||||
TunnelHopConfig * prev = nullptr;
|
||||
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
|
||||
{
|
||||
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_LastHop->SetReplyHop (replyTunnelConfig->GetFirstHop ());
|
||||
}
|
||||
else
|
||||
else // inbound
|
||||
m_LastHop->SetNextRouter (&i2p::context.GetRouterInfo ());
|
||||
}
|
||||
}
|
||||
|
||||
~TunnelConfig ()
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue