@streamr/trackerless-network 100.2.2 → 100.2.4-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/README.md +1 -1
- package/dist/package.json +6 -6
- package/dist/src/NetworkStack.js +3 -5
- package/dist/src/NetworkStack.js.map +1 -1
- package/dist/src/logic/{RandomGraphNode.d.ts → ContentDeliveryLayerNode.d.ts} +6 -7
- package/dist/src/logic/{RandomGraphNode.js → ContentDeliveryLayerNode.js} +28 -42
- package/dist/src/logic/ContentDeliveryLayerNode.js.map +1 -0
- package/dist/src/logic/ContentDeliveryManager.d.ts +3 -3
- package/dist/src/logic/ContentDeliveryManager.js +4 -4
- package/dist/src/logic/ContentDeliveryManager.js.map +1 -1
- package/dist/src/logic/Layer1Node.d.ts +11 -12
- package/dist/src/logic/createContentDeliveryLayerNode.d.ts +10 -0
- package/dist/src/logic/{createRandomGraphNode.js → createContentDeliveryLayerNode.js} +6 -6
- package/dist/src/logic/createContentDeliveryLayerNode.js.map +1 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +8 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +4 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +10 -2
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +4 -0
- package/dist/test/benchmark/first-message.js +2 -1
- 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 +6 -6
- package/dist/test/utils/utils.js.map +1 -1
- package/package.json +6 -6
- package/src/NetworkStack.ts +3 -5
- package/src/logic/{RandomGraphNode.ts → ContentDeliveryLayerNode.ts} +31 -47
- package/src/logic/ContentDeliveryManager.ts +7 -7
- package/src/logic/Layer1Node.ts +11 -21
- package/src/logic/{createRandomGraphNode.ts → createContentDeliveryLayerNode.ts} +5 -5
- package/src/proto/packages/dht/protos/DhtRpc.client.ts +8 -0
- package/src/proto/packages/dht/protos/DhtRpc.server.ts +4 -0
- package/src/proto/packages/dht/protos/DhtRpc.ts +11 -3
- package/test/benchmark/first-message.ts +3 -2
- package/test/end-to-end/{random-graph-with-real-connections.test.ts → content-delivery-layer-node-with-real-connections.test.ts} +45 -45
- package/test/end-to-end/proxy-connections.test.ts +2 -2
- package/test/integration/{RandomGraphNode-Layer1Node-Latencies.test.ts → ContentDeliveryLayerNode-Layer1Node-Latencies.test.ts} +45 -46
- package/test/integration/{RandomGraphNode-Layer1Node.test.ts → ContentDeliveryLayerNode-Layer1Node.test.ts} +46 -48
- package/test/integration/Propagation.test.ts +20 -15
- package/test/unit/{RandomGraphNode.test.ts → ContentDeliveryLayerNode.test.ts} +15 -13
- package/test/utils/mock/MockLayer0Node.ts +10 -0
- package/test/utils/mock/MockLayer1Node.ts +22 -4
- package/test/utils/mock/Transport.ts +10 -1
- package/test/utils/utils.ts +6 -6
- package/dist/src/logic/RandomGraphNode.js.map +0 -1
- package/dist/src/logic/createRandomGraphNode.d.ts +0 -10
- package/dist/src/logic/createRandomGraphNode.js.map +0 -1
|
@@ -2,7 +2,7 @@ import { DhtAddress, ListeningRpcCommunicator, getNodeIdFromPeerDescriptor } fro
|
|
|
2
2
|
import { Handshaker } from './neighbor-discovery/Handshaker'
|
|
3
3
|
import { NeighborFinder } from './neighbor-discovery/NeighborFinder'
|
|
4
4
|
import { NeighborUpdateManager } from './neighbor-discovery/NeighborUpdateManager'
|
|
5
|
-
import {
|
|
5
|
+
import { StrictContentDeliveryLayerNodeConfig, ContentDeliveryLayerNode } from './ContentDeliveryLayerNode'
|
|
6
6
|
import { NodeList } from './NodeList'
|
|
7
7
|
import { Propagation } from './propagation/Propagation'
|
|
8
8
|
import { StreamMessage } from '../proto/packages/trackerless-network/protos/NetworkRpc'
|
|
@@ -12,7 +12,7 @@ import { Inspector } from './inspect/Inspector'
|
|
|
12
12
|
import { TemporaryConnectionRpcLocal } from './temporary-connection/TemporaryConnectionRpcLocal'
|
|
13
13
|
import { formStreamPartContentDeliveryServiceId } from './formStreamPartDeliveryServiceId'
|
|
14
14
|
|
|
15
|
-
type
|
|
15
|
+
type ContentDeliveryLayerNodeConfig = MarkOptional<StrictContentDeliveryLayerNodeConfig,
|
|
16
16
|
'nearbyNodeView' | 'randomNodeView' | 'neighbors' | 'leftNodeView' | 'rightNodeView' | 'propagation'
|
|
17
17
|
| 'handshaker' | 'neighborFinder' | 'neighborUpdateManager' | 'neighborTargetCount'
|
|
18
18
|
| 'rpcCommunicator' | 'nodeViewSize'
|
|
@@ -23,7 +23,7 @@ type RandomGraphNodeConfig = MarkOptional<StrictRandomGraphNodeConfig,
|
|
|
23
23
|
neighborUpdateInterval?: number
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
const createConfigWithDefaults = (config:
|
|
26
|
+
const createConfigWithDefaults = (config: ContentDeliveryLayerNodeConfig): StrictContentDeliveryLayerNodeConfig => {
|
|
27
27
|
const ownNodeId = getNodeIdFromPeerDescriptor(config.localPeerDescriptor)
|
|
28
28
|
const rpcCommunicator = config.rpcCommunicator ?? new ListeningRpcCommunicator(
|
|
29
29
|
formStreamPartContentDeliveryServiceId(config.streamPartId),
|
|
@@ -125,6 +125,6 @@ const createConfigWithDefaults = (config: RandomGraphNodeConfig): StrictRandomGr
|
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
-
export const
|
|
129
|
-
return new
|
|
128
|
+
export const createContentDeliveryLayerNode = (config: ContentDeliveryLayerNodeConfig): ContentDeliveryLayerNode => {
|
|
129
|
+
return new ContentDeliveryLayerNode(createConfigWithDefaults(config))
|
|
130
130
|
}
|
|
@@ -47,10 +47,14 @@ import type { RpcOptions } from "@protobuf-ts/runtime-rpc";
|
|
|
47
47
|
*/
|
|
48
48
|
export interface IDhtNodeRpcClient {
|
|
49
49
|
/**
|
|
50
|
+
* TODO rename to getClosestNeighbors (breaking change)
|
|
51
|
+
*
|
|
50
52
|
* @generated from protobuf rpc: getClosestPeers(dht.ClosestPeersRequest) returns (dht.ClosestPeersResponse);
|
|
51
53
|
*/
|
|
52
54
|
getClosestPeers(input: ClosestPeersRequest, options?: RpcOptions): UnaryCall<ClosestPeersRequest, ClosestPeersResponse>;
|
|
53
55
|
/**
|
|
56
|
+
* TODO rename to getClosestRingContacts (breaking change)
|
|
57
|
+
*
|
|
54
58
|
* @generated from protobuf rpc: getClosestRingPeers(dht.ClosestRingPeersRequest) returns (dht.ClosestRingPeersResponse);
|
|
55
59
|
*/
|
|
56
60
|
getClosestRingPeers(input: ClosestRingPeersRequest, options?: RpcOptions): UnaryCall<ClosestRingPeersRequest, ClosestRingPeersResponse>;
|
|
@@ -73,6 +77,8 @@ export class DhtNodeRpcClient implements IDhtNodeRpcClient, ServiceInfo {
|
|
|
73
77
|
constructor(private readonly _transport: RpcTransport) {
|
|
74
78
|
}
|
|
75
79
|
/**
|
|
80
|
+
* TODO rename to getClosestNeighbors (breaking change)
|
|
81
|
+
*
|
|
76
82
|
* @generated from protobuf rpc: getClosestPeers(dht.ClosestPeersRequest) returns (dht.ClosestPeersResponse);
|
|
77
83
|
*/
|
|
78
84
|
getClosestPeers(input: ClosestPeersRequest, options?: RpcOptions): UnaryCall<ClosestPeersRequest, ClosestPeersResponse> {
|
|
@@ -80,6 +86,8 @@ export class DhtNodeRpcClient implements IDhtNodeRpcClient, ServiceInfo {
|
|
|
80
86
|
return stackIntercept<ClosestPeersRequest, ClosestPeersResponse>("unary", this._transport, method, opt, input);
|
|
81
87
|
}
|
|
82
88
|
/**
|
|
89
|
+
* TODO rename to getClosestRingContacts (breaking change)
|
|
90
|
+
*
|
|
83
91
|
* @generated from protobuf rpc: getClosestRingPeers(dht.ClosestRingPeersRequest) returns (dht.ClosestRingPeersResponse);
|
|
84
92
|
*/
|
|
85
93
|
getClosestRingPeers(input: ClosestRingPeersRequest, options?: RpcOptions): UnaryCall<ClosestRingPeersRequest, ClosestRingPeersResponse> {
|
|
@@ -34,10 +34,14 @@ import { ServerCallContext } from "@protobuf-ts/runtime-rpc";
|
|
|
34
34
|
*/
|
|
35
35
|
export interface IDhtNodeRpc<T = ServerCallContext> {
|
|
36
36
|
/**
|
|
37
|
+
* TODO rename to getClosestNeighbors (breaking change)
|
|
38
|
+
*
|
|
37
39
|
* @generated from protobuf rpc: getClosestPeers(dht.ClosestPeersRequest) returns (dht.ClosestPeersResponse);
|
|
38
40
|
*/
|
|
39
41
|
getClosestPeers(request: ClosestPeersRequest, context: T): Promise<ClosestPeersResponse>;
|
|
40
42
|
/**
|
|
43
|
+
* TODO rename to getClosestRingContacts (breaking change)
|
|
44
|
+
*
|
|
41
45
|
* @generated from protobuf rpc: getClosestRingPeers(dht.ClosestRingPeersRequest) returns (dht.ClosestRingPeersResponse);
|
|
42
46
|
*/
|
|
43
47
|
getClosestRingPeers(request: ClosestRingPeersRequest, context: T): Promise<ClosestRingPeersResponse>;
|
|
@@ -108,6 +108,8 @@ export interface DataEntry {
|
|
|
108
108
|
deleted: boolean;
|
|
109
109
|
}
|
|
110
110
|
/**
|
|
111
|
+
* TODO rename to ClosestNeighborsRequest
|
|
112
|
+
*
|
|
111
113
|
* @generated from protobuf message dht.ClosestPeersRequest
|
|
112
114
|
*/
|
|
113
115
|
export interface ClosestPeersRequest {
|
|
@@ -121,6 +123,8 @@ export interface ClosestPeersRequest {
|
|
|
121
123
|
requestId: string;
|
|
122
124
|
}
|
|
123
125
|
/**
|
|
126
|
+
* TODO rename to ClosestPeersResponse
|
|
127
|
+
*
|
|
124
128
|
* @generated from protobuf message dht.ClosestPeersResponse
|
|
125
129
|
*/
|
|
126
130
|
export interface ClosestPeersResponse {
|
|
@@ -134,6 +138,8 @@ export interface ClosestPeersResponse {
|
|
|
134
138
|
requestId: string;
|
|
135
139
|
}
|
|
136
140
|
/**
|
|
141
|
+
* TODO rename to ClosestRingContactsRequest
|
|
142
|
+
*
|
|
137
143
|
* @generated from protobuf message dht.ClosestRingPeersRequest
|
|
138
144
|
*/
|
|
139
145
|
export interface ClosestRingPeersRequest {
|
|
@@ -147,6 +153,8 @@ export interface ClosestRingPeersRequest {
|
|
|
147
153
|
requestId: string;
|
|
148
154
|
}
|
|
149
155
|
/**
|
|
156
|
+
* TODO rename to ClosestRingContactsResponse
|
|
157
|
+
*
|
|
150
158
|
* @generated from protobuf message dht.ClosestRingPeersResponse
|
|
151
159
|
*/
|
|
152
160
|
export interface ClosestRingPeersResponse {
|
|
@@ -181,9 +189,9 @@ export interface RecursiveOperationRequest {
|
|
|
181
189
|
*/
|
|
182
190
|
export interface RecursiveOperationResponse {
|
|
183
191
|
/**
|
|
184
|
-
* @generated from protobuf field: repeated dht.PeerDescriptor
|
|
192
|
+
* @generated from protobuf field: repeated dht.PeerDescriptor closestConnectedNodes = 1;
|
|
185
193
|
*/
|
|
186
|
-
|
|
194
|
+
closestConnectedNodes: PeerDescriptor[];
|
|
187
195
|
/**
|
|
188
196
|
* @generated from protobuf field: repeated dht.DataEntry dataEntries = 2;
|
|
189
197
|
*/
|
|
@@ -837,7 +845,7 @@ export const RecursiveOperationRequest = new RecursiveOperationRequest$Type();
|
|
|
837
845
|
class RecursiveOperationResponse$Type extends MessageType<RecursiveOperationResponse> {
|
|
838
846
|
constructor() {
|
|
839
847
|
super("dht.RecursiveOperationResponse", [
|
|
840
|
-
{ no: 1, name: "
|
|
848
|
+
{ no: 1, name: "closestConnectedNodes", kind: "message", repeat: 1 /*RepeatType.PACKED*/, T: () => PeerDescriptor },
|
|
841
849
|
{ no: 2, name: "dataEntries", kind: "message", repeat: 1 /*RepeatType.PACKED*/, T: () => DataEntry },
|
|
842
850
|
{ no: 3, name: "noCloserNodesFound", kind: "scalar", T: 8 /*ScalarType.BOOL*/ },
|
|
843
851
|
{ no: 4, name: "routingPath", kind: "message", repeat: 1 /*RepeatType.PACKED*/, T: () => PeerDescriptor }
|
|
@@ -26,7 +26,7 @@ import { NetworkNode } from '../../src/NetworkNode'
|
|
|
26
26
|
import { streamPartIdToDataKey } from '../../src/logic/EntryPointDiscovery'
|
|
27
27
|
import { createMockPeerDescriptor, createNetworkNodeWithSimulator } from '../utils/utils'
|
|
28
28
|
import { Layer1Node } from '../../src/logic/Layer1Node'
|
|
29
|
-
import {
|
|
29
|
+
import { ContentDeliveryLayerNode } from '../../src/logic/ContentDeliveryLayerNode'
|
|
30
30
|
|
|
31
31
|
const numNodes = 10000
|
|
32
32
|
|
|
@@ -160,7 +160,8 @@ run().then(() => {
|
|
|
160
160
|
const layer0Node = currentNode.stack.getLayer0Node() as DhtNode
|
|
161
161
|
console.log(layer0Node.getNeighbors().length)
|
|
162
162
|
console.log(layer0Node.getConnectionCount())
|
|
163
|
-
const streamPartDelivery = contentDeliveryManager
|
|
163
|
+
const streamPartDelivery = contentDeliveryManager
|
|
164
|
+
.getStreamPartDelivery(streamParts[0])! as { layer1Node: Layer1Node, node: ContentDeliveryLayerNode }
|
|
164
165
|
console.log(streamPartDelivery.layer1Node.getNeighbors())
|
|
165
166
|
console.log(streamPartDelivery.node.getNeighbors())
|
|
166
167
|
console.log(nodes[nodes.length - 1])
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { ConnectionManager, DhtNode, PeerDescriptor } from '@streamr/dht'
|
|
2
|
-
import {
|
|
2
|
+
import { ContentDeliveryLayerNode } from '../../src/logic/ContentDeliveryLayerNode'
|
|
3
3
|
import { waitForCondition } from '@streamr/utils'
|
|
4
4
|
import { createMockPeerDescriptor, createStreamMessage } from '../utils/utils'
|
|
5
|
-
import {
|
|
5
|
+
import { createContentDeliveryLayerNode } from '../../src/logic/createContentDeliveryLayerNode'
|
|
6
6
|
import { StreamPartIDUtils } from '@streamr/protocol'
|
|
7
7
|
import { randomEthereumAddress } from '@streamr/test-utils'
|
|
8
8
|
import { Layer0Node } from '../../src/logic/Layer0Node'
|
|
9
9
|
import { Layer1Node } from '../../src/logic/Layer1Node'
|
|
10
10
|
|
|
11
|
-
describe('
|
|
11
|
+
describe('content delivery layer node with real connections', () => {
|
|
12
12
|
|
|
13
13
|
const epPeerDescriptor: PeerDescriptor = createMockPeerDescriptor({
|
|
14
14
|
websocket: { host: '127.0.0.1', port: 12221, tls: false }
|
|
@@ -23,11 +23,11 @@ describe('random graph with real connections', () => {
|
|
|
23
23
|
let dhtNode2: Layer0Node & Layer1Node
|
|
24
24
|
let dhtNode3: Layer0Node & Layer1Node
|
|
25
25
|
let dhtNode4: Layer0Node & Layer1Node
|
|
26
|
-
let
|
|
27
|
-
let
|
|
28
|
-
let
|
|
29
|
-
let
|
|
30
|
-
let
|
|
26
|
+
let contentDeliveryLayerNode1: ContentDeliveryLayerNode
|
|
27
|
+
let contentDeliveryLayerNode2: ContentDeliveryLayerNode
|
|
28
|
+
let contentDeliveryLayerNode3: ContentDeliveryLayerNode
|
|
29
|
+
let contentDeliveryLayerNode4: ContentDeliveryLayerNode
|
|
30
|
+
let contentDeliveryLayerNode5: ContentDeliveryLayerNode
|
|
31
31
|
const websocketPortRange = { min: 12222, max: 12225 }
|
|
32
32
|
|
|
33
33
|
beforeEach(async () => {
|
|
@@ -42,7 +42,7 @@ describe('random graph with real connections', () => {
|
|
|
42
42
|
await dhtNode3.start()
|
|
43
43
|
await dhtNode4.start()
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
contentDeliveryLayerNode1 = createContentDeliveryLayerNode(
|
|
46
46
|
{
|
|
47
47
|
streamPartId,
|
|
48
48
|
layer1Node: epDhtNode,
|
|
@@ -52,7 +52,7 @@ describe('random graph with real connections', () => {
|
|
|
52
52
|
isLocalNodeEntryPoint: () => false
|
|
53
53
|
}
|
|
54
54
|
)
|
|
55
|
-
|
|
55
|
+
contentDeliveryLayerNode2 = createContentDeliveryLayerNode({
|
|
56
56
|
streamPartId,
|
|
57
57
|
layer1Node: dhtNode1,
|
|
58
58
|
transport: dhtNode1.getTransport(),
|
|
@@ -60,7 +60,7 @@ describe('random graph with real connections', () => {
|
|
|
60
60
|
localPeerDescriptor: dhtNode1.getLocalPeerDescriptor(),
|
|
61
61
|
isLocalNodeEntryPoint: () => false
|
|
62
62
|
})
|
|
63
|
-
|
|
63
|
+
contentDeliveryLayerNode3 = createContentDeliveryLayerNode({
|
|
64
64
|
streamPartId,
|
|
65
65
|
layer1Node: dhtNode2,
|
|
66
66
|
transport: dhtNode2.getTransport(),
|
|
@@ -68,7 +68,7 @@ describe('random graph with real connections', () => {
|
|
|
68
68
|
localPeerDescriptor: dhtNode2.getLocalPeerDescriptor(),
|
|
69
69
|
isLocalNodeEntryPoint: () => false
|
|
70
70
|
})
|
|
71
|
-
|
|
71
|
+
contentDeliveryLayerNode4 = createContentDeliveryLayerNode({
|
|
72
72
|
streamPartId,
|
|
73
73
|
layer1Node: dhtNode3,
|
|
74
74
|
transport: dhtNode3.getTransport(),
|
|
@@ -76,7 +76,7 @@ describe('random graph with real connections', () => {
|
|
|
76
76
|
localPeerDescriptor: dhtNode3.getLocalPeerDescriptor(),
|
|
77
77
|
isLocalNodeEntryPoint: () => false
|
|
78
78
|
})
|
|
79
|
-
|
|
79
|
+
contentDeliveryLayerNode5 = createContentDeliveryLayerNode({
|
|
80
80
|
streamPartId,
|
|
81
81
|
layer1Node: dhtNode4,
|
|
82
82
|
transport: dhtNode4.getTransport(),
|
|
@@ -84,6 +84,13 @@ describe('random graph with real connections', () => {
|
|
|
84
84
|
localPeerDescriptor: dhtNode4.getLocalPeerDescriptor(),
|
|
85
85
|
isLocalNodeEntryPoint: () => false
|
|
86
86
|
})
|
|
87
|
+
await Promise.all([
|
|
88
|
+
contentDeliveryLayerNode1.start(),
|
|
89
|
+
contentDeliveryLayerNode2.start(),
|
|
90
|
+
contentDeliveryLayerNode3.start(),
|
|
91
|
+
contentDeliveryLayerNode4.start(),
|
|
92
|
+
contentDeliveryLayerNode5.start()
|
|
93
|
+
])
|
|
87
94
|
await epDhtNode.joinDht([epPeerDescriptor])
|
|
88
95
|
await Promise.all([
|
|
89
96
|
dhtNode1.joinDht([epPeerDescriptor]),
|
|
@@ -91,13 +98,6 @@ describe('random graph with real connections', () => {
|
|
|
91
98
|
dhtNode3.joinDht([epPeerDescriptor]),
|
|
92
99
|
dhtNode4.joinDht([epPeerDescriptor])
|
|
93
100
|
])
|
|
94
|
-
await Promise.all([
|
|
95
|
-
randomGraphNode1.start(),
|
|
96
|
-
randomGraphNode2.start(),
|
|
97
|
-
randomGraphNode3.start(),
|
|
98
|
-
randomGraphNode4.start(),
|
|
99
|
-
randomGraphNode5.start()
|
|
100
|
-
])
|
|
101
101
|
})
|
|
102
102
|
|
|
103
103
|
afterEach(async () => {
|
|
@@ -107,11 +107,11 @@ describe('random graph with real connections', () => {
|
|
|
107
107
|
dhtNode2.stop(),
|
|
108
108
|
dhtNode3.stop(),
|
|
109
109
|
dhtNode4.stop(),
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
110
|
+
contentDeliveryLayerNode1.stop(),
|
|
111
|
+
contentDeliveryLayerNode2.stop(),
|
|
112
|
+
contentDeliveryLayerNode3.stop(),
|
|
113
|
+
contentDeliveryLayerNode4.stop(),
|
|
114
|
+
contentDeliveryLayerNode5.stop(),
|
|
115
115
|
(epDhtNode.getTransport() as ConnectionManager).stop(),
|
|
116
116
|
(dhtNode1.getTransport() as ConnectionManager).stop(),
|
|
117
117
|
(dhtNode2.getTransport() as ConnectionManager).stop(),
|
|
@@ -122,32 +122,32 @@ describe('random graph with real connections', () => {
|
|
|
122
122
|
|
|
123
123
|
it('can fully connected topologies ', async () => {
|
|
124
124
|
await waitForCondition(() => {
|
|
125
|
-
return
|
|
126
|
-
&&
|
|
127
|
-
&&
|
|
128
|
-
&&
|
|
129
|
-
&&
|
|
125
|
+
return contentDeliveryLayerNode1.getNeighbors().length >= 3
|
|
126
|
+
&& contentDeliveryLayerNode2.getNeighbors().length >= 3
|
|
127
|
+
&& contentDeliveryLayerNode3.getNeighbors().length >= 3
|
|
128
|
+
&& contentDeliveryLayerNode4.getNeighbors().length >= 3
|
|
129
|
+
&& contentDeliveryLayerNode5.getNeighbors().length >= 3
|
|
130
130
|
}, 10000)
|
|
131
|
-
expect(
|
|
132
|
-
expect(
|
|
133
|
-
expect(
|
|
134
|
-
expect(
|
|
135
|
-
expect(
|
|
131
|
+
expect(contentDeliveryLayerNode1.getNeighbors().length).toBeGreaterThanOrEqual(3)
|
|
132
|
+
expect(contentDeliveryLayerNode2.getNeighbors().length).toBeGreaterThanOrEqual(3)
|
|
133
|
+
expect(contentDeliveryLayerNode3.getNeighbors().length).toBeGreaterThanOrEqual(3)
|
|
134
|
+
expect(contentDeliveryLayerNode4.getNeighbors().length).toBeGreaterThanOrEqual(3)
|
|
135
|
+
expect(contentDeliveryLayerNode5.getNeighbors().length).toBeGreaterThanOrEqual(3)
|
|
136
136
|
})
|
|
137
137
|
|
|
138
138
|
it('can propagate messages', async () => {
|
|
139
139
|
let receivedMessageCount = 0
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
140
|
+
contentDeliveryLayerNode2.on('message', () => receivedMessageCount += 1)
|
|
141
|
+
contentDeliveryLayerNode3.on('message', () => receivedMessageCount += 1)
|
|
142
|
+
contentDeliveryLayerNode4.on('message', () => receivedMessageCount += 1)
|
|
143
|
+
contentDeliveryLayerNode5.on('message', () => receivedMessageCount += 1)
|
|
144
144
|
|
|
145
145
|
await waitForCondition(() => {
|
|
146
|
-
return
|
|
147
|
-
&&
|
|
148
|
-
&&
|
|
149
|
-
&&
|
|
150
|
-
&&
|
|
146
|
+
return contentDeliveryLayerNode1.getNeighbors().length >= 3
|
|
147
|
+
&& contentDeliveryLayerNode2.getNeighbors().length >= 3
|
|
148
|
+
&& contentDeliveryLayerNode3.getNeighbors().length >= 3
|
|
149
|
+
&& contentDeliveryLayerNode4.getNeighbors().length >= 3
|
|
150
|
+
&& contentDeliveryLayerNode5.getNeighbors().length >= 3
|
|
151
151
|
}, 10000)
|
|
152
152
|
|
|
153
153
|
const msg = createStreamMessage(
|
|
@@ -155,7 +155,7 @@ describe('random graph with real connections', () => {
|
|
|
155
155
|
streamPartId,
|
|
156
156
|
randomEthereumAddress()
|
|
157
157
|
)
|
|
158
|
-
|
|
158
|
+
contentDeliveryLayerNode1.broadcast(msg)
|
|
159
159
|
await waitForCondition(() => receivedMessageCount >= 4)
|
|
160
160
|
})
|
|
161
161
|
})
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
import { randomEthereumAddress } from '@streamr/test-utils'
|
|
12
12
|
import { hexToBinary, utf8ToBinary, wait, waitForCondition, waitForEvent3 } from '@streamr/utils'
|
|
13
13
|
import { NetworkNode, createNetworkNode } from '../../src/NetworkNode'
|
|
14
|
-
import {
|
|
14
|
+
import { ContentDeliveryLayerNode } from '../../src/logic/ContentDeliveryLayerNode'
|
|
15
15
|
import { ProxyClient } from '../../src/logic/proxy/ProxyClient'
|
|
16
16
|
import { ProxyDirection } from '../../src/proto/packages/trackerless-network/protos/NetworkRpc'
|
|
17
17
|
import { createMockPeerDescriptor } from '../utils/utils'
|
|
@@ -48,7 +48,7 @@ describe('Proxy connections', () => {
|
|
|
48
48
|
const hasConnectionFromProxy = (proxyNode: NetworkNode): boolean => {
|
|
49
49
|
const delivery = proxyNode.stack.getContentDeliveryManager().getStreamPartDelivery(STREAM_PART_ID)
|
|
50
50
|
return (delivery !== undefined)
|
|
51
|
-
? ((delivery as { node:
|
|
51
|
+
? ((delivery as { node: ContentDeliveryLayerNode }).node).hasProxyConnection(proxiedNode.getNodeId())
|
|
52
52
|
: false
|
|
53
53
|
}
|
|
54
54
|
|
|
@@ -1,97 +1,96 @@
|
|
|
1
1
|
import { DhtNode, LatencyType, PeerDescriptor, Simulator, SimulatorTransport, getNodeIdFromPeerDescriptor } from '@streamr/dht'
|
|
2
2
|
import { waitForCondition } from '@streamr/utils'
|
|
3
3
|
import { range } from 'lodash'
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { ContentDeliveryLayerNode } from '../../src/logic/ContentDeliveryLayerNode'
|
|
5
|
+
import { createContentDeliveryLayerNode } from '../../src/logic/createContentDeliveryLayerNode'
|
|
6
6
|
import { createMockPeerDescriptor } from '../utils/utils'
|
|
7
7
|
import { StreamPartIDUtils } from '@streamr/protocol'
|
|
8
8
|
import { Layer1Node } from '../../src/logic/Layer1Node'
|
|
9
9
|
|
|
10
|
-
describe('
|
|
11
|
-
const
|
|
12
|
-
let
|
|
13
|
-
let
|
|
14
|
-
let
|
|
15
|
-
let
|
|
10
|
+
describe('ContentDeliveryLayerNode-DhtNode-Latencies', () => {
|
|
11
|
+
const otherNodeCount = 64
|
|
12
|
+
let otherLayer1Nodes: Layer1Node[]
|
|
13
|
+
let entryPointLayer1Node: Layer1Node
|
|
14
|
+
let entryPointContentDeliveryLayerNode: ContentDeliveryLayerNode
|
|
15
|
+
let otherContentDeliveryLayerNodes: ContentDeliveryLayerNode[]
|
|
16
16
|
|
|
17
17
|
const streamPartId = StreamPartIDUtils.parse('stream#0')
|
|
18
18
|
const entrypointDescriptor = createMockPeerDescriptor()
|
|
19
19
|
|
|
20
|
-
const peerDescriptors: PeerDescriptor[] = range(
|
|
20
|
+
const peerDescriptors: PeerDescriptor[] = range(otherNodeCount).map(() => createMockPeerDescriptor())
|
|
21
21
|
beforeEach(async () => {
|
|
22
22
|
const simulator = new Simulator(LatencyType.FIXED, 50)
|
|
23
23
|
const entrypointCm = new SimulatorTransport(entrypointDescriptor, simulator)
|
|
24
|
-
const cms: SimulatorTransport[] = range(
|
|
24
|
+
const cms: SimulatorTransport[] = range(otherNodeCount).map((i) =>
|
|
25
25
|
new SimulatorTransport(peerDescriptors[i], simulator)
|
|
26
26
|
)
|
|
27
27
|
await entrypointCm.start()
|
|
28
28
|
await Promise.all(cms.map((cm) => cm.start()))
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
entryPointLayer1Node = new DhtNode({
|
|
31
31
|
transport: entrypointCm,
|
|
32
32
|
peerDescriptor: entrypointDescriptor,
|
|
33
33
|
serviceId: streamPartId
|
|
34
34
|
})
|
|
35
|
-
|
|
35
|
+
otherLayer1Nodes = range(otherNodeCount).map((i) => new DhtNode({
|
|
36
36
|
transport: cms[i],
|
|
37
37
|
peerDescriptor: peerDescriptors[i],
|
|
38
38
|
serviceId: streamPartId
|
|
39
39
|
}))
|
|
40
|
-
|
|
40
|
+
otherContentDeliveryLayerNodes = range(otherNodeCount).map((i) => createContentDeliveryLayerNode({
|
|
41
41
|
streamPartId,
|
|
42
|
-
layer1Node:
|
|
42
|
+
layer1Node: otherLayer1Nodes[i],
|
|
43
43
|
transport: cms[i],
|
|
44
44
|
connectionLocker: cms[i],
|
|
45
45
|
localPeerDescriptor: peerDescriptors[i],
|
|
46
46
|
isLocalNodeEntryPoint: () => false
|
|
47
47
|
}))
|
|
48
|
-
|
|
48
|
+
entryPointContentDeliveryLayerNode = createContentDeliveryLayerNode({
|
|
49
49
|
streamPartId,
|
|
50
|
-
layer1Node:
|
|
50
|
+
layer1Node: entryPointLayer1Node,
|
|
51
51
|
transport: entrypointCm,
|
|
52
52
|
connectionLocker: entrypointCm,
|
|
53
53
|
localPeerDescriptor: entrypointDescriptor,
|
|
54
54
|
isLocalNodeEntryPoint: () => false
|
|
55
55
|
})
|
|
56
56
|
|
|
57
|
-
await
|
|
58
|
-
|
|
59
|
-
await
|
|
57
|
+
await entryPointLayer1Node.start()
|
|
58
|
+
entryPointContentDeliveryLayerNode.start()
|
|
59
|
+
await entryPointLayer1Node.joinDht([entrypointDescriptor])
|
|
60
|
+
await Promise.all(otherLayer1Nodes.map((node) => node.start()))
|
|
60
61
|
})
|
|
61
62
|
|
|
62
63
|
afterEach(async () => {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
await Promise.all(
|
|
66
|
-
await Promise.all(
|
|
64
|
+
entryPointLayer1Node.stop()
|
|
65
|
+
entryPointContentDeliveryLayerNode.stop()
|
|
66
|
+
await Promise.all(otherLayer1Nodes.map((node) => node.stop()))
|
|
67
|
+
await Promise.all(otherContentDeliveryLayerNodes.map((node) => node.stop()))
|
|
67
68
|
})
|
|
68
69
|
|
|
69
70
|
it('happy path single node', async () => {
|
|
70
|
-
await
|
|
71
|
-
|
|
72
|
-
await graphNodes[0].start()
|
|
71
|
+
await otherContentDeliveryLayerNodes[0].start()
|
|
72
|
+
await otherLayer1Nodes[0].joinDht([entrypointDescriptor])
|
|
73
73
|
await Promise.all([
|
|
74
|
-
waitForCondition(() =>
|
|
75
|
-
waitForCondition(() =>
|
|
74
|
+
waitForCondition(() => otherContentDeliveryLayerNodes[0].getNearbyNodeView().getIds().length === 1),
|
|
75
|
+
waitForCondition(() => otherContentDeliveryLayerNodes[0].getNeighbors().length === 1)
|
|
76
76
|
])
|
|
77
|
-
expect(
|
|
78
|
-
expect(
|
|
77
|
+
expect(otherContentDeliveryLayerNodes[0].getNearbyNodeView().getIds().length).toEqual(1)
|
|
78
|
+
expect(otherContentDeliveryLayerNodes[0].getNeighbors().length).toEqual(1)
|
|
79
79
|
})
|
|
80
80
|
|
|
81
81
|
it('happy path 5 nodes', async () => {
|
|
82
|
-
|
|
83
|
-
range(4).forEach((i) => graphNodes[i].start())
|
|
82
|
+
range(4).forEach((i) => otherContentDeliveryLayerNodes[i].start())
|
|
84
83
|
await Promise.all(range(4).map(async (i) => {
|
|
85
|
-
await
|
|
84
|
+
await otherLayer1Nodes[i].joinDht([entrypointDescriptor])
|
|
86
85
|
}))
|
|
87
|
-
await waitForCondition(() => range(4).every((i) =>
|
|
86
|
+
await waitForCondition(() => range(4).every((i) => otherContentDeliveryLayerNodes[i].getNeighbors().length >= 4), 15000, 1000)
|
|
88
87
|
range(4).forEach((i) => {
|
|
89
|
-
expect(
|
|
90
|
-
expect(
|
|
88
|
+
expect(otherContentDeliveryLayerNodes[i].getNearbyNodeView().getIds().length).toBeGreaterThanOrEqual(4)
|
|
89
|
+
expect(otherContentDeliveryLayerNodes[i].getNeighbors().length).toBeGreaterThanOrEqual(4)
|
|
91
90
|
})
|
|
92
91
|
// Check bidirectionality
|
|
93
|
-
const allNodes =
|
|
94
|
-
allNodes.push(
|
|
92
|
+
const allNodes = otherContentDeliveryLayerNodes
|
|
93
|
+
allNodes.push(entryPointContentDeliveryLayerNode)
|
|
95
94
|
range(5).forEach((i) => {
|
|
96
95
|
const ownNodeId = allNodes[i].getOwnNodeId()
|
|
97
96
|
allNodes[i].getNearbyNodeView().getIds().forEach((nodeId) => {
|
|
@@ -105,26 +104,26 @@ describe('RandomGraphNode-DhtNode-Latencies', () => {
|
|
|
105
104
|
}, 60000)
|
|
106
105
|
|
|
107
106
|
it('happy path 64 nodes', async () => {
|
|
108
|
-
await Promise.all(range(
|
|
109
|
-
await Promise.all(range(
|
|
110
|
-
|
|
107
|
+
await Promise.all(range(otherNodeCount).map((i) => otherContentDeliveryLayerNodes[i].start()))
|
|
108
|
+
await Promise.all(range(otherNodeCount).map((i) => {
|
|
109
|
+
otherLayer1Nodes[i].joinDht([entrypointDescriptor])
|
|
111
110
|
}))
|
|
112
|
-
await Promise.all(
|
|
111
|
+
await Promise.all(otherContentDeliveryLayerNodes.map((node) =>
|
|
113
112
|
waitForCondition(() => node.getNeighbors().length >= 4, 10000)
|
|
114
113
|
))
|
|
115
114
|
|
|
116
|
-
await Promise.all(
|
|
115
|
+
await Promise.all(otherContentDeliveryLayerNodes.map((node) =>
|
|
117
116
|
waitForCondition(() => node.getOutgoingHandshakeCount() === 0)
|
|
118
117
|
))
|
|
119
118
|
|
|
120
119
|
await waitForCondition(() => {
|
|
121
120
|
let mismatchCounter = 0
|
|
122
|
-
|
|
121
|
+
otherContentDeliveryLayerNodes.forEach((node) => {
|
|
123
122
|
const nodeId = node.getOwnNodeId()
|
|
124
123
|
node.getNeighbors().forEach((neighbor) => {
|
|
125
124
|
const neighborId = getNodeIdFromPeerDescriptor(neighbor)
|
|
126
|
-
if (neighborId !==
|
|
127
|
-
const neighbor =
|
|
125
|
+
if (neighborId !== entryPointContentDeliveryLayerNode.getOwnNodeId()) {
|
|
126
|
+
const neighbor = otherContentDeliveryLayerNodes.find((n) => n.getOwnNodeId() === neighborId)
|
|
128
127
|
const neighborIds = neighbor!.getNeighbors().map((n) => getNodeIdFromPeerDescriptor(n))
|
|
129
128
|
if (!neighborIds.includes(nodeId)) {
|
|
130
129
|
mismatchCounter += 1
|