@optimystic/db-p2p 0.24.0 → 0.24.1
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/dist/src/cohort-topic/host.js +34 -11
- package/dist/src/cohort-topic/host.js.map +1 -1
- package/dist/src/cohort-topic/stream-util.d.ts +25 -11
- package/dist/src/cohort-topic/stream-util.d.ts.map +1 -1
- package/dist/src/cohort-topic/stream-util.js +31 -19
- package/dist/src/cohort-topic/stream-util.js.map +1 -1
- package/dist/src/matchmaking/query-transport.js +3 -3
- package/dist/src/matchmaking/query-transport.js.map +1 -1
- package/dist/src/reactivity/notify-transport.d.ts +4 -4
- package/dist/src/reactivity/notify-transport.js +6 -6
- package/dist/src/reactivity/notify-transport.js.map +1 -1
- package/dist/src/reactivity/push-state-gossip.js +2 -2
- package/dist/src/reactivity/push-state-gossip.js.map +1 -1
- package/dist/src/reactivity/recover-transport.d.ts +6 -2
- package/dist/src/reactivity/recover-transport.d.ts.map +1 -1
- package/dist/src/reactivity/recover-transport.js +7 -3
- package/dist/src/reactivity/recover-transport.js.map +1 -1
- package/dist/src/testing/cohort-topic-mesh-harness.d.ts +13 -6
- package/dist/src/testing/cohort-topic-mesh-harness.d.ts.map +1 -1
- package/dist/src/testing/cohort-topic-mesh-harness.js +15 -6
- package/dist/src/testing/cohort-topic-mesh-harness.js.map +1 -1
- package/package.json +3 -3
- package/src/cohort-topic/host.ts +2932 -2901
- package/src/cohort-topic/stream-util.ts +147 -135
- package/src/matchmaking/query-transport.ts +492 -492
- package/src/reactivity/notify-transport.ts +6 -6
- package/src/reactivity/push-state-gossip.ts +2 -2
- package/src/reactivity/recover-transport.ts +412 -408
- package/src/testing/cohort-topic-mesh-harness.ts +20 -10
|
@@ -23,6 +23,8 @@
|
|
|
23
23
|
import { generateKeyPair } from '@libp2p/crypto/keys';
|
|
24
24
|
import { peerIdFromPrivateKey } from '@libp2p/peer-id';
|
|
25
25
|
import type { PrivateKey, PeerId } from '@libp2p/interface';
|
|
26
|
+
import * as lp from 'it-length-prefixed';
|
|
27
|
+
import type { Uint8ArrayList } from 'uint8arraylist';
|
|
26
28
|
import { hashPeerId, type RouteAndMaybeActV1, type NearAnchorV1 } from 'p2p-fret';
|
|
27
29
|
import {
|
|
28
30
|
RingHash,
|
|
@@ -97,22 +99,29 @@ export async function makeMembers(n: number): Promise<Member[]> {
|
|
|
97
99
|
return out;
|
|
98
100
|
}
|
|
99
101
|
|
|
100
|
-
// --- in-process duplex stream (what
|
|
102
|
+
// --- in-process duplex stream (what readFramed iterates) ---
|
|
101
103
|
|
|
102
104
|
/**
|
|
103
|
-
* One end of an in-memory duplex pipe. `send` enqueues a
|
|
104
|
-
* (half-close-write) signals EOF to the peer's reader. The async iterator yields this end's inbox
|
|
105
|
-
*
|
|
106
|
-
*
|
|
105
|
+
* One end of an in-memory duplex pipe. `send` enqueues a chunk onto the *peer's* inbox; `close`
|
|
106
|
+
* (half-close-write) signals EOF to the peer's reader. The async iterator yields this end's inbox, so
|
|
107
|
+
* `p2p-fret`'s `readFramed` decodes exactly one varint-length-prefixed frame from the chunks the other
|
|
108
|
+
* end wrote — the varint prefix delimits the frame; EOF before a whole frame is a truncation error.
|
|
109
|
+
*
|
|
110
|
+
* Chunks are `Uint8Array | Uint8ArrayList` because `sendFramed` writes the prefix + body as one
|
|
111
|
+
* `Uint8ArrayList`; `send` returns `true` ("queue has room"), matching the `stream.send` signature
|
|
112
|
+
* `sendFramed` passes through. Deliberately NOT carrying `closeRead` / `addEventListener` /
|
|
113
|
+
* `removeEventListener` / `push` / `log`: `readFramed` duck-types the full libp2p message-stream
|
|
114
|
+
* surface onto its `byteStream` path, and this stub must stay on the plain-iterable path.
|
|
107
115
|
*/
|
|
108
116
|
export class MockStreamEnd {
|
|
109
|
-
private readonly inbox: Uint8Array[] = [];
|
|
117
|
+
private readonly inbox: (Uint8Array | Uint8ArrayList)[] = [];
|
|
110
118
|
private inboundClosed = false;
|
|
111
119
|
private waiter: (() => void) | undefined;
|
|
112
120
|
public peer!: MockStreamEnd;
|
|
113
121
|
|
|
114
|
-
send(frame: Uint8Array):
|
|
122
|
+
send(frame: Uint8Array | Uint8ArrayList): boolean {
|
|
115
123
|
this.peer.accept(frame);
|
|
124
|
+
return true;
|
|
116
125
|
}
|
|
117
126
|
|
|
118
127
|
close(): Promise<void> {
|
|
@@ -124,7 +133,7 @@ export class MockStreamEnd {
|
|
|
124
133
|
this.peer.endInbound();
|
|
125
134
|
}
|
|
126
135
|
|
|
127
|
-
private accept(frame: Uint8Array): void {
|
|
136
|
+
private accept(frame: Uint8Array | Uint8ArrayList): void {
|
|
128
137
|
this.inbox.push(frame);
|
|
129
138
|
this.wake();
|
|
130
139
|
}
|
|
@@ -140,7 +149,7 @@ export class MockStreamEnd {
|
|
|
140
149
|
w?.();
|
|
141
150
|
}
|
|
142
151
|
|
|
143
|
-
async *[Symbol.asyncIterator](): AsyncGenerator<Uint8Array> {
|
|
152
|
+
async *[Symbol.asyncIterator](): AsyncGenerator<Uint8Array | Uint8ArrayList> {
|
|
144
153
|
for (;;) {
|
|
145
154
|
if (this.inbox.length > 0) {
|
|
146
155
|
yield this.inbox.shift()!;
|
|
@@ -228,7 +237,8 @@ export class MockNode {
|
|
|
228
237
|
}
|
|
229
238
|
const [dialerEnd, handlerEnd] = streamPair();
|
|
230
239
|
handler(handlerEnd, { remotePeer: from });
|
|
231
|
-
|
|
240
|
+
// Frame exactly as `sendFramed` does — the handler's `readFramed` expects a varint prefix.
|
|
241
|
+
dialerEnd.send(lp.encode.single(frame));
|
|
232
242
|
void dialerEnd.close();
|
|
233
243
|
}
|
|
234
244
|
}
|