@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.
- package/dist/package.json +6 -6
- package/dist/src/NetworkNode.js +1 -1
- package/dist/src/NetworkNode.js.map +1 -1
- package/dist/src/NetworkStack.d.ts +5 -5
- package/dist/src/NetworkStack.js +21 -21
- package/dist/src/NetworkStack.js.map +1 -1
- package/dist/src/exports.d.ts +2 -2
- package/dist/src/exports.js +2 -2
- package/dist/src/exports.js.map +1 -1
- package/dist/src/logic/ContentDeliveryLayerNode.d.ts +5 -5
- package/dist/src/logic/ContentDeliveryLayerNode.js +85 -85
- package/dist/src/logic/ContentDeliveryLayerNode.js.map +1 -1
- package/dist/src/logic/ContentDeliveryManager.d.ts +11 -12
- package/dist/src/logic/ContentDeliveryManager.js +65 -61
- package/dist/src/logic/ContentDeliveryManager.js.map +1 -1
- package/dist/src/logic/ContentDeliveryRpcLocal.d.ts +5 -5
- package/dist/src/logic/ContentDeliveryRpcLocal.js +9 -9
- package/dist/src/logic/ContentDeliveryRpcLocal.js.map +1 -1
- package/dist/src/logic/{Layer0Node.d.ts → ControlLayerNode.d.ts} +1 -1
- package/dist/src/logic/{Layer0Node.js → ControlLayerNode.js} +1 -1
- package/dist/src/logic/ControlLayerNode.js.map +1 -0
- package/dist/src/logic/{Layer1Node.d.ts → DiscoveryLayerNode.d.ts} +8 -8
- package/dist/src/logic/{Layer1Node.js → DiscoveryLayerNode.js} +1 -1
- package/dist/src/logic/DiscoveryLayerNode.js.map +1 -0
- package/dist/src/logic/PeerDescriptorStoreManager.d.ts +28 -0
- package/dist/src/logic/PeerDescriptorStoreManager.js +79 -0
- package/dist/src/logic/PeerDescriptorStoreManager.js.map +1 -0
- package/dist/src/logic/StreamPartNetworkSplitAvoidance.d.ts +5 -5
- package/dist/src/logic/StreamPartNetworkSplitAvoidance.js +8 -8
- package/dist/src/logic/StreamPartNetworkSplitAvoidance.js.map +1 -1
- package/dist/src/logic/StreamPartReconnect.d.ts +5 -5
- package/dist/src/logic/StreamPartReconnect.js +10 -10
- package/dist/src/logic/StreamPartReconnect.js.map +1 -1
- package/dist/src/logic/createContentDeliveryLayerNode.d.ts +3 -3
- package/dist/src/logic/createContentDeliveryLayerNode.js +34 -34
- package/dist/src/logic/createContentDeliveryLayerNode.js.map +1 -1
- package/dist/src/logic/inspect/InspectSession.d.ts +3 -3
- package/dist/src/logic/inspect/InspectSession.js +5 -5
- package/dist/src/logic/inspect/InspectSession.js.map +1 -1
- package/dist/src/logic/inspect/Inspector.d.ts +2 -2
- package/dist/src/logic/inspect/Inspector.js +8 -8
- package/dist/src/logic/inspect/Inspector.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/HandshakeRpcLocal.d.ts +4 -4
- package/dist/src/logic/neighbor-discovery/HandshakeRpcLocal.js +24 -24
- package/dist/src/logic/neighbor-discovery/HandshakeRpcLocal.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/HandshakeRpcRemote.d.ts +1 -1
- package/dist/src/logic/neighbor-discovery/HandshakeRpcRemote.js +4 -4
- package/dist/src/logic/neighbor-discovery/HandshakeRpcRemote.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/Handshaker.d.ts +3 -3
- package/dist/src/logic/neighbor-discovery/Handshaker.js +37 -37
- package/dist/src/logic/neighbor-discovery/Handshaker.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborFinder.d.ts +3 -3
- package/dist/src/logic/neighbor-discovery/NeighborFinder.js +9 -9
- package/dist/src/logic/neighbor-discovery/NeighborFinder.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateManager.d.ts +3 -3
- package/dist/src/logic/neighbor-discovery/NeighborUpdateManager.js +12 -12
- package/dist/src/logic/neighbor-discovery/NeighborUpdateManager.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.d.ts +3 -3
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.js +14 -14
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.js.map +1 -1
- package/dist/src/logic/proxy/ProxyClient.d.ts +3 -3
- package/dist/src/logic/proxy/ProxyClient.js +25 -25
- package/dist/src/logic/proxy/ProxyClient.js.map +1 -1
- package/dist/src/logic/proxy/ProxyConnectionRpcLocal.d.ts +3 -3
- package/dist/src/logic/proxy/ProxyConnectionRpcLocal.js +10 -10
- package/dist/src/logic/proxy/ProxyConnectionRpcLocal.js.map +1 -1
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcLocal.d.ts +3 -3
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcLocal.js +11 -11
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcLocal.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +4 -4
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +8 -8
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +11 -3
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +7 -5
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +2 -2
- package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.js +1 -1
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.client.js +1 -1
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.d.ts +6 -23
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.js +5 -23
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.js.map +1 -1
- package/dist/test/benchmark/first-message.js +7 -7
- package/dist/test/benchmark/first-message.js.map +1 -1
- package/dist/test/utils/utils.d.ts +2 -2
- package/dist/test/utils/utils.js +3 -3
- package/dist/test/utils/utils.js.map +1 -1
- package/package.json +6 -6
- package/protos/NetworkRpc.proto +3 -9
- package/src/NetworkNode.ts +1 -1
- package/src/NetworkStack.ts +24 -24
- package/src/exports.ts +2 -2
- package/src/logic/ContentDeliveryLayerNode.ts +112 -112
- package/src/logic/ContentDeliveryManager.ts +71 -67
- package/src/logic/ContentDeliveryRpcLocal.ts +12 -12
- package/src/logic/{Layer0Node.ts → ControlLayerNode.ts} +1 -1
- package/src/logic/{Layer1Node.ts → DiscoveryLayerNode.ts} +8 -8
- package/src/logic/PeerDescriptorStoreManager.ts +97 -0
- package/src/logic/StreamPartNetworkSplitAvoidance.ts +11 -11
- package/src/logic/StreamPartReconnect.ts +12 -12
- package/src/logic/createContentDeliveryLayerNode.ts +38 -38
- package/src/logic/inspect/InspectSession.ts +6 -6
- package/src/logic/inspect/Inspector.ts +9 -9
- package/src/logic/neighbor-discovery/HandshakeRpcLocal.ts +26 -26
- package/src/logic/neighbor-discovery/HandshakeRpcRemote.ts +6 -6
- package/src/logic/neighbor-discovery/Handshaker.ts +45 -45
- package/src/logic/neighbor-discovery/NeighborFinder.ts +10 -10
- package/src/logic/neighbor-discovery/NeighborUpdateManager.ts +14 -14
- package/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.ts +17 -17
- package/src/logic/proxy/ProxyClient.ts +26 -26
- package/src/logic/proxy/ProxyConnectionRpcLocal.ts +12 -12
- package/src/logic/temporary-connection/TemporaryConnectionRpcLocal.ts +13 -13
- package/src/proto/google/protobuf/any.ts +1 -1
- package/src/proto/google/protobuf/empty.ts +1 -1
- package/src/proto/google/protobuf/timestamp.ts +1 -1
- package/src/proto/packages/dht/protos/DhtRpc.client.ts +9 -9
- package/src/proto/packages/dht/protos/DhtRpc.server.ts +3 -3
- package/src/proto/packages/dht/protos/DhtRpc.ts +15 -5
- package/src/proto/packages/proto-rpc/protos/ProtoRpc.ts +1 -1
- package/src/proto/packages/trackerless-network/protos/NetworkRpc.client.ts +1 -1
- package/src/proto/packages/trackerless-network/protos/NetworkRpc.server.ts +1 -1
- package/src/proto/packages/trackerless-network/protos/NetworkRpc.ts +10 -27
- package/test/benchmark/StreamPartIdDataKeyDistribution.test.ts +1 -1
- package/test/benchmark/first-message.ts +9 -9
- package/test/end-to-end/content-delivery-layer-node-with-real-connections.test.ts +12 -12
- package/test/end-to-end/proxy-and-full-node.test.ts +4 -4
- package/test/integration/ContentDeliveryLayerNode-Layer1Node-Latencies.test.ts +19 -19
- package/test/integration/ContentDeliveryLayerNode-Layer1Node.test.ts +19 -19
- package/test/integration/ContentDeliveryManager.test.ts +11 -11
- package/test/integration/Inspect.test.ts +1 -1
- package/test/integration/Propagation.test.ts +6 -6
- package/test/integration/joining-streams-on-offline-peers.test.ts +3 -3
- package/test/integration/stream-without-default-entrypoints.test.ts +2 -2
- package/test/integration/streamEntryPointReplacing.test.ts +2 -2
- package/test/unit/ContentDeliveryLayerNode.test.ts +11 -11
- package/test/unit/ContentDeliveryManager.test.ts +2 -2
- package/test/unit/{EntrypointDiscovery.test.ts → PeerDescriptorStoreManager.test.ts} +28 -29
- package/test/unit/StreamPartIDDataKey.test.ts +1 -1
- package/test/unit/StreamPartNetworkSplitAvoidance.test.ts +8 -8
- package/test/unit/StreamPartReconnect.test.ts +9 -9
- package/test/utils/fake/FakePeerDescriptorStoreManager.ts +29 -0
- package/test/utils/mock/{MockLayer0Node.ts → MockControlLayerNode.ts} +2 -2
- package/test/utils/mock/{MockLayer1Node.ts → MockDiscoveryLayerNode.ts} +2 -2
- package/test/utils/utils.ts +5 -5
- package/dist/src/logic/EntryPointDiscovery.d.ts +0 -27
- package/dist/src/logic/EntryPointDiscovery.js +0 -80
- package/dist/src/logic/EntryPointDiscovery.js.map +0 -1
- package/dist/src/logic/Layer0Node.js.map +0 -1
- package/dist/src/logic/Layer1Node.js.map +0 -1
- package/src/logic/EntryPointDiscovery.ts +0 -100
- package/test/utils/fake/FakeEntryPointDiscovery.ts +0 -29
package/src/NetworkStack.ts
CHANGED
|
@@ -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,
|
|
15
|
-
import {
|
|
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?:
|
|
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
|
|
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.
|
|
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.
|
|
110
|
-
logger.info(`Node id is ${getNodeIdFromPeerDescriptor(this.
|
|
111
|
-
const connectionManager = this.
|
|
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.
|
|
113
|
+
areEqualPeerDescriptors(entryPoint, this.controlLayerNode!.getLocalPeerDescriptor())
|
|
114
114
|
))) {
|
|
115
|
-
await this.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
140
|
+
await this.controlLayerNode?.joinDht(this.options.layer0.entryPoints)
|
|
141
141
|
}
|
|
142
142
|
})
|
|
143
|
-
await this.
|
|
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
|
-
|
|
152
|
-
return this.
|
|
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.
|
|
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.
|
|
169
|
+
peerDescriptor: this.getControlLayerNode().getLocalPeerDescriptor(),
|
|
170
170
|
controlLayer: {
|
|
171
|
-
connections: this.
|
|
172
|
-
neighbors: this.
|
|
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.
|
|
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.
|
|
192
|
+
await this.controlLayerNode!.stop()
|
|
193
193
|
this.contentDeliveryManager = undefined
|
|
194
|
-
this.
|
|
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 {
|
|
3
|
+
export { ContentDeliveryManagerOptions } from './logic/ContentDeliveryManager'
|
|
4
4
|
export { ProxyDirection, GroupKeyRequest, GroupKeyResponse } from './proto/packages/trackerless-network/protos/NetworkRpc'
|
|
5
|
-
export { streamPartIdToDataKey } from './logic/
|
|
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 {
|
|
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
|
|
42
|
+
export interface StrictContentDeliveryLayerNodeOptions {
|
|
43
43
|
streamPartId: StreamPartID
|
|
44
|
-
|
|
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
|
|
76
|
+
private options: StrictContentDeliveryLayerNodeOptions
|
|
77
77
|
private readonly contentDeliveryRpcLocal: ContentDeliveryRpcLocal
|
|
78
78
|
private abortController: AbortController = new AbortController()
|
|
79
79
|
|
|
80
|
-
constructor(
|
|
80
|
+
constructor(options: StrictContentDeliveryLayerNodeOptions) {
|
|
81
81
|
super()
|
|
82
|
-
this.
|
|
82
|
+
this.options = options
|
|
83
83
|
this.duplicateDetectors = new Map()
|
|
84
84
|
this.contentDeliveryRpcLocal = new ContentDeliveryRpcLocal({
|
|
85
|
-
localPeerDescriptor: this.
|
|
86
|
-
streamPartId: this.
|
|
87
|
-
rpcCommunicator: this.
|
|
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: (
|
|
90
|
+
onLeaveNotice: (remoteNodeId: DhtAddress, sourceIsStreamEntryPoint: boolean) => {
|
|
91
91
|
if (this.abortController.signal.aborted) {
|
|
92
92
|
return
|
|
93
93
|
}
|
|
94
|
-
const contact = this.
|
|
95
|
-
|| this.
|
|
96
|
-
|| this.
|
|
97
|
-
|| this.
|
|
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.
|
|
101
|
-
this.
|
|
102
|
-
this.
|
|
103
|
-
this.
|
|
104
|
-
this.
|
|
105
|
-
this.
|
|
106
|
-
this.
|
|
107
|
-
this.
|
|
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: (
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
163
|
+
this.options.neighbors,
|
|
164
164
|
'nodeAdded',
|
|
165
165
|
(id, remote) => {
|
|
166
|
-
this.
|
|
167
|
-
this.
|
|
166
|
+
this.options.propagation.onNeighborJoined(id)
|
|
167
|
+
this.options.connectionLocker.weakLockConnection(
|
|
168
168
|
getNodeIdFromPeerDescriptor(remote.getPeerDescriptor()),
|
|
169
|
-
this.
|
|
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.
|
|
176
|
+
this.options.neighbors,
|
|
177
177
|
'nodeRemoved',
|
|
178
178
|
(_id, remote) => {
|
|
179
|
-
this.
|
|
179
|
+
this.options.connectionLocker.weakUnlockConnection(
|
|
180
180
|
getNodeIdFromPeerDescriptor(remote.getPeerDescriptor()),
|
|
181
|
-
this.
|
|
181
|
+
this.options.streamPartId
|
|
182
182
|
)
|
|
183
183
|
},
|
|
184
184
|
this.abortController.signal
|
|
185
185
|
)
|
|
186
|
-
if (this.
|
|
186
|
+
if (this.options.proxyConnectionRpcLocal !== undefined) {
|
|
187
187
|
addManagedEventListener(
|
|
188
|
-
this.
|
|
188
|
+
this.options.proxyConnectionRpcLocal,
|
|
189
189
|
'newConnection',
|
|
190
|
-
(id: DhtAddress) => this.
|
|
190
|
+
(id: DhtAddress) => this.options.propagation.onNeighborJoined(id),
|
|
191
191
|
this.abortController.signal
|
|
192
192
|
)
|
|
193
193
|
}
|
|
194
|
-
this.
|
|
195
|
-
await this.
|
|
194
|
+
this.options.neighborFinder.start()
|
|
195
|
+
await this.options.neighborUpdateManager.start()
|
|
196
196
|
}
|
|
197
197
|
|
|
198
198
|
private registerDefaultServerMethods(): void {
|
|
199
|
-
this.
|
|
199
|
+
this.options.rpcCommunicator.registerRpcNotification(StreamMessage, 'sendStreamMessage',
|
|
200
200
|
(msg: StreamMessage, context) => this.contentDeliveryRpcLocal.sendStreamMessage(msg, context))
|
|
201
|
-
this.
|
|
201
|
+
this.options.rpcCommunicator.registerRpcNotification(LeaveStreamPartNotice, 'leaveStreamPartNotice',
|
|
202
202
|
(req: LeaveStreamPartNotice, context) => this.contentDeliveryRpcLocal.leaveStreamPartNotice(req, context))
|
|
203
|
-
this.
|
|
204
|
-
(req: TemporaryConnectionRequest, context) => this.
|
|
205
|
-
this.
|
|
206
|
-
(req: TemporaryConnectionRequest, context) => this.
|
|
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.
|
|
215
|
-
this.
|
|
214
|
+
const contacts = this.options.discoveryLayerNode.getRingContacts()
|
|
215
|
+
this.options.leftNodeView.replaceAll(contacts.left.map((peer) =>
|
|
216
216
|
new ContentDeliveryRpcRemote(
|
|
217
|
-
this.
|
|
217
|
+
this.options.localPeerDescriptor,
|
|
218
218
|
peer,
|
|
219
|
-
this.
|
|
219
|
+
this.options.rpcCommunicator,
|
|
220
220
|
ContentDeliveryRpcClient,
|
|
221
|
-
this.
|
|
221
|
+
this.options.rpcRequestTimeout
|
|
222
222
|
)
|
|
223
223
|
))
|
|
224
|
-
this.
|
|
224
|
+
this.options.rightNodeView.replaceAll(contacts.right.map((peer) =>
|
|
225
225
|
new ContentDeliveryRpcRemote(
|
|
226
|
-
this.
|
|
226
|
+
this.options.localPeerDescriptor,
|
|
227
227
|
peer,
|
|
228
|
-
this.
|
|
228
|
+
this.options.rpcCommunicator,
|
|
229
229
|
ContentDeliveryRpcClient,
|
|
230
|
-
this.
|
|
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.
|
|
240
|
+
const closestContacts = this.options.discoveryLayerNode.getClosestContacts()
|
|
241
241
|
this.updateNearbyNodeView(closestContacts)
|
|
242
|
-
if (this.
|
|
243
|
-
this.
|
|
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.
|
|
252
|
+
const closestContacts = this.options.discoveryLayerNode.getClosestContacts()
|
|
253
253
|
this.updateNearbyNodeView(closestContacts)
|
|
254
254
|
}
|
|
255
255
|
|
|
256
256
|
private updateNearbyNodeView(nodes: PeerDescriptor[]) {
|
|
257
|
-
this.
|
|
257
|
+
this.options.nearbyNodeView.replaceAll(Array.from(nodes).map((descriptor) =>
|
|
258
258
|
new ContentDeliveryRpcRemote(
|
|
259
|
-
this.
|
|
259
|
+
this.options.localPeerDescriptor,
|
|
260
260
|
descriptor,
|
|
261
|
-
this.
|
|
261
|
+
this.options.rpcCommunicator,
|
|
262
262
|
ContentDeliveryRpcClient,
|
|
263
|
-
this.
|
|
263
|
+
this.options.rpcRequestTimeout
|
|
264
264
|
)
|
|
265
265
|
))
|
|
266
|
-
for (const descriptor of this.
|
|
267
|
-
if (this.
|
|
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.
|
|
270
|
+
this.options.nearbyNodeView.add(
|
|
271
271
|
new ContentDeliveryRpcRemote(
|
|
272
|
-
this.
|
|
272
|
+
this.options.localPeerDescriptor,
|
|
273
273
|
descriptor,
|
|
274
|
-
this.
|
|
274
|
+
this.options.rpcCommunicator,
|
|
275
275
|
ContentDeliveryRpcClient,
|
|
276
|
-
this.
|
|
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.
|
|
287
|
-
this.
|
|
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.
|
|
289
|
+
this.options.localPeerDescriptor,
|
|
290
290
|
descriptor,
|
|
291
|
-
this.
|
|
291
|
+
this.options.rpcCommunicator,
|
|
292
292
|
ContentDeliveryRpcClient,
|
|
293
|
-
this.
|
|
293
|
+
this.options.rpcRequestTimeout
|
|
294
294
|
)
|
|
295
295
|
))
|
|
296
|
-
if (this.
|
|
297
|
-
this.
|
|
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.
|
|
307
|
-
this.
|
|
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.
|
|
309
|
+
this.options.localPeerDescriptor,
|
|
310
310
|
descriptor,
|
|
311
|
-
this.
|
|
311
|
+
this.options.rpcCommunicator,
|
|
312
312
|
ContentDeliveryRpcClient,
|
|
313
|
-
this.
|
|
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.
|
|
321
|
-
this.
|
|
322
|
-
this.
|
|
323
|
-
this.
|
|
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.
|
|
329
|
-
return this.
|
|
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.
|
|
340
|
-
this.
|
|
341
|
-
remote.leaveStreamPartNotice(this.
|
|
342
|
-
this.
|
|
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.
|
|
344
|
+
this.options.streamPartId
|
|
345
345
|
)
|
|
346
346
|
})
|
|
347
|
-
this.
|
|
347
|
+
this.options.rpcCommunicator.destroy()
|
|
348
348
|
this.removeAllListeners()
|
|
349
|
-
this.
|
|
350
|
-
this.
|
|
351
|
-
this.
|
|
352
|
-
this.
|
|
353
|
-
this.
|
|
354
|
-
this.
|
|
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.
|
|
363
|
-
this.
|
|
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.
|
|
367
|
+
return this.options.inspector.inspect(peerDescriptor)
|
|
368
368
|
}
|
|
369
369
|
|
|
370
370
|
private getPropagationTargets(msg: StreamMessage): DhtAddress[] {
|
|
371
|
-
let propagationTargets = this.
|
|
372
|
-
if (this.
|
|
373
|
-
propagationTargets = propagationTargets.concat(this.
|
|
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.
|
|
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.
|
|
380
|
+
return getNodeIdFromPeerDescriptor(this.options.localPeerDescriptor)
|
|
381
381
|
}
|
|
382
382
|
|
|
383
383
|
getOutgoingHandshakeCount(): number {
|
|
384
|
-
return this.
|
|
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.
|
|
391
|
+
return this.options.neighbors.getAll().map((n) => n.getPeerDescriptor())
|
|
392
392
|
}
|
|
393
393
|
|
|
394
394
|
getNearbyNodeView(): NodeList {
|
|
395
|
-
return this.
|
|
395
|
+
return this.options.nearbyNodeView
|
|
396
396
|
}
|
|
397
397
|
|
|
398
398
|
private isStopped() {
|