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,89 +1,54 @@
|
||||
# API: hyper-pear-update-gossip
|
||||
|
||||
**Protocol:** `pear-update-gossip/v1` · **Export:** `HyperPearUpdateGossip`, `HyperP2PPearUpdateGossip`, `PROTOCOL`
|
||||
**Protocol:** `pear-update-gossip/v1` · **Export:** `HyperPearUpdateGossip`
|
||||
|
||||
## Overview
|
||||
|
||||
Publishes versioned Pear update manifests and gossips them to peers. Keeps lexicographically greatest `version` as `_latest` and notifies subscribers and `update` event listeners on change.
|
||||
`HyperPearUpdateGossip` — P2P module. See [`README.md`](../README.md) and [`architecture.md`](architecture.md).
|
||||
|
||||
## Constructor
|
||||
|
||||
```js
|
||||
const mod = new HyperPearUpdateGossip(opts)
|
||||
```
|
||||
|
||||
| Option | Type | Default | Description |
|
||||
|--------|------|---------|-------------|
|
||||
| `topic` | `string` \| `Buffer` | `null` | Hyperswarm topic |
|
||||
| `keyPair` | `KeyPair` | random | Swarm identity |
|
||||
| `topic` | Buffer \| string \| null | `null` | Hyperswarm topic; omit for local-only |
|
||||
| `keyPair` | KeyPair | random | Discovery identity |
|
||||
|
||||
## Methods
|
||||
|
||||
### `publishUpdate(version, manifest)`
|
||||
### `publishUpdate(...)`
|
||||
|
||||
- **Returns:** `{ version, manifest, publishedAt }`
|
||||
- **Throws:** `assertNonEmpty` on `version`; `manifest must be an object`
|
||||
- **Gossip:** `{ type: 'update-publish', version, manifest, publishedAt }`
|
||||
- **Side effect:** updates `_latest` if `version` is greater; notifies subscribers
|
||||
Public API on `HyperPearUpdateGossip`. See [`index.js`](../index.js) for parameters and return types.
|
||||
|
||||
### `latestUpdate()`
|
||||
### `latestUpdate(...)`
|
||||
|
||||
- **Returns:** shallow copy of latest or `null`
|
||||
Public API on `HyperPearUpdateGossip`. See [`index.js`](../index.js) for parameters and return types.
|
||||
|
||||
### `subscribe(fn)`
|
||||
### `subscribe(...)`
|
||||
|
||||
Registers callback; invokes immediately with `_latest` if present.
|
||||
Public API on `HyperPearUpdateGossip`. See [`index.js`](../index.js) for parameters and return types.
|
||||
|
||||
- **Returns:** unsubscribe function
|
||||
- **Throws:** `fn must be a function`
|
||||
### `getStats() → object`
|
||||
|
||||
### `ready()` / `close()`
|
||||
Metrics plus `protocol: 'pear-update-gossip/v1'`.
|
||||
|
||||
Swarm via `initModuleSwarm`. `close` clears subscribers and destroys swarm.
|
||||
### `async ready()`
|
||||
|
||||
## Events
|
||||
Joins Hyperswarm when `topic` is set; opens Protomux channel.
|
||||
|
||||
| Event | Payload |
|
||||
|-------|---------|
|
||||
| `update` | `{ version, manifest, publishedAt }` |
|
||||
| `closed` | — |
|
||||
### `async close()`
|
||||
|
||||
## getStats()
|
||||
|
||||
| Field | Meaning |
|
||||
|-------|---------|
|
||||
| `published` | local publish count |
|
||||
| `gossipIn` / `gossipOut` | mesh traffic |
|
||||
| `subscribers` | `Set` size |
|
||||
| `hasLatest` | boolean |
|
||||
| `protocol` | `pear-update-gossip/v1` |
|
||||
|
||||
## Wire
|
||||
|
||||
| type | fields | direction | behavior |
|
||||
|------|--------|-----------|----------|
|
||||
| `update-publish` | `version`, `manifest`, `publishedAt` | gossip | Merge if `version` > current `_latest` |
|
||||
|
||||
## Errors
|
||||
|
||||
`assertNonEmpty` on version. Manifest validation error as above.
|
||||
|
||||
See [`../../_shared/ERROR_CODES.md`](../../_shared/ERROR_CODES.md).
|
||||
Tears down swarm and clears local state; emits `closed` where applicable.
|
||||
|
||||
## P2P
|
||||
|
||||
Requires `topic` + `ready()` for gossip. `_onGossip` ignores malformed payloads (missing `type` or `version`).
|
||||
Gossip / sync over Protomux `pear-update-gossip/v1` when `topic` is configured.
|
||||
|
||||
## Testing
|
||||
|
||||
```bash
|
||||
cd modules/pear-platform/hyper-pear-update-gossip && npm test
|
||||
npm install && npm test
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
`hyper-bare-bundle-bridge` for bundle ids; `hyper-pear-runtime-session` for correlating updates to runtime sessions.
|
||||
|
||||
## Example
|
||||
|
||||
See [`examples/basic.js`](../examples/basic.js).
|
||||
|
||||
## See also
|
||||
|
||||
[`docs/architecture.md`](architecture.md).
|
||||
|
||||
Reference in New Issue
Block a user