@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
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
import { DhtAddress } from '@streamr/dht'
|
|
2
|
-
import { randomUserId } from '@streamr/test-utils'
|
|
3
|
-
import { StreamPartIDUtils, hexToBinary, toUserIdRaw, utf8ToBinary, wait, until, waitForEvent3 } from '@streamr/utils'
|
|
4
|
-
import { NetworkNode, createNetworkNode } from '../../src/NetworkNode'
|
|
5
|
-
import { ContentDeliveryLayerNode } from '../../src/logic/ContentDeliveryLayerNode'
|
|
6
|
-
import { ProxyClient } from '../../src/logic/proxy/ProxyClient'
|
|
7
|
-
import {
|
|
8
|
-
ContentType,
|
|
9
|
-
EncryptionType,
|
|
10
|
-
ProxyDirection,
|
|
11
|
-
SignatureType,
|
|
12
|
-
StreamMessage
|
|
13
|
-
} from '../../generated/packages/trackerless-network/protos/NetworkRpc'
|
|
14
|
-
import { createMockPeerDescriptor } from '../utils/utils'
|
|
15
|
-
|
|
16
|
-
const PROXIED_NODE_USER_ID = randomUserId()
|
|
17
|
-
const STREAM_PART_ID = StreamPartIDUtils.parse('proxy-test#0')
|
|
18
|
-
const MESSAGE: StreamMessage = {
|
|
19
|
-
messageId: {
|
|
20
|
-
streamId: StreamPartIDUtils.getStreamID(STREAM_PART_ID),
|
|
21
|
-
streamPartition: StreamPartIDUtils.getStreamPartition(STREAM_PART_ID),
|
|
22
|
-
timestamp: 666,
|
|
23
|
-
sequenceNumber: 0,
|
|
24
|
-
publisherId: toUserIdRaw(randomUserId()),
|
|
25
|
-
messageChainId: 'msgChainId'
|
|
26
|
-
},
|
|
27
|
-
previousMessageRef: {
|
|
28
|
-
timestamp: 665,
|
|
29
|
-
sequenceNumber: 0
|
|
30
|
-
},
|
|
31
|
-
body: {
|
|
32
|
-
oneofKind: 'contentMessage',
|
|
33
|
-
contentMessage: {
|
|
34
|
-
content: utf8ToBinary(JSON.stringify({
|
|
35
|
-
hello: 'world'
|
|
36
|
-
})),
|
|
37
|
-
contentType: ContentType.JSON,
|
|
38
|
-
encryptionType: EncryptionType.NONE,
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
signatureType: SignatureType.SECP256K1,
|
|
42
|
-
signature: hexToBinary('0x1234')
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
describe('Proxy connections', () => {
|
|
46
|
-
|
|
47
|
-
let proxyNode1: NetworkNode
|
|
48
|
-
let proxyNode2: NetworkNode
|
|
49
|
-
let proxiedNode: NetworkNode
|
|
50
|
-
|
|
51
|
-
const hasConnectionFromProxy = (proxyNode: NetworkNode): boolean => {
|
|
52
|
-
const delivery = proxyNode.stack.getContentDeliveryManager().getStreamPartDelivery(STREAM_PART_ID)
|
|
53
|
-
return (delivery !== undefined)
|
|
54
|
-
? ((delivery as { node: ContentDeliveryLayerNode }).node).hasProxyConnection(proxiedNode.getNodeId())
|
|
55
|
-
: false
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const hasConnectionToProxy = (proxyNodeId: DhtAddress, direction: ProxyDirection): boolean => {
|
|
59
|
-
const client = (proxiedNode.stack.getContentDeliveryManager().getStreamPartDelivery(STREAM_PART_ID) as { client: ProxyClient }).client
|
|
60
|
-
return client.hasConnection(proxyNodeId, direction)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
beforeEach(async () => {
|
|
64
|
-
const proxyNodeDescriptor1 = createMockPeerDescriptor({
|
|
65
|
-
websocket: { host: '127.0.0.1', port: 23132, tls: false }
|
|
66
|
-
})
|
|
67
|
-
const proxyNodeDescriptor2 = createMockPeerDescriptor({
|
|
68
|
-
websocket: { host: '127.0.0.1', port: 23133, tls: false }
|
|
69
|
-
})
|
|
70
|
-
const proxiedNodeDescriptor = createMockPeerDescriptor()
|
|
71
|
-
proxyNode1 = createNetworkNode({
|
|
72
|
-
layer0: {
|
|
73
|
-
entryPoints: [proxyNodeDescriptor1],
|
|
74
|
-
peerDescriptor: proxyNodeDescriptor1,
|
|
75
|
-
websocketServerEnableTls: false
|
|
76
|
-
},
|
|
77
|
-
networkNode: {
|
|
78
|
-
acceptProxyConnections: true
|
|
79
|
-
}
|
|
80
|
-
})
|
|
81
|
-
await proxyNode1.start()
|
|
82
|
-
proxyNode1.stack.getContentDeliveryManager().joinStreamPart(STREAM_PART_ID)
|
|
83
|
-
proxyNode2 = createNetworkNode({
|
|
84
|
-
layer0: {
|
|
85
|
-
entryPoints: [proxyNodeDescriptor1],
|
|
86
|
-
peerDescriptor: proxyNodeDescriptor2,
|
|
87
|
-
websocketServerEnableTls: false
|
|
88
|
-
},
|
|
89
|
-
networkNode: {
|
|
90
|
-
acceptProxyConnections: true
|
|
91
|
-
}
|
|
92
|
-
})
|
|
93
|
-
await proxyNode2.start()
|
|
94
|
-
proxyNode2.stack.getContentDeliveryManager().joinStreamPart(STREAM_PART_ID)
|
|
95
|
-
proxiedNode = createNetworkNode({
|
|
96
|
-
layer0: {
|
|
97
|
-
entryPoints: [proxyNode1.getPeerDescriptor()],
|
|
98
|
-
peerDescriptor: proxiedNodeDescriptor,
|
|
99
|
-
}
|
|
100
|
-
})
|
|
101
|
-
await proxiedNode.start(false)
|
|
102
|
-
}, 30000)
|
|
103
|
-
|
|
104
|
-
afterEach(async () => {
|
|
105
|
-
await proxyNode1.stop()
|
|
106
|
-
await proxyNode2.stop()
|
|
107
|
-
await proxiedNode.stop()
|
|
108
|
-
})
|
|
109
|
-
|
|
110
|
-
it('happy path publishing', async () => {
|
|
111
|
-
await proxiedNode.setProxies(STREAM_PART_ID, [proxyNode1.getPeerDescriptor()], ProxyDirection.PUBLISH, PROXIED_NODE_USER_ID, 1)
|
|
112
|
-
await Promise.all([
|
|
113
|
-
waitForEvent3(proxyNode1.stack.getContentDeliveryManager() as any, 'newMessage'),
|
|
114
|
-
proxiedNode.broadcast(MESSAGE)
|
|
115
|
-
])
|
|
116
|
-
})
|
|
117
|
-
|
|
118
|
-
it('happy path subscribing', async () => {
|
|
119
|
-
await proxiedNode.setProxies(STREAM_PART_ID, [proxyNode1.getPeerDescriptor()], ProxyDirection.SUBSCRIBE, PROXIED_NODE_USER_ID, 1)
|
|
120
|
-
await Promise.all([
|
|
121
|
-
waitForEvent3(proxiedNode.stack.getContentDeliveryManager() as any, 'newMessage'),
|
|
122
|
-
proxyNode1.broadcast(MESSAGE)
|
|
123
|
-
])
|
|
124
|
-
})
|
|
125
|
-
|
|
126
|
-
it('can leave proxy publish connection', async () => {
|
|
127
|
-
await proxiedNode.setProxies(STREAM_PART_ID, [proxyNode1.getPeerDescriptor()], ProxyDirection.PUBLISH, PROXIED_NODE_USER_ID, 1)
|
|
128
|
-
expect(proxiedNode.hasStreamPart(STREAM_PART_ID)).toBe(true)
|
|
129
|
-
expect(hasConnectionFromProxy(proxyNode1)).toBe(true)
|
|
130
|
-
await proxiedNode.setProxies(STREAM_PART_ID, [], ProxyDirection.PUBLISH, PROXIED_NODE_USER_ID, 0)
|
|
131
|
-
expect(proxiedNode.hasStreamPart(STREAM_PART_ID)).toBe(false)
|
|
132
|
-
await until(() => hasConnectionFromProxy(proxyNode1) === false)
|
|
133
|
-
})
|
|
134
|
-
|
|
135
|
-
it('can leave proxy subscribe connection', async () => {
|
|
136
|
-
await proxiedNode.setProxies(STREAM_PART_ID, [proxyNode1.getPeerDescriptor()], ProxyDirection.SUBSCRIBE, PROXIED_NODE_USER_ID, 1)
|
|
137
|
-
expect(proxiedNode.hasStreamPart(STREAM_PART_ID)).toBe(true)
|
|
138
|
-
expect(hasConnectionFromProxy(proxyNode1)).toBe(true)
|
|
139
|
-
await proxiedNode.setProxies(STREAM_PART_ID, [], ProxyDirection.SUBSCRIBE, PROXIED_NODE_USER_ID, 0)
|
|
140
|
-
expect(proxiedNode.hasStreamPart(STREAM_PART_ID)).toBe(false)
|
|
141
|
-
await until(() => hasConnectionFromProxy(proxyNode1) === false)
|
|
142
|
-
})
|
|
143
|
-
|
|
144
|
-
it('can open multiple proxy connections', async () => {
|
|
145
|
-
await proxiedNode.setProxies(
|
|
146
|
-
STREAM_PART_ID,
|
|
147
|
-
[proxyNode1.getPeerDescriptor(), proxyNode2.getPeerDescriptor()],
|
|
148
|
-
ProxyDirection.SUBSCRIBE,
|
|
149
|
-
PROXIED_NODE_USER_ID
|
|
150
|
-
)
|
|
151
|
-
expect(proxiedNode.hasStreamPart(STREAM_PART_ID)).toBe(true)
|
|
152
|
-
expect(hasConnectionFromProxy(proxyNode1)).toBe(true)
|
|
153
|
-
expect(hasConnectionFromProxy(proxyNode2)).toBe(true)
|
|
154
|
-
})
|
|
155
|
-
|
|
156
|
-
it('can open multiple proxy connections and close one', async () => {
|
|
157
|
-
await proxiedNode.setProxies(
|
|
158
|
-
STREAM_PART_ID,
|
|
159
|
-
[proxyNode1.getPeerDescriptor(), proxyNode2.getPeerDescriptor()],
|
|
160
|
-
ProxyDirection.SUBSCRIBE,
|
|
161
|
-
PROXIED_NODE_USER_ID
|
|
162
|
-
)
|
|
163
|
-
expect(proxiedNode.hasStreamPart(STREAM_PART_ID)).toBe(true)
|
|
164
|
-
expect(hasConnectionFromProxy(proxyNode1)).toBe(true)
|
|
165
|
-
expect(hasConnectionFromProxy(proxyNode2)).toBe(true)
|
|
166
|
-
await proxiedNode.setProxies(STREAM_PART_ID, [proxyNode1.getPeerDescriptor()], ProxyDirection.SUBSCRIBE, PROXIED_NODE_USER_ID)
|
|
167
|
-
expect(proxiedNode.hasStreamPart(STREAM_PART_ID)).toBe(true)
|
|
168
|
-
await until(() => hasConnectionFromProxy(proxyNode2) === false)
|
|
169
|
-
expect(hasConnectionFromProxy(proxyNode1)).toBe(true)
|
|
170
|
-
})
|
|
171
|
-
|
|
172
|
-
it('can open and close all connections', async () => {
|
|
173
|
-
await proxiedNode.setProxies(
|
|
174
|
-
STREAM_PART_ID,
|
|
175
|
-
[proxyNode1.getPeerDescriptor(), proxyNode2.getPeerDescriptor()],
|
|
176
|
-
ProxyDirection.SUBSCRIBE,
|
|
177
|
-
PROXIED_NODE_USER_ID
|
|
178
|
-
)
|
|
179
|
-
expect(proxiedNode.hasStreamPart(STREAM_PART_ID)).toBe(true)
|
|
180
|
-
expect(hasConnectionFromProxy(proxyNode1)).toBe(true)
|
|
181
|
-
expect(hasConnectionFromProxy(proxyNode2)).toBe(true)
|
|
182
|
-
|
|
183
|
-
await proxiedNode.setProxies(STREAM_PART_ID, [], ProxyDirection.SUBSCRIBE, PROXIED_NODE_USER_ID)
|
|
184
|
-
expect(proxiedNode.hasStreamPart(STREAM_PART_ID)).toBe(false)
|
|
185
|
-
await until(() => hasConnectionFromProxy(proxyNode1) === false)
|
|
186
|
-
await until(() => hasConnectionFromProxy(proxyNode2) === false)
|
|
187
|
-
})
|
|
188
|
-
|
|
189
|
-
it('will reconnect if proxy node goes offline and comes back online', async () => {
|
|
190
|
-
await proxiedNode.setProxies(
|
|
191
|
-
STREAM_PART_ID,
|
|
192
|
-
[proxyNode1.getPeerDescriptor()],
|
|
193
|
-
ProxyDirection.SUBSCRIBE,
|
|
194
|
-
PROXIED_NODE_USER_ID
|
|
195
|
-
)
|
|
196
|
-
expect(proxiedNode.hasStreamPart(STREAM_PART_ID)).toBe(true)
|
|
197
|
-
await proxyNode1.leave(STREAM_PART_ID)
|
|
198
|
-
await until(() => hasConnectionToProxy(proxyNode1.getNodeId(), ProxyDirection.SUBSCRIBE))
|
|
199
|
-
expect(hasConnectionFromProxy(proxyNode1)).toBe(false)
|
|
200
|
-
proxyNode1.stack.getContentDeliveryManager().joinStreamPart(STREAM_PART_ID)
|
|
201
|
-
await until(() => hasConnectionToProxy(proxyNode1.getNodeId(), ProxyDirection.SUBSCRIBE), 25000)
|
|
202
|
-
// TODO why wait is needed?
|
|
203
|
-
await wait(100)
|
|
204
|
-
expect(hasConnectionFromProxy(proxyNode1)).toBe(true)
|
|
205
|
-
}, 30000)
|
|
206
|
-
|
|
207
|
-
it('can\'t join proxied stream part', async () => {
|
|
208
|
-
await proxiedNode.setProxies(
|
|
209
|
-
STREAM_PART_ID,
|
|
210
|
-
[proxyNode1.getPeerDescriptor()],
|
|
211
|
-
ProxyDirection.PUBLISH,
|
|
212
|
-
PROXIED_NODE_USER_ID
|
|
213
|
-
)
|
|
214
|
-
await expect(proxiedNode.join(STREAM_PART_ID)).rejects.toThrow('Cannot join')
|
|
215
|
-
})
|
|
216
|
-
|
|
217
|
-
it('can\'t broadcast to subscribe-only proxied stream part', async () => {
|
|
218
|
-
await proxiedNode.setProxies(
|
|
219
|
-
STREAM_PART_ID,
|
|
220
|
-
[proxyNode1.getPeerDescriptor()],
|
|
221
|
-
ProxyDirection.SUBSCRIBE,
|
|
222
|
-
PROXIED_NODE_USER_ID
|
|
223
|
-
)
|
|
224
|
-
await expect(proxiedNode.broadcast(MESSAGE)).rejects.toThrow('Cannot broadcast')
|
|
225
|
-
})
|
|
226
|
-
})
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { randomUserId } from '@streamr/test-utils'
|
|
2
|
-
import {
|
|
3
|
-
StreamPartIDUtils,
|
|
4
|
-
hexToBinary,
|
|
5
|
-
toUserIdRaw,
|
|
6
|
-
waitForEvent3
|
|
7
|
-
} from '@streamr/utils'
|
|
8
|
-
import { NetworkNode, createNetworkNode } from '../../src/NetworkNode'
|
|
9
|
-
import { ProxyDirection, SignatureType, StreamMessage } from '../../generated/packages/trackerless-network/protos/NetworkRpc'
|
|
10
|
-
import { createMockPeerDescriptor } from '../utils/utils'
|
|
11
|
-
|
|
12
|
-
const STREAM_PART_ID = StreamPartIDUtils.parse('proxy-test#0')
|
|
13
|
-
|
|
14
|
-
describe('proxy group key exchange', () => {
|
|
15
|
-
const proxyNodeDescriptor = createMockPeerDescriptor({
|
|
16
|
-
websocket: { host: '127.0.0.1', port: 23134, tls: false }
|
|
17
|
-
})
|
|
18
|
-
const publisherDescriptor = createMockPeerDescriptor()
|
|
19
|
-
const subscriberDescriptor = createMockPeerDescriptor()
|
|
20
|
-
|
|
21
|
-
const publisherUserId = randomUserId()
|
|
22
|
-
const subscriberUserId = randomUserId()
|
|
23
|
-
|
|
24
|
-
let proxyNode: NetworkNode
|
|
25
|
-
let publisher: NetworkNode
|
|
26
|
-
let subscriber: NetworkNode
|
|
27
|
-
|
|
28
|
-
beforeEach(async () => {
|
|
29
|
-
proxyNode = createNetworkNode({
|
|
30
|
-
layer0: {
|
|
31
|
-
entryPoints: [proxyNodeDescriptor],
|
|
32
|
-
peerDescriptor: proxyNodeDescriptor,
|
|
33
|
-
websocketServerEnableTls: false
|
|
34
|
-
},
|
|
35
|
-
networkNode: {
|
|
36
|
-
acceptProxyConnections: true
|
|
37
|
-
}
|
|
38
|
-
})
|
|
39
|
-
await proxyNode.start()
|
|
40
|
-
proxyNode.stack.getContentDeliveryManager().joinStreamPart(STREAM_PART_ID)
|
|
41
|
-
publisher = createNetworkNode({
|
|
42
|
-
layer0: {
|
|
43
|
-
entryPoints: [proxyNodeDescriptor],
|
|
44
|
-
peerDescriptor: publisherDescriptor,
|
|
45
|
-
}
|
|
46
|
-
})
|
|
47
|
-
await publisher.start(false)
|
|
48
|
-
|
|
49
|
-
subscriber = createNetworkNode({
|
|
50
|
-
layer0: {
|
|
51
|
-
entryPoints: [proxyNodeDescriptor],
|
|
52
|
-
peerDescriptor: subscriberDescriptor,
|
|
53
|
-
}
|
|
54
|
-
})
|
|
55
|
-
await subscriber.start(false)
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
afterEach(async () => {
|
|
59
|
-
await proxyNode.stop()
|
|
60
|
-
await publisher.stop()
|
|
61
|
-
await subscriber.stop()
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
it('happy path request', async () => {
|
|
65
|
-
await publisher.setProxies(STREAM_PART_ID, [proxyNodeDescriptor], ProxyDirection.PUBLISH, publisherUserId)
|
|
66
|
-
await subscriber.setProxies(STREAM_PART_ID, [proxyNodeDescriptor], ProxyDirection.SUBSCRIBE, subscriberUserId)
|
|
67
|
-
|
|
68
|
-
const request: StreamMessage = {
|
|
69
|
-
messageId: {
|
|
70
|
-
streamId: StreamPartIDUtils.getStreamID(STREAM_PART_ID),
|
|
71
|
-
streamPartition: StreamPartIDUtils.getStreamPartition(STREAM_PART_ID),
|
|
72
|
-
timestamp: Date.now(),
|
|
73
|
-
sequenceNumber: 0,
|
|
74
|
-
publisherId: toUserIdRaw(subscriberUserId),
|
|
75
|
-
messageChainId: '0'
|
|
76
|
-
},
|
|
77
|
-
body: {
|
|
78
|
-
oneofKind: 'groupKeyRequest' as const,
|
|
79
|
-
groupKeyRequest: {
|
|
80
|
-
requestId: 'requestId',
|
|
81
|
-
recipientId: toUserIdRaw(publisherUserId),
|
|
82
|
-
rsaPublicKey: new Uint8Array(),
|
|
83
|
-
groupKeyIds: ['mock']
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
|
-
signatureType: SignatureType.SECP256K1,
|
|
87
|
-
signature: hexToBinary('1234')
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
await Promise.all([
|
|
91
|
-
waitForEvent3(publisher.stack.getContentDeliveryManager() as any, 'newMessage'),
|
|
92
|
-
subscriber.broadcast(request)
|
|
93
|
-
])
|
|
94
|
-
})
|
|
95
|
-
|
|
96
|
-
it('happy path response', async () => {
|
|
97
|
-
await publisher.setProxies(STREAM_PART_ID, [proxyNodeDescriptor], ProxyDirection.PUBLISH, publisherUserId)
|
|
98
|
-
await subscriber.setProxies(STREAM_PART_ID, [proxyNodeDescriptor], ProxyDirection.SUBSCRIBE, subscriberUserId)
|
|
99
|
-
|
|
100
|
-
const response: StreamMessage = {
|
|
101
|
-
messageId: {
|
|
102
|
-
streamId: StreamPartIDUtils.getStreamID(STREAM_PART_ID),
|
|
103
|
-
streamPartition: StreamPartIDUtils.getStreamPartition(STREAM_PART_ID),
|
|
104
|
-
timestamp: Date.now(),
|
|
105
|
-
sequenceNumber: 0,
|
|
106
|
-
publisherId: toUserIdRaw(publisherUserId),
|
|
107
|
-
messageChainId: '0'
|
|
108
|
-
},
|
|
109
|
-
body: {
|
|
110
|
-
oneofKind: 'groupKeyResponse' as const,
|
|
111
|
-
groupKeyResponse: {
|
|
112
|
-
requestId: 'requestId',
|
|
113
|
-
recipientId: toUserIdRaw(publisherUserId),
|
|
114
|
-
groupKeys: []
|
|
115
|
-
}
|
|
116
|
-
},
|
|
117
|
-
signatureType: SignatureType.SECP256K1,
|
|
118
|
-
signature: hexToBinary('1234')
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
await Promise.all([
|
|
122
|
-
waitForEvent3(subscriber.stack.getContentDeliveryManager() as any, 'newMessage'),
|
|
123
|
-
publisher.broadcast(response)
|
|
124
|
-
])
|
|
125
|
-
})
|
|
126
|
-
})
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { toNodeId, getRandomRegion } from '@streamr/dht'
|
|
2
|
-
import { StreamPartIDUtils, until } from '@streamr/utils'
|
|
3
|
-
import { range } from 'lodash'
|
|
4
|
-
import { NetworkStack } from '../../src/NetworkStack'
|
|
5
|
-
import { createMockPeerDescriptor, createStreamMessage } from '../utils/utils'
|
|
6
|
-
import { randomUserId } from '@streamr/test-utils'
|
|
7
|
-
|
|
8
|
-
describe('Full node network with WebRTC connections', () => {
|
|
9
|
-
|
|
10
|
-
const NUM_OF_NODES = 22
|
|
11
|
-
|
|
12
|
-
const epPeerDescriptor = createMockPeerDescriptor({
|
|
13
|
-
websocket: { host: '127.0.0.1', port: 14444, tls: false },
|
|
14
|
-
region: getRandomRegion()
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
const streamPartId = StreamPartIDUtils.parse('webrtc-network#0')
|
|
18
|
-
|
|
19
|
-
let entryPoint: NetworkStack
|
|
20
|
-
|
|
21
|
-
let nodes: NetworkStack[]
|
|
22
|
-
|
|
23
|
-
beforeEach(async () => {
|
|
24
|
-
|
|
25
|
-
nodes = []
|
|
26
|
-
|
|
27
|
-
entryPoint = new NetworkStack({
|
|
28
|
-
layer0: {
|
|
29
|
-
entryPoints: [epPeerDescriptor],
|
|
30
|
-
peerDescriptor: epPeerDescriptor,
|
|
31
|
-
websocketServerEnableTls: false
|
|
32
|
-
}
|
|
33
|
-
})
|
|
34
|
-
await entryPoint.start()
|
|
35
|
-
entryPoint.getContentDeliveryManager().joinStreamPart(streamPartId)
|
|
36
|
-
|
|
37
|
-
await Promise.all(range(NUM_OF_NODES).map(async () => {
|
|
38
|
-
const peerDescriptor = createMockPeerDescriptor()
|
|
39
|
-
const node = new NetworkStack({
|
|
40
|
-
layer0: {
|
|
41
|
-
peerDescriptor,
|
|
42
|
-
entryPoints: [epPeerDescriptor]
|
|
43
|
-
}
|
|
44
|
-
})
|
|
45
|
-
nodes.push(node)
|
|
46
|
-
await node.start()
|
|
47
|
-
node.getContentDeliveryManager().joinStreamPart(streamPartId)
|
|
48
|
-
}))
|
|
49
|
-
|
|
50
|
-
}, 90000)
|
|
51
|
-
|
|
52
|
-
afterEach(async () => {
|
|
53
|
-
await Promise.all([
|
|
54
|
-
entryPoint.stop(),
|
|
55
|
-
...nodes.map((node) => node.stop())
|
|
56
|
-
])
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
it('happy path', async () => {
|
|
60
|
-
await Promise.all(nodes.map((node) =>
|
|
61
|
-
until(() => {
|
|
62
|
-
return node.getContentDeliveryManager().getNeighbors(streamPartId).length >= 3
|
|
63
|
-
}
|
|
64
|
-
, 30000)
|
|
65
|
-
))
|
|
66
|
-
let receivedMessageCount = 0
|
|
67
|
-
const successIds: string[] = []
|
|
68
|
-
nodes.forEach((node) => {
|
|
69
|
-
node.getContentDeliveryManager().on('newMessage', () => {
|
|
70
|
-
successIds.push(toNodeId(node.getContentDeliveryManager().getPeerDescriptor()))
|
|
71
|
-
receivedMessageCount += 1
|
|
72
|
-
})
|
|
73
|
-
})
|
|
74
|
-
const msg = createStreamMessage(
|
|
75
|
-
JSON.stringify({ hello: 'WORLD' }),
|
|
76
|
-
streamPartId,
|
|
77
|
-
randomUserId()
|
|
78
|
-
)
|
|
79
|
-
entryPoint.getContentDeliveryManager().broadcast(msg)
|
|
80
|
-
await until(() => receivedMessageCount === NUM_OF_NODES)
|
|
81
|
-
}, 120000)
|
|
82
|
-
|
|
83
|
-
})
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { toNodeId } from '@streamr/dht'
|
|
2
|
-
import { StreamPartIDUtils, until } from '@streamr/utils'
|
|
3
|
-
import { range } from 'lodash'
|
|
4
|
-
import { NetworkStack } from '../../src/NetworkStack'
|
|
5
|
-
import { createMockPeerDescriptor, createStreamMessage } from '../utils/utils'
|
|
6
|
-
import { randomUserId } from '@streamr/test-utils'
|
|
7
|
-
|
|
8
|
-
describe('Full node network with WebSocket connections only', () => {
|
|
9
|
-
|
|
10
|
-
const NUM_OF_NODES = 12
|
|
11
|
-
const epPeerDescriptor = createMockPeerDescriptor({
|
|
12
|
-
websocket: { host: '127.0.0.1', port: 15555, tls: false }
|
|
13
|
-
})
|
|
14
|
-
const streamPartId = StreamPartIDUtils.parse('websocket-network#0')
|
|
15
|
-
|
|
16
|
-
let entryPoint: NetworkStack
|
|
17
|
-
|
|
18
|
-
let nodes: NetworkStack[]
|
|
19
|
-
|
|
20
|
-
beforeEach(async () => {
|
|
21
|
-
|
|
22
|
-
nodes = []
|
|
23
|
-
|
|
24
|
-
entryPoint = new NetworkStack({
|
|
25
|
-
layer0: {
|
|
26
|
-
entryPoints: [epPeerDescriptor],
|
|
27
|
-
peerDescriptor: epPeerDescriptor,
|
|
28
|
-
websocketServerEnableTls: false
|
|
29
|
-
}
|
|
30
|
-
})
|
|
31
|
-
await entryPoint.start()
|
|
32
|
-
entryPoint.getContentDeliveryManager().joinStreamPart(streamPartId)
|
|
33
|
-
|
|
34
|
-
await Promise.all(range(NUM_OF_NODES).map(async (i) => {
|
|
35
|
-
const node = new NetworkStack({
|
|
36
|
-
layer0: {
|
|
37
|
-
entryPoints: [epPeerDescriptor],
|
|
38
|
-
websocketPortRange: { min: 15556 + i, max: 15556 + i },
|
|
39
|
-
numberOfNodesPerKBucket: 4,
|
|
40
|
-
websocketServerEnableTls: false
|
|
41
|
-
}
|
|
42
|
-
})
|
|
43
|
-
nodes.push(node)
|
|
44
|
-
await node.start()
|
|
45
|
-
node.getContentDeliveryManager().joinStreamPart(streamPartId)
|
|
46
|
-
}))
|
|
47
|
-
|
|
48
|
-
}, 120000)
|
|
49
|
-
|
|
50
|
-
afterEach(async () => {
|
|
51
|
-
await Promise.all([
|
|
52
|
-
entryPoint.stop(),
|
|
53
|
-
...nodes.map((node) => node.stop())
|
|
54
|
-
])
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
it('happy path', async () => {
|
|
58
|
-
await Promise.all(nodes.map((node) =>
|
|
59
|
-
until(() => {
|
|
60
|
-
return node.getContentDeliveryManager().getNeighbors(streamPartId).length >= 4
|
|
61
|
-
}
|
|
62
|
-
, 30000)
|
|
63
|
-
))
|
|
64
|
-
let receivedMessageCount = 0
|
|
65
|
-
const successIds: string[] = []
|
|
66
|
-
nodes.forEach((node) => {
|
|
67
|
-
node.getContentDeliveryManager().on('newMessage', () => {
|
|
68
|
-
successIds.push(toNodeId(node.getContentDeliveryManager().getPeerDescriptor()))
|
|
69
|
-
receivedMessageCount += 1
|
|
70
|
-
})
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
const msg = createStreamMessage(
|
|
74
|
-
JSON.stringify({ hello: 'WORLD' }),
|
|
75
|
-
streamPartId,
|
|
76
|
-
randomUserId()
|
|
77
|
-
)
|
|
78
|
-
entryPoint.getContentDeliveryManager().broadcast(msg)
|
|
79
|
-
await until(() => receivedMessageCount === NUM_OF_NODES)
|
|
80
|
-
}, 220000)
|
|
81
|
-
|
|
82
|
-
})
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import { DhtNode, LatencyType, PeerDescriptor, Simulator, SimulatorTransport, toNodeId } from '@streamr/dht'
|
|
2
|
-
import { StreamPartIDUtils, until } from '@streamr/utils'
|
|
3
|
-
import { range } from 'lodash'
|
|
4
|
-
import { ContentDeliveryLayerNode } from '../../src/logic/ContentDeliveryLayerNode'
|
|
5
|
-
import { DiscoveryLayerNode } from '../../src/logic/DiscoveryLayerNode'
|
|
6
|
-
import { createContentDeliveryLayerNode } from '../../src/logic/createContentDeliveryLayerNode'
|
|
7
|
-
import { createMockPeerDescriptor } from '../utils/utils'
|
|
8
|
-
|
|
9
|
-
describe('ContentDeliveryLayerNode-DhtNode-Latencies', () => {
|
|
10
|
-
const otherNodeCount = 64
|
|
11
|
-
let otherDiscoveryLayerNodes: DiscoveryLayerNode[]
|
|
12
|
-
let entryPointDiscoveryLayerNode: DiscoveryLayerNode
|
|
13
|
-
let entryPointContentDeliveryLayerNode: ContentDeliveryLayerNode
|
|
14
|
-
let otherContentDeliveryLayerNodes: ContentDeliveryLayerNode[]
|
|
15
|
-
|
|
16
|
-
const streamPartId = StreamPartIDUtils.parse('stream#0')
|
|
17
|
-
const entrypointDescriptor = createMockPeerDescriptor()
|
|
18
|
-
|
|
19
|
-
const peerDescriptors: PeerDescriptor[] = range(otherNodeCount).map(() => createMockPeerDescriptor())
|
|
20
|
-
beforeEach(async () => {
|
|
21
|
-
const simulator = new Simulator(LatencyType.FIXED, 50)
|
|
22
|
-
const entrypointCm = new SimulatorTransport(entrypointDescriptor, simulator)
|
|
23
|
-
const cms: SimulatorTransport[] = range(otherNodeCount).map((i) =>
|
|
24
|
-
new SimulatorTransport(peerDescriptors[i], simulator)
|
|
25
|
-
)
|
|
26
|
-
await entrypointCm.start()
|
|
27
|
-
await Promise.all(cms.map((cm) => cm.start()))
|
|
28
|
-
|
|
29
|
-
entryPointDiscoveryLayerNode = new DhtNode({
|
|
30
|
-
transport: entrypointCm,
|
|
31
|
-
connectionsView: entrypointCm,
|
|
32
|
-
peerDescriptor: entrypointDescriptor,
|
|
33
|
-
serviceId: streamPartId
|
|
34
|
-
})
|
|
35
|
-
otherDiscoveryLayerNodes = range(otherNodeCount).map((i) => new DhtNode({
|
|
36
|
-
transport: cms[i],
|
|
37
|
-
connectionsView: cms[i],
|
|
38
|
-
peerDescriptor: peerDescriptors[i],
|
|
39
|
-
serviceId: streamPartId
|
|
40
|
-
}))
|
|
41
|
-
otherContentDeliveryLayerNodes = range(otherNodeCount).map((i) => createContentDeliveryLayerNode({
|
|
42
|
-
streamPartId,
|
|
43
|
-
discoveryLayerNode: otherDiscoveryLayerNodes[i],
|
|
44
|
-
transport: cms[i],
|
|
45
|
-
connectionLocker: cms[i],
|
|
46
|
-
localPeerDescriptor: peerDescriptors[i],
|
|
47
|
-
isLocalNodeEntryPoint: () => false
|
|
48
|
-
}))
|
|
49
|
-
entryPointContentDeliveryLayerNode = createContentDeliveryLayerNode({
|
|
50
|
-
streamPartId,
|
|
51
|
-
discoveryLayerNode: entryPointDiscoveryLayerNode,
|
|
52
|
-
transport: entrypointCm,
|
|
53
|
-
connectionLocker: entrypointCm,
|
|
54
|
-
localPeerDescriptor: entrypointDescriptor,
|
|
55
|
-
isLocalNodeEntryPoint: () => false
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
await entryPointDiscoveryLayerNode.start()
|
|
59
|
-
entryPointContentDeliveryLayerNode.start()
|
|
60
|
-
await entryPointDiscoveryLayerNode.joinDht([entrypointDescriptor])
|
|
61
|
-
await Promise.all(otherDiscoveryLayerNodes.map((node) => node.start()))
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
afterEach(async () => {
|
|
65
|
-
entryPointDiscoveryLayerNode.stop()
|
|
66
|
-
entryPointContentDeliveryLayerNode.stop()
|
|
67
|
-
await Promise.all(otherDiscoveryLayerNodes.map((node) => node.stop()))
|
|
68
|
-
await Promise.all(otherContentDeliveryLayerNodes.map((node) => node.stop()))
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
it('happy path single node', async () => {
|
|
72
|
-
await otherContentDeliveryLayerNodes[0].start()
|
|
73
|
-
await otherDiscoveryLayerNodes[0].joinDht([entrypointDescriptor])
|
|
74
|
-
await Promise.all([
|
|
75
|
-
until(() => otherContentDeliveryLayerNodes[0].getNearbyNodeView().getIds().length === 1),
|
|
76
|
-
until(() => otherContentDeliveryLayerNodes[0].getNeighbors().length === 1)
|
|
77
|
-
])
|
|
78
|
-
expect(otherContentDeliveryLayerNodes[0].getNearbyNodeView().getIds().length).toEqual(1)
|
|
79
|
-
expect(otherContentDeliveryLayerNodes[0].getNeighbors().length).toEqual(1)
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
it('happy path 5 nodes', async () => {
|
|
83
|
-
range(4).forEach((i) => otherContentDeliveryLayerNodes[i].start())
|
|
84
|
-
await Promise.all(range(4).map(async (i) => {
|
|
85
|
-
await otherDiscoveryLayerNodes[i].joinDht([entrypointDescriptor])
|
|
86
|
-
}))
|
|
87
|
-
await until(() => range(4).every((i) => otherContentDeliveryLayerNodes[i].getNeighbors().length >= 4), 15000, 1000)
|
|
88
|
-
range(4).forEach((i) => {
|
|
89
|
-
expect(otherContentDeliveryLayerNodes[i].getNearbyNodeView().getIds().length).toBeGreaterThanOrEqual(4)
|
|
90
|
-
expect(otherContentDeliveryLayerNodes[i].getNeighbors().length).toBeGreaterThanOrEqual(4)
|
|
91
|
-
})
|
|
92
|
-
// Check bidirectionality
|
|
93
|
-
const allNodes = otherContentDeliveryLayerNodes
|
|
94
|
-
allNodes.push(entryPointContentDeliveryLayerNode)
|
|
95
|
-
range(5).forEach((i) => {
|
|
96
|
-
const ownNodeId = allNodes[i].getOwnNodeId()
|
|
97
|
-
allNodes[i].getNearbyNodeView().getIds().forEach((nodeId) => {
|
|
98
|
-
const neighbor = allNodes.find((node) => {
|
|
99
|
-
return node.getOwnNodeId() === ownNodeId
|
|
100
|
-
})
|
|
101
|
-
const neighborNodeIds = neighbor!.getNeighbors().map((n) => toNodeId(n))
|
|
102
|
-
expect(neighborNodeIds).toContain(nodeId)
|
|
103
|
-
})
|
|
104
|
-
})
|
|
105
|
-
}, 60000)
|
|
106
|
-
|
|
107
|
-
it('happy path 64 nodes', async () => {
|
|
108
|
-
await Promise.all(range(otherNodeCount).map((i) => otherContentDeliveryLayerNodes[i].start()))
|
|
109
|
-
await Promise.all(range(otherNodeCount).map((i) => {
|
|
110
|
-
otherDiscoveryLayerNodes[i].joinDht([entrypointDescriptor])
|
|
111
|
-
}))
|
|
112
|
-
await Promise.all(otherContentDeliveryLayerNodes.map((node) =>
|
|
113
|
-
until(() => node.getNeighbors().length >= 4, 10000)
|
|
114
|
-
))
|
|
115
|
-
|
|
116
|
-
await Promise.all(otherContentDeliveryLayerNodes.map((node) =>
|
|
117
|
-
until(() => node.getOutgoingHandshakeCount() === 0)
|
|
118
|
-
))
|
|
119
|
-
|
|
120
|
-
await until(() => {
|
|
121
|
-
let mismatchCounter = 0
|
|
122
|
-
otherContentDeliveryLayerNodes.forEach((node) => {
|
|
123
|
-
const nodeId = node.getOwnNodeId()
|
|
124
|
-
node.getNeighbors().forEach((neighbor) => {
|
|
125
|
-
const neighborId = toNodeId(neighbor)
|
|
126
|
-
if (neighborId !== entryPointContentDeliveryLayerNode.getOwnNodeId()) {
|
|
127
|
-
const neighbor = otherContentDeliveryLayerNodes.find((n) => n.getOwnNodeId() === neighborId)
|
|
128
|
-
const neighborNodeIds = neighbor!.getNeighbors().map((n) => toNodeId(n))
|
|
129
|
-
if (!neighborNodeIds.includes(nodeId)) {
|
|
130
|
-
mismatchCounter += 1
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
})
|
|
134
|
-
})
|
|
135
|
-
// NET-1074 Investigate why sometimes unidirectional connections remain.
|
|
136
|
-
return mismatchCounter <= 2
|
|
137
|
-
}, 20000, 1000)
|
|
138
|
-
}, 90000)
|
|
139
|
-
})
|