Commit fb8d0ca0 authored by Vladimír Čunát's avatar Vladimír Čunát

Merge !815: lib/nsrep: refactor a piece of code

parents fd15bc6c f13d3ef8
......@@ -137,35 +137,30 @@ static unsigned eval_addr_set(const pack_t *addr_set, struct kr_context *ctx,
}
}
/* We can't always use favour. If these conditions held:
*
* rtt_cache_entry_score[i] < KR_NS_TIMEOUT
* rtt_cache_entry_score[i] + favour > KR_NS_TIMEOUT
* cur_addr_score < rtt_cache_entry_score[i] + favour
*
* we would prefer "certainly dead" cur_addr_score
* instead of "almost dead but alive" rtt_cache_entry_score[i]
*/
const unsigned cur_favour = cur_addr_score < KR_NS_TIMEOUT ? favour : 0;
for (size_t i = 0; i < KR_NSREP_MAXADDR; ++i) {
if (cur_addr_score >= KR_NS_TIMEOUT) {
/* We can't use favour here.
* If all of the conditions below are true
*
* rtt_cache_entry_score[i] < KR_NS_TIMEOUT
* rtt_cache_entry_score[i] + favour > KR_NS_TIMEOUT
* cur_addr_score < rtt_cache_entry_score[i] + favour
*
* we will prefer "certainly dead" cur_addr_score
* instead of "almost dead, but alive" rtt_cache_entry_score[i]
*/
if (cur_addr_score >= rtt_cache_entry_score[i]) {
continue;
}
}
if (cur_addr_score >= KR_NS_TIMEOUT
|| cur_addr_score < rtt_cache_entry_score[i] + favour) {
/* Shake down previous contenders */
for (size_t j = KR_NSREP_MAXADDR - 1; j > i; --j) {
addr[j] = addr[j - 1];
rtt_cache_entry_ptr[j] = rtt_cache_entry_ptr[j - 1];
rtt_cache_entry_score[j] = rtt_cache_entry_score[j - 1];
}
addr[i] = it;
rtt_cache_entry_score[i] = cur_addr_score;
rtt_cache_entry_ptr[i] = cached;
break;
if (cur_addr_score >= rtt_cache_entry_score[i] + cur_favour)
continue;
/* Shake down previous contenders */
for (size_t j = KR_NSREP_MAXADDR - 1; j > i; --j) {
addr[j] = addr[j - 1];
rtt_cache_entry_ptr[j] = rtt_cache_entry_ptr[j - 1];
rtt_cache_entry_score[j] = rtt_cache_entry_score[j - 1];
}
addr[i] = it;
rtt_cache_entry_score[i] = cur_addr_score;
rtt_cache_entry_ptr[i] = cached;
break;
}
}
......
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