From bb62926636c5c4b283968dd1b200bb82603b6072 Mon Sep 17 00:00:00 2001 From: Adrien Beraud <adrien.beraud@savoirfairelinux.com> Date: Mon, 7 Aug 2017 16:07:06 -0400 Subject: [PATCH] ringaccount: avoid flipping dht status [Guillaume: fix ci msg typo] Change-Id: Id4fecc5683ef82cdf81d0b75c1d54ebffd8dc8dd Reviewed-by: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com> --- src/ringdht/ringaccount.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/ringdht/ringaccount.cpp b/src/ringdht/ringaccount.cpp index 30e4e1de53..a17b589981 100644 --- a/src/ringdht/ringaccount.cpp +++ b/src/ringdht/ringaccount.cpp @@ -2139,10 +2139,14 @@ RingAccount::doRegister_() }); #endif - dht_.setOnStatusChanged([this](dht::NodeStatus s4, dht::NodeStatus s6) { + auto currentDhtStatus = std::make_shared<dht::NodeStatus>(dht::NodeStatus::Disconnected); + dht_.setOnStatusChanged([this, currentDhtStatus](dht::NodeStatus s4, dht::NodeStatus s6) { RING_DBG("[Account %s] Dht status : IPv4 %s; IPv6 %s", getAccountID().c_str(), dhtStatusStr(s4), dhtStatusStr(s6)); RegistrationState state; - switch (std::max(s4, s6)) { + auto newStatus = std::max(s4, s6); + if (newStatus == *currentDhtStatus) + return; + switch (newStatus) { case dht::NodeStatus::Connecting: RING_WARN("[Account %s] connecting to the DHT network...", getAccountID().c_str()); state = RegistrationState::TRYING; @@ -2159,6 +2163,7 @@ RingAccount::doRegister_() state = RegistrationState::ERROR_GENERIC; break; } + *currentDhtStatus = newStatus; setRegistrationState(state); }); -- GitLab