From 81afe325f65a338071b94413052bee8ef0855dda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Gallou=C3=ABt?= Date: Thu, 26 Apr 2018 20:20:28 +0000 Subject: [PATCH] Update ratemax softly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Adrien Gallouët --- mud.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/mud.c b/mud.c index b1a5726..44d803c 100644 --- a/mud.c +++ b/mud.c @@ -1423,10 +1423,14 @@ mud_recv(struct mud *mud, void *data, size_t size) path->latmax = lat; if (path->recv.ratemax > rate) { - const uint64_t range = path->latmax - path->latmin; - if (range && lat > path->latmin + (range >> 1)) - path->recv.ratemax = ((lat - path->latmin) * rate + - (path->latmax - lat) * path->recv.ratemax) / range; + const uint64_t latmin = path->latmin + (path->latmin >> 3); + const uint64_t latmax = path->latmax; + if (latmin < lat) { + const uint64_t a = lat - latmin; + const uint64_t b = latmax - lat; + const uint64_t r = latmax - latmin; + path->recv.ratemax = (a * rate + (b + r) * path->recv.ratemax) / (r << 1); + } } path->recv.rate = rate;