diff --git a/include/opendht/dhtrunner.h b/include/opendht/dhtrunner.h index cdf94053..097b003f 100644 --- a/include/opendht/dhtrunner.h +++ b/include/opendht/dhtrunner.h @@ -360,6 +360,7 @@ public: std::string getSearchLog(const InfoHash&, sa_family_t af = AF_UNSPEC) const; std::vector getPublicAddress(sa_family_t af = AF_UNSPEC); std::vector getPublicAddressStr(sa_family_t af = AF_UNSPEC); + void getPublicAddress(std::function&&)>, sa_family_t af = AF_UNSPEC); // securedht methods diff --git a/src/dhtrunner.cpp b/src/dhtrunner.cpp index b1e775b7..c027df8b 100644 --- a/src/dhtrunner.cpp +++ b/src/dhtrunner.cpp @@ -594,6 +594,18 @@ DhtRunner::getPublicAddressStr(sa_family_t af) return ret; } +void +DhtRunner::getPublicAddress(std::function&&)> cb, sa_family_t af) +{ + std::lock_guard lck(storage_mtx); + ongoing_ops++; + pending_ops_prio.emplace([cb = std::move(cb), this, af](SecureDht& dht){ + cb(dht.getPublicAddress(af)); + opEnded(); + }); + cv.notify_all(); +} + void DhtRunner::registerCertificate(std::shared_ptr cert) { std::lock_guard lck(dht_mtx);