Merge pull request #4 from lemoer/patch-fix-pong-handler

Patchset to improve the pong handler

It seem that we have some troll in the network or something is broken.
This commit is contained in:
Rafał Leśniak 2016-05-18 22:53:45 +02:00
commit b3607cd5f9

View file

@ -123,12 +123,19 @@ bool send_pong(connection_t *c) {
} }
bool pong_h(connection_t *c, const char *request) { bool pong_h(connection_t *c, const char *request) {
int current_rtt = 0; int ret;
int tv_sec, tv_usec, ret; long current_rtt = 0;
long tv_sec, tv_usec;
struct timeval _now; struct timeval _now;
if (!c->status.pinged) {
logger(DEBUG_ALWAYS, LOG_WARNING, "received pong without ping");
return false;
}
c->status.pinged = false; c->status.pinged = false;
ret = sscanf(request, "%*d %d %d", &tv_sec, &tv_usec); ret = sscanf(request, "%*d %ld %ld", &tv_sec, &tv_usec);
gettimeofday(&_now, NULL); gettimeofday(&_now, NULL);
if (ret != 2) { if (ret != 2) {
@ -137,12 +144,17 @@ bool pong_h(connection_t *c, const char *request) {
tv_usec = c->last_ping_time.tv_usec; tv_usec = c->last_ping_time.tv_usec;
} }
/* RTT should be in ms */ if (_now.tv_sec - tv_sec > 2*pingtimeout) {
current_rtt = (_now.tv_sec - tv_sec)*1000; /* timeout_handler should close the meta connection after pingtimeout.
/* Compute diff between usec */ * So if we still receive such pong, something is fishy. */
current_rtt += _now.tv_usec >= tv_usec ? _now.tv_usec - tv_usec : tv_usec - _now.tv_usec; logger(DEBUG_ALWAYS, LOG_ERR, "bogus pong received from %s (%s)", c->name, c->hostname);
return false;
}
current_rtt = current_rtt/1000; /* current_rtt should be in ms */
current_rtt += (_now.tv_sec - tv_sec) * 1000;
/* Compute diff between usec */
current_rtt += (_now.tv_usec - tv_usec) / 1000;
if (c->edge->avg_rtt == 0) if (c->edge->avg_rtt == 0)
c->edge->avg_rtt = current_rtt; c->edge->avg_rtt = current_rtt;