Skip to main content

SharedUnlockPeer

Struct SharedUnlockPeer 

Source
pub struct SharedUnlockPeer<D: SharedUnlockDriver>(Arc<InnerPeer<D>>);
Expand description

One participant in the shared unlock protocol.

Tuple Fields§

§0: Arc<InnerPeer<D>>

Implementations§

Source§

impl<D: SharedUnlockDriver + Send + Sync + 'static> SharedUnlockPeer<D>

Source

pub fn create(driver: D, ipc_client: Arc<dyn IpcClient>) -> Self

Creates a peer. Nothing is sent until SharedUnlockPeer::start is called.

Source

pub fn create_for_test( driver: D, ipc_client: Arc<dyn IpcClient>, sync_interval: Duration, vault_timeout_grace_period: Duration, peer_stale_after: Duration, ) -> Self

Creates a peer that syncs on the given timings rather than the production ones, so tests do not have to wait out a 5s interval. Compiled only for tests and under test-support.

Source

fn create_with_timing( driver: D, ipc_client: Arc<dyn IpcClient>, timing: SharedUnlockTiming, ) -> Self

Source

pub fn set_destinations( &self, user_id: UserId, destinations: Vec<SharedUnlockClient>, )

Sets which clients this peer shares one user’s unlock state with, in both directions: a client that is not in the set is never synced that user, and that user’s syncs from it are dropped on arrival. Replaces any previous set for the user.

Every user defaults to no client at all — a peer neither sends nor accepts anything for a user until this is called for it.

Source

fn is_destination(&self, user_id: UserId, endpoint: &Endpoint) -> bool

Source

pub async fn start( &self, cancellation_token: Option<CancellationToken>, ) -> Result<(), PeerStartError>

Starts the receive loop and the sync timer, then announces this peer’s state once so it does not have to wait a full interval to be discovered.

Source

pub async fn receive_message( &self, incoming_message: TypedIncomingMessage<SharedUnlockSync>, ) -> Result<(), ()>

Handles a sync from another peer.

Source

pub async fn handle_device_event(&self, event: DeviceEvent) -> Result<(), ()>

Records a lock state change made on this device and syncs it to every peer immediately.

Source

async fn apply_remote_state( &self, user_id: UserId, remote: TimestampedLockState, ) -> Result<(), ()>

Applies a peer’s state if it is newer than what this device has recorded.

Source

async fn sync_all_users(&self)

Sends this peer’s state for every logged-in user to every peer it syncs with.

Source

async fn sync_user(&self, user_id: UserId)

Source

async fn sync_all_users_to(&self, target: &SyncTarget)

Sends this peer’s state for every logged-in user to one specific peer.

Source

async fn sync_user_to(&self, user_id: UserId, target: &SyncTarget)

Source

async fn may_sync_user_to(&self, user_id: UserId, target: &SyncTarget) -> bool

Whether a user’s state may be sent to a peer.

The peer must be among the user’s configured destinations.

A web peer is additionally entitled only to the users whose vault URL is the origin it was validated against — the same rule SharedUnlockPeer::receive_message applies to incoming syncs, applied outbound so a page served by one vault is never handed another vault’s key material. A web peer with no recorded origin fails closed.

Source

async fn sync_targets(&self) -> Vec<SyncTarget>

This peer’s leader, if it has one, plus every peer that syncs to it.

Source

async fn send_message(&self, message: SharedUnlockSync, recipient: Endpoint)

Source

pub fn recorded_changed_at(&self, user_id: UserId) -> Option<u64>

The date this peer has recorded for a user, for tests that assert two peers converged on one date and not merely on one state. Compiled only for tests and under test-support.

Source

fn recorded_state(&self, user_id: UserId) -> Option<TimestampedLockState>

Source

fn advertised_state(&self, user_id: UserId) -> TimestampedLockState

The state to advertise for a user: the recorded one, or a presence marker.

Source

fn record_remote_state(&self, user_id: UserId, state: TimestampedLockState)

Records a state reported by a peer, if it still supersedes what is recorded.

Source

fn record_local_state(&self, user_id: UserId, lock_state: LockState)

Records a change made on this device.

Trait Implementations§

Source§

impl<D: SharedUnlockDriver> Clone for SharedUnlockPeer<D>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<D> Freeze for SharedUnlockPeer<D>

§

impl<D> !RefUnwindSafe for SharedUnlockPeer<D>

§

impl<D> Send for SharedUnlockPeer<D>
where D: Sync + Send,

§

impl<D> Sync for SharedUnlockPeer<D>
where D: Sync + Send,

§

impl<D> Unpin for SharedUnlockPeer<D>

§

impl<D> UnsafeUnpin for SharedUnlockPeer<D>

§

impl<D> !UnwindSafe for SharedUnlockPeer<D>

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
§

impl<T> Any for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

§

fn type_name(&self) -> &'static str

§

impl<T> AnySync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

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
§

impl<T> CompatExt for T

§

fn compat(self) -> Compat<T>

Applies the [Compat] adapter by value. Read more
§

fn compat_ref(&self) -> Compat<&T>

Applies the [Compat] adapter by shared reference. Read more
§

fn compat_mut(&mut self) -> Compat<&mut T>

Applies the [Compat] adapter by mutable reference. Read more
Source§

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

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, UT> HandleAlloc<UT> for T
where T: Send + Sync,

§

fn new_handle(value: Arc<T>) -> Handle

Create a new handle for an Arc value Read more
§

unsafe fn clone_handle(handle: Handle) -> Handle

Clone a handle Read more
§

unsafe fn consume_handle(handle: Handle) -> Arc<T>

Consume a handle, getting back the initial Arc<> Read more
§

unsafe fn get_arc(handle: Handle) -> Arc<Self>

Get a clone of the Arc<> using a “borrowed” handle. Read more
§

impl<T> Instrument for T

§

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

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

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,