@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.
Files changed (188) hide show
  1. package/dist/src/NetworkNode.d.ts +2 -1
  2. package/dist/src/NetworkNode.js +6 -2
  3. package/dist/src/NetworkNode.js.map +1 -1
  4. package/dist/src/NetworkStack.d.ts +6 -2
  5. package/dist/src/NetworkStack.js +21 -1
  6. package/dist/src/NetworkStack.js.map +1 -1
  7. package/dist/src/exports.d.ts +1 -0
  8. package/dist/src/exports.js +4 -1
  9. package/dist/src/exports.js.map +1 -1
  10. package/dist/src/logic/DeliveryRpcLocal.js +1 -0
  11. package/dist/src/logic/DeliveryRpcLocal.js.map +1 -1
  12. package/dist/src/logic/DuplicateMessageDetector.d.ts +3 -3
  13. package/dist/src/logic/DuplicateMessageDetector.js +10 -6
  14. package/dist/src/logic/DuplicateMessageDetector.js.map +1 -1
  15. package/dist/src/logic/EntryPointDiscovery.js +8 -5
  16. package/dist/src/logic/EntryPointDiscovery.js.map +1 -1
  17. package/dist/src/logic/Layer0Node.d.ts +2 -0
  18. package/dist/src/logic/Layer1Node.d.ts +4 -4
  19. package/dist/src/logic/NodeList.d.ts +6 -8
  20. package/dist/src/logic/NodeList.js +10 -12
  21. package/dist/src/logic/NodeList.js.map +1 -1
  22. package/dist/src/logic/RandomGraphNode.d.ts +5 -5
  23. package/dist/src/logic/RandomGraphNode.js +27 -22
  24. package/dist/src/logic/RandomGraphNode.js.map +1 -1
  25. package/dist/src/logic/StreamrNode.d.ts +3 -2
  26. package/dist/src/logic/StreamrNode.js +25 -6
  27. package/dist/src/logic/StreamrNode.js.map +1 -1
  28. package/dist/src/logic/createRandomGraphNode.d.ts +2 -2
  29. package/dist/src/logic/createRandomGraphNode.js +16 -15
  30. package/dist/src/logic/createRandomGraphNode.js.map +1 -1
  31. package/dist/src/logic/inspect/InspectSession.js +3 -2
  32. package/dist/src/logic/inspect/InspectSession.js.map +1 -1
  33. package/dist/src/logic/inspect/Inspector.d.ts +5 -3
  34. package/dist/src/logic/inspect/Inspector.js +15 -2
  35. package/dist/src/logic/inspect/Inspector.js.map +1 -1
  36. package/dist/src/logic/neighbor-discovery/HandshakeRpcLocal.d.ts +1 -1
  37. package/dist/src/logic/neighbor-discovery/HandshakeRpcLocal.js +18 -17
  38. package/dist/src/logic/neighbor-discovery/HandshakeRpcLocal.js.map +1 -1
  39. package/dist/src/logic/neighbor-discovery/HandshakeRpcRemote.js.map +1 -1
  40. package/dist/src/logic/neighbor-discovery/Handshaker.d.ts +3 -4
  41. package/dist/src/logic/neighbor-discovery/Handshaker.js +29 -27
  42. package/dist/src/logic/neighbor-discovery/Handshaker.js.map +1 -1
  43. package/dist/src/logic/neighbor-discovery/NeighborFinder.d.ts +1 -1
  44. package/dist/src/logic/neighbor-discovery/NeighborFinder.js +4 -2
  45. package/dist/src/logic/neighbor-discovery/NeighborFinder.js.map +1 -1
  46. package/dist/src/logic/neighbor-discovery/NeighborUpdateManager.d.ts +2 -1
  47. package/dist/src/logic/neighbor-discovery/NeighborUpdateManager.js +8 -4
  48. package/dist/src/logic/neighbor-discovery/NeighborUpdateManager.js.map +1 -1
  49. package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.d.ts +4 -1
  50. package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.js +31 -20
  51. package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.js.map +1 -1
  52. package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcRemote.js.map +1 -1
  53. package/dist/src/logic/node-info/NodeInfoClient.d.ts +9 -0
  54. package/dist/src/logic/node-info/NodeInfoClient.js +19 -0
  55. package/dist/src/logic/node-info/NodeInfoClient.js.map +1 -0
  56. package/dist/src/logic/node-info/NodeInfoRpcLocal.d.ts +12 -0
  57. package/dist/src/logic/node-info/NodeInfoRpcLocal.js +29 -0
  58. package/dist/src/logic/node-info/NodeInfoRpcLocal.js.map +1 -0
  59. package/dist/src/logic/node-info/NodeInfoRpcRemote.d.ts +6 -0
  60. package/dist/src/logic/node-info/NodeInfoRpcRemote.js +11 -0
  61. package/dist/src/logic/node-info/NodeInfoRpcRemote.js.map +1 -0
  62. package/dist/src/logic/propagation/FifoMapWithTTL.js +7 -3
  63. package/dist/src/logic/propagation/FifoMapWithTTL.js.map +1 -1
  64. package/dist/src/logic/propagation/Propagation.js +3 -0
  65. package/dist/src/logic/propagation/Propagation.js.map +1 -1
  66. package/dist/src/logic/propagation/PropagationTaskStore.js +1 -0
  67. package/dist/src/logic/propagation/PropagationTaskStore.js.map +1 -1
  68. package/dist/src/logic/protocol-integration/stream-message/GroupKeyRequestTranslator.js +1 -1
  69. package/dist/src/logic/protocol-integration/stream-message/GroupKeyRequestTranslator.js.map +1 -1
  70. package/dist/src/logic/protocol-integration/stream-message/GroupKeyResponseTranslator.js +1 -1
  71. package/dist/src/logic/protocol-integration/stream-message/GroupKeyResponseTranslator.js.map +1 -1
  72. package/dist/src/logic/protocol-integration/stream-message/StreamMessageTranslator.js +43 -15
  73. package/dist/src/logic/protocol-integration/stream-message/StreamMessageTranslator.js.map +1 -1
  74. package/dist/src/logic/protocol-integration/stream-message/oldStreamMessageBinaryUtils.d.ts +3 -0
  75. package/dist/src/logic/protocol-integration/stream-message/oldStreamMessageBinaryUtils.js +14 -0
  76. package/dist/src/logic/protocol-integration/stream-message/oldStreamMessageBinaryUtils.js.map +1 -0
  77. package/dist/src/logic/proxy/ProxyClient.d.ts +1 -1
  78. package/dist/src/logic/proxy/ProxyClient.js +18 -11
  79. package/dist/src/logic/proxy/ProxyClient.js.map +1 -1
  80. package/dist/src/logic/proxy/ProxyConnectionRpcLocal.js +2 -1
  81. package/dist/src/logic/proxy/ProxyConnectionRpcLocal.js.map +1 -1
  82. package/dist/src/logic/proxy/ProxyConnectionRpcRemote.js.map +1 -1
  83. package/dist/src/logic/temporary-connection/TemporaryConnectionRpcLocal.d.ts +5 -3
  84. package/dist/src/logic/temporary-connection/TemporaryConnectionRpcLocal.js +9 -2
  85. package/dist/src/logic/temporary-connection/TemporaryConnectionRpcLocal.js.map +1 -1
  86. package/dist/src/logic/temporary-connection/TemporaryConnectionRpcRemote.d.ts +1 -0
  87. package/dist/src/logic/temporary-connection/TemporaryConnectionRpcRemote.js +11 -0
  88. package/dist/src/logic/temporary-connection/TemporaryConnectionRpcRemote.js.map +1 -1
  89. package/dist/src/logic/utils.js.map +1 -1
  90. package/dist/src/proto/google/protobuf/any.js +8 -8
  91. package/dist/src/proto/google/protobuf/any.js.map +1 -1
  92. package/dist/src/proto/google/protobuf/empty.js +2 -4
  93. package/dist/src/proto/google/protobuf/empty.js.map +1 -1
  94. package/dist/src/proto/google/protobuf/timestamp.js +10 -10
  95. package/dist/src/proto/google/protobuf/timestamp.js.map +1 -1
  96. package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +4 -5
  97. package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +38 -29
  98. package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -1
  99. package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +26 -12
  100. package/dist/src/proto/packages/dht/protos/DhtRpc.js +12 -16
  101. package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
  102. package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +2 -3
  103. package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.js +1 -1
  104. package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.client.d.ts +36 -0
  105. package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.client.js +50 -17
  106. package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.client.js.map +1 -1
  107. package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.d.ts +118 -5
  108. package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.js +91 -8
  109. package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.js.map +1 -1
  110. package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.server.d.ts +16 -0
  111. package/dist/test/benchmark/first-message.js +7 -5
  112. package/dist/test/benchmark/first-message.js.map +1 -1
  113. package/dist/test/utils/utils.js +2 -1
  114. package/dist/test/utils/utils.js.map +1 -1
  115. package/jest.config.js +3 -38
  116. package/package.json +7 -7
  117. package/protos/NetworkRpc.proto +38 -5
  118. package/src/NetworkNode.ts +5 -1
  119. package/src/NetworkStack.ts +23 -2
  120. package/src/exports.ts +4 -0
  121. package/src/logic/DuplicateMessageDetector.ts +7 -7
  122. package/src/logic/EntryPointDiscovery.ts +3 -3
  123. package/src/logic/Layer0Node.ts +2 -0
  124. package/src/logic/Layer1Node.ts +4 -4
  125. package/src/logic/NodeList.ts +9 -15
  126. package/src/logic/RandomGraphNode.ts +27 -23
  127. package/src/logic/StreamrNode.ts +18 -4
  128. package/src/logic/createRandomGraphNode.ts +19 -18
  129. package/src/logic/inspect/Inspector.ts +18 -5
  130. package/src/logic/neighbor-discovery/HandshakeRpcLocal.ts +18 -18
  131. package/src/logic/neighbor-discovery/Handshaker.ts +31 -32
  132. package/src/logic/neighbor-discovery/NeighborFinder.ts +2 -2
  133. package/src/logic/neighbor-discovery/NeighborUpdateManager.ts +7 -5
  134. package/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.ts +39 -27
  135. package/src/logic/node-info/NodeInfoClient.ts +21 -0
  136. package/src/logic/node-info/NodeInfoRpcLocal.ts +35 -0
  137. package/src/logic/node-info/NodeInfoRpcRemote.ts +11 -0
  138. package/src/logic/protocol-integration/stream-message/GroupKeyRequestTranslator.ts +1 -1
  139. package/src/logic/protocol-integration/stream-message/GroupKeyResponseTranslator.ts +1 -1
  140. package/src/logic/protocol-integration/stream-message/StreamMessageTranslator.ts +56 -27
  141. package/src/logic/protocol-integration/stream-message/oldStreamMessageBinaryUtils.ts +11 -0
  142. package/src/logic/proxy/ProxyClient.ts +10 -10
  143. package/src/logic/temporary-connection/TemporaryConnectionRpcLocal.ts +15 -4
  144. package/src/logic/temporary-connection/TemporaryConnectionRpcRemote.ts +11 -0
  145. package/src/proto/google/protobuf/any.ts +4 -4
  146. package/src/proto/google/protobuf/empty.ts +2 -4
  147. package/src/proto/google/protobuf/timestamp.ts +4 -4
  148. package/src/proto/packages/dht/protos/DhtRpc.client.ts +6 -7
  149. package/src/proto/packages/dht/protos/DhtRpc.server.ts +3 -4
  150. package/src/proto/packages/dht/protos/DhtRpc.ts +37 -20
  151. package/src/proto/packages/proto-rpc/protos/ProtoRpc.ts +1 -1
  152. package/src/proto/packages/trackerless-network/protos/NetworkRpc.client.ts +42 -1
  153. package/src/proto/packages/trackerless-network/protos/NetworkRpc.server.ts +17 -1
  154. package/src/proto/packages/trackerless-network/protos/NetworkRpc.ts +155 -12
  155. package/test/benchmark/first-message.ts +28 -8
  156. package/test/end-to-end/inspect.test.ts +13 -1
  157. package/test/end-to-end/proxy-and-full-node.test.ts +14 -1
  158. package/test/end-to-end/proxy-connections.test.ts +14 -2
  159. package/test/end-to-end/proxy-key-exchange.test.ts +15 -8
  160. package/test/end-to-end/random-graph-with-real-connections.test.ts +21 -21
  161. package/test/end-to-end/webrtc-full-node-network.test.ts +3 -3
  162. package/test/end-to-end/websocket-full-node-network.test.ts +3 -3
  163. package/test/integration/Handshakes.test.ts +8 -8
  164. package/test/integration/NetworkNode.test.ts +19 -1
  165. package/test/integration/NetworkRpc.test.ts +3 -2
  166. package/test/integration/NodeInfoRpc.test.ts +103 -0
  167. package/test/integration/Propagation.test.ts +2 -2
  168. package/test/integration/RandomGraphNode-Layer1Node-Latencies.test.ts +20 -21
  169. package/test/integration/RandomGraphNode-Layer1Node.test.ts +22 -19
  170. package/test/integration/stream-without-default-entrypoints.test.ts +17 -11
  171. package/test/unit/HandshakeRpcLocal.test.ts +15 -15
  172. package/test/unit/Handshaker.test.ts +3 -3
  173. package/test/unit/NeighborFinder.test.ts +5 -5
  174. package/test/unit/NeighborUpdateRpcLocal.test.ts +125 -0
  175. package/test/unit/NodeList.test.ts +56 -57
  176. package/test/unit/Propagation.test.ts +4 -2
  177. package/test/unit/RandomGraphNode.test.ts +7 -8
  178. package/test/unit/StreamMessageTranslator.test.ts +7 -4
  179. package/test/unit/StreamrNode.test.ts +2 -0
  180. package/test/unit/TemporaryConnectionRpcLocal.test.ts +32 -0
  181. package/test/unit/oldStreamMessageBinaryUtils.test.ts +39 -0
  182. package/test/utils/mock/MockLayer0Node.ts +6 -1
  183. package/test/utils/mock/MockLayer1Node.ts +2 -2
  184. package/test/utils/mock/Transport.ts +1 -1
  185. package/test/utils/utils.ts +3 -1
  186. package/tsconfig.jest.json +3 -3
  187. package/tsconfig.node.json +0 -1
  188. 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
- targetNeighborConnected: (nodeId: DhtAddress) => void
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
- targetNeighbors: NodeList
53
+ neighbors: NodeList
53
54
  handshaker: Handshaker
54
55
  neighborFinder: NeighborFinder
55
56
  neighborUpdateManager: NeighborUpdateManager
56
57
  propagation: Propagation
57
58
  rpcCommunicator: ListeningRpcCommunicator
58
- numOfTargetNeighbors: number
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.targetNeighbors.get(sourceId)
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(contact.getPeerDescriptor())
98
- this.config.targetNeighbors.remove(contact.getPeerDescriptor())
99
- this.config.nearbyNodeView.remove(contact.getPeerDescriptor())
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.targetNeighbors,
147
+ this.config.neighbors,
147
148
  'nodeAdded',
148
149
  (id, _remote) => {
149
150
  this.config.propagation.onNeighborJoined(id)
150
- this.emit('targetNeighborConnected', id)
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.targetNeighbors.size() < this.config.numOfTargetNeighbors) {
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.getAllNeighborPeerDescriptors()) {
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.targetNeighbors.size() < this.config.numOfTargetNeighbors) {
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
- if (this.config.targetNeighbors.hasNode(peerDescriptor)) {
261
- this.config.targetNeighbors.remove(peerDescriptor)
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([getNodeIdFromPeerDescriptor(peerDescriptor)])
264
- this.config.temporaryConnectionRpcLocal.removeNode(peerDescriptor)
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.getAllNeighborPeerDescriptors().forEach((peer: PeerDescriptor) => {
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.targetNeighbors.getAll().map(
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.targetNeighbors.stop()
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.targetNeighbors.getIds()
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
- getNumberOfOutgoingHandshakes(): number {
335
+ getOutgoingHandshakeCount(): number {
332
336
  return this.config.handshaker.getOngoingHandshakes().size
333
337
  }
334
338
 
335
- getTargetNeighborIds(): DhtAddress[] {
339
+ getNeighbors(): PeerDescriptor[] {
336
340
  if (!this.started && this.isStopped()) {
337
341
  return []
338
342
  }
339
- return this.config.targetNeighbors.getIds()
343
+ return this.config.neighbors.getAll().map((n) => n.getPeerDescriptor())
340
344
  }
341
345
 
342
346
  getNearbyNodeView(): NodeList {
@@ -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
- streamPartitionNumOfNeighbors?: number
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
- numOfTargetNeighbors: this.config.streamPartitionNumOfNeighbors,
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.getTargetNeighborIds()
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' | 'targetNeighbors' | 'propagation'
17
- | 'handshaker' | 'neighborFinder' | 'neighborUpdateManager' | 'numOfTargetNeighbors'
16
+ 'nearbyNodeView' | 'randomNodeView' | 'neighbors' | 'propagation'
17
+ | 'handshaker' | 'neighborFinder' | 'neighborUpdateManager' | 'neighborCount'
18
18
  | 'rpcCommunicator' | 'nodeViewSize'
19
19
  | 'inspector' | 'temporaryConnectionRpcLocal'> & {
20
- maxNumberOfContacts?: number
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 numOfTargetNeighbors = config.numOfTargetNeighbors ?? 4
33
- const maxNumberOfContacts = config.maxNumberOfContacts ?? 20
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, numOfTargetNeighbors + 1)
38
- const randomNodeView = config.randomNodeView ?? new NodeList(ownNodeId, maxNumberOfContacts)
39
- const targetNeighbors = config.targetNeighbors ?? new NodeList(ownNodeId, maxNumberOfContacts)
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 = targetNeighbors.get(neighborId) ?? temporaryConnectionRpcLocal.getNodes().get(neighborId)
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
- targetNeighbors,
72
- maxNeighborCount: numOfTargetNeighbors,
71
+ neighbors,
72
+ maxNeighborCount: neighborCount,
73
73
  rpcRequestTimeout: config.rpcRequestTimeout
74
74
  })
75
75
  const neighborFinder = config.neighborFinder ?? new NeighborFinder({
76
- targetNeighbors,
76
+ neighbors,
77
77
  nearbyNodeView,
78
78
  doFindNeighbors: (excludedIds) => handshaker.attemptHandshakesOnContacts(excludedIds),
79
- minCount: numOfTargetNeighbors
79
+ minCount: neighborCount
80
80
  })
81
81
  const neighborUpdateManager = config.neighborUpdateManager ?? new NeighborUpdateManager({
82
- targetNeighbors,
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
- targetNeighbors,
101
+ neighbors,
101
102
  rpcCommunicator,
102
103
  handshaker,
103
104
  neighborFinder,
104
105
  neighborUpdateManager,
105
106
  propagation,
106
- numOfTargetNeighbors,
107
- nodeViewSize: maxNumberOfContacts,
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: 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: 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
- targetNeighbors: NodeList
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.targetNeighbors.hasNode(senderDescriptor)
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.targetNeighbors.size() + this.config.ongoingHandshakes.size < this.config.maxNeighborCount) {
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.targetNeighbors.size(getInterleaveSourceIds()) - this.config.ongoingInterleaves.size >= 2) {
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.targetNeighbors.add(this.config.createDeliveryRpcRemote(requester))
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 furthest = this.config.targetNeighbors.getFurthest(exclude)
99
- const furthestPeerDescriptor = furthest ? furthest.getPeerDescriptor() : undefined
100
- if (furthest) {
101
- const nodeId = getNodeIdFromPeerDescriptor(furthest.getPeerDescriptor())
102
- const remote = this.config.createRpcRemote(furthest.getPeerDescriptor())
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 furthest node from the target neighbors
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 furthest node as a neighbor
109
+ // If response is not accepted, keep the last node as a neighbor
110
110
  if (response.accepted) {
111
- this.config.targetNeighbors.remove(furthest.getPeerDescriptor())
112
- this.config.connectionLocker.unlockConnection(furthestPeerDescriptor!, this.config.streamPartId)
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.targetNeighbors.add(this.config.createDeliveryRpcRemote(requester))
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: furthestPeerDescriptor
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.targetNeighbors.hasNodeById(senderId)) {
135
+ if (this.config.neighbors.has(senderId)) {
136
136
  this.config.connectionLocker.unlockConnection(senderPeerDescriptor, this.config.streamPartId)
137
- this.config.targetNeighbors.remove(senderPeerDescriptor)
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
- targetNeighbors: NodeList
23
+ neighbors: NodeList
25
24
  nearbyNodeView: NodeList
26
25
  randomNodeView: NodeList
27
- rpcCommunicator: 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
- targetNeighbors: this.config.targetNeighbors,
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.targetNeighbors.size() + this.ongoingHandshakes.size < this.config.maxNeighborCount - 2) {
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.targetNeighbors.size() + this.ongoingHandshakes.size < this.config.maxNeighborCount) {
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.targetNeighbors.getIds())
75
- const targetNeighbors = this.selectParallelTargets(exclude)
76
- targetNeighbors.forEach((contact) => this.ongoingHandshakes.add(getNodeIdFromPeerDescriptor(contact.getPeerDescriptor())))
77
- return this.doParallelHandshakes(targetNeighbors, exclude)
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 targetNeighbors = this.config.nearbyNodeView.getClosestAndFurthest(excludedIds)
82
- while (targetNeighbors.length < PARALLEL_HANDSHAKE_COUNT && this.config.randomNodeView.size(excludedIds) > 0) {
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
- targetNeighbors.push(random)
84
+ neighbors.push(random)
86
85
  }
87
86
  }
88
- return targetNeighbors.map((neighbor) => this.createRpcRemote(neighbor.getPeerDescriptor()))
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.targetNeighbors.getIds())
110
- const targetNeighbor = this.config.nearbyNodeView.getClosest(exclude) ?? this.config.randomNodeView.getRandom(exclude)
111
- if (targetNeighbor) {
112
- const accepted = await this.handshakeWithTarget(this.createRpcRemote(targetNeighbor.getPeerDescriptor()))
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(targetNeighbor.getPeerDescriptor()))
113
+ excludedIds.push(getNodeIdFromPeerDescriptor(neighbor.getPeerDescriptor()))
115
114
  }
116
115
  }
117
116
  return excludedIds
118
117
  }
119
118
 
120
- private async handshakeWithTarget(targetNeighbor: HandshakeRpcRemote, concurrentNodeId?: DhtAddress): Promise<boolean> {
121
- const targetNodeId = getNodeIdFromPeerDescriptor(targetNeighbor.getPeerDescriptor())
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 targetNeighbor.handshake(
122
+ const result = await neighbor.handshake(
124
123
  this.config.streamPartId,
125
- this.config.targetNeighbors.getIds(),
124
+ this.config.neighbors.getIds(),
126
125
  concurrentNodeId
127
126
  )
128
127
  if (result.accepted) {
129
- this.config.targetNeighbors.add(this.createDeliveryRpcRemote(targetNeighbor.getPeerDescriptor()))
130
- this.config.connectionLocker.lockConnection(targetNeighbor.getPeerDescriptor(), this.config.streamPartId)
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 targetNeighbor = this.createRpcRemote(target)
141
- const targetNodeId = getNodeIdFromPeerDescriptor(targetNeighbor.getPeerDescriptor())
139
+ const neighbor = this.createRpcRemote(target)
140
+ const targetNodeId = getNodeIdFromPeerDescriptor(neighbor.getPeerDescriptor())
142
141
  this.ongoingHandshakes.add(targetNodeId)
143
- const result = await targetNeighbor.handshake(
142
+ const result = await neighbor.handshake(
144
143
  this.config.streamPartId,
145
- this.config.targetNeighbors.getIds(),
144
+ this.config.neighbors.getIds(),
146
145
  undefined,
147
146
  interleaveSourceId
148
147
  )
149
148
  if (result.accepted) {
150
- this.config.targetNeighbors.add(this.createDeliveryRpcRemote(targetNeighbor.getPeerDescriptor()))
151
- this.config.connectionLocker.lockConnection(targetNeighbor.getPeerDescriptor(), this.config.streamPartId)
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
- targetNeighbors: NodeList
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.targetNeighbors.size() < this.config.minCount && newExcludes.length < this.config.nearbyNodeView.size()) {
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 {