From 685541176be6d5d8ebc4bdf3811d2f1e02dc79fb Mon Sep 17 00:00:00 2001 From: Cecylia Bocovich Date: Mon, 30 Jan 2023 15:23:01 -0500 Subject: [PATCH] Add documentation --- crates/rdsys-backend/src/lib.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/crates/rdsys-backend/src/lib.rs b/crates/rdsys-backend/src/lib.rs index 7b23e51..6ef21a6 100644 --- a/crates/rdsys-backend/src/lib.rs +++ b/crates/rdsys-backend/src/lib.rs @@ -1,3 +1,8 @@ +//! # Rdsys Backend Distributor API +//! +//! `rdsys_backend` is an implementation of the rdsys backend API +//! https://gitlab.torproject.org/tpo/anti-censorship/rdsys/-/blob/main/doc/backend-api.md + use bytes::{self, Buf, Bytes}; use futures_util::StreamExt; use reqwest::Client; @@ -32,6 +37,8 @@ impl From for Error { } } +/// An iterable wrapper of ResourceDiff items for the streamed chunks of Bytes +/// received from the connection to the rdsys backend pub struct ResourceStream { rx: mpsc::Receiver, buf: Vec, @@ -160,6 +167,23 @@ mod tests { } } +/// Makes an http connection to the rdsys backend api endpoint and returns a ResourceStream +/// if successful +/// +/// # Examples +/// use rdsys_backend::start_stream; +/// +/// ``` +/// let endpoint = String::from("http://127.0.0.1:7100/resource-stream"); +/// let name = String::from("https"); +/// let token = String::from("HttpsApiTokenPlaceholder"); +/// let types = vec![String::from("obfs2"), String::from("scramblesuit")]; +/// let rx = start_stream(endpoint, name, token, types).await.unwrap(); +/// for diff in rx { +/// println!("Received diff: {:?}", diff); +/// } +/// ``` +/// pub async fn start_stream( api_endpoint: String, name: String,