From 9d83ee169b1079c322eac4a6b97ebb62cb1eb425 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20D=C3=A9saulniers?= <simon.desaulniers@savoirfairelinux.com> Date: Sat, 4 Feb 2017 19:30:49 -0500 Subject: [PATCH] dht: randomize id in Dht layer --- src/dht.cpp | 10 +++++----- src/securedht.cpp | 8 ++------ 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/dht.cpp b/src/dht.cpp index 6b93871c..2619ed2e 100644 --- a/src/dht.cpp +++ b/src/dht.cpp @@ -2883,11 +2883,11 @@ Dht::~Dht() Dht::Dht() : store(), scheduler(DHT_LOG), network_engine(DHT_LOG, scheduler) {} Dht::Dht(int s, int s6, Config config) - : myid(config.node_id), - is_bootstrap(config.is_bootstrap), - maintain_storage(config.maintain_storage), store(), store_quota(), - scheduler(DHT_LOG), - network_engine(myid, config.network, s, s6, DHT_LOG, scheduler, + : myid(config.node_id != zeroes ? config.node_id : InfoHash::getRandom()), + is_bootstrap(config.is_bootstrap), + maintain_storage(config.maintain_storage), store(), store_quota(), + scheduler(DHT_LOG), + network_engine(myid, config.network, s, s6, DHT_LOG, scheduler, std::bind(&Dht::onError, this, _1, _2), std::bind(&Dht::onNewNode, this, _1, _2), std::bind(&Dht::onReportedAddr, this, _1, _2), diff --git a/src/securedht.cpp b/src/securedht.cpp index d9bcfc54..7642fec9 100644 --- a/src/securedht.cpp +++ b/src/securedht.cpp @@ -36,12 +36,8 @@ namespace dht { Config& getConfig(SecureDht::Config& conf) { auto& c = conf.node_config; - if (c.node_id == InfoHash()) { - if (conf.id.second) - c.node_id = InfoHash::get("node:"+conf.id.second->getId().toString()); - else - c.node_id = InfoHash::getRandom(); - } + if (c.node_id == InfoHash() and conf.id.second) + c.node_id = InfoHash::get("node:"+conf.id.second->getId().toString()); return c; } -- GitLab