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