mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 21:37:17 +01:00
select first hop from existing connections if applicable
This commit is contained in:
parent
7f172964f6
commit
d2b4a6fd50
|
@ -489,6 +489,14 @@ namespace transport
|
||||||
m_PeerCleanupTimer.async_wait (std::bind (&Transports::HandlePeerCleanupTimer, this, std::placeholders::_1));
|
m_PeerCleanupTimer.async_wait (std::bind (&Transports::HandlePeerCleanupTimer, this, std::placeholders::_1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<const i2p::data::RouterInfo> Transports::GetRandomPeer () const
|
||||||
|
{
|
||||||
|
CryptoPP::RandomNumberGenerator& rnd = i2p::context.GetRandomNumberGenerator ();
|
||||||
|
auto it = m_Peers.begin ();
|
||||||
|
std::advance (it, rnd.GenerateWord32 (0, m_Peers.size () - 1));
|
||||||
|
return it != m_Peers.end () ? it->second.router : nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -98,6 +98,8 @@ namespace transport
|
||||||
uint32_t GetInBandwidth () const { return m_InBandwidth; }; // bytes per second
|
uint32_t GetInBandwidth () const { return m_InBandwidth; }; // bytes per second
|
||||||
uint32_t GetOutBandwidth () const { return m_OutBandwidth; }; // bytes per second
|
uint32_t GetOutBandwidth () const { return m_OutBandwidth; }; // bytes per second
|
||||||
bool IsBandwidthExceeded () const;
|
bool IsBandwidthExceeded () const;
|
||||||
|
size_t GetNumPeers () const { return m_Peers.size (); };
|
||||||
|
std::shared_ptr<const i2p::data::RouterInfo> GetRandomPeer () const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include "NetDb.h"
|
#include "NetDb.h"
|
||||||
#include "Timestamp.h"
|
#include "Timestamp.h"
|
||||||
#include "Garlic.h"
|
#include "Garlic.h"
|
||||||
|
#include "Transports.h"
|
||||||
#include "TunnelPool.h"
|
#include "TunnelPool.h"
|
||||||
|
|
||||||
namespace i2p
|
namespace i2p
|
||||||
|
@ -341,10 +342,20 @@ namespace tunnel
|
||||||
if (inboundTunnel)
|
if (inboundTunnel)
|
||||||
{
|
{
|
||||||
LogPrint ("Creating destination outbound tunnel...");
|
LogPrint ("Creating destination outbound tunnel...");
|
||||||
|
int numHops = m_NumOutboundHops;
|
||||||
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_NumOutboundHops; i++)
|
if (i2p::transport::transports.GetNumPeers () > 25)
|
||||||
|
{
|
||||||
|
auto r = i2p::transport::transports.GetRandomPeer ();
|
||||||
|
if (r)
|
||||||
|
{
|
||||||
|
prevHop = r;
|
||||||
|
hops.push_back (r);
|
||||||
|
numHops--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int i = 0; i < numHops; i++)
|
||||||
{
|
{
|
||||||
auto hop = SelectNextHop (prevHop);
|
auto hop = SelectNextHop (prevHop);
|
||||||
if (!hop)
|
if (!hop)
|
||||||
|
|
Loading…
Reference in a new issue