specify number of hops for a tunnel pool

This commit is contained in:
orignal 2014-06-25 19:28:33 -04:00
parent 92dc9b3542
commit ec21138bd2
6 changed files with 25 additions and 20 deletions

View File

@ -340,7 +340,7 @@ namespace stream
CryptoPP::Integer (m_Keys.signingPrivateKey, 20));
CryptoPP::DH dh (i2p::crypto::elgp, i2p::crypto::elgg);
dh.GenerateKeyPair(i2p::context.GetRandomNumberGenerator (), m_EncryptionPrivateKey, m_EncryptionPublicKey);
m_Pool = i2p::tunnel::tunnels.CreateTunnelPool (*this);
m_Pool = i2p::tunnel::tunnels.CreateTunnelPool (*this, 3); // 3-hops tunnel
}
StreamingDestination::StreamingDestination (const std::string& fullPath): m_LeaseSet (nullptr)
@ -356,7 +356,7 @@ namespace stream
CryptoPP::Integer (m_Keys.signingPrivateKey, 20));
CryptoPP::DH dh (i2p::crypto::elgp, i2p::crypto::elgg);
dh.GenerateKeyPair(i2p::context.GetRandomNumberGenerator (), m_EncryptionPrivateKey, m_EncryptionPublicKey);
m_Pool = i2p::tunnel::tunnels.CreateTunnelPool (*this);
m_Pool = i2p::tunnel::tunnels.CreateTunnelPool (*this, 3); // 3-hops tunnel
}
StreamingDestination::~StreamingDestination ()

View File

@ -275,9 +275,9 @@ namespace tunnel
return tunnel;
}
TunnelPool * Tunnels::CreateTunnelPool (i2p::data::LocalDestination& localDestination)
TunnelPool * Tunnels::CreateTunnelPool (i2p::data::LocalDestination& localDestination, int numHops)
{
auto pool = new TunnelPool (localDestination);
auto pool = new TunnelPool (localDestination, numHops);
m_Pools[pool->GetIdentHash ()] = pool;
return pool;
}
@ -441,7 +441,7 @@ namespace tunnel
LogPrint ("Creating zero hops inbound tunnel...");
CreateZeroHopsInboundTunnel ();
if (!m_ExploratoryPool)
m_ExploratoryPool = CreateTunnelPool (i2p::context);
m_ExploratoryPool = CreateTunnelPool (i2p::context, 2); // 2-hop exploratory
return;
}

View File

@ -114,7 +114,7 @@ namespace tunnel
void PostTunnelData (I2NPMessage * msg);
template<class TTunnel>
TTunnel * CreateTunnel (TunnelConfig * config, OutboundTunnel * outboundTunnel = 0);
TunnelPool * CreateTunnelPool (i2p::data::LocalDestination& localDestination);
TunnelPool * CreateTunnelPool (i2p::data::LocalDestination& localDestination, int numHops);
void DeleteTunnelPool (TunnelPool * pool);
private:

View File

@ -134,9 +134,9 @@ namespace tunnel
return m_LastHop;
}
size_t GetNumHops () const
int GetNumHops () const
{
size_t num = 0;
int num = 0;
TunnelHopConfig * hop = m_FirstHop;
while (hop)
{
@ -183,6 +183,8 @@ namespace tunnel
newConfig->m_LastHop = newHop;
if (hop->isGateway) // inbound tunnel
newHop->SetReplyHop (m_FirstHop); // use it as reply tunnel
else
newHop->SetNextRouter (&i2p::context.GetRouterInfo ());
}
if (!hop->next) newConfig->m_FirstHop = newHop; // last hop

View File

@ -10,8 +10,8 @@ namespace i2p
{
namespace tunnel
{
TunnelPool::TunnelPool (i2p::data::LocalDestination& localDestination, int numTunnels):
m_LocalDestination (localDestination), m_NumTunnels (numTunnels), m_LastOutboundTunnel (nullptr)
TunnelPool::TunnelPool (i2p::data::LocalDestination& localDestination, int numHops, int numTunnels):
m_LocalDestination (localDestination), m_NumHops (numHops), m_NumTunnels (numTunnels), m_LastOutboundTunnel (nullptr)
{
}
@ -189,15 +189,18 @@ namespace tunnel
if (inboundTunnel)
{
LogPrint ("Creating destination outbound tunnel...");
auto firstHop = i2p::data::netdb.GetRandomRouter (&i2p::context.GetRouterInfo ());
auto secondHop = i2p::data::netdb.GetRandomRouter (firstHop);
auto * tunnel = tunnels.CreateTunnel<OutboundTunnel> (
new TunnelConfig (std::vector<const i2p::data::RouterInfo *>
const i2p::data::RouterInfo * prevHop = &i2p::context.GetRouterInfo ();
std::vector<const i2p::data::RouterInfo *> hops;
for (int i = 0; i < m_NumHops; i++)
{
firstHop,
secondHop
},
inboundTunnel->GetTunnelConfig ()));
auto hop = i2p::data::netdb.GetRandomRouter (prevHop);
prevHop = hop;
hops.push_back (hop);
}
auto * tunnel = tunnels.CreateTunnel<OutboundTunnel> (
new TunnelConfig (hops, inboundTunnel->GetTunnelConfig ()));
tunnel->SetTunnelPool (this);
}
}

View File

@ -23,7 +23,7 @@ namespace tunnel
{
public:
TunnelPool (i2p::data::LocalDestination& localDestination, int numTunnels = 5);
TunnelPool (i2p::data::LocalDestination& localDestination, int numHops, int numTunnels = 5);
~TunnelPool ();
const uint8_t * GetEncryptionPrivateKey () const { return m_LocalDestination.GetEncryptionPrivateKey (); };
@ -53,7 +53,7 @@ namespace tunnel
private:
i2p::data::LocalDestination& m_LocalDestination;
int m_NumTunnels;
int m_NumHops, m_NumTunnels;
std::set<InboundTunnel *, TunnelCreationTimeCmp> m_InboundTunnels; // recent tunnel appears first
std::set<OutboundTunnel *, TunnelCreationTimeCmp> m_OutboundTunnels;
std::map<uint32_t, std::pair<OutboundTunnel *, InboundTunnel *> > m_Tests;