1
- use std:: time:: Duration ;
2
-
3
- lazy_static:: lazy_static! {
4
- /// Entry port to the proxy.
5
- static ref ENTRY : & ' static str = {
6
- if crate :: TARGET_REPLACEMENT . 0 == b":9223" {
7
- "0.0.0.0:9222"
8
- } else {
9
- "0.0.0.0:9223"
10
- }
11
- } ;
12
- /// Target chrome server.
13
- static ref TARGET : & ' static str = {
14
- if crate :: TARGET_REPLACEMENT . 1 == b":9222" {
15
- "0.0.0.0:9223"
16
- } else {
17
- "0.0.0.0:9224"
18
- }
19
- } ;
20
- /// The buffer size.
21
- static ref BUFFER_SIZE : usize = {
22
- let buffer_size = std:: env:: var( "BUFFER_SIZE" )
23
- . ok( )
24
- . and_then( |s| s. parse( ) . ok( ) )
25
- . unwrap_or( 131072 ) ; // Default to 128kb
26
- buffer_size
27
- } ;
28
-
29
- /// 10 sec cache
30
- static ref TEN_SECONDS : Duration = {
31
- Duration :: from_secs( 10 )
32
- } ;
33
-
34
- }
35
-
36
1
pub ( crate ) mod proxy {
2
+ use crate :: conf:: { BUFFER_SIZE , ENTRY , TARGET , TEN_SECONDS } ;
37
3
use crate :: { connect_with_retries, fork, shutdown_instances, CACHEABLE , LAST_CACHE } ;
38
4
use std:: { io:: ErrorKind , time:: Instant } ;
39
5
use tokio:: {
@@ -43,8 +9,8 @@ pub(crate) mod proxy {
43
9
44
10
/// Run the proxy forwarder for chrome. This allows connecting to chrome outside of the network.
45
11
pub async fn run_proxy ( ) -> std:: io:: Result < ( ) > {
46
- let listener = TcpListener :: bind ( * crate :: proxy :: ENTRY ) . await ?;
47
- println ! ( "Proxy Listening on {}" , * crate :: proxy :: ENTRY ) ;
12
+ let listener = TcpListener :: bind ( * ENTRY ) . await ?;
13
+ println ! ( "Proxy Listening on {}" , * ENTRY ) ;
48
14
let base_time = Instant :: now ( ) ;
49
15
50
16
loop {
@@ -81,7 +47,7 @@ pub(crate) mod proxy {
81
47
let total_elapsed =
82
48
tokio:: time:: Duration :: from_secs ( elasped) + elapsed_since_base;
83
49
84
- if total_elapsed >= * crate :: proxy :: TEN_SECONDS {
50
+ if total_elapsed >= * TEN_SECONDS {
85
51
CACHEABLE . store ( true , std:: sync:: atomic:: Ordering :: Relaxed ) ;
86
52
}
87
53
}
@@ -97,10 +63,10 @@ pub(crate) mod proxy {
97
63
98
64
/// Handle the proxy connection.
99
65
async fn handle_connection ( client_stream : & mut TcpStream ) -> std:: io:: Result < ( ) > {
100
- let server_stream: Option < TcpStream > = connect_with_retries ( * crate :: proxy :: TARGET ) . await ;
66
+ let server_stream: Option < TcpStream > = connect_with_retries ( * TARGET ) . await ;
101
67
102
68
if let Some ( mut server_stream) = server_stream {
103
- let buffer_size = * crate :: proxy :: BUFFER_SIZE ;
69
+ let buffer_size = * BUFFER_SIZE ;
104
70
let mut buf1 = vec ! [ 0u8 ; buffer_size] ;
105
71
let mut buf2 = vec ! [ 0u8 ; buffer_size] ;
106
72
0 commit comments