Browse Source

different tunnel length for IB and OB

pull/113/head
orignal 10 years ago
parent
commit
3ca560b895
  1. 2
      Destination.cpp
  2. 6
      Tunnel.cpp
  3. 2
      Tunnel.h
  4. 16
      TunnelPool.cpp
  5. 4
      TunnelPool.h

2
Destination.cpp

@ -16,7 +16,7 @@ namespace client @@ -16,7 +16,7 @@ namespace client
{
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, 3); // 3-hops tunnel
m_Pool = i2p::tunnel::tunnels.CreateTunnelPool (*this, 3, 3); // 3-hops tunnel
if (m_IsPublic)
LogPrint ("Local address ", GetIdentHash ().ToBase32 (), ".b32.i2p created");
m_StreamingDestination = new i2p::stream::StreamingDestination (*this); // TODO:

6
Tunnel.cpp

@ -287,9 +287,9 @@ namespace tunnel @@ -287,9 +287,9 @@ namespace tunnel
return tunnel;
}
TunnelPool * Tunnels::CreateTunnelPool (i2p::garlic::GarlicDestination& localDestination, int numHops)
TunnelPool * Tunnels::CreateTunnelPool (i2p::garlic::GarlicDestination& localDestination, int numInboundHops, int numOutboundHops)
{
auto pool = new TunnelPool (localDestination, numHops);
auto pool = new TunnelPool (localDestination, numInboundHops, numOutboundHops);
std::unique_lock<std::mutex> l(m_PoolsMutex);
m_Pools[pool->GetIdentHash ()] = pool;
return pool;
@ -510,7 +510,7 @@ namespace tunnel @@ -510,7 +510,7 @@ namespace tunnel
LogPrint ("Creating zero hops inbound tunnel...");
CreateZeroHopsInboundTunnel ();
if (!m_ExploratoryPool)
m_ExploratoryPool = CreateTunnelPool (i2p::context, 2); // 2-hop exploratory
m_ExploratoryPool = CreateTunnelPool (i2p::context, 2, 2); // 2-hop exploratory
return;
}

2
Tunnel.h

@ -129,7 +129,7 @@ namespace tunnel @@ -129,7 +129,7 @@ namespace tunnel
void PostTunnelData (I2NPMessage * msg);
template<class TTunnel>
TTunnel * CreateTunnel (TunnelConfig * config, OutboundTunnel * outboundTunnel = 0);
TunnelPool * CreateTunnelPool (i2p::garlic::GarlicDestination& localDestination, int numHops);
TunnelPool * CreateTunnelPool (i2p::garlic::GarlicDestination& localDestination, int numInboundHops, int numOuboundHops);
void DeleteTunnelPool (TunnelPool * pool);
void StopTunnelPool (TunnelPool * pool);

16
TunnelPool.cpp

@ -10,9 +10,9 @@ namespace i2p @@ -10,9 +10,9 @@ namespace i2p
{
namespace tunnel
{
TunnelPool::TunnelPool (i2p::garlic::GarlicDestination& localDestination, int numHops, int numTunnels):
m_LocalDestination (localDestination), m_NumHops (numHops), m_NumTunnels (numTunnels),
m_IsActive (true)
TunnelPool::TunnelPool (i2p::garlic::GarlicDestination& localDestination, int numInboundHops, int numOutboundHops, int numTunnels):
m_LocalDestination (localDestination), m_NumInboundHops (numInboundHops), m_NumOutboundHops (numOutboundHops),
m_NumTunnels (numTunnels), m_IsActive (true)
{
}
@ -244,8 +244,10 @@ namespace tunnel @@ -244,8 +244,10 @@ namespace tunnel
std::shared_ptr<const i2p::data::RouterInfo> TunnelPool::SelectNextHop (std::shared_ptr<const i2p::data::RouterInfo> prevHop) const
{
auto hop = m_NumHops >= 3 ? i2p::data::netdb.GetHighBandwidthRandomRouter (prevHop) :
i2p::data::netdb.GetRandomRouter (prevHop);
bool isExploratory = (&m_LocalDestination == &i2p::context); // TODO: implement it better
auto hop = isExploratory ? i2p::data::netdb.GetRandomRouter (prevHop):
i2p::data::netdb.GetHighBandwidthRandomRouter (prevHop);
if (!hop)
hop = i2p::data::netdb.GetRandomRouter ();
return hop;
@ -259,7 +261,7 @@ namespace tunnel @@ -259,7 +261,7 @@ namespace tunnel
LogPrint ("Creating destination inbound tunnel...");
auto prevHop = i2p::context.GetSharedRouterInfo ();
std::vector<std::shared_ptr<const i2p::data::RouterInfo> > hops;
int numHops = m_NumHops;
int numHops = m_NumInboundHops;
if (outboundTunnel)
{
// last hop
@ -303,7 +305,7 @@ namespace tunnel @@ -303,7 +305,7 @@ namespace tunnel
auto prevHop = i2p::context.GetSharedRouterInfo ();
std::vector<std::shared_ptr<const i2p::data::RouterInfo> > hops;
for (int i = 0; i < m_NumHops; i++)
for (int i = 0; i < m_NumOutboundHops; i++)
{
auto hop = SelectNextHop (prevHop);
prevHop = hop;

4
TunnelPool.h

@ -26,7 +26,7 @@ namespace tunnel @@ -26,7 +26,7 @@ namespace tunnel
{
public:
TunnelPool (i2p::garlic::GarlicDestination& localDestination, int numHops, int numTunnels = 5);
TunnelPool (i2p::garlic::GarlicDestination& localDestination, int numInboundHops, int numOutboundHops, int numTunnels = 5);
~TunnelPool ();
const uint8_t * GetEncryptionPrivateKey () const { return m_LocalDestination.GetEncryptionPrivateKey (); };
@ -66,7 +66,7 @@ namespace tunnel @@ -66,7 +66,7 @@ namespace tunnel
private:
i2p::garlic::GarlicDestination& m_LocalDestination;
int m_NumHops, m_NumTunnels;
int m_NumInboundHops, m_NumOutboundHops, m_NumTunnels;
mutable std::mutex m_InboundTunnelsMutex;
std::set<InboundTunnel *, TunnelCreationTimeCmp> m_InboundTunnels; // recent tunnel appears first
mutable std::mutex m_OutboundTunnelsMutex;

Loading…
Cancel
Save