Skip to main content

Client

Struct Client 

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

Client is the main handle for interacting with iroh-services. It communicates with iroh-services entirely through an iroh endpoint, and is configured through a builder. Client requires either an Ssh Key or ApiSecret

use iroh::{Endpoint, endpoint::presets};
use iroh_services::Client;

async fn build_client() -> anyhow::Result<()> {
    let endpoint = Endpoint::bind(presets::N0).await?;

    // needs IROH_SERVICES_API_SECRET set to an environment variable
    // client will now push endpoint metrics to iroh-services.
    let client = Client::builder(&endpoint)
        .api_secret_from_str("MY_API_SECRET")?
        .build()
        .await;

    Ok(())
}

Implementations§

Source§

impl Client

Source

pub fn builder(endpoint: &Endpoint) -> ClientBuilder

Source

pub async fn name(&self) -> Result<Option<String>, Error>

Read the current endpoint name from the local client.

Source

pub async fn set_name(&self, name: impl Into<String>) -> Result<(), Error>

Name the active endpoint cloud-side.

names can be any UTF-8 string, with a min length of 2 bytes, and maximum length of 128 bytes. name uniqueness is not enforced.

Source

pub async fn set_group(&self, group: impl Into<String>) -> Result<(), Error>

Attach the active endpoint to a single named group cloud-side.

Group names follow the same rules as endpoint names: any UTF-8 string, minimum 2 bytes, maximum 128 bytes. group uniqueness is not enforced.

Source

pub async fn set_attributes<I, K, V>(&self, attrs: I) -> Result<(), Error>
where I: IntoIterator<Item = (K, V)>, K: Into<String>, V: Into<String>,

Replace the arbitrary key-value attributes on the active endpoint cloud-side.

Accepts any iterable of (key, value) pairs (arrays of tuples, Vecs, HashMaps, BTreeMaps, etc.), so most calls fit on a single line:

client
    .set_attributes([("env", "prod"), ("region", "us-west")])
    .await?;

Keys follow the same rules as endpoint names (2–128 bytes). Values may be empty and are limited to 128 bytes. The map is limited to 128 entries. Each call fully replaces the prior set; passing an empty iterator clears all attributes.

Source

pub async fn ping(&self) -> Result<Pong, Error>

Pings the remote node.

Source

pub async fn push_metrics(&self) -> Result<(), Error>

immediately send a single dump of metrics to iroh-services. It’s not necessary to call this function if you’re using a non-zero metrics interval, which will automatically propagate metrics on the set interval for you

Source

pub async fn grant_capability( &self, remote_id: EndpointId, caps: impl IntoIterator<Item = impl Into<Cap>>, ) -> Result<(), Error>

Grant capabilities to a remote endpoint. Creates a signed RCAN token and sends it to iroh-services for storage. The remote can then use this token when dialing back to authorize its requests.

Source

pub async fn net_diagnostics( &self, send: bool, ) -> Result<DiagnosticsReport, Error>

run local network status diagnostics, optionally uploading the results

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

impl Debug for Client

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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
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
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

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