plugin NAT-port: raise MappingError if something get wrong during "addportmapping" + log unexpected errors (i.e. everything else than MappingError)
This commit is contained in:
parent
aec189c087
commit
ece10e8cd2
1 changed files with 13 additions and 6 deletions
|
|
@ -150,12 +150,16 @@ class NatPort(object):
|
||||||
# to avoid testing again the first series the next time
|
# to avoid testing again the first series the next time
|
||||||
self._starting_port_cache = ext_port
|
self._starting_port_cache = ext_port
|
||||||
|
|
||||||
mapping = self._upnp.addportmapping(
|
try:
|
||||||
# the last parameter is remoteHost, we don't use it
|
mapping = self._upnp.addportmapping(
|
||||||
ext_port, protocol, self._upnp.lanaddr, int_port, desc, '')
|
# 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:
|
if not mapping:
|
||||||
raise MappingError
|
raise failure.Failure(MappingError())
|
||||||
else:
|
else:
|
||||||
self._to_unmap.append((ext_port, protocol))
|
self._to_unmap.append((ext_port, protocol))
|
||||||
finally:
|
finally:
|
||||||
|
|
@ -182,9 +186,12 @@ class NatPort(object):
|
||||||
ext_port = ext_port,
|
ext_port = ext_port,
|
||||||
))
|
))
|
||||||
return ext_port
|
return ext_port
|
||||||
def mappingEb(failure):
|
def mappingEb(failure_):
|
||||||
failure.trap(MappingError)
|
failure_.trap(MappingError)
|
||||||
log.warning(u"Can't map internal {int_port}".format(int_port=int_port))
|
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 = threads.deferToThread(self._mapPortBlocking, int_port, ext_port, protocol, desc)
|
||||||
d.addCallbacks(mappingCb, mappingEb)
|
d.addCallbacks(mappingCb, mappingEb)
|
||||||
|
d.addErrback(mappingUnknownEb)
|
||||||
return d
|
return d
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue