From 47a83f4628df48638c2aebbfbcddc1531aac20d0 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Mon, 20 Dec 2021 12:37:18 -0500 Subject: [PATCH] Do not trace out if a packet can't be replied to --- confluent_server/confluent/discovery/protocols/slp.py | 10 ++++++++-- confluent_server/confluent/discovery/protocols/ssdp.py | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/confluent_server/confluent/discovery/protocols/slp.py b/confluent_server/confluent/discovery/protocols/slp.py index 4fd1391c..a9beda8e 100644 --- a/confluent_server/confluent/discovery/protocols/slp.py +++ b/confluent_server/confluent/discovery/protocols/slp.py @@ -112,7 +112,10 @@ def _parse_slp_packet(packet, peer, rsps, xidmap, defer=None, sock=None): identifier = addr else: probepeer = (peer[0], struct.unpack('H', os.urandom(2))[0] | 1025) + peer[2:] - sock.sendto(b'\x00', probepeer) + try: + sock.sendto(b'\x00', probepeer) + except Exception: + return defer.append((packet, peer)) return if (identifier, parsed['xid']) in rsps: @@ -487,7 +490,10 @@ def snoop(handler, protocol=None): mac = neighutil.get_hwaddr(peer[0]) if not mac: probepeer = (peer[0], struct.unpack('H', os.urandom(2))[0] | 1025) + peer[2:] - s.sendto(b'\x00', probepeer) + try: + s.sendto(b'\x00', probepeer) + except Exception: + continue deferpeers.append(peer) continue process_peer(newmacs, known_peers, peerbymacaddress, peer) diff --git a/confluent_server/confluent/discovery/protocols/ssdp.py b/confluent_server/confluent/discovery/protocols/ssdp.py index 71dee347..f747f0b6 100644 --- a/confluent_server/confluent/discovery/protocols/ssdp.py +++ b/confluent_server/confluent/discovery/protocols/ssdp.py @@ -167,7 +167,10 @@ def snoop(handler, byehandler=None, protocol=None, uuidlookup=None): continue mac = neighutil.get_hwaddr(peer[0]) if not mac: - s.sendto(b'\x00', peer) + try: + s.sendto(b'\x00', peer) + except Exception: + continue deferrednotifies.append((peer, rsp)) continue _process_snoop(peer, rsp, mac, known_peers, newmacs, peerbymacaddress, byehandler, machandlers) @@ -311,8 +314,11 @@ def _find_service(service, target): for s in r: (rsp, peer) = s.recvfrom(9000) if not neighutil.get_hwaddr(peer[0]): + try: + s.sendto(b'\x00', peer) + except Exception: + continue deferparse.append((rsp, peer)) - s.sendto(b'\x00', peer) continue _parse_ssdp(peer, rsp, peerdata) timeout = deadline - util.monotonic_time()