franck 8270d2d7ca Add continuous querying and caching
Replace one-shot, blind-sleep mDNS lookups with a warm cache backed by
persistent background queriers:

- PTR (browse): a single ServiceBrowser tracks every service type seen
  so far (recreated with the enlarged type set when a new one shows
  up, rather than one browser per type), so zeroconf continuously
  refreshes it in the background; answers are read straight from the
  mDNS cache instead of blocking timeout seconds on every query.
- TXT/SRV: still resolved via get_service_info() (already cache-first
  internally), but a background job now periodically re-primes the
  cache so it doesn't go cold between queries.
- A/AAAA (bare hostnames): answers are read from the mDNS cache first;
  only a first-ever query for a name blocks waiting for a response,
  with a background job keeping it warm afterwards.

Periodic refresh jobs are scheduled by a single heap-based scheduler
thread and executed by a fixed pool of 4 worker threads, so the
background thread count stays constant no matter how many distinct
names/services get queried over the proxy's lifetime.

All returned TTLs now reflect the real remaining TTL of the underlying
mDNS record instead of a fixed constant, and goodbye packets (TTL=0)
are handled for free since eviction is delegated to zeroconf's own
cache.

Also add .gitignore for the project-local .venv/ and __pycache__/.
2026-08-05 11:32:18 +02:00
2026-08-05 11:32:18 +02:00
2025-03-09 14:22:24 +01:00
2020-08-03 23:24:02 +02:00
2026-08-05 11:32:18 +02:00
2026-08-05 10:50:54 +02:00
2020-08-02 17:31:50 +02:00

This is a Discovery Proxy for Multicast DNS-Based Service Discovery, written in pure Python. It makes use of zeroconf to obtain mDNS advertisements on the local network and Twisted to re-publish them as a unicast DNS service.

Both IPv4 and IPv6 are supported on the mDNS side. For IPv6, only Unique Local Addresses (ULA, fc00::/7) are published in AAAA records: link-local addresses aren't usable by unicast DNS clients (DNS has no way to express the required zone index), and globally routable addresses are filtered out so that only internal ULA addresses are advertised.

This kind of proxy is specified by RFC 8766. I did not actually follow the standard in implementing it, which means that it doesn't abide by many of the finer details. Nevertheless, it works fine with clients like macOS 10.15 and iOS 13. Any violations of the standard are to be considered bugs and should be fixed over time.

Other implementations of discovery proxies are ohybridproxy and included with mDNSResponder. Since the former only runs on OpenWRT and mDNSResponder is not readily available on Linux, I decided to put together my own implementation in Python. Its dependencies are pure Python, so it should be possible to run it pretty much anywhere.

To use the discovery proxy, run it while specifying a domain to use and a port number to listen on:

python3 proxy.py home.arpa 35353

Then, delegate that domain to the machine the proxy is running on (192.0.2.2 in the example below) and advertise it by adding the necessary records to your network's DNS search domain (example.com in the example below). If you are using dnsmasq, this can be done using

server=/home.arpa/192.0.2.2#35353
ptr-record=b._dns-sd._udp.example.com,home.arpa
ptr-record=lb._dns-sd._udp.example.com,home.arpa
ptr-record=db._dns-sd._udp.example.com,home.arpa

To check whether it is working, you can try some of the following queries (assuming your computer is named yourcomputer and advertises an SSH service):

dig yourcomputer.home.arpa
dig yourcomputer.home.arpa aaaa
dig _ssh._tcp.home.arpa ptr
dig yourcomputer._ssh._tcp.home.arpa srv
S
Description
No description provided
Readme MIT
60 KiB
Languages
Python 100%