Skip to content
Snippets Groups Projects
Commit 5f624f6e authored by Adrien Béraud's avatar Adrien Béraud
Browse files

SwarmManager: minor optimisations

Change-Id: Icdbef7639c772533b633427fc2cf0ae51595b584
parent 66d81002
No related branches found
No related tags found
No related merge requests found
......@@ -503,7 +503,7 @@ RoutingTable::getAllNodes() const
const auto& knownNodes = b.getKnownNodes();
const auto& mobileNodes = b.getMobileNodes();
const auto& connectingNodes = b.getConnectingNodes();
ret.reserve(nodes.size() + knownNodes.size() + mobileNodes.size() + connectingNodes.size());
ret.insert(ret.end(), nodes.begin(), nodes.end());
ret.insert(ret.end(), knownNodes.begin(), knownNodes.end());
ret.insert(ret.end(), mobileNodes.begin(), mobileNodes.end());
......
......@@ -202,6 +202,8 @@ public:
return connecting_nodes.find(nodeId) != connecting_nodes.end();
}
bool isEmpty() const { return nodes.empty(); }
/**
* Indicate if bucket is full
* @return true if bucket is full, false if not
......
......@@ -91,7 +91,7 @@ SwarmManager::addChannel(const std::shared_ptr<dhtnet::ChannelSocketInterface>&
auto emit = false;
{
std::lock_guard lock(mutex);
emit = routing_table.findBucket(getId())->getNodeIds().size() == 0;
emit = routing_table.findBucket(getId())->isEmpty();
auto bucket = routing_table.findBucket(channel->deviceId());
if (routing_table.addNode(channel, bucket)) {
std::error_code ec;
......@@ -348,7 +348,7 @@ SwarmManager::tryConnect(const NodeId& nodeId)
bucket->addKnownNode(nodeId);
bucket = shared->routing_table.findBucket(shared->getId());
if (bucket->getConnectingNodesSize() == 0
&& bucket->getNodeIds().size() == 0 && shared->onConnectionChanged_) {
&& bucket->isEmpty() && shared->onConnectionChanged_) {
lk.unlock();
JAMI_WARNING("[SwarmManager {:p}] Bootstrap: all connections failed",
fmt::ptr(shared.get()));
......@@ -368,11 +368,7 @@ std::vector<NodeId>
SwarmManager::getAllNodes() const
{
std::lock_guard lock(mutex);
std::vector<NodeId> nodes;
const auto& rtNodes = routing_table.getAllNodes();
nodes.insert(nodes.end(), rtNodes.begin(), rtNodes.end());
return nodes;
return routing_table.getAllNodes();
}
void
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment