keepsimple1 / mdns-sd

Rust library for mDNS based Service Discovery
Apache License 2.0
96 stars 37 forks source link

feat: honor cache flush #201

Closed lyager closed 5 months ago

lyager commented 5 months ago

According to RFC 6762, when the cache-flush bit is set on a RR, all previously cache entries should be set to expire 1 second in the future.

This bit was previously called 'UNIQUE` which might have the same meaning, but cache-flush seems more in line with the RFC

lyager commented 5 months ago

I've had issues with embedded devices changing IP's and appearing with both the previous and current IP. I'm guessing this goes for other records too?

lyager commented 5 months ago

Thanks for the response, I'll dive into it 👍

lyager commented 5 months ago

I had some trouble constructing a proper test. My idea was to start browsing, similar to the test service_with_temporarily_invalidated_ptr, but I had trouble constructing response packets. I'll give it another shot, but if you have some test code where MDNS response packets are constructed and send out, please let me know :)

lyager commented 5 months ago

Broke a test putting into draft while looking at it.

keepsimple1 commented 5 months ago

I had some trouble constructing a proper test. My idea was to start browsing, similar to the test service_with_temporarily_invalidated_ptr, but I had trouble constructing response packets. I'll give it another shot, but if you have some test code where MDNS response packets are constructed and send out, please let me know :)

service_with_temporarily_invalidated_ptr is a good sample to start. The response packet is constructed in to_packet_data called by broadcast_dns_on_intf . And you want to add CLASS_CACHE_FLUSH when creating a record (valid record instead of the invalid one in below):

https://github.com/keepsimple1/mdns-sd/blob/1b9647d8c90986e2ee14d31d6907e38b516c26be/src/service_daemon.rs#L2775-L2784

And a different, possible simpler approach is to construct a DnsCache directly, and then call its add_or_update and verify if the changes are applied.

lyager commented 5 months ago

I fixed the already existing test. Thanks for the help with understanding, I'll attempt writing a specific cache-flush test now.

lyager commented 5 months ago

Test added for cache flush - hope it's ok.

lyager commented 5 months ago

Thanks for the feedback, I've stoppede squashing the commit, if you prefer me to, let me know.