mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 04:04:16 +00:00
recognize routers with NTCP2
This commit is contained in:
parent
a70d0edf2e
commit
4f23d7b7df
@ -244,6 +244,18 @@ namespace data
|
||||
}
|
||||
else if (!strcmp (key, "caps"))
|
||||
ExtractCaps (value);
|
||||
else if (!strcmp (key, "s")) // ntcp2 static key
|
||||
{
|
||||
if (!address->ntcp2) address->ntcp2.reset (new NTCP2Ext ());
|
||||
supportedTransports |= (address->host.is_v4 ()) ? eNTCP2V4 : eNTCP2V6;
|
||||
Base64ToByteStream (value, strlen (value), address->ntcp2->staticKey, 32);
|
||||
}
|
||||
else if (!strcmp (key, "i")) // ntcp2 iv
|
||||
{
|
||||
if (!address->ntcp2) address->ntcp2.reset (new NTCP2Ext ());
|
||||
supportedTransports |= (address->host.is_v4 ()) ? eNTCP2V4 : eNTCP2V6;
|
||||
Base64ToByteStream (value, strlen (value), address->ntcp2->iv, 16);
|
||||
}
|
||||
else if (key[0] == 'i')
|
||||
{
|
||||
// introducers
|
||||
@ -735,6 +747,14 @@ namespace data
|
||||
return m_SupportedTransports & (eSSUV4 | eSSUV6);
|
||||
}
|
||||
|
||||
bool RouterInfo::IsNTCP2 (bool v4only) const
|
||||
{
|
||||
if (v4only)
|
||||
return m_SupportedTransports & eNTCP2V4;
|
||||
else
|
||||
return m_SupportedTransports & (eNTCP2V4 | eNTCP2V6);
|
||||
}
|
||||
|
||||
bool RouterInfo::IsV6 () const
|
||||
{
|
||||
return m_SupportedTransports & (eNTCPV6 | eSSUV6);
|
||||
@ -742,19 +762,19 @@ namespace data
|
||||
|
||||
bool RouterInfo::IsV4 () const
|
||||
{
|
||||
return m_SupportedTransports & (eNTCPV4 | eSSUV4);
|
||||
return m_SupportedTransports & (eNTCPV4 | eSSUV4 | eNTCP2V4);
|
||||
}
|
||||
|
||||
void RouterInfo::EnableV6 ()
|
||||
{
|
||||
if (!IsV6 ())
|
||||
m_SupportedTransports |= eNTCPV6 | eSSUV6;
|
||||
m_SupportedTransports |= eNTCPV6 | eSSUV6 | eNTCP2V6;
|
||||
}
|
||||
|
||||
void RouterInfo::EnableV4 ()
|
||||
{
|
||||
if (!IsV4 ())
|
||||
m_SupportedTransports |= eNTCPV4 | eSSUV4;
|
||||
m_SupportedTransports |= eNTCPV4 | eSSUV4 | eNTCP2V4;
|
||||
}
|
||||
|
||||
|
||||
@ -762,7 +782,7 @@ namespace data
|
||||
{
|
||||
if (IsV6 ())
|
||||
{
|
||||
m_SupportedTransports &= ~(eNTCPV6 | eSSUV6);
|
||||
m_SupportedTransports &= ~(eNTCPV6 | eSSUV6 | eNTCP2V6);
|
||||
for (auto it = m_Addresses->begin (); it != m_Addresses->end ();)
|
||||
{
|
||||
auto addr = *it;
|
||||
@ -778,7 +798,7 @@ namespace data
|
||||
{
|
||||
if (IsV4 ())
|
||||
{
|
||||
m_SupportedTransports &= ~(eNTCPV4 | eSSUV4);
|
||||
m_SupportedTransports &= ~(eNTCPV4 | eSSUV4 | eNTCP2V4);
|
||||
for (auto it = m_Addresses->begin (); it != m_Addresses->end ();)
|
||||
{
|
||||
auto addr = *it;
|
||||
|
@ -48,7 +48,9 @@ namespace data
|
||||
eNTCPV4 = 0x01,
|
||||
eNTCPV6 = 0x02,
|
||||
eSSUV4 = 0x04,
|
||||
eSSUV6 = 0x08
|
||||
eSSUV6 = 0x08,
|
||||
eNTCP2V4 = 0x10,
|
||||
eNTCP2V6 = 0x20
|
||||
};
|
||||
|
||||
enum Caps
|
||||
@ -88,6 +90,12 @@ namespace data
|
||||
std::vector<Introducer> introducers;
|
||||
};
|
||||
|
||||
struct NTCP2Ext
|
||||
{
|
||||
uint8_t staticKey[32];
|
||||
uint8_t iv[16];
|
||||
};
|
||||
|
||||
struct Address
|
||||
{
|
||||
TransportStyle transportStyle;
|
||||
@ -97,6 +105,7 @@ namespace data
|
||||
uint64_t date;
|
||||
uint8_t cost;
|
||||
std::unique_ptr<SSUExt> ssu; // not null for SSU
|
||||
std::unique_ptr<NTCP2Ext> ntcp2; // not null for NTCP2
|
||||
|
||||
bool IsCompatible (const boost::asio::ip::address& other) const
|
||||
{
|
||||
@ -144,6 +153,7 @@ namespace data
|
||||
bool IsReachable () const { return m_Caps & Caps::eReachable; };
|
||||
bool IsNTCP (bool v4only = true) const;
|
||||
bool IsSSU (bool v4only = true) const;
|
||||
bool IsNTCP2 (bool v4only = true) const;
|
||||
bool IsV6 () const;
|
||||
bool IsV4 () const;
|
||||
void EnableV6 ();
|
||||
|
Loading…
x
Reference in New Issue
Block a user