Skip to content

Commit

Permalink
fix getConnections (#285)
Browse files Browse the repository at this point in the history
Signed-off-by: turuslan <[email protected]>
  • Loading branch information
turuslan authored Dec 19, 2024
1 parent a52146d commit b183f88
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/network/impl/connection_manager_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ namespace libp2p::network {
if (it == connections_.end()) {
return {};
}

return std::vector<ConnectionManager::ConnectionSPtr>(it->second.begin(),
it->second.end());
std::vector<ConnectionSPtr> out;
out.reserve(it->second.size());
for (const auto &conn : it->second) {
if (not conn->isClosed()) {
out.emplace_back(conn);
}
}
return out;
}

ConnectionManager::ConnectionSPtr
Expand Down Expand Up @@ -66,7 +71,11 @@ namespace libp2p::network {
out.reserve(connections_.size());

for (auto &&entry : connections_) {
out.insert(out.end(), entry.second.begin(), entry.second.end());
for (const auto &conn : entry.second) {
if (not conn->isClosed()) {
out.emplace_back(conn);
}
}
}

return out;
Expand Down

0 comments on commit b183f88

Please sign in to comment.