Crate yosemite

Source
Expand description

§yosemite

License Crates.io docs.rs

yosemite is a SAMv3 client library for interacting with the I2P network.

It provides both synchronous and asynchronous APIs which are configurable via sync and async feature flags, respectively.

§Supported features

  • Streams
    • Forwarding
    • Read/Write for synchronous streams
    • AsyncRead/AsyncWrite for asynchronous streams
  • Datagrams
    • Repliable
    • Anonymous

§Usage

async is enabled by default, giving access to asynchronous APIs:

yosemite = "0.4.2"

sync enables synchronous APIs:

yosemite = { version = "0.4.2", default-features = false, features = ["sync"] }

sync and async are mutually exclusive, only one or the other can be enabled. The APIs are otherwise the same but async requires blocking calls to .await.

§Example usage of the API:
use tokio::io::AsyncReadExt;
use yosemite::{style::Stream, Session};

#[tokio::main]
async fn main() -> yosemite::Result<()> {
    let mut session = Session::<Stream>::new(Default::default()).await?;

    while let Ok(mut stream) = session.accept().await {
        println!("{} connected", stream.remote_destination());

        tokio::spawn(async move {
            let mut buffer = vec![0u8; 512];

            while let Ok(nread) = stream.read(&mut buffer).await {
                println!(
                    "client sent: {:?}",
                    std::str::from_utf8(&buffer[..nread])
                );
            }
        });
    }

    Ok(())
}

See examples for instructions on how to use yosemite.

§Copying

MIT

Modules§

style
Session style.

Structs§

RouterApi
Router API.
Session
SAMv3 session.
SessionOptions
Session options.
Stream
Asynchronous virtual stream.
StreamOptions
Stream options.

Enums§

DestinationKind
Destination kind.
Error
yosemite error type.
I2pError
I2P error.
ProtocolError
Protocol error.

Type Aliases§

Result
Result type of the crate.