mirror of
https://git.jami.net/savoirfairelinux/jami-daemon.git
synced 2025-08-12 22:09:25 +08:00
NAT-PMP: improve connectivityChanged support
Will properly check for a valid PMP IGD, clear and reopen ports in case of connectivity change. Change-Id: I47acfa9027217f5ba9f6c6c5b99d46abf5908e31 Tuleap: #805 Tuleap: #841
This commit is contained in:
@ -226,7 +226,7 @@ UPnPContext::~UPnPContext()
|
||||
if (pmpIGD_) {
|
||||
{
|
||||
std::lock_guard<std::mutex> lk(pmpMutex_);
|
||||
pmpIGD_->clearAll();
|
||||
pmpIGD_->clearMappings();
|
||||
}
|
||||
pmpCv_.notify_all();
|
||||
}
|
||||
@ -267,6 +267,8 @@ UPnPContext::connectivityChanged()
|
||||
validIGDs_.clear();
|
||||
#if HAVE_LIBNATPMP
|
||||
if (pmpIGD_) {
|
||||
std::lock_guard<std::mutex> lk(pmpMutex_);
|
||||
pmpIGD_->clear();
|
||||
pmpIGD_->renewal_ = clock::now();
|
||||
pmpIGD_.reset();
|
||||
}
|
||||
@ -293,12 +295,12 @@ UPnPContext::hasValidIGD(std::chrono::seconds timeout)
|
||||
|
||||
std::unique_lock<std::mutex> lock(validIGDMutex_);
|
||||
if (!validIGDCondVar_.wait_for(lock, timeout,
|
||||
[this]{return not validIGDs_.empty();})) {
|
||||
[this]{return hasValidIGD_unlocked();})) {
|
||||
RING_WARN("UPnP: check for valid IGD timeout");
|
||||
return false;
|
||||
}
|
||||
|
||||
return not validIGDs_.empty();
|
||||
return hasValidIGD_unlocked();
|
||||
}
|
||||
|
||||
size_t
|
||||
@ -319,6 +321,16 @@ UPnPContext::removeIGDListener(size_t token)
|
||||
igdListeners_.erase(it);
|
||||
}
|
||||
|
||||
bool
|
||||
UPnPContext::hasValidIGD_unlocked() const
|
||||
{
|
||||
return
|
||||
#if HAVE_LIBNATPMP
|
||||
pmpIGD_ or
|
||||
#endif
|
||||
not validIGDs_.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* chooses the IGD to use,
|
||||
* assumes you already have a lock on validIGDMutex_
|
||||
|
@ -146,6 +146,7 @@ private:
|
||||
* assumes you already have a lock on igd_mutex_
|
||||
*/
|
||||
IGD* chooseIGD_unlocked() const;
|
||||
bool hasValidIGD_unlocked() const;
|
||||
|
||||
/* tries to add mapping, assumes you alreayd have lock on igd_mutex_ */
|
||||
Mapping addMapping(IGD* igd,
|
||||
|
@ -205,11 +205,14 @@ using time_point = clock::time_point;
|
||||
|
||||
class PMPIGD : public IGD {
|
||||
public:
|
||||
|
||||
void clearAll() {
|
||||
void clear() {
|
||||
toRemove_.clear();
|
||||
udpMappings.clear();
|
||||
tcpMappings.clear();
|
||||
}
|
||||
|
||||
void clearMappings() {
|
||||
clear();
|
||||
clearAll_ = true;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user