@dxos/network-manager 2.33.9-dev.7d11f506 → 2.33.9-dev.9bbef4e2

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.
Files changed (158) hide show
  1. package/dist/src/network-manager.blueprint-test.d.ts +3 -1
  2. package/dist/src/network-manager.blueprint-test.d.ts.map +1 -1
  3. package/dist/src/network-manager.blueprint-test.js +46 -17
  4. package/dist/src/network-manager.blueprint-test.js.map +1 -1
  5. package/dist/src/network-manager.browser-test.js +1 -1
  6. package/dist/src/network-manager.browser-test.js.map +1 -1
  7. package/dist/src/network-manager.d.ts.map +1 -1
  8. package/dist/src/network-manager.js +13 -12
  9. package/dist/src/network-manager.js.map +1 -1
  10. package/dist/src/network-manager.test.js +5 -4
  11. package/dist/src/network-manager.test.js.map +1 -1
  12. package/dist/src/proto/gen/dxos/credentials.d.ts +39 -0
  13. package/dist/src/proto/gen/dxos/credentials.d.ts.map +1 -1
  14. package/dist/src/proto/gen/dxos/halo/keys.d.ts +44 -2
  15. package/dist/src/proto/gen/dxos/halo/keys.d.ts.map +1 -1
  16. package/dist/src/proto/gen/dxos/halo/keys.js +4 -0
  17. package/dist/src/proto/gen/dxos/halo/keys.js.map +1 -1
  18. package/dist/src/proto/gen/dxos/mesh/signal.d.ts +74 -16
  19. package/dist/src/proto/gen/dxos/mesh/signal.d.ts.map +1 -1
  20. package/dist/src/proto/gen/dxos/mesh/signalMessage.d.ts +79 -0
  21. package/dist/src/proto/gen/dxos/mesh/signalMessage.d.ts.map +1 -0
  22. package/dist/src/proto/gen/dxos/mesh/signalMessage.js +3 -0
  23. package/dist/src/proto/gen/dxos/mesh/signalMessage.js.map +1 -0
  24. package/dist/src/proto/gen/google/protobuf.d.ts +8 -2
  25. package/dist/src/proto/gen/google/protobuf.d.ts.map +1 -1
  26. package/dist/src/proto/gen/index.d.ts +17 -4
  27. package/dist/src/proto/gen/index.d.ts.map +1 -1
  28. package/dist/src/proto/gen/index.js +1 -1
  29. package/dist/src/proto/gen/index.js.map +1 -1
  30. package/dist/src/proto/substitutions.d.ts +4 -0
  31. package/dist/src/proto/substitutions.d.ts.map +1 -1
  32. package/dist/src/proto/substitutions.js +3 -1
  33. package/dist/src/proto/substitutions.js.map +1 -1
  34. package/dist/src/protocol-factory.js +3 -3
  35. package/dist/src/protocol-factory.js.map +1 -1
  36. package/dist/src/signal/in-memory-signal-manager.d.ts +7 -7
  37. package/dist/src/signal/in-memory-signal-manager.d.ts.map +1 -1
  38. package/dist/src/signal/in-memory-signal-manager.js +34 -13
  39. package/dist/src/signal/in-memory-signal-manager.js.map +1 -1
  40. package/dist/src/signal/index.d.ts +1 -2
  41. package/dist/src/signal/index.d.ts.map +1 -1
  42. package/dist/src/signal/index.js +1 -2
  43. package/dist/src/signal/index.js.map +1 -1
  44. package/dist/src/signal/integration.test.d.ts +2 -0
  45. package/dist/src/signal/integration.test.d.ts.map +1 -0
  46. package/dist/src/signal/integration.test.js +102 -0
  47. package/dist/src/signal/integration.test.js.map +1 -0
  48. package/dist/src/signal/message-router.d.ts +20 -8
  49. package/dist/src/signal/message-router.d.ts.map +1 -1
  50. package/dist/src/signal/message-router.js +96 -17
  51. package/dist/src/signal/message-router.js.map +1 -1
  52. package/dist/src/signal/message-router.test.js +125 -22
  53. package/dist/src/signal/message-router.test.js.map +1 -1
  54. package/dist/src/signal/signal-client.d.ts +33 -17
  55. package/dist/src/signal/signal-client.d.ts.map +1 -1
  56. package/dist/src/signal/signal-client.js +102 -82
  57. package/dist/src/signal/signal-client.js.map +1 -1
  58. package/dist/src/signal/signal-client.test.js +60 -75
  59. package/dist/src/signal/signal-client.test.js.map +1 -1
  60. package/dist/src/signal/{websocket-signal-manager.d.ts → signal-manager-impl.d.ts} +13 -11
  61. package/dist/src/signal/signal-manager-impl.d.ts.map +1 -0
  62. package/dist/src/signal/signal-manager-impl.js +151 -0
  63. package/dist/src/signal/signal-manager-impl.js.map +1 -0
  64. package/dist/src/signal/signal-manager.d.ts +12 -11
  65. package/dist/src/signal/signal-manager.d.ts.map +1 -1
  66. package/dist/src/signal/signal-rpc-client.d.ts +19 -0
  67. package/dist/src/signal/signal-rpc-client.d.ts.map +1 -0
  68. package/dist/src/signal/signal-rpc-client.js +108 -0
  69. package/dist/src/signal/signal-rpc-client.js.map +1 -0
  70. package/dist/src/signal/signal-rpc-client.test.d.ts +2 -0
  71. package/dist/src/signal/signal-rpc-client.test.d.ts.map +1 -0
  72. package/dist/src/signal/signal-rpc-client.test.js +74 -0
  73. package/dist/src/signal/signal-rpc-client.test.js.map +1 -0
  74. package/dist/src/swarm/connection.d.ts +3 -3
  75. package/dist/src/swarm/connection.d.ts.map +1 -1
  76. package/dist/src/swarm/connection.js +8 -11
  77. package/dist/src/swarm/connection.js.map +1 -1
  78. package/dist/src/swarm/swarm.d.ts +6 -7
  79. package/dist/src/swarm/swarm.d.ts.map +1 -1
  80. package/dist/src/swarm/swarm.js +29 -25
  81. package/dist/src/swarm/swarm.js.map +1 -1
  82. package/dist/src/swarm/swarm.test.js +156 -115
  83. package/dist/src/swarm/swarm.test.js.map +1 -1
  84. package/dist/src/testing/test-protocol.d.ts.map +1 -1
  85. package/dist/src/testing/test-protocol.js +3 -3
  86. package/dist/src/testing/test-protocol.js.map +1 -1
  87. package/dist/src/topology/fully-connected-topology.d.ts +0 -1
  88. package/dist/src/topology/fully-connected-topology.d.ts.map +1 -1
  89. package/dist/src/topology/fully-connected-topology.js +4 -9
  90. package/dist/src/topology/fully-connected-topology.js.map +1 -1
  91. package/dist/src/topology/mmst-topology.d.ts +0 -1
  92. package/dist/src/topology/mmst-topology.d.ts.map +1 -1
  93. package/dist/src/topology/mmst-topology.js +6 -11
  94. package/dist/src/topology/mmst-topology.js.map +1 -1
  95. package/dist/src/topology/star-topology.d.ts +0 -1
  96. package/dist/src/topology/star-topology.d.ts.map +1 -1
  97. package/dist/src/topology/star-topology.js +5 -10
  98. package/dist/src/topology/star-topology.js.map +1 -1
  99. package/dist/src/topology/topology.d.ts +0 -6
  100. package/dist/src/topology/topology.d.ts.map +1 -1
  101. package/dist/src/transport/in-memory-transport.d.ts +2 -2
  102. package/dist/src/transport/in-memory-transport.d.ts.map +1 -1
  103. package/dist/src/transport/in-memory-transport.js +2 -2
  104. package/dist/src/transport/in-memory-transport.js.map +1 -1
  105. package/dist/src/transport/transport.d.ts +3 -3
  106. package/dist/src/transport/transport.d.ts.map +1 -1
  107. package/dist/src/transport/webrtc-transport.d.ts +3 -3
  108. package/dist/src/transport/webrtc-transport.d.ts.map +1 -1
  109. package/dist/src/transport/webrtc-transport.js +3 -3
  110. package/dist/src/transport/webrtc-transport.js.map +1 -1
  111. package/dist/tests-setup.js +1 -1
  112. package/dist/tsconfig.tsbuildinfo +1 -1
  113. package/package.json +17 -12
  114. package/src/network-manager.blueprint-test.ts +57 -22
  115. package/src/network-manager.browser-test.ts +1 -1
  116. package/src/network-manager.test.ts +8 -7
  117. package/src/network-manager.ts +10 -10
  118. package/src/proto/defs/dxos/mesh/signal.proto +54 -23
  119. package/src/proto/defs/dxos/mesh/signalMessage.proto +51 -0
  120. package/src/proto/gen/dxos/credentials.ts +40 -0
  121. package/src/proto/gen/dxos/halo/keys.ts +45 -2
  122. package/src/proto/gen/dxos/mesh/signal.ts +73 -16
  123. package/src/proto/gen/dxos/mesh/signalMessage.ts +83 -0
  124. package/src/proto/gen/google/protobuf.ts +9 -2
  125. package/src/proto/gen/index.ts +18 -5
  126. package/src/proto/substitutions.ts +3 -1
  127. package/src/protocol-factory.ts +1 -1
  128. package/src/signal/in-memory-signal-manager.ts +38 -13
  129. package/src/signal/index.ts +1 -2
  130. package/src/signal/integration.test.ts +117 -0
  131. package/src/signal/message-router.test.ts +169 -58
  132. package/src/signal/message-router.ts +120 -27
  133. package/src/signal/signal-client.test.ts +70 -90
  134. package/src/signal/signal-client.ts +120 -87
  135. package/src/signal/signal-manager-impl.ts +166 -0
  136. package/src/signal/signal-manager.ts +12 -12
  137. package/src/signal/signal-rpc-client.test.ts +86 -0
  138. package/src/signal/signal-rpc-client.ts +121 -0
  139. package/src/swarm/connection.ts +6 -9
  140. package/src/swarm/swarm.test.ts +208 -167
  141. package/src/swarm/swarm.ts +26 -22
  142. package/src/testing/test-protocol.ts +1 -1
  143. package/src/topology/fully-connected-topology.ts +2 -10
  144. package/src/topology/mmst-topology.ts +2 -10
  145. package/src/topology/star-topology.ts +2 -8
  146. package/src/topology/topology.ts +0 -7
  147. package/src/transport/in-memory-transport.ts +3 -3
  148. package/src/transport/transport.ts +3 -3
  149. package/src/transport/webrtc-transport.ts +4 -4
  150. package/dist/src/signal/websocket-rpc.d.ts +0 -30
  151. package/dist/src/signal/websocket-rpc.d.ts.map +0 -1
  152. package/dist/src/signal/websocket-rpc.js +0 -203
  153. package/dist/src/signal/websocket-rpc.js.map +0 -1
  154. package/dist/src/signal/websocket-signal-manager.d.ts.map +0 -1
  155. package/dist/src/signal/websocket-signal-manager.js +0 -134
  156. package/dist/src/signal/websocket-signal-manager.js.map +0 -1
  157. package/src/signal/websocket-rpc.ts +0 -208
  158. package/src/signal/websocket-signal-manager.ts +0 -158
@@ -25,21 +25,16 @@ const log = debug('dxos:network-manager:test');
25
25
  interface CreatePeerOptions {
26
26
  topic: PublicKey
27
27
  peerId: PublicKey
28
- inMemory?: boolean
29
28
  topology?: Topology
30
29
  signal?: string[]
31
30
  ice?: any
32
31
  }
33
32
 
34
- const signalApiPort = 12098;
35
- const signalApiUrl = 'ws://0.0.0.0:' + signalApiPort;
36
-
37
33
  const createPeer = async ({
38
34
  topic,
39
35
  peerId,
40
- inMemory,
41
36
  topology = new FullyConnectedTopology(),
42
- signal = !inMemory ? [signalApiUrl] : undefined,
37
+ signal,
43
38
  ice
44
39
  }: CreatePeerOptions) => {
45
40
  const networkManager = new NetworkManager({ signal, ice });
@@ -55,14 +50,14 @@ const createPeer = async ({
55
50
  };
56
51
  };
57
52
 
58
- const sharedTests = (inMemory: boolean) => {
53
+ const sharedTests = ({ inMemory, signalUrl } : { inMemory: boolean, signalUrl?: string }) => {
59
54
  it('two peers connect to each other', async () => {
60
55
  const topic = PublicKey.random();
61
56
  const peer1Id = PublicKey.random();
62
57
  const peer2Id = PublicKey.random();
63
58
 
64
- const { plugin: plugin1, networkManager: nm1 } = await createPeer({ topic, peerId: peer1Id, inMemory });
65
- const { plugin: plugin2, networkManager: nm2 } = await createPeer({ topic, peerId: peer2Id, inMemory });
59
+ const { plugin: plugin1, networkManager: nm1 } = await createPeer({ topic, peerId: peer1Id, signal: !inMemory ? [signalUrl!] : undefined });
60
+ const { plugin: plugin2, networkManager: nm2 } = await createPeer({ topic, peerId: peer2Id, signal: !inMemory ? [signalUrl!] : undefined });
66
61
 
67
62
  const received: any[] = [];
68
63
  const mockReceive = (p: Protocol, s: string) => {
@@ -74,13 +69,11 @@ const sharedTests = (inMemory: boolean) => {
74
69
  plugin2.on('connect', async () => {
75
70
  await plugin2.send(peer1Id.asBuffer(), 'Foo');
76
71
  });
77
-
78
72
  await waitForExpect(() => {
79
73
  expect(received.length).toBe(2);
80
74
  expect(received[0]).toBeInstanceOf(Protocol);
81
75
  expect(received[1]).toBe('Foo');
82
76
  });
83
-
84
77
  await nm1.destroy();
85
78
  await nm2.destroy();
86
79
  }).timeout(10_000).retries(3);
@@ -90,8 +83,8 @@ const sharedTests = (inMemory: boolean) => {
90
83
  const peer1Id = PublicKey.random();
91
84
  const peer2Id = PublicKey.random();
92
85
 
93
- const { networkManager: networkManager1, plugin: plugin1 } = await createPeer({ topic, peerId: peer1Id, inMemory });
94
- const { networkManager: networkManager2, plugin: plugin2 } = await createPeer({ topic, peerId: peer2Id, inMemory });
86
+ const { networkManager: networkManager1, plugin: plugin1 } = await createPeer({ topic, peerId: peer1Id, signal: !inMemory ? [signalUrl!] : undefined });
87
+ const { networkManager: networkManager2, plugin: plugin2 } = await createPeer({ topic, peerId: peer2Id, signal: !inMemory ? [signalUrl!] : undefined });
95
88
 
96
89
  await Promise.all([
97
90
  Event.wrap(plugin1, 'connect').waitForCount(1),
@@ -117,11 +110,53 @@ const sharedTests = (inMemory: boolean) => {
117
110
  log('Peer1 destroyed');
118
111
  await networkManager2.destroy();
119
112
  log('Peer2 destroyed');
120
- }).timeout(10_000).retries(3);
113
+ }).timeout(10_000);
114
+
115
+ it('join and leave swarm and reconnect', async () => {
116
+ const topic = PublicKey.random();
117
+ const peer1Id = PublicKey.random();
118
+ const peer2Id = PublicKey.random();
119
+
120
+ const { networkManager: networkManager1, plugin: plugin1 } = await createPeer({ topic, peerId: peer1Id, signal: !inMemory ? [signalUrl!] : undefined });
121
+ const { networkManager: networkManager2, plugin: plugin2 } = await createPeer({ topic, peerId: peer2Id, signal: !inMemory ? [signalUrl!] : undefined });
122
+
123
+ await Promise.all([
124
+ Event.wrap(plugin1, 'connect').waitForCount(1),
125
+ Event.wrap(plugin2, 'connect').waitForCount(1)
126
+ ]);
127
+
128
+ log('Connected');
129
+
130
+ const disconnectPromises = Promise.all([
131
+ Event.wrap(plugin1, 'disconnect').waitForCount(1),
132
+ Event.wrap(plugin2, 'disconnect').waitForCount(1)
133
+ ]);
134
+
135
+ const connectPromises = Promise.all([
136
+ Event.wrap(plugin1, 'connect').waitForCount(1),
137
+ Event.wrap(plugin2, 'connect').waitForCount(1)
138
+ ]);
139
+
140
+ log('Disconnecting peer2');
141
+ await networkManager2.leaveProtocolSwarm(topic);
142
+
143
+ log('Reconnecting peer2');
144
+ const newPeer2Id = PublicKey.random();
145
+ networkManager2.joinProtocolSwarm({ topic, peerId: newPeer2Id, protocol: testProtocolProvider(topic.asBuffer(), peer2Id.asBuffer(), plugin2), topology: new FullyConnectedTopology() });
146
+
147
+ await disconnectPromises;
148
+
149
+ await connectPromises;
150
+
151
+ await networkManager1.destroy();
152
+ log('Peer1 destroyed');
153
+ await networkManager2.destroy();
154
+ log('Peer2 destroyed');
155
+ }).timeout(10_000);
121
156
  };
122
157
 
123
158
  // eslint-disable-next-line jest/no-export
124
- export const webRTCTests = () => {
159
+ export const webRTCTests = ({ signalUrl } : { signalUrl?: string } = {}) => {
125
160
  let topic: PublicKey;
126
161
  let peer1Id: PublicKey;
127
162
  let peer2Id: PublicKey;
@@ -132,7 +167,7 @@ export const webRTCTests = () => {
132
167
  peer2Id = PublicKey.random();
133
168
  });
134
169
 
135
- sharedTests(false);
170
+ sharedTests({ inMemory: false, signalUrl });
136
171
 
137
172
  it.skip('two peers with different signal & turn servers', async () => {
138
173
  const { networkManager: networkManager1, plugin: plugin1 } = await createPeer({ topic, peerId: peer1Id, signal: ['wss://apollo3.kube.moon.dxos.network/dxos/signal'], ice: [{ urls: 'turn:apollo3.kube.moon.dxos.network:3478', username: 'dxos', credential: 'dxos' }] });
@@ -187,7 +222,7 @@ export const webRTCTests = () => {
187
222
 
188
223
  // eslint-disable-next-line jest/no-export
189
224
  export function inMemoryTests () {
190
- sharedTests(true);
225
+ sharedTests({ inMemory: true });
191
226
 
192
227
  it('two swarms at the same time', async () => {
193
228
  const topicA = PublicKey.random();
@@ -197,10 +232,10 @@ export function inMemoryTests () {
197
232
  const peerB1Id = PublicKey.random();
198
233
  const peerB2Id = PublicKey.random();
199
234
 
200
- const { plugin: pluginA1 } = await createPeer({ topic: topicA, peerId: peerA1Id, inMemory: true });
201
- const { plugin: pluginA2 } = await createPeer({ topic: topicA, peerId: peerA2Id, inMemory: true });
202
- const { plugin: pluginB1 } = await createPeer({ topic: topicB, peerId: peerB1Id, inMemory: true });
203
- const { plugin: pluginB2 } = await createPeer({ topic: topicB, peerId: peerB2Id, inMemory: true });
235
+ const { plugin: pluginA1 } = await createPeer({ topic: topicA, peerId: peerA1Id });
236
+ const { plugin: pluginA2 } = await createPeer({ topic: topicA, peerId: peerA2Id });
237
+ const { plugin: pluginB1 } = await createPeer({ topic: topicB, peerId: peerB1Id });
238
+ const { plugin: pluginB2 } = await createPeer({ topic: topicB, peerId: peerB2Id });
204
239
 
205
240
  const receivedA: any[] = [];
206
241
  const mockReceiveA = (p: Protocol, s: string) => {
@@ -241,7 +276,7 @@ export function inMemoryTests () {
241
276
 
242
277
  await Promise.all(range(peersPerTopic).map(async (_, index) => {
243
278
  const peerId = PublicKey.random();
244
- const { plugin } = await createPeer({ topic, peerId, inMemory: true });
279
+ const { plugin } = await createPeer({ topic, peerId });
245
280
 
246
281
  const [done, pongReceived] = latch(peersPerTopic - 1);
247
282
 
@@ -6,7 +6,7 @@ import { inMemoryTests, webRTCTests } from './network-manager.blueprint-test';
6
6
 
7
7
  describe('Network manager', () => {
8
8
  describe('WebRTC transport', () => {
9
- webRTCTests();
9
+ webRTCTests({ signalUrl: 'ws://localhost:12087/.well-known/dx/signal' });
10
10
  }).timeout(10_000);
11
11
 
12
12
  // TODO(marik-d): In-memory tests seem to be broken in the browser. Need more investigation.
@@ -2,24 +2,25 @@
2
2
  // Copyright 2021 DXOS.org
3
3
  //
4
4
 
5
- import { Awaited } from '@dxos/async';
6
- import { createTestBroker } from '@dxos/signal';
5
+ import { createTestBroker, TestBroker } from '@dxos/signal';
7
6
 
8
7
  import { webRTCTests, inMemoryTests } from './network-manager.blueprint-test';
9
8
 
9
+ const PORT = 12087;
10
+
10
11
  describe('Network manager', () => {
11
12
  describe('WebRTC transport', () => {
12
- let broker: Awaited<ReturnType<typeof createTestBroker>>;
13
+ let broker: TestBroker;
13
14
 
14
15
  before(async () => {
15
- broker = await createTestBroker(12098);
16
+ broker = await createTestBroker(PORT);
16
17
  });
17
18
 
18
- after(async () => {
19
- await broker?.stop();
19
+ after(() => {
20
+ broker?.stop();
20
21
  });
21
22
 
22
- webRTCTests();
23
+ webRTCTests({ signalUrl: `ws://localhost:${PORT}/.well-known/dx/signal` });
23
24
  }).timeout(10_000);
24
25
 
25
26
  describe('In-memory transport', () => {
@@ -2,8 +2,8 @@
2
2
  // Copyright 2020 DXOS.org
3
3
  //
4
4
 
5
- import assert from 'assert';
6
5
  import debug from 'debug';
6
+ import assert from 'node:assert';
7
7
 
8
8
  import { Event } from '@dxos/async';
9
9
  import { GreetingCommandPlugin, ERR_GREET_ALREADY_CONNECTED_TO_SWARM } from '@dxos/credentials';
@@ -12,8 +12,8 @@ import { PublicKey } from '@dxos/protocols';
12
12
  import { ComplexMap } from '@dxos/util';
13
13
 
14
14
  import { ConnectionLog } from './connection-log';
15
- import { Message } from './proto/gen/dxos/mesh/signal';
16
- import { InMemorySignalManager, SignalManager, WebsocketSignalManager } from './signal';
15
+ import { SignalMessage } from './proto/gen/dxos/mesh/signalMessage';
16
+ import { InMemorySignalManager, SignalManager, SignalManagerImpl } from './signal';
17
17
  import { MessageRouter } from './signal/message-router';
18
18
  import { Swarm, SwarmMapper } from './swarm';
19
19
  import { Topology } from './topology';
@@ -48,20 +48,20 @@ export class NetworkManager {
48
48
  constructor (options: NetworkManagerOptions = {}) {
49
49
  this._ice = options.ice ?? [];
50
50
 
51
- const onOffer = async (message: Message) =>
51
+ const onOffer = async (message: SignalMessage) =>
52
52
  await this._swarms.get(message.topic!)?.onOffer(message) ?? { accept: false };
53
53
 
54
54
  this._signalManager = options.signal
55
- ? new WebsocketSignalManager(options.signal, onOffer)
55
+ ? new SignalManagerImpl(options.signal)
56
56
  : new InMemorySignalManager(onOffer);
57
57
 
58
- this._signalManager.peerCandidatesChanged
59
- .on(([topic, candidates]) => this._swarms.get(topic)?.onPeerCandidatesChanged(candidates));
58
+ this._signalManager.swarmEvent
59
+ .on(([topic, event]) => this._swarms.get(topic)?.onSwarmEvent(event));
60
60
 
61
- this._signalManager.onSignal.on(msg => this._messageRouter.receiveMessage(msg));
61
+ this._signalManager.onMessage.on(msg => this._messageRouter.receiveMessage(msg));
62
62
 
63
63
  this._messageRouter = new MessageRouter({
64
- sendMessage: msg => this._signalManager.signal(msg),
64
+ sendMessage: msg => this._signalManager.message(msg),
65
65
  onSignal: async (msg) => this._swarms.get(msg.topic!)?.onSignal(msg),
66
66
  onOffer: msg => onOffer(msg)
67
67
  });
@@ -118,7 +118,6 @@ export class NetworkManager {
118
118
  topology,
119
119
  protocol,
120
120
  this._messageRouter,
121
- this._signalManager.lookup.bind(this._signalManager),
122
121
  transportFactory,
123
122
  options.label
124
123
  );
@@ -177,6 +176,7 @@ export class NetworkManager {
177
176
  });
178
177
  }
179
178
 
179
+ await this._messageRouter.destroy();
180
180
  await this._signalManager.destroy();
181
181
  }
182
182
  }
@@ -1,38 +1,69 @@
1
- //
2
- // Copyright 2020 DXOS.org
3
- //
4
-
5
1
  syntax = "proto3";
6
2
 
7
- import "@dxos/protocols/src/proto/dxos/halo/keys.proto";
3
+ import "google/protobuf/any.proto";
4
+ import "google/protobuf/empty.proto";
5
+ import "google/protobuf/timestamp.proto";
8
6
 
9
7
  package dxos.mesh.signal;
10
8
 
9
+ option go_package = "github.com/dxos/kube/go/signal/pb";
10
+
11
+ message JoinRequest {
12
+ bytes swarm = 1;
13
+ bytes peer = 2;
14
+ }
15
+
11
16
  message Message {
12
- /// Sender's public key.
13
- PubKey id = 1;
14
- /// Receiver`s public key.
15
- PubKey remoteId = 2;
16
- PubKey topic = 3;
17
- PubKey sessionId = 4;
18
- MessageData data = 5;
17
+ bytes author = 1;
18
+ bytes recipient = 2;
19
+ google.protobuf.Any payload = 3;
19
20
  }
20
21
 
21
- message MessageData {
22
- oneof payload {
23
- Offer offer = 1;
24
- Answer answer = 2;
25
- Signal signal = 3;
26
- }
22
+ message ReceptionRequest {
23
+ bytes peer = 1;
24
+ }
25
+
26
+ // Goes on Pub/Sub swarm topic and as a Join stream in RPC.
27
+ message SwarmEvent {
28
+ message PeerAvailable {
29
+ bytes peer = 1;
30
+ google.protobuf.Timestamp since = 2;
31
+ // When, if at all (handle the default value as not), this availability would expires were it not re-announced, like
32
+ // periodically in Pub/Sub with some margin such that Pub/Sub network partitions lead to offline statuses.
33
+ optional google.protobuf.Timestamp until = 3;
34
+
35
+ // Only relevant in Pub/Sub. Optional, the host topic to eagerly send PeerAvailable messages back to.
36
+ optional bytes announceBackToHost = 4;
37
+ }
38
+
39
+ message PeerLeft {
40
+ bytes peer = 1;
41
+ }
42
+
43
+ oneof event {
44
+ // The peer was announced as available on the swarm.
45
+ PeerAvailable peerAvailable = 1;
46
+ // The peer left, or their announcement timed out.
47
+ PeerLeft peerLeft = 2;
48
+ }
27
49
  }
28
50
 
29
- message Offer {
51
+ // Goes on a Pub/Sub host topic.
52
+ message HostEvent {
53
+ oneof event {
54
+ SwarmEvent.PeerAvailable peerAvailable = 1;
55
+ }
30
56
  }
31
57
 
32
- message Answer {
33
- bool accept = 1;
58
+ // Goes on Pub/Sub peer topic.
59
+ message PeerEvent {
60
+ oneof event {
61
+ Message message = 1;
62
+ }
34
63
  }
35
64
 
36
- message Signal {
37
- string json = 1;
65
+ service Signal {
66
+ rpc Join(JoinRequest) returns (stream SwarmEvent);
67
+ rpc ReceiveMessages(ReceptionRequest) returns (stream Message);
68
+ rpc SendMessage(Message) returns (google.protobuf.Empty);
38
69
  }
@@ -0,0 +1,51 @@
1
+ //
2
+ // Copyright 2020 DXOS.org
3
+ //
4
+
5
+ syntax = "proto3";
6
+
7
+ import "@dxos/protocols/src/proto/dxos/halo/keys.proto";
8
+
9
+ package dxos.mesh.signalMessage;
10
+
11
+ message SignalMessage {
12
+ /// Sender's public key.
13
+ PubKey id = 1;
14
+ /// Receiver`s public key.
15
+ PubKey remoteId = 2;
16
+ /// Swarm identefier.
17
+ PubKey topic = 3;
18
+ /// Unique connection identifier.
19
+ PubKey sessionId = 4;
20
+ /// Message payload.
21
+ MessageData data = 5;
22
+ /// Unique message identifier. Used for Acknolegment and matching Anwers to Offers.
23
+ optional PubKey messageId = 6;
24
+ }
25
+
26
+ message MessageData {
27
+ oneof payload {
28
+ Offer offer = 1;
29
+ Answer answer = 2;
30
+ Signal signal = 3;
31
+ Acknowledgement ack = 4;
32
+ }
33
+ }
34
+
35
+ message Offer {
36
+ }
37
+
38
+ message Answer {
39
+ bool accept = 1;
40
+ /// MessageId of the Offer being answered.
41
+ optional PubKey offerMessageId = 2;
42
+ }
43
+
44
+ message Signal {
45
+ string json = 1;
46
+ }
47
+
48
+ message Acknowledgement {
49
+ // MessageId of the Message being acknowledged.
50
+ PubKey messageId = 1;
51
+ }
@@ -2,26 +2,66 @@ import type { Stream } from "@dxos/codec-protobuf";
2
2
  import substitutions from "../../substitutions";
3
3
  import * as dxos_halo_keys from "./halo/keys";
4
4
  import * as dxos_mesh_signal from "./mesh/signal";
5
+ import * as dxos_mesh_signalMessage from "./mesh/signalMessage";
5
6
  import * as google_protobuf from "../google/protobuf";
7
+ /**
8
+ * Defined in:
9
+ * {@link file://./../../../../../../common/protocols/src/proto/dxos/halo/signed.proto}
10
+ */
6
11
  export interface Message {
7
12
  payload: google_protobuf.Any;
8
13
  }
9
14
  /**
10
15
  * A generic container message used whenever messages are signed (e.g. PartyCredential)
16
+ *
17
+ * Defined in:
18
+ * {@link file://./../../../../../../common/protocols/src/proto/dxos/halo/signed.proto}
11
19
  */
12
20
  export interface SignedMessage {
21
+ /**
22
+ * The signed message contents.
23
+ */
13
24
  signed: SignedMessage.Signed;
25
+ /**
26
+ * An array of Signatures, one for each key that signed the message.
27
+ */
14
28
  signatures?: SignedMessage.Signature[];
15
29
  }
16
30
  export namespace SignedMessage {
31
+ /**
32
+ * Defined in:
33
+ * {@link file://./../../../../../../common/protocols/src/proto/dxos/halo/signed.proto}
34
+ */
17
35
  export interface Signed {
36
+ /**
37
+ * RFC-3339 datetime string.
38
+ */
18
39
  created: string;
19
40
  nonce: Uint8Array;
41
+ /**
42
+ * The payload to be signed.
43
+ */
20
44
  payload: google_protobuf.Any;
21
45
  }
46
+ /**
47
+ * Defined in:
48
+ * {@link file://./../../../../../../common/protocols/src/proto/dxos/halo/signed.proto}
49
+ */
22
50
  export interface Signature {
51
+ /**
52
+ * The publicKey of the keypair that made this signature.
53
+ */
23
54
  key: ReturnType<(typeof substitutions)["dxos.halo.keys.PubKey"]["decode"]>;
55
+ /**
56
+ * The bytes of the signature.
57
+ */
24
58
  signature: Uint8Array;
59
+ /**
60
+ * The certification chain of SignedMessages for this key.
61
+ *
62
+ * Options:
63
+ * - proto3_optional = true
64
+ */
25
65
  keyChain?: dxos_halo_keys.KeyChain;
26
66
  }
27
67
  }
@@ -2,7 +2,12 @@ import type { Stream } from "@dxos/codec-protobuf";
2
2
  import substitutions from "../../../substitutions";
3
3
  import * as dxos_credentials from "../credentials";
4
4
  import * as dxos_mesh_signal from "../mesh/signal";
5
+ import * as dxos_mesh_signalMessage from "../mesh/signalMessage";
5
6
  import * as google_protobuf from "../../google/protobuf";
7
+ /**
8
+ * Defined in:
9
+ * {@link file://./../../../../../../../common/protocols/src/proto/dxos/halo/keys.proto}
10
+ */
6
11
  export enum KeyType {
7
12
  UNKNOWN = 0,
8
13
  IDENTITY = 1,
@@ -11,12 +16,24 @@ export enum KeyType {
11
16
  FEED = 4,
12
17
  DXNS_ADDRESS = 5
13
18
  }
19
+ /**
20
+ * Defined in:
21
+ * {@link file://./../../../../../../../common/protocols/src/proto/dxos/halo/keys.proto}
22
+ */
14
23
  export interface PubKey {
15
- data?: Uint8Array;
24
+ data: Uint8Array;
16
25
  }
26
+ /**
27
+ * Defined in:
28
+ * {@link file://./../../../../../../../common/protocols/src/proto/dxos/halo/keys.proto}
29
+ */
17
30
  export interface PrivKey {
18
- data?: Uint8Array;
31
+ data: Uint8Array;
19
32
  }
33
+ /**
34
+ * Defined in:
35
+ * {@link file://./../../../../../../../common/protocols/src/proto/dxos/halo/keys.proto}
36
+ */
20
37
  export interface KeyRecord {
21
38
  /**
22
39
  * The `KeyType` type of the key. This is often unknown for keys from other sources.
@@ -28,33 +45,59 @@ export interface KeyRecord {
28
45
  publicKey: ReturnType<(typeof substitutions)["dxos.halo.keys.PubKey"]["decode"]>;
29
46
  /**
30
47
  * The secret key as a Buffer (this will never be visible outside the Keyring).
48
+ *
49
+ * Options:
50
+ * - proto3_optional = true
31
51
  */
32
52
  secretKey?: ReturnType<(typeof substitutions)["dxos.halo.keys.PrivKey"]["decode"]>;
33
53
  /**
34
54
  * Is this key from a Greeting "hint"?
55
+ *
56
+ * Options:
57
+ * - proto3_optional = true
35
58
  */
36
59
  hint?: boolean;
37
60
  /**
38
61
  * Determines if this is our key?
39
62
  * Usually true if `secretKey` is present; may be false for "inception keys" such as the Party key.
63
+ *
64
+ * Options:
65
+ * - proto3_optional = true
40
66
  */
41
67
  own?: boolean;
42
68
  /**
43
69
  * Is this key to be trusted?
70
+ *
71
+ * Options:
72
+ * - proto3_optional = true
44
73
  */
45
74
  trusted?: boolean;
46
75
  /**
47
76
  * An RFC-3339 date/time string for when the key was added to the Keyring.
77
+ *
78
+ * Options:
79
+ * - proto3_optional = true
48
80
  */
49
81
  added?: string;
50
82
  /**
51
83
  * An RFC-3339 date/time string for when the key was created.
84
+ *
85
+ * Options:
86
+ * - proto3_optional = true
52
87
  */
53
88
  created?: string;
54
89
  }
90
+ /**
91
+ * Defined in:
92
+ * {@link file://./../../../../../../../common/protocols/src/proto/dxos/halo/keys.proto}
93
+ */
55
94
  export interface KeyRecordList {
56
95
  keys?: KeyRecord[];
57
96
  }
97
+ /**
98
+ * Defined in:
99
+ * {@link file://./../../../../../../../common/protocols/src/proto/dxos/halo/keys.proto}
100
+ */
58
101
  export interface KeyChain {
59
102
  publicKey: ReturnType<(typeof substitutions)["dxos.halo.keys.PubKey"]["decode"]>;
60
103
  message: dxos_credentials.SignedMessage;
@@ -2,30 +2,87 @@ import type { Stream } from "@dxos/codec-protobuf";
2
2
  import substitutions from "../../../substitutions";
3
3
  import * as dxos_credentials from "../credentials";
4
4
  import * as dxos_halo_keys from "../halo/keys";
5
+ import * as dxos_mesh_signalMessage from "./signalMessage";
5
6
  import * as google_protobuf from "../../google/protobuf";
7
+ /**
8
+ * Defined in:
9
+ * {@link file://./../../../defs/dxos/mesh/signal.proto}
10
+ */
11
+ export interface JoinRequest {
12
+ swarm: Uint8Array;
13
+ peer: Uint8Array;
14
+ }
15
+ /**
16
+ * Defined in:
17
+ * {@link file://./../../../defs/dxos/mesh/signal.proto}
18
+ */
6
19
  export interface Message {
20
+ author: Uint8Array;
21
+ recipient: Uint8Array;
22
+ payload: google_protobuf.Any;
23
+ }
24
+ /**
25
+ * Defined in:
26
+ * {@link file://./../../../defs/dxos/mesh/signal.proto}
27
+ */
28
+ export interface ReceptionRequest {
29
+ peer: Uint8Array;
30
+ }
31
+ /**
32
+ * Defined in:
33
+ * {@link file://./../../../defs/dxos/mesh/signal.proto}
34
+ */
35
+ export interface SwarmEvent {
36
+ peerAvailable?: SwarmEvent.PeerAvailable;
37
+ peerLeft?: SwarmEvent.PeerLeft;
38
+ }
39
+ export namespace SwarmEvent {
7
40
  /**
8
- * Sender's public key.
41
+ * Defined in:
42
+ * {@link file://./../../../defs/dxos/mesh/signal.proto}
9
43
  */
10
- id?: ReturnType<(typeof substitutions)["dxos.halo.keys.PubKey"]["decode"]>;
44
+ export interface PeerAvailable {
45
+ peer: Uint8Array;
46
+ since: ReturnType<(typeof substitutions)["google.protobuf.Timestamp"]["decode"]>;
47
+ /**
48
+ * Options:
49
+ * - proto3_optional = true
50
+ */
51
+ until?: ReturnType<(typeof substitutions)["google.protobuf.Timestamp"]["decode"]>;
52
+ /**
53
+ * Options:
54
+ * - proto3_optional = true
55
+ */
56
+ announceBackToHost?: Uint8Array;
57
+ }
11
58
  /**
12
- * Receiver`s public key.
59
+ * Defined in:
60
+ * {@link file://./../../../defs/dxos/mesh/signal.proto}
13
61
  */
14
- remoteId?: ReturnType<(typeof substitutions)["dxos.halo.keys.PubKey"]["decode"]>;
15
- topic?: ReturnType<(typeof substitutions)["dxos.halo.keys.PubKey"]["decode"]>;
16
- sessionId?: ReturnType<(typeof substitutions)["dxos.halo.keys.PubKey"]["decode"]>;
17
- data?: MessageData;
18
- }
19
- export interface MessageData {
20
- offer?: Offer;
21
- answer?: Answer;
22
- signal?: Signal;
62
+ export interface PeerLeft {
63
+ peer: Uint8Array;
64
+ }
23
65
  }
24
- export interface Offer {
66
+ /**
67
+ * Defined in:
68
+ * {@link file://./../../../defs/dxos/mesh/signal.proto}
69
+ */
70
+ export interface HostEvent {
71
+ peerAvailable?: SwarmEvent.PeerAvailable;
25
72
  }
26
- export interface Answer {
27
- accept?: boolean;
73
+ /**
74
+ * Defined in:
75
+ * {@link file://./../../../defs/dxos/mesh/signal.proto}
76
+ */
77
+ export interface PeerEvent {
78
+ message?: Message;
28
79
  }
80
+ /**
81
+ * Defined in:
82
+ * {@link file://./../../../defs/dxos/mesh/signal.proto}
83
+ */
29
84
  export interface Signal {
30
- json?: string;
85
+ join: (request: JoinRequest) => Stream<SwarmEvent>;
86
+ receiveMessages: (request: ReceptionRequest) => Stream<Message>;
87
+ sendMessage: (request: Message) => Promise<void>;
31
88
  }