pub struct Service { /* private fields */ }Expand description
A running sharing service. Dropping it stops it.
Implementations§
Source§impl Service
impl Service
Sourcepub fn start(
config: Config,
identity: Identity,
on_event: Arc<dyn Fn(Event) + Send + Sync>,
) -> Result<Service, Error>
pub fn start( config: Config, identity: Identity, on_event: Arc<dyn Fn(Event) + Send + Sync>, ) -> Result<Service, Error>
Start sharing with config, presenting identity: the host’s stored
certificate and key. Fails before anything is announced when the identity,
the trust store or the listen port cannot be used.
Sourcepub fn bound_port(&self) -> u16
pub fn bound_port(&self) -> u16
The port the service listens on (the chosen one when Config::port was 0).
Sourcepub fn peer_add_resolved(
&self,
fingerprint: &str,
alias: &str,
host: IpAddr,
port: u16,
txt: &[(String, String)],
) -> Result<(), Error>
pub fn peer_add_resolved( &self, fingerprint: &str, alias: &str, host: IpAddr, port: u16, txt: &[(String, String)], ) -> Result<(), Error>
Add a device a host-run resolver found (on iOS, Swift’s NWBrowser feeds
this). txt holds the TXT keys (fp, alias, type, model, px).
The fingerprint must be 64 hex characters; identity is still proven by
the handshake certificate, never by this announcement.
Sourcepub fn peer_remove(&self, fingerprint: &str) -> bool
pub fn peer_remove(&self, fingerprint: &str) -> bool
Remove a device a host-run resolver reported gone. Returns whether it was on the list.
Sourcepub fn status(&self) -> SendStatus
pub fn status(&self) -> SendStatus
Counts and process resource usage, read now. No polling thread runs for this.
pub fn snapshot(&self) -> Snapshot
Sourcepub fn refresh(&self)
pub fn refresh(&self)
Look for devices again now: announce on multicast and sweep the local networks (the sweep is skipped while one is already running).
pub fn devices(&self) -> Vec<Device>
Sourcepub fn fingerprint(&self) -> String
pub fn fingerprint(&self) -> String
The fingerprint of this Mac’s certificate.
Sourcepub fn devices_trust(&self) -> Vec<TrustEntry>
pub fn devices_trust(&self) -> Vec<TrustEntry>
Every device with a record, newest sighting first.
Sourcepub fn default_state(&self) -> TrustState
pub fn default_state(&self) -> TrustState
What a never-seen device is subject to: Ask or Deny.
Sourcepub fn set_trust(
&self,
fingerprint: &str,
state: TrustState,
) -> Result<(), Error>
pub fn set_trust( &self, fingerprint: &str, state: TrustState, ) -> Result<(), Error>
Set a device to Allow, Ask or Deny. Deny also withdraws what the device has pending or in flight.
Sourcepub fn set_label(&self, fingerprint: &str, label: &str) -> Result<(), Error>
pub fn set_label(&self, fingerprint: &str, label: &str) -> Result<(), Error>
The owner’s own name for a device (empty clears it).
Sourcepub fn forget(&self, fingerprint: &str) -> Result<(), Error>
pub fn forget(&self, fingerprint: &str) -> Result<(), Error>
Drop the record of a device that is not on the network now.
Sourcepub fn set_default_state(&self, state: TrustState) -> Result<(), Error>
pub fn set_default_state(&self, state: TrustState) -> Result<(), Error>
How devices seen for the first time start: Ask or Deny.
pub fn set_save_dir(&self, directory: PathBuf)
Sourcepub fn send(
&self,
target: &str,
items: Vec<SendItem>,
clipboard: bool,
) -> Result<String, Error>
pub fn send( &self, target: &str, items: Vec<SendItem>, clipboard: bool, ) -> Result<String, Error>
Send to the device with this fingerprint (or, failing that, alias). Returns the transfer id; progress arrives as events.
Sourcepub fn stop(&self)
pub fn stop(&self)
Stop sharing. Pending requests are declined, transfers in flight are cancelled, and the
acceptor and liveness threads are ended and joined: when this returns the listening socket
is closed and its port can be bound again, and no thread of the service’s own is left
running. It returns promptly (a few milliseconds), never waiting on a peer. Connection
handlers and liveness probes already running are not joined; they finish on their own
within their socket timeouts. Calling it again, or dropping the Service, does nothing more.