@@ -2,6 +2,7 @@ use std::collections::BTreeMap;
2
2
use std:: sync:: Mutex ;
3
3
use std:: time;
4
4
5
+ use ahash:: HashSet ;
5
6
use ansi_term:: Style ;
6
7
use lazy_static:: lazy_static;
7
8
use rand:: Rng ;
@@ -103,6 +104,7 @@ async fn worker(plugin: &dyn Plugin, session: Arc<Session>) {
103
104
104
105
let timeout = time:: Duration :: from_millis ( session. options . timeout ) ;
105
106
let retry_time: time:: Duration = time:: Duration :: from_millis ( session. options . retry_time ) ;
107
+ let mut unreachables: HashSet < String > = HashSet :: default ( ) ;
106
108
107
109
while let Ok ( creds) = session. recv_new_credentials ( ) . await {
108
110
if session. is_stop ( ) {
@@ -126,36 +128,43 @@ async fn worker(plugin: &dyn Plugin, session: Arc<Session>) {
126
128
127
129
attempt += 1 ;
128
130
129
- match plugin. attempt ( & creds, timeout) . await {
130
- Err ( err) => {
131
- errors += 1 ;
132
- if attempt < session. options . retries {
133
- log:: debug!(
134
- "[{}] attempt {}/{}: {}" ,
135
- & creds. target,
136
- attempt,
137
- session. options. retries,
138
- err
139
- ) ;
140
- std:: thread:: sleep ( retry_time) ;
141
- continue ;
142
- } else {
143
- log:: error!(
144
- "[{}] attempt {}/{}: {}" ,
145
- & creds. target,
146
- attempt,
147
- session. options. retries,
148
- err
149
- ) ;
131
+ // skip attempt if we had enough failures from this specific target
132
+ if !unreachables. contains ( & creds. target ) {
133
+ match plugin. attempt ( & creds, timeout) . await {
134
+ Err ( err) => {
135
+ errors += 1 ;
136
+ if attempt < session. options . retries {
137
+ log:: debug!(
138
+ "[{}] attempt {}/{}: {}" ,
139
+ & creds. target,
140
+ attempt,
141
+ session. options. retries,
142
+ err
143
+ ) ;
144
+ std:: thread:: sleep ( retry_time) ;
145
+ continue ;
146
+ } else {
147
+ // add this target to the list of unreachable in order to avoi
148
+ // pointless attempts
149
+ unreachables. insert ( creds. target . clone ( ) ) ;
150
+
151
+ log:: error!(
152
+ "[{}] attempt {}/{}: {}" ,
153
+ & creds. target,
154
+ attempt,
155
+ session. options. retries,
156
+ err
157
+ ) ;
158
+ }
150
159
}
151
- }
152
- Ok ( loot ) => {
153
- // do we have new loot?
154
- if let Some ( loot ) = loot {
155
- session . add_loot ( loot ) . await . unwrap ( ) ;
160
+ Ok ( loot ) => {
161
+ // do we have new loot?
162
+ if let Some ( loot) = loot {
163
+ session . add_loot ( loot ) . await . unwrap ( ) ;
164
+ }
156
165
}
157
- }
158
- } ;
166
+ } ;
167
+ }
159
168
160
169
break ;
161
170
}
0 commit comments