Repository navigation
feat: extend DnsAddress with an InterfaceId - #342
Conversation
9530a44 to
8e7f17b
Compare
| let selected_addrs = self.selected_addrs(my_ip_interfaces(true)); | ||
| for addr in selected_addrs { | ||
| info.insert_ipaddr(addr); | ||
| info.insert_scoped_addr(addr, None); |
There was a problem hiding this comment.
I'm not sure yet if we can eliminate this None and the one in https://github.com/keepsimple1/mdns-sd/pull/342/files#diff-2061a30a0f84a30fe5c20cfb9505c70e8efd1147fc27ebb4deb5e35c53d3a59fR205 which would make the Option superfluous.
There was a problem hiding this comment.
I think we should pass in the actual interface id instead of None since we have the info from my_ip_interfaces().
We can modify selected_addrs() function to return a set of ScopedAddr
cefb9a4 to
c0873d8
Compare
| let mut resolved = false; | ||
|
|
||
| while let Ok(event) = browse_chan.recv_timeout(timeout) { | ||
| match event { |
There was a problem hiding this comment.
Those next 3 changes were suggested by rust clippy for single_match, if not feasible please let me know.
There was a problem hiding this comment.
I've reverted all unrelated changes, to avoid adding too much refactoring to this PR
keepsimple1
left a comment
There was a problem hiding this comment.
Thanks again for your PR! I've added a few inline comments. And I also have a high level question:
Instead of add interface info in each address, should we add the interface info at ServiceInfo ?
For IPv6, I think it's pretty clear we can / should add the interface at ServiceInfo layer because mDNS for IPv6 is in link-local scopes (only). It is possible that there are two service instances with exact same name but on two different IPv6 interfaces. Currently we would combine them into one ServiceInfo with two addresses, which would be incorrect.
For IPv4, things are different. If a host has 2 IPv4 interfaces configured on the same LAN, they will only see one service instance given the same name. It's ok / making sense to combine into one ServiceInfo. That said, it's also workable if we return two ServiceInfo records each for one Interface.
Looking at Avahi, it seems they are reporting service instances based on interfaces. So basically my question is: shall we do that too? (Avahi also reports IPv4 and IPv6 separately, but I think we could combine them).
What do you think?
| class: u16, | ||
| ttl: u32, | ||
| address: IpAddr, | ||
| scope: Option<InterfaceScope>, |
There was a problem hiding this comment.
I think we can get rid of Option as DnsIncoming can always have the interface info.
| num_answers: u16, | ||
| num_authorities: u16, | ||
| num_additionals: u16, | ||
| scope: Option<InterfaceScope>, |
There was a problem hiding this comment.
we can get rid of Option here as this interface is available when creating DnsIncoming.
|
|
||
| /// InterfaceScope is used to represent the interface name and index | ||
| #[derive(Clone, Debug, Eq, Hash, PartialEq)] | ||
| pub struct InterfaceScope { |
There was a problem hiding this comment.
nitpick: scope is really a concept in IPv6, not a concept of a network interface. How about naming this struct InterfaceId ?
| let selected_addrs = self.selected_addrs(my_ip_interfaces(true)); | ||
| for addr in selected_addrs { | ||
| info.insert_ipaddr(addr); | ||
| info.insert_scoped_addr(addr, None); |
There was a problem hiding this comment.
I think we should pass in the actual interface id instead of None since we have the info from my_ip_interfaces().
We can modify selected_addrs() function to return a set of ScopedAddr
|
|
||
| /// ScopedAddress is used to represent an address and its interface scope | ||
| #[derive(Clone, Debug, Eq, Hash, PartialEq)] | ||
| pub struct ScopedAddress { |
There was a problem hiding this comment.
nitpick: To follow the naming pattern of IpAddr etc, shall we name this ScopedAddr ?
There was a problem hiding this comment.
Fair point, but I guess we sort of agreed upon adding InterfaceId to ServiceInfo instead.
| #[derive(Clone, Debug, Eq, Hash, PartialEq)] | ||
| pub struct ScopedAddress { | ||
| address: IpAddr, | ||
| scope: Option<InterfaceScope>, |
There was a problem hiding this comment.
I think we can get rid of Option here as there is always an interface owning the address.
| } | ||
| } | ||
|
|
||
| impl DnsRecordExt for DnsAddress { |
There was a problem hiding this comment.
We also need to update matches for DnsAddress to check scope (or interface_id)
Thanks for reviewing, I will address those comments after resolving the high level discussion.
Yes that makes sense, I thought about this route shorty but didn't yet tried it out. Now it also makes sense to me to separate IPv4 and IPv6 ServiceInfos and per interface like Avahi does. That would make the structure more cleaner. From a library consumer perspective that approach would be more feasible than the route I took initially. The consumer of the library can still |
Could you elaborate more about this separation of IPv4 and IPv6 Serviceinfos ? My initial thought was that they can always been combined and so this library can do it for the users. But I'd like to understand more from your point of view. |
Ah, maybe I got something wrong. I envisioned an addition of |
|
@keepsimple1: 'm going to add
struct InterfaceId {
name: String,
index: Option<u32>,
}If you don't object. |
| use crate::error::{e_fmt, Error, Result}; | ||
| use crate::{ | ||
| error::{e_fmt, Error, Result}, | ||
| service_info::InterfaceScope, |
There was a problem hiding this comment.
@keepsimple1: dns_parser is ought to be a separate module, do we want to provide InterfaceId from dns_parser. Or would it be better to create a separate module interface_id which provides InterfaceId for dns_parser and service_info. I'm not that fluent yet in rust best practices about modules, I'm just guessing from experience from other languages and I sort of would prefer the interface_id module.
There was a problem hiding this comment.
I think it's okay to define InterfaceId in dns_parser. We can refactor the module later once we have clearer understanding.
|
I've started to work on adding an Line 94 in 4192b1a But how do we want to do that without introducing a breaking change? |
I see the following option here:
|
I'm thinking maybe this is a good time for us to move towards using
When a service is resolved, we will send both existing If the new variant works well, we can deprecate the Of course, this still a breaking change because (Sorry about bringing up more changes, I hope this PR can form a good foundation for future enhancements) Thoughts? |
No objections. The only thing I was curious is that: should |
|
I think this PR might be too involved. And since the full diff will introduce some breaking changes, I am wondering if we can split it into two steps:
Would you like to use this PR to commit the 1) stuff first? Meantime we can think more about 2) and also do some experiments. |
Yes sounds reasonable, I'll only touch |
This allows for adding an interface scope to resolved IPv6 link local addresses to resolve keepsimple1#339
c0873d8 to
775d32d
Compare
DnsAddress with an InterfaceId
keepsimple1
left a comment
There was a problem hiding this comment.
LGTM! Only one minor comment about a typo. Thanks!
| time::SystemTime, | ||
| }; | ||
|
|
||
| /// InterfaceId is used to represent the interface indentifer |
There was a problem hiding this comment.
typo: "indentifer" -> "identifier"
There was a problem hiding this comment.
Fixed with 35116be, thanks for reviewing.
There was a problem hiding this comment.
I also fixed some more minor spelling issues with typos-cli in ba742ed
This allows for adding an interface scope to resolved IPv6 link local addresses to resolve #339