pub struct Node { /* private fields */ }Implementations§
Source§impl Node
impl Node
Sourcepub async fn start(
dir: &Path,
connector: &Connector,
) -> Result<(Self, Receiver<Message>)>
pub async fn start( dir: &Path, connector: &Connector, ) -> Result<(Self, Receiver<Message>)>
Starts this computer’s node. State (its key and the roster) lives in dir. Messages for
agents the app delivers to (Reach::App) come out of the returned inbox.
pub fn id(&self) -> EndpointId
Sourcepub fn network_id(&self) -> Option<String>
pub fn network_id(&self) -> Option<String>
The network’s id (its root key), once this computer is in one.
pub fn role(&self) -> Option<Role>
Sourcepub fn create(&self, name: &str) -> Result<String>
pub fn create(&self, name: &str) -> Result<String>
Starts a new network with this computer as its owner. Returns the recovery code: show it once; it is kept nowhere.
Sourcepub fn invite(&self) -> Result<String>
pub fn invite(&self) -> Result<String>
A one-time invite for another computer, good for an hour while this one stays on.
pub async fn join(&self, ticket: &str, name: &str) -> Result<()>
Sourcepub fn remove(&self, computer: &str, cascade: bool) -> Result<()>
pub fn remove(&self, computer: &str, cascade: bool) -> Result<()>
Takes a computer out of the network for good. cascade also voids every computer it
admitted: for one that was stolen.
Sourcepub fn promote(&self, computer: &str) -> Result<()>
pub fn promote(&self, computer: &str) -> Result<()>
The owner makes a computer an admin: it can invite and remove members.
Sourcepub fn recover(&self, code: &str) -> Result<()>
pub fn recover(&self, code: &str) -> Result<()>
Makes this computer the owner with the network’s recovery code, for when the owner was lost. Remove the old one afterwards.
Sourcepub fn set_agents(&self, agents: impl IntoIterator<Item = (Agent, Reach)>)
pub fn set_agents(&self, agents: impl IntoIterator<Item = (Agent, Reach)>)
What this computer offers. The first call opens it to letters, and the others hear at once (the hello that catches up with them, which a computer that was off may need for a removal it missed), so what waited for it while it started comes now.
Sourcepub fn set_senders(&self, senders: impl IntoIterator<Item = String>)
pub fn set_senders(&self, senders: impl IntoIterator<Item = String>)
Names the app sends letters as without offering them to the network: a hosted assistant that asks agents elsewhere but can’t be asked itself. Answers to its letters still come back.
Sourcepub fn set_rules(&self, rules: Vec<Rule>) -> Result<()>
pub fn set_rules(&self, rules: Vec<Rule>) -> Result<()>
Who on the other computers may write to this computer’s agents, the first match deciding. Answers to this computer’s own letters always pass, so a rule added while a request runs doesn’t strand it.
pub fn rules(&self) -> Vec<Rule>
Sourcepub fn set_network_name(&self, name: Option<String>)
pub fn set_network_name(&self, name: Option<String>)
What the app calls this network (home, work) when a computer is in several: the invites
it makes carry the name, so the computer that joins can call it the same (crate::read_invite).
Sourcepub fn set_reply_command(&self, command: impl Into<String>)
pub fn set_reply_command(&self, command: impl Into<String>)
The command agents the network knocks on run to reply (default codync-network).
Sourcepub async fn peers(&self) -> Result<Vec<Peer>>
pub async fn peers(&self) -> Result<Vec<Peer>>
Every computer in the network, asked now for what it offers.
Sourcepub fn directory(&self) -> Vec<Peer>
pub fn directory(&self) -> Vec<Peer>
Every computer in the network, as last heard, without asking anyone.
Sourcepub fn changes(&self) -> Receiver<()>
pub fn changes(&self) -> Receiver<()>
Changes whenever what Node::directory shows does: a computer joins or leaves, a role
or name changes, another computer offers different agents, or it starts or stops
answering. Ticks only; read the directory for what changed.
Sourcepub fn resolve(&self, name: &str) -> Result<Address>
pub fn resolve(&self, name: &str) -> Result<Address>
Where a bare agent name or a full agent@computer points: this computer first, then the
directory. Refuses a name more than one computer has, naming them.