Blob Blame 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 65084f81a..104b4a9f4 100644
--- a/modules/ratelimit/ratelimit_helper.c
+++ b/modules/ratelimit/ratelimit_helper.c
@@ -1056,7 +1056,12 @@ void rl_timer_repl(utime_t ticks, void *param)
 			if (bin_push_int((*pipe)->limit) < 0)
 				goto error;
 
-			if ((ret = bin_push_int((*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(((*pipe)->algo == PIPE_ALGO_HISTORY ?
+						 (*pipe)->counter : (*pipe)->my_last_counter))) < 0)
 				goto error;
 			nr++;