Skip to content

Commit

Permalink
different tunnel length for IB and OB
Browse files Browse the repository at this point in the history
  • Loading branch information
orignal committed Nov 30, 2014
1 parent 5e83d95 commit 3ca560b
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Destination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions Tunnel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion Tunnel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
16 changes: 9 additions & 7 deletions TunnelPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}

Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions TunnelPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 (); };
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 3ca560b

Please sign in to comment.