Skip to main content

fips_core/tree/
mod.rs

1//! Spanning Tree Protocol Entities
2//!
3//! Tree coordinates and parent declarations for the FIPS spanning tree.
4//! The spanning tree provides a routing topology where each node maintains
5//! a path to a common root, enabling greedy distance-based routing.
6
7mod coordinate;
8mod declaration;
9mod state;
10
11use thiserror::Error;
12
13use crate::{IdentityError, NodeAddr};
14
15pub use coordinate::{CoordEntry, TreeCoordinate};
16pub use declaration::ParentDeclaration;
17pub use state::TreeState;
18
19/// Errors related to spanning tree operations.
20#[derive(Debug, Error)]
21pub enum TreeError {
22    #[error("invalid tree coordinate: empty path")]
23    EmptyCoordinate,
24
25    #[error("invalid ancestry: does not reach claimed root")]
26    AncestryNotToRoot,
27
28    #[error("invalid ancestry: root declaration must contain only the sender")]
29    RootDeclarationMismatch,
30
31    #[error("invalid ancestry: non-root declaration must include a parent hop")]
32    AncestryTooShort,
33
34    #[error("invalid ancestry: sender {declared} does not match first path entry {ancestry}")]
35    AncestryNodeMismatch {
36        declared: NodeAddr,
37        ancestry: NodeAddr,
38    },
39
40    #[error(
41        "invalid ancestry: signed parent {declared} does not match first ancestry hop {ancestry}"
42    )]
43    AncestryParentMismatch {
44        declared: NodeAddr,
45        ancestry: NodeAddr,
46    },
47
48    #[error(
49        "invalid ancestry: advertised root {advertised} is not the minimum path entry {minimum}"
50    )]
51    AncestryRootNotMinimum {
52        advertised: NodeAddr,
53        minimum: NodeAddr,
54    },
55
56    #[error("signature verification failed for node {0:?}")]
57    InvalidSignature(NodeAddr),
58
59    #[error("sequence number regression: got {got}, expected > {expected}")]
60    SequenceRegression { got: u64, expected: u64 },
61
62    #[error("parent not in peers: {0:?}")]
63    ParentNotPeer(NodeAddr),
64
65    #[error("identity error: {0}")]
66    Identity(#[from] IdentityError),
67}
68
69#[cfg(test)]
70mod tests;