Skip to main content

Discovery

Struct Discovery 

Source
#[non_exhaustive]
pub struct Discovery { /* private fields */ }
Expand description

Announces the server on the local network through multicast DNS and DNS service discovery (RFC 6762, RFC 6763). Clients that browse DNS-SD, such as the Finder, GNOME Files and Dolphin, list it. Pass it to SmbServerBuilder::discovery.

While SmbServer::serve runs, the server is announced as <name>._smb._tcp.local with the port it listens on and an empty TXT record. With a model, <name>._device-info._tcp.local carries TXT model=<model> as well. When serve stops, the records are withdrawn before it returns, waiting at most 2 seconds for that.

On Linux, the server registers with Avahi when avahi-daemon is on the system D-Bus, registers again when avahi-daemon restarts, and moves to Avahi when avahi-daemon reaches the bus after serve started. The SRV record then points at Avahi’s host name, which Avahi announces with the host’s addresses on the interfaces it uses, sending AAAA records over IPv4 too in its default configuration. The listen address picks where the service records go: over IPv4 for 0.0.0.0, over IPv6 for an IPv6-only [::], over both for a dual-stack [::], and on the address’s interface for any other address. Once the server uses Avahi, it is not announced while avahi-daemon is gone, until it returns.

Without Avahi, and on Unix systems other than Apple’s, the server answers mDNS queries itself on UDP port 5353. The SRV record points at <host>.local, where <host> is the first label of the host name, announced with the addresses the listener accepts connections on: IPv4 for 0.0.0.0; IPv6 for [::], and IPv4 too when that socket also accepts IPv4; the one address for any other listen address. Loopback, point-to-point and down interfaces are left out. A name that contains a dot is not announced. When another program holds UDP port 5353, the server is not announced.

On Apple platforms, the server registers with mDNSResponder, which renames it on a conflict and withdraws the records when the server stops or exits. The SRV record points at the host name, which mDNSResponder announces with the host’s IPv4 and IPv6 addresses, whatever addresses the listener accepts. A wildcard listen address registers the service on every interface, any other address on that address’s interface only. When mDNSResponder restarts, the server registers again.

On Windows, the server registers with the DNS client service, which picks a new name when the name is taken, and withdraws the records when the server stops or its process exits. The SRV record points at the computer’s DNS host name, which the DNS client announces with the host’s IPv4 and IPv6 addresses, whatever addresses the listener accepts; a listen address other than a wildcard registers the service on that address’s interface only. The device-info record carries port 9. A name that contains a dot is not announced. A restart of the DNS Client service drops the registration until the server is restarted.

On other platforms nothing is announced over mDNS.

On hosts other than Windows, a server listening on port 445 is also announced to Windows, which lists computers in its Network folder through WS-Discovery and opens them on port 445. The server answers probes on UDP port 3702, sends Hello when it starts or gains an address and Bye when it stops, and serves its metadata over HTTP on TCP port 5357, or on a free port, with a warning, when another program has 5357. Windows lists it under its NetBIOS name, in workgroup workgroup, and opens it by resolving that name, so the server is announced to Windows only when its NetBIOS name is the first label of the host name, ignoring case; otherwise a warning says to set netbios_name to the host name. The NetBIOS name must also be 1 to 15 characters without control characters or any of "/\[]:|<>+=;,?*. Listen on [::]:445: Windows may resolve the name to an IPv6 address too and then connect over IPv6 alone, so it lists a server that listens on IPv4 only but cannot open it, and such a server logs a warning. The server answers on each interface that is up, has an address the listener accepts, and is not loopback, point-to-point, a VPN tunnel (tun*, utun*, wg*), a container network (docker*, br-*, veth*, cni*, flannel*, cali*) or one of Apple’s peer-to-peer links (awdl*, llw*, anpi*). It answers senders with a link-local address or an address on one of that interface’s networks, and follows interface changes within 5 seconds. Its endpoint address is derived from server_guid when that is set, otherwise from the host name and the NetBIOS name, and from the port, so it stays the same across restarts. On macOS, run the server as root for WS-Discovery: as a non-root user, macOS may refuse to send its messages, which is logged as a warning, or not deliver the probes to it, and Windows then does not list the server. On Windows, which announces the computer itself, and on other ports, nothing is announced over WS-Discovery.

Each of these cases, and any failure to announce, is logged; serve runs on either way.

Implementations§

Source§

impl Discovery

Source

pub fn new() -> Self

Discovery under the default name, without a model.

Source

pub fn name(self, name: impl Into<String>) -> Self

Instance name: the name file managers list the server under. 1 to 63 bytes of UTF-8 without control characters, used as given, so pass it in Unicode normalization form C. Defaults to the NetBIOS name in upper case. On Apple platforms with neither a name nor a model set, the server is registered under the computer name instead, and macOS announces the Mac’s own model for it. When another service on the network has the name, the server is renamed with a number added, and the new name is logged. On Windows, and with the built-in responder, a name that contains a dot is not announced.

Source

pub fn model(self, model: impl Into<String>) -> Self

Model code announced in <name>._device-info._tcp.local. The Finder picks the icon it shows for the server by this code. 1 to 249 printable ASCII characters. Not announced unless set.

Source

pub fn ws_discovery(self, enabled: bool) -> Self

Whether to announce the server to Windows over WS-Discovery. By default it is announced when it listens on port 445 on a host other than Windows, and the reason is logged when it is not. With true, build fails when the listen port is set to one other than 445 or the NetBIOS name is not one Windows accepts, and a skipped announcement is logged as a warning.

Source

pub fn workgroup(self, workgroup: impl Into<String>) -> Self

Workgroup Windows lists the server in. 1 to 15 characters without control characters or any of "/\[]:|<>+=;,?*, sent in upper case. Defaults to WORKGROUP.

Source

pub fn manufacturer(self, manufacturer: impl Into<String>) -> Self

Manufacturer Windows shows in the server’s properties. 1 to 255 characters without control characters. Defaults to smb-server.

Source

pub fn model_name(self, model_name: impl Into<String>) -> Self

Model name Windows shows in the server’s properties, apart from the model code the Finder reads. 1 to 255 characters without control characters. Defaults to smb-server.

Source

pub fn firmware_version(self, version: impl Into<String>) -> Self

Firmware version Windows shows in the server’s properties. 1 to 255 characters without control characters. Defaults to the version of this crate.

Trait Implementations§

Source§

impl Clone for Discovery

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Discovery

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Discovery

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> NoneValue for T
where T: Default,

Source§

type NoneType = T

The type of the none-equivalent value that NoneValue::null_value produces.
Source§

fn null_value() -> T

The none-equivalent value.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more