Exemplo n.º 1
0
 def doReportSuccess(self, *args, **kwargs):
     """
     Action method.
     """
     try:
         min_port = min(
             [addr[1] for addr in list(self.stun_results.values())])
         max_port = max(
             [addr[1] for addr in list(self.stun_results.values())])
         my_ip = strng.to_text(list(self.stun_results.values())[0][0])
         if min_port == max_port:
             result = ('stun-success', 'non-symmetric', my_ip, min_port)
         else:
             result = ('stun-success', 'symmetric', my_ip,
                       self.stun_results)
         self.my_address = (my_ip, min_port)
     except:
         lg.exc()
         result = ('stun-failed', None, None, [])
         self.my_address = None
     if self.my_address:
         bpio.WriteTextFile(settings.ExternalIPFilename(),
                            self.my_address[0])
         bpio.WriteTextFile(settings.ExternalUDPPortFilename(),
                            str(self.my_address[1]))
     if _Debug:
         lg.out(
             _DebugLevel,
             'stun_client.doReportSuccess based on %d nodes: %s' %
             (len(self.stun_results), str(self.my_address)))
     if _Debug:
         lg.out(_DebugLevel + 10, '    %s' % str(result))
     for cb in self.callbacks:
         cb(result[0], result[1], result[2], result[3])
     self.callbacks = []
Exemplo n.º 2
0
 def doInit(self, arg):
     """
     Action method.
     """
     self.listen_port = arg
     if udp.proto(self.listen_port):
         udp.proto(self.listen_port).add_callback(self._datagramReceived)
     else:
         lg.err('udp port %s is not opened' % self.listen_port)
     try:
         externalPort = int(
             bpio.ReadTextFile(settings.ExternalUDPPortFilename()))
     except:
         externalPort = self.listen_port
     dht_service.set_node_data('stun_port', externalPort)
Exemplo n.º 3
0
 def doReportSuccess(self, *args, **kwargs):
     """
     Action method.
     """
     try:
         min_port = min(
             [addr[1] for addr in list(self.stun_results.values())])
         max_port = max(
             [addr[1] for addr in list(self.stun_results.values())])
         my_ip = strng.to_text(list(self.stun_results.values())[0][0])
         if min_port == max_port:
             result = ('stun-success', 'non-symmetric', my_ip, min_port)
         else:
             result = ('stun-success', 'symmetric', my_ip,
                       self.stun_results)
         self.my_address = (my_ip, min_port)
     except:
         lg.exc()
         result = ('stun-failed', None, None, [])
         self.my_address = None
     if _Debug:
         lg.out(
             _DebugLevel,
             'stun_client.doReportSuccess based on %d nodes: %r' % (
                 len(self.stun_results),
                 result,
             ))
     if self.my_address:
         current_external_ip = misc.readExternalIP()
         if current_external_ip != self.my_address[0]:
             events.send('my-external-ip-changed',
                         data=dict(
                             old=current_external_ip,
                             new=self.my_address[0],
                         ))
         bpio.WriteTextFile(settings.ExternalIPFilename(),
                            self.my_address[0])
         bpio.WriteTextFile(settings.ExternalUDPPortFilename(),
                            str(self.my_address[1]))
     for cb in self.callbacks:
         cb(result[0], result[1], result[2], result[3])
     self.callbacks = []