Add documentation

This commit is contained in:
Cecylia Bocovich 2023-01-30 15:23:01 -05:00
parent 04e7caef31
commit 685541176b
1 changed files with 24 additions and 0 deletions

View File

@ -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 bytes::{self, Buf, Bytes};
use futures_util::StreamExt; use futures_util::StreamExt;
use reqwest::Client; use reqwest::Client;
@ -32,6 +37,8 @@ impl From<io::Error> 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 { pub struct ResourceStream {
rx: mpsc::Receiver<Bytes>, rx: mpsc::Receiver<Bytes>,
buf: Vec<u8>, buf: Vec<u8>,
@ -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( pub async fn start_stream(
api_endpoint: String, api_endpoint: String,
name: String, name: String,