Commit fb09e1a7 authored by Sébastien Blin's avatar Sébastien Blin

upnp: remove restartTimers_

Change-Id: I41fc348e6bcc2a0e042fe9355cb86288065300d4
parent 1f9c191b
......@@ -67,11 +67,8 @@ NatPmp::NatPmp()
or restart_;
});
if (not pmpRun_ or not pmpIGD_) break;
auto now = clock::now();
// If the restart flag is set, wait for 1 second to have passed by to try and reinitialize natpmp.
if (restart_ and (now - restartTimer_ >= std::chrono::seconds(1))) {
std::lock_guard<std::mutex> lk(natpmpMutex_);
if (restart_) {
std::lock_guard<std::mutex> lkNat(natpmpMutex_);
clearNatPmpHdl(natpmpHdl_);
int err = 0;
char localHostBuf[INET_ADDRSTRLEN];
......@@ -87,7 +84,10 @@ NatPmp::NatPmp()
}
if (err < 0) {
JAMI_ERR("NAT-PMP: Can't initialize libnatpmp -> %s", getNatPmpErrorStr(err).c_str());
restartTimer_ = clock::now();
// Retry to re-init nat pmp in 10 seconds
if (pmpRun_)
pmpCv_.wait_for(lk, std::chrono::seconds(10));
continue;
} else {
char addrbuf[INET_ADDRSTRLEN];
inet_ntop(AF_INET, &natpmpHdl_.gateway, addrbuf, sizeof(addrbuf));
......@@ -98,6 +98,7 @@ NatPmp::NatPmp()
}
// Check if we need to update IGD.
auto now = clock::now();
if (pmpIGD_->renewal_ < now) {
lk.unlock();
searchForPmpIgd();
......@@ -172,7 +173,6 @@ NatPmp::clearIgds()
std::lock_guard<std::mutex> lk(validIgdMutex_);
pmpIGD_.reset(new PMPIGD());
restart_ = true;
restartTimer_ = clock::now();
}
void
......
......@@ -95,7 +95,6 @@ private:
std::thread pmpThread_ {}; // NatPmp thread.
std::atomic_bool restart_ {false}; // Variable to indicate we need to restart natpmp after a connectivity change.
time_point restartTimer_ {clock::now()}; // Keeps track of time elapsed since restart was triggered.
unsigned int restartSearchRetry_ {0}; // Keeps track of number of times we try to find an IGD after a connectivity change.
std::shared_ptr<PMPIGD> pmpIGD_ {}; // IGD discovered by NatPmp.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment