From: Štěpán Balážik Date: Fri, 4 Sep 2020 14:50:26 +0000 (+0200) Subject: selection: don't include servers over error limit in selection X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2f815b6785ecda13235cc00d6d77cdd9de856d13;p=thirdparty%2Fknot-resolver.git selection: don't include servers over error limit in selection --- diff --git a/lib/selection.c b/lib/selection.c index c22de5ad6..4d94c4b2f 100644 --- a/lib/selection.c +++ b/lib/selection.c @@ -178,8 +178,6 @@ void shuffle_choices(struct choice choices[], int choices_len) { } } -#define ERROR_LIMIT 2 - // Performs the actual selection (currently epsilon-greedy with epsilon = 0.05). struct kr_transport *choose_transport(struct choice choices[], int choices_len, @@ -211,11 +209,7 @@ struct kr_transport *choose_transport(struct choice choices[], // EXPLOIT shuffle_choices(choices, choices_len); qsort(choices, choices_len, sizeof(struct choice), cmp_choices); - if (choices[0].address_state->error_count > ERROR_LIMIT) { - return NULL; - } else { - choice = 0; - } + choice = 0; } unsigned timeout = calc_timeout(choices[choice].address_state->rtt_state); diff --git a/lib/selection.h b/lib/selection.h index 24e6deda8..f46f0d7a6 100644 --- a/lib/selection.h +++ b/lib/selection.h @@ -11,6 +11,8 @@ #include "lib/cache/api.h" +#define ERROR_LIMIT_PER_SERVER 2 + /** * These errors are to be reported as feedback to server selection. * See `kr_server_selection::error` for more details. diff --git a/lib/selection_forward.c b/lib/selection_forward.c index 27bb1a490..8ca1fcece 100644 --- a/lib/selection_forward.c +++ b/lib/selection_forward.c @@ -55,7 +55,7 @@ void forward_choose_transport(struct kr_query *qry, struct kr_transport **transp check_tcp_connections(addr_state, qry->request, &address->ip); check_network_settings(addr_state, addr_len, qry->flags.NO_IPV4, qry->flags.NO_IPV6); - if(addr_state->generation == -1) { + if(addr_state->generation == -1 || addr_state->error_count >= ERROR_LIMIT_PER_SERVER) { continue; } addr_state->forward_index = i; diff --git a/lib/selection_iter.c b/lib/selection_iter.c index 59e17f5c8..6fee28c8f 100644 --- a/lib/selection_iter.c +++ b/lib/selection_iter.c @@ -163,7 +163,8 @@ void iter_choose_transport(struct kr_query *qry, struct kr_transport **transport size_t address_len; uint8_t* address = (uint8_t *)trie_it_key(it, &address_len); struct address_state *address_state = (struct address_state *)*trie_it_val(it); - if (address_state->generation == local_state->generation) { + if (address_state->generation == local_state->generation && + address_state->error_count < ERROR_LIMIT_PER_SERVER) { choices[valid_addresses] = (struct choice){ .address = address, .address_len = address_len,