diff --git a/src/upnp/protocol/mapping.cpp b/src/upnp/protocol/mapping.cpp index 0773065ff9c9f606f2cf513df296b53d9ca6bb98..792ec9e92fc49e40868b17ba1a3a1852651be807 100644 --- a/src/upnp/protocol/mapping.cpp +++ b/src/upnp/protocol/mapping.cpp @@ -43,7 +43,7 @@ Mapping::Mapping(PortType type, uint16_t portExternal, uint16_t portInternal, bo Mapping::Mapping(const Mapping& other) { - std::lock_guard<std::mutex> lock(mutex_); + std::lock_guard<std::mutex> lock(other.mutex_); internalAddr_ = other.internalAddr_; internalPort_ = other.internalPort_; @@ -95,17 +95,6 @@ Mapping::setAvailable(bool val) void Mapping::setState(const MappingState& state) { - { - std::lock_guard<std::mutex> lock(mutex_); - if (state_ == state) - return; - } - - JAMI_DBG("Changed mapping %s state from %s to %s", - toString().c_str(), - getStateStr(), - getStateStr(state)); - std::lock_guard<std::mutex> lock(mutex_); state_ = state; } @@ -136,22 +125,17 @@ Mapping::toString(bool extraInfo) const bool Mapping::isValid() const { - { - std::lock_guard<std::mutex> lock(mutex_); - if (state_ == MappingState::FAILED) - return false; - if (internalPort_ == 0) - return false; - if (externalPort_ == 0) - return false; - if (not igd_ or not igd_->isValid()) - return false; - } - - if (not hasValidHostAddress()) + std::lock_guard<std::mutex> lock(mutex_); + if (state_ == MappingState::FAILED) return false; - - return true; + if (internalPort_ == 0) + return false; + if (externalPort_ == 0) + return false; + if (not igd_ or not igd_->isValid()) + return false; + IpAddr intAddr(internalAddr_); + return intAddr and not intAddr.isLoopback(); } bool