From 9c43c811a1bc5c12be688908f6a34dd8246ffd72 Mon Sep 17 00:00:00 2001 From: Jonathan Moody <103143855+moodyjon@users.noreply.github.com> Date: Wed, 11 Jan 2023 11:17:43 -0600 Subject: [PATCH] Handle mapped IPv4 address more neatly. (for consistency with client code) --- hub/herald/udp.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hub/herald/udp.py b/hub/herald/udp.py index 7929530..5b380f7 100644 --- a/hub/herald/udp.py +++ b/hub/herald/udp.py @@ -275,6 +275,11 @@ class SPVStatusClientProtocol(asyncio.DatagramProtocol): def datagram_received(self, data: bytes, addr: Union[Tuple[str, int], Tuple[str, int, int, int]]): try: + if len(addr) > 2: # IPv6 with possible mapped IPv4 + ipaddr = ipaddress.ip_address(addr[0]) + if ipaddr.ipv4_mapped: + # mapped IPv4 address identified + addr = (ipaddr.ipv4_mapped.compressed, addr[1]) self.responses.put_nowait(((addr[:2], perf_counter()), SPVPong.decode(data))) except (ValueError, struct.error, AttributeError, TypeError, RuntimeError): return