[avahi] Collisions not getting detected in python-avahi

Daniel Stonier d.stonier at gmail.com
Mon Aug 15 02:26:40 PDT 2011


On 10 August 2011 18:12, Daniel Stonier <d.stonier at gmail.com> wrote:

>
> Hi all,
>
> I'm having trouble getting avahi to detect collisions when trying to add a
> service with a name that is already existing.
>
> For reference
>
>  - Platform is ubuntu 10.04
>  - I'm using exactly the script at
> http://avahi.org/wiki/PythonPublishExample
>  - I have two shells open, and run the same script in each shell
>
> Results:
>
> The first execution starts the Demo Service and can be seen when running
> `avahi-browse -a`.
>
> The second execution appears to go smoothly, the group state change goes
> through 'ENTRY_GROUP_REGISTERING'->'ENTRY_GROUP_ESTABLISHED', but nothing
> appears on the avahi browser. I would have expected a group state change to
> 'ENTRY_GROUP_COLLISION' here.
>
> Additionally, the underlying avahi library is doing collisions properly - I
> can check that by running
>
> > avahi-publish -s 'Demo Service' _demo._tcp 1234
> > Failed to add service: Local name collision
>
> Is there a problem with python-avahi and dbus in handling the local name
> collisions?
>
> Regards,
> Daniel Stonier.
>

Discovered a little more enlightenment on this problem - you can detect this
in python via exceptions around the AddService call:

****************************************************************************************

        try:
            self._group.AddService(
                avahi.IF_UNSPEC,
                avahi.PROTO_UNSPEC,
                dbus.UInt32(0),
                service.name,
                service.service_type,
                service.domain,
                service.hostname + "." + service.domain,
                dbus.UInt16(str(service.port)),
                avahi.string_array_to_txt_array(service.description))
            self._group.Commit()
        except dbus.exceptions.DBusException as e:
            # is there  a better way to detect this?
            if e.get_dbus_name() == avahi.DBUS_NAME + ".CollisionError":

****************************************************************************************

Thats awkward. Is there a reason this doesn't go to the group-state_changed
callback (when checking ENTRY_GROUP_COLLISION) along with collisions from
other computers on the lan?

I currently proceed to call GetAlternativeServiceName(...) when this
exception throws.   Is there a better way to handle these?

Cheers,
Daniel.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/avahi/attachments/20110815/b399c756/attachment.htm>


More information about the avahi mailing list