mirror of
https://github.com/MercuryWorkshop/epoxy-tls.git
synced 2025-05-12 14:00:01 -04:00
rename wstcp -> epoxy
This commit is contained in:
parent
f035e51256
commit
6e3f968f9c
9 changed files with 72 additions and 70 deletions
88
Cargo.lock
generated
88
Cargo.lock
generated
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
[package]
|
||||
name = "wstcp-client"
|
||||
name = "epoxy-client"
|
||||
version = "1.0.0"
|
||||
edition = "2021"
|
||||
|
||||
|
|
|
@ -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!"
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>wstcp</title>
|
||||
<script src="wstcp_client.js"></script>
|
||||
<title>epoxy</title>
|
||||
<script src="epoxy_client_bundled.js"></script>
|
||||
<script src="index.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
running... (wait for the browser alert)
|
||||
running... (wait for the browser alert if not running ws test)
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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<Incoming>) -> 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<Incoming>) -> 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<Incoming>) -> 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(())
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
[package]
|
||||
name = "wstcp-server"
|
||||
name = "epoxy-server"
|
||||
version = "1.0.0"
|
||||
edition = "2021"
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue