-
Notifications
You must be signed in to change notification settings - Fork 174
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -409,7 +409,7 @@ class OPENDHT_PUBLIC DhtRunner { | |
void run(const Config& config, Context&& context); | ||
|
||
void setOnStatusChanged(StatusCallback&& cb) { | ||
statusCb = std::move(cb); | ||
statusCbs.emplace_back(std::move(cb)); | ||
} | ||
|
||
/** | ||
|
@@ -519,7 +519,8 @@ class OPENDHT_PUBLIC DhtRunner { | |
|
||
NodeStatus status4 {NodeStatus::Disconnected}, | ||
status6 {NodeStatus::Disconnected}; | ||
StatusCallback statusCb {nullptr}; | ||
|
||
std::list<StatusCallback> statusCbs {}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could be a vector |
||
|
||
/** PeerDiscovery Parameters */ | ||
std::shared_ptr<PeerDiscovery> peerDiscovery_; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -180,9 +180,8 @@ DhtRunner::run(const Config& config, Context&& context) | |
throw; | ||
} | ||
|
||
if (context.statusChangedCallback) { | ||
statusCb = std::move(context.statusChangedCallback); | ||
} | ||
statusCbs.clear(); | ||
statusCbs.emplace_back(std::move(context.statusChangedCallback)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. only emplace if |
||
if (context.certificateStore) { | ||
dht_->setLocalCertificateStore(std::move(context.certificateStore)); | ||
} | ||
|
@@ -264,6 +263,13 @@ DhtRunner::run(const Config& config, Context&& context) | |
} | ||
} | ||
} | ||
if (config.peer_discovery && config.peer_publish) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what if only There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be |
||
statusCbs.emplace_back([this](NodeStatus status4, NodeStatus status6) { | ||
if (status4 == NodeStatus::Disconnected && status6 == NodeStatus::Disconnected) { | ||
peerDiscovery_->connectivityChanged(); | ||
} | ||
}); | ||
} | ||
#endif | ||
} | ||
} | ||
|
@@ -690,8 +696,13 @@ DhtRunner::loop_() | |
if (nstatus4 != status4 || nstatus6 != status6) { | ||
status4 = nstatus4; | ||
status6 = nstatus6; | ||
if (statusCb) | ||
statusCb(status4, status6); | ||
if (!statusCbs.empty()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if not needed |
||
{ | ||
for (auto& cb : statusCbs){ | ||
if (cb) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. check not needed |
||
cb(status4, status6); | ||
} | ||
} | ||
} | ||
|
||
return wakeup; | ||
|
@@ -1039,10 +1050,6 @@ 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(); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
emplace if not empty