From 3765873b94bd463b79f8beb580ae5fd2ee407876 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= Date: Tue, 13 Apr 2021 18:41:14 -0400 Subject: [PATCH] dhtrunner: add async version of getPublicAddress --- include/opendht/dhtrunner.h | 1 + src/dhtrunner.cpp | 12 ++++++++++++ 2 files changed, 13 insertions(+) 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);