@dxos/network-manager 0.1.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/LICENSE +21 -0
- package/dist/src/connection-log.d.ts +23 -0
- package/dist/src/connection-log.d.ts.map +1 -0
- package/dist/src/connection-log.js +98 -0
- package/dist/src/connection-log.js.map +1 -0
- package/dist/src/index.d.ts +9 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +28 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/network-manager.d.ts +80 -0
- package/dist/src/network-manager.d.ts.map +1 -0
- package/dist/src/network-manager.js +123 -0
- package/dist/src/network-manager.js.map +1 -0
- package/dist/src/network-manager.test.d.ts +2 -0
- package/dist/src/network-manager.test.d.ts.map +1 -0
- package/dist/src/network-manager.test.js +621 -0
- package/dist/src/network-manager.test.js.map +1 -0
- package/dist/src/presence.test.d.ts +2 -0
- package/dist/src/presence.test.d.ts.map +1 -0
- package/dist/src/presence.test.js +60 -0
- package/dist/src/presence.test.js.map +1 -0
- package/dist/src/protocol-factory.d.ts +30 -0
- package/dist/src/protocol-factory.d.ts.map +1 -0
- package/dist/src/protocol-factory.js +64 -0
- package/dist/src/protocol-factory.js.map +1 -0
- package/dist/src/signal/index.d.ts +4 -0
- package/dist/src/signal/index.d.ts.map +1 -0
- package/dist/src/signal/index.js +23 -0
- package/dist/src/signal/index.js.map +1 -0
- package/dist/src/signal/integration.test.d.ts +2 -0
- package/dist/src/signal/integration.test.d.ts.map +1 -0
- package/dist/src/signal/integration.test.js +105 -0
- package/dist/src/signal/integration.test.js.map +1 -0
- package/dist/src/signal/message-router.d.ts +39 -0
- package/dist/src/signal/message-router.d.ts.map +1 -0
- package/dist/src/signal/message-router.js +135 -0
- package/dist/src/signal/message-router.js.map +1 -0
- package/dist/src/signal/message-router.test.d.ts +2 -0
- package/dist/src/signal/message-router.test.d.ts.map +1 -0
- package/dist/src/signal/message-router.test.js +211 -0
- package/dist/src/signal/message-router.test.js.map +1 -0
- package/dist/src/signal/signal-connection.d.ts +21 -0
- package/dist/src/signal/signal-connection.d.ts.map +1 -0
- package/dist/src/signal/signal-connection.js +6 -0
- package/dist/src/signal/signal-connection.js.map +1 -0
- package/dist/src/signal/signal-messaging.d.ts +34 -0
- package/dist/src/signal/signal-messaging.d.ts.map +1 -0
- package/dist/src/signal/signal-messaging.js +6 -0
- package/dist/src/signal/signal-messaging.js.map +1 -0
- package/dist/src/swarm/connection.d.ts +69 -0
- package/dist/src/swarm/connection.d.ts.map +1 -0
- package/dist/src/swarm/connection.js +187 -0
- package/dist/src/swarm/connection.js.map +1 -0
- package/dist/src/swarm/index.d.ts +4 -0
- package/dist/src/swarm/index.d.ts.map +1 -0
- package/dist/src/swarm/index.js +23 -0
- package/dist/src/swarm/index.js.map +1 -0
- package/dist/src/swarm/swarm-mapper.d.ts +30 -0
- package/dist/src/swarm/swarm-mapper.d.ts.map +1 -0
- package/dist/src/swarm/swarm-mapper.js +90 -0
- package/dist/src/swarm/swarm-mapper.js.map +1 -0
- package/dist/src/swarm/swarm.d.ts +64 -0
- package/dist/src/swarm/swarm.d.ts.map +1 -0
- package/dist/src/swarm/swarm.js +276 -0
- package/dist/src/swarm/swarm.js.map +1 -0
- package/dist/src/swarm/swarm.test.d.ts +2 -0
- package/dist/src/swarm/swarm.test.d.ts.map +1 -0
- package/dist/src/swarm/swarm.test.js +145 -0
- package/dist/src/swarm/swarm.test.js.map +1 -0
- package/dist/src/testing/index.d.ts +2 -0
- package/dist/src/testing/index.d.ts.map +1 -0
- package/dist/src/testing/index.js +21 -0
- package/dist/src/testing/index.js.map +1 -0
- package/dist/src/testing/test-protocol.d.ts +59 -0
- package/dist/src/testing/test-protocol.d.ts.map +1 -0
- package/dist/src/testing/test-protocol.js +140 -0
- package/dist/src/testing/test-protocol.js.map +1 -0
- package/dist/src/topology/fully-connected-topology.d.ts +11 -0
- package/dist/src/topology/fully-connected-topology.d.ts.map +1 -0
- package/dist/src/topology/fully-connected-topology.js +34 -0
- package/dist/src/topology/fully-connected-topology.js.map +1 -0
- package/dist/src/topology/index.d.ts +5 -0
- package/dist/src/topology/index.d.ts.map +1 -0
- package/dist/src/topology/index.js +24 -0
- package/dist/src/topology/index.js.map +1 -0
- package/dist/src/topology/mmst-topology.d.ts +31 -0
- package/dist/src/topology/mmst-topology.d.ts.map +1 -0
- package/dist/src/topology/mmst-topology.js +73 -0
- package/dist/src/topology/mmst-topology.js.map +1 -0
- package/dist/src/topology/star-topology.d.ts +13 -0
- package/dist/src/topology/star-topology.d.ts.map +1 -0
- package/dist/src/topology/star-topology.js +60 -0
- package/dist/src/topology/star-topology.js.map +1 -0
- package/dist/src/topology/topology.d.ts +56 -0
- package/dist/src/topology/topology.d.ts.map +1 -0
- package/dist/src/topology/topology.js +6 -0
- package/dist/src/topology/topology.js.map +1 -0
- package/dist/src/transport/index.d.ts +6 -0
- package/dist/src/transport/index.d.ts.map +1 -0
- package/dist/src/transport/index.js +25 -0
- package/dist/src/transport/index.js.map +1 -0
- package/dist/src/transport/memory-transport.d.ts +32 -0
- package/dist/src/transport/memory-transport.d.ts.map +1 -0
- package/dist/src/transport/memory-transport.js +98 -0
- package/dist/src/transport/memory-transport.js.map +1 -0
- package/dist/src/transport/memory-transport.test.d.ts +2 -0
- package/dist/src/transport/memory-transport.test.d.ts.map +1 -0
- package/dist/src/transport/memory-transport.test.js +84 -0
- package/dist/src/transport/memory-transport.test.js.map +1 -0
- package/dist/src/transport/transport.d.ts +38 -0
- package/dist/src/transport/transport.d.ts.map +1 -0
- package/dist/src/transport/transport.js +6 -0
- package/dist/src/transport/transport.js.map +1 -0
- package/dist/src/transport/webrtc-transport-proxy.d.ts +48 -0
- package/dist/src/transport/webrtc-transport-proxy.d.ts.map +1 -0
- package/dist/src/transport/webrtc-transport-proxy.js +139 -0
- package/dist/src/transport/webrtc-transport-proxy.js.map +1 -0
- package/dist/src/transport/webrtc-transport-proxy.test.d.ts +2 -0
- package/dist/src/transport/webrtc-transport-proxy.test.d.ts.map +1 -0
- package/dist/src/transport/webrtc-transport-proxy.test.js +245 -0
- package/dist/src/transport/webrtc-transport-proxy.test.js.map +1 -0
- package/dist/src/transport/webrtc-transport-service.d.ts +15 -0
- package/dist/src/transport/webrtc-transport-service.d.ts.map +1 -0
- package/dist/src/transport/webrtc-transport-service.js +97 -0
- package/dist/src/transport/webrtc-transport-service.js.map +1 -0
- package/dist/src/transport/webrtc-transport.d.ts +34 -0
- package/dist/src/transport/webrtc-transport.d.ts.map +1 -0
- package/dist/src/transport/webrtc-transport.js +100 -0
- package/dist/src/transport/webrtc-transport.js.map +1 -0
- package/dist/src/transport/webrtc-transport.test.d.ts +2 -0
- package/dist/src/transport/webrtc-transport.test.d.ts.map +1 -0
- package/dist/src/transport/webrtc-transport.test.js +80 -0
- package/dist/src/transport/webrtc-transport.test.js.map +1 -0
- package/dist/src/transport/webrtc.d.ts +6 -0
- package/dist/src/transport/webrtc.d.ts.map +1 -0
- package/dist/src/transport/webrtc.js +17 -0
- package/dist/src/transport/webrtc.js.map +1 -0
- package/dist/src/transport/wrtc-simple-peer.test.d.ts +2 -0
- package/dist/src/transport/wrtc-simple-peer.test.d.ts.map +1 -0
- package/dist/src/transport/wrtc-simple-peer.test.js +24 -0
- package/dist/src/transport/wrtc-simple-peer.test.js.map +1 -0
- package/dist/src/types.d.ts +6 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +6 -0
- package/dist/src/types.js.map +1 -0
- package/package.json +58 -0
- package/src/connection-log.ts +102 -0
- package/src/globals.d.ts +7 -0
- package/src/index.ts +12 -0
- package/src/network-manager.test.ts +764 -0
- package/src/network-manager.ts +204 -0
- package/src/presence.test.ts +78 -0
- package/src/protocol-factory.ts +83 -0
- package/src/signal/index.ts +7 -0
- package/src/signal/integration.test.ts +129 -0
- package/src/signal/message-router.test.ts +274 -0
- package/src/signal/message-router.ts +200 -0
- package/src/signal/signal-connection.ts +20 -0
- package/src/signal/signal-messaging.ts +38 -0
- package/src/swarm/connection.ts +206 -0
- package/src/swarm/index.ts +7 -0
- package/src/swarm/swarm-mapper.ts +120 -0
- package/src/swarm/swarm.test.ts +192 -0
- package/src/swarm/swarm.ts +328 -0
- package/src/testing/index.ts +5 -0
- package/src/testing/test-protocol.ts +160 -0
- package/src/topology/fully-connected-topology.ts +38 -0
- package/src/topology/index.ts +8 -0
- package/src/topology/mmst-topology.ts +105 -0
- package/src/topology/star-topology.ts +67 -0
- package/src/topology/topology.ts +69 -0
- package/src/transport/index.ts +9 -0
- package/src/transport/memory-transport.test.ts +110 -0
- package/src/transport/memory-transport.ts +128 -0
- package/src/transport/transport.ts +47 -0
- package/src/transport/webrtc-transport-proxy.test.ts +290 -0
- package/src/transport/webrtc-transport-proxy.ts +167 -0
- package/src/transport/webrtc-transport-service.ts +115 -0
- package/src/transport/webrtc-transport.test.ts +112 -0
- package/src/transport/webrtc-transport.ts +122 -0
- package/src/transport/webrtc.ts +15 -0
- package/src/transport/wrtc-simple-peer.test.ts +24 -0
- package/src/types.ts +10 -0
- package/src/typings.d.ts +7 -0
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
//
|
|
3
|
+
// Copyright 2022 DXOS.org
|
|
4
|
+
//
|
|
5
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
// @dxos/mocha platform=nodejs
|
|
10
|
+
const earljs_1 = require("earljs");
|
|
11
|
+
const mocha_1 = require("mocha");
|
|
12
|
+
const wait_for_expect_1 = __importDefault(require("wait-for-expect"));
|
|
13
|
+
const keys_1 = require("@dxos/keys");
|
|
14
|
+
const messaging_1 = require("@dxos/messaging");
|
|
15
|
+
const signal_1 = require("@dxos/signal");
|
|
16
|
+
const testutils_1 = require("@dxos/testutils");
|
|
17
|
+
const message_router_1 = require("./message-router");
|
|
18
|
+
(0, mocha_1.describe)('MessageRouter', function () {
|
|
19
|
+
let topic;
|
|
20
|
+
let broker1;
|
|
21
|
+
before(async function () {
|
|
22
|
+
broker1 = await (0, signal_1.createTestBroker)();
|
|
23
|
+
});
|
|
24
|
+
beforeEach(function () {
|
|
25
|
+
topic = keys_1.PublicKey.random();
|
|
26
|
+
});
|
|
27
|
+
after(function () {
|
|
28
|
+
broker1.stop();
|
|
29
|
+
});
|
|
30
|
+
const createSignalClientAndMessageRouter = async ({ signalApiUrl, onSignal = (async () => { }), onOffer = async () => ({ accept: true }), topic }) => {
|
|
31
|
+
const peerId = keys_1.PublicKey.random();
|
|
32
|
+
const signalManager = new messaging_1.WebsocketSignalManager([signalApiUrl]);
|
|
33
|
+
(0, testutils_1.afterTest)(() => signalManager.destroy());
|
|
34
|
+
const messenger = new messaging_1.Messenger({ signalManager });
|
|
35
|
+
await messenger.listen({
|
|
36
|
+
peerId,
|
|
37
|
+
payloadType: 'dxos.mesh.swarm.SwarmMessage',
|
|
38
|
+
onMessage: async (message) => await router.receiveMessage(message)
|
|
39
|
+
});
|
|
40
|
+
const router = new message_router_1.MessageRouter({
|
|
41
|
+
// todo(mykola): added catch to avoid not finished request.
|
|
42
|
+
sendMessage: async (message) => await messenger.sendMessage(message),
|
|
43
|
+
onSignal,
|
|
44
|
+
onOffer,
|
|
45
|
+
topic
|
|
46
|
+
});
|
|
47
|
+
return {
|
|
48
|
+
peerId,
|
|
49
|
+
signalManager,
|
|
50
|
+
router
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
(0, mocha_1.it)('signaling between 2 clients', async () => {
|
|
54
|
+
const received = [];
|
|
55
|
+
const signalMock1 = async (msg) => {
|
|
56
|
+
received.push(msg);
|
|
57
|
+
};
|
|
58
|
+
const { signalManager: signalManager1, peerId: peer1 } = await createSignalClientAndMessageRouter({
|
|
59
|
+
signalApiUrl: broker1.url(),
|
|
60
|
+
onSignal: signalMock1,
|
|
61
|
+
topic
|
|
62
|
+
});
|
|
63
|
+
const { signalManager: signalManager2, router: router2, peerId: peer2 } = await createSignalClientAndMessageRouter({
|
|
64
|
+
signalApiUrl: broker1.url(),
|
|
65
|
+
topic
|
|
66
|
+
});
|
|
67
|
+
await signalManager1.join({ topic, peerId: peer1 });
|
|
68
|
+
await signalManager2.join({ topic, peerId: peer2 });
|
|
69
|
+
const msg = {
|
|
70
|
+
author: peer2,
|
|
71
|
+
recipient: peer1,
|
|
72
|
+
sessionId: keys_1.PublicKey.random(),
|
|
73
|
+
topic,
|
|
74
|
+
data: { signal: { json: JSON.stringify({ asd: 'asd' }) } }
|
|
75
|
+
};
|
|
76
|
+
await router2.signal(msg);
|
|
77
|
+
await (0, wait_for_expect_1.default)(() => {
|
|
78
|
+
(0, earljs_1.expect)(received[0]).toBeAnObjectWith(msg);
|
|
79
|
+
}, 4000);
|
|
80
|
+
}).timeout(5000);
|
|
81
|
+
(0, mocha_1.it)('offer/answer', async () => {
|
|
82
|
+
const { signalManager: signalManager1, router: router1, peerId: peer1 } = await createSignalClientAndMessageRouter({
|
|
83
|
+
signalApiUrl: broker1.url(),
|
|
84
|
+
onSignal: (async () => { }),
|
|
85
|
+
onOffer: async () => ({ accept: true }),
|
|
86
|
+
topic
|
|
87
|
+
});
|
|
88
|
+
const { signalManager: signalManager2, peerId: peer2 } = await createSignalClientAndMessageRouter({
|
|
89
|
+
signalApiUrl: broker1.url(),
|
|
90
|
+
onSignal: (async () => { }),
|
|
91
|
+
onOffer: async () => ({ accept: true }),
|
|
92
|
+
topic
|
|
93
|
+
});
|
|
94
|
+
await signalManager1.join({ topic, peerId: peer1 });
|
|
95
|
+
await signalManager2.join({ topic, peerId: peer2 });
|
|
96
|
+
const answer = await router1.offer({
|
|
97
|
+
author: peer1,
|
|
98
|
+
recipient: peer2,
|
|
99
|
+
sessionId: keys_1.PublicKey.random(),
|
|
100
|
+
topic,
|
|
101
|
+
data: { offer: {} }
|
|
102
|
+
});
|
|
103
|
+
(0, earljs_1.expect)(answer.accept).toEqual(true);
|
|
104
|
+
}).timeout(5000);
|
|
105
|
+
(0, mocha_1.it)('signaling between 3 clients', async () => {
|
|
106
|
+
const received1 = [];
|
|
107
|
+
const signalMock1 = async (msg) => {
|
|
108
|
+
received1.push(msg);
|
|
109
|
+
};
|
|
110
|
+
const { signalManager: signalManager1, router: router1, peerId: peer1 } = await createSignalClientAndMessageRouter({
|
|
111
|
+
signalApiUrl: broker1.url(),
|
|
112
|
+
onSignal: signalMock1,
|
|
113
|
+
onOffer: async () => ({ accept: true }),
|
|
114
|
+
topic
|
|
115
|
+
});
|
|
116
|
+
const received2 = [];
|
|
117
|
+
const signalMock2 = async (msg) => {
|
|
118
|
+
received2.push(msg);
|
|
119
|
+
};
|
|
120
|
+
const { signalManager: signalManager2, router: router2, peerId: peer2 } = await createSignalClientAndMessageRouter({
|
|
121
|
+
signalApiUrl: broker1.url(),
|
|
122
|
+
onSignal: signalMock2,
|
|
123
|
+
onOffer: async () => ({ accept: true }),
|
|
124
|
+
topic
|
|
125
|
+
});
|
|
126
|
+
const received3 = [];
|
|
127
|
+
const signalMock3 = async (msg) => {
|
|
128
|
+
received3.push(msg);
|
|
129
|
+
};
|
|
130
|
+
const { signalManager: signalManager3, router: router3, peerId: peer3 } = await createSignalClientAndMessageRouter({
|
|
131
|
+
signalApiUrl: broker1.url(),
|
|
132
|
+
onSignal: signalMock3,
|
|
133
|
+
onOffer: async () => ({ accept: true }),
|
|
134
|
+
topic
|
|
135
|
+
});
|
|
136
|
+
await signalManager1.join({ topic, peerId: peer1 });
|
|
137
|
+
await signalManager2.join({ topic, peerId: peer2 });
|
|
138
|
+
await signalManager3.join({ topic, peerId: peer3 });
|
|
139
|
+
// sending signal from peer1 to peer3.
|
|
140
|
+
const msg1to3 = {
|
|
141
|
+
author: peer1,
|
|
142
|
+
recipient: peer3,
|
|
143
|
+
sessionId: keys_1.PublicKey.random(),
|
|
144
|
+
topic,
|
|
145
|
+
data: { signal: { json: '1to3' } }
|
|
146
|
+
};
|
|
147
|
+
await router1.signal(msg1to3);
|
|
148
|
+
await (0, wait_for_expect_1.default)(() => {
|
|
149
|
+
(0, earljs_1.expect)(received3[0]).toBeAnObjectWith(msg1to3);
|
|
150
|
+
}, 4000);
|
|
151
|
+
// sending signal from peer2 to peer3.
|
|
152
|
+
const msg2to3 = {
|
|
153
|
+
author: peer2,
|
|
154
|
+
recipient: peer3,
|
|
155
|
+
sessionId: keys_1.PublicKey.random(),
|
|
156
|
+
topic,
|
|
157
|
+
data: { signal: { json: '2to3' } }
|
|
158
|
+
};
|
|
159
|
+
await router2.signal(msg2to3);
|
|
160
|
+
await (0, wait_for_expect_1.default)(() => {
|
|
161
|
+
(0, earljs_1.expect)(received3[1]).toBeAnObjectWith(msg2to3);
|
|
162
|
+
}, 4000);
|
|
163
|
+
// sending signal from peer3 to peer1.
|
|
164
|
+
const msg3to1 = {
|
|
165
|
+
author: peer3,
|
|
166
|
+
recipient: peer1,
|
|
167
|
+
sessionId: keys_1.PublicKey.random(),
|
|
168
|
+
topic,
|
|
169
|
+
data: { signal: { json: '3to1' } }
|
|
170
|
+
};
|
|
171
|
+
await router3.signal(msg3to1);
|
|
172
|
+
await (0, wait_for_expect_1.default)(() => {
|
|
173
|
+
(0, earljs_1.expect)(received1[0]).toBeAnObjectWith(msg3to1);
|
|
174
|
+
}, 4000);
|
|
175
|
+
}).timeout(5000);
|
|
176
|
+
(0, mocha_1.it)('two offers', async () => {
|
|
177
|
+
const { signalManager: signalManager1, router: router1, peerId: peer1 } = await createSignalClientAndMessageRouter({
|
|
178
|
+
signalApiUrl: broker1.url(),
|
|
179
|
+
onSignal: (async () => { }),
|
|
180
|
+
onOffer: async () => ({ accept: true }),
|
|
181
|
+
topic
|
|
182
|
+
});
|
|
183
|
+
const { signalManager: signalManager2, router: router2, peerId: peer2 } = await createSignalClientAndMessageRouter({
|
|
184
|
+
signalApiUrl: broker1.url(),
|
|
185
|
+
onSignal: (async () => { }),
|
|
186
|
+
onOffer: async () => ({ accept: true }),
|
|
187
|
+
topic
|
|
188
|
+
});
|
|
189
|
+
await signalManager1.join({ topic, peerId: peer1 });
|
|
190
|
+
await signalManager2.join({ topic, peerId: peer2 });
|
|
191
|
+
// sending offer from peer1 to peer2.
|
|
192
|
+
const answer1 = await router1.offer({
|
|
193
|
+
author: peer1,
|
|
194
|
+
recipient: peer2,
|
|
195
|
+
sessionId: keys_1.PublicKey.random(),
|
|
196
|
+
topic,
|
|
197
|
+
data: { offer: {} }
|
|
198
|
+
});
|
|
199
|
+
(0, earljs_1.expect)(answer1.accept).toEqual(true);
|
|
200
|
+
// sending offer from peer2 to peer1.
|
|
201
|
+
const answer2 = await router2.offer({
|
|
202
|
+
author: peer2,
|
|
203
|
+
recipient: peer1,
|
|
204
|
+
sessionId: keys_1.PublicKey.random(),
|
|
205
|
+
topic,
|
|
206
|
+
data: { offer: {} }
|
|
207
|
+
});
|
|
208
|
+
(0, earljs_1.expect)(answer2.accept).toEqual(true);
|
|
209
|
+
}).timeout(5000);
|
|
210
|
+
});
|
|
211
|
+
//# sourceMappingURL=message-router.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message-router.test.js","sourceRoot":"","sources":["../../../src/signal/message-router.test.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;;;AAEF,8BAA8B;AAE9B,mCAAgC;AAChC,iCAAqC;AACrC,sEAA4C;AAG5C,qCAAuC;AACvC,+CAAoE;AAEpE,yCAAgD;AAChD,+CAA4C;AAE5C,qDAAiD;AAGjD,IAAA,gBAAQ,EAAC,eAAe,EAAE;IACxB,IAAI,KAAgB,CAAC;IAErB,IAAI,OAAqD,CAAC;IAE1D,MAAM,CAAC,KAAK;QACV,OAAO,GAAG,MAAM,IAAA,yBAAgB,GAAE,CAAC;IACrC,CAAC,CAAC,CAAC;IAEH,UAAU,CAAC;QACT,KAAK,GAAG,gBAAS,CAAC,MAAM,EAAE,CAAC;IAC7B,CAAC,CAAC,CAAC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,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;YACvC,KAAK;SACN,CAAC,CAAC;QAEH,MAAM,cAAc,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;QACpD,MAAM,cAAc,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;QAEpD,qCAAqC;QACrC,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC;YAClC,MAAM,EAAE,KAAK;YACb,SAAS,EAAE,KAAK;YAChB,SAAS,EAAE,gBAAS,CAAC,MAAM,EAAE;YAC7B,KAAK;YACL,IAAI,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE;SACpB,CAAC,CAAC;QACH,IAAA,eAAM,EAAC,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAErC,qCAAqC;QACrC,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC;YAClC,MAAM,EAAE,KAAK;YACb,SAAS,EAAE,KAAK;YAChB,SAAS,EAAE,gBAAS,CAAC,MAAM,EAAE;YAC7B,KAAK;YACL,IAAI,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE;SACpB,CAAC,CAAC;QACH,IAAA,eAAM,EAAC,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACvC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAK,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { PublicKey } from '@dxos/keys';
|
|
2
|
+
/**
|
|
3
|
+
* Signal peer discovery interface.
|
|
4
|
+
*/
|
|
5
|
+
export interface SignalConnection {
|
|
6
|
+
/**
|
|
7
|
+
* Join topic on signal network, to be discoverable by other peers.
|
|
8
|
+
*/
|
|
9
|
+
join(params: {
|
|
10
|
+
topic: PublicKey;
|
|
11
|
+
peerId: PublicKey;
|
|
12
|
+
}): Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Leave topic on signal network, to stop being discoverable by other peers.
|
|
15
|
+
*/
|
|
16
|
+
leave(params: {
|
|
17
|
+
topic: PublicKey;
|
|
18
|
+
peerId: PublicKey;
|
|
19
|
+
}): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=signal-connection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signal-connection.d.ts","sourceRoot":"","sources":["../../../src/signal/signal-connection.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,IAAI,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,SAAS,CAAC;QAAC,MAAM,EAAE,SAAS,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAErE;;OAEG;IACH,KAAK,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,SAAS,CAAC;QAAC,MAAM,EAAE,SAAS,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACvE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signal-connection.js","sourceRoot":"","sources":["../../../src/signal/signal-connection.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { PublicKey } from '@dxos/keys';
|
|
2
|
+
import { Answer, Offer, Signal } from '@dxos/protocols/proto/dxos/mesh/swarm';
|
|
3
|
+
export interface OfferMessage {
|
|
4
|
+
author: PublicKey;
|
|
5
|
+
recipient: PublicKey;
|
|
6
|
+
topic: PublicKey;
|
|
7
|
+
sessionId: PublicKey;
|
|
8
|
+
data: {
|
|
9
|
+
offer: Offer;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export interface SignalMessage {
|
|
13
|
+
author: PublicKey;
|
|
14
|
+
recipient: PublicKey;
|
|
15
|
+
topic: PublicKey;
|
|
16
|
+
sessionId: PublicKey;
|
|
17
|
+
data: {
|
|
18
|
+
signal: Signal;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Signal peer messaging interface.
|
|
23
|
+
*/
|
|
24
|
+
export interface SignalMessaging {
|
|
25
|
+
/**
|
|
26
|
+
* Offer/answer RPC.
|
|
27
|
+
*/
|
|
28
|
+
offer(msg: OfferMessage): Promise<Answer>;
|
|
29
|
+
/**
|
|
30
|
+
* Reliably send a signal to a peer.
|
|
31
|
+
*/
|
|
32
|
+
signal(msg: SignalMessage): Promise<void>;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=signal-messaging.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signal-messaging.d.ts","sourceRoot":"","sources":["../../../src/signal/signal-messaging.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,uCAAuC,CAAC;AAE9E,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,SAAS,CAAC;IAClB,SAAS,EAAE,SAAS,CAAC;IACrB,KAAK,EAAE,SAAS,CAAC;IACjB,SAAS,EAAE,SAAS,CAAC;IACrB,IAAI,EAAE;QAAE,KAAK,EAAE,KAAK,CAAA;KAAE,CAAC;CACxB;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,SAAS,CAAC;IAClB,SAAS,EAAE,SAAS,CAAC;IACrB,KAAK,EAAE,SAAS,CAAC;IACjB,SAAS,EAAE,SAAS,CAAC;IACrB,IAAI,EAAE;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;CAC1B;AAED;;GAEG;AAEH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,KAAK,CAAC,GAAG,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAE1C;;OAEG;IACH,MAAM,CAAC,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signal-messaging.js","sourceRoot":"","sources":["../../../src/signal/signal-messaging.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { Event } from '@dxos/async';
|
|
2
|
+
import { ErrorStream } from '@dxos/debug';
|
|
3
|
+
import { PublicKey } from '@dxos/keys';
|
|
4
|
+
import { Protocol } from '@dxos/mesh-protocol';
|
|
5
|
+
import { SignalMessage, SignalMessaging } from '../signal';
|
|
6
|
+
import { Transport, TransportFactory } from '../transport';
|
|
7
|
+
/**
|
|
8
|
+
* State machine for each connection.
|
|
9
|
+
*/
|
|
10
|
+
export declare enum ConnectionState {
|
|
11
|
+
/**
|
|
12
|
+
* Initial state. Connection is registered but no attempt to connect to the remote peer has been performed.
|
|
13
|
+
* Might mean that we are waiting for the answer signal from the remote peer.
|
|
14
|
+
*/
|
|
15
|
+
INITIAL = "INITIAL",
|
|
16
|
+
/**
|
|
17
|
+
* Originating a connection.
|
|
18
|
+
*/
|
|
19
|
+
INITIATING_CONNECTION = "INITIATING_CONNECTION",
|
|
20
|
+
/**
|
|
21
|
+
* Waiting for a connection to be originated from the remote peer.
|
|
22
|
+
*/
|
|
23
|
+
WAITING_FOR_CONNECTION = "WAITING_FOR_CONNECTION",
|
|
24
|
+
/**
|
|
25
|
+
* Peer rejected offer.
|
|
26
|
+
*/
|
|
27
|
+
ACCEPTED = "ACCEPTED",
|
|
28
|
+
/**
|
|
29
|
+
* Peer rejected offer.
|
|
30
|
+
*/
|
|
31
|
+
REJECTED = "REJECTED",
|
|
32
|
+
/**
|
|
33
|
+
* Connection is established.
|
|
34
|
+
*/
|
|
35
|
+
CONNECTED = "CONNECTED",
|
|
36
|
+
/**
|
|
37
|
+
* Connection closed.
|
|
38
|
+
*/
|
|
39
|
+
CLOSED = "CLOSED"
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Represents a connection to a remote peer.
|
|
43
|
+
*/
|
|
44
|
+
export declare class Connection {
|
|
45
|
+
readonly topic: PublicKey;
|
|
46
|
+
readonly ownId: PublicKey;
|
|
47
|
+
readonly remoteId: PublicKey;
|
|
48
|
+
readonly sessionId: PublicKey;
|
|
49
|
+
readonly initiator: boolean;
|
|
50
|
+
private readonly _signalMessaging;
|
|
51
|
+
private readonly _protocol;
|
|
52
|
+
private readonly _transportFactory;
|
|
53
|
+
private _state;
|
|
54
|
+
private _transport;
|
|
55
|
+
private _bufferedSignals;
|
|
56
|
+
readonly stateChanged: Event<ConnectionState>;
|
|
57
|
+
readonly errors: ErrorStream;
|
|
58
|
+
constructor(topic: PublicKey, ownId: PublicKey, // TODO(burdon): peerID?
|
|
59
|
+
remoteId: PublicKey, sessionId: PublicKey, initiator: boolean, _signalMessaging: SignalMessaging, _protocol: Protocol, _transportFactory: TransportFactory);
|
|
60
|
+
get state(): ConnectionState;
|
|
61
|
+
get transport(): Transport | undefined;
|
|
62
|
+
get protocol(): Protocol;
|
|
63
|
+
initiate(): void;
|
|
64
|
+
open(): void;
|
|
65
|
+
close(): Promise<void>;
|
|
66
|
+
signal(msg: SignalMessage): Promise<void>;
|
|
67
|
+
private _changeState;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=connection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../../src/swarm/connection.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,EAAgB,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,SA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CE,KAAK;IAkBL,MAAM,CAAC,GAAG,EAAE,aAAa;IAqB/B,OAAO,CAAC,YAAY;CAIrB"}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
//
|
|
3
|
+
// Copyright 2021 DXOS.org
|
|
4
|
+
//
|
|
5
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
6
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
7
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
8
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
9
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.Connection = exports.ConnectionState = void 0;
|
|
16
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
17
|
+
const async_1 = require("@dxos/async");
|
|
18
|
+
const debug_1 = require("@dxos/debug");
|
|
19
|
+
const log_1 = require("@dxos/log");
|
|
20
|
+
/**
|
|
21
|
+
* State machine for each connection.
|
|
22
|
+
*/
|
|
23
|
+
var ConnectionState;
|
|
24
|
+
(function (ConnectionState) {
|
|
25
|
+
/**
|
|
26
|
+
* Initial state. Connection is registered but no attempt to connect to the remote peer has been performed.
|
|
27
|
+
* Might mean that we are waiting for the answer signal from the remote peer.
|
|
28
|
+
*/
|
|
29
|
+
ConnectionState["INITIAL"] = "INITIAL";
|
|
30
|
+
/**
|
|
31
|
+
* Originating a connection.
|
|
32
|
+
*/
|
|
33
|
+
ConnectionState["INITIATING_CONNECTION"] = "INITIATING_CONNECTION";
|
|
34
|
+
/**
|
|
35
|
+
* Waiting for a connection to be originated from the remote peer.
|
|
36
|
+
*/
|
|
37
|
+
ConnectionState["WAITING_FOR_CONNECTION"] = "WAITING_FOR_CONNECTION";
|
|
38
|
+
/**
|
|
39
|
+
* Peer rejected offer.
|
|
40
|
+
*/
|
|
41
|
+
ConnectionState["ACCEPTED"] = "ACCEPTED";
|
|
42
|
+
/**
|
|
43
|
+
* Peer rejected offer.
|
|
44
|
+
*/
|
|
45
|
+
ConnectionState["REJECTED"] = "REJECTED";
|
|
46
|
+
/**
|
|
47
|
+
* Connection is established.
|
|
48
|
+
*/
|
|
49
|
+
ConnectionState["CONNECTED"] = "CONNECTED";
|
|
50
|
+
/**
|
|
51
|
+
* Connection closed.
|
|
52
|
+
*/
|
|
53
|
+
ConnectionState["CLOSED"] = "CLOSED";
|
|
54
|
+
})(ConnectionState = exports.ConnectionState || (exports.ConnectionState = {}));
|
|
55
|
+
/**
|
|
56
|
+
* Represents a connection to a remote peer.
|
|
57
|
+
*/
|
|
58
|
+
class Connection {
|
|
59
|
+
constructor(topic, ownId, // TODO(burdon): peerID?
|
|
60
|
+
remoteId, sessionId, initiator, _signalMessaging, _protocol, _transportFactory) {
|
|
61
|
+
this.topic = topic;
|
|
62
|
+
this.ownId = ownId;
|
|
63
|
+
this.remoteId = remoteId;
|
|
64
|
+
this.sessionId = sessionId;
|
|
65
|
+
this.initiator = initiator;
|
|
66
|
+
this._signalMessaging = _signalMessaging;
|
|
67
|
+
this._protocol = _protocol;
|
|
68
|
+
this._transportFactory = _transportFactory;
|
|
69
|
+
this._state = ConnectionState.INITIAL;
|
|
70
|
+
this._bufferedSignals = [];
|
|
71
|
+
this.stateChanged = new async_1.Event();
|
|
72
|
+
this.errors = new debug_1.ErrorStream();
|
|
73
|
+
}
|
|
74
|
+
get state() {
|
|
75
|
+
return this._state;
|
|
76
|
+
}
|
|
77
|
+
get transport() {
|
|
78
|
+
return this._transport;
|
|
79
|
+
}
|
|
80
|
+
get protocol() {
|
|
81
|
+
return this._protocol;
|
|
82
|
+
}
|
|
83
|
+
// TODO(burdon): Make async.
|
|
84
|
+
initiate() {
|
|
85
|
+
this._signalMessaging
|
|
86
|
+
.offer({
|
|
87
|
+
author: this.ownId,
|
|
88
|
+
recipient: this.remoteId,
|
|
89
|
+
sessionId: this.sessionId,
|
|
90
|
+
topic: this.topic,
|
|
91
|
+
data: { offer: {} }
|
|
92
|
+
})
|
|
93
|
+
.then((answer) => {
|
|
94
|
+
(0, log_1.log)('received', { answer, topic: this.topic, ownId: this.ownId, remoteId: this.remoteId }, { file: "packages/core/mesh/network-manager/src/swarm/connection.ts", line: 103 });
|
|
95
|
+
if (this.state !== ConnectionState.INITIAL) {
|
|
96
|
+
(0, log_1.log)('ignoring response', {}, { file: "packages/core/mesh/network-manager/src/swarm/connection.ts", line: 105 });
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (answer.accept) {
|
|
100
|
+
try {
|
|
101
|
+
this.open();
|
|
102
|
+
}
|
|
103
|
+
catch (err) {
|
|
104
|
+
this.errors.raise(err);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
// If the peer rejected our connection remove it from the set of candidates.
|
|
109
|
+
this._changeState(ConnectionState.REJECTED);
|
|
110
|
+
}
|
|
111
|
+
this._changeState(ConnectionState.ACCEPTED);
|
|
112
|
+
})
|
|
113
|
+
.catch((err) => {
|
|
114
|
+
this.errors.raise(err);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
// TODO(burdon): Make async?
|
|
118
|
+
open() {
|
|
119
|
+
(0, node_assert_1.default)(this._state === ConnectionState.INITIAL, 'Invalid state.');
|
|
120
|
+
this._changeState(this.initiator ? ConnectionState.INITIATING_CONNECTION : ConnectionState.WAITING_FOR_CONNECTION);
|
|
121
|
+
(0, node_assert_1.default)(!this._transport);
|
|
122
|
+
this._transport = this._transportFactory.create({
|
|
123
|
+
topic: this.topic,
|
|
124
|
+
ownId: this.ownId,
|
|
125
|
+
remoteId: this.remoteId,
|
|
126
|
+
sessionId: this.sessionId,
|
|
127
|
+
initiator: this.initiator,
|
|
128
|
+
stream: this._protocol.stream,
|
|
129
|
+
sendSignal: this._signalMessaging.signal.bind(this._signalMessaging)
|
|
130
|
+
});
|
|
131
|
+
this._transport.connected.once(() => {
|
|
132
|
+
this._changeState(ConnectionState.CONNECTED);
|
|
133
|
+
});
|
|
134
|
+
this._transport.closed.once(() => {
|
|
135
|
+
this._transport = undefined;
|
|
136
|
+
this.close().catch((err) => this.errors.raise(err));
|
|
137
|
+
});
|
|
138
|
+
this._transport.errors.pipeTo(this.errors);
|
|
139
|
+
// Replay signals that were received before transport was created.
|
|
140
|
+
for (const signal of this._bufferedSignals) {
|
|
141
|
+
void this._transport.signal(signal); // TODO(burdon): Remove async?
|
|
142
|
+
}
|
|
143
|
+
this._bufferedSignals = [];
|
|
144
|
+
}
|
|
145
|
+
async close() {
|
|
146
|
+
var _a;
|
|
147
|
+
if (this._state === ConnectionState.CLOSED) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
// TODO(dmaretskyi): CLOSING state.
|
|
151
|
+
(0, log_1.log)('closing', { peerId: this.ownId }, { file: "packages/core/mesh/network-manager/src/swarm/connection.ts", line: 169 });
|
|
152
|
+
// This will try to gracefull close the stream flushing any unsent data packets.
|
|
153
|
+
await this._protocol.close();
|
|
154
|
+
// After the transport is closed streams are disconnected.
|
|
155
|
+
await ((_a = this._transport) === null || _a === void 0 ? void 0 : _a.close());
|
|
156
|
+
this._changeState(ConnectionState.CLOSED);
|
|
157
|
+
(0, log_1.log)('closed', { peerId: this.ownId }, { file: "packages/core/mesh/network-manager/src/swarm/connection.ts", line: 178 });
|
|
158
|
+
}
|
|
159
|
+
async signal(msg) {
|
|
160
|
+
var _a, _b;
|
|
161
|
+
(0, node_assert_1.default)(msg.sessionId);
|
|
162
|
+
if (!msg.sessionId.equals(this.sessionId)) {
|
|
163
|
+
(0, log_1.log)('dropping signal for incorrect session id', {}, { file: "packages/core/mesh/network-manager/src/swarm/connection.ts", line: 184 });
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
(0, node_assert_1.default)(msg.data.signal);
|
|
167
|
+
(0, node_assert_1.default)((_a = msg.author) === null || _a === void 0 ? void 0 : _a.equals(this.remoteId));
|
|
168
|
+
(0, node_assert_1.default)((_b = msg.recipient) === null || _b === void 0 ? void 0 : _b.equals(this.ownId));
|
|
169
|
+
if (this._state === ConnectionState.INITIAL) {
|
|
170
|
+
(0, log_1.log)('buffered signal', { peerId: this.ownId, remoteId: this.remoteId, msg: msg.data }, { file: "packages/core/mesh/network-manager/src/swarm/connection.ts", line: 192 });
|
|
171
|
+
this._bufferedSignals.push(msg.data.signal);
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
(0, node_assert_1.default)(this._transport, 'Connection not ready to accept signals.');
|
|
175
|
+
(0, log_1.log)('received signal', { peerId: this.ownId, remoteId: this.remoteId, msg: msg.data }, { file: "packages/core/mesh/network-manager/src/swarm/connection.ts", line: 198 });
|
|
176
|
+
await this._transport.signal(msg.data.signal);
|
|
177
|
+
}
|
|
178
|
+
_changeState(state) {
|
|
179
|
+
this._state = state;
|
|
180
|
+
this.stateChanged.emit(state);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
__decorate([
|
|
184
|
+
async_1.synchronized
|
|
185
|
+
], Connection.prototype, "close", null);
|
|
186
|
+
exports.Connection = Connection;
|
|
187
|
+
//# sourceMappingURL=connection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../../../src/swarm/connection.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;;;;;;;;;;AAEF,8DAAiC;AAEjC,uCAAkD;AAClD,uCAA0C;AAE1C,mCAAgC;AAOhC;;GAEG;AACH,IAAY,eAoCX;AApCD,WAAY,eAAe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,IAAI,EAAE,oFAAC,CAAC;YACvF,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAC5C,OAAO;SACR;QAED,IAAA,qBAAM,EAAC,IAAI,CAAC,UAAU,EAAE,yCAAyC,CAAC,CAAC;QACnE,IAAA,SAAG,EAAC,iBAAiB,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,GAAG,EAAE,GAAG,CAAC,IAAI,EAAE,oFAAC,CAAC;QACvF,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAChD,CAAC;IAEO,YAAY,CAAC,KAAsB;QACzC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC;CACF;AA3CO;IADL,oBAAY;uCAiBZ;AAtHH,gCAiJC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/swarm/index.ts"],"names":[],"mappings":"AAIA,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
//
|
|
3
|
+
// Copyright 2020 DXOS.org
|
|
4
|
+
//
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
17
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
__exportStar(require("./connection"), exports);
|
|
21
|
+
__exportStar(require("./swarm"), exports);
|
|
22
|
+
__exportStar(require("./swarm-mapper"), exports);
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/swarm/index.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;;;;;;;;;;;;;;AAEF,+CAA6B;AAC7B,0CAAwB;AACxB,iDAA+B"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Event } from '@dxos/async';
|
|
2
|
+
import { PublicKey } from '@dxos/keys';
|
|
3
|
+
import { PresencePlugin } from '@dxos/protocol-plugin-presence';
|
|
4
|
+
import { ConnectionState } from './connection';
|
|
5
|
+
import { Swarm } from './swarm';
|
|
6
|
+
/**
|
|
7
|
+
* State of the connection to the remote peer with additional info derived from network mapping.
|
|
8
|
+
*/
|
|
9
|
+
export declare type PeerState = ConnectionState | 'INDIRECTLY_CONNECTED' | 'ME';
|
|
10
|
+
/**
|
|
11
|
+
* Information about remote peer, directly or indirectly connected.
|
|
12
|
+
*/
|
|
13
|
+
export interface PeerInfo {
|
|
14
|
+
id: PublicKey;
|
|
15
|
+
state: PeerState;
|
|
16
|
+
connections: PublicKey[];
|
|
17
|
+
}
|
|
18
|
+
export declare class SwarmMapper {
|
|
19
|
+
private readonly _swarm;
|
|
20
|
+
private readonly _presence;
|
|
21
|
+
private readonly _subscriptions;
|
|
22
|
+
private readonly _connectionSubscriptions;
|
|
23
|
+
private readonly _peers;
|
|
24
|
+
get peers(): PeerInfo[];
|
|
25
|
+
readonly mapUpdated: Event<PeerInfo[]>;
|
|
26
|
+
constructor(_swarm: Swarm, _presence: PresencePlugin | undefined);
|
|
27
|
+
private _update;
|
|
28
|
+
destroy(): void;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=swarm-mapper.d.ts.map
|
|
@@ -0,0 +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;AAEvC,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAGhE,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC;;GAEG;AACH,oBAAY,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;IAcpB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAd5B,OAAO,CAAC,QAAQ,CAAC,cAAc,CAA4B;IAC3D,OAAO,CAAC,QAAQ,CAAC,wBAAwB,CAA0D;IAEnG,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuD;IAE9E,IAAI,KAAK,IAAI,QAAQ,EAAE,CAEtB;IAED,QAAQ,CAAC,UAAU,oBAA2B;gBAI3B,MAAM,EAAE,KAAK,EACb,SAAS,EAAE,cAAc,GAAG,SAAS;IA6BxD,OAAO,CAAC,OAAO;IA0Cf,OAAO;CAIR"}
|