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 theServer.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>
impl<'a, const QLEN: usize, const ALEN: usize, const LLEN: usize, const SLEN: usize, const LK: usize> Server<'a, QLEN, ALEN, LLEN, SLEN, LK>
Sourcepub fn new(
iter: impl Iterator<Item = ServiceInfo<'a, LLEN>>,
) -> Server<'a, QLEN, ALEN, LLEN, SLEN, LK>
pub fn new( iter: impl Iterator<Item = ServiceInfo<'a, LLEN>>, ) -> Server<'a, QLEN, ALEN, LLEN, SLEN, LK>
Creates a new server instance.
Sourcepub fn query(
&mut self,
service_type: &'a str,
ip: impl Into<IpAddr>,
netmask: impl Into<IpAddr>,
)
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],
);Sourcepub fn handle<'x>(
&mut self,
input: Input<'x>,
buffer: &mut [u8],
) -> Output<'x, LLEN, SLEN>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more