places/history_sync/
mod.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5use serde_derive::*;
6use std::fmt;
7use std::time::{SystemTime, UNIX_EPOCH};
8use types::Timestamp;
9
10pub mod engine;
11#[cfg(test)]
12mod payload_evolution_tests;
13mod plan;
14pub mod record;
15
16pub use engine::HistorySyncEngine;
17
18const MAX_INCOMING_PLACES: usize = 5000;
19const MAX_OUTGOING_PLACES: usize = 5000;
20const MAX_VISITS: usize = 20;
21pub const HISTORY_TTL: u32 = 5_184_000; // 60 days in milliseconds
22
23/// Visit timestamps on the server are *microseconds* since the epoch.
24#[derive(
25    Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Deserialize, Serialize, Default,
26)]
27pub struct ServerVisitTimestamp(pub u64);
28
29impl From<ServerVisitTimestamp> for Timestamp {
30    #[inline]
31    fn from(ts: ServerVisitTimestamp) -> Timestamp {
32        Timestamp(ts.0 / 1000)
33    }
34}
35
36impl From<Timestamp> for ServerVisitTimestamp {
37    #[inline]
38    fn from(ts: Timestamp) -> ServerVisitTimestamp {
39        ServerVisitTimestamp(ts.0 * 1000)
40    }
41}
42
43impl From<SystemTime> for ServerVisitTimestamp {
44    #[inline]
45    fn from(st: SystemTime) -> Self {
46        let d = st.duration_since(UNIX_EPOCH).unwrap_or_default();
47        ServerVisitTimestamp(d.as_secs() * 1_000_000 + (u64::from(d.subsec_nanos()) / 1_000))
48    }
49}
50
51impl fmt::Display for ServerVisitTimestamp {
52    #[inline]
53    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
54        write!(f, "{}", self.0)
55    }
56}