Browse Source

common constructor for TunnelConfig

pull/8/head
orignal 11 years ago
parent
commit
3aab091e9f
  1. 38
      Tunnel.cpp
  2. 31
      TunnelConfig.h

38
Tunnel.cpp

@ -353,7 +353,10 @@ namespace tunnel @@ -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 @@ -361,8 +364,11 @@ namespace tunnel
//OutboundTunnel * outboundTunnel = GetNextOutboundTunnel ();
LogPrint ("Creating two hops outbound tunnel...");
CreateTunnel<OutboundTunnel> (
new TunnelConfig (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 @@ -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,8 +414,11 @@ namespace tunnel @@ -404,8 +414,11 @@ 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 ()),
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 @@ -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 @@ -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 @@ -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

31
TunnelConfig.h

@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
#include <inttypes.h>
#include <sstream>
#include <vector>
#include "RouterInfo.h"
#include "RouterContext.h"
@ -83,32 +84,28 @@ namespace tunnel @@ -83,32 +84,28 @@ namespace tunnel
{
public:
TunnelConfig (const i2p::data::RouterInfo * peer, TunnelConfig * replyTunnelConfig = 0) // one hop
{
m_FirstHop = new TunnelHopConfig (peer);
m_LastHop = m_FirstHop;
if (replyTunnelConfig) // outbound
TunnelConfig (std::vector<const i2p::data::RouterInfo *> peers,
TunnelConfig * replyTunnelConfig = 0) // replyTunnelConfig=0 means inbound
{
m_FirstHop->isGateway = false;
m_LastHop->SetReplyHop (replyTunnelConfig->GetFirstHop ());
}
TunnelHopConfig * prev = nullptr;
for (auto it: peers)
{
auto hop = new TunnelHopConfig (it);
if (prev)
prev->SetNext (hop);
else
m_FirstHop->SetNextRouter (&i2p::context.GetRouterInfo ());
m_FirstHop = hop;
prev = hop;
}
m_LastHop = prev;
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)
if (replyTunnelConfig) // outbound
{
m_FirstHop->isGateway = false;
m_LastHop->SetReplyHop (replyTunnelConfig->GetFirstHop ());
}
else
else // inbound
m_LastHop->SetNextRouter (&i2p::context.GetRouterInfo ());
}

Loading…
Cancel
Save