Browse Source

filter out unspecified addresses. Check floodfill status change

pull/1285/merge
orignal 6 years ago
parent
commit
846eac29dc
  1. 17
      libi2pd/NetDb.cpp
  2. 18
      libi2pd/RouterInfo.cpp
  3. 1
      libi2pd/RouterInfo.h
  4. 56
      libi2pd/Transports.cpp

17
libi2pd/NetDb.cpp

@ -207,9 +207,18 @@ namespace data
{ {
if (r->IsNewer (buf, len)) if (r->IsNewer (buf, len))
{ {
bool wasFloodfill = r->IsFloodfill ();
r->Update (buf, len); r->Update (buf, len);
LogPrint (eLogInfo, "NetDb: RouterInfo updated: ", ident.ToBase64()); 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<std::mutex> l(m_FloodfillsMutex);
if (wasFloodfill)
m_Floodfills.remove (r);
else
m_Floodfills.push_back (r);
}
} }
else else
{ {
@ -220,7 +229,7 @@ namespace data
else else
{ {
r = std::make_shared<RouterInfo> (buf, len); r = std::make_shared<RouterInfo> (buf, len);
if (!r->IsUnreachable ()) if (!r->IsUnreachable () && r->HasValidAddresses ())
{ {
bool inserted = false; bool inserted = false;
{ {
@ -559,11 +568,11 @@ namespace data
++it; ++it;
} }
} }
// clean up expired floodfills // clean up expired floodfills or not floodfills anymore
{ {
std::unique_lock<std::mutex> l(m_FloodfillsMutex); std::unique_lock<std::mutex> l(m_FloodfillsMutex);
for (auto it = m_Floodfills.begin (); it != m_Floodfills.end ();) for (auto it = m_Floodfills.begin (); it != m_Floodfills.end ();)
if ((*it)->IsUnreachable ()) if ((*it)->IsUnreachable () || !(*it)->IsFloodfill ())
it = m_Floodfills.erase (it); it = m_Floodfills.erase (it);
else else
++it; ++it;

18
libi2pd/RouterInfo.cpp

@ -210,11 +210,19 @@ namespace data
address->host = boost::asio::ip::address::from_string (value, ecode); address->host = boost::asio::ip::address::from_string (value, ecode);
if (!ecode) if (!ecode)
{ {
// add supported protocol #if BOOST_VERSION >= 104900
if (address->host.is_v4 ()) if (!address->host.is_unspecified ()) // check if address is valid
supportedTransports |= (address->transportStyle == eTransportNTCP) ? eNTCPV4 : eSSUV4; #else
else address->host.to_string (ecode);
supportedTransports |= (address->transportStyle == eTransportNTCP) ? eNTCPV6 : eSSUV6; 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")) else if (!strcmp (key, "port"))

1
libi2pd/RouterInfo.h

@ -169,6 +169,7 @@ namespace data
void EnableV4 (); void EnableV4 ();
void DisableV4 (); void DisableV4 ();
bool IsCompatible (const RouterInfo& other) const { return m_SupportedTransports & other.m_SupportedTransports; }; bool IsCompatible (const RouterInfo& other) const { return m_SupportedTransports & other.m_SupportedTransports; };
bool HasValidAddresses () const { return m_SupportedTransports; };
bool UsesIntroducer () const; bool UsesIntroducer () const;
bool IsIntroducer () const { return m_Caps & eSSUIntroducer; }; bool IsIntroducer () const { return m_Caps & eSSUIntroducer; };
bool IsPeerTesting () const { return m_Caps & eSSUTesting; }; bool IsPeerTesting () const { return m_Caps & eSSUTesting; };

56
libi2pd/Transports.cpp

@ -426,37 +426,28 @@ namespace transport
auto address = peer.router->GetNTCPAddress (!context.SupportsV6 ()); auto address = peer.router->GetNTCPAddress (!context.SupportsV6 ());
if (address && m_NTCPServer) if (address && m_NTCPServer)
{ {
#if BOOST_VERSION >= 104900 if (!peer.router->UsesIntroducer () && !peer.router->IsUnreachable ())
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(!m_NTCPServer->ShouldLimit())
{ {
if(!m_NTCPServer->ShouldLimit()) auto s = std::make_shared<NTCPSession> (*m_NTCPServer, peer.router);
if(m_NTCPServer->UsingProxy())
{ {
auto s = std::make_shared<NTCPSession> (*m_NTCPServer, peer.router); NTCPServer::RemoteAddressType remote = NTCPServer::eIP4Address;
if(m_NTCPServer->UsingProxy()) std::string addr = address->host.to_string();
{
NTCPServer::RemoteAddressType remote = NTCPServer::eIP4Address; if(address->host.is_v6())
std::string addr = address->host.to_string(); remote = NTCPServer::eIP6Address;
if(address->host.is_v6()) m_NTCPServer->ConnectWithProxy(addr, address->port, remote, s);
remote = NTCPServer::eIP6Address;
m_NTCPServer->ConnectWithProxy(addr, address->port, remote, s);
}
else
m_NTCPServer->Connect (address->host, address->port, s);
return true;
} }
else else
{ m_NTCPServer->Connect (address->host, address->port, s);
LogPrint(eLogWarning, "Transports: NTCP Limit hit falling back to SSU"); 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 ())) if (m_SSUServer && peer.router->IsSSU (!context.SupportsV6 ()))
{ {
auto address = peer.router->GetSSUAddress (!context.SupportsV6 ()); auto address = peer.router->GetSSUAddress (!context.SupportsV6 ());
#if BOOST_VERSION >= 104900 m_SSUServer->CreateSession (peer.router, address->host, address->port);
if (!address->host.is_unspecified ()) // we have address now return true;
#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;
}
} }
} }
LogPrint (eLogInfo, "Transports: No NTCP or SSU addresses available"); LogPrint (eLogInfo, "Transports: No NTCP or SSU addresses available");

Loading…
Cancel
Save