summaryrefslogtreecommitdiffstats
path: root/src/state.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/state.rs')
-rw-r--r--src/state.rs15
1 files changed, 7 insertions, 8 deletions
diff --git a/src/state.rs b/src/state.rs
index 78b058c..46ebfb9 100644
--- a/src/state.rs
+++ b/src/state.rs
@@ -676,6 +676,8 @@ pub(crate) struct AppState {
/// A catch-up source given up for not answering our sync messages, and until when it
/// isn't chosen again (`swarm::source`).
pub(crate) catch_up_avoided: Arc<std::sync::Mutex<Option<(String, Instant)>>>,
+ /// The node's wall clock (`clock`).
+ pub(crate) clock: Arc<crate::clock::Clock>,
}
/// The peer a catching-up node syncs with first (`swarm::source`).
@@ -913,7 +915,7 @@ impl AppState {
// how long the change took to reach them (`swarm::stats`).
replica.doc.commit_with(
automerge::transaction::CommitOptions::default()
- .with_time(unix_millis() as i64),
+ .with_time(state.clock.now_millis() as i64),
);
}
// Discard partial ops (e.g. old value deleted, new one not written).
@@ -1087,19 +1089,16 @@ impl AppState {
}
}
-pub(crate) fn unix_millis() -> u64 {
- std::time::SystemTime::now()
- .duration_since(std::time::UNIX_EPOCH)
- .map(|d| d.as_millis() as u64)
- .unwrap_or(0)
-}
-
/// The node as seen by the remake module.
impl Host for AppState {
fn remake(&self) -> &RemakeState {
&self.remake
}
+ fn clock(&self) -> Arc<crate::clock::Clock> {
+ Arc::clone(&self.clock)
+ }
+
fn node_id(&self) -> String {
self.local_id().to_owned()
}