Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: a simple way to automatically uniquify the service name when other hosts already have the desired name. #264

Open
hgomersall opened this issue Oct 11, 2024 · 12 comments
Assignees
Labels
enhancement New feature or request

Comments

@hgomersall
Copy link
Contributor

This might be desired behaviour following from my understanding of the correct way mDNS-SD should function. I might also be misusing the library.

I have a service running and advertising on a Linux machine. If I run the same executable on a different (Windows) machine, when I run my discover code I see the first machine advertised from the Windows machine as well as from the original Linux machine. I know this is the case as the TXT record contains a UUID generated from each server. I then receive two records advertising the Linux machine, each with a different UUID.

This is not a huge problem, as I can filter on repeated IP addresses, but it seems a little odd to re-advertise a service not explicitly registered.

@hgomersall
Copy link
Contributor Author

Ok, I think I understand what is going on here. The resolver is finding other machines in the network with the same name but different IP address. It's not clearly what, if anything, one should do about this.

@hgomersall
Copy link
Contributor Author

hgomersall commented Oct 11, 2024

I suppose the point here really is to have a way to automate the RFC 6763 Appendix D policy of updating the name to something unique. This would be a useful feature.
Perhaps a function on ServiceDaemon that takes a name and returns a unique version of it based on a standard policy.

@hgomersall hgomersall changed the title Windows readvertising a not-registered service from a different host Feature request: a simple way to automatically uniquify the service name when other hosts already have the desired name. Oct 11, 2024
@keepsimple1
Copy link
Owner

It's surely a useful feature! (It even feels overdue now you mentioned it)

Perhaps a function on ServiceDaemon that takes a name and returns a unique version of it based on a standard policy.

yeah, this could be defined as a new event that can received by a daemon handle. I will take a look at the scope. (It seems like a substantial feature as we need to support Probing and Conflict Resolution. It'll a lot of fun implementing it ;-) )

@hgomersall
Copy link
Contributor Author

hgomersall commented Oct 12, 2024

Yeah, I was thinking about this and it's not entirely trivial to work around potential races. It's not hard to envisage two servers fighting in tandem to get a unique name! (though I might be missing something about how it works).

Edit: this is clearly addressed in rfc 6762 as you linked to!

@dalepsmith
Copy link
Contributor

Yes please!

Something I'd like to request is either a user supplied function/closure for the conflict resolution algorithm, or at least some kind of hook or callback with the newly resolved name.

If I remember correctly, this was either hard or impossible with Avahi. Bonjour did have some of interface for this (again, if my memory serves).

The new conflict-resolved name should be saved in some kind of non-vol storage to be used on the next system start. Having some kind of callback would allow custom implementations, like for embedded systems.

@keepsimple1
Copy link
Owner

Something I'd like to request is either a user supplied function/closure for the conflict resolution algorithm, or at least some kind of hook or callback with the newly resolved name.

As the first / current phase, I'm looking into generating an event with the newly resolved name (as the RFC seems to mandate automatically generated name). Will keep the option of user supplied conflict resolution open / possible.

@keepsimple1
Copy link
Owner

keepsimple1 commented Oct 19, 2024

@hgomersall I've opened a PR #265 that implements the basic conflict resolution (and required probing). When you have time, could you please take a look and give it a try?

I also updated the example register.rs to support input of hostname and --disable-ipv6 option to help testing conflict resolution easily (using same names on two different machines):

Usage:
cargo run --example register <service_type> <instance_name> <hostname> [options]
Options:
--unregister: automatically unregister after 2 seconds
--disable-ipv6: not to use IPv6 interfaces.

@keepsimple1 keepsimple1 added the enhancement New feature or request label Oct 19, 2024
@hgomersall
Copy link
Contributor Author

Yeah, I'll take a look. It might not be for a few days if that's ok.

@dalepsmith
Copy link
Contributor

Not sure where I saw it in the RFC's, or maybe it was in some Apple docs?
Service names get uniqueified like " (N)",
but host names should be like "-N". Don't want to have spaces in host name. (Parens are probably out too).

@keepsimple1
Copy link
Owner

Not sure where I saw it in the RFC's, or maybe it was in some Apple docs? Service names get uniqueified like " (N)", but host names should be like "-N". Don't want to have spaces in host name. (Parens are probably out too).

Thanks! This makes sense. I've updated my PR to reflect this.

@keepsimple1
Copy link
Owner

PR merged. Please let me know if any problems. We can iterate / fix things before the next release.

@keepsimple1
Copy link
Owner

A new release 0.12.0 is published and includes this feature. Any comments / feedbacks are very appreciated, and will be helpful for adding the support of custom function of name conflict resolution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants