Example #1
0
 def test_uri_parts(self):
     self.assertEqual(('tcp', 'localhost', '1234'),
                      network_util.uri_parts('tcp://localhost:1234'))
     self.assertEqual(('tcp', '1.1.1.1', '22'),
                      network_util.uri_parts('tcp://1.1.1.1:22'))
     with self.assertRaises(RuntimeError):
         network_util.uri_parts('tcp://::1234')
Example #2
0
 def test_uri_parts(self):
     self.assertEqual(('tcp', 'localhost', '1234'),
         network_util.uri_parts('tcp://localhost:1234'))
     self.assertEqual(('tcp', '1.1.1.1', '22'),
         network_util.uri_parts('tcp://1.1.1.1:22'))
     with self.assertRaises(RuntimeError):
         network_util.uri_parts('tcp://::1234')
Example #3
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
Example #4
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