Skip to content
Snippets Groups Projects
Commit d70186a0 authored by Marek Vavruša's avatar Marek Vavruša
Browse files

lib/nsrep: be more aggresive with TCP for broken delegations

libuv doesn't do connected UDP sockets, so we can't get ICMP unreachable
otherwise
parent 14b8f25b
No related branches found
No related tags found
No related merge requests found
......@@ -123,9 +123,12 @@ static int eval_nsrep(const char *k, void *v, void *baton)
update_nsrep(ns, (const knot_dname_t *)k, addr, score);
ns->reputation = reputation;
} else {
/* With 5% chance, probe server with a probability given by its RTT / MAX_RTT */
unsigned roll = kr_rand_uint(KR_NS_MAX_SCORE);
if ((roll % 100 < 5) && (roll >= score)) {
/* With 10% chance, probe server with a probability given by its RTT / MAX_RTT */
if ((kr_rand_uint(100) < 10) && (kr_rand_uint(KR_NS_MAX_SCORE) >= score)) {
/* If this is a low-reliability probe, go with TCP to get ICMP reachability check. */
if (score >= KR_NS_LONG) {
qry->flags |= QUERY_TCP;
}
update_nsrep(ns, (const knot_dname_t *)k, addr, score);
ns->reputation = reputation;
return 1; /* Stop evaluation */
......
......@@ -33,6 +33,7 @@ struct kr_query;
enum kr_ns_score {
KR_NS_MAX_SCORE = KR_CONN_RTT_MAX,
KR_NS_TIMEOUT = (95 * KR_NS_MAX_SCORE) / 100,
KR_NS_LONG = (3 * KR_NS_TIMEOUT) / 4,
KR_NS_UNKNOWN = KR_NS_TIMEOUT / 2,
KR_NS_GLUED = 10
};
......
......@@ -380,12 +380,10 @@ int kr_resolve_consume(struct kr_request *request, knot_pkt_t *packet)
state = knot_overlay_consume(&request->overlay, packet);
}
/* Resolution failed, invalidate current NS and reset to UDP. */
/* Resolution failed, invalidate current NS. */
if (state == KNOT_STATE_FAIL) {
kr_nsrep_update_rtt(&qry->ns, KR_NS_TIMEOUT, ctx->cache_rtt);
if (invalidate_ns(rplan, qry) == 0) {
qry->flags &= ~QUERY_TCP;
}
invalidate_ns(rplan, qry); /* @note Stay with TCP as it's likely this is broken delegation. */
/* Track RTT for iterative answers */
} else if (!(qry->flags & QUERY_CACHED)) {
struct timeval now;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment