Skip to main content

iroh_services/
lib.rs

1//! iroh-services is the client side of interacting with [iroh-services]. iroh-services gives
2//! visibility into a running iroh network by pushing metrics aggregations
3//! from [iroh] endpoints into a central hub for monitoring.
4//!
5//! Typical setup looks something like this:
6//! ```no_run
7//! use iroh::{Endpoint, endpoint::presets};
8//! use iroh_services::Client;
9//!
10//! #[tokio::main]
11//! async fn main() -> anyhow::Result<()> {
12//!     let endpoint = Endpoint::bind(presets::N0).await?;
13//!
14//!     // needs IROH_SERVICES_API_SECRET set to an environment variable
15//!     // client will now push endpoint metrics to iroh-services.
16//!     let client = Client::builder(&endpoint)
17//!         .api_secret_from_env()?
18//!         .build()
19//!         .await?;
20//!
21//!     // we can also ping the service just to confirm everything is working
22//!     client.ping().await?;
23//!
24//!     Ok(())
25//! }
26//! ```
27//!
28//! [iroh-services]: https://services.iroh.computer
29//! [iroh]: https://iroh.computer
30
31mod client;
32mod client_host;
33#[cfg(not(target_arch = "wasm32"))]
34mod openssh;
35
36pub mod api_secret;
37pub mod caps;
38// File-based log collection is native-only (rolling file appender, fs access).
39#[cfg(not(target_arch = "wasm32"))]
40pub mod logs;
41pub mod net_diagnostics;
42mod preset;
43pub mod protocol;
44
45mod built_info {
46    include!(concat!(env!("OUT_DIR"), "/built.rs"));
47}
48
49/// Version of this crate.
50pub const IROH_SERVICES_VERSION: &str = built_info::PKG_VERSION;
51
52/// Version of iroh this crate was built against.
53pub static IROH_VERSION: std::sync::LazyLock<&str> = std::sync::LazyLock::new(|| {
54    built_info::DEPENDENCIES
55        .iter()
56        .find(|(name, _)| *name == "iroh")
57        .expect("iroh dependency not found")
58        .1
59});
60
61pub use anyhow;
62pub use client_host::{CLIENT_HOST_ALPN, ClientHost, ClientHostClient};
63pub use iroh_metrics::Registry;
64
65pub use self::{
66    api_secret::{API_SECRET_ENV_VAR_NAME, ApiSecret},
67    client::{Client, ClientBuilder},
68    net_diagnostics::{DiagnosticsReport, checks::run_diagnostics},
69    preset::{IrohServicesPreset, PresetBuilder, preset},
70    protocol::ALPN,
71};