@streamr/dht 100.0.0-testnet-two.1 → 100.0.0-testnet-two.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/package.json +5 -5
- package/dist/src/connection/ConnectionLockHandler.d.ts +11 -11
- package/dist/src/connection/ConnectionLockHandler.js.map +1 -1
- package/dist/src/connection/ConnectionLockRpcLocal.d.ts +3 -3
- package/dist/src/connection/ConnectionManager.d.ts +5 -4
- package/dist/src/connection/ConnectionManager.js +32 -36
- package/dist/src/connection/ConnectionManager.js.map +1 -1
- package/dist/src/connection/ManagedConnection.d.ts +2 -2
- package/dist/src/connection/simulator/Simulator.js.map +1 -1
- package/dist/src/connection/simulator/SimulatorConnection.js +21 -22
- package/dist/src/connection/simulator/SimulatorConnection.js.map +1 -1
- package/dist/src/connection/simulator/SimulatorConnector.js +4 -3
- package/dist/src/connection/simulator/SimulatorConnector.js.map +1 -1
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js +11 -8
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnector.js +1 -1
- package/dist/src/connection/webrtc/WebrtcConnector.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.d.ts +2 -2
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnector.js +6 -5
- package/dist/src/connection/websocket/WebsocketConnector.js.map +1 -1
- package/dist/src/dht/DhtNode.d.ts +9 -8
- package/dist/src/dht/DhtNode.js +26 -22
- package/dist/src/dht/DhtNode.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcLocal.d.ts +2 -1
- package/dist/src/dht/DhtNodeRpcLocal.js +2 -1
- package/dist/src/dht/DhtNodeRpcLocal.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcRemote.d.ts +6 -5
- package/dist/src/dht/DhtNodeRpcRemote.js +9 -7
- package/dist/src/dht/DhtNodeRpcRemote.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcLocal.d.ts +3 -3
- package/dist/src/dht/ExternalApiRpcLocal.js +3 -2
- package/dist/src/dht/ExternalApiRpcLocal.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcRemote.d.ts +3 -2
- package/dist/src/dht/ExternalApiRpcRemote.js +3 -2
- package/dist/src/dht/ExternalApiRpcRemote.js.map +1 -1
- package/dist/src/dht/PeerManager.d.ts +9 -9
- package/dist/src/dht/PeerManager.js +35 -30
- package/dist/src/dht/PeerManager.js.map +1 -1
- package/dist/src/dht/contact/Contact.d.ts +2 -2
- package/dist/src/dht/contact/ContactList.d.ts +7 -7
- package/dist/src/dht/contact/ContactList.js.map +1 -1
- package/dist/src/dht/contact/RandomContactList.d.ts +4 -4
- package/dist/src/dht/contact/RandomContactList.js +2 -3
- package/dist/src/dht/contact/RandomContactList.js.map +1 -1
- package/dist/src/dht/contact/RpcRemote.d.ts +1 -4
- package/dist/src/dht/contact/RpcRemote.js +1 -5
- package/dist/src/dht/contact/RpcRemote.js.map +1 -1
- package/dist/src/dht/contact/SortedContactList.d.ts +13 -13
- package/dist/src/dht/contact/SortedContactList.js +5 -5
- package/dist/src/dht/contact/SortedContactList.js.map +1 -1
- package/dist/src/dht/discovery/DiscoverySession.d.ts +3 -2
- package/dist/src/dht/discovery/DiscoverySession.js +9 -9
- package/dist/src/dht/discovery/DiscoverySession.js.map +1 -1
- package/dist/src/dht/discovery/PeerDiscovery.d.ts +3 -1
- package/dist/src/dht/discovery/PeerDiscovery.js +18 -10
- package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.d.ts +3 -3
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.js +15 -14
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js +2 -2
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.d.ts +2 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.js +6 -6
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.js.map +1 -1
- package/dist/src/dht/routing/Router.d.ts +2 -2
- package/dist/src/dht/routing/Router.js +2 -2
- package/dist/src/dht/routing/Router.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcLocal.js +3 -3
- package/dist/src/dht/routing/RouterRpcLocal.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcRemote.js +4 -2
- package/dist/src/dht/routing/RouterRpcRemote.js.map +1 -1
- package/dist/src/dht/routing/RoutingSession.d.ts +3 -3
- package/dist/src/dht/routing/RoutingSession.js +4 -4
- package/dist/src/dht/routing/RoutingSession.js.map +1 -1
- package/dist/src/dht/store/LocalDataStore.d.ts +6 -9
- package/dist/src/dht/store/LocalDataStore.js +27 -32
- package/dist/src/dht/store/LocalDataStore.js.map +1 -1
- package/dist/src/dht/store/StoreManager.d.ts +3 -3
- package/dist/src/dht/store/StoreManager.js +26 -23
- package/dist/src/dht/store/StoreManager.js.map +1 -1
- package/dist/src/dht/store/StoreRpcLocal.d.ts +2 -1
- package/dist/src/dht/store/StoreRpcLocal.js +10 -8
- package/dist/src/dht/store/StoreRpcLocal.js.map +1 -1
- package/dist/src/exports.d.ts +2 -0
- package/dist/src/exports.js +6 -1
- package/dist/src/exports.js.map +1 -1
- package/dist/src/helpers/AddressTools.js +2 -0
- package/dist/src/helpers/AddressTools.js.map +1 -1
- package/dist/src/helpers/PeerID.d.ts +2 -2
- package/dist/src/helpers/PeerID.js +3 -3
- package/dist/src/helpers/PeerID.js.map +1 -1
- package/dist/src/helpers/peerIdFromPeerDescriptor.d.ts +2 -2
- package/dist/src/helpers/peerIdFromPeerDescriptor.js +2 -3
- package/dist/src/helpers/peerIdFromPeerDescriptor.js.map +1 -1
- package/dist/src/identifiers.d.ts +6 -0
- package/dist/src/identifiers.js +23 -0
- package/dist/src/identifiers.js.map +1 -0
- package/package.json +5 -5
- package/src/connection/ConnectionLockHandler.ts +15 -15
- package/src/connection/ConnectionLockRpcLocal.ts +3 -3
- package/src/connection/ConnectionManager.ts +36 -46
- package/src/connection/ManagedConnection.ts +2 -2
- package/src/connection/simulator/Simulator.ts +2 -2
- package/src/connection/simulator/SimulatorConnection.ts +21 -23
- package/src/connection/simulator/SimulatorConnector.ts +6 -5
- package/src/connection/webrtc/BrowserWebrtcConnection.ts +0 -4
- package/src/connection/webrtc/NodeWebrtcConnection.ts +11 -10
- package/src/connection/webrtc/WebrtcConnector.ts +2 -3
- package/src/connection/webrtc/WebrtcConnectorRpcLocal.ts +2 -3
- package/src/connection/websocket/WebsocketConnector.ts +9 -9
- package/src/dht/DhtNode.ts +36 -35
- package/src/dht/DhtNodeRpcLocal.ts +3 -2
- package/src/dht/DhtNodeRpcRemote.ts +14 -12
- package/src/dht/ExternalApiRpcLocal.ts +15 -6
- package/src/dht/ExternalApiRpcRemote.ts +5 -4
- package/src/dht/PeerManager.ts +43 -38
- package/src/dht/contact/Contact.ts +2 -2
- package/src/dht/contact/ContactList.ts +7 -7
- package/src/dht/contact/RandomContactList.ts +6 -6
- package/src/dht/contact/RpcRemote.ts +0 -8
- package/src/dht/contact/SortedContactList.ts +22 -22
- package/src/dht/discovery/DiscoverySession.ts +16 -14
- package/src/dht/discovery/PeerDiscovery.ts +34 -12
- package/src/dht/recursive-operation/RecursiveOperationManager.ts +17 -17
- package/src/dht/recursive-operation/RecursiveOperationRpcRemote.ts +2 -2
- package/src/dht/recursive-operation/RecursiveOperationSession.ts +11 -11
- package/src/dht/routing/Router.ts +5 -5
- package/src/dht/routing/RouterRpcLocal.ts +3 -3
- package/src/dht/routing/RouterRpcRemote.ts +4 -4
- package/src/dht/routing/RoutingSession.ts +6 -8
- package/src/dht/store/LocalDataStore.ts +31 -40
- package/src/dht/store/StoreManager.ts +31 -31
- package/src/dht/store/StoreRpcLocal.ts +11 -9
- package/src/exports.ts +2 -0
- package/src/helpers/AddressTools.ts +2 -0
- package/src/helpers/PeerID.ts +4 -4
- package/src/helpers/peerIdFromPeerDescriptor.ts +4 -6
- package/src/identifiers.ts +20 -0
- package/test/RandomGraphSimulation.ts +3 -2
- package/test/benchmark/Find.test.ts +4 -3
- package/test/benchmark/KademliaCorrectness.test.ts +4 -4
- package/test/benchmark/SortedContactListBenchmark.test.ts +15 -14
- package/test/benchmark/kademlia-simulation/Contact.ts +7 -8
- package/test/benchmark/kademlia-simulation/KademliaSimulation.ts +2 -2
- package/test/benchmark/kademlia-simulation/SimulationNode.ts +10 -11
- package/test/data/generateGroundTruthData.ts +5 -4
- package/test/end-to-end/Layer0Webrtc-Layer1.test.ts +2 -2
- package/test/end-to-end/RecoveryFromFailedAutoCertification.test.ts +1 -1
- package/test/end-to-end/memory-leak.test.ts +3 -2
- package/test/integration/ConnectionManager.test.ts +3 -3
- package/test/integration/DhtJoinPeerDiscovery.test.ts +2 -1
- package/test/integration/DhtNodeExternalAPI.test.ts +7 -7
- package/test/integration/DhtNodeRpcRemote.test.ts +3 -2
- package/test/integration/Find.test.ts +3 -3
- package/test/integration/Layer1-scale.test.ts +3 -3
- package/test/integration/Mock-Layer1-Layer0.test.ts +6 -5
- package/test/integration/ReplicateData.test.ts +38 -30
- package/test/integration/RouteMessage.test.ts +9 -10
- package/test/integration/RouterRpcRemote.test.ts +1 -1
- package/test/integration/ScaleDownDht.test.ts +4 -4
- package/test/integration/SimultaneousConnections.test.ts +7 -14
- package/test/integration/Store.test.ts +17 -7
- package/test/integration/StoreAndDelete.test.ts +11 -10
- package/test/integration/StoreOnDhtWithTwoNodes.test.ts +7 -6
- package/test/integration/StoreRpcRemote.test.ts +3 -5
- package/test/unit/AddressTools.test.ts +4 -0
- package/test/unit/LocalDataStore.test.ts +41 -41
- package/test/unit/PeerManager.test.ts +7 -8
- package/test/unit/RandomContactList.test.ts +3 -3
- package/test/unit/RecursiveOperationManager.test.ts +2 -1
- package/test/unit/RecursiveOperationSession.test.ts +2 -3
- package/test/unit/Router.test.ts +2 -2
- package/test/unit/RoutingSession.test.ts +2 -2
- package/test/unit/SortedContactList.test.ts +6 -6
- package/test/unit/StoreManager.test.ts +26 -23
- package/test/utils/customMatchers.ts +3 -2
- package/test/utils/mock/mockDataEntry.ts +8 -6
- package/test/utils/utils.ts +4 -4
- package/dist/src/helpers/nodeId.d.ts +0 -6
- package/dist/src/helpers/nodeId.js +0 -31
- package/dist/src/helpers/nodeId.js.map +0 -1
- package/src/helpers/nodeId.ts +0 -28
|
@@ -5,13 +5,14 @@ import { NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/Dh
|
|
|
5
5
|
import { createMockConnectionDhtNode, waitNodesReadyForTesting } from '../utils/utils'
|
|
6
6
|
import { execSync } from 'child_process'
|
|
7
7
|
import fs from 'fs'
|
|
8
|
-
import { Logger
|
|
8
|
+
import { Logger } from '@streamr/utils'
|
|
9
9
|
import { PeerID } from '../../src/helpers/PeerID'
|
|
10
|
-
import {
|
|
10
|
+
import { keyFromPeerDescriptor, peerIdFromPeerDescriptor } from '../../src/helpers/peerIdFromPeerDescriptor'
|
|
11
11
|
import { SortedContactList } from '../../src/dht/contact/SortedContactList'
|
|
12
12
|
import { Contact } from '../../src/dht/contact/Contact'
|
|
13
|
-
import {
|
|
13
|
+
import { DhtAddress, getDhtAddressFromRaw, getRawFromDhtAddress } from '../../src/identifiers'
|
|
14
14
|
import { createMockDataEntry } from '../utils/mock/mockDataEntry'
|
|
15
|
+
import { LocalDataStore } from '../../src/dht/store/LocalDataStore'
|
|
15
16
|
|
|
16
17
|
const logger = new Logger(module)
|
|
17
18
|
|
|
@@ -27,7 +28,7 @@ describe('Replicate data from node to node in DHT', () => {
|
|
|
27
28
|
let nodes: DhtNode[]
|
|
28
29
|
let entrypointDescriptor: PeerDescriptor
|
|
29
30
|
const simulator = new Simulator(LatencyType.FIXED, 20)
|
|
30
|
-
const nodesById: Map<
|
|
31
|
+
const nodesById: Map<DhtAddress, DhtNode> = new Map()
|
|
31
32
|
|
|
32
33
|
if (!fs.existsSync('test/data/nodeids.json')) {
|
|
33
34
|
console.log('ground truth data does not exist yet, generating..')
|
|
@@ -40,15 +41,20 @@ describe('Replicate data from node to node in DHT', () => {
|
|
|
40
41
|
return nodes[Math.floor(Math.random() * nodes.length)]
|
|
41
42
|
}
|
|
42
43
|
*/
|
|
44
|
+
|
|
45
|
+
const getEntries = (key: DhtAddress, localDataStore: LocalDataStore) => {
|
|
46
|
+
return Array.from(localDataStore.values(key))
|
|
47
|
+
}
|
|
48
|
+
|
|
43
49
|
beforeEach(async () => {
|
|
44
50
|
nodes = []
|
|
45
51
|
entryPoint = await createMockConnectionDhtNode(simulator,
|
|
46
|
-
Uint8Array.from(dhtIds[0].data), K, MAX_CONNECTIONS)
|
|
52
|
+
getDhtAddressFromRaw(Uint8Array.from(dhtIds[0].data)), K, MAX_CONNECTIONS)
|
|
47
53
|
nodes.push(entryPoint)
|
|
48
54
|
nodesById.set(entryPoint.getNodeId(), entryPoint)
|
|
49
55
|
|
|
50
56
|
entrypointDescriptor = {
|
|
51
|
-
nodeId:
|
|
57
|
+
nodeId: getRawFromDhtAddress(entryPoint.getNodeId()),
|
|
52
58
|
type: NodeType.NODEJS
|
|
53
59
|
}
|
|
54
60
|
|
|
@@ -56,7 +62,7 @@ describe('Replicate data from node to node in DHT', () => {
|
|
|
56
62
|
|
|
57
63
|
for (let i = 1; i < NUM_NODES; i++) {
|
|
58
64
|
const node = await createMockConnectionDhtNode(simulator,
|
|
59
|
-
Uint8Array.from(dhtIds[i].data), K, MAX_CONNECTIONS)
|
|
65
|
+
getDhtAddressFromRaw(Uint8Array.from(dhtIds[i].data)), K, MAX_CONNECTIONS)
|
|
60
66
|
nodesById.set(node.getNodeId(), node)
|
|
61
67
|
nodes.push(node)
|
|
62
68
|
}
|
|
@@ -74,13 +80,13 @@ describe('Replicate data from node to node in DHT', () => {
|
|
|
74
80
|
})
|
|
75
81
|
|
|
76
82
|
it('Data replicates to the closest node no matter where it is stored', async () => {
|
|
77
|
-
const dataKey = PeerID.fromString('3232323e12r31r3')
|
|
78
|
-
const data = createMockDataEntry({ key: dataKey
|
|
83
|
+
const dataKey = getDhtAddressFromRaw(PeerID.fromString('3232323e12r31r3').value)
|
|
84
|
+
const data = createMockDataEntry({ key: dataKey })
|
|
79
85
|
|
|
80
86
|
// calculate offline which node is closest to the data
|
|
81
87
|
|
|
82
88
|
const sortedList = new SortedContactList<Contact>({
|
|
83
|
-
referenceId: dataKey
|
|
89
|
+
referenceId: dataKey,
|
|
84
90
|
maxSize: 10000,
|
|
85
91
|
allowToContainReferenceId: true,
|
|
86
92
|
emitEvents: false
|
|
@@ -95,7 +101,7 @@ describe('Replicate data from node to node in DHT', () => {
|
|
|
95
101
|
|
|
96
102
|
logger.info('Nodes sorted according to distance to data are: ')
|
|
97
103
|
closest.forEach((contact) => {
|
|
98
|
-
logger.info(
|
|
104
|
+
logger.info(contact.getNodeId())
|
|
99
105
|
})
|
|
100
106
|
|
|
101
107
|
logger.info('node 0 joining to the DHT')
|
|
@@ -103,23 +109,24 @@ describe('Replicate data from node to node in DHT', () => {
|
|
|
103
109
|
await nodes[0].joinDht([entrypointDescriptor])
|
|
104
110
|
|
|
105
111
|
logger.info('storing data to node 0')
|
|
106
|
-
const successfulStorers = await nodes[0].storeDataToDht(dataKey
|
|
112
|
+
const successfulStorers = await nodes[0].storeDataToDht(dataKey, data.data!)
|
|
107
113
|
expect(successfulStorers.length).toBe(1)
|
|
108
114
|
logger.info('data successfully stored to node 0')
|
|
109
115
|
|
|
110
116
|
logger.info('Nodes sorted according to distance to data with storing nodes marked are: ')
|
|
111
117
|
|
|
112
118
|
closest.forEach((contact) => {
|
|
113
|
-
const node = nodesById.get(
|
|
119
|
+
const node = nodesById.get(contact.getNodeId())!
|
|
114
120
|
let hasDataMarker = ''
|
|
115
121
|
|
|
116
122
|
// @ts-expect-error private field
|
|
117
|
-
|
|
123
|
+
const store = node.localDataStore
|
|
124
|
+
if (getEntries(dataKey, store).length > 0) {
|
|
118
125
|
hasDataMarker = '<-'
|
|
119
126
|
}
|
|
120
127
|
|
|
121
128
|
// eslint-disable-next-line max-len
|
|
122
|
-
logger.info(peerIdFromPeerDescriptor(contact.getPeerDescriptor()) + ' ' +
|
|
129
|
+
logger.info(peerIdFromPeerDescriptor(contact.getPeerDescriptor()) + ' ' + node.getNodeId() + hasDataMarker)
|
|
123
130
|
})
|
|
124
131
|
|
|
125
132
|
logger.info(NUM_NODES + ' nodes joining layer0 DHT')
|
|
@@ -138,26 +145,28 @@ describe('Replicate data from node to node in DHT', () => {
|
|
|
138
145
|
logger.info('After join of 99 nodes: nodes sorted according to distance to data with storing nodes marked are: ')
|
|
139
146
|
|
|
140
147
|
closest.forEach((contact) => {
|
|
141
|
-
const node = nodesById.get(
|
|
148
|
+
const node = nodesById.get(contact.getNodeId())!
|
|
142
149
|
let hasDataMarker = ''
|
|
143
150
|
|
|
144
151
|
// @ts-expect-error private field
|
|
145
|
-
|
|
152
|
+
const store = node.localDataStore
|
|
153
|
+
if (getEntries(dataKey, store).length > 0) {
|
|
146
154
|
hasDataMarker = '<-'
|
|
147
155
|
}
|
|
148
156
|
|
|
149
|
-
logger.info(
|
|
157
|
+
logger.info(node.getNodeId() + hasDataMarker)
|
|
150
158
|
})
|
|
151
159
|
|
|
152
|
-
const closestNode = nodesById.get(
|
|
160
|
+
const closestNode = nodesById.get(closest[0].getNodeId())!
|
|
153
161
|
|
|
154
162
|
// @ts-expect-error private field
|
|
155
|
-
|
|
163
|
+
const store = closestNode.localDataStore
|
|
164
|
+
expect(getEntries(dataKey, store).length).toBeGreaterThanOrEqual(1)
|
|
156
165
|
}, 180000)
|
|
157
166
|
|
|
158
167
|
it('Data replicates to the last remaining node if all other nodes leave gracefully', async () => {
|
|
159
|
-
const dataKey = PeerID.fromString('3232323e12r31r3')
|
|
160
|
-
const data = createMockDataEntry({ key: dataKey
|
|
168
|
+
const dataKey = getDhtAddressFromRaw(PeerID.fromString('3232323e12r31r3').value)
|
|
169
|
+
const data = createMockDataEntry({ key: dataKey })
|
|
161
170
|
|
|
162
171
|
logger.info(NUM_NODES + ' nodes joining layer0 DHT')
|
|
163
172
|
await Promise.all(
|
|
@@ -173,7 +182,7 @@ describe('Replicate data from node to node in DHT', () => {
|
|
|
173
182
|
const randomIndex = Math.floor(Math.random() * nodes.length)
|
|
174
183
|
logger.info('storing data to a random node: ' + randomIndex)
|
|
175
184
|
|
|
176
|
-
const successfulStorers = await nodes[randomIndex].storeDataToDht(dataKey
|
|
185
|
+
const successfulStorers = await nodes[randomIndex].storeDataToDht(dataKey, data.data!)
|
|
177
186
|
|
|
178
187
|
logger.info('data successfully stored to ' + successfulStorers + ' nodes')
|
|
179
188
|
|
|
@@ -187,10 +196,10 @@ describe('Replicate data from node to node in DHT', () => {
|
|
|
187
196
|
const index = Math.floor(Math.random() * randomIndices.length)
|
|
188
197
|
const nodeIndex = randomIndices[index]
|
|
189
198
|
randomIndices.splice(index, 1)
|
|
190
|
-
|
|
199
|
+
// @ts-expect-error private field
|
|
200
|
+
const store = nodes[nodeIndex].localDataStore
|
|
191
201
|
logger.info('Stopping node ' + nodeIndex + ' ' +
|
|
192
|
-
|
|
193
|
-
(nodes[nodeIndex].localDataStore.getEntries(dataKey.value) ? ', has data' : ' does not have data'))
|
|
202
|
+
((getEntries(dataKey, store).length > 0) ? ', has data' : ' does not have data'))
|
|
194
203
|
|
|
195
204
|
await nodes[nodeIndex].stop()
|
|
196
205
|
}
|
|
@@ -198,10 +207,9 @@ describe('Replicate data from node to node in DHT', () => {
|
|
|
198
207
|
logger.info('after random graceful leaving, node ' + randomIndices[0] + ' is left')
|
|
199
208
|
|
|
200
209
|
// @ts-expect-error private field
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
expect(nodes[randomIndices[0]].localDataStore.getEntries(dataKey.value).size).toBeGreaterThanOrEqual(1)
|
|
210
|
+
const firstStore = nodes[randomIndices[0]].localDataStore
|
|
211
|
+
logger.info('data of ' + randomIndices[0] + ' was ' + getEntries(dataKey, firstStore))
|
|
212
|
+
expect(getEntries(dataKey, firstStore).length).toBeGreaterThanOrEqual(1)
|
|
205
213
|
|
|
206
214
|
}, 180000)
|
|
207
215
|
})
|
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
import { DhtNode, Events as DhtNodeEvents } from '../../src/dht/DhtNode'
|
|
2
2
|
import { Message, MessageType, NodeType, PeerDescriptor, RouteMessageWrapper } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
3
3
|
import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
|
|
4
|
-
import { Logger,
|
|
4
|
+
import { Logger, runAndWaitForEvents3, waitForCondition } from '@streamr/utils'
|
|
5
5
|
import { createMockConnectionDhtNode, createWrappedClosestPeersRequest } from '../utils/utils'
|
|
6
6
|
import { PeerID, PeerIDKey } from '../../src/helpers/PeerID'
|
|
7
7
|
import { Simulator } from '../../src/connection/simulator/Simulator'
|
|
8
8
|
import { v4 } from 'uuid'
|
|
9
9
|
import { Any } from '../../src/proto/google/protobuf/any'
|
|
10
10
|
import { RoutingMode } from '../../src/dht/routing/RoutingSession'
|
|
11
|
-
import {
|
|
12
|
-
import { createRandomNodeId } from '../../src/helpers/nodeId'
|
|
11
|
+
import { createRandomDhtAddress, getDhtAddressFromRaw, getRawFromDhtAddress } from '../../src/identifiers'
|
|
13
12
|
|
|
14
13
|
const logger = new Logger(module)
|
|
15
14
|
|
|
16
15
|
// TODO refactor the test to not to use PeerID
|
|
17
16
|
const getPeerId = (node: DhtNode) => {
|
|
18
|
-
return PeerID.fromValue(
|
|
17
|
+
return PeerID.fromValue(getRawFromDhtAddress(node.getNodeId()))
|
|
19
18
|
}
|
|
20
19
|
|
|
21
20
|
const NUM_NODES = 30
|
|
@@ -33,18 +32,18 @@ describe('Route Message With Mock Connections', () => {
|
|
|
33
32
|
beforeEach(async () => {
|
|
34
33
|
routerNodes = []
|
|
35
34
|
simulator = new Simulator()
|
|
36
|
-
entryPoint = await createMockConnectionDhtNode(simulator,
|
|
35
|
+
entryPoint = await createMockConnectionDhtNode(simulator, createRandomDhtAddress())
|
|
37
36
|
|
|
38
37
|
entryPointDescriptor = {
|
|
39
|
-
nodeId:
|
|
38
|
+
nodeId: getRawFromDhtAddress(entryPoint.getNodeId()),
|
|
40
39
|
type: NodeType.NODEJS
|
|
41
40
|
}
|
|
42
41
|
|
|
43
|
-
sourceNode = await createMockConnectionDhtNode(simulator,
|
|
44
|
-
destinationNode = await createMockConnectionDhtNode(simulator,
|
|
42
|
+
sourceNode = await createMockConnectionDhtNode(simulator, createRandomDhtAddress())
|
|
43
|
+
destinationNode = await createMockConnectionDhtNode(simulator, createRandomDhtAddress())
|
|
45
44
|
|
|
46
45
|
for (let i = 1; i < NUM_NODES; i++) {
|
|
47
|
-
const node = await createMockConnectionDhtNode(simulator, PeerID.fromString(`${i}`).value)
|
|
46
|
+
const node = await createMockConnectionDhtNode(simulator, getDhtAddressFromRaw(PeerID.fromString(`${i}`).value))
|
|
48
47
|
routerNodes.push(node)
|
|
49
48
|
}
|
|
50
49
|
|
|
@@ -157,7 +156,7 @@ describe('Route Message With Mock Connections', () => {
|
|
|
157
156
|
await Promise.all(
|
|
158
157
|
routerNodes.map(async (node) =>
|
|
159
158
|
Promise.all(routerNodes.map(async (receiver) => {
|
|
160
|
-
if (
|
|
159
|
+
if (node.getNodeId() !== receiver.getNodeId()) {
|
|
161
160
|
const rpcWrapper = createWrappedClosestPeersRequest(sourceNode.getLocalPeerDescriptor())
|
|
162
161
|
const message: Message = {
|
|
163
162
|
serviceId: 'nonexisting_service',
|
|
@@ -25,7 +25,7 @@ describe('RemoteRouter', () => {
|
|
|
25
25
|
serverRpcCommunicator.on('outgoingMessage', (message: RpcMessage) => {
|
|
26
26
|
clientRpcCommunicator.handleIncomingMessage(message)
|
|
27
27
|
})
|
|
28
|
-
remoteRouter = new RouterRpcRemote(clientPeerDescriptor, serverPeerDescriptor,
|
|
28
|
+
remoteRouter = new RouterRpcRemote(clientPeerDescriptor, serverPeerDescriptor, clientRpcCommunicator, RouterRpcClient)
|
|
29
29
|
})
|
|
30
30
|
|
|
31
31
|
it('routeMessage happy path', async () => {
|
|
@@ -3,9 +3,9 @@ import { DhtNode } from '../../src/dht/DhtNode'
|
|
|
3
3
|
import { NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
4
4
|
import { createMockConnectionDhtNode } from '../utils/utils'
|
|
5
5
|
import { areEqualPeerDescriptors, getNodeIdFromPeerDescriptor } from '../../src/helpers/peerIdFromPeerDescriptor'
|
|
6
|
-
import { Logger
|
|
6
|
+
import { Logger } from '@streamr/utils'
|
|
7
7
|
import { getRandomRegion } from '../../src/connection/simulator/pings'
|
|
8
|
-
import {
|
|
8
|
+
import { createRandomDhtAddress, getRawFromDhtAddress } from '../../src/identifiers'
|
|
9
9
|
|
|
10
10
|
const logger = new Logger(module)
|
|
11
11
|
|
|
@@ -23,11 +23,11 @@ describe('Scaling down a Dht network', () => {
|
|
|
23
23
|
beforeEach(async () => {
|
|
24
24
|
nodes = []
|
|
25
25
|
entryPoint = await createMockConnectionDhtNode(simulator,
|
|
26
|
-
|
|
26
|
+
createRandomDhtAddress(), K, MAX_CONNECTIONS)
|
|
27
27
|
nodes.push(entryPoint)
|
|
28
28
|
|
|
29
29
|
entrypointDescriptor = {
|
|
30
|
-
nodeId:
|
|
30
|
+
nodeId: getRawFromDhtAddress(entryPoint.getNodeId()),
|
|
31
31
|
type: NodeType.NODEJS,
|
|
32
32
|
region: getRandomRegion()
|
|
33
33
|
}
|
|
@@ -3,11 +3,10 @@ import { ConnectionManager } from '../../src/connection/ConnectionManager'
|
|
|
3
3
|
import { DefaultConnectorFacade, DefaultConnectorFacadeConfig } from '../../src/connection/ConnectorFacade'
|
|
4
4
|
import { LatencyType, Simulator } from '../../src/connection/simulator/Simulator'
|
|
5
5
|
import { SimulatorTransport } from '../../src/connection/simulator/SimulatorTransport'
|
|
6
|
-
import { Message, MessageType,
|
|
6
|
+
import { Message, MessageType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
7
7
|
import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
|
|
8
8
|
import { createMockPeerDescriptor } from '../utils/utils'
|
|
9
9
|
import { getRandomRegion } from '../../src/connection/simulator/pings'
|
|
10
|
-
import { createRandomNodeId } from '../../src/helpers/nodeId'
|
|
11
10
|
import { MockTransport } from '../utils/mock/Transport'
|
|
12
11
|
|
|
13
12
|
const BASE_MESSAGE: Message = {
|
|
@@ -88,27 +87,23 @@ describe('SimultaneousConnections', () => {
|
|
|
88
87
|
let connectionManager1: ConnectionManager
|
|
89
88
|
let connectionManager2: ConnectionManager
|
|
90
89
|
|
|
91
|
-
const wsPeerDescriptor1
|
|
92
|
-
nodeId: createRandomNodeId(),
|
|
93
|
-
type: NodeType.NODEJS,
|
|
90
|
+
const wsPeerDescriptor1 = createMockPeerDescriptor({
|
|
94
91
|
websocket: {
|
|
95
92
|
host: '127.0.0.1',
|
|
96
93
|
port: 43432,
|
|
97
94
|
tls: false
|
|
98
95
|
},
|
|
99
96
|
region: getRandomRegion()
|
|
100
|
-
}
|
|
97
|
+
})
|
|
101
98
|
|
|
102
|
-
const wsPeerDescriptor2
|
|
103
|
-
nodeId: createRandomNodeId(),
|
|
104
|
-
type: NodeType.NODEJS,
|
|
99
|
+
const wsPeerDescriptor2 = createMockPeerDescriptor({
|
|
105
100
|
websocket: {
|
|
106
101
|
host: '127.0.0.1',
|
|
107
102
|
port: 43433,
|
|
108
103
|
tls: false
|
|
109
104
|
},
|
|
110
105
|
region: getRandomRegion()
|
|
111
|
-
}
|
|
106
|
+
})
|
|
112
107
|
|
|
113
108
|
beforeEach(async () => {
|
|
114
109
|
|
|
@@ -176,16 +171,14 @@ describe('SimultaneousConnections', () => {
|
|
|
176
171
|
let connectionManager1: ConnectionManager
|
|
177
172
|
let connectionManager2: ConnectionManager
|
|
178
173
|
|
|
179
|
-
const wsPeerDescriptor1
|
|
180
|
-
nodeId: createRandomNodeId(),
|
|
181
|
-
type: NodeType.NODEJS,
|
|
174
|
+
const wsPeerDescriptor1 = createMockPeerDescriptor({
|
|
182
175
|
websocket: {
|
|
183
176
|
host: '127.0.0.1',
|
|
184
177
|
port: 43432,
|
|
185
178
|
tls: false
|
|
186
179
|
},
|
|
187
180
|
region: getRandomRegion()
|
|
188
|
-
}
|
|
181
|
+
})
|
|
189
182
|
|
|
190
183
|
const wsPeerDescriptor2 = createMockPeerDescriptor({ region: getRandomRegion() })
|
|
191
184
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { LatencyType, Simulator } from '../../src/connection/simulator/Simulator'
|
|
2
2
|
import { DhtNode } from '../../src/dht/DhtNode'
|
|
3
|
-
import {
|
|
3
|
+
import { getDhtAddressFromRaw } from '../../src/identifiers'
|
|
4
4
|
import { getNodeIdFromPeerDescriptor } from '../../src/helpers/peerIdFromPeerDescriptor'
|
|
5
5
|
import { PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
6
6
|
import { createMockDataEntry, expectEqualData } from '../utils/mock/mockDataEntry'
|
|
@@ -44,17 +44,23 @@ describe('Storing data in DHT', () => {
|
|
|
44
44
|
it('Storing data works', async () => {
|
|
45
45
|
const storingNodeIndex = 34
|
|
46
46
|
const entry = createMockDataEntry()
|
|
47
|
-
const successfulStorers = await nodes[storingNodeIndex].storeDataToDht(
|
|
47
|
+
const successfulStorers = await nodes[storingNodeIndex].storeDataToDht(
|
|
48
|
+
getDhtAddressFromRaw(entry.key),
|
|
49
|
+
entry.data!
|
|
50
|
+
)
|
|
48
51
|
expect(successfulStorers.length).toBeGreaterThan(4)
|
|
49
52
|
}, 30000)
|
|
50
53
|
|
|
51
54
|
it('Storing and getting data works', async () => {
|
|
52
55
|
const storingNode = getRandomNode()
|
|
53
56
|
const entry = createMockDataEntry()
|
|
54
|
-
const successfulStorers = await storingNode.storeDataToDht(
|
|
57
|
+
const successfulStorers = await storingNode.storeDataToDht(
|
|
58
|
+
getDhtAddressFromRaw(entry.key),
|
|
59
|
+
entry.data!
|
|
60
|
+
)
|
|
55
61
|
expect(successfulStorers.length).toBeGreaterThan(4)
|
|
56
62
|
const fetchingNode = getRandomNode()
|
|
57
|
-
const results = await fetchingNode.getDataFromDht(entry.key)
|
|
63
|
+
const results = await fetchingNode.getDataFromDht(getDhtAddressFromRaw(entry.key))
|
|
58
64
|
results.forEach((result) => {
|
|
59
65
|
expectEqualData(result, entry)
|
|
60
66
|
})
|
|
@@ -64,13 +70,17 @@ describe('Storing data in DHT', () => {
|
|
|
64
70
|
const storingNode = getRandomNode()
|
|
65
71
|
const entry = createMockDataEntry()
|
|
66
72
|
const requestor = createMockPeerDescriptor()
|
|
67
|
-
const successfulStorers = await storingNode.storeDataToDht(
|
|
73
|
+
const successfulStorers = await storingNode.storeDataToDht(
|
|
74
|
+
getDhtAddressFromRaw(entry.key),
|
|
75
|
+
entry.data!,
|
|
76
|
+
getDhtAddressFromRaw(requestor.nodeId)
|
|
77
|
+
)
|
|
68
78
|
expect(successfulStorers.length).toBeGreaterThan(4)
|
|
69
79
|
const fetchingNode = getRandomNode()
|
|
70
|
-
const results = await fetchingNode.getDataFromDht(entry.key)
|
|
80
|
+
const results = await fetchingNode.getDataFromDht(getDhtAddressFromRaw(entry.key))
|
|
71
81
|
results.forEach((result) => {
|
|
72
82
|
expectEqualData(result, entry)
|
|
73
|
-
expect(
|
|
83
|
+
expect(getDhtAddressFromRaw(result.creator)).toEqual(getNodeIdFromPeerDescriptor(requestor))
|
|
74
84
|
})
|
|
75
85
|
}, 30000)
|
|
76
86
|
})
|
|
@@ -2,7 +2,8 @@ import { LatencyType, Simulator } from '../../src/connection/simulator/Simulator
|
|
|
2
2
|
import { DhtNode } from '../../src/dht/DhtNode'
|
|
3
3
|
import { createMockConnectionDhtNode, waitConnectionManagersReadyForTesting } from '../utils/utils'
|
|
4
4
|
import { createMockDataEntry, expectEqualData } from '../utils/mock/mockDataEntry'
|
|
5
|
-
import {
|
|
5
|
+
import { createRandomDhtAddress } from '../../src/identifiers'
|
|
6
|
+
import { getDhtAddressFromRaw } from '../../src/identifiers'
|
|
6
7
|
|
|
7
8
|
const NUM_NODES = 5
|
|
8
9
|
const MAX_CONNECTIONS = 5
|
|
@@ -20,7 +21,7 @@ describe('Storing data in DHT', () => {
|
|
|
20
21
|
beforeEach(async () => {
|
|
21
22
|
nodes = []
|
|
22
23
|
const entryPoint = await createMockConnectionDhtNode(simulator,
|
|
23
|
-
|
|
24
|
+
createRandomDhtAddress(), K, MAX_CONNECTIONS)
|
|
24
25
|
nodes.push(entryPoint)
|
|
25
26
|
for (let i = 1; i < NUM_NODES; i++) {
|
|
26
27
|
const node = await createMockConnectionDhtNode(simulator,
|
|
@@ -38,11 +39,11 @@ describe('Storing data in DHT', () => {
|
|
|
38
39
|
it('Data can be deleted', async () => {
|
|
39
40
|
const storingNode = getRandomNode()
|
|
40
41
|
const entry = createMockDataEntry()
|
|
41
|
-
const successfulStorers = await storingNode.storeDataToDht(entry.key, entry.data!)
|
|
42
|
+
const successfulStorers = await storingNode.storeDataToDht(getDhtAddressFromRaw(entry.key), entry.data!)
|
|
42
43
|
expect(successfulStorers.length).toBeGreaterThan(4)
|
|
43
|
-
await storingNode.deleteDataFromDht(entry.key, true)
|
|
44
|
+
await storingNode.deleteDataFromDht(getDhtAddressFromRaw(entry.key), true)
|
|
44
45
|
const fetchingNode = getRandomNode()
|
|
45
|
-
const results = await fetchingNode.getDataFromDht(entry.key)
|
|
46
|
+
const results = await fetchingNode.getDataFromDht(getDhtAddressFromRaw(entry.key))
|
|
46
47
|
results.forEach((result) => {
|
|
47
48
|
expect(result.deleted).toBeTrue()
|
|
48
49
|
expectEqualData(result, entry)
|
|
@@ -52,18 +53,18 @@ describe('Storing data in DHT', () => {
|
|
|
52
53
|
it('Data can be deleted and re-stored', async () => {
|
|
53
54
|
const storingNode = getRandomNode()
|
|
54
55
|
const entry = createMockDataEntry()
|
|
55
|
-
const successfulStorers1 = await storingNode.storeDataToDht(entry.key, entry.data!)
|
|
56
|
+
const successfulStorers1 = await storingNode.storeDataToDht(getDhtAddressFromRaw(entry.key), entry.data!)
|
|
56
57
|
expect(successfulStorers1.length).toBeGreaterThan(4)
|
|
57
|
-
await storingNode.deleteDataFromDht(entry.key, true)
|
|
58
|
+
await storingNode.deleteDataFromDht(getDhtAddressFromRaw(entry.key), true)
|
|
58
59
|
const fetchingNode = getRandomNode()
|
|
59
|
-
const results1 = await fetchingNode.getDataFromDht(entry.key)
|
|
60
|
+
const results1 = await fetchingNode.getDataFromDht(getDhtAddressFromRaw(entry.key))
|
|
60
61
|
results1.forEach((result) => {
|
|
61
62
|
expect(result.deleted).toBeTrue()
|
|
62
63
|
expectEqualData(result, entry)
|
|
63
64
|
})
|
|
64
|
-
const successfulStorers2 = await storingNode.storeDataToDht(entry.key, entry.data!)
|
|
65
|
+
const successfulStorers2 = await storingNode.storeDataToDht(getDhtAddressFromRaw(entry.key), entry.data!)
|
|
65
66
|
expect(successfulStorers2.length).toBeGreaterThan(4)
|
|
66
|
-
const results2 = await fetchingNode.getDataFromDht(entry.key)
|
|
67
|
+
const results2 = await fetchingNode.getDataFromDht(getDhtAddressFromRaw(entry.key))
|
|
67
68
|
results2.forEach((result) => {
|
|
68
69
|
expect(result.deleted).toBeFalse()
|
|
69
70
|
expectEqualData(result, entry)
|
|
@@ -3,6 +3,7 @@ import { DhtNode } from '../../src/dht/DhtNode'
|
|
|
3
3
|
import { Simulator } from '../../src/connection/simulator/Simulator'
|
|
4
4
|
import { waitForCondition } from '@streamr/utils'
|
|
5
5
|
import { createMockDataEntry, expectEqualData } from '../utils/mock/mockDataEntry'
|
|
6
|
+
import { getDhtAddressFromRaw } from '../../src/identifiers'
|
|
6
7
|
|
|
7
8
|
describe('Storing data in DHT with two peers', () => {
|
|
8
9
|
|
|
@@ -31,10 +32,10 @@ describe('Storing data in DHT with two peers', () => {
|
|
|
31
32
|
it('Node can store on two peer DHT', async () => {
|
|
32
33
|
const storedData1 = createMockDataEntry()
|
|
33
34
|
const storedData2 = createMockDataEntry()
|
|
34
|
-
await otherNode.storeDataToDht(storedData1.key, storedData1.data!)
|
|
35
|
-
await entryPoint.storeDataToDht(storedData2.key, storedData2.data!)
|
|
36
|
-
const foundData1 = await otherNode.getDataFromDht(storedData1.key)
|
|
37
|
-
const foundData2 = await entryPoint.getDataFromDht(storedData2.key)
|
|
35
|
+
await otherNode.storeDataToDht(getDhtAddressFromRaw(storedData1.key), storedData1.data!)
|
|
36
|
+
await entryPoint.storeDataToDht(getDhtAddressFromRaw(storedData2.key), storedData2.data!)
|
|
37
|
+
const foundData1 = await otherNode.getDataFromDht(getDhtAddressFromRaw(storedData1.key))
|
|
38
|
+
const foundData2 = await entryPoint.getDataFromDht(getDhtAddressFromRaw(storedData2.key))
|
|
38
39
|
expectEqualData(foundData1[0], storedData1)
|
|
39
40
|
expectEqualData(foundData2[0], storedData2)
|
|
40
41
|
})
|
|
@@ -43,8 +44,8 @@ describe('Storing data in DHT with two peers', () => {
|
|
|
43
44
|
await otherNode.stop()
|
|
44
45
|
await waitForCondition(() => entryPoint.getNumberOfNeighbors() === 0)
|
|
45
46
|
const storedData = createMockDataEntry()
|
|
46
|
-
await entryPoint.storeDataToDht(storedData.key, storedData.data!)
|
|
47
|
-
const foundData = await entryPoint.getDataFromDht(storedData.key)
|
|
47
|
+
await entryPoint.storeDataToDht(getDhtAddressFromRaw(storedData.key), storedData.data!)
|
|
48
|
+
const foundData = await entryPoint.getDataFromDht(getDhtAddressFromRaw(storedData.key))
|
|
48
49
|
expectEqualData(foundData[0], storedData)
|
|
49
50
|
}, 60000)
|
|
50
51
|
})
|
|
@@ -9,9 +9,7 @@ import { StoreRpcClient } from '../../src/proto/packages/dht/protos/DhtRpc.clien
|
|
|
9
9
|
import { StoreRpcRemote } from '../../src/dht/store/StoreRpcRemote'
|
|
10
10
|
import { createMockDataEntry } from '../utils/mock/mockDataEntry'
|
|
11
11
|
import { getNodeIdFromPeerDescriptor } from '../../src/helpers/peerIdFromPeerDescriptor'
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
const SERVICE_ID = 'test'
|
|
12
|
+
import { createRandomDhtAddress, getRawFromDhtAddress } from '../../src/identifiers'
|
|
15
13
|
|
|
16
14
|
describe('StoreRpcRemote', () => {
|
|
17
15
|
|
|
@@ -24,7 +22,7 @@ describe('StoreRpcRemote', () => {
|
|
|
24
22
|
const request: StoreDataRequest = {
|
|
25
23
|
key: data.key,
|
|
26
24
|
data: data.data,
|
|
27
|
-
creator:
|
|
25
|
+
creator: getRawFromDhtAddress(createRandomDhtAddress()),
|
|
28
26
|
ttl: 10
|
|
29
27
|
}
|
|
30
28
|
|
|
@@ -38,7 +36,7 @@ describe('StoreRpcRemote', () => {
|
|
|
38
36
|
serverRpcCommunicator.on('outgoingMessage', (message: RpcMessage) => {
|
|
39
37
|
clientRpcCommunicator.handleIncomingMessage(message)
|
|
40
38
|
})
|
|
41
|
-
rpcRemote = new StoreRpcRemote(clientPeerDescriptor, serverPeerDescriptor,
|
|
39
|
+
rpcRemote = new StoreRpcRemote(clientPeerDescriptor, serverPeerDescriptor, clientRpcCommunicator, StoreRpcClient)
|
|
42
40
|
})
|
|
43
41
|
|
|
44
42
|
it('storeData happy path', async () => {
|
|
@@ -37,4 +37,8 @@ describe('isPrivateIPv4', () => {
|
|
|
37
37
|
it('return false for a public address', () => {
|
|
38
38
|
expect(isPrivateIPv4('203.0.113.181')).toBe(false)
|
|
39
39
|
})
|
|
40
|
+
|
|
41
|
+
it('return true for localhost IP address', () => {
|
|
42
|
+
expect(isPrivateIPv4('127.0.0.1')).toBe(true)
|
|
43
|
+
})
|
|
40
44
|
})
|