Verified Commit 299e605b authored by Grigorii Demidov's avatar Grigorii Demidov Committed by Petr Špaček

lib/nsrep: minor changes

parent 3dc14715
......@@ -1077,12 +1077,8 @@ static int session_tls_hs_cb(struct session *session, int status)
int deletion_res = worker_del_tcp_waiting(worker, &peer->ip);
if (status) {
for (size_t i = 0; i < session->waiting.len; ++i) {
struct qr_task *task = session->waiting.at[0];
struct kr_query *qry = array_tail(task->ctx->req.rplan.pending);
kr_nsrep_update_rtt(&qry->ns, &peer->ip, KR_NS_TIMEOUT,
worker->engine->resolver.cache_rtt, KR_NS_UPDATE);
}
kr_nsrep_update_rtt(NULL, &peer->ip, KR_NS_TIMEOUT,
worker->engine->resolver.cache_rtt, KR_NS_RESET);
} else {
if (deletion_res != 0) {
/* session isn't in list of waiting queries, *
......@@ -1248,6 +1244,9 @@ static void on_tcp_connect_timeout(uv_timer_t *timer)
VERBOSE_MSG(qry, "=> connection to '%s' failed\n", addr_str);
}
kr_nsrep_update_rtt(NULL, &peer->ip, KR_NS_TIMEOUT,
worker->engine->resolver.cache_rtt, KR_NS_RESET);
while (session->waiting.len > 0) {
struct qr_task *task = session->waiting.at[0];
struct request_ctx *ctx = task->ctx;
......
......@@ -280,12 +280,12 @@ int kr_nsrep_elect_addr(struct kr_query *qry, struct kr_context *ctx)
int kr_nsrep_update_rtt(struct kr_nsrep *ns, const struct sockaddr *addr,
unsigned score, kr_nsrep_lru_t *cache, int umode)
{
if (!ns || !cache || ns->addr[0].ip.sa_family == AF_UNSPEC) {
if (!cache) {
return kr_error(EINVAL);
}
const char *addr_in = kr_inaddr(&ns->addr[0].ip);
size_t addr_len = kr_inaddr_len(&ns->addr[0].ip);
const char *addr_in = NULL;
size_t addr_len = 0;
if (addr) { /* Caller provided specific address */
if (addr->sa_family == AF_INET) {
addr_in = (const char *)&((struct sockaddr_in *)addr)->sin_addr;
......@@ -293,8 +293,18 @@ int kr_nsrep_update_rtt(struct kr_nsrep *ns, const struct sockaddr *addr,
} else if (addr->sa_family == AF_INET6) {
addr_in = (const char *)&((struct sockaddr_in6 *)addr)->sin6_addr;
addr_len = sizeof(struct in6_addr);
} else {
assert(false && "kr_nsrep_update_rtt: unexpected address family");
}
} else if (ns != NULL && ns->addr[0].ip.sa_family != AF_UNSPEC) {
addr_in = kr_inaddr(&ns->addr[0].ip);
addr_len = kr_inaddr_len(&ns->addr[0].ip);
} else {
return kr_error(EINVAL);
}
assert(addr_in != NULL && addr_len > 0);
unsigned *cur = lru_get_new(cache, addr_in, addr_len);
if (!cur) {
return kr_ok();
......
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