@dxos/network-manager 0.6.8-main.3be982f → 0.6.8-staging.63bcb81
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/browser/{chunk-ZT4NXID2.mjs → chunk-ZQ4OU7JZ.mjs} +289 -251
- package/dist/lib/browser/chunk-ZQ4OU7JZ.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +5 -2
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node/{chunk-DZJ3BJOK.cjs → chunk-IQBYIEAR.cjs} +294 -256
- package/dist/lib/node/chunk-IQBYIEAR.cjs.map +7 -0
- package/dist/lib/node/index.cjs +28 -28
- package/dist/lib/node/index.cjs.map +1 -1
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +22 -19
- package/dist/lib/node/testing/index.cjs.map +3 -3
- package/dist/types/src/network-manager.d.ts +9 -6
- package/dist/types/src/network-manager.d.ts.map +1 -1
- package/dist/types/src/signal/signal-connection.d.ts +3 -2
- package/dist/types/src/signal/signal-connection.d.ts.map +1 -1
- package/dist/types/src/signal/signal-messenger.d.ts +5 -4
- package/dist/types/src/signal/signal-messenger.d.ts.map +1 -1
- package/dist/types/src/signal/swarm-messenger.d.ts +4 -7
- package/dist/types/src/signal/swarm-messenger.d.ts.map +1 -1
- package/dist/types/src/swarm/connection.d.ts +4 -4
- package/dist/types/src/swarm/connection.d.ts.map +1 -1
- package/dist/types/src/swarm/peer.d.ts +5 -4
- package/dist/types/src/swarm/peer.d.ts.map +1 -1
- package/dist/types/src/swarm/swarm-mapper.d.ts.map +1 -1
- package/dist/types/src/swarm/swarm.d.ts +4 -4
- package/dist/types/src/swarm/swarm.d.ts.map +1 -1
- package/dist/types/src/tests/basic-test-suite.d.ts.map +1 -1
- package/dist/types/src/tests/property-test-suite.d.ts.map +1 -1
- package/package.json +19 -18
- package/src/connection-log.ts +1 -1
- package/src/network-manager.ts +27 -13
- package/src/signal/integration.test.ts +25 -19
- package/src/signal/signal-connection.ts +3 -2
- package/src/signal/signal-messenger.ts +5 -4
- package/src/signal/swarm-messenger.test.ts +21 -21
- package/src/signal/swarm-messenger.ts +11 -10
- package/src/swarm/connection.test.ts +19 -17
- package/src/swarm/connection.ts +16 -15
- package/src/swarm/peer.ts +41 -35
- package/src/swarm/swarm-mapper.ts +7 -6
- package/src/swarm/swarm.test.ts +36 -28
- package/src/swarm/swarm.ts +57 -53
- package/src/testing/test-builder.ts +1 -1
- package/src/tests/basic-test-suite.ts +8 -5
- package/src/tests/property-test-suite.ts +4 -1
- package/dist/lib/browser/chunk-ZT4NXID2.mjs.map +0 -7
- package/dist/lib/node/chunk-DZJ3BJOK.cjs.map +0 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"swarm-messenger.d.ts","sourceRoot":"","sources":["../../../../src/signal/swarm-messenger.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,sBAAsB,CAAC;AAGhD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"swarm-messenger.d.ts","sourceRoot":"","sources":["../../../../src/signal/swarm-messenger.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,sBAAsB,CAAC;AAGhD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE9D,OAAO,EAAE,KAAK,MAAM,EAAqB,MAAM,uCAAuC,CAAC;AAGvF,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,aAAa,EAAE,KAAK,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAMjG,MAAM,MAAM,qBAAqB,GAAG;IAClC,WAAW,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAChD,OAAO,EAAE,CAAC,OAAO,EAAE,YAAY,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACpD,QAAQ,EAAE,CAAC,OAAO,EAAE,aAAa,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACpD,KAAK,EAAE,SAAS,CAAC;CAClB,CAAC;AAIF;;GAEG;AACH,qBAAa,cAAe,YAAW,eAAe;IACpD,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAiB;IAEtC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAkC;IAC/D,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA4C;IACtE,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA6C;IACtE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAY;IAEnC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA4E;gBAE9F,EAAE,WAAW,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,qBAAqB;IAOtE,cAAc,CAAC,EACnB,MAAM,EACN,SAAS,EACT,OAAO,GACR,EAAE;QACD,MAAM,EAAE,QAAQ,CAAC;QACjB,SAAS,EAAE,QAAQ,CAAC;QACpB,OAAO,EAAE,GAAG,CAAC;KACd,GAAG,OAAO,CAAC,IAAI,CAAC;IA2BX,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAS7C,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC;YAerC,oBAAoB;YA0BpB,eAAe;YAWf,YAAY;YAqCZ,aAAa;CAuB5B"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Event } from '@dxos/async';
|
|
2
2
|
import { ErrorStream } from '@dxos/debug';
|
|
3
3
|
import { PublicKey } from '@dxos/keys';
|
|
4
|
+
import { type PeerInfo } from '@dxos/messaging';
|
|
4
5
|
import { type SignalMessage, type SignalMessenger } from '../signal';
|
|
5
6
|
import { type Transport, type TransportFactory, type TransportStats } from '../transport';
|
|
6
7
|
import { type WireProtocol } from '../wire-protocol';
|
|
@@ -52,8 +53,8 @@ export declare enum ConnectionState {
|
|
|
52
53
|
*/
|
|
53
54
|
export declare class Connection {
|
|
54
55
|
readonly topic: PublicKey;
|
|
55
|
-
readonly
|
|
56
|
-
readonly
|
|
56
|
+
readonly localInfo: PeerInfo;
|
|
57
|
+
readonly remoteInfo: PeerInfo;
|
|
57
58
|
readonly sessionId: PublicKey;
|
|
58
59
|
readonly initiator: boolean;
|
|
59
60
|
private readonly _signalMessaging;
|
|
@@ -75,8 +76,7 @@ export declare class Connection {
|
|
|
75
76
|
readonly transportStats: Event<TransportStats>;
|
|
76
77
|
private readonly _signalSendTask;
|
|
77
78
|
private _signallingDelay;
|
|
78
|
-
constructor(topic: PublicKey,
|
|
79
|
-
remoteId: PublicKey, sessionId: PublicKey, initiator: boolean, _signalMessaging: SignalMessenger, _protocol: WireProtocol, _transportFactory: TransportFactory, _callbacks?: ConnectionCallbacks | undefined);
|
|
79
|
+
constructor(topic: PublicKey, localInfo: PeerInfo, remoteInfo: PeerInfo, sessionId: PublicKey, initiator: boolean, _signalMessaging: SignalMessenger, _protocol: WireProtocol, _transportFactory: TransportFactory, _callbacks?: ConnectionCallbacks | undefined);
|
|
80
80
|
get sessionIdString(): string;
|
|
81
81
|
get state(): ConnectionState;
|
|
82
82
|
get transport(): Transport | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../../../src/swarm/connection.ts"],"names":[],"mappings":"AAIA,OAAO,EAAgB,KAAK,EAAoE,MAAM,aAAa,CAAC;AAEpH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../../../src/swarm/connection.ts"],"names":[],"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os/messaging';
|
|
3
4
|
import { SystemError } from '@dxos/protocols';
|
|
4
5
|
import { type Answer } from '@dxos/protocols/proto/dxos/mesh/swarm';
|
|
5
6
|
import { Connection } from './connection';
|
|
@@ -34,7 +35,7 @@ interface PeerCallbacks {
|
|
|
34
35
|
/**
|
|
35
36
|
* Returns true if the remote peer's offer should be accepted.
|
|
36
37
|
*/
|
|
37
|
-
onOffer: (
|
|
38
|
+
onOffer: (remote: PeerInfo) => Promise<boolean>;
|
|
38
39
|
/**
|
|
39
40
|
* Peer is available to connect.
|
|
40
41
|
*/
|
|
@@ -45,9 +46,9 @@ interface PeerCallbacks {
|
|
|
45
46
|
* Can open and close multiple connections to the remote peer.
|
|
46
47
|
*/
|
|
47
48
|
export declare class Peer {
|
|
48
|
-
readonly
|
|
49
|
+
readonly remoteInfo: PeerInfo;
|
|
49
50
|
readonly topic: PublicKey;
|
|
50
|
-
readonly
|
|
51
|
+
readonly localInfo: PeerInfo;
|
|
51
52
|
private readonly _signalMessaging;
|
|
52
53
|
private readonly _protocolProvider;
|
|
53
54
|
private readonly _transportFactory;
|
|
@@ -68,7 +69,7 @@ export declare class Peer {
|
|
|
68
69
|
advertizing: boolean;
|
|
69
70
|
initiating: boolean;
|
|
70
71
|
readonly connectionDisplaced: Event<Connection>;
|
|
71
|
-
constructor(
|
|
72
|
+
constructor(remoteInfo: PeerInfo, topic: PublicKey, localInfo: PeerInfo, _signalMessaging: SignalMessenger, _protocolProvider: WireProtocolProvider, _transportFactory: TransportFactory, _connectionLimiter: ConnectionLimiter, _callbacks: PeerCallbacks);
|
|
72
73
|
/**
|
|
73
74
|
* Respond to remote offer.
|
|
74
75
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"peer.d.ts","sourceRoot":"","sources":["../../../../src/swarm/peer.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,EAA8B,MAAM,aAAa,CAAC;AAGhE,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAA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U,CAAC;IAE/B;;OAEG;IACI,WAAW,UAAS;IAEpB,UAAU,UAAS;IAE1B,SAAgB,mBAAmB,oBAA2B;gBAG5C,UAAU,EAAE,QAAQ,EACpB,KAAK,EAAE,SAAS,EAChB,SAAS,EAAE,QAAQ,EAClB,gBAAgB,EAAE,eAAe,EACjC,iBAAiB,EAAE,oBAAoB,EACvC,iBAAiB,EAAE,gBAAgB,EACnC,kBAAkB,EAAE,iBAAiB,EACrC,UAAU,EAAE,aAAa;IAG5C;;OAEG;IACG,OAAO,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC;IA2DrD;;OAEG;IACG,kBAAkB;IAyExB;;;OAGG;IACH,OAAO,CAAC,iBAAiB;IAiHnB,eAAe,CAAC,GAAG,CAAC,EAAE,KAAK;IAgB3B,QAAQ,CAAC,OAAO,EAAE,aAAa;IAU/B,WAAW,CAAC,MAAM,CAAC,EAAE,KAAK;CAOjC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"swarm-mapper.d.ts","sourceRoot":"","sources":["../../../../src/swarm/swarm-mapper.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,EAAsB,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"swarm-mapper.d.ts","sourceRoot":"","sources":["../../../../src/swarm/swarm-mapper.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,EAAsB,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAKvC,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,SAAS,CAAC;AAErC;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,eAAe,GAAG,sBAAsB,GAAG,IAAI,CAAC;AAExE;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,SAAS,CAAC;IACd,KAAK,EAAE,SAAS,CAAC;IACjB,WAAW,EAAE,SAAS,EAAE,CAAC;CAC1B;AAID,qBAAa,WAAW;IAWV,OAAO,CAAC,QAAQ,CAAC,MAAM;IAVnC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAA4B;IAC3D,OAAO,CAAC,QAAQ,CAAC,wBAAwB,CAA4D;IACrG,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAyD;IAEhF,QAAQ,CAAC,UAAU,oBAA2B;IAE9C,IAAI,KAAK,IAAI,QAAQ,EAAE,CAEtB;gBAE4B,MAAM,EAAE,KAAK;IA+B1C,OAAO,CAAC,OAAO;IAmDf,OAAO;CAIR"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ErrorStream } from '@dxos/debug';
|
|
2
2
|
import { PublicKey } from '@dxos/keys';
|
|
3
|
-
import { type Messenger } from '@dxos/messaging';
|
|
4
|
-
import { type SwarmEvent } from '@dxos/protocols/proto/dxos/mesh/signal';
|
|
3
|
+
import { type SwarmEvent, type Messenger, type PeerInfo } from '@dxos/messaging';
|
|
5
4
|
import { type Answer } from '@dxos/protocols/proto/dxos/mesh/swarm';
|
|
6
5
|
import { type Connection } from './connection';
|
|
7
6
|
import { type ConnectionLimiter } from './connection-limiter';
|
|
@@ -17,7 +16,7 @@ import { type WireProtocolProvider } from '../wire-protocol';
|
|
|
17
16
|
*/
|
|
18
17
|
export declare class Swarm {
|
|
19
18
|
private readonly _topic;
|
|
20
|
-
private readonly
|
|
19
|
+
private readonly _ownPeer;
|
|
21
20
|
private _topology;
|
|
22
21
|
private readonly _protocolProvider;
|
|
23
22
|
private readonly _messenger;
|
|
@@ -33,9 +32,10 @@ export declare class Swarm {
|
|
|
33
32
|
*/
|
|
34
33
|
readonly _instanceId: string;
|
|
35
34
|
readonly errors: ErrorStream;
|
|
36
|
-
constructor(_topic: PublicKey,
|
|
35
|
+
constructor(_topic: PublicKey, _ownPeer: PeerInfo, _topology: Topology, _protocolProvider: WireProtocolProvider, _messenger: Messenger, _transportFactory: TransportFactory, _label: string | undefined, _connectionLimiter: ConnectionLimiter, _initiationDelay?: number);
|
|
37
36
|
get connections(): Connection[];
|
|
38
37
|
get ownPeerId(): PublicKey;
|
|
38
|
+
get ownPeer(): PeerInfo;
|
|
39
39
|
/**
|
|
40
40
|
* Custom label assigned to this swarm. Used in devtools to display human-readable names for swarms.
|
|
41
41
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"swarm.d.ts","sourceRoot":"","sources":["../../../../src/swarm/swarm.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,
|
|
1
|
+
{"version":3,"file":"swarm.d.ts","sourceRoot":"","sources":["../../../../src/swarm/swarm.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAE,KAAK,UAAU,EAAwB,KAAK,SAAS,EAAE,KAAK,QAAQ,EAAgB,MAAM,iBAAiB,CAAC;AAErH,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,uCAAuC,CAAC;AAGpE,OAAO,EAAE,KAAK,UAAU,EAAmB,MAAM,cAAc,CAAC;AAChE,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAE9D,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,aAAa,EAAkB,MAAM,WAAW,CAAC;AAClF,OAAO,EAAwB,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,KAAK,oBAAoB,EAAE,MA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AC,IAAI,CAAC;IAmB/C,SAAS;IAOT,QAAQ;IAId,OAAO,CAAC,gBAAgB;YAuDV,YAAY;IAO1B,OAAO,CAAC,mBAAmB;IAwC3B;;OAEG;YACW,mBAAmB;YA6BnB,gBAAgB;IAS9B,OAAO,CAAC,eAAe;CAGxB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"basic-test-suite.d.ts","sourceRoot":"","sources":["../../../../src/tests/basic-test-suite.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAK9C;;GAEG;AACH,eAAO,MAAM,cAAc,gBAAiB,WAAW,
|
|
1
|
+
{"version":3,"file":"basic-test-suite.d.ts","sourceRoot":"","sources":["../../../../src/tests/basic-test-suite.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAK9C;;GAEG;AACH,eAAO,MAAM,cAAc,gBAAiB,WAAW,6BA4LtD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"property-test-suite.d.ts","sourceRoot":"","sources":["../../../../src/tests/property-test-suite.ts"],"names":[],"mappings":"AAgBA;;GAEG;AAEH,eAAO,MAAM,iBAAiB,
|
|
1
|
+
{"version":3,"file":"property-test-suite.d.ts","sourceRoot":"","sources":["../../../../src/tests/property-test-suite.ts"],"names":[],"mappings":"AAgBA;;GAEG;AAEH,eAAO,MAAM,iBAAiB,YA0M7B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/network-manager",
|
|
3
|
-
"version": "0.6.8-
|
|
3
|
+
"version": "0.6.8-staging.63bcb81",
|
|
4
4
|
"description": "Network Manager",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -51,22 +51,23 @@
|
|
|
51
51
|
"tiny-invariant": "^1.3.1",
|
|
52
52
|
"ws": "^8.14.2",
|
|
53
53
|
"xor-distance": "^2.0.0",
|
|
54
|
-
"@dxos/async": "0.6.8-
|
|
55
|
-
"@dxos/
|
|
56
|
-
"@dxos/
|
|
57
|
-
"@dxos/
|
|
58
|
-
"@dxos/
|
|
59
|
-
"@dxos/
|
|
60
|
-
"@dxos/
|
|
61
|
-
"@dxos/
|
|
62
|
-
"@dxos/
|
|
63
|
-
"@dxos/
|
|
64
|
-
"@dxos/
|
|
65
|
-
"@dxos/
|
|
66
|
-
"@dxos/
|
|
67
|
-
"@dxos/
|
|
68
|
-
"@dxos/
|
|
69
|
-
"@dxos/
|
|
54
|
+
"@dxos/async": "0.6.8-staging.63bcb81",
|
|
55
|
+
"@dxos/codec-protobuf": "0.6.8-staging.63bcb81",
|
|
56
|
+
"@dxos/config": "0.6.8-staging.63bcb81",
|
|
57
|
+
"@dxos/crypto": "0.6.8-staging.63bcb81",
|
|
58
|
+
"@dxos/debug": "0.6.8-staging.63bcb81",
|
|
59
|
+
"@dxos/context": "0.6.8-staging.63bcb81",
|
|
60
|
+
"@dxos/credentials": "0.6.8-staging.63bcb81",
|
|
61
|
+
"@dxos/edge-client": "0.6.8-staging.63bcb81",
|
|
62
|
+
"@dxos/invariant": "0.6.8-staging.63bcb81",
|
|
63
|
+
"@dxos/keys": "0.6.8-staging.63bcb81",
|
|
64
|
+
"@dxos/log": "0.6.8-staging.63bcb81",
|
|
65
|
+
"@dxos/messaging": "0.6.8-staging.63bcb81",
|
|
66
|
+
"@dxos/node-std": "0.6.8-staging.63bcb81",
|
|
67
|
+
"@dxos/protocols": "0.6.8-staging.63bcb81",
|
|
68
|
+
"@dxos/rpc": "0.6.8-staging.63bcb81",
|
|
69
|
+
"@dxos/teleport": "0.6.8-staging.63bcb81",
|
|
70
|
+
"@dxos/util": "0.6.8-staging.63bcb81"
|
|
70
71
|
},
|
|
71
72
|
"devDependencies": {
|
|
72
73
|
"@swc-node/register": "1.9.1",
|
|
@@ -76,7 +77,7 @@
|
|
|
76
77
|
"fast-check": "^3.19.0",
|
|
77
78
|
"fetch-mock": "^11.0.0",
|
|
78
79
|
"typescript": "^5.5.4",
|
|
79
|
-
"@dxos/signal": "0.6.8-
|
|
80
|
+
"@dxos/signal": "0.6.8-staging.63bcb81"
|
|
80
81
|
},
|
|
81
82
|
"publishConfig": {
|
|
82
83
|
"access": "public"
|
package/src/connection-log.ts
CHANGED
|
@@ -54,7 +54,7 @@ export class ConnectionLog {
|
|
|
54
54
|
const connectionInfo: ConnectionInfo = {
|
|
55
55
|
state: ConnectionState.CREATED,
|
|
56
56
|
closeReason: connection.closeReason,
|
|
57
|
-
remotePeerId: connection.
|
|
57
|
+
remotePeerId: PublicKey.from(connection.remoteInfo.peerKey),
|
|
58
58
|
sessionId: connection.sessionId,
|
|
59
59
|
transport: connection.transport && Object.getPrototypeOf(connection.transport).constructor.name,
|
|
60
60
|
protocolExtensions: [], // TODO(dmaretskyi): Fix.
|
package/src/network-manager.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { Event, synchronized } from '@dxos/async';
|
|
|
6
6
|
import { invariant } from '@dxos/invariant';
|
|
7
7
|
import { PublicKey } from '@dxos/keys';
|
|
8
8
|
import { log } from '@dxos/log';
|
|
9
|
-
import { Messenger, type SignalManager } from '@dxos/messaging';
|
|
9
|
+
import { Messenger, type PeerInfo, type SignalManager } from '@dxos/messaging';
|
|
10
10
|
import { trace } from '@dxos/protocols';
|
|
11
11
|
import { ConnectionState } from '@dxos/protocols/proto/dxos/client/services';
|
|
12
12
|
import { ComplexMap } from '@dxos/util';
|
|
@@ -32,9 +32,9 @@ export type SwarmOptions = {
|
|
|
32
32
|
topic: PublicKey;
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
|
-
* This node's peer
|
|
35
|
+
* This node's peer info.
|
|
36
36
|
*/
|
|
37
|
-
|
|
37
|
+
peerInfo?: PeerInfo;
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
40
|
* Protocol to use for every connection.
|
|
@@ -56,7 +56,8 @@ export type SwarmOptions = {
|
|
|
56
56
|
export type SwarmNetworkManagerOptions = {
|
|
57
57
|
transportFactory: TransportFactory;
|
|
58
58
|
signalManager: SignalManager;
|
|
59
|
-
|
|
59
|
+
enableDevtoolsLogging?: boolean; // Log to devtools.
|
|
60
|
+
peerInfo?: PeerInfo;
|
|
60
61
|
};
|
|
61
62
|
|
|
62
63
|
/**
|
|
@@ -76,26 +77,28 @@ export class SwarmNetworkManager {
|
|
|
76
77
|
private readonly _connectionLimiter: ConnectionLimiter;
|
|
77
78
|
private readonly _connectionLog?: ConnectionLog;
|
|
78
79
|
private readonly _instanceId = PublicKey.random().toHex();
|
|
80
|
+
private _peerInfo?: PeerInfo = undefined;
|
|
79
81
|
|
|
80
82
|
private _connectionState = ConnectionState.ONLINE;
|
|
81
83
|
public readonly connectionStateChanged = new Event<ConnectionState>();
|
|
82
84
|
public readonly topicsUpdated = new Event<void>();
|
|
83
85
|
|
|
84
|
-
constructor({ transportFactory, signalManager,
|
|
86
|
+
constructor({ transportFactory, signalManager, enableDevtoolsLogging, peerInfo }: SwarmNetworkManagerOptions) {
|
|
85
87
|
this._transportFactory = transportFactory;
|
|
86
88
|
|
|
87
89
|
// Listen for signal manager events.
|
|
88
90
|
this._signalManager = signalManager;
|
|
89
|
-
this._signalManager.swarmEvent.on((
|
|
91
|
+
this._signalManager.swarmEvent.on((event) => this._swarms.get(event.topic)?.onSwarmEvent(event));
|
|
90
92
|
this._messenger = new Messenger({ signalManager: this._signalManager });
|
|
91
93
|
this._signalConnection = {
|
|
92
94
|
join: (opts) => this._signalManager.join(opts),
|
|
93
95
|
leave: (opts) => this._signalManager.leave(opts),
|
|
94
96
|
};
|
|
97
|
+
this._peerInfo = peerInfo;
|
|
95
98
|
|
|
96
99
|
this._connectionLimiter = new ConnectionLimiter();
|
|
97
100
|
// TODO(burdon): Inject listener (generic pattern).
|
|
98
|
-
if (
|
|
101
|
+
if (enableDevtoolsLogging) {
|
|
99
102
|
this._connectionLog = new ConnectionLog();
|
|
100
103
|
}
|
|
101
104
|
}
|
|
@@ -122,6 +125,10 @@ export class SwarmNetworkManager {
|
|
|
122
125
|
return this._swarms.get(topic);
|
|
123
126
|
}
|
|
124
127
|
|
|
128
|
+
setPeerInfo(peerInfo: PeerInfo) {
|
|
129
|
+
this._peerInfo = peerInfo;
|
|
130
|
+
}
|
|
131
|
+
|
|
125
132
|
async open() {
|
|
126
133
|
log.trace('dxos.mesh.network-manager.open', trace.begin({ id: this._instanceId }));
|
|
127
134
|
await this._messenger.open();
|
|
@@ -146,23 +153,30 @@ export class SwarmNetworkManager {
|
|
|
146
153
|
@synchronized
|
|
147
154
|
async joinSwarm({
|
|
148
155
|
topic,
|
|
149
|
-
|
|
156
|
+
peerInfo,
|
|
150
157
|
topology,
|
|
151
158
|
protocolProvider: protocol,
|
|
152
159
|
label,
|
|
153
160
|
}: SwarmOptions): Promise<SwarmConnection> {
|
|
154
161
|
invariant(PublicKey.isPublicKey(topic));
|
|
155
|
-
|
|
162
|
+
if (!peerInfo) {
|
|
163
|
+
peerInfo = {
|
|
164
|
+
peerKey: this._peerInfo?.peerKey ?? PublicKey.random().toHex(),
|
|
165
|
+
identityKey: this._peerInfo?.identityKey ?? PublicKey.random().toHex(),
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
invariant(PublicKey.from(peerInfo.peerKey));
|
|
169
|
+
invariant(PublicKey.from(peerInfo.identityKey!));
|
|
156
170
|
invariant(topology);
|
|
157
171
|
invariant(typeof protocol === 'function');
|
|
158
172
|
if (this._swarms.has(topic)) {
|
|
159
173
|
throw new Error(`Already connected to swarm: ${PublicKey.from(topic)}`);
|
|
160
174
|
}
|
|
161
175
|
|
|
162
|
-
log('joining', { topic: PublicKey.from(topic),
|
|
176
|
+
log('joining', { topic: PublicKey.from(topic), peerInfo, topology: topology.toString() }); // TODO(burdon): Log peerId.
|
|
163
177
|
const swarm = new Swarm(
|
|
164
178
|
topic,
|
|
165
|
-
|
|
179
|
+
peerInfo,
|
|
166
180
|
topology,
|
|
167
181
|
protocol,
|
|
168
182
|
this._messenger,
|
|
@@ -181,7 +195,7 @@ export class SwarmNetworkManager {
|
|
|
181
195
|
// Open before joining.
|
|
182
196
|
await swarm.open();
|
|
183
197
|
|
|
184
|
-
this._signalConnection.join({ topic,
|
|
198
|
+
this._signalConnection.join({ topic, peer: peerInfo }).catch((error) => log.catch(error));
|
|
185
199
|
|
|
186
200
|
this.topicsUpdated.emit();
|
|
187
201
|
this._connectionLog?.joinedSwarm(swarm);
|
|
@@ -204,7 +218,7 @@ export class SwarmNetworkManager {
|
|
|
204
218
|
|
|
205
219
|
log('leaving', { topic: PublicKey.from(topic) });
|
|
206
220
|
const swarm = this._swarms.get(topic)!;
|
|
207
|
-
await this._signalConnection.leave({ topic,
|
|
221
|
+
await this._signalConnection.leave({ topic, peer: swarm.ownPeer });
|
|
208
222
|
|
|
209
223
|
const map = this._mappers.get(topic)!;
|
|
210
224
|
map.destroy();
|
|
@@ -8,7 +8,7 @@ import { expect } from 'earljs';
|
|
|
8
8
|
import waitForExpect from 'wait-for-expect';
|
|
9
9
|
|
|
10
10
|
import { PublicKey } from '@dxos/keys';
|
|
11
|
-
import { Messenger, WebsocketSignalManager } from '@dxos/messaging';
|
|
11
|
+
import { Messenger, type PeerInfo, WebsocketSignalManager } from '@dxos/messaging';
|
|
12
12
|
import { runTestSignalServer, type SignalServerRunner } from '@dxos/signal';
|
|
13
13
|
import { afterAll, afterTest, beforeAll, describe, test } from '@dxos/test';
|
|
14
14
|
|
|
@@ -26,7 +26,13 @@ describe('Signal Integration Test', () => {
|
|
|
26
26
|
void broker.stop();
|
|
27
27
|
});
|
|
28
28
|
|
|
29
|
-
const setupPeer = async ({
|
|
29
|
+
const setupPeer = async ({
|
|
30
|
+
peer = { peerKey: PublicKey.random().toHex() },
|
|
31
|
+
topic = PublicKey.random(),
|
|
32
|
+
}: {
|
|
33
|
+
peer?: PeerInfo;
|
|
34
|
+
topic?: PublicKey;
|
|
35
|
+
}) => {
|
|
30
36
|
const signalManager = new WebsocketSignalManager([{ server: broker.url() }]);
|
|
31
37
|
await signalManager.open();
|
|
32
38
|
afterTest(() => signalManager.close());
|
|
@@ -37,7 +43,7 @@ describe('Signal Integration Test', () => {
|
|
|
37
43
|
messenger.open();
|
|
38
44
|
afterTest(() => messenger.close());
|
|
39
45
|
await messenger.listen({
|
|
40
|
-
|
|
46
|
+
peer,
|
|
41
47
|
onMessage: async (message) => await messageRouter.receiveMessage(message),
|
|
42
48
|
});
|
|
43
49
|
|
|
@@ -53,6 +59,8 @@ describe('Signal Integration Test', () => {
|
|
|
53
59
|
});
|
|
54
60
|
|
|
55
61
|
return {
|
|
62
|
+
peer,
|
|
63
|
+
topic,
|
|
56
64
|
signalManager,
|
|
57
65
|
messenger,
|
|
58
66
|
receivedSignals,
|
|
@@ -61,21 +69,19 @@ describe('Signal Integration Test', () => {
|
|
|
61
69
|
};
|
|
62
70
|
|
|
63
71
|
test('two peers connecting', async () => {
|
|
64
|
-
const peer1 = PublicKey.random();
|
|
65
|
-
const peer2 = PublicKey.random();
|
|
66
72
|
const topic = PublicKey.random();
|
|
67
73
|
|
|
68
|
-
const peerNetworking1 = await setupPeer({
|
|
69
|
-
const peerNetworking2 = await setupPeer({
|
|
74
|
+
const peerNetworking1 = await setupPeer({ topic });
|
|
75
|
+
const peerNetworking2 = await setupPeer({ topic });
|
|
70
76
|
const promise1 = peerNetworking1.signalManager.swarmEvent.waitFor(
|
|
71
|
-
({
|
|
77
|
+
({ peerAvailable }) => !!peerAvailable && peerNetworking2.peer.peerKey === peerAvailable.peer.peerKey,
|
|
72
78
|
);
|
|
73
79
|
const promise2 = peerNetworking1.signalManager.swarmEvent.waitFor(
|
|
74
|
-
({
|
|
80
|
+
({ peerAvailable }) => !!peerAvailable && peerNetworking1.peer.peerKey === peerAvailable.peer.peerKey,
|
|
75
81
|
);
|
|
76
82
|
|
|
77
|
-
await peerNetworking1.signalManager.join({ topic,
|
|
78
|
-
await peerNetworking2.signalManager.join({ topic,
|
|
83
|
+
await peerNetworking1.signalManager.join({ topic, peer: peerNetworking1.peer });
|
|
84
|
+
await peerNetworking2.signalManager.join({ topic, peer: peerNetworking2.peer });
|
|
79
85
|
|
|
80
86
|
await promise1;
|
|
81
87
|
await promise2;
|
|
@@ -83,8 +89,8 @@ describe('Signal Integration Test', () => {
|
|
|
83
89
|
expect(
|
|
84
90
|
await peerNetworking1.messageRouter.offer({
|
|
85
91
|
topic,
|
|
86
|
-
author:
|
|
87
|
-
recipient:
|
|
92
|
+
author: peerNetworking1.peer,
|
|
93
|
+
recipient: peerNetworking2.peer,
|
|
88
94
|
sessionId: PublicKey.random(),
|
|
89
95
|
data: {
|
|
90
96
|
offer: {},
|
|
@@ -95,8 +101,8 @@ describe('Signal Integration Test', () => {
|
|
|
95
101
|
expect(
|
|
96
102
|
await peerNetworking2.messageRouter.offer({
|
|
97
103
|
topic,
|
|
98
|
-
author:
|
|
99
|
-
recipient:
|
|
104
|
+
author: peerNetworking2.peer,
|
|
105
|
+
recipient: peerNetworking1.peer,
|
|
100
106
|
sessionId: PublicKey.random(),
|
|
101
107
|
data: {
|
|
102
108
|
offer: {},
|
|
@@ -107,8 +113,8 @@ describe('Signal Integration Test', () => {
|
|
|
107
113
|
{
|
|
108
114
|
const message: SignalMessage = {
|
|
109
115
|
topic,
|
|
110
|
-
author:
|
|
111
|
-
recipient:
|
|
116
|
+
author: peerNetworking1.peer,
|
|
117
|
+
recipient: peerNetworking2.peer,
|
|
112
118
|
sessionId: PublicKey.random(),
|
|
113
119
|
data: {
|
|
114
120
|
signal: { payload: { message: 'Hello world!' } },
|
|
@@ -125,8 +131,8 @@ describe('Signal Integration Test', () => {
|
|
|
125
131
|
{
|
|
126
132
|
const message: SignalMessage = {
|
|
127
133
|
topic,
|
|
128
|
-
author:
|
|
129
|
-
recipient:
|
|
134
|
+
author: peerNetworking2.peer,
|
|
135
|
+
recipient: peerNetworking1.peer,
|
|
130
136
|
sessionId: PublicKey.random(),
|
|
131
137
|
data: {
|
|
132
138
|
signal: { payload: { foo: 'bar' } },
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { type PublicKey } from '@dxos/keys';
|
|
6
|
+
import { type PeerInfo } from '@dxos/messaging';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Signal peer discovery interface.
|
|
@@ -11,10 +12,10 @@ export interface SignalConnection {
|
|
|
11
12
|
/**
|
|
12
13
|
* Join topic on signal network, to be discoverable by other peers.
|
|
13
14
|
*/
|
|
14
|
-
join(params: { topic: PublicKey;
|
|
15
|
+
join(params: { topic: PublicKey; peer: PeerInfo }): Promise<void>;
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* Leave topic on signal network, to stop being discoverable by other peers.
|
|
18
19
|
*/
|
|
19
|
-
leave(params: { topic: PublicKey;
|
|
20
|
+
leave(params: { topic: PublicKey; peer: PeerInfo }): Promise<void>;
|
|
20
21
|
}
|
|
@@ -3,19 +3,20 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { type PublicKey } from '@dxos/keys';
|
|
6
|
+
import { type PeerInfo } from '@dxos/messaging';
|
|
6
7
|
import { type Answer, type Offer, type Signal, type SignalBatch } from '@dxos/protocols/proto/dxos/mesh/swarm';
|
|
7
8
|
|
|
8
9
|
export interface OfferMessage {
|
|
9
|
-
author:
|
|
10
|
-
recipient:
|
|
10
|
+
author: PeerInfo;
|
|
11
|
+
recipient: PeerInfo;
|
|
11
12
|
topic: PublicKey;
|
|
12
13
|
sessionId: PublicKey;
|
|
13
14
|
data: { offer: Offer };
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
export interface SignalMessage {
|
|
17
|
-
author:
|
|
18
|
-
recipient:
|
|
18
|
+
author: PeerInfo;
|
|
19
|
+
recipient: PeerInfo;
|
|
19
20
|
topic: PublicKey;
|
|
20
21
|
sessionId: PublicKey;
|
|
21
22
|
data: { signal?: Signal; signalBatch?: SignalBatch };
|