Skip to main content

ServiceDiscovery

Struct ServiceDiscovery 

Source
pub struct ServiceDiscovery { /* private fields */ }
Expand description

Service Discovery implementation using DNS-SD. This implementation advertise all the registered addresses, query for the same service on the same network and keeps a cache of known service instances

Notice that this crate does not provide any means of finding your own ip address. There are crates that provide this kind of feature.

§Example

use simple_mdns::sync_discovery::ServiceDiscovery;
use simple_mdns::InstanceInformation;
use std::str::FromStr;

let mut discovery = ServiceDiscovery::new(
    InstanceInformation::new("a".into()).with_socket_address("192.168.1.22:8090".parse().expect("Invalid Socket Address")),
    "_mysrv._tcp.local",
    60
).expect("Failed to create service discovery");

Implementations§

Source§

impl ServiceDiscovery

Source

pub fn new( instance_information: InstanceInformation, service_name: &str, resource_ttl: u32, ) -> Result<Self, SimpleMdnsError>

Creates a new ServiceDiscovery by providing instance_information, service_name, resource ttl. The service will be created using IPV4 scope with UNSPECIFIED Interface

service_name must be in the standard specified by the mdns RFC, example: _my_service._tcp.local resource_ttl refers to the amount of time in seconds your service will be cached in the dns responder.

Source

pub fn new_with_scope( instance_information: InstanceInformation, service_name: &str, resource_ttl: u32, on_discovery: Option<Sender<InstanceInformation>>, network_scope: NetworkScope, ) -> Result<Self, SimpleMdnsError>

Creates a new ServiceDiscovery by providing instance_information, service_name, resource ttl, on_disovery and network_scope

service_name must be in the standard specified by the mdns RFC, example: _my_service._tcp.local resource_ttl refers to the amount of time in seconds your service will be cached in the dns responder. on_discovery channel, if provided, will receive every instance information when discovered network_scope to be used

Source

pub fn remove_service_from_discovery(&mut self)

Remove service from discovery by announcing with a cache flush and removing all the internal resource records

Source

pub fn get_known_services(&self) -> HashSet<InstanceInformation>

Return the InstanceInformation of all known services

Source

pub fn announce(&self, cache_flush: bool)

Announce the service by sending a packet with all the resource records in the answers section. It is not necessary to call this method manually, it will be called automatically when the instance is added to the discovery.

if cache_flush is true, then the resources will have the cache flush flag set, this will cause them to be removed from any cache that receives the packet.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.