@streamr/trackerless-network 102.0.0-beta.1 → 102.0.0-beta.2
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,89 +0,0 @@
|
|
|
1
|
-
import { LatencyType, PeerDescriptor, Simulator, SimulatorTransport } from '@streamr/dht'
|
|
2
|
-
import { StreamPartIDUtils } 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('inspect', () => {
|
|
9
|
-
|
|
10
|
-
let simulator: Simulator
|
|
11
|
-
|
|
12
|
-
const streamPartId = StreamPartIDUtils.parse('stream#0')
|
|
13
|
-
let sequenceNumber: number
|
|
14
|
-
|
|
15
|
-
const publisherDescriptor = createMockPeerDescriptor()
|
|
16
|
-
const inspectorPeerDescriptor = createMockPeerDescriptor()
|
|
17
|
-
|
|
18
|
-
const inspectedNodeCount = 12
|
|
19
|
-
|
|
20
|
-
let publisherNode: NetworkStack
|
|
21
|
-
let inspectorNode: NetworkStack
|
|
22
|
-
let inspectedNodes: NetworkStack[]
|
|
23
|
-
|
|
24
|
-
let publishInterval: NodeJS.Timeout
|
|
25
|
-
|
|
26
|
-
const initiateNode = async (peerDescriptor: PeerDescriptor, simulator: Simulator): Promise<NetworkStack> => {
|
|
27
|
-
const transport = new SimulatorTransport(peerDescriptor, simulator)
|
|
28
|
-
await transport.start()
|
|
29
|
-
const node = new NetworkStack({
|
|
30
|
-
layer0: {
|
|
31
|
-
entryPoints: [publisherDescriptor],
|
|
32
|
-
peerDescriptor,
|
|
33
|
-
transport,
|
|
34
|
-
connectionsView: transport
|
|
35
|
-
}
|
|
36
|
-
})
|
|
37
|
-
await node.start()
|
|
38
|
-
return node
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
beforeEach(async () => {
|
|
42
|
-
simulator = new Simulator(LatencyType.REAL)
|
|
43
|
-
|
|
44
|
-
publisherNode = await initiateNode(publisherDescriptor, simulator)
|
|
45
|
-
inspectorNode = await initiateNode(inspectorPeerDescriptor, simulator)
|
|
46
|
-
|
|
47
|
-
inspectedNodes = []
|
|
48
|
-
await Promise.all(range(inspectedNodeCount).map(async () => {
|
|
49
|
-
const peerDescriptor = createMockPeerDescriptor()
|
|
50
|
-
const node = await initiateNode(peerDescriptor, simulator)
|
|
51
|
-
inspectedNodes.push(node)
|
|
52
|
-
}))
|
|
53
|
-
await Promise.all([
|
|
54
|
-
publisherNode.joinStreamPart(streamPartId, { minCount: 4, timeout: 15000 }),
|
|
55
|
-
inspectorNode.joinStreamPart(streamPartId, { minCount: 4, timeout: 15000 }),
|
|
56
|
-
...inspectedNodes.map((node) => node.joinStreamPart(streamPartId, { minCount: 4, timeout: 15000 }))
|
|
57
|
-
])
|
|
58
|
-
sequenceNumber = 0
|
|
59
|
-
}, 30000)
|
|
60
|
-
|
|
61
|
-
afterEach(async () => {
|
|
62
|
-
clearInterval(publishInterval)
|
|
63
|
-
await Promise.all([
|
|
64
|
-
publisherNode.stop(),
|
|
65
|
-
inspectorNode.stop(),
|
|
66
|
-
...inspectedNodes.map((node) => node.stop())
|
|
67
|
-
])
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
it('gets successful inspections from all suspects', async () => {
|
|
71
|
-
publishInterval = setInterval(async () => {
|
|
72
|
-
const msg = createStreamMessage(
|
|
73
|
-
JSON.stringify({ hello: 'WORLD' }),
|
|
74
|
-
streamPartId,
|
|
75
|
-
randomUserId(),
|
|
76
|
-
123123,
|
|
77
|
-
sequenceNumber
|
|
78
|
-
)
|
|
79
|
-
publisherNode.getContentDeliveryManager().broadcast(msg)
|
|
80
|
-
sequenceNumber += 1
|
|
81
|
-
}, 200)
|
|
82
|
-
|
|
83
|
-
for (const node of inspectedNodes) {
|
|
84
|
-
const result = await inspectorNode.getContentDeliveryManager().inspect(node.getControlLayerNode().getLocalPeerDescriptor(), streamPartId)
|
|
85
|
-
expect(result).toEqual(true)
|
|
86
|
-
}
|
|
87
|
-
}, 25000)
|
|
88
|
-
|
|
89
|
-
})
|
|
@@ -1,82 +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 { NeighborUpdateRpcRemote } from '../../src/logic/neighbor-discovery/NeighborUpdateRpcRemote'
|
|
10
|
-
import { NeighborUpdate } from '../../generated/packages/trackerless-network/protos/NetworkRpc'
|
|
11
|
-
import {
|
|
12
|
-
NeighborUpdateRpcClient,
|
|
13
|
-
} from '../../generated/packages/trackerless-network/protos/NetworkRpc.client'
|
|
14
|
-
|
|
15
|
-
describe('NeighborUpdateRpcRemote', () => {
|
|
16
|
-
let mockServerRpc: ListeningRpcCommunicator
|
|
17
|
-
let clientRpc: ListeningRpcCommunicator
|
|
18
|
-
let rpcRemote: NeighborUpdateRpcRemote
|
|
19
|
-
|
|
20
|
-
const clientNode: PeerDescriptor = {
|
|
21
|
-
nodeId: new Uint8Array([1, 1, 1]),
|
|
22
|
-
type: NodeType.NODEJS
|
|
23
|
-
}
|
|
24
|
-
const serverNode: PeerDescriptor = {
|
|
25
|
-
nodeId: new Uint8Array([2, 2, 2]),
|
|
26
|
-
type: NodeType.NODEJS
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
let simulator: Simulator
|
|
30
|
-
let mockConnectionManager1: SimulatorTransport
|
|
31
|
-
let mockConnectionManager2: SimulatorTransport
|
|
32
|
-
|
|
33
|
-
beforeEach(async () => {
|
|
34
|
-
simulator = new Simulator()
|
|
35
|
-
mockConnectionManager1 = new SimulatorTransport(serverNode, simulator)
|
|
36
|
-
await mockConnectionManager1.start()
|
|
37
|
-
mockConnectionManager2 = new SimulatorTransport(clientNode, simulator)
|
|
38
|
-
await mockConnectionManager2.start()
|
|
39
|
-
|
|
40
|
-
mockServerRpc = new ListeningRpcCommunicator('test', mockConnectionManager1)
|
|
41
|
-
clientRpc = new ListeningRpcCommunicator('test', mockConnectionManager2)
|
|
42
|
-
|
|
43
|
-
mockServerRpc.registerRpcMethod(
|
|
44
|
-
NeighborUpdate,
|
|
45
|
-
NeighborUpdate,
|
|
46
|
-
'neighborUpdate',
|
|
47
|
-
async (): Promise<NeighborUpdate> => {
|
|
48
|
-
const node: PeerDescriptor = {
|
|
49
|
-
nodeId: new Uint8Array([4, 2, 4]),
|
|
50
|
-
type: NodeType.NODEJS
|
|
51
|
-
}
|
|
52
|
-
const update: NeighborUpdate = {
|
|
53
|
-
streamPartId: StreamPartIDUtils.parse('stream#0'),
|
|
54
|
-
neighborDescriptors: [
|
|
55
|
-
node
|
|
56
|
-
],
|
|
57
|
-
removeMe: false
|
|
58
|
-
}
|
|
59
|
-
return update
|
|
60
|
-
}
|
|
61
|
-
)
|
|
62
|
-
rpcRemote = new NeighborUpdateRpcRemote(
|
|
63
|
-
clientNode,
|
|
64
|
-
serverNode,
|
|
65
|
-
clientRpc,
|
|
66
|
-
NeighborUpdateRpcClient
|
|
67
|
-
)
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
afterEach(async () => {
|
|
71
|
-
clientRpc.stop()
|
|
72
|
-
mockServerRpc.stop()
|
|
73
|
-
await mockConnectionManager1.stop()
|
|
74
|
-
await mockConnectionManager2.stop()
|
|
75
|
-
simulator.stop()
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
it('updateNeighbors', async () => {
|
|
79
|
-
const res = await rpcRemote.updateNeighbors(StreamPartIDUtils.parse('test#0'), [])
|
|
80
|
-
expect(res.peerDescriptors.length).toEqual(1)
|
|
81
|
-
})
|
|
82
|
-
})
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { PeerDescriptor, Simulator, SimulatorTransport } from '@streamr/dht'
|
|
2
|
-
import { randomUserId } from '@streamr/test-utils'
|
|
3
|
-
import { StreamPartIDUtils, hexToBinary, toUserIdRaw, utf8ToBinary, until } from '@streamr/utils'
|
|
4
|
-
import { NetworkNode, createNetworkNode } from '../../src/NetworkNode'
|
|
5
|
-
import { ContentType, EncryptionType, SignatureType, StreamMessage } from '../../generated/packages/trackerless-network/protos/NetworkRpc'
|
|
6
|
-
import { createMockPeerDescriptor } from '../utils/utils'
|
|
7
|
-
|
|
8
|
-
const STREAM_PART_ID = StreamPartIDUtils.parse('test#0')
|
|
9
|
-
|
|
10
|
-
describe('NetworkNode', () => {
|
|
11
|
-
|
|
12
|
-
let transport1: SimulatorTransport
|
|
13
|
-
let transport2: SimulatorTransport
|
|
14
|
-
|
|
15
|
-
let node1: NetworkNode
|
|
16
|
-
let node2: NetworkNode
|
|
17
|
-
|
|
18
|
-
const pd1: PeerDescriptor = createMockPeerDescriptor()
|
|
19
|
-
|
|
20
|
-
const pd2: PeerDescriptor = createMockPeerDescriptor()
|
|
21
|
-
|
|
22
|
-
beforeEach(async () => {
|
|
23
|
-
const simulator = new Simulator()
|
|
24
|
-
transport1 = new SimulatorTransport(pd1, simulator)
|
|
25
|
-
await transport1.start()
|
|
26
|
-
transport2 = new SimulatorTransport(pd2, simulator)
|
|
27
|
-
await transport2.start()
|
|
28
|
-
|
|
29
|
-
node1 = createNetworkNode({
|
|
30
|
-
layer0: {
|
|
31
|
-
entryPoints: [pd1],
|
|
32
|
-
peerDescriptor: pd1,
|
|
33
|
-
transport: transport1,
|
|
34
|
-
connectionsView: transport1
|
|
35
|
-
}
|
|
36
|
-
})
|
|
37
|
-
node2 = createNetworkNode({
|
|
38
|
-
layer0: {
|
|
39
|
-
entryPoints: [pd1],
|
|
40
|
-
peerDescriptor: pd2,
|
|
41
|
-
transport: transport2,
|
|
42
|
-
connectionsView: transport2
|
|
43
|
-
}
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
await node1.start()
|
|
47
|
-
node1.setStreamPartEntryPoints(STREAM_PART_ID, [pd1])
|
|
48
|
-
await node2.start()
|
|
49
|
-
node2.setStreamPartEntryPoints(STREAM_PART_ID, [pd1])
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
afterEach(async () => {
|
|
53
|
-
await Promise.all([
|
|
54
|
-
node1.stop(),
|
|
55
|
-
node2.stop()
|
|
56
|
-
])
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
it('wait for join + broadcast and subscribe', async () => {
|
|
60
|
-
const streamMessage: StreamMessage = {
|
|
61
|
-
messageId: {
|
|
62
|
-
streamId: StreamPartIDUtils.getStreamID(STREAM_PART_ID),
|
|
63
|
-
streamPartition: StreamPartIDUtils.getStreamPartition(STREAM_PART_ID),
|
|
64
|
-
timestamp: 666,
|
|
65
|
-
sequenceNumber: 0,
|
|
66
|
-
publisherId: toUserIdRaw(randomUserId()),
|
|
67
|
-
messageChainId: 'msgChainId'
|
|
68
|
-
},
|
|
69
|
-
previousMessageRef: {
|
|
70
|
-
timestamp: 665,
|
|
71
|
-
sequenceNumber: 0
|
|
72
|
-
},
|
|
73
|
-
body: {
|
|
74
|
-
oneofKind: 'contentMessage',
|
|
75
|
-
contentMessage: {
|
|
76
|
-
content: utf8ToBinary(JSON.stringify({
|
|
77
|
-
hello: 'world'
|
|
78
|
-
})),
|
|
79
|
-
contentType: ContentType.JSON,
|
|
80
|
-
encryptionType: EncryptionType.NONE,
|
|
81
|
-
}
|
|
82
|
-
},
|
|
83
|
-
signatureType: SignatureType.SECP256K1,
|
|
84
|
-
signature: hexToBinary('0x1234'),
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
let msgCount = 0
|
|
88
|
-
await node1.join(STREAM_PART_ID)
|
|
89
|
-
node1.addMessageListener((msg) => {
|
|
90
|
-
expect(msg.messageId!.timestamp).toEqual(666)
|
|
91
|
-
expect(msg.messageId!.sequenceNumber).toEqual(0)
|
|
92
|
-
msgCount += 1
|
|
93
|
-
})
|
|
94
|
-
await node2.broadcast(streamMessage)
|
|
95
|
-
await until(() => msgCount === 1)
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
it('fetchNodeInfo', async () => {
|
|
99
|
-
await node1.join(STREAM_PART_ID)
|
|
100
|
-
await node2.join(STREAM_PART_ID)
|
|
101
|
-
const result1 = await node1.fetchNodeInfo(pd2)
|
|
102
|
-
const result2 = await node2.fetchNodeInfo(pd1)
|
|
103
|
-
const result3 = await node1.fetchNodeInfo(node1.getPeerDescriptor())
|
|
104
|
-
expect(result1.streamPartitions.length).toEqual(1)
|
|
105
|
-
expect(result2.streamPartitions.length).toEqual(1)
|
|
106
|
-
expect(result3.streamPartitions.length).toEqual(1)
|
|
107
|
-
expect(result1.controlLayer.connections.length).toEqual(1)
|
|
108
|
-
expect(result2.controlLayer.connections.length).toEqual(1)
|
|
109
|
-
expect(result3.controlLayer.connections.length).toEqual(1)
|
|
110
|
-
expect(result1.controlLayer.neighbors.length).toEqual(1)
|
|
111
|
-
expect(result2.controlLayer.neighbors.length).toEqual(1)
|
|
112
|
-
expect(result3.controlLayer.neighbors.length).toEqual(1)
|
|
113
|
-
})
|
|
114
|
-
|
|
115
|
-
})
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { DhtCallContext } from '@streamr/dht'
|
|
2
|
-
import {
|
|
3
|
-
ProtoRpcClient,
|
|
4
|
-
RpcCommunicator,
|
|
5
|
-
toProtoRpcClient
|
|
6
|
-
} from '@streamr/proto-rpc'
|
|
7
|
-
import { StreamPartIDUtils, until } from '@streamr/utils'
|
|
8
|
-
import { Empty } from '../../generated/google/protobuf/empty'
|
|
9
|
-
import { RpcMessage } from '../../generated/packages/proto-rpc/protos/ProtoRpc'
|
|
10
|
-
import { StreamMessage } from '../../generated/packages/trackerless-network/protos/NetworkRpc'
|
|
11
|
-
import { ContentDeliveryRpcClient } from '../../generated/packages/trackerless-network/protos/NetworkRpc.client'
|
|
12
|
-
import { createStreamMessage } from '../utils/utils'
|
|
13
|
-
import { randomUserId } from '@streamr/test-utils'
|
|
14
|
-
|
|
15
|
-
describe('Network RPC', () => {
|
|
16
|
-
let rpcCommunicator1: RpcCommunicator<DhtCallContext>
|
|
17
|
-
let rpcCommunicator2: RpcCommunicator<DhtCallContext>
|
|
18
|
-
let client: ProtoRpcClient<ContentDeliveryRpcClient>
|
|
19
|
-
let recvCounter = 0
|
|
20
|
-
|
|
21
|
-
beforeEach(() => {
|
|
22
|
-
rpcCommunicator1 = new RpcCommunicator()
|
|
23
|
-
rpcCommunicator2 = new RpcCommunicator()
|
|
24
|
-
rpcCommunicator1.setOutgoingMessageListener(async (message: RpcMessage) => {
|
|
25
|
-
rpcCommunicator2.handleIncomingMessage(message, new DhtCallContext())
|
|
26
|
-
})
|
|
27
|
-
client = toProtoRpcClient(new ContentDeliveryRpcClient(rpcCommunicator1.getRpcClientTransport()))
|
|
28
|
-
rpcCommunicator2.registerRpcNotification(
|
|
29
|
-
StreamMessage,
|
|
30
|
-
'sendStreamMessage',
|
|
31
|
-
async (): Promise<Empty> => {
|
|
32
|
-
recvCounter += 1
|
|
33
|
-
return {}
|
|
34
|
-
}
|
|
35
|
-
)
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
afterEach(() => {
|
|
39
|
-
rpcCommunicator1.stop()
|
|
40
|
-
rpcCommunicator2.stop()
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
it('sends Data', async () => {
|
|
44
|
-
const msg = createStreamMessage(
|
|
45
|
-
JSON.stringify({ hello: 'WORLD' }),
|
|
46
|
-
StreamPartIDUtils.parse('testStream#0'),
|
|
47
|
-
randomUserId()
|
|
48
|
-
)
|
|
49
|
-
await client.sendStreamMessage(msg)
|
|
50
|
-
await until(() => recvCounter === 1)
|
|
51
|
-
})
|
|
52
|
-
})
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
StreamPartIDUtils,
|
|
3
|
-
until
|
|
4
|
-
} from '@streamr/utils'
|
|
5
|
-
import { NetworkStack } from '../../src/NetworkStack'
|
|
6
|
-
import { createMockPeerDescriptor, createStreamMessage } from '../utils/utils'
|
|
7
|
-
import { randomUserId } from '@streamr/test-utils'
|
|
8
|
-
|
|
9
|
-
const STREAM_PART_ID = StreamPartIDUtils.parse('stream#0')
|
|
10
|
-
|
|
11
|
-
describe('NetworkStack', () => {
|
|
12
|
-
|
|
13
|
-
let stack1: NetworkStack
|
|
14
|
-
let stack2: NetworkStack
|
|
15
|
-
|
|
16
|
-
const epDescriptor = createMockPeerDescriptor({
|
|
17
|
-
websocket: { host: '127.0.0.1', port: 32222, tls: false }
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
beforeEach(async () => {
|
|
21
|
-
stack1 = new NetworkStack({
|
|
22
|
-
layer0: {
|
|
23
|
-
peerDescriptor: epDescriptor,
|
|
24
|
-
entryPoints: [epDescriptor],
|
|
25
|
-
websocketServerEnableTls: false
|
|
26
|
-
}
|
|
27
|
-
})
|
|
28
|
-
stack2 = new NetworkStack({
|
|
29
|
-
layer0: {
|
|
30
|
-
websocketPortRange: { min: 32223, max: 32223 },
|
|
31
|
-
entryPoints: [epDescriptor],
|
|
32
|
-
websocketServerEnableTls: false
|
|
33
|
-
}
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
await stack1.start()
|
|
37
|
-
stack1.getContentDeliveryManager().setStreamPartEntryPoints(STREAM_PART_ID, [epDescriptor])
|
|
38
|
-
await stack2.start()
|
|
39
|
-
stack2.getContentDeliveryManager().setStreamPartEntryPoints(STREAM_PART_ID, [epDescriptor])
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
afterEach(async () => {
|
|
43
|
-
await Promise.all([
|
|
44
|
-
stack1.stop(),
|
|
45
|
-
stack2.stop()
|
|
46
|
-
])
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
it('Can use NetworkNode pub/sub via NetworkStack', async () => {
|
|
50
|
-
let receivedMessages = 0
|
|
51
|
-
stack1.getContentDeliveryManager().joinStreamPart(STREAM_PART_ID)
|
|
52
|
-
stack1.getContentDeliveryManager().on('newMessage', () => {
|
|
53
|
-
receivedMessages += 1
|
|
54
|
-
})
|
|
55
|
-
const msg = createStreamMessage(
|
|
56
|
-
JSON.stringify({ hello: 'WORLD' }),
|
|
57
|
-
STREAM_PART_ID,
|
|
58
|
-
randomUserId()
|
|
59
|
-
)
|
|
60
|
-
stack2.getContentDeliveryManager().broadcast(msg)
|
|
61
|
-
await until(() => receivedMessages === 1)
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
it('join and wait for neighbors', async () => {
|
|
65
|
-
await Promise.all([
|
|
66
|
-
stack1.joinStreamPart(STREAM_PART_ID, { minCount: 1, timeout: 5000 }),
|
|
67
|
-
stack2.joinStreamPart(STREAM_PART_ID, { minCount: 1, timeout: 5000 }),
|
|
68
|
-
])
|
|
69
|
-
expect(stack1.getContentDeliveryManager().getNeighbors(STREAM_PART_ID).length).toBe(1)
|
|
70
|
-
expect(stack2.getContentDeliveryManager().getNeighbors(STREAM_PART_ID).length).toBe(1)
|
|
71
|
-
})
|
|
72
|
-
})
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { ListeningRpcCommunicator, PeerDescriptor, Simulator, SimulatorTransport } from '@streamr/dht'
|
|
2
|
-
import { StreamPartIDUtils, until } from '@streamr/utils'
|
|
3
|
-
import { NetworkStack } from '../../src/NetworkStack'
|
|
4
|
-
import { NodeInfoClient } from '../../src/logic/node-info/NodeInfoClient'
|
|
5
|
-
import { NODE_INFO_RPC_SERVICE_ID } from '../../src/logic/node-info/NodeInfoRpcLocal'
|
|
6
|
-
import { createMockPeerDescriptor } from '../utils/utils'
|
|
7
|
-
|
|
8
|
-
// TODO add Jest utility so that the normalization is not needed (NET-1254)
|
|
9
|
-
const normalizePeerDescriptor = (peerDescriptor: PeerDescriptor) => {
|
|
10
|
-
return {
|
|
11
|
-
...peerDescriptor,
|
|
12
|
-
nodeId: new Uint8Array(peerDescriptor.nodeId)
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
describe('NetworkStack NodeInfoRpc', () => {
|
|
17
|
-
|
|
18
|
-
let requesteStack: NetworkStack
|
|
19
|
-
let otherStack: NetworkStack
|
|
20
|
-
let nodeInfoClient: NodeInfoClient
|
|
21
|
-
let requesteeTransport1: SimulatorTransport
|
|
22
|
-
let otherTransport: SimulatorTransport
|
|
23
|
-
let requestorTransport: SimulatorTransport
|
|
24
|
-
|
|
25
|
-
let simulator: Simulator
|
|
26
|
-
|
|
27
|
-
const requesteePeerDescriptor = createMockPeerDescriptor()
|
|
28
|
-
const otherPeerDescriptor = createMockPeerDescriptor()
|
|
29
|
-
const requestorPeerDescriptor = createMockPeerDescriptor()
|
|
30
|
-
|
|
31
|
-
beforeEach(async () => {
|
|
32
|
-
simulator = new Simulator()
|
|
33
|
-
requesteeTransport1 = new SimulatorTransport(requesteePeerDescriptor, simulator)
|
|
34
|
-
otherTransport = new SimulatorTransport(otherPeerDescriptor, simulator)
|
|
35
|
-
requestorTransport = new SimulatorTransport(requestorPeerDescriptor, simulator)
|
|
36
|
-
await requesteeTransport1.start()
|
|
37
|
-
await otherTransport.start()
|
|
38
|
-
await requestorTransport.start()
|
|
39
|
-
requesteStack = new NetworkStack({
|
|
40
|
-
layer0: {
|
|
41
|
-
transport: requesteeTransport1,
|
|
42
|
-
connectionsView: requesteeTransport1,
|
|
43
|
-
peerDescriptor: requesteePeerDescriptor,
|
|
44
|
-
entryPoints: [requesteePeerDescriptor]
|
|
45
|
-
}
|
|
46
|
-
})
|
|
47
|
-
otherStack = new NetworkStack({
|
|
48
|
-
layer0: {
|
|
49
|
-
transport: otherTransport,
|
|
50
|
-
connectionsView: otherTransport,
|
|
51
|
-
peerDescriptor: otherPeerDescriptor,
|
|
52
|
-
entryPoints: [requesteePeerDescriptor]
|
|
53
|
-
}
|
|
54
|
-
})
|
|
55
|
-
await requesteStack.start()
|
|
56
|
-
await otherStack.start()
|
|
57
|
-
nodeInfoClient = new NodeInfoClient(requestorPeerDescriptor, new ListeningRpcCommunicator(NODE_INFO_RPC_SERVICE_ID, requestorTransport))
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
afterEach(async () => {
|
|
61
|
-
await requesteStack.stop()
|
|
62
|
-
await otherStack.stop()
|
|
63
|
-
await requesteeTransport1.stop()
|
|
64
|
-
await otherTransport.stop()
|
|
65
|
-
await requestorTransport.stop()
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
it('happy path', async () => {
|
|
69
|
-
const streamPartId1 = StreamPartIDUtils.parse('stream1#0')
|
|
70
|
-
const streamPartId2 = StreamPartIDUtils.parse('stream2#0')
|
|
71
|
-
requesteStack.getContentDeliveryManager().joinStreamPart(streamPartId1)
|
|
72
|
-
otherStack.getContentDeliveryManager().joinStreamPart(streamPartId1)
|
|
73
|
-
requesteStack.getContentDeliveryManager().joinStreamPart(streamPartId2)
|
|
74
|
-
otherStack.getContentDeliveryManager().joinStreamPart(streamPartId2)
|
|
75
|
-
await until(() =>
|
|
76
|
-
requesteStack.getContentDeliveryManager().getNeighbors(streamPartId1).length === 1
|
|
77
|
-
&& otherStack.getContentDeliveryManager().getNeighbors(streamPartId1).length === 1
|
|
78
|
-
&& requesteStack.getContentDeliveryManager().getNeighbors(streamPartId2).length === 1
|
|
79
|
-
&& otherStack.getContentDeliveryManager().getNeighbors(streamPartId2).length === 1
|
|
80
|
-
)
|
|
81
|
-
const result = await nodeInfoClient.getInfo(requesteePeerDescriptor)
|
|
82
|
-
expect(result).toMatchObject({
|
|
83
|
-
peerDescriptor: normalizePeerDescriptor(requesteePeerDescriptor),
|
|
84
|
-
controlLayer: {
|
|
85
|
-
neighbors: [normalizePeerDescriptor(otherPeerDescriptor)],
|
|
86
|
-
connections: [normalizePeerDescriptor(otherPeerDescriptor), normalizePeerDescriptor(requestorPeerDescriptor)]
|
|
87
|
-
},
|
|
88
|
-
streamPartitions: [
|
|
89
|
-
{
|
|
90
|
-
id: streamPartId1,
|
|
91
|
-
controlLayerNeighbors: [normalizePeerDescriptor(otherPeerDescriptor)],
|
|
92
|
-
contentDeliveryLayerNeighbors: [{
|
|
93
|
-
peerDescriptor: normalizePeerDescriptor(otherPeerDescriptor)
|
|
94
|
-
}]
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
id: streamPartId2,
|
|
98
|
-
controlLayerNeighbors: [normalizePeerDescriptor(otherPeerDescriptor)],
|
|
99
|
-
contentDeliveryLayerNeighbors: [{
|
|
100
|
-
peerDescriptor: normalizePeerDescriptor(otherPeerDescriptor)
|
|
101
|
-
}]
|
|
102
|
-
}
|
|
103
|
-
],
|
|
104
|
-
applicationVersion: expect.any(String)
|
|
105
|
-
})
|
|
106
|
-
expect(result.streamPartitions.length).toEqual(2)
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
})
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { Simulator } 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 { createMockContentDeliveryLayerNodeAndDhtNode, createMockPeerDescriptor, createStreamMessage } from '../utils/utils'
|
|
7
|
-
import { randomUserId } from '@streamr/test-utils'
|
|
8
|
-
|
|
9
|
-
describe('Propagation', () => {
|
|
10
|
-
const entryPointDescriptor = createMockPeerDescriptor()
|
|
11
|
-
let discoveryLayerNodes: DiscoveryLayerNode[]
|
|
12
|
-
let contentDeliveryLayerNodes: ContentDeliveryLayerNode[]
|
|
13
|
-
const STREAM_PART_ID = StreamPartIDUtils.parse('testingtesting#0')
|
|
14
|
-
let totalReceived: number
|
|
15
|
-
const NUM_OF_NODES = 256
|
|
16
|
-
|
|
17
|
-
beforeEach(async () => {
|
|
18
|
-
const simulator = new Simulator()
|
|
19
|
-
totalReceived = 0
|
|
20
|
-
discoveryLayerNodes = []
|
|
21
|
-
contentDeliveryLayerNodes = []
|
|
22
|
-
const [entryPoint, node1] = await createMockContentDeliveryLayerNodeAndDhtNode(
|
|
23
|
-
entryPointDescriptor,
|
|
24
|
-
entryPointDescriptor,
|
|
25
|
-
STREAM_PART_ID,
|
|
26
|
-
simulator
|
|
27
|
-
)
|
|
28
|
-
await entryPoint.start()
|
|
29
|
-
await entryPoint.joinDht([entryPointDescriptor])
|
|
30
|
-
await node1.start()
|
|
31
|
-
node1.on('message', () => {totalReceived += 1})
|
|
32
|
-
discoveryLayerNodes.push(entryPoint)
|
|
33
|
-
contentDeliveryLayerNodes.push(node1)
|
|
34
|
-
|
|
35
|
-
await Promise.all(range(NUM_OF_NODES).map(async (_i) => {
|
|
36
|
-
const descriptor = createMockPeerDescriptor()
|
|
37
|
-
const [layer1, contentDeliveryLayerNode] = await createMockContentDeliveryLayerNodeAndDhtNode(
|
|
38
|
-
descriptor,
|
|
39
|
-
entryPointDescriptor,
|
|
40
|
-
STREAM_PART_ID,
|
|
41
|
-
simulator
|
|
42
|
-
)
|
|
43
|
-
await layer1.start()
|
|
44
|
-
await contentDeliveryLayerNode.start()
|
|
45
|
-
await layer1.joinDht([entryPointDescriptor]).then(() => {
|
|
46
|
-
contentDeliveryLayerNode.on('message', () => { totalReceived += 1 })
|
|
47
|
-
discoveryLayerNodes.push(layer1)
|
|
48
|
-
contentDeliveryLayerNodes.push(contentDeliveryLayerNode)
|
|
49
|
-
})
|
|
50
|
-
}))
|
|
51
|
-
}, 45000)
|
|
52
|
-
|
|
53
|
-
afterEach(async () => {
|
|
54
|
-
await Promise.all(contentDeliveryLayerNodes.map((node) => node.stop()))
|
|
55
|
-
await Promise.all(discoveryLayerNodes.map((node) => node.stop()))
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
it('All nodes receive messages', async () => {
|
|
59
|
-
await until(
|
|
60
|
-
() => contentDeliveryLayerNodes.every((node) => node.getNeighbors().length >= 3), 30000
|
|
61
|
-
)
|
|
62
|
-
await until(() => {
|
|
63
|
-
const avg = contentDeliveryLayerNodes.reduce((acc, curr) => {
|
|
64
|
-
return acc + curr.getNeighbors().length
|
|
65
|
-
}, 0) / contentDeliveryLayerNodes.length
|
|
66
|
-
return avg >= 4
|
|
67
|
-
}, 20000)
|
|
68
|
-
const msg = createStreamMessage(
|
|
69
|
-
JSON.stringify({ hello: 'WORLD' }),
|
|
70
|
-
STREAM_PART_ID,
|
|
71
|
-
randomUserId()
|
|
72
|
-
)
|
|
73
|
-
contentDeliveryLayerNodes[0].broadcast(msg)
|
|
74
|
-
await until(() => totalReceived >= NUM_OF_NODES, 10000)
|
|
75
|
-
}, 45000)
|
|
76
|
-
})
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { LatencyType, PeerDescriptor, Simulator, SimulatorTransport } from '@streamr/dht'
|
|
2
|
-
import { StreamPartIDUtils, until } from '@streamr/utils'
|
|
3
|
-
import { NetworkStack } from '../../src/NetworkStack'
|
|
4
|
-
import { streamPartIdToDataKey } from '../../src/logic/ContentDeliveryManager'
|
|
5
|
-
import { Any } from '../../generated/google/protobuf/any'
|
|
6
|
-
import { createMockPeerDescriptor, createStreamMessage } from '../utils/utils'
|
|
7
|
-
import { randomUserId } from '@streamr/test-utils'
|
|
8
|
-
|
|
9
|
-
const STREAM_PART_ID = StreamPartIDUtils.parse('stream#0')
|
|
10
|
-
|
|
11
|
-
describe('Joining stream parts on offline nodes', () => {
|
|
12
|
-
|
|
13
|
-
const entryPointPeerDescriptor: PeerDescriptor = createMockPeerDescriptor()
|
|
14
|
-
const node1PeerDescriptor: PeerDescriptor = createMockPeerDescriptor()
|
|
15
|
-
const node2PeerDescriptor: PeerDescriptor = createMockPeerDescriptor()
|
|
16
|
-
const offlineDescriptor1: PeerDescriptor = createMockPeerDescriptor()
|
|
17
|
-
const offlineDescriptor2: PeerDescriptor = createMockPeerDescriptor()
|
|
18
|
-
|
|
19
|
-
let entryPoint: NetworkStack
|
|
20
|
-
let node1: NetworkStack
|
|
21
|
-
let node2: NetworkStack
|
|
22
|
-
let simulator: Simulator
|
|
23
|
-
|
|
24
|
-
beforeEach(async () => {
|
|
25
|
-
simulator = new Simulator(LatencyType.REAL)
|
|
26
|
-
const entryPointTransport = new SimulatorTransport(entryPointPeerDescriptor, simulator)
|
|
27
|
-
entryPoint = new NetworkStack({
|
|
28
|
-
layer0: {
|
|
29
|
-
transport: entryPointTransport,
|
|
30
|
-
connectionsView: entryPointTransport,
|
|
31
|
-
peerDescriptor: entryPointPeerDescriptor,
|
|
32
|
-
entryPoints: [entryPointPeerDescriptor]
|
|
33
|
-
}
|
|
34
|
-
})
|
|
35
|
-
const node1Transport = new SimulatorTransport(node1PeerDescriptor, simulator)
|
|
36
|
-
node1 = new NetworkStack({
|
|
37
|
-
layer0: {
|
|
38
|
-
transport: node1Transport,
|
|
39
|
-
connectionsView: node1Transport,
|
|
40
|
-
peerDescriptor: node1PeerDescriptor,
|
|
41
|
-
entryPoints: [entryPointPeerDescriptor]
|
|
42
|
-
}
|
|
43
|
-
})
|
|
44
|
-
const node2Transport = new SimulatorTransport(node2PeerDescriptor, simulator)
|
|
45
|
-
node2 = new NetworkStack({
|
|
46
|
-
layer0: {
|
|
47
|
-
transport: node2Transport,
|
|
48
|
-
connectionsView: node2Transport,
|
|
49
|
-
peerDescriptor: node2PeerDescriptor,
|
|
50
|
-
entryPoints: [entryPointPeerDescriptor]
|
|
51
|
-
}
|
|
52
|
-
})
|
|
53
|
-
await entryPointTransport.start()
|
|
54
|
-
await node1Transport.start()
|
|
55
|
-
await node2Transport.start()
|
|
56
|
-
await entryPoint.start()
|
|
57
|
-
await node1.start()
|
|
58
|
-
await node2.start()
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
afterEach(async () => {
|
|
62
|
-
await entryPoint.stop()
|
|
63
|
-
await node1.stop()
|
|
64
|
-
await node2.stop()
|
|
65
|
-
simulator.stop()
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
it('should recover if discovered nodes are offline', async () => {
|
|
69
|
-
let messageReceived = false
|
|
70
|
-
|
|
71
|
-
// store offline peer descriptors to DHT
|
|
72
|
-
await entryPoint.getControlLayerNode().storeDataToDht(streamPartIdToDataKey(STREAM_PART_ID), Any.pack(offlineDescriptor1, PeerDescriptor))
|
|
73
|
-
await entryPoint.getControlLayerNode().storeDataToDht(streamPartIdToDataKey(STREAM_PART_ID), Any.pack(offlineDescriptor2, PeerDescriptor))
|
|
74
|
-
|
|
75
|
-
node1.getContentDeliveryManager().joinStreamPart(STREAM_PART_ID)
|
|
76
|
-
node1.getContentDeliveryManager().on('newMessage', () => { messageReceived = true })
|
|
77
|
-
const msg = createStreamMessage(JSON.stringify({ hello: 'WORLD' }), STREAM_PART_ID, randomUserId())
|
|
78
|
-
node2.getContentDeliveryManager().broadcast(msg)
|
|
79
|
-
await until(() => messageReceived, 40000)
|
|
80
|
-
}, 60000)
|
|
81
|
-
|
|
82
|
-
})
|