upnp: refactor to improve handling of port mappings renewal
The two main changes are:
1) Renewal requests are now sent for both UPnP and NAT-PMP mappings, not
just NAT-PMP. The old code asked for an infinite lifetime when
creating UPnP mappings and assumed that it got it, but this is not a
safe assumption. (See GitLab issue below for more information.)
2) The updateMappingList function was removed. This function used to be
called every 30 seconds to handle a bunch of unrelated tasks (one of
which was renewing port mappings) and generated mostly unnecessary
network traffic every time when using UPnP (because of the call to
pruneMappingList). These tasks are now performed separately instead
of being bundled together, and only when needed (either based on a
timer or on certain events occuring, depending on the task).
GitLab: #31
Change-Id: Id0f60ddb76fb8eb4517eadbb971892d125cebfc7
diff --git a/tools/upnp/upnpctrl.cpp b/tools/upnp/upnpctrl.cpp
index a5034a6..7c4febf 100644
--- a/tools/upnp/upnpctrl.cpp
+++ b/tools/upnp/upnpctrl.cpp
@@ -115,6 +115,8 @@
}
} else if (command == "mappings") {
print_mappings(upnpContext);
+ } else if (command == "restart") {
+ upnpContext->restart();
} else {
fmt::print("Unknown command: {}\n", command);
}