|
|
@ -742,15 +742,17 @@ namespace data |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (IsV6 ()) |
|
|
|
if (IsV6 ()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
for (auto& it : *m_Addresses) |
|
|
|
if ((*m_Addresses)[eNTCP2V6Idx]) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (it && it->IsV6 ()) |
|
|
|
if ((*m_Addresses)[eNTCP2V6Idx]->IsV4 ()) |
|
|
|
{ |
|
|
|
(*m_Addresses)[eNTCP2V6Idx]->caps &= ~AddressCaps::eV6; |
|
|
|
if (it->IsV4 ()) |
|
|
|
(*m_Addresses)[eNTCP2V6Idx].reset (); |
|
|
|
it->caps &= ~AddressCaps::eV6; |
|
|
|
} |
|
|
|
else |
|
|
|
if ((*m_Addresses)[eSSU2V6Idx]) |
|
|
|
it.reset (); |
|
|
|
{ |
|
|
|
} |
|
|
|
if ((*m_Addresses)[eSSU2V6Idx]->IsV4 ()) |
|
|
|
|
|
|
|
(*m_Addresses)[eSSU2V6Idx]->caps &= ~AddressCaps::eV6; |
|
|
|
|
|
|
|
(*m_Addresses)[eSSU2V6Idx].reset (); |
|
|
|
} |
|
|
|
} |
|
|
|
UpdateSupportedTransports (); |
|
|
|
UpdateSupportedTransports (); |
|
|
|
} |
|
|
|
} |
|
|
@ -760,15 +762,17 @@ namespace data |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (IsV4 ()) |
|
|
|
if (IsV4 ()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
for (auto& it : *m_Addresses) |
|
|
|
if ((*m_Addresses)[eNTCP2V4Idx]) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (it && it->IsV4 ()) |
|
|
|
if ((*m_Addresses)[eNTCP2V4Idx]->IsV6 ()) |
|
|
|
{ |
|
|
|
(*m_Addresses)[eNTCP2V4Idx]->caps &= ~AddressCaps::eV4; |
|
|
|
if (it->IsV6 ()) |
|
|
|
(*m_Addresses)[eNTCP2V4Idx].reset (); |
|
|
|
it->caps &= ~AddressCaps::eV4; |
|
|
|
} |
|
|
|
else |
|
|
|
if ((*m_Addresses)[eSSU2V4Idx]) |
|
|
|
it.reset (); |
|
|
|
{ |
|
|
|
} |
|
|
|
if ((*m_Addresses)[eSSU2V4Idx]->IsV6 ()) |
|
|
|
|
|
|
|
(*m_Addresses)[eSSU2V4Idx]->caps &= ~AddressCaps::eV4; |
|
|
|
|
|
|
|
(*m_Addresses)[eSSU2V4Idx].reset (); |
|
|
|
} |
|
|
|
} |
|
|
|
UpdateSupportedTransports (); |
|
|
|
UpdateSupportedTransports (); |
|
|
|
} |
|
|
|
} |
|
|
@ -789,11 +793,7 @@ namespace data |
|
|
|
{ |
|
|
|
{ |
|
|
|
m_SupportedTransports &= ~eNTCP2V6Mesh; |
|
|
|
m_SupportedTransports &= ~eNTCP2V6Mesh; |
|
|
|
m_ReachableTransports &= ~eNTCP2V6Mesh; |
|
|
|
m_ReachableTransports &= ~eNTCP2V6Mesh; |
|
|
|
for (auto& it: *m_Addresses) |
|
|
|
(*m_Addresses)[eNTCP2V6MeshIdx].reset (); |
|
|
|
{ |
|
|
|
|
|
|
|
if (it && i2p::util::net::IsYggdrasilAddress (it->host)) |
|
|
|
|
|
|
|
it.reset (); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -859,12 +859,10 @@ namespace data |
|
|
|
std::shared_ptr<const RouterInfo::Address> RouterInfo::GetSSU2AddressWithStaticKey (const uint8_t * key, bool isV6) const |
|
|
|
std::shared_ptr<const RouterInfo::Address> RouterInfo::GetSSU2AddressWithStaticKey (const uint8_t * key, bool isV6) const |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!key) return nullptr; |
|
|
|
if (!key) return nullptr; |
|
|
|
return GetAddress ( |
|
|
|
auto addr = (*GetAddresses ())[isV6 ? eSSU2V6Idx : eSSU2V4Idx]; |
|
|
|
[key, isV6](std::shared_ptr<const RouterInfo::Address> address)->bool |
|
|
|
if (addr && !memcmp (addr->s, key, 32)) |
|
|
|
{ |
|
|
|
return addr; |
|
|
|
return address->IsSSU2 () && !memcmp (address->s, key, 32) && |
|
|
|
return nullptr; |
|
|
|
((isV6 && address->IsV6 ()) || (!isV6 && address->IsV4 ())); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<const RouterInfo::Address> RouterInfo::GetPublishedNTCP2V4Address () const |
|
|
|
std::shared_ptr<const RouterInfo::Address> RouterInfo::GetPublishedNTCP2V4Address () const |
|
|
@ -910,23 +908,15 @@ namespace data |
|
|
|
bool RouterInfo::IsSSU2PeerTesting (bool v4) const |
|
|
|
bool RouterInfo::IsSSU2PeerTesting (bool v4) const |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!(m_SupportedTransports & (v4 ? eSSU2V4 : eSSU2V6))) return false; |
|
|
|
if (!(m_SupportedTransports & (v4 ? eSSU2V4 : eSSU2V6))) return false; |
|
|
|
return (bool)GetAddress ( |
|
|
|
auto addr = (*GetAddresses ())[v4 ? eSSU2V4Idx : eSSU2V6Idx]; |
|
|
|
[v4](std::shared_ptr<const RouterInfo::Address> address)->bool |
|
|
|
return addr && addr->IsPeerTesting () && addr->IsReachableSSU (); |
|
|
|
{ |
|
|
|
|
|
|
|
return (address->IsSSU2 ()) && address->IsPeerTesting () && |
|
|
|
|
|
|
|
((v4 && address->IsV4 ()) || (!v4 && address->IsV6 ())) && address->IsReachableSSU (); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool RouterInfo::IsSSU2Introducer (bool v4) const |
|
|
|
bool RouterInfo::IsSSU2Introducer (bool v4) const |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!(m_SupportedTransports & (v4 ? eSSU2V4 : eSSU2V6))) return false; |
|
|
|
if (!(m_SupportedTransports & (v4 ? eSSU2V4 : eSSU2V6))) return false; |
|
|
|
return (bool)GetAddress ( |
|
|
|
auto addr = (*GetAddresses ())[v4 ? eSSU2V4Idx : eSSU2V6Idx]; |
|
|
|
[v4](std::shared_ptr<const RouterInfo::Address> address)->bool |
|
|
|
return addr && addr->IsIntroducer () && !addr->host.is_unspecified () && addr->port; |
|
|
|
{ |
|
|
|
|
|
|
|
return (address->IsSSU2 ()) && address->IsIntroducer () && |
|
|
|
|
|
|
|
((v4 && address->IsV4 ()) || (!v4 && address->IsV6 ())) && !address->host.is_unspecified (); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void RouterInfo::SetUnreachableAddressesTransportCaps (uint8_t transports) |
|
|
|
void RouterInfo::SetUnreachableAddressesTransportCaps (uint8_t transports) |
|
|
@ -1269,16 +1259,14 @@ namespace data |
|
|
|
{ |
|
|
|
{ |
|
|
|
auto addresses = GetAddresses (); |
|
|
|
auto addresses = GetAddresses (); |
|
|
|
if (!addresses) return false; |
|
|
|
if (!addresses) return false; |
|
|
|
for (auto& addr : *addresses) |
|
|
|
auto addr = (*addresses)[v4 ? eSSU2V4Idx : eSSU2V6Idx]; |
|
|
|
|
|
|
|
if (addr) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (addr && addr->IsSSU2 () && ((v4 && addr->IsV4 ()) || (!v4 && addr->IsV6 ()))) |
|
|
|
for (auto& intro: addr->ssu->introducers) |
|
|
|
{ |
|
|
|
if (intro.iTag == introducer.iTag) return false; // already presented
|
|
|
|
for (auto& intro: addr->ssu->introducers) |
|
|
|
addr->ssu->introducers.push_back (introducer); |
|
|
|
if (intro.iTag == introducer.iTag) return false; // already presented
|
|
|
|
SetReachableTransports (GetReachableTransports () | ((addr->IsV4 () ? eSSU2V4 : eSSU2V6))); |
|
|
|
addr->ssu->introducers.push_back (introducer); |
|
|
|
return true; |
|
|
|
SetReachableTransports (GetReachableTransports () | ((addr->IsV4 () ? eSSU2V4 : eSSU2V6))); |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
@ -1287,19 +1275,17 @@ namespace data |
|
|
|
{ |
|
|
|
{ |
|
|
|
auto addresses = GetAddresses (); |
|
|
|
auto addresses = GetAddresses (); |
|
|
|
if (!addresses) return false; |
|
|
|
if (!addresses) return false; |
|
|
|
for (auto& addr: *addresses) |
|
|
|
auto addr = (*addresses)[v4 ? eSSU2V4Idx : eSSU2V6Idx]; |
|
|
|
|
|
|
|
if (addr) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (addr && addr->IsSSU2 () && ((v4 && addr->IsV4 ()) || (!v4 && addr->IsV6 ()))) |
|
|
|
for (auto it = addr->ssu->introducers.begin (); it != addr->ssu->introducers.end (); ++it) |
|
|
|
{ |
|
|
|
if (h == it->iH) |
|
|
|
for (auto it = addr->ssu->introducers.begin (); it != addr->ssu->introducers.end (); ++it) |
|
|
|
{ |
|
|
|
if (h == it->iH) |
|
|
|
addr->ssu->introducers.erase (it); |
|
|
|
{ |
|
|
|
if (addr->ssu->introducers.empty ()) |
|
|
|
addr->ssu->introducers.erase (it); |
|
|
|
SetReachableTransports (GetReachableTransports () & ~(addr->IsV4 () ? eSSU2V4 : eSSU2V6)); |
|
|
|
if (addr->ssu->introducers.empty ()) |
|
|
|
return true; |
|
|
|
SetReachableTransports (GetReachableTransports () & ~(addr->IsV4 () ? eSSU2V4 : eSSU2V6)); |
|
|
|
} |
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|