Skip to content

Comments

Add support for multiple addresses when publishing a service.#27

Closed
basilfx wants to merge 4 commits intopython-zeroconf:masterfrom
basilfx:master
Closed

Add support for multiple addresses when publishing a service.#27
basilfx wants to merge 4 commits intopython-zeroconf:masterfrom
basilfx:master

Conversation

@basilfx
Copy link

@basilfx basilfx commented Sep 6, 2015

Hi,

I use this module to advertise my own service, and noticed that it does not allow multiple addresses (TYPE_A records) when advertising. Services such as iTunes do this.

This PR adds support for it, without breaking existing implementations. ServiceInfo now has a list named addresses, instead of address, but still allows address parameter. It supports publishing, but also browsing will show multiple addresses.

To illustrate:
schermafbeelding 2015-09-06 om 17 09 10

(This app lists IP addresses twice. It's not a cause of this PR.)

Kind regards,
Bas

@jstasiak
Copy link
Collaborator

@basilfx Thank you for the contribution. One thing I'm not sure about is the fact that ServiceInfo loses the address attribute which changes the API, I'll think about this.

@basilfx
Copy link
Author

basilfx commented Sep 18, 2015

Maybe something like this could keep it compatible with the current API (if added to ServiceInfo)? This would ensure that you can still get and set to the address property.

@property
def address(self):
    return self.addresses[0] if self.addresses else None

@address.setter
def address(self, value):
    if value is None:
        self.addresses = []
    else:
        if value in self.addresses:
            self.addresses.remove(value)

        # Ensure address is at index 0 so `self.address == value`.
        self.addresses.insert(0, value)

Haven't tested it :-)

@jstasiak
Copy link
Collaborator

Yes, I'm also thinking about something along these lines :)

@dtantsur
Copy link
Collaborator

Hi @basilfx @jstasiak! Can I help with moving this PR forward? I think it will simplify IPv6 support in the future, which is something I need.

dtantsur added a commit to dtantsur/python-zeroconf that referenced this pull request May 20, 2019
* Raise deprecation warnings when address is used
* Add a compatibility property to avoid breaking existing code
  (based on suggestion by Bas Stottelaar in PR python-zeroconf#27)
* Make addresses keyword-only, so that address can be eventually
  removed and replaced with it without breaking consumers
* Raise TypeError instead of an assertion on conflicting address
  and addresses
dtantsur added a commit to dtantsur/python-zeroconf that referenced this pull request May 20, 2019
* Raise deprecation warnings when address is used
* Add a compatibility property to avoid breaking existing code
  (based on suggestion by Bas Stottelaar in PR python-zeroconf#27)
* Make addresses keyword-only, so that address can be eventually
  removed and replaced with it without breaking consumers
* Raise TypeError instead of an assertion on conflicting address
  and addresses
@dtantsur
Copy link
Collaborator

Update: I've posted #170 with an updated version of this PR.

dtantsur added a commit to dtantsur/python-zeroconf that referenced this pull request May 20, 2019
* Raise deprecation warnings when address is used
* Add a compatibility property to avoid breaking existing code
  (based on suggestion by Bas Stottelaar in PR python-zeroconf#27)
* Make addresses keyword-only, so that address can be eventually
  removed and replaced with it without breaking consumers
* Raise TypeError instead of an assertion on conflicting address
  and addresses
dtantsur added a commit to dtantsur/python-zeroconf that referenced this pull request May 20, 2019
* Raise deprecation warnings when address is used
* Add a compatibility property to avoid breaking existing code
  (based on suggestion by Bas Stottelaar in PR python-zeroconf#27)
* Make addresses keyword-only, so that address can be eventually
  removed and replaced with it without breaking consumers
* Raise TypeError instead of an assertion on conflicting address
  and addresses
jstasiak pushed a commit that referenced this pull request May 22, 2019
This is a rebased and fixed version of PR #27, which also adds compatibility shim for ServiceInfo.address and does a proper deprecation for it.

* Present all addresses that are available.

* Add support for publishing multiple addresses.

* Add test for backwards compatibility.

* Provide proper deprecation of the "address" argument and field

* Raise deprecation warnings when address is used
* Add a compatibility property to avoid breaking existing code
  (based on suggestion by Bas Stottelaar in PR #27)
* Make addresses keyword-only, so that address can be eventually
  removed and replaced with it without breaking consumers
* Raise TypeError instead of an assertion on conflicting address
  and addresses

* Disable black on ServiceInfo.__init__ until black is fixed

Due to psf/black#759 black produces
code that is invalid Python 3.5 syntax even with --target-version py35.
This patch disables reformatting for this call (it doesn't seem to be
possible per line) until it's fixed.
@basilfx
Copy link
Author

basilfx commented May 27, 2019

I'll close this one now that #170 is merged. Thank you @dtantsur.

@basilfx basilfx closed this May 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants