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

Commit

Permalink
RouterInfo: refactor private caps setter and remove dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
anonimal committed Apr 22, 2017
1 parent 1f5a458 commit 8db6d07
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 51 deletions.
90 changes: 44 additions & 46 deletions src/core/router/info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ void RouterInfo::ParseRouterInfo(const std::string& router_info)
value.c_str(), value.size(), address.key, 32);
break;
case Trait::Caps:
ExtractCaps(value.c_str());
SetCaps(value);
break;
default:
// Test for introducers
Expand Down Expand Up @@ -450,7 +450,7 @@ void RouterInfo::ParseRouterInfo(const std::string& router_info)
// Set capabilities
// TODO(anonimal): review setter implementation
if (key == GetTrait(Trait::Caps))
ExtractCaps(value.c_str());
SetCaps(value);
}

// Router *should* be unreachable
Expand All @@ -463,43 +463,49 @@ void RouterInfo::ParseRouterInfo(const std::string& router_info)
}
}

// TODO(anonimal): refactor + rename as setter
void RouterInfo::ExtractCaps(
const char* value) {
const char* cap = value;
while (*cap) {
switch (GetTrait(*cap)) {
case CapFlag::Floodfill:
m_Caps |= Cap::Floodfill;
break;
case CapFlag::UnlimitedBandwidth:
m_Caps |= Cap::UnlimitedBandwidth;
break;
case CapFlag::HighBandwidth1:
case CapFlag::HighBandwidth2:
case CapFlag::HighBandwidth3:
case CapFlag::HighBandwidth4:
m_Caps |= Cap::HighBandwidth;
break;
case CapFlag::Hidden:
m_Caps |= Cap::Hidden;
break;
case CapFlag::Reachable:
m_Caps |= Cap::Reachable;
break;
case CapFlag::Unreachable:
m_Caps |= Cap::Unreachable;
break;
case CapFlag::SSUTesting:
m_Caps |= Cap::SSUTesting;
break;
case CapFlag::SSUIntroducer:
m_Caps |= Cap::SSUIntroducer;
break;
default: {}
void RouterInfo::SetCaps(const std::string& caps)
{
LOG(debug) << "RouterInfo: " << __func__ << ": setting caps " << caps;
for (const auto& cap : caps)
{
switch (GetTrait(cap))
{
case CapFlag::Floodfill:
m_Caps |= Cap::Floodfill;
break;
case CapFlag::UnlimitedBandwidth:
m_Caps |= Cap::UnlimitedBandwidth;
break;
case CapFlag::HighBandwidth1:
case CapFlag::HighBandwidth2:
case CapFlag::HighBandwidth3:
case CapFlag::HighBandwidth4:
m_Caps |= Cap::HighBandwidth;
break;
// TODO(anonimal): Low bandwidth!?
case CapFlag::Hidden:
m_Caps |= Cap::Hidden;
break;
case CapFlag::Reachable:
m_Caps |= Cap::Reachable;
break;
case CapFlag::Unreachable:
m_Caps |= Cap::Unreachable;
break;
case CapFlag::SSUTesting:
m_Caps |= Cap::SSUTesting;
break;
case CapFlag::SSUIntroducer:
m_Caps |= Cap::SSUIntroducer;
break;
case CapFlag::Unknown:
default:
{
LOG(error) << "RouterInfo: " << __func__
<< ": ignoring unknown cap " << cap;
}
}
}
cap++;
}
}

void RouterInfo::UpdateCapsProperty()
Expand Down Expand Up @@ -818,14 +824,6 @@ void RouterInfo::SetCaps(
UpdateCapsProperty();
}

// TODO(anonimal): refactor this setter, it should be simpler
void RouterInfo::SetCaps(
const char* caps) {
SetProperty("caps", caps);
m_Caps = 0;
ExtractCaps(caps);
}

void RouterInfo::SetProperty(
const std::string& key,
const std::string& value) {
Expand Down
6 changes: 1 addition & 5 deletions src/core/router/info.h
Original file line number Diff line number Diff line change
Expand Up @@ -478,9 +478,6 @@ class RouterInfo : public RoutingDestination {
void SetCaps(
std::uint8_t caps);

void SetCaps(
const char* caps);

void SetUnreachable(bool unreachable) {
m_IsUnreachable = unreachable;
}
Expand Down Expand Up @@ -573,8 +570,7 @@ class RouterInfo : public RoutingDestination {
core::StringStream& router_info,
const PrivateKeys& private_keys);

void ExtractCaps(
const char* value);
void SetCaps(const std::string& caps);

const Address* GetAddress(
Transport s,
Expand Down

0 comments on commit 8db6d07

Please sign in to comment.