weirdnet_device_link/
lib.rs1mod bytes;
16pub mod compact;
17pub mod invite;
18pub mod net;
19pub mod offer;
20pub mod reach;
21pub mod relays;
22pub mod session;
23pub mod wire;
24
25pub use compact::KNOWN_RELAYS;
26pub use invite::{Invite, InviteHost, answer_invite, decode_invite, encode_invite, is_invite};
27pub use net::{HostNode, Pairing};
28pub use offer::{Offer, VerifiedOffer, decode_link, encode_link, is_offer, offer_addrs, offer_scheme};
29pub use reach::{known_relays, link_node_config, parse_relays, relay_groups, relays_from_env, with_link_limits};
30pub use relays::{RelayProbe, RelayState, relay_states};
31pub use session::{Host, HostStatus, Sender};
32pub use wire::{LinkReply, LinkRequest, Transfer};
33
34use weirdnet_net::profile::{Profile, WEIRDNET};
35
36pub const VERSION: u8 = 2;
39pub const OFFER_TTL_MS: i64 = 120_000;
41pub const MAX_ATTEMPTS: u32 = 3;
43
44pub static LINK_PROFILE: Profile = Profile { protocol: "/weirdnet/link/2", thread: "weirdnet-link", ..WEIRDNET };
47
48#[derive(Debug, thiserror::Error)]
49pub enum Error {
50 #[error("{0}")]
51 Invalid(&'static str),
52 #[error("this code is from an older version; update both devices")]
55 OlderCode,
56 #[error("this code is from a newer version; update this device")]
58 NewerCode,
59 #[error("this code expired; show a new one on the other device")]
60 Expired,
61 #[error("the other device refused: {0}")]
62 Refused(String),
63 #[error("{0}")]
66 Net(String),
67 #[error("keys: {0}")]
68 Keys(String),
69}
70
71impl From<weirdnet_keys::KeysError> for Error {
72 fn from(e: weirdnet_keys::KeysError) -> Self {
73 Error::Keys(e.to_string())
74 }
75}
76
77impl From<weirdnet_net::NetError> for Error {
78 fn from(e: weirdnet_net::NetError) -> Self {
79 Error::Net(e.to_string())
80 }
81}
82
83pub type Result<T, E = Error> = std::result::Result<T, E>;
84
85#[cfg(test)]
86mod relay_tests;
87
88#[cfg(test)]
89mod error_tests {
90 use super::*;
91
92 #[test]
93 fn network_errors_are_not_prefixed_twice() {
94 let e = Error::from(weirdnet_net::NetError::Network("the node did not start in time".into()));
95 assert_eq!(e.to_string(), "network: the node did not start in time");
96 }
97}