示例#1
0
    def valid_peer_uri(self, uri):
        try:
            [self_protocol, self_addr, self_port] = network_util.uri_parts(self.uri)
            [other_protocol, other_addr, other_port] = network_util.uri_parts(uri)
        except RuntimeError:
            return False

        if not network_util.is_valid_protocol(other_protocol) or not network_util.is_valid_port(other_port):
            return False

        if network_util.is_private_ip_address(self_addr):
            if not network_util.is_private_ip_address(other_addr):
                self.log.warning(("Trying to connect to external " "network with a private ip address."))
        else:
            if network_util.is_private_ip_address(other_addr):
                return False

        return True
示例#2
0
    def valid_peer_uri(self, uri):
        try:
            [_, self_addr, _] = network_util.uri_parts(self.uri)
            [other_protocol, other_addr, other_port] = \
                network_util.uri_parts(uri)
        except RuntimeError:
            return False

        if not network_util.is_valid_protocol(other_protocol) \
                or not network_util.is_valid_port(other_port):
            return False

        if network_util.is_private_ip_address(self_addr):
            if not network_util.is_private_ip_address(other_addr):
                self.log.warning(('Trying to connect to external '
                                  'network with a private ip address.'))
        else:
            if network_util.is_private_ip_address(other_addr):
                return False

        return True
示例#3
0
 def test_is_valid_port(self):
     self.assertTrue(network_util.is_valid_port(1))
     self.assertTrue(network_util.is_valid_port(65335))
     self.assertFalse(network_util.is_valid_port(-1))
     self.assertFalse(network_util.is_valid_port(70000))
示例#4
0
 def test_is_valid_port(self):
     self.assertTrue(network_util.is_valid_port(1))
     self.assertTrue(network_util.is_valid_port(65335))
     self.assertFalse(network_util.is_valid_port(-1))
     self.assertFalse(network_util.is_valid_port(70000))