From 8ae8693c38d5f6fcdc086079fef2ba34cbc221bf Mon Sep 17 00:00:00 2001 From: anonimal Date: Sat, 22 Apr 2017 00:35:25 +0000 Subject: [PATCH] RouterInfo: treat singular cap as not plural otherwise there is potential confusion with relation to caps member. --- src/core/router/context.cc | 30 +++++----- src/core/router/info.cc | 82 +++++++++++++------------- src/core/router/info.h | 102 ++++++++++++++++----------------- src/core/router/net_db/impl.cc | 2 +- 4 files changed, 108 insertions(+), 108 deletions(-) diff --git a/src/core/router/context.cc b/src/core/router/context.cc index 810ba78a..6736ed3c 100644 --- a/src/core/router/context.cc +++ b/src/core/router/context.cc @@ -88,9 +88,9 @@ void RouterContext::NewRouterInfo() { routerInfo.AddSSUAddress(m_Host, m_Port, routerInfo.GetIdentHash()); routerInfo.AddNTCPAddress(m_Host, m_Port); routerInfo.SetCaps( - core::RouterInfo::Caps::Reachable | - core::RouterInfo::Caps::SSUTesting | - core::RouterInfo::Caps::SSUIntroducer); + core::RouterInfo::Cap::Reachable | + core::RouterInfo::Cap::SSUTesting | + core::RouterInfo::Cap::SSUIntroducer); routerInfo.SetProperty("netId", I2P_NETWORK_ID); routerInfo.SetProperty("router.version", I2P_VERSION); routerInfo.CreateBuffer(m_Keys); @@ -156,10 +156,10 @@ void RouterContext::SetFloodfill( m_IsFloodfill = floodfill; if (floodfill) { m_RouterInfo.SetCaps( - m_RouterInfo.GetCaps() | core::RouterInfo::Caps::Floodfill); + m_RouterInfo.GetCaps() | core::RouterInfo::Cap::Floodfill); } else { m_RouterInfo.SetCaps( - m_RouterInfo.GetCaps() & ~core::RouterInfo::Caps::Floodfill); + m_RouterInfo.GetCaps() & ~core::RouterInfo::Cap::Floodfill); // we don't publish number of routers and leaseset for non-floodfill m_RouterInfo.DeleteProperty(ROUTER_INFO_PROPERTY_LEASESETS); m_RouterInfo.DeleteProperty(ROUTER_INFO_PROPERTY_ROUTERS); @@ -170,7 +170,7 @@ void RouterContext::SetFloodfill( void RouterContext::SetHighBandwidth() { if (!m_RouterInfo.IsHighBandwidth()) { m_RouterInfo.SetCaps( - m_RouterInfo.GetCaps() | core::RouterInfo::Caps::HighBandwidth); + m_RouterInfo.GetCaps() | core::RouterInfo::Cap::HighBandwidth); UpdateRouterInfo(); } } @@ -178,19 +178,19 @@ void RouterContext::SetHighBandwidth() { void RouterContext::SetLowBandwidth() { if (m_RouterInfo.IsHighBandwidth()) { m_RouterInfo.SetCaps( - m_RouterInfo.GetCaps() & ~core::RouterInfo::Caps::HighBandwidth); + m_RouterInfo.GetCaps() & ~core::RouterInfo::Cap::HighBandwidth); UpdateRouterInfo(); } } bool RouterContext::IsUnreachable() const { - return m_RouterInfo.GetCaps() & core::RouterInfo::Caps::Unreachable; + return m_RouterInfo.GetCaps() & core::RouterInfo::Cap::Unreachable; } void RouterContext::SetUnreachable() { // set caps m_RouterInfo.SetCaps( // LU, B - core::RouterInfo::Caps::Unreachable | core::RouterInfo::Caps::SSUTesting); + core::RouterInfo::Cap::Unreachable | core::RouterInfo::Cap::SSUTesting); // remove NTCP address RemoveTransport(core::RouterInfo::Transport::NTCP); // delete previous introducers @@ -203,11 +203,11 @@ void RouterContext::SetUnreachable() { void RouterContext::SetReachable() { // update caps std::uint8_t caps = m_RouterInfo.GetCaps(); - caps &= ~core::RouterInfo::Caps::Unreachable; - caps |= core::RouterInfo::Caps::Reachable; - caps |= core::RouterInfo::Caps::SSUIntroducer; + caps &= ~core::RouterInfo::Cap::Unreachable; + caps |= core::RouterInfo::Cap::Reachable; + caps |= core::RouterInfo::Cap::SSUIntroducer; if (m_IsFloodfill) - caps |= core::RouterInfo::Caps::Floodfill; + caps |= core::RouterInfo::Cap::Floodfill; m_RouterInfo.SetCaps(caps); // insert NTCP back @@ -254,8 +254,8 @@ void RouterContext::SetSupportsSSU(bool supportsSSU) { RemoveTransport(core::RouterInfo::Transport::SSU); // Remove SSU-related flags m_RouterInfo.SetCaps(m_RouterInfo.GetCaps() - & ~core::RouterInfo::Caps::SSUTesting - & ~core::RouterInfo::Caps::SSUIntroducer); + & ~core::RouterInfo::Cap::SSUTesting + & ~core::RouterInfo::Cap::SSUIntroducer); UpdateRouterInfo(); } diff --git a/src/core/router/info.cc b/src/core/router/info.cc index 74b915f7..b913a762 100644 --- a/src/core/router/info.cc +++ b/src/core/router/info.cc @@ -469,32 +469,32 @@ void RouterInfo::ExtractCaps( const char* cap = value; while (*cap) { switch (GetTrait(*cap)) { - case CapsFlag::Floodfill: - m_Caps |= Caps::Floodfill; + case CapFlag::Floodfill: + m_Caps |= Cap::Floodfill; break; - case CapsFlag::UnlimitedBandwidth: - m_Caps |= Caps::UnlimitedBandwidth; + case CapFlag::UnlimitedBandwidth: + m_Caps |= Cap::UnlimitedBandwidth; break; - case CapsFlag::HighBandwidth1: - case CapsFlag::HighBandwidth2: - case CapsFlag::HighBandwidth3: - case CapsFlag::HighBandwidth4: - m_Caps |= Caps::HighBandwidth; + case CapFlag::HighBandwidth1: + case CapFlag::HighBandwidth2: + case CapFlag::HighBandwidth3: + case CapFlag::HighBandwidth4: + m_Caps |= Cap::HighBandwidth; break; - case CapsFlag::Hidden: - m_Caps |= Caps::Hidden; + case CapFlag::Hidden: + m_Caps |= Cap::Hidden; break; - case CapsFlag::Reachable: - m_Caps |= Caps::Reachable; + case CapFlag::Reachable: + m_Caps |= Cap::Reachable; break; - case CapsFlag::Unreachable: - m_Caps |= Caps::Unreachable; + case CapFlag::Unreachable: + m_Caps |= Cap::Unreachable; break; - case CapsFlag::SSUTesting: - m_Caps |= Caps::SSUTesting; + case CapFlag::SSUTesting: + m_Caps |= Cap::SSUTesting; break; - case CapsFlag::SSUIntroducer: - m_Caps |= Caps::SSUIntroducer; + case CapFlag::SSUIntroducer: + m_Caps |= Cap::SSUIntroducer; break; default: {} } @@ -506,26 +506,26 @@ void RouterInfo::UpdateCapsProperty() { std::string caps; - if (m_Caps & Caps::Floodfill) + if (m_Caps & Cap::Floodfill) { - caps += GetTrait(CapsFlag::HighBandwidth4); // highest bandwidth - caps += GetTrait(CapsFlag::Floodfill); + caps += GetTrait(CapFlag::HighBandwidth4); // highest bandwidth + caps += GetTrait(CapFlag::Floodfill); } else { - caps += (m_Caps & Caps::HighBandwidth) - ? GetTrait(CapsFlag::HighBandwidth3) - : GetTrait(CapsFlag::LowBandwidth2); + caps += (m_Caps & Cap::HighBandwidth) + ? GetTrait(CapFlag::HighBandwidth3) + : GetTrait(CapFlag::LowBandwidth2); } - if (m_Caps & Caps::Hidden) - caps += GetTrait(CapsFlag::Hidden); + if (m_Caps & Cap::Hidden) + caps += GetTrait(CapFlag::Hidden); - if (m_Caps & Caps::Reachable) - caps += GetTrait(CapsFlag::Reachable); + if (m_Caps & Cap::Reachable) + caps += GetTrait(CapFlag::Reachable); - if (m_Caps & Caps::Unreachable) - caps += GetTrait(CapsFlag::Unreachable); + if (m_Caps & Cap::Unreachable) + caps += GetTrait(CapFlag::Unreachable); SetProperty("caps", caps); } @@ -586,9 +586,9 @@ void RouterInfo::CreateRouterInfo( // Get SSU capabilities std::string caps; if (IsPeerTesting()) - caps += GetTrait(CapsFlag::SSUTesting); + caps += GetTrait(CapFlag::SSUTesting); if (IsIntroducer()) - caps += GetTrait(CapsFlag::SSUIntroducer); + caps += GetTrait(CapFlag::SSUIntroducer); // Write SSU capabilities options.WriteKeyPair(GetTrait(Trait::Caps), caps); @@ -770,8 +770,8 @@ void RouterInfo::AddSSUAddress( m_Addresses.push_back(addr); m_SupportedTransports |= addr.host.is_v6() ? SupportedTransport::SSUv6 : SupportedTransport::SSUv4; - m_Caps |= Caps::SSUTesting; - m_Caps |= Caps::SSUIntroducer; + m_Caps |= Cap::SSUTesting; + m_Caps |= Cap::SSUIntroducer; } bool RouterInfo::AddIntroducer( @@ -838,7 +838,7 @@ void RouterInfo::DeleteProperty( } bool RouterInfo::IsFloodfill() const { - return m_Caps & Caps::Floodfill; + return m_Caps & Cap::Floodfill; } bool RouterInfo::IsNTCP( @@ -896,7 +896,7 @@ void RouterInfo::DisableV6() { } bool RouterInfo::UsesIntroducer() const { - return m_Caps & Caps::Unreachable; // non-reachable + return m_Caps & Cap::Unreachable; // non-reachable } const RouterInfo::Address* RouterInfo::GetNTCPAddress( @@ -947,10 +947,10 @@ const std::string RouterInfo::GetDescription(const std::string& tabs) const for (const auto& opt : m_Options) ss << tabs << "\t\t[" << opt.first << "] : [" << opt.second << "]" << std::endl; ss << tabs << "\tSSU Caps: [" - << (IsPeerTesting() ? GetTrait(CapsFlag::SSUTesting) - : GetTrait(CapsFlag::Unknown)) - << (IsIntroducer() ? GetTrait(CapsFlag::SSUIntroducer) - : GetTrait(CapsFlag::Unknown)) + << (IsPeerTesting() ? GetTrait(CapFlag::SSUTesting) + : GetTrait(CapFlag::Unknown)) + << (IsIntroducer() ? GetTrait(CapFlag::SSUIntroducer) + : GetTrait(CapFlag::Unknown)) << "]" << std::endl; ss << tabs << "\tAddresses(" << m_Addresses.size() << "): " << std::endl; for (const auto& address : m_Addresses) diff --git a/src/core/router/info.h b/src/core/router/info.h index 5ce80f61..f5a3d0fb 100644 --- a/src/core/router/info.h +++ b/src/core/router/info.h @@ -74,9 +74,9 @@ class RouterInfo : public RoutingDestination { SSUv6 = 0x08, }; - /// @enum Caps + /// @enum Cap /// @brief RI capabilities - enum Caps : std::uint8_t + enum Cap : std::uint8_t { Floodfill = 0x01, UnlimitedBandwidth = 0x02, @@ -88,9 +88,9 @@ class RouterInfo : public RoutingDestination { Unreachable = 0x80, }; - /// @enum CapsFlag + /// @enum CapFlag /// @brief Flags used for RI capabilities - enum struct CapsFlag : std::uint8_t + enum struct CapFlag : std::uint8_t { Floodfill, Hidden, @@ -110,50 +110,50 @@ class RouterInfo : public RoutingDestination { /// @return Char flag of given enumerated caps flag /// @param flag Flag enum used for caps char flag - char GetTrait(CapsFlag flag) const noexcept + char GetTrait(CapFlag flag) const noexcept { switch (flag) { - case CapsFlag::Floodfill: + case CapFlag::Floodfill: return 'f'; // Floodfill - case CapsFlag::Hidden: + case CapFlag::Hidden: return 'H'; // Hidden - case CapsFlag::Reachable: + case CapFlag::Reachable: return 'R'; // Reachable - case CapsFlag::Unreachable: + case CapFlag::Unreachable: return 'U'; // Unreachable - case CapsFlag::LowBandwidth1: + case CapFlag::LowBandwidth1: return 'K'; // Under 12 KBps shared bandwidth - case CapsFlag::LowBandwidth2: + case CapFlag::LowBandwidth2: return 'L'; // 12 - 48 KBps shared bandwidth - case CapsFlag::HighBandwidth1: + case CapFlag::HighBandwidth1: return 'M'; // 48 - 64 KBps shared bandwidth - case CapsFlag::HighBandwidth2: + case CapFlag::HighBandwidth2: return 'N'; // 64 - 128 KBps shared bandwidth - case CapsFlag::HighBandwidth3: + case CapFlag::HighBandwidth3: return 'O'; // 128 - 256 KBps shared bandwidth - case CapsFlag::HighBandwidth4: + case CapFlag::HighBandwidth4: return 'P'; // 256 - 2000 KBps shared bandwidth - case CapsFlag::UnlimitedBandwidth: + case CapFlag::UnlimitedBandwidth: return 'X'; // Over 2000 KBps shared bandwidth - case CapsFlag::SSUTesting: + case CapFlag::SSUTesting: return 'B'; // Willing and able to participate in peer tests (as Bob or Charlie) - case CapsFlag::SSUIntroducer: + case CapFlag::SSUIntroducer: return 'C'; // Willing and able to serve as an introducer (serving as Bob for an otherwise unreachable Alice) - case CapsFlag::Unknown: + case CapFlag::Unknown: default: return ' '; // TODO(anonimal): review } @@ -161,49 +161,49 @@ class RouterInfo : public RoutingDestination { /// @return Enumerated caps flag /// @param value Char value of potential caps flag given - CapsFlag GetTrait(const char& value) const noexcept + CapFlag GetTrait(const char& value) const noexcept { - if (value == GetTrait(CapsFlag::Floodfill)) - return CapsFlag::Floodfill; + if (value == GetTrait(CapFlag::Floodfill)) + return CapFlag::Floodfill; - else if (value == GetTrait(CapsFlag::Hidden)) - return CapsFlag::Hidden; + else if (value == GetTrait(CapFlag::Hidden)) + return CapFlag::Hidden; - else if (value == GetTrait(CapsFlag::Reachable)) - return CapsFlag::Reachable; + else if (value == GetTrait(CapFlag::Reachable)) + return CapFlag::Reachable; - else if (value == GetTrait(CapsFlag::Unreachable)) - return CapsFlag::Unreachable; + else if (value == GetTrait(CapFlag::Unreachable)) + return CapFlag::Unreachable; - else if (value == GetTrait(CapsFlag::LowBandwidth1)) - return CapsFlag::LowBandwidth1; + else if (value == GetTrait(CapFlag::LowBandwidth1)) + return CapFlag::LowBandwidth1; - else if (value == GetTrait(CapsFlag::LowBandwidth2)) - return CapsFlag::LowBandwidth2; + else if (value == GetTrait(CapFlag::LowBandwidth2)) + return CapFlag::LowBandwidth2; - else if (value == GetTrait(CapsFlag::HighBandwidth1)) - return CapsFlag::HighBandwidth1; + else if (value == GetTrait(CapFlag::HighBandwidth1)) + return CapFlag::HighBandwidth1; - else if (value == GetTrait(CapsFlag::HighBandwidth2)) - return CapsFlag::HighBandwidth2; + else if (value == GetTrait(CapFlag::HighBandwidth2)) + return CapFlag::HighBandwidth2; - else if (value == GetTrait(CapsFlag::HighBandwidth3)) - return CapsFlag::HighBandwidth3; + else if (value == GetTrait(CapFlag::HighBandwidth3)) + return CapFlag::HighBandwidth3; - else if (value == GetTrait(CapsFlag::HighBandwidth4)) - return CapsFlag::HighBandwidth4; + else if (value == GetTrait(CapFlag::HighBandwidth4)) + return CapFlag::HighBandwidth4; - else if (value == GetTrait(CapsFlag::UnlimitedBandwidth)) - return CapsFlag::UnlimitedBandwidth; + else if (value == GetTrait(CapFlag::UnlimitedBandwidth)) + return CapFlag::UnlimitedBandwidth; - else if (value == GetTrait(CapsFlag::SSUTesting)) - return CapsFlag::SSUTesting; + else if (value == GetTrait(CapFlag::SSUTesting)) + return CapFlag::SSUTesting; - else if (value == GetTrait(CapsFlag::SSUIntroducer)) - return CapsFlag::SSUIntroducer; + else if (value == GetTrait(CapFlag::SSUIntroducer)) + return CapFlag::SSUIntroducer; else - return CapsFlag::Unknown; // TODO(anonimal): review + return CapFlag::Unknown; // TODO(anonimal): review } struct Introducer { @@ -467,19 +467,19 @@ class RouterInfo : public RoutingDestination { bool UsesIntroducer() const; bool IsIntroducer() const { - return m_Caps & Caps::SSUIntroducer; + return m_Caps & Cap::SSUIntroducer; } bool IsPeerTesting() const { - return m_Caps & Caps::SSUTesting; + return m_Caps & Cap::SSUTesting; } bool IsHidden() const { - return m_Caps & Caps::Hidden; + return m_Caps & Cap::Hidden; } bool IsHighBandwidth() const { - return m_Caps & Caps::HighBandwidth; + return m_Caps & Cap::HighBandwidth; } std::uint8_t GetCaps() const { diff --git a/src/core/router/net_db/impl.cc b/src/core/router/net_db/impl.cc index 99080c81..05775c51 100644 --- a/src/core/router/net_db/impl.cc +++ b/src/core/router/net_db/impl.cc @@ -904,7 +904,7 @@ std::shared_ptr NetDb::GetHighBandwidthRandomRouter( return !router->IsHidden() && router != compatible_with && router->IsCompatible(*compatible_with) && - (router->GetCaps() & RouterInfo::Caps::HighBandwidth); + (router->GetCaps() & RouterInfo::Cap::HighBandwidth); }); }