Begin build phase
This commit is contained in:
@@ -1,30 +1,36 @@
|
||||
# hyper-p2p-rpc
|
||||
|
||||
Production core infrastructure module: Hyperswarm discovery + Protomux when `topic` is set.
|
||||
Typed/streaming RPC over **Protomux on an existing framed stream** (typically `@hyperswarm/secret-stream`). This module does **not** join Hyperswarm — bring your own socket or use `hyper-p2p-secret-stream-pair` for local tests.
|
||||
|
||||
**Category:** Core infrastructure
|
||||
|
||||
**Composes with:** `hyper-p2p-presence`, `hyper-p2p-capabilities`
|
||||
**Composes with:** `hyper-p2p-capabilities`, `hyper-p2p-presence` (app-level stacks)
|
||||
|
||||
**Protocol:** `hyper-p2p-rpc/v2`
|
||||
**Protocol:** `hyper-p2p-rpc/v2`, `hyper-p2p-rpc-stream/v2`
|
||||
|
||||
## When to use
|
||||
|
||||
Multi-peer apps that need core infrastructure over a shared Hyperswarm topic.
|
||||
P2P services that already have a connected `SecretStream` (or compatible duplex) and need method calls + bidirectional streaming.
|
||||
|
||||
## When not to use
|
||||
|
||||
Single-process tools with no P2P topic (use local APIs only or skip `ready()`).
|
||||
Apps that only have a Hyperswarm topic but no connection yet — discover/connect first, then `handleConnection(socket)`.
|
||||
|
||||
## Quick start
|
||||
|
||||
```js
|
||||
const { RPCServer } = require('hyper-p2p-rpc')
|
||||
const topic = process.argv[2] // 64-char hex or string
|
||||
const mod = new RPCServer({ topic, enableBackgroundTimers: false })
|
||||
await mod.ready() // joins swarm when topic set
|
||||
// ... application logic ...
|
||||
await mod.close()
|
||||
const SecretStream = require('@hyperswarm/secret-stream')
|
||||
const { RPCServer, RPCClient } = require('hyper-p2p-rpc')
|
||||
const { createPair } = require('hyper-p2p-secret-stream-pair')
|
||||
|
||||
const pair = createPair()
|
||||
await pair.open()
|
||||
const server = new RPCServer()
|
||||
server.register('echo', async (p) => p)
|
||||
server.handleConnection(pair.initiator)
|
||||
const client = new RPCClient(pair.responder)
|
||||
const res = await client.call('echo', { msg: 'hi' })
|
||||
pair.destroy()
|
||||
```
|
||||
|
||||
## Docs
|
||||
|
||||
Reference in New Issue
Block a user