From 477d3df1dda719b950213604d792eeec833a289c Mon Sep 17 00:00:00 2001 From: games647 Date: Wed, 13 May 2020 22:40:26 +0200 Subject: [PATCH] Favor nano time, because it's monotonic --- .../java/com/github/games647/fastlogin/core/AuthStorage.java | 2 +- .../java/com/github/games647/fastlogin/core/RateLimiter.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/com/github/games647/fastlogin/core/AuthStorage.java b/core/src/main/java/com/github/games647/fastlogin/core/AuthStorage.java index e9d0808c..904d5921 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/AuthStorage.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/AuthStorage.java @@ -70,7 +70,7 @@ public class AuthStorage { // adding paranoid hides hostname, username, version and so // could be useful for hiding server details - config.addDataSourceProperty("paranoid", "true"); + config.addDataSourceProperty("paranoid", true); // enable MySQL specific optimizations // disabled by default - will return the same prepared statement instance diff --git a/core/src/main/java/com/github/games647/fastlogin/core/RateLimiter.java b/core/src/main/java/com/github/games647/fastlogin/core/RateLimiter.java index 63e64244..9f422d2e 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/RateLimiter.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/RateLimiter.java @@ -21,8 +21,8 @@ public class RateLimiter { * @return true if allowed */ public boolean tryAcquire() { - // currentTime millis could be expensive on some systems - long now = System.currentTimeMillis(); + // current time millis is not monotonic - it can jump back depending on user choice or NTP + long now = System.nanoTime() / 1_000_000; // after this the request should be expired long toBeExpired = now - expireTime;