mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-25 07:31:07 +00:00
Move UDP listen inside try block
This commit is contained in:
parent
e4149496d2
commit
4a18f03960
@ -6,6 +6,7 @@ from sys import platform
|
|||||||
# from Twisted
|
# from Twisted
|
||||||
from twisted.internet import defer, threads, reactor
|
from twisted.internet import defer, threads, reactor
|
||||||
from twisted.internet.protocol import DatagramProtocol
|
from twisted.internet.protocol import DatagramProtocol
|
||||||
|
from twisted.internet.error import CannotListenError
|
||||||
from twisted.python.procutils import which
|
from twisted.python.procutils import which
|
||||||
from twisted.python import log
|
from twisted.python import log
|
||||||
|
|
||||||
@ -125,16 +126,17 @@ def get_local_ip_for(target):
|
|||||||
# avoid this DNS lookup. This also makes node startup fractionally
|
# avoid this DNS lookup. This also makes node startup fractionally
|
||||||
# faster.
|
# faster.
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
try:
|
||||||
udpprot = DatagramProtocol()
|
udpprot = DatagramProtocol()
|
||||||
port = reactor.listenUDP(0, udpprot)
|
port = reactor.listenUDP(0, udpprot)
|
||||||
try:
|
|
||||||
udpprot.transport.connect(target_ipaddr, 7)
|
udpprot.transport.connect(target_ipaddr, 7)
|
||||||
localip = udpprot.transport.getHost().host
|
localip = udpprot.transport.getHost().host
|
||||||
except socket.error:
|
|
||||||
# no route to that host
|
|
||||||
localip = None
|
|
||||||
d = port.stopListening()
|
d = port.stopListening()
|
||||||
d.addErrback(log.err)
|
d.addErrback(log.err)
|
||||||
|
except (socket.error, CannotListenError):
|
||||||
|
# no route to that host
|
||||||
|
localip = None
|
||||||
return localip
|
return localip
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user