Skip to content
Snippets Groups Projects
Commit a406c4a3 authored by François-Simon Fauteux-Chapleau's avatar François-Simon Fauteux-Chapleau
Browse files

upnp_context: unregister all FAILED mappings

This patch fixes a bug where FAILED mappings with the "auto-update"
option enabled are left in the local list, even after a new mapping has
been requested. This can cause the list to grow substantially over time
and was partly responsible for the bug described in the following issue:
jami-client-qt#1898

GitLab: #45
Change-Id: I009ff791ae90d10f64d46dede3b2cbfc9c1b7160
parent b92387af
Branches
No related tags found
No related merge requests found
...@@ -630,12 +630,15 @@ UPnPContext::enforceAvailableMappingsLimits() ...@@ -630,12 +630,15 @@ UPnPContext::enforceAvailableMappingsLimits()
int pendingCount = 0; int pendingCount = 0;
int inProgressCount = 0; int inProgressCount = 0;
int openCount = 0; int openCount = 0;
int unavailableCount = 0;
{ {
std::lock_guard lock(mappingMutex_); std::lock_guard lock(mappingMutex_);
const auto& mappingList = getMappingList(type); const auto& mappingList = getMappingList(type);
for (const auto& [_, mapping] : mappingList) { for (const auto& [_, mapping] : mappingList) {
if (!mapping->isAvailable()) if (!mapping->isAvailable()) {
unavailableCount++;
continue; continue;
}
switch (mapping->getState()) { switch (mapping->getState()) {
case MappingState::PENDING: case MappingState::PENDING:
pendingCount++; pendingCount++;
...@@ -652,12 +655,13 @@ UPnPContext::enforceAvailableMappingsLimits() ...@@ -652,12 +655,13 @@ UPnPContext::enforceAvailableMappingsLimits()
} }
} }
int availableCount = openCount + pendingCount + inProgressCount; int availableCount = openCount + pendingCount + inProgressCount;
if (logger_) logger_->debug("Number of 'available' {} mappings in the local list: {} ({} open + {} pending + {} in progress)", if (logger_) logger_->debug("Number of {} mappings in the local list: {} available ({} open + {} pending + {} in progress), {} unavailable",
Mapping::getTypeStr(type), Mapping::getTypeStr(type),
availableCount, availableCount,
openCount, openCount,
pendingCount, pendingCount,
inProgressCount); inProgressCount,
unavailableCount);
int minAvailableMappings = getMinAvailableMappings(type); int minAvailableMappings = getMinAvailableMappings(type);
if (minAvailableMappings > availableCount) { if (minAvailableMappings > availableCount) {
...@@ -1307,16 +1311,19 @@ UPnPContext::handleFailedMapping(const Mapping::sharedPtr_t& map) ...@@ -1307,16 +1311,19 @@ UPnPContext::handleFailedMapping(const Mapping::sharedPtr_t& map)
} }
if (isReady()) { if (isReady()) {
// We have a valid IGD, but the mapping request
// failed, so try again with a new port number.
Mapping newMapping(map->getType()); Mapping newMapping(map->getType());
newMapping.enableAutoUpdate(true); newMapping.enableAutoUpdate(true);
newMapping.setNotifyCallback(map->getNotifyCallback()); newMapping.setNotifyCallback(map->getNotifyCallback());
reserveMapping(newMapping);
if (logger_) logger_->debug("Mapping {} has auto-update enabled, a new mapping will be requested",
map->toString());
// TODO: figure out if this line is actually necessary // Remove the old (failed) mapping from the local list
// (See https://review.jami.net/c/jami-daemon/+/16940)
map->setNotifyCallback(nullptr); map->setNotifyCallback(nullptr);
unregisterMapping(map);
if (logger_) logger_->debug("Mapping {} had auto-update enabled, a new mapping will be requested",
map->toString());
reserveMapping(newMapping);
} else { } else {
// If there is no valid IGD, the mapping is marked as pending // If there is no valid IGD, the mapping is marked as pending
// and will be requested when an IGD becomes available. // and will be requested when an IGD becomes available.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment