@@ -11,6 +11,7 @@ use crate::tunnel::connectors::{Socks5TunnelConnector, TcpTunnelConnector, UdpTu
1111use crate :: tunnel:: listeners:: {
1212 new_stdio_listener, new_udp_listener, HttpProxyTunnelListener , Socks5TunnelListener , TcpTunnelListener ,
1313} ;
14+ use crate :: tunnel:: server:: { TlsServerConfig , WsServer , WsServerConfig } ;
1415use crate :: tunnel:: { to_host_port, RemoteAddr , TransportAddr , TransportScheme } ;
1516use base64:: Engine ;
1617use clap:: Parser ;
@@ -20,16 +21,16 @@ use log::debug;
2021use parking_lot:: { Mutex , RwLock } ;
2122use serde:: { Deserialize , Serialize } ;
2223use std:: collections:: BTreeMap ;
23- use std:: fmt:: { Debug , Formatter } ;
24+ use std:: fmt:: Debug ;
25+ use std:: io;
2426use std:: io:: ErrorKind ;
2527use std:: net:: { IpAddr , Ipv4Addr , Ipv6Addr , SocketAddr , SocketAddrV4 , SocketAddrV6 } ;
2628use std:: path:: PathBuf ;
2729use std:: str:: FromStr ;
2830use std:: sync:: Arc ;
2931use std:: time:: Duration ;
30- use std:: { fmt, io} ;
3132use tokio:: select;
32- use tokio_rustls:: rustls:: pki_types:: { CertificateDer , DnsName , PrivateKeyDer } ;
33+ use tokio_rustls:: rustls:: pki_types:: DnsName ;
3334use tracing:: { error, info} ;
3435use tracing_subscriber:: filter:: Directive ;
3536use tracing_subscriber:: EnvFilter ;
@@ -690,49 +691,6 @@ fn parse_server_url(arg: &str) -> Result<Url, io::Error> {
690691 Ok ( url)
691692}
692693
693- #[ derive( Debug ) ]
694- pub struct TlsServerConfig {
695- pub tls_certificate : Mutex < Vec < CertificateDer < ' static > > > ,
696- pub tls_key : Mutex < PrivateKeyDer < ' static > > ,
697- pub tls_client_ca_certificates : Option < Mutex < Vec < CertificateDer < ' static > > > > ,
698- pub tls_certificate_path : Option < PathBuf > ,
699- pub tls_key_path : Option < PathBuf > ,
700- pub tls_client_ca_certs_path : Option < PathBuf > ,
701- }
702-
703- pub struct WsServerConfig {
704- pub socket_so_mark : Option < u32 > ,
705- pub bind : SocketAddr ,
706- pub websocket_ping_frequency : Option < Duration > ,
707- pub timeout_connect : Duration ,
708- pub websocket_mask_frame : bool ,
709- pub tls : Option < TlsServerConfig > ,
710- pub dns_resolver : DnsResolver ,
711- pub restriction_config : Option < PathBuf > ,
712- }
713-
714- impl Debug for WsServerConfig {
715- fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
716- f. debug_struct ( "WsServerConfig" )
717- . field ( "socket_so_mark" , & self . socket_so_mark )
718- . field ( "bind" , & self . bind )
719- . field ( "websocket_ping_frequency" , & self . websocket_ping_frequency )
720- . field ( "timeout_connect" , & self . timeout_connect )
721- . field ( "websocket_mask_frame" , & self . websocket_mask_frame )
722- . field ( "restriction_config" , & self . restriction_config )
723- . field ( "tls" , & self . tls . is_some ( ) )
724- . field (
725- "mTLS" ,
726- & self
727- . tls
728- . as_ref ( )
729- . map ( |x| x. tls_client_ca_certificates . is_some ( ) )
730- . unwrap_or ( false ) ,
731- )
732- . finish ( )
733- }
734- }
735-
736694#[ tokio:: main]
737695async fn main ( ) -> anyhow:: Result < ( ) > {
738696 let args = Wstunnel :: parse ( ) ;
@@ -1194,18 +1152,17 @@ async fn main() -> anyhow::Result<()> {
11941152 . expect ( "Cannot create DNS resolver" ) ,
11951153 restriction_config : args. restrict_config ,
11961154 } ;
1155+ let server = WsServer :: new ( server_config) ;
11971156
11981157 info ! (
11991158 "Starting wstunnel server v{} with config {:?}" ,
12001159 env!( "CARGO_PKG_VERSION" ) ,
1201- server_config
1160+ server . config
12021161 ) ;
12031162 debug ! ( "Restriction rules: {:#?}" , restrictions) ;
1204- tunnel:: server:: run_server ( Arc :: new ( server_config) , restrictions)
1205- . await
1206- . unwrap_or_else ( |err| {
1207- panic ! ( "Cannot start wstunnel server: {:?}" , err) ;
1208- } ) ;
1163+ server. serve ( restrictions) . await . unwrap_or_else ( |err| {
1164+ panic ! ( "Cannot start wstunnel server: {:?}" , err) ;
1165+ } ) ;
12091166 }
12101167 }
12111168
0 commit comments