mirror of
https://github.com/savoirfairelinux/opendht.git
synced 2026-11-08 04:21:51 +00:00
listeners: init with local values
This commit is contained in:
1 parent
f6ef054d9d
commit
277a9312e2
2 files changed
+10
-1
No files matched your search
@@ -509,8 +509,11 @@ private:
|
||||
std::vector<Storage> store {};
|
||||
std::list<Search> searches {};
|
||||
uint16_t search_id {0};
|
||||
|
||||
// map a global listen token to IPv4, IPv6 specific listen tokens.
|
||||
// 0 is the invalid token.
|
||||
std::map<size_t, std::pair<size_t, size_t>> listeners {};
|
||||
size_t listener_token {0};
|
||||
size_t listener_token {1};
|
||||
|
||||
sockaddr_storage blacklist[BLACKLISTED_MAX] {};
|
||||
unsigned next_blacklisted = 0;
|
||||
|
||||
@@ -1000,6 +1000,8 @@ Dht::announce(const InfoHash& id, sa_family_t af, const std::shared_ptr<Value>&
|
||||
size_t
|
||||
Dht::listenTo(const InfoHash& id, sa_family_t af, GetCallback cb, Value::Filter f)
|
||||
{
|
||||
if (!isRunning(af))
|
||||
return 0;
|
||||
DHT_WARN("listenTo %s", id.toString().c_str());
|
||||
auto sri = std::find_if (searches.begin(), searches.end(), [id,af](const Search& s) {
|
||||
return s.id == id && s.af == af;
|
||||
@@ -1037,6 +1039,8 @@ Dht::listen(const InfoHash& id, GetCallback cb, Value::Filter f)
|
||||
return true;
|
||||
};
|
||||
|
||||
gcb(getLocal(id, f));
|
||||
|
||||
auto token4 = Dht::listenTo(id, AF_INET, gcb, f);
|
||||
auto token6 = Dht::listenTo(id, AF_INET6, gcb, f);
|
||||
auto token = ++listener_token;
|
||||
@@ -1053,6 +1057,8 @@ Dht::cancelListen(const InfoHash& id, size_t token)
|
||||
for (auto& s : searches) {
|
||||
if (s.id != id) continue;
|
||||
auto af_token = s.af == AF_INET ? it->second.first : it->second.second;
|
||||
if (af_token == 0)
|
||||
continue;
|
||||
auto sit = s.listeners.find(af_token);
|
||||
if (sit == s.listeners.end())
|
||||
continue;
|
||||
|
||||
Reference in new issue
Block a user