فهرست منبع

net/ lilith: change last_seen to use UNIXEPOCH instead of SystemTime

lunar-mining 2 سال پیش
والد
کامیت
cf3642fb3a
4فایلهای تغییر یافته به همراه10 افزوده شده و 17 حذف شده
  1. 2 3
      bin/lilith/src/main.rs
  2. 3 4
      src/net/hosts.rs
  3. 2 3
      src/net/protocol/protocol_seed.rs
  4. 3 7
      src/net/session/outbound_session.rs

+ 2 - 3
bin/lilith/src/main.rs

@@ -21,7 +21,7 @@ use std::{
     path::Path,
     path::Path,
     process::exit,
     process::exit,
     sync::Arc,
     sync::Arc,
-    time::SystemTime,
+    time::UNIX_EPOCH,
 };
 };
 
 
 use async_trait::async_trait;
 use async_trait::async_trait;
@@ -216,8 +216,7 @@ impl Lilith {
                                     channel.stop().await;
                                     channel.stop().await;
 
 
                                     // Peer is responsive. Update last_seen and add it to the whitelist.
                                     // Peer is responsive. Update last_seen and add it to the whitelist.
-                                    let last_seen =
-                                        SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs();
+                                    let last_seen = UNIX_EPOCH.elapsed().unwrap().as_secs();
 
 
                                     // Remove oldest element if the whitelist reaches max size.
                                     // Remove oldest element if the whitelist reaches max size.
                                     if whitelist.len() == 1000 {
                                     if whitelist.len() == 1000 {

+ 3 - 4
src/net/hosts.rs

@@ -597,7 +597,7 @@ impl Hosts {
 #[cfg(test)]
 #[cfg(test)]
 mod tests {
 mod tests {
     use super::{super::settings::Settings, *};
     use super::{super::settings::Settings, *};
-    use std::time::SystemTime;
+    use std::time::UNIX_EPOCH;
 
 
     #[test]
     #[test]
     fn test_is_local_host() {
     fn test_is_local_host() {
@@ -638,7 +638,7 @@ mod tests {
 
 
     #[test]
     #[test]
     fn test_greylist_store() {
     fn test_greylist_store() {
-        let last_seen = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs();
+        let last_seen = UNIX_EPOCH.elapsed().unwrap().as_secs();
 
 
         smol::block_on(async {
         smol::block_on(async {
             let settings = Settings {
             let settings = Settings {
@@ -697,8 +697,7 @@ mod tests {
             assert!(hosts.is_empty_whitelist().await);
             assert!(hosts.is_empty_whitelist().await);
 
 
             let url = Url::parse("tcp://dark.renaissance:333").unwrap();
             let url = Url::parse("tcp://dark.renaissance:333").unwrap();
-            let last_seen =
-                SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs();
+            let last_seen = UNIX_EPOCH.elapsed().unwrap().as_secs();
 
 
             hosts.whitelist_store(&url, last_seen).await;
             hosts.whitelist_store(&url, last_seen).await;
 
 

+ 2 - 3
src/net/protocol/protocol_seed.rs

@@ -16,7 +16,7 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
  */
 
 
-use std::{sync::Arc, time::SystemTime};
+use std::{sync::Arc, time::UNIX_EPOCH};
 
 
 use async_trait::async_trait;
 use async_trait::async_trait;
 use log::debug;
 use log::debug;
@@ -72,8 +72,7 @@ impl ProtocolSeed {
         // from settings- that doesn't mean they will be reachable.
         // from settings- that doesn't mean they will be reachable.
         let mut addrs = vec![];
         let mut addrs = vec![];
         for addr in self.settings.external_addrs.clone() {
         for addr in self.settings.external_addrs.clone() {
-            let last_seen =
-                SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs();
+            let last_seen = UNIX_EPOCH.elapsed().unwrap().as_secs();
             addrs.push((addr, last_seen));
             addrs.push((addr, last_seen));
         }
         }
 
 

+ 3 - 7
src/net/session/outbound_session.rs

@@ -31,7 +31,7 @@ use std::{
         atomic::{AtomicU32, Ordering},
         atomic::{AtomicU32, Ordering},
         Arc, Weak,
         Arc, Weak,
     },
     },
-    time::{Duration, Instant, SystemTime},
+    time::{Duration, Instant, UNIX_EPOCH},
 };
 };
 
 
 use async_trait::async_trait;
 use async_trait::async_trait;
@@ -276,8 +276,7 @@ impl Slot {
             // Update the last_seen field for this whitelisted peer.
             // Update the last_seen field for this whitelisted peer.
             // TODO: This peer should also be flagged as an "anchor" because we have been
             // TODO: This peer should also be flagged as an "anchor" because we have been
             // able to establish a connection to it to it.
             // able to establish a connection to it to it.
-            let last_seen =
-                SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs();
+            let last_seen = UNIX_EPOCH.elapsed().unwrap().as_secs();
 
 
             hosts.whitelist_update(&addr_final, last_seen).await;
             hosts.whitelist_update(&addr_final, last_seen).await;
 
 
@@ -632,10 +631,7 @@ impl GreylistRefinery {
                                 channel.stop().await;
                                 channel.stop().await;
 
 
                                 // Peer is responsive. Update last_seen and add it to the whitelist.
                                 // Peer is responsive. Update last_seen and add it to the whitelist.
-                                let last_seen = SystemTime::now()
-                                    .duration_since(SystemTime::UNIX_EPOCH)
-                                    .unwrap()
-                                    .as_secs();
+                                let last_seen = UNIX_EPOCH.elapsed().unwrap().as_secs();
 
 
                                 // Remove oldest element if the whitelist reaches max size.
                                 // Remove oldest element if the whitelist reaches max size.
                                 if whitelist.len() == 1000 {
                                 if whitelist.len() == 1000 {