Browse Source

select ipv4 peers for peer test

pull/731/head
orignal 8 years ago
parent
commit
7a7ae4cc83
  1. 6
      NetDb.cpp
  2. 2
      NetDb.h
  3. 4
      SSU.cpp
  4. 2
      SSU.h
  5. 21
      Transports.cpp

6
NetDb.cpp

@ -1008,12 +1008,12 @@ namespace data
}); });
} }
std::shared_ptr<const RouterInfo> NetDb::GetRandomPeerTestRouter () const std::shared_ptr<const RouterInfo> NetDb::GetRandomPeerTestRouter (bool v4only) const
{ {
return GetRandomRouter ( return GetRandomRouter (
[](std::shared_ptr<const RouterInfo> router)->bool [v4only](std::shared_ptr<const RouterInfo> router)->bool
{ {
return !router->IsHidden () && router->IsPeerTesting (); return !router->IsHidden () && router->IsPeerTesting () && router->IsSSU (v4only);
}); });
} }

2
NetDb.h

@ -69,7 +69,7 @@ namespace data
std::shared_ptr<const RouterInfo> GetRandomRouter () const; std::shared_ptr<const RouterInfo> GetRandomRouter () const;
std::shared_ptr<const RouterInfo> GetRandomRouter (std::shared_ptr<const RouterInfo> compatibleWith) const; std::shared_ptr<const RouterInfo> GetRandomRouter (std::shared_ptr<const RouterInfo> compatibleWith) const;
std::shared_ptr<const RouterInfo> GetHighBandwidthRandomRouter (std::shared_ptr<const RouterInfo> compatibleWith) const; std::shared_ptr<const RouterInfo> GetHighBandwidthRandomRouter (std::shared_ptr<const RouterInfo> compatibleWith) const;
std::shared_ptr<const RouterInfo> GetRandomPeerTestRouter () const; std::shared_ptr<const RouterInfo> GetRandomPeerTestRouter (bool v4only = true) const;
std::shared_ptr<const RouterInfo> GetRandomIntroducer () const; std::shared_ptr<const RouterInfo> GetRandomIntroducer () const;
std::shared_ptr<const RouterInfo> GetClosestFloodfill (const IdentHash& destination, const std::set<IdentHash>& excluded, bool closeThanUsOnly = false) const; std::shared_ptr<const RouterInfo> GetClosestFloodfill (const IdentHash& destination, const std::set<IdentHash>& excluded, bool closeThanUsOnly = false) const;
std::vector<IdentHash> GetClosestFloodfills (const IdentHash& destination, size_t num, std::vector<IdentHash> GetClosestFloodfills (const IdentHash& destination, size_t num,

4
SSU.cpp

@ -342,9 +342,9 @@ namespace transport
return nullptr; return nullptr;
} }
void SSUServer::CreateSession (std::shared_ptr<const i2p::data::RouterInfo> router, bool peerTest) void SSUServer::CreateSession (std::shared_ptr<const i2p::data::RouterInfo> router, bool peerTest, bool v4only)
{ {
auto address = router->GetSSUAddress (!context.SupportsV6 ()); auto address = router->GetSSUAddress (v4only || !context.SupportsV6 ());
if (address) if (address)
CreateSession (router, address->host, address->port, peerTest); CreateSession (router, address->host, address->port, peerTest);
else else

2
SSU.h

@ -42,7 +42,7 @@ namespace transport
~SSUServer (); ~SSUServer ();
void Start (); void Start ();
void Stop (); void Stop ();
void CreateSession (std::shared_ptr<const i2p::data::RouterInfo> router, bool peerTest = false); void CreateSession (std::shared_ptr<const i2p::data::RouterInfo> router, bool peerTest = false, bool v4only = false);
void CreateSession (std::shared_ptr<const i2p::data::RouterInfo> router, void CreateSession (std::shared_ptr<const i2p::data::RouterInfo> router,
const boost::asio::ip::address& addr, int port, bool peerTest = false); const boost::asio::ip::address& addr, int port, bool peerTest = false);
void CreateDirectSession (std::shared_ptr<const i2p::data::RouterInfo> router, boost::asio::ip::udp::endpoint remoteEndpoint, bool peerTest); void CreateDirectSession (std::shared_ptr<const i2p::data::RouterInfo> router, boost::asio::ip::udp::endpoint remoteEndpoint, bool peerTest);

21
Transports.cpp

@ -519,7 +519,7 @@ namespace transport
void Transports::DetectExternalIP () void Transports::DetectExternalIP ()
{ {
if (RoutesRestricted()) if (RoutesRestricted())
{ {
LogPrint(eLogInfo, "Transports: restricted routes enabled, not detecting ip"); LogPrint(eLogInfo, "Transports: restricted routes enabled, not detecting ip");
i2p::context.SetStatus (eRouterStatusOK); i2p::context.SetStatus (eRouterStatusOK);
return; return;
@ -527,13 +527,14 @@ namespace transport
if (m_SSUServer) if (m_SSUServer)
{ {
bool nat; i2p::config::GetOption("nat", nat); bool nat; i2p::config::GetOption("nat", nat);
if (nat) bool isv4 = i2p::context.SupportsV4 ();
if (nat && isv4)
i2p::context.SetStatus (eRouterStatusTesting); i2p::context.SetStatus (eRouterStatusTesting);
for (int i = 0; i < 5; i++) for (int i = 0; i < 5; i++)
{ {
auto router = i2p::data::netdb.GetRandomPeerTestRouter (); auto router = i2p::data::netdb.GetRandomPeerTestRouter (isv4); // v4 only if v4
if (router && router->IsSSU (!context.SupportsV6 ())) if (router)
m_SSUServer->CreateSession (router, true); // peer test m_SSUServer->CreateSession (router, true, isv4); // peer test
else else
{ {
// if not peer test capable routers found pick any // if not peer test capable routers found pick any
@ -549,23 +550,25 @@ namespace transport
void Transports::PeerTest () void Transports::PeerTest ()
{ {
if (RoutesRestricted()) return; if (RoutesRestricted() || !i2p::context.SupportsV4 ()) return;
if (m_SSUServer) if (m_SSUServer)
{ {
bool statusChanged = false; bool statusChanged = false;
for (int i = 0; i < 5; i++) for (int i = 0; i < 5; i++)
{ {
auto router = i2p::data::netdb.GetRandomPeerTestRouter (); auto router = i2p::data::netdb.GetRandomPeerTestRouter (true); // v4 only
if (router && router->IsSSU (!context.SupportsV6 ())) if (router)
{ {
if (!statusChanged) if (!statusChanged)
{ {
statusChanged = true; statusChanged = true;
i2p::context.SetStatus (eRouterStatusTesting); // first time only i2p::context.SetStatus (eRouterStatusTesting); // first time only
} }
m_SSUServer->CreateSession (router, true); // peer test m_SSUServer->CreateSession (router, true, true); // peer test v4
} }
} }
if (!statusChanged)
LogPrint (eLogWarning, "Can't find routers for peer test");
} }
} }

Loading…
Cancel
Save