mirror of
https://github.com/MercuryWorkshop/epoxy-tls.git
synced 2025-05-13 06:20:02 -04:00
use blazingly fast flume channels 🚀
This commit is contained in:
parent
5af56fe582
commit
5e741d3808
11 changed files with 225 additions and 135 deletions
|
@ -238,9 +238,9 @@ onmessage = async (msg) => {
|
|||
log(`total avg mux (${num_outer_tests} tests of ${num_inner_tests} reqs): ${total_mux_multi} ms or ${total_mux_multi / 1000} s`);
|
||||
|
||||
} else {
|
||||
let resp = await epoxy_client.fetch("https://httpbin.org/get");
|
||||
let resp = await epoxy_client.fetch("https://www.example.com/");
|
||||
console.log(resp, Object.fromEntries(resp.headers));
|
||||
plog(await resp.json());
|
||||
log(await resp.text());
|
||||
}
|
||||
log("done");
|
||||
};
|
||||
|
|
|
@ -200,13 +200,10 @@ pub async fn make_mux(
|
|||
),
|
||||
WispError,
|
||||
> {
|
||||
let (wtx, wrx) = WebSocketWrapper::connect(url, vec![])
|
||||
.await
|
||||
.map_err(|_| WispError::WsImplSocketClosed)?;
|
||||
let (wtx, wrx) =
|
||||
WebSocketWrapper::connect(url, vec![]).map_err(|_| WispError::WsImplSocketClosed)?;
|
||||
wtx.wait_for_open().await;
|
||||
let mux = ClientMux::new(wrx, wtx, Some(&[Box::new(UdpProtocolExtensionBuilder())])).await?;
|
||||
|
||||
Ok(mux)
|
||||
ClientMux::new(wrx, wtx, Some(&[Box::new(UdpProtocolExtensionBuilder())])).await
|
||||
}
|
||||
|
||||
pub fn spawn_mux_fut(
|
||||
|
@ -215,6 +212,7 @@ pub fn spawn_mux_fut(
|
|||
url: String,
|
||||
) {
|
||||
wasm_bindgen_futures::spawn_local(async move {
|
||||
debug!("epoxy: mux future started");
|
||||
if let Err(e) = fut.await {
|
||||
log!("epoxy: error in mux future, restarting: {:?}", e);
|
||||
while let Err(e) = replace_mux(mux.clone(), &url).await {
|
||||
|
@ -229,7 +227,7 @@ pub fn spawn_mux_fut(
|
|||
pub async fn replace_mux(mux: Arc<RwLock<ClientMux>>, url: &str) -> Result<(), WispError> {
|
||||
let (mux_replace, fut) = make_mux(url).await?;
|
||||
let mut mux_write = mux.write().await;
|
||||
mux_write.close().await?;
|
||||
let _ = mux_write.close().await;
|
||||
*mux_write = mux_replace;
|
||||
drop(mux_write);
|
||||
spawn_mux_fut(mux, fut, url.into());
|
||||
|
|
|
@ -123,6 +123,7 @@ impl tower_service::Service<hyper::Uri> for TlsWispService {
|
|||
let stream = service.call(uri_parsed).await?.into_inner();
|
||||
if utils::get_is_secure(&req).map_err(|_| WispError::InvalidUri)? {
|
||||
let connector = TlsConnector::from(rustls_config);
|
||||
log!("got stream");
|
||||
Ok(TokioIo::new(Either::Left(
|
||||
connector
|
||||
.connect(
|
||||
|
@ -143,6 +144,7 @@ impl tower_service::Service<hyper::Uri> for TlsWispService {
|
|||
pub enum WebSocketError {
|
||||
Unknown,
|
||||
SendFailed,
|
||||
CloseFailed,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for WebSocketError {
|
||||
|
@ -151,6 +153,7 @@ impl std::fmt::Display for WebSocketError {
|
|||
match self {
|
||||
Unknown => write!(f, "Unknown error"),
|
||||
SendFailed => write!(f, "Send failed"),
|
||||
CloseFailed => write!(f, "Close failed"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -213,7 +216,7 @@ impl WebSocketRead for WebSocketReader {
|
|||
}
|
||||
|
||||
impl WebSocketWrapper {
|
||||
pub async fn connect(
|
||||
pub fn connect(
|
||||
url: &str,
|
||||
protocols: Vec<String>,
|
||||
) -> Result<(Self, WebSocketReader), JsValue> {
|
||||
|
@ -327,6 +330,12 @@ impl WebSocketWrite for WebSocketWrapper {
|
|||
_ => Err(WispError::WsImplNotSupported),
|
||||
}
|
||||
}
|
||||
|
||||
async fn wisp_close(&mut self) -> Result<(), WispError> {
|
||||
self.inner
|
||||
.close()
|
||||
.map_err(|_| WebSocketError::CloseFailed.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for WebSocketWrapper {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue