Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docs from gitbook to crates #18

Merged
merged 38 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
0063bb6
update: change namespaces to prefix
Oct 23, 2023
582d24d
update: v0+ API matching + plain runnable with Dialer
Oct 30, 2023
0302fa0
update: lint
Oct 30, 2023
d31964c
fix: fmt
Oct 30, 2023
400eb32
fix: clippy
Oct 30, 2023
177cbc0
fix: resolve conflicts from the prev PR
Nov 1, 2023
f2f1d72
update: keep the library code safe
Nov 1, 2023
fdec4f1
update: cleaning code + more sensible comments
erikziyunchi Nov 5, 2023
330f987
fix: clippy
erikziyunchi Nov 5, 2023
1e5f376
update: remove dup .wasm + link go-side runner for plain.wasm & PR fo…
erikziyunchi Nov 5, 2023
493061d
update: adding listener(base), tests, refactoring
erikziyunchi Nov 9, 2023
8447289
fix: fmt
erikziyunchi Nov 9, 2023
044eff6
fix: clippy
erikziyunchi Nov 9, 2023
cfddea1
fix: conflict
erikziyunchi Nov 9, 2023
20b832d
update: add relay, test
erikziyunchi Nov 10, 2023
8bbc3c7
fix: sleep 1 sec before terminating relay to allow the test finish + …
erikziyunchi Nov 10, 2023
d8bfa5f
fix: clippy & give a bit more time before terminate for relay test
erikziyunchi Nov 10, 2023
c2010a5
fix: isolate relay test with another test file
erikziyunchi Nov 10, 2023
3f569a3
fix: fmt
erikziyunchi Nov 10, 2023
90b5d93
fix: change port in relay test
erikziyunchi Nov 10, 2023
94a6ac2
add docs from gitbook to crates
jmwample Dec 1, 2023
d0da8c0
image move and crate name
jmwample Dec 1, 2023
f6e7b46
update: add multi listener for v0
erikziyunchi Dec 18, 2023
cd43711
update: lint
erikziyunchi Dec 18, 2023
9e38b7a
fix: resolve conflict
erikziyunchi Dec 19, 2023
aa3bed6
fix: lint
erikziyunchi Dec 19, 2023
b169832
fix: new ss wasm binary + change port in test
erikziyunchi Dec 19, 2023
664e389
fix: fmt
erikziyunchi Dec 19, 2023
799932c
update: working cli (v1 runner mode)
erikziyunchi Dec 20, 2023
f2ac547
fmt + lint
erikziyunchi Dec 20, 2023
aeb70fc
update: merge changes & add partial doc
erikziyunchi Jan 4, 2024
384e208
fix: resolve conflict
erikziyunchi Jan 4, 2024
8723287
clippy
erikziyunchi Jan 4, 2024
bdb72a6
update: sync cli-tool
erikziyunchi Jan 4, 2024
8af50d1
update: match main
erikziyunchi Jan 7, 2024
df14b71
update: more doc
erikziyunchi Jan 7, 2024
01931bd
update: more docs
erikziyunchi Jan 9, 2024
8a869ed
resolve conflict
erikziyunchi Jan 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .github/assets/water_rust_lib_draft1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ resolver="2"


[workspace.package]
authors = ["cerikccc@gmail.com", "gaukas", "jmwample", "ewust"]
authors = ["hi@erikchi.com", "gaukas", "jmwample", "ewust"]
description = "Water WebAssembly Transport Executor for rust"
edition = "2021"
# documentation = "https://example.com/bar"
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ If you quoted or used our work, please cite our paper [Just add WATER: WebAssemb

The repo contains 2 main components:
1. A Rust crate [`water`](https://github.com/erikziyunchi/water-rs/tree/main/crates/water) runtime library used to interact with `.wasm` WebAssembly Transport Modules(WATM).
2. A Rust crate [`water-wasm-crate`](https://github.com/erikziyunchi/water-rs/tree/main/crates/wasm) for WATM-development where developers can easily create their own `.wasm`.
2. A Rust crate [`water_wasm`](https://github.com/erikziyunchi/water-rs/tree/main/crates/wasm) for WATM-development where developers can easily create their own `.wasm`.

Also include examples for demonstration of usage:
1. A standalone cli tool which can be used to load a `.wasm` WATM directly and run it. See [water-rs/tree/main/examples/clients/cli](https://github.com/erikziyunchi/water-rs/tree/main/examples/clients/cli).
2. A few examples WATM implementations with `water-wasm-crate`, see [water-rs/tree/main/examples/water_bins](https://github.com/erikziyunchi/water-rs/tree/main/examples/water_bins).
2. A few examples WATM implementations with `water_wasm` crate, see [water-rs/tree/main/examples/water_bins](https://github.com/erikziyunchi/water-rs/tree/main/examples/water_bins).
3. Examples of using the above WATM examples with our `water` library, see [tests](https://github.com/erikziyunchi/water-rs/tree/main/tests/tests) for usage.

## Running tests
Expand All @@ -61,4 +61,4 @@ cargo test -p <crate_name> --verbose

# run a single test (or test matching name prefix) in a single crate
cargo test -p <crate_name> --verbose -- <test_name>
```
```
3 changes: 0 additions & 3 deletions crates/wasm/README.md

This file was deleted.

14 changes: 10 additions & 4 deletions crates/wasm/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
//! This module contains the default config struct for the WATM module
//!
//! The config should be read from a .json file by the WATM module and setup the
//! corresponding connection addresses and ports

use super::*;

// A Config currently contains the local + remote ip & port
/// A Config currently contains the local + remote ip & port + bypass flag
#[derive(Debug, Deserialize, Clone)]
pub struct Config {
pub remote_address: String,
Expand All @@ -16,7 +21,7 @@ impl Default for Config {
}
}

// implement a constructor for the config
/// implement a constructor for the config
impl Config {
pub fn new() -> Self {
Config {
Expand All @@ -29,8 +34,9 @@ impl Config {
}
}

// ============ Some implementation for V1 ============
// A config struct that shares between your host & wasm to establish a connection
// ============ Below are some implementations for V1 ============

/// A config struct that shares between your host & wasm to establish a connection
// #[cfg(feature = "v1")]
#[derive(Serialize, Deserialize)]
pub struct StreamConfigV1 {
Expand Down
36 changes: 18 additions & 18 deletions crates/wasm/src/connections.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
//! This module contains the Connection struct, which is the main struct for a connection
//! that contains the inbound and outbound streams and the config for the connection in the WATM module.
//!
//! The config is a generic type that can be defined / replaced by the WATM module where it decouples
//! the configuration of WATM module from the Host program, where if there is a config diff,
//! we don't need to recompile the Host program to achieve our fast deloyment goal.
//!
//!
//! The module also contains the ConnFile struct, which is the struct for one way of connection -- either for in / outbound
//!

use super::*;

// ConnStream can store either a network stream Or a file stream
Expand All @@ -15,7 +26,7 @@ impl ConnStream {
}
}

// ConnFile is the struct for a connection -- either for in / outbound
/// ConnFile is the struct for a connection -- either for in / outbound
pub struct ConnFile {
pub fd: i32,
pub file: Option<ConnStream>,
Expand All @@ -28,7 +39,7 @@ impl Default for ConnFile {
}

impl ConnFile {
// A default constructor for ConnFile
/// A default constructor for ConnFile
pub fn new() -> Self {
ConnFile { fd: -1, file: None }
}
Expand Down Expand Up @@ -62,7 +73,7 @@ impl ConnFile {
}
}

// A Connection normally contains both in & outbound streams + a config
/// A Connection normally contains both in & outbound streams + a generic config
pub struct Connection<T> {
pub inbound_conn: ConnFile,
pub outbound_conn: ConnFile,
Expand All @@ -81,7 +92,7 @@ impl<T: Default> Default for Connection<T> {
}

impl<T> Connection<T> {
// A default constructor
/// A constructor that takes in the customized config
pub fn new(config: T) -> Self {
Connection {
inbound_conn: ConnFile::new(),
Expand All @@ -90,6 +101,7 @@ impl<T> Connection<T> {
}
}

/// Setting the inbound connection for the WATM module, which is talking to the Host
pub fn set_inbound(&mut self, fd: i32, stream: ConnStream) {
if fd < 0 {
eprintln!("[WASM] > ERROR: fd is negative");
Expand All @@ -105,6 +117,7 @@ impl<T> Connection<T> {
self.inbound_conn.file = Some(stream);
}

/// Setting the outbound connection for the WATM module, which is talking to the remote
pub fn set_outbound(&mut self, fd: i32, stream: ConnStream) {
if fd < 0 {
eprintln!("[WASM] > ERROR: fd is negative");
Expand All @@ -120,20 +133,6 @@ impl<T> Connection<T> {
self.outbound_conn.file = Some(stream);
}

// pub fn decoder_read_from_outbound<D: AsyncDecodeReader>(&mut self, decoder: &mut D, buf: &mut [u8]) -> Result<i64, anyhow::Error> {
// debug!("[WASM] running in decoder_read_from_outbound");

// // match self.outbound_conn.file.as_mut().unwrap() {
// // ConnStream::TcpStream(stream) => {
// // decoder.read_decrypted(stream);
// // },
// // ConnStream::File(stream) => {
// // decoder.read_decrypted(stream);
// // },
// // }
// Ok(decoder.poll_read_decrypted(self.outbound_conn.file.as_mut().unwrap().as_read(), buf)? as i64)
// }

/// this _read function is triggered by the Host to read from the remote connection
pub fn _read_from_outbound<D: Decoder>(
&mut self,
Expand Down Expand Up @@ -186,6 +185,7 @@ impl<T> Connection<T> {
Ok(len_after_decoding as i64)
}

/// this _write function is triggered by the Host to write to the remote connection
pub fn _write_2_outbound<E: Encoder>(
&mut self,
encoder: &mut E,
Expand Down
8 changes: 4 additions & 4 deletions crates/wasm/src/decoder.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
//! Logic for unpackaging trait

use super::*;

use tokio::io::AsyncRead;

// Developer Guide: Logic for packaging

// A trait for a decoder, developers should implement this trait and pass it to _read_from_outbound
/// A trait for a decoder, developers should implement this trait and pass it to _read_from_outbound
pub trait Decoder {
fn decode(&self, input: &[u8], output: &mut [u8]) -> Result<u32, anyhow::Error>;
}

// A default decoder that does just copy + paste
/// A default decoder that does just copy + paste
pub struct DefaultDecoder;

impl Decoder for DefaultDecoder {
Expand Down
8 changes: 8 additions & 0 deletions crates/wasm/src/dialer.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
//! This module is responsible for v1's dialing to remote server.
//!
//! It will create a TCP connection to the remote server by calling the
//! Host exported helper function `connect_tcp`, and receives a file descriptor
//! for the connection.
//!
//! Developers can use this lib to create a TCP connection to the remote server (ip:port from config).

use super::*;

use anyhow::{anyhow, Ok};
Expand Down
8 changes: 4 additions & 4 deletions crates/wasm/src/encoder.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
//! Logic for packaging trait

use super::*;

use tokio::io::AsyncWrite;

// Developer Guide: Logic for packaging

// A trait for a encoder, developers should implement this trait and pass it to _write_to_outbound
/// A trait for a encoder, developers should implement this trait and pass it to _write_to_outbound
pub trait Encoder {
fn encode(&self, input: &[u8], output: &mut [u8]) -> Result<u32, anyhow::Error>;
}

// A default encoder that does just copy + paste
/// A default encoder that does just copy + paste
pub struct DefaultEncoder;

impl Encoder for DefaultEncoder {
Expand Down
13 changes: 9 additions & 4 deletions crates/wasm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// lib.rs
// export all modules
//! This lib is for a demo and ease of developing the WATM module

pub mod config;
pub mod connections;
pub mod decoder;
Expand Down Expand Up @@ -34,10 +34,15 @@ use tracing::{debug, info};
use anyhow::Result;
use serde::{Deserialize, Serialize};

// TODO: move these to speicific implementations, shouldn't be in the crate lib
// =================== WASM Imports =====================
extern "C" {
// #[link_name = "create-listen"]
/// These functions are exported from the host to the WATM module,
/// which means host must provide these functions to the WATM module.
///
/// create a listener (specified by returned fd) -- pass ptr + size for the ip:port struct sharing to Host
// #[link_name = "create_listen"]
pub fn create_listen(ptr: u32, size: u32) -> i32;

/// create a TcpStream connection (specified by returned fd) -- pass ptr + size for the ip:port struct sharing to Host
pub fn connect_tcp(ptr: u32, size: u32) -> i32;
}
5 changes: 0 additions & 5 deletions crates/wasm/src/listener.rs

This file was deleted.

3 changes: 0 additions & 3 deletions crates/wasm/src/v1/README.md

This file was deleted.

Loading
Loading