PeerPigeon
The mesh: browsers and servers linked over WebRTC, with signed storage that replicates between them.
bash
npm install peerpigeonGitHub · npm · Quick start
What it gives an app
- A partial mesh. Each peer keeps between
minPeersandmaxPeerslinks, chosen and repaired as peers come and go, through FreeRTC relays. - Gossip and direct messages.
broadcastreaches the whole room;sendDirectreaches one peer, routed hop by hop across the mesh by CECR. - Encryption. A room cipher and per-peer keys:
broadcastEncryptedandsendEncryptedDirect. - Signed, synced storage. Records in five spaces, signed by their writers, synced to the room and kept on storage servers. See Storage.
- Relay choice. It joins the room's closest healthy relays, local ones first (how).
The node
js
import { PeerPigeonNode } from 'peerpigeon'
const node = new PeerPigeonNode({ networkId: 'my-app', sessionId: 'lobby', signalingServer: 'wss://peer.ooo/ws', automaticSignalingServer: true, storage: {} })
await node.start()Options
| Option | Default | What it does |
|---|---|---|
networkId | Your app's namespace. Peers meet only with the same network and room | |
sessionId | The room | |
signalingServer | The relay to start from | |
signalingServers | More relays, used if the registry is empty or unreachable | |
automaticSignalingServer | Choose the room's relays from the registry | |
relayDirectory | _relays.peer.ooo | DNS directory of direct relays (false to use only the registry) |
minPeers, maxPeers | How many links to keep | |
role | none | What this peer is, announced to relays ('storage') |
dialRoles | any | Dial only peers with these roles ([]: dial nobody, still answer) |
iceServers | FreeRTC's | ICE servers for WebRTC (FreeRTC's defaults are public STUN servers) |
crypto | on | false to leave encryption out; { keyPair } to be the same identity as on another device; { persistKeyPair: 'session' } to keep it for this tab only |
storage | off | Options to attach storage (replicate, servers, …) |
debug | off | PeerPigeon's own console messages |
Methods
| Method | |
|---|---|
start() | Join the room (opens storage when asked for) |
broadcast(data), broadcastReliable(data) | To everyone in the room; the reliable one tracks delivery |
sendDirect(peerId, data) | To one peer, across the mesh |
broadcastEncrypted(text), sendEncryptedDirect(peerId, text) | The same, encrypted |
getConnectedPeers() | The peers linked to this one |
getGlobalPeers(), getDiscoveredPeers() | Peers known in the room |
getPeerRole(peerId) | The role a relay listed a peer with |
connectToPeer(peerId) | Dial a peer now, whatever its role |
getKeyPair() | This node's identity, secret keys included |
currentRelay(), currentRelayName() | The relay in use, as a URL and as a name to show |
openStorage(sessionId, { owner }) | Another storage room, for example one owned by a single key |
storage | This node's storage (see Storage) |
storageServers | Its link to the storage servers |
destroy() | Leave and close everything |
Events
node.on(event, handler): ready, peerConnected, peerDisconnected, message, keyDiscovered, graphChanged, capacityChanged, deliveryProgress, deliveryComplete, deliveryTimeout, cecrStateChanged, error.
A message carries kind ('broadcast' or 'direct'), data, fromPeerId, encrypted, local (sent by this node) and hops.
In Node
The same package runs in Node, which is how storage servers and test peers run. WebRTC there comes from werift.