Browse Source

set ipv6 address caps depending on peer test

pull/1645/head
orignal 4 years ago
parent
commit
a6ea37a21e
  1. 37
      libi2pd/RouterContext.cpp
  2. 4
      libi2pd/RouterContext.h
  3. 2
      libi2pd/SSU.cpp

37
libi2pd/RouterContext.cpp

@ -28,7 +28,7 @@ namespace i2p
RouterContext::RouterContext (): RouterContext::RouterContext ():
m_LastUpdateTime (0), m_AcceptsTunnels (true), m_IsFloodfill (false), m_LastUpdateTime (0), m_AcceptsTunnels (true), m_IsFloodfill (false),
m_ShareRatio (100), m_Status (eRouterStatusUnknown), m_StatusV6 (eRouterStatusOK), m_ShareRatio (100), m_Status (eRouterStatusUnknown), m_StatusV6 (eRouterStatusUnknown),
m_Error (eRouterErrorNone), m_NetID (I2PD_NET_ID) m_Error (eRouterErrorNone), m_NetID (I2PD_NET_ID)
{ {
} }
@ -199,10 +199,10 @@ namespace i2p
switch (m_Status) switch (m_Status)
{ {
case eRouterStatusOK: case eRouterStatusOK:
SetReachable (); SetReachable (true, false); // ipv4
break; break;
case eRouterStatusFirewalled: case eRouterStatusFirewalled:
SetUnreachable (); SetUnreachable (true, false); // ipv4
break; break;
default: default:
; ;
@ -213,7 +213,20 @@ namespace i2p
void RouterContext::SetStatusV6 (RouterStatus status) void RouterContext::SetStatusV6 (RouterStatus status)
{ {
if (status != m_StatusV6) if (status != m_StatusV6)
{
m_StatusV6 = status; m_StatusV6 = status;
switch (m_StatusV6)
{
case eRouterStatusOK:
SetReachable (false, true); // ipv6
break;
case eRouterStatusFirewalled:
SetUnreachable (false, true); // ipv6
break;
default:
;
}
}
} }
void RouterContext::UpdatePort (int port) void RouterContext::UpdatePort (int port)
@ -443,7 +456,7 @@ namespace i2p
} }
} }
void RouterContext::SetUnreachable () void RouterContext::SetUnreachable (bool v4, bool v6)
{ {
// set caps // set caps
uint8_t caps = m_RouterInfo.GetCaps (); uint8_t caps = m_RouterInfo.GetCaps ();
@ -455,22 +468,22 @@ namespace i2p
// delete previous introducers // delete previous introducers
auto& addresses = m_RouterInfo.GetAddresses (); auto& addresses = m_RouterInfo.GetAddresses ();
for (auto& addr : addresses) for (auto& addr : addresses)
if (addr->ssu) if (addr->ssu && ((v4 && addr->IsV4 ()) || (v6 && addr->IsV6 ())))
{ {
addr->cost = i2p::data::COST_SSU_THROUGH_INTRODUCERS; addr->cost = i2p::data::COST_SSU_THROUGH_INTRODUCERS;
addr->caps &= ~i2p::data::RouterInfo::eSSUIntroducer; // can't be introducer addr->caps &= ~i2p::data::RouterInfo::eSSUIntroducer; // can't be introducer
addr->ssu->introducers.clear (); addr->ssu->introducers.clear ();
port = addr->port; port = addr->port;
} }
// remove NTCP2 v4 address // unpiblish NTCP2 addreeses
bool ntcp2; i2p::config::GetOption("ntcp2.enabled", ntcp2); bool ntcp2; i2p::config::GetOption("ntcp2.enabled", ntcp2);
if (ntcp2) if (ntcp2)
PublishNTCP2Address (port, false, true, false, false); // ipv4 only PublishNTCP2Address (port, false, v4, v6, false);
// update // update
UpdateRouterInfo (); UpdateRouterInfo ();
} }
void RouterContext::SetReachable () void RouterContext::SetReachable (bool v4, bool v6)
{ {
// update caps // update caps
uint8_t caps = m_RouterInfo.GetCaps (); uint8_t caps = m_RouterInfo.GetCaps ();
@ -483,14 +496,14 @@ namespace i2p
// delete previous introducers // delete previous introducers
auto& addresses = m_RouterInfo.GetAddresses (); auto& addresses = m_RouterInfo.GetAddresses ();
for (auto& addr : addresses) for (auto& addr : addresses)
if (addr->ssu) if (addr->ssu && ((v4 && addr->IsV4 ()) || (v6 && addr->IsV6 ())))
{ {
addr->cost = i2p::data::COST_SSU_DIRECT; addr->cost = i2p::data::COST_SSU_DIRECT;
addr->caps |= i2p::data::RouterInfo::eSSUIntroducer; addr->caps |= i2p::data::RouterInfo::eSSUIntroducer;
addr->ssu->introducers.clear (); addr->ssu->introducers.clear ();
port = addr->port; port = addr->port;
} }
// insert NTCP2 back // publish NTCP2
bool ntcp2; i2p::config::GetOption("ntcp2.enabled", ntcp2); bool ntcp2; i2p::config::GetOption("ntcp2.enabled", ntcp2);
if (ntcp2) if (ntcp2)
{ {
@ -499,7 +512,7 @@ namespace i2p
{ {
uint16_t ntcp2Port; i2p::config::GetOption ("ntcp2.port", ntcp2Port); uint16_t ntcp2Port; i2p::config::GetOption ("ntcp2.port", ntcp2Port);
if (!ntcp2Port) ntcp2Port = port; if (!ntcp2Port) ntcp2Port = port;
PublishNTCP2Address (ntcp2Port, true, true, false, false); // ipv4 only PublishNTCP2Address (ntcp2Port, true, v4, v6, false);
} }
} }
// update // update
@ -757,7 +770,7 @@ namespace i2p
} }
if (IsUnreachable ()) if (IsUnreachable ())
SetReachable (); // we assume reachable until we discover firewall through peer tests SetReachable (true, true); // we assume reachable until we discover firewall through peer tests
// read NTCP2 // read NTCP2
bool ntcp2; i2p::config::GetOption("ntcp2.enabled", ntcp2); bool ntcp2; i2p::config::GetOption("ntcp2.enabled", ntcp2);

4
libi2pd/RouterContext.h

@ -105,8 +105,8 @@ namespace garlic
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;
void SetUnreachable (); void SetUnreachable (bool v4, bool v6);
void SetReachable (); void SetReachable (bool v4, bool v6);
bool IsFloodfill () const { return m_IsFloodfill; }; bool IsFloodfill () const { return m_IsFloodfill; };
void SetFloodfill (bool floodfill); void SetFloodfill (bool floodfill);
void SetFamily (const std::string& family); void SetFamily (const std::string& family);

2
libi2pd/SSU.cpp

@ -706,7 +706,7 @@ namespace transport
return; return;
} }
// we are firewalled // we are firewalled
if (!i2p::context.IsUnreachable ()) i2p::context.SetUnreachable (); if (!i2p::context.IsUnreachable ()) i2p::context.SetUnreachable (true, false); // ipv4
std::list<boost::asio::ip::udp::endpoint> newList; std::list<boost::asio::ip::udp::endpoint> newList;
size_t numIntroducers = 0; size_t numIntroducers = 0;
uint32_t ts = i2p::util::GetSecondsSinceEpoch (); uint32_t ts = i2p::util::GetSecondsSinceEpoch ();

Loading…
Cancel
Save