svinota / mdns

mDNS library
GNU General Public License v3.0
21 stars 10 forks source link

How to advertise a service? #3

Open Kentzo opened 10 years ago

Kentzo commented 10 years ago

It appears that mdns is a bit inaccurate in documentation. In example:

class ServiceInfo(object):
    """Service information"""

    def __init__(self, type, name, address=None, port=None, weight=0,
            priority=0, properties=None, server=None, records=None,
            ttl=_DNS_TTL, signer=None):
        """Create a service description.

        domain: fully qualified service type name
        name: fully qualified service name
        address: IP address as unsigned short, network byte order
        port: port that the service runs on
        weight: weight of the service
        priority: priority of the service
        properties: dictionary of properties (or a string holding the bytes
            for the text field)
        server: fully qualified name for service host (defaults to name)"""

But how one supposed to advertise a service? I'm trying:

z = Zeroconf()
ServiceInfo('_tcp.', 'blablabla._tcp.', address=socket.inet_aton('192.168.1.10'), port=socket.htons(25000))
z.register_service(i)

But I don't see service in the Bonjour Browser app. Could you be so kind and point me where I'm wrong?

svinota commented 10 years ago

Due to security reasons, by default mdns module doesn't listen on any public sockets.

So in order to see anything, you have to explicitly choose addresses to be exposed on:

z = Zeroconf(address=['127.0.0.1', '192.168.0.1'])

svinota commented 10 years ago

Thanks for reporting, I will fix the doc issue asap.

Kentzo commented 10 years ago

@svinota I'm not trying to find a service. Instead, I'm trying to make service advertised via mdns visible to others. In this "others" is the Bonjour Browser application.

Kentzo commented 10 years ago

@svinota Could you also clarify what name means? As per RFC6763, Service Instance Name = . .

As far as understand, type is . But what are and ? And why name have to end with type?

svinota commented 10 years ago

I'm trying to make service advertised via mdns visible to others.

Exactly. By default Zeroconf instances are not public, you have to explicitly specify interfaces to listen on by giving appropriate IP addrs of interfaces (needed by setsockopt() for IP_MULTICAST_IF and IP_ADD_MEMBERSHIP)

svinota commented 10 years ago

Could you also clarify what name means?

FQDN of the service.

As far as understand, type is . But what are and ?

Don't think I completely understand the question

And why name have to end with type?

Just a bad (really bad) design. Actually, this library needs a deep refactoring.

Kentzo commented 10 years ago

@svinota Sorry, for some reason question missed a few really important keywords :)

As per RFC6763, Service Instance Name = <Instance> . <Service> . <Domain>. How can I map name and type terms to this definition?

svinota commented 10 years ago

name = <Instance> . <Service> . <Domain> . type = <Domain> .

I hope in some mean time I will remove this ancient requirement. If you can help — welcome. Anyway, thanks that pointing this out, w/o the request it wouldn't move on.

Kentzo commented 10 years ago

np

Kentzo commented 10 years ago

@svinota, So, here is the complete program I'm trying to run:

from mdns.zeroconf import *
import socket

z = Zeroconf(address=['127.0.0.1'])
s = ServiceInfo('local.', 'MyName._ssh._tcp.local.', address=socket.inet_aton('192.168.1.100'), port=socket.htons(25000))
z.register_service(s)
z.engine.join()

I'm checking with the dns-sd tool bundled with OSX 10.9:

$dns-sd -B _ssh._tcp. local.
Browsing for _ssh._tcp..local.
DATE: ---Sat 14 Dec 2013---
 9:29:41.622  ...STARTING...
Timestamp     A/R    Flags  if Domain               Service Type         Instance Name
 9:29:41.624  Add        2   4 local.               _ssh._tcp.           Kentzo-Air

As you can see, there is only one such service that's always advertised on my machine, but not the new one.

svinota commented 10 years ago

yep, reproduced. It looks like you found a bug in the service announce code.

Will fix it today, thanks a lot.

svinota commented 10 years ago

Fixed in 95af39201e7640dbdf288103bde00d893893e4bf

Used test code:

from mdns.zeroconf import *
from socket import *

r = Zeroconf(("127.0.0.1", '192.168.0.1'))
n = 'bala._workstation._tcp.local.'
d = '_workstation._tcp.local.'
info = ServiceInfo(d, n, inet_aton('192.168.0.1'), 1234)
r.register_service(info)

raw_input(" >> ")

Checked with avahi-browse.

Pls verify

Kentzo commented 10 years ago

@svinota I'm using OSX 10.9, so I'm browsing for dns-sd messages like this:

$dns-sd -B _workstation._tcp local.

Unfortunately it still doesn't work when I'm running your script. However, if I register service via the dns-sd tool:

$dns-sd -R my _workstation._tcp local. 1234

It will appear in the browser.

svinota commented 10 years ago

Unfortunately, neither have I OSX, nor have knowledge of this system, so all I can right now — is to check compatibility with Avahi. Next week I will ask guys having OSX to validate the work of the library; until that I can rely only on your help.

Can you please check, that avahi-browse sees the service, registered with the mdns library and the service registered via dns-sd in the same way? Does Avahi sees the library service on your system at all?