summaryrefslogtreecommitdiffstats
path: root/src/document/replica.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/document/replica.rs')
-rw-r--r--src/document/replica.rs38
1 files changed, 19 insertions, 19 deletions
diff --git a/src/document/replica.rs b/src/document/replica.rs
index 0cab0be..fe76c12 100644
--- a/src/document/replica.rs
+++ b/src/document/replica.rs
@@ -20,14 +20,14 @@ use tokio::sync::watch;
/// * `id` is the hash of the epoch's snapshot change. It tells two epochs of the same
/// generation apart, which only happens if two remakes committed concurrently.
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
-pub struct Epoch {
- pub generation: u64,
- pub id: [u8; 32],
+pub(crate) struct Epoch {
+ pub(crate) generation: u64,
+ pub(crate) id: [u8; 32],
}
/// How a peer's epoch relates to ours.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
-pub enum EpochRelation {
+pub(crate) enum EpochRelation {
Same,
/// The peer is on an older generation and has to migrate.
PeerBehind,
@@ -39,12 +39,12 @@ pub enum EpochRelation {
impl Epoch {
/// Swarms that have never been compacted.
- pub const GENESIS: Epoch = Epoch {
+ pub(crate) const GENESIS: Epoch = Epoch {
generation: 0,
id: [0; 32],
};
- pub fn relation_to(&self, peer: &Epoch) -> EpochRelation {
+ pub(crate) fn relation_to(&self, peer: &Epoch) -> EpochRelation {
use std::cmp::Ordering;
match peer.generation.cmp(&self.generation) {
Ordering::Less => EpochRelation::PeerBehind,
@@ -54,7 +54,7 @@ impl Epoch {
}
}
- pub fn id_hex(&self) -> String {
+ pub(crate) fn id_hex(&self) -> String {
self.id.iter().map(|byte| format!("{byte:02x}")).collect()
}
}
@@ -90,12 +90,12 @@ impl fmt::Debug for Epoch {
/// The refresh also publishes a [`Stamp`], for what must not wait for the lock: a
/// tokio read lock waits behind a writer, and applying a large sync message holds the
/// write lock for seconds.
-pub struct Replica {
- pub epoch: Epoch,
+pub(crate) struct Replica {
+ pub(crate) epoch: Epoch,
/// How many times this node changed epoch (switch, rejoin, abandoned rejoin) in this
/// run: messages carry it, so a late one can't flip a peer's view of our epoch back.
- pub epoch_seq: u32,
- pub doc: AutoCommit,
+ pub(crate) epoch_seq: u32,
+ pub(crate) doc: AutoCommit,
heads: Vec<ChangeHash>,
stamp: watch::Sender<Stamp>,
}
@@ -103,15 +103,15 @@ pub struct Replica {
/// The epoch label and the heads of the replica, as of its last refresh, published
/// together: keepalives and HELLOs read them without the document's lock.
#[derive(Clone, Debug)]
-pub struct Stamp {
- pub epoch: Epoch,
- pub epoch_seq: u32,
+pub(crate) struct Stamp {
+ pub(crate) epoch: Epoch,
+ pub(crate) epoch_seq: u32,
/// Sorted.
- pub heads: Arc<[ChangeHash]>,
+ pub(crate) heads: Arc<[ChangeHash]>,
}
impl Replica {
- pub fn new(epoch: Epoch, doc: AutoCommit) -> Self {
+ pub(crate) fn new(epoch: Epoch, doc: AutoCommit) -> Self {
let (stamp, _) = watch::channel(Stamp {
epoch,
epoch_seq: 0,
@@ -129,13 +129,13 @@ impl Replica {
}
/// The document's heads as of the last refresh, sorted.
- pub fn heads(&self) -> &[ChangeHash] {
+ pub(crate) fn heads(&self) -> &[ChangeHash] {
&self.heads
}
/// Call after changing the document or its epoch (under the write lock). Publishes
/// the new [`Stamp`].
- pub fn refresh_heads(&mut self) {
+ pub(crate) fn refresh_heads(&mut self) {
self.heads = self.doc.get_heads();
self.heads.sort_unstable();
self.stamp.send_replace(Stamp {
@@ -146,7 +146,7 @@ impl Replica {
}
/// The published stamps, from the last refresh on.
- pub fn stamps(&self) -> watch::Receiver<Stamp> {
+ pub(crate) fn stamps(&self) -> watch::Receiver<Stamp> {
self.stamp.subscribe()
}
}