@optimystic/db-p2p 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -0
- package/dist/index.min.js +17 -17
- package/dist/index.min.js.map +4 -4
- package/dist/src/cluster/client.d.ts +1 -2
- package/dist/src/cluster/client.d.ts.map +1 -1
- package/dist/src/cluster/client.js.map +1 -1
- package/dist/src/cluster/cluster-repo.d.ts.map +1 -1
- package/dist/src/cluster/cluster-repo.js +10 -1
- package/dist/src/cluster/cluster-repo.js.map +1 -1
- package/dist/src/libp2p-key-network.d.ts.map +1 -1
- package/dist/src/libp2p-key-network.js +4 -4
- package/dist/src/libp2p-key-network.js.map +1 -1
- package/dist/src/libp2p-node-base.d.ts +53 -0
- package/dist/src/libp2p-node-base.d.ts.map +1 -0
- package/dist/src/libp2p-node-base.js +291 -0
- package/dist/src/libp2p-node-base.js.map +1 -0
- package/dist/src/libp2p-node-rn.d.ts +11 -0
- package/dist/src/libp2p-node-rn.d.ts.map +1 -0
- package/dist/src/libp2p-node-rn.js +19 -0
- package/dist/src/libp2p-node-rn.js.map +1 -0
- package/dist/src/libp2p-node.d.ts +3 -37
- package/dist/src/libp2p-node.d.ts.map +1 -1
- package/dist/src/libp2p-node.js +6 -287
- package/dist/src/libp2p-node.js.map +1 -1
- package/dist/src/protocol-client.d.ts +1 -2
- package/dist/src/protocol-client.d.ts.map +1 -1
- package/dist/src/protocol-client.js.map +1 -1
- package/dist/src/repo/client.d.ts +1 -2
- package/dist/src/repo/client.d.ts.map +1 -1
- package/dist/src/repo/client.js.map +1 -1
- package/dist/src/rn.d.ts +29 -0
- package/dist/src/rn.d.ts.map +1 -0
- package/dist/src/rn.js +29 -0
- package/dist/src/rn.js.map +1 -0
- package/package.json +6 -2
- package/src/cluster/client.ts +1 -2
- package/src/cluster/cluster-repo.ts +9 -1
- package/src/index.ts +0 -2
- package/src/libp2p-key-network.ts +5 -6
- package/src/libp2p-node-base.ts +386 -0
- package/src/libp2p-node-rn.ts +30 -0
- package/src/libp2p-node.ts +14 -364
- package/src/protocol-client.ts +3 -3
- package/src/repo/client.ts +1 -2
- package/src/rn.ts +28 -0
package/README.md
CHANGED
|
@@ -483,6 +483,50 @@ const node = await createLibp2pNode({
|
|
|
483
483
|
});
|
|
484
484
|
```
|
|
485
485
|
|
|
486
|
+
#### Custom transports (including React Native)
|
|
487
|
+
|
|
488
|
+
By default, `createLibp2pNode()` uses TCP + circuit-relay transport.
|
|
489
|
+
|
|
490
|
+
To use non-default transports, pass `transports` (and typically `listenAddrs`):
|
|
491
|
+
|
|
492
|
+
```typescript
|
|
493
|
+
import { webSockets } from '@libp2p/websockets';
|
|
494
|
+
import { circuitRelayTransport } from '@libp2p/circuit-relay-v2';
|
|
495
|
+
import { createLibp2pNode } from '@optimystic/db-p2p';
|
|
496
|
+
|
|
497
|
+
const node = await createLibp2pNode({
|
|
498
|
+
networkName: 'mynet',
|
|
499
|
+
bootstrapNodes: ['/dns4/relay.example.com/tcp/443/wss/p2p/12D3...'],
|
|
500
|
+
transports: [webSockets(), circuitRelayTransport()],
|
|
501
|
+
listenAddrs: [], // client-only; no incoming connections
|
|
502
|
+
});
|
|
503
|
+
```
|
|
504
|
+
|
|
505
|
+
#### React Native
|
|
506
|
+
|
|
507
|
+
For React Native, import from `@optimystic/db-p2p/rn` instead of the root entrypoint.
|
|
508
|
+
The `/rn` entrypoint does **not** import `@libp2p/tcp`, so Metro/Hermes won't try to
|
|
509
|
+
bundle Node-only native modules. It requires `options.transports` explicitly:
|
|
510
|
+
|
|
511
|
+
```typescript
|
|
512
|
+
import { webSockets } from '@libp2p/websockets';
|
|
513
|
+
import { circuitRelayTransport } from '@libp2p/circuit-relay-v2';
|
|
514
|
+
import { createLibp2pNode } from '@optimystic/db-p2p/rn';
|
|
515
|
+
|
|
516
|
+
const node = await createLibp2pNode({
|
|
517
|
+
networkName: 'mynet',
|
|
518
|
+
bootstrapNodes: ['/dns4/relay.example.com/tcp/443/wss/p2p/12D3...'],
|
|
519
|
+
transports: [webSockets(), circuitRelayTransport()],
|
|
520
|
+
});
|
|
521
|
+
```
|
|
522
|
+
|
|
523
|
+
RN environments (Hermes, JSC) may also need polyfills for globals that libp2p
|
|
524
|
+
and its dependencies expect. Install these early (e.g. in your app's entry file
|
|
525
|
+
before any other imports):
|
|
526
|
+
|
|
527
|
+
- `crypto.getRandomValues` — e.g. `react-native-get-random-values`
|
|
528
|
+
- `TextEncoder` / `TextDecoder` — e.g. `text-encoding` or `fast-text-encoding`
|
|
529
|
+
|
|
486
530
|
### Ring Transitions
|
|
487
531
|
|
|
488
532
|
Nodes automatically transition between rings based on capacity thresholds:
|