Next-depth pass: network-stack, CRDTs, gossip, scheduling, experimental

Expand introspection helpers and getStats(protocol) across six categories
after the storage/trust giant pass.

network-stack (10): listPeerIds, hasPeer, bestPeer, listCircuitIds,
queueDepth, listPendingIds, and related helpers; protocol in getStats.

state-crdts: crdt-map has/size/entries; conflict-set size/isEmpty;
reactive-state size/keys; richer getStats on map and conflict-set.

messaging-gossip: gossip-mesh seenCount/clearSeen; dedup size/clear;
event-bus getStats merges metrics/topics/peers.

scheduling-queues: topic-lease listShards/isHeld; peer-scheduler listJobs;
activity-queue pending/claimed stats.

measurement-rate-control: bucket-rate listPeerIds/peerCount.

experimental (16): protocol-rich getStats; mycelium listPeerIds/totalCredits;
pheromone listPathIds.

Docs: API Methods for link-probe, crdt-map, gossip-mesh; expanded category
READMEs for state-crdts, messaging-gossip, scheduling, measurement.

Co-authored-by: Cursor <[email protected]>
This commit is contained in:
Raven Scott
2026-05-21 00:32:11 -04:00
co-authored by Cursor
parent 7cb1612e71
commit 70119888cd
37 changed files with 463 additions and 168 deletions
+36 -40
View File
@@ -6,7 +6,7 @@
## Overview
Production state & crdts module: Hyperswarm discovery + Protomux when `topic` is set.
Last-writer-wins map CRDT: per-key cells with timestamp + peer tie-break. Gossip `set` on local writes; `merge` for snapshots.
## Constructor
@@ -16,81 +16,77 @@ const mod = new HyperP2PCrdtMap(opts)
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| `topic` | varies | null | topic |
| `keyPair` | KeyPair | random Ed25519 | keyPair |
| `topic` | Buffer \| string \| null | `null` | Hyperswarm topic |
| `keyPair` | KeyPair | random Ed25519 | Writer identity (`peerId` hex) |
## Methods
### `set(key, value)`
### `set(key, value) → boolean`
- **Returns:** `value`
- **Throws:** — (none documented in method body)
Applies LWW cell `{ key, value, ts, peerId }`. Returns `true` if local write wins. Gossip on success.
### `get(key)`
### `get(key) → value | undefined`
- **Returns:** `value`
- **Throws:** — (none documented in method body)
Current winning value (not tombstone metadata).
### `delete(key)`
### `delete(key) → boolean`
- **Returns:** `value`
- **Throws:** — (none documented in method body)
`set(key, null)` tombstone.
### `keys()`
### `keys() → string[]`
- **Returns:** `value`
- **Throws:** — (none documented in method body)
All cell keys.
### `merge(remote)`
### `has(key) → boolean`
- **Returns:** `value`
- **Throws:** — (none documented in method body)
Whether a cell exists (including tombstoned).
### `toJSON(—)`
### `size() → number`
- **Returns:** `value`
- **Throws:** — (none documented in method body)
Cell count.
### `ready(—)`
### `entries() → [key, value][]`
- **Returns:** `Promise`
- **Throws:** — (none documented in method body)
Live values only.
### `getStats(—)`
### `values() → any[]`
- **Returns:** `object`
- **Throws:** — (none documented in method body)
All winning values.
### `close(—)`
### `merge(remote) → number`
- **Returns:** `Promise<void>`
- **Throws:** — (none documented in method body)
`remote.cells` array; returns count of updated keys.
### `toJSON() → { cells }`
Snapshot for persistence.
### `getStats() → object`
`{ ops, errors, cells, protocol }`.
### `async ready()` / `async close()`
Protomux `crdt-map/v1` when `topic` set.
## Events
| Event | Payload |
|-------|---------|
| `closed` | no payload |
| `merge` | updated |
| `merge` | `{ updated }` |
| `set` | cell |
## getStats()
Returns `{ ...this._stats }` — typically `ops`, `errors`, and module-specific counters (`created`, `relays`, `open`, `peers`, etc.).
Library-only modules may include `mode: 'local'`.
## Errors
Stable message substrings: see [`../_shared/ERROR_CODES.md`](../../_shared/ERROR_CODES.md).
`{ ops, errors, cells, protocol: 'crdt-map/v1' }`.
## P2P
When `topic` is set, `ready()` joins Hyperswarm and opens Protomux `crdt-map/v1`.
Gossip type `set` with `{ cell }`.
## Testing
```bash
npm install && npm test
```
Integration: [`../../real_tests/integration/crdt-map-two-node.js`](../../../real_tests/integration/crdt-map-two-node.js)