@streamr/trackerless-network 100.0.0-testnet-three.6 → 100.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/package.json +7 -7
- package/dist/src/NetworkNode.js +11 -11
- package/dist/src/NetworkNode.js.map +1 -1
- package/dist/src/NetworkStack.d.ts +6 -6
- package/dist/src/NetworkStack.js +22 -20
- package/dist/src/NetworkStack.js.map +1 -1
- package/dist/src/exports.d.ts +3 -3
- package/dist/src/exports.js +7 -1
- package/dist/src/exports.js.map +1 -1
- package/dist/src/logic/{StreamrNode.d.ts → ContentDeliveryManager.d.ts} +6 -6
- package/dist/src/logic/{StreamrNode.js → ContentDeliveryManager.js} +16 -13
- package/dist/src/logic/ContentDeliveryManager.js.map +1 -0
- package/dist/src/logic/{DeliveryRpcLocal.d.ts → ContentDeliveryRpcLocal.d.ts} +4 -4
- package/dist/src/logic/{DeliveryRpcLocal.js → ContentDeliveryRpcLocal.js} +4 -4
- package/dist/src/logic/ContentDeliveryRpcLocal.js.map +1 -0
- package/dist/src/logic/{DeliveryRpcRemote.d.ts → ContentDeliveryRpcRemote.d.ts} +2 -2
- package/dist/src/logic/{DeliveryRpcRemote.js → ContentDeliveryRpcRemote.js} +4 -4
- package/dist/src/logic/ContentDeliveryRpcRemote.js.map +1 -0
- package/dist/src/logic/EntryPointDiscovery.d.ts +1 -1
- package/dist/src/logic/EntryPointDiscovery.js +3 -3
- package/dist/src/logic/EntryPointDiscovery.js.map +1 -1
- package/dist/src/logic/Layer0Node.d.ts +1 -1
- package/dist/src/logic/Layer1Node.d.ts +7 -1
- package/dist/src/logic/NodeList.d.ts +11 -10
- package/dist/src/logic/NodeList.js +7 -2
- package/dist/src/logic/NodeList.js.map +1 -1
- package/dist/src/logic/RandomGraphNode.d.ts +4 -1
- package/dist/src/logic/RandomGraphNode.js +36 -14
- package/dist/src/logic/RandomGraphNode.js.map +1 -1
- package/dist/src/logic/createRandomGraphNode.d.ts +1 -1
- package/dist/src/logic/createRandomGraphNode.js +16 -7
- package/dist/src/logic/createRandomGraphNode.js.map +1 -1
- package/dist/src/logic/formStreamPartDeliveryServiceId.d.ts +1 -1
- package/dist/src/logic/formStreamPartDeliveryServiceId.js +4 -3
- package/dist/src/logic/formStreamPartDeliveryServiceId.js.map +1 -1
- package/dist/src/logic/inspect/Inspector.js +2 -2
- package/dist/src/logic/inspect/Inspector.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/HandshakeRpcLocal.d.ts +3 -4
- package/dist/src/logic/neighbor-discovery/HandshakeRpcLocal.js +6 -11
- package/dist/src/logic/neighbor-discovery/HandshakeRpcLocal.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/HandshakeRpcRemote.js +2 -2
- package/dist/src/logic/neighbor-discovery/HandshakeRpcRemote.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/Handshaker.d.ts +4 -3
- package/dist/src/logic/neighbor-discovery/Handshaker.js +35 -16
- package/dist/src/logic/neighbor-discovery/Handshaker.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborFinder.d.ts +3 -0
- package/dist/src/logic/neighbor-discovery/NeighborFinder.js +7 -1
- package/dist/src/logic/neighbor-discovery/NeighborFinder.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateManager.d.ts +1 -2
- package/dist/src/logic/neighbor-discovery/NeighborUpdateManager.js +0 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateManager.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.d.ts +1 -2
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.js +2 -3
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcRemote.js +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcRemote.js.map +1 -1
- package/dist/src/logic/protocol-integration/stream-message/GroupKeyResponseTranslator.js.map +1 -1
- package/dist/src/logic/protocol-integration/stream-message/StreamMessageTranslator.js +64 -52
- package/dist/src/logic/protocol-integration/stream-message/StreamMessageTranslator.js.map +1 -1
- package/dist/src/logic/protocol-integration/stream-message/oldStreamMessageBinaryUtils.d.ts +5 -1
- package/dist/src/logic/protocol-integration/stream-message/oldStreamMessageBinaryUtils.js +19 -1
- package/dist/src/logic/protocol-integration/stream-message/oldStreamMessageBinaryUtils.js.map +1 -1
- package/dist/src/logic/proxy/ProxyClient.d.ts +1 -1
- package/dist/src/logic/proxy/ProxyClient.js +8 -8
- package/dist/src/logic/proxy/ProxyClient.js.map +1 -1
- package/dist/src/logic/proxy/ProxyConnectionRpcLocal.d.ts +2 -2
- package/dist/src/logic/proxy/ProxyConnectionRpcLocal.js +5 -5
- package/dist/src/logic/proxy/ProxyConnectionRpcLocal.js.map +1 -1
- package/dist/src/logic/proxy/ProxyConnectionRpcRemote.js +1 -1
- package/dist/src/logic/proxy/ProxyConnectionRpcRemote.js.map +1 -1
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcLocal.d.ts +5 -1
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcLocal.js +7 -2
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcLocal.js.map +1 -1
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcRemote.js +2 -2
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcRemote.js.map +1 -1
- package/dist/src/proto/google/protobuf/any.d.ts +11 -4
- package/dist/src/proto/google/protobuf/any.js.map +1 -1
- package/dist/src/proto/google/protobuf/empty.d.ts +0 -1
- package/dist/src/proto/google/protobuf/empty.js.map +1 -1
- package/dist/src/proto/google/protobuf/timestamp.d.ts +9 -3
- package/dist/src/proto/google/protobuf/timestamp.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +16 -6
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +11 -4
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +98 -87
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +45 -49
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +10 -4
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.client.d.ts +4 -4
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.client.js +7 -7
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.client.js.map +1 -1
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.d.ts +62 -26
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.js +31 -14
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.js.map +1 -1
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.server.d.ts +2 -2
- package/dist/test/benchmark/first-message.js +5 -5
- package/dist/test/benchmark/first-message.js.map +1 -1
- package/dist/test/utils/utils.d.ts +2 -2
- package/dist/test/utils/utils.js +18 -11
- package/dist/test/utils/utils.js.map +1 -1
- package/karma.config.js +2 -0
- package/package.json +7 -7
- package/protos/NetworkRpc.proto +19 -11
- package/src/NetworkNode.ts +11 -11
- package/src/NetworkStack.ts +30 -25
- package/src/exports.ts +7 -3
- package/src/logic/{StreamrNode.ts → ContentDeliveryManager.ts} +21 -17
- package/src/logic/{DeliveryRpcLocal.ts → ContentDeliveryRpcLocal.ts} +5 -5
- package/src/logic/{DeliveryRpcRemote.ts → ContentDeliveryRpcRemote.ts} +2 -2
- package/src/logic/EntryPointDiscovery.ts +4 -4
- package/src/logic/Layer0Node.ts +1 -1
- package/src/logic/Layer1Node.ts +16 -1
- package/src/logic/NodeList.ts +20 -14
- package/src/logic/RandomGraphNode.ts +89 -27
- package/src/logic/createRandomGraphNode.ts +18 -9
- package/src/logic/formStreamPartDeliveryServiceId.ts +2 -1
- package/src/logic/inspect/Inspector.ts +2 -2
- package/src/logic/neighbor-discovery/HandshakeRpcLocal.ts +10 -15
- package/src/logic/neighbor-discovery/HandshakeRpcRemote.ts +2 -2
- package/src/logic/neighbor-discovery/Handshaker.ts +41 -22
- package/src/logic/neighbor-discovery/NeighborFinder.ts +10 -1
- package/src/logic/neighbor-discovery/NeighborUpdateManager.ts +1 -3
- package/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.ts +5 -7
- package/src/logic/neighbor-discovery/NeighborUpdateRpcRemote.ts +1 -1
- package/src/logic/protocol-integration/stream-message/GroupKeyResponseTranslator.ts +0 -1
- package/src/logic/protocol-integration/stream-message/StreamMessageTranslator.ts +74 -71
- package/src/logic/protocol-integration/stream-message/oldStreamMessageBinaryUtils.ts +28 -2
- package/src/logic/proxy/ProxyClient.ts +11 -11
- package/src/logic/proxy/ProxyConnectionRpcLocal.ts +9 -11
- package/src/logic/proxy/ProxyConnectionRpcRemote.ts +1 -1
- package/src/logic/temporary-connection/TemporaryConnectionRpcLocal.ts +14 -6
- package/src/logic/temporary-connection/TemporaryConnectionRpcRemote.ts +2 -2
- package/src/proto/google/protobuf/any.ts +11 -4
- package/src/proto/google/protobuf/empty.ts +0 -1
- package/src/proto/google/protobuf/timestamp.ts +9 -3
- package/src/proto/packages/dht/protos/DhtRpc.client.ts +22 -9
- package/src/proto/packages/dht/protos/DhtRpc.server.ts +10 -4
- package/src/proto/packages/dht/protos/DhtRpc.ts +122 -100
- package/src/proto/packages/trackerless-network/protos/NetworkRpc.client.ts +8 -8
- package/src/proto/packages/trackerless-network/protos/NetworkRpc.server.ts +2 -2
- package/src/proto/packages/trackerless-network/protos/NetworkRpc.ts +79 -37
- package/test/benchmark/StreamPartIdDataKeyDistribution.test.ts +60 -0
- package/test/benchmark/first-message.ts +5 -5
- package/test/end-to-end/inspect.test.ts +6 -6
- package/test/end-to-end/proxy-and-full-node.test.ts +19 -19
- package/test/end-to-end/proxy-connections.test.ts +7 -7
- package/test/end-to-end/proxy-key-exchange.test.ts +16 -13
- package/test/end-to-end/webrtc-full-node-network.test.ts +8 -8
- package/test/end-to-end/websocket-full-node-network.test.ts +9 -9
- package/test/integration/ContentDeliveryManager.test.ts +135 -0
- package/test/integration/{DeliveryRpcRemote.test.ts → ContentDeliveryRpcRemote.test.ts} +6 -6
- package/test/integration/Handshakes.test.ts +7 -3
- package/test/integration/Inspect.test.ts +2 -2
- package/test/integration/NetworkRpc.test.ts +3 -3
- package/test/integration/NetworkStack.test.ts +7 -7
- package/test/integration/NodeInfoRpc.test.ts +10 -10
- package/test/integration/joining-streams-on-offline-peers.test.ts +3 -3
- package/test/integration/stream-without-default-entrypoints.test.ts +1 -1
- package/test/integration/streamEntryPointReplacing.test.ts +10 -8
- package/test/unit/ContentDeliveryManager.test.ts +96 -0
- package/test/unit/{DeliveryRpcLocal.test.ts → ContentDeliveryRpcLocal.test.ts} +4 -4
- package/test/unit/EntrypointDiscovery.test.ts +4 -4
- package/test/unit/HandshakeRpcLocal.test.ts +31 -15
- package/test/unit/Handshaker.test.ts +8 -3
- package/test/unit/NeighborFinder.test.ts +5 -2
- package/test/unit/NeighborUpdateRpcLocal.test.ts +8 -12
- package/test/unit/NetworkNode.test.ts +6 -6
- package/test/unit/NodeList.test.ts +6 -6
- package/test/unit/Propagation.test.ts +10 -7
- package/test/unit/RandomGraphNode.test.ts +3 -3
- package/test/unit/StreamMessageTranslator.test.ts +3 -4
- package/test/unit/StreamPartIDDataKey.test.ts +12 -0
- package/test/unit/TemporaryConnectionRpcLocal.test.ts +7 -1
- package/test/utils/mock/MockLayer0Node.ts +1 -1
- package/test/utils/mock/MockLayer1Node.ts +3 -0
- package/test/utils/utils.ts +19 -13
- package/dist/src/logic/DeliveryRpcLocal.js.map +0 -1
- package/dist/src/logic/DeliveryRpcRemote.js.map +0 -1
- package/dist/src/logic/StreamrNode.js.map +0 -1
- package/test/integration/StreamrNode.test.ts +0 -131
- package/test/unit/GroupKeyRequestTranslator.test.ts +0 -36
- package/test/unit/StreamrNode.test.ts +0 -98
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DhtNode,
|
|
3
|
+
Simulator,
|
|
4
|
+
SimulatorTransport
|
|
5
|
+
} from '@streamr/dht'
|
|
6
|
+
import { ContentDeliveryManager, Events } from '../../src/logic/ContentDeliveryManager'
|
|
7
|
+
import { waitForEvent3, waitForCondition } from '@streamr/utils'
|
|
8
|
+
import { createMockPeerDescriptor, createStreamMessage } from '../utils/utils'
|
|
9
|
+
import { StreamPartIDUtils } from '@streamr/protocol'
|
|
10
|
+
import { randomEthereumAddress } from '@streamr/test-utils'
|
|
11
|
+
import { Layer0Node } from '../../src/logic/Layer0Node'
|
|
12
|
+
|
|
13
|
+
describe('ContentDeliveryManager', () => {
|
|
14
|
+
|
|
15
|
+
let layer0Node1: Layer0Node
|
|
16
|
+
let layer0Node2: Layer0Node
|
|
17
|
+
let transport1: SimulatorTransport
|
|
18
|
+
let transport2: SimulatorTransport
|
|
19
|
+
let manager1: ContentDeliveryManager
|
|
20
|
+
let manager2: ContentDeliveryManager
|
|
21
|
+
|
|
22
|
+
const peerDescriptor1 = createMockPeerDescriptor()
|
|
23
|
+
const peerDescriptor2 = createMockPeerDescriptor()
|
|
24
|
+
const STREAM_PART_ID = StreamPartIDUtils.parse('test#0')
|
|
25
|
+
|
|
26
|
+
const msg = createStreamMessage(
|
|
27
|
+
JSON.stringify({ hello: 'WORLD' }),
|
|
28
|
+
STREAM_PART_ID,
|
|
29
|
+
randomEthereumAddress()
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
afterEach(async () => {
|
|
33
|
+
await Promise.all([
|
|
34
|
+
manager1.destroy(),
|
|
35
|
+
manager2.destroy()
|
|
36
|
+
])
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
beforeEach(async () => {
|
|
40
|
+
const simulator = new Simulator()
|
|
41
|
+
transport1 = new SimulatorTransport(peerDescriptor1, simulator)
|
|
42
|
+
await transport1.start()
|
|
43
|
+
transport2 = new SimulatorTransport(peerDescriptor2, simulator)
|
|
44
|
+
await transport2.start()
|
|
45
|
+
layer0Node1 = new DhtNode({
|
|
46
|
+
transport: transport1,
|
|
47
|
+
peerDescriptor: peerDescriptor1,
|
|
48
|
+
entryPoints: [peerDescriptor1]
|
|
49
|
+
})
|
|
50
|
+
layer0Node2 = new DhtNode({
|
|
51
|
+
transport: transport2,
|
|
52
|
+
peerDescriptor: peerDescriptor2,
|
|
53
|
+
entryPoints: [peerDescriptor1]
|
|
54
|
+
})
|
|
55
|
+
await Promise.all([
|
|
56
|
+
layer0Node1.start(),
|
|
57
|
+
layer0Node2.start()
|
|
58
|
+
])
|
|
59
|
+
await Promise.all([
|
|
60
|
+
layer0Node1.joinDht([peerDescriptor1]),
|
|
61
|
+
layer0Node2.joinDht([peerDescriptor1])
|
|
62
|
+
])
|
|
63
|
+
|
|
64
|
+
manager1 = new ContentDeliveryManager({})
|
|
65
|
+
manager2 = new ContentDeliveryManager({})
|
|
66
|
+
await manager1.start(layer0Node1, transport1, transport1)
|
|
67
|
+
manager1.setStreamPartEntryPoints(STREAM_PART_ID, [peerDescriptor1])
|
|
68
|
+
await manager2.start(layer0Node2, transport2, transport2)
|
|
69
|
+
manager2.setStreamPartEntryPoints(STREAM_PART_ID, [peerDescriptor1])
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
it('starts', async () => {
|
|
73
|
+
expect(manager1.getPeerDescriptor()).toEqual(peerDescriptor1)
|
|
74
|
+
expect(manager2.getPeerDescriptor()).toEqual(peerDescriptor2)
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
it('Joining stream', async () => {
|
|
78
|
+
manager1.joinStreamPart(STREAM_PART_ID)
|
|
79
|
+
manager2.joinStreamPart(STREAM_PART_ID)
|
|
80
|
+
await waitForCondition(() => manager1.getNeighbors(STREAM_PART_ID).length === 1)
|
|
81
|
+
await waitForCondition(() => manager2.getNeighbors(STREAM_PART_ID).length === 1)
|
|
82
|
+
expect(manager1.getNeighbors(STREAM_PART_ID).length).toEqual(1)
|
|
83
|
+
expect(manager2.getNeighbors(STREAM_PART_ID).length).toEqual(1)
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
it('Publishing after joining and waiting for neighbors', async () => {
|
|
87
|
+
manager1.joinStreamPart(STREAM_PART_ID)
|
|
88
|
+
manager2.joinStreamPart(STREAM_PART_ID)
|
|
89
|
+
await waitForCondition(() => manager1.getNeighbors(STREAM_PART_ID).length === 1)
|
|
90
|
+
await waitForCondition(() => manager2.getNeighbors(STREAM_PART_ID).length === 1)
|
|
91
|
+
await Promise.all([
|
|
92
|
+
waitForEvent3<Events>(manager1, 'newMessage'),
|
|
93
|
+
manager2.broadcast(msg)
|
|
94
|
+
])
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
it('multi-stream pub/sub', async () => {
|
|
98
|
+
const streamPartId2 = StreamPartIDUtils.parse('test2#0')
|
|
99
|
+
manager1.setStreamPartEntryPoints(streamPartId2, [peerDescriptor1])
|
|
100
|
+
manager2.setStreamPartEntryPoints(streamPartId2, [peerDescriptor1])
|
|
101
|
+
manager1.joinStreamPart(STREAM_PART_ID)
|
|
102
|
+
manager1.joinStreamPart(streamPartId2)
|
|
103
|
+
manager2.joinStreamPart(STREAM_PART_ID)
|
|
104
|
+
manager2.joinStreamPart(streamPartId2)
|
|
105
|
+
await Promise.all([
|
|
106
|
+
waitForCondition(() => manager1.getNeighbors(STREAM_PART_ID).length === 1),
|
|
107
|
+
waitForCondition(() => manager2.getNeighbors(STREAM_PART_ID).length === 1),
|
|
108
|
+
waitForCondition(() => manager1.getNeighbors(streamPartId2).length === 1),
|
|
109
|
+
waitForCondition(() => manager2.getNeighbors(streamPartId2).length === 1)
|
|
110
|
+
])
|
|
111
|
+
const msg2 = createStreamMessage(
|
|
112
|
+
JSON.stringify({ hello: 'WORLD' }),
|
|
113
|
+
streamPartId2,
|
|
114
|
+
randomEthereumAddress()
|
|
115
|
+
)
|
|
116
|
+
await Promise.all([
|
|
117
|
+
waitForEvent3<Events>(manager1, 'newMessage'),
|
|
118
|
+
waitForEvent3<Events>(manager2, 'newMessage'),
|
|
119
|
+
manager1.broadcast(msg2),
|
|
120
|
+
manager2.broadcast(msg)
|
|
121
|
+
])
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
it('leaving stream parts', async () => {
|
|
125
|
+
manager1.joinStreamPart(STREAM_PART_ID)
|
|
126
|
+
manager2.joinStreamPart(STREAM_PART_ID)
|
|
127
|
+
await Promise.all([
|
|
128
|
+
waitForCondition(() => manager1.getNeighbors(STREAM_PART_ID).length === 1),
|
|
129
|
+
waitForCondition(() => manager2.getNeighbors(STREAM_PART_ID).length === 1)
|
|
130
|
+
])
|
|
131
|
+
await manager2.leaveStreamPart(STREAM_PART_ID)
|
|
132
|
+
await waitForCondition(() => manager1.getNeighbors(STREAM_PART_ID).length === 0)
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
})
|
|
@@ -5,8 +5,8 @@ import {
|
|
|
5
5
|
SimulatorTransport,
|
|
6
6
|
NodeType
|
|
7
7
|
} from '@streamr/dht'
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import { ContentDeliveryRpcRemote } from '../../src/logic/ContentDeliveryRpcRemote'
|
|
9
|
+
import { ContentDeliveryRpcClient } from '../../src/proto/packages/trackerless-network/protos/NetworkRpc.client'
|
|
10
10
|
import {
|
|
11
11
|
LeaveStreamPartNotice,
|
|
12
12
|
StreamMessage
|
|
@@ -17,10 +17,10 @@ import { createStreamMessage } from '../utils/utils'
|
|
|
17
17
|
import { StreamPartIDUtils } from '@streamr/protocol'
|
|
18
18
|
import { randomEthereumAddress } from '@streamr/test-utils'
|
|
19
19
|
|
|
20
|
-
describe('
|
|
20
|
+
describe('ContentDeliveryRpcRemote', () => {
|
|
21
21
|
let mockServerRpc: ListeningRpcCommunicator
|
|
22
22
|
let clientRpc: ListeningRpcCommunicator
|
|
23
|
-
let rpcRemote:
|
|
23
|
+
let rpcRemote: ContentDeliveryRpcRemote
|
|
24
24
|
|
|
25
25
|
const clientNode: PeerDescriptor = {
|
|
26
26
|
nodeId: new Uint8Array([1, 1, 1]),
|
|
@@ -66,11 +66,11 @@ describe('DeliveryRpcRemote', () => {
|
|
|
66
66
|
}
|
|
67
67
|
)
|
|
68
68
|
|
|
69
|
-
rpcRemote = new
|
|
69
|
+
rpcRemote = new ContentDeliveryRpcRemote(
|
|
70
70
|
clientNode,
|
|
71
71
|
serverNode,
|
|
72
72
|
clientRpc,
|
|
73
|
-
|
|
73
|
+
ContentDeliveryRpcClient
|
|
74
74
|
)
|
|
75
75
|
})
|
|
76
76
|
|
|
@@ -11,7 +11,6 @@ import {
|
|
|
11
11
|
HandshakeRpcClient
|
|
12
12
|
} from '../../src/proto/packages/trackerless-network/protos/NetworkRpc.client'
|
|
13
13
|
import { NodeList } from '../../src/logic/NodeList'
|
|
14
|
-
import { mockConnectionLocker } from '../utils/utils'
|
|
15
14
|
import { StreamPartHandshakeRequest, StreamPartHandshakeResponse } from '../../src/proto/packages/trackerless-network/protos/NetworkRpc'
|
|
16
15
|
import { HandshakeRpcRemote } from '../../src/logic/neighbor-discovery/HandshakeRpcRemote'
|
|
17
16
|
import { StreamPartIDUtils } from '@streamr/protocol'
|
|
@@ -33,8 +32,10 @@ describe('Handshakes', () => {
|
|
|
33
32
|
let rpcCommunicator1: ListeningRpcCommunicator
|
|
34
33
|
let rpcCommunicator2: ListeningRpcCommunicator
|
|
35
34
|
let rpcCommunicator3: ListeningRpcCommunicator
|
|
36
|
-
let nodeView: NodeList
|
|
37
35
|
let neighbors: NodeList
|
|
36
|
+
let leftNodeView: NodeList
|
|
37
|
+
let rightNodeView: NodeList
|
|
38
|
+
let nodeView: NodeList
|
|
38
39
|
let handshaker: Handshaker
|
|
39
40
|
const streamPartId = StreamPartIDUtils.parse('stream#0')
|
|
40
41
|
|
|
@@ -82,6 +83,8 @@ describe('Handshakes', () => {
|
|
|
82
83
|
rpcCommunicator3 = new ListeningRpcCommunicator(streamPartId, simulatorTransport3)
|
|
83
84
|
|
|
84
85
|
const handshakerNodeId = getNodeIdFromPeerDescriptor(peerDescriptor2)
|
|
86
|
+
leftNodeView = new NodeList(handshakerNodeId, 10)
|
|
87
|
+
rightNodeView = new NodeList(handshakerNodeId, 10)
|
|
85
88
|
nodeView = new NodeList(handshakerNodeId, 10)
|
|
86
89
|
neighbors = new NodeList(handshakerNodeId, 4)
|
|
87
90
|
handshaker = new Handshaker({
|
|
@@ -89,8 +92,9 @@ describe('Handshakes', () => {
|
|
|
89
92
|
streamPartId,
|
|
90
93
|
nearbyNodeView: nodeView,
|
|
91
94
|
randomNodeView: nodeView,
|
|
95
|
+
leftNodeView,
|
|
96
|
+
rightNodeView,
|
|
92
97
|
neighbors,
|
|
93
|
-
connectionLocker: mockConnectionLocker,
|
|
94
98
|
rpcCommunicator: rpcCommunicator2,
|
|
95
99
|
maxNeighborCount: 4,
|
|
96
100
|
ongoingHandshakes: new Set()
|
|
@@ -75,12 +75,12 @@ describe('inspect', () => {
|
|
|
75
75
|
123123,
|
|
76
76
|
sequenceNumber
|
|
77
77
|
)
|
|
78
|
-
publisherNode.
|
|
78
|
+
publisherNode.getContentDeliveryManager().broadcast(msg)
|
|
79
79
|
sequenceNumber += 1
|
|
80
80
|
}, 200)
|
|
81
81
|
|
|
82
82
|
for (const node of inspectedNodes) {
|
|
83
|
-
const result = await inspectorNode.
|
|
83
|
+
const result = await inspectorNode.getContentDeliveryManager().inspect(node.getLayer0Node().getLocalPeerDescriptor(), streamPartId)
|
|
84
84
|
expect(result).toEqual(true)
|
|
85
85
|
}
|
|
86
86
|
}, 25000)
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
ProtoRpcClient,
|
|
4
4
|
toProtoRpcClient
|
|
5
5
|
} from '@streamr/proto-rpc'
|
|
6
|
-
import {
|
|
6
|
+
import { ContentDeliveryRpcClient } from '../../src/proto/packages/trackerless-network/protos/NetworkRpc.client'
|
|
7
7
|
import { StreamMessage } from '../../src/proto/packages/trackerless-network/protos/NetworkRpc'
|
|
8
8
|
import { waitForCondition } from '@streamr/utils'
|
|
9
9
|
import { Empty } from '../../src/proto/google/protobuf/empty'
|
|
@@ -16,7 +16,7 @@ import { randomEthereumAddress } from '@streamr/test-utils'
|
|
|
16
16
|
describe('Network RPC', () => {
|
|
17
17
|
let rpcCommunicator1: RpcCommunicator<DhtCallContext>
|
|
18
18
|
let rpcCommunicator2: RpcCommunicator<DhtCallContext>
|
|
19
|
-
let client: ProtoRpcClient<
|
|
19
|
+
let client: ProtoRpcClient<ContentDeliveryRpcClient>
|
|
20
20
|
let recvCounter = 0
|
|
21
21
|
|
|
22
22
|
beforeEach(() => {
|
|
@@ -25,7 +25,7 @@ describe('Network RPC', () => {
|
|
|
25
25
|
rpcCommunicator1.on('outgoingMessage', (message: RpcMessage) => {
|
|
26
26
|
rpcCommunicator2.handleIncomingMessage(message)
|
|
27
27
|
})
|
|
28
|
-
client = toProtoRpcClient(new
|
|
28
|
+
client = toProtoRpcClient(new ContentDeliveryRpcClient(rpcCommunicator1.getRpcClientTransport()))
|
|
29
29
|
rpcCommunicator2.registerRpcNotification(
|
|
30
30
|
StreamMessage,
|
|
31
31
|
'sendStreamMessage',
|
|
@@ -34,9 +34,9 @@ describe('NetworkStack', () => {
|
|
|
34
34
|
})
|
|
35
35
|
|
|
36
36
|
await stack1.start()
|
|
37
|
-
stack1.
|
|
37
|
+
stack1.getContentDeliveryManager().setStreamPartEntryPoints(STREAM_PART_ID, [epDescriptor])
|
|
38
38
|
await stack2.start()
|
|
39
|
-
stack2.
|
|
39
|
+
stack2.getContentDeliveryManager().setStreamPartEntryPoints(STREAM_PART_ID, [epDescriptor])
|
|
40
40
|
})
|
|
41
41
|
|
|
42
42
|
afterEach(async () => {
|
|
@@ -48,8 +48,8 @@ describe('NetworkStack', () => {
|
|
|
48
48
|
|
|
49
49
|
it('Can use NetworkNode pub/sub via NetworkStack', async () => {
|
|
50
50
|
let receivedMessages = 0
|
|
51
|
-
stack1.
|
|
52
|
-
stack1.
|
|
51
|
+
stack1.getContentDeliveryManager().joinStreamPart(STREAM_PART_ID)
|
|
52
|
+
stack1.getContentDeliveryManager().on('newMessage', () => {
|
|
53
53
|
receivedMessages += 1
|
|
54
54
|
})
|
|
55
55
|
const msg = createStreamMessage(
|
|
@@ -57,7 +57,7 @@ describe('NetworkStack', () => {
|
|
|
57
57
|
STREAM_PART_ID,
|
|
58
58
|
randomEthereumAddress()
|
|
59
59
|
)
|
|
60
|
-
stack2.
|
|
60
|
+
stack2.getContentDeliveryManager().broadcast(msg)
|
|
61
61
|
await waitForCondition(() => receivedMessages === 1)
|
|
62
62
|
})
|
|
63
63
|
|
|
@@ -66,7 +66,7 @@ describe('NetworkStack', () => {
|
|
|
66
66
|
stack1.joinStreamPart(STREAM_PART_ID, { minCount: 1, timeout: 5000 }),
|
|
67
67
|
stack2.joinStreamPart(STREAM_PART_ID, { minCount: 1, timeout: 5000 }),
|
|
68
68
|
])
|
|
69
|
-
expect(stack1.
|
|
70
|
-
expect(stack2.
|
|
69
|
+
expect(stack1.getContentDeliveryManager().getNeighbors(STREAM_PART_ID).length).toBe(1)
|
|
70
|
+
expect(stack2.getContentDeliveryManager().getNeighbors(STREAM_PART_ID).length).toBe(1)
|
|
71
71
|
})
|
|
72
72
|
})
|
|
@@ -67,15 +67,15 @@ describe('NetworkStack NodeInfoRpc', () => {
|
|
|
67
67
|
it('happy path', async () => {
|
|
68
68
|
const streamPartId1 = StreamPartIDUtils.parse('stream1#0')
|
|
69
69
|
const streamPartId2 = StreamPartIDUtils.parse('stream2#0')
|
|
70
|
-
requesteStack.
|
|
71
|
-
otherStack.
|
|
72
|
-
requesteStack.
|
|
73
|
-
otherStack.
|
|
70
|
+
requesteStack.getContentDeliveryManager().joinStreamPart(streamPartId1)
|
|
71
|
+
otherStack.getContentDeliveryManager().joinStreamPart(streamPartId1)
|
|
72
|
+
requesteStack.getContentDeliveryManager().joinStreamPart(streamPartId2)
|
|
73
|
+
otherStack.getContentDeliveryManager().joinStreamPart(streamPartId2)
|
|
74
74
|
await waitForCondition(() =>
|
|
75
|
-
requesteStack.
|
|
76
|
-
&& otherStack.
|
|
77
|
-
&& requesteStack.
|
|
78
|
-
&& otherStack.
|
|
75
|
+
requesteStack.getContentDeliveryManager().getNeighbors(streamPartId1).length === 1
|
|
76
|
+
&& otherStack.getContentDeliveryManager().getNeighbors(streamPartId1).length === 1
|
|
77
|
+
&& requesteStack.getContentDeliveryManager().getNeighbors(streamPartId2).length === 1
|
|
78
|
+
&& otherStack.getContentDeliveryManager().getNeighbors(streamPartId2).length === 1
|
|
79
79
|
)
|
|
80
80
|
const result = await nodeInfoClient.getInfo(requesteePeerDescriptor)
|
|
81
81
|
expect(result).toMatchObject({
|
|
@@ -88,12 +88,12 @@ describe('NetworkStack NodeInfoRpc', () => {
|
|
|
88
88
|
{
|
|
89
89
|
id: streamPartId1,
|
|
90
90
|
controlLayerNeighbors: [normalizePeerDescriptor(otherPeerDescriptor)],
|
|
91
|
-
|
|
91
|
+
contentDeliveryLayerNeighbors: [normalizePeerDescriptor(otherPeerDescriptor)]
|
|
92
92
|
},
|
|
93
93
|
{
|
|
94
94
|
id: streamPartId2,
|
|
95
95
|
controlLayerNeighbors: [normalizePeerDescriptor(otherPeerDescriptor)],
|
|
96
|
-
|
|
96
|
+
contentDeliveryLayerNeighbors: [normalizePeerDescriptor(otherPeerDescriptor)]
|
|
97
97
|
}
|
|
98
98
|
],
|
|
99
99
|
version: expect.any(String)
|
|
@@ -70,10 +70,10 @@ describe('Joining stream parts on offline nodes', () => {
|
|
|
70
70
|
await entryPoint.getLayer0Node().storeDataToDht(streamPartIdToDataKey(STREAM_PART_ID), Any.pack(offlineDescriptor1, PeerDescriptor))
|
|
71
71
|
await entryPoint.getLayer0Node().storeDataToDht(streamPartIdToDataKey(STREAM_PART_ID), Any.pack(offlineDescriptor2, PeerDescriptor))
|
|
72
72
|
|
|
73
|
-
node1.
|
|
74
|
-
node1.
|
|
73
|
+
node1.getContentDeliveryManager().joinStreamPart(STREAM_PART_ID)
|
|
74
|
+
node1.getContentDeliveryManager().on('newMessage', () => { messageReceived = true })
|
|
75
75
|
const msg = createStreamMessage(JSON.stringify({ hello: 'WORLD' }), STREAM_PART_ID, randomEthereumAddress())
|
|
76
|
-
node2.
|
|
76
|
+
node2.getContentDeliveryManager().broadcast(msg)
|
|
77
77
|
await waitForCondition(() => messageReceived, 40000)
|
|
78
78
|
}, 60000)
|
|
79
79
|
|
|
@@ -119,7 +119,7 @@ describe('stream without default entrypoints', () => {
|
|
|
119
119
|
await nodes[i].join(STREAM_PART_ID, { minCount: (i > 0) ? 1 : 0, timeout: 15000 })
|
|
120
120
|
}
|
|
121
121
|
await waitForCondition(async () => {
|
|
122
|
-
const entryPointData = await nodes[15].stack.getLayer0Node().
|
|
122
|
+
const entryPointData = await nodes[15].stack.getLayer0Node().fetchDataFromDht(streamPartIdToDataKey(STREAM_PART_ID))
|
|
123
123
|
return entryPointData.length >= 7
|
|
124
124
|
}, 15000)
|
|
125
125
|
|
|
@@ -68,27 +68,29 @@ describe('Stream Entry Points are replaced when known entry points leave streams
|
|
|
68
68
|
simulator.stop()
|
|
69
69
|
})
|
|
70
70
|
|
|
71
|
+
// TODO: Investigate why 60 second timeouts are needed
|
|
71
72
|
it('stream entry points are replaced when nodes leave streams', async () => {
|
|
72
|
-
|
|
73
|
-
await Promise.all(initialNodesOnStream.map((node) => node.joinStreamPart(STREAM_PART_ID, { minCount: 4, timeout: 30000 })))
|
|
73
|
+
await Promise.all(initialNodesOnStream.map((node) => node.joinStreamPart(STREAM_PART_ID, { minCount: 4, timeout: 60000 })))
|
|
74
74
|
|
|
75
75
|
let receivedMessages = 0
|
|
76
76
|
for (const node of laterNodesOnStream) {
|
|
77
|
-
await node.joinStreamPart(STREAM_PART_ID, { minCount: 4, timeout:
|
|
78
|
-
node.
|
|
77
|
+
await node.joinStreamPart(STREAM_PART_ID, { minCount: 4, timeout: 60000 })
|
|
78
|
+
node.getContentDeliveryManager().on('newMessage', () => {
|
|
79
79
|
receivedMessages += 1
|
|
80
80
|
})
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
await Promise.all(initialNodesOnStream.map((node) => node.
|
|
84
|
-
await waitForCondition(() =>
|
|
83
|
+
await Promise.all(initialNodesOnStream.map((node) => node.getContentDeliveryManager().leaveStreamPart(STREAM_PART_ID)))
|
|
84
|
+
await waitForCondition(() =>
|
|
85
|
+
laterNodesOnStream.every((node) => node.getContentDeliveryManager().getNeighbors(STREAM_PART_ID).length >= 4), 60000, 1000
|
|
86
|
+
)
|
|
85
87
|
|
|
86
88
|
const msg = createStreamMessage(
|
|
87
89
|
JSON.stringify({ hello: 'WORLD' }),
|
|
88
90
|
STREAM_PART_ID,
|
|
89
91
|
randomEthereumAddress()
|
|
90
92
|
)
|
|
91
|
-
newNodeInStream.
|
|
92
|
-
await waitForCondition(() => receivedMessages === NUM_OF_LATER_NODES,
|
|
93
|
+
newNodeInStream.getContentDeliveryManager().broadcast(msg)
|
|
94
|
+
await waitForCondition(() => receivedMessages === NUM_OF_LATER_NODES, 30000)
|
|
93
95
|
}, 200000)
|
|
94
96
|
})
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { areEqualPeerDescriptors } from '@streamr/dht'
|
|
2
|
+
import { StreamPartIDUtils } from '@streamr/protocol'
|
|
3
|
+
import { randomEthereumAddress } from '@streamr/test-utils'
|
|
4
|
+
import { waitForCondition } from '@streamr/utils'
|
|
5
|
+
import { ContentDeliveryManager } from '../../src/logic/ContentDeliveryManager'
|
|
6
|
+
import { MockLayer0Node } from '../utils/mock/MockLayer0Node'
|
|
7
|
+
import { MockTransport } from '../utils/mock/Transport'
|
|
8
|
+
import { createMockPeerDescriptor, createStreamMessage, mockConnectionLocker } from '../utils/utils'
|
|
9
|
+
import { ProxyDirection } from '../../src/proto/packages/trackerless-network/protos/NetworkRpc'
|
|
10
|
+
|
|
11
|
+
describe('ContentDeliveryManager', () => {
|
|
12
|
+
|
|
13
|
+
let manager: ContentDeliveryManager
|
|
14
|
+
const peerDescriptor = createMockPeerDescriptor()
|
|
15
|
+
|
|
16
|
+
beforeEach(async () => {
|
|
17
|
+
manager = new ContentDeliveryManager({})
|
|
18
|
+
const mockLayer0 = new MockLayer0Node(peerDescriptor)
|
|
19
|
+
await manager.start(mockLayer0, new MockTransport(), mockConnectionLocker)
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
afterEach(async () => {
|
|
23
|
+
await manager.destroy()
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
it('PeerDescriptor is correct', () => {
|
|
27
|
+
expect(areEqualPeerDescriptors(peerDescriptor, manager.getPeerDescriptor()))
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
describe('join and leave', () => {
|
|
31
|
+
|
|
32
|
+
const streamPartId = StreamPartIDUtils.parse('stream#0')
|
|
33
|
+
const message = createStreamMessage(
|
|
34
|
+
JSON.stringify({ hello: 'WORLD' }),
|
|
35
|
+
streamPartId,
|
|
36
|
+
randomEthereumAddress()
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
beforeEach(async () => {
|
|
40
|
+
manager.setStreamPartEntryPoints(streamPartId, [manager.getPeerDescriptor()])
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
it('can join stream part', async () => {
|
|
44
|
+
manager.joinStreamPart(streamPartId)
|
|
45
|
+
expect(manager.hasStreamPart(streamPartId)).toEqual(true)
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
it('can leave stream part', async () => {
|
|
49
|
+
manager.joinStreamPart(streamPartId)
|
|
50
|
+
expect(manager.hasStreamPart(streamPartId)).toEqual(true)
|
|
51
|
+
await manager.leaveStreamPart(streamPartId)
|
|
52
|
+
expect(manager.hasStreamPart(streamPartId)).toEqual(false)
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
it('broadcast joins stream', async () => {
|
|
56
|
+
manager.broadcast(message)
|
|
57
|
+
await waitForCondition(() => manager.hasStreamPart(streamPartId))
|
|
58
|
+
})
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
describe('proxied stream', () => {
|
|
62
|
+
it('happy path', async () => {
|
|
63
|
+
const streamPartId = StreamPartIDUtils.parse('stream#0')
|
|
64
|
+
const proxy = createMockPeerDescriptor()
|
|
65
|
+
const userId = randomEthereumAddress()
|
|
66
|
+
await manager.setProxies(streamPartId, [proxy], ProxyDirection.PUBLISH, userId)
|
|
67
|
+
expect(manager.isProxiedStreamPart(streamPartId)).toBe(true)
|
|
68
|
+
await manager.setProxies(streamPartId, [], ProxyDirection.PUBLISH, userId)
|
|
69
|
+
expect(manager.isProxiedStreamPart(streamPartId)).toBe(false)
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
it('empty node list', async () => {
|
|
73
|
+
const streamPartId = StreamPartIDUtils.parse('stream#0')
|
|
74
|
+
const proxy = createMockPeerDescriptor()
|
|
75
|
+
const userId = randomEthereumAddress()
|
|
76
|
+
await manager.setProxies(streamPartId, [], ProxyDirection.PUBLISH, userId)
|
|
77
|
+
expect(manager.isProxiedStreamPart(streamPartId)).toBe(false)
|
|
78
|
+
await manager.setProxies(streamPartId, [proxy], ProxyDirection.PUBLISH, userId)
|
|
79
|
+
expect(manager.isProxiedStreamPart(streamPartId)).toBe(true)
|
|
80
|
+
await manager.setProxies(streamPartId, [], ProxyDirection.PUBLISH, userId)
|
|
81
|
+
expect(manager.isProxiedStreamPart(streamPartId)).toBe(false)
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
it('connection count to 0', async () => {
|
|
85
|
+
const streamPartId = StreamPartIDUtils.parse('stream#0')
|
|
86
|
+
const proxy = createMockPeerDescriptor()
|
|
87
|
+
const userId = randomEthereumAddress()
|
|
88
|
+
await manager.setProxies(streamPartId, [proxy], ProxyDirection.PUBLISH, userId, 0)
|
|
89
|
+
expect(manager.isProxiedStreamPart(streamPartId)).toBe(false)
|
|
90
|
+
await manager.setProxies(streamPartId, [proxy], ProxyDirection.PUBLISH, userId)
|
|
91
|
+
expect(manager.isProxiedStreamPart(streamPartId)).toBe(true)
|
|
92
|
+
await manager.setProxies(streamPartId, [proxy], ProxyDirection.PUBLISH, userId, 0)
|
|
93
|
+
expect(manager.isProxiedStreamPart(streamPartId)).toBe(false)
|
|
94
|
+
})
|
|
95
|
+
})
|
|
96
|
+
})
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { ListeningRpcCommunicator } from '@streamr/dht'
|
|
2
2
|
import { StreamPartIDUtils } from '@streamr/protocol'
|
|
3
3
|
import { randomEthereumAddress } from '@streamr/test-utils'
|
|
4
|
-
import {
|
|
4
|
+
import { ContentDeliveryRpcLocal } from '../../src/logic/ContentDeliveryRpcLocal'
|
|
5
5
|
import { LeaveStreamPartNotice } from '../../src/proto/packages/trackerless-network/protos/NetworkRpc'
|
|
6
6
|
import { MockTransport } from '../utils/mock/Transport'
|
|
7
7
|
import { createMockPeerDescriptor, createStreamMessage } from '../utils/utils'
|
|
8
8
|
|
|
9
|
-
describe('
|
|
9
|
+
describe('ContentDeliveryRpcLocal', () => {
|
|
10
10
|
|
|
11
|
-
let rpcLocal:
|
|
11
|
+
let rpcLocal: ContentDeliveryRpcLocal
|
|
12
12
|
const peerDescriptor = createMockPeerDescriptor()
|
|
13
13
|
|
|
14
14
|
const mockSender = createMockPeerDescriptor()
|
|
@@ -30,7 +30,7 @@ describe('DeliveryRpcLocal', () => {
|
|
|
30
30
|
mockOnLeaveNotice = jest.fn((_m) => {})
|
|
31
31
|
mockMarkForInspection = jest.fn((_m) => {})
|
|
32
32
|
|
|
33
|
-
rpcLocal = new
|
|
33
|
+
rpcLocal = new ContentDeliveryRpcLocal({
|
|
34
34
|
markAndCheckDuplicate: mockDuplicateCheck,
|
|
35
35
|
broadcast: mockBroadcast,
|
|
36
36
|
onLeaveNotice: mockOnLeaveNotice,
|
|
@@ -37,7 +37,7 @@ describe('EntryPointDiscovery', () => {
|
|
|
37
37
|
deleted: true
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
const
|
|
40
|
+
const fakeFetchEntryPointData = async (): Promise<DataEntry[]> => {
|
|
41
41
|
return [fakeData, fakeDeletedData]
|
|
42
42
|
}
|
|
43
43
|
|
|
@@ -46,7 +46,7 @@ describe('EntryPointDiscovery', () => {
|
|
|
46
46
|
return [peerDescriptor]
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
const
|
|
49
|
+
const fakeEmptyFetchEntryPointData = async (): Promise<DataEntry[]> => {
|
|
50
50
|
return []
|
|
51
51
|
}
|
|
52
52
|
|
|
@@ -70,7 +70,7 @@ describe('EntryPointDiscovery', () => {
|
|
|
70
70
|
localPeerDescriptor: peerDescriptor,
|
|
71
71
|
streamPartId: STREAM_PART_ID,
|
|
72
72
|
layer1Node,
|
|
73
|
-
|
|
73
|
+
fetchEntryPointData: fakeFetchEntryPointData,
|
|
74
74
|
storeEntryPointData: fakeStoreEntryPointData,
|
|
75
75
|
deleteEntryPointData: fakeDeleteEntryPointData,
|
|
76
76
|
storeInterval: 2000
|
|
@@ -79,7 +79,7 @@ describe('EntryPointDiscovery', () => {
|
|
|
79
79
|
localPeerDescriptor: peerDescriptor,
|
|
80
80
|
streamPartId: STREAM_PART_ID,
|
|
81
81
|
layer1Node,
|
|
82
|
-
|
|
82
|
+
fetchEntryPointData: fakeEmptyFetchEntryPointData,
|
|
83
83
|
storeEntryPointData: fakeStoreEntryPointData,
|
|
84
84
|
deleteEntryPointData: fakeDeleteEntryPointData,
|
|
85
85
|
storeInterval: 2000
|
|
@@ -2,7 +2,7 @@ import { DhtAddress, NodeType, getNodeIdFromPeerDescriptor, getRawFromDhtAddress
|
|
|
2
2
|
import { NodeList } from '../../src/logic/NodeList'
|
|
3
3
|
import { HandshakeRpcLocal } from '../../src/logic/neighbor-discovery/HandshakeRpcLocal'
|
|
4
4
|
import { InterleaveRequest, StreamPartHandshakeRequest } from '../../src/proto/packages/trackerless-network/protos/NetworkRpc'
|
|
5
|
-
import { createMockPeerDescriptor, createMockHandshakeRpcRemote,
|
|
5
|
+
import { createMockPeerDescriptor, createMockHandshakeRpcRemote, createMockContentDeliveryRpcRemote } from '../utils/utils'
|
|
6
6
|
import { StreamPartIDUtils } from '@streamr/protocol'
|
|
7
7
|
|
|
8
8
|
const STREAM_PART_ID = StreamPartIDUtils.parse('stream#0')
|
|
@@ -26,11 +26,10 @@ describe('HandshakeRpcLocal', () => {
|
|
|
26
26
|
|
|
27
27
|
rpcLocal = new HandshakeRpcLocal({
|
|
28
28
|
streamPartId: STREAM_PART_ID,
|
|
29
|
-
connectionLocker: mockConnectionLocker,
|
|
30
29
|
ongoingHandshakes,
|
|
31
30
|
ongoingInterleaves,
|
|
32
31
|
createRpcRemote: (_p) => createMockHandshakeRpcRemote(),
|
|
33
|
-
|
|
32
|
+
createContentDeliveryRpcRemote: (_p) => createMockContentDeliveryRpcRemote(),
|
|
34
33
|
handshakeWithInterleaving: async (_p, _t) => {
|
|
35
34
|
handshakeWithInterleaving()
|
|
36
35
|
return true
|
|
@@ -54,10 +53,10 @@ describe('HandshakeRpcLocal', () => {
|
|
|
54
53
|
})
|
|
55
54
|
|
|
56
55
|
it('handshake interleave', async () => {
|
|
57
|
-
neighbors.add(
|
|
58
|
-
neighbors.add(
|
|
59
|
-
neighbors.add(
|
|
60
|
-
neighbors.add(
|
|
56
|
+
neighbors.add(createMockContentDeliveryRpcRemote())
|
|
57
|
+
neighbors.add(createMockContentDeliveryRpcRemote())
|
|
58
|
+
neighbors.add(createMockContentDeliveryRpcRemote())
|
|
59
|
+
neighbors.add(createMockContentDeliveryRpcRemote())
|
|
61
60
|
const req = StreamPartHandshakeRequest.create({
|
|
62
61
|
streamPartId: STREAM_PART_ID,
|
|
63
62
|
requestId: 'requestId'
|
|
@@ -111,10 +110,10 @@ describe('HandshakeRpcLocal', () => {
|
|
|
111
110
|
})
|
|
112
111
|
|
|
113
112
|
it('rejects handshakes if interleaving to the requestor is ongoing', async () => {
|
|
114
|
-
neighbors.add(
|
|
115
|
-
neighbors.add(
|
|
116
|
-
neighbors.add(
|
|
117
|
-
neighbors.add(
|
|
113
|
+
neighbors.add(createMockContentDeliveryRpcRemote())
|
|
114
|
+
neighbors.add(createMockContentDeliveryRpcRemote())
|
|
115
|
+
neighbors.add(createMockContentDeliveryRpcRemote())
|
|
116
|
+
neighbors.add(createMockContentDeliveryRpcRemote())
|
|
118
117
|
const requestor = createMockPeerDescriptor()
|
|
119
118
|
ongoingInterleaves.add(getNodeIdFromPeerDescriptor(requestor))
|
|
120
119
|
const req = StreamPartHandshakeRequest.create({
|
|
@@ -131,10 +130,10 @@ describe('HandshakeRpcLocal', () => {
|
|
|
131
130
|
const interleavingPeer1 = createMockPeerDescriptor()
|
|
132
131
|
const interleavingPeer2 = createMockPeerDescriptor()
|
|
133
132
|
const interleavingPeer3 = createMockPeerDescriptor()
|
|
134
|
-
neighbors.add(
|
|
135
|
-
neighbors.add(
|
|
136
|
-
neighbors.add(
|
|
137
|
-
neighbors.add(
|
|
133
|
+
neighbors.add(createMockContentDeliveryRpcRemote(interleavingPeer1))
|
|
134
|
+
neighbors.add(createMockContentDeliveryRpcRemote(interleavingPeer2))
|
|
135
|
+
neighbors.add(createMockContentDeliveryRpcRemote(interleavingPeer3))
|
|
136
|
+
neighbors.add(createMockContentDeliveryRpcRemote())
|
|
138
137
|
ongoingInterleaves.add(getNodeIdFromPeerDescriptor(interleavingPeer1))
|
|
139
138
|
ongoingInterleaves.add(getNodeIdFromPeerDescriptor(interleavingPeer2))
|
|
140
139
|
ongoingInterleaves.add(getNodeIdFromPeerDescriptor(interleavingPeer3))
|
|
@@ -149,4 +148,21 @@ describe('HandshakeRpcLocal', () => {
|
|
|
149
148
|
expect(handshakeWithInterleaving).toHaveBeenCalledTimes(0)
|
|
150
149
|
})
|
|
151
150
|
|
|
151
|
+
it('rejects handshakes if the requestor has more than maxNeighborCount neighbors', async () => {
|
|
152
|
+
neighbors.add(createMockContentDeliveryRpcRemote())
|
|
153
|
+
neighbors.add(createMockContentDeliveryRpcRemote())
|
|
154
|
+
neighbors.add(createMockContentDeliveryRpcRemote())
|
|
155
|
+
neighbors.add(createMockContentDeliveryRpcRemote())
|
|
156
|
+
neighbors.add(createMockContentDeliveryRpcRemote())
|
|
157
|
+
const req = StreamPartHandshakeRequest.create({
|
|
158
|
+
streamPartId: STREAM_PART_ID,
|
|
159
|
+
requestId: 'requestId'
|
|
160
|
+
})
|
|
161
|
+
const res = await rpcLocal.handshake(req, {
|
|
162
|
+
incomingSourceDescriptor: createMockPeerDescriptor()
|
|
163
|
+
} as any)
|
|
164
|
+
expect(res.accepted).toEqual(false)
|
|
165
|
+
expect(handshakeWithInterleaving).toHaveBeenCalledTimes(0)
|
|
166
|
+
})
|
|
167
|
+
|
|
152
168
|
})
|