#[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
impl Discovery
Sourcepub fn name(self, name: impl Into<String>) -> Self
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.
Sourcepub fn model(self, model: impl Into<String>) -> Self
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.
Sourcepub fn ws_discovery(self, enabled: bool) -> Self
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.
Sourcepub fn workgroup(self, workgroup: impl Into<String>) -> Self
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.
Sourcepub fn manufacturer(self, manufacturer: impl Into<String>) -> Self
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.
Sourcepub fn model_name(self, model_name: impl Into<String>) -> Self
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.
Sourcepub fn firmware_version(self, version: impl Into<String>) -> Self
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§
Auto Trait Implementations§
impl Forget for Discovery
impl Freeze for Discovery
impl Move for Discovery
impl RefUnwindSafe for Discovery
impl Send for Discovery
impl Sync for Discovery
impl Unpin for Discovery
impl UnsafeUnpin for Discovery
impl UnwindSafe for Discovery
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> NoneValue for Twhere
T: Default,
impl<T> NoneValue for Twhere
T: Default,
Source§type NoneType = T
type NoneType = T
NoneValue::null_value produces.