This commit is contained in:
Raven Scott
2026-05-20 20:19:20 -04:00
parent 040f1d05ea
commit d70060ec4e
365 changed files with 23547 additions and 431 deletions
+52
View File
@@ -0,0 +1,52 @@
# API: hyper-p2p-anycast-selector
**Protocol:** `anycast-selector/v1`
**Export:** `HyperP2PAnycastSelector`
## Constructor
```js
const mod = new HyperP2PAnycastSelector(opts)
```
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| `topic` | `string` \| `Buffer` | `null` | Hyperswarm topic; enables P2P when set |
| `keyPair` | `KeyPair` | random | Ed25519 key pair (`hypercore-crypto`) |
| `enableBackgroundTimers` | `boolean` | `false` | Periodic timers (keep false in unit tests) |
## Methods
| Method | Returns | Notes |
|--------|---------|-------|
| `close(...)` | See source | — |
| `getStats(...)` | See source | — |
| `ready(...)` | See source | — |
| `registerCapability(...)` | See source | — |
| `resolve(...)` | See source | — |
| `updateLatency(...)` | See source | — |
## Events
| Event | Description |
|-------|-------------|
| `closed` | Module-specific |
| `resolved` | Module-specific |
## Metrics
Call `getStats()` when implemented for counters (Wave 6 network modules always expose stats).
## P2P
When `topic` is set, `ready()` joins Hyperswarm and opens Protomux `anycast-selector/v1` via [`_shared/p2p-bare.js`](../_shared/p2p-bare.js).
## Testing
```bash
npm install
npm test
```
Integration: [`../../real_tests/integration/anycast-selector-two-node.js`](../../real_tests/integration/anycast-selector-two-node.js)
@@ -0,0 +1,22 @@
# Architecture: hyper-p2p-anycast-selector
Lowest-latency capability routing for Bare/Pear P2P overlays.
```mermaid
flowchart TB
App[Application] --> Mod[HyperP2PAnycastSelector]
Mod --> Mux[Protomux anycast-selector/v1]
Mux --> Swarm[Hyperswarm topic]
```
## Wire messages (gossip)
JSON envelopes via `gossipSend` when connected. Message `type` fields are module-specific; see `index.js` `onmessage` handler.
## Composition (Wave 6)
See [`../_shared/WAVE6_NETWORK_STACK.md`](../_shared/WAVE6_NETWORK_STACK.md) for pairing with network-stack modules.
## State
In-memory maps/arrays; merged from remote gossip when `topic` is configured.