aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/swarm/bootstrap.rs2
-rw-r--r--src/swarm/members.rs18
-rw-r--r--src/swarm/peer/forget.rs5
3 files changed, 12 insertions, 13 deletions
diff --git a/src/swarm/bootstrap.rs b/src/swarm/bootstrap.rs
index 27b5e6b..7626d53 100644
--- a/src/swarm/bootstrap.rs
+++ b/src/swarm/bootstrap.rs
@@ -246,7 +246,7 @@ fn swarm_id_path() -> Vec<String> {
}
/// The swarm ID the document names, if any.
-fn read_swarm_id(doc: &Document) -> Option<String> {
+fn read_swarm_id(doc: &(impl crate::document::view::Read + ?Sized)) -> Option<String> {
match view::read_path(doc, &swarm_id_path()) {
Ok(Some(JsonValue::String(id))) if !id.is_empty() => Some(id),
_ => None,
diff --git a/src/swarm/members.rs b/src/swarm/members.rs
index 754b702..eac4d55 100644
--- a/src/swarm/members.rs
+++ b/src/swarm/members.rs
@@ -24,7 +24,6 @@ use std::time::Duration;
use serde_json::{Value as JsonValue, json};
use tracing::{debug, info, warn};
-use crate::document::Document;
use crate::document::meta;
use crate::document::store::StoreError;
use crate::document::view::{self, Read, Write};
@@ -74,7 +73,7 @@ fn tier_path(pk: &str) -> Vec<String> {
}
/// `pk`'s tier; transient unless its entry says stable.
-pub(crate) fn tier(doc: &Document, pk: &str) -> Tier {
+pub(crate) fn tier(doc: &(impl Read + ?Sized), pk: &str) -> Tier {
match view::read_path(doc, &tier_path(pk)) {
Ok(Some(JsonValue::String(tier))) if tier == "stable" => Tier::Stable,
_ => Tier::Transient,
@@ -112,7 +111,7 @@ pub(crate) fn party(doc: &(impl Read + ?Sized), pk: &str) -> Option<String> {
}
/// `pk`'s alias, if it gave itself one.
-pub(crate) fn alias(doc: &Document, pk: &str) -> Option<String> {
+pub(crate) fn alias(doc: &(impl Read + ?Sized), pk: &str) -> Option<String> {
match view::read_path(doc, &alias_path(pk)) {
Ok(Some(JsonValue::String(alias))) => Some(alias),
_ => None,
@@ -120,7 +119,7 @@ pub(crate) fn alias(doc: &Document, pk: &str) -> Option<String> {
}
/// The aliases of all members that have one.
-pub(crate) fn aliases(doc: &Document) -> HashMap<String, String> {
+pub(crate) fn aliases(doc: &(impl Read + ?Sized)) -> HashMap<String, String> {
members(doc)
.into_iter()
.filter_map(|pk| alias(doc, &pk).map(|alias| (pk, alias)))
@@ -148,7 +147,7 @@ fn dashboard_path(pk: &str) -> Vec<String> {
}
/// Where people reach `pk`'s dashboard, if it says.
-pub(crate) fn dashboard(doc: &Document, pk: &str) -> Option<String> {
+pub(crate) fn dashboard(doc: &(impl Read + ?Sized), pk: &str) -> Option<String> {
match view::read_path(doc, &dashboard_path(pk)) {
Ok(Some(JsonValue::String(url))) => Some(url),
_ => None,
@@ -182,7 +181,7 @@ const MAX_ADDRESSES: usize = 16;
/// Where `pk` says it can be reached (at most `MAX_ADDRESSES`); none if its entry
/// doesn't say.
-pub(crate) fn addresses(doc: &Document, pk: &str) -> Vec<String> {
+pub(crate) fn addresses(doc: &(impl Read + ?Sized), pk: &str) -> Vec<String> {
match view::read_path(doc, &addresses_path(pk)) {
Ok(Some(JsonValue::Array(items))) => items
.into_iter()
@@ -199,7 +198,7 @@ pub(crate) fn addresses(doc: &Document, pk: &str) -> Vec<String> {
/// What the member list tells this node besides who its neighbours are: where members
/// are (`learn_addresses`), what they call themselves (`set_aliases`), and the relays
/// listed (`relays`). Done whenever the neighbours are recomputed (`topology::refresh`).
-pub(crate) fn apply(state: &AppState, doc: &Document) {
+pub(crate) fn apply(state: &AppState, doc: &(impl Read + ?Sized)) {
learn_addresses(state, doc);
set_aliases(state, aliases(doc));
state.transport.learn_relays(&relays(doc));
@@ -220,7 +219,7 @@ fn set_aliases(state: &AppState, aliases: HashMap<String, String>) {
/// Hands every other member's addresses to the transport (`Transport::learn_addresses`):
/// the member list is how a node finds where members it never met are.
-pub(crate) fn learn_addresses(state: &AppState, doc: &Document) {
+pub(crate) fn learn_addresses(state: &AppState, doc: &(impl Read + ?Sized)) {
let me = state.local_id();
for pk in members(doc) {
if pk != me {
@@ -236,7 +235,7 @@ const MAX_RELAYS: usize = 32;
/// addresses (`libp2p:<multiaddr>`, with or without the relay's peer ID) of relays that
/// aren't members, e.g. nodes that only relay. Every member's transport may
/// pick them (`Transport::learn_relays`), after the relays it is configured with.
-pub(crate) fn relays(doc: &Document) -> Vec<String> {
+pub(crate) fn relays(doc: &(impl Read + ?Sized)) -> Vec<String> {
match view::read_path(doc, &meta::path(&[meta::RELAYS])) {
Ok(Some(JsonValue::Array(items))) => items
.into_iter()
@@ -571,6 +570,7 @@ pub(crate) fn unregister(doc: &mut (impl Write + ?Sized), pk: &str) -> Result<()
#[cfg(test)]
mod tests {
use super::*;
+ use crate::document::Document;
use crate::document::testing::change;
#[test]
diff --git a/src/swarm/peer/forget.rs b/src/swarm/peer/forget.rs
index 8616ae9..b911993 100644
--- a/src/swarm/peer/forget.rs
+++ b/src/swarm/peer/forget.rs
@@ -9,10 +9,9 @@ use serde_json::Value as JsonValue;
use tokio::time::Instant;
use tracing::{info, warn};
-use crate::document::Document;
use crate::document::meta;
use crate::document::store::StoreError;
-use crate::document::view;
+use crate::document::view::{self, Read};
use crate::state::{AppState, Standing};
fn forgotten_dir() -> Vec<String> {
@@ -32,7 +31,7 @@ pub(crate) fn affects_forget_records(path: &[String]) -> bool {
path.starts_with(&dir) || dir.starts_with(path)
}
-fn forgotten_peers(doc: &Document) -> Vec<String> {
+fn forgotten_peers(doc: &(impl Read + ?Sized)) -> Vec<String> {
view::keys_at(doc, &forgotten_dir())
.ok()
.flatten()