Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

re-publish and re-discover immediately when the node disconnects #713

Merged
merged 3 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 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) {
statusCb = std::move(cb);
if (cb)
statusCbs.emplace_back(std::move(cb));
}

/**
Expand Down Expand Up @@ -519,7 +520,8 @@ class OPENDHT_PUBLIC DhtRunner {

NodeStatus status4 {NodeStatus::Disconnected},
status6 {NodeStatus::Disconnected};
StatusCallback statusCb {nullptr};

std::vector<StatusCallback> statusCbs {};

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

if (context.statusChangedCallback) {
statusCb = std::move(context.statusChangedCallback);
}
statusCbs.clear();
if (context.statusChangedCallback)
statusCbs.emplace_back(std::move(context.statusChangedCallback));
if (context.certificateStore) {
dht_->setLocalCertificateStore(std::move(context.certificateStore));
}
Expand Down Expand Up @@ -264,6 +264,13 @@ DhtRunner::run(const Config& config, Context&& context)
}
}
}
if (peerDiscovery_) {
statusCbs.emplace_back([this](NodeStatus status4, NodeStatus status6) {
if (status4 == NodeStatus::Disconnected && status6 == NodeStatus::Disconnected) {
peerDiscovery_->connectivityChanged();
}
});
}
#endif
}
}
Expand Down Expand Up @@ -690,8 +697,9 @@ DhtRunner::loop_()
if (nstatus4 != status4 || nstatus6 != status6) {
status4 = nstatus4;
status6 = nstatus6;
if (statusCb)
statusCb(status4, status6);
for (auto& cb : statusCbs){
cb(status4, status6);
}
}

return wakeup;
Expand Down
8 changes: 6 additions & 2 deletions src/peer_discovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,12 @@ PeerDiscovery::DomainPeerDiscovery::reDiscover()
void
PeerDiscovery::DomainPeerDiscovery::connectivityChanged()
{
reDiscover();
publish(sockAddrSend_);
ioContext_->post([this] () {
reDiscover();
publish(sockAddrSend_);
});
if (logger_)
logger_->d("PeerDiscovery: connectivity changed");
}

PeerDiscovery::PeerDiscovery(in_port_t port, Sp<asio::io_context> ioContext, Sp<Logger> logger)
Expand Down
Loading