@dxos/messaging 0.8.3 → 0.8.4-main.1068cf700f
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-5MOQVHHI.mjs +694 -0
- package/dist/lib/neutral/chunk-5MOQVHHI.mjs.map +7 -0
- package/dist/lib/{browser/chunk-ISA3S2ZX.mjs → neutral/index.mjs} +412 -1018
- 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 -12
- package/dist/lib/neutral/testing/index.mjs.map +7 -0
- package/dist/types/src/messenger.blueprint-test.d.ts.map +1 -1
- package/dist/types/src/messenger.d.ts +1 -1
- package/dist/types/src/messenger.d.ts.map +1 -1
- package/dist/types/src/signal-client/signal-client.d.ts +2 -2
- package/dist/types/src/signal-client/signal-client.d.ts.map +1 -1
- package/dist/types/src/signal-client/signal-local-state.d.ts +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.d.ts +2 -2
- 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 +1 -1
- package/dist/types/src/signal-manager/edge-signal-manager.d.ts.map +1 -1
- package/dist/types/src/signal-manager/index.d.ts +1 -1
- package/dist/types/src/signal-manager/index.d.ts.map +1 -1
- package/dist/types/src/signal-manager/memory-signal-manager.d.ts +1 -1
- package/dist/types/src/signal-manager/memory-signal-manager.d.ts.map +1 -1
- package/dist/types/src/signal-manager/signal-manager.d.ts +1 -1
- package/dist/types/src/signal-manager/signal-manager.d.ts.map +1 -1
- package/dist/types/src/signal-manager/websocket-signal-manager.d.ts +1 -1
- package/dist/types/src/signal-manager/websocket-signal-manager.d.ts.map +1 -1
- package/dist/types/src/signal-methods.d.ts +2 -2
- package/dist/types/src/signal-methods.d.ts.map +1 -1
- package/dist/types/src/testing/test-builder.d.ts +1 -1
- package/dist/types/src/testing/test-builder.d.ts.map +1 -1
- package/dist/types/src/testing/test-peer.d.ts +1 -1
- package/dist/types/src/testing/test-peer.d.ts.map +1 -1
- package/dist/types/src/testing/utils.d.ts +1 -1
- package/dist/types/src/testing/utils.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +25 -21
- package/src/messenger.blueprint-test.ts +2 -2
- package/src/messenger.node.test.ts +7 -38
- package/src/messenger.ts +5 -5
- package/src/signal-client/signal-client.node.test.ts +4 -3
- package/src/signal-client/signal-client.ts +7 -6
- package/src/signal-client/signal-local-state.ts +4 -3
- package/src/signal-client/signal-rpc-client.node.test.ts +1 -1
- package/src/signal-client/signal-rpc-client.ts +6 -6
- package/src/signal-manager/edge-signal-manager.ts +23 -13
- package/src/signal-manager/index.ts +1 -1
- package/src/signal-manager/memory-signal-manager.ts +2 -1
- package/src/signal-manager/signal-manager.ts +1 -1
- package/src/signal-manager/websocket-signal-manager.node.test.ts +3 -2
- package/src/signal-manager/websocket-signal-manager.ts +4 -3
- package/src/signal-methods.ts +3 -3
- package/src/testing/test-builder.ts +3 -2
- package/src/testing/test-peer.ts +3 -2
- package/src/testing/utils.ts +3 -2
- package/dist/lib/browser/chunk-ISA3S2ZX.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/chunk-GMND65DN.cjs +0 -2291
- package/dist/lib/node/chunk-GMND65DN.cjs.map +0 -7
- package/dist/lib/node/index.cjs +0 -43
- package/dist/lib/node/index.cjs.map +0 -7
- package/dist/lib/node/meta.json +0 -1
- package/dist/lib/node/testing/index.cjs +0 -159
- package/dist/lib/node/testing/index.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-SO4RY3ON.mjs +0 -2309
- package/dist/lib/node-esm/chunk-SO4RY3ON.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 -143
- package/dist/lib/node-esm/testing/index.mjs.map +0 -7
package/package.json
CHANGED
|
@@ -1,23 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/messaging",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.4-main.1068cf700f",
|
|
4
4
|
"description": "Messaging",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/dxos/dxos"
|
|
10
|
+
},
|
|
7
11
|
"license": "MIT",
|
|
8
12
|
"author": "DXOS.org",
|
|
9
|
-
"sideEffects":
|
|
13
|
+
"sideEffects": false,
|
|
10
14
|
"type": "module",
|
|
11
15
|
"exports": {
|
|
12
16
|
".": {
|
|
17
|
+
"source": "./src/index.ts",
|
|
13
18
|
"types": "./dist/types/src/index.d.ts",
|
|
14
|
-
"
|
|
15
|
-
"node": "./dist/lib/node-esm/index.mjs"
|
|
19
|
+
"default": "./dist/lib/neutral/index.mjs"
|
|
16
20
|
},
|
|
17
21
|
"./testing": {
|
|
22
|
+
"source": "./src/testing/index.ts",
|
|
18
23
|
"types": "./dist/types/src/testing/index.d.ts",
|
|
19
|
-
"
|
|
20
|
-
"node": "./dist/lib/node-esm/testing/index.mjs"
|
|
24
|
+
"default": "./dist/lib/neutral/testing/index.mjs"
|
|
21
25
|
}
|
|
22
26
|
},
|
|
23
27
|
"types": "dist/types/src/index.d.ts",
|
|
@@ -36,23 +40,23 @@
|
|
|
36
40
|
"dependencies": {
|
|
37
41
|
"isomorphic-ws": "^5.0.0",
|
|
38
42
|
"ws": "^8.14.2",
|
|
39
|
-
"@dxos/async": "0.8.
|
|
40
|
-
"@dxos/context": "0.8.
|
|
41
|
-
"@dxos/edge-client": "0.8.
|
|
42
|
-
"@dxos/codec-protobuf": "0.8.
|
|
43
|
-
"@dxos/invariant": "0.8.
|
|
44
|
-
"@dxos/keys": "0.8.
|
|
45
|
-
"@dxos/log": "0.8.
|
|
46
|
-
"@dxos/node-std": "0.8.
|
|
47
|
-
"@dxos/protocols": "0.8.
|
|
48
|
-
"@dxos/
|
|
49
|
-
"@dxos/
|
|
50
|
-
"@dxos/util": "0.8.
|
|
43
|
+
"@dxos/async": "0.8.4-main.1068cf700f",
|
|
44
|
+
"@dxos/context": "0.8.4-main.1068cf700f",
|
|
45
|
+
"@dxos/edge-client": "0.8.4-main.1068cf700f",
|
|
46
|
+
"@dxos/codec-protobuf": "0.8.4-main.1068cf700f",
|
|
47
|
+
"@dxos/invariant": "0.8.4-main.1068cf700f",
|
|
48
|
+
"@dxos/keys": "0.8.4-main.1068cf700f",
|
|
49
|
+
"@dxos/log": "0.8.4-main.1068cf700f",
|
|
50
|
+
"@dxos/node-std": "0.8.4-main.1068cf700f",
|
|
51
|
+
"@dxos/protocols": "0.8.4-main.1068cf700f",
|
|
52
|
+
"@dxos/tracing": "0.8.4-main.1068cf700f",
|
|
53
|
+
"@dxos/rpc": "0.8.4-main.1068cf700f",
|
|
54
|
+
"@dxos/util": "0.8.4-main.1068cf700f"
|
|
51
55
|
},
|
|
52
56
|
"devDependencies": {
|
|
53
|
-
"@dxos/keyring": "0.8.
|
|
54
|
-
"@dxos/test-utils": "0.8.
|
|
55
|
-
"@dxos/signal": "0.8.
|
|
57
|
+
"@dxos/keyring": "0.8.4-main.1068cf700f",
|
|
58
|
+
"@dxos/test-utils": "0.8.4-main.1068cf700f",
|
|
59
|
+
"@dxos/signal": "0.8.4-main.1068cf700f"
|
|
56
60
|
},
|
|
57
61
|
"publishConfig": {
|
|
58
62
|
"access": "public"
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { describe, expect,
|
|
5
|
+
import { describe, expect, onTestFinished, test } from 'vitest';
|
|
6
6
|
|
|
7
7
|
import { asyncTimeout, latch, sleep } from '@dxos/async';
|
|
8
8
|
import { range } from '@dxos/util';
|
|
9
9
|
|
|
10
10
|
import { WebsocketSignalManager } from './signal-manager';
|
|
11
11
|
import { type Message } from './signal-methods';
|
|
12
|
-
import {
|
|
12
|
+
import { PAYLOAD_1, PAYLOAD_2, PAYLOAD_3, TestBuilder, messageEqual } from './testing';
|
|
13
13
|
|
|
14
14
|
export const messengerTests = (signalManagerFactory: TestBuilder['createSignalManager']) => {
|
|
15
15
|
test('Message between peers', async () => {
|
|
@@ -2,48 +2,17 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
import { asyncTimeout } from '@dxos/async';
|
|
8
|
-
import { runTestSignalServer, type SignalServerRunner } from '@dxos/signal';
|
|
5
|
+
import { beforeEach, describe } from 'vitest';
|
|
9
6
|
|
|
10
7
|
import { messengerTests } from './messenger.blueprint-test';
|
|
11
|
-
import {
|
|
12
|
-
import { type Message } from './signal-methods';
|
|
13
|
-
import { PAYLOAD_1, TestBuilder } from './testing';
|
|
8
|
+
import { MemorySignalManager, MemorySignalManagerContext } from './signal-manager';
|
|
14
9
|
|
|
10
|
+
// TODO(mykola): Use EDGE signal server.
|
|
15
11
|
describe('Messenger with WebsocketSignalManager', () => {
|
|
16
|
-
let
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
broker = await runTestSignalServer();
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
afterAll(() => {
|
|
23
|
-
void broker.stop();
|
|
12
|
+
let context: MemorySignalManagerContext;
|
|
13
|
+
beforeEach(async () => {
|
|
14
|
+
context = new MemorySignalManagerContext();
|
|
24
15
|
});
|
|
25
16
|
|
|
26
|
-
messengerTests(async () => new
|
|
27
|
-
|
|
28
|
-
test('Message with broken signal server', { timeout: 1000 }, async () => {
|
|
29
|
-
const builder = new TestBuilder({
|
|
30
|
-
signalManagerFactory: async () =>
|
|
31
|
-
new WebsocketSignalManager([{ server: 'ws://broken.kube.' }, { server: broker.url() }]),
|
|
32
|
-
});
|
|
33
|
-
onTestFinished(() => builder.close());
|
|
34
|
-
const peer1 = await builder.createPeer();
|
|
35
|
-
const peer2 = await builder.createPeer();
|
|
36
|
-
|
|
37
|
-
const message: Message = {
|
|
38
|
-
author: peer1.peerInfo,
|
|
39
|
-
recipient: peer2.peerInfo,
|
|
40
|
-
payload: PAYLOAD_1,
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
{
|
|
44
|
-
const receivePromise = peer2.waitTillReceive(message);
|
|
45
|
-
await peer1.messenger.sendMessage(message);
|
|
46
|
-
await asyncTimeout(receivePromise, 1_000);
|
|
47
|
-
}
|
|
48
|
-
});
|
|
17
|
+
messengerTests(async () => new MemorySignalManager(context));
|
|
49
18
|
});
|
package/src/messenger.ts
CHANGED
|
@@ -15,7 +15,7 @@ import { ComplexMap, ComplexSet } from '@dxos/util';
|
|
|
15
15
|
|
|
16
16
|
import { MessengerMonitor } from './messenger-monitor';
|
|
17
17
|
import { type SignalManager } from './signal-manager';
|
|
18
|
-
import { type
|
|
18
|
+
import { type Message, type PeerInfo } from './signal-methods';
|
|
19
19
|
import { MESSAGE_TIMEOUT } from './timeouts';
|
|
20
20
|
|
|
21
21
|
export type OnMessage = (params: Message) => Promise<void>;
|
|
@@ -140,10 +140,10 @@ export class Messenger {
|
|
|
140
140
|
log('message not delivered', { messageId: reliablePayload.messageId });
|
|
141
141
|
this._onAckCallbacks.delete(reliablePayload.messageId!);
|
|
142
142
|
timeoutHit(
|
|
143
|
-
new ProtocolTimeoutError(
|
|
144
|
-
'signaling message not delivered',
|
|
145
|
-
new TimeoutError(MESSAGE_TIMEOUT, 'Message not delivered'),
|
|
146
|
-
),
|
|
143
|
+
new ProtocolTimeoutError({
|
|
144
|
+
message: 'signaling message not delivered',
|
|
145
|
+
cause: new TimeoutError(MESSAGE_TIMEOUT, 'Message not delivered'),
|
|
146
|
+
}),
|
|
147
147
|
);
|
|
148
148
|
void messageContext.dispose();
|
|
149
149
|
this._monitor.recordReliableMessage({ sendAttempts, sent: false });
|
|
@@ -2,19 +2,20 @@
|
|
|
2
2
|
// Copyright 2020 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { afterAll, beforeAll, describe, expect,
|
|
5
|
+
import { afterAll, beforeAll, describe, expect, onTestFinished, test } from 'vitest';
|
|
6
6
|
|
|
7
7
|
import { asyncTimeout, waitForCondition } from '@dxos/async';
|
|
8
8
|
import { type Any, type TaggedType } from '@dxos/codec-protobuf';
|
|
9
9
|
import { PublicKey } from '@dxos/keys';
|
|
10
10
|
import { log } from '@dxos/log';
|
|
11
11
|
import { type TYPES } from '@dxos/protocols/proto';
|
|
12
|
-
import {
|
|
12
|
+
import { type SignalServerRunner, runTestSignalServer } from '@dxos/signal';
|
|
13
13
|
import { ComplexSet, range } from '@dxos/util';
|
|
14
14
|
|
|
15
|
-
import { SignalClient } from './signal-client';
|
|
16
15
|
import { type Message, type PeerInfo } from '../signal-methods';
|
|
17
16
|
|
|
17
|
+
import { SignalClient } from './signal-client';
|
|
18
|
+
|
|
18
19
|
const PAYLOAD: TaggedType<TYPES, 'google.protobuf.Any'> = {
|
|
19
20
|
'@type': 'google.protobuf.Any',
|
|
20
21
|
type_url: 'google.protobuf.Any',
|
|
@@ -3,26 +3,27 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { DeferredTask, Event, Trigger, scheduleTask, scheduleTaskInterval, sleep } from '@dxos/async';
|
|
6
|
-
import { type Context,
|
|
6
|
+
import { type Context, Resource, cancelWithContext } from '@dxos/context';
|
|
7
7
|
import { invariant } from '@dxos/invariant';
|
|
8
8
|
import { PublicKey } from '@dxos/keys';
|
|
9
9
|
import { log } from '@dxos/log';
|
|
10
10
|
import { trace } from '@dxos/protocols';
|
|
11
11
|
import { type SwarmResponse } from '@dxos/protocols/proto/dxos/edge/messenger';
|
|
12
|
-
import { type
|
|
12
|
+
import { type JoinRequest, type LeaveRequest, type QueryRequest } from '@dxos/protocols/proto/dxos/edge/signal';
|
|
13
13
|
import { SignalState } from '@dxos/protocols/proto/dxos/mesh/signal';
|
|
14
14
|
|
|
15
|
-
import { SignalClientMonitor } from './signal-client-monitor';
|
|
16
|
-
import { SignalLocalState } from './signal-local-state';
|
|
17
|
-
import { SignalRPCClient } from './signal-rpc-client';
|
|
18
15
|
import {
|
|
19
|
-
type PeerInfo,
|
|
20
16
|
type Message,
|
|
17
|
+
type PeerInfo,
|
|
21
18
|
type SignalClientMethods,
|
|
22
19
|
type SignalStatus,
|
|
23
20
|
type SwarmEvent,
|
|
24
21
|
} from '../signal-methods';
|
|
25
22
|
|
|
23
|
+
import { SignalClientMonitor } from './signal-client-monitor';
|
|
24
|
+
import { SignalLocalState } from './signal-local-state';
|
|
25
|
+
import { SignalRPCClient } from './signal-rpc-client';
|
|
26
|
+
|
|
26
27
|
const DEFAULT_RECONNECT_TIMEOUT = 100;
|
|
27
28
|
const MAX_RECONNECT_TIMEOUT = 5_000;
|
|
28
29
|
const ERROR_RECONCILE_DELAY = 1_000;
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { Event, asyncTimeout } from '@dxos/async';
|
|
6
6
|
import type { Stream } from '@dxos/codec-protobuf/stream';
|
|
7
|
-
import {
|
|
7
|
+
import { type Context, cancelWithContext } from '@dxos/context';
|
|
8
8
|
import { PublicKey } from '@dxos/keys';
|
|
9
9
|
import { log } from '@dxos/log';
|
|
10
10
|
import {
|
|
@@ -13,9 +13,10 @@ import {
|
|
|
13
13
|
} from '@dxos/protocols/proto/dxos/mesh/signal';
|
|
14
14
|
import { ComplexMap, ComplexSet, safeAwaitAll } from '@dxos/util';
|
|
15
15
|
|
|
16
|
-
import { type SignalRPCClient } from './signal-rpc-client';
|
|
17
16
|
import type { Message, SwarmEvent } from '../signal-methods';
|
|
18
17
|
|
|
18
|
+
import { type SignalRPCClient } from './signal-rpc-client';
|
|
19
|
+
|
|
19
20
|
export class SignalLocalState {
|
|
20
21
|
/**
|
|
21
22
|
* Swarm events streams. Keys represent actually joined topic and peerId.
|
|
@@ -9,7 +9,7 @@ import { PublicKey } from '@dxos/keys';
|
|
|
9
9
|
import { log } from '@dxos/log';
|
|
10
10
|
import { schema } from '@dxos/protocols/proto';
|
|
11
11
|
import { type Message as SignalMessage, type SwarmEvent } from '@dxos/protocols/proto/dxos/mesh/signal';
|
|
12
|
-
import {
|
|
12
|
+
import { type SignalServerRunner, runTestSignalServer } from '@dxos/signal';
|
|
13
13
|
|
|
14
14
|
import { SignalRPCClient } from './signal-rpc-client';
|
|
15
15
|
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import WebSocket from 'isomorphic-ws';
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { TimeoutError, Trigger, scheduleTaskInterval } from '@dxos/async';
|
|
8
8
|
import { type Any, type Stream } from '@dxos/codec-protobuf';
|
|
9
9
|
import { Context } from '@dxos/context';
|
|
10
10
|
import { invariant } from '@dxos/invariant';
|
|
@@ -12,8 +12,8 @@ import { PublicKey } from '@dxos/keys';
|
|
|
12
12
|
import { log } from '@dxos/log';
|
|
13
13
|
import { trace } from '@dxos/protocols';
|
|
14
14
|
import { schema } from '@dxos/protocols/proto';
|
|
15
|
-
import { type Message as SignalMessage
|
|
16
|
-
import {
|
|
15
|
+
import { type Signal, type Message as SignalMessage } from '@dxos/protocols/proto/dxos/mesh/signal';
|
|
16
|
+
import { type ProtoRpcPeer, createProtoRpcPeer } from '@dxos/rpc';
|
|
17
17
|
|
|
18
18
|
import { SignalRpcClientMonitor } from './signal-rpc-client-monitor';
|
|
19
19
|
|
|
@@ -36,7 +36,7 @@ export type SignalCallbacks = {
|
|
|
36
36
|
getMetadata?: () => any;
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
-
export type
|
|
39
|
+
export type SignalRPCClientProps = {
|
|
40
40
|
url: string;
|
|
41
41
|
callbacks?: SignalCallbacks;
|
|
42
42
|
};
|
|
@@ -61,7 +61,7 @@ export class SignalRPCClient {
|
|
|
61
61
|
|
|
62
62
|
private readonly _monitor = new SignalRpcClientMonitor();
|
|
63
63
|
|
|
64
|
-
constructor({ url, callbacks = {} }:
|
|
64
|
+
constructor({ url, callbacks = {} }: SignalRPCClientProps) {
|
|
65
65
|
const traceId = PublicKey.random().toHex();
|
|
66
66
|
log.trace('dxos.mesh.signal-rpc-client.constructor', trace.begin({ id: traceId }));
|
|
67
67
|
this._url = url;
|
|
@@ -169,7 +169,7 @@ export class SignalRPCClient {
|
|
|
169
169
|
|
|
170
170
|
await this._closeComplete.wait({ timeout: 1_000 });
|
|
171
171
|
} catch (err) {
|
|
172
|
-
const failureReason = err instanceof TimeoutError ? 'timeout' : err?.constructor?.name ?? 'unknown';
|
|
172
|
+
const failureReason = err instanceof TimeoutError ? 'timeout' : (err?.constructor?.name ?? 'unknown');
|
|
173
173
|
this._monitor.recordClientCloseFailure({ failureReason });
|
|
174
174
|
}
|
|
175
175
|
}
|
|
@@ -3,25 +3,26 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { Event, scheduleMicroTask } from '@dxos/async';
|
|
6
|
-
import {
|
|
7
|
-
import { type EdgeConnection, protocol } from '@dxos/edge-client';
|
|
6
|
+
import { Resource, cancelWithContext } from '@dxos/context';
|
|
7
|
+
import { type EdgeConnection, EdgeIdentityChangedError, protocol } from '@dxos/edge-client';
|
|
8
8
|
import { invariant } from '@dxos/invariant';
|
|
9
9
|
import { PublicKey } from '@dxos/keys';
|
|
10
10
|
import { log } from '@dxos/log';
|
|
11
11
|
import { EdgeService } from '@dxos/protocols';
|
|
12
12
|
import { type buf, bufWkt } from '@dxos/protocols/buf';
|
|
13
13
|
import {
|
|
14
|
-
SwarmRequestSchema,
|
|
15
|
-
SwarmRequest_Action as SwarmRequestAction,
|
|
16
|
-
SwarmResponseSchema,
|
|
17
14
|
type Message as EdgeMessage,
|
|
18
15
|
type PeerSchema,
|
|
16
|
+
SwarmRequest_Action as SwarmRequestAction,
|
|
17
|
+
SwarmRequestSchema,
|
|
18
|
+
SwarmResponseSchema,
|
|
19
19
|
} from '@dxos/protocols/buf/dxos/edge/messenger_pb';
|
|
20
20
|
import { type SwarmResponse } from '@dxos/protocols/proto/dxos/edge/messenger';
|
|
21
21
|
import { ComplexMap, ComplexSet } from '@dxos/util';
|
|
22
22
|
|
|
23
|
+
import { type Message, type PeerInfo, PeerInfoHash, type SwarmEvent } from '../signal-methods';
|
|
24
|
+
|
|
23
25
|
import { type SignalManager } from './signal-manager';
|
|
24
|
-
import { type PeerInfo, type Message, type SwarmEvent, PeerInfoHash } from '../signal-methods';
|
|
25
26
|
|
|
26
27
|
export class EdgeSignalManager extends Resource implements SignalManager {
|
|
27
28
|
/**
|
|
@@ -86,13 +87,22 @@ export class EdgeSignalManager extends Resource implements SignalManager {
|
|
|
86
87
|
|
|
87
88
|
async leave({ topic, peer }: { topic: PublicKey; peer: PeerInfo }): Promise<void> {
|
|
88
89
|
this._swarmPeers.delete(topic);
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
90
|
+
try {
|
|
91
|
+
await this._edgeConnection.send(
|
|
92
|
+
protocol.createMessage(SwarmRequestSchema, {
|
|
93
|
+
serviceId: EdgeService.SWARM,
|
|
94
|
+
source: createMessageSource(topic, peer),
|
|
95
|
+
payload: { action: SwarmRequestAction.LEAVE, swarmKeys: [topic.toHex()] },
|
|
96
|
+
}),
|
|
97
|
+
);
|
|
98
|
+
} catch (err) {
|
|
99
|
+
if (err instanceof EdgeIdentityChangedError) {
|
|
100
|
+
// Note: On edge identity change, the connection is closed and EDGE will remove us from the swarm.
|
|
101
|
+
// So we should just delete the swarm from _swarmPeers.
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
throw err;
|
|
105
|
+
}
|
|
96
106
|
}
|
|
97
107
|
|
|
98
108
|
async query({ topic }: { topic: PublicKey }): Promise<SwarmResponse> {
|
|
@@ -13,8 +13,9 @@ import { type SwarmResponse } from '@dxos/protocols/proto/dxos/edge/messenger';
|
|
|
13
13
|
import { type QueryRequest } from '@dxos/protocols/proto/dxos/edge/signal';
|
|
14
14
|
import { ComplexMap, ComplexSet } from '@dxos/util';
|
|
15
15
|
|
|
16
|
+
import { type Message, type PeerInfo, PeerInfoHash, type SignalStatus, type SwarmEvent } from '../signal-methods';
|
|
17
|
+
|
|
16
18
|
import { type SignalManager } from './signal-manager';
|
|
17
|
-
import { type SwarmEvent, type PeerInfo, type SignalStatus, type Message, PeerInfoHash } from '../signal-methods';
|
|
18
19
|
|
|
19
20
|
/**
|
|
20
21
|
* Common signaling context that connects multiple MemorySignalManager instances.
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { type Event } from '@dxos/async';
|
|
6
6
|
import { type Lifecycle } from '@dxos/context';
|
|
7
7
|
|
|
8
|
-
import { type
|
|
8
|
+
import { type SignalMethods, type SignalStatus } from '../signal-methods';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Manages a collection of signaling clients.
|
|
@@ -6,12 +6,13 @@ import { afterAll, beforeAll, describe, test } from 'vitest';
|
|
|
6
6
|
|
|
7
7
|
import { asyncTimeout, sleep } from '@dxos/async';
|
|
8
8
|
import { PublicKey } from '@dxos/keys';
|
|
9
|
-
import {
|
|
9
|
+
import { type SignalServerRunner, runTestSignalServer } from '@dxos/signal';
|
|
10
10
|
import { openAndClose } from '@dxos/test-utils';
|
|
11
11
|
|
|
12
|
-
import { WebsocketSignalManager } from './websocket-signal-manager';
|
|
13
12
|
import { createMessage, expectPeerAvailable, expectReceivedMessage } from '../testing';
|
|
14
13
|
|
|
14
|
+
import { WebsocketSignalManager } from './websocket-signal-manager';
|
|
15
|
+
|
|
15
16
|
describe.skip('WebSocketSignalManager', () => {
|
|
16
17
|
let broker1: SignalServerRunner;
|
|
17
18
|
let broker2: SignalServerRunner;
|
|
@@ -13,18 +13,19 @@ import { type SwarmResponse } from '@dxos/protocols/proto/dxos/edge/messenger';
|
|
|
13
13
|
import { type JoinRequest, type LeaveRequest, type QueryRequest } from '@dxos/protocols/proto/dxos/edge/signal';
|
|
14
14
|
import { BitField, safeAwaitAll } from '@dxos/util';
|
|
15
15
|
|
|
16
|
-
import { type SignalManager } from './signal-manager';
|
|
17
|
-
import { WebsocketSignalManagerMonitor } from './websocket-signal-manager-monitor';
|
|
18
16
|
import { SignalClient } from '../signal-client';
|
|
19
17
|
import {
|
|
20
|
-
type PeerInfo,
|
|
21
18
|
type Message,
|
|
19
|
+
type PeerInfo,
|
|
22
20
|
type SignalClientMethods,
|
|
23
21
|
type SignalMethods,
|
|
24
22
|
type SignalStatus,
|
|
25
23
|
type SwarmEvent,
|
|
26
24
|
} from '../signal-methods';
|
|
27
25
|
|
|
26
|
+
import { type SignalManager } from './signal-manager';
|
|
27
|
+
import { WebsocketSignalManagerMonitor } from './websocket-signal-manager-monitor';
|
|
28
|
+
|
|
28
29
|
const MAX_SERVER_FAILURES = 5;
|
|
29
30
|
const WSS_SIGNAL_SERVER_REBOOT_DELAY = 3_000;
|
|
30
31
|
|
package/src/signal-methods.ts
CHANGED
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
|
|
5
5
|
import { type Event } from '@dxos/async';
|
|
6
6
|
import { type Lifecycle } from '@dxos/context';
|
|
7
|
-
import { type
|
|
7
|
+
import { type Peer, type SwarmResponse } from '@dxos/protocols/proto/dxos/edge/messenger';
|
|
8
8
|
import {
|
|
9
|
+
type JoinRequest,
|
|
9
10
|
type LeaveRequest,
|
|
10
11
|
type Message,
|
|
11
|
-
type SwarmEvent,
|
|
12
|
-
type JoinRequest,
|
|
13
12
|
type QueryRequest,
|
|
13
|
+
type SwarmEvent,
|
|
14
14
|
} from '@dxos/protocols/proto/dxos/edge/signal';
|
|
15
15
|
import { type SignalState } from '@dxos/protocols/proto/dxos/mesh/signal';
|
|
16
16
|
|
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import { type SignalManager, MemorySignalManager, MemorySignalManagerContext } from '../signal-manager';
|
|
5
|
+
import { MemorySignalManager, MemorySignalManagerContext, type SignalManager } from '../signal-manager';
|
|
7
6
|
import { type Message } from '../signal-methods';
|
|
8
7
|
|
|
8
|
+
import { TestPeer } from './test-peer';
|
|
9
|
+
|
|
9
10
|
export type TestBuilderOptions = {
|
|
10
11
|
signalManagerFactory?: (peer: TestPeer) => Promise<SignalManager>;
|
|
11
12
|
messageDisruption?: (msg: Message) => Message[];
|
package/src/testing/test-peer.ts
CHANGED
|
@@ -9,12 +9,13 @@ import { PublicKey } from '@dxos/keys';
|
|
|
9
9
|
import { log } from '@dxos/log';
|
|
10
10
|
import { buf } from '@dxos/protocols/buf';
|
|
11
11
|
|
|
12
|
-
import { type TestBuilder } from './test-builder';
|
|
13
|
-
import { expectPeerAvailable, expectPeerLeft, expectReceivedMessage } from './utils';
|
|
14
12
|
import { Messenger } from '../messenger';
|
|
15
13
|
import { type SignalManager } from '../signal-manager';
|
|
16
14
|
import { type Message, type PeerInfo } from '../signal-methods';
|
|
17
15
|
|
|
16
|
+
import { type TestBuilder } from './test-builder';
|
|
17
|
+
import { expectPeerAvailable, expectPeerLeft, expectReceivedMessage } from './utils';
|
|
18
|
+
|
|
18
19
|
export class TestPeer extends Resource {
|
|
19
20
|
public peerId = PublicKey.random();
|
|
20
21
|
public signalManager!: SignalManager;
|
package/src/testing/utils.ts
CHANGED
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { type Event, asyncTimeout } from '@dxos/async';
|
|
6
6
|
import { type Any } from '@dxos/codec-protobuf';
|
|
7
7
|
import { PublicKey } from '@dxos/keys';
|
|
8
8
|
|
|
9
|
+
import { type Message, type PeerInfo, type SignalMethods } from '../signal-methods';
|
|
10
|
+
|
|
9
11
|
import { PAYLOAD_1 } from './test-messages';
|
|
10
|
-
import { type SignalMethods, type Message, type PeerInfo } from '../signal-methods';
|
|
11
12
|
|
|
12
13
|
export const expectPeerAvailable = (client: SignalMethods, expectedTopic: PublicKey, peer: PeerInfo) =>
|
|
13
14
|
asyncTimeout(
|