diff --git a/libi2pd/RouterInfo.cpp b/libi2pd/RouterInfo.cpp
index afbaadbf..a1c8821f 100644
--- a/libi2pd/RouterInfo.cpp
+++ b/libi2pd/RouterInfo.cpp
@@ -198,14 +198,14 @@ namespace data
auto address = std::make_shared
();
s.read ((char *)&address->cost, sizeof (address->cost));
s.read ((char *)&address->date, sizeof (address->date));
- bool isNTCP2Only = false;
+ bool isHost = false, isIntroKey = false, isStaticKey = false;
char transportStyle[6];
- auto transportStyleLen = ReadString (transportStyle, 6, s) - 1;
+ ReadString (transportStyle, 6, s);
if (!strncmp (transportStyle, "NTCP", 4)) // NTCP or NTCP2
- {
+ {
address->transportStyle = eTransportNTCP;
- if (transportStyleLen > 4 && transportStyle[4] == '2') isNTCP2Only= true;
- }
+ address->ntcp2.reset (new NTCP2Ext ());
+ }
else if (!strcmp (transportStyle, "SSU"))
{
address->transportStyle = eTransportSSU;
@@ -230,22 +230,7 @@ namespace data
{
boost::system::error_code ecode;
address->host = boost::asio::ip::address::from_string (value, ecode);
- if (!ecode)
- {
-#if BOOST_VERSION >= 104900
- if (!address->host.is_unspecified ()) // check if address is valid
-#else
- address->host.to_string (ecode);
- if (!ecode)
-#endif
- {
- // add supported protocol
- if (address->host.is_v4 ())
- supportedTransports |= (address->transportStyle == eTransportNTCP) ? eNTCPV4 : eSSUV4;
- else
- supportedTransports |= (address->transportStyle == eTransportNTCP) ? eNTCPV6 : eSSUV6;
- }
- }
+ if (!ecode && !address->host.is_unspecified ()) isHost = true;
}
else if (!strcmp (key, "port"))
address->port = boost::lexical_cast(value);
@@ -259,7 +244,7 @@ namespace data
else if (!strcmp (key, "key"))
{
if (address->ssu)
- Base64ToByteStream (value, strlen (value), address->ssu->key, 32);
+ isIntroKey = (Base64ToByteStream (value, strlen (value), address->ssu->key, 32) == 32);
else
LogPrint (eLogWarning, "RouterInfo: Unexpected field 'key' for NTCP");
}
@@ -267,14 +252,11 @@ namespace data
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);
+ isStaticKey = true;
}
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);
address->ntcp2->isPublished = true; // presence if "i" means "published"
}
@@ -314,9 +296,22 @@ namespace data
}
if (!s) return;
}
- if (introducers) supportedTransports |= eSSUV4; // in case if host is not presented
- if (isNTCP2Only && address->ntcp2) address->ntcp2->isNTCP2Only = true;
- if (supportedTransports & ~(eNTCPV4 | eNTCPV6)) // exclude NTCP only
+ if (address->transportStyle == eTransportNTCP)
+ {
+ if (isStaticKey && isHost)
+ supportedTransports |= address->host.is_v4 () ? eNTCP2V4 : eNTCP2V6;
+ }
+ else if (address->transportStyle == eTransportSSU)
+ {
+ if (isIntroKey)
+ {
+ if (isHost)
+ supportedTransports |= address->host.is_v4 () ? eSSUV4 : eSSUV6;
+ else
+ if (introducers) supportedTransports |= eSSUV4; // in case if host is not presented
+ }
+ }
+ if (supportedTransports)
{
addresses->push_back(address);
m_SupportedTransports |= supportedTransports;
@@ -741,7 +736,6 @@ namespace data
addr->cost = port ? 3 : 14; // override from RouterContext::PublishNTCP2Address
addr->date = 0;
addr->ntcp2.reset (new NTCP2Ext ());
- addr->ntcp2->isNTCP2Only = true; // NTCP2 only address
if (port) addr->ntcp2->isPublished = true;
memcpy (addr->ntcp2->staticKey, staticKey, 32);
memcpy (addr->ntcp2->iv, iv, 16);
@@ -834,24 +828,24 @@ namespace data
bool RouterInfo::IsV6 () const
{
- return m_SupportedTransports & (eNTCPV6 | eSSUV6 | eNTCP2V6);
+ return m_SupportedTransports & (eSSUV6 | eNTCP2V6);
}
bool RouterInfo::IsV4 () const
{
- return m_SupportedTransports & (eNTCPV4 | eSSUV4 | eNTCP2V4);
+ return m_SupportedTransports & (eSSUV4 | eNTCP2V4);
}
void RouterInfo::EnableV6 ()
{
if (!IsV6 ())
- m_SupportedTransports |= eNTCPV6 | eSSUV6 | eNTCP2V6;
+ m_SupportedTransports |= eSSUV6 | eNTCP2V6;
}
void RouterInfo::EnableV4 ()
{
if (!IsV4 ())
- m_SupportedTransports |= eNTCPV4 | eSSUV4 | eNTCP2V4;
+ m_SupportedTransports |= eSSUV4 | eNTCP2V4;
}
@@ -859,7 +853,7 @@ namespace data
{
if (IsV6 ())
{
- m_SupportedTransports &= ~(eNTCPV6 | eSSUV6 | eNTCP2V6);
+ m_SupportedTransports &= ~(eSSUV6 | eNTCP2V6);
for (auto it = m_Addresses->begin (); it != m_Addresses->end ();)
{
auto addr = *it;
@@ -875,7 +869,7 @@ namespace data
{
if (IsV4 ())
{
- m_SupportedTransports &= ~(eNTCPV4 | eSSUV4 | eNTCP2V4);
+ m_SupportedTransports &= ~(eSSUV4 | eNTCP2V4);
for (auto it = m_Addresses->begin (); it != m_Addresses->end ();)
{
auto addr = *it;
diff --git a/libi2pd/RouterInfo.h b/libi2pd/RouterInfo.h
index ff767a8b..a5303e84 100644
--- a/libi2pd/RouterInfo.h
+++ b/libi2pd/RouterInfo.h
@@ -54,12 +54,10 @@ namespace data
enum SupportedTranports
{
- eNTCPV4 = 0x01,
- eNTCPV6 = 0x02,
+ eNTCP2V4 = 0x01,
+ eNTCP2V6 = 0x02,
eSSUV4 = 0x04,
- eSSUV6 = 0x08,
- eNTCP2V4 = 0x10,
- eNTCP2V6 = 0x20
+ eSSUV6 = 0x08
};
enum Caps
@@ -104,7 +102,6 @@ namespace data
Tag<32> staticKey;
Tag<16> iv;
bool isPublished = false;
- bool isNTCP2Only = false;
};
struct Address
@@ -136,7 +133,6 @@ namespace data
bool IsNTCP2 () const { return (bool)ntcp2; };
bool IsPublishedNTCP2 () const { return IsNTCP2 () && ntcp2->isPublished; };
- bool IsNTCP2Only () const { return ntcp2 && ntcp2->isNTCP2Only; };
};
typedef std::list > Addresses;