From 6e3f968f9c1ae47a11e4d92b6aac4ada4aff910e Mon Sep 17 00:00:00 2001 From: Toshit Chawda Date: Sun, 14 Jan 2024 22:05:02 -0800 Subject: [PATCH] rename wstcp -> epoxy --- Cargo.lock | 88 +++++++++++++++++++-------------------- README.md | 4 +- client/Cargo.toml | 2 +- client/build.sh | 15 ++++--- client/src/lib.rs | 2 +- client/src/web/index.html | 6 +-- client/src/web/index.js | 14 +++---- client/src/websocket.rs | 9 ++-- server/Cargo.toml | 2 +- 9 files changed, 72 insertions(+), 70 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e0f98c3..4f61515 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -236,6 +236,50 @@ version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" +[[package]] +name = "epoxy-client" +version = "1.0.0" +dependencies = [ + "async-compression", + "base64", + "bytes", + "console_error_panic_hook", + "either", + "fastwebsockets", + "futures-util", + "getrandom", + "http 1.0.0", + "http-body-util", + "hyper", + "js-sys", + "penguin-mux-wasm", + "pin-project-lite", + "rand", + "ring", + "tokio", + "tokio-rustls", + "tokio-util", + "wasm-bindgen", + "wasm-bindgen-futures", + "wasm-streams", + "web-sys", + "webpki-roots", + "ws_stream_wasm", +] + +[[package]] +name = "epoxy-server" +version = "1.0.0" +dependencies = [ + "http-body-util", + "hyper", + "hyper-util", + "rusty-penguin", + "tokio", + "tokio-native-tls", + "tokio-tungstenite", +] + [[package]] name = "errno" version = "0.3.8" @@ -1544,50 +1588,6 @@ dependencies = [ "web-sys", ] -[[package]] -name = "wstcp-client" -version = "1.0.0" -dependencies = [ - "async-compression", - "base64", - "bytes", - "console_error_panic_hook", - "either", - "fastwebsockets", - "futures-util", - "getrandom", - "http 1.0.0", - "http-body-util", - "hyper", - "js-sys", - "penguin-mux-wasm", - "pin-project-lite", - "rand", - "ring", - "tokio", - "tokio-rustls", - "tokio-util", - "wasm-bindgen", - "wasm-bindgen-futures", - "wasm-streams", - "web-sys", - "webpki-roots", - "ws_stream_wasm", -] - -[[package]] -name = "wstcp-server" -version = "1.0.0" -dependencies = [ - "http-body-util", - "hyper", - "hyper-util", - "rusty-penguin", - "tokio", - "tokio-native-tls", - "tokio-tungstenite", -] - [[package]] name = "zeroize" version = "1.7.0" diff --git a/README.md b/README.md index 1a735bd..3296ec5 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ -# wsproxy-rust +# epoxy ## Building ### Server 1. Generate certs with `mkcert` and place the public certificate in `./server/src/pem.pem` and private certificate in `./server/src/key.pem` -2. Run `cargo r --bin wstcp-server`, optionally with `-r` flag for release +2. Run `cargo r --bin epoxy-server`, optionally with `-r` flag for release ### Client diff --git a/client/Cargo.toml b/client/Cargo.toml index 55f64ff..376cbc8 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "wstcp-client" +name = "epoxy-client" version = "1.0.0" edition = "2021" diff --git a/client/build.sh b/client/build.sh index 03c053b..3f7a42a 100755 --- a/client/build.sh +++ b/client/build.sh @@ -7,16 +7,19 @@ mkdir out/ cargo build --target wasm32-unknown-unknown --release echo "[ws] built rust" -wasm-bindgen --weak-refs --no-typescript --target no-modules --out-dir out/ ../target/wasm32-unknown-unknown/release/wstcp_client.wasm +wasm-bindgen --weak-refs --no-typescript --target no-modules --out-dir out/ ../target/wasm32-unknown-unknown/release/epoxy_client.wasm echo "[ws] bindgen finished" -mv out/wstcp_client_bg.wasm out/wstcp_client_unoptimized.wasm -time wasm-opt -O4 out/wstcp_client_unoptimized.wasm -o out/wstcp_client_bg.wasm +mv out/epoxy_client_bg.wasm out/epoxy_client_unoptimized.wasm +time wasm-opt -O4 out/epoxy_client_unoptimized.wasm -o out/epoxy_client_bg.wasm echo "[ws] optimized" -AUTOGENERATED_SOURCE=$(<"out/wstcp_client.js") -WASM_BASE64=$(base64 -w0 out/wstcp_client_bg.wasm) -echo "${AUTOGENERATED_SOURCE//__wbg_init(input) \{/__wbg_init(input) \{input=\'data:application/wasm;base64,$WASM_BASE64\'}" > out/wstcp_client_bundled.js +AUTOGENERATED_SOURCE=$(<"out/epoxy_client.js") +WASM_BASE64=$(base64 -w0 out/epoxy_client_bg.wasm) +AUTOGENERATED_SOURCE="${AUTOGENERATED_SOURCE//__wbg_init(input) \{/__wbg_init(input) \{input=\'data:application/wasm;base64,$WASM_BASE64\'}" +AUTOGENERATED_SOURCE="${AUTOGENERATED_SOURCE//let wasm_bindgen/let epoxy}" +AUTOGENERATED_SOURCE="${AUTOGENERATED_SOURCE//wasm_bindgen =/epoxy =}" +echo "${AUTOGENERATED_SOURCE}" > out/epoxy_client_bundled.js cp -r src/web/* out/ echo "[ws] done!" diff --git a/client/src/lib.rs b/client/src/lib.rs index 74248d7..89a4554 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -58,7 +58,7 @@ async fn send_req( wasm_bindgen_futures::spawn_local(async move { if let Err(e) = conn.await { - error!("wstcp: error in muxed hyper connection! {:?}", e); + error!("epoxy: error in muxed hyper connection! {:?}", e); } }); diff --git a/client/src/web/index.html b/client/src/web/index.html index defc525..2237f3d 100644 --- a/client/src/web/index.html +++ b/client/src/web/index.html @@ -1,10 +1,10 @@ - wstcp - + epoxy + - running... (wait for the browser alert) + running... (wait for the browser alert if not running ws test) diff --git a/client/src/web/index.js b/client/src/web/index.js index 3744986..292ecd0 100644 --- a/client/src/web/index.js +++ b/client/src/web/index.js @@ -1,18 +1,18 @@ (async () => { console.log( "%cWASM is significantly slower with DevTools open!", - "color:red;font-size:2rem;font-weight:bold" + "color:red;font-size:3rem;font-weight:bold" ); const should_feature_test = (new URL(window.location.href)).searchParams.has("feature_test"); const should_perf_test = (new URL(window.location.href)).searchParams.has("perf_test"); const should_ws_test = (new URL(window.location.href)).searchParams.has("ws_test"); - await wasm_bindgen("./wstcp_client_bg.wasm"); + await epoxy(); const tconn0 = performance.now(); // args: websocket url, user agent, redirect limit - let epoxy = await new wasm_bindgen.EpoxyClient("wss://localhost:4000", navigator.userAgent, 10); + let epoxy_client = await new epoxy.EpoxyClient("wss://localhost:4000", navigator.userAgent, 10); const tconn1 = performance.now(); console.warn(`conn establish took ${tconn1 - tconn0} ms or ${(tconn1 - tconn0) / 1000} s`); @@ -25,14 +25,14 @@ ["https://httpbin.org/redirect/11", {}], ["https://httpbin.org/redirect/1", { redirect: "manual" }] ]) { - let resp = await epoxy.fetch(url[0], url[1]); + let resp = await epoxy_client.fetch(url[0], url[1]); console.warn(url, resp, Object.fromEntries(resp.headers)); console.warn(await resp.text()); } } else if (should_perf_test) { const test_mux = async (url) => { const t0 = performance.now(); - await epoxy.fetch(url); + await epoxy_client.fetch(url); const t1 = performance.now(); return t1 - t0; }; @@ -62,7 +62,7 @@ console.warn(`avg native (10) took ${total_native} ms or ${total_native / 1000} s`); console.warn(`mux - native: ${total_mux - total_native} ms or ${(total_mux - total_native) / 1000} s`); } else if (should_ws_test) { - let ws = await epoxy.connect_ws( + let ws = await epoxy_client.connect_ws( () => console.log("opened"), () => console.log("closed"), err => console.error(err), @@ -73,7 +73,7 @@ ); await ws.send("data"); } else { - let resp = await epoxy.fetch("https://httpbin.org/get"); + let resp = await epoxy_client.fetch("https://httpbin.org/get"); console.warn(resp, Object.fromEntries(resp.headers)); console.warn(await resp.text()); } diff --git a/client/src/websocket.rs b/client/src/websocket.rs index b06dd7c..56161ce 100644 --- a/client/src/websocket.rs +++ b/client/src/websocket.rs @@ -30,7 +30,6 @@ impl EpxWebSocket { Err(jerr!("Use EpoxyClient.connect_ws() instead.")) } - // shut up #[allow(clippy::too_many_arguments)] pub async fn connect( @@ -75,7 +74,7 @@ impl EpxWebSocket { wasm_bindgen_futures::spawn_local(async move { if let Err(e) = conn.with_upgrades().await { - error!("wstcp: error in muxed hyper connection (ws)! {:?}", e); + error!("epoxy: error in muxed hyper connection (ws)! {:?}", e); } }); @@ -176,7 +175,7 @@ impl EpxWebSocket { // https://github.com/snapview/tungstenite-rs/blob/314feea3055a93e585882fb769854a912a7e6dae/src/handshake/client.rs#L189 fn verify(response: &Response) -> Result<(), JsError> { if response.status() != StatusCode::SWITCHING_PROTOCOLS { - return Err(jerr!("wstcpws connect: Invalid status code")); + return Err(jerr!("epoxy ws connect: Invalid status code")); } let headers = response.headers(); @@ -187,7 +186,7 @@ fn verify(response: &Response) -> Result<(), JsError> { .map(|h| h.eq_ignore_ascii_case("websocket")) .unwrap_or(false) { - return Err(jerr!("wstcpws connect: Invalid upgrade header")); + return Err(jerr!("epoxy ws connect: Invalid upgrade header")); } if !headers @@ -196,7 +195,7 @@ fn verify(response: &Response) -> Result<(), JsError> { .map(|h| h.eq_ignore_ascii_case("Upgrade")) .unwrap_or(false) { - return Err(jerr!("wstcpws connect: Invalid upgrade header")); + return Err(jerr!("epoxy ws connect: Invalid upgrade header")); } Ok(()) diff --git a/server/Cargo.toml b/server/Cargo.toml index a1f7d0a..6abb7ca 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "wstcp-server" +name = "epoxy-server" version = "1.0.0" edition = "2021"