mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 04:04:16 +00:00
add/removed NTCP addresses
This commit is contained in:
parent
0be664cc3d
commit
3236827781
@ -154,14 +154,17 @@ namespace i2p
|
|||||||
i2p::context.SetSupportsV6 (ipv6);
|
i2p::context.SetSupportsV6 (ipv6);
|
||||||
i2p::context.SetSupportsV4 (ipv4);
|
i2p::context.SetSupportsV4 (ipv4);
|
||||||
|
|
||||||
|
bool ntcp; i2p::config::GetOption("ntcp", ntcp);
|
||||||
|
i2p::context.PublishNTCPAddress (ntcp, !ipv6);
|
||||||
bool ntcp2; i2p::config::GetOption("ntcp2.enabled", ntcp2);
|
bool ntcp2; i2p::config::GetOption("ntcp2.enabled", ntcp2);
|
||||||
if (ntcp2)
|
if (ntcp2)
|
||||||
{
|
{
|
||||||
bool published; i2p::config::GetOption("ntcp2.published", published);
|
bool published; i2p::config::GetOption("ntcp2.published", published);
|
||||||
if (published)
|
if (published)
|
||||||
{
|
{
|
||||||
uint16_t port; i2p::config::GetOption("ntcp2.port", port);
|
uint16_t ntcp2port; i2p::config::GetOption("ntcp2.port", ntcp2port);
|
||||||
i2p::context.PublishNTCP2Address (port, true); // publish
|
if (!ntcp && !ntcp2port) ntcp2port = port; // use standard port
|
||||||
|
i2p::context.PublishNTCP2Address (ntcp2port, true); // publish
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
i2p::context.PublishNTCP2Address (port, false); // unpublish
|
i2p::context.PublishNTCP2Address (port, false); // unpublish
|
||||||
|
@ -344,6 +344,51 @@ namespace i2p
|
|||||||
return m_RouterInfo.GetCaps () & i2p::data::RouterInfo::eUnreachable;
|
return m_RouterInfo.GetCaps () & i2p::data::RouterInfo::eUnreachable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RouterContext::PublishNTCPAddress (bool publish, bool v4only)
|
||||||
|
{
|
||||||
|
auto& addresses = m_RouterInfo.GetAddresses ();
|
||||||
|
if (publish)
|
||||||
|
{
|
||||||
|
for (const auto& addr : addresses) // v4
|
||||||
|
{
|
||||||
|
if (addr->transportStyle == i2p::data::RouterInfo::eTransportSSU &&
|
||||||
|
addr->host.is_v4 ())
|
||||||
|
{
|
||||||
|
// insert NTCP address with host/port from SSU
|
||||||
|
m_RouterInfo.AddNTCPAddress (addr->host.to_string ().c_str (), addr->port);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!v4only)
|
||||||
|
{
|
||||||
|
for (const auto& addr : addresses) // v6
|
||||||
|
{
|
||||||
|
if (addr->transportStyle == i2p::data::RouterInfo::eTransportSSU &&
|
||||||
|
addr->host.is_v6 ())
|
||||||
|
{
|
||||||
|
// insert NTCP address with host/port from SSU
|
||||||
|
m_RouterInfo.AddNTCPAddress (addr->host.to_string ().c_str (), addr->port);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (auto it = addresses.begin (); it != addresses.end ();)
|
||||||
|
{
|
||||||
|
if ((*it)->transportStyle == i2p::data::RouterInfo::eTransportNTCP && !(*it)->IsNTCP2 () &&
|
||||||
|
(!v4only || (*it)->host.is_v4 ()))
|
||||||
|
{
|
||||||
|
it = addresses.erase (it);
|
||||||
|
if (v4only) break; // otherwise might be more than one address
|
||||||
|
}
|
||||||
|
else
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void RouterContext::SetUnreachable ()
|
void RouterContext::SetUnreachable ()
|
||||||
{
|
{
|
||||||
// set caps
|
// set caps
|
||||||
@ -353,22 +398,13 @@ namespace i2p
|
|||||||
caps &= ~i2p::data::RouterInfo::eFloodfill; // can't be floodfill
|
caps &= ~i2p::data::RouterInfo::eFloodfill; // can't be floodfill
|
||||||
caps &= ~i2p::data::RouterInfo::eSSUIntroducer; // can't be introducer
|
caps &= ~i2p::data::RouterInfo::eSSUIntroducer; // can't be introducer
|
||||||
m_RouterInfo.SetCaps (caps);
|
m_RouterInfo.SetCaps (caps);
|
||||||
// remove NTCP address
|
// remove NTCP v4 address
|
||||||
auto& addresses = m_RouterInfo.GetAddresses ();
|
PublishNTCPAddress (false);
|
||||||
for (auto it = addresses.begin (); it != addresses.end (); ++it)
|
|
||||||
{
|
|
||||||
if ((*it)->transportStyle == i2p::data::RouterInfo::eTransportNTCP && !(*it)->IsNTCP2 () &&
|
|
||||||
(*it)->host.is_v4 ())
|
|
||||||
{
|
|
||||||
addresses.erase (it);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// delete previous introducers
|
// delete previous introducers
|
||||||
|
auto& addresses = m_RouterInfo.GetAddresses ();
|
||||||
for (auto& addr : addresses)
|
for (auto& addr : addresses)
|
||||||
if (addr->ssu)
|
if (addr->ssu)
|
||||||
addr->ssu->introducers.clear ();
|
addr->ssu->introducers.clear ();
|
||||||
|
|
||||||
// update
|
// update
|
||||||
UpdateRouterInfo ();
|
UpdateRouterInfo ();
|
||||||
}
|
}
|
||||||
@ -383,27 +419,15 @@ namespace i2p
|
|||||||
if (m_IsFloodfill)
|
if (m_IsFloodfill)
|
||||||
caps |= i2p::data::RouterInfo::eFloodfill;
|
caps |= i2p::data::RouterInfo::eFloodfill;
|
||||||
m_RouterInfo.SetCaps (caps);
|
m_RouterInfo.SetCaps (caps);
|
||||||
|
|
||||||
auto& addresses = m_RouterInfo.GetAddresses ();
|
|
||||||
// insert NTCP back
|
// insert NTCP back
|
||||||
bool ntcp; i2p::config::GetOption("ntcp", ntcp);
|
bool ntcp; i2p::config::GetOption("ntcp", ntcp);
|
||||||
if (ntcp) {
|
if (ntcp)
|
||||||
for (const auto& addr : addresses)
|
PublishNTCPAddress (true);
|
||||||
{
|
|
||||||
if (addr->transportStyle == i2p::data::RouterInfo::eTransportSSU &&
|
|
||||||
addr->host.is_v4 ())
|
|
||||||
{
|
|
||||||
// insert NTCP address with host/port from SSU
|
|
||||||
m_RouterInfo.AddNTCPAddress (addr->host.to_string ().c_str (), addr->port);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// delete previous introducers
|
// delete previous introducers
|
||||||
|
auto& addresses = m_RouterInfo.GetAddresses ();
|
||||||
for (auto& addr : addresses)
|
for (auto& addr : addresses)
|
||||||
if (addr->ssu)
|
if (addr->ssu)
|
||||||
addr->ssu->introducers.clear ();
|
addr->ssu->introducers.clear ();
|
||||||
|
|
||||||
// update
|
// update
|
||||||
UpdateRouterInfo ();
|
UpdateRouterInfo ();
|
||||||
}
|
}
|
||||||
|
@ -81,6 +81,7 @@ namespace i2p
|
|||||||
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 publish = true);
|
void PublishNTCP2Address (int port, bool publish = true);
|
||||||
void UpdateNTCP2Address (bool enable);
|
void UpdateNTCP2Address (bool enable);
|
||||||
|
void PublishNTCPAddress (bool publish, bool v4only = true);
|
||||||
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;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user