def test_encode_and_decode_address_validAddresses(self): valid_addresses = [("127.0.0.1", 80), ("4.2.2.1", 53), ("8.8.8.8", 52), ("12.12.42.42", 1385), ("0.0.0.0", 0), ("255.255.255.255", 65535)] for address in valid_addresses: self.assertEquals(address, decode_address(encode_address(address)))
def _decode_addresses(address_string): """Decode a concatenated address string into a list of addres tuples""" addresses = [] # Each address string has a length of 6 encoded_addresses = _chunkify(address_string, 6) for address_string in encoded_addresses: decoded_peer = basic_coder.decode_address(address_string) addresses.append(decoded_peer) return addresses
def decode_node(node_string): """ Decodes a network string into a Node object @see encode_node for the format of this network string """ node_id = basic_coder.decode_network_id(node_string[:20]) address = basic_coder.decode_address(node_string[20:]) return Node(node_id, address)