1
1
//! Example: simple L4 proxy
2
2
3
- use std:: num:: NonZeroU64 ;
4
3
use std:: { env, io} ;
5
4
6
5
use tokio:: net:: { TcpListener , TcpStream } ;
7
- #[ cfg( feature = "feat-rate-limit" ) ]
8
- use tokio_splice2:: rate:: RateLimit ;
9
6
10
7
// #[tokio::main(flavor = "current_thread")]
11
8
#[ tokio:: main]
@@ -91,19 +88,14 @@ async fn forwarding(mut stream1: TcpStream) -> io::Result<()> {
91
88
// let result = tokio_splice::zero_copy_bidirectional(&mut stream1, &mut
92
89
// stream2).await;
93
90
94
- let limit = env:: var ( "LIMIT" )
95
- . ok ( )
96
- . and_then ( |r| r. parse ( ) . ok ( ) )
97
- . unwrap_or ( 1u64 * 1000 * 1000 ) ;
91
+ // let limit = env::var("LIMIT")
92
+ // .ok()
93
+ // .and_then(|r| r.parse().ok())
94
+ // .unwrap_or(1u64 * 1000 * 1000);
98
95
99
- println ! (
100
- "Rate limit is set to {}/s" ,
101
- human_format_next:: Formatter :: SI
102
- . with_custom_unit( "B" )
103
- . format( limit) ,
104
- ) ;
96
+ // println!("Rate limit is set to {limit} B/s");
105
97
106
- let limit = RateLimit :: new ( NonZeroU64 :: new ( limit) . unwrap ( ) ) ;
98
+ // let limit = RateLimit::new(NonZeroU64::new(limit).unwrap());
107
99
108
100
// let rate_limiter_clone = rate_limiter.clone();
109
101
// tokio::spawn(async move {
@@ -141,12 +133,8 @@ async fn forwarding(mut stream1: TcpStream) -> io::Result<()> {
141
133
// }
142
134
// });
143
135
144
- let io_sl2sr = tokio_splice2:: context:: SpliceIoCtx :: prepare ( ) ?
145
- . into_io ( )
146
- . with_rate_limit ( limit. clone ( ) ) ;
147
- let io_sr2sl = tokio_splice2:: context:: SpliceIoCtx :: prepare ( ) ?
148
- . into_io ( )
149
- . with_rate_limit ( limit) ;
136
+ let io_sl2sr = tokio_splice2:: context:: SpliceIoCtx :: prepare ( ) ?. into_io ( ) ;
137
+ let io_sr2sl = tokio_splice2:: context:: SpliceIoCtx :: prepare ( ) ?. into_io ( ) ;
150
138
151
139
let traffic = tokio_splice2:: io:: SpliceBidiIo { io_sl2sr, io_sr2sl }
152
140
. execute ( & mut stream1, & mut stream2)
@@ -157,17 +145,9 @@ async fn forwarding(mut stream1: TcpStream) -> io::Result<()> {
157
145
// let total = traffic.0 + traffic.1;
158
146
let cost = instant. elapsed ( ) ;
159
147
println ! (
160
- "Forwarded traffic: total: {}, time: {:.2}s, avg: {:.4} -> {}, error: {:?}" ,
161
- human_format_next:: Formatter :: SI
162
- . with_custom_unit( "B" )
163
- . with_decimals:: <4 >( )
164
- . format( total as f64 ) ,
148
+ "Forwarded traffic: total: {total} B, time: {:.2} s, avg: {:.4} B/s, error: {:?}" ,
165
149
cost. as_secs_f64( ) ,
166
150
total as f64 / cost. as_secs_f64( ) ,
167
- human_format_next:: Formatter :: SI
168
- . with_custom_unit( "B/s" )
169
- . with_decimals:: <4 >( )
170
- . format( ( total as f64 / cost. as_secs_f64( ) ) as u64 ) ,
171
151
traffic. error
172
152
) ;
173
153
0 commit comments