|
|
|
@ -176,10 +176,14 @@ namespace data
@@ -176,10 +176,14 @@ namespace data
|
|
|
|
|
auto address = std::make_shared<Address>(); |
|
|
|
|
s.read ((char *)&address->cost, sizeof (address->cost)); |
|
|
|
|
s.read ((char *)&address->date, sizeof (address->date)); |
|
|
|
|
char transportStyle[5]; |
|
|
|
|
ReadString (transportStyle, 5, s); |
|
|
|
|
if (!strcmp (transportStyle, "NTCP")) |
|
|
|
|
bool isNtcp2 = false; |
|
|
|
|
char transportStyle[6]; |
|
|
|
|
auto transportStyleLen = ReadString (transportStyle, 6, s) - 1; |
|
|
|
|
if (!strncmp (transportStyle, "NTCP", 4)) // NTCP or NTCP2
|
|
|
|
|
{ |
|
|
|
|
address->transportStyle = eTransportNTCP; |
|
|
|
|
if (transportStyleLen > 4 || transportStyle[4] == '2') isNtcp2= true; |
|
|
|
|
} |
|
|
|
|
else if (!strcmp (transportStyle, "SSU")) |
|
|
|
|
{ |
|
|
|
|
address->transportStyle = eTransportSSU; |
|
|
|
@ -288,7 +292,7 @@ namespace data
@@ -288,7 +292,7 @@ namespace data
|
|
|
|
|
if (!s) return; |
|
|
|
|
} |
|
|
|
|
if (introducers) supportedTransports |= eSSUV4; // in case if host is not presented
|
|
|
|
|
if (supportedTransports) |
|
|
|
|
if (supportedTransports && !isNtcp2) // we ignore NTCP2 addresses for now. TODO:
|
|
|
|
|
{ |
|
|
|
|
addresses->push_back(address); |
|
|
|
|
m_SupportedTransports |= supportedTransports; |
|
|
|
@ -435,7 +439,7 @@ namespace data
@@ -435,7 +439,7 @@ namespace data
|
|
|
|
|
s.write ((const char *)&address.date, sizeof (address.date)); |
|
|
|
|
std::stringstream properties; |
|
|
|
|
if (address.transportStyle == eTransportNTCP) |
|
|
|
|
WriteString ("NTCP", s); |
|
|
|
|
WriteString (address.IsNTCP2 () ? "NTCP2" : "NTCP", s); |
|
|
|
|
else if (address.transportStyle == eTransportSSU) |
|
|
|
|
{ |
|
|
|
|
WriteString ("SSU", s); |
|
|
|
@ -451,10 +455,13 @@ namespace data
@@ -451,10 +455,13 @@ namespace data
|
|
|
|
|
else |
|
|
|
|
WriteString ("", s); |
|
|
|
|
|
|
|
|
|
WriteString ("host", properties); |
|
|
|
|
properties << '='; |
|
|
|
|
WriteString (address.host.to_string (), properties); |
|
|
|
|
properties << ';'; |
|
|
|
|
if (!address.IsNTCP2 ()) // we don't publish NTCP2 address fow now. TODO: implement
|
|
|
|
|
{ |
|
|
|
|
WriteString ("host", properties); |
|
|
|
|
properties << '='; |
|
|
|
|
WriteString (address.host.to_string (), properties); |
|
|
|
|
properties << ';'; |
|
|
|
|
} |
|
|
|
|
if (address.transportStyle == eTransportSSU) |
|
|
|
|
{ |
|
|
|
|
// write introducers if any
|
|
|
|
@ -529,10 +536,23 @@ namespace data
@@ -529,10 +536,23 @@ namespace data
|
|
|
|
|
properties << ';'; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
WriteString ("port", properties); |
|
|
|
|
properties << '='; |
|
|
|
|
WriteString (boost::lexical_cast<std::string>(address.port), properties); |
|
|
|
|
properties << ';'; |
|
|
|
|
|
|
|
|
|
if (!address.IsNTCP2 ()) // we don't publish NTCP2 address fow now. TODO: implement
|
|
|
|
|
{ |
|
|
|
|
WriteString ("port", properties); |
|
|
|
|
properties << '='; |
|
|
|
|
WriteString (boost::lexical_cast<std::string>(address.port), properties); |
|
|
|
|
properties << ';'; |
|
|
|
|
} |
|
|
|
|
if (address.IsNTCP2 ()) |
|
|
|
|
{ |
|
|
|
|
// publish s and v for NTCP2
|
|
|
|
|
WriteString ("s", properties); properties << '='; |
|
|
|
|
WriteString (address.ntcp2->staticKey.ToBase64 (), properties); properties << ';'; |
|
|
|
|
WriteString ("v", properties); properties << '='; |
|
|
|
|
WriteString ("2", properties); properties << ';'; |
|
|
|
|
// TODO: publish "i"
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
uint16_t size = htobe16 (properties.str ().size ()); |
|
|
|
|
s.write ((char *)&size, sizeof (size)); |
|
|
|
@ -668,6 +688,21 @@ namespace data
@@ -668,6 +688,21 @@ namespace data
|
|
|
|
|
m_Caps |= eSSUIntroducer; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void RouterInfo::AddNTCP2Address (const uint8_t * staticKey, const uint8_t * iv) |
|
|
|
|
{ |
|
|
|
|
for (const auto& it: *m_Addresses) // don't insert one more NTCP2
|
|
|
|
|
if (it->ntcp2) return; |
|
|
|
|
auto addr = std::make_shared<Address>(); |
|
|
|
|
addr->port = 0; |
|
|
|
|
addr->transportStyle = eTransportNTCP; |
|
|
|
|
addr->cost = 14; |
|
|
|
|
addr->date = 0; |
|
|
|
|
addr->ntcp2.reset (new NTCP2Ext ()); |
|
|
|
|
memcpy (addr->ntcp2->staticKey, staticKey, 32); |
|
|
|
|
memcpy (addr->ntcp2->iv, iv, 32); |
|
|
|
|
m_Addresses->push_back(std::move(addr)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool RouterInfo::AddIntroducer (const Introducer& introducer) |
|
|
|
|
{ |
|
|
|
|
for (auto& addr : *m_Addresses) |
|
|
|
|