-
Notifications
You must be signed in to change notification settings - Fork 1.1k
use SystemTime instead of Instant #2406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we only use Instant
across the codebase because SystemTime
is a very recent addition.
I can't think of any downside on using SystemTime
over Instant
so feel free to go ahead with these changes :)
@@ -50,6 +49,7 @@ use libp2p_swarm::{ | |||
use log::{debug, info, warn}; | |||
use smallvec::SmallVec; | |||
use std::collections::{BTreeMap, HashSet, VecDeque}; | |||
use std::time::SystemTime; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IF we end up merging this, we need to use instant::SystemTime
here.
@@ -697,7 +697,7 @@ where | |||
let inner = QueryInner::new(info); | |||
let id = self.queries.add_iter_closest(target.clone(), peers, inner); // (*) | |||
|
|||
// Instantly finish the query if we already have enough records. | |||
// SystemTimely finish the query if we already have enough records. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be an erroneous change :D
@@ -721,7 +721,7 @@ where | |||
/// After the initial publication of the record, it is subject to (re-)replication | |||
/// and (re-)publication as per the configured intervals. Periodic (re-)publication | |||
/// does not update the record's expiration in local storage, thus a given record | |||
/// with an explicit expiration will always expire at that instant and until then | |||
/// with an explicit expiration will always expire at that SystemTime and until then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This too.
Great to see this happening @laptou!
https://doc.rust-lang.org/nightly/std/time/struct.SystemTime.html I am not sure whether we rely on this property anywhere within the codebase.
Would it not be enough to use |
Replacing In order to serialize an let now = Instant::now();
let now_system_time = SystemTime::now();
if instant > now {
now_system_time + (instant - now)
} else {
now_system_time - (now - instant)
} |
Learned something today, thanks for the comments! |
This branch is based on the
master
branch in my fork, so it also contains the changes from #2405.In this PR, I changed all instances of
Instant
toSystemTime
in the Kademlia behaviour, because I am trying to make aRecordStore
that serializes the records to an SQLite database, butInstant
s are extremely resistant to serialization. For now, I have only modified the structures used by Kademlia and their transitive dependencies, so there are still many uses ofInstant
in the ping, mDNS, and gossipsub behaviours.