diff --git a/src/upnp/protocol/pupnp/pupnp.cpp b/src/upnp/protocol/pupnp/pupnp.cpp index 2c81e6740fbcc8874fa06e0798e925eb4849abb2..f0f45f45935baad41b806101d0d7a03a8a52fecb 100644 --- a/src/upnp/protocol/pupnp/pupnp.cpp +++ b/src/upnp/protocol/pupnp/pupnp.cpp @@ -174,6 +174,18 @@ PUPnP::registerClient() } } +void +PUPnP::unregisterClient() +{ + int upnp_err = UpnpUnRegisterClient(ctrlptHandle_); + if (upnp_err != UPNP_E_SUCCESS) { + if (logger_) logger_->error("PUPnP: Failed to unregister client: {}", UpnpGetErrorMessage(upnp_err)); + } else { + if (logger_) logger_->debug("PUPnP: Successfully unregistered client"); + clientRegistered_ = false; + } +} + void PUPnP::setObserver(UpnpMappingObserver* obs) { @@ -264,6 +276,12 @@ PUPnP::clearIgds() { // JAMI_DBG("PUPnP: clearing IGDs and devices lists"); + // We need to unregister the client to make sure that we don't keep receiving and + // processing IGD-related events unnecessarily, see: + // https://git.jami.net/savoirfairelinux/dhtnet/-/issues/29 + if (clientRegistered_) + unregisterClient(); + searchForIgdTimer_.cancel(); igdSearchCounter_ = 0; diff --git a/src/upnp/protocol/pupnp/pupnp.h b/src/upnp/protocol/pupnp/pupnp.h index 03086ddc1f5ec09cd8106bebc1f60439104b96e3..5bba6dcf6d16d2bdf07a2251f83a6bce8cac2640 100644 --- a/src/upnp/protocol/pupnp/pupnp.h +++ b/src/upnp/protocol/pupnp/pupnp.h @@ -124,6 +124,9 @@ private: // Register the client void registerClient(); + // Unregister the client + void unregisterClient(); + // Start search for UPNP devices void searchForDevices();