PeerTree.js is a deterministic, self‑healing, bounded‑degree tree network designed for building true distributed applications.
Nodes automatically join, leave, reorganize, and recover without centralized coordination.
PeerTree.js handles:
- topology
- membership
- routing
- broadcast
- fault recovery
- structural correctness
- cryptographic identity & message verification
- DNS‑free HTTPS transport
Developers focus only on application logic.
- Self‑organizing topology
- Deterministic join & drop logic
- Self‑healing behavior
- Efficient broadcast
- Cross‑tree isolation (523)
- Elliptic‑curve digital signatures
- DNS‑free HTTPS using self‑signed certificates
- Minimal API surface
- Scales to millions of nodes
PeerTree.js includes a built‑in security layer that ensures message authenticity, peer identity validation, and encrypted transport — without DNS, certificate authorities, or external trust systems.
Every PeerTree node generates an elliptic‑curve keypair (secp256k1).
All messages are:
- signed by the sender
- verified by the receiver
- rejected if signatures fail
Each message includes:
remPublicKey— sender’s public keysignature— ECDSA signatureremMUID— derived address (Bitcoin‑style P2PKH)msgTime— timestampremIp— sender’s IP
A message is accepted only if:
remPublicKeyexistsremMUIDmatches the public key’s P2PKH addressborgIOSkeymatches the local node’s keysignatureis valid forhash(remIp + msgTime)treeIdmatches (unless it’s a join request)
If any check fails: the msg is rejected. This prevents spoofing, impersonation, replay attacks, and unauthorized commands.
PeerTree.js uses HTTPS with self‑signed certificates for all communication.
- No DNS required
- No certificate authority required
- No external trust dependencies
- Works in isolated networks
- Works with dynamic IPs
- Works in peer‑to‑peer environments
Each node:
- generates its own self‑signed certificate
- exposes an HTTPS endpoint
- validates peers using cryptographic signatures, not DNS
This creates a fully encrypted, trustless, peer‑to‑peer transport layer.
Each tree has a unique treeId.
Nodes reject all foreign‑tree messages except join negotiation:
This prevents:
- routing contamination
- accidental merging
- cross‑organism interference
PeerTree.js maintains a bounded‑degree tree:
- each node has at most
maxPeerschildren - routing tables propagate deterministically
- the
lastNodepointer tracks the growth tip - join and drop events update structure automatically
If a structural rule fails, nodes regroup and form a new tree.
Broadcasts propagate downward in parallel: root → children → grandchildren → ...
Broadcast time: O(depth)
With maxPeers = 100, a million‑node tree is only ~3–4 layers deep.
Routing uses deterministic tables:
- no global lookup
- no DHT
- no gossip
- no loops
Replies follow the reverse path.
PeerTree.js handles three drop cases:
- Case 1: only child
- Case 2: last child
- Case 3: middle child
Each case has deterministic rules for:
- reassigning lastNode
- updating routing tables
- maintaining structure
If a drop transition fails, nodes automatically re‑discover and re‑form a valid tree.
For 1,000,000 nodes:
| maxPeers | Depth | Broadcast Time (10ms hop) |
|---|---|---|
| 3 | ~13 | ~130ms |
| 10 | ~5 | ~50ms |
| 25 | ~4 | ~40ms |
| 100 | ~3 | ~30ms |
Flat trees = fast broadcasts + strong verification.
PeerTree.js supports efficient broadcast verification:
- one bottom node per parent acts as a sentinel
- it queries its siblings
- replies with an aggregated count
Verification overhead: O(N / maxPeers²)
This becomes extremely small for large maxPeers.
PeerTree.js is ideal for:
- distributed storage
- decentralized messaging
- multi‑agent systems
- swarm intelligence
- real‑time collaboration
- distributed compute
- simulation environments
Anything requiring large‑scale, low‑latency, self‑organizing behavior fits naturally.
📄 License MIT
🤝 Contributing Pull requests welcome. Please open issues for bugs, questions, or feature requests.