Add self peer into knownnodes if detected external IP with UPnP
This commit is contained in:
parent
668a73abf6
commit
92c0196887
20
src/upnp.py
20
src/upnp.py
|
@ -16,6 +16,7 @@ from random import randint
|
||||||
from urlparse import urlparse
|
from urlparse import urlparse
|
||||||
from xml.dom.minidom import Document, parseString
|
from xml.dom.minidom import Document, parseString
|
||||||
|
|
||||||
|
import knownnodes
|
||||||
import queues
|
import queues
|
||||||
import state
|
import state
|
||||||
import tr
|
import tr
|
||||||
|
@ -166,9 +167,11 @@ class Router: # pylint: disable=old-style-class
|
||||||
def GetExternalIPAddress(self):
|
def GetExternalIPAddress(self):
|
||||||
"""Get the external address"""
|
"""Get the external address"""
|
||||||
|
|
||||||
resp = self.soapRequest(self.upnp_schema + ':1', 'GetExternalIPAddress')
|
resp = self.soapRequest(
|
||||||
dom = parseString(resp)
|
self.upnp_schema + ':1', 'GetExternalIPAddress')
|
||||||
return dom.getElementsByTagName('NewExternalIPAddress')[0].childNodes[0].data
|
dom = parseString(resp.read())
|
||||||
|
return dom.getElementsByTagName(
|
||||||
|
'NewExternalIPAddress')[0].childNodes[0].data
|
||||||
|
|
||||||
def soapRequest(self, service, action, arguments=None):
|
def soapRequest(self, service, action, arguments=None):
|
||||||
"""Make a request to a router"""
|
"""Make a request to a router"""
|
||||||
|
@ -261,6 +264,17 @@ 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)
|
||||||
|
try:
|
||||||
|
self_peer = state.Peer(
|
||||||
|
newRouter.GetExternalIPAddress(),
|
||||||
|
self.extPort
|
||||||
|
)
|
||||||
|
except:
|
||||||
|
logger.debug('Failed to get external IP')
|
||||||
|
else:
|
||||||
|
with knownnodes.knownNodesLock:
|
||||||
|
knownnodes.addKnownNode(
|
||||||
|
1, self_peer, is_self=True)
|
||||||
queues.UISignalQueue.put(('updateStatusBar', tr._translate(
|
queues.UISignalQueue.put(('updateStatusBar', tr._translate(
|
||||||
"MainWindow", 'UPnP port mapping established on port %1'
|
"MainWindow", 'UPnP port mapping established on port %1'
|
||||||
).arg(str(self.extPort))))
|
).arg(str(self.extPort))))
|
||||||
|
|
Reference in New Issue
Block a user