pub struct NodeStore { /* private fields */ }Implementations§
Source§impl NodeStore
impl NodeStore
Sourcepub fn open(path: &Path) -> Result<Self, String>
pub fn open(path: &Path) -> Result<Self, String>
Opens the registry, empty when the file does not exist. A file that exists and does not parse is an error, not an empty registry: silently forgetting every enrolled node would re-open every enrollment token.
Sourcepub fn mint_token(
&mut self,
name: &str,
projects: Vec<String>,
ttl_secs: i64,
now_secs: i64,
) -> Result<(String, i64), String>
pub fn mint_token( &mut self, name: &str, projects: Vec<String>, ttl_secs: i64, now_secs: i64, ) -> Result<(String, i64), String>
Mints a single-use enrollment token. Returns the plaintext once.
Sourcepub fn pair(
&mut self,
name: &str,
projects: Vec<String>,
pubkey_hex: &str,
listen: ListenInfo,
now_secs: i64,
now_iso: &str,
) -> Result<(NodeRecord, String), String>
pub fn pair( &mut self, name: &str, projects: Vec<String>, pubkey_hex: &str, listen: ListenInfo, now_secs: i64, now_iso: &str, ) -> Result<(NodeRecord, String), String>
Enrols a listening node from its pairing request, without a token changing hands (R12): the owner carries the node’s request in and the reply out, which is how a hub that opens no port (the desktop) learns a node. The token is minted and spent inside this call, so the usual checks (a free name, a real key, a bare https address) apply unchanged. Returns the node and the hub’s transport key, which the node pins.
Sourcepub fn enroll(
&mut self,
token: &str,
pubkey_hex: &str,
listen: Option<ListenInfo>,
now_secs: i64,
now_iso: &str,
) -> Result<NodeRecord, String>
pub fn enroll( &mut self, token: &str, pubkey_hex: &str, listen: Option<ListenInfo>, now_secs: i64, now_iso: &str, ) -> Result<NodeRecord, String>
Spends a token and registers the node’s public key.
Sourcepub fn authenticate(
&mut self,
node_id: &str,
method: &str,
path: &str,
ts_ms: i64,
body: &[u8],
sig_hex: &str,
now_ms: i64,
) -> Result<NodeRecord, AuthError>
pub fn authenticate( &mut self, node_id: &str, method: &str, path: &str, ts_ms: i64, body: &[u8], sig_hex: &str, now_ms: i64, ) -> Result<NodeRecord, AuthError>
Checks a signed request and, on success, advances the node’s replay mark.
Sourcepub fn hub_node_key(&mut self) -> Result<(String, String), String>
pub fn hub_node_key(&mut self) -> Result<(String, String), String>
The hub’s transport key for listening nodes as (seed, public), made on
first use.
Sourcepub fn listening(&self) -> Vec<NodeRecord>
pub fn listening(&self) -> Vec<NodeRecord>
Active nodes the hub has to dial.
Sourcepub fn mark_polled(&mut self, id: &str, now_iso: &str)
pub fn mark_polled(&mut self, id: &str, now_iso: &str)
Notes that the hub polled id just now.
pub fn list(&self) -> Vec<NodeRecord>
pub fn get(&self, id: &str) -> Option<NodeRecord>
Sourcepub fn find(&self, name_or_id: &str) -> Option<NodeRecord>
pub fn find(&self, name_or_id: &str) -> Option<NodeRecord>
Finds an active node by name or id.
pub fn revoke(&mut self, id: &str, now_iso: &str) -> Result<NodeRecord, String>
Sourcepub fn record_beat(
&mut self,
id: &str,
beat: &Beat,
desired: &dyn Fn(&TargetReport) -> Result<String, String>,
now_iso: &str,
) -> Result<(), String>
pub fn record_beat( &mut self, id: &str, beat: &Beat, desired: &dyn Fn(&TargetReport) -> Result<String, String>, now_iso: &str, ) -> Result<(), String>
Replaces a node’s observed state from a beat. desired is what the hub
would write for each target id (Ok(sha)), or why it will not (Err).
Sourcepub fn prune_projects(
&mut self,
existing: &[String],
) -> Result<Vec<(String, String)>, String>
pub fn prune_projects( &mut self, existing: &[String], ) -> Result<Vec<(String, String)>, String>
Drops grants for projects that no longer exist. A grant is a project NAME,
so without this a deleted project’s name would pass to whoever creates a
project of that name later. Returns (node name, project) for each grant removed.
Sourcepub fn accept(
&mut self,
id: &str,
target: &str,
expected: Option<&str>,
) -> Result<String, String>
pub fn accept( &mut self, id: &str, target: &str, expected: Option<&str>, ) -> Result<String, String>
Records the hash a human accepted into the vault for a pull target. Records the node’s current file for a pull target as accepted.
expected is the hash of the bytes the owner actually fetched and reviewed. Without
it, accept recorded whatever the node last reported, and a file that changed between
the fetch and the accept was accepted as in sync without anyone having seen it.
Source§impl NodeStore
impl NodeStore
Sourcepub fn lease_target(
&mut self,
node_id: &str,
target: &str,
sha256: &str,
holder: &str,
ttl_secs: i64,
now_secs: i64,
) -> Result<Lease, String>
pub fn lease_target( &mut self, node_id: &str, target: &str, sha256: &str, holder: &str, ttl_secs: i64, now_secs: i64, ) -> Result<Lease, String>
Takes a lease on target of node_id, or replaces the caller’s own. Refused while another
holder’s lease is alive, and for a lifetime over MAX_LEASE_SECS.
Sourcepub fn release_lease(
&mut self,
node_id: &str,
target: &str,
holder: &str,
now_secs: i64,
) -> Result<(), String>
pub fn release_lease( &mut self, node_id: &str, target: &str, holder: &str, now_secs: i64, ) -> Result<(), String>
Ends the lease on target, which only its holder may do. An expired lease is already gone.
Source§impl NodeStore
impl NodeStore
Sourcepub fn set_approval_policy(
&mut self,
id: &str,
policy: &str,
) -> Result<NodeRecord, String>
pub fn set_approval_policy( &mut self, id: &str, policy: &str, ) -> Result<NodeRecord, String>
Sets whether every push to a node is held for a human.
Sourcepub fn usable_approval(
&self,
node_id: &str,
target: &str,
sha: &str,
now_secs: i64,
) -> Option<ApprovalRecord>
pub fn usable_approval( &self, node_id: &str, target: &str, sha: &str, now_secs: i64, ) -> Option<ApprovalRecord>
The approval for exactly these bytes, if there is one and it can still be used: approved, within its lifetime, for an active node.
Sourcepub fn approval_for(
&self,
node_id: &str,
target: &str,
sha: &str,
) -> Option<ApprovalRecord>
pub fn approval_for( &self, node_id: &str, target: &str, sha: &str, ) -> Option<ApprovalRecord>
The newest request for these bytes in any state.
Sourcepub fn request_approval(
&mut self,
node_id: &str,
target: &TargetReport,
sha: &str,
from_seq: Option<i64>,
to_seq: Option<i64>,
now_secs: i64,
now_iso: &str,
) -> Result<ApprovalRecord, String>
pub fn request_approval( &mut self, node_id: &str, target: &TargetReport, sha: &str, from_seq: Option<i64>, to_seq: Option<i64>, now_secs: i64, now_iso: &str, ) -> Result<ApprovalRecord, String>
Opens a request for a human, unless one for the same bytes is already open, decided, or spent. A consumed or expired request for the same bytes (a revert) opens a fresh one: an old yes does not cover a later push.
Sourcepub fn decide(
&mut self,
approval_id: &str,
approve: bool,
by: &str,
now_secs: i64,
now_iso: &str,
) -> Result<ApprovalRecord, String>
pub fn decide( &mut self, approval_id: &str, approve: bool, by: &str, now_secs: i64, now_iso: &str, ) -> Result<ApprovalRecord, String>
A human’s answer. Only a pending request can be decided: an approval is never revived, and a decision on stale bytes is a decision on a request the hub no longer asks for.
Sourcepub fn add_approver(
&mut self,
pubkey_hex: &str,
label: &str,
now_iso: &str,
) -> Result<Approver, String>
pub fn add_approver( &mut self, pubkey_hex: &str, label: &str, now_iso: &str, ) -> Result<Approver, String>
Registers a device whose signature counts as the owner’s approval.
Sourcepub fn remove_approver(&mut self, fp_prefix: &str) -> Result<Approver, String>
pub fn remove_approver(&mut self, fp_prefix: &str) -> Result<Approver, String>
Removes a device by (a prefix of at least 8 characters of) its fingerprint.
Nodes set to device approval lose their only approver if this was the
last one: they fall back to required, so nothing is left unapprovable and
nothing silently becomes approvable by the hub alone.
pub fn approvers(&self) -> Vec<Approver>
Sourcepub fn decide_signed(
&mut self,
approval_id: &str,
signed: SignedApproval,
now_secs: i64,
now_iso: &str,
) -> Result<ApprovalRecord, String>
pub fn decide_signed( &mut self, approval_id: &str, signed: SignedApproval, now_secs: i64, now_iso: &str, ) -> Result<ApprovalRecord, String>
A human’s yes, signed on their own device. The hub holds no key that could have made it: it checks the signature against the registered devices, that the token names exactly this request (node, target, bytes, request id), and that its lifetime is no longer than the hub’s own.