[Twisted-Python] Finding peers.

Tim Allen screwtape at froup.com
Mon Jul 7 09:38:38 EDT 2003

On Sunday, Jul 6, 2003, at 23:59 Australia/Sydney, Jody Winston wrote:
> I'm also interested in using Rendezvous in twisted.  I don't have much
> time at the present to both learn Rendezvous and the internals of
> twisted but I'll pass on two links if you haven't seen them.  The
> first link is http://dotlocal.org/ and they are "Software developers
> interested in implementing zeroconf, multicast dns and dns service
> discovery".  The second link is a Python implementation of Rendezvous,
> PyRendezvous, which can be found at..
> http://radio.weblogs.com/0105002/stories/2003/01/06/ 
> multicastDnsServiceDiscoverForPython.html

I just spend a day or so reading about ZeroConf and Twisted's DNS  
support, and hacking together the attached code.

The quick, quick summary is this: ZeroConf has two important parts:  
DNS-SD and mDNS.

DNS-SD (DNS based Service Discovery) is the easy part - it's just a  
standard way of organising DNS records such that a set of DNS queries  
can create a useful list of things to connect to. 'Implementing' DNS-SD  
support is not at all difficult, providing there exists an API to  
request PTR and SRV records, and providing you can add them to your DNS  

mDNS (Multicast DNS) is more complex, and seems to require  
operating-system cooperation. Regular DNS queries to the magic address on port 5353 UDP are declared to be multicast queries, and  
link-local. Also, any attempt to resolve any address ending in '.local'  
should be done via multicast. With multicast DNS come some different (I  
think - I don't know DNS all that well) behaviours:
	- When you send a request that you've already got a reply for, you  
should include the
	  list of names you already have, so those services know not to  
respond a second time.
	- Single requests can have multiple replies.
	- You can have a 'continuous request'.

I haven't read the mDNS spec in detail, but the interaction between  
Twisted and the operating system's resolver seems complex. It'd be nice  
if Python had a DNS API more extensive than gethostbyname(), but it  

The attached files are a first draft at a DNS-SD client library for  
Twisted. dns_sd.py contains the meat, and dns_st_client.py is a thin  
wrapper based on doc/examples/dns-service.py dns_sd.py also contains a  
quick hack to make Twisted.Names issue mDNS requests. The end result is  
that on my Powerbook G4 running Mac OS X 10.2.6, I get the following  

$ ./dns_sd_client.py http tcp local
{'instance': u"Tim Allen's Web Site",
  'servers': [('grundoon.local', 80)],
  'serviceInstance': "Tim Allen's Web Site._http._tcp.local",
  'settings': {'path': '/~st/'}}
{'instance': u'Grundoon',
  'servers': [('grundoon.local', 80)],
  'serviceInstance': 'Grundoon._http._tcp.local',
  'settings': {}}

Note that my laptop's name is 'grundoon' and my login name is 'st'.

The only obvious wart in the code as it stands is that the spec says  
that the 'instance' name can contain any Unicode character, while  
Twisted's DNS code seems to choke on DNS name components that contain  
periods. For the record, the DNS-SD spec says that embedded periods  
should be written '\.', and backslashes obviously '\\'.

It occurs to me now that perhaps I should have written a patch for the  
Twisted DNS code and submitted it along with this message, but it's  
getting late and I wish to get some sleep before I go to work tomorrow.  

-------------- next part --------------
A non-text attachment was scrubbed...
Name: dns_sd.py
Type: application/octet-stream
Size: 6757 bytes
Desc: not available
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20030707/26bfc172/attachment.obj 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dns_sd_client.py
Type: application/octet-stream
Size: 598 bytes
Desc: not available
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20030707/26bfc172/attachment-0001.obj 

More information about the Twisted-Python mailing list