mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2024-11-16 00:12:43 +00:00
try both ipv4 and ipv6 NTCP2 addresses if presented
This commit is contained in:
parent
1a9e11d86d
commit
e0cec79ad6
@ -935,6 +935,24 @@ namespace data
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<const RouterInfo::Address> RouterInfo::GetPublishedNTCP2V4Address () const
|
||||||
|
{
|
||||||
|
return GetAddress (
|
||||||
|
[](std::shared_ptr<const RouterInfo::Address> address)->bool
|
||||||
|
{
|
||||||
|
return address->IsPublishedNTCP2 () && address->host.is_v4 ();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<const RouterInfo::Address> RouterInfo::GetPublishedNTCP2V6Address () const
|
||||||
|
{
|
||||||
|
return GetAddress (
|
||||||
|
[](std::shared_ptr<const RouterInfo::Address> address)->bool
|
||||||
|
{
|
||||||
|
return address->IsPublishedNTCP2 () && address->host.is_v6 ();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
std::shared_ptr<RouterProfile> RouterInfo::GetProfile () const
|
std::shared_ptr<RouterProfile> RouterInfo::GetProfile () const
|
||||||
{
|
{
|
||||||
if (!m_Profile)
|
if (!m_Profile)
|
||||||
|
@ -154,6 +154,8 @@ namespace data
|
|||||||
int GetVersion () const { return m_Version; };
|
int GetVersion () const { return m_Version; };
|
||||||
Addresses& GetAddresses () { return *m_Addresses; }; // should be called for local RI only, otherwise must return shared_ptr
|
Addresses& GetAddresses () { return *m_Addresses; }; // should be called for local RI only, otherwise must return shared_ptr
|
||||||
std::shared_ptr<const Address> GetNTCP2Address (bool publishedOnly, bool v4only = true) const;
|
std::shared_ptr<const Address> GetNTCP2Address (bool publishedOnly, bool v4only = true) const;
|
||||||
|
std::shared_ptr<const Address> GetPublishedNTCP2V4Address () const;
|
||||||
|
std::shared_ptr<const Address> GetPublishedNTCP2V6Address () const;
|
||||||
std::shared_ptr<const Address> GetSSUAddress (bool v4only = true) const;
|
std::shared_ptr<const Address> GetSSUAddress (bool v4only = true) const;
|
||||||
std::shared_ptr<const Address> GetSSUV6Address () const;
|
std::shared_ptr<const Address> GetSSUV6Address () const;
|
||||||
|
|
||||||
|
@ -389,13 +389,23 @@ namespace transport
|
|||||||
peer.router = netdb.FindRouter (ident); // try to get new one from netdb
|
peer.router = netdb.FindRouter (ident); // try to get new one from netdb
|
||||||
if (peer.router) // we have RI already
|
if (peer.router) // we have RI already
|
||||||
{
|
{
|
||||||
if (!peer.numAttempts) // NTCP2
|
if (peer.numAttempts < 2) // NTCP2, 0 - ipv6, 1- ipv4
|
||||||
{
|
{
|
||||||
peer.numAttempts++;
|
|
||||||
if (m_NTCP2Server) // we support NTCP2
|
if (m_NTCP2Server) // we support NTCP2
|
||||||
{
|
{
|
||||||
// NTCP2 have priority over NTCP
|
std::shared_ptr<const RouterInfo::Address> address;
|
||||||
auto address = peer.router->GetNTCP2Address (true, !context.SupportsV6 ()); // published only
|
if (!peer.numAttempts) // NTCP2 ipv6
|
||||||
|
{
|
||||||
|
if (context.SupportsV6 ())
|
||||||
|
address = peer.router->GetPublishedNTCP2V6Address ();
|
||||||
|
peer.numAttempts++;
|
||||||
|
}
|
||||||
|
if (!address && peer.numAttempts == 1) // NTCP2 ipv4
|
||||||
|
{
|
||||||
|
if (context.SupportsV4 ())
|
||||||
|
address = peer.router->GetPublishedNTCP2V4Address ();
|
||||||
|
peer.numAttempts++;
|
||||||
|
}
|
||||||
if (address && !peer.router->IsUnreachable () && (!m_CheckReserved || !i2p::util::net::IsInReservedRange(address->host)))
|
if (address && !peer.router->IsUnreachable () && (!m_CheckReserved || !i2p::util::net::IsInReservedRange(address->host)))
|
||||||
{
|
{
|
||||||
auto s = std::make_shared<NTCP2Session> (*m_NTCP2Server, peer.router, address);
|
auto s = std::make_shared<NTCP2Session> (*m_NTCP2Server, peer.router, address);
|
||||||
@ -415,8 +425,10 @@ namespace transport
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
peer.numAttempts = 2; // switch to SSU
|
||||||
}
|
}
|
||||||
if (peer.numAttempts == 1)// SSU
|
if (peer.numAttempts == 2)// SSU
|
||||||
{
|
{
|
||||||
peer.numAttempts++;
|
peer.numAttempts++;
|
||||||
if (m_SSUServer && peer.router->IsSSU (!context.SupportsV6 ()))
|
if (m_SSUServer && peer.router->IsSSU (!context.SupportsV6 ()))
|
||||||
|
Loading…
Reference in New Issue
Block a user