From 846eac29dc482fb5809e79dc05d4b0d49dcfe081 Mon Sep 17 00:00:00 2001 From: orignal Date: Sun, 24 Feb 2019 18:26:58 -0500 Subject: [PATCH] filter out unspecified addresses. Check floodfill status change --- libi2pd/NetDb.cpp | 17 ++++++++++--- libi2pd/RouterInfo.cpp | 18 ++++++++++---- libi2pd/RouterInfo.h | 1 + libi2pd/Transports.cpp | 56 ++++++++++++++---------------------------- 4 files changed, 46 insertions(+), 46 deletions(-) diff --git a/libi2pd/NetDb.cpp b/libi2pd/NetDb.cpp index 0c4ce89e..9d858d91 100644 --- a/libi2pd/NetDb.cpp +++ b/libi2pd/NetDb.cpp @@ -207,9 +207,18 @@ namespace data { if (r->IsNewer (buf, len)) { + bool wasFloodfill = r->IsFloodfill (); r->Update (buf, len); LogPrint (eLogInfo, "NetDb: RouterInfo updated: ", ident.ToBase64()); - // TODO: check if floodfill has been changed + if (wasFloodfill != r->IsFloodfill ()) // if floodfill status updated + { + LogPrint (eLogDebug, "NetDb: RouterInfo floodfill status updated: ", ident.ToBase64()); + std::unique_lock l(m_FloodfillsMutex); + if (wasFloodfill) + m_Floodfills.remove (r); + else + m_Floodfills.push_back (r); + } } else { @@ -220,7 +229,7 @@ namespace data else { r = std::make_shared (buf, len); - if (!r->IsUnreachable ()) + if (!r->IsUnreachable () && r->HasValidAddresses ()) { bool inserted = false; { @@ -559,11 +568,11 @@ namespace data ++it; } } - // clean up expired floodfills + // clean up expired floodfills or not floodfills anymore { std::unique_lock l(m_FloodfillsMutex); for (auto it = m_Floodfills.begin (); it != m_Floodfills.end ();) - if ((*it)->IsUnreachable ()) + if ((*it)->IsUnreachable () || !(*it)->IsFloodfill ()) it = m_Floodfills.erase (it); else ++it; diff --git a/libi2pd/RouterInfo.cpp b/libi2pd/RouterInfo.cpp index ca357e45..aecda51e 100644 --- a/libi2pd/RouterInfo.cpp +++ b/libi2pd/RouterInfo.cpp @@ -210,11 +210,19 @@ namespace data address->host = boost::asio::ip::address::from_string (value, ecode); if (!ecode) { - // add supported protocol - if (address->host.is_v4 ()) - supportedTransports |= (address->transportStyle == eTransportNTCP) ? eNTCPV4 : eSSUV4; - else - supportedTransports |= (address->transportStyle == eTransportNTCP) ? eNTCPV6 : eSSUV6; +#if BOOST_VERSION >= 104900 + if (!address->host.is_unspecified ()) // check if address is valid +#else + address->host.to_string (ecode); + if (!ecode) +#endif + { + // add supported protocol + if (address->host.is_v4 ()) + supportedTransports |= (address->transportStyle == eTransportNTCP) ? eNTCPV4 : eSSUV4; + else + supportedTransports |= (address->transportStyle == eTransportNTCP) ? eNTCPV6 : eSSUV6; + } } } else if (!strcmp (key, "port")) diff --git a/libi2pd/RouterInfo.h b/libi2pd/RouterInfo.h index c417c21d..084ad8a7 100644 --- a/libi2pd/RouterInfo.h +++ b/libi2pd/RouterInfo.h @@ -169,6 +169,7 @@ namespace data void EnableV4 (); void DisableV4 (); bool IsCompatible (const RouterInfo& other) const { return m_SupportedTransports & other.m_SupportedTransports; }; + bool HasValidAddresses () const { return m_SupportedTransports; }; bool UsesIntroducer () const; bool IsIntroducer () const { return m_Caps & eSSUIntroducer; }; bool IsPeerTesting () const { return m_Caps & eSSUTesting; }; diff --git a/libi2pd/Transports.cpp b/libi2pd/Transports.cpp index f2fc5c12..c00e5d52 100644 --- a/libi2pd/Transports.cpp +++ b/libi2pd/Transports.cpp @@ -426,37 +426,28 @@ namespace transport auto address = peer.router->GetNTCPAddress (!context.SupportsV6 ()); if (address && m_NTCPServer) { -#if BOOST_VERSION >= 104900 - if (!address->host.is_unspecified ()) // we have address now -#else - boost::system::error_code ecode; - address->host.to_string (ecode); - if (!ecode) -#endif + if (!peer.router->UsesIntroducer () && !peer.router->IsUnreachable ()) { - if (!peer.router->UsesIntroducer () && !peer.router->IsUnreachable ()) + if(!m_NTCPServer->ShouldLimit()) { - if(!m_NTCPServer->ShouldLimit()) + auto s = std::make_shared (*m_NTCPServer, peer.router); + if(m_NTCPServer->UsingProxy()) { - auto s = std::make_shared (*m_NTCPServer, peer.router); - if(m_NTCPServer->UsingProxy()) - { - NTCPServer::RemoteAddressType remote = NTCPServer::eIP4Address; - std::string addr = address->host.to_string(); - - if(address->host.is_v6()) - remote = NTCPServer::eIP6Address; - - m_NTCPServer->ConnectWithProxy(addr, address->port, remote, s); - } - else - m_NTCPServer->Connect (address->host, address->port, s); - return true; + NTCPServer::RemoteAddressType remote = NTCPServer::eIP4Address; + std::string addr = address->host.to_string(); + + if(address->host.is_v6()) + remote = NTCPServer::eIP6Address; + + m_NTCPServer->ConnectWithProxy(addr, address->port, remote, s); } else - { - LogPrint(eLogWarning, "Transports: NTCP Limit hit falling back to SSU"); - } + m_NTCPServer->Connect (address->host, address->port, s); + return true; + } + else + { + LogPrint(eLogWarning, "Transports: NTCP Limit hit falling back to SSU"); } } } @@ -469,17 +460,8 @@ namespace transport if (m_SSUServer && peer.router->IsSSU (!context.SupportsV6 ())) { auto address = peer.router->GetSSUAddress (!context.SupportsV6 ()); -#if BOOST_VERSION >= 104900 - if (!address->host.is_unspecified ()) // we have address now -#else - boost::system::error_code ecode; - address->host.to_string (ecode); - if (!ecode) -#endif - { - m_SSUServer->CreateSession (peer.router, address->host, address->port); - return true; - } + m_SSUServer->CreateSession (peer.router, address->host, address->port); + return true; } } LogPrint (eLogInfo, "Transports: No NTCP or SSU addresses available");