@@ -332,7 +332,9 @@ impl Server {
332332 use_sync : bool ,
333333 ) -> Result < UdpServer > {
334334 let upstream_addr = inner_state ! ( self , udp_upstream) . unwrap ( ) ;
335- let udp_server = UdpServer :: bind_and_start ( addr, upstream_addr, use_sync) . await ?;
335+ let udp_server =
336+ UdpServer :: bind_and_start ( addr, upstream_addr, use_sync, self . config . udp_timeout_ms )
337+ . await ?;
336338
337339 let udp_server_addr = udp_server. local_addr ( ) . unwrap ( ) ;
338340 inner_state ! ( self , udp_upstream) = Some ( udp_server_addr) ;
@@ -491,15 +493,9 @@ impl Server {
491493 proxy_rule_manager : inner_state ! ( self , proxy_rule_manager) . clone ( ) ,
492494 stats_sender,
493495 tcp_nodelay : cfg. tcp_nodelay ,
496+ tcp_timeout_ms : cfg. tcp_timeout_ms ,
494497 } ) ;
495498
496- // if let Some(p) = cfg.server_addr.proto {
497- // if p.is_udp_supported() {
498- // let addr = cfg.upstream_udp.unwrap_or(cfg.upstream_addr);
499- // let udp_server = UdpServer::bind_and_start(cfg.addr, upstream_addr, false).await;
500- // }
501- // }
502-
503499 loop {
504500 match proxy_listener. accept ( ) . await {
505501 Ok ( ( inbound_stream, _addr) ) => {
@@ -532,6 +528,7 @@ impl Server {
532528 inbound_stream,
533529 outbound_stream,
534530 & psp. stats_sender ,
531+ psp. tcp_timeout_ms ,
535532 )
536533 . await
537534 . ok ( ) ;
@@ -789,6 +786,7 @@ impl Server {
789786 inbound_stream,
790787 outbound_stream,
791788 & params. stats_sender ,
789+ params. tcp_timeout_ms ,
792790 )
793791 . await ?;
794792 }
@@ -863,6 +861,7 @@ impl Server {
863861 mut inbound_stream : TcpStream ,
864862 mut outbound_stream : TcpStream ,
865863 stats_sender : & Sender < ServerStats > ,
864+ tcp_timeout_ms : u64 ,
866865 ) -> Result < ProxyTraffic , ProxyError > {
867866 stats_sender. send ( ServerStats :: NewConnection ) . await . ok ( ) ;
868867
@@ -897,13 +896,15 @@ impl Server {
897896 & mut outbound_writer,
898897 & mut inbound_buffer,
899898 & mut tx_bytes,
900- & mut inbound_stream_eos) => result,
899+ & mut inbound_stream_eos,
900+ tcp_timeout_ms) => result,
901901 result = Self :: transfer_data_with_timeout(
902902 & mut outbound_reader,
903903 & mut inbound_writer,
904904 & mut outbound_buffer,
905905 & mut rx_bytes,
906- & mut outbound_stream_eos) => result,
906+ & mut outbound_stream_eos,
907+ tcp_timeout_ms) => result,
907908 }
908909 } else if !outbound_stream_eos {
909910 Self :: transfer_data_with_timeout (
@@ -912,6 +913,7 @@ impl Server {
912913 & mut outbound_buffer,
913914 & mut rx_bytes,
914915 & mut outbound_stream_eos,
916+ tcp_timeout_ms,
915917 )
916918 . await
917919 } else {
@@ -921,6 +923,7 @@ impl Server {
921923 & mut inbound_buffer,
922924 & mut tx_bytes,
923925 & mut inbound_stream_eos,
926+ tcp_timeout_ms,
924927 )
925928 . await
926929 } ;
@@ -956,12 +959,13 @@ impl Server {
956959 buffer : & mut [ u8 ] ,
957960 out_bytes : & mut u64 ,
958961 eos_flag : & mut bool ,
962+ tcp_timeout_ms : u64 ,
959963 ) -> Result < usize , ProxyError >
960964 where
961965 R : AsyncRead + Unpin ,
962966 W : AsyncWrite + Unpin ,
963967 {
964- match tokio:: time:: timeout ( Duration :: from_secs ( 15 ) , reader. read ( buffer) )
968+ match tokio:: time:: timeout ( Duration :: from_millis ( tcp_timeout_ms ) , reader. read ( buffer) )
965969 . await
966970 . map_err ( |_: Elapsed | ProxyError :: Timeout ) ?
967971 {
@@ -1206,7 +1210,7 @@ impl Api for Server {
12061210 cert : cfg. cert . clone ( ) ,
12071211 cipher : cfg. cipher . clone ( ) ,
12081212 password : cfg. password . clone ( ) ,
1209- idle_timeout : cfg. max_idle_timeout_ms ,
1213+ idle_timeout : cfg. quic_timeout_ms ,
12101214 retry_interval : cfg. retry_interval_ms ,
12111215 }
12121216 }
@@ -1252,7 +1256,7 @@ impl Api for Server {
12521256 base_common_quic_config. cert = config. cert ;
12531257 base_common_quic_config. cipher = config. cipher ;
12541258 base_common_quic_config. password = config. password ;
1255- base_common_quic_config. max_idle_timeout_ms = config. idle_timeout ;
1259+ base_common_quic_config. quic_timeout_ms = config. idle_timeout ;
12561260 base_common_quic_config. retry_interval_ms = config. retry_interval ;
12571261 let upstream_addr = NetAddr :: from_str ( config. upstream_addr . as_str ( ) ) ?;
12581262 let quic_client_join_handle = self
@@ -1273,4 +1277,5 @@ struct ProxySupportParams {
12731277 proxy_rule_manager : Option < ProxyRuleManager > ,
12741278 stats_sender : Sender < ServerStats > ,
12751279 tcp_nodelay : bool ,
1280+ tcp_timeout_ms : u64 ,
12761281}
0 commit comments