some initial websocket mucking about

This commit is contained in:
bunnie 2022-08-25 05:04:37 +08:00
parent 63347f5fbe
commit ea55d23e67
3 changed files with 91 additions and 2 deletions

66
Cargo.lock generated
View file

@ -344,6 +344,12 @@ version = "1.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
[[package]]
name = "bytes"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec8a7b6a70fde80372154c65702f00a0f56f3e1c36abbc6c440484be248856db"
[[package]]
name = "bzip2"
version = "0.4.3"
@ -1744,6 +1750,23 @@ dependencies = [
"digest 0.10.3",
]
[[package]]
name = "http"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75f43d41e26995c17e71ee126451dd3941010b0514a81a9d11f3b341debc2399"
dependencies = [
"bytes",
"fnv",
"itoa 1.0.2",
]
[[package]]
name = "httparse"
version = "1.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "496ce29bb5a52785b44e0f7ca2847ae0bb839c9bd28f69acac9b99d461c0c04c"
[[package]]
name = "humantime"
version = "1.3.0"
@ -3341,6 +3364,17 @@ dependencies = [
"opaque-debug",
]
[[package]]
name = "sha-1"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "028f48d513f9678cda28f6e4064755b3fbb2af6acd672f2c209b62323f7aea0f"
dependencies = [
"cfg-if 1.0.0",
"cpufeatures",
"digest 0.10.3",
]
[[package]]
name = "sha2"
version = "0.9.8"
@ -3432,6 +3466,8 @@ dependencies = [
"tracking-allocator",
"trng",
"tts-frontend",
"tungstenite",
"url",
"usb-device-xous",
"utralib",
"webpki-roots",
@ -3954,6 +3990,28 @@ dependencies = [
"xous-tts-backend",
]
[[package]]
name = "tungstenite"
version = "0.17.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e27992fd6a8c29ee7eef28fc78349aa244134e10ad447ce3b9f0ac0ed0fa4ce0"
dependencies = [
"base64",
"byteorder",
"bytes",
"http",
"httparse",
"log",
"rand 0.8.5",
"rustls",
"sha-1 0.10.0",
"thiserror",
"url",
"utf-8",
"webpki",
"webpki-roots",
]
[[package]]
name = "typenum"
version = "1.15.0"
@ -4141,6 +4199,12 @@ dependencies = [
"usb-device",
]
[[package]]
name = "utf-8"
version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9"
[[package]]
name = "utralib"
version = "0.1.0"
@ -4187,7 +4251,7 @@ dependencies = [
"rand_core 0.6.3",
"random-pick",
"rkyv",
"sha-1",
"sha-1 0.9.8",
"sha2",
"sntpc",
"subtle",

View file

@ -77,6 +77,8 @@ rustls = {version = "0.20.6", optional = true}
# rustls = {path="../../../rustls/rustls"}
webpki-roots = {version = "0.22.4", optional = true}
ring = {version = "0.16.20", optional = true} # for testing ring math functions
tungstenite = {version = "0.17.3", optional = true, features = ["rustls-tls-webpki-roots"]}
url = {version = "2.2.2", optional = true}
# for the curve25519 tests
# hardware acceleration adaptations are inserted into a fork of the main branch.
@ -115,5 +117,5 @@ tracking-alloc = ["tracking-allocator", "tracing", "tracing-subscriber"]
dbg-ecupdate = [] # for issuing manual commands to initiate an EC update (vs UX). Also need to enable this feature in the status crate. Intended for debug only.
test-rekey = []
nettest = [] # batch network tests
tls = ["rustls", "webpki-roots", "ring"]
tls = ["rustls", "webpki-roots", "ring", "tungstenite", "url"]
default = ["tls"] # "debugprint"

View file

@ -393,6 +393,29 @@ impl<'a> ShellCmdApi<'a> for NetCmd {
log::set_max_level(log::LevelFilter::Info);
}
#[cfg(feature="tls")]
"ws" => {
let (mut socket, response) =
tungstenite::connect(url::Url::parse("wss://socket.io").unwrap()).expect("Can't connect");
log::info!("Connected to the server");
log::info!("Response HTTP code: {}", response.status());
log::info!("Response contains the following headers:");
for (ref header, _value) in response.headers() {
log::info!("* {}", header);
}
if let Some(msg) = tokens.next() {
socket.write_message(tungstenite::Message::Text(msg.into())).unwrap();
} else {
socket.write_message(tungstenite::Message::Text("Hello WebSocket".into())).unwrap();
}
loop {
let msg = socket.read_message().expect("Error reading message");
log::info!("Received: {}", msg);
}
socket.close(None);
}
#[cfg(feature="tls")]
"tls" => {
log::set_max_level(log::LevelFilter::Info);
log::info!("starting TLS run");