@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,162 +0,0 @@
|
|
|
1
|
-
import { ConnectionManager, DhtNode, PeerDescriptor, Simulator, SimulatorTransport, toNodeId, getRandomRegion } from '@streamr/dht'
|
|
2
|
-
import { Logger, 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
|
-
const logger = new Logger(module)
|
|
10
|
-
|
|
11
|
-
describe('ContentDeliveryLayerNode-DhtNode', () => {
|
|
12
|
-
const otherNodeCount = 64
|
|
13
|
-
let entryPointDiscoveryLayerNode: DiscoveryLayerNode
|
|
14
|
-
let otherDiscoveryLayerNodes: DiscoveryLayerNode[]
|
|
15
|
-
let entryPointContentDeliveryLayerNode: ContentDeliveryLayerNode
|
|
16
|
-
let otherContentDeliveryLayerNodes: ContentDeliveryLayerNode[]
|
|
17
|
-
|
|
18
|
-
const streamPartId = StreamPartIDUtils.parse('stream#0')
|
|
19
|
-
const entrypointDescriptor = createMockPeerDescriptor({
|
|
20
|
-
region: getRandomRegion()
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
const peerDescriptors: PeerDescriptor[] = range(otherNodeCount).map(() => {
|
|
24
|
-
return createMockPeerDescriptor({
|
|
25
|
-
region: getRandomRegion()
|
|
26
|
-
})
|
|
27
|
-
})
|
|
28
|
-
beforeEach(async () => {
|
|
29
|
-
const simulator = new Simulator()
|
|
30
|
-
const entrypointCm = new SimulatorTransport(
|
|
31
|
-
entrypointDescriptor,
|
|
32
|
-
simulator
|
|
33
|
-
)
|
|
34
|
-
await entrypointCm.start()
|
|
35
|
-
|
|
36
|
-
const cms: ConnectionManager[] = range(otherNodeCount).map((i) =>
|
|
37
|
-
new SimulatorTransport(
|
|
38
|
-
peerDescriptors[i],
|
|
39
|
-
simulator
|
|
40
|
-
)
|
|
41
|
-
)
|
|
42
|
-
await Promise.all(cms.map((cm) => cm.start()))
|
|
43
|
-
|
|
44
|
-
entryPointDiscoveryLayerNode = new DhtNode({
|
|
45
|
-
transport: entrypointCm,
|
|
46
|
-
connectionsView: entrypointCm,
|
|
47
|
-
peerDescriptor: entrypointDescriptor,
|
|
48
|
-
serviceId: streamPartId
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
otherDiscoveryLayerNodes = range(otherNodeCount).map((i) => new DhtNode({
|
|
52
|
-
transport: cms[i],
|
|
53
|
-
connectionsView: cms[i],
|
|
54
|
-
peerDescriptor: peerDescriptors[i],
|
|
55
|
-
serviceId: streamPartId
|
|
56
|
-
}))
|
|
57
|
-
|
|
58
|
-
otherContentDeliveryLayerNodes = range(otherNodeCount).map((i) => createContentDeliveryLayerNode({
|
|
59
|
-
streamPartId,
|
|
60
|
-
discoveryLayerNode: otherDiscoveryLayerNodes[i],
|
|
61
|
-
transport: cms[i],
|
|
62
|
-
connectionLocker: cms[i],
|
|
63
|
-
localPeerDescriptor: peerDescriptors[i],
|
|
64
|
-
neighborUpdateInterval: 2000,
|
|
65
|
-
isLocalNodeEntryPoint: () => false
|
|
66
|
-
}))
|
|
67
|
-
|
|
68
|
-
entryPointContentDeliveryLayerNode = createContentDeliveryLayerNode({
|
|
69
|
-
streamPartId,
|
|
70
|
-
discoveryLayerNode: entryPointDiscoveryLayerNode,
|
|
71
|
-
transport: entrypointCm,
|
|
72
|
-
connectionLocker: entrypointCm,
|
|
73
|
-
localPeerDescriptor: entrypointDescriptor,
|
|
74
|
-
neighborUpdateInterval: 2000,
|
|
75
|
-
isLocalNodeEntryPoint: () => false
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
await entryPointDiscoveryLayerNode.start()
|
|
79
|
-
await entryPointContentDeliveryLayerNode.start()
|
|
80
|
-
await entryPointDiscoveryLayerNode.joinDht([entrypointDescriptor])
|
|
81
|
-
await Promise.all(otherDiscoveryLayerNodes.map((node) => node.start()))
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
afterEach(async () => {
|
|
85
|
-
await entryPointDiscoveryLayerNode.stop()
|
|
86
|
-
entryPointContentDeliveryLayerNode.stop()
|
|
87
|
-
await Promise.all(otherDiscoveryLayerNodes.map((node) => node.stop()))
|
|
88
|
-
await Promise.all(otherContentDeliveryLayerNodes.map((node) => node.stop()))
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
it('happy path single node ', async () => {
|
|
92
|
-
await otherContentDeliveryLayerNodes[0].start()
|
|
93
|
-
await otherDiscoveryLayerNodes[0].joinDht([entrypointDescriptor])
|
|
94
|
-
|
|
95
|
-
await until(() => otherContentDeliveryLayerNodes[0].getNeighbors().length === 1)
|
|
96
|
-
expect(otherContentDeliveryLayerNodes[0].getNearbyNodeView().getIds().length).toEqual(1)
|
|
97
|
-
expect(otherContentDeliveryLayerNodes[0].getNeighbors().length).toEqual(1)
|
|
98
|
-
})
|
|
99
|
-
|
|
100
|
-
it('happy path 4 nodes', async () => {
|
|
101
|
-
range(4).forEach((i) => otherContentDeliveryLayerNodes[i].start())
|
|
102
|
-
await Promise.all(range(4).map(async (i) => {
|
|
103
|
-
await otherDiscoveryLayerNodes[i].joinDht([entrypointDescriptor])
|
|
104
|
-
}))
|
|
105
|
-
|
|
106
|
-
await until(() => range(4).every((i) => otherContentDeliveryLayerNodes[i].getNeighbors().length === 4))
|
|
107
|
-
range(4).forEach((i) => {
|
|
108
|
-
expect(otherContentDeliveryLayerNodes[i].getNearbyNodeView().getIds().length).toBeGreaterThanOrEqual(4)
|
|
109
|
-
expect(otherContentDeliveryLayerNodes[i].getNeighbors().length).toBeGreaterThanOrEqual(4)
|
|
110
|
-
})
|
|
111
|
-
|
|
112
|
-
// Check bidirectionality
|
|
113
|
-
const allNodes = otherContentDeliveryLayerNodes
|
|
114
|
-
allNodes.push(entryPointContentDeliveryLayerNode)
|
|
115
|
-
range(5).forEach((i) => {
|
|
116
|
-
allNodes[i].getNearbyNodeView().getIds().forEach((nodeId) => {
|
|
117
|
-
const neighbor = allNodes.find((node) => {
|
|
118
|
-
return node.getOwnNodeId() === nodeId
|
|
119
|
-
})
|
|
120
|
-
const neighborNodeIds = neighbor!.getNeighbors().map((n) => toNodeId(n))
|
|
121
|
-
expect(neighborNodeIds.includes(allNodes[i].getOwnNodeId())).toEqual(true)
|
|
122
|
-
})
|
|
123
|
-
})
|
|
124
|
-
}, 10000)
|
|
125
|
-
|
|
126
|
-
it('happy path 64 nodes', async () => {
|
|
127
|
-
await Promise.all(range(otherNodeCount).map((i) => otherContentDeliveryLayerNodes[i].start()))
|
|
128
|
-
await Promise.all(range(otherNodeCount).map((i) => {
|
|
129
|
-
otherDiscoveryLayerNodes[i].joinDht([entrypointDescriptor])
|
|
130
|
-
}))
|
|
131
|
-
await Promise.all(otherContentDeliveryLayerNodes.map((node) =>
|
|
132
|
-
until(() => node.getNeighbors().length >= 4, 10000)
|
|
133
|
-
))
|
|
134
|
-
|
|
135
|
-
const avg = otherContentDeliveryLayerNodes.reduce((acc, curr) => {
|
|
136
|
-
return acc + curr.getNeighbors().length
|
|
137
|
-
}, 0) / otherNodeCount
|
|
138
|
-
|
|
139
|
-
logger.info(`AVG Number of neighbors: ${avg}`)
|
|
140
|
-
await Promise.all(otherContentDeliveryLayerNodes.map((node) =>
|
|
141
|
-
until(() => node.getOutgoingHandshakeCount() === 0)
|
|
142
|
-
))
|
|
143
|
-
await until(() => {
|
|
144
|
-
let mismatchCounter = 0
|
|
145
|
-
otherContentDeliveryLayerNodes.forEach((node) => {
|
|
146
|
-
const nodeId = node.getOwnNodeId()
|
|
147
|
-
node.getNeighbors().forEach((neighbor) => {
|
|
148
|
-
const neighborId = toNodeId(neighbor)
|
|
149
|
-
if (neighborId !== entryPointContentDeliveryLayerNode.getOwnNodeId()) {
|
|
150
|
-
const neighbor = otherContentDeliveryLayerNodes.find((n) => n.getOwnNodeId() === neighborId)
|
|
151
|
-
const neighborNodeIds = neighbor!.getNeighbors().map((n) => toNodeId(n))
|
|
152
|
-
if (!neighborNodeIds.includes(nodeId)) {
|
|
153
|
-
mismatchCounter += 1
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
})
|
|
157
|
-
})
|
|
158
|
-
// NET-1074 Investigate why sometimes unidirectional connections remain.
|
|
159
|
-
return mismatchCounter <= 2
|
|
160
|
-
}, 20000, 1000)
|
|
161
|
-
}, 95000)
|
|
162
|
-
})
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DhtNode,
|
|
3
|
-
Simulator,
|
|
4
|
-
SimulatorTransport
|
|
5
|
-
} from '@streamr/dht'
|
|
6
|
-
import { StreamPartIDUtils, until, waitForEvent3, wait } from '@streamr/utils'
|
|
7
|
-
import { ContentDeliveryManager, Events } from '../../src/logic/ContentDeliveryManager'
|
|
8
|
-
import { ControlLayerNode } from '../../src/logic/ControlLayerNode'
|
|
9
|
-
import { createMockPeerDescriptor, createStreamMessage } from '../utils/utils'
|
|
10
|
-
import { randomUserId } from '@streamr/test-utils'
|
|
11
|
-
|
|
12
|
-
describe('ContentDeliveryManager', () => {
|
|
13
|
-
|
|
14
|
-
let controlLayerNode1: ControlLayerNode
|
|
15
|
-
let controlLayerNode2: ControlLayerNode
|
|
16
|
-
let transport1: SimulatorTransport
|
|
17
|
-
let transport2: SimulatorTransport
|
|
18
|
-
let manager1: ContentDeliveryManager
|
|
19
|
-
let manager2: ContentDeliveryManager
|
|
20
|
-
|
|
21
|
-
const peerDescriptor1 = createMockPeerDescriptor()
|
|
22
|
-
const peerDescriptor2 = createMockPeerDescriptor()
|
|
23
|
-
const STREAM_PART_ID = StreamPartIDUtils.parse('test#0')
|
|
24
|
-
|
|
25
|
-
const msg = createStreamMessage(
|
|
26
|
-
JSON.stringify({ hello: 'WORLD' }),
|
|
27
|
-
STREAM_PART_ID,
|
|
28
|
-
randomUserId()
|
|
29
|
-
)
|
|
30
|
-
let simulator: Simulator
|
|
31
|
-
|
|
32
|
-
beforeEach(async () => {
|
|
33
|
-
simulator = new Simulator()
|
|
34
|
-
transport1 = new SimulatorTransport(peerDescriptor1, simulator)
|
|
35
|
-
await transport1.start()
|
|
36
|
-
transport2 = new SimulatorTransport(peerDescriptor2, simulator)
|
|
37
|
-
await transport2.start()
|
|
38
|
-
controlLayerNode1 = new DhtNode({
|
|
39
|
-
transport: transport1,
|
|
40
|
-
connectionsView: transport1,
|
|
41
|
-
peerDescriptor: peerDescriptor1,
|
|
42
|
-
entryPoints: [peerDescriptor1]
|
|
43
|
-
})
|
|
44
|
-
controlLayerNode2 = new DhtNode({
|
|
45
|
-
transport: transport2,
|
|
46
|
-
connectionsView: transport2,
|
|
47
|
-
peerDescriptor: peerDescriptor2,
|
|
48
|
-
entryPoints: [peerDescriptor1]
|
|
49
|
-
})
|
|
50
|
-
await Promise.all([
|
|
51
|
-
controlLayerNode1.start(),
|
|
52
|
-
controlLayerNode2.start()
|
|
53
|
-
])
|
|
54
|
-
await Promise.all([
|
|
55
|
-
controlLayerNode1.joinDht([peerDescriptor1]),
|
|
56
|
-
controlLayerNode2.joinDht([peerDescriptor1])
|
|
57
|
-
])
|
|
58
|
-
|
|
59
|
-
manager1 = new ContentDeliveryManager({ neighborUpdateInterval: 100 })
|
|
60
|
-
manager2 = new ContentDeliveryManager({ neighborUpdateInterval: 100 })
|
|
61
|
-
await manager1.start(controlLayerNode1, transport1, transport1)
|
|
62
|
-
manager1.setStreamPartEntryPoints(STREAM_PART_ID, [peerDescriptor1])
|
|
63
|
-
await manager2.start(controlLayerNode2, transport2, transport2)
|
|
64
|
-
manager2.setStreamPartEntryPoints(STREAM_PART_ID, [peerDescriptor1])
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
afterEach(async () => {
|
|
68
|
-
await Promise.all([
|
|
69
|
-
manager1.destroy(),
|
|
70
|
-
manager2.destroy(),
|
|
71
|
-
controlLayerNode1.stop(),
|
|
72
|
-
controlLayerNode2.stop(),
|
|
73
|
-
transport1.stop(),
|
|
74
|
-
transport2.stop()
|
|
75
|
-
])
|
|
76
|
-
simulator.stop()
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
it('starts', async () => {
|
|
80
|
-
expect(manager1.getPeerDescriptor()).toEqual(peerDescriptor1)
|
|
81
|
-
expect(manager2.getPeerDescriptor()).toEqual(peerDescriptor2)
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
it('Joining stream', async () => {
|
|
85
|
-
manager1.joinStreamPart(STREAM_PART_ID)
|
|
86
|
-
manager2.joinStreamPart(STREAM_PART_ID)
|
|
87
|
-
await until(() => manager1.getNeighbors(STREAM_PART_ID).length === 1)
|
|
88
|
-
await until(() => manager2.getNeighbors(STREAM_PART_ID).length === 1)
|
|
89
|
-
expect(manager1.getNeighbors(STREAM_PART_ID).length).toEqual(1)
|
|
90
|
-
expect(manager2.getNeighbors(STREAM_PART_ID).length).toEqual(1)
|
|
91
|
-
})
|
|
92
|
-
|
|
93
|
-
it('Publishing after joining and waiting for neighbors', async () => {
|
|
94
|
-
manager1.joinStreamPart(STREAM_PART_ID)
|
|
95
|
-
manager2.joinStreamPart(STREAM_PART_ID)
|
|
96
|
-
await until(() => manager1.getNeighbors(STREAM_PART_ID).length === 1)
|
|
97
|
-
await until(() => manager2.getNeighbors(STREAM_PART_ID).length === 1)
|
|
98
|
-
await Promise.all([
|
|
99
|
-
waitForEvent3<Events>(manager1, 'newMessage'),
|
|
100
|
-
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
101
|
-
manager2.broadcast(msg)
|
|
102
|
-
])
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
it('multi-stream pub/sub', async () => {
|
|
106
|
-
const streamPartId2 = StreamPartIDUtils.parse('test2#0')
|
|
107
|
-
manager1.setStreamPartEntryPoints(streamPartId2, [peerDescriptor1])
|
|
108
|
-
manager2.setStreamPartEntryPoints(streamPartId2, [peerDescriptor1])
|
|
109
|
-
manager1.joinStreamPart(STREAM_PART_ID)
|
|
110
|
-
manager1.joinStreamPart(streamPartId2)
|
|
111
|
-
manager2.joinStreamPart(STREAM_PART_ID)
|
|
112
|
-
manager2.joinStreamPart(streamPartId2)
|
|
113
|
-
await Promise.all([
|
|
114
|
-
until(() => manager1.getNeighbors(STREAM_PART_ID).length === 1),
|
|
115
|
-
until(() => manager2.getNeighbors(STREAM_PART_ID).length === 1),
|
|
116
|
-
until(() => manager1.getNeighbors(streamPartId2).length === 1),
|
|
117
|
-
until(() => manager2.getNeighbors(streamPartId2).length === 1)
|
|
118
|
-
])
|
|
119
|
-
const msg2 = createStreamMessage(
|
|
120
|
-
JSON.stringify({ hello: 'WORLD' }),
|
|
121
|
-
streamPartId2,
|
|
122
|
-
randomUserId()
|
|
123
|
-
)
|
|
124
|
-
await Promise.all([
|
|
125
|
-
waitForEvent3<Events>(manager1, 'newMessage'),
|
|
126
|
-
waitForEvent3<Events>(manager2, 'newMessage'),
|
|
127
|
-
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
128
|
-
manager1.broadcast(msg2),
|
|
129
|
-
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
130
|
-
manager2.broadcast(msg)
|
|
131
|
-
])
|
|
132
|
-
})
|
|
133
|
-
|
|
134
|
-
it('leaving stream parts', async () => {
|
|
135
|
-
manager1.joinStreamPart(STREAM_PART_ID)
|
|
136
|
-
manager2.joinStreamPart(STREAM_PART_ID)
|
|
137
|
-
await Promise.all([
|
|
138
|
-
until(() => manager1.getNeighbors(STREAM_PART_ID).length === 1),
|
|
139
|
-
until(() => manager2.getNeighbors(STREAM_PART_ID).length === 1)
|
|
140
|
-
])
|
|
141
|
-
await manager2.leaveStreamPart(STREAM_PART_ID)
|
|
142
|
-
await until(() => manager1.getNeighbors(STREAM_PART_ID).length === 0)
|
|
143
|
-
})
|
|
144
|
-
|
|
145
|
-
it('RTTs are updated for node info', async () => {
|
|
146
|
-
manager1.joinStreamPart(STREAM_PART_ID)
|
|
147
|
-
manager2.joinStreamPart(STREAM_PART_ID)
|
|
148
|
-
await Promise.all([
|
|
149
|
-
until(() => manager1.getNeighbors(STREAM_PART_ID).length === 1),
|
|
150
|
-
until(() => manager2.getNeighbors(STREAM_PART_ID).length === 1)
|
|
151
|
-
])
|
|
152
|
-
// Wait for RTTs to be updated
|
|
153
|
-
await wait(500)
|
|
154
|
-
const nodeInfo1 = manager1.getNodeInfo()
|
|
155
|
-
const nodeInfo2 = manager2.getNodeInfo()
|
|
156
|
-
expect(nodeInfo1[0].contentDeliveryLayerNeighbors[0].rtt).toBeGreaterThanOrEqual(0)
|
|
157
|
-
expect(nodeInfo2[0].contentDeliveryLayerNeighbors[0].rtt).toBeGreaterThanOrEqual(0)
|
|
158
|
-
})
|
|
159
|
-
|
|
160
|
-
})
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ListeningRpcCommunicator,
|
|
3
|
-
NodeType,
|
|
4
|
-
PeerDescriptor,
|
|
5
|
-
Simulator,
|
|
6
|
-
SimulatorTransport
|
|
7
|
-
} from '@streamr/dht'
|
|
8
|
-
import { StreamPartIDUtils, until } from '@streamr/utils'
|
|
9
|
-
import { ContentDeliveryRpcRemote } from '../../src/logic/ContentDeliveryRpcRemote'
|
|
10
|
-
import { Empty } from '../../generated/google/protobuf/empty'
|
|
11
|
-
import {
|
|
12
|
-
LeaveStreamPartNotice,
|
|
13
|
-
StreamMessage
|
|
14
|
-
} from '../../generated/packages/trackerless-network/protos/NetworkRpc'
|
|
15
|
-
import { ContentDeliveryRpcClient } from '../../generated/packages/trackerless-network/protos/NetworkRpc.client'
|
|
16
|
-
import { createStreamMessage } from '../utils/utils'
|
|
17
|
-
import { randomUserId } from '@streamr/test-utils'
|
|
18
|
-
|
|
19
|
-
describe('ContentDeliveryRpcRemote', () => {
|
|
20
|
-
let mockServerRpc: ListeningRpcCommunicator
|
|
21
|
-
let clientRpc: ListeningRpcCommunicator
|
|
22
|
-
let rpcRemote: ContentDeliveryRpcRemote
|
|
23
|
-
|
|
24
|
-
const clientNode: PeerDescriptor = {
|
|
25
|
-
nodeId: new Uint8Array([1, 1, 1]),
|
|
26
|
-
type: NodeType.NODEJS
|
|
27
|
-
}
|
|
28
|
-
const serverNode: PeerDescriptor = {
|
|
29
|
-
nodeId: new Uint8Array([2, 2, 2]),
|
|
30
|
-
type: NodeType.NODEJS
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
let recvCounter: number
|
|
34
|
-
|
|
35
|
-
let simulator: Simulator
|
|
36
|
-
let mockConnectionManager1: SimulatorTransport
|
|
37
|
-
let mockConnectionManager2: SimulatorTransport
|
|
38
|
-
|
|
39
|
-
beforeEach(async () => {
|
|
40
|
-
recvCounter = 0
|
|
41
|
-
simulator = new Simulator()
|
|
42
|
-
mockConnectionManager1 = new SimulatorTransport(serverNode, simulator)
|
|
43
|
-
await mockConnectionManager1.start()
|
|
44
|
-
mockConnectionManager2 = new SimulatorTransport(clientNode, simulator)
|
|
45
|
-
await mockConnectionManager2.start()
|
|
46
|
-
|
|
47
|
-
mockServerRpc = new ListeningRpcCommunicator('test', mockConnectionManager1)
|
|
48
|
-
clientRpc = new ListeningRpcCommunicator('test', mockConnectionManager2)
|
|
49
|
-
|
|
50
|
-
mockServerRpc.registerRpcNotification(
|
|
51
|
-
StreamMessage,
|
|
52
|
-
'sendStreamMessage',
|
|
53
|
-
async (): Promise<Empty> => {
|
|
54
|
-
recvCounter += 1
|
|
55
|
-
return Empty
|
|
56
|
-
}
|
|
57
|
-
)
|
|
58
|
-
|
|
59
|
-
mockServerRpc.registerRpcNotification(
|
|
60
|
-
LeaveStreamPartNotice,
|
|
61
|
-
'leaveStreamPartNotice',
|
|
62
|
-
async (): Promise<Empty> => {
|
|
63
|
-
recvCounter += 1
|
|
64
|
-
return Empty
|
|
65
|
-
}
|
|
66
|
-
)
|
|
67
|
-
|
|
68
|
-
rpcRemote = new ContentDeliveryRpcRemote(
|
|
69
|
-
clientNode,
|
|
70
|
-
serverNode,
|
|
71
|
-
clientRpc,
|
|
72
|
-
ContentDeliveryRpcClient
|
|
73
|
-
)
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
afterEach(async () => {
|
|
77
|
-
clientRpc.stop()
|
|
78
|
-
mockServerRpc.stop()
|
|
79
|
-
await mockConnectionManager1.stop()
|
|
80
|
-
await mockConnectionManager2.stop()
|
|
81
|
-
simulator.stop()
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
it('sendStreamMessage', async () => {
|
|
85
|
-
const msg = createStreamMessage(
|
|
86
|
-
JSON.stringify({ hello: 'WORLD' }),
|
|
87
|
-
StreamPartIDUtils.parse('test-stream#0'),
|
|
88
|
-
randomUserId()
|
|
89
|
-
)
|
|
90
|
-
|
|
91
|
-
await rpcRemote.sendStreamMessage(msg)
|
|
92
|
-
await until(() => recvCounter === 1)
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
it('leaveNotice', async () => {
|
|
96
|
-
rpcRemote.leaveStreamPartNotice(StreamPartIDUtils.parse('test#0'), false)
|
|
97
|
-
await until(() => recvCounter === 1)
|
|
98
|
-
})
|
|
99
|
-
|
|
100
|
-
})
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ListeningRpcCommunicator,
|
|
3
|
-
NodeType,
|
|
4
|
-
PeerDescriptor,
|
|
5
|
-
Simulator,
|
|
6
|
-
SimulatorTransport
|
|
7
|
-
} from '@streamr/dht'
|
|
8
|
-
import { StreamPartIDUtils } from '@streamr/utils'
|
|
9
|
-
import { HandshakeRpcRemote } from '../../src/logic/neighbor-discovery/HandshakeRpcRemote'
|
|
10
|
-
import {
|
|
11
|
-
StreamPartHandshakeRequest,
|
|
12
|
-
StreamPartHandshakeResponse
|
|
13
|
-
} from '../../generated/packages/trackerless-network/protos/NetworkRpc'
|
|
14
|
-
import {
|
|
15
|
-
HandshakeRpcClient,
|
|
16
|
-
} from '../../generated/packages/trackerless-network/protos/NetworkRpc.client'
|
|
17
|
-
|
|
18
|
-
describe('HandshakeRpcRemote', () => {
|
|
19
|
-
let mockServerRpc: ListeningRpcCommunicator
|
|
20
|
-
let clientRpc: ListeningRpcCommunicator
|
|
21
|
-
let rpcRemote: HandshakeRpcRemote
|
|
22
|
-
|
|
23
|
-
const clientNode: PeerDescriptor = {
|
|
24
|
-
nodeId: new Uint8Array([1, 1, 1]),
|
|
25
|
-
type: NodeType.NODEJS
|
|
26
|
-
}
|
|
27
|
-
const serverNode: PeerDescriptor = {
|
|
28
|
-
nodeId: new Uint8Array([2, 2, 2]),
|
|
29
|
-
type: NodeType.NODEJS
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
let simulator: Simulator
|
|
33
|
-
let mockConnectionManager1: SimulatorTransport
|
|
34
|
-
let mockConnectionManager2: SimulatorTransport
|
|
35
|
-
|
|
36
|
-
beforeEach(async () => {
|
|
37
|
-
simulator = new Simulator()
|
|
38
|
-
mockConnectionManager1 = new SimulatorTransport(serverNode, simulator)
|
|
39
|
-
await mockConnectionManager1.start()
|
|
40
|
-
mockConnectionManager2 = new SimulatorTransport(clientNode, simulator)
|
|
41
|
-
await mockConnectionManager2.start()
|
|
42
|
-
|
|
43
|
-
mockServerRpc = new ListeningRpcCommunicator('test', mockConnectionManager1)
|
|
44
|
-
clientRpc = new ListeningRpcCommunicator('test', mockConnectionManager2)
|
|
45
|
-
|
|
46
|
-
mockServerRpc.registerRpcMethod(
|
|
47
|
-
StreamPartHandshakeRequest,
|
|
48
|
-
StreamPartHandshakeResponse,
|
|
49
|
-
'handshake',
|
|
50
|
-
async (msg: StreamPartHandshakeRequest): Promise<StreamPartHandshakeResponse> => {
|
|
51
|
-
const res: StreamPartHandshakeResponse = {
|
|
52
|
-
requestId: msg.requestId,
|
|
53
|
-
accepted: true
|
|
54
|
-
}
|
|
55
|
-
return res
|
|
56
|
-
}
|
|
57
|
-
)
|
|
58
|
-
|
|
59
|
-
rpcRemote = new HandshakeRpcRemote(
|
|
60
|
-
clientNode,
|
|
61
|
-
serverNode,
|
|
62
|
-
clientRpc,
|
|
63
|
-
HandshakeRpcClient
|
|
64
|
-
)
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
afterEach(async () => {
|
|
68
|
-
clientRpc.stop()
|
|
69
|
-
mockServerRpc.stop()
|
|
70
|
-
await mockConnectionManager1.stop()
|
|
71
|
-
await mockConnectionManager2.stop()
|
|
72
|
-
simulator.stop()
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
it('handshake', async () => {
|
|
76
|
-
const result = await rpcRemote.handshake(StreamPartIDUtils.parse('test#0'), [])
|
|
77
|
-
expect(result.accepted).toEqual(true)
|
|
78
|
-
})
|
|
79
|
-
})
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ListeningRpcCommunicator,
|
|
3
|
-
NodeType,
|
|
4
|
-
PeerDescriptor,
|
|
5
|
-
Simulator,
|
|
6
|
-
SimulatorTransport,
|
|
7
|
-
toNodeId
|
|
8
|
-
} from '@streamr/dht'
|
|
9
|
-
import { StreamPartIDUtils } from '@streamr/utils'
|
|
10
|
-
import { NodeList } from '../../src/logic/NodeList'
|
|
11
|
-
import { Handshaker } from '../../src/logic/neighbor-discovery/Handshaker'
|
|
12
|
-
import { StreamPartHandshakeRequest, StreamPartHandshakeResponse } from '../../generated/packages/trackerless-network/protos/NetworkRpc'
|
|
13
|
-
import { ContentDeliveryRpcClient } from '../../generated/packages/trackerless-network/protos/NetworkRpc.client'
|
|
14
|
-
import { ContentDeliveryRpcRemote } from '../../src/logic/ContentDeliveryRpcRemote'
|
|
15
|
-
|
|
16
|
-
describe('Handshakes', () => {
|
|
17
|
-
|
|
18
|
-
const peerDescriptor1: PeerDescriptor = {
|
|
19
|
-
nodeId: new Uint8Array([1, 1, 1]),
|
|
20
|
-
type: NodeType.NODEJS
|
|
21
|
-
}
|
|
22
|
-
const peerDescriptor2: PeerDescriptor = {
|
|
23
|
-
nodeId: new Uint8Array([2, 1, 1]),
|
|
24
|
-
type: NodeType.NODEJS
|
|
25
|
-
}
|
|
26
|
-
const peerDescriptor3: PeerDescriptor = {
|
|
27
|
-
nodeId: new Uint8Array([3, 1, 1]),
|
|
28
|
-
type: NodeType.NODEJS
|
|
29
|
-
}
|
|
30
|
-
let rpcCommunicator1: ListeningRpcCommunicator
|
|
31
|
-
let rpcCommunicator2: ListeningRpcCommunicator
|
|
32
|
-
let rpcCommunicator3: ListeningRpcCommunicator
|
|
33
|
-
let neighbors: NodeList
|
|
34
|
-
let leftNodeView: NodeList
|
|
35
|
-
let rightNodeView: NodeList
|
|
36
|
-
let nodeView: NodeList
|
|
37
|
-
let handshaker: Handshaker
|
|
38
|
-
const streamPartId = StreamPartIDUtils.parse('stream#0')
|
|
39
|
-
|
|
40
|
-
const acceptHandshake = async (request: StreamPartHandshakeRequest): Promise<StreamPartHandshakeResponse> => {
|
|
41
|
-
const response: StreamPartHandshakeResponse = {
|
|
42
|
-
requestId: request.requestId,
|
|
43
|
-
accepted: true
|
|
44
|
-
}
|
|
45
|
-
return response
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const rejectHandshake = async (request: StreamPartHandshakeRequest): Promise<StreamPartHandshakeResponse> => {
|
|
49
|
-
const response: StreamPartHandshakeResponse = {
|
|
50
|
-
requestId: request.requestId,
|
|
51
|
-
accepted: false
|
|
52
|
-
}
|
|
53
|
-
return response
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const interleavingHandshake = async (request: StreamPartHandshakeRequest): Promise<StreamPartHandshakeResponse> => {
|
|
57
|
-
const response: StreamPartHandshakeResponse = {
|
|
58
|
-
requestId: request.requestId,
|
|
59
|
-
accepted: true,
|
|
60
|
-
interleaveTargetDescriptor: peerDescriptor3
|
|
61
|
-
}
|
|
62
|
-
return response
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
let simulator: Simulator
|
|
66
|
-
let simulatorTransport1: SimulatorTransport
|
|
67
|
-
let simulatorTransport2: SimulatorTransport
|
|
68
|
-
let simulatorTransport3: SimulatorTransport
|
|
69
|
-
|
|
70
|
-
beforeEach(async () => {
|
|
71
|
-
simulator = new Simulator()
|
|
72
|
-
simulatorTransport1 = new SimulatorTransport(peerDescriptor1, simulator)
|
|
73
|
-
await simulatorTransport1.start()
|
|
74
|
-
simulatorTransport2 = new SimulatorTransport(peerDescriptor2, simulator)
|
|
75
|
-
await simulatorTransport2.start()
|
|
76
|
-
simulatorTransport3 = new SimulatorTransport(peerDescriptor3, simulator)
|
|
77
|
-
await simulatorTransport3.start()
|
|
78
|
-
|
|
79
|
-
rpcCommunicator1 = new ListeningRpcCommunicator(streamPartId, simulatorTransport1)
|
|
80
|
-
rpcCommunicator2 = new ListeningRpcCommunicator(streamPartId, simulatorTransport2)
|
|
81
|
-
rpcCommunicator3 = new ListeningRpcCommunicator(streamPartId, simulatorTransport3)
|
|
82
|
-
|
|
83
|
-
const handshakerNodeId = toNodeId(peerDescriptor2)
|
|
84
|
-
leftNodeView = new NodeList(handshakerNodeId, 10)
|
|
85
|
-
rightNodeView = new NodeList(handshakerNodeId, 10)
|
|
86
|
-
nodeView = new NodeList(handshakerNodeId, 10)
|
|
87
|
-
nodeView.add(new ContentDeliveryRpcRemote(
|
|
88
|
-
peerDescriptor2,
|
|
89
|
-
peerDescriptor1,
|
|
90
|
-
rpcCommunicator2,
|
|
91
|
-
ContentDeliveryRpcClient
|
|
92
|
-
))
|
|
93
|
-
neighbors = new NodeList(handshakerNodeId, 4)
|
|
94
|
-
handshaker = new Handshaker({
|
|
95
|
-
localPeerDescriptor: peerDescriptor2,
|
|
96
|
-
streamPartId,
|
|
97
|
-
nearbyNodeView: nodeView,
|
|
98
|
-
randomNodeView: nodeView,
|
|
99
|
-
leftNodeView,
|
|
100
|
-
rightNodeView,
|
|
101
|
-
neighbors,
|
|
102
|
-
rpcCommunicator: rpcCommunicator2,
|
|
103
|
-
maxNeighborCount: 4,
|
|
104
|
-
ongoingHandshakes: new Set()
|
|
105
|
-
})
|
|
106
|
-
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
afterEach(async () => {
|
|
110
|
-
rpcCommunicator1.stop()
|
|
111
|
-
rpcCommunicator2.stop()
|
|
112
|
-
rpcCommunicator3.stop()
|
|
113
|
-
await simulatorTransport1.stop()
|
|
114
|
-
await simulatorTransport2.stop()
|
|
115
|
-
await simulatorTransport3.stop()
|
|
116
|
-
simulator.stop()
|
|
117
|
-
})
|
|
118
|
-
|
|
119
|
-
it('Handshake accepted', async () => {
|
|
120
|
-
rpcCommunicator1.registerRpcMethod(StreamPartHandshakeRequest, StreamPartHandshakeResponse, 'handshake', acceptHandshake)
|
|
121
|
-
const res = await handshaker.attemptHandshakesOnContacts([])
|
|
122
|
-
expect(res).toHaveLength(0)
|
|
123
|
-
expect(neighbors.has(toNodeId(peerDescriptor1))).toEqual(true)
|
|
124
|
-
})
|
|
125
|
-
|
|
126
|
-
it('Handshake rejected', async () => {
|
|
127
|
-
rpcCommunicator1.registerRpcMethod(StreamPartHandshakeRequest, StreamPartHandshakeResponse, 'handshake', rejectHandshake)
|
|
128
|
-
const res = await handshaker.attemptHandshakesOnContacts([])
|
|
129
|
-
expect(res[0]).toEqual(toNodeId(peerDescriptor1))
|
|
130
|
-
expect(neighbors.has(toNodeId(peerDescriptor1))).toEqual(false)
|
|
131
|
-
})
|
|
132
|
-
|
|
133
|
-
it('Handshake with Interleaving', async () => {
|
|
134
|
-
rpcCommunicator1.registerRpcMethod(StreamPartHandshakeRequest, StreamPartHandshakeResponse, 'handshake', interleavingHandshake)
|
|
135
|
-
rpcCommunicator3.registerRpcMethod(StreamPartHandshakeRequest, StreamPartHandshakeResponse, 'handshake', acceptHandshake)
|
|
136
|
-
const res = await handshaker.attemptHandshakesOnContacts([])
|
|
137
|
-
expect(res).toHaveLength(0)
|
|
138
|
-
expect(neighbors.has(toNodeId(peerDescriptor1))).toEqual(true)
|
|
139
|
-
expect(neighbors.has(toNodeId(peerDescriptor3))).toEqual(true)
|
|
140
|
-
})
|
|
141
|
-
})
|