@streamr/trackerless-network 102.0.0-beta.1 → 102.0.0-beta.3
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 +5 -5
- package/package.json +5 -5
- package/src/NetworkNode.ts +0 -142
- package/src/NetworkStack.ts +0 -197
- package/src/exports.ts +0 -18
- package/src/logic/ContentDeliveryLayerNode.ts +0 -424
- package/src/logic/ContentDeliveryManager.ts +0 -401
- package/src/logic/ContentDeliveryRpcLocal.ts +0 -48
- package/src/logic/ContentDeliveryRpcRemote.ts +0 -44
- package/src/logic/ControlLayerNode.ts +0 -17
- package/src/logic/DiscoveryLayerNode.ts +0 -30
- package/src/logic/DuplicateMessageDetector.ts +0 -167
- package/src/logic/ExternalNetworkRpc.ts +0 -42
- package/src/logic/NodeList.ts +0 -114
- package/src/logic/PeerDescriptorStoreManager.ts +0 -96
- package/src/logic/StreamPartNetworkSplitAvoidance.ts +0 -90
- package/src/logic/StreamPartReconnect.ts +0 -38
- package/src/logic/createContentDeliveryLayerNode.ts +0 -130
- package/src/logic/formStreamPartDeliveryServiceId.ts +0 -7
- package/src/logic/inspect/InspectSession.ts +0 -55
- package/src/logic/inspect/Inspector.ts +0 -100
- package/src/logic/neighbor-discovery/HandshakeRpcLocal.ts +0 -138
- package/src/logic/neighbor-discovery/HandshakeRpcRemote.ts +0 -66
- package/src/logic/neighbor-discovery/Handshaker.ts +0 -215
- package/src/logic/neighbor-discovery/NeighborFinder.ts +0 -77
- package/src/logic/neighbor-discovery/NeighborUpdateManager.ts +0 -69
- package/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.ts +0 -75
- package/src/logic/neighbor-discovery/NeighborUpdateRpcRemote.ts +0 -35
- package/src/logic/node-info/NodeInfoClient.ts +0 -23
- package/src/logic/node-info/NodeInfoRpcLocal.ts +0 -28
- package/src/logic/node-info/NodeInfoRpcRemote.ts +0 -11
- package/src/logic/propagation/FifoMapWithTTL.ts +0 -116
- package/src/logic/propagation/Propagation.ts +0 -84
- package/src/logic/propagation/PropagationTaskStore.ts +0 -41
- package/src/logic/proxy/ProxyClient.ts +0 -286
- package/src/logic/proxy/ProxyConnectionRpcLocal.ts +0 -106
- package/src/logic/proxy/ProxyConnectionRpcRemote.ts +0 -26
- package/src/logic/temporary-connection/TemporaryConnectionRpcLocal.ts +0 -73
- package/src/logic/temporary-connection/TemporaryConnectionRpcRemote.ts +0 -29
- package/src/logic/utils.ts +0 -18
- package/src/types.ts +0 -13
- package/test/benchmark/StreamPartIdDataKeyDistribution.test.ts +0 -60
- package/test/benchmark/first-message.ts +0 -171
- package/test/end-to-end/content-delivery-layer-node-with-real-connections.test.ts +0 -165
- package/test/end-to-end/external-network-rpc.test.ts +0 -67
- package/test/end-to-end/inspect.test.ts +0 -124
- package/test/end-to-end/proxy-and-full-node.test.ts +0 -143
- package/test/end-to-end/proxy-connections.test.ts +0 -226
- package/test/end-to-end/proxy-key-exchange.test.ts +0 -126
- package/test/end-to-end/webrtc-full-node-network.test.ts +0 -83
- package/test/end-to-end/websocket-full-node-network.test.ts +0 -82
- package/test/integration/ContentDeliveryLayerNode-Layer1Node-Latencies.test.ts +0 -139
- package/test/integration/ContentDeliveryLayerNode-Layer1Node.test.ts +0 -162
- package/test/integration/ContentDeliveryManager.test.ts +0 -160
- package/test/integration/ContentDeliveryRpcRemote.test.ts +0 -100
- package/test/integration/HandshakeRpcRemote.test.ts +0 -79
- package/test/integration/Handshakes.test.ts +0 -141
- package/test/integration/Inspect.test.ts +0 -89
- package/test/integration/NeighborUpdateRpcRemote.test.ts +0 -82
- package/test/integration/NetworkNode.test.ts +0 -115
- package/test/integration/NetworkRpc.test.ts +0 -52
- package/test/integration/NetworkStack.test.ts +0 -72
- package/test/integration/NodeInfoRpc.test.ts +0 -109
- package/test/integration/Propagation.test.ts +0 -76
- package/test/integration/joining-streams-on-offline-peers.test.ts +0 -82
- package/test/integration/stream-without-default-entrypoints.test.ts +0 -128
- package/test/integration/streamEntryPointReplacing.test.ts +0 -97
- package/test/types/global.d.ts +0 -1
- package/test/unit/ContentDeliveryLayerNode.test.ts +0 -112
- package/test/unit/ContentDeliveryManager.test.ts +0 -96
- package/test/unit/ContentDeliveryRpcLocal.test.ts +0 -60
- package/test/unit/DuplicateMessageDetector.test.ts +0 -192
- package/test/unit/ExternalNetworkRpc.test.ts +0 -48
- package/test/unit/FifoMapWithTtl.test.ts +0 -253
- package/test/unit/HandshakeRpcLocal.test.ts +0 -155
- package/test/unit/Handshaker.test.ts +0 -69
- package/test/unit/InspectSession.test.ts +0 -83
- package/test/unit/Inspector.test.ts +0 -51
- package/test/unit/NeighborFinder.test.ts +0 -51
- package/test/unit/NeighborUpdateRpcLocal.test.ts +0 -139
- package/test/unit/NetworkNode.test.ts +0 -42
- package/test/unit/NodeList.test.ts +0 -164
- package/test/unit/NumberPair.test.ts +0 -22
- package/test/unit/PeerDescriptorStoreManager.test.ts +0 -103
- package/test/unit/Propagation.test.ts +0 -151
- package/test/unit/ProxyConnectionRpcRemote.test.ts +0 -39
- package/test/unit/StreamPartIDDataKey.test.ts +0 -12
- package/test/unit/StreamPartNetworkSplitAvoidance.test.ts +0 -31
- package/test/unit/StreamPartReconnect.test.ts +0 -30
- package/test/unit/TemporaryConnectionRpcLocal.test.ts +0 -38
- package/test/utils/fake/FakePeerDescriptorStoreManager.ts +0 -29
- package/test/utils/mock/MockConnectionsView.ts +0 -18
- package/test/utils/mock/MockControlLayerNode.ts +0 -78
- package/test/utils/mock/MockDiscoveryLayerNode.ts +0 -60
- package/test/utils/mock/MockHandshaker.ts +0 -17
- package/test/utils/mock/MockNeighborFinder.ts +0 -20
- package/test/utils/mock/MockNeighborUpdateManager.ts +0 -21
- package/test/utils/mock/MockTransport.ts +0 -30
- package/test/utils/utils.ts +0 -144
- package/tsconfig.browser.json +0 -13
- package/tsconfig.jest.json +0 -17
- package/tsconfig.json +0 -3
- package/tsconfig.node.json +0 -17
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@streamr/trackerless-network",
|
|
3
|
-
"version": "102.0.0-beta.
|
|
3
|
+
"version": "102.0.0-beta.3",
|
|
4
4
|
"description": "Minimal and extendable implementation of the Streamr Network node.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@protobuf-ts/runtime": "^2.8.2",
|
|
32
32
|
"@protobuf-ts/runtime-rpc": "^2.8.2",
|
|
33
|
-
"@streamr/dht": "102.0.0-beta.
|
|
34
|
-
"@streamr/proto-rpc": "102.0.0-beta.
|
|
35
|
-
"@streamr/utils": "102.0.0-beta.
|
|
33
|
+
"@streamr/dht": "102.0.0-beta.3",
|
|
34
|
+
"@streamr/proto-rpc": "102.0.0-beta.3",
|
|
35
|
+
"@streamr/utils": "102.0.0-beta.3",
|
|
36
36
|
"eventemitter3": "^5.0.0",
|
|
37
37
|
"lodash": "^4.17.21",
|
|
38
38
|
"ts-essentials": "^10.0.4",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@streamr/browser-test-runner": "^0.0.1",
|
|
44
|
-
"@streamr/test-utils": "102.0.0-beta.
|
|
44
|
+
"@streamr/test-utils": "102.0.0-beta.3",
|
|
45
45
|
"@types/lodash": "^4.17.14",
|
|
46
46
|
"@types/yallist": "^4.0.1",
|
|
47
47
|
"expect": "^29.6.2",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@streamr/trackerless-network",
|
|
3
|
-
"version": "102.0.0-beta.
|
|
3
|
+
"version": "102.0.0-beta.3",
|
|
4
4
|
"description": "Minimal and extendable implementation of the Streamr Network node.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@protobuf-ts/runtime": "^2.8.2",
|
|
32
32
|
"@protobuf-ts/runtime-rpc": "^2.8.2",
|
|
33
|
-
"@streamr/dht": "102.0.0-beta.
|
|
34
|
-
"@streamr/proto-rpc": "102.0.0-beta.
|
|
35
|
-
"@streamr/utils": "102.0.0-beta.
|
|
33
|
+
"@streamr/dht": "102.0.0-beta.3",
|
|
34
|
+
"@streamr/proto-rpc": "102.0.0-beta.3",
|
|
35
|
+
"@streamr/utils": "102.0.0-beta.3",
|
|
36
36
|
"eventemitter3": "^5.0.0",
|
|
37
37
|
"lodash": "^4.17.21",
|
|
38
38
|
"ts-essentials": "^10.0.4",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@streamr/browser-test-runner": "^0.0.1",
|
|
44
|
-
"@streamr/test-utils": "102.0.0-beta.
|
|
44
|
+
"@streamr/test-utils": "102.0.0-beta.3",
|
|
45
45
|
"@types/lodash": "^4.17.14",
|
|
46
46
|
"@types/yallist": "^4.0.1",
|
|
47
47
|
"expect": "^29.6.2",
|
package/src/NetworkNode.ts
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { IMessageType } from '@protobuf-ts/runtime'
|
|
2
|
-
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
3
|
-
import { DhtAddress, PeerDescriptor } from '@streamr/dht'
|
|
4
|
-
import { ProtoRpcClient } from '@streamr/proto-rpc'
|
|
5
|
-
import { MetricsContext, StreamPartID, UserID } from '@streamr/utils'
|
|
6
|
-
import { ExternalNetworkRpc, ExternalRpcClient, ExternalRpcClientClass } from './logic/ExternalNetworkRpc'
|
|
7
|
-
import { NetworkOptions, NetworkStack } from './NetworkStack'
|
|
8
|
-
import { ProxyDirection, StreamMessage } from '../generated/packages/trackerless-network/protos/NetworkRpc'
|
|
9
|
-
import { NodeInfo } from './types'
|
|
10
|
-
|
|
11
|
-
export const createNetworkNode = (opts: NetworkOptions): NetworkNode => {
|
|
12
|
-
return new NetworkNode(new NetworkStack(opts))
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Convenience wrapper for building client-facing functionality. Used by client.
|
|
17
|
-
*/
|
|
18
|
-
export class NetworkNode {
|
|
19
|
-
|
|
20
|
-
readonly stack: NetworkStack
|
|
21
|
-
private stopped = false
|
|
22
|
-
private externalNetworkRpc?: ExternalNetworkRpc
|
|
23
|
-
|
|
24
|
-
/** @internal */
|
|
25
|
-
constructor(stack: NetworkStack) {
|
|
26
|
-
this.stack = stack
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
async start(doJoin?: boolean): Promise<void> {
|
|
30
|
-
await this.stack.start(doJoin)
|
|
31
|
-
this.externalNetworkRpc = new ExternalNetworkRpc(this.stack.getControlLayerNode().getTransport())
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
async inspect(node: PeerDescriptor, streamPartId: StreamPartID): Promise<boolean> {
|
|
35
|
-
return this.stack.getContentDeliveryManager().inspect(node, streamPartId)
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
async broadcast(msg: StreamMessage): Promise<void> {
|
|
39
|
-
await this.stack.broadcast(msg)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
async join(streamPartId: StreamPartID, neighborRequirement?: { minCount: number, timeout: number }): Promise<void> {
|
|
43
|
-
await this.stack.joinStreamPart(streamPartId, neighborRequirement)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
async setProxies(
|
|
47
|
-
streamPartId: StreamPartID,
|
|
48
|
-
nodes: PeerDescriptor[],
|
|
49
|
-
direction: ProxyDirection,
|
|
50
|
-
userId: UserID,
|
|
51
|
-
connectionCount?: number
|
|
52
|
-
): Promise<void> {
|
|
53
|
-
await this.stack.getContentDeliveryManager().setProxies(streamPartId, nodes, direction, userId, connectionCount)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
isProxiedStreamPart(streamPartId: StreamPartID): boolean {
|
|
57
|
-
return this.stack.getContentDeliveryManager().isProxiedStreamPart(streamPartId)
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
addMessageListener(listener: (msg: StreamMessage) => void): void {
|
|
61
|
-
this.stack.getContentDeliveryManager().on('newMessage', listener)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
setStreamPartEntryPoints(streamPartId: StreamPartID, contactPeerDescriptors: PeerDescriptor[]): void {
|
|
65
|
-
this.stack.getContentDeliveryManager().setStreamPartEntryPoints(streamPartId, contactPeerDescriptors)
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
removeMessageListener(listener: (msg: StreamMessage) => void): void {
|
|
69
|
-
this.stack.getContentDeliveryManager().off('newMessage', listener)
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
async leave(streamPartId: StreamPartID): Promise<void> {
|
|
73
|
-
if (this.stopped) {
|
|
74
|
-
return
|
|
75
|
-
}
|
|
76
|
-
await this.stack.getContentDeliveryManager().leaveStreamPart(streamPartId)
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
getNeighbors(streamPartId: StreamPartID): readonly DhtAddress[] {
|
|
80
|
-
return this.stack.getContentDeliveryManager().getNeighbors(streamPartId)
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
hasStreamPart(streamPartId: StreamPartID): boolean {
|
|
84
|
-
return this.stack.getContentDeliveryManager().hasStreamPart(streamPartId)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
async stop(): Promise<void> {
|
|
88
|
-
this.stopped = true
|
|
89
|
-
this.externalNetworkRpc!.destroy()
|
|
90
|
-
await this.stack.stop()
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
getPeerDescriptor(): PeerDescriptor {
|
|
94
|
-
return this.stack.getControlLayerNode().getLocalPeerDescriptor()
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
getMetricsContext(): MetricsContext {
|
|
98
|
-
return this.stack.getMetricsContext()
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
getNodeId(): DhtAddress {
|
|
102
|
-
return this.stack.getContentDeliveryManager().getNodeId()
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
getOptions(): NetworkOptions {
|
|
106
|
-
return this.stack.getOptions()
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
getStreamParts(): StreamPartID[] {
|
|
110
|
-
return this.stack.getContentDeliveryManager().getStreamParts()
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
async fetchNodeInfo(node: PeerDescriptor): Promise<NodeInfo> {
|
|
114
|
-
return this.stack.fetchNodeInfo(node)
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
getDiagnosticInfo(): Record<string, unknown> {
|
|
118
|
-
return {
|
|
119
|
-
controlLayer: this.stack.getControlLayerNode().getDiagnosticInfo(),
|
|
120
|
-
contentLayer: this.stack.getContentDeliveryManager().getDiagnosticInfo()
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
registerExternalNetworkRpcMethod<
|
|
125
|
-
RequestClass extends IMessageType<RequestType>,
|
|
126
|
-
ResponseClass extends IMessageType<ResponseType>,
|
|
127
|
-
RequestType extends object,
|
|
128
|
-
ResponseType extends object
|
|
129
|
-
>(
|
|
130
|
-
request: RequestClass,
|
|
131
|
-
response: ResponseClass,
|
|
132
|
-
name: string,
|
|
133
|
-
fn: (req: RequestType, context: ServerCallContext) => Promise<ResponseType>
|
|
134
|
-
): void {
|
|
135
|
-
this.externalNetworkRpc!.registerRpcMethod(request, response, name, fn)
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
createExternalRpcClient<T extends ExternalRpcClient>(clientClass: ExternalRpcClientClass<T> ): ProtoRpcClient<T> {
|
|
139
|
-
return this.externalNetworkRpc!.createRpcClient(clientClass)
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
}
|
package/src/NetworkStack.ts
DELETED
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ConnectionManager,
|
|
3
|
-
DhtNode,
|
|
4
|
-
DhtNodeOptions,
|
|
5
|
-
ListeningRpcCommunicator,
|
|
6
|
-
PeerDescriptor,
|
|
7
|
-
areEqualPeerDescriptors,
|
|
8
|
-
toNodeId
|
|
9
|
-
} from '@streamr/dht'
|
|
10
|
-
import { Logger, MetricsContext, StreamID, StreamPartID, toStreamPartID, until } from '@streamr/utils'
|
|
11
|
-
import { pull } from 'lodash'
|
|
12
|
-
import { version as applicationVersion } from '../package.json'
|
|
13
|
-
import { ContentDeliveryManager, ContentDeliveryManagerOptions } from './logic/ContentDeliveryManager'
|
|
14
|
-
import { ControlLayerNode } from './logic/ControlLayerNode'
|
|
15
|
-
import { NodeInfoClient } from './logic/node-info/NodeInfoClient'
|
|
16
|
-
import { NODE_INFO_RPC_SERVICE_ID, NodeInfoRpcLocal } from './logic/node-info/NodeInfoRpcLocal'
|
|
17
|
-
import { ProxyDirection, StreamMessage } from '../generated/packages/trackerless-network/protos/NetworkRpc'
|
|
18
|
-
import { NodeInfo } from './types'
|
|
19
|
-
|
|
20
|
-
export interface NetworkOptions {
|
|
21
|
-
layer0?: DhtNodeOptions
|
|
22
|
-
networkNode?: ContentDeliveryManagerOptions
|
|
23
|
-
metricsContext?: MetricsContext
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const logger = new Logger(module)
|
|
27
|
-
|
|
28
|
-
const instances: NetworkStack[] = []
|
|
29
|
-
const stopInstances = async () => {
|
|
30
|
-
// make a clone so that it is ok for each instance.stop() to remove itself from the list (at line 139)
|
|
31
|
-
// while the map function is iterating the list
|
|
32
|
-
const clonedInstances = [...instances]
|
|
33
|
-
await Promise.all(clonedInstances.map((instance) => instance.stop()))
|
|
34
|
-
}
|
|
35
|
-
const EXIT_EVENTS = [`exit`, `SIGINT`, `SIGUSR1`, `SIGUSR2`, `uncaughtException`, `unhandledRejection`, `SIGTERM`]
|
|
36
|
-
EXIT_EVENTS.forEach((event) => {
|
|
37
|
-
process.on(event, async (eventArg) => {
|
|
38
|
-
const isError = (event === 'uncaughtException') || (event === 'unhandledRejection')
|
|
39
|
-
if (isError) {
|
|
40
|
-
logger.error(`exit event: ${event}`, eventArg)
|
|
41
|
-
}
|
|
42
|
-
await stopInstances()
|
|
43
|
-
process.exit(isError ? 1 : 0)
|
|
44
|
-
})
|
|
45
|
-
})
|
|
46
|
-
declare let window: any
|
|
47
|
-
if (typeof window === 'object') {
|
|
48
|
-
window.addEventListener('unload', async () => {
|
|
49
|
-
await stopInstances()
|
|
50
|
-
})
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export class NetworkStack {
|
|
54
|
-
|
|
55
|
-
private controlLayerNode?: ControlLayerNode
|
|
56
|
-
private contentDeliveryManager?: ContentDeliveryManager
|
|
57
|
-
private stopped = false
|
|
58
|
-
private readonly metricsContext: MetricsContext
|
|
59
|
-
private readonly options: NetworkOptions
|
|
60
|
-
private nodeInfoRpcLocal?: NodeInfoRpcLocal
|
|
61
|
-
private nodeInfoClient?: NodeInfoClient
|
|
62
|
-
|
|
63
|
-
constructor(options: NetworkOptions) {
|
|
64
|
-
this.options = options
|
|
65
|
-
this.metricsContext = options.metricsContext ?? new MetricsContext()
|
|
66
|
-
this.controlLayerNode = new DhtNode({
|
|
67
|
-
...options.layer0,
|
|
68
|
-
metricsContext: this.metricsContext,
|
|
69
|
-
allowIncomingPrivateConnections: options.networkNode?.acceptProxyConnections
|
|
70
|
-
})
|
|
71
|
-
this.contentDeliveryManager = new ContentDeliveryManager({
|
|
72
|
-
...options.networkNode,
|
|
73
|
-
metricsContext: this.metricsContext
|
|
74
|
-
})
|
|
75
|
-
instances.push(this)
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
async joinStreamPart(streamPartId: StreamPartID, neighborRequirement?: { minCount: number, timeout: number }): Promise<void> {
|
|
79
|
-
if (this.getContentDeliveryManager().isProxiedStreamPart(streamPartId)) {
|
|
80
|
-
throw new Error(`Cannot join to ${streamPartId} as proxy connections have been set`)
|
|
81
|
-
}
|
|
82
|
-
await this.ensureConnectedToControlLayer()
|
|
83
|
-
this.getContentDeliveryManager().joinStreamPart(streamPartId)
|
|
84
|
-
if (neighborRequirement !== undefined) {
|
|
85
|
-
await until(() => {
|
|
86
|
-
return this.getContentDeliveryManager().getNeighbors(streamPartId).length >= neighborRequirement.minCount
|
|
87
|
-
}, neighborRequirement.timeout)
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
async broadcast(msg: StreamMessage): Promise<void> {
|
|
92
|
-
const streamPartId = toStreamPartID(msg.messageId!.streamId as StreamID, msg.messageId!.streamPartition)
|
|
93
|
-
if (
|
|
94
|
-
this.getContentDeliveryManager().isProxiedStreamPart(streamPartId, ProxyDirection.SUBSCRIBE)
|
|
95
|
-
&& (msg.body.oneofKind === 'contentMessage')
|
|
96
|
-
) {
|
|
97
|
-
throw new Error(`Cannot broadcast to ${streamPartId} as proxy subscribe connections have been set`)
|
|
98
|
-
}
|
|
99
|
-
// TODO could combine these two calls to isProxiedStreamPart?
|
|
100
|
-
if (!this.contentDeliveryManager!.isProxiedStreamPart(streamPartId)) {
|
|
101
|
-
await this.ensureConnectedToControlLayer()
|
|
102
|
-
}
|
|
103
|
-
this.getContentDeliveryManager().broadcast(msg)
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
async start(doJoin = true): Promise<void> {
|
|
107
|
-
logger.info('Starting a Streamr Network Node')
|
|
108
|
-
await this.controlLayerNode!.start()
|
|
109
|
-
logger.info(`Node id is ${toNodeId(this.controlLayerNode!.getLocalPeerDescriptor())}`)
|
|
110
|
-
const connectionManager = this.controlLayerNode!.getTransport() as ConnectionManager
|
|
111
|
-
if ((this.options.layer0?.entryPoints?.some((entryPoint) =>
|
|
112
|
-
areEqualPeerDescriptors(entryPoint, this.controlLayerNode!.getLocalPeerDescriptor())
|
|
113
|
-
))) {
|
|
114
|
-
await this.controlLayerNode?.joinDht(this.options.layer0.entryPoints)
|
|
115
|
-
} else if (doJoin) {
|
|
116
|
-
// in practice there aren't be existing connections and therefore this always connects
|
|
117
|
-
await this.ensureConnectedToControlLayer()
|
|
118
|
-
}
|
|
119
|
-
// TODO: remove undefined checks here. Assume that start is approproately awaited before stop is called.
|
|
120
|
-
await this.contentDeliveryManager?.start(this.controlLayerNode!, connectionManager, connectionManager)
|
|
121
|
-
if (this.contentDeliveryManager) {
|
|
122
|
-
const infoRpcCommunicator = new ListeningRpcCommunicator(NODE_INFO_RPC_SERVICE_ID, this.getConnectionManager())
|
|
123
|
-
this.nodeInfoRpcLocal = new NodeInfoRpcLocal(this, infoRpcCommunicator)
|
|
124
|
-
this.nodeInfoClient = new NodeInfoClient(
|
|
125
|
-
this.controlLayerNode!.getLocalPeerDescriptor(),
|
|
126
|
-
infoRpcCommunicator
|
|
127
|
-
)
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
private async ensureConnectedToControlLayer(): Promise<void> {
|
|
132
|
-
// TODO we could wrap joinDht with pOnce and call it here (no else-if needed in that case)
|
|
133
|
-
if (!this.controlLayerNode!.hasJoined()) {
|
|
134
|
-
setImmediate(async () => {
|
|
135
|
-
if (this.options.layer0?.entryPoints !== undefined) {
|
|
136
|
-
// TODO should catch possible rejection?
|
|
137
|
-
// the question mark is there to avoid problems when stop() is called before start()
|
|
138
|
-
// -> TODO change to exlamation mark if we don't support that (and remove NetworkStackStoppedDuringStart.test)
|
|
139
|
-
await this.controlLayerNode?.joinDht(this.options.layer0.entryPoints)
|
|
140
|
-
}
|
|
141
|
-
})
|
|
142
|
-
await this.controlLayerNode!.waitForNetworkConnectivity()
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
getContentDeliveryManager(): ContentDeliveryManager {
|
|
147
|
-
return this.contentDeliveryManager!
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
getControlLayerNode(): ControlLayerNode {
|
|
151
|
-
return this.controlLayerNode!
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
getMetricsContext(): MetricsContext {
|
|
155
|
-
return this.metricsContext
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
async fetchNodeInfo(node: PeerDescriptor): Promise<NodeInfo> {
|
|
159
|
-
if (!areEqualPeerDescriptors(node, this.getControlLayerNode().getLocalPeerDescriptor())) {
|
|
160
|
-
return this.nodeInfoClient!.getInfo(node)
|
|
161
|
-
} else {
|
|
162
|
-
return this.createNodeInfo()
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
createNodeInfo(): NodeInfo {
|
|
167
|
-
return {
|
|
168
|
-
peerDescriptor: this.getControlLayerNode().getLocalPeerDescriptor(),
|
|
169
|
-
controlLayer: {
|
|
170
|
-
connections: this.getControlLayerNode().getConnectionsView().getConnections(),
|
|
171
|
-
neighbors: this.getControlLayerNode().getNeighbors()
|
|
172
|
-
},
|
|
173
|
-
streamPartitions: this.getContentDeliveryManager().getNodeInfo(),
|
|
174
|
-
applicationVersion
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
getOptions(): NetworkOptions {
|
|
179
|
-
return this.options
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
private getConnectionManager(): ConnectionManager {
|
|
183
|
-
return this.controlLayerNode!.getTransport() as ConnectionManager
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
async stop(): Promise<void> {
|
|
187
|
-
if (!this.stopped) {
|
|
188
|
-
this.stopped = true
|
|
189
|
-
pull(instances, this)
|
|
190
|
-
await this.contentDeliveryManager!.destroy()
|
|
191
|
-
await this.controlLayerNode!.stop()
|
|
192
|
-
this.contentDeliveryManager = undefined
|
|
193
|
-
this.controlLayerNode = undefined
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
}
|
package/src/exports.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export { NetworkNode, createNetworkNode } from './NetworkNode'
|
|
2
|
-
export { NetworkOptions, NetworkStack } from './NetworkStack'
|
|
3
|
-
export { ContentDeliveryManagerOptions, streamPartIdToDataKey } from './logic/ContentDeliveryManager'
|
|
4
|
-
export {
|
|
5
|
-
ContentType,
|
|
6
|
-
EncryptionType,
|
|
7
|
-
GroupKey,
|
|
8
|
-
GroupKeyRequest,
|
|
9
|
-
GroupKeyResponse,
|
|
10
|
-
MessageID,
|
|
11
|
-
MessageRef,
|
|
12
|
-
ProxyDirection,
|
|
13
|
-
SignatureType,
|
|
14
|
-
StreamMessage,
|
|
15
|
-
ControlLayerInfo
|
|
16
|
-
} from '../generated/packages/trackerless-network/protos/NetworkRpc'
|
|
17
|
-
export { ExternalRpcClient, ExternalRpcClientClass } from './logic/ExternalNetworkRpc'
|
|
18
|
-
export { NodeInfo, StreamPartitionInfo, ContentDeliveryLayerNeighborInfo } from './types'
|