1pub mod store;
2pub use store::{Error, Store};
3
4use localtime::LocalTime;
5
6use crate::node::KnownAddress;
7use crate::prelude::NodeId;
8use crate::storage::{refs::RefsAt, ReadRepository, RemoteId};
9
10#[derive(Debug, Copy, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
12#[serde(rename_all = "camelCase")]
13#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
14pub struct SyncedAt {
15 pub oid: crate::git::Oid,
17 pub timestamp: LocalTime,
19}
20
21impl SyncedAt {
22 pub fn load<S: ReadRepository>(
24 repo: &S,
25 remote: RemoteId,
26 ) -> Result<Self, crate::git::raw::Error> {
27 let refs = RefsAt::new(repo, remote)?;
28 let oid = refs.at;
29
30 Self::new(oid, repo)
31 }
32
33 pub fn new<S: ReadRepository>(
35 oid: crate::git::Oid,
36 repo: &S,
37 ) -> Result<Self, crate::git::raw::Error> {
38 let timestamp = repo.commit(oid)?.time();
39 let timestamp = LocalTime::from_secs(timestamp.seconds() as u64);
40
41 Ok(Self { oid, timestamp })
42 }
43}
44
45impl Ord for SyncedAt {
46 fn cmp(&self, other: &Self) -> std::cmp::Ordering {
47 self.timestamp.cmp(&other.timestamp)
48 }
49}
50
51impl PartialOrd for SyncedAt {
52 fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
53 Some(self.cmp(other))
54 }
55}
56
57#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
59#[serde(rename_all = "camelCase")]
60pub struct SyncedSeed {
61 pub nid: NodeId,
63 pub addresses: Vec<KnownAddress>,
65 pub synced_at: SyncedAt,
67}