Skip to main content

Crate tonic_iroh_transport

Crate tonic_iroh_transport 

Source
Expand description

Transport layer for using tonic gRPC over iroh p2p connections.

§Feature flags

  • client: Outbound connectors (IrohConnect, connect_alpn).
  • server: Inbound transport runtime (TransportBuilder, TransportGuard).
  • discovery: Peer discovery/swarm support (depends on client).
  • otel: OpenTelemetry trace context propagation interceptors.

§Example

use tonic_iroh_transport::TransportBuilder;
use http::Request;
use tonic::body::Body;
use std::convert::Infallible;
use std::task::Poll;
use axum::response::Response;
use tower::Service;

#[derive(Clone)]
struct Dummy;
impl tonic::server::NamedService for Dummy {
    const NAME: &'static str = "test.Service";
}
impl Service<Request<Body>> for Dummy {
    type Response = Response;
    type Error = Infallible;
    type Future = std::future::Ready<Result<Self::Response, Self::Error>>;
    fn poll_ready(&mut self, _cx: &mut std::task::Context<'_>) -> Poll<Result<(), Self::Error>> {
        Poll::Ready(Ok(()))
    }
    fn call(&mut self, _req: Request<Body>) -> Self::Future {
        std::future::ready(Ok(Response::new(axum::body::Body::empty())))
    }
}

// Create an endpoint
let endpoint = iroh::Endpoint::bind(iroh::endpoint::presets::N0).await?;

// Build and run the node
let rpc = TransportBuilder::new(endpoint)
    .add_rpc(Dummy)
    .spawn()
    .await?;

// ... do work ...

// Graceful shutdown
rpc.shutdown().await?;

Re-exports§

pub use channel::IrohChannel;
pub use client::connect_alpn;
pub use client::ConnectBuilder;
pub use client::IrohConnect;
pub use error::Error;
pub use error::Result;
pub use pool::ConnectionPool;
pub use pool::ConnectionRef;
pub use pool::PoolError;
pub use pool::PoolOptions;
pub use stream::IrohContext;
pub use stream::IrohStream;
pub use transport::TransportBuilder;
pub use transport::TransportGuard;
pub use iroh;

Modules§

channel
gRPC channel backed by h2 directly, without hyper.
client
Client connector for tonic over iroh.
error
Error types for tonic-iroh-transport.
pool
Connection pool for reusing iroh connections.
stream
AsyncRead/AsyncWrite wrapper for iroh QUIC streams.
transport
Unified transport builder for composing RPC services over a single iroh router.

Structs§

UserData
Under the hood this is a UTF-8 String is no longer than UserData::MAX_LENGTH bytes.

Functions§

user_data_alpns
Get all ALPNs from user_data.
user_data_has_alpn
Check if user_data contains a specific ALPN.
user_data_has_service
Check if user_data contains the ALPN for a specific tonic service.