Commit 4eae3d9a authored by Grigorii Demidov's avatar Grigorii Demidov Committed by Petr Špaček

daemon: addition to fd54dd5a, handle STUB in the same way as FORWARDING;

also improvement in NS election algorytm when using FORWARDING & STUB.
parent 7db1882e
......@@ -694,7 +694,8 @@ static int session_tls_hs_cb(struct session *session, int status)
if (status) {
struct qr_task *task = session_waitinglist_get(session);
unsigned score = task->ctx->req.options.FORWARD ? KR_NS_FWD_DEAD : KR_NS_DEAD;
struct kr_qflags *options = &task->ctx->req.options;
unsigned score = options->FORWARD || options->STUB ? KR_NS_FWD_DEAD : KR_NS_DEAD;
kr_nsrep_update_rtt(NULL, peer, score,
worker->engine->resolver.cache_rtt,
KR_NS_UPDATE_NORESET);
......@@ -818,7 +819,8 @@ static void on_connect(uv_connect_t *req, int status)
}
worker_del_tcp_waiting(worker, peer);
struct qr_task *task = session_waitinglist_get(session);
unsigned score = task->ctx->req.options.FORWARD ? KR_NS_FWD_DEAD : KR_NS_DEAD;
struct kr_qflags *options = &task->ctx->req.options;
unsigned score = options->FORWARD || options->STUB ? KR_NS_FWD_DEAD : KR_NS_DEAD;
kr_nsrep_update_rtt(NULL, peer, score,
worker->engine->resolver.cache_rtt,
KR_NS_UPDATE_NORESET);
......@@ -893,7 +895,7 @@ static void on_tcp_connect_timeout(uv_timer_t *timer)
VERBOSE_MSG(qry, "=> connection to '%s' failed\n", peer_str);
}
unsigned score = qry->flags.FORWARD ? KR_NS_FWD_DEAD : KR_NS_DEAD;
unsigned score = qry->flags.FORWARD || qry->flags.STUB ? KR_NS_FWD_DEAD : KR_NS_DEAD;
kr_nsrep_update_rtt(NULL, peer, score,
worker->engine->resolver.cache_rtt,
KR_NS_UPDATE_NORESET);
......@@ -926,7 +928,7 @@ static void on_udp_timeout(uv_timer_t *timer)
char *addr_str = kr_straddr(choice);
VERBOSE_MSG(qry, "=> server: '%s' flagged as 'bad'\n", addr_str ? addr_str : "");
}
unsigned score = qry->flags.FORWARD ? KR_NS_FWD_DEAD : KR_NS_DEAD;
unsigned score = qry->flags.FORWARD || qry->flags.STUB ? KR_NS_FWD_DEAD : KR_NS_DEAD;
kr_nsrep_update_rtt(&qry->ns, choice, score,
worker->engine->resolver.cache_rtt,
KR_NS_UPDATE_NORESET);
......@@ -986,7 +988,8 @@ static void on_retransmit(uv_timer_t *req)
struct qr_task *task = session_tasklist_get_first(session);
if (retransmit(task) == NULL) {
/* Not possible to spawn request, start timeout timer with remaining deadline. */
uint64_t timeout = task->ctx->req.options.FORWARD ? KR_NS_FWD_TIMEOUT / 2 :
struct kr_qflags *options = &task->ctx->req.options;
uint64_t timeout = options->FORWARD || options->STUB ? KR_NS_FWD_TIMEOUT / 2 :
KR_CONN_RTT_MAX - task->pending_count * KR_CONN_RETRY;
uv_timer_start(req, on_udp_timeout, timeout, 0);
} else {
......@@ -1292,7 +1295,7 @@ static int tcp_task_make_connection(struct qr_task *task, const struct sockaddr
worker_del_tcp_waiting(ctx->worker, addr);
free(conn);
session_close(session);
unsigned score = qry->flags.FORWARD ? KR_NS_FWD_DEAD : KR_NS_DEAD;
unsigned score = qry->flags.FORWARD || qry->flags.STUB ? KR_NS_FWD_DEAD : KR_NS_DEAD;
kr_nsrep_update_rtt(NULL, peer, score,
worker->engine->resolver.cache_rtt,
KR_NS_UPDATE_NORESET);
......
......@@ -508,7 +508,17 @@ int kr_nsrep_sort(struct kr_nsrep *ns, struct kr_context *ctx)
if (sa->sa_family == AF_INET) {
scores[i] += FAVOUR_IPV6;
}
} else if (rtt_cache_entry->score >= KR_NS_FWD_TIMEOUT) {
} else if (rtt_cache_entry->score < KR_NS_FWD_TIMEOUT) {
/* some probability to bump bad ones up for re-probe */
scores[i] = rtt_cache_entry->score;
/* The lower the rtt, the more likely it will be selected. */
if (!kr_rand_coin(rtt_cache_entry->score, KR_NS_FWD_TIMEOUT)) {
scores[i] = 1;
}
if (sa->sa_family == AF_INET) {
scores[i] += FAVOUR_IPV6;
}
} else {
uint64_t now = kr_now();
uint64_t elapsed = now - rtt_cache_entry->tout_timestamp;
scores[i] = KR_NS_MAX_SCORE + 1;
......@@ -522,11 +532,6 @@ int kr_nsrep_sort(struct kr_nsrep *ns, struct kr_context *ctx)
rtt_cache_entry->tout_timestamp = now;
timeouted_address_is_already_selected = true;
}
} else {
scores[i] = rtt_cache_entry->score;
if (sa->sa_family == AF_INET) {
scores[i] += FAVOUR_IPV6;
}
}
if (VERBOSE_STATUS) {
kr_log_verbose("[ ][nsre] score %d for %s;\t cached RTT: %d\n",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment