Example #1
0
 def addPortMapping(self, intport, extport, desc, proto='UDP', lease=0):
     "add a port mapping. returns a deferred"
     from nat import getLocalIPAddress
     from twisted.internet import defer
     cd = defer.Deferred()
     d = getLocalIPAddress()
     d.addCallback(lambda locIP: self._cbAddPortMapping(
         intport, extport, desc, proto, lease, locIP, cd))
     return cd
Example #2
0
 def addPortMapping(self, intport, extport, desc, proto='UDP', lease=0):
     "add a port mapping. returns a deferred"
     from nat import getLocalIPAddress
     from twisted.internet import defer
     cd = defer.Deferred()
     d = getLocalIPAddress()
     d.addCallback(lambda locIP: self._cbAddPortMapping(intport, extport,
                                                        desc, proto, lease,
                                                        locIP, cd))
     return cd
Example #3
0
 def _cb_map_gotUPnP(self, upnp, port):
     from shtoom.nat import isBogusAddress, getLocalIPAddress
     # XXX Test that upnp is present
     self.upnp = upnp
     # Extract local address from the port
     locAddr = port.getHost().host
     if isBogusAddress(locAddr):
         # lookup local IP.
         d = getLocalIPAddress()
         d.addCallback(lambda x: self._cb_map_gotLocalIP(x, port))
     else:
         self._cb_map_gotLocalIP(locAddr, port)
Example #4
0
 def _cb_map_gotUPnP(self, upnp, port):
     from shtoom.nat import isBogusAddress, getLocalIPAddress
     # XXX Test that upnp is present
     self.upnp = upnp
     # Extract local address from the port
     locAddr = port.getHost().host
     if isBogusAddress(locAddr):
         # lookup local IP.
         d = getLocalIPAddress()
         d.addCallback(lambda x: self._cb_map_gotLocalIP(x, port))
     else:
         self._cb_map_gotLocalIP(locAddr, port)
Example #5
0
 def startDiscovery(self):
     #start discover the nat type
     from nat import isBogusAddress, getLocalIPAddress
     if _ForceStunType is not None:
         self.natType = _ForceStunType#_ForceStunType=None, initial
         reactor.callLater(0, self._finishedStun)
         return
     localAddress = self.transport.getHost().host
     print "startDiscover--localAddress is %s"%str(localAddress)
     if isBogusAddress(localAddress):
         print "localAddress is invalid!"
         d = getLocalIPAddress()
         d.addCallback(self._resolveStunServers)
     else:
         self._resolveStunServers(localAddress)
Example #6
0
 def startDiscovery(self):
     from nat import isBogusAddress, getLocalIPAddress
     if _ForceStunType is not None:
         self.natType = _ForceStunType
         reactor.callLater(0, self._finishedStun)
         return
     if not self.transport:
         self.natType = _ForceStunType
         reactor.callLater(0, self._finishedStun)
         return
     localAddress = self.transport.getHost().host
     if STUNVERBOSE:
         print 'startDiscovery, localAddres =', localAddress
     if isBogusAddress(localAddress):
         d = getLocalIPAddress()
         d.addCallback(self._resolveStunServers)
         # d.addErrback(self._hostNotResolved, localAddress)
         d.addErrback(lambda x: self._finishedStun())
     else:
         self._resolveStunServers(localAddress)
         self.timerTask = reactor.callLater(self.timeout, self._timeout, localAddress)
Example #7
0
 def startDiscovery(self):
     from nat import isBogusAddress, getLocalIPAddress
     if _ForceStunType is not None:
         self.natType = _ForceStunType
         reactor.callLater(0, self._finishedStun)
         return
     if not self.transport:
         self.natType = _ForceStunType
         reactor.callLater(0, self._finishedStun)
         return
     localAddress = self.transport.getHost().host
     if STUNVERBOSE:
         print 'startDiscovery, localAddres =', localAddress
     if isBogusAddress(localAddress):
         d = getLocalIPAddress()
         d.addCallback(self._resolveStunServers)
         # d.addErrback(self._hostNotResolved, localAddress)
         d.addErrback(lambda x: self._finishedStun())
     else:
         self._resolveStunServers(localAddress)
         self.timerTask = reactor.callLater(self.timeout, self._timeout,
                                            localAddress)