Skip to content

Commit

Permalink
remove tungstenite since tokio-tungstenite exists
Browse files Browse the repository at this point in the history
  • Loading branch information
ssrlive committed Sep 17, 2024
1 parent 78cb57a commit 1ad2cc5
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 19 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
18 changes: 10 additions & 8 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<F>(config: &Config, quit: crate::CancellationToken, callback: Option<F>) -> Result<()>
Expand Down Expand Up @@ -274,7 +276,7 @@ pub(crate) async fn create_ws_stream<S: AsyncRead + AsyncWrite + Unpin>(
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"));
Expand Down
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
13 changes: 8 additions & 5 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions src/udprelay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)>;
Expand Down
2 changes: 1 addition & 1 deletion src/weirduri.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use tungstenite::{
use tokio_tungstenite::tungstenite::{
client::IntoClientRequest,
error::{Error, Result, UrlError},
handshake::client::{generate_key, Request},
Expand Down

0 comments on commit 1ad2cc5

Please sign in to comment.