Sfoglia il codice sorgente

event_graph: fix bug: add NanoTimestamp::from_secs()

darkfi 1 anno fa
parent
commit
7d9d0f809e
2 ha cambiato i file con 6 aggiunte e 2 eliminazioni
  1. 2 2
      src/event_graph/proto.rs
  2. 4 0
      src/util/time.rs

+ 2 - 2
src/event_graph/proto.rs

@@ -38,10 +38,10 @@ const MALICIOUS_THRESHOLD: usize = 5;
 /// Global limit of messages per window
 const WINDOW_MAXSIZE: usize = 200;
 /// Rolling length of the window
-const WINDOW_EXPIRY_TIME: NanoTimestamp = NanoTimestamp(60);
+const WINDOW_EXPIRY_TIME: NanoTimestamp = NanoTimestamp::from_secs(60);
 
 /// Rolling length of the window
-const RATELIMIT_EXPIRY_TIME: NanoTimestamp = NanoTimestamp(10);
+const RATELIMIT_EXPIRY_TIME: NanoTimestamp = NanoTimestamp::from_secs(10);
 /// Ratelimit kicks in above this count
 const RATELIMIT_MIN_COUNT: usize = 6;
 /// Sample point used to calculate sleep time when ratelimit is active

+ 4 - 0
src/util/time.rs

@@ -112,6 +112,10 @@ impl NanoTimestamp {
         self.0
     }
 
+    pub const fn from_secs(secs: u128) -> Self {
+        Self(secs * 1_000_000_000)
+    }
+
     pub fn current_time() -> Self {
         Self(UNIX_EPOCH.elapsed().unwrap().as_nanos())
     }