Updates
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
# API: hyper-p2p-mycelium-pool
|
||||
|
||||
**Protocol:** `mycelium-pool/v1`
|
||||
|
||||
**Export:** `HyperP2PMyceliumPool`
|
||||
|
||||
## Overview
|
||||
|
||||
Production experimental (wave 4) module: Hyperswarm discovery + Protomux when `topic` is set.
|
||||
|
||||
## Constructor
|
||||
|
||||
```js
|
||||
const mod = new HyperP2PMyceliumPool(opts)
|
||||
```
|
||||
|
||||
| Option | Type | Default | Description |
|
||||
|--------|------|---------|-------------|
|
||||
| `topic` | varies | null | topic |
|
||||
| `keyPair` | KeyPair | random Ed25519 | keyPair |
|
||||
|
||||
## Methods
|
||||
|
||||
### `balance(peerId)`
|
||||
|
||||
- **Returns:** `value`
|
||||
- **Throws:** — (none documented in method body)
|
||||
|
||||
### `donate(peerId, credits)`
|
||||
|
||||
- **Returns:** `value`
|
||||
- **Throws:**
|
||||
- `Error: credits must be non-negative`
|
||||
|
||||
### `borrow(peerId, n)`
|
||||
|
||||
- **Returns:** `value`
|
||||
- **Throws:**
|
||||
- `Error: borrow amount must be non-negative`
|
||||
|
||||
### `repay(peerId, n)`
|
||||
|
||||
- **Returns:** `value`
|
||||
- **Throws:** — (none documented in method body)
|
||||
|
||||
### `mergeBalances(remote)`
|
||||
|
||||
- **Returns:** `value`
|
||||
- **Throws:** — (none documented in method body)
|
||||
|
||||
### `toJSON(—)`
|
||||
|
||||
- **Returns:** `value`
|
||||
- **Throws:** — (none documented in method body)
|
||||
|
||||
### `ready(—)`
|
||||
|
||||
- **Returns:** `Promise`
|
||||
- **Throws:** — (none documented in method body)
|
||||
|
||||
### `getStats(—)`
|
||||
|
||||
- **Returns:** `object`
|
||||
- **Throws:** — (none documented in method body)
|
||||
|
||||
### `close(—)`
|
||||
|
||||
- **Returns:** `Promise<void>`
|
||||
- **Throws:** — (none documented in method body)
|
||||
|
||||
## Events
|
||||
|
||||
| Event | Payload |
|
||||
|-------|---------|
|
||||
| `borrow` | loan |
|
||||
| `closed` | no payload |
|
||||
| `donate` | peerId, balance |
|
||||
|
||||
## 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 `mycelium-pool/v1`.
|
||||
|
||||
## Testing
|
||||
|
||||
```bash
|
||||
npm install && npm test
|
||||
```
|
||||
|
||||
Integration: [`../../real_tests/integration/mycelium-pool-two-node.js`](../../../real_tests/integration/mycelium-pool-two-node.js)
|
||||
@@ -0,0 +1,44 @@
|
||||
# Architecture: hyper-p2p-mycelium-pool
|
||||
|
||||
**Category:** Experimental (Wave 4)
|
||||
|
||||
```mermaid
|
||||
flowchart LR
|
||||
App[Application] --> Mod[HyperP2PMyceliumPool]
|
||||
Mod --> Mux[Protomux mycelium-pool/v1]
|
||||
Mux --> Swarm[Hyperswarm]
|
||||
```
|
||||
|
||||
## Sequence (P2P)
|
||||
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
participant App
|
||||
participant Mod as Module
|
||||
participant SW as Hyperswarm
|
||||
participant Peer
|
||||
App->>Mod: ready(topic)
|
||||
Mod->>SW: join(topic)
|
||||
SW->>Peer: connection
|
||||
Mod->>Peer: gossip / Protomux
|
||||
Peer-->>Mod: onmessage
|
||||
Mod-->>App: emit(event)
|
||||
```
|
||||
|
||||
## Wire messages
|
||||
|
||||
| type | fields | direction | behavior |
|
||||
|------|--------|-----------|----------|
|
||||
| `balance` | balance, peerId | gossip | Handled in onmessage / gossipSend |
|
||||
| `borrow` | balance, type | gossip | Handled in onmessage / gossipSend |
|
||||
|
||||
## State model
|
||||
|
||||
- In-memory `Map` / `Set` structures for hot path
|
||||
- Optional Hyperbee/Hypercore persistence when `storageDir` or `memoryOnly` is configured
|
||||
- `close()` tears down swarm, timers, and clears ephemeral state
|
||||
|
||||
## Composition
|
||||
|
||||
Composes with: `hyper-p2p-pheromone-trail`, `hyper-p2p-whisper-mesh`, `hyper-p2p-entropy-beacon`.
|
||||
|
||||
Reference in New Issue
Block a user