1
0
mirror of https://github.com/PurpleI2P/i2pd.git synced 2025-01-22 12:24:19 +00:00

select high bandwidth routers for client tunnels

This commit is contained in:
orignal 2014-09-25 21:08:20 -04:00
parent c4ec2ea297
commit 79d2f69837
4 changed files with 42 additions and 17 deletions

View File

@ -785,22 +785,34 @@ namespace data
} }
} }
const RouterInfo * NetDb::GetRandomRouter () const
{
return GetRandomRouter (
[](const RouterInfo * router)->bool
{
return !router->IsHidden ();
});
}
const RouterInfo * NetDb::GetRandomRouter (const RouterInfo * compatibleWith) const const RouterInfo * NetDb::GetRandomRouter (const RouterInfo * compatibleWith) const
{ {
if (compatibleWith) return GetRandomRouter (
return GetRandomRouter ( [compatibleWith](const RouterInfo * router)->bool
[compatibleWith](const RouterInfo * router)->bool {
{ return !router->IsHidden () && router->IsCompatible (*compatibleWith);
return !router->IsHidden () && router->IsCompatible (*compatibleWith); });
});
else
return GetRandomRouter (
[](const RouterInfo * router)->bool
{
return !router->IsHidden ();
});
} }
const RouterInfo * NetDb::GetHighBandwidthRandomRouter (const RouterInfo * compatibleWith) const
{
return GetRandomRouter (
[compatibleWith](const RouterInfo * router)->bool
{
return !router->IsHidden () && router->IsCompatible (*compatibleWith) &&
(router->GetCaps () & RouterInfo::eHighBandwidth);
});
}
template<typename Filter> template<typename Filter>
const RouterInfo * NetDb::GetRandomRouter (Filter filter) const const RouterInfo * NetDb::GetRandomRouter (Filter filter) const
{ {

View File

@ -79,8 +79,10 @@ namespace data
void HandleDatabaseSearchReplyMsg (I2NPMessage * msg); void HandleDatabaseSearchReplyMsg (I2NPMessage * msg);
void HandleDatabaseLookupMsg (I2NPMessage * msg); void HandleDatabaseLookupMsg (I2NPMessage * msg);
const RouterInfo * GetRandomRouter (const RouterInfo * compatibleWith = nullptr) const; const RouterInfo * GetRandomRouter () const;
const RouterInfo * GetRandomRouter (const RouterInfo * compatibleWith) const;
const RouterInfo * GetHighBandwidthRandomRouter (const RouterInfo * compatibleWith) const;
void PostI2NPMsg (I2NPMessage * msg); void PostI2NPMsg (I2NPMessage * msg);
// for web interface // for web interface

View File

@ -197,6 +197,15 @@ namespace tunnel
i2p::garlic::routing.PostI2NPMsg (msg); i2p::garlic::routing.PostI2NPMsg (msg);
} }
const i2p::data::RouterInfo * TunnelPool::SelectNextHop (const i2p::data::RouterInfo * prevHop) const
{
auto hop = m_NumHops >= 3 ? i2p::data::netdb.GetHighBandwidthRandomRouter (prevHop) :
i2p::data::netdb.GetRandomRouter (prevHop);
if (!hop)
hop = i2p::data::netdb.GetRandomRouter ();
return hop;
}
void TunnelPool::CreateInboundTunnel () void TunnelPool::CreateInboundTunnel ()
{ {
OutboundTunnel * outboundTunnel = GetNextOutboundTunnel (); OutboundTunnel * outboundTunnel = GetNextOutboundTunnel ();
@ -219,7 +228,7 @@ namespace tunnel
} }
for (int i = 0; i < numHops; i++) for (int i = 0; i < numHops; i++)
{ {
auto hop = i2p::data::netdb.GetRandomRouter (prevHop); auto hop = SelectNextHop (prevHop);
prevHop = hop; prevHop = hop;
hops.push_back (hop); hops.push_back (hop);
} }
@ -251,7 +260,7 @@ namespace tunnel
std::vector<const i2p::data::RouterInfo *> hops; std::vector<const i2p::data::RouterInfo *> hops;
for (int i = 0; i < m_NumHops; i++) for (int i = 0; i < m_NumHops; i++)
{ {
auto hop = i2p::data::netdb.GetRandomRouter (prevHop); auto hop = SelectNextHop (prevHop);
prevHop = hop; prevHop = hop;
hops.push_back (hop); hops.push_back (hop);
} }
@ -263,7 +272,7 @@ namespace tunnel
else else
LogPrint ("Can't create outbound tunnel. No inbound tunnels found"); LogPrint ("Can't create outbound tunnel. No inbound tunnels found");
} }
void TunnelPool::RecreateOutboundTunnel (OutboundTunnel * tunnel) void TunnelPool::RecreateOutboundTunnel (OutboundTunnel * tunnel)
{ {
InboundTunnel * inboundTunnel = GetNextInboundTunnel (); InboundTunnel * inboundTunnel = GetNextInboundTunnel ();

View File

@ -7,6 +7,7 @@
#include <utility> #include <utility>
#include "Identity.h" #include "Identity.h"
#include "LeaseSet.h" #include "LeaseSet.h"
#include "RouterInfo.h"
#include "I2NPProtocol.h" #include "I2NPProtocol.h"
#include "TunnelBase.h" #include "TunnelBase.h"
#include "RouterContext.h" #include "RouterContext.h"
@ -53,6 +54,7 @@ namespace tunnel
template<class TTunnels> template<class TTunnels>
typename TTunnels::value_type GetNextTunnel (TTunnels& tunnels, typename TTunnels::value_type GetNextTunnel (TTunnels& tunnels,
typename TTunnels::value_type suggested = nullptr); typename TTunnels::value_type suggested = nullptr);
const i2p::data::RouterInfo * SelectNextHop (const i2p::data::RouterInfo * prevHop) const;
private: private: