mirror of
https://github.com/savoirfairelinux/opendht.git
synced 2026-11-08 04:21:51 +00:00
dht: allow to specify address family for getPublicAddress
This commit is contained in:
1 parent
a340943994
commit
8575bd4f96
3 files changed
+8
-8
No files matched your search
@@ -369,7 +369,7 @@ public:
|
||||
/* This must be provided by the user. */
|
||||
static bool isBlacklisted(const sockaddr*, socklen_t) { return false; }
|
||||
|
||||
std::vector<Address> getPublicAddress();
|
||||
std::vector<Address> getPublicAddress(sa_family_t family = 0);
|
||||
|
||||
protected:
|
||||
LogMethod DHT_DEBUG = NOLOG;
|
||||
|
||||
@@ -293,14 +293,14 @@ public:
|
||||
std::lock_guard<std::mutex> lck(dht_mtx);
|
||||
return dht_->getSearchesLog(af);
|
||||
}
|
||||
std::vector<Address> getPublicAddress()
|
||||
std::vector<Address> getPublicAddress(sa_family_t af = 0)
|
||||
{
|
||||
std::lock_guard<std::mutex> lck(dht_mtx);
|
||||
return dht_->getPublicAddress();
|
||||
return dht_->getPublicAddress(af);
|
||||
}
|
||||
std::vector<std::string> getPublicAddressStr()
|
||||
std::vector<std::string> getPublicAddressStr(sa_family_t af = 0)
|
||||
{
|
||||
auto addrs = getPublicAddress();
|
||||
auto addrs = getPublicAddress(af);
|
||||
std::vector<std::string> ret(addrs.size());
|
||||
std::transform(addrs.begin(), addrs.end(), ret.begin(), dht::printAddr);
|
||||
return ret;
|
||||
|
||||
+3
-3
@@ -573,15 +573,15 @@ Dht::isNodeBlacklisted(const sockaddr *sa, socklen_t salen) const
|
||||
}
|
||||
|
||||
std::vector<Address>
|
||||
Dht::getPublicAddress()
|
||||
Dht::getPublicAddress(sa_family_t family)
|
||||
{
|
||||
std::sort(reported_addr.begin(), reported_addr.end(), [](const ReportedAddr& a, const ReportedAddr& b) {
|
||||
return a.first < b.first;
|
||||
});
|
||||
std::vector<Address> ret;
|
||||
ret.reserve(reported_addr.size());
|
||||
for (const auto& addr : reported_addr)
|
||||
ret.emplace_back(addr.second);
|
||||
if (!family || family == addr.second.first.ss_family)
|
||||
ret.emplace_back(addr.second);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user