aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/federation/held.rs50
1 files changed, 47 insertions, 3 deletions
diff --git a/src/federation/held.rs b/src/federation/held.rs
index ec3738f..508b2eb 100644
--- a/src/federation/held.rs
+++ b/src/federation/held.rs
@@ -34,6 +34,7 @@ use super::event::{self, Does, Event, Signed};
use super::fold::Federation;
use super::revision::Feature;
use super::store::memory::{Built, Offered, Store};
+use super::store::set::Set;
use super::store::{Fold, Id, Refused};
use super::version::Version;
use super::vote::{self, Act, Rules, Seen};
@@ -123,10 +124,51 @@ pub(crate) struct Voter {
pub(crate) rules: Rules,
}
+/// What carries the store: a document it is read from, or a set of events, which is
+/// the store's own document (`store::set`).
+enum Carried {
+ Store(Box<Store<Federation>>),
+ Set(Box<Set<Federation>>),
+}
+
+impl std::ops::Deref for Carried {
+ type Target = Store<Federation>;
+
+ fn deref(&self) -> &Store<Federation> {
+ match self {
+ Carried::Store(store) => store,
+ Carried::Set(set) => set.store(),
+ }
+ }
+}
+
+impl Carried {
+ fn offer(&mut self, bytes: Vec<u8>) -> Offered {
+ match self {
+ Carried::Store(store) => store.offer(bytes),
+ Carried::Set(set) => set.offer(bytes, Instant::now()),
+ }
+ }
+
+ fn drop_taken(&mut self, ids: &[Id]) -> Result<Vec<Id>, Refused> {
+ match self {
+ Carried::Store(store) => store.drop_taken(ids),
+ Carried::Set(set) => set.drop_taken(ids, Instant::now()),
+ }
+ }
+
+ fn allow(&mut self, ids: &[Id]) {
+ match self {
+ Carried::Store(store) => store.allow(ids),
+ Carried::Set(set) => set.allow(ids, Instant::now()),
+ }
+ }
+}
+
#[derive(Default)]
struct Inner {
/// None until a document holding a store holds its root.
- store: Option<Store<Federation>>,
+ store: Option<Carried>,
/// The document read from (`Replica::epoch_seq`), and its events read.
epoch_seq: Option<u32>,
read: HashSet<Id>,
@@ -322,7 +364,9 @@ impl Holding {
match started {
Ok(store) => {
info!(store = %id, refused = own.len(), dropped = dropped.len(), "Reading the store from the document");
- inner.store = Some(store.refusing(&own, &dropped, &writes));
+ inner.store = Some(Carried::Store(Box::new(
+ store.refusing(&own, &dropped, &writes),
+ )));
}
Err(why) => {
if inner.none.replace(id) != Some(id) {
@@ -968,7 +1012,7 @@ impl Holding {
/// `f` of the store, where the node holds one.
pub(crate) fn with<T>(&self, f: impl FnOnce(&Store<Federation>) -> T) -> Option<T> {
- self.inner.lock_or_recover().store.as_ref().map(f)
+ self.inner.lock_or_recover().store.as_deref().map(f)
}
/// What a remake's snapshot holds of the store: as this node reads it anew from