@@ -5,125 +5,25 @@ use std::{
55
66use color_eyre:: eyre:: { OptionExt as _, WrapErr as _} ;
77
8- use crate :: {
9- parsers:: parse_ipv4,
10- proxy:: ProxyType ,
11- raw_config:: RawConfig ,
12- utils:: { is_docker, pretty_error} ,
13- } ;
8+ use crate :: { proxy:: ProxyType , raw_config:: RawConfig , utils:: is_docker} ;
149
1510pub const APP_DIRECTORY_NAME : & str = "proxy_scraper_checker" ;
1611pub const USER_AGENT : & str = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) \
1712 AppleWebKit/537.36 (KHTML, like Gecko) \
1813 Chrome/135.0.0.0 Safari/537.36";
1914
20- #[ derive( Clone ) ]
21- pub enum CheckWebsiteType {
22- Unknown ,
23- PlainIp ,
24- HttpbinIp ,
25- }
26-
2715#[ derive( serde:: Deserialize ) ]
2816pub struct HttpbinResponse {
2917 pub origin : String ,
3018}
3119
32- impl CheckWebsiteType {
33- pub async fn guess (
34- check_website : & str ,
35- http_client : reqwest:: Client ,
36- ) -> Self {
37- if check_website. is_empty ( ) {
38- return Self :: Unknown ;
39- }
40-
41- let response = match http_client. get ( check_website) . send ( ) . await {
42- Ok ( resp) => resp,
43- Err ( err) => {
44- log:: error!(
45- "Failed to open check_website without proxy, it will be \
46- impossible to determine anonymity and geolocation of \
47- proxies: {err}",
48- ) ;
49- return Self :: Unknown ;
50- }
51- } ;
52-
53- let response = match response. error_for_status ( ) {
54- Ok ( response) => response,
55- Err ( err) => {
56- if let Some ( status) = err. status ( ) {
57- log:: error!(
58- "check_website returned error HTTP status code: \
59- {status}"
60- ) ;
61- } else {
62- log:: error!(
63- "check_website returned error HTTP status code"
64- ) ;
65- }
66- return Self :: Unknown ;
67- }
68- } ;
69-
70- let body = match response. text ( ) . await {
71- Ok ( text) => text,
72- Err ( err) => {
73- log:: error!( "Failed to decode check_website response: {err}" ) ;
74- return Self :: Unknown ;
75- }
76- } ;
77-
78- if let Ok ( httpbin) = serde_json:: from_str :: < HttpbinResponse > ( & body) {
79- match parse_ipv4 ( & httpbin. origin ) {
80- Ok ( Some ( _) ) => {
81- return Self :: HttpbinIp ;
82- }
83- Ok ( None ) => {
84- log:: error!( "Failed to parse ipv4 from httpbin response" ) ;
85- }
86- Err ( e) => {
87- log:: error!(
88- "Failed to parse ipv4 from httpbin response: {}" ,
89- pretty_error( & e)
90- ) ;
91- }
92- }
93- } else {
94- match parse_ipv4 ( & body) {
95- Ok ( Some ( _) ) => {
96- return Self :: PlainIp ;
97- }
98- Ok ( None ) => { }
99- Err ( e) => {
100- log:: error!(
101- "Failed to parse ipv4 from response: {}" ,
102- pretty_error( & e)
103- ) ;
104- }
105- }
106- }
107-
108- Self :: Unknown
109- }
110-
111- pub const fn supports_geolocation ( & self ) -> bool {
112- match self {
113- Self :: Unknown => false ,
114- Self :: PlainIp | Self :: HttpbinIp => true ,
115- }
116- }
117- }
118-
11920#[ expect( clippy:: struct_excessive_bools) ]
12021pub struct Config {
12122 pub timeout : tokio:: time:: Duration ,
12223 pub source_timeout : tokio:: time:: Duration ,
12324 pub proxies_per_source_limit : usize ,
12425 pub max_concurrent_checks : usize ,
12526 pub check_website : String ,
126- pub check_website_type : CheckWebsiteType ,
12727 pub sort_by_speed : bool ,
12828 pub enable_geolocation : bool ,
12929 pub debug : bool ,
@@ -157,23 +57,17 @@ async fn get_output_path(
15757impl Config {
15858 pub async fn from_raw_config (
15959 raw_config : RawConfig ,
160- http_client : reqwest:: Client ,
16160 ) -> color_eyre:: Result < Self > {
162- let ( check_website_type, output_path) = tokio:: try_join!(
163- async {
164- Ok ( CheckWebsiteType :: guess(
165- & raw_config. check_website,
166- http_client,
167- )
168- . await )
169- } ,
170- get_output_path( & raw_config)
171- ) ?;
61+ let output_path = get_output_path ( & raw_config) . await ?;
17262
17363 let max_concurrent_checks =
17464 match rlimit:: increase_nofile_limit ( u64:: MAX ) {
17565 Ok ( lim) => {
66+ #[ cfg( target_pointer_width = "32" ) ]
67+ let lim = cast:: usize ( lim) . unwrap_or ( usize:: MAX ) ;
68+ #[ cfg( not( target_pointer_width = "32" ) ) ]
17669 let lim = cast:: usize ( lim) ;
70+
17771 if raw_config. max_concurrent_checks > lim {
17872 log:: warn!(
17973 "max_concurrent_checks config value is too high \
@@ -196,10 +90,8 @@ impl Config {
19690 proxies_per_source_limit : raw_config. proxies_per_source_limit ,
19791 max_concurrent_checks,
19892 check_website : raw_config. check_website ,
199- check_website_type : check_website_type. clone ( ) ,
20093 sort_by_speed : raw_config. sort_by_speed ,
201- enable_geolocation : raw_config. enable_geolocation
202- && check_website_type. supports_geolocation ( ) ,
94+ enable_geolocation : raw_config. enable_geolocation ,
20395 debug : raw_config. debug ,
20496 output_path,
20597 output_json : raw_config. output . json ,
0 commit comments