pub fn publish_srp_host(
        &mut self,
        _instance: &ot::Instance,
        srp_host: &ot::SrpServerHost,
    ) -> Result<(), anyhow::Error> {
        if srp_host.is_deleted() {
            // Delete the host.
            info!("No longer advertising {:?} on {:?}", srp_host.full_name_cstr(), LOCAL_DOMAIN);

            self.hosts.remove(srp_host.full_name_cstr());
            return Ok(());
        }

        let host: &mut AdvertisingProxyHost =
            if let Some(host) = self.hosts.get_mut(srp_host.full_name_cstr()) {
                // Use the existing host.
                info!(
                    "Updating advertisement of {:?} on {:?}",
                    srp_host.full_name_cstr(),
                    LOCAL_DOMAIN
                );

                host
            } else {
                // Add the host.
                info!("Advertising {:?} on {:?}", srp_host.full_name_cstr(), LOCAL_DOMAIN);

                self.hosts.insert(
                    srp_host.full_name_cstr().to_owned(),
                    AdvertisingProxyHost { services: Default::default() },
                );
                self.hosts.get_mut(srp_host.full_name_cstr()).unwrap()
            };

        let services = &mut host.services;

        for srp_service in srp_host.find_services::<&CStr, &CStr>(
            ot::SrpServerServiceFlags::BASE_TYPE_SERVICE_ONLY,
            None,
            None,
        ) {
            if srp_service.is_deleted() {
                // Delete the service.
                info!(
                    "No longer advertising {:?} on {:?}",
                    srp_service.full_name_cstr(),
                    LOCAL_DOMAIN
                );
                services.remove(srp_service.full_name_cstr());
                continue;
            }

            let is_up_to_date = services
                .get(srp_service.full_name_cstr())
                .map(|s| s.is_up_to_date(srp_service))
                .unwrap_or(false);

            if is_up_to_date {
                // Service is already up to date.
                continue;
            }

            info!("Advertising {:?} on {:?}", srp_service.full_name_cstr(), LOCAL_DOMAIN);

            // (Re-)Add the service.

            services.insert(
                srp_service.full_name_cstr().to_owned(),
                AdvertisingProxyService {
                    txt_data: srp_service.txt_data().to_vec(),
                    port: srp_service.port(),
                    priority: srp_service.priority(),
                    weight: srp_service.weight(),
                },
            );
        }

        Ok(())
    }
/// Updates the mDNS service with the host and services from the SrpServerHost.
Updates the mDNS service with the host and services from the SrpServerHost.
Updates the mDNS service with the host and services from the SrpServerHost .
pub fn publish_srp_host(
        &mut self,
        _instance: &ot::Instance,
        srp_host: &ot::SrpServerHost,
    ) -> Result<(), anyhow::Error> {
        if srp_host.is_deleted() {
            // Delete the host.
            info!("No longer advertising {:?} on {:?}", srp_host.full_name_cstr(), LOCAL_DOMAIN);
            self.hosts.remove(srp_host.full_name_cstr());
            return Ok(());
        }
        let host: &mut AdvertisingProxyHost =
            if let Some(host) = self.hosts.get_mut(srp_host.full_name_cstr()) {
                // Use the existing host.
                info!(
                    "Updating advertisement of {:?} on {:?}",
                    srp_host.full_name_cstr(),
                    LOCAL_DOMAIN
                );
                host
            } else {
                // Add the host.
                info!("Advertising {:?} on {:?}", srp_host.full_name_cstr(), LOCAL_DOMAIN);
                self.hosts.insert(
                    srp_host.full_name_cstr().to_owned(),
                    AdvertisingProxyHost { services: Default::default() },
                );
                self.hosts.get_mut(srp_host.full_name_cstr()).unwrap()
            };
        let services = &mut host.services;
        for srp_service in srp_host.find_services::<&CStr, &CStr>(
            ot::SrpServerServiceFlags::BASE_TYPE_SERVICE_ONLY,
            None,
            None,
        ) {
            if srp_service.is_deleted() {
                // Delete the service.
                info!(
                    "No longer advertising {:?} on {:?}",
                    srp_service.full_name_cstr(),
                    LOCAL_DOMAIN
                );
                services.remove(srp_service.full_name_cstr());
                continue;
            }
            let is_up_to_date = services
                .get(srp_service.full_name_cstr())
                .map(|s| s.is_up_to_date(srp_service))
                .unwrap_or(false);
            if is_up_to_date {
                // Service is already up to date.
                continue;
            }
            info!("Advertising {:?} on {:?}", srp_service.full_name_cstr(), LOCAL_DOMAIN);
            // (Re-)Add the service.
            services.insert(
                srp_service.full_name_cstr().to_owned(),
                AdvertisingProxyService {
                    txt_data: srp_service.txt_data().to_vec(),
                    port: srp_service.port(),
                    priority: srp_service.priority(),
                    weight: srp_service.weight(),
                },
            );
        }
        Ok(())
    }
pub fn publish_srp_host ( & mut self , _instance : & ot :: Instance , srp_host : & ot :: SrpServerHost , ) -> Result < ( ) , anyhow :: Error > { if srp_host . is_deleted ( ) { // Delete the host. info ! ( " " srp_host full_name_cstr ( ) LOCAL_DOMAIN ) ; self . hosts . remove ( srp_host . full_name_cstr ( ) ) ; return Ok ( ( ) ) ; } let host : & mut AdvertisingProxyHost = if let Some ( host ) = self . hosts . get_mut ( srp_host . full_name_cstr ( ) ) { // Use the existing host. info ! ( " " srp_host full_name_cstr ( ) LOCAL_DOMAIN ) ; host } else { // Add the host. info ! ( " " srp_host full_name_cstr ( ) LOCAL_DOMAIN ) ; self . hosts . insert ( srp_host . full_name_cstr ( ) . to_owned ( ) , AdvertisingProxyHost { services : Default :: default ( ) } , ) ; self . hosts . get_mut ( srp_host . full_name_cstr ( ) ) . unwrap ( ) } ; let services = & mut host . services ; for srp_service in srp_host . find_services :: < & CStr , & CStr > ( ot :: SrpServerServiceFlags :: BASE_TYPE_SERVICE_ONLY , None , None , ) { if srp_service . is_deleted ( ) { // Delete the service. info ! ( " " srp_service full_name_cstr ( ) LOCAL_DOMAIN ) ; services . remove ( srp_service . full_name_cstr ( ) ) ; continue ; } let is_up_to_date = services . get ( srp_service . full_name_cstr ( ) ) . map ( | s | s . is_up_to_date ( srp_service ) ) . unwrap_or ( false ) ; if is_up_to_date { // Service is already up to date. continue ; } info ! ( " " srp_service full_name_cstr ( ) LOCAL_DOMAIN ) ; // (Re-)Add the service. services . insert ( srp_service . full_name_cstr ( ) . to_owned ( ) , AdvertisingProxyService { txt_data : srp_service . txt_data ( ) . to_vec ( ) , port : srp_service . port ( ) , priority : srp_service . priority ( ) , weight : srp_service . weight ( ) , } , ) ; } Ok ( ( ) ) }
Updates the mDNS service with the host and services from the SrpServerHost.
Updates the mDNS service with the host and services from the SrpServerHost .
&mut self
_instance
&ot::Instance
srp_host
&ot::SrpServerHost
&mut self
_instance
&ot::Instance
srp_host
&ot::SrpServerHost