Skip to content
Snippets Groups Projects
Commit 5e7a6465 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

upnp: make mapping operations atomic

Change-Id: I2c04e3831f68a55b7682c42eb93464e1fab78b1b
parent a37e4631
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment