@streamr/dht 100.0.0-testnet-two.0 → 100.0.0-testnet-two.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/package.json +66 -0
- 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.js +3 -3
- package/dist/src/connection/ConnectionManager.js.map +1 -1
- package/dist/src/connection/Handshaker.d.ts +1 -1
- package/dist/src/connection/Handshaker.js +14 -5
- package/dist/src/connection/Handshaker.js.map +1 -1
- package/dist/src/connection/ManagedConnection.d.ts +3 -3
- package/dist/src/connection/ManagedConnection.js +3 -3
- package/dist/src/connection/ManagedConnection.js.map +1 -1
- package/dist/src/connection/simulator/Simulator.js.map +1 -1
- package/dist/src/connection/simulator/SimulatorConnector.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 +11 -3
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnector.js +18 -8
- 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 +23 -18
- package/dist/src/dht/DhtNode.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcLocal.d.ts +4 -3
- package/dist/src/dht/DhtNodeRpcLocal.js +3 -2
- package/dist/src/dht/DhtNodeRpcLocal.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcRemote.d.ts +6 -5
- package/dist/src/dht/DhtNodeRpcRemote.js +10 -11
- 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 +12 -12
- 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 -12
- 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 +16 -9
- 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 +12 -11
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.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/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 -8
- package/dist/src/dht/store/LocalDataStore.js +18 -24
- 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 +20 -21
- 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 -1
- package/dist/src/helpers/peerIdFromPeerDescriptor.js.map +1 -1
- package/dist/src/helpers/versionCompatibility.d.ts +2 -0
- package/dist/src/helpers/versionCompatibility.js +18 -0
- package/dist/src/helpers/versionCompatibility.js.map +1 -0
- package/dist/src/identifiers.d.ts +6 -0
- package/dist/src/identifiers.js +23 -0
- package/dist/src/identifiers.js.map +1 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +13 -5
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +9 -5
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
- package/package.json +5 -5
- package/protos/DhtRpc.proto +3 -1
- package/src/connection/ConnectionLockHandler.ts +15 -15
- package/src/connection/ConnectionLockRpcLocal.ts +3 -3
- package/src/connection/ConnectionManager.ts +4 -7
- package/src/connection/Handshaker.ts +21 -6
- package/src/connection/ManagedConnection.ts +10 -6
- package/src/connection/simulator/Simulator.ts +2 -2
- package/src/connection/simulator/SimulatorConnector.ts +2 -2
- package/src/connection/webrtc/BrowserWebrtcConnection.ts +0 -4
- package/src/connection/webrtc/WebrtcConnector.ts +2 -3
- package/src/connection/webrtc/WebrtcConnectorRpcLocal.ts +11 -5
- package/src/connection/websocket/WebsocketConnector.ts +19 -11
- package/src/dht/DhtNode.ts +33 -31
- package/src/dht/DhtNodeRpcLocal.ts +4 -4
- package/src/dht/DhtNodeRpcRemote.ts +15 -17
- package/src/dht/ExternalApiRpcLocal.ts +15 -6
- package/src/dht/ExternalApiRpcRemote.ts +5 -4
- package/src/dht/PeerManager.ts +20 -20
- 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 -16
- package/src/dht/discovery/PeerDiscovery.ts +32 -11
- package/src/dht/recursive-operation/RecursiveOperationManager.ts +14 -14
- 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/RoutingSession.ts +6 -8
- package/src/dht/store/LocalDataStore.ts +25 -33
- package/src/dht/store/StoreManager.ts +25 -29
- 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 -4
- package/src/helpers/versionCompatibility.ts +13 -0
- package/src/identifiers.ts +20 -0
- package/src/proto/packages/dht/protos/DhtRpc.ts +18 -10
- 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 +25 -23
- 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 +37 -29
- 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/unit/versionCompatibility.test.ts +16 -0
- package/test/utils/customMatchers.ts +3 -2
- package/test/utils/mock/mockDataEntry.ts +8 -6
- package/test/utils/utils.ts +4 -4
- package/tsconfig.browser.json +2 -1
- package/tsconfig.jest.json +2 -1
- package/tsconfig.node.json +2 -1
- 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,12 +5,12 @@ 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
10
|
import { getNodeIdFromPeerDescriptor, 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
15
|
|
|
16
16
|
const logger = new Logger(module)
|
|
@@ -27,7 +27,7 @@ describe('Replicate data from node to node in DHT', () => {
|
|
|
27
27
|
let nodes: DhtNode[]
|
|
28
28
|
let entrypointDescriptor: PeerDescriptor
|
|
29
29
|
const simulator = new Simulator(LatencyType.FIXED, 20)
|
|
30
|
-
const nodesById: Map<
|
|
30
|
+
const nodesById: Map<DhtAddress, DhtNode> = new Map()
|
|
31
31
|
|
|
32
32
|
if (!fs.existsSync('test/data/nodeids.json')) {
|
|
33
33
|
console.log('ground truth data does not exist yet, generating..')
|
|
@@ -43,12 +43,12 @@ describe('Replicate data from node to node in DHT', () => {
|
|
|
43
43
|
beforeEach(async () => {
|
|
44
44
|
nodes = []
|
|
45
45
|
entryPoint = await createMockConnectionDhtNode(simulator,
|
|
46
|
-
Uint8Array.from(dhtIds[0].data), K, MAX_CONNECTIONS)
|
|
46
|
+
getDhtAddressFromRaw(Uint8Array.from(dhtIds[0].data)), K, MAX_CONNECTIONS)
|
|
47
47
|
nodes.push(entryPoint)
|
|
48
48
|
nodesById.set(entryPoint.getNodeId(), entryPoint)
|
|
49
49
|
|
|
50
50
|
entrypointDescriptor = {
|
|
51
|
-
nodeId:
|
|
51
|
+
nodeId: getRawFromDhtAddress(entryPoint.getNodeId()),
|
|
52
52
|
type: NodeType.NODEJS
|
|
53
53
|
}
|
|
54
54
|
|
|
@@ -56,7 +56,7 @@ describe('Replicate data from node to node in DHT', () => {
|
|
|
56
56
|
|
|
57
57
|
for (let i = 1; i < NUM_NODES; i++) {
|
|
58
58
|
const node = await createMockConnectionDhtNode(simulator,
|
|
59
|
-
Uint8Array.from(dhtIds[i].data), K, MAX_CONNECTIONS)
|
|
59
|
+
getDhtAddressFromRaw(Uint8Array.from(dhtIds[i].data)), K, MAX_CONNECTIONS)
|
|
60
60
|
nodesById.set(node.getNodeId(), node)
|
|
61
61
|
nodes.push(node)
|
|
62
62
|
}
|
|
@@ -74,13 +74,13 @@ describe('Replicate data from node to node in DHT', () => {
|
|
|
74
74
|
})
|
|
75
75
|
|
|
76
76
|
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
|
|
77
|
+
const dataKey = getDhtAddressFromRaw(PeerID.fromString('3232323e12r31r3').value)
|
|
78
|
+
const data = createMockDataEntry({ key: dataKey })
|
|
79
79
|
|
|
80
80
|
// calculate offline which node is closest to the data
|
|
81
81
|
|
|
82
82
|
const sortedList = new SortedContactList<Contact>({
|
|
83
|
-
referenceId: dataKey
|
|
83
|
+
referenceId: dataKey,
|
|
84
84
|
maxSize: 10000,
|
|
85
85
|
allowToContainReferenceId: true,
|
|
86
86
|
emitEvents: false
|
|
@@ -103,7 +103,7 @@ describe('Replicate data from node to node in DHT', () => {
|
|
|
103
103
|
await nodes[0].joinDht([entrypointDescriptor])
|
|
104
104
|
|
|
105
105
|
logger.info('storing data to node 0')
|
|
106
|
-
const successfulStorers = await nodes[0].storeDataToDht(dataKey
|
|
106
|
+
const successfulStorers = await nodes[0].storeDataToDht(dataKey, data.data!)
|
|
107
107
|
expect(successfulStorers.length).toBe(1)
|
|
108
108
|
logger.info('data successfully stored to node 0')
|
|
109
109
|
|
|
@@ -114,7 +114,8 @@ describe('Replicate data from node to node in DHT', () => {
|
|
|
114
114
|
let hasDataMarker = ''
|
|
115
115
|
|
|
116
116
|
// @ts-expect-error private field
|
|
117
|
-
|
|
117
|
+
const store = node.localDataStore
|
|
118
|
+
if (store.getEntries(dataKey)) {
|
|
118
119
|
hasDataMarker = '<-'
|
|
119
120
|
}
|
|
120
121
|
|
|
@@ -142,7 +143,8 @@ describe('Replicate data from node to node in DHT', () => {
|
|
|
142
143
|
let hasDataMarker = ''
|
|
143
144
|
|
|
144
145
|
// @ts-expect-error private field
|
|
145
|
-
|
|
146
|
+
const store = node.localDataStore
|
|
147
|
+
if (store.getEntries(dataKey)) {
|
|
146
148
|
hasDataMarker = '<-'
|
|
147
149
|
}
|
|
148
150
|
|
|
@@ -152,12 +154,13 @@ describe('Replicate data from node to node in DHT', () => {
|
|
|
152
154
|
const closestNode = nodesById.get(getNodeIdFromPeerDescriptor(closest[0].getPeerDescriptor()))!
|
|
153
155
|
|
|
154
156
|
// @ts-expect-error private field
|
|
155
|
-
|
|
157
|
+
const store = closestNode.localDataStore
|
|
158
|
+
expect(store.getEntries(dataKey).size).toBeGreaterThanOrEqual(1)
|
|
156
159
|
}, 180000)
|
|
157
160
|
|
|
158
161
|
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
|
|
162
|
+
const dataKey = getDhtAddressFromRaw(PeerID.fromString('3232323e12r31r3').value)
|
|
163
|
+
const data = createMockDataEntry({ key: dataKey })
|
|
161
164
|
|
|
162
165
|
logger.info(NUM_NODES + ' nodes joining layer0 DHT')
|
|
163
166
|
await Promise.all(
|
|
@@ -173,7 +176,7 @@ describe('Replicate data from node to node in DHT', () => {
|
|
|
173
176
|
const randomIndex = Math.floor(Math.random() * nodes.length)
|
|
174
177
|
logger.info('storing data to a random node: ' + randomIndex)
|
|
175
178
|
|
|
176
|
-
const successfulStorers = await nodes[randomIndex].storeDataToDht(dataKey
|
|
179
|
+
const successfulStorers = await nodes[randomIndex].storeDataToDht(dataKey, data.data!)
|
|
177
180
|
|
|
178
181
|
logger.info('data successfully stored to ' + successfulStorers + ' nodes')
|
|
179
182
|
|
|
@@ -187,10 +190,10 @@ describe('Replicate data from node to node in DHT', () => {
|
|
|
187
190
|
const index = Math.floor(Math.random() * randomIndices.length)
|
|
188
191
|
const nodeIndex = randomIndices[index]
|
|
189
192
|
randomIndices.splice(index, 1)
|
|
190
|
-
|
|
193
|
+
// @ts-expect-error private field
|
|
194
|
+
const store = nodes[nodeIndex].localDataStore
|
|
191
195
|
logger.info('Stopping node ' + nodeIndex + ' ' +
|
|
192
|
-
|
|
193
|
-
(nodes[nodeIndex].localDataStore.getEntries(dataKey.value) ? ', has data' : ' does not have data'))
|
|
196
|
+
(store.getEntries(dataKey) ? ', has data' : ' does not have data'))
|
|
194
197
|
|
|
195
198
|
await nodes[nodeIndex].stop()
|
|
196
199
|
}
|
|
@@ -198,10 +201,9 @@ describe('Replicate data from node to node in DHT', () => {
|
|
|
198
201
|
logger.info('after random graceful leaving, node ' + randomIndices[0] + ' is left')
|
|
199
202
|
|
|
200
203
|
// @ts-expect-error private field
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
expect(nodes[randomIndices[0]].localDataStore.getEntries(dataKey.value).size).toBeGreaterThanOrEqual(1)
|
|
204
|
+
const firstStore = nodes[randomIndices[0]].localDataStore
|
|
205
|
+
logger.info('data of ' + randomIndices[0] + ' was ' + firstStore.getEntries(dataKey))
|
|
206
|
+
expect(firstStore.getEntries(dataKey).size).toBeGreaterThanOrEqual(1)
|
|
205
207
|
|
|
206
208
|
}, 180000)
|
|
207
209
|
})
|
|
@@ -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
|
})
|
|
@@ -2,17 +2,16 @@ import { wait } from '@streamr/utils'
|
|
|
2
2
|
import { LocalDataStore } from '../../src/dht/store/LocalDataStore'
|
|
3
3
|
import {
|
|
4
4
|
getNodeIdFromPeerDescriptor,
|
|
5
|
-
peerIdFromPeerDescriptor
|
|
6
5
|
} from '../../src/helpers/peerIdFromPeerDescriptor'
|
|
7
6
|
import { createMockPeerDescriptor } from '../utils/utils'
|
|
8
7
|
import { createMockDataEntry, expectEqualData } from '../utils/mock/mockDataEntry'
|
|
9
|
-
import {
|
|
8
|
+
import { DhtAddress, createRandomDhtAddress, getDhtAddressFromRaw } from '../../src/identifiers'
|
|
10
9
|
|
|
11
10
|
describe('LocalDataStore', () => {
|
|
12
11
|
|
|
13
12
|
let localDataStore: LocalDataStore
|
|
14
13
|
|
|
15
|
-
const getEntryArray = (key:
|
|
14
|
+
const getEntryArray = (key: DhtAddress) => {
|
|
16
15
|
return Array.from(localDataStore.getEntries(key).values())
|
|
17
16
|
}
|
|
18
17
|
|
|
@@ -27,84 +26,93 @@ describe('LocalDataStore', () => {
|
|
|
27
26
|
it('can store', () => {
|
|
28
27
|
const storedEntry = createMockDataEntry()
|
|
29
28
|
localDataStore.storeEntry(storedEntry)
|
|
30
|
-
const fetchedEntries = getEntryArray(storedEntry.key)
|
|
29
|
+
const fetchedEntries = getEntryArray(getDhtAddressFromRaw(storedEntry.key))
|
|
31
30
|
expect(fetchedEntries).toHaveLength(1)
|
|
32
31
|
expectEqualData(fetchedEntries[0], storedEntry)
|
|
33
32
|
})
|
|
34
33
|
|
|
35
34
|
it('multiple storers behind one key', () => {
|
|
36
|
-
const creator1 =
|
|
37
|
-
const creator2 =
|
|
38
|
-
const key =
|
|
35
|
+
const creator1 = createRandomDhtAddress()
|
|
36
|
+
const creator2 = createRandomDhtAddress()
|
|
37
|
+
const key = createRandomDhtAddress()
|
|
39
38
|
const storedEntry1 = createMockDataEntry({ key, creator: creator1 })
|
|
40
39
|
const storedEntry2 = createMockDataEntry({ key, creator: creator2 })
|
|
41
40
|
localDataStore.storeEntry(storedEntry1)
|
|
42
41
|
localDataStore.storeEntry(storedEntry2)
|
|
43
42
|
const fetchedEntries = localDataStore.getEntries(key)
|
|
44
43
|
expect(fetchedEntries.size).toBe(2)
|
|
45
|
-
expectEqualData(fetchedEntries.get(
|
|
46
|
-
expectEqualData(fetchedEntries.get(
|
|
44
|
+
expectEqualData(fetchedEntries.get(creator1)!, storedEntry1)
|
|
45
|
+
expectEqualData(fetchedEntries.get(creator2)!, storedEntry2)
|
|
47
46
|
})
|
|
48
47
|
|
|
49
48
|
it('can remove data entries', () => {
|
|
50
|
-
const creator1 =
|
|
51
|
-
const creator2 =
|
|
52
|
-
const key =
|
|
49
|
+
const creator1 = createRandomDhtAddress()
|
|
50
|
+
const creator2 = createRandomDhtAddress()
|
|
51
|
+
const key = createRandomDhtAddress()
|
|
53
52
|
const storedEntry1 = createMockDataEntry({ key, creator: creator1 })
|
|
54
53
|
const storedEntry2 = createMockDataEntry({ key, creator: creator2 })
|
|
55
54
|
localDataStore.storeEntry(storedEntry1)
|
|
56
55
|
localDataStore.storeEntry(storedEntry2)
|
|
57
|
-
localDataStore.deleteEntry(key,
|
|
56
|
+
localDataStore.deleteEntry(key, creator1)
|
|
58
57
|
const fetchedEntries = getEntryArray(key)
|
|
59
58
|
expect(fetchedEntries).toHaveLength(1)
|
|
60
59
|
expectEqualData(fetchedEntries[0], storedEntry2)
|
|
61
60
|
})
|
|
62
61
|
|
|
63
62
|
it('can remove all data entries', () => {
|
|
64
|
-
const creator1 =
|
|
65
|
-
const creator2 =
|
|
66
|
-
const key =
|
|
63
|
+
const creator1 = createRandomDhtAddress()
|
|
64
|
+
const creator2 = createRandomDhtAddress()
|
|
65
|
+
const key = createRandomDhtAddress()
|
|
67
66
|
const storedEntry1 = createMockDataEntry({ key, creator: creator1 })
|
|
68
67
|
const storedEntry2 = createMockDataEntry({ key, creator: creator2 })
|
|
69
68
|
localDataStore.storeEntry(storedEntry1)
|
|
70
69
|
localDataStore.storeEntry(storedEntry2)
|
|
71
|
-
localDataStore.deleteEntry(key,
|
|
72
|
-
localDataStore.deleteEntry(key,
|
|
70
|
+
localDataStore.deleteEntry(key, creator1)
|
|
71
|
+
localDataStore.deleteEntry(key, creator2)
|
|
73
72
|
expect(getEntryArray(key)).toHaveLength(0)
|
|
74
73
|
})
|
|
75
74
|
|
|
76
75
|
it('data is deleted after TTL', async () => {
|
|
77
76
|
const storedEntry = createMockDataEntry({ ttl: 1000 })
|
|
78
77
|
localDataStore.storeEntry(storedEntry)
|
|
79
|
-
expect(getEntryArray(storedEntry.key)).toHaveLength(1)
|
|
78
|
+
expect(getEntryArray(getDhtAddressFromRaw(storedEntry.key))).toHaveLength(1)
|
|
80
79
|
await wait(1100)
|
|
81
|
-
expect(getEntryArray(storedEntry.key)).toHaveLength(0)
|
|
80
|
+
expect(getEntryArray(getDhtAddressFromRaw(storedEntry.key))).toHaveLength(0)
|
|
82
81
|
})
|
|
83
82
|
|
|
84
83
|
describe('mark data as deleted', () => {
|
|
85
84
|
|
|
86
85
|
it('happy path', () => {
|
|
87
|
-
const creator1 =
|
|
86
|
+
const creator1 = createRandomDhtAddress()
|
|
88
87
|
const storedEntry = createMockDataEntry({ creator: creator1 })
|
|
89
88
|
localDataStore.storeEntry(storedEntry)
|
|
90
|
-
const notDeletedData = localDataStore.getEntries(storedEntry.key)
|
|
91
|
-
expect(notDeletedData.get(
|
|
92
|
-
const returnValue = localDataStore.markAsDeleted(
|
|
89
|
+
const notDeletedData = localDataStore.getEntries(getDhtAddressFromRaw(storedEntry.key))
|
|
90
|
+
expect(notDeletedData.get(creator1)!.deleted).toBeFalse()
|
|
91
|
+
const returnValue = localDataStore.markAsDeleted(
|
|
92
|
+
getDhtAddressFromRaw(storedEntry.key),
|
|
93
|
+
creator1
|
|
94
|
+
)
|
|
93
95
|
expect(returnValue).toBe(true)
|
|
94
|
-
const deletedData = localDataStore.getEntries(storedEntry.key)
|
|
95
|
-
expect(deletedData.get(
|
|
96
|
+
const deletedData = localDataStore.getEntries(getDhtAddressFromRaw(storedEntry.key))
|
|
97
|
+
expect(deletedData.get(creator1)!.deleted).toBeTrue()
|
|
96
98
|
})
|
|
97
99
|
|
|
98
100
|
it('data not stored', () => {
|
|
99
|
-
const
|
|
100
|
-
const returnValue = localDataStore.markAsDeleted(
|
|
101
|
+
const key = createRandomDhtAddress()
|
|
102
|
+
const returnValue = localDataStore.markAsDeleted(
|
|
103
|
+
key,
|
|
104
|
+
getNodeIdFromPeerDescriptor(createMockPeerDescriptor())
|
|
105
|
+
)
|
|
101
106
|
expect(returnValue).toBe(false)
|
|
102
107
|
})
|
|
103
108
|
|
|
104
109
|
it('data not stored by the given creator', () => {
|
|
105
110
|
const storedEntry = createMockDataEntry()
|
|
106
111
|
localDataStore.storeEntry(storedEntry)
|
|
107
|
-
const returnValue = localDataStore.markAsDeleted(
|
|
112
|
+
const returnValue = localDataStore.markAsDeleted(
|
|
113
|
+
getDhtAddressFromRaw(storedEntry.key),
|
|
114
|
+
getNodeIdFromPeerDescriptor(createMockPeerDescriptor())
|
|
115
|
+
)
|
|
108
116
|
expect(returnValue).toBe(false)
|
|
109
117
|
})
|
|
110
118
|
})
|