radicle: canonical reference rules

Introduce the `rules` module beneath `canonical`. The implementation follows
the Canonical References RIP[^0].

A `Rule` defines the DIDs and threshold required to get the canonical tip
for a reference (or set of references). Since a `Rule` has some specific
validation rules, there can be two versions of a `Rule`. The `RawRule` is one
that can be easily constructed, serialized, and deserialized. It must then be
validated into a `ValidRule`, which validates any constraints, and can be used
in the computing of a canonical tip.

For convenience, a set of `ValidRule`s is wrapped into the `Rules` type, which
also has a further constraint that each rule refers to a specific `refspec`.

[0]: 1d1ce874f7
This commit is contained in:
Fintan Halpenny 2024-07-09 09:02:22 +01:00 committed by Lorenz Leutgeb
parent fb8681f5bc
commit af6cf03acd
5 changed files with 1223 additions and 0 deletions

7
Cargo.lock generated
View File

@ -845,6 +845,12 @@ dependencies = [
"regex-syntax", "regex-syntax",
] ]
[[package]]
name = "fast-glob"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3afcf4effa2c44390b9912544582d5af29e10dc4c816c5dbebf748e1c7416faa"
[[package]] [[package]]
name = "faster-hex" name = "faster-hex"
version = "0.9.0" version = "0.9.0"
@ -2464,6 +2470,7 @@ dependencies = [
"crossbeam-channel", "crossbeam-channel",
"cyphernet", "cyphernet",
"emojis", "emojis",
"fast-glob",
"fastrand", "fastrand",
"git2", "git2",
"jsonschema", "jsonschema",

View File

@ -22,6 +22,7 @@ chrono = { workspace = true, features = ["clock"], optional = true }
colored = { workspace = true, optional = true } colored = { workspace = true, optional = true }
crossbeam-channel = { workspace = true } crossbeam-channel = { workspace = true }
cyphernet = { workspace = true, features = ["tor", "dns", "p2p-ed25519"] } cyphernet = { workspace = true, features = ["tor", "dns", "p2p-ed25519"] }
fast-glob = { version = "0.3.2" }
fastrand = { workspace = true } fastrand = { workspace = true }
git2 = { workspace = true, features = ["vendored-libgit2"] } git2 = { workspace = true, features = ["vendored-libgit2"] }
libc = { workspace = true } libc = { workspace = true }

View File

@ -1,3 +1,6 @@
pub mod rules;
pub use rules::{MatchedRule, RawRule, Rules, ValidRule};
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::fmt; use std::fmt;

File diff suppressed because it is too large Load Diff

View File

@ -477,6 +477,12 @@ impl AsRef<NonEmpty<Did>> for Delegates {
} }
} }
impl From<Did> for Delegates {
fn from(did: Did) -> Self {
Self(NonEmpty::new(did))
}
}
impl TryFrom<Vec<Did>> for Delegates { impl TryFrom<Vec<Did>> for Delegates {
type Error = DelegatesError; type Error = DelegatesError;