publish NTCP2 address

This commit is contained in:
orignal 2018-07-23 13:51:29 -04:00
parent c8f51380e6
commit 1a38e925bf
3 changed files with 26 additions and 5 deletions

View File

@ -146,7 +146,7 @@ namespace i2p
bool updated = false; bool updated = false;
for (auto& address : m_RouterInfo.GetAddresses ()) for (auto& address : m_RouterInfo.GetAddresses ())
{ {
if (address->port != port) if (!address->IsNTCP2 () && address->port != port)
{ {
address->port = port; address->port = port;
updated = true; updated = true;
@ -156,6 +156,22 @@ namespace i2p
UpdateRouterInfo (); UpdateRouterInfo ();
} }
void RouterContext::PublishNTCP2Address (int port)
{
bool updated = false;
for (auto& address : m_RouterInfo.GetAddresses ())
{
if (address->IsNTCP2 () && address->port != port)
{
address->port = port;
address->ntcp2->isPublished = true;
updated = true;
}
}
if (updated)
UpdateRouterInfo ();
}
void RouterContext::UpdateAddress (const boost::asio::ip::address& host) void RouterContext::UpdateAddress (const boost::asio::ip::address& host)
{ {
bool updated = false; bool updated = false;

View File

@ -76,8 +76,9 @@ namespace i2p
void SetNetID (int netID) { m_NetID = netID; }; void SetNetID (int netID) { m_NetID = netID; };
bool DecryptTunnelBuildRecord (const uint8_t * encrypted, uint8_t * data, BN_CTX * ctx) const; bool DecryptTunnelBuildRecord (const uint8_t * encrypted, uint8_t * data, BN_CTX * ctx) const;
void UpdatePort (int port); // called from Daemon void UpdatePort (int port); // called from Daemon
void UpdateAddress (const boost::asio::ip::address& host); // called from SSU or Daemon void UpdateAddress (const boost::asio::ip::address& host); // called from SSU or Daemon
void PublishNTCP2Address (int port);
bool AddIntroducer (const i2p::data::RouterInfo::Introducer& introducer); bool AddIntroducer (const i2p::data::RouterInfo::Introducer& introducer);
void RemoveIntroducer (const boost::asio::ip::udp::endpoint& e); void RemoveIntroducer (const boost::asio::ip::udp::endpoint& e);
bool IsUnreachable () const; bool IsUnreachable () const;

View File

@ -456,7 +456,7 @@ namespace data
else else
WriteString ("", s); WriteString ("", s);
if (!address.IsNTCP2 ()) // we don't publish NTCP2 address fow now. TODO: implement if (!address.IsNTCP2 () || address.IsPublishedNTCP2 ())
{ {
WriteString ("host", properties); WriteString ("host", properties);
properties << '='; properties << '=';
@ -538,7 +538,7 @@ namespace data
} }
} }
if (!address.IsNTCP2 ()) // we don't publish NTCP2 address fow now. TODO: implement if (!address.IsNTCP2 () || address.IsPublishedNTCP2 ())
{ {
WriteString ("port", properties); WriteString ("port", properties);
properties << '='; properties << '=';
@ -552,7 +552,11 @@ namespace data
WriteString (address.ntcp2->staticKey.ToBase64 (), properties); properties << ';'; WriteString (address.ntcp2->staticKey.ToBase64 (), properties); properties << ';';
WriteString ("v", properties); properties << '='; WriteString ("v", properties); properties << '=';
WriteString ("2", properties); properties << ';'; WriteString ("2", properties); properties << ';';
// TODO: publish "i" if (address.IsPublishedNTCP2 ())
{
WriteString ("i", properties); properties << '=';
WriteString (address.ntcp2->iv.ToBase64 (), properties); properties << ';';
}
} }
uint16_t size = htobe16 (properties.str ().size ()); uint16_t size = htobe16 (properties.str ().size ());