Blob Blame History Raw
From: Razvan Crainea <razvan@opensips.org>
Date: Thu, 1 Feb 2018 10:59:55 +0200
Subject: [PATCH] ratelimit: replicate the current counter for SBT

(cherry picked from commit 08bc17915bc113ee045f8a6d37257450a199c753)

diff --git a/modules/ratelimit/ratelimit_helper.c b/modules/ratelimit/ratelimit_helper.c
index 89a71501e..c803259c2 100644
--- a/modules/ratelimit/ratelimit_helper.c
+++ b/modules/ratelimit/ratelimit_helper.c
@@ -1030,7 +1030,13 @@ void rl_timer_repl(utime_t ticks, void *param)
 			if (bin_push_int(&packet, (*pipe)->limit) < 0)
 				goto error;
 
-			if ((ret = bin_push_int(&packet, (*pipe)->my_last_counter)) < 0)
+			/*
+			 * for the SBT algorithm it is safe to replicate the current
+			 * counter, since it is always updating according to the window
+			 */
+			if ((ret = bin_push_int(&packet,
+						((*pipe)->algo == PIPE_ALGO_HISTORY ?
+						 (*pipe)->counter : (*pipe)->my_last_counter))) < 0)
 				goto error;
 			nr++;