Skip to content

Commit

Permalink
publish and upublish NTCP2 and yggdrasil addresses separatly
Browse files Browse the repository at this point in the history
  • Loading branch information
orignal committed Mar 16, 2021
1 parent 436a3e7 commit 43d458c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
6 changes: 3 additions & 3 deletions daemon/Daemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ namespace util
{
uint16_t ntcp2port; i2p::config::GetOption("ntcp2.port", ntcp2port);
if (!ntcp2port) ntcp2port = port; // use standard port
i2p::context.PublishNTCP2Address (ntcp2port, true); // publish
i2p::context.PublishNTCP2Address (ntcp2port, true, ipv4, ipv6, false); // publish
if (ipv6)
{
std::string ipv6Addr; i2p::config::GetOption("ntcp2.addressv6", ipv6Addr);
Expand All @@ -228,12 +228,12 @@ namespace util
}
}
else
i2p::context.PublishNTCP2Address (port, false); // unpublish
i2p::context.PublishNTCP2Address (port, false, ipv4, ipv6, false); // unpublish
}
if (ygg)
{
if (!ntcp2)
i2p::context.PublishNTCP2Address (port, true);
i2p::context.PublishNTCP2Address (port, true, false, false, true);
i2p::context.UpdateNTCP2V6Address (yggaddr);
if (!ipv4 && !ipv6)
i2p::context.SetStatus (eRouterStatusMesh);
Expand Down
10 changes: 6 additions & 4 deletions libi2pd/RouterContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,15 @@ namespace i2p
UpdateRouterInfo ();
}

void RouterContext::PublishNTCP2Address (int port, bool publish, bool v4only)
void RouterContext::PublishNTCP2Address (int port, bool publish, bool v4, bool v6, bool ygg)
{
if (!m_NTCP2Keys) return;
bool updated = false;
for (auto& address : m_RouterInfo.GetAddresses ())
{
if (address->IsNTCP2 () && (address->port != port || address->ntcp2->isPublished != publish) && (!v4only || address->IsV4 ()))
if (address->IsNTCP2 () && (address->port != port || address->ntcp2->isPublished != publish)
&& ((v4 && address->IsV4 ()) || (v6 && address->IsV6 ()) ||
(ygg && i2p::util::net::IsYggdrasilAddress (address->host))))
{
if (!port && !address->port)
{
Expand Down Expand Up @@ -457,7 +459,7 @@ namespace i2p
// remove NTCP2 v4 address
bool ntcp2; i2p::config::GetOption("ntcp2.enabled", ntcp2);
if (ntcp2)
PublishNTCP2Address (port, false, true);
PublishNTCP2Address (port, false, true, false, false); // ipv4 only
// update
UpdateRouterInfo ();
}
Expand Down Expand Up @@ -491,7 +493,7 @@ namespace i2p
{
uint16_t ntcp2Port; i2p::config::GetOption ("ntcp2.port", ntcp2Port);
if (!ntcp2Port) ntcp2Port = port;
PublishNTCP2Address (ntcp2Port, true, true);
PublishNTCP2Address (ntcp2Port, true, true, false, false); // ipv4 only
}
}
// update
Expand Down
2 changes: 1 addition & 1 deletion libi2pd/RouterContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ namespace garlic

void UpdatePort (int port); // called from Daemon
void UpdateAddress (const boost::asio::ip::address& host); // called from SSU or Daemon
void PublishNTCP2Address (int port, bool publish = true, bool v4only = false);
void PublishNTCP2Address (int port, bool publish, bool v4, bool v6, bool ygg);
void UpdateNTCP2Address (bool enable);
void RemoveNTCPAddress (bool v4only = true); // delete NTCP address for older routers. TODO: remove later
bool AddIntroducer (const i2p::data::RouterInfo::Introducer& introducer);
Expand Down

0 comments on commit 43d458c

Please sign in to comment.