Mercurial > libervia-backend
diff src/plugins/plugin_misc_nat-port.py @ 2488:78c7992a26ed
plugin NAT-port: raise MappingError if something get wrong during "addportmapping" + log unexpected errors (i.e. everything else than MappingError)
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 01 Feb 2018 07:24:34 +0100 |
parents | 0046283a285d |
children |
line wrap: on
line diff
--- a/src/plugins/plugin_misc_nat-port.py Thu Feb 01 07:21:41 2018 +0100 +++ b/src/plugins/plugin_misc_nat-port.py Thu Feb 01 07:24:34 2018 +0100 @@ -150,12 +150,16 @@ # to avoid testing again the first series the next time self._starting_port_cache = ext_port - mapping = self._upnp.addportmapping( - # the last parameter is remoteHost, we don't use it - ext_port, protocol, self._upnp.lanaddr, int_port, desc, '') + try: + mapping = self._upnp.addportmapping( + # the last parameter is remoteHost, we don't use it + ext_port, protocol, self._upnp.lanaddr, int_port, desc, '') + except Exception as e: + log.error(_(u"addportmapping error: {msg}").format(msg=e)) + raise failure.Failure(MappingError()) if not mapping: - raise MappingError + raise failure.Failure(MappingError()) else: self._to_unmap.append((ext_port, protocol)) finally: @@ -182,9 +186,12 @@ ext_port = ext_port, )) return ext_port - def mappingEb(failure): - failure.trap(MappingError) + def mappingEb(failure_): + failure_.trap(MappingError) log.warning(u"Can't map internal {int_port}".format(int_port=int_port)) + def mappingUnknownEb(failure_): + log.error(_(u"error while trying to map ports: {msg}").format(msg=failure_)) d = threads.deferToThread(self._mapPortBlocking, int_port, ext_port, protocol, desc) d.addCallbacks(mappingCb, mappingEb) + d.addErrback(mappingUnknownEb) return d