Skip to content
This repository was archived by the owner on Oct 1, 2021. It is now read-only.

Commit 8212b4e

Browse files
authored
Add the ability to suppress mdns service scans for some services (#256)
- When we are already running a ServiceBrowser for services that netdisco scans for we will already have all the answers we expect to get in the cache. By scanning for these services again, we generate additional network traffic. Since the known answer list was not shared between ServiceBrowsers in earlier versions of zeroconf, we will send an empty list which will cause every services we already have in the cache to be re-populated.
1 parent 0e7296e commit 8212b4e

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

netdisco/discovery.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def __init__(self):
4545
self.is_discovering = False
4646
self.discoverables = None
4747

48-
def scan(self, zeroconf_instance=None):
48+
def scan(self, zeroconf_instance=None, suppress_mdns_types=None):
4949
"""Start and tells scanners to scan."""
5050
self.is_discovering = True
5151

@@ -54,6 +54,10 @@ def scan(self, zeroconf_instance=None):
5454
# Needs to be after MDNS init
5555
self._load_device_support()
5656

57+
if suppress_mdns_types:
58+
for type_ in suppress_mdns_types:
59+
self.mdns.unregister_type(type_)
60+
5761
self.mdns.start()
5862

5963
self.ssdp = SSDP()

netdisco/mdns.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ def register_service(self, service):
3434
"""Register a mDNS service."""
3535
self.services.append(service)
3636

37+
def unregister_type(self, type_):
38+
"""Unregister a mDNS type."""
39+
removes = []
40+
for service in self.services:
41+
if service.typ == type_:
42+
removes.append(service)
43+
for service in removes:
44+
self.services.remove(service)
45+
3746
def start(self):
3847
"""Start discovery."""
3948
try:

0 commit comments

Comments
 (0)