Browse Source

check if router is reachable by transport before obtaining address

pull/1677/head
orignal 3 years ago
parent
commit
2185019b59
  1. 5
      libi2pd/RouterInfo.cpp
  2. 3
      libi2pd/RouterInfo.h
  3. 8
      libi2pd/Transports.cpp

5
libi2pd/RouterInfo.cpp

@ -1179,11 +1179,6 @@ namespace data @@ -1179,11 +1179,6 @@ namespace data
});
}
bool RouterInfo::IsReachableFrom (const RouterInfo& other) const
{
return m_ReachableTransports & other.m_SupportedTransports;
}
void RouterInfo::SetUnreachableAddressesTransportCaps (uint8_t transports)
{
for (auto& addr: *m_Addresses)

3
libi2pd/RouterInfo.h

@ -204,7 +204,8 @@ namespace data @@ -204,7 +204,8 @@ namespace data
void EnableMesh ();
void DisableMesh ();
bool IsCompatible (const RouterInfo& other) const { return m_SupportedTransports & other.m_SupportedTransports; };
bool IsReachableFrom (const RouterInfo& other) const;
bool IsReachableFrom (const RouterInfo& other) const { return m_ReachableTransports & other.m_SupportedTransports; };
bool IsReachableBy (SupportedTransports transport) const { return m_ReachableTransports & transport; };
bool HasValidAddresses () const { return m_SupportedTransports; };
bool IsHidden () const { return m_Caps & eHidden; };
bool IsHighBandwidth () const { return m_Caps & RouterInfo::eHighBandwidth; };

8
libi2pd/Transports.cpp

@ -447,7 +447,7 @@ namespace transport @@ -447,7 +447,7 @@ namespace transport
std::shared_ptr<const RouterInfo::Address> address;
if (!peer.numAttempts) // NTCP2 ipv6
{
if (context.GetRouterInfo ().IsNTCP2V6 () && peer.router->IsNTCP2V6 ())
if (context.GetRouterInfo ().IsNTCP2V6 () && peer.router->IsReachableBy (RouterInfo::eNTCP2V6))
{
address = peer.router->GetPublishedNTCP2V6Address ();
if (address && m_CheckReserved && i2p::util::net::IsInReservedRange(address->host))
@ -457,7 +457,7 @@ namespace transport @@ -457,7 +457,7 @@ namespace transport
}
if (!address && peer.numAttempts == 1) // NTCP2 ipv4
{
if (context.GetRouterInfo ().IsNTCP2 (true) && peer.router->IsNTCP2 (true) && !peer.router->IsUnreachable ())
if (context.GetRouterInfo ().IsNTCP2 (true) && peer.router->IsReachableBy (RouterInfo::eNTCP2V4))
{
address = peer.router->GetPublishedNTCP2V4Address ();
if (address && m_CheckReserved && i2p::util::net::IsInReservedRange(address->host))
@ -485,7 +485,7 @@ namespace transport @@ -485,7 +485,7 @@ namespace transport
std::shared_ptr<const RouterInfo::Address> address;
if (peer.numAttempts == 2) // SSU ipv6
{
if (context.GetRouterInfo ().IsSSUV6 () && peer.router->IsSSUV6 ())
if (context.GetRouterInfo ().IsSSUV6 () && peer.router->IsReachableBy (RouterInfo::eSSUV6))
{
address = peer.router->GetSSUV6Address ();
if (address && m_CheckReserved && i2p::util::net::IsInReservedRange(address->host))
@ -495,7 +495,7 @@ namespace transport @@ -495,7 +495,7 @@ namespace transport
}
if (!address && peer.numAttempts == 3) // SSU ipv4
{
if (context.GetRouterInfo ().IsSSU (true) && peer.router->IsSSU (true))
if (context.GetRouterInfo ().IsSSU (true) && peer.router->IsReachableBy (RouterInfo::eSSUV4))
{
address = peer.router->GetSSUAddress (true);
if (address && m_CheckReserved && i2p::util::net::IsInReservedRange(address->host))

Loading…
Cancel
Save