Client

Struct Client 

Source
pub struct Client {
Show 13 fields pub(crate) client_secret: Arc<ClientSecret>, pub(crate) fs: Arc<ZoeClientFileStorage>, pub(crate) storage: Arc<ZoeClientStorage>, pub(crate) message_manager: Arc<ZoeClientMessageManager>, pub(crate) blob_service: Arc<ZoeClientBlobService>, pub(crate) relay_connections: Arc<RwLock<BTreeMap<KeyId, RelayClient>>>, pub(crate) relay_info: Arc<RwLock<BTreeMap<KeyId, RelayConnectionInfo>>>, pub(crate) encryption_key: [u8; 32], pub(crate) client_secret_observable: SharedObservable<ClientSecret>, pub(crate) relay_status_sender: Arc<Sender<RelayStatusUpdate>>, _relay_status_keeper: Arc<InactiveReceiver<RelayStatusUpdate>>, pub(crate) connection_monitors: Arc<RwLock<BTreeMap<KeyId, JoinHandle<()>>>>, pub(crate) session_manager: Arc<ZoeClientSessionManager>,
}

Fields§

§client_secret: Arc<ClientSecret>§fs: Arc<ZoeClientFileStorage>§storage: Arc<ZoeClientStorage>§message_manager: Arc<ZoeClientMessageManager>§blob_service: Arc<ZoeClientBlobService>§relay_connections: Arc<RwLock<BTreeMap<KeyId, RelayClient>>>§relay_info: Arc<RwLock<BTreeMap<KeyId, RelayConnectionInfo>>>§encryption_key: [u8; 32]§client_secret_observable: SharedObservable<ClientSecret>

Observable state for client secret updates - third parties can subscribe to changes

§relay_status_sender: Arc<Sender<RelayStatusUpdate>>

Broadcast channel for per-relay connection status updates

§_relay_status_keeper: Arc<InactiveReceiver<RelayStatusUpdate>>

Keeper receiver to prevent relay status broadcast channel closure (not actively used) Arc-wrapped to ensure channel stays open even when Client instances are cloned and dropped

§connection_monitors: Arc<RwLock<BTreeMap<KeyId, JoinHandle<()>>>>

Connection monitoring tasks for each relay

§session_manager: Arc<ZoeClientSessionManager>

Session manager for the client

Implementations§

Source§

impl Client

Source

pub async fn store_file(&self, file_path: PathBuf) -> Result<FileRef>

Store a file by reading from disk, encrypting, and storing in blob storage

This method:

  1. Reads the file from the provided path
  2. Encrypts the content using convergent encryption
  3. Stores the encrypted data in the blob store
  4. Returns metadata needed to retrieve the file later
§Arguments
  • file_path - Path to the file to store
§Returns

A FileRef containing the metadata needed to retrieve the file

§Errors

Returns an error if:

  • The file cannot be read
  • Encryption fails
  • Blob storage operation fails
Source

pub async fn store_data( &self, data: &[u8], reference_name: &str, content_type: Option<String>, ) -> Result<FileRef>

Store raw data (not from a file) with encryption and blob storage

This method allows storing arbitrary data without reading from disk.

§Arguments
  • data - The raw data to store
  • reference_name - A reference name for the data (used in metadata)
  • content_type - Optional content type for metadata
§Returns

FileRef containing the blob hash, encryption info, and metadata

Source

pub async fn has_file(&self, stored_info: &FileRef) -> Result<bool>

Check if a file exists in storage

§Arguments
  • stored_info - Metadata from when the file was stored
§Returns

true if the file exists in storage, false otherwise

Source

pub async fn retrieve_file( &self, file_ref: &FileRef, output_path: PathBuf, ) -> Result<()>

Retrieve a file from storage and save it to disk

This method:

  1. Retrieves the encrypted data from blob storage using the FileRef
  2. Decrypts the content
  3. Writes the decrypted content to the specified path
§Arguments
  • file_ref - Metadata for the file to retrieve
  • output_path - Path where the decrypted file should be saved
§Errors

Returns an error if:

  • The file cannot be found in storage
  • Decryption fails
  • Writing to disk fails
Source

pub async fn retrieve_file_bytes(&self, file_ref: &FileRef) -> Result<Vec<u8>>

Retrieve a file from storage as bytes

This method:

  1. Retrieves the encrypted data from blob storage using the FileRef
  2. Decrypts the content
  3. Returns the decrypted content as bytes
§Arguments
  • file_ref - Metadata for the file to retrieve
§Returns

The decrypted file content as Vec<u8>

§Errors

Returns an error if:

  • The file cannot be found in storage
  • Decryption fails
Source§

impl Client

Source

pub async fn add_relay(&self, address: RelayAddress) -> Result<()>

Add a relay server to the client

This will attempt to connect to all addresses in the RelayAddress in random order with a 10-second timeout per attempt. Only adds the relay to local state if a connection succeeds.

Source

pub fn add_relay_background( &self, address: RelayAddress, ) -> RelayConnectionHandle

Add a relay server to the client in the background

This returns immediately with a handle that you can optionally poll for the result. The connection attempt continues in the background regardless of whether you poll the handle. Relay status updates will be sent via the normal broadcast channels.

§Usage Examples
// Fire and forget - just start the connection in background
let handle = client.add_relay_background(relay_address);
handle.detach(); // Connection continues in background

// Poll occasionally for result
let mut handle = client.add_relay_background(relay_address);
loop {
    match handle.try_result()? {
        Some(result) => {
            // Connection completed
            break result;
        }
        None => {
            // Still connecting, do other work
            tokio::time::sleep(Duration::from_millis(100)).await;
        }
    }
}

// Wait for completion
let result = client.add_relay_background(relay_address).await_result().await?;
Source

async fn try_connect_to_relay_addresses( &self, address: &RelayAddress, ) -> Result<(SocketAddr, RelayClient), Vec<(String, ClientError)>>

Try to connect to a relay using all its addresses in random order

Returns the successful address and relay client, or all connection errors

Source

pub async fn remove_relay( &self, server_public_key: VerifyingKey, ) -> Result<bool>

Remove a relay connection (offline mode only)

Source

pub async fn get_relay_status(&self) -> Result<Vec<RelayConnectionInfo>>

Get list of all configured relays with their connection status

Source

pub async fn has_connected_relays(&self) -> bool

Check if any relays are currently connected

Source

pub async fn reconnect_failed_relays(&self) -> Result<usize>

Attempt to reconnect to all failed relays

Source

async fn connect_to_relay( &self, server_public_key: VerifyingKey, server_addr: SocketAddr, ) -> Result<RelayClient>

Connect to a specific relay (internal method)

Source

pub async fn close(&self)

Source

pub fn overall_status_stream( &self, ) -> impl Stream<Item = OverallConnectionStatus>

Create a stream of overall connection status computed from relay status updates

This is a computed stream that automatically updates when any relay status changes. It maintains local state and only locks once for initial state, then updates based on incoming relay status changes without additional locking.

Source

pub async fn overall_status(&self) -> OverallConnectionStatus

Calculate the current overall connection status

This is computed from the current relay states, ensuring it’s always accurate but makes it a bit more expensive to compute. For live updates it is recommended to use overall_status_stream instead.

Source

fn start_connection_monitoring( &self, relay_id: KeyId, relay_client: RelayClient, )

Start monitoring a relay connection for disconnections

Source

async fn stop_connection_monitoring(&self, relay_id: KeyId)

Stop monitoring a relay connection

Source

async fn notify_relay_status_change( &self, relay_id: KeyId, relay_address: RelayAddress, status: RelayConnectionStatus, )

Notify about relay status change

Source§

impl Client

Source

pub fn subscribe_to_relay_status(&self) -> Receiver<RelayStatusUpdate>

Subscribe to per-relay connection status updates

This provides real-time updates about individual relay connection status changes. Each relay reports its status independently via this broadcast channel.

Source§

impl Client

Source

pub fn client_secret(&self) -> ClientSecret

Get the current client secret

Source§

impl Client

Source

pub fn subscribe_to_client_secret(&self) -> Subscriber<ClientSecret>

Subscribe to client secret updates

Third parties can use this to be notified when the client secret changes, allowing them to store updated client secrets with the current server configuration.

Source

pub(crate) async fn update_client_secret_state(&self)

Update the client secret observable state with current server configuration

Source§

impl Client

Source

pub fn client_secret_hex(&self) -> Result<String>

Source

pub fn id_hex(&self) -> String

Source

pub fn session_manager(&self) -> Arc<ZoeClientSessionManager>

Close the client and clean up all resources Get access to the session manager for PQXDH operations

This provides access to the underlying session manager which handles PQXDH protocol handlers and state management.

§Returns

A reference to the SessionManager

Source

pub fn group_manager(&self) -> GroupManager

Source§

impl Client

Source

pub fn message_manager(&self) -> &Arc<ZoeClientMessageManager>

Get access to the multi-relay message manager

Source

pub fn blob_service(&self) -> &Arc<ZoeClientBlobService>

Get access to the multi-relay blob service

Source

pub fn storage(&self) -> &Arc<ZoeClientStorage>

Get access to storage

Source

pub fn public_key(&self) -> VerifyingKey

Get the client’s public key

Source

pub fn keypair(&self) -> &Arc<KeyPair>

Get the client’s keypair

Source

pub fn blob_client(&self) -> &BlobClient

Get a reference to the blob client for advanced operations

This provides direct access to the underlying blob storage client for operations not covered by the high-level file storage API.

§Returns

A reference to the BlobClient

Source§

impl Client

Source

pub fn builder() -> ClientBuilder

Create a new ClientBuilder for constructing a Client

Trait Implementations§

Source§

impl Clone for Client

Source§

fn clone(&self) -> Client

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 Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl !UnwindSafe for Client

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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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
§

impl<T> Classify for T

§

type Classified = T

§

fn classify(self) -> T

§

impl<T> Classify for T

§

type Classified = T

§

fn classify(self) -> T

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
§

impl<T> Declassify for T

§

type Declassified = T

§

fn declassify(self) -> T

§

impl<T> Declassify for T

§

type Declassified = T

§

fn declassify(self) -> T

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

§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. 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.

§

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

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

§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> TaskRetFutTrait for T
where T: Send,