Expand pubsub, economy, routing-advanced, and platform categories.

Manual pass adds listChannels, totalSupply, openCount, listSessionIds, new api.md files, corrected trust/reactive/conflict getStats docs, and category README hubs for routing-advanced, measurement, pear-platform, and trust-security.

Co-authored-by: Cursor <[email protected]>
This commit is contained in:
Raven Scott
2026-05-21 00:58:14 -04:00
co-authored by Cursor
parent 0a75712c81
commit f1536f9b6b
19 changed files with 176 additions and 367 deletions
@@ -1,85 +1,25 @@
# API: hyper-p2p-qos-topic
**Protocol:** `qos-topic/v1`
**Protocol:** `qos-topic/v1` · **Export:** `HyperP2PQosTopic`
**Export:** `HyperP2PQosTopic`, `PROTOCOL`
## Overview
Priority pub/sub with three QoS queues (02). Higher QoS messages drain before lower; subscribers declare minimum QoS per channel. Publishes gossip as `qos-publish`.
## Constructor
| Option | Description |
|--------|-------------|
| `topic` | Hyperswarm topic |
| `keyPair` | Publisher identity |
QoS tiers `0` (low) … `2` (high). Drain processes higher tiers first.
## Methods
### `subscribe(channel, handler, qos?)`
### `subscribe(channel, handler, qos?) → unsubscribe`
Default subscriber QoS `0`. Handler receives messages where `msg.qos >= sub.qos`.
Handler receives messages where `msg.qos >= sub.qos`.
### `publish(channel, payload, opts?)`
### `publish(channel, payload, opts?) → msg`
- **opts.qos** — clamped 02
- Enqueues then `_drain()` priority order
### `pending(qos?) → number` — queue depth
### `pending(qos?)`
### `listChannels()` / `hasHandler(channel)`
Queue depth for one level or total.
### `getStats() → { published, delivered, pending, protocol }`
### `getStats()` / `ready()` / `close()`
`published`, `delivered`, `gossipIn`, `gossipOut`.
### `async ready()` / `async close()`
## Wire
| type | fields |
|------|--------|
| `qos-publish` | `channel`, `payload`, `qos`, `from`, `at` |
## Events
`message`.
## Errors
`assertNonEmpty(channel)`, invalid handler.
## Composition
`hyper-p2p-topic-channel` for retain; Messaging stack `qos-topic-two-node.js`.
## Testing
`npm test`, integration smoke.
## Example
`examples/basic.js`
## State model
Three queues `_queues[0..2]`; drain processes highest index first.
## Performance
`pending()` walks all queues; bound publish rate if memory grows.
## Versioning
`qos-topic/v1` publish type unchanged since flagship release.
## Security
No encryption; use `hyper-p2p-encrypted-topic` for sensitive channels.
## Related modules
- `hyper-p2p-topic-channel` — retain and subscribe
## See also
[`docs/architecture.md`](architecture.md)
`qos-publish` — enqueued by remote peer then drained locally.
@@ -71,6 +71,10 @@ class HyperP2PQosTopic extends EventEmitter {
return this._queues[qos]?.length || 0
}
listChannels () { return [...this._handlers.keys()] }
hasHandler (channel) { return this._handlers.has(channel) }
_onGossip (data) {
if (!data || data.type !== 'qos-publish') return
this._stats.gossipIn++
@@ -1,80 +1,25 @@
# API: hyper-p2p-subscription-lease
**Protocol:** `subscription-lease/v1`
**Export:** `HyperP2PSubscriptionLease`, `PROTOCOL`
## Overview
Time-bounded exclusive channel subscription leases. `acquire` fails if another holders lease is unexpired; background timer sweeps expired entries when enabled.
## Constructor
| Option | Default | Description |
|--------|---------|-------------|
| `leaseMs` | `60000` | Lease duration |
| `enableBackgroundTimers` | `false` | Periodic expiry sweep |
**Protocol:** `subscription-lease/v1` · **Export:** `HyperP2PSubscriptionLease`
## Methods
### `acquire(channel)` / `renew(channel)` / `release(channel)`
### `acquire(channel) → { ok, holder?, ...lease }`
### `getLease(channel)` / `isActive(channel)`
Fails when another holder has a non-expired lease.
### `getStats()` / `ready()` / `close()`
### `renew(channel) → boolean` / `release(channel) → boolean`
### `holder(channel) → peerHex | null`
### `listChannels()` / `activeLeases() → lease[]`
### `getStats() → { acquired, released, active, protocol }`
### `async ready()` / `async close()`
Enable `enableBackgroundTimers` for expiry sweep every 5s.
## Wire
| type | purpose |
|------|---------|
| `sub-lease` | full lease object |
| `sub-release` | `channel`, `holder` |
## Events
`acquire`, `release`, `expired`.
## Errors
`assertNonEmpty(channel)`; acquire conflict returns `{ ok: false, holder }`.
## Composition
`hyper-p2p-topic-channel` subscribe exclusivity.
## Testing
`npm test`
## Example
`examples/basic.js`
## State model
`_leases` map channel → `{ holder, expiresAt }`; timer sweeps expired when enabled.
## Performance
Acquire is O(1); gossip on every renew — throttle renew frequency.
## Versioning
`subscription-lease/v1` wire messages documented in architecture.
## Security
Leases are cooperative, not Byzantine-safe; use consensus modules for hard exclusivity.
## Related modules
- `hyper-p2p-topic-channel` — delivery path
## Changelog
- lease acquire/renew/release with optional background expiry timer.
- Default `leaseMs` is 60000 unless overridden in constructor.
## See also
[`docs/architecture.md`](architecture.md)
`sub-lease`, `sub-release`
@@ -70,6 +70,13 @@ class HyperP2PSubscriptionLease extends EventEmitter {
return lease.holder
}
listChannels () { return [...this._leases.keys()] }
activeLeases () {
const now = Date.now()
return [...this._leases.values()].filter((l) => l.expiresAt > now)
}
_expireSweep () {
const now = Date.now()
for (const [ch, lease] of this._leases) {