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,90 +1,54 @@
|
||||
# API: hyper-p2p-dht-bootstrap-hint
|
||||
|
||||
**Protocol:** `dht-bootstrap-hint/v1` · **Export:** `HyperP2PDhtBootstrapHint`, `PROTOCOL`
|
||||
**Protocol:** `dht-bootstrap-hint/v1` · **Export:** `HyperP2PDhtBootstrapHint`
|
||||
|
||||
## Overview
|
||||
|
||||
Aggregates DHT bootstrap hints keyed by `nodeId` + `address`. Score increases when unique peers report the same hint; `bestHint()` returns highest score then freshest `lastSeen`.
|
||||
`HyperP2PDhtBootstrapHint` — P2P module. See [`README.md`](../README.md) and [`architecture.md`](architecture.md).
|
||||
|
||||
## Constructor
|
||||
|
||||
```js
|
||||
const mod = new HyperP2PDhtBootstrapHint(opts)
|
||||
```
|
||||
|
||||
| Option | Type | Default | Description |
|
||||
|--------|------|---------|-------------|
|
||||
| `topic` | `string` \| `Buffer` | `null` | Swarm topic |
|
||||
| `keyPair` | `KeyPair` | random | `peerHex` for `sources` set |
|
||||
| `topic` | Buffer \| string \| null | `null` | Hyperswarm topic; omit for local-only |
|
||||
| `keyPair` | KeyPair | random | Discovery identity |
|
||||
|
||||
## Methods
|
||||
|
||||
### `addHint(nodeId, address)`
|
||||
### `addHint(...)`
|
||||
|
||||
- **Returns:** internal entry with `score`, `lastSeen`, `sources`
|
||||
- **Throws:** `assertNonEmpty` on both args
|
||||
- **Gossip:** `{ type: 'hint-add', nodeId, address, from: peerHex, at }`
|
||||
- **Emits:** `hint` `{ nodeId, address, score }`
|
||||
Public API on `HyperP2PDhtBootstrapHint`. See [`index.js`](../index.js) for parameters and return types.
|
||||
|
||||
### `getHints()`
|
||||
### `getHints(...)`
|
||||
|
||||
- **Returns:** serializable array with `sources` as string array
|
||||
Public API on `HyperP2PDhtBootstrapHint`. See [`index.js`](../index.js) for parameters and return types.
|
||||
|
||||
### `bestHint()`
|
||||
### `bestHint(...)`
|
||||
|
||||
- **Returns:** `{ nodeId, address, score, lastSeen }` or `null`
|
||||
Public API on `HyperP2PDhtBootstrapHint`. See [`index.js`](../index.js) for parameters and return types.
|
||||
|
||||
### `ready()` / `close()`
|
||||
### `getStats() → object`
|
||||
|
||||
Clears hints on close.
|
||||
Metrics plus `protocol: 'dht-bootstrap-hint/v1'`.
|
||||
|
||||
## Events
|
||||
### `async ready()`
|
||||
|
||||
| Event | Payload |
|
||||
|-------|---------|
|
||||
| `hint` | local or `{ nodeId, address, remote: true }` |
|
||||
| `closed` | — |
|
||||
Joins Hyperswarm when `topic` is set; opens Protomux channel.
|
||||
|
||||
## getStats()
|
||||
### `async close()`
|
||||
|
||||
`added`, `gossipIn`, `gossipOut`, `hints`, `protocol`.
|
||||
|
||||
## Wire
|
||||
|
||||
| type | fields | behavior |
|
||||
|------|--------|----------|
|
||||
| `hint-add` | `nodeId`, `address`, `from`, `at` | `_mergeHint`: increment score for new source |
|
||||
|
||||
## Errors
|
||||
|
||||
`assertNonEmpty` on `nodeId`, `address`.
|
||||
|
||||
See [`../../_shared/ERROR_CODES.md`](../../_shared/ERROR_CODES.md).
|
||||
Tears down swarm and clears local state; emits `closed` where applicable.
|
||||
|
||||
## P2P
|
||||
|
||||
Hint key: `` `${nodeId}\0${address}` `` via internal `hintKey()`.
|
||||
Gossip / sync over Protomux `dht-bootstrap-hint/v1` when `topic` is configured.
|
||||
|
||||
## Testing
|
||||
|
||||
```bash
|
||||
cd modules/network-transport/hyper-p2p-dht-bootstrap-hint && npm test
|
||||
npm install && npm test
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
`hyper-p2p-peer-bootstrap-store`, `hyper-p2p-discovery-health`, `hyper-p2p-topic-announcer`.
|
||||
|
||||
## Example
|
||||
|
||||
See [`examples/basic.js`](../examples/basic.js).
|
||||
|
||||
## Remote merge rules
|
||||
|
||||
- `hint-add` requires `nodeId` and `address`
|
||||
- New gossip `from` increments `score` once per source
|
||||
- `lastSeen` is max of local and remote `at`
|
||||
|
||||
## Lifecycle
|
||||
|
||||
`ready()` joins swarm; `close()` clears `_hints` and nulls `_peerMsgs`.
|
||||
|
||||
## See also
|
||||
|
||||
[`docs/architecture.md`](architecture.md), [`../../MODULE_CATEGORIES.md`](../../MODULE_CATEGORIES.md).
|
||||
|
||||
Reference in New Issue
Block a user