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
{ {
CryptoPP::DH dh (i2p::crypto::elgp, i2p::crypto::elgg); CryptoPP::DH dh (i2p::crypto::elgp, i2p::crypto::elgg);
dh.GenerateKeyPair(i2p::context.GetRandomNumberGenerator (), m_EncryptionPrivateKey, m_EncryptionPublicKey); 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) if (m_IsPublic)
LogPrint ("Local address ", GetIdentHash ().ToBase32 (), ".b32.i2p created"); LogPrint ("Local address ", GetIdentHash ().ToBase32 (), ".b32.i2p created");
m_StreamingDestination = new i2p::stream::StreamingDestination (*this); // TODO: m_StreamingDestination = new i2p::stream::StreamingDestination (*this); // TODO:

6
Tunnel.cpp

@ -287,9 +287,9 @@ namespace tunnel
return 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); std::unique_lock<std::mutex> l(m_PoolsMutex);
m_Pools[pool->GetIdentHash ()] = pool; m_Pools[pool->GetIdentHash ()] = pool;
return pool; return pool;
@ -510,7 +510,7 @@ namespace tunnel
LogPrint ("Creating zero hops inbound tunnel..."); LogPrint ("Creating zero hops inbound tunnel...");
CreateZeroHopsInboundTunnel (); CreateZeroHopsInboundTunnel ();
if (!m_ExploratoryPool) if (!m_ExploratoryPool)
m_ExploratoryPool = CreateTunnelPool (i2p::context, 2); // 2-hop exploratory m_ExploratoryPool = CreateTunnelPool (i2p::context, 2, 2); // 2-hop exploratory
return; return;
} }

2
Tunnel.h

@ -129,7 +129,7 @@ namespace tunnel
void PostTunnelData (I2NPMessage * msg); void PostTunnelData (I2NPMessage * msg);
template<class TTunnel> template<class TTunnel>
TTunnel * CreateTunnel (TunnelConfig * config, OutboundTunnel * outboundTunnel = 0); 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 DeleteTunnelPool (TunnelPool * pool);
void StopTunnelPool (TunnelPool * pool); void StopTunnelPool (TunnelPool * pool);

16
TunnelPool.cpp

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

4
TunnelPool.h

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

Loading…
Cancel
Save