Beispiel #1
0
 def doAlive(self, arg):
     """
     Action method.
     """
     udp.send_command(self.node.listen_port, udp.CMD_ALIVE,
                      self.peer_rtt_id, self.peer_address)
     # print 'doAlive', self.peer_rtt_id
     self.peer_rtt_id = '0'
Beispiel #2
0
 def doAlive(self, *args, **kwargs):
     """
     Action method.
     """
     udp.send_command(self.node.listen_port, udp.CMD_ALIVE,
                      strng.to_bin(self.peer_rtt_id), self.peer_address)
     # print 'doAlive', self.peer_rtt_id
     self.peer_rtt_id = '0'
Beispiel #3
0
def connect(local_port, remote_ip, servers, min_port, max_port):
    def _loop():
        for port_num in range(min_port, max_port + 1):
            udp.send_command(local_port, udp.CMD_PING, 'ping', (remote_ip, port_num))
        reactor.callLater(5, _loop)
    for srv in servers:
        udp.send_command(local_port, udp.CMD_PING, 'ping', srv)
    _loop()
Beispiel #4
0
def connect(local_port, remote_ip, servers, min_port, max_port):
    def _loop():
        for port_num in range(min_port, max_port + 1):
            udp.send_command(local_port, udp.CMD_PING, 'ping', (remote_ip, port_num))
        reactor.callLater(5, _loop)
    for srv in servers:
        udp.send_command(local_port, udp.CMD_PING, 'ping', srv)
    _loop()
Beispiel #5
0
 def _loop():
     incomings = []
     for line in open(incomings_filename).read().split('\n'):
         addr = line.strip().split(':')
         addr[1] = int(addr[1])
         incomings.append(tuple(addr))
     if len(incomings):
         for inc in incomings:
             udp.send_command(local_port, udp.CMD_PING, 'ping', inc)
     reactor.callLater(5, _loop)
Beispiel #6
0
 def _loop():
     incomings = []
     for line in open(incomings_filename).read().split('\n'):
         addr = line.strip().split(':')
         addr[1] = int(addr[1])
         incomings.append(tuple(addr))
     if len(incomings):
         for inc in incomings:
             udp.send_command(local_port, udp.CMD_PING, 'ping', inc)
     reactor.callLater(5, _loop)
Beispiel #7
0
 def doAlive(self, arg):
     """
     Action method.
     """
     udp.send_command(
         self.node.listen_port,
         udp.CMD_ALIVE,
         self.peer_rtt_id,
         self.peer_address)
     # print 'doAlive', self.peer_rtt_id
     self.peer_rtt_id = '0'
Beispiel #8
0
 def doPing(self, arg):
     """
     Action method.
     """
     #        if udp_stream._Debug:
     #            if not (self.peer_address.count('37.18.255.42') or self.peer_address.count('37.18.255.38')):
     #                return
     # rtt_id_out = self._rtt_start('PING')
     udp.send_command(self.node.listen_port, udp.CMD_PING, self.my_rtt_id,
                      self.peer_address)
     # # print 'doPing', self.my_rtt_id
     self.my_rtt_id = '0'
Beispiel #9
0
    def doPing(self, arg):
        """
        Action method.
        """
#        if udp_stream._Debug:
#            if not (self.peer_address.count('37.18.255.42') or self.peer_address.count('37.18.255.38')):
#                return
        # rtt_id_out = self._rtt_start('PING')
        udp.send_command(self.node.listen_port, udp.CMD_PING,
                         self.my_rtt_id, self.peer_address)
        # # print 'doPing', self.my_rtt_id
        self.my_rtt_id = '0'
Beispiel #10
0
 def doSendYourIPPort(self, arg):
     """
     Action method.
     """
     try:
         datagram, address = arg
         command, payload = datagram
     except:
         return False
     youripport = '%s:%d' % (address[0], address[1])
     udp.send_command(self.listen_port, udp.CMD_MYIPPORT, youripport, address)
     lg.out(4, 'stun_server.doSendYourIPPort [%s] to %s' % (
         youripport, address))
Beispiel #11
0
 def doSendYourIPPort(self, arg):
     """
     Action method.
     """
     try:
         datagram, address = arg
         command, payload = datagram
     except:
         return False
     youripport = '%s:%d' % (address[0], address[1])
     udp.send_command(self.listen_port, udp.CMD_MYIPPORT, youripport, address)
     lg.out(4, 'stun_server.doSendYourIPPort [%s] to %s' % (
         youripport, address))
Beispiel #12
0
 def doGreeting(self, arg):
     """
     Action method.
     """
     # rtt_id_out = self._rtt_start('GREETING')
     payload = "%s %s %s %s" % (
         str(self.node.my_id), str(self.node.my_idurl),
         str(self.peer_rtt_id), str(self.my_rtt_id),)
     udp.send_command(
         self.node.listen_port,
         udp.CMD_GREETING,
         payload,
         self.peer_address)
     # print 'doGreeting', self.peer_rtt_id, self.my_rtt_id
     self.peer_rtt_id = '0'
     self.my_rtt_id = '0'
Beispiel #13
0
 def doSendYourIPPort(self, *args, **kwargs):
     """
     Action method.
     """
     try:
         datagram, address = args[0]
         command, payload = datagram
     except:
         return False
     youripport = net_misc.pack_address((address[0], address[1]))
     udp.send_command(self.listen_port, udp.CMD_MYIPPORT, youripport,
                      address)
     if _Debug:
         lg.out(
             _DebugLevel, 'stun_server.doSendYourIPPort [%s] to %s' %
             (youripport, address))
Beispiel #14
0
 def doGreeting(self, arg):
     """
     Action method.
     """
     # rtt_id_out = self._rtt_start('GREETING')
     payload = "%s %s %s %s" % (
         str(self.node.my_id),
         str(self.node.my_idurl),
         str(self.peer_rtt_id),
         str(self.my_rtt_id),
     )
     udp.send_command(self.node.listen_port, udp.CMD_GREETING, payload,
                      self.peer_address)
     # print 'doGreeting', self.peer_rtt_id, self.my_rtt_id
     self.peer_rtt_id = '0'
     self.my_rtt_id = '0'
Beispiel #15
0
 def doStun(self, arg):
     """
     Action method.
     """
     if arg is not None:
         if _Debug:
             lg.out(_DebugLevel + 10, 'stun_client.doStun to one stun_server: %s' % str(arg))
         udp.send_command(self.listen_port, udp.CMD_STUN, '', arg)
         return
     if _Debug:
         lg.out(_DebugLevel + 10, 'stun_client.doStun to %d stun_servers' % (
             len(self.stun_servers)))  # , self.stun_servers))
     for address in self.stun_servers:
         if address is None:
             continue
         if address in self.stun_results.keys():
             continue
         udp.send_command(self.listen_port, udp.CMD_STUN, '', address)
Beispiel #16
0
 def doStun(self, arg):
     """
     Action method.
     """
     if arg is not None:
         if _Debug:
             lg.out(_DebugLevel + 10, 'stun_client.doStun to one stun_server: %s' % str(arg))
         udp.send_command(self.listen_port, udp.CMD_STUN, '', arg)
         return
     if _Debug:
         lg.out(_DebugLevel + 10, 'stun_client.doStun to %d stun_servers' % (
             len(self.stun_servers)))  # , self.stun_servers))
     for address in self.stun_servers:
         if address is None:
             continue
         if address in self.stun_results.keys():
             continue
         udp.send_command(self.listen_port, udp.CMD_STUN, '', address)
Beispiel #17
0
def datagram_received(datagram, address, local_port):
    try:
        cmd, payload = datagram
    except:
        return
    if sys.argv[1] == 'server':
        udp.send_command(local_port, udp.CMD_PING, 'stun %s:%d' % address, address)
    elif sys.argv[1] == 'listen':
        if payload.startswith('stun'):
            print payload
        elif payload.startswith('ping'):
            udp.send_command(local_port, udp.CMD_PING, 'ok', address)
    elif sys.argv[1] == 'connect':
        if payload.startswith('stun'):
            print payload
        elif payload.startswith('ping'):
            udp.send_command(local_port, udp.CMD_PING, 'ok', address)
            if address[0] == sys.argv[3]:
                print 'OKAY!!!!!!!!!!!!!!', address
                reactor.stop()
Beispiel #18
0
def datagram_received(datagram, address, local_port):
    try:
        cmd, payload = datagram
    except:
        return
    if sys.argv[1] == 'server':
        udp.send_command(local_port, udp.CMD_PING, 'stun %s:%d' % address, address)
    elif sys.argv[1] == 'listen':
        if payload.startswith('stun'):
            print(payload)
        elif payload.startswith('ping'):
            udp.send_command(local_port, udp.CMD_PING, 'ok', address)
    elif sys.argv[1] == 'connect':
        if payload.startswith('stun'):
            print(payload)
        elif payload.startswith('ping'):
            udp.send_command(local_port, udp.CMD_PING, 'ok', address)
            if address[0] == sys.argv[3]:
                print('OKAY!!!!!!!!!!!!!!', address)
                reactor.stop()
Beispiel #19
0
 def send_packet(self, command, payload):
     self.bytes_sent += len(payload)
     return udp.send_command(self.node.listen_port, command,
                             payload, self.peer_address)
Beispiel #20
0
 def _loop():
     for port_num in range(min_port, max_port + 1):
         udp.send_command(local_port, udp.CMD_PING, 'ping', (remote_ip, port_num))
     reactor.callLater(5, _loop)
Beispiel #21
0
 def send_packet(self, command, payload):
     self.bytes_sent += len(payload)
     return udp.send_command(self.node.listen_port, command, payload,
                             self.peer_address)
Beispiel #22
0
 def _loop():
     for port_num in range(min_port, max_port + 1):
         udp.send_command(local_port, udp.CMD_PING, 'ping',
                          (remote_ip, port_num))
     reactor.callLater(5, _loop)