keepsimple1 / mdns-sd

Rust library for mDNS based Service Discovery
Apache License 2.0
102 stars 39 forks source link

feat: verify to support Cache Flush on Failure Indication #267

Closed keepsimple1 closed 1 week ago

keepsimple1 commented 2 weeks ago

This patch is to resolve issue #54 by implement a function to support Cache Flush on Failure Indication

A new API of ServiceDaemon is added:

    pub fn verify_resource(&self, resource: DnsResource, timeout: Duration) -> Result<()>

The idea is that, a querier can call this API anytime to verify if the service records still valid. A ServiceRemoved event will be triggered if no response in timeout.

DnsResource supports SRV record and ADDR record at this moment.

For convenience, VERIFY_RESOURCE_TIMEOUT_DEFAULT is defined for timeout.

UPDATE:

I simplified the new API based on this thought: (most) users would not make 2 calls to verify service_instance_name and hostname for one service instance. The user should be able to call just once to verify a service instance. The library will send query for both SRV and ADDR records internally.

The API now is this:

    pub fn verify(&self, instance_fullname: String, timeout: Duration) -> Result<()>