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