Skip to content
This repository has been archived by the owner on Sep 1, 2022. It is now read-only.

Commit

Permalink
RouterInfo: treat singular cap as not plural
Browse files Browse the repository at this point in the history
otherwise there is potential confusion with relation to caps member.
  • Loading branch information
anonimal committed Apr 22, 2017
1 parent f7bac4c commit 8ae8693
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 108 deletions.
30 changes: 15 additions & 15 deletions src/core/router/context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -170,27 +170,27 @@ 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();
}
}

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
Expand All @@ -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
Expand Down Expand Up @@ -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();
}
Expand Down
82 changes: 41 additions & 41 deletions src/core/router/info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -838,7 +838,7 @@ void RouterInfo::DeleteProperty(
}

bool RouterInfo::IsFloodfill() const {
return m_Caps & Caps::Floodfill;
return m_Caps & Cap::Floodfill;
}

bool RouterInfo::IsNTCP(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 8ae8693

Please sign in to comment.