Commit 2a4f9f2f authored by Jelte Jansen's avatar Jelte Jansen

[master] fix updateRTT for fast responses

- updateRTT now accepts 0 (and will change it internally to 1 as it needs a value >0 for division)
- improved check for negative values due to clock changes in the caller
parent b5f4af26
......@@ -174,6 +174,9 @@ NameserverEntry::updateAddressRTTAtIndex(uint32_t rtt, size_t index,
uint32_t old_rtt = addresses_[family][index].getRTT();
uint32_t new_rtt = (uint32_t)(old_rtt * UPDATE_RTT_ALPHA + rtt *
(1 - UPDATE_RTT_ALPHA));
if (new_rtt == 0) {
new_rtt = 1;
}
addresses_[family][index].setRTT(new_rtt);
}
......
......@@ -608,18 +608,19 @@ public:
// Update the NSAS with the time it took
struct timeval cur_time;
gettimeofday(&cur_time, NULL);
uint32_t rtt;
if (cur_time.tv_sec >= current_ns_qsent_time.tv_sec ||
cur_time.tv_usec > current_ns_qsent_time.tv_usec) {
uint32_t rtt = 0;
// Only calculate RTT if it is positive
if (cur_time.tv_sec > current_ns_qsent_time.tv_sec ||
(cur_time.tv_sec == current_ns_qsent_time.tv_sec &&
cur_time.tv_usec > current_ns_qsent_time.tv_usec)) {
rtt = 1000 * (cur_time.tv_sec - current_ns_qsent_time.tv_sec);
rtt += (cur_time.tv_usec - current_ns_qsent_time.tv_usec) / 1000;
} else {
rtt = 1;
}
dlog("RTT: " + boost::lexical_cast<std::string>(rtt));
current_ns_address.updateRTT(rtt);
try {
Message incoming(Message::PARSE);
InputBuffer ibuf(buffer_->getData(), buffer_->getLength());
......
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