|
|
@ -215,6 +215,7 @@ namespace data |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
address->transportStyle = eTransportUnknown; |
|
|
|
address->transportStyle = eTransportUnknown; |
|
|
|
|
|
|
|
address->caps = 0; |
|
|
|
address->port = 0; |
|
|
|
address->port = 0; |
|
|
|
uint16_t size, r = 0; |
|
|
|
uint16_t size, r = 0; |
|
|
|
s.read ((char *)&size, sizeof (size)); if (!s) return; |
|
|
|
s.read ((char *)&size, sizeof (size)); if (!s) return; |
|
|
@ -250,7 +251,7 @@ namespace data |
|
|
|
LogPrint (eLogWarning, "RouterInfo: Unexpected field 'key' for NTCP"); |
|
|
|
LogPrint (eLogWarning, "RouterInfo: Unexpected field 'key' for NTCP"); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (!strcmp (key, "caps")) |
|
|
|
else if (!strcmp (key, "caps")) |
|
|
|
ExtractCaps (value); |
|
|
|
address->caps = ExtractCaps (value); |
|
|
|
else if (!strcmp (key, "s")) // ntcp2 static key
|
|
|
|
else if (!strcmp (key, "s")) // ntcp2 static key
|
|
|
|
{ |
|
|
|
{ |
|
|
|
Base64ToByteStream (value, strlen (value), address->ntcp2->staticKey, 32); |
|
|
|
Base64ToByteStream (value, strlen (value), address->ntcp2->staticKey, 32); |
|
|
@ -353,7 +354,7 @@ namespace data |
|
|
|
|
|
|
|
|
|
|
|
// extract caps
|
|
|
|
// extract caps
|
|
|
|
if (!strcmp (key, "caps")) |
|
|
|
if (!strcmp (key, "caps")) |
|
|
|
ExtractCaps (value); |
|
|
|
m_Caps = ExtractCaps (value); |
|
|
|
// extract version
|
|
|
|
// extract version
|
|
|
|
else if (!strcmp (key, ROUTER_INFO_PROPERTY_VERSION)) |
|
|
|
else if (!strcmp (key, ROUTER_INFO_PROPERTY_VERSION)) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -402,44 +403,46 @@ namespace data |
|
|
|
return m_Family == fam; |
|
|
|
return m_Family == fam; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void RouterInfo::ExtractCaps (const char * value) |
|
|
|
uint8_t RouterInfo::ExtractCaps (const char * value) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
uint8_t caps = 0; |
|
|
|
const char * cap = value; |
|
|
|
const char * cap = value; |
|
|
|
while (*cap) |
|
|
|
while (*cap) |
|
|
|
{ |
|
|
|
{ |
|
|
|
switch (*cap) |
|
|
|
switch (*cap) |
|
|
|
{ |
|
|
|
{ |
|
|
|
case CAPS_FLAG_FLOODFILL: |
|
|
|
case CAPS_FLAG_FLOODFILL: |
|
|
|
m_Caps |= Caps::eFloodfill; |
|
|
|
caps |= Caps::eFloodfill; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case CAPS_FLAG_HIGH_BANDWIDTH1: |
|
|
|
case CAPS_FLAG_HIGH_BANDWIDTH1: |
|
|
|
case CAPS_FLAG_HIGH_BANDWIDTH2: |
|
|
|
case CAPS_FLAG_HIGH_BANDWIDTH2: |
|
|
|
case CAPS_FLAG_HIGH_BANDWIDTH3: |
|
|
|
case CAPS_FLAG_HIGH_BANDWIDTH3: |
|
|
|
m_Caps |= Caps::eHighBandwidth; |
|
|
|
caps |= Caps::eHighBandwidth; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case CAPS_FLAG_EXTRA_BANDWIDTH1: |
|
|
|
case CAPS_FLAG_EXTRA_BANDWIDTH1: |
|
|
|
case CAPS_FLAG_EXTRA_BANDWIDTH2: |
|
|
|
case CAPS_FLAG_EXTRA_BANDWIDTH2: |
|
|
|
m_Caps |= Caps::eExtraBandwidth | Caps::eHighBandwidth; |
|
|
|
caps |= Caps::eExtraBandwidth | Caps::eHighBandwidth; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case CAPS_FLAG_HIDDEN: |
|
|
|
case CAPS_FLAG_HIDDEN: |
|
|
|
m_Caps |= Caps::eHidden; |
|
|
|
caps |= Caps::eHidden; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case CAPS_FLAG_REACHABLE: |
|
|
|
case CAPS_FLAG_REACHABLE: |
|
|
|
m_Caps |= Caps::eReachable; |
|
|
|
caps |= Caps::eReachable; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case CAPS_FLAG_UNREACHABLE: |
|
|
|
case CAPS_FLAG_UNREACHABLE: |
|
|
|
m_Caps |= Caps::eUnreachable; |
|
|
|
caps |= Caps::eUnreachable; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case CAPS_FLAG_SSU_TESTING: |
|
|
|
case CAPS_FLAG_SSU_TESTING: |
|
|
|
m_Caps |= Caps::eSSUTesting; |
|
|
|
caps |= Caps::eSSUTesting; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case CAPS_FLAG_SSU_INTRODUCER: |
|
|
|
case CAPS_FLAG_SSU_INTRODUCER: |
|
|
|
m_Caps |= Caps::eSSUIntroducer; |
|
|
|
caps |= Caps::eSSUIntroducer; |
|
|
|
break; |
|
|
|
break; |
|
|
|
default: ; |
|
|
|
default: ; |
|
|
|
} |
|
|
|
} |
|
|
|
cap++; |
|
|
|
cap++; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return caps; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void RouterInfo::UpdateCapsProperty () |
|
|
|
void RouterInfo::UpdateCapsProperty () |
|
|
@ -496,8 +499,8 @@ namespace data |
|
|
|
WriteString ("caps", properties); |
|
|
|
WriteString ("caps", properties); |
|
|
|
properties << '='; |
|
|
|
properties << '='; |
|
|
|
std::string caps; |
|
|
|
std::string caps; |
|
|
|
if (IsPeerTesting ()) caps += CAPS_FLAG_SSU_TESTING; |
|
|
|
if (address.IsPeerTesting ()) caps += CAPS_FLAG_SSU_TESTING; |
|
|
|
if (IsIntroducer ()) caps += CAPS_FLAG_SSU_INTRODUCER; |
|
|
|
if (address.IsIntroducer ()) caps += CAPS_FLAG_SSU_INTRODUCER; |
|
|
|
WriteString (caps, properties); |
|
|
|
WriteString (caps, properties); |
|
|
|
properties << ';'; |
|
|
|
properties << ';'; |
|
|
|
} |
|
|
|
} |
|
|
@ -721,7 +724,8 @@ namespace data |
|
|
|
addr->host = boost::asio::ip::address::from_string (host); |
|
|
|
addr->host = boost::asio::ip::address::from_string (host); |
|
|
|
addr->port = port; |
|
|
|
addr->port = port; |
|
|
|
addr->transportStyle = eTransportSSU; |
|
|
|
addr->transportStyle = eTransportSSU; |
|
|
|
addr->cost = 10; // NTCP should have priority over SSU
|
|
|
|
addr->cost = 10; // NTCP2 should have priority over SSU
|
|
|
|
|
|
|
|
addr->caps = i2p::data::RouterInfo::eSSUTesting | i2p::data::RouterInfo::eSSUIntroducer; // BC;
|
|
|
|
addr->date = 0; |
|
|
|
addr->date = 0; |
|
|
|
addr->ssu.reset (new SSUExt ()); |
|
|
|
addr->ssu.reset (new SSUExt ()); |
|
|
|
addr->ssu->mtu = mtu; |
|
|
|
addr->ssu->mtu = mtu; |
|
|
@ -745,6 +749,7 @@ namespace data |
|
|
|
addr->port = port; |
|
|
|
addr->port = port; |
|
|
|
addr->transportStyle = eTransportNTCP; |
|
|
|
addr->transportStyle = eTransportNTCP; |
|
|
|
addr->cost = port ? 3 : 14; // override from RouterContext::PublishNTCP2Address
|
|
|
|
addr->cost = port ? 3 : 14; // override from RouterContext::PublishNTCP2Address
|
|
|
|
|
|
|
|
addr->caps = 0; |
|
|
|
addr->date = 0; |
|
|
|
addr->date = 0; |
|
|
|
addr->ntcp2.reset (new NTCP2Ext ()); |
|
|
|
addr->ntcp2.reset (new NTCP2Ext ()); |
|
|
|
if (port) addr->ntcp2->isPublished = true; |
|
|
|
if (port) addr->ntcp2->isPublished = true; |
|
|
@ -794,8 +799,7 @@ namespace data |
|
|
|
void RouterInfo::SetCaps (const char * caps) |
|
|
|
void RouterInfo::SetCaps (const char * caps) |
|
|
|
{ |
|
|
|
{ |
|
|
|
SetProperty ("caps", caps); |
|
|
|
SetProperty ("caps", caps); |
|
|
|
m_Caps = 0; |
|
|
|
m_Caps = ExtractCaps (caps); |
|
|
|
ExtractCaps (caps); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void RouterInfo::SetProperty (const std::string& key, const std::string& value) |
|
|
|
void RouterInfo::SetProperty (const std::string& key, const std::string& value) |
|
|
@ -1020,5 +1024,28 @@ namespace data |
|
|
|
return IsReachable () && m_Version >= NETDB_MIN_FLOODFILL_VERSION && |
|
|
|
return IsReachable () && m_Version >= NETDB_MIN_FLOODFILL_VERSION && |
|
|
|
GetIdentity ()->GetSigningKeyType () != SIGNING_KEY_TYPE_DSA_SHA1; |
|
|
|
GetIdentity ()->GetSigningKeyType () != SIGNING_KEY_TYPE_DSA_SHA1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool RouterInfo::IsPeerTesting (bool v4only) const |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
auto supportedTransports = m_SupportedTransports & (eSSUV4 | eSSUV6); |
|
|
|
|
|
|
|
if (!supportedTransports) return false; // no SSU
|
|
|
|
|
|
|
|
if (v4only && !(supportedTransports & eSSUV4)) return false; // no SSU v4
|
|
|
|
|
|
|
|
return GetAddress ( |
|
|
|
|
|
|
|
[](std::shared_ptr<const RouterInfo::Address> address)->bool |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return (address->transportStyle == eTransportSSU) && address->IsPeerTesting (); |
|
|
|
|
|
|
|
}) != nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool RouterInfo::IsIntroducer () const |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// TODO: support ipv6
|
|
|
|
|
|
|
|
if (!(m_SupportedTransports & eSSUV4)) return false; |
|
|
|
|
|
|
|
return GetAddress ( |
|
|
|
|
|
|
|
[](std::shared_ptr<const RouterInfo::Address> address)->bool |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return (address->transportStyle == eTransportSSU) && address->IsIntroducer (); |
|
|
|
|
|
|
|
}) != nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|