@streamr/trackerless-network 100.0.0-testnet-two.4 → 100.0.0-testnet-three.1
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/src/NetworkNode.d.ts +2 -1
- package/dist/src/NetworkNode.js +6 -2
- package/dist/src/NetworkNode.js.map +1 -1
- package/dist/src/NetworkStack.d.ts +6 -2
- package/dist/src/NetworkStack.js +21 -1
- package/dist/src/NetworkStack.js.map +1 -1
- package/dist/src/exports.d.ts +1 -0
- package/dist/src/exports.js +4 -1
- package/dist/src/exports.js.map +1 -1
- package/dist/src/logic/DeliveryRpcLocal.js +1 -0
- package/dist/src/logic/DeliveryRpcLocal.js.map +1 -1
- package/dist/src/logic/DuplicateMessageDetector.d.ts +3 -3
- package/dist/src/logic/DuplicateMessageDetector.js +10 -6
- package/dist/src/logic/DuplicateMessageDetector.js.map +1 -1
- package/dist/src/logic/EntryPointDiscovery.js +8 -5
- package/dist/src/logic/EntryPointDiscovery.js.map +1 -1
- package/dist/src/logic/Layer0Node.d.ts +2 -0
- package/dist/src/logic/Layer1Node.d.ts +4 -4
- package/dist/src/logic/NodeList.d.ts +6 -8
- package/dist/src/logic/NodeList.js +10 -12
- package/dist/src/logic/NodeList.js.map +1 -1
- package/dist/src/logic/RandomGraphNode.d.ts +5 -5
- package/dist/src/logic/RandomGraphNode.js +27 -22
- package/dist/src/logic/RandomGraphNode.js.map +1 -1
- package/dist/src/logic/StreamrNode.d.ts +3 -2
- package/dist/src/logic/StreamrNode.js +25 -6
- package/dist/src/logic/StreamrNode.js.map +1 -1
- package/dist/src/logic/createRandomGraphNode.d.ts +2 -2
- package/dist/src/logic/createRandomGraphNode.js +16 -15
- package/dist/src/logic/createRandomGraphNode.js.map +1 -1
- package/dist/src/logic/inspect/InspectSession.js +3 -2
- package/dist/src/logic/inspect/InspectSession.js.map +1 -1
- package/dist/src/logic/inspect/Inspector.d.ts +5 -3
- package/dist/src/logic/inspect/Inspector.js +15 -2
- package/dist/src/logic/inspect/Inspector.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/HandshakeRpcLocal.d.ts +1 -1
- package/dist/src/logic/neighbor-discovery/HandshakeRpcLocal.js +18 -17
- package/dist/src/logic/neighbor-discovery/HandshakeRpcLocal.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/HandshakeRpcRemote.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/Handshaker.d.ts +3 -4
- package/dist/src/logic/neighbor-discovery/Handshaker.js +29 -27
- package/dist/src/logic/neighbor-discovery/Handshaker.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborFinder.d.ts +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborFinder.js +4 -2
- package/dist/src/logic/neighbor-discovery/NeighborFinder.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateManager.d.ts +2 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateManager.js +8 -4
- package/dist/src/logic/neighbor-discovery/NeighborUpdateManager.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.d.ts +4 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.js +31 -20
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcRemote.js.map +1 -1
- package/dist/src/logic/node-info/NodeInfoClient.d.ts +9 -0
- package/dist/src/logic/node-info/NodeInfoClient.js +19 -0
- package/dist/src/logic/node-info/NodeInfoClient.js.map +1 -0
- package/dist/src/logic/node-info/NodeInfoRpcLocal.d.ts +12 -0
- package/dist/src/logic/node-info/NodeInfoRpcLocal.js +29 -0
- package/dist/src/logic/node-info/NodeInfoRpcLocal.js.map +1 -0
- package/dist/src/logic/node-info/NodeInfoRpcRemote.d.ts +6 -0
- package/dist/src/logic/node-info/NodeInfoRpcRemote.js +11 -0
- package/dist/src/logic/node-info/NodeInfoRpcRemote.js.map +1 -0
- package/dist/src/logic/propagation/FifoMapWithTTL.js +7 -3
- package/dist/src/logic/propagation/FifoMapWithTTL.js.map +1 -1
- package/dist/src/logic/propagation/Propagation.js +3 -0
- package/dist/src/logic/propagation/Propagation.js.map +1 -1
- package/dist/src/logic/propagation/PropagationTaskStore.js +1 -0
- package/dist/src/logic/propagation/PropagationTaskStore.js.map +1 -1
- package/dist/src/logic/protocol-integration/stream-message/GroupKeyRequestTranslator.js +1 -1
- package/dist/src/logic/protocol-integration/stream-message/GroupKeyRequestTranslator.js.map +1 -1
- package/dist/src/logic/protocol-integration/stream-message/GroupKeyResponseTranslator.js +1 -1
- package/dist/src/logic/protocol-integration/stream-message/GroupKeyResponseTranslator.js.map +1 -1
- package/dist/src/logic/protocol-integration/stream-message/StreamMessageTranslator.js +43 -15
- package/dist/src/logic/protocol-integration/stream-message/StreamMessageTranslator.js.map +1 -1
- package/dist/src/logic/protocol-integration/stream-message/oldStreamMessageBinaryUtils.d.ts +3 -0
- package/dist/src/logic/protocol-integration/stream-message/oldStreamMessageBinaryUtils.js +14 -0
- package/dist/src/logic/protocol-integration/stream-message/oldStreamMessageBinaryUtils.js.map +1 -0
- package/dist/src/logic/proxy/ProxyClient.d.ts +1 -1
- package/dist/src/logic/proxy/ProxyClient.js +18 -11
- package/dist/src/logic/proxy/ProxyClient.js.map +1 -1
- package/dist/src/logic/proxy/ProxyConnectionRpcLocal.js +2 -1
- package/dist/src/logic/proxy/ProxyConnectionRpcLocal.js.map +1 -1
- package/dist/src/logic/proxy/ProxyConnectionRpcRemote.js.map +1 -1
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcLocal.d.ts +5 -3
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcLocal.js +9 -2
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcLocal.js.map +1 -1
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcRemote.d.ts +1 -0
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcRemote.js +11 -0
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcRemote.js.map +1 -1
- package/dist/src/logic/utils.js.map +1 -1
- package/dist/src/proto/google/protobuf/any.js +8 -8
- package/dist/src/proto/google/protobuf/any.js.map +1 -1
- package/dist/src/proto/google/protobuf/empty.js +2 -4
- package/dist/src/proto/google/protobuf/empty.js.map +1 -1
- package/dist/src/proto/google/protobuf/timestamp.js +10 -10
- package/dist/src/proto/google/protobuf/timestamp.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +4 -5
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +38 -29
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +26 -12
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +12 -16
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +2 -3
- package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.js +1 -1
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.client.d.ts +36 -0
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.client.js +50 -17
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.client.js.map +1 -1
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.d.ts +118 -5
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.js +91 -8
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.js.map +1 -1
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.server.d.ts +16 -0
- package/dist/test/benchmark/first-message.js +7 -5
- package/dist/test/benchmark/first-message.js.map +1 -1
- package/dist/test/utils/utils.js +2 -1
- package/dist/test/utils/utils.js.map +1 -1
- package/jest.config.js +3 -38
- package/package.json +7 -7
- package/protos/NetworkRpc.proto +38 -5
- package/src/NetworkNode.ts +5 -1
- package/src/NetworkStack.ts +23 -2
- package/src/exports.ts +4 -0
- package/src/logic/DuplicateMessageDetector.ts +7 -7
- package/src/logic/EntryPointDiscovery.ts +3 -3
- package/src/logic/Layer0Node.ts +2 -0
- package/src/logic/Layer1Node.ts +4 -4
- package/src/logic/NodeList.ts +9 -15
- package/src/logic/RandomGraphNode.ts +27 -23
- package/src/logic/StreamrNode.ts +18 -4
- package/src/logic/createRandomGraphNode.ts +19 -18
- package/src/logic/inspect/Inspector.ts +18 -5
- package/src/logic/neighbor-discovery/HandshakeRpcLocal.ts +18 -18
- package/src/logic/neighbor-discovery/Handshaker.ts +31 -32
- package/src/logic/neighbor-discovery/NeighborFinder.ts +2 -2
- package/src/logic/neighbor-discovery/NeighborUpdateManager.ts +7 -5
- package/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.ts +39 -27
- package/src/logic/node-info/NodeInfoClient.ts +21 -0
- package/src/logic/node-info/NodeInfoRpcLocal.ts +35 -0
- package/src/logic/node-info/NodeInfoRpcRemote.ts +11 -0
- package/src/logic/protocol-integration/stream-message/GroupKeyRequestTranslator.ts +1 -1
- package/src/logic/protocol-integration/stream-message/GroupKeyResponseTranslator.ts +1 -1
- package/src/logic/protocol-integration/stream-message/StreamMessageTranslator.ts +56 -27
- package/src/logic/protocol-integration/stream-message/oldStreamMessageBinaryUtils.ts +11 -0
- package/src/logic/proxy/ProxyClient.ts +10 -10
- package/src/logic/temporary-connection/TemporaryConnectionRpcLocal.ts +15 -4
- package/src/logic/temporary-connection/TemporaryConnectionRpcRemote.ts +11 -0
- package/src/proto/google/protobuf/any.ts +4 -4
- package/src/proto/google/protobuf/empty.ts +2 -4
- package/src/proto/google/protobuf/timestamp.ts +4 -4
- package/src/proto/packages/dht/protos/DhtRpc.client.ts +6 -7
- package/src/proto/packages/dht/protos/DhtRpc.server.ts +3 -4
- package/src/proto/packages/dht/protos/DhtRpc.ts +37 -20
- package/src/proto/packages/proto-rpc/protos/ProtoRpc.ts +1 -1
- package/src/proto/packages/trackerless-network/protos/NetworkRpc.client.ts +42 -1
- package/src/proto/packages/trackerless-network/protos/NetworkRpc.server.ts +17 -1
- package/src/proto/packages/trackerless-network/protos/NetworkRpc.ts +155 -12
- package/test/benchmark/first-message.ts +28 -8
- package/test/end-to-end/inspect.test.ts +13 -1
- package/test/end-to-end/proxy-and-full-node.test.ts +14 -1
- package/test/end-to-end/proxy-connections.test.ts +14 -2
- package/test/end-to-end/proxy-key-exchange.test.ts +15 -8
- package/test/end-to-end/random-graph-with-real-connections.test.ts +21 -21
- package/test/end-to-end/webrtc-full-node-network.test.ts +3 -3
- package/test/end-to-end/websocket-full-node-network.test.ts +3 -3
- package/test/integration/Handshakes.test.ts +8 -8
- package/test/integration/NetworkNode.test.ts +19 -1
- package/test/integration/NetworkRpc.test.ts +3 -2
- package/test/integration/NodeInfoRpc.test.ts +103 -0
- package/test/integration/Propagation.test.ts +2 -2
- package/test/integration/RandomGraphNode-Layer1Node-Latencies.test.ts +20 -21
- package/test/integration/RandomGraphNode-Layer1Node.test.ts +22 -19
- package/test/integration/stream-without-default-entrypoints.test.ts +17 -11
- package/test/unit/HandshakeRpcLocal.test.ts +15 -15
- package/test/unit/Handshaker.test.ts +3 -3
- package/test/unit/NeighborFinder.test.ts +5 -5
- package/test/unit/NeighborUpdateRpcLocal.test.ts +125 -0
- package/test/unit/NodeList.test.ts +56 -57
- package/test/unit/Propagation.test.ts +4 -2
- package/test/unit/RandomGraphNode.test.ts +7 -8
- package/test/unit/StreamMessageTranslator.test.ts +7 -4
- package/test/unit/StreamrNode.test.ts +2 -0
- package/test/unit/TemporaryConnectionRpcLocal.test.ts +32 -0
- package/test/unit/oldStreamMessageBinaryUtils.test.ts +39 -0
- package/test/utils/mock/MockLayer0Node.ts +6 -1
- package/test/utils/mock/MockLayer1Node.ts +2 -2
- package/test/utils/mock/Transport.ts +1 -1
- package/test/utils/utils.ts +3 -1
- package/tsconfig.jest.json +3 -3
- package/tsconfig.node.json +0 -1
- package/dist/package.json +0 -55
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
TemporaryConnectionRequest,
|
|
15
15
|
TemporaryConnectionResponse,
|
|
16
16
|
MessageID,
|
|
17
|
+
CloseTemporaryConnection,
|
|
17
18
|
} from '../proto/packages/trackerless-network/protos/NetworkRpc'
|
|
18
19
|
import { NodeList } from './NodeList'
|
|
19
20
|
import { DeliveryRpcClient } from '../proto/packages/trackerless-network/protos/NetworkRpc.client'
|
|
@@ -36,7 +37,7 @@ import { uniqBy } from 'lodash'
|
|
|
36
37
|
|
|
37
38
|
export interface Events {
|
|
38
39
|
message: (message: StreamMessage) => void
|
|
39
|
-
|
|
40
|
+
neighborConnected: (nodeId: DhtAddress) => void
|
|
40
41
|
entryPointLeaveDetected: () => void
|
|
41
42
|
}
|
|
42
43
|
|
|
@@ -49,13 +50,13 @@ export interface StrictRandomGraphNodeConfig {
|
|
|
49
50
|
nodeViewSize: number
|
|
50
51
|
nearbyNodeView: NodeList
|
|
51
52
|
randomNodeView: NodeList
|
|
52
|
-
|
|
53
|
+
neighbors: NodeList
|
|
53
54
|
handshaker: Handshaker
|
|
54
55
|
neighborFinder: NeighborFinder
|
|
55
56
|
neighborUpdateManager: NeighborUpdateManager
|
|
56
57
|
propagation: Propagation
|
|
57
58
|
rpcCommunicator: ListeningRpcCommunicator
|
|
58
|
-
|
|
59
|
+
neighborCount: number
|
|
59
60
|
inspector: Inspector
|
|
60
61
|
temporaryConnectionRpcLocal: TemporaryConnectionRpcLocal
|
|
61
62
|
isLocalNodeEntryPoint: () => boolean
|
|
@@ -90,13 +91,13 @@ export class RandomGraphNode extends EventEmitter<Events> {
|
|
|
90
91
|
}
|
|
91
92
|
const contact = this.config.nearbyNodeView.get(sourceId)
|
|
92
93
|
|| this.config.randomNodeView.get(sourceId)
|
|
93
|
-
|| this.config.
|
|
94
|
+
|| this.config.neighbors.get(sourceId)
|
|
94
95
|
|| this.config.proxyConnectionRpcLocal?.getConnection(sourceId )?.remote
|
|
95
96
|
// TODO: check integrity of notifier?
|
|
96
97
|
if (contact) {
|
|
97
|
-
this.config.layer1Node.removeContact(
|
|
98
|
-
this.config.
|
|
99
|
-
this.config.nearbyNodeView.remove(
|
|
98
|
+
this.config.layer1Node.removeContact(sourceId)
|
|
99
|
+
this.config.neighbors.remove(sourceId)
|
|
100
|
+
this.config.nearbyNodeView.remove(sourceId)
|
|
100
101
|
this.config.connectionLocker.unlockConnection(contact.getPeerDescriptor(), this.config.streamPartId)
|
|
101
102
|
this.config.neighborFinder.start([sourceId])
|
|
102
103
|
this.config.proxyConnectionRpcLocal?.removeConnection(sourceId)
|
|
@@ -143,11 +144,11 @@ export class RandomGraphNode extends EventEmitter<Events> {
|
|
|
143
144
|
this.abortController.signal
|
|
144
145
|
)
|
|
145
146
|
addManagedEventListener(
|
|
146
|
-
this.config.
|
|
147
|
+
this.config.neighbors,
|
|
147
148
|
'nodeAdded',
|
|
148
149
|
(id, _remote) => {
|
|
149
150
|
this.config.propagation.onNeighborJoined(id)
|
|
150
|
-
this.emit('
|
|
151
|
+
this.emit('neighborConnected', id)
|
|
151
152
|
},
|
|
152
153
|
this.abortController.signal
|
|
153
154
|
)
|
|
@@ -174,6 +175,8 @@ export class RandomGraphNode extends EventEmitter<Events> {
|
|
|
174
175
|
(req: LeaveStreamPartNotice, context) => this.deliveryRpcLocal.leaveStreamPartNotice(req, context))
|
|
175
176
|
this.config.rpcCommunicator.registerRpcMethod(TemporaryConnectionRequest, TemporaryConnectionResponse, 'openConnection',
|
|
176
177
|
(req: TemporaryConnectionRequest, context) => this.config.temporaryConnectionRpcLocal.openConnection(req, context))
|
|
178
|
+
this.config.rpcCommunicator.registerRpcNotification(CloseTemporaryConnection, 'closeConnection',
|
|
179
|
+
(req: TemporaryConnectionRequest, context) => this.config.temporaryConnectionRpcLocal.closeConnection(req, context))
|
|
177
180
|
}
|
|
178
181
|
|
|
179
182
|
private newContact(closestNodes: PeerDescriptor[]): void {
|
|
@@ -182,7 +185,7 @@ export class RandomGraphNode extends EventEmitter<Events> {
|
|
|
182
185
|
return
|
|
183
186
|
}
|
|
184
187
|
this.updateNearbyNodeView(closestNodes)
|
|
185
|
-
if (this.config.
|
|
188
|
+
if (this.config.neighbors.size() < this.config.neighborCount) {
|
|
186
189
|
this.config.neighborFinder.start()
|
|
187
190
|
}
|
|
188
191
|
}
|
|
@@ -205,7 +208,7 @@ export class RandomGraphNode extends EventEmitter<Events> {
|
|
|
205
208
|
this.config.rpcRequestTimeout
|
|
206
209
|
)
|
|
207
210
|
))
|
|
208
|
-
for (const descriptor of this.config.layer1Node.
|
|
211
|
+
for (const descriptor of this.config.layer1Node.getNeighbors()) {
|
|
209
212
|
if (this.config.nearbyNodeView.size() >= this.config.nodeViewSize) {
|
|
210
213
|
break
|
|
211
214
|
}
|
|
@@ -235,7 +238,7 @@ export class RandomGraphNode extends EventEmitter<Events> {
|
|
|
235
238
|
this.config.rpcRequestTimeout
|
|
236
239
|
)
|
|
237
240
|
))
|
|
238
|
-
if (this.config.
|
|
241
|
+
if (this.config.neighbors.size() < this.config.neighborCount) {
|
|
239
242
|
this.config.neighborFinder.start()
|
|
240
243
|
}
|
|
241
244
|
}
|
|
@@ -257,11 +260,12 @@ export class RandomGraphNode extends EventEmitter<Events> {
|
|
|
257
260
|
}
|
|
258
261
|
|
|
259
262
|
private onNodeDisconnected(peerDescriptor: PeerDescriptor): void {
|
|
260
|
-
|
|
261
|
-
|
|
263
|
+
const nodeId = getNodeIdFromPeerDescriptor(peerDescriptor)
|
|
264
|
+
if (this.config.neighbors.has(nodeId)) {
|
|
265
|
+
this.config.neighbors.remove(nodeId)
|
|
262
266
|
this.config.connectionLocker.unlockConnection(peerDescriptor, this.config.streamPartId)
|
|
263
|
-
this.config.neighborFinder.start([
|
|
264
|
-
this.config.temporaryConnectionRpcLocal.removeNode(
|
|
267
|
+
this.config.neighborFinder.start([nodeId])
|
|
268
|
+
this.config.temporaryConnectionRpcLocal.removeNode(nodeId)
|
|
265
269
|
}
|
|
266
270
|
}
|
|
267
271
|
|
|
@@ -270,7 +274,7 @@ export class RandomGraphNode extends EventEmitter<Events> {
|
|
|
270
274
|
this.config.layer1Node.getClosestContacts(this.config.nodeViewSize).forEach((peer: PeerDescriptor) => {
|
|
271
275
|
nodes.push(peer)
|
|
272
276
|
})
|
|
273
|
-
this.config.layer1Node.
|
|
277
|
+
this.config.layer1Node.getNeighbors().forEach((peer: PeerDescriptor) => {
|
|
274
278
|
nodes.push(peer)
|
|
275
279
|
})
|
|
276
280
|
return uniqBy(nodes, (p) => getNodeIdFromPeerDescriptor(p))
|
|
@@ -289,13 +293,13 @@ export class RandomGraphNode extends EventEmitter<Events> {
|
|
|
289
293
|
}
|
|
290
294
|
this.abortController.abort()
|
|
291
295
|
this.config.proxyConnectionRpcLocal?.stop()
|
|
292
|
-
this.config.
|
|
296
|
+
this.config.neighbors.getAll().map(
|
|
293
297
|
(remote) => remote.leaveStreamPartNotice(this.config.streamPartId, this.config.isLocalNodeEntryPoint())
|
|
294
298
|
)
|
|
295
299
|
this.config.rpcCommunicator.destroy()
|
|
296
300
|
this.removeAllListeners()
|
|
297
301
|
this.config.nearbyNodeView.stop()
|
|
298
|
-
this.config.
|
|
302
|
+
this.config.neighbors.stop()
|
|
299
303
|
this.config.randomNodeView.stop()
|
|
300
304
|
this.config.neighborFinder.stop()
|
|
301
305
|
this.config.neighborUpdateManager.stop()
|
|
@@ -315,7 +319,7 @@ export class RandomGraphNode extends EventEmitter<Events> {
|
|
|
315
319
|
}
|
|
316
320
|
|
|
317
321
|
private getPropagationTargets(msg: StreamMessage): DhtAddress[] {
|
|
318
|
-
let propagationTargets = this.config.
|
|
322
|
+
let propagationTargets = this.config.neighbors.getIds()
|
|
319
323
|
if (this.config.proxyConnectionRpcLocal) {
|
|
320
324
|
propagationTargets = propagationTargets.concat(this.config.proxyConnectionRpcLocal.getPropagationTargets(msg))
|
|
321
325
|
}
|
|
@@ -328,15 +332,15 @@ export class RandomGraphNode extends EventEmitter<Events> {
|
|
|
328
332
|
return getNodeIdFromPeerDescriptor(this.config.localPeerDescriptor)
|
|
329
333
|
}
|
|
330
334
|
|
|
331
|
-
|
|
335
|
+
getOutgoingHandshakeCount(): number {
|
|
332
336
|
return this.config.handshaker.getOngoingHandshakes().size
|
|
333
337
|
}
|
|
334
338
|
|
|
335
|
-
|
|
339
|
+
getNeighbors(): PeerDescriptor[] {
|
|
336
340
|
if (!this.started && this.isStopped()) {
|
|
337
341
|
return []
|
|
338
342
|
}
|
|
339
|
-
return this.config.
|
|
343
|
+
return this.config.neighbors.getAll().map((n) => n.getPeerDescriptor())
|
|
340
344
|
}
|
|
341
345
|
|
|
342
346
|
getNearbyNodeView(): NodeList {
|
package/src/logic/StreamrNode.ts
CHANGED
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
} from '@streamr/utils'
|
|
19
19
|
import { EventEmitter } from 'eventemitter3'
|
|
20
20
|
import { sampleSize } from 'lodash'
|
|
21
|
-
import { ProxyDirection, StreamMessage } from '../proto/packages/trackerless-network/protos/NetworkRpc'
|
|
21
|
+
import { ProxyDirection, StreamPartitionInfo, StreamMessage } from '../proto/packages/trackerless-network/protos/NetworkRpc'
|
|
22
22
|
import { Layer0Node } from './Layer0Node'
|
|
23
23
|
import { Layer1Node } from './Layer1Node'
|
|
24
24
|
import { RandomGraphNode } from './RandomGraphNode'
|
|
@@ -52,7 +52,7 @@ interface Metrics extends MetricsDefinition {
|
|
|
52
52
|
|
|
53
53
|
export interface StreamrNodeConfig {
|
|
54
54
|
metricsContext?: MetricsContext
|
|
55
|
-
|
|
55
|
+
streamPartitionNeighborCount?: number
|
|
56
56
|
streamPartitionMinPropagationTargets?: number
|
|
57
57
|
acceptProxyConnections?: boolean
|
|
58
58
|
rpcRequestTimeout?: number
|
|
@@ -222,7 +222,7 @@ export class StreamrNode extends EventEmitter<Events> {
|
|
|
222
222
|
connectionLocker: this.connectionLocker!,
|
|
223
223
|
localPeerDescriptor: this.layer0Node!.getLocalPeerDescriptor(),
|
|
224
224
|
minPropagationTargets: this.config.streamPartitionMinPropagationTargets,
|
|
225
|
-
|
|
225
|
+
neighborCount: this.config.streamPartitionNeighborCount,
|
|
226
226
|
acceptProxyConnections: this.config.acceptProxyConnections,
|
|
227
227
|
rpcRequestTimeout: this.config.rpcRequestTimeout,
|
|
228
228
|
isLocalNodeEntryPoint
|
|
@@ -284,6 +284,20 @@ export class StreamrNode extends EventEmitter<Events> {
|
|
|
284
284
|
return false
|
|
285
285
|
}
|
|
286
286
|
|
|
287
|
+
// TODO inline this method?
|
|
288
|
+
getNodeInfo(): StreamPartitionInfo[] {
|
|
289
|
+
const streamParts = Array.from(this.streamParts.entries()).filter(([_, node]) => node.proxied === false)
|
|
290
|
+
return streamParts.map(([streamPartId]) => {
|
|
291
|
+
const stream = this.streamParts.get(streamPartId)! as { node: RandomGraphNode, layer1Node: Layer1Node }
|
|
292
|
+
return {
|
|
293
|
+
id: streamPartId,
|
|
294
|
+
controlLayerNeighbors: stream.layer1Node.getNeighbors(),
|
|
295
|
+
deliveryLayerNeighbors: stream.node.getNeighbors()
|
|
296
|
+
}
|
|
297
|
+
})
|
|
298
|
+
|
|
299
|
+
}
|
|
300
|
+
|
|
287
301
|
setStreamPartEntryPoints(streamPartId: StreamPartID, entryPoints: PeerDescriptor[]): void {
|
|
288
302
|
this.knownStreamPartEntryPoints.set(streamPartId, entryPoints)
|
|
289
303
|
}
|
|
@@ -314,7 +328,7 @@ export class StreamrNode extends EventEmitter<Events> {
|
|
|
314
328
|
getNeighbors(streamPartId: StreamPartID): DhtAddress[] {
|
|
315
329
|
const streamPart = this.streamParts.get(streamPartId)
|
|
316
330
|
return (streamPart !== undefined) && (streamPart.proxied === false)
|
|
317
|
-
? streamPart.node.
|
|
331
|
+
? streamPart.node.getNeighbors().map((n) => getNodeIdFromPeerDescriptor(n))
|
|
318
332
|
: []
|
|
319
333
|
}
|
|
320
334
|
|
|
@@ -13,11 +13,11 @@ import { TemporaryConnectionRpcLocal } from './temporary-connection/TemporaryCon
|
|
|
13
13
|
import { formStreamPartDeliveryServiceId } from './formStreamPartDeliveryServiceId'
|
|
14
14
|
|
|
15
15
|
type RandomGraphNodeConfig = MarkOptional<StrictRandomGraphNodeConfig,
|
|
16
|
-
'nearbyNodeView' | 'randomNodeView' | '
|
|
17
|
-
| 'handshaker' | 'neighborFinder' | 'neighborUpdateManager' | '
|
|
16
|
+
'nearbyNodeView' | 'randomNodeView' | 'neighbors' | 'propagation'
|
|
17
|
+
| 'handshaker' | 'neighborFinder' | 'neighborUpdateManager' | 'neighborCount'
|
|
18
18
|
| 'rpcCommunicator' | 'nodeViewSize'
|
|
19
19
|
| 'inspector' | 'temporaryConnectionRpcLocal'> & {
|
|
20
|
-
|
|
20
|
+
maxContactCount?: number
|
|
21
21
|
minPropagationTargets?: number
|
|
22
22
|
acceptProxyConnections?: boolean
|
|
23
23
|
neighborUpdateInterval?: number
|
|
@@ -29,14 +29,14 @@ const createConfigWithDefaults = (config: RandomGraphNodeConfig): StrictRandomGr
|
|
|
29
29
|
formStreamPartDeliveryServiceId(config.streamPartId),
|
|
30
30
|
config.transport
|
|
31
31
|
)
|
|
32
|
-
const
|
|
33
|
-
const
|
|
32
|
+
const neighborCount = config.neighborCount ?? 4
|
|
33
|
+
const maxContactCount = config.maxContactCount ?? 20
|
|
34
34
|
const minPropagationTargets = config.minPropagationTargets ?? 2
|
|
35
35
|
const acceptProxyConnections = config.acceptProxyConnections ?? false
|
|
36
36
|
const neighborUpdateInterval = config.neighborUpdateInterval ?? 10000
|
|
37
|
-
const nearbyNodeView = config.nearbyNodeView ?? new NodeList(ownNodeId,
|
|
38
|
-
const randomNodeView = config.randomNodeView ?? new NodeList(ownNodeId,
|
|
39
|
-
const
|
|
37
|
+
const nearbyNodeView = config.nearbyNodeView ?? new NodeList(ownNodeId, maxContactCount)
|
|
38
|
+
const randomNodeView = config.randomNodeView ?? new NodeList(ownNodeId, maxContactCount)
|
|
39
|
+
const neighbors = config.neighbors ?? new NodeList(ownNodeId, maxContactCount)
|
|
40
40
|
|
|
41
41
|
const temporaryConnectionRpcLocal = new TemporaryConnectionRpcLocal({
|
|
42
42
|
rpcCommunicator,
|
|
@@ -50,7 +50,7 @@ const createConfigWithDefaults = (config: RandomGraphNodeConfig): StrictRandomGr
|
|
|
50
50
|
const propagation = config.propagation ?? new Propagation({
|
|
51
51
|
minPropagationTargets,
|
|
52
52
|
sendToNeighbor: async (neighborId: DhtAddress, msg: StreamMessage): Promise<void> => {
|
|
53
|
-
const remote =
|
|
53
|
+
const remote = neighbors.get(neighborId) ?? temporaryConnectionRpcLocal.getNodes().get(neighborId)
|
|
54
54
|
const proxyConnection = proxyConnectionRpcLocal?.getConnection(neighborId)
|
|
55
55
|
if (remote) {
|
|
56
56
|
await remote.sendStreamMessage(msg)
|
|
@@ -68,24 +68,25 @@ const createConfigWithDefaults = (config: RandomGraphNodeConfig): StrictRandomGr
|
|
|
68
68
|
rpcCommunicator,
|
|
69
69
|
nearbyNodeView,
|
|
70
70
|
randomNodeView,
|
|
71
|
-
|
|
72
|
-
maxNeighborCount:
|
|
71
|
+
neighbors,
|
|
72
|
+
maxNeighborCount: neighborCount,
|
|
73
73
|
rpcRequestTimeout: config.rpcRequestTimeout
|
|
74
74
|
})
|
|
75
75
|
const neighborFinder = config.neighborFinder ?? new NeighborFinder({
|
|
76
|
-
|
|
76
|
+
neighbors,
|
|
77
77
|
nearbyNodeView,
|
|
78
78
|
doFindNeighbors: (excludedIds) => handshaker.attemptHandshakesOnContacts(excludedIds),
|
|
79
|
-
minCount:
|
|
79
|
+
minCount: neighborCount
|
|
80
80
|
})
|
|
81
81
|
const neighborUpdateManager = config.neighborUpdateManager ?? new NeighborUpdateManager({
|
|
82
|
-
|
|
82
|
+
neighbors,
|
|
83
83
|
nearbyNodeView,
|
|
84
84
|
localPeerDescriptor: config.localPeerDescriptor,
|
|
85
85
|
neighborFinder,
|
|
86
86
|
streamPartId: config.streamPartId,
|
|
87
87
|
rpcCommunicator,
|
|
88
|
-
neighborUpdateInterval
|
|
88
|
+
neighborUpdateInterval,
|
|
89
|
+
neighborCount
|
|
89
90
|
})
|
|
90
91
|
const inspector = config.inspector ?? new Inspector({
|
|
91
92
|
localPeerDescriptor: config.localPeerDescriptor,
|
|
@@ -97,14 +98,14 @@ const createConfigWithDefaults = (config: RandomGraphNodeConfig): StrictRandomGr
|
|
|
97
98
|
...config,
|
|
98
99
|
nearbyNodeView,
|
|
99
100
|
randomNodeView,
|
|
100
|
-
|
|
101
|
+
neighbors,
|
|
101
102
|
rpcCommunicator,
|
|
102
103
|
handshaker,
|
|
103
104
|
neighborFinder,
|
|
104
105
|
neighborUpdateManager,
|
|
105
106
|
propagation,
|
|
106
|
-
|
|
107
|
-
nodeViewSize:
|
|
107
|
+
neighborCount,
|
|
108
|
+
nodeViewSize: maxContactCount,
|
|
108
109
|
proxyConnectionRpcLocal,
|
|
109
110
|
inspector,
|
|
110
111
|
temporaryConnectionRpcLocal
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { PeerDescriptor, ConnectionLocker, LockID, DhtAddress, getNodeIdFromPeerDescriptor } from '@streamr/dht'
|
|
1
|
+
import { PeerDescriptor, ConnectionLocker, LockID, DhtAddress, getNodeIdFromPeerDescriptor, ListeningRpcCommunicator } from '@streamr/dht'
|
|
2
2
|
import { MessageID } from '../../proto/packages/trackerless-network/protos/NetworkRpc'
|
|
3
3
|
import { InspectSession, Events as InspectSessionEvents } from './InspectSession'
|
|
4
4
|
import { TemporaryConnectionRpcClient } from '../../proto/packages/trackerless-network/protos/NetworkRpc.client'
|
|
5
|
-
import { RpcCommunicator } from '@streamr/proto-rpc'
|
|
6
5
|
import { Logger, waitForEvent3 } from '@streamr/utils'
|
|
7
6
|
import { TemporaryConnectionRpcRemote } from '../temporary-connection/TemporaryConnectionRpcRemote'
|
|
8
7
|
import { StreamPartID } from '@streamr/protocol'
|
|
@@ -10,10 +9,11 @@ import { StreamPartID } from '@streamr/protocol'
|
|
|
10
9
|
interface InspectorConfig {
|
|
11
10
|
localPeerDescriptor: PeerDescriptor
|
|
12
11
|
streamPartId: StreamPartID
|
|
13
|
-
rpcCommunicator:
|
|
12
|
+
rpcCommunicator: ListeningRpcCommunicator
|
|
14
13
|
connectionLocker: ConnectionLocker
|
|
15
14
|
inspectionTimeout?: number
|
|
16
15
|
openInspectConnection?: (peerDescriptor: PeerDescriptor, lockId: LockID) => Promise<void>
|
|
16
|
+
closeInspectConnection?: (peerDescriptor: PeerDescriptor, lockId: LockID) => Promise<void>
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
const logger = new Logger(module)
|
|
@@ -24,10 +24,11 @@ export class Inspector {
|
|
|
24
24
|
private readonly sessions: Map<DhtAddress, InspectSession> = new Map()
|
|
25
25
|
private readonly streamPartId: StreamPartID
|
|
26
26
|
private readonly localPeerDescriptor: PeerDescriptor
|
|
27
|
-
private readonly rpcCommunicator:
|
|
27
|
+
private readonly rpcCommunicator: ListeningRpcCommunicator
|
|
28
28
|
private readonly connectionLocker: ConnectionLocker
|
|
29
29
|
private readonly inspectionTimeout: number
|
|
30
30
|
private readonly openInspectConnection: (peerDescriptor: PeerDescriptor, lockId: LockID) => Promise<void>
|
|
31
|
+
private readonly closeInspectConnection: (peerDescriptor: PeerDescriptor, lockId: LockID) => Promise<void>
|
|
31
32
|
|
|
32
33
|
constructor(config: InspectorConfig) {
|
|
33
34
|
this.streamPartId = config.streamPartId
|
|
@@ -36,6 +37,7 @@ export class Inspector {
|
|
|
36
37
|
this.connectionLocker = config.connectionLocker
|
|
37
38
|
this.inspectionTimeout = config.inspectionTimeout ?? DEFAULT_TIMEOUT
|
|
38
39
|
this.openInspectConnection = config.openInspectConnection ?? this.defaultOpenInspectConnection
|
|
40
|
+
this.closeInspectConnection = config.closeInspectConnection ?? this.defaultCloseInspectConnection
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
async defaultOpenInspectConnection(peerDescriptor: PeerDescriptor, lockId: LockID): Promise<void> {
|
|
@@ -49,6 +51,17 @@ export class Inspector {
|
|
|
49
51
|
this.connectionLocker.lockConnection(peerDescriptor, lockId)
|
|
50
52
|
}
|
|
51
53
|
|
|
54
|
+
async defaultCloseInspectConnection(peerDescriptor: PeerDescriptor, lockId: LockID): Promise<void> {
|
|
55
|
+
const rpcRemote = new TemporaryConnectionRpcRemote(
|
|
56
|
+
this.localPeerDescriptor,
|
|
57
|
+
peerDescriptor,
|
|
58
|
+
this.rpcCommunicator,
|
|
59
|
+
TemporaryConnectionRpcClient
|
|
60
|
+
)
|
|
61
|
+
await rpcRemote.closeConnection()
|
|
62
|
+
this.connectionLocker.unlockConnection(peerDescriptor, lockId)
|
|
63
|
+
}
|
|
64
|
+
|
|
52
65
|
async inspect(peerDescriptor: PeerDescriptor): Promise<boolean> {
|
|
53
66
|
const nodeId = getNodeIdFromPeerDescriptor(peerDescriptor)
|
|
54
67
|
const session = new InspectSession({
|
|
@@ -64,8 +77,8 @@ export class Inspector {
|
|
|
64
77
|
} catch (err) {
|
|
65
78
|
logger.trace('Inspect session timed out, removing')
|
|
66
79
|
} finally {
|
|
80
|
+
await this.closeInspectConnection(peerDescriptor, lockId)
|
|
67
81
|
this.sessions.delete(nodeId)
|
|
68
|
-
this.connectionLocker.unlockConnection(peerDescriptor, lockId)
|
|
69
82
|
}
|
|
70
83
|
return success || session.getInspectedMessageCount() < 1
|
|
71
84
|
}
|
|
@@ -23,7 +23,7 @@ import { StreamPartID } from '@streamr/protocol'
|
|
|
23
23
|
|
|
24
24
|
interface HandshakeRpcLocalConfig {
|
|
25
25
|
streamPartId: StreamPartID
|
|
26
|
-
|
|
26
|
+
neighbors: NodeList
|
|
27
27
|
connectionLocker: ConnectionLocker
|
|
28
28
|
ongoingHandshakes: Set<DhtAddress>
|
|
29
29
|
ongoingInterleaves: Set<DhtAddress>
|
|
@@ -53,13 +53,13 @@ export class HandshakeRpcLocal implements IHandshakeRpc {
|
|
|
53
53
|
const senderNodeId = getNodeIdFromPeerDescriptor(senderDescriptor)
|
|
54
54
|
if (this.config.ongoingInterleaves.has(senderNodeId)) {
|
|
55
55
|
return this.rejectHandshake(request)
|
|
56
|
-
} else if (this.config.
|
|
56
|
+
} else if (this.config.neighbors.has(senderNodeId)
|
|
57
57
|
|| this.config.ongoingHandshakes.has(senderNodeId)
|
|
58
58
|
) {
|
|
59
59
|
return this.acceptHandshake(request, senderDescriptor)
|
|
60
|
-
} else if (this.config.
|
|
60
|
+
} else if (this.config.neighbors.size() + this.config.ongoingHandshakes.size < this.config.maxNeighborCount) {
|
|
61
61
|
return this.acceptHandshake(request, senderDescriptor)
|
|
62
|
-
} else if (this.config.
|
|
62
|
+
} else if (this.config.neighbors.size(getInterleaveSourceIds()) - this.config.ongoingInterleaves.size >= 2) {
|
|
63
63
|
// Do not accept the handshakes requests if the target neighbor count can potentially drop below 2
|
|
64
64
|
// due to interleaving. This ensures that a stable number of connections is kept during high churn.
|
|
65
65
|
return this.acceptHandshakeWithInterleaving(request, senderDescriptor)
|
|
@@ -73,7 +73,7 @@ export class HandshakeRpcLocal implements IHandshakeRpc {
|
|
|
73
73
|
requestId: request.requestId,
|
|
74
74
|
accepted: true
|
|
75
75
|
}
|
|
76
|
-
this.config.
|
|
76
|
+
this.config.neighbors.add(this.config.createDeliveryRpcRemote(requester))
|
|
77
77
|
this.config.connectionLocker.lockConnection(requester, this.config.streamPartId)
|
|
78
78
|
return res
|
|
79
79
|
}
|
|
@@ -95,21 +95,21 @@ export class HandshakeRpcLocal implements IHandshakeRpc {
|
|
|
95
95
|
if (request.interleaveSourceId !== undefined) {
|
|
96
96
|
exclude.push(getDhtAddressFromRaw(request.interleaveSourceId))
|
|
97
97
|
}
|
|
98
|
-
const
|
|
99
|
-
const
|
|
100
|
-
if (
|
|
101
|
-
const nodeId = getNodeIdFromPeerDescriptor(
|
|
102
|
-
const remote = this.config.createRpcRemote(
|
|
98
|
+
const last = this.config.neighbors.getLast(exclude)
|
|
99
|
+
const lastPeerDescriptor = last ? last.getPeerDescriptor() : undefined
|
|
100
|
+
if (last) {
|
|
101
|
+
const nodeId = getNodeIdFromPeerDescriptor(last.getPeerDescriptor())
|
|
102
|
+
const remote = this.config.createRpcRemote(last.getPeerDescriptor())
|
|
103
103
|
this.config.ongoingInterleaves.add(nodeId)
|
|
104
104
|
// Run this with then catch instead of setImmediate to avoid changes in state
|
|
105
105
|
// eslint-disable-next-line promise/catch-or-return
|
|
106
106
|
remote.interleaveRequest(requester).then((response) => {
|
|
107
|
-
// If response is accepted, remove the
|
|
107
|
+
// If response is accepted, remove the last node from the target neighbors
|
|
108
108
|
// and unlock the connection
|
|
109
|
-
// If response is not accepted, keep the
|
|
109
|
+
// If response is not accepted, keep the last node as a neighbor
|
|
110
110
|
if (response.accepted) {
|
|
111
|
-
this.config.
|
|
112
|
-
this.config.connectionLocker.unlockConnection(
|
|
111
|
+
this.config.neighbors.remove(getNodeIdFromPeerDescriptor(lastPeerDescriptor!))
|
|
112
|
+
this.config.connectionLocker.unlockConnection(lastPeerDescriptor!, this.config.streamPartId)
|
|
113
113
|
}
|
|
114
114
|
return
|
|
115
115
|
}).catch(() => {
|
|
@@ -118,12 +118,12 @@ export class HandshakeRpcLocal implements IHandshakeRpc {
|
|
|
118
118
|
this.config.ongoingInterleaves.delete(nodeId)
|
|
119
119
|
})
|
|
120
120
|
}
|
|
121
|
-
this.config.
|
|
121
|
+
this.config.neighbors.add(this.config.createDeliveryRpcRemote(requester))
|
|
122
122
|
this.config.connectionLocker.lockConnection(requester, this.config.streamPartId)
|
|
123
123
|
return {
|
|
124
124
|
requestId: request.requestId,
|
|
125
125
|
accepted: true,
|
|
126
|
-
interleaveTargetDescriptor:
|
|
126
|
+
interleaveTargetDescriptor: lastPeerDescriptor
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
129
|
|
|
@@ -132,9 +132,9 @@ export class HandshakeRpcLocal implements IHandshakeRpc {
|
|
|
132
132
|
const senderId = getNodeIdFromPeerDescriptor(senderPeerDescriptor)
|
|
133
133
|
try {
|
|
134
134
|
await this.config.handshakeWithInterleaving(message.interleaveTargetDescriptor!, senderId)
|
|
135
|
-
if (this.config.
|
|
135
|
+
if (this.config.neighbors.has(senderId)) {
|
|
136
136
|
this.config.connectionLocker.unlockConnection(senderPeerDescriptor, this.config.streamPartId)
|
|
137
|
-
this.config.
|
|
137
|
+
this.config.neighbors.remove(senderId)
|
|
138
138
|
}
|
|
139
139
|
return { accepted: true }
|
|
140
140
|
} catch (err) {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { ConnectionLocker, DhtAddress, PeerDescriptor, getNodeIdFromPeerDescriptor } from '@streamr/dht'
|
|
1
|
+
import { ConnectionLocker, DhtAddress, PeerDescriptor, ListeningRpcCommunicator, getNodeIdFromPeerDescriptor } from '@streamr/dht'
|
|
2
2
|
import { NodeList } from '../NodeList'
|
|
3
3
|
import { DeliveryRpcRemote } from '../DeliveryRpcRemote'
|
|
4
|
-
import { RpcCommunicator } from '@streamr/proto-rpc'
|
|
5
4
|
import {
|
|
6
5
|
DeliveryRpcClient, HandshakeRpcClient
|
|
7
6
|
} from '../../proto/packages/trackerless-network/protos/NetworkRpc.client'
|
|
@@ -21,10 +20,10 @@ interface HandshakerConfig {
|
|
|
21
20
|
localPeerDescriptor: PeerDescriptor
|
|
22
21
|
streamPartId: StreamPartID
|
|
23
22
|
connectionLocker: ConnectionLocker
|
|
24
|
-
|
|
23
|
+
neighbors: NodeList
|
|
25
24
|
nearbyNodeView: NodeList
|
|
26
25
|
randomNodeView: NodeList
|
|
27
|
-
rpcCommunicator:
|
|
26
|
+
rpcCommunicator: ListeningRpcCommunicator
|
|
28
27
|
maxNeighborCount: number
|
|
29
28
|
rpcRequestTimeout?: number
|
|
30
29
|
}
|
|
@@ -43,7 +42,7 @@ export class Handshaker {
|
|
|
43
42
|
this.config = config
|
|
44
43
|
this.rpcLocal = new HandshakeRpcLocal({
|
|
45
44
|
streamPartId: this.config.streamPartId,
|
|
46
|
-
|
|
45
|
+
neighbors: this.config.neighbors,
|
|
47
46
|
connectionLocker: this.config.connectionLocker,
|
|
48
47
|
ongoingHandshakes: this.ongoingHandshakes,
|
|
49
48
|
ongoingInterleaves: new Set(),
|
|
@@ -60,10 +59,10 @@ export class Handshaker {
|
|
|
60
59
|
|
|
61
60
|
async attemptHandshakesOnContacts(excludedIds: DhtAddress[]): Promise<DhtAddress[]> {
|
|
62
61
|
// TODO use config option or named constant? or why the value 2?
|
|
63
|
-
if (this.config.
|
|
62
|
+
if (this.config.neighbors.size() + this.ongoingHandshakes.size < this.config.maxNeighborCount - 2) {
|
|
64
63
|
logger.trace(`Attempting parallel handshakes with ${PARALLEL_HANDSHAKE_COUNT} targets`)
|
|
65
64
|
return this.selectParallelTargetsAndHandshake(excludedIds)
|
|
66
|
-
} else if (this.config.
|
|
65
|
+
} else if (this.config.neighbors.size() + this.ongoingHandshakes.size < this.config.maxNeighborCount) {
|
|
67
66
|
logger.trace(`Attempting handshake with new target`)
|
|
68
67
|
return this.selectNewTargetAndHandshake(excludedIds)
|
|
69
68
|
}
|
|
@@ -71,21 +70,21 @@ export class Handshaker {
|
|
|
71
70
|
}
|
|
72
71
|
|
|
73
72
|
private async selectParallelTargetsAndHandshake(excludedIds: DhtAddress[]): Promise<DhtAddress[]> {
|
|
74
|
-
const exclude = excludedIds.concat(this.config.
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
return this.doParallelHandshakes(
|
|
73
|
+
const exclude = excludedIds.concat(this.config.neighbors.getIds())
|
|
74
|
+
const neighbors = this.selectParallelTargets(exclude)
|
|
75
|
+
neighbors.forEach((contact) => this.ongoingHandshakes.add(getNodeIdFromPeerDescriptor(contact.getPeerDescriptor())))
|
|
76
|
+
return this.doParallelHandshakes(neighbors, exclude)
|
|
78
77
|
}
|
|
79
78
|
|
|
80
79
|
private selectParallelTargets(excludedIds: DhtAddress[]): HandshakeRpcRemote[] {
|
|
81
|
-
const
|
|
82
|
-
while (
|
|
80
|
+
const neighbors = this.config.nearbyNodeView.getFirstAndLast(excludedIds)
|
|
81
|
+
while (neighbors.length < PARALLEL_HANDSHAKE_COUNT && this.config.randomNodeView.size(excludedIds) > 0) {
|
|
83
82
|
const random = this.config.randomNodeView.getRandom(excludedIds)
|
|
84
83
|
if (random) {
|
|
85
|
-
|
|
84
|
+
neighbors.push(random)
|
|
86
85
|
}
|
|
87
86
|
}
|
|
88
|
-
return
|
|
87
|
+
return neighbors.map((neighbor) => this.createRpcRemote(neighbor.getPeerDescriptor()))
|
|
89
88
|
}
|
|
90
89
|
|
|
91
90
|
private async doParallelHandshakes(targets: HandshakeRpcRemote[], excludedIds: DhtAddress[]): Promise<DhtAddress[]> {
|
|
@@ -106,28 +105,28 @@ export class Handshaker {
|
|
|
106
105
|
}
|
|
107
106
|
|
|
108
107
|
private async selectNewTargetAndHandshake(excludedIds: DhtAddress[]): Promise<DhtAddress[]> {
|
|
109
|
-
const exclude = excludedIds.concat(this.config.
|
|
110
|
-
const
|
|
111
|
-
if (
|
|
112
|
-
const accepted = await this.handshakeWithTarget(this.createRpcRemote(
|
|
108
|
+
const exclude = excludedIds.concat(this.config.neighbors.getIds())
|
|
109
|
+
const neighbor = this.config.nearbyNodeView.getFirst(exclude) ?? this.config.randomNodeView.getRandom(exclude)
|
|
110
|
+
if (neighbor) {
|
|
111
|
+
const accepted = await this.handshakeWithTarget(this.createRpcRemote(neighbor.getPeerDescriptor()))
|
|
113
112
|
if (!accepted) {
|
|
114
|
-
excludedIds.push(getNodeIdFromPeerDescriptor(
|
|
113
|
+
excludedIds.push(getNodeIdFromPeerDescriptor(neighbor.getPeerDescriptor()))
|
|
115
114
|
}
|
|
116
115
|
}
|
|
117
116
|
return excludedIds
|
|
118
117
|
}
|
|
119
118
|
|
|
120
|
-
private async handshakeWithTarget(
|
|
121
|
-
const targetNodeId = getNodeIdFromPeerDescriptor(
|
|
119
|
+
private async handshakeWithTarget(neighbor: HandshakeRpcRemote, concurrentNodeId?: DhtAddress): Promise<boolean> {
|
|
120
|
+
const targetNodeId = getNodeIdFromPeerDescriptor(neighbor.getPeerDescriptor())
|
|
122
121
|
this.ongoingHandshakes.add(targetNodeId)
|
|
123
|
-
const result = await
|
|
122
|
+
const result = await neighbor.handshake(
|
|
124
123
|
this.config.streamPartId,
|
|
125
|
-
this.config.
|
|
124
|
+
this.config.neighbors.getIds(),
|
|
126
125
|
concurrentNodeId
|
|
127
126
|
)
|
|
128
127
|
if (result.accepted) {
|
|
129
|
-
this.config.
|
|
130
|
-
this.config.connectionLocker.lockConnection(
|
|
128
|
+
this.config.neighbors.add(this.createDeliveryRpcRemote(neighbor.getPeerDescriptor()))
|
|
129
|
+
this.config.connectionLocker.lockConnection(neighbor.getPeerDescriptor(), this.config.streamPartId)
|
|
131
130
|
}
|
|
132
131
|
if (result.interleaveTargetDescriptor) {
|
|
133
132
|
await this.handshakeWithInterleaving(result.interleaveTargetDescriptor, targetNodeId)
|
|
@@ -137,18 +136,18 @@ export class Handshaker {
|
|
|
137
136
|
}
|
|
138
137
|
|
|
139
138
|
private async handshakeWithInterleaving(target: PeerDescriptor, interleaveSourceId: DhtAddress): Promise<boolean> {
|
|
140
|
-
const
|
|
141
|
-
const targetNodeId = getNodeIdFromPeerDescriptor(
|
|
139
|
+
const neighbor = this.createRpcRemote(target)
|
|
140
|
+
const targetNodeId = getNodeIdFromPeerDescriptor(neighbor.getPeerDescriptor())
|
|
142
141
|
this.ongoingHandshakes.add(targetNodeId)
|
|
143
|
-
const result = await
|
|
142
|
+
const result = await neighbor.handshake(
|
|
144
143
|
this.config.streamPartId,
|
|
145
|
-
this.config.
|
|
144
|
+
this.config.neighbors.getIds(),
|
|
146
145
|
undefined,
|
|
147
146
|
interleaveSourceId
|
|
148
147
|
)
|
|
149
148
|
if (result.accepted) {
|
|
150
|
-
this.config.
|
|
151
|
-
this.config.connectionLocker.lockConnection(
|
|
149
|
+
this.config.neighbors.add(this.createDeliveryRpcRemote(neighbor.getPeerDescriptor()))
|
|
150
|
+
this.config.connectionLocker.lockConnection(neighbor.getPeerDescriptor(), this.config.streamPartId)
|
|
152
151
|
}
|
|
153
152
|
this.ongoingHandshakes.delete(targetNodeId)
|
|
154
153
|
return result.accepted
|
|
@@ -3,7 +3,7 @@ import { NodeList } from '../NodeList'
|
|
|
3
3
|
import { DhtAddress } from '@streamr/dht'
|
|
4
4
|
|
|
5
5
|
interface FindNeighborsSessionConfig {
|
|
6
|
-
|
|
6
|
+
neighbors: NodeList
|
|
7
7
|
nearbyNodeView: NodeList
|
|
8
8
|
doFindNeighbors: (excludedNodes: DhtAddress[]) => Promise<DhtAddress[]>
|
|
9
9
|
minCount: number
|
|
@@ -27,7 +27,7 @@ export class NeighborFinder {
|
|
|
27
27
|
return
|
|
28
28
|
}
|
|
29
29
|
const newExcludes = await this.config.doFindNeighbors(excluded)
|
|
30
|
-
if (this.config.
|
|
30
|
+
if (this.config.neighbors.size() < this.config.minCount && newExcludes.length < this.config.nearbyNodeView.size()) {
|
|
31
31
|
// TODO should we catch possible promise rejection?
|
|
32
32
|
setAbortableTimeout(() => this.findNeighbors(newExcludes), INTERVAL, this.abortController.signal)
|
|
33
33
|
} else {
|