@streamr/trackerless-network 100.2.5-beta.1 → 101.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. package/dist/package.json +6 -6
  2. package/dist/src/NetworkNode.js +1 -1
  3. package/dist/src/NetworkNode.js.map +1 -1
  4. package/dist/src/NetworkStack.d.ts +5 -5
  5. package/dist/src/NetworkStack.js +21 -21
  6. package/dist/src/NetworkStack.js.map +1 -1
  7. package/dist/src/exports.d.ts +2 -2
  8. package/dist/src/exports.js +2 -2
  9. package/dist/src/exports.js.map +1 -1
  10. package/dist/src/logic/ContentDeliveryLayerNode.d.ts +5 -5
  11. package/dist/src/logic/ContentDeliveryLayerNode.js +85 -85
  12. package/dist/src/logic/ContentDeliveryLayerNode.js.map +1 -1
  13. package/dist/src/logic/ContentDeliveryManager.d.ts +11 -12
  14. package/dist/src/logic/ContentDeliveryManager.js +65 -61
  15. package/dist/src/logic/ContentDeliveryManager.js.map +1 -1
  16. package/dist/src/logic/ContentDeliveryRpcLocal.d.ts +5 -5
  17. package/dist/src/logic/ContentDeliveryRpcLocal.js +9 -9
  18. package/dist/src/logic/ContentDeliveryRpcLocal.js.map +1 -1
  19. package/dist/src/logic/{Layer0Node.d.ts → ControlLayerNode.d.ts} +1 -1
  20. package/dist/src/logic/{Layer0Node.js → ControlLayerNode.js} +1 -1
  21. package/dist/src/logic/ControlLayerNode.js.map +1 -0
  22. package/dist/src/logic/{Layer1Node.d.ts → DiscoveryLayerNode.d.ts} +8 -8
  23. package/dist/src/logic/{Layer1Node.js → DiscoveryLayerNode.js} +1 -1
  24. package/dist/src/logic/DiscoveryLayerNode.js.map +1 -0
  25. package/dist/src/logic/PeerDescriptorStoreManager.d.ts +28 -0
  26. package/dist/src/logic/PeerDescriptorStoreManager.js +79 -0
  27. package/dist/src/logic/PeerDescriptorStoreManager.js.map +1 -0
  28. package/dist/src/logic/StreamPartNetworkSplitAvoidance.d.ts +5 -5
  29. package/dist/src/logic/StreamPartNetworkSplitAvoidance.js +8 -8
  30. package/dist/src/logic/StreamPartNetworkSplitAvoidance.js.map +1 -1
  31. package/dist/src/logic/StreamPartReconnect.d.ts +5 -5
  32. package/dist/src/logic/StreamPartReconnect.js +10 -10
  33. package/dist/src/logic/StreamPartReconnect.js.map +1 -1
  34. package/dist/src/logic/createContentDeliveryLayerNode.d.ts +3 -3
  35. package/dist/src/logic/createContentDeliveryLayerNode.js +34 -34
  36. package/dist/src/logic/createContentDeliveryLayerNode.js.map +1 -1
  37. package/dist/src/logic/inspect/InspectSession.d.ts +3 -3
  38. package/dist/src/logic/inspect/InspectSession.js +5 -5
  39. package/dist/src/logic/inspect/InspectSession.js.map +1 -1
  40. package/dist/src/logic/inspect/Inspector.d.ts +2 -2
  41. package/dist/src/logic/inspect/Inspector.js +8 -8
  42. package/dist/src/logic/inspect/Inspector.js.map +1 -1
  43. package/dist/src/logic/neighbor-discovery/HandshakeRpcLocal.d.ts +4 -4
  44. package/dist/src/logic/neighbor-discovery/HandshakeRpcLocal.js +24 -24
  45. package/dist/src/logic/neighbor-discovery/HandshakeRpcLocal.js.map +1 -1
  46. package/dist/src/logic/neighbor-discovery/HandshakeRpcRemote.d.ts +1 -1
  47. package/dist/src/logic/neighbor-discovery/HandshakeRpcRemote.js +4 -4
  48. package/dist/src/logic/neighbor-discovery/HandshakeRpcRemote.js.map +1 -1
  49. package/dist/src/logic/neighbor-discovery/Handshaker.d.ts +3 -3
  50. package/dist/src/logic/neighbor-discovery/Handshaker.js +37 -37
  51. package/dist/src/logic/neighbor-discovery/Handshaker.js.map +1 -1
  52. package/dist/src/logic/neighbor-discovery/NeighborFinder.d.ts +3 -3
  53. package/dist/src/logic/neighbor-discovery/NeighborFinder.js +9 -9
  54. package/dist/src/logic/neighbor-discovery/NeighborFinder.js.map +1 -1
  55. package/dist/src/logic/neighbor-discovery/NeighborUpdateManager.d.ts +3 -3
  56. package/dist/src/logic/neighbor-discovery/NeighborUpdateManager.js +12 -12
  57. package/dist/src/logic/neighbor-discovery/NeighborUpdateManager.js.map +1 -1
  58. package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.d.ts +3 -3
  59. package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.js +14 -14
  60. package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.js.map +1 -1
  61. package/dist/src/logic/proxy/ProxyClient.d.ts +3 -3
  62. package/dist/src/logic/proxy/ProxyClient.js +25 -25
  63. package/dist/src/logic/proxy/ProxyClient.js.map +1 -1
  64. package/dist/src/logic/proxy/ProxyConnectionRpcLocal.d.ts +3 -3
  65. package/dist/src/logic/proxy/ProxyConnectionRpcLocal.js +10 -10
  66. package/dist/src/logic/proxy/ProxyConnectionRpcLocal.js.map +1 -1
  67. package/dist/src/logic/temporary-connection/TemporaryConnectionRpcLocal.d.ts +3 -3
  68. package/dist/src/logic/temporary-connection/TemporaryConnectionRpcLocal.js +11 -11
  69. package/dist/src/logic/temporary-connection/TemporaryConnectionRpcLocal.js.map +1 -1
  70. package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +4 -4
  71. package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +8 -8
  72. package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -1
  73. package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +11 -3
  74. package/dist/src/proto/packages/dht/protos/DhtRpc.js +7 -5
  75. package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
  76. package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +2 -2
  77. package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.js +1 -1
  78. package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.client.js +1 -1
  79. package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.d.ts +6 -23
  80. package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.js +5 -23
  81. package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.js.map +1 -1
  82. package/dist/test/benchmark/first-message.js +7 -7
  83. package/dist/test/benchmark/first-message.js.map +1 -1
  84. package/dist/test/utils/utils.d.ts +2 -2
  85. package/dist/test/utils/utils.js +3 -3
  86. package/dist/test/utils/utils.js.map +1 -1
  87. package/package.json +6 -6
  88. package/protos/NetworkRpc.proto +3 -9
  89. package/src/NetworkNode.ts +1 -1
  90. package/src/NetworkStack.ts +24 -24
  91. package/src/exports.ts +2 -2
  92. package/src/logic/ContentDeliveryLayerNode.ts +112 -112
  93. package/src/logic/ContentDeliveryManager.ts +71 -67
  94. package/src/logic/ContentDeliveryRpcLocal.ts +12 -12
  95. package/src/logic/{Layer0Node.ts → ControlLayerNode.ts} +1 -1
  96. package/src/logic/{Layer1Node.ts → DiscoveryLayerNode.ts} +8 -8
  97. package/src/logic/PeerDescriptorStoreManager.ts +97 -0
  98. package/src/logic/StreamPartNetworkSplitAvoidance.ts +11 -11
  99. package/src/logic/StreamPartReconnect.ts +12 -12
  100. package/src/logic/createContentDeliveryLayerNode.ts +38 -38
  101. package/src/logic/inspect/InspectSession.ts +6 -6
  102. package/src/logic/inspect/Inspector.ts +9 -9
  103. package/src/logic/neighbor-discovery/HandshakeRpcLocal.ts +26 -26
  104. package/src/logic/neighbor-discovery/HandshakeRpcRemote.ts +6 -6
  105. package/src/logic/neighbor-discovery/Handshaker.ts +45 -45
  106. package/src/logic/neighbor-discovery/NeighborFinder.ts +10 -10
  107. package/src/logic/neighbor-discovery/NeighborUpdateManager.ts +14 -14
  108. package/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.ts +17 -17
  109. package/src/logic/proxy/ProxyClient.ts +26 -26
  110. package/src/logic/proxy/ProxyConnectionRpcLocal.ts +12 -12
  111. package/src/logic/temporary-connection/TemporaryConnectionRpcLocal.ts +13 -13
  112. package/src/proto/google/protobuf/any.ts +1 -1
  113. package/src/proto/google/protobuf/empty.ts +1 -1
  114. package/src/proto/google/protobuf/timestamp.ts +1 -1
  115. package/src/proto/packages/dht/protos/DhtRpc.client.ts +9 -9
  116. package/src/proto/packages/dht/protos/DhtRpc.server.ts +3 -3
  117. package/src/proto/packages/dht/protos/DhtRpc.ts +15 -5
  118. package/src/proto/packages/proto-rpc/protos/ProtoRpc.ts +1 -1
  119. package/src/proto/packages/trackerless-network/protos/NetworkRpc.client.ts +1 -1
  120. package/src/proto/packages/trackerless-network/protos/NetworkRpc.server.ts +1 -1
  121. package/src/proto/packages/trackerless-network/protos/NetworkRpc.ts +10 -27
  122. package/test/benchmark/StreamPartIdDataKeyDistribution.test.ts +1 -1
  123. package/test/benchmark/first-message.ts +9 -9
  124. package/test/end-to-end/content-delivery-layer-node-with-real-connections.test.ts +12 -12
  125. package/test/end-to-end/proxy-and-full-node.test.ts +4 -4
  126. package/test/integration/ContentDeliveryLayerNode-Layer1Node-Latencies.test.ts +19 -19
  127. package/test/integration/ContentDeliveryLayerNode-Layer1Node.test.ts +19 -19
  128. package/test/integration/ContentDeliveryManager.test.ts +11 -11
  129. package/test/integration/Inspect.test.ts +1 -1
  130. package/test/integration/Propagation.test.ts +6 -6
  131. package/test/integration/joining-streams-on-offline-peers.test.ts +3 -3
  132. package/test/integration/stream-without-default-entrypoints.test.ts +2 -2
  133. package/test/integration/streamEntryPointReplacing.test.ts +2 -2
  134. package/test/unit/ContentDeliveryLayerNode.test.ts +11 -11
  135. package/test/unit/ContentDeliveryManager.test.ts +2 -2
  136. package/test/unit/{EntrypointDiscovery.test.ts → PeerDescriptorStoreManager.test.ts} +28 -29
  137. package/test/unit/StreamPartIDDataKey.test.ts +1 -1
  138. package/test/unit/StreamPartNetworkSplitAvoidance.test.ts +8 -8
  139. package/test/unit/StreamPartReconnect.test.ts +9 -9
  140. package/test/utils/fake/FakePeerDescriptorStoreManager.ts +29 -0
  141. package/test/utils/mock/{MockLayer0Node.ts → MockControlLayerNode.ts} +2 -2
  142. package/test/utils/mock/{MockLayer1Node.ts → MockDiscoveryLayerNode.ts} +2 -2
  143. package/test/utils/utils.ts +5 -5
  144. package/dist/src/logic/EntryPointDiscovery.d.ts +0 -27
  145. package/dist/src/logic/EntryPointDiscovery.js +0 -80
  146. package/dist/src/logic/EntryPointDiscovery.js.map +0 -1
  147. package/dist/src/logic/Layer0Node.js.map +0 -1
  148. package/dist/src/logic/Layer1Node.js.map +0 -1
  149. package/src/logic/EntryPointDiscovery.ts +0 -100
  150. package/test/utils/fake/FakeEntryPointDiscovery.ts +0 -29
@@ -11,15 +11,15 @@ import { StreamID, StreamPartID, toStreamPartID } from '@streamr/protocol'
11
11
  import { Logger, MetricsContext, waitForCondition } from '@streamr/utils'
12
12
  import { pull } from 'lodash'
13
13
  import { version as applicationVersion } from '../package.json'
14
- import { ContentDeliveryManager, ContentDeliveryManagerConfig } from './logic/ContentDeliveryManager'
15
- import { Layer0Node } from './logic/Layer0Node'
14
+ import { ContentDeliveryManager, ContentDeliveryManagerOptions } from './logic/ContentDeliveryManager'
15
+ import { ControlLayerNode } from './logic/ControlLayerNode'
16
16
  import { NodeInfoClient } from './logic/node-info/NodeInfoClient'
17
17
  import { NODE_INFO_RPC_SERVICE_ID, NodeInfoRpcLocal } from './logic/node-info/NodeInfoRpcLocal'
18
18
  import { NodeInfoResponse, ProxyDirection, StreamMessage } from './proto/packages/trackerless-network/protos/NetworkRpc'
19
19
 
20
20
  export interface NetworkOptions {
21
21
  layer0?: DhtNodeOptions
22
- networkNode?: ContentDeliveryManagerConfig
22
+ networkNode?: ContentDeliveryManagerOptions
23
23
  metricsContext?: MetricsContext
24
24
  }
25
25
 
@@ -54,7 +54,7 @@ export type NodeInfo = Required<NodeInfoResponse>
54
54
 
55
55
  export class NetworkStack {
56
56
 
57
- private layer0Node?: Layer0Node
57
+ private controlLayerNode?: ControlLayerNode
58
58
  private contentDeliveryManager?: ContentDeliveryManager
59
59
  private stopped = false
60
60
  private readonly metricsContext: MetricsContext
@@ -65,7 +65,7 @@ export class NetworkStack {
65
65
  constructor(options: NetworkOptions) {
66
66
  this.options = options
67
67
  this.metricsContext = options.metricsContext ?? new MetricsContext()
68
- this.layer0Node = new DhtNode({
68
+ this.controlLayerNode = new DhtNode({
69
69
  ...options.layer0,
70
70
  metricsContext: this.metricsContext
71
71
  })
@@ -106,24 +106,24 @@ export class NetworkStack {
106
106
 
107
107
  async start(doJoin = true): Promise<void> {
108
108
  logger.info('Starting a Streamr Network Node')
109
- await this.layer0Node!.start()
110
- logger.info(`Node id is ${getNodeIdFromPeerDescriptor(this.layer0Node!.getLocalPeerDescriptor())}`)
111
- const connectionManager = this.layer0Node!.getTransport() as ConnectionManager
109
+ await this.controlLayerNode!.start()
110
+ logger.info(`Node id is ${getNodeIdFromPeerDescriptor(this.controlLayerNode!.getLocalPeerDescriptor())}`)
111
+ const connectionManager = this.controlLayerNode!.getTransport() as ConnectionManager
112
112
  if ((this.options.layer0?.entryPoints !== undefined) && (this.options.layer0.entryPoints.some((entryPoint) =>
113
- areEqualPeerDescriptors(entryPoint, this.layer0Node!.getLocalPeerDescriptor())
113
+ areEqualPeerDescriptors(entryPoint, this.controlLayerNode!.getLocalPeerDescriptor())
114
114
  ))) {
115
- await this.layer0Node?.joinDht(this.options.layer0.entryPoints)
115
+ await this.controlLayerNode?.joinDht(this.options.layer0.entryPoints)
116
116
  } else if (doJoin) {
117
117
  // in practice there aren't be existing connections and therefore this always connects
118
118
  await this.ensureConnectedToControlLayer()
119
119
  }
120
120
  // TODO: remove undefined checks here. Assume that start is approproately awaited before stop is called.
121
- await this.contentDeliveryManager?.start(this.layer0Node!, connectionManager, connectionManager)
121
+ await this.contentDeliveryManager?.start(this.controlLayerNode!, connectionManager, connectionManager)
122
122
  if (this.contentDeliveryManager) {
123
123
  const infoRpcCommunicator = new ListeningRpcCommunicator(NODE_INFO_RPC_SERVICE_ID, this.getConnectionManager())
124
124
  this.nodeInfoRpcLocal = new NodeInfoRpcLocal(this, infoRpcCommunicator)
125
125
  this.nodeInfoClient = new NodeInfoClient(
126
- this.layer0Node!.getLocalPeerDescriptor(),
126
+ this.controlLayerNode!.getLocalPeerDescriptor(),
127
127
  infoRpcCommunicator
128
128
  )
129
129
  }
@@ -131,16 +131,16 @@ export class NetworkStack {
131
131
 
132
132
  private async ensureConnectedToControlLayer(): Promise<void> {
133
133
  // TODO we could wrap joinDht with pOnce and call it here (no else-if needed in that case)
134
- if (!this.layer0Node!.hasJoined()) {
134
+ if (!this.controlLayerNode!.hasJoined()) {
135
135
  setImmediate(async () => {
136
136
  if (this.options.layer0?.entryPoints !== undefined) {
137
137
  // TODO should catch possible rejection?
138
138
  // the question mark is there to avoid problems when stop() is called before start()
139
139
  // -> TODO change to exlamation mark if we don't support that (and remove NetworkStackStoppedDuringStart.test)
140
- await this.layer0Node?.joinDht(this.options.layer0.entryPoints)
140
+ await this.controlLayerNode?.joinDht(this.options.layer0.entryPoints)
141
141
  }
142
142
  })
143
- await this.layer0Node!.waitForNetworkConnectivity()
143
+ await this.controlLayerNode!.waitForNetworkConnectivity()
144
144
  }
145
145
  }
146
146
 
@@ -148,8 +148,8 @@ export class NetworkStack {
148
148
  return this.contentDeliveryManager!
149
149
  }
150
150
 
151
- getLayer0Node(): Layer0Node {
152
- return this.layer0Node!
151
+ getControlLayerNode(): ControlLayerNode {
152
+ return this.controlLayerNode!
153
153
  }
154
154
 
155
155
  getMetricsContext(): MetricsContext {
@@ -157,7 +157,7 @@ export class NetworkStack {
157
157
  }
158
158
 
159
159
  async fetchNodeInfo(node: PeerDescriptor): Promise<NodeInfo> {
160
- if (!areEqualPeerDescriptors(node, this.getLayer0Node().getLocalPeerDescriptor())) {
160
+ if (!areEqualPeerDescriptors(node, this.getControlLayerNode().getLocalPeerDescriptor())) {
161
161
  return this.nodeInfoClient!.getInfo(node)
162
162
  } else {
163
163
  return this.createNodeInfo()
@@ -166,10 +166,10 @@ export class NetworkStack {
166
166
 
167
167
  createNodeInfo(): NodeInfo {
168
168
  return {
169
- peerDescriptor: this.getLayer0Node().getLocalPeerDescriptor(),
169
+ peerDescriptor: this.getControlLayerNode().getLocalPeerDescriptor(),
170
170
  controlLayer: {
171
- connections: this.getLayer0Node().getConnectionsView().getConnections(),
172
- neighbors: this.getLayer0Node().getNeighbors()
171
+ connections: this.getControlLayerNode().getConnectionsView().getConnections(),
172
+ neighbors: this.getControlLayerNode().getNeighbors()
173
173
  },
174
174
  streamPartitions: this.getContentDeliveryManager().getNodeInfo(),
175
175
  version: applicationVersion
@@ -181,7 +181,7 @@ export class NetworkStack {
181
181
  }
182
182
 
183
183
  private getConnectionManager(): ConnectionManager {
184
- return this.layer0Node!.getTransport() as ConnectionManager
184
+ return this.controlLayerNode!.getTransport() as ConnectionManager
185
185
  }
186
186
 
187
187
  async stop(): Promise<void> {
@@ -189,9 +189,9 @@ export class NetworkStack {
189
189
  this.stopped = true
190
190
  pull(instances, this)
191
191
  await this.contentDeliveryManager!.destroy()
192
- await this.layer0Node!.stop()
192
+ await this.controlLayerNode!.stop()
193
193
  this.contentDeliveryManager = undefined
194
- this.layer0Node = undefined
194
+ this.controlLayerNode = undefined
195
195
  }
196
196
  }
197
197
 
package/src/exports.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  export { NetworkStack, NetworkOptions, NodeInfo } from './NetworkStack'
2
2
  export { NetworkNode, createNetworkNode } from './NetworkNode'
3
- export { ContentDeliveryManagerConfig } from './logic/ContentDeliveryManager'
3
+ export { ContentDeliveryManagerOptions } from './logic/ContentDeliveryManager'
4
4
  export { ProxyDirection, GroupKeyRequest, GroupKeyResponse } from './proto/packages/trackerless-network/protos/NetworkRpc'
5
- export { streamPartIdToDataKey } from './logic/EntryPointDiscovery'
5
+ export { streamPartIdToDataKey } from './logic/ContentDeliveryManager'
6
6
  export {
7
7
  convertStreamMessageToBytes,
8
8
  convertBytesToStreamMessage,
@@ -30,7 +30,7 @@ import { ProxyConnectionRpcLocal } from './proxy/ProxyConnectionRpcLocal'
30
30
  import { Inspector } from './inspect/Inspector'
31
31
  import { TemporaryConnectionRpcLocal } from './temporary-connection/TemporaryConnectionRpcLocal'
32
32
  import { markAndCheckDuplicate } from './utils'
33
- import { Layer1Node } from './Layer1Node'
33
+ import { DiscoveryLayerNode } from './DiscoveryLayerNode'
34
34
  import { StreamPartID } from '@streamr/protocol'
35
35
 
36
36
  export interface Events {
@@ -39,9 +39,9 @@ export interface Events {
39
39
  entryPointLeaveDetected: () => void
40
40
  }
41
41
 
42
- export interface StrictContentDeliveryLayerNodeConfig {
42
+ export interface StrictContentDeliveryLayerNodeOptions {
43
43
  streamPartId: StreamPartID
44
- layer1Node: Layer1Node
44
+ discoveryLayerNode: DiscoveryLayerNode
45
45
  transport: ITransport
46
46
  connectionLocker: ConnectionLocker
47
47
  localPeerDescriptor: PeerDescriptor
@@ -73,44 +73,44 @@ export class ContentDeliveryLayerNode extends EventEmitter<Events> {
73
73
 
74
74
  private started = false
75
75
  private readonly duplicateDetectors: Map<string, DuplicateMessageDetector>
76
- private config: StrictContentDeliveryLayerNodeConfig
76
+ private options: StrictContentDeliveryLayerNodeOptions
77
77
  private readonly contentDeliveryRpcLocal: ContentDeliveryRpcLocal
78
78
  private abortController: AbortController = new AbortController()
79
79
 
80
- constructor(config: StrictContentDeliveryLayerNodeConfig) {
80
+ constructor(options: StrictContentDeliveryLayerNodeOptions) {
81
81
  super()
82
- this.config = config
82
+ this.options = options
83
83
  this.duplicateDetectors = new Map()
84
84
  this.contentDeliveryRpcLocal = new ContentDeliveryRpcLocal({
85
- localPeerDescriptor: this.config.localPeerDescriptor,
86
- streamPartId: this.config.streamPartId,
87
- rpcCommunicator: this.config.rpcCommunicator,
85
+ localPeerDescriptor: this.options.localPeerDescriptor,
86
+ streamPartId: this.options.streamPartId,
87
+ rpcCommunicator: this.options.rpcCommunicator,
88
88
  markAndCheckDuplicate: (msg: MessageID, prev?: MessageRef) => markAndCheckDuplicate(this.duplicateDetectors, msg, prev),
89
89
  broadcast: (message: StreamMessage, previousNode?: DhtAddress) => this.broadcast(message, previousNode),
90
- onLeaveNotice: (sourceId: DhtAddress, sourceIsStreamEntryPoint: boolean) => {
90
+ onLeaveNotice: (remoteNodeId: DhtAddress, sourceIsStreamEntryPoint: boolean) => {
91
91
  if (this.abortController.signal.aborted) {
92
92
  return
93
93
  }
94
- const contact = this.config.nearbyNodeView.get(sourceId)
95
- || this.config.randomNodeView.get(sourceId)
96
- || this.config.neighbors.get(sourceId)
97
- || this.config.proxyConnectionRpcLocal?.getConnection(sourceId)?.remote
94
+ const contact = this.options.nearbyNodeView.get(remoteNodeId)
95
+ || this.options.randomNodeView.get(remoteNodeId)
96
+ || this.options.neighbors.get(remoteNodeId)
97
+ || this.options.proxyConnectionRpcLocal?.getConnection(remoteNodeId)?.remote
98
98
  // TODO: check integrity of notifier?
99
99
  if (contact) {
100
- this.config.layer1Node.removeContact(sourceId)
101
- this.config.neighbors.remove(sourceId)
102
- this.config.nearbyNodeView.remove(sourceId)
103
- this.config.randomNodeView.remove(sourceId)
104
- this.config.leftNodeView.remove(sourceId)
105
- this.config.rightNodeView.remove(sourceId)
106
- this.config.neighborFinder.start([sourceId])
107
- this.config.proxyConnectionRpcLocal?.removeConnection(sourceId)
100
+ this.options.discoveryLayerNode.removeContact(remoteNodeId)
101
+ this.options.neighbors.remove(remoteNodeId)
102
+ this.options.nearbyNodeView.remove(remoteNodeId)
103
+ this.options.randomNodeView.remove(remoteNodeId)
104
+ this.options.leftNodeView.remove(remoteNodeId)
105
+ this.options.rightNodeView.remove(remoteNodeId)
106
+ this.options.neighborFinder.start([remoteNodeId])
107
+ this.options.proxyConnectionRpcLocal?.removeConnection(remoteNodeId)
108
108
  }
109
109
  if (sourceIsStreamEntryPoint) {
110
110
  this.emit('entryPointLeaveDetected')
111
111
  }
112
112
  },
113
- markForInspection: (senderId: DhtAddress, messageId: MessageID) => this.config.inspector.markMessage(senderId, messageId)
113
+ markForInspection: (remoteNodeId: DhtAddress, messageId: MessageID) => this.options.inspector.markMessage(remoteNodeId, messageId)
114
114
  })
115
115
  }
116
116
 
@@ -118,92 +118,92 @@ export class ContentDeliveryLayerNode extends EventEmitter<Events> {
118
118
  this.started = true
119
119
  this.registerDefaultServerMethods()
120
120
  addManagedEventListener<any, any>(
121
- this.config.layer1Node as any,
121
+ this.options.discoveryLayerNode as any,
122
122
  'nearbyContactAdded',
123
123
  () => this.onNearbyContactAdded(),
124
124
  this.abortController.signal
125
125
  )
126
126
  addManagedEventListener<any, any>(
127
- this.config.layer1Node as any,
127
+ this.options.discoveryLayerNode as any,
128
128
  'nearbyContactRemoved',
129
129
  () => this.onNearbyContactRemoved(),
130
130
  this.abortController.signal
131
131
  )
132
132
  addManagedEventListener<any, any>(
133
- this.config.layer1Node as any,
133
+ this.options.discoveryLayerNode as any,
134
134
  'randomContactAdded',
135
135
  () => this.onRandomContactAdded(),
136
136
  this.abortController.signal
137
137
  )
138
138
  addManagedEventListener<any, any>(
139
- this.config.layer1Node as any,
139
+ this.options.discoveryLayerNode as any,
140
140
  'randomContactRemoved',
141
141
  () => this.onRandomContactRemoved(),
142
142
  this.abortController.signal
143
143
  )
144
144
  addManagedEventListener<any, any>(
145
- this.config.layer1Node as any,
145
+ this.options.discoveryLayerNode as any,
146
146
  'ringContactAdded',
147
147
  () => this.onRingContactsUpdated(),
148
148
  this.abortController.signal
149
149
  )
150
150
  addManagedEventListener<any, any>(
151
- this.config.layer1Node as any,
151
+ this.options.discoveryLayerNode as any,
152
152
  'ringContactRemoved',
153
153
  () => this.onRingContactsUpdated(),
154
154
  this.abortController.signal
155
155
  )
156
156
  addManagedEventListener<any, any>(
157
- this.config.transport as any,
157
+ this.options.transport as any,
158
158
  'disconnected',
159
159
  (peerDescriptor: PeerDescriptor) => this.onNodeDisconnected(peerDescriptor),
160
160
  this.abortController.signal
161
161
  )
162
162
  addManagedEventListener(
163
- this.config.neighbors,
163
+ this.options.neighbors,
164
164
  'nodeAdded',
165
165
  (id, remote) => {
166
- this.config.propagation.onNeighborJoined(id)
167
- this.config.connectionLocker.weakLockConnection(
166
+ this.options.propagation.onNeighborJoined(id)
167
+ this.options.connectionLocker.weakLockConnection(
168
168
  getNodeIdFromPeerDescriptor(remote.getPeerDescriptor()),
169
- this.config.streamPartId
169
+ this.options.streamPartId
170
170
  )
171
171
  this.emit('neighborConnected', id)
172
172
  },
173
173
  this.abortController.signal
174
174
  )
175
175
  addManagedEventListener(
176
- this.config.neighbors,
176
+ this.options.neighbors,
177
177
  'nodeRemoved',
178
178
  (_id, remote) => {
179
- this.config.connectionLocker.weakUnlockConnection(
179
+ this.options.connectionLocker.weakUnlockConnection(
180
180
  getNodeIdFromPeerDescriptor(remote.getPeerDescriptor()),
181
- this.config.streamPartId
181
+ this.options.streamPartId
182
182
  )
183
183
  },
184
184
  this.abortController.signal
185
185
  )
186
- if (this.config.proxyConnectionRpcLocal !== undefined) {
186
+ if (this.options.proxyConnectionRpcLocal !== undefined) {
187
187
  addManagedEventListener(
188
- this.config.proxyConnectionRpcLocal,
188
+ this.options.proxyConnectionRpcLocal,
189
189
  'newConnection',
190
- (id: DhtAddress) => this.config.propagation.onNeighborJoined(id),
190
+ (id: DhtAddress) => this.options.propagation.onNeighborJoined(id),
191
191
  this.abortController.signal
192
192
  )
193
193
  }
194
- this.config.neighborFinder.start()
195
- await this.config.neighborUpdateManager.start()
194
+ this.options.neighborFinder.start()
195
+ await this.options.neighborUpdateManager.start()
196
196
  }
197
197
 
198
198
  private registerDefaultServerMethods(): void {
199
- this.config.rpcCommunicator.registerRpcNotification(StreamMessage, 'sendStreamMessage',
199
+ this.options.rpcCommunicator.registerRpcNotification(StreamMessage, 'sendStreamMessage',
200
200
  (msg: StreamMessage, context) => this.contentDeliveryRpcLocal.sendStreamMessage(msg, context))
201
- this.config.rpcCommunicator.registerRpcNotification(LeaveStreamPartNotice, 'leaveStreamPartNotice',
201
+ this.options.rpcCommunicator.registerRpcNotification(LeaveStreamPartNotice, 'leaveStreamPartNotice',
202
202
  (req: LeaveStreamPartNotice, context) => this.contentDeliveryRpcLocal.leaveStreamPartNotice(req, context))
203
- this.config.rpcCommunicator.registerRpcMethod(TemporaryConnectionRequest, TemporaryConnectionResponse, 'openConnection',
204
- (req: TemporaryConnectionRequest, context) => this.config.temporaryConnectionRpcLocal.openConnection(req, context))
205
- this.config.rpcCommunicator.registerRpcNotification(CloseTemporaryConnection, 'closeConnection',
206
- (req: TemporaryConnectionRequest, context) => this.config.temporaryConnectionRpcLocal.closeConnection(req, context))
203
+ this.options.rpcCommunicator.registerRpcMethod(TemporaryConnectionRequest, TemporaryConnectionResponse, 'openConnection',
204
+ (req: TemporaryConnectionRequest, context) => this.options.temporaryConnectionRpcLocal.openConnection(req, context))
205
+ this.options.rpcCommunicator.registerRpcNotification(CloseTemporaryConnection, 'closeConnection',
206
+ (req: TemporaryConnectionRequest, context) => this.options.temporaryConnectionRpcLocal.closeConnection(req, context))
207
207
  }
208
208
 
209
209
  private onRingContactsUpdated(): void {
@@ -211,23 +211,23 @@ export class ContentDeliveryLayerNode extends EventEmitter<Events> {
211
211
  if (this.isStopped()) {
212
212
  return
213
213
  }
214
- const contacts = this.config.layer1Node.getRingContacts()
215
- this.config.leftNodeView.replaceAll(contacts.left.map((peer) =>
214
+ const contacts = this.options.discoveryLayerNode.getRingContacts()
215
+ this.options.leftNodeView.replaceAll(contacts.left.map((peer) =>
216
216
  new ContentDeliveryRpcRemote(
217
- this.config.localPeerDescriptor,
217
+ this.options.localPeerDescriptor,
218
218
  peer,
219
- this.config.rpcCommunicator,
219
+ this.options.rpcCommunicator,
220
220
  ContentDeliveryRpcClient,
221
- this.config.rpcRequestTimeout
221
+ this.options.rpcRequestTimeout
222
222
  )
223
223
  ))
224
- this.config.rightNodeView.replaceAll(contacts.right.map((peer) =>
224
+ this.options.rightNodeView.replaceAll(contacts.right.map((peer) =>
225
225
  new ContentDeliveryRpcRemote(
226
- this.config.localPeerDescriptor,
226
+ this.options.localPeerDescriptor,
227
227
  peer,
228
- this.config.rpcCommunicator,
228
+ this.options.rpcCommunicator,
229
229
  ContentDeliveryRpcClient,
230
- this.config.rpcRequestTimeout
230
+ this.options.rpcRequestTimeout
231
231
  )
232
232
  ))
233
233
  }
@@ -237,10 +237,10 @@ export class ContentDeliveryLayerNode extends EventEmitter<Events> {
237
237
  if (this.isStopped()) {
238
238
  return
239
239
  }
240
- const closestContacts = this.config.layer1Node.getClosestContacts()
240
+ const closestContacts = this.options.discoveryLayerNode.getClosestContacts()
241
241
  this.updateNearbyNodeView(closestContacts)
242
- if (this.config.neighbors.size() < this.config.neighborTargetCount) {
243
- this.config.neighborFinder.start()
242
+ if (this.options.neighbors.size() < this.options.neighborTargetCount) {
243
+ this.options.neighborFinder.start()
244
244
  }
245
245
  }
246
246
 
@@ -249,31 +249,31 @@ export class ContentDeliveryLayerNode extends EventEmitter<Events> {
249
249
  if (this.isStopped()) {
250
250
  return
251
251
  }
252
- const closestContacts = this.config.layer1Node.getClosestContacts()
252
+ const closestContacts = this.options.discoveryLayerNode.getClosestContacts()
253
253
  this.updateNearbyNodeView(closestContacts)
254
254
  }
255
255
 
256
256
  private updateNearbyNodeView(nodes: PeerDescriptor[]) {
257
- this.config.nearbyNodeView.replaceAll(Array.from(nodes).map((descriptor) =>
257
+ this.options.nearbyNodeView.replaceAll(Array.from(nodes).map((descriptor) =>
258
258
  new ContentDeliveryRpcRemote(
259
- this.config.localPeerDescriptor,
259
+ this.options.localPeerDescriptor,
260
260
  descriptor,
261
- this.config.rpcCommunicator,
261
+ this.options.rpcCommunicator,
262
262
  ContentDeliveryRpcClient,
263
- this.config.rpcRequestTimeout
263
+ this.options.rpcRequestTimeout
264
264
  )
265
265
  ))
266
- for (const descriptor of this.config.layer1Node.getNeighbors()) {
267
- if (this.config.nearbyNodeView.size() >= this.config.nodeViewSize) {
266
+ for (const descriptor of this.options.discoveryLayerNode.getNeighbors()) {
267
+ if (this.options.nearbyNodeView.size() >= this.options.nodeViewSize) {
268
268
  break
269
269
  }
270
- this.config.nearbyNodeView.add(
270
+ this.options.nearbyNodeView.add(
271
271
  new ContentDeliveryRpcRemote(
272
- this.config.localPeerDescriptor,
272
+ this.options.localPeerDescriptor,
273
273
  descriptor,
274
- this.config.rpcCommunicator,
274
+ this.options.rpcCommunicator,
275
275
  ContentDeliveryRpcClient,
276
- this.config.rpcRequestTimeout
276
+ this.options.rpcRequestTimeout
277
277
  )
278
278
  )
279
279
  }
@@ -283,18 +283,18 @@ export class ContentDeliveryLayerNode extends EventEmitter<Events> {
283
283
  if (this.isStopped()) {
284
284
  return
285
285
  }
286
- const randomContacts = this.config.layer1Node.getRandomContacts(RANDOM_NODE_VIEW_SIZE)
287
- this.config.randomNodeView.replaceAll(randomContacts.map((descriptor) =>
286
+ const randomContacts = this.options.discoveryLayerNode.getRandomContacts(RANDOM_NODE_VIEW_SIZE)
287
+ this.options.randomNodeView.replaceAll(randomContacts.map((descriptor) =>
288
288
  new ContentDeliveryRpcRemote(
289
- this.config.localPeerDescriptor,
289
+ this.options.localPeerDescriptor,
290
290
  descriptor,
291
- this.config.rpcCommunicator,
291
+ this.options.rpcCommunicator,
292
292
  ContentDeliveryRpcClient,
293
- this.config.rpcRequestTimeout
293
+ this.options.rpcRequestTimeout
294
294
  )
295
295
  ))
296
- if (this.config.neighbors.size() < this.config.neighborTargetCount) {
297
- this.config.neighborFinder.start()
296
+ if (this.options.neighbors.size() < this.options.neighborTargetCount) {
297
+ this.options.neighborFinder.start()
298
298
  }
299
299
  }
300
300
 
@@ -303,30 +303,30 @@ export class ContentDeliveryLayerNode extends EventEmitter<Events> {
303
303
  if (this.isStopped()) {
304
304
  return
305
305
  }
306
- const randomContacts = this.config.layer1Node.getRandomContacts(RANDOM_NODE_VIEW_SIZE)
307
- this.config.randomNodeView.replaceAll(randomContacts.map((descriptor) =>
306
+ const randomContacts = this.options.discoveryLayerNode.getRandomContacts(RANDOM_NODE_VIEW_SIZE)
307
+ this.options.randomNodeView.replaceAll(randomContacts.map((descriptor) =>
308
308
  new ContentDeliveryRpcRemote(
309
- this.config.localPeerDescriptor,
309
+ this.options.localPeerDescriptor,
310
310
  descriptor,
311
- this.config.rpcCommunicator,
311
+ this.options.rpcCommunicator,
312
312
  ContentDeliveryRpcClient,
313
- this.config.rpcRequestTimeout
313
+ this.options.rpcRequestTimeout
314
314
  )
315
315
  ))
316
316
  }
317
317
 
318
318
  private onNodeDisconnected(peerDescriptor: PeerDescriptor): void {
319
319
  const nodeId = getNodeIdFromPeerDescriptor(peerDescriptor)
320
- if (this.config.neighbors.has(nodeId)) {
321
- this.config.neighbors.remove(nodeId)
322
- this.config.neighborFinder.start([nodeId])
323
- this.config.temporaryConnectionRpcLocal.removeNode(nodeId)
320
+ if (this.options.neighbors.has(nodeId)) {
321
+ this.options.neighbors.remove(nodeId)
322
+ this.options.neighborFinder.start([nodeId])
323
+ this.options.temporaryConnectionRpcLocal.removeNode(nodeId)
324
324
  }
325
325
  }
326
326
 
327
327
  hasProxyConnection(nodeId: DhtAddress): boolean {
328
- if (this.config.proxyConnectionRpcLocal) {
329
- return this.config.proxyConnectionRpcLocal.hasConnection(nodeId)
328
+ if (this.options.proxyConnectionRpcLocal) {
329
+ return this.options.proxyConnectionRpcLocal.hasConnection(nodeId)
330
330
  }
331
331
  return false
332
332
  }
@@ -336,22 +336,22 @@ export class ContentDeliveryLayerNode extends EventEmitter<Events> {
336
336
  return
337
337
  }
338
338
  this.abortController.abort()
339
- this.config.proxyConnectionRpcLocal?.stop()
340
- this.config.neighbors.getAll().map((remote) => {
341
- remote.leaveStreamPartNotice(this.config.streamPartId, this.config.isLocalNodeEntryPoint())
342
- this.config.connectionLocker.weakUnlockConnection(
339
+ this.options.proxyConnectionRpcLocal?.stop()
340
+ this.options.neighbors.getAll().map((remote) => {
341
+ remote.leaveStreamPartNotice(this.options.streamPartId, this.options.isLocalNodeEntryPoint())
342
+ this.options.connectionLocker.weakUnlockConnection(
343
343
  getNodeIdFromPeerDescriptor(remote.getPeerDescriptor()),
344
- this.config.streamPartId
344
+ this.options.streamPartId
345
345
  )
346
346
  })
347
- this.config.rpcCommunicator.destroy()
347
+ this.options.rpcCommunicator.destroy()
348
348
  this.removeAllListeners()
349
- this.config.nearbyNodeView.stop()
350
- this.config.neighbors.stop()
351
- this.config.randomNodeView.stop()
352
- this.config.neighborFinder.stop()
353
- this.config.neighborUpdateManager.stop()
354
- this.config.inspector.stop()
349
+ this.options.nearbyNodeView.stop()
350
+ this.options.neighbors.stop()
351
+ this.options.randomNodeView.stop()
352
+ this.options.neighborFinder.stop()
353
+ this.options.neighborUpdateManager.stop()
354
+ this.options.inspector.stop()
355
355
  }
356
356
 
357
357
  broadcast(msg: StreamMessage, previousNode?: DhtAddress): void {
@@ -359,40 +359,40 @@ export class ContentDeliveryLayerNode extends EventEmitter<Events> {
359
359
  markAndCheckDuplicate(this.duplicateDetectors, msg.messageId!, msg.previousMessageRef)
360
360
  }
361
361
  this.emit('message', msg)
362
- const skipBackPropagation = previousNode !== undefined && !this.config.temporaryConnectionRpcLocal.hasNode(previousNode)
363
- this.config.propagation.feedUnseenMessage(msg, this.getPropagationTargets(msg), skipBackPropagation ? previousNode : null)
362
+ const skipBackPropagation = previousNode !== undefined && !this.options.temporaryConnectionRpcLocal.hasNode(previousNode)
363
+ this.options.propagation.feedUnseenMessage(msg, this.getPropagationTargets(msg), skipBackPropagation ? previousNode : null)
364
364
  }
365
365
 
366
366
  inspect(peerDescriptor: PeerDescriptor): Promise<boolean> {
367
- return this.config.inspector.inspect(peerDescriptor)
367
+ return this.options.inspector.inspect(peerDescriptor)
368
368
  }
369
369
 
370
370
  private getPropagationTargets(msg: StreamMessage): DhtAddress[] {
371
- let propagationTargets = this.config.neighbors.getIds()
372
- if (this.config.proxyConnectionRpcLocal) {
373
- propagationTargets = propagationTargets.concat(this.config.proxyConnectionRpcLocal.getPropagationTargets(msg))
371
+ let propagationTargets = this.options.neighbors.getIds()
372
+ if (this.options.proxyConnectionRpcLocal) {
373
+ propagationTargets = propagationTargets.concat(this.options.proxyConnectionRpcLocal.getPropagationTargets(msg))
374
374
  }
375
- propagationTargets = propagationTargets.concat(this.config.temporaryConnectionRpcLocal.getNodes().getIds())
375
+ propagationTargets = propagationTargets.concat(this.options.temporaryConnectionRpcLocal.getNodes().getIds())
376
376
  return propagationTargets
377
377
  }
378
378
 
379
379
  getOwnNodeId(): DhtAddress {
380
- return getNodeIdFromPeerDescriptor(this.config.localPeerDescriptor)
380
+ return getNodeIdFromPeerDescriptor(this.options.localPeerDescriptor)
381
381
  }
382
382
 
383
383
  getOutgoingHandshakeCount(): number {
384
- return this.config.handshaker.getOngoingHandshakes().size
384
+ return this.options.handshaker.getOngoingHandshakes().size
385
385
  }
386
386
 
387
387
  getNeighbors(): PeerDescriptor[] {
388
388
  if (!this.started && this.isStopped()) {
389
389
  return []
390
390
  }
391
- return this.config.neighbors.getAll().map((n) => n.getPeerDescriptor())
391
+ return this.options.neighbors.getAll().map((n) => n.getPeerDescriptor())
392
392
  }
393
393
 
394
394
  getNearbyNodeView(): NodeList {
395
- return this.config.nearbyNodeView
395
+ return this.options.nearbyNodeView
396
396
  }
397
397
 
398
398
  private isStopped() {