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

Commit

Permalink
Add the ability to suppress mdns service scans for some services (#256)
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
bdraco authored Jun 23, 2021
1 parent 0e7296e commit 8212b4e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion netdisco/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __init__(self):
self.is_discovering = False
self.discoverables = None

def scan(self, zeroconf_instance=None):
def scan(self, zeroconf_instance=None, suppress_mdns_types=None):
"""Start and tells scanners to scan."""
self.is_discovering = True

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

if suppress_mdns_types:
for type_ in suppress_mdns_types:
self.mdns.unregister_type(type_)

self.mdns.start()

self.ssdp = SSDP()
Expand Down
9 changes: 9 additions & 0 deletions netdisco/mdns.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ def register_service(self, service):
"""Register a mDNS service."""
self.services.append(service)

def unregister_type(self, type_):
"""Unregister a mDNS type."""
removes = []
for service in self.services:
if service.typ == type_:
removes.append(service)
for service in removes:
self.services.remove(service)

def start(self):
"""Start discovery."""
try:
Expand Down

0 comments on commit 8212b4e

Please sign in to comment.