@streamr/trackerless-network 100.0.0-testnet-three.5 → 100.0.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 +9 -9
- package/dist/src/NetworkNode.d.ts +3 -3
- package/dist/src/NetworkNode.js.map +1 -1
- package/dist/src/NetworkStack.d.ts +6 -4
- package/dist/src/NetworkStack.js +23 -6
- package/dist/src/NetworkStack.js.map +1 -1
- package/dist/src/exports.d.ts +3 -3
- package/dist/src/exports.js +7 -2
- package/dist/src/exports.js.map +1 -1
- package/dist/src/logic/EntryPointDiscovery.d.ts +1 -1
- package/dist/src/logic/EntryPointDiscovery.js +2 -2
- 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 +2 -1
- package/dist/src/logic/NodeList.js +7 -2
- package/dist/src/logic/NodeList.js.map +1 -1
- package/dist/src/logic/RandomGraphNode.d.ts +3 -0
- package/dist/src/logic/RandomGraphNode.js +26 -4
- package/dist/src/logic/RandomGraphNode.js.map +1 -1
- package/dist/src/logic/StreamrNode.js +9 -4
- package/dist/src/logic/StreamrNode.js.map +1 -1
- package/dist/src/logic/createRandomGraphNode.d.ts +1 -1
- package/dist/src/logic/createRandomGraphNode.js +15 -6
- package/dist/src/logic/createRandomGraphNode.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 +1 -2
- package/dist/src/logic/neighbor-discovery/HandshakeRpcLocal.js +3 -8
- package/dist/src/logic/neighbor-discovery/HandshakeRpcLocal.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/Handshaker.d.ts +3 -2
- package/dist/src/logic/neighbor-discovery/Handshaker.js +29 -10
- 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 +0 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.js.map +1 -1
- package/dist/src/logic/node-info/NodeInfoClient.d.ts +2 -2
- package/dist/src/logic/node-info/NodeInfoClient.js +3 -1
- package/dist/src/logic/node-info/NodeInfoClient.js.map +1 -1
- package/dist/src/logic/node-info/NodeInfoRpcLocal.js +1 -10
- package/dist/src/logic/node-info/NodeInfoRpcLocal.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 +58 -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/ProxyConnectionRpcLocal.js +2 -2
- package/dist/src/logic/proxy/ProxyConnectionRpcLocal.js.map +1 -1
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcLocal.d.ts +5 -1
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcLocal.js +5 -0
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcLocal.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +6 -6
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +2 -2
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +54 -87
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +17 -49
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +4 -4
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.d.ts +53 -21
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.js +24 -11
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.js.map +1 -1
- package/dist/test/benchmark/first-message.js +1 -1
- package/dist/test/benchmark/first-message.js.map +1 -1
- package/dist/test/utils/utils.js +9 -5
- package/dist/test/utils/utils.js.map +1 -1
- package/package.json +9 -9
- package/protos/NetworkRpc.proto +16 -9
- package/src/NetworkNode.ts +3 -3
- package/src/NetworkStack.ts +35 -9
- package/src/exports.ts +7 -3
- package/src/logic/EntryPointDiscovery.ts +3 -3
- package/src/logic/Layer0Node.ts +1 -1
- package/src/logic/Layer1Node.ts +16 -1
- package/src/logic/NodeList.ts +9 -3
- package/src/logic/RandomGraphNode.ts +74 -10
- package/src/logic/StreamrNode.ts +9 -4
- package/src/logic/createRandomGraphNode.ts +16 -7
- package/src/logic/inspect/Inspector.ts +2 -2
- package/src/logic/neighbor-discovery/HandshakeRpcLocal.ts +5 -10
- package/src/logic/neighbor-discovery/Handshaker.ts +32 -12
- 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 +1 -3
- package/src/logic/node-info/NodeInfoClient.ts +6 -4
- package/src/logic/node-info/NodeInfoRpcLocal.ts +1 -10
- package/src/logic/protocol-integration/stream-message/GroupKeyResponseTranslator.ts +0 -1
- package/src/logic/protocol-integration/stream-message/StreamMessageTranslator.ts +59 -62
- package/src/logic/protocol-integration/stream-message/oldStreamMessageBinaryUtils.ts +28 -2
- package/src/logic/proxy/ProxyConnectionRpcLocal.ts +3 -5
- package/src/logic/temporary-connection/TemporaryConnectionRpcLocal.ts +10 -2
- package/src/proto/packages/dht/protos/DhtRpc.client.ts +7 -7
- package/src/proto/packages/dht/protos/DhtRpc.server.ts +4 -4
- package/src/proto/packages/dht/protos/DhtRpc.ts +64 -100
- package/src/proto/packages/trackerless-network/protos/NetworkRpc.ts +69 -31
- package/test/benchmark/StreamPartIdDataKeyDistribution.test.ts +60 -0
- package/test/benchmark/first-message.ts +1 -1
- package/test/end-to-end/proxy-key-exchange.test.ts +13 -10
- package/test/integration/Handshakes.test.ts +7 -3
- package/test/integration/NetworkNode.test.ts +8 -4
- package/test/integration/stream-without-default-entrypoints.test.ts +1 -1
- package/test/integration/streamEntryPointReplacing.test.ts +5 -5
- package/test/unit/EntrypointDiscovery.test.ts +4 -4
- package/test/unit/HandshakeRpcLocal.test.ts +18 -2
- package/test/unit/Handshaker.test.ts +8 -3
- package/test/unit/NeighborFinder.test.ts +3 -0
- package/test/unit/NeighborUpdateRpcLocal.test.ts +0 -4
- package/test/unit/Propagation.test.ts +10 -7
- 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 +10 -7
- package/test/unit/GroupKeyRequestTranslator.test.ts +0 -36
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
|
|
3
|
+
import { groupBy, range } from 'lodash'
|
|
4
|
+
import { streamPartIdToDataKey } from '../../src/logic/EntryPointDiscovery'
|
|
5
|
+
import { StreamPartIDUtils } from '@streamr/protocol'
|
|
6
|
+
import { DhtAddress } from '@streamr/dht'
|
|
7
|
+
|
|
8
|
+
describe('StreamPartIdDataKeyDistribution', () => {
|
|
9
|
+
|
|
10
|
+
it('partitions are well distributed', () => {
|
|
11
|
+
|
|
12
|
+
const streamId = 'stream'
|
|
13
|
+
const dataKeys = range(100).map((i) => {
|
|
14
|
+
const streamPartId = StreamPartIDUtils.parse(streamId + '#' + i)
|
|
15
|
+
return streamPartIdToDataKey(streamPartId)
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
const byInitials = groupBy(dataKeys, (dataKey: DhtAddress) => dataKey[0])
|
|
19
|
+
expect(Object.keys(byInitials).length).toEqual(16)
|
|
20
|
+
console.log(Object.values(byInitials).map((a) => a.length))
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
it('streamIds are well distributed', () => {
|
|
24
|
+
const dataKeys = range(10000).map(() => {
|
|
25
|
+
const streamPartId = StreamPartIDUtils.parse(Math.random().toString(32).substr(2, 32) + '#0')
|
|
26
|
+
return streamPartIdToDataKey(streamPartId)
|
|
27
|
+
})
|
|
28
|
+
const byInitials = groupBy(dataKeys, (dataKey: DhtAddress) => dataKey[0])
|
|
29
|
+
expect(Object.keys(byInitials).length).toEqual(16)
|
|
30
|
+
console.log(Object.values(byInitials).map((a) => a.length))
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it('streamPartIds are well distributed', () => {
|
|
34
|
+
const streamIds = range(10000).map(() => Math.random().toString(32).substr(2, 32))
|
|
35
|
+
const dataKeys: DhtAddress[] = []
|
|
36
|
+
streamIds.forEach((streamId) => {
|
|
37
|
+
range(100).forEach((i) => {
|
|
38
|
+
const streamPartId = StreamPartIDUtils.parse(streamId + '#' + i)
|
|
39
|
+
dataKeys.push(streamPartIdToDataKey(streamPartId))
|
|
40
|
+
})
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
const byInitials = groupBy(dataKeys, (dataKey: DhtAddress) => dataKey[0])
|
|
44
|
+
expect(Object.keys(byInitials).length).toEqual(16)
|
|
45
|
+
console.log(Object.values(byInitials).map((a) => a.length))
|
|
46
|
+
|
|
47
|
+
const byTwoInitials = groupBy(dataKeys, (dataKey: DhtAddress) => dataKey[0] + dataKey[1])
|
|
48
|
+
expect(Object.keys(byTwoInitials).length).toEqual(16 * 16)
|
|
49
|
+
console.log(Object.values(byTwoInitials).map((a) => a.length))
|
|
50
|
+
|
|
51
|
+
const byThreeInitials = groupBy(dataKeys, (dataKey: DhtAddress) => dataKey[0] + dataKey[1] + dataKey[2])
|
|
52
|
+
expect(Object.keys(byThreeInitials).length).toEqual(16 * 16 * 16)
|
|
53
|
+
console.log(Object.values(byThreeInitials).map((a) => a.length))
|
|
54
|
+
|
|
55
|
+
const byFourInitials = groupBy(dataKeys, (dataKey: DhtAddress) => dataKey[0] + dataKey[1] + dataKey[2] + dataKey[3])
|
|
56
|
+
expect(Object.keys(byFourInitials).length).toEqual(16 * 16 * 16 * 16)
|
|
57
|
+
console.log(Object.values(byFourInitials).map((a) => a.length))
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
})
|
|
@@ -155,7 +155,7 @@ run().then(() => {
|
|
|
155
155
|
console.error(err)
|
|
156
156
|
const streamrNode = currentNode.stack.getStreamrNode()
|
|
157
157
|
const streamParts = streamrNode.getStreamParts()
|
|
158
|
-
const foundData = nodes[0].stack.getLayer0Node().
|
|
158
|
+
const foundData = nodes[0].stack.getLayer0Node().fetchDataFromDht(streamPartIdToDataKey(streamParts[0]))
|
|
159
159
|
console.log(foundData)
|
|
160
160
|
const layer0Node = currentNode.stack.getLayer0Node() as DhtNode
|
|
161
161
|
console.log(layer0Node.getNeighbors().length)
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ContentType,
|
|
3
3
|
EncryptionType,
|
|
4
|
-
GroupKeyRequest,
|
|
5
|
-
GroupKeyResponse,
|
|
6
4
|
MessageID,
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
GroupKeyRequest as OldGroupKeyRequest,
|
|
6
|
+
GroupKeyResponse as OldGroupKeyResponse,
|
|
7
|
+
SignatureType,
|
|
9
8
|
StreamMessage,
|
|
10
9
|
StreamMessageType,
|
|
11
10
|
StreamPartIDUtils
|
|
12
11
|
} from '@streamr/protocol'
|
|
13
12
|
import { hexToBinary, toEthereumAddress, waitForEvent3 } from '@streamr/utils'
|
|
14
13
|
import { NetworkNode, createNetworkNode } from '../../src/NetworkNode'
|
|
14
|
+
import {
|
|
15
|
+
convertGroupKeyRequestToBytes,
|
|
16
|
+
convertGroupKeyResponseToBytes
|
|
17
|
+
} from '../../src/logic/protocol-integration/stream-message/oldStreamMessageBinaryUtils'
|
|
15
18
|
import { ProxyDirection } from '../../src/proto/packages/trackerless-network/protos/NetworkRpc'
|
|
16
19
|
import { createMockPeerDescriptor } from '../utils/utils'
|
|
17
20
|
|
|
@@ -72,7 +75,7 @@ describe('proxy group key exchange', () => {
|
|
|
72
75
|
await publisher.setProxies(STREAM_PART_ID, [proxyNodeDescriptor], ProxyDirection.PUBLISH, publisherUserId)
|
|
73
76
|
await subscriber.setProxies(STREAM_PART_ID, [proxyNodeDescriptor], ProxyDirection.SUBSCRIBE, subscriberUserId)
|
|
74
77
|
|
|
75
|
-
const groupKeyRequest = new
|
|
78
|
+
const groupKeyRequest = new OldGroupKeyRequest({
|
|
76
79
|
recipient: publisherUserId,
|
|
77
80
|
requestId: 'requestId',
|
|
78
81
|
rsaPublicKey: 'mockKey',
|
|
@@ -90,9 +93,9 @@ describe('proxy group key exchange', () => {
|
|
|
90
93
|
'0'
|
|
91
94
|
),
|
|
92
95
|
messageType: StreamMessageType.GROUP_KEY_REQUEST,
|
|
93
|
-
contentType: ContentType.
|
|
96
|
+
contentType: ContentType.BINARY,
|
|
94
97
|
encryptionType: EncryptionType.NONE,
|
|
95
|
-
content:
|
|
98
|
+
content: convertGroupKeyRequestToBytes(groupKeyRequest),
|
|
96
99
|
signatureType: SignatureType.SECP256K1,
|
|
97
100
|
signature: hexToBinary('1234')
|
|
98
101
|
})
|
|
@@ -107,7 +110,7 @@ describe('proxy group key exchange', () => {
|
|
|
107
110
|
await publisher.setProxies(STREAM_PART_ID, [proxyNodeDescriptor], ProxyDirection.PUBLISH, publisherUserId)
|
|
108
111
|
await subscriber.setProxies(STREAM_PART_ID, [proxyNodeDescriptor], ProxyDirection.SUBSCRIBE, subscriberUserId)
|
|
109
112
|
|
|
110
|
-
const groupKeyResponse = new
|
|
113
|
+
const groupKeyResponse = new OldGroupKeyResponse({
|
|
111
114
|
recipient: publisherUserId,
|
|
112
115
|
requestId: 'requestId',
|
|
113
116
|
encryptedGroupKeys: []
|
|
@@ -122,9 +125,9 @@ describe('proxy group key exchange', () => {
|
|
|
122
125
|
'0'
|
|
123
126
|
),
|
|
124
127
|
messageType: StreamMessageType.GROUP_KEY_RESPONSE,
|
|
125
|
-
contentType: ContentType.
|
|
128
|
+
contentType: ContentType.BINARY,
|
|
126
129
|
encryptionType: EncryptionType.NONE,
|
|
127
|
-
content:
|
|
130
|
+
content: convertGroupKeyResponseToBytes(groupKeyResponse),
|
|
128
131
|
signatureType: SignatureType.SECP256K1,
|
|
129
132
|
signature: hexToBinary('1234')
|
|
130
133
|
})
|
|
@@ -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()
|
|
@@ -98,12 +98,16 @@ describe('NetworkNode', () => {
|
|
|
98
98
|
await node2.join(STREAM_PART_ID)
|
|
99
99
|
const result1 = await node1.fetchNodeInfo(pd2)
|
|
100
100
|
const result2 = await node2.fetchNodeInfo(pd1)
|
|
101
|
+
const result3 = await node1.fetchNodeInfo(node1.getPeerDescriptor())
|
|
101
102
|
expect(result1.streamPartitions.length).toEqual(1)
|
|
102
103
|
expect(result2.streamPartitions.length).toEqual(1)
|
|
103
|
-
expect(
|
|
104
|
-
expect(
|
|
105
|
-
expect(
|
|
106
|
-
expect(
|
|
104
|
+
expect(result3.streamPartitions.length).toEqual(1)
|
|
105
|
+
expect(result1.controlLayer.connections.length).toEqual(1)
|
|
106
|
+
expect(result2.controlLayer.connections.length).toEqual(1)
|
|
107
|
+
expect(result3.controlLayer.connections.length).toEqual(1)
|
|
108
|
+
expect(result1.controlLayer.neighbors.length).toEqual(1)
|
|
109
|
+
expect(result2.controlLayer.neighbors.length).toEqual(1)
|
|
110
|
+
expect(result3.controlLayer.neighbors.length).toEqual(1)
|
|
107
111
|
})
|
|
108
112
|
|
|
109
113
|
})
|
|
@@ -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,20 +68,20 @@ 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:
|
|
77
|
+
await node.joinStreamPart(STREAM_PART_ID, { minCount: 4, timeout: 60000 })
|
|
78
78
|
node.getStreamrNode().on('newMessage', () => {
|
|
79
79
|
receivedMessages += 1
|
|
80
80
|
})
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
await Promise.all(initialNodesOnStream.map((node) => node.getStreamrNode().leaveStreamPart(STREAM_PART_ID)))
|
|
84
|
-
await waitForCondition(() => laterNodesOnStream.every((node) => node.getStreamrNode().getNeighbors(STREAM_PART_ID).length >= 4),
|
|
84
|
+
await waitForCondition(() => laterNodesOnStream.every((node) => node.getStreamrNode().getNeighbors(STREAM_PART_ID).length >= 4), 60000, 1000)
|
|
85
85
|
|
|
86
86
|
const msg = createStreamMessage(
|
|
87
87
|
JSON.stringify({ hello: 'WORLD' }),
|
|
@@ -89,6 +89,6 @@ describe('Stream Entry Points are replaced when known entry points leave streams
|
|
|
89
89
|
randomEthereumAddress()
|
|
90
90
|
)
|
|
91
91
|
newNodeInStream.getStreamrNode().broadcast(msg)
|
|
92
|
-
await waitForCondition(() => receivedMessages === NUM_OF_LATER_NODES,
|
|
92
|
+
await waitForCondition(() => receivedMessages === NUM_OF_LATER_NODES, 30000)
|
|
93
93
|
}, 200000)
|
|
94
94
|
})
|
|
@@ -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, createMockDeliveryRpcRemote
|
|
5
|
+
import { createMockPeerDescriptor, createMockHandshakeRpcRemote, createMockDeliveryRpcRemote } from '../utils/utils'
|
|
6
6
|
import { StreamPartIDUtils } from '@streamr/protocol'
|
|
7
7
|
|
|
8
8
|
const STREAM_PART_ID = StreamPartIDUtils.parse('stream#0')
|
|
@@ -26,7 +26,6 @@ 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(),
|
|
@@ -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(createMockDeliveryRpcRemote())
|
|
153
|
+
neighbors.add(createMockDeliveryRpcRemote())
|
|
154
|
+
neighbors.add(createMockDeliveryRpcRemote())
|
|
155
|
+
neighbors.add(createMockDeliveryRpcRemote())
|
|
156
|
+
neighbors.add(createMockDeliveryRpcRemote())
|
|
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
|
})
|
|
@@ -2,7 +2,7 @@ import { ListeningRpcCommunicator, Simulator, SimulatorTransport, getNodeIdFromP
|
|
|
2
2
|
import { range } from 'lodash'
|
|
3
3
|
import { NodeList } from '../../src/logic/NodeList'
|
|
4
4
|
import { Handshaker } from '../../src/logic/neighbor-discovery/Handshaker'
|
|
5
|
-
import { createMockPeerDescriptor, createMockDeliveryRpcRemote
|
|
5
|
+
import { createMockPeerDescriptor, createMockDeliveryRpcRemote } from '../utils/utils'
|
|
6
6
|
import { StreamPartIDUtils } from '@streamr/protocol'
|
|
7
7
|
|
|
8
8
|
describe('Handshaker', () => {
|
|
@@ -14,6 +14,8 @@ describe('Handshaker', () => {
|
|
|
14
14
|
const streamPartId = StreamPartIDUtils.parse('stream#0')
|
|
15
15
|
|
|
16
16
|
let neighbors: NodeList
|
|
17
|
+
let leftNodeView: NodeList
|
|
18
|
+
let rightNodeView: NodeList
|
|
17
19
|
let nearbyNodeView: NodeList
|
|
18
20
|
let randomNodeView: NodeList
|
|
19
21
|
|
|
@@ -28,14 +30,17 @@ describe('Handshaker', () => {
|
|
|
28
30
|
|
|
29
31
|
const nodeId = getNodeIdFromPeerDescriptor(peerDescriptor)
|
|
30
32
|
neighbors = new NodeList(nodeId, 10)
|
|
33
|
+
leftNodeView = new NodeList(nodeId, 20)
|
|
34
|
+
rightNodeView = new NodeList(nodeId, 20)
|
|
31
35
|
nearbyNodeView = new NodeList(nodeId, 20)
|
|
32
36
|
randomNodeView = new NodeList(nodeId, 20)
|
|
33
37
|
|
|
34
38
|
handshaker = new Handshaker({
|
|
35
39
|
localPeerDescriptor: peerDescriptor,
|
|
36
40
|
streamPartId,
|
|
37
|
-
connectionLocker: mockConnectionLocker,
|
|
38
41
|
neighbors,
|
|
42
|
+
leftNodeView,
|
|
43
|
+
rightNodeView,
|
|
39
44
|
nearbyNodeView,
|
|
40
45
|
randomNodeView,
|
|
41
46
|
rpcCommunicator,
|
|
@@ -56,7 +61,7 @@ describe('Handshaker', () => {
|
|
|
56
61
|
})
|
|
57
62
|
|
|
58
63
|
it('attemptHandshakesOnContact with known nodes that cannot be connected to', async () => {
|
|
59
|
-
range(2).forEach(() =>
|
|
64
|
+
range(2).forEach(() => randomNodeView.add(createMockDeliveryRpcRemote()))
|
|
60
65
|
const res = await handshaker.attemptHandshakesOnContacts([])
|
|
61
66
|
expect(res.length).toEqual(2)
|
|
62
67
|
})
|
|
@@ -31,6 +31,9 @@ describe('NeighborFinder', () => {
|
|
|
31
31
|
neighborFinder = new NeighborFinder({
|
|
32
32
|
neighbors,
|
|
33
33
|
nearbyNodeView,
|
|
34
|
+
leftNodeView: new NodeList(nodeId, 30),
|
|
35
|
+
rightNodeView: new NodeList(nodeId, 30),
|
|
36
|
+
randomNodeView: new NodeList(nodeId, 30),
|
|
34
37
|
doFindNeighbors: (excluded) => mockDoFindNeighbors(excluded),
|
|
35
38
|
minCount
|
|
36
39
|
})
|
|
@@ -40,9 +40,6 @@ describe('NeighborUpdateRpcLocal', () => {
|
|
|
40
40
|
neighborFinder = {
|
|
41
41
|
start: jest.fn()
|
|
42
42
|
} as any
|
|
43
|
-
const connectionLocker = {
|
|
44
|
-
unlockConnection: jest.fn()
|
|
45
|
-
} as any
|
|
46
43
|
ongoingHandshakes = new Set()
|
|
47
44
|
|
|
48
45
|
rpcLocal = new NeighborUpdateRpcLocal({
|
|
@@ -53,7 +50,6 @@ describe('NeighborUpdateRpcLocal', () => {
|
|
|
53
50
|
streamPartId,
|
|
54
51
|
rpcCommunicator,
|
|
55
52
|
neighborTargetCount,
|
|
56
|
-
connectionLocker,
|
|
57
53
|
ongoingHandshakes
|
|
58
54
|
})
|
|
59
55
|
})
|
|
@@ -3,8 +3,7 @@ import {
|
|
|
3
3
|
EncryptionType,
|
|
4
4
|
MessageID,
|
|
5
5
|
SignatureType,
|
|
6
|
-
StreamMessage
|
|
7
|
-
StreamMessageType,
|
|
6
|
+
StreamMessage
|
|
8
7
|
} from '../../src/proto/packages/trackerless-network/protos/NetworkRpc'
|
|
9
8
|
import { Propagation } from '../../src/logic/propagation/Propagation'
|
|
10
9
|
import { hexToBinary, toEthereumAddress, utf8ToBinary, wait } from '@streamr/utils'
|
|
@@ -23,12 +22,16 @@ function makeMsg(streamId: string, partition: number, ts: number, msgNo: number)
|
|
|
23
22
|
}
|
|
24
23
|
return {
|
|
25
24
|
messageId,
|
|
26
|
-
content: new Uint8Array([1]),
|
|
27
|
-
contentType: ContentType.JSON,
|
|
28
|
-
encryptionType: EncryptionType.NONE,
|
|
29
25
|
signature: hexToBinary('0x1111'),
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
signatureType: SignatureType.SECP256K1,
|
|
27
|
+
body: {
|
|
28
|
+
oneofKind: 'contentMessage',
|
|
29
|
+
contentMessage: {
|
|
30
|
+
content: new Uint8Array([1]),
|
|
31
|
+
contentType: ContentType.JSON,
|
|
32
|
+
encryptionType: EncryptionType.NONE
|
|
33
|
+
}
|
|
34
|
+
}
|
|
32
35
|
}
|
|
33
36
|
}
|
|
34
37
|
|
|
@@ -9,7 +9,6 @@ import {
|
|
|
9
9
|
} from '@streamr/protocol'
|
|
10
10
|
import { binaryToHex, binaryToUtf8, hexToBinary, toEthereumAddress, utf8ToBinary } from '@streamr/utils'
|
|
11
11
|
import { StreamMessageTranslator } from '../../src/logic/protocol-integration/stream-message/StreamMessageTranslator'
|
|
12
|
-
import { StreamMessageType } from '../../src/proto/packages/trackerless-network/protos/NetworkRpc'
|
|
13
12
|
import { createStreamMessage } from '../utils/utils'
|
|
14
13
|
|
|
15
14
|
const STREAM_PART_ID = StreamPartIDUtils.parse('TEST#0')
|
|
@@ -49,10 +48,10 @@ describe('StreamMessageTranslator', () => {
|
|
|
49
48
|
expect(translated.messageId!.sequenceNumber).toEqual(0)
|
|
50
49
|
expect(binaryToHex(translated.messageId!.publisherId, true)).toEqual('0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
|
|
51
50
|
expect(translated.previousMessageRef).toEqual(undefined)
|
|
52
|
-
expect(translated.
|
|
53
|
-
expect(translated.groupKeyId).toEqual(undefined)
|
|
51
|
+
expect(translated.body.oneofKind).toEqual('contentMessage')
|
|
52
|
+
expect((translated.body as any).contentMessage.groupKeyId).toEqual(undefined)
|
|
54
53
|
expect(translated.signature).toStrictEqual(signature)
|
|
55
|
-
expect(JSON.parse(binaryToUtf8(translated.content))).toEqual({ hello: 'WORLD' })
|
|
54
|
+
expect(JSON.parse(binaryToUtf8((translated.body as any).contentMessage.content))).toEqual({ hello: 'WORLD' })
|
|
56
55
|
})
|
|
57
56
|
|
|
58
57
|
it('translates protobuf to old protocol', () => {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { StreamPartIDUtils } from '@streamr/protocol'
|
|
2
|
+
import { streamPartIdToDataKey } from '../../src/logic/EntryPointDiscovery'
|
|
3
|
+
|
|
4
|
+
describe('StreamPartIDtoDataKey', () => {
|
|
5
|
+
|
|
6
|
+
it('generated key length is correct (160 bits)', () => {
|
|
7
|
+
const streamPartId = StreamPartIDUtils.parse('stream#0')
|
|
8
|
+
const dataKey = streamPartIdToDataKey(streamPartId)
|
|
9
|
+
expect(dataKey.length).toEqual(40)
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
})
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { StreamPartIDUtils } from '@streamr/protocol'
|
|
1
2
|
import { TemporaryConnectionRpcLocal } from '../../src/logic/temporary-connection/TemporaryConnectionRpcLocal'
|
|
2
3
|
import { MockTransport } from '../utils/mock/Transport'
|
|
3
4
|
import { createMockPeerDescriptor } from '../utils/utils'
|
|
@@ -13,7 +14,12 @@ describe('TemporaryConnectionRpcLocal', () => {
|
|
|
13
14
|
rpcCommunicator = new ListeningRpcCommunicator('mock', new MockTransport())
|
|
14
15
|
rpcLocal = new TemporaryConnectionRpcLocal({
|
|
15
16
|
localPeerDescriptor: peerDescriptor,
|
|
16
|
-
rpcCommunicator
|
|
17
|
+
rpcCommunicator,
|
|
18
|
+
streamPartId: StreamPartIDUtils.parse('mock#0'),
|
|
19
|
+
connectionLocker: {
|
|
20
|
+
weakLockConnection: jest.fn(),
|
|
21
|
+
weakUnlockConnection: jest.fn()
|
|
22
|
+
} as any
|
|
17
23
|
})
|
|
18
24
|
})
|
|
19
25
|
|
|
@@ -31,6 +31,9 @@ export class MockLayer1Node extends EventEmitter implements Layer1Node {
|
|
|
31
31
|
// eslint-disable-next-line class-methods-use-this
|
|
32
32
|
async joinDht(): Promise<void> {}
|
|
33
33
|
|
|
34
|
+
// eslint-disable-next-line class-methods-use-this
|
|
35
|
+
async joinRing(): Promise<void> {}
|
|
36
|
+
|
|
34
37
|
// eslint-disable-next-line class-methods-use-this
|
|
35
38
|
async start(): Promise<void> {}
|
|
36
39
|
|
package/test/utils/utils.ts
CHANGED
|
@@ -15,8 +15,7 @@ import {
|
|
|
15
15
|
EncryptionType,
|
|
16
16
|
MessageID,
|
|
17
17
|
SignatureType,
|
|
18
|
-
StreamMessage
|
|
19
|
-
StreamMessageType
|
|
18
|
+
StreamMessage
|
|
20
19
|
} from '../../src/proto/packages/trackerless-network/protos/NetworkRpc'
|
|
21
20
|
import { DeliveryRpcRemote } from '../../src/logic/DeliveryRpcRemote'
|
|
22
21
|
import { createRandomGraphNode } from '../../src/logic/createRandomGraphNode'
|
|
@@ -78,13 +77,17 @@ export const createStreamMessage = (
|
|
|
78
77
|
messageChainId: 'messageChain0',
|
|
79
78
|
}
|
|
80
79
|
const msg: StreamMessage = {
|
|
81
|
-
messageType: StreamMessageType.MESSAGE,
|
|
82
|
-
encryptionType: EncryptionType.NONE,
|
|
83
|
-
content: utf8ToBinary(content),
|
|
84
|
-
contentType: ContentType.JSON,
|
|
85
80
|
messageId,
|
|
86
|
-
signature: hexToBinary('0x1234'),
|
|
87
81
|
signatureType: SignatureType.SECP256K1,
|
|
82
|
+
signature: hexToBinary('0x1234'),
|
|
83
|
+
body: {
|
|
84
|
+
oneofKind: 'contentMessage',
|
|
85
|
+
contentMessage: {
|
|
86
|
+
encryptionType: EncryptionType.NONE,
|
|
87
|
+
contentType: ContentType.JSON,
|
|
88
|
+
content: utf8ToBinary(content)
|
|
89
|
+
}
|
|
90
|
+
}
|
|
88
91
|
}
|
|
89
92
|
return msg
|
|
90
93
|
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { GroupKeyRequest as OldGroupKeyRequest } from '@streamr/protocol'
|
|
2
|
-
import { hexToBinary, toEthereumAddress, utf8ToBinary } from '@streamr/utils'
|
|
3
|
-
import { GroupKeyRequest } from '../../src/proto/packages/trackerless-network/protos/NetworkRpc'
|
|
4
|
-
import { GroupKeyRequestTranslator } from '../../src/logic/protocol-integration/stream-message/GroupKeyRequestTranslator'
|
|
5
|
-
|
|
6
|
-
describe('GroupKeyRequestTranslator', () => {
|
|
7
|
-
|
|
8
|
-
const oldGroupKeyRequest = new OldGroupKeyRequest({
|
|
9
|
-
rsaPublicKey: 'aaaaaaaa',
|
|
10
|
-
recipient: toEthereumAddress('0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'),
|
|
11
|
-
requestId: 'request',
|
|
12
|
-
groupKeyIds: ['id1', 'id2', 'id3']
|
|
13
|
-
})
|
|
14
|
-
const newGroupKeyRequest: GroupKeyRequest = {
|
|
15
|
-
rsaPublicKey: utf8ToBinary('aaaaaaaa'),
|
|
16
|
-
recipientId: hexToBinary('0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'),
|
|
17
|
-
requestId: 'request',
|
|
18
|
-
groupKeyIds: ['id1', 'id2', 'id3']
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
it('translates old protocol to protobuf', () => {
|
|
22
|
-
const translated = GroupKeyRequestTranslator.toProtobuf(oldGroupKeyRequest)
|
|
23
|
-
expect(translated.rsaPublicKey).toEqual(newGroupKeyRequest.rsaPublicKey)
|
|
24
|
-
expect(translated.recipientId).toEqual(newGroupKeyRequest.recipientId)
|
|
25
|
-
expect(translated.requestId).toEqual(newGroupKeyRequest.requestId)
|
|
26
|
-
expect(translated.groupKeyIds).toEqual(newGroupKeyRequest.groupKeyIds)
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
it('translates protobuf to old protocol', () => {
|
|
30
|
-
const translated = GroupKeyRequestTranslator.toClientProtocol(newGroupKeyRequest)
|
|
31
|
-
expect(translated.rsaPublicKey).toEqual(oldGroupKeyRequest.rsaPublicKey)
|
|
32
|
-
expect(translated.recipient).toEqual(oldGroupKeyRequest.recipient)
|
|
33
|
-
expect(translated.requestId).toEqual(oldGroupKeyRequest.requestId)
|
|
34
|
-
expect(translated.groupKeyIds).toEqual(oldGroupKeyRequest.groupKeyIds)
|
|
35
|
-
})
|
|
36
|
-
})
|