Skip to content

Commit

Permalink
update: more & better READMEs
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Chi committed Oct 30, 2023
1 parent bbe6daf commit b54ca07
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 47 deletions.
55 changes: 10 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,16 @@
# W.A.T.E.R.: WebAssembly Transport Executable Reactor -- Rust
# W.A.T.E.R.: WebAssembly Transport Executable Runtime
[![License](https://img.shields.io/badge/License-Apache_2.0-yellowgreen.svg)](https://opensource.org/licenses/Apache-2.0) [![Build Status](https://github.com/erikziyunchi/WASMable-Transport/actions/workflows/rust.yml/badge.svg?branch=main)](https://github.com/erikziyunchi/WASMable-Transport/actions/workflows/rust.yml)

WASMable Transport: Yet another more Pluggable Pluggable Transport
> Here is the [repo](https://github.com/erikziyunchi/wasm_proxy) contains all the PoC examples, and this framework is the conprehensive result after all the research.
> Here is the [repo](https://github.com/erikziyunchi/wasm_proxy) contains all the other WASM PoC examples has explored, and this library is the conprehensive result after all the research.
The repo will contain 2 parts of purposes:
1. A cli tool where can directly load a `.wasm` binary proxy and run it (with our WASM development guidence).
2. A library can be used directly to integrate / coporate `.wasm` binary proxy.

## Designs

### What is needed for the library / cli
#### The Host side:
**Config**: calls main program / some library entry func -> use claps to get args (making use of some `Args` struct) -> then convert it to a `WATERConfig` struct.

**execute**:
1. wasmtime runtime creation
2. Setup env:
1. memory initialiation & limitation
2. (optional for now) wasm_config sharing to WASM
3. export helper functions (e.g. creation of TCP, TLS, crypto, etc)
3. (optional) setup multi-threading
4. Run the `entry_fn`

#### The WASM side:
1. get version
2. load config_wasm
3. start netwroking with imported funcions from Host

## How to run?
To run the Host program + WASM:
```shell
cargo run --bin wasmable_transport -- --wasm-path <./proxy.wasm> --entry-fn <main> --config-wasm <conf.json>
```

Then you can netcat into the connection, for now, I included a `proxy.wasm` as a multiple conneciton echo server, test with several terminals:
```shell
nc 127.0.0.1 9005
```
you should see `> CONNECTED` in the terminal of running WASM, then you can connect a bunch like this and input anything to see how it echos.
The repo contains 2 main parts for the library:
1. A Rust crate [`water`](https://github.com/erikziyunchi/water-rs/tree/main/crates/water) for Host-development where developers can use to interact with their `.wasm` binary
2. A Rust crate [`water-wasm-crate`](https://github.com/erikziyunchi/water-rs/tree/main/crates/wasm) for WATM-development where developers can make their own `.wasm` binary easier.

Also include examples for demonstration of usage:
1. A cli tool where can directly load a `.wasm` binary and run it, see [here](https://github.com/erikziyunchi/water-rs/tree/main/examples/clients/cli).
2. Some WATM examples implemented using our `water-wasm-crate`, see [here](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 @@ -52,10 +23,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>
```

## TODOs
- [ ] wasm_config sharing implementation
- [ ] Generalize Host export TCP listener helper function
- [ ] Host export TCP connect helper function
- [ ] Host export TLS helper function (with decoupled connection & packaging)
```
3 changes: 3 additions & 0 deletions crates/wasm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# WATM development Library -- `water-wasm-crate`

A library for eaiser development of WATM modules, satisfies APIs [here](https://app.gitbook.com/o/KHlQypYtIQKkb8YeZ6Hx/s/lVX5MqollomuX6vW80T6/wasm-and-wasi-apis).
13 changes: 13 additions & 0 deletions crates/water/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Host Library -- `water`

A library for integrating WATER, satisfies APIs [here](https://app.gitbook.com/o/KHlQypYtIQKkb8YeZ6Hx/s/lVX5MqollomuX6vW80T6/rust-apis).

## Designs
**execute**:
1. wasmtime runtime creation
2. Setup env:
1. memory initialiation & limitation
2. (`v1_preview` feature) wasm_config sharing to WASM
3. export helper functions (e.g. creation of TCP, TLS, crypto, etc)
3. (`v1` feature) setup multi-threading
4. Run the `entry_fn` or execute as the Role (`Dial`, `Listen`, `Relay`)
4 changes: 4 additions & 0 deletions examples/clients/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ description.workspace = true
edition.workspace = true
publish = false

[[bin]]
name = "water_cli"
path = "src/main.rs"

[dependencies]
# rand = "0.8"
# pprof = { version = "0.11.1", features = ["flamegraph", "protobuf-codec", "prost-codec"] }
Expand Down
15 changes: 15 additions & 0 deletions examples/clients/cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# cli tool for using `water` library

🚧 Currently under reimplementation 🚧

## How to run?
To run the Host program + WASM:
```shell
cargo run --bin wasmable_transport -- --wasm-path <./proxy.wasm> --entry-fn <main> --config-wasm <conf.json>
```

Then you can netcat into the connection, for now, I included a `proxy.wasm` as a multiple conneciton echo server, test with several terminals:
```shell
nc 127.0.0.1 9005
```
you should see `> CONNECTED` in the terminal of running WASM, then you can connect a bunch like this and input anything to see how it echos.
5 changes: 5 additions & 0 deletions examples/water_bins/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# WATM Examples

This folder is for all the WATM examples that developed using the [WATM library crate](https://github.com/erikziyunchi/water-rs/tree/main/crates/wasm), and runnable with the [WATER library engine](https://github.com/erikziyunchi/water-rs/tree/main/crates/water).

One can find details of these in each examples' README.
26 changes: 26 additions & 0 deletions examples/water_bins/echo_client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# WATM as worker implementation of an echo client

It uses the `water-wasm-crate` library and is able to run as a `Dialer` or `Listener` Role. It is currently implemented with `v1_preview` where it has the capability of managing connections inside it (tell the Host which `address:port` it `dial()` to / `listen()` on).

## How to run?
You can also find a full runnable test for this example with using our water-host library [here](https://github.com/erikziyunchi/water-rs/blob/main/tests/tests/echo_tests.rs).

You can config it as the following:
```json
{
"remote_address": "127.0.0.1",
"remote_port": 8080,
"local_address": "127.0.0.1",
"local_port": 8088
}
```

## How to compile?
```shell
cargo build --target wasm32-wasi && mv ../../../target/wasm32-wasi/debug/echo_client.wasm ./echo_client.wasm
```

If you want to optmize the size of the `.wasm` binary:
```shell
wasm-opt --strip-debug ./echo_client.wasm -o ./echo_client.wasm
```
Binary file not shown.
16 changes: 14 additions & 2 deletions examples/water_bins/ss_client_wasm_v1/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# WASM as manager implementation of ShadowSocks-Client
# WATM as manager implementation of ShadowSocks-Client

It uses the `wasm-water-crate` library and manages the whole flow of the ShadowSocks Client, to test it for now, you need to also deploy the ShadowSocks's [native server](https://github.com/shadowsocks/shadowsocks-rust) with the same configuration using here.
It uses the `water-wasm-crate` library and manages the whole flow of the ShadowSocks Client as an example(ported from [ShadowSocks' official Rust implementation](https://github.com/shadowsocks/shadowsocks-rust)) of porting existing proxy protocol implementations, to test it for now, you need to also deploy the ShadowSocks's [native server](https://github.com/shadowsocks/shadowsocks-rust) with the same configuration using here. It is currently implemented with `v1_preview`.

## How to run?
You can also find a full runnable test for this example with using our water-host library [here](https://github.com/erikziyunchi/water-rs/blob/main/tests/tests/ss_testing.rs).

Currently the config we have written into the client is:
```json
Expand All @@ -12,3 +15,12 @@ Currently the config we have written into the client is:
}
```

## How to compile?
```shell
cargo build --target wasm32-wasi && mv ../../../target/wasm32-wasi/debug/ss_client_wasm.wasm ./ss_client_wasm.wasm
```

If you want to optmize the size of the `.wasm` binary:
```shell
wasm-opt --strip-debug ./ss_client_wasm.wasm -o ./ss_client_wasm.wasm
```
Binary file removed examples/water_bins/ss_client_wasm_v1/proxy.wasm
Binary file not shown.

0 comments on commit b54ca07

Please sign in to comment.