weirdnet-net 0.2.0

Weirdnet networking: a libp2p node (TCP, QUIC, Noise, Yamux, mDNS, Kademlia, relays, hole punching, AutoNAT) carrying the application's own request and response types, signed key-exchange offers and answers with short codes, invitation tokens and links, sealed exchange messaging, node identities, user certificates and cards, under versioned identifier profiles.
Documentation

weirdnet-net

Peer-to-peer networking for applications that keep their own data: a libp2p node, key exchanges with invitation tokens and links, sealed messaging over those exchanges, node identities, and user certificates and cards. The application brings its own request and response types, its own storage and its own policy; the crate brings the wire.

  • node: a Node<Q, R> over TCP and QUIC (or an in-memory transport for tests) with Noise and Yamux, mDNS, Kademlia, identify, ping, a relay client and an opt-in relay server, DCUtR hole punching and AutoNAT. The swarm runs on its own thread; the handle is blocking. Requests are the application's Q, answers its R (CBOR), answered by a Handler. NodeConfig::relay_limits sets what the relay server allows: RelayLimits::default() keeps libp2p's (2-minute, 128 KiB circuits, enough for hole punching and small requests), RelayLimits::unlimited() caps nothing, so circuits carry data. Key-only dialing: request_key(peer, …) finds a peer by its key alone (the DHT, then circuits through this node's relays and names servers); request_user(user_id, …) looks the user's record up and dials it.
  • names: where a peer is now. A PeerRecord (addresses and relay circuits, home relay, seq, expiry of at most a day) is signed by the node key and chained to the user key by the node's certificate; a Withdrawal, signed by one of the user's nodes with a higher seq, removes it and holds until it expires. Records go to the home relay's names server (/weirdnet/names/1: Node::register, discover, lookup; a node serves it with NodeConfig::names_server) and, while the device hosts something, to the Kademlia DHT under SHA-256("weirdnet/peer/" + user id) (put_entry, get_entries), where every storing node runs Profile::accept: valid signature, unrevoked certificate, unexpired, higher seq wins. _weirdnet.<name> TXT "v=1 user=<id>" binds a domain to a user (binding_txt, parse_binding).
  • exchange: signed offers and answers (Ed25519 node keys, fresh X25519 keys), the derived exchange key, a ten-digit short code and a fingerprint to compare out of band, tokens and links (invitations), scopes with an expiry, and sealed messages bound to the exchange and direction.
  • sealed: send a sealed request through the application's envelope and open the answer (call), and answer one only for the exchange's own, Noise-authenticated peer (serve).
  • invite: invitation automation over the application's records (Host) and messages (Ask, Say): connect (hello, then an offer delivered and answered on the spot or kept for the owner), answering on arrival when the host's decide says so, poll and settle for kept offers and undelivered answers, crossing offers settled on one exchange, trust on first use (known, pinned, impostor, names resolving to the pinned node), relay addresses for a peer and the addresses fit for invite links.
  • identity, user, sync, shard, addr: node identities through an IdentityStore, user certificates, revocations, cards and link grants, the linked-node sync key, dark-shard blobs as custodians carry them, and address helpers.

Every identifier on the wire or under a signature comes from a Profile. WEIRDNET is the default (/weirdnet/net/1, wnet-x1-offer:, weirdnet://join/, port 4747 and so on). An application with nodes already in the field passes its own profile with the values those nodes use, so nothing changes for them.

Key cryptography is not here: every derivation, seal and open goes through weirdnet-keys, and key backups and recovery stay there. Shard blobs and backups cross the network as opaque bytes. See SECURITY.md for the boundaries and what has not been checked.

use weirdnet_net::{WEIRDNET, Keypair, exchange::Token, profile::invite_scope};

let (anna, ben) = (Keypair::generate_ed25519(), Keypair::generate_ed25519());
let p = &WEIRDNET;
let (offer, secret) = p.offer(&anna, "anna", vec![], invite_scope("garden", "member"), 0, 60_000).unwrap();
let link = p.link(&p.offer_token(&offer).unwrap());
let Token::Offer(seen) = p.parse_token(&link).unwrap() else { unreachable!() };
p.verify_offer(&seen, 1).unwrap();
let (answer, on_ben) = p.answer(&ben, &seen, "ben", vec![], 1).unwrap();
let on_anna = p.complete(&answer, &offer, &secret[..]).unwrap();
assert_eq!(on_anna.short_code, on_ben.short_code);