Skip to content

Commit

Permalink
peer discovery: address requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
AmnaSnene authored and aberaud committed Jun 25, 2024
1 parent 8b3f7f2 commit 3e2fd5e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
5 changes: 3 additions & 2 deletions include/opendht/dhtrunner.h
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,8 @@ class OPENDHT_PUBLIC DhtRunner {
void run(const Config& config, Context&& context);

void setOnStatusChanged(StatusCallback&& cb) {
statusCbs.emplace_back(std::move(cb));
if (cb)
statusCbs.emplace_back(std::move(cb));
}

/**
Expand Down Expand Up @@ -520,7 +521,7 @@ class OPENDHT_PUBLIC DhtRunner {
NodeStatus status4 {NodeStatus::Disconnected},
status6 {NodeStatus::Disconnected};

std::list<StatusCallback> statusCbs {};
std::vector<StatusCallback> statusCbs {};

/** PeerDiscovery Parameters */
std::shared_ptr<PeerDiscovery> peerDiscovery_;
Expand Down
17 changes: 9 additions & 8 deletions src/dhtrunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ DhtRunner::run(const Config& config, Context&& context)
}

statusCbs.clear();
statusCbs.emplace_back(std::move(context.statusChangedCallback));
if (context.statusChangedCallback)
statusCbs.emplace_back(std::move(context.statusChangedCallback));
if (context.certificateStore) {
dht_->setLocalCertificateStore(std::move(context.certificateStore));
}
Expand Down Expand Up @@ -263,7 +264,7 @@ DhtRunner::run(const Config& config, Context&& context)
}
}
}
if (config.peer_discovery && config.peer_publish) {
if (peerDiscovery_) {
statusCbs.emplace_back([this](NodeStatus status4, NodeStatus status6) {
if (status4 == NodeStatus::Disconnected && status6 == NodeStatus::Disconnected) {
peerDiscovery_->connectivityChanged();
Expand Down Expand Up @@ -696,12 +697,8 @@ DhtRunner::loop_()
if (nstatus4 != status4 || nstatus6 != status6) {
status4 = nstatus4;
status6 = nstatus6;
if (!statusCbs.empty())
{
for (auto& cb : statusCbs){
if (cb)
cb(status4, status6);
}
for (auto& cb : statusCbs){
cb(status4, status6);
}
}

Expand Down Expand Up @@ -1050,6 +1047,10 @@ DhtRunner::connectivityChanged()
std::lock_guard<std::mutex> lck(storage_mtx);
pending_ops_prio.emplace([=](SecureDht& dht) {
dht.connectivityChanged();
#ifdef OPENDHT_PEER_DISCOVERY
if (peerDiscovery_)
peerDiscovery_->connectivityChanged();
#endif
});
cv.notify_all();
}
Expand Down

0 comments on commit 3e2fd5e

Please sign in to comment.