@dxos/messaging 0.8.4-main.c4373fc → 0.8.4-main.cb12b3f963
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/lib/neutral/chunk-EC4H56J5.mjs +497 -0
- package/dist/lib/neutral/chunk-EC4H56J5.mjs.map +7 -0
- package/dist/lib/neutral/index.mjs +1249 -0
- package/dist/lib/neutral/index.mjs.map +7 -0
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/lib/{browser → neutral}/testing/index.mjs +18 -46
- package/dist/lib/neutral/testing/index.mjs.map +7 -0
- package/dist/types/src/messenger-monitor.d.ts.map +1 -1
- package/dist/types/src/messenger.blueprint-test.d.ts +1 -1
- package/dist/types/src/messenger.blueprint-test.d.ts.map +1 -1
- package/dist/types/src/messenger.d.ts +3 -2
- package/dist/types/src/messenger.d.ts.map +1 -1
- package/dist/types/src/signal-client/signal-client-monitor.d.ts.map +1 -1
- package/dist/types/src/signal-client/signal-client.d.ts +5 -6
- package/dist/types/src/signal-client/signal-client.d.ts.map +1 -1
- package/dist/types/src/signal-client/signal-local-state.d.ts.map +1 -1
- package/dist/types/src/signal-client/signal-rpc-client-monitor.d.ts.map +1 -1
- package/dist/types/src/signal-client/signal-rpc-client.d.ts +3 -3
- package/dist/types/src/signal-client/signal-rpc-client.d.ts.map +1 -1
- package/dist/types/src/signal-manager/edge-signal-manager.d.ts +5 -5
- package/dist/types/src/signal-manager/edge-signal-manager.d.ts.map +1 -1
- package/dist/types/src/signal-manager/memory-signal-manager.d.ts +5 -4
- package/dist/types/src/signal-manager/memory-signal-manager.d.ts.map +1 -1
- package/dist/types/src/signal-manager/utils.d.ts.map +1 -1
- package/dist/types/src/signal-manager/websocket-signal-manager-monitor.d.ts.map +1 -1
- package/dist/types/src/signal-manager/websocket-signal-manager.d.ts +5 -6
- package/dist/types/src/signal-manager/websocket-signal-manager.d.ts.map +1 -1
- package/dist/types/src/signal-methods.d.ts +5 -5
- package/dist/types/src/signal-methods.d.ts.map +1 -1
- package/dist/types/src/testing/test-builder.d.ts.map +1 -1
- package/dist/types/src/testing/test-peer.d.ts.map +1 -1
- package/dist/types/src/testing/utils.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +24 -29
- package/src/messenger.blueprint-test.ts +13 -12
- package/src/messenger.node.test.ts +7 -38
- package/src/messenger.ts +37 -32
- package/src/signal-client/signal-client.node.test.ts +9 -9
- package/src/signal-client/signal-client.ts +6 -10
- package/src/signal-client/signal-local-state.ts +0 -1
- package/src/signal-client/signal-rpc-client.ts +4 -6
- package/src/signal-manager/edge-signal-manager.ts +10 -7
- package/src/signal-manager/memory-signal-manager.ts +17 -15
- package/src/signal-manager/websocket-signal-manager.node.test.ts +13 -13
- package/src/signal-manager/websocket-signal-manager.ts +9 -16
- package/src/signal-methods.ts +5 -5
- package/src/testing/test-builder.ts +4 -3
- package/src/testing/test-peer.ts +0 -1
- package/src/testing/utils.ts +0 -1
- package/dist/lib/browser/chunk-CD3GXEDZ.mjs +0 -2433
- package/dist/lib/browser/chunk-CD3GXEDZ.mjs.map +0 -7
- package/dist/lib/browser/index.mjs +0 -22
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/browser/testing/index.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-IVXFEWLW.mjs +0 -2433
- package/dist/lib/node-esm/chunk-IVXFEWLW.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -22
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/lib/node-esm/testing/index.mjs +0 -172
- package/dist/lib/node-esm/testing/index.mjs.map +0 -7
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { Event, scheduleMicroTask } from '@dxos/async';
|
|
6
|
-
import { Resource, cancelWithContext } from '@dxos/context';
|
|
6
|
+
import { type Context, Resource, cancelWithContext } from '@dxos/context';
|
|
7
7
|
import { type EdgeConnection, EdgeIdentityChangedError, protocol } from '@dxos/edge-client';
|
|
8
8
|
import { invariant } from '@dxos/invariant';
|
|
9
9
|
import { PublicKey } from '@dxos/keys';
|
|
@@ -21,7 +21,6 @@ import { type SwarmResponse } from '@dxos/protocols/proto/dxos/edge/messenger';
|
|
|
21
21
|
import { ComplexMap, ComplexSet } from '@dxos/util';
|
|
22
22
|
|
|
23
23
|
import { type Message, type PeerInfo, PeerInfoHash, type SwarmEvent } from '../signal-methods';
|
|
24
|
-
|
|
25
24
|
import { type SignalManager } from './signal-manager';
|
|
26
25
|
|
|
27
26
|
export class EdgeSignalManager extends Resource implements SignalManager {
|
|
@@ -60,7 +59,7 @@ export class EdgeSignalManager extends Resource implements SignalManager {
|
|
|
60
59
|
/**
|
|
61
60
|
* Warning: PeerInfo is inferred from edgeConnection.
|
|
62
61
|
*/
|
|
63
|
-
async join({ topic, peer }: { topic: PublicKey; peer: PeerInfo }): Promise<void> {
|
|
62
|
+
async join(ctx: Context, { topic, peer }: { topic: PublicKey; peer: PeerInfo }): Promise<void> {
|
|
64
63
|
if (!this._matchSelfPeerInfo(peer)) {
|
|
65
64
|
// NOTE: Could only join swarm with the same peer info as the edge connection.
|
|
66
65
|
log.warn('ignoring peer info on join request', {
|
|
@@ -77,6 +76,7 @@ export class EdgeSignalManager extends Resource implements SignalManager {
|
|
|
77
76
|
|
|
78
77
|
this._swarmPeers.set(topic, { lastState: peer.state, joinedPeers: new ComplexSet<PeerInfo>(PeerInfoHash) });
|
|
79
78
|
await this._edgeConnection.send(
|
|
79
|
+
ctx,
|
|
80
80
|
protocol.createMessage(SwarmRequestSchema, {
|
|
81
81
|
serviceId: EdgeService.SWARM,
|
|
82
82
|
source: createMessageSource(topic, peer),
|
|
@@ -85,10 +85,11 @@ export class EdgeSignalManager extends Resource implements SignalManager {
|
|
|
85
85
|
);
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
async leave({ topic, peer }: { topic: PublicKey; peer: PeerInfo }): Promise<void> {
|
|
88
|
+
async leave(ctx: Context, { topic, peer }: { topic: PublicKey; peer: PeerInfo }): Promise<void> {
|
|
89
89
|
this._swarmPeers.delete(topic);
|
|
90
90
|
try {
|
|
91
91
|
await this._edgeConnection.send(
|
|
92
|
+
ctx,
|
|
92
93
|
protocol.createMessage(SwarmRequestSchema, {
|
|
93
94
|
serviceId: EdgeService.SWARM,
|
|
94
95
|
source: createMessageSource(topic, peer),
|
|
@@ -105,13 +106,14 @@ export class EdgeSignalManager extends Resource implements SignalManager {
|
|
|
105
106
|
}
|
|
106
107
|
}
|
|
107
108
|
|
|
108
|
-
async query({ topic }: { topic: PublicKey }): Promise<SwarmResponse> {
|
|
109
|
+
async query(ctx: Context, { topic }: { topic: PublicKey }): Promise<SwarmResponse> {
|
|
109
110
|
const response = cancelWithContext(
|
|
110
111
|
this._ctx,
|
|
111
112
|
this.swarmState.waitFor((state) => state.swarmKey === topic.toHex()),
|
|
112
113
|
);
|
|
113
114
|
|
|
114
115
|
await this._edgeConnection.send(
|
|
116
|
+
ctx,
|
|
115
117
|
protocol.createMessage(SwarmRequestSchema, {
|
|
116
118
|
serviceId: EdgeService.SWARM,
|
|
117
119
|
source: createMessageSource(topic, {
|
|
@@ -125,7 +127,7 @@ export class EdgeSignalManager extends Resource implements SignalManager {
|
|
|
125
127
|
return response;
|
|
126
128
|
}
|
|
127
129
|
|
|
128
|
-
async sendMessage(message: Message): Promise<void> {
|
|
130
|
+
async sendMessage(ctx: Context, message: Message): Promise<void> {
|
|
129
131
|
if (!this._matchSelfPeerInfo(message.author)) {
|
|
130
132
|
// NOTE: Could only join swarm with the same peer info as the edge connection.
|
|
131
133
|
log.warn('ignoring author on send request', {
|
|
@@ -135,6 +137,7 @@ export class EdgeSignalManager extends Resource implements SignalManager {
|
|
|
135
137
|
}
|
|
136
138
|
|
|
137
139
|
await this._edgeConnection.send(
|
|
140
|
+
ctx,
|
|
138
141
|
protocol.createMessage(bufWkt.AnySchema, {
|
|
139
142
|
serviceId: EdgeService.SIGNAL,
|
|
140
143
|
source: message.author,
|
|
@@ -228,7 +231,7 @@ export class EdgeSignalManager extends Resource implements SignalManager {
|
|
|
228
231
|
private async _rejoinAllSwarms(): Promise<void> {
|
|
229
232
|
log('rejoin swarms', { swarms: Array.from(this._swarmPeers.keys()) });
|
|
230
233
|
for (const [topic, { lastState }] of this._swarmPeers.entries()) {
|
|
231
|
-
await this.join({
|
|
234
|
+
await this.join(this._ctx, {
|
|
232
235
|
topic,
|
|
233
236
|
peer: {
|
|
234
237
|
peerKey: this._edgeConnection.peerKey,
|
|
@@ -14,7 +14,6 @@ import { type QueryRequest } from '@dxos/protocols/proto/dxos/edge/signal';
|
|
|
14
14
|
import { ComplexMap, ComplexSet } from '@dxos/util';
|
|
15
15
|
|
|
16
16
|
import { type Message, type PeerInfo, PeerInfoHash, type SignalStatus, type SwarmEvent } from '../signal-methods';
|
|
17
|
-
|
|
18
17
|
import { type SignalManager } from './signal-manager';
|
|
19
18
|
|
|
20
19
|
/**
|
|
@@ -63,7 +62,7 @@ export class MemorySignalManager implements SignalManager {
|
|
|
63
62
|
this._ctx = new Context();
|
|
64
63
|
this._ctx.onDispose(this._context.swarmEvent.on((data) => this.swarmEvent.emit(data)));
|
|
65
64
|
|
|
66
|
-
await Promise.all([...this._joinedSwarms.values()].map((value) => this.join(value)));
|
|
65
|
+
await Promise.all([...this._joinedSwarms.values()].map((value) => this.join(this._ctx, value)));
|
|
67
66
|
}
|
|
68
67
|
|
|
69
68
|
async close(): Promise<void> {
|
|
@@ -76,7 +75,7 @@ export class MemorySignalManager implements SignalManager {
|
|
|
76
75
|
[...this._joinedSwarms.values()],
|
|
77
76
|
);
|
|
78
77
|
|
|
79
|
-
await Promise.all([...this._joinedSwarms.values()].map((value) => this.leave(value)));
|
|
78
|
+
await Promise.all([...this._joinedSwarms.values()].map((value) => this.leave(this._ctx, value)));
|
|
80
79
|
|
|
81
80
|
// assign joined swarms back because .leave() deletes it.
|
|
82
81
|
this._joinedSwarms = joinedSwarmsCopy;
|
|
@@ -88,7 +87,7 @@ export class MemorySignalManager implements SignalManager {
|
|
|
88
87
|
return [];
|
|
89
88
|
}
|
|
90
89
|
|
|
91
|
-
async join({ topic, peer }: { topic: PublicKey; peer: PeerInfo }): Promise<void> {
|
|
90
|
+
async join(_ctx: Context, { topic, peer }: { topic: PublicKey; peer: PeerInfo }): Promise<void> {
|
|
92
91
|
invariant(!this._ctx.disposed, 'Closed');
|
|
93
92
|
|
|
94
93
|
this._joinedSwarms.add({ topic, peer });
|
|
@@ -120,7 +119,7 @@ export class MemorySignalManager implements SignalManager {
|
|
|
120
119
|
}
|
|
121
120
|
}
|
|
122
121
|
|
|
123
|
-
async leave({ topic, peer }: { topic: PublicKey; peer: PeerInfo }): Promise<void> {
|
|
122
|
+
async leave(_ctx: Context, { topic, peer }: { topic: PublicKey; peer: PeerInfo }): Promise<void> {
|
|
124
123
|
invariant(!this._ctx.disposed, 'Closed');
|
|
125
124
|
|
|
126
125
|
this._joinedSwarms.delete({ topic, peer });
|
|
@@ -141,19 +140,22 @@ export class MemorySignalManager implements SignalManager {
|
|
|
141
140
|
this._context.swarmEvent.emit(swarmEvent);
|
|
142
141
|
}
|
|
143
142
|
|
|
144
|
-
async query(request: QueryRequest): Promise<SwarmResponse> {
|
|
143
|
+
async query(_ctx: Context, request: QueryRequest): Promise<SwarmResponse> {
|
|
145
144
|
throw new Error('Not implemented');
|
|
146
145
|
}
|
|
147
146
|
|
|
148
|
-
async sendMessage(
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
147
|
+
async sendMessage(
|
|
148
|
+
_ctx: Context,
|
|
149
|
+
{
|
|
150
|
+
author,
|
|
151
|
+
recipient,
|
|
152
|
+
payload,
|
|
153
|
+
}: {
|
|
154
|
+
author: PeerInfo;
|
|
155
|
+
recipient: PeerInfo;
|
|
156
|
+
payload: Any;
|
|
157
|
+
},
|
|
158
|
+
): Promise<void> {
|
|
157
159
|
log('send message', { author, recipient, ...dec(payload) });
|
|
158
160
|
|
|
159
161
|
invariant(recipient);
|
|
@@ -5,12 +5,12 @@
|
|
|
5
5
|
import { afterAll, beforeAll, describe, test } from 'vitest';
|
|
6
6
|
|
|
7
7
|
import { asyncTimeout, sleep } from '@dxos/async';
|
|
8
|
+
import { Context } from '@dxos/context';
|
|
8
9
|
import { PublicKey } from '@dxos/keys';
|
|
9
10
|
import { type SignalServerRunner, runTestSignalServer } from '@dxos/signal';
|
|
10
11
|
import { openAndClose } from '@dxos/test-utils';
|
|
11
12
|
|
|
12
13
|
import { createMessage, expectPeerAvailable, expectReceivedMessage } from '../testing';
|
|
13
|
-
|
|
14
14
|
import { WebsocketSignalManager } from './websocket-signal-manager';
|
|
15
15
|
|
|
16
16
|
describe.skip('WebSocketSignalManager', () => {
|
|
@@ -40,9 +40,9 @@ describe.skip('WebSocketSignalManager', () => {
|
|
|
40
40
|
const joined21 = expectPeerAvailable(client2, topic, { peerKey: peer1.toHex() });
|
|
41
41
|
const joined31 = expectPeerAvailable(client3, topic, { peerKey: peer1.toHex() });
|
|
42
42
|
|
|
43
|
-
await client1.join({ topic, peer: { peerKey: peer1.toHex() } });
|
|
44
|
-
await client2.join({ topic, peer: { peerKey: peer2.toHex() } });
|
|
45
|
-
await client3.join({ topic, peer: { peerKey: peer3.toHex() } });
|
|
43
|
+
await client1.join(Context.default(), { topic, peer: { peerKey: peer1.toHex() } });
|
|
44
|
+
await client2.join(Context.default(), { topic, peer: { peerKey: peer2.toHex() } });
|
|
45
|
+
await client3.join(Context.default(), { topic, peer: { peerKey: peer3.toHex() } });
|
|
46
46
|
|
|
47
47
|
await Promise.all([joined12, joined13, joined21, joined31]);
|
|
48
48
|
});
|
|
@@ -57,8 +57,8 @@ describe.skip('WebSocketSignalManager', () => {
|
|
|
57
57
|
const joined12 = expectPeerAvailable(client1, topic, { peerKey: peer2.toHex() });
|
|
58
58
|
const joined21 = expectPeerAvailable(client2, topic, { peerKey: peer1.toHex() });
|
|
59
59
|
|
|
60
|
-
await client1.join({ topic, peer: { peerKey: peer1.toHex() } });
|
|
61
|
-
await client2.join({ topic, peer: { peerKey: peer2.toHex() } });
|
|
60
|
+
await client1.join(Context.default(), { topic, peer: { peerKey: peer1.toHex() } });
|
|
61
|
+
await client2.join(Context.default(), { topic, peer: { peerKey: peer2.toHex() } });
|
|
62
62
|
|
|
63
63
|
await asyncTimeout(Promise.all([joined12, joined21]), 1_000);
|
|
64
64
|
|
|
@@ -67,7 +67,7 @@ describe.skip('WebSocketSignalManager', () => {
|
|
|
67
67
|
const received = expectReceivedMessage(client2.onMessage, message);
|
|
68
68
|
await client2.subscribeMessages({ peerKey: peer2.toHex() });
|
|
69
69
|
await sleep(50);
|
|
70
|
-
await client1.sendMessage(message);
|
|
70
|
+
await client1.sendMessage(Context.default(), message);
|
|
71
71
|
|
|
72
72
|
await asyncTimeout(received, 1_000);
|
|
73
73
|
});
|
|
@@ -82,8 +82,8 @@ describe.skip('WebSocketSignalManager', () => {
|
|
|
82
82
|
const joined12 = expectPeerAvailable(client1, topic, { peerKey: peer2.toHex() });
|
|
83
83
|
const joined21 = expectPeerAvailable(client2, topic, { peerKey: peer1.toHex() });
|
|
84
84
|
|
|
85
|
-
await client1.join({ topic, peer: { peerKey: peer1.toHex() } });
|
|
86
|
-
await client2.join({ topic, peer: { peerKey: peer2.toHex() } });
|
|
85
|
+
await client1.join(Context.default(), { topic, peer: { peerKey: peer1.toHex() } });
|
|
86
|
+
await client2.join(Context.default(), { topic, peer: { peerKey: peer2.toHex() } });
|
|
87
87
|
|
|
88
88
|
await Promise.all([joined12, joined21]);
|
|
89
89
|
});
|
|
@@ -98,15 +98,15 @@ describe.skip('WebSocketSignalManager', () => {
|
|
|
98
98
|
const joined112 = expectPeerAvailable(client1, topic1, { peerKey: peer2.toHex() });
|
|
99
99
|
const joined121 = expectPeerAvailable(client2, topic1, { peerKey: peer1.toHex() });
|
|
100
100
|
|
|
101
|
-
await client1.join({ topic: topic1, peer: { peerKey: peer1.toHex() } });
|
|
102
|
-
await client2.join({ topic: topic1, peer: { peerKey: peer2.toHex() } });
|
|
101
|
+
await client1.join(Context.default(), { topic: topic1, peer: { peerKey: peer1.toHex() } });
|
|
102
|
+
await client2.join(Context.default(), { topic: topic1, peer: { peerKey: peer2.toHex() } });
|
|
103
103
|
await Promise.all([joined112, joined121]);
|
|
104
104
|
|
|
105
105
|
const joined212 = expectPeerAvailable(client1, topic2, { peerKey: peer2.toHex() });
|
|
106
106
|
const joined221 = expectPeerAvailable(client2, topic2, { peerKey: peer1.toHex() });
|
|
107
107
|
|
|
108
|
-
await client1.join({ topic: topic2, peer: { peerKey: peer1.toHex() } });
|
|
109
|
-
await client2.join({ topic: topic2, peer: { peerKey: peer2.toHex() } });
|
|
108
|
+
await client1.join(Context.default(), { topic: topic2, peer: { peerKey: peer1.toHex() } });
|
|
109
|
+
await client2.join(Context.default(), { topic: topic2, peer: { peerKey: peer2.toHex() } });
|
|
110
110
|
await Promise.all([joined212, joined221]);
|
|
111
111
|
});
|
|
112
112
|
});
|
|
@@ -3,11 +3,10 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { Event, sleep, synchronized } from '@dxos/async';
|
|
6
|
-
import { LifecycleState, Resource } from '@dxos/context';
|
|
6
|
+
import { type Context, LifecycleState, Resource } from '@dxos/context';
|
|
7
7
|
import { invariant } from '@dxos/invariant';
|
|
8
|
-
import { PublicKey } from '@dxos/keys';
|
|
9
8
|
import { log } from '@dxos/log';
|
|
10
|
-
import { RateLimitExceededError, TimeoutError
|
|
9
|
+
import { RateLimitExceededError, TimeoutError } from '@dxos/protocols';
|
|
11
10
|
import { type Runtime } from '@dxos/protocols/proto/dxos/config';
|
|
12
11
|
import { type SwarmResponse } from '@dxos/protocols/proto/dxos/edge/messenger';
|
|
13
12
|
import { type JoinRequest, type LeaveRequest, type QueryRequest } from '@dxos/protocols/proto/dxos/edge/signal';
|
|
@@ -22,7 +21,6 @@ import {
|
|
|
22
21
|
type SignalStatus,
|
|
23
22
|
type SwarmEvent,
|
|
24
23
|
} from '../signal-methods';
|
|
25
|
-
|
|
26
24
|
import { type SignalManager } from './signal-manager';
|
|
27
25
|
import { WebsocketSignalManagerMonitor } from './websocket-signal-manager-monitor';
|
|
28
26
|
|
|
@@ -49,8 +47,6 @@ export class WebsocketSignalManager extends Resource implements SignalManager {
|
|
|
49
47
|
|
|
50
48
|
readonly onMessage = new Event<Message>();
|
|
51
49
|
|
|
52
|
-
private readonly _instanceId = PublicKey.random().toHex();
|
|
53
|
-
|
|
54
50
|
constructor(
|
|
55
51
|
private readonly _hosts: Runtime.Services.Signal[],
|
|
56
52
|
private readonly _getMetadata?: () => any,
|
|
@@ -77,11 +73,8 @@ export class WebsocketSignalManager extends Resource implements SignalManager {
|
|
|
77
73
|
|
|
78
74
|
protected override async _open(): Promise<void> {
|
|
79
75
|
log('open signal manager', { hosts: this._hosts });
|
|
80
|
-
log.trace('dxos.mesh.websocket-signal-manager.open', trace.begin({ id: this._instanceId }));
|
|
81
76
|
|
|
82
77
|
await safeAwaitAll(this._servers.values(), (server) => server.open());
|
|
83
|
-
|
|
84
|
-
log.trace('dxos.mesh.websocket-signal-manager.open', trace.end({ id: this._instanceId }));
|
|
85
78
|
}
|
|
86
79
|
|
|
87
80
|
protected override async _close(): Promise<void> {
|
|
@@ -105,30 +98,30 @@ export class WebsocketSignalManager extends Resource implements SignalManager {
|
|
|
105
98
|
}
|
|
106
99
|
|
|
107
100
|
@synchronized
|
|
108
|
-
async join({ topic, peer }: JoinRequest): Promise<void> {
|
|
101
|
+
async join(_ctx: Context, { topic, peer }: JoinRequest): Promise<void> {
|
|
109
102
|
log('join', { topic, peer });
|
|
110
103
|
invariant(this._lifecycleState === LifecycleState.OPEN);
|
|
111
|
-
await this._forEachServer((server) => server.join({ topic, peer }));
|
|
104
|
+
await this._forEachServer((server) => server.join(_ctx, { topic, peer }));
|
|
112
105
|
}
|
|
113
106
|
|
|
114
107
|
@synchronized
|
|
115
|
-
async leave({ topic, peer }: LeaveRequest): Promise<void> {
|
|
108
|
+
async leave(_ctx: Context, { topic, peer }: LeaveRequest): Promise<void> {
|
|
116
109
|
log('leaving', { topic, peer });
|
|
117
110
|
invariant(this._lifecycleState === LifecycleState.OPEN);
|
|
118
|
-
await this._forEachServer((server) => server.leave({ topic, peer }));
|
|
111
|
+
await this._forEachServer((server) => server.leave(_ctx, { topic, peer }));
|
|
119
112
|
}
|
|
120
113
|
|
|
121
|
-
async query({ topic }: QueryRequest): Promise<SwarmResponse> {
|
|
114
|
+
async query(_ctx: Context, { topic }: QueryRequest): Promise<SwarmResponse> {
|
|
122
115
|
throw new Error('Not implemented');
|
|
123
116
|
}
|
|
124
117
|
|
|
125
|
-
async sendMessage({ author, recipient, payload }: Message): Promise<void> {
|
|
118
|
+
async sendMessage(_ctx: Context, { author, recipient, payload }: Message): Promise<void> {
|
|
126
119
|
log('signal', { recipient });
|
|
127
120
|
invariant(this._lifecycleState === LifecycleState.OPEN);
|
|
128
121
|
|
|
129
122
|
void this._forEachServer(async (server, serverName, index) => {
|
|
130
123
|
void server
|
|
131
|
-
.sendMessage({ author, recipient, payload })
|
|
124
|
+
.sendMessage(_ctx, { author, recipient, payload })
|
|
132
125
|
.then(() => this._clearServerFailedFlag(serverName, index))
|
|
133
126
|
.catch((err) => {
|
|
134
127
|
if (err instanceof RateLimitExceededError) {
|
package/src/signal-methods.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { type Event } from '@dxos/async';
|
|
6
|
-
import { type Lifecycle } from '@dxos/context';
|
|
6
|
+
import { type Context, type Lifecycle } from '@dxos/context';
|
|
7
7
|
import { type Peer, type SwarmResponse } from '@dxos/protocols/proto/dxos/edge/messenger';
|
|
8
8
|
import {
|
|
9
9
|
type JoinRequest,
|
|
@@ -51,22 +51,22 @@ export interface SignalMethods {
|
|
|
51
51
|
/**
|
|
52
52
|
* Join topic on signal network, to be discoverable by other peers.
|
|
53
53
|
*/
|
|
54
|
-
join: (params: JoinRequest) => Promise<void>;
|
|
54
|
+
join: (ctx: Context, params: JoinRequest) => Promise<void>;
|
|
55
55
|
|
|
56
56
|
/**
|
|
57
57
|
* Leave topic on signal network, to stop being discoverable by other peers.
|
|
58
58
|
*/
|
|
59
|
-
leave: (params: LeaveRequest) => Promise<void>;
|
|
59
|
+
leave: (ctx: Context, params: LeaveRequest) => Promise<void>;
|
|
60
60
|
|
|
61
61
|
/**
|
|
62
62
|
* Query peers in the swarm without joining it.
|
|
63
63
|
*/
|
|
64
|
-
query: (params: QueryRequest) => Promise<SwarmResponse>;
|
|
64
|
+
query: (ctx: Context, params: QueryRequest) => Promise<SwarmResponse>;
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
67
|
* Send message to peer.
|
|
68
68
|
*/
|
|
69
|
-
sendMessage: (message: Message) => Promise<void>;
|
|
69
|
+
sendMessage: (ctx: Context, message: Message) => Promise<void>;
|
|
70
70
|
|
|
71
71
|
/**
|
|
72
72
|
* Start receiving messages from peer.
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { type Context } from '@dxos/context';
|
|
6
|
+
|
|
5
7
|
import { MemorySignalManager, MemorySignalManagerContext, type SignalManager } from '../signal-manager';
|
|
6
8
|
import { type Message } from '../signal-methods';
|
|
7
|
-
|
|
8
9
|
import { TestPeer } from './test-peer';
|
|
9
10
|
|
|
10
11
|
export type TestBuilderOptions = {
|
|
@@ -25,9 +26,9 @@ export class TestBuilder {
|
|
|
25
26
|
if (this.options.messageDisruption) {
|
|
26
27
|
// Imitates signal network disruptions (e. g. message doubling, ).
|
|
27
28
|
const trueSend = signalManager.sendMessage.bind(signalManager);
|
|
28
|
-
signalManager.sendMessage = async (message: Message) => {
|
|
29
|
+
signalManager.sendMessage = async (ctx: Context, message: Message) => {
|
|
29
30
|
for (const msg of this.options.messageDisruption!(message)) {
|
|
30
|
-
await trueSend(msg);
|
|
31
|
+
await trueSend(ctx, msg);
|
|
31
32
|
}
|
|
32
33
|
};
|
|
33
34
|
}
|
package/src/testing/test-peer.ts
CHANGED
|
@@ -12,7 +12,6 @@ import { buf } from '@dxos/protocols/buf';
|
|
|
12
12
|
import { Messenger } from '../messenger';
|
|
13
13
|
import { type SignalManager } from '../signal-manager';
|
|
14
14
|
import { type Message, type PeerInfo } from '../signal-methods';
|
|
15
|
-
|
|
16
15
|
import { type TestBuilder } from './test-builder';
|
|
17
16
|
import { expectPeerAvailable, expectPeerLeft, expectReceivedMessage } from './utils';
|
|
18
17
|
|
package/src/testing/utils.ts
CHANGED
|
@@ -7,7 +7,6 @@ import { type Any } from '@dxos/codec-protobuf';
|
|
|
7
7
|
import { PublicKey } from '@dxos/keys';
|
|
8
8
|
|
|
9
9
|
import { type Message, type PeerInfo, type SignalMethods } from '../signal-methods';
|
|
10
|
-
|
|
11
10
|
import { PAYLOAD_1 } from './test-messages';
|
|
12
11
|
|
|
13
12
|
export const expectPeerAvailable = (client: SignalMethods, expectedTopic: PublicKey, peer: PeerInfo) =>
|