parent
27874df45f
commit
1b36da9327
|
@ -167,6 +167,9 @@ class uPnPThread(threading.Thread, StoppableThread):
|
||||||
def __init__ (self):
|
def __init__ (self):
|
||||||
threading.Thread.__init__(self, name="uPnPThread")
|
threading.Thread.__init__(self, name="uPnPThread")
|
||||||
self.localPort = shared.config.getint('bitmessagesettings', 'port')
|
self.localPort = shared.config.getint('bitmessagesettings', 'port')
|
||||||
|
try:
|
||||||
|
self.extPort = shared.config.getint('bitmessagesettings', 'extport')
|
||||||
|
except:
|
||||||
self.extPort = None
|
self.extPort = None
|
||||||
self.routers = []
|
self.routers = []
|
||||||
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
|
@ -197,7 +200,7 @@ class uPnPThread(threading.Thread, StoppableThread):
|
||||||
logger.debug("Found UPnP router at %s", ip)
|
logger.debug("Found UPnP router at %s", ip)
|
||||||
self.routers.append(newRouter)
|
self.routers.append(newRouter)
|
||||||
self.createPortMapping(newRouter)
|
self.createPortMapping(newRouter)
|
||||||
shared.UISignalQueue.put(('updateStatusBar', tr.translateText("MainWindow",'UPnP port mapping established')))
|
shared.UISignalQueue.put(('updateStatusBar', tr.translateText("MainWindow",'UPnP port mapping established on port {}').format(self.extPort)))
|
||||||
break
|
break
|
||||||
except socket.timeout as e:
|
except socket.timeout as e:
|
||||||
pass
|
pass
|
||||||
|
@ -251,11 +254,15 @@ class uPnPThread(threading.Thread, StoppableThread):
|
||||||
localIP = router.localAddress
|
localIP = router.localAddress
|
||||||
if i == 0:
|
if i == 0:
|
||||||
extPort = self.localPort # try same port first
|
extPort = self.localPort # try same port first
|
||||||
|
elif i == 1 and self.extPort:
|
||||||
|
extPort = self.extPort # try external port from last time next
|
||||||
else:
|
else:
|
||||||
extPort = randint(32767, 65535)
|
extPort = randint(32767, 65535)
|
||||||
logger.debug("Requesting UPnP mapping for %s:%i on external port %i", localIP, self.localPort, extPort)
|
logger.debug("Requesting UPnP mapping for %s:%i on external port %i", localIP, self.localPort, extPort)
|
||||||
router.AddPortMapping(extPort, self.localPort, localIP, 'TCP', 'BitMessage')
|
router.AddPortMapping(extPort, self.localPort, localIP, 'TCP', 'BitMessage')
|
||||||
shared.extPort = extPort
|
shared.extPort = extPort
|
||||||
|
self.extPort = extPort
|
||||||
|
shared.config.set('bitmessagesettings', 'extport', str(extPort))
|
||||||
break
|
break
|
||||||
except UPnPError:
|
except UPnPError:
|
||||||
logger.debug("UPnP error: ", exc_info=True)
|
logger.debug("UPnP error: ", exc_info=True)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user