Added a handler for SIGUSR1, which toggles off/on the enforcement calls to tc.
[distributedratelimiting.git] / drl / drl_state.c
index 8583d0d..fed3326 100644 (file)
@@ -118,7 +118,7 @@ void free_comm(comm_t *comm) {
     }
 }
 
-int read_comm(comm_t *comm, double *aggregate) {
+int read_comm(comm_t *comm, double *aggregate, double decayto) {
     remote_limiter_t *remote;
 
     pthread_mutex_lock(&comm->lock);
@@ -131,9 +131,11 @@ int read_comm(comm_t *comm, double *aggregate) {
             *aggregate += remote->rate;
 
             /* If we continue to read it without having heard an update,
-             * we start to decay its value. */
+             * we start to make the peer's value approach decayto, getting
+             * half of the way there each time. */
             if (remote->awol >= REMOTE_AWOL_THRESHOLD) {
-                remote->rate = remote->rate / 2;
+                printlog(LOG_WARN, "AWOL remote limiter detected.\n");
+                remote->rate += ((decayto - remote->rate) / 2);
             } else {
                 remote->awol++;
             }
@@ -212,6 +214,7 @@ void *limiter_receive_thread(void *unused) {
 
     sigemptyset(&signal_mask);
     sigaddset(&signal_mask, SIGHUP);
+    sigaddset(&signal_mask, SIGUSR1);
     pthread_sigmask(SIG_BLOCK, &signal_mask, NULL);
 
     pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL);