gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-wallet-core] branch master updated: fix utterly broken throttling


From: gnunet
Subject: [taler-wallet-core] branch master updated: fix utterly broken throttling logic
Date: Fri, 04 Sep 2020 12:48:33 +0200

This is an automated email from the git hooks/post-receive script.

dold pushed a commit to branch master
in repository wallet-core.

The following commit(s) were added to refs/heads/master by this push:
     new ccaac89c fix utterly broken throttling logic
ccaac89c is described below

commit ccaac89c3b90ca6d1cce4813fd273f675d6f5802
Author: Florian Dold <florian.dold@gmail.com>
AuthorDate: Fri Sep 4 16:17:32 2020 +0530

    fix utterly broken throttling logic
---
 packages/taler-wallet-core/src/util/RequestThrottler.ts | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/packages/taler-wallet-core/src/util/RequestThrottler.ts 
b/packages/taler-wallet-core/src/util/RequestThrottler.ts
index f01e4395..8c9f304e 100644
--- a/packages/taler-wallet-core/src/util/RequestThrottler.ts
+++ b/packages/taler-wallet-core/src/util/RequestThrottler.ts
@@ -21,7 +21,7 @@
 /**
  * Imports.
  */
-import { getTimestampNow, timestampDifference } from "../util/time";
+import { getTimestampNow, timestampDifference, timestampCmp } from 
"../util/time";
 import { URL } from "./url";
 import { Logger } from "./logging";
 
@@ -53,25 +53,26 @@ class OriginState {
 
   private refill(): void {
     const now = getTimestampNow();
+    if (timestampCmp(now, this.lastUpdate) < 0) {
+      // Did the system time change?
+      this.lastUpdate = now;
+      return;
+    }
     const d = timestampDifference(now, this.lastUpdate);
     if (d.d_ms === "forever") {
       throw Error("assertion failed");
     }
-    if (d.d_ms < 0) {
-      return;
-    }
-    const d_s = d.d_ms / 1000;
     this.tokensSecond = Math.min(
       MAX_PER_SECOND,
-      this.tokensSecond + d_s / 1000,
+      this.tokensSecond + d.d_ms / 1000,
     );
     this.tokensMinute = Math.min(
       MAX_PER_MINUTE,
-      this.tokensMinute + (d_s / 1000) * 60,
+      this.tokensMinute + d.d_ms / 1000 / 60,
     );
     this.tokensHour = Math.min(
       MAX_PER_HOUR,
-      this.tokensHour + (d_s / 1000) * 60 * 60,
+      this.tokensHour + d.d_ms / 1000 / 60 / 60,
     );
     this.lastUpdate = now;
   }

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]