Skip to main content

Service

Struct Service 

Source
pub struct Service { /* private fields */ }
Expand description

A running sharing service. Dropping it stops it.

Implementations§

Source§

impl Service

Source

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.

Source

pub fn bound_port(&self) -> u16

The port the service listens on (the chosen one when Config::port was 0).

Source

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.

Source

pub fn peer_remove(&self, fingerprint: &str) -> bool

Remove a device a host-run resolver reported gone. Returns whether it was on the list.

Source

pub fn status(&self) -> SendStatus

Counts and process resource usage, read now. No polling thread runs for this.

Source

pub fn snapshot(&self) -> Snapshot

Source

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).

Source

pub fn devices(&self) -> Vec<Device>

Source

pub fn fingerprint(&self) -> String

The fingerprint of this Mac’s certificate.

Source

pub fn devices_trust(&self) -> Vec<TrustEntry>

Every device with a record, newest sighting first.

Source

pub fn default_state(&self) -> TrustState

What a never-seen device is subject to: Ask or Deny.

Source

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.

Source

pub fn set_label(&self, fingerprint: &str, label: &str) -> Result<(), Error>

The owner’s own name for a device (empty clears it).

Source

pub fn forget(&self, fingerprint: &str) -> Result<(), Error>

Drop the record of a device that is not on the network now.

Source

pub fn set_default_state(&self, state: TrustState) -> Result<(), Error>

How devices seen for the first time start: Ask or Deny.

Source

pub fn set_save_dir(&self, directory: PathBuf)

Source

pub fn alias(&self) -> String

This computer’s name as other devices list it.

Source

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.

Source

pub fn respond(&self, id: &str, accept: bool) -> bool

Answer a waiting request.

Source

pub fn cancel(&self, transfer_id: &str) -> bool

Cancel a transfer, either direction.

Source

pub fn dismiss(&self, transfer_id: &str)

Forget a finished transfer.

Source

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.

Trait Implementations§

Source§

impl Drop for Service

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. 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> 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> Same for T

Source§

type Output = T

Should always be Self
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.