Zeroconf (Bonjour/Avahi) support for HTTP

Want something added? Ask for it here.
User avatar
shypike
Administrator
Administrator
Posts: 19773
Joined: January 18th, 2008, 12:49 pm

Re: Zeroconf (Bonjour/Avahi) support for HTTP

Post by shypike »

I'm not sure if Bonjour will ever be implemented.
I have spent quite some time on my own code.
The conclusion: Bonjour sucks.
There so many issues with it, that I think we'll have more complaints
rather then less about unreachable addresses.
I don't know if it's the PyBonjour library or Bonjour itself, but the result is very unreliable.
Bonjour (or PyBonjour) insists in slapping .local at the end of the host address
and often that doesn't resolve properly.
At least I cannot get it work properly in my mixed OSX, Windows, Linux environment.
User avatar
sander
Release Testers
Release Testers
Posts: 9429
Joined: January 22nd, 2008, 2:22 pm

Re: Zeroconf (Bonjour/Avahi) support for HTTP

Post by sander »

shypike wrote: I'm not sure if Bonjour will ever be implemented.
I have spent quite some time on my own code.
The conclusion: Bonjour sucks.
There so many issues with it, that I think we'll have more complaints
rather then less about unreachable addresses.
I don't know if it's the PyBonjour library or Bonjour itself, but the result is very unreliable.
Bonjour (or PyBonjour) insists in slapping .local at the end of the host address
and often that doesn't resolve properly.
At least I cannot get it work properly in my mixed OSX, Windows, Linux environment.
Ahh ... and I just had the new code working.  :P I'll post the snippet anyway.

Apart from your points, my biggest concern would be:  bonjour seems to be platform dependent because of the additional platform dependent stuff you have to install (Windows: bonjour for windows, Linux: avahi - stuff, Mac: nothing), which would make SAB itself have more platform dependent stuff ... brrr. Furthermore, bonjour is common in Mac world, but no very well known in the Windows. So it would not be a solution for Windows users.

So: no bonjour in SAB. Clear. (Now what is the solution for all those people not able to start and/or find their own instance of SAB?)


FWIW: ".local" at the end is needed, because it makes clear to name resolution it is bonjour. See http://developer.apple.com/library/mac/ ... names.html . What is it that you don't like about that?


And a seperate question on Mac OS X: I still don't know know how to run the SAB from source. It says to install cherrypy and Cheetah. Any hints? I only see instruction for SABnzbd 0.2.5 on Mac. Warning: I'm a Mac-newbie
If you like our support, check our special newsserver deal or donate at: https://sabnzbd.org/donate
User avatar
sander
Release Testers
Release Testers
Posts: 9429
Joined: January 22nd, 2008, 2:22 pm

Re: Zeroconf (Bonjour/Avahi) support for HTTP

Post by sander »

The code to inserted in SABnzbd.py after "cherrypy.engine.wait(cherrypy.process.wspbus.states.STARTED)":


Code: Select all

####Start Bonjour Zeroconf patch########################################################

    try:
        from sabnzbd.utils import pybonjour
        logging.info('Zeroconf service succesfully imported')

    except OSError:
        logging.info('Zeroconf service could not be registered')
    else:

        logging.info('cherryhost is ' + cherryhost)
        if cherryhost == '0.0.0.0' or cherryhost in ('::','[::]'):
		logging.info('SABnzbd is configured to listen on LAN interface, so start Bonjour Zeroconf')


		# logging.info("does this work " + str(sabnzbd.cfg.cherryport.get_int()) )

		# pity: the following does not work; gives error: "UnboundLocalError: local variable 'http_port' referenced before assignment"
		# logging.info("http_port is " + str(http_port) )
		# logging.info("http_ports is " + str(http_ports) )


		from socket import gethostname
	
	        def zeroconf_callback(sdRef, flags, errorCode, name, regtype, domain):
	            if errorCode == pybonjour.kDNSServiceErr_NoError:
	                logging.info('Registering Zeroconf service')

		# first advertise plain HTTP:

		portrunning = sabnzbd.cfg.cherryport.get_int()

	        zeroconf_sdRef = pybonjour.DNSServiceRegister(
	            name = "SABnzbd on " + gethostname() ,
	            regtype = '_http._tcp',
	            port = portrunning,
	            txtRecord = pybonjour.TXTRecord({'path': '/sabnzbd/'}),
	            callBack = zeroconf_callback)

	        pybonjour.DNSServiceProcessResult(zeroconf_sdRef)

		# now check if HTTPS is used, and if so, advertise it:

		# Remark: advertising '_https._tcp' is not preferred (http://www.dns-sd.org/ServiceTypes.html), we do it anyway


		if enable_https:
			logging.info("enable_https / HTTPS is on, so advertise it ...")
			portrunning = cherryport

			zeroconf_sdRef = pybonjour.DNSServiceRegister(
			    name = "SABnzbd on " + gethostname() ,
			    regtype = '_https._tcp',
			    port = portrunning,
			    txtRecord = pybonjour.TXTRecord({'path': '/sabnzbd/'}),
			    callBack = zeroconf_callback)

			pybonjour.DNSServiceProcessResult(zeroconf_sdRef)

	else:
		logging.info('SABnzbd is not configured to listen on a LAN interface, so not starting Bonjour Zeroconf')

####End Bonjour Zeroconf patch##########################################################

If you like our support, check our special newsserver deal or donate at: https://sabnzbd.org/donate
User avatar
shypike
Administrator
Administrator
Posts: 19773
Joined: January 18th, 2008, 12:49 pm

Re: Zeroconf (Bonjour/Avahi) support for HTTP

Post by shypike »

Mac users have the top menu.
They can start the browser from there.

Macs understand .local, but Windows and Linux do not without extra effort.
BTW: I have VMWare Fusion on the Mac which completely throws Bonjour of its rocker.

Running SABnzbd from sources on a Mac is a bit complicated.
The full version needs ActiveState's Python for Mac.
There's a basic instruction for Apple Python here: http://wiki.sabnzbd.org/howto-osx-src
But this won't enable the top menu.
User avatar
shypike
Administrator
Administrator
Posts: 19773
Joined: January 18th, 2008, 12:49 pm

Re: Zeroconf (Bonjour/Avahi) support for HTTP

Post by shypike »

I'm looking again into Bonjour.
I managed to get VMWare Fusion to give up its virtual adapters vmnet1 and vmnet8.
The problem is that sysname.local is converted to the internal-only vmnet8 address
instead of the proper IP address.
This makes the Bonjour system break down completely.
All of a sudden all Bonjour-enabled services on my LAN become visible.

What were these people at VMWare thinking?
User avatar
sander
Release Testers
Release Testers
Posts: 9429
Joined: January 22nd, 2008, 2:22 pm

Re: Zeroconf (Bonjour/Avahi) support for HTTP

Post by sander »

shypike wrote: I'm looking again into Bonjour.
I managed to get VMWare Fusion to give up its virtual adapters vmnet1 and vmnet8.
The problem is that sysname.local is converted to the internal-only vmnet8 address
instead of the proper IP address.
This makes the Bonjour system break down completely.
All of a sudden all Bonjour-enabled services on my LAN become visible.

What were these people at VMWare thinking?
So, were your Bonjour problems caused by VMware?

If so, have you already run Bonjour on 'bare metal'? What were the results?
If you like our support, check our special newsserver deal or donate at: https://sabnzbd.org/donate
fkmtc
Full Member
Full Member
Posts: 209
Joined: September 19th, 2010, 4:49 am

Re: Zeroconf (Bonjour/Avahi) support for HTTP

Post by fkmtc »

Hi,

How about a full python implementation of ZeroConf : http://sourceforge.net/projects/pyzeroconf/ ?

sander, tried it ?

Thanks,
Jérôme
User avatar
sander
Release Testers
Release Testers
Posts: 9429
Joined: January 22nd, 2008, 2:22 pm

Re: Zeroconf (Bonjour/Avahi) support for HTTP

Post by sander »

Interesting. I did some test runs, with various results. See below.

The source and the website seems to have little documentation. I'll mail the author of the software for help.

PS: the bad news: in 2007 (!!!) someone is asking if the project is still maintained, with no response from the maintainer ... (see http://sourceforge.net/projects/pyzeroc ... ic/1578872)



Code: Select all


sander@R540:~/Downloads/pyzeroconf-0.12$ python Zeroconf.py 
Multicast DNS Service Discovery for Python, version 0.12
1. Testing registration of a service...
   Registering service...
   Registration done.
2. Testing query of service information...
   Getting ZOE service: None
   Query done.
3. Testing query of own service...
   Getting self: None
   Query done.
4. Testing unregister of service information...
   Unregister done.
sander@R540:~/Downloads/pyzeroconf-0.12$ 


sander@R540:~/Downloads/pyzeroconf-0.12$ python ZeroconfTest.py 
Traceback (most recent call last):
  File "ZeroconfTest.py", line 27, in <module>
    import Rendezvous as r
ImportError: No module named Rendezvous



sander@R540:~/Downloads/pyzeroconf-0.12$ python ZeroconfTest2.py 
Traceback (most recent call last):
  File "ZeroconfTest2.py", line 27, in <module>
    from Rendezvous import *
ImportError: No module named Rendezvous
sander@R540:~/Downloads/pyzeroconf-0.12$




sander@R540:~/Downloads/pyzeroconf-0.12$ python Browser.py 
Multicast DNS Service Discovery for Python Browser test
1. Testing browsing for a service...
Service iPod van Felker._http._tcp.local. added
Type is _http._tcp.local.
Traceback (most recent call last):
  File "/home/sander/Downloads/pyzeroconf-0.12/Zeroconf.py", line 862, in run
    self.readers[socket].handle_read()
  File "/home/sander/Downloads/pyzeroconf-0.12/Zeroconf.py", line 907, in handle_read
    msg = DNSIncoming(data)
  File "/home/sander/Downloads/pyzeroconf-0.12/Zeroconf.py", line 470, in __init__
    self.readOthers()
  File "/home/sander/Downloads/pyzeroconf-0.12/Zeroconf.py", line 534, in readOthers
    domain = self.readName()
  File "/home/sander/Downloads/pyzeroconf-0.12/Zeroconf.py", line 602, in readName
    raise "Bad domain name at " + str(off)
TypeError: exceptions must be old-style classes or derived from BaseException, not str
Traceback (most recent call last):
  File "/home/sander/Downloads/pyzeroconf-0.12/Zeroconf.py", line 862, in run
    self.readers[socket].handle_read()
  File "/home/sander/Downloads/pyzeroconf-0.12/Zeroconf.py", line 907, in handle_read
    msg = DNSIncoming(data)
  File "/home/sander/Downloads/pyzeroconf-0.12/Zeroconf.py", line 470, in __init__
    self.readOthers()
  File "/home/sander/Downloads/pyzeroconf-0.12/Zeroconf.py", line 534, in readOthers
    domain = self.readName()
  File "/home/sander/Downloads/pyzeroconf-0.12/Zeroconf.py", line 602, in readName
    raise "Bad domain name at " + str(off)
TypeError: exceptions must be old-style classes or derived from BaseException, not str
Exception in thread Thread-5:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 552, in __bootstrap_inner
    self.run()
  File "/home/sander/Downloads/pyzeroconf-0.12/Zeroconf.py", line 1020, in run
    event(self.zeroconf)
  File "/home/sander/Downloads/pyzeroconf-0.12/Zeroconf.py", line 985, in <lambda>
    callback = lambda x: self.listener.addService(x, self.type, record.alias)
  File "Browser.py", line 16, in addService
    print "Address is", str(socket.inet_ntoa(info.getAddress()))
AttributeError: 'NoneType' object has no attribute 'getAddress'



User avatar
sander
Release Testers
Release Testers
Posts: 9429
Joined: January 22nd, 2008, 2:22 pm

Re: Zeroconf (Bonjour/Avahi) support for HTTP

Post by sander »

Update:

The most recent version is on https://github.com/paulsm/pyzeroconf

I was able to run the included zeroconf.py without problems, but my zeroconf browser (avahi-discover) did not see the Bonjour service it registered. Furthermore the author said his last activity on the code was in 2009.

So I had no success with this code.
Post Reply