Beispiel #1
0
    def _initialize(self):
        class Dummy:
            pass

        obj = Dummy()

        def onError():
            self.sm.removeCallback(callbackId)
            self.sm.change(self.CLOSED)

        def onDiscover(device):
            if device is None:
                onError()
                return
            self.device = device
            obj.op = UPnpActions.getExternalIP(device, self.reactor,
                                               onExternalIP)

        def onExternalIP(externalIP):
            if externalIP is None:
                onError()
                return
            self.externalIP = externalIP
            self.sm.removeCallback(callbackId)
            self.sm.change(self.READY)

        self.sm.change(self.INITIALIZING)
        obj.op = UPnpActions.findDevice(self.reactor, onDiscover)
        callbackId = self.sm.insertCallback(lambda: obj.op.cancel(),
                                            src=self.INITIALIZING,
                                            single=True)
Beispiel #2
0
 def onDiscover(device):
     if device is None:
         onError()
         return
     self.device = device
     obj.op = UPnpActions.getExternalIP(device, self.reactor,
                                        onExternalIP)
Beispiel #3
0
    def _initialize(self):
        class Dummy:
            pass

        obj = Dummy()

        def onError():
            self.sm.removeCallback(callbackId)
            self.sm.change(self.CLOSED)

        def onDiscover(device):
            if device is None:
                onError()
                return
            self.device = device
            obj.op = UPnpActions.getExternalIP(device, self.reactor, onExternalIP)

        def onExternalIP(externalIP):
            if externalIP is None:
                onError()
                return
            self.externalIP = externalIP
            self.sm.removeCallback(callbackId)
            self.sm.change(self.READY)

        self.sm.change(self.INITIALIZING)
        obj.op = UPnpActions.findDevice(self.reactor, onDiscover)
        callbackId = self.sm.insertCallback(lambda: obj.op.cancel(), src=self.INITIALIZING, single=True)
Beispiel #4
0
 def doAttempt():
     if obj.attempt == 3:
         obj.op.notify(None)
         return
     obj.attempt += 1
     obj.externalPort = randint(10000, 20000)
     desc = "CSpace_t%d" % int(time())
     obj.addOp = UPnpActions.addMapping(
         self.device, obj.externalPort, "TCP", localPort, localIP, desc, self.reactor, onAdd
     )
     obj.callbackId = self.sm.insertCallback(onAbort, src=self.READY, single=True)
     obj.op.setCanceler(onCancel)
Beispiel #5
0
 def doAttempt():
     if obj.attempt == 3:
         obj.op.notify(None)
         return
     obj.attempt += 1
     obj.externalPort = randint(10000, 20000)
     desc = 'CSpace_t%d' % int(time())
     obj.addOp = UPnpActions.addMapping(self.device, obj.externalPort,
                                        'TCP', localPort, localIP, desc,
                                        self.reactor, onAdd)
     obj.callbackId = self.sm.insertCallback(onAbort,
                                             src=self.READY,
                                             single=True)
     obj.op.setCanceler(onCancel)
Beispiel #6
0
 def onCleanup():
     self.cleaningupCount += 1
     UPnpActions.delMapping(self.device, obj.externalPort, 'TCP',
                            self.reactor, onDelMapping)
Beispiel #7
0
 def onDiscover(device):
     if device is None:
         onError()
         return
     self.device = device
     obj.op = UPnpActions.getExternalIP(device, self.reactor, onExternalIP)
Beispiel #8
0
 def onCleanup():
     self.cleaningupCount += 1
     UPnpActions.delMapping(self.device, obj.externalPort, "TCP", self.reactor, onDelMapping)