aboutsummaryrefslogtreecommitdiffstats
path: root/src/swarm
diff options
context:
space:
mode:
Diffstat (limited to 'src/swarm')
-rw-r--r--src/swarm/dissemination.rs10
-rw-r--r--src/swarm/flood.rs6
-rw-r--r--src/swarm/plumtree.rs14
-rw-r--r--src/swarm/refusals.rs15
-rw-r--r--src/swarm/relay.rs4
-rw-r--r--src/swarm/sync.rs10
-rw-r--r--src/swarm/tree.rs8
7 files changed, 37 insertions, 30 deletions
diff --git a/src/swarm/dissemination.rs b/src/swarm/dissemination.rs
index 4c15d0f..11d9295 100644
--- a/src/swarm/dissemination.rs
+++ b/src/swarm/dissemination.rs
@@ -11,7 +11,7 @@
use async_trait::async_trait;
use tracing::trace;
-use crate::document::ChangeHash;
+use crate::document::UnitId;
use crate::state::AppState;
use crate::swarm::tree::Plan;
@@ -34,7 +34,7 @@ pub(crate) trait Dissemination: Send + Sync + 'static {
state: &AppState,
writer: u64,
from: &str,
- changes: &[ChangeHash],
+ changes: &[UnitId],
) -> Option<Plan>;
/// What a sync message from `peer` says about how well this works (`/admin/stats`):
@@ -46,7 +46,7 @@ pub(crate) trait Dissemination: Send + Sync + 'static {
peer: &str,
writer: Option<u64>,
carried: bool,
- authors: &[(String, Vec<ChangeHash>)],
+ authors: &[(String, Vec<UnitId>)],
);
/// `peer` asks us to send it `writer`'s changes at once (`eager`, a GRAFT) or to
@@ -59,7 +59,7 @@ pub(crate) trait Dissemination: Send + Sync + 'static {
/// `peer` told us of `heads` we lack (a STATUS: an announcement, or its keepalive's),
/// for a way that minds which neighbour has changes first (PlumTree). By default
/// nothing.
- fn announced(&self, peer: &str, heads: &[ChangeHash]) {
+ fn announced(&self, peer: &str, heads: &[UnitId]) {
let _ = (peer, heads);
}
@@ -83,7 +83,7 @@ pub(crate) async fn pass_on(
state: &AppState,
writer: u64,
from: &str,
- changes: &[ChangeHash],
+ changes: &[UnitId],
mut plan: Plan,
) -> Plan {
if !changes.is_empty() {
diff --git a/src/swarm/flood.rs b/src/swarm/flood.rs
index 39cb096..2883f80 100644
--- a/src/swarm/flood.rs
+++ b/src/swarm/flood.rs
@@ -8,7 +8,7 @@
use async_trait::async_trait;
-use crate::document::ChangeHash;
+use crate::document::UnitId;
use crate::state::AppState;
use crate::swarm::dissemination::{Dissemination, pass_on};
use crate::swarm::topology;
@@ -41,7 +41,7 @@ impl Dissemination for Flood {
state: &AppState,
writer: u64,
from: &str,
- changes: &[ChangeHash],
+ changes: &[UnitId],
) -> Option<Plan> {
let plan = self.plan(state, writer).await?;
Some(pass_on(state, writer, from, changes, plan).await)
@@ -55,7 +55,7 @@ impl Dissemination for Flood {
peer: &str,
writer: Option<u64>,
carried: bool,
- authors: &[(String, Vec<ChangeHash>)],
+ authors: &[(String, Vec<UnitId>)],
) {
let _ = peer;
if writer.is_some() && carried && authors.is_empty() {
diff --git a/src/swarm/plumtree.rs b/src/swarm/plumtree.rs
index 9560b9f..340fa68 100644
--- a/src/swarm/plumtree.rs
+++ b/src/swarm/plumtree.rs
@@ -45,7 +45,7 @@ use async_trait::async_trait;
use tokio::time::Instant;
use tracing::debug;
-use crate::document::ChangeHash;
+use crate::document::UnitId;
use crate::locks::MutexExt;
use crate::state::AppState;
use crate::swarm::dissemination::{Dissemination, pass_on};
@@ -99,7 +99,7 @@ const SETTLE_UNKNOWN: Duration = Duration::from_secs(2);
#[derive(Default)]
pub(crate) struct PlumTree {
lazy: Mutex<HashSet<String>>,
- announced: Mutex<HashMap<ChangeHash, (String, Instant)>>,
+ announced: Mutex<HashMap<UnitId, (String, Instant)>>,
ahead_times: Mutex<HashMap<String, u32>>,
/// When we last grafted each link (`settling`).
grafted: Mutex<HashMap<String, Instant>>,
@@ -124,7 +124,7 @@ impl PlumTree {
/// pushes in a row: its link is the faster, by at least an announcement's delay
/// (`relay::ANNOUNCE_DELAY`), which a push over it doesn't wait. The changes are
/// forgotten as announced.
- fn ahead(&self, peer: &str, authors: &[(String, Vec<ChangeHash>)]) -> Option<String> {
+ fn ahead(&self, peer: &str, authors: &[(String, Vec<UnitId>)]) -> Option<String> {
let now = Instant::now();
let told: Vec<(String, Instant)> = {
let mut announced = self.announced.lock_or_recover();
@@ -186,7 +186,7 @@ impl PlumTree {
}
/// The changes, come another way, are forgotten as announced.
- fn forget_announced(&self, authors: &[(String, Vec<ChangeHash>)]) {
+ fn forget_announced(&self, authors: &[(String, Vec<UnitId>)]) {
let mut announced = self.announced.lock_or_recover();
for change in authors.iter().flat_map(|(_, changes)| changes) {
announced.remove(change);
@@ -241,7 +241,7 @@ impl Dissemination for PlumTree {
state: &AppState,
writer: u64,
from: &str,
- changes: &[ChangeHash],
+ changes: &[UnitId],
) -> Option<Plan> {
let plan = self.plan(state, writer).await?;
Some(pass_on(state, writer, from, changes, plan).await)
@@ -262,7 +262,7 @@ impl Dissemination for PlumTree {
peer: &str,
writer: Option<u64>,
carried: bool,
- authors: &[(String, Vec<ChangeHash>)],
+ authors: &[(String, Vec<UnitId>)],
) {
match writer {
Some(writer) if carried && authors.is_empty() => {
@@ -304,7 +304,7 @@ impl Dissemination for PlumTree {
}
/// The first to tell us of each head is the one noticed.
- fn announced(&self, peer: &str, heads: &[ChangeHash]) {
+ fn announced(&self, peer: &str, heads: &[UnitId]) {
let mut announced = self.announced.lock_or_recover();
if announced.len() + heads.len() > MAX_ANNOUNCED {
announced.clear();
diff --git a/src/swarm/refusals.rs b/src/swarm/refusals.rs
index 652f9bc..bdc727e 100644
--- a/src/swarm/refusals.rs
+++ b/src/swarm/refusals.rs
@@ -18,7 +18,7 @@ use std::time::Duration;
use tracing::{debug, warn};
-use crate::document::ChangeHash;
+use crate::document::UnitId;
use crate::document::replica::Epoch;
use crate::state::AppState;
use crate::transport::{ParsedMessage, RefusalsMessage};
@@ -34,13 +34,13 @@ pub(crate) async fn tell(
peer: &str,
epoch: Epoch,
epoch_seq: u32,
- mut changes: Vec<ChangeHash>,
+ mut changes: Vec<UnitId>,
) {
changes.truncate(MAX_LISTED);
let message = ParsedMessage::Refusals(RefusalsMessage {
epoch,
epoch_seq,
- changes,
+ changes: changes.into_iter().map(Into::into).collect(),
});
if let Err(error) = state.transport.send_message(peer, &message).await {
// Told again with the next refusal.
@@ -53,7 +53,12 @@ pub(crate) async fn tell(
pub(crate) async fn received(state: &AppState, peer: &str, message: RefusalsMessage) {
let doc = std::sync::Arc::clone(&state.doc);
let screening = std::sync::Arc::clone(&state.screening);
- let changes: Vec<ChangeHash> = message.changes.into_iter().take(MAX_LISTED).collect();
+ let changes: Vec<UnitId> = message
+ .changes
+ .into_iter()
+ .take(MAX_LISTED)
+ .map(Into::into)
+ .collect();
let judged = tokio::task::spawn_blocking(move || {
use crate::locks::MutexExt;
let replica = doc.blocking_read();
@@ -76,7 +81,7 @@ pub(crate) async fn received(state: &AppState, peer: &str, message: RefusalsMess
let mut refused = None;
let mut taken = Vec::new();
for hash in changes {
- match crate::access::rules::judge_held(&replica.doc, replica.epoch, &hash) {
+ match crate::access::rules::judge_held(&replica.doc, replica.epoch, &hash.into()) {
Some(Err(why)) => {
refused = Some((hash, why));
break;
diff --git a/src/swarm/relay.rs b/src/swarm/relay.rs
index 54749b0..560a41e 100644
--- a/src/swarm/relay.rs
+++ b/src/swarm/relay.rs
@@ -153,7 +153,7 @@ pub(crate) struct Pending {
pub(crate) async fn announce(
state: &AppState,
from: &str,
- writers: &[(u64, Vec<crate::document::ChangeHash>)],
+ writers: &[(u64, Vec<crate::document::UnitId>)],
unauthored: bool,
) {
if !state.initial_sync_done.load(Ordering::Acquire) {
@@ -343,6 +343,8 @@ pub(crate) async fn pull_after_grace(state: &AppState, peer: &str, remote: &tran
crate::document::changes::missing(&replica.doc, remote.heads.listed())
};
if !missing.is_empty() {
+ let missing: Vec<crate::document::UnitId> =
+ missing.into_iter().map(Into::into).collect();
state.dissemination().announced(peer, &missing);
let grace = state
.lock_rtt()
diff --git a/src/swarm/sync.rs b/src/swarm/sync.rs
index 006df9d..bb99547 100644
--- a/src/swarm/sync.rs
+++ b/src/swarm/sync.rs
@@ -484,9 +484,9 @@ pub(crate) async fn handle_sync(
bool,
bool,
bool,
- (Vec<(String, Vec<crate::document::ChangeHash>)>, bool),
+ (Vec<(String, Vec<crate::document::UnitId>)>, bool),
Option<std::time::Duration>,
- Option<(u32, Vec<crate::document::ChangeHash>)>,
+ Option<(u32, Vec<crate::document::UnitId>)>,
);
tokio::task::spawn_blocking(move || -> Result<Option<Applied>> {
let (payload_len, message) =
@@ -658,7 +658,7 @@ pub(crate) async fn handle_sync(
}
// Caught up: our other neighbours may lack what the source had.
if changed || just_caught_up {
- let writers: Vec<(u64, Vec<crate::document::ChangeHash>)> = authors
+ let writers: Vec<(u64, Vec<crate::document::UnitId>)> = authors
.into_iter()
.map(|(author, changes)| (crate::swarm::topology::pair_key(&author), changes))
.collect();
@@ -856,7 +856,7 @@ async fn download_and_apply_delta(
async fn own_changes(
state: &AppState,
seen_heads: &mut Vec<crate::document::ChangeHash>,
-) -> Option<Vec<crate::document::ChangeHash>> {
+) -> Option<Vec<crate::document::UnitId>> {
let replica = state.doc.read().await;
let before = std::mem::replace(seen_heads, replica.heads().to_vec());
if !crate::document::changes::holds_all(&replica.doc, &before) {
@@ -867,7 +867,7 @@ async fn own_changes(
.authors
.into_iter()
.find(|(author, _)| author == state.local_id())
- .map(|(_, hashes)| hashes)
+ .map(|(_, hashes)| hashes.into_iter().map(Into::into).collect())
}
pub(crate) async fn run_sync_worker(state: AppState, mut rx: mpsc::UnboundedReceiver<SyncEvent>) {
diff --git a/src/swarm/tree.rs b/src/swarm/tree.rs
index 4d5afd8..0dd4e31 100644
--- a/src/swarm/tree.rs
+++ b/src/swarm/tree.rs
@@ -388,7 +388,7 @@ pub(crate) async fn note_arrival(
peer: &str,
writer: Option<u64>,
carried: bool,
- authors: &[(String, Vec<crate::document::ChangeHash>)],
+ authors: &[(String, Vec<crate::document::UnitId>)],
) {
match writer {
Some(writer) if carried => {
@@ -663,7 +663,7 @@ pub(crate) async fn forward(
state: &AppState,
writer: u64,
from: &str,
- changes: &[crate::document::ChangeHash],
+ changes: &[crate::document::UnitId],
) -> Option<Plan> {
let plan = plan(state, writer).await?;
Some(crate::swarm::dissemination::pass_on(state, writer, from, changes, plan).await)
@@ -688,7 +688,7 @@ impl crate::swarm::dissemination::Dissemination for WritersTrees {
state: &AppState,
writer: u64,
from: &str,
- changes: &[crate::document::ChangeHash],
+ changes: &[crate::document::UnitId],
) -> Option<Plan> {
forward(state, writer, from, changes).await
}
@@ -699,7 +699,7 @@ impl crate::swarm::dissemination::Dissemination for WritersTrees {
peer: &str,
writer: Option<u64>,
carried: bool,
- authors: &[(String, Vec<crate::document::ChangeHash>)],
+ authors: &[(String, Vec<crate::document::UnitId>)],
) {
note_arrival(state, peer, writer, carried, authors).await;
}