Skip to content
Snippets Groups Projects
Unverified Commit fb09e1a7 authored by Sébastien Blin's avatar Sébastien Blin
Browse files

upnp: remove restartTimers_

Change-Id: I41fc348e6bcc2a0e042fe9355cb86288065300d4
parent 1f9c191b
No related branches found
No related tags found
No related merge requests found
...@@ -67,11 +67,8 @@ NatPmp::NatPmp() ...@@ -67,11 +67,8 @@ NatPmp::NatPmp()
or restart_; or restart_;
}); });
if (not pmpRun_ or not pmpIGD_) break; if (not pmpRun_ or not pmpIGD_) break;
auto now = clock::now(); if (restart_) {
std::lock_guard<std::mutex> lkNat(natpmpMutex_);
// 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_);
clearNatPmpHdl(natpmpHdl_); clearNatPmpHdl(natpmpHdl_);
int err = 0; int err = 0;
char localHostBuf[INET_ADDRSTRLEN]; char localHostBuf[INET_ADDRSTRLEN];
...@@ -87,7 +84,10 @@ NatPmp::NatPmp() ...@@ -87,7 +84,10 @@ NatPmp::NatPmp()
} }
if (err < 0) { if (err < 0) {
JAMI_ERR("NAT-PMP: Can't initialize libnatpmp -> %s", getNatPmpErrorStr(err).c_str()); 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 { } else {
char addrbuf[INET_ADDRSTRLEN]; char addrbuf[INET_ADDRSTRLEN];
inet_ntop(AF_INET, &natpmpHdl_.gateway, addrbuf, sizeof(addrbuf)); inet_ntop(AF_INET, &natpmpHdl_.gateway, addrbuf, sizeof(addrbuf));
...@@ -98,6 +98,7 @@ NatPmp::NatPmp() ...@@ -98,6 +98,7 @@ NatPmp::NatPmp()
} }
// Check if we need to update IGD. // Check if we need to update IGD.
auto now = clock::now();
if (pmpIGD_->renewal_ < now) { if (pmpIGD_->renewal_ < now) {
lk.unlock(); lk.unlock();
searchForPmpIgd(); searchForPmpIgd();
...@@ -172,7 +173,6 @@ NatPmp::clearIgds() ...@@ -172,7 +173,6 @@ NatPmp::clearIgds()
std::lock_guard<std::mutex> lk(validIgdMutex_); std::lock_guard<std::mutex> lk(validIgdMutex_);
pmpIGD_.reset(new PMPIGD()); pmpIGD_.reset(new PMPIGD());
restart_ = true; restart_ = true;
restartTimer_ = clock::now();
} }
void void
......
...@@ -95,7 +95,6 @@ private: ...@@ -95,7 +95,6 @@ private:
std::thread pmpThread_ {}; // NatPmp thread. std::thread pmpThread_ {}; // NatPmp thread.
std::atomic_bool restart_ {false}; // Variable to indicate we need to restart natpmp after a connectivity change. 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. 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. std::shared_ptr<PMPIGD> pmpIGD_ {}; // IGD discovered by NatPmp.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment