Skip to main content

Server

Struct Server 

Source
pub struct Server<'a, const QLEN: usize, const ALEN: usize, const LLEN: usize, const SLEN: usize, const LK: usize> { /* private fields */ }
Expand description

A server for broadcasting/discovering peers.

  • QLEN - Max number of queries in a single mDNS packet. Only used if not std. Typically 4 for SRV, PTR, TXT and A (or AAAA).
  • ALEN - Max number of answers in a single mDNS packet. Only used if not std. Typically 4 for SRV, PTR, TXT and A (or AAAA).
  • LLEN - Max number of segments for a parsed Label. All services have max 4 segments: martin_test._myservice._udp.local.
  • SLEN - Capacity for service infos and query targets in the Server.
  • LK – List size for DNS label compression. 10 is a good value.

Specifying too small QLEN, ALEN, LLEN or SLEN does not make the server fail, but rather reject messages that can’t be parsed.

use opslag::{Server, ServiceInfo};

let info = ServiceInfo::<4>::new(
    "_midiriff._udp.local", // name of service
    "martin_test",          // instance name, in case multiple services on same host
    "mini.local",           // host
    [192, 168, 0, 1],       // IP address of host
    [255, 255, 255, 0],     // Netmask for the IP
    1234,                   // port of service
 );

// Max 4 queries
// Max 4 answers
// Max 4 segments in a label.
// 1 handled service
// 10 entries for dns label compression
let server = Server::<4, 4, 4, 1, 10>::new([info].into_iter());

Implementations§

Source§

impl<'a, const QLEN: usize, const ALEN: usize, const LLEN: usize, const SLEN: usize, const LK: usize> Server<'a, QLEN, ALEN, LLEN, SLEN, LK>

Source

pub fn new( iter: impl Iterator<Item = ServiceInfo<'a, LLEN>>, ) -> Server<'a, QLEN, ALEN, LLEN, SLEN, LK>

Creates a new server instance.

Source

pub fn query( &mut self, service_type: &'a str, ip: impl Into<IpAddr>, netmask: impl Into<IpAddr>, )

Register a service type to query for without advertising.

This enables discovery-only mode for the given service type: the server will send PTR queries to discover remote instances but will not advertise any local service. The first query goes out immediately (on the next timeout).

use opslag::Server;

let mut server: Server<4, 4, 4, 1, 10> = Server::new(std::iter::empty());
server.query(
    "_my-service._udp.local",
    [192, 168, 0, 1],
    [255, 255, 255, 0],
);
Source

pub fn handle<'x>( &mut self, input: Input<'x>, buffer: &mut [u8], ) -> Output<'x, LLEN, SLEN>

Handle some input and produce output.

You can send Input::Timeout whenenver. The buffer is for outgoing packets. Upon Output::Packet the buffer will be filled to some point with data to transmit.

Auto Trait Implementations§

§

impl<'a, const QLEN: usize, const ALEN: usize, const LLEN: usize, const SLEN: usize, const LK: usize> Freeze for Server<'a, QLEN, ALEN, LLEN, SLEN, LK>

§

impl<'a, const QLEN: usize, const ALEN: usize, const LLEN: usize, const SLEN: usize, const LK: usize> RefUnwindSafe for Server<'a, QLEN, ALEN, LLEN, SLEN, LK>

§

impl<'a, const QLEN: usize, const ALEN: usize, const LLEN: usize, const SLEN: usize, const LK: usize> Send for Server<'a, QLEN, ALEN, LLEN, SLEN, LK>

§

impl<'a, const QLEN: usize, const ALEN: usize, const LLEN: usize, const SLEN: usize, const LK: usize> Sync for Server<'a, QLEN, ALEN, LLEN, SLEN, LK>

§

impl<'a, const QLEN: usize, const ALEN: usize, const LLEN: usize, const SLEN: usize, const LK: usize> Unpin for Server<'a, QLEN, ALEN, LLEN, SLEN, LK>

§

impl<'a, const QLEN: usize, const ALEN: usize, const LLEN: usize, const SLEN: usize, const LK: usize> UnwindSafe for Server<'a, QLEN, ALEN, LLEN, SLEN, LK>

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.