pub fn pair(
library: &mut Library,
network: &Network,
code: &PairingCode,
showing: Showing<'_>,
now: &dyn Fn() -> u64,
rng: &mut impl CryptoRng,
) -> Result<Paired, NodeError>Expand description
Pairs a new replica, as the sponsor: announces the code’s first two digits on the
network, waits as showing says for a replica to pair with the code, records it once it
says it made its library, and answers its first sync. network must take connections.
The code takes CODE_TRIES tries: the one in which it matches spends it, and so does
the last of those that fail before it matches; showing is told of the others. If the
first sync fails, the new replica’s records are deleted again, as the new replica
removes its library: the pairing failed. Changes are made at the time now gives when
they are made.
§Errors
Returns NodeError::PairingExpired if no replica paired in time, the error of the
last try if each failed before the code matched, such as NodeError::Sync with
SyncError::WrongCode if one typed another code, NodeError::PairingFailed if the
first sync failed, and other errors if the network or the library fails.