示例#1
0
    def get_valid_peers(peer_ips, peer_ip, public_port):
        new_peers = set()
        tmp = list(peer_ips)
        tmp.append("{0}:{1}".format(peer_ip, public_port))

        for ip_port in tmp:
            try:
                parse_peer_addr(ip_port, True)
                new_peers.add(ip_port)
            except Exception as _:
                logger.warning("Invalid Peer Address {} sent by {}".format(ip_port, peer_ip))

        return new_peers
示例#2
0
 def connect_peer(self, peer_address):
     try:
         ip_addr, ip_port = parse_peer_addr(peer_address)
         if peer_address not in self.get_connected_peer_addrs():
             reactor.connectTCP(ip_addr, ip_port, self)
     except Exception as e:
         logger.warning("Could not connect to %s - %s", peer_address, str(e))
示例#3
0
    def get_valid_peers(peer_ips, peer_ip, public_port):
        new_peers = set()

        for ip_port in peer_ips:
            try:
                parse_peer_addr(ip_port)
                new_peers.add(ip_port)
            except Exception as e:
                logger.warning("Invalid Peer Address %s", ip_port)
                logger.warning("Sent by %s", peer_ip)
                logger.exception(e)

        if 0 < public_port <= 65535:
            new_peers.add("{0}:{1}".format(peer_ip, public_port))

        return new_peers
示例#4
0
文件: test_helper.py 项目: grx7/QRL
 def test_global_1(self):
     with self.assertRaisesRegexp(ValueError,
                                  'Local Peer IP Found 192.168.0.1:9000'):
         parse_peer_addr('192.168.0.1:9000', check_global=True)
示例#5
0
文件: test_helper.py 项目: grx7/QRL
 def test_global_2(self):
     ip, port = parse_peer_addr('123.123.123.1:9000', check_global=True)
     self.assertEquals('123.123.123.1', ip)
     self.assertEquals(9000, port)
示例#6
0
文件: test_helper.py 项目: grx7/QRL
 def test_wrong_port_3(self):
     with self.assertRaisesRegexp(ValueError,
                                  'Invalid Peer Port 192.168.0.1:-1'):
         parse_peer_addr('192.168.0.1:-1')
示例#7
0
文件: test_helper.py 项目: grx7/QRL
 def test_invalid_2(self):
     with self.assertRaisesRegexp(AddressValueError,
                                  'Expected 4 octets in \'abc\''):
         parse_peer_addr('abc')
示例#8
0
文件: test_helper.py 项目: grx7/QRL
 def test_invalid_1(self):
     with self.assertRaisesRegexp(AddressValueError,
                                  'Address cannot be empty'):
         parse_peer_addr('')
示例#9
0
文件: test_helper.py 项目: grx7/QRL
 def test_basic_3(self):
     ip, port = parse_peer_addr('192.168.0.1')
     self.assertEquals('192.168.0.1', ip)
     self.assertEquals(9000, port)
示例#10
0
文件: test_helper.py 项目: grx7/QRL
 def test_basic_2(self):
     ip, port = parse_peer_addr('192.168.0.1:1234')
     self.assertEquals('192.168.0.1', ip)
     self.assertEquals(1234, port)