aboutsummaryrefslogtreecommitdiffstats
path: root/src/config/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/config/mod.rs')
-rw-r--r--src/config/mod.rs83
1 files changed, 70 insertions, 13 deletions
diff --git a/src/config/mod.rs b/src/config/mod.rs
index efc190d..e68b60c 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -216,6 +216,30 @@ pub(crate) const OPTIONS: &[OptionSpec] = &[
),
#[cfg(feature = "federation")]
option(
+ "store-document",
+ Kind::Text,
+ "PATH",
+ None,
+ "With store-root or store-id: hold the store in a document of its own kind, a set of events (docs/document.md), kept in this file, instead of in the Automerge document a swarm syncs otherwise. The node then syncs with nodes holding such a set, and with no others: a swarm is of one kind. The file holds the store's events, what the node refused of its own and what its operator had it drop, and its members' entries; started again, the node goes on from it. Without the file yet, the node begins it from the root where it is given one (store-root) and pins no checkpoint; else it joins with nothing, and gathers of the members it reaches what its set begins from, by name: the root, or the checkpoint store-checkpoint names. Can't be combined with store-file, which the file stands for.",
+ ),
+ #[cfg(feature = "federation")]
+ option(
+ "store-both",
+ Kind::Flag,
+ "BOOL",
+ Some("false"),
+ "With store-document: hold the store in the Automerge document too, and sync with nodes of either kind, taking into each what the other holds: an event that comes by one goes on by the other, and the node's entry is in both. For moving a running swarm to sets of events node by node (docs/document.md, From an Automerge document to this): a node is started with it, on the document it has, and without it once no node it reaches holds the Automerge document alone. Without the set's file yet, the set begins from the store as the node reads it of its document.",
+ ),
+ #[cfg(feature = "federation")]
+ option(
+ "store-keeps-forgotten",
+ Kind::Duration,
+ "DURATION",
+ Some("30d"),
+ "With store-document: for how long the node keeps what a checkpoint its store moved to forgot, for nodes still before that checkpoint, which build it from that. A node behind for longer starts from a checkpoint its operator pins.",
+ ),
+ #[cfg(feature = "federation")]
+ option(
"store-checkpoint",
Kind::Text,
"ID",
@@ -809,6 +833,17 @@ pub(crate) struct Settings {
#[cfg(feature = "federation")]
pub(crate) store_checkpoint: Option<String>,
#[cfg(feature = "federation")]
+ pub(crate) store_document: Option<PathBuf>,
+ #[cfg(feature = "federation")]
+ #[serde(default)]
+ pub(crate) store_both: bool,
+ #[cfg(feature = "federation")]
+ #[serde(
+ default = "default_store_keeps_forgotten",
+ with = "crate::units::duration_option"
+ )]
+ pub(crate) store_keeps_forgotten: Duration,
+ #[cfg(feature = "federation")]
pub(crate) store_party: Option<String>,
#[cfg(feature = "federation")]
#[serde(default)]
@@ -1070,6 +1105,10 @@ fn default_neighbours() -> usize {
fn default_electorate_window() -> Duration {
Duration::from_secs(7 * 24 * 3600)
}
+#[cfg(feature = "federation")]
+fn default_store_keeps_forgotten() -> Duration {
+ Duration::from_secs(30 * 24 * 3600)
+}
fn default_clock_skew_warn() -> Duration {
Duration::from_secs(2)
}
@@ -1332,6 +1371,8 @@ impl Settings {
let of_a_store = [
("store-file", self.store_file.is_some()),
("store-checkpoint", self.store_checkpoint.is_some()),
+ ("store-document", self.store_document.is_some()),
+ ("store-both", self.store_both),
("store-party", self.store_party.is_some()),
("store-readers", !self.store_readers.is_empty()),
(
@@ -1355,6 +1396,14 @@ impl Settings {
return Ok(());
}
};
+ if self.store_document.is_some() && self.store_file.is_some() && !self.store_both {
+ bail!("store-document holds what store-file would: unset store-file");
+ }
+ if self.store_both && self.store_document.is_none() {
+ bail!(
+ "store-both: set store-document, the file of the set of events the node holds beside its Automerge document"
+ );
+ }
match &self.store_party {
None => bail!(
"{store}: set store-party, the party this node is of: in a swarm holding a store, nodes sync with the nodes its parties list, each as its party's"
@@ -1482,6 +1531,10 @@ impl Settings {
#[cfg(feature = "federation")]
("store-checkpoint", self.store_checkpoint.is_some()),
#[cfg(feature = "federation")]
+ ("store-document", self.store_document.is_some()),
+ #[cfg(feature = "federation")]
+ ("store-both", self.store_both),
+ #[cfg(feature = "federation")]
("store-party", self.store_party.is_some()),
#[cfg(feature = "federation")]
("store-readers", !self.store_readers.is_empty()),
@@ -1564,7 +1617,7 @@ fn command() -> Command {
with_options(::config::arguments::with_print_config(command), OPTIONS)
}
-/// `continuum node-id FILE`: the node ID of the key in `FILE` (`Loaded::node_id`).
+/// `continuum node-id FILE`: the node ID of the key in `FILE` (`asked_node_id`).
const NODE_ID: &str = "node-id";
/// The configuration, and where each value set came from (absent: default).
@@ -1575,9 +1628,6 @@ pub(crate) struct Loaded {
pub(crate) files: Vec<PathBuf>,
/// `--print-config`: print [`Loaded::report`] and exit.
pub(crate) print_only: bool,
- /// `node-id FILE [--create]`: print the node ID of the key `FILE` holds, made there
- /// with `--create` where there is none, and exit.
- pub(crate) node_id: Option<(PathBuf, bool)>,
}
impl Loaded {
@@ -1647,22 +1697,30 @@ pub(crate) fn load() -> Result<Loaded> {
::config::arguments::refuse_gone(std::env::args().skip(1), &SCHEMA)?;
let matches = command().get_matches();
let print_only = ::config::arguments::prints_config(&matches);
- let node_id = matches.subcommand_matches(NODE_ID).map(|sub| {
- let file = sub.get_one::<String>("file").expect("required");
- (PathBuf::from(file), sub.get_flag("create"))
- });
- if print_only || node_id.is_some() {
- // Logs go to stdout too: the report or the node ID goes there alone (the report
- // says where each value came from anyway).
+ if print_only {
+ // Logs go to stdout too: the report goes there alone (it says where each value
+ // came from anyway).
let _ = crate::logging::set_filter("off");
}
let (merged, files) = merged(&matches, &SCHEMA, &[])?;
let mut loaded = resolve(merged, files)?;
loaded.print_only = print_only;
- loaded.node_id = node_id;
Ok(loaded)
}
+/// `node-id FILE [--create]`, where the command line asks for it: the file whose key's
+/// node ID to print, made there with `--create` where there is none. Asked before
+/// the configuration is read: it needs none of a node's, which a party's founders
+/// don't have yet as they ask for their nodes' IDs.
+pub(crate) fn asked_node_id() -> Option<(PathBuf, bool)> {
+ let matches = command().get_matches();
+ let sub = matches.subcommand_matches(NODE_ID)?;
+ let file = sub.get_one::<String>("file").expect("required");
+ // Logs go to stdout too: the node ID goes there alone.
+ let _ = crate::logging::set_filter("off");
+ Some((PathBuf::from(file), sub.get_flag("create")))
+}
+
/// HyParView's active view, where `neighbours` isn't set: the paper's, for swarms of up
/// to about 10 000 members (its fanout of 4, plus one).
const HYPARVIEW_NEIGHBOURS: usize = 5;
@@ -1768,7 +1826,6 @@ fn resolve(merged: Layer, files: Vec<PathBuf>) -> Result<Loaded> {
.collect(),
files,
print_only: false,
- node_id: None,
})
}