From 1ad2cc516b7ea2c95ddb3a7d36489b0a3d391034 Mon Sep 17 00:00:00 2001 From: ssrlive <30760636+ssrlive@users.noreply.github.com> Date: Sat, 14 Sep 2024 17:11:35 +0800 Subject: [PATCH] remove tungstenite since tokio-tungstenite exists --- Cargo.toml | 3 +-- src/client.rs | 18 ++++++++++-------- src/error.rs | 2 +- src/server.rs | 13 ++++++++----- src/udprelay.rs | 3 +-- src/weirduri.rs | 2 +- 6 files changed, 22 insertions(+), 19 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7581113..b8ce82a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,9 +51,8 @@ tokio-rustls = { version = "0.26", default-features = false, features = [ "tls12", "ring", ] } -tokio-tungstenite = { version = "0.23", features = ["rustls-tls-webpki-roots"] } +tokio-tungstenite = { version = "0.24", features = ["rustls-tls-webpki-roots"] } tokio-util = "0.7" -tungstenite = { version = "0.23", features = ["rustls-tls-webpki-roots"] } url = "2" webpki = { package = "rustls-webpki", version = "0.102", features = [ "alloc", diff --git a/src/client.rs b/src/client.rs index e1d9e88..ae5bcdd 100644 --- a/src/client.rs +++ b/src/client.rs @@ -22,14 +22,16 @@ use tokio::{ net::TcpStream, }; use tokio_rustls::client::TlsStream; -use tokio_tungstenite::WebSocketStream; -use tungstenite::{ - client::IntoClientRequest, - handshake::{ - client::{self, Response}, - machine::TryParse, +use tokio_tungstenite::{ + tungstenite::{ + client::IntoClientRequest, + handshake::{ + client::{self, Response}, + machine::TryParse, + }, + protocol::{Message, Role}, }, - protocol::{Message, Role}, + WebSocketStream, }; pub async fn run_client(config: &Config, quit: crate::CancellationToken, callback: Option) -> Result<()> @@ -274,7 +276,7 @@ pub(crate) async fn create_ws_stream( let response = Response::try_parse(&buf)?.ok_or("response parse failed")?.1; let remote_key = response.headers().get("Sec-WebSocket-Accept").ok_or(format!("{:?}", response))?; - let accept_key = tungstenite::handshake::derive_accept_key(key.as_bytes()); + let accept_key = tokio_tungstenite::tungstenite::handshake::derive_accept_key(key.as_bytes()); if accept_key.as_str() != remote_key.to_str().map_err(|e| e.to_string())? { return Err(Error::from("accept key error")); diff --git a/src/error.rs b/src/error.rs index 64ccf5c..17ad4fe 100644 --- a/src/error.rs +++ b/src/error.rs @@ -28,7 +28,7 @@ pub enum Error { HeaderToStr(#[from] http::header::ToStrError), #[error("tungstenite::error::Error {0}")] - Tungstenite(#[from] tungstenite::error::Error), + Tungstenite(#[from] tokio_tungstenite::tungstenite::error::Error), #[error("reqwest::Error {0}")] Reqwest(#[from] reqwest::Error), diff --git a/src/server.rs b/src/server.rs index d7a502b..43ac8d5 100644 --- a/src/server.rs +++ b/src/server.rs @@ -20,11 +20,14 @@ use tokio::{ sync::Mutex, }; use tokio_rustls::{rustls, TlsAcceptor}; -use tokio_tungstenite::{accept_hdr_async, WebSocketStream}; -use tungstenite::{ - handshake::server::{create_response, ErrorResponse, Request, Response}, - handshake::{machine::TryParse, server}, - protocol::{Message, Role}, +use tokio_tungstenite::{ + accept_hdr_async, + tungstenite::{ + handshake::server::{create_response, ErrorResponse, Request, Response}, + handshake::{machine::TryParse, server}, + protocol::{Message, Role}, + }, + WebSocketStream, }; const WS_HANDSHAKE_LEN: usize = 1024; diff --git a/src/udprelay.rs b/src/udprelay.rs index f54a75b..4bb80ca 100644 --- a/src/udprelay.rs +++ b/src/udprelay.rs @@ -21,8 +21,7 @@ use tokio::{ sync::{broadcast, mpsc, Mutex}, time, }; -use tokio_tungstenite::WebSocketStream; -use tungstenite::protocol::Message; +use tokio_tungstenite::{tungstenite::protocol::Message, WebSocketStream}; pub(crate) type UdpRequestReceiver = broadcast::Receiver<(Bytes, Address, Address)>; pub(crate) type UdpRequestSender = broadcast::Sender<(Bytes, Address, Address)>; diff --git a/src/weirduri.rs b/src/weirduri.rs index f5b48c1..73c9dc5 100644 --- a/src/weirduri.rs +++ b/src/weirduri.rs @@ -1,4 +1,4 @@ -use tungstenite::{ +use tokio_tungstenite::tungstenite::{ client::IntoClientRequest, error::{Error, Result, UrlError}, handshake::client::{generate_key, Request},