mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
extend shellchat net ws to utilize /lib/tls
This commit is contained in:
parent
bcb6a8c3bf
commit
de6b6baab9
3 changed files with 39 additions and 14 deletions
|
|
@ -227,8 +227,8 @@ impl Tls {
|
|||
let archive =
|
||||
unsafe { rkyv::archived_value::<RustlsOwnedTrustAnchor>(&bytes, pos) };
|
||||
let ta = archive.deserialize(&mut AllocDeserializer {}).ok();
|
||||
log::info!("get {}", key);
|
||||
log::trace!("get '{}' = '{:?}'", key, &ta);
|
||||
log::info!("get trust anchor {}", key);
|
||||
log::trace!("get trust anchor'{}' = '{:?}'", key, &ta);
|
||||
ta
|
||||
}
|
||||
Err(e) => {
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ url = {version = "2.2.2", optional = true}
|
|||
ring = {version = "0.16.20", optional = true}
|
||||
|
||||
# for websocket testing
|
||||
tungstenite = {version = "0.20.0", optional = true, features = ["rustls-tls-webpki-roots"]}
|
||||
tungstenite = {version = "0.20.0", optional = true}
|
||||
|
||||
# for performance testing
|
||||
perflib = {path="../../tools/perflib", optional = true}
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@ use crate::{CommonEnv, ShellCmdApi};
|
|||
use com::api::NET_MTU;
|
||||
use net::NetPingCallback;
|
||||
use num_traits::*;
|
||||
use std::io::Read;
|
||||
use std::io::Write;
|
||||
use std::io::{Read, Write};
|
||||
use std::net::{IpAddr, TcpListener, TcpStream};
|
||||
use std::sync::mpsc;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::thread;
|
||||
use std::time::{Duration, Instant};
|
||||
use tls::Tls;
|
||||
use xous::MessageEnvelope;
|
||||
use xous_ipc::String;
|
||||
|
||||
|
|
@ -415,16 +415,41 @@ impl<'a> ShellCmdApi<'a> for NetCmd {
|
|||
#[cfg(feature = "websocket")]
|
||||
"ws" => {
|
||||
if self.ws.is_none() {
|
||||
let (socket, response) =
|
||||
tungstenite::connect(url::Url::parse("wss://awake.noskills.club/ws").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);
|
||||
let server = "wss://awake.noskills.club/ws";
|
||||
let url = url::Url::parse(server).expect("Can't parse");
|
||||
log::info!("attempting websocket connection to {}", url.as_str());
|
||||
let host = url.host_str().expect("failed to extract host from url");
|
||||
match TcpStream::connect((host, 443)) {
|
||||
Ok(sock) => {
|
||||
log::info!("tcp connected to {host}");
|
||||
let xtls = Tls::new();
|
||||
match xtls.stream_owned(host, sock) {
|
||||
Ok(tls_stream) => {
|
||||
log::info!("tls configured");
|
||||
match tungstenite::client(url, tls_stream) {
|
||||
Ok((_socket, response)) => {
|
||||
log::info!("Websocket connected to: {}", 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);
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
log::info!("failed to connect websocket: {}", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => log::warn!("failed to configure tls: {e}"),
|
||||
}
|
||||
}
|
||||
Err(e) => log::warn!("failed to connect tcp: {e}"),
|
||||
}
|
||||
self.ws = Some(socket);
|
||||
}
|
||||
let mut err = false;
|
||||
if let Some(socket) = &mut self.ws {
|
||||
|
|
|
|||
Loading…
Reference in a new issue