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
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
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))