return 1;
}
+/** Set time interval for cleaning rtt cache.
+ * Servers with score >= KR_NS_TIMEOUTED will be cleaned after
+ * this interval ended up, so that they will be able to participate
+ * in NS elections again. */
+static int cache_touted_ns_clean_interval(lua_State *L)
+{
+ struct engine *engine = engine_luaget(L);
+ struct kr_context *ctx = &engine->resolver;
+
+ /* Check parameters */
+ int n = lua_gettop(L);
+ if (n < 1) {
+ lua_pushinteger(L, ctx->cache_rtt_tout_retry_interval);
+ return 1;
+ }
+
+ if (!lua_isnumber(L, 1)) {
+ format_error(L, "expected 'cache.ns_tout(interval in ms)'");
+ lua_error(L);
+ }
+
+ lua_Number interval_lua = lua_tonumber(L, 1);
+ if (!(interval_lua >= 0 && interval_lua < UINT_MAX)) {
+ format_error(L, "invalid interval specified, it must be in range > 0, < " xstr(UINT_MAX));
+ lua_error(L);
+ }
+
+ ctx->cache_rtt_tout_retry_interval = interval_lua;
+ lua_pushinteger(L, ctx->cache_rtt_tout_retry_interval);
+ return 1;
+}
+
+
int lib_cache(lua_State *L)
{
static const luaL_Reg lib[] = {
{ "get", cache_get },
{ "max_ttl", cache_max_ttl },
{ "min_ttl", cache_min_ttl },
+ { "ns_tout", cache_touted_ns_clean_interval },
{ NULL, NULL }
};
#undef ADDR_SET
-static unsigned eval_addr_set(pack_t *addr_set, kr_nsrep_rtt_lru_t *rtt_cache,
- unsigned score, uint8_t *addr[], struct kr_qflags opts)
+static unsigned eval_addr_set(pack_t *addr_set, struct kr_context *ctx,
+ unsigned score, uint8_t *addr[])
{
+ kr_nsrep_rtt_lru_t *rtt_cache = ctx->cache_rtt;
+ struct kr_qflags opts = ctx->options;
/* Name server is better candidate if it has address record. */
uint8_t *it = pack_head(*addr_set);
while (it != pack_tail(*addr_set)) {
elapsed = elapsed > UINT_MAX ? UINT_MAX : elapsed;
/* If NS once was marked as "timeouted",
* it won't participate in NS elections
- * at least KR_NS_TIMEOUT_RETRY_INTERVAL milliseconds. */
+ * at least ctx->cache_rtt_tout_retry_interval milliseconds. */
addr_score = cached->score;
if (cached->score >= KR_NS_TIMEOUT &&
- elapsed > KR_NS_TIMEOUT_RETRY_INTERVAL) {
+ elapsed > ctx->cache_rtt_tout_retry_interval) {
addr_score = KR_NS_LONG - 1;
cached->score = addr_score;
cached->tout_timestamp = 0;
}
}
} else {
- score = eval_addr_set(addr_set, ctx->cache_rtt, score, addr_choice, ctx->options);
+ score = eval_addr_set(addr_set, ctx, score, addr_choice);
}
/* Probabilistic bee foraging strategy (naive).
}
/* Evaluate addr list */
uint8_t *addr_choice[KR_NSREP_MAXADDR] = { NULL, };
- unsigned score = eval_addr_set(addr_set, ctx->cache_rtt, ns->score, addr_choice, ctx->options);
+ unsigned score = eval_addr_set(addr_set, ctx, ns->score, addr_choice);
update_nsrep_set(ns, ns->name, addr_choice, score);
return kr_ok();
}