Browse Source

recognize routers with NTCP2

pull/1194/head
orignal 7 years ago
parent
commit
4f23d7b7df
  1. 30
      libi2pd/RouterInfo.cpp
  2. 12
      libi2pd/RouterInfo.h

30
libi2pd/RouterInfo.cpp

@ -244,6 +244,18 @@ namespace data
} }
else if (!strcmp (key, "caps")) else if (!strcmp (key, "caps"))
ExtractCaps (value); 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') else if (key[0] == 'i')
{ {
// introducers // introducers
@ -735,6 +747,14 @@ namespace data
return m_SupportedTransports & (eSSUV4 | eSSUV6); 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 bool RouterInfo::IsV6 () const
{ {
return m_SupportedTransports & (eNTCPV6 | eSSUV6); return m_SupportedTransports & (eNTCPV6 | eSSUV6);
@ -742,19 +762,19 @@ namespace data
bool RouterInfo::IsV4 () const bool RouterInfo::IsV4 () const
{ {
return m_SupportedTransports & (eNTCPV4 | eSSUV4); return m_SupportedTransports & (eNTCPV4 | eSSUV4 | eNTCP2V4);
} }
void RouterInfo::EnableV6 () void RouterInfo::EnableV6 ()
{ {
if (!IsV6 ()) if (!IsV6 ())
m_SupportedTransports |= eNTCPV6 | eSSUV6; m_SupportedTransports |= eNTCPV6 | eSSUV6 | eNTCP2V6;
} }
void RouterInfo::EnableV4 () void RouterInfo::EnableV4 ()
{ {
if (!IsV4 ()) if (!IsV4 ())
m_SupportedTransports |= eNTCPV4 | eSSUV4; m_SupportedTransports |= eNTCPV4 | eSSUV4 | eNTCP2V4;
} }
@ -762,7 +782,7 @@ namespace data
{ {
if (IsV6 ()) if (IsV6 ())
{ {
m_SupportedTransports &= ~(eNTCPV6 | eSSUV6); m_SupportedTransports &= ~(eNTCPV6 | eSSUV6 | eNTCP2V6);
for (auto it = m_Addresses->begin (); it != m_Addresses->end ();) for (auto it = m_Addresses->begin (); it != m_Addresses->end ();)
{ {
auto addr = *it; auto addr = *it;
@ -778,7 +798,7 @@ namespace data
{ {
if (IsV4 ()) if (IsV4 ())
{ {
m_SupportedTransports &= ~(eNTCPV4 | eSSUV4); m_SupportedTransports &= ~(eNTCPV4 | eSSUV4 | eNTCP2V4);
for (auto it = m_Addresses->begin (); it != m_Addresses->end ();) for (auto it = m_Addresses->begin (); it != m_Addresses->end ();)
{ {
auto addr = *it; auto addr = *it;

12
libi2pd/RouterInfo.h

@ -48,7 +48,9 @@ namespace data
eNTCPV4 = 0x01, eNTCPV4 = 0x01,
eNTCPV6 = 0x02, eNTCPV6 = 0x02,
eSSUV4 = 0x04, eSSUV4 = 0x04,
eSSUV6 = 0x08 eSSUV6 = 0x08,
eNTCP2V4 = 0x10,
eNTCP2V6 = 0x20
}; };
enum Caps enum Caps
@ -88,6 +90,12 @@ namespace data
std::vector<Introducer> introducers; std::vector<Introducer> introducers;
}; };
struct NTCP2Ext
{
uint8_t staticKey[32];
uint8_t iv[16];
};
struct Address struct Address
{ {
TransportStyle transportStyle; TransportStyle transportStyle;
@ -97,6 +105,7 @@ namespace data
uint64_t date; uint64_t date;
uint8_t cost; uint8_t cost;
std::unique_ptr<SSUExt> ssu; // not null for SSU 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 bool IsCompatible (const boost::asio::ip::address& other) const
{ {
@ -144,6 +153,7 @@ namespace data
bool IsReachable () const { return m_Caps & Caps::eReachable; }; bool IsReachable () const { return m_Caps & Caps::eReachable; };
bool IsNTCP (bool v4only = true) const; bool IsNTCP (bool v4only = true) const;
bool IsSSU (bool v4only = true) const; bool IsSSU (bool v4only = true) const;
bool IsNTCP2 (bool v4only = true) const;
bool IsV6 () const; bool IsV6 () const;
bool IsV4 () const; bool IsV4 () const;
void EnableV6 (); void EnableV6 ();

Loading…
Cancel
Save