mod bytes;
pub mod compact;
pub mod invite;
pub mod net;
pub mod offer;
pub mod reach;
pub mod relays;
pub mod session;
pub mod wire;
pub use compact::KNOWN_RELAYS;
pub use invite::{Invite, InviteHost, answer_invite, decode_invite, encode_invite, is_invite};
pub use net::{HostNode, Pairing};
pub use offer::{Offer, VerifiedOffer, decode_link, encode_link, is_offer, offer_addrs, offer_scheme};
pub use reach::{known_relays, link_node_config, parse_relays, relay_groups, relays_from_env, with_link_limits};
pub use relays::{RelayProbe, RelayState, relay_states};
pub use session::{Host, HostStatus, Sender};
pub use wire::{LinkReply, LinkRequest, Transfer};
use weirdnet_net::profile::{Profile, WEIRDNET};
pub const VERSION: u8 = 2;
pub const OFFER_TTL_MS: i64 = 120_000;
pub const MAX_ATTEMPTS: u32 = 3;
pub static LINK_PROFILE: Profile = Profile { protocol: "/weirdnet/link/2", thread: "weirdnet-link", ..WEIRDNET };
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("{0}")]
Invalid(&'static str),
#[error("this code is from an older version; update both devices")]
OlderCode,
#[error("this code is from a newer version; update this device")]
NewerCode,
#[error("this code expired; show a new one on the other device")]
Expired,
#[error("the other device refused: {0}")]
Refused(String),
#[error("{0}")]
Net(String),
#[error("keys: {0}")]
Keys(String),
}
impl From<weirdnet_keys::KeysError> for Error {
fn from(e: weirdnet_keys::KeysError) -> Self {
Error::Keys(e.to_string())
}
}
impl From<weirdnet_net::NetError> for Error {
fn from(e: weirdnet_net::NetError) -> Self {
Error::Net(e.to_string())
}
}
pub type Result<T, E = Error> = std::result::Result<T, E>;
#[cfg(test)]
mod relay_tests;
#[cfg(test)]
mod error_tests {
use super::*;
#[test]
fn network_errors_are_not_prefixed_twice() {
let e = Error::from(weirdnet_net::NetError::Network("the node did not start in time".into()));
assert_eq!(e.to_string(), "network: the node did not start in time");
}
}