Expand category docs and module APIs across the library.
Manual pass adds helpers (listChannels, taskCounts, openProposals), richer getStats with protocol fields, category README hubs, and tightened api.md for core, messaging, network, routing, supercomputer, and consensus modules. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -1,91 +1,31 @@
|
||||
# API: hyper-p2p-overlay-topology
|
||||
|
||||
**Protocol:** `overlay-topology/v1`
|
||||
|
||||
**Export:** `HyperP2POverlayTopology`
|
||||
**Protocol:** `overlay-topology/v1` · **Export:** `HyperP2POverlayTopology`
|
||||
|
||||
## Overview
|
||||
|
||||
Maintains a degree-bounded neighbor map with weights, gossips topology updates, and suggests replacements for failed peers. Feeds `circuit-loom` hop selection.
|
||||
|
||||
## Constructor
|
||||
|
||||
```js
|
||||
const mod = new HyperP2POverlayTopology(opts)
|
||||
```
|
||||
|
||||
| Option | Type | Default | Description |
|
||||
|--------|------|---------|-------------|
|
||||
| `topic` | varies | null | topic |
|
||||
| `keyPair` | KeyPair | random Ed25519 | keyPair |
|
||||
Weighted neighbor graph with `maxDegree` cap and churn healing via `suggestReplacement`.
|
||||
|
||||
## Methods
|
||||
|
||||
### `addNeighbor(peerId, weight = 1)`
|
||||
### `addNeighbor(peerId, weight?) → neighbor`
|
||||
|
||||
- **Returns:** `value`
|
||||
- **Throws:**
|
||||
- `Error: maxDegree exceeded`
|
||||
- `Error: peerId required`
|
||||
- `Error: weight must be non-negative`
|
||||
**Throws:** `peerId required`, `weight must be non-negative`, `maxDegree exceeded`.
|
||||
|
||||
### `removeNeighbor(peerId)`
|
||||
### `removeNeighbor(peerId) → boolean`
|
||||
|
||||
- **Returns:** `value`
|
||||
- **Throws:**
|
||||
- `Error: peerId required`
|
||||
### `getNeighbors() → neighbor[]`
|
||||
|
||||
### `getNeighbors(—)`
|
||||
### `hasNeighbor(peerId) → boolean` / `neighborCount() → number`
|
||||
|
||||
- **Returns:** `value`
|
||||
- **Throws:** — (none documented in method body)
|
||||
### `suggestReplacement(failedPeer) → neighbor | null`
|
||||
|
||||
### `suggestReplacement(failedPeer)`
|
||||
Lowest-weight alternate neighbor.
|
||||
|
||||
- **Returns:** `value`
|
||||
- **Throws:**
|
||||
- `Error: failedPeer required`
|
||||
### `getStats() → { added, removed, healed, degree, protocol }`
|
||||
|
||||
### `getStats(—)`
|
||||
|
||||
- **Returns:** `object`
|
||||
- **Throws:** — (none documented in method body)
|
||||
|
||||
### `ready(—)`
|
||||
|
||||
- **Returns:** `Promise`
|
||||
- **Throws:** — (none documented in method body)
|
||||
|
||||
### `close(—)`
|
||||
|
||||
- **Returns:** `Promise<void>`
|
||||
- **Throws:** — (none documented in method body)
|
||||
### `async ready()` / `async close()`
|
||||
|
||||
## Events
|
||||
|
||||
| Event | Payload |
|
||||
|-------|---------|
|
||||
| `closed` | no payload |
|
||||
| `neighbor-added` | n |
|
||||
| `neighbor-removed` | payload object |
|
||||
|
||||
## 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).
|
||||
|
||||
## P2P
|
||||
|
||||
When `topic` is set, `ready()` joins Hyperswarm and opens Protomux `overlay-topology/v1`.
|
||||
|
||||
## Testing
|
||||
|
||||
```bash
|
||||
npm install && npm test
|
||||
```
|
||||
|
||||
Integration: [`../../real_tests/integration/overlay-topology-two-node.js`](../../../real_tests/integration/overlay-topology-two-node.js)
|
||||
`neighbor-added`, `neighbor-removed`, `closed`
|
||||
|
||||
Reference in New Issue
Block a user