@streamr/dht 100.0.0-testnet-two.4 → 100.0.0-testnet-three.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 +8 -8
- package/dist/src/connection/Connection.d.ts +1 -0
- package/dist/src/connection/Connection.js +10 -3
- package/dist/src/connection/Connection.js.map +1 -1
- package/dist/src/connection/ConnectionLockHandler.d.ts +3 -3
- package/dist/src/connection/ConnectionLockHandler.js +8 -10
- package/dist/src/connection/ConnectionLockHandler.js.map +1 -1
- package/dist/src/connection/ConnectionLockRpcLocal.js +5 -4
- package/dist/src/connection/ConnectionLockRpcLocal.js.map +1 -1
- package/dist/src/connection/ConnectionLockRpcRemote.js +4 -4
- package/dist/src/connection/ConnectionLockRpcRemote.js.map +1 -1
- package/dist/src/connection/ConnectionManager.d.ts +8 -8
- package/dist/src/connection/ConnectionManager.js +54 -55
- package/dist/src/connection/ConnectionManager.js.map +1 -1
- package/dist/src/connection/ConnectorFacade.d.ts +3 -2
- package/dist/src/connection/ConnectorFacade.js +7 -0
- package/dist/src/connection/ConnectorFacade.js.map +1 -1
- package/dist/src/connection/Handshaker.js +3 -1
- package/dist/src/connection/Handshaker.js.map +1 -1
- package/dist/src/connection/IConnection.d.ts +2 -7
- package/dist/src/connection/IConnection.js +1 -8
- package/dist/src/connection/IConnection.js.map +1 -1
- package/dist/src/connection/ManagedConnection.js +23 -15
- package/dist/src/connection/ManagedConnection.js.map +1 -1
- package/dist/src/connection/ManagedWebrtcConnection.js.map +1 -1
- package/dist/src/connection/connectivityChecker.js.map +1 -1
- package/dist/src/connection/connectivityRequestHandler.js +5 -2
- package/dist/src/connection/connectivityRequestHandler.js.map +1 -1
- package/dist/src/connection/simulator/Simulator.js +32 -20
- package/dist/src/connection/simulator/Simulator.js.map +1 -1
- package/dist/src/connection/simulator/SimulatorConnection.js +13 -10
- package/dist/src/connection/simulator/SimulatorConnection.js.map +1 -1
- package/dist/src/connection/simulator/SimulatorConnector.js +9 -6
- package/dist/src/connection/simulator/SimulatorConnector.js.map +1 -1
- package/dist/src/connection/simulator/pings.js.map +1 -1
- package/dist/src/connection/webrtc/NodeWebrtcConnection.d.ts +1 -1
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js +26 -14
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnector.d.ts +0 -1
- package/dist/src/connection/webrtc/WebrtcConnector.js +18 -17
- package/dist/src/connection/webrtc/WebrtcConnector.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js +10 -9
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js.map +1 -1
- package/dist/src/connection/webrtc/iceServerAsString.js.map +1 -1
- package/dist/src/connection/websocket/AutoCertifierClientFacade.js +3 -0
- package/dist/src/connection/websocket/AutoCertifierClientFacade.js.map +1 -1
- package/dist/src/connection/websocket/ClientWebsocket.js +7 -4
- package/dist/src/connection/websocket/ClientWebsocket.js.map +1 -1
- package/dist/src/connection/websocket/ServerWebsocket.d.ts +1 -0
- package/dist/src/connection/websocket/ServerWebsocket.js +22 -3
- package/dist/src/connection/websocket/ServerWebsocket.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnector.d.ts +2 -1
- package/dist/src/connection/websocket/WebsocketConnector.js +24 -15
- package/dist/src/connection/websocket/WebsocketConnector.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.d.ts +2 -1
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.js +3 -1
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.js +2 -2
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketServer.js +6 -3
- package/dist/src/connection/websocket/WebsocketServer.js.map +1 -1
- package/dist/src/dht/DhtNode.d.ts +18 -19
- package/dist/src/dht/DhtNode.js +56 -65
- package/dist/src/dht/DhtNode.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcLocal.d.ts +1 -1
- package/dist/src/dht/DhtNodeRpcLocal.js +5 -4
- package/dist/src/dht/DhtNodeRpcLocal.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcRemote.d.ts +2 -1
- package/dist/src/dht/DhtNodeRpcRemote.js +5 -3
- package/dist/src/dht/DhtNodeRpcRemote.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcLocal.d.ts +1 -1
- package/dist/src/dht/ExternalApiRpcLocal.js +4 -3
- package/dist/src/dht/ExternalApiRpcLocal.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcRemote.js.map +1 -1
- package/dist/src/dht/PeerManager.d.ts +5 -5
- package/dist/src/dht/PeerManager.js +31 -24
- package/dist/src/dht/PeerManager.js.map +1 -1
- package/dist/src/dht/contact/Contact.js +3 -2
- package/dist/src/dht/contact/Contact.js.map +1 -1
- package/dist/src/dht/contact/ContactList.js +9 -5
- package/dist/src/dht/contact/ContactList.js.map +1 -1
- package/dist/src/dht/contact/RandomContactList.js +1 -0
- package/dist/src/dht/contact/RandomContactList.js.map +1 -1
- package/dist/src/dht/contact/RpcRemote.d.ts +2 -1
- package/dist/src/dht/contact/RpcRemote.js +4 -0
- package/dist/src/dht/contact/RpcRemote.js.map +1 -1
- package/dist/src/dht/contact/SortedContactList.js +3 -2
- package/dist/src/dht/contact/SortedContactList.js.map +1 -1
- package/dist/src/dht/discovery/DiscoverySession.js +8 -8
- package/dist/src/dht/discovery/DiscoverySession.js.map +1 -1
- package/dist/src/dht/discovery/PeerDiscovery.d.ts +8 -2
- package/dist/src/dht/discovery/PeerDiscovery.js +26 -17
- package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.d.ts +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.js +9 -9
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.js +3 -2
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js +6 -5
- 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 +26 -20
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.d.ts +4 -2
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js +5 -2
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js.map +1 -1
- package/dist/src/dht/routing/DuplicateDetector.d.ts +2 -4
- package/dist/src/dht/routing/DuplicateDetector.js +10 -15
- package/dist/src/dht/routing/DuplicateDetector.js.map +1 -1
- package/dist/src/dht/routing/Router.d.ts +1 -1
- package/dist/src/dht/routing/Router.js +20 -15
- package/dist/src/dht/routing/Router.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcLocal.js +4 -4
- package/dist/src/dht/routing/RouterRpcLocal.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcRemote.js +11 -9
- package/dist/src/dht/routing/RouterRpcRemote.js.map +1 -1
- package/dist/src/dht/routing/RoutingSession.d.ts +2 -0
- package/dist/src/dht/routing/RoutingSession.js +27 -9
- package/dist/src/dht/routing/RoutingSession.js.map +1 -1
- package/dist/src/dht/store/LocalDataStore.js +5 -4
- package/dist/src/dht/store/LocalDataStore.js.map +1 -1
- package/dist/src/dht/store/StoreManager.js +8 -8
- package/dist/src/dht/store/StoreManager.js.map +1 -1
- package/dist/src/dht/store/StoreRpcLocal.js +1 -0
- package/dist/src/dht/store/StoreRpcLocal.js.map +1 -1
- package/dist/src/dht/store/StoreRpcRemote.js +3 -3
- package/dist/src/dht/store/StoreRpcRemote.js.map +1 -1
- package/dist/src/exports.d.ts +1 -4
- package/dist/src/exports.js +4 -7
- package/dist/src/exports.js.map +1 -1
- package/dist/src/helpers/AddressTools.js.map +1 -1
- package/dist/src/helpers/Connectivity.js.map +1 -1
- package/dist/src/helpers/MapWithTtl.js +2 -1
- package/dist/src/helpers/MapWithTtl.js.map +1 -1
- package/dist/src/helpers/createPeerDescriptor.d.ts +3 -0
- package/dist/src/helpers/createPeerDescriptor.js +56 -0
- package/dist/src/helpers/createPeerDescriptor.js.map +1 -0
- package/dist/src/helpers/createPeerDescriptorSignaturePayload.d.ts +2 -0
- package/dist/src/helpers/createPeerDescriptorSignaturePayload.js +30 -0
- package/dist/src/helpers/createPeerDescriptorSignaturePayload.js.map +1 -0
- package/dist/src/helpers/debugHelpers.js.map +1 -1
- package/dist/src/helpers/errors.js +2 -0
- package/dist/src/helpers/errors.js.map +1 -1
- package/dist/src/helpers/offering.d.ts +4 -0
- package/dist/src/helpers/offering.js +18 -0
- package/dist/src/helpers/offering.js.map +1 -0
- package/dist/src/helpers/protoToString.js.map +1 -1
- package/dist/src/identifiers.d.ts +3 -0
- package/dist/src/identifiers.js +9 -1
- package/dist/src/identifiers.js.map +1 -1
- package/dist/src/proto/google/protobuf/any.d.ts +8 -5
- package/dist/src/proto/google/protobuf/any.js +8 -8
- package/dist/src/proto/google/protobuf/any.js.map +1 -1
- package/dist/src/proto/google/protobuf/empty.d.ts +0 -1
- package/dist/src/proto/google/protobuf/empty.js +2 -4
- package/dist/src/proto/google/protobuf/empty.js.map +1 -1
- package/dist/src/proto/google/protobuf/timestamp.d.ts +10 -1
- package/dist/src/proto/google/protobuf/timestamp.js +10 -10
- package/dist/src/proto/google/protobuf/timestamp.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +4 -5
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +38 -29
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +22 -12
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +11 -16
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +2 -3
- package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.js +1 -1
- package/dist/src/rpc-protocol/DhtCallContext.d.ts +0 -1
- package/dist/src/rpc-protocol/DhtCallContext.js +8 -0
- package/dist/src/rpc-protocol/DhtCallContext.js.map +1 -1
- package/dist/src/transport/ITransport.d.ts +1 -1
- package/dist/src/transport/ListeningRpcCommunicator.js +2 -0
- package/dist/src/transport/ListeningRpcCommunicator.js.map +1 -1
- package/dist/src/transport/RoutingRpcCommunicator.d.ts +2 -1
- package/dist/src/transport/RoutingRpcCommunicator.js +2 -0
- package/dist/src/transport/RoutingRpcCommunicator.js.map +1 -1
- package/package.json +8 -8
- package/protos/DhtRpc.proto +7 -4
- package/src/connection/Connection.ts +6 -1
- package/src/connection/ConnectionLockHandler.ts +3 -3
- package/src/connection/ConnectionLockRpcLocal.ts +1 -5
- package/src/connection/ConnectionLockRpcRemote.ts +1 -1
- package/src/connection/ConnectionManager.ts +24 -38
- package/src/connection/ConnectorFacade.ts +3 -2
- package/src/connection/IConnection.ts +2 -8
- package/src/connection/ManagedConnection.ts +3 -3
- package/src/connection/connectivityRequestHandler.ts +7 -3
- package/src/connection/simulator/Simulator.ts +1 -2
- package/src/connection/simulator/SimulatorConnection.ts +1 -1
- package/src/connection/simulator/SimulatorConnector.ts +1 -2
- package/src/connection/webrtc/BrowserWebrtcConnection.ts +4 -3
- package/src/connection/webrtc/NodeWebrtcConnection.ts +5 -4
- package/src/connection/webrtc/WebrtcConnector.ts +9 -17
- package/src/connection/webrtc/WebrtcConnectorRpcLocal.ts +7 -7
- package/src/connection/websocket/ClientWebsocket.ts +3 -2
- package/src/connection/websocket/ServerWebsocket.ts +17 -1
- package/src/connection/websocket/WebsocketConnector.ts +10 -9
- package/src/connection/websocket/WebsocketConnectorRpcLocal.ts +4 -2
- package/src/connection/websocket/WebsocketConnectorRpcRemote.ts +1 -1
- package/src/connection/websocket/WebsocketServer.ts +2 -2
- package/src/dht/DhtNode.ts +63 -86
- package/src/dht/DhtNodeRpcLocal.ts +5 -5
- package/src/dht/DhtNodeRpcRemote.ts +3 -3
- package/src/dht/ExternalApiRpcLocal.ts +3 -4
- package/src/dht/PeerManager.ts +14 -20
- package/src/dht/contact/Contact.ts +1 -2
- package/src/dht/contact/RpcRemote.ts +2 -1
- package/src/dht/discovery/DiscoverySession.ts +2 -3
- package/src/dht/discovery/PeerDiscovery.ts +16 -9
- package/src/dht/recursive-operation/RecursiveOperationManager.ts +12 -6
- package/src/dht/recursive-operation/RecursiveOperationRpcLocal.ts +1 -1
- package/src/dht/recursive-operation/RecursiveOperationRpcRemote.ts +3 -2
- package/src/dht/recursive-operation/RecursiveOperationSession.ts +19 -9
- package/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.ts +13 -3
- package/src/dht/routing/DuplicateDetector.ts +9 -21
- package/src/dht/routing/Router.ts +12 -11
- package/src/dht/routing/RouterRpcLocal.ts +1 -2
- package/src/dht/routing/RouterRpcRemote.ts +5 -5
- package/src/dht/routing/RoutingSession.ts +22 -2
- package/src/dht/store/StoreManager.ts +1 -2
- package/src/dht/store/StoreRpcRemote.ts +1 -1
- package/src/exports.ts +9 -4
- package/src/helpers/createPeerDescriptor.ts +56 -0
- package/src/helpers/createPeerDescriptorSignaturePayload.ts +28 -0
- package/src/helpers/offering.ts +15 -0
- package/src/identifiers.ts +10 -1
- package/src/proto/google/protobuf/any.ts +12 -9
- package/src/proto/google/protobuf/empty.ts +2 -5
- package/src/proto/google/protobuf/timestamp.ts +14 -5
- package/src/proto/packages/dht/protos/DhtRpc.client.ts +6 -7
- package/src/proto/packages/dht/protos/DhtRpc.server.ts +3 -4
- package/src/proto/packages/dht/protos/DhtRpc.ts +32 -20
- package/src/proto/packages/proto-rpc/protos/ProtoRpc.ts +1 -1
- package/src/rpc-protocol/DhtCallContext.ts +0 -1
- package/src/transport/ITransport.ts +1 -1
- package/src/transport/RoutingRpcCommunicator.ts +1 -1
- package/test/benchmark/Find.test.ts +6 -8
- package/test/benchmark/KademliaCorrectness.test.ts +2 -3
- package/test/benchmark/SortedContactListBenchmark.test.ts +16 -16
- package/test/benchmark/WebsocketServerMemoryLeak.test.ts +1 -1
- package/test/benchmark/kademlia-simulation/KademliaSimulation.ts +8 -8
- package/test/benchmark/kademlia-simulation/SimulationNode.ts +8 -8
- package/test/end-to-end/Layer0-Layer1.test.ts +1 -1
- package/test/end-to-end/Layer0.test.ts +4 -4
- package/test/end-to-end/Layer0MixedConnectionTypes.test.ts +12 -12
- package/test/end-to-end/Layer0Webrtc-Layer1.test.ts +18 -18
- package/test/end-to-end/Layer0Webrtc.test.ts +13 -10
- package/test/end-to-end/Layer1-Scale-WebSocket.test.ts +2 -2
- package/test/end-to-end/Layer1-Scale-Webrtc.test.ts +2 -2
- package/test/end-to-end/RecoveryFromFailedAutoCertification.test.ts +1 -1
- package/test/end-to-end/WebsocketConnectionRequest.test.ts +3 -3
- package/test/end-to-end/memory-leak.test.ts +2 -2
- package/test/integration/ConnectionLocking.test.ts +60 -47
- package/test/integration/ConnectionManager.test.ts +8 -7
- package/test/integration/DhtJoinPeerDiscovery.test.ts +2 -2
- package/test/integration/DhtNodeExternalAPI.test.ts +1 -2
- package/test/integration/DhtNodeRpcRemote.test.ts +4 -3
- package/test/integration/DhtRpc.test.ts +4 -3
- package/test/integration/Find.test.ts +4 -6
- package/test/integration/Layer1-scale.test.ts +7 -7
- package/test/integration/Mock-Layer1-Layer0.test.ts +21 -24
- package/test/integration/MultipleEntryPointJoining.test.ts +7 -7
- package/test/integration/ReplicateData.test.ts +52 -161
- package/test/integration/RouteMessage.test.ts +24 -47
- package/test/integration/RouterRpcRemote.test.ts +7 -4
- package/test/integration/ScaleDownDht.test.ts +2 -3
- package/test/integration/SimultaneousConnections.test.ts +9 -8
- package/test/integration/Store.test.ts +1 -2
- package/test/integration/StoreAndDelete.test.ts +5 -0
- package/test/integration/StoreOnDhtWithThreeNodes.test.ts +59 -0
- package/test/integration/StoreOnDhtWithTwoNodes.test.ts +1 -1
- package/test/integration/StoreRpcRemote.test.ts +4 -4
- package/test/integration/WebrtcConnectionManagement.test.ts +6 -5
- package/test/integration/WebrtcConnectorRpc.test.ts +3 -2
- package/test/integration/WebsocketConnectionManagement.test.ts +27 -15
- package/test/integration/WebsocketConnectorRpc.test.ts +3 -2
- package/test/integration/{RpcErrors.test.ts → rpc-connections-over-webrpc.test.ts} +6 -3
- package/test/unit/DuplicateDetector.test.ts +2 -2
- package/test/unit/LocalDataStore.test.ts +1 -4
- package/test/unit/RandomContactList.test.ts +2 -4
- package/test/unit/RecursiveOperationManager.test.ts +5 -6
- package/test/unit/RecursiveOperationSession.test.ts +5 -4
- package/test/unit/Router.test.ts +25 -8
- package/test/unit/RoutingSession.test.ts +3 -3
- package/test/unit/SortedContactList.test.ts +2 -4
- package/test/unit/connectivityRequestHandler.test.ts +5 -3
- package/test/unit/createPeerDescriptor.test.ts +63 -0
- package/test/utils/FakeTransport.ts +7 -4
- package/test/utils/mock/Transport.ts +1 -1
- package/test/utils/utils.ts +6 -6
- package/dist/src/helpers/PeerID.d.ts +0 -27
- package/dist/src/helpers/PeerID.js +0 -87
- package/dist/src/helpers/PeerID.js.map +0 -1
- package/dist/src/helpers/UUID.d.ts +0 -8
- package/dist/src/helpers/UUID.js +0 -36
- package/dist/src/helpers/UUID.js.map +0 -1
- package/dist/src/helpers/peerIdFromPeerDescriptor.d.ts +0 -7
- package/dist/src/helpers/peerIdFromPeerDescriptor.js +0 -23
- package/dist/src/helpers/peerIdFromPeerDescriptor.js.map +0 -1
- package/src/helpers/PeerID.ts +0 -97
- package/src/helpers/UUID.ts +0 -35
- package/src/helpers/peerIdFromPeerDescriptor.ts +0 -20
- package/test/unit/PeerID.test.ts +0 -22
- package/test/unit/UUID.test.ts +0 -55
|
@@ -1,215 +1,106 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
2
|
import { LatencyType, Simulator } from '../../src/connection/simulator/Simulator'
|
|
3
3
|
import { DhtNode } from '../../src/dht/DhtNode'
|
|
4
|
-
import { NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
5
4
|
import { createMockConnectionDhtNode, waitNodesReadyForTesting } from '../utils/utils'
|
|
6
|
-
import { execSync } from 'child_process'
|
|
7
|
-
import fs from 'fs'
|
|
8
|
-
import { Logger } from '@streamr/utils'
|
|
9
|
-
import { PeerID } from '../../src/helpers/PeerID'
|
|
10
|
-
import { keyFromPeerDescriptor, peerIdFromPeerDescriptor } from '../../src/helpers/peerIdFromPeerDescriptor'
|
|
11
5
|
import { SortedContactList } from '../../src/dht/contact/SortedContactList'
|
|
12
|
-
import {
|
|
13
|
-
import { DhtAddress, getDhtAddressFromRaw,
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
const logger = new Logger(module)
|
|
18
|
-
|
|
19
|
-
jest.setTimeout(60000)
|
|
6
|
+
import { createMockDataEntry, expectEqualData } from '../utils/mock/mockDataEntry'
|
|
7
|
+
import { DhtAddress, createRandomDhtAddress, getDhtAddressFromRaw, getNodeIdFromPeerDescriptor } from '../../src/identifiers'
|
|
8
|
+
import { sample } from 'lodash'
|
|
9
|
+
import { DataEntry, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
20
10
|
|
|
11
|
+
const DATA = createMockDataEntry()
|
|
21
12
|
const NUM_NODES = 100
|
|
22
13
|
const MAX_CONNECTIONS = 80
|
|
23
14
|
const K = 8
|
|
15
|
+
const ENTRY_POINT_INDEX = 0
|
|
16
|
+
|
|
17
|
+
const getDataEntries = (node: DhtNode): DataEntry[] => {
|
|
18
|
+
// @ts-expect-error private field
|
|
19
|
+
const store = node.localDataStore
|
|
20
|
+
return Array.from(store.values(getDhtAddressFromRaw(DATA.key)))
|
|
21
|
+
}
|
|
24
22
|
|
|
25
23
|
describe('Replicate data from node to node in DHT', () => {
|
|
26
24
|
|
|
27
|
-
let entryPoint: DhtNode
|
|
28
25
|
let nodes: DhtNode[]
|
|
29
|
-
let
|
|
26
|
+
let entryPointDescriptor: PeerDescriptor
|
|
30
27
|
const simulator = new Simulator(LatencyType.FIXED, 20)
|
|
31
|
-
const nodesById: Map<DhtAddress, DhtNode> = new Map()
|
|
32
|
-
|
|
33
|
-
if (!fs.existsSync('test/data/nodeids.json')) {
|
|
34
|
-
console.log('ground truth data does not exist yet, generating..')
|
|
35
|
-
execSync('npm run prepare-kademlia-simulation')
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const dhtIds: Array<{ type: string, data: Array<number> }> = JSON.parse(fs.readFileSync('test/data/nodeids.json').toString())
|
|
39
|
-
/*
|
|
40
|
-
const getRandomNode = () => {
|
|
41
|
-
return nodes[Math.floor(Math.random() * nodes.length)]
|
|
42
|
-
}
|
|
43
|
-
*/
|
|
44
|
-
|
|
45
|
-
const getEntries = (key: DhtAddress, localDataStore: LocalDataStore) => {
|
|
46
|
-
return Array.from(localDataStore.values(key))
|
|
47
|
-
}
|
|
48
28
|
|
|
49
29
|
beforeEach(async () => {
|
|
30
|
+
const entryPoint = await createMockConnectionDhtNode(simulator, createRandomDhtAddress(), K, MAX_CONNECTIONS)
|
|
31
|
+
entryPointDescriptor = entryPoint.getLocalPeerDescriptor()
|
|
32
|
+
await entryPoint.joinDht([entryPointDescriptor])
|
|
50
33
|
nodes = []
|
|
51
|
-
entryPoint = await createMockConnectionDhtNode(simulator,
|
|
52
|
-
getDhtAddressFromRaw(Uint8Array.from(dhtIds[0].data)), K, MAX_CONNECTIONS)
|
|
53
34
|
nodes.push(entryPoint)
|
|
54
|
-
nodesById.set(entryPoint.getNodeId(), entryPoint)
|
|
55
|
-
|
|
56
|
-
entrypointDescriptor = {
|
|
57
|
-
nodeId: getRawFromDhtAddress(entryPoint.getNodeId()),
|
|
58
|
-
type: NodeType.NODEJS
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
nodes.push(entryPoint)
|
|
62
|
-
|
|
63
35
|
for (let i = 1; i < NUM_NODES; i++) {
|
|
64
|
-
const node = await createMockConnectionDhtNode(
|
|
65
|
-
|
|
66
|
-
|
|
36
|
+
const node = await createMockConnectionDhtNode(
|
|
37
|
+
simulator,
|
|
38
|
+
createRandomDhtAddress(),
|
|
39
|
+
K,
|
|
40
|
+
MAX_CONNECTIONS
|
|
41
|
+
)
|
|
67
42
|
nodes.push(node)
|
|
68
43
|
}
|
|
69
|
-
})
|
|
44
|
+
}, 60000)
|
|
70
45
|
|
|
71
46
|
afterEach(async () => {
|
|
72
|
-
await Promise.all(
|
|
73
|
-
|
|
74
|
-
])
|
|
75
|
-
logger.info('nodes stopped')
|
|
76
|
-
})
|
|
47
|
+
await Promise.all(nodes.map(async (node) => await node.stop()))
|
|
48
|
+
}, 60000)
|
|
77
49
|
|
|
78
50
|
afterAll(async () => {
|
|
79
51
|
simulator.stop()
|
|
80
52
|
})
|
|
81
53
|
|
|
82
54
|
it('Data replicates to the closest node no matter where it is stored', async () => {
|
|
83
|
-
const dataKey = getDhtAddressFromRaw(PeerID.fromString('3232323e12r31r3').value)
|
|
84
|
-
const data = createMockDataEntry({ key: dataKey })
|
|
85
|
-
|
|
86
55
|
// calculate offline which node is closest to the data
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
referenceId: dataKey,
|
|
56
|
+
const sortedList = new SortedContactList<DhtNode>({
|
|
57
|
+
referenceId: getDhtAddressFromRaw(DATA.key),
|
|
90
58
|
maxSize: 10000,
|
|
91
59
|
allowToContainReferenceId: true,
|
|
92
60
|
emitEvents: false
|
|
93
61
|
})
|
|
94
|
-
|
|
95
|
-
nodes.forEach((node) => {
|
|
96
|
-
sortedList.addContact(new Contact(node.getLocalPeerDescriptor())
|
|
97
|
-
)
|
|
98
|
-
})
|
|
62
|
+
nodes.forEach((node) => sortedList.addContact(node))
|
|
99
63
|
|
|
100
64
|
const closest = sortedList.getAllContacts()
|
|
101
|
-
|
|
102
|
-
logger.info('Nodes sorted according to distance to data are: ')
|
|
103
|
-
closest.forEach((contact) => {
|
|
104
|
-
logger.info(contact.getNodeId())
|
|
105
|
-
})
|
|
106
|
-
|
|
107
|
-
logger.info('node 0 joining to the DHT')
|
|
108
|
-
|
|
109
|
-
await nodes[0].joinDht([entrypointDescriptor])
|
|
110
|
-
|
|
111
|
-
logger.info('storing data to node 0')
|
|
112
|
-
const successfulStorers = await nodes[0].storeDataToDht(dataKey, data.data!)
|
|
65
|
+
const successfulStorers = await nodes[0].storeDataToDht(getDhtAddressFromRaw(DATA.key), DATA.data!)
|
|
113
66
|
expect(successfulStorers.length).toBe(1)
|
|
114
|
-
logger.info('data successfully stored to node 0')
|
|
115
|
-
|
|
116
|
-
logger.info('Nodes sorted according to distance to data with storing nodes marked are: ')
|
|
117
67
|
|
|
118
|
-
closest.forEach((contact) => {
|
|
119
|
-
const node = nodesById.get(contact.getNodeId())!
|
|
120
|
-
let hasDataMarker = ''
|
|
121
|
-
|
|
122
|
-
// @ts-expect-error private field
|
|
123
|
-
const store = node.localDataStore
|
|
124
|
-
if (getEntries(dataKey, store).length > 0) {
|
|
125
|
-
hasDataMarker = '<-'
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// eslint-disable-next-line max-len
|
|
129
|
-
logger.info(peerIdFromPeerDescriptor(contact.getPeerDescriptor()) + ' ' + node.getNodeId() + hasDataMarker)
|
|
130
|
-
})
|
|
131
|
-
|
|
132
|
-
logger.info(NUM_NODES + ' nodes joining layer0 DHT')
|
|
133
68
|
await Promise.all(
|
|
134
|
-
nodes.map((node) => {
|
|
135
|
-
if (
|
|
136
|
-
node.joinDht([
|
|
69
|
+
nodes.map(async (node, i) => {
|
|
70
|
+
if (i !== ENTRY_POINT_INDEX) {
|
|
71
|
+
await node.joinDht([entryPointDescriptor])
|
|
137
72
|
}
|
|
138
73
|
})
|
|
139
74
|
)
|
|
140
|
-
|
|
141
|
-
logger.info('completed ' + NUM_NODES + ' nodes joining layer0 DHT')
|
|
142
|
-
|
|
143
75
|
await waitNodesReadyForTesting(nodes)
|
|
144
76
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
const node = nodesById.get(contact.getNodeId())!
|
|
149
|
-
let hasDataMarker = ''
|
|
150
|
-
|
|
151
|
-
// @ts-expect-error private field
|
|
152
|
-
const store = node.localDataStore
|
|
153
|
-
if (getEntries(dataKey, store).length > 0) {
|
|
154
|
-
hasDataMarker = '<-'
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
logger.info(node.getNodeId() + hasDataMarker)
|
|
158
|
-
})
|
|
159
|
-
|
|
160
|
-
const closestNode = nodesById.get(closest[0].getNodeId())!
|
|
161
|
-
|
|
162
|
-
// @ts-expect-error private field
|
|
163
|
-
const store = closestNode.localDataStore
|
|
164
|
-
expect(getEntries(dataKey, store).length).toBeGreaterThanOrEqual(1)
|
|
77
|
+
const data = getDataEntries(closest[0])
|
|
78
|
+
expect(data).toHaveLength(1)
|
|
79
|
+
expectEqualData(data[0], DATA)
|
|
165
80
|
}, 180000)
|
|
166
81
|
|
|
167
|
-
it('Data replicates to the
|
|
168
|
-
const dataKey = getDhtAddressFromRaw(PeerID.fromString('3232323e12r31r3').value)
|
|
169
|
-
const data = createMockDataEntry({ key: dataKey })
|
|
170
|
-
|
|
171
|
-
logger.info(NUM_NODES + ' nodes joining layer0 DHT')
|
|
82
|
+
it('Data replicates to the other nodes when storers are stopped', async () => {
|
|
172
83
|
await Promise.all(
|
|
173
|
-
nodes.map((node) => {
|
|
174
|
-
|
|
84
|
+
nodes.map(async (node, i) => {
|
|
85
|
+
if (i !== ENTRY_POINT_INDEX) {
|
|
86
|
+
await node.joinDht([entryPointDescriptor])
|
|
87
|
+
}
|
|
175
88
|
})
|
|
176
89
|
)
|
|
177
|
-
|
|
178
|
-
logger.info('completed ' + NUM_NODES + ' nodes joining layer0 DHT')
|
|
179
|
-
|
|
180
90
|
await waitNodesReadyForTesting(nodes)
|
|
181
91
|
|
|
182
92
|
const randomIndex = Math.floor(Math.random() * nodes.length)
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
while (randomIndices.length > 1) {
|
|
196
|
-
const index = Math.floor(Math.random() * randomIndices.length)
|
|
197
|
-
const nodeIndex = randomIndices[index]
|
|
198
|
-
randomIndices.splice(index, 1)
|
|
199
|
-
// @ts-expect-error private field
|
|
200
|
-
const store = nodes[nodeIndex].localDataStore
|
|
201
|
-
logger.info('Stopping node ' + nodeIndex + ' ' +
|
|
202
|
-
((getEntries(dataKey, store).length > 0) ? ', has data' : ' does not have data'))
|
|
203
|
-
|
|
204
|
-
await nodes[nodeIndex].stop()
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
logger.info('after random graceful leaving, node ' + randomIndices[0] + ' is left')
|
|
208
|
-
|
|
209
|
-
// @ts-expect-error private field
|
|
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)
|
|
213
|
-
|
|
93
|
+
const storerDescriptors = await nodes[randomIndex].storeDataToDht(getDhtAddressFromRaw(DATA.key), DATA.data!)
|
|
94
|
+
const stoppedNodeIds: DhtAddress[] = []
|
|
95
|
+
await Promise.all(storerDescriptors.map(async (storerDescriptor) => {
|
|
96
|
+
const storer = nodes.find((n) => n.getNodeId() === getNodeIdFromPeerDescriptor(storerDescriptor))!
|
|
97
|
+
await storer.stop()
|
|
98
|
+
stoppedNodeIds.push(storer.getNodeId())
|
|
99
|
+
}))
|
|
100
|
+
|
|
101
|
+
const randomNonStoppedNode = sample(nodes.filter((n) => !stoppedNodeIds.includes(n.getNodeId())))!
|
|
102
|
+
const data = await randomNonStoppedNode.getDataFromDht(getDhtAddressFromRaw(DATA.key))
|
|
103
|
+
expect(data).toHaveLength(1)
|
|
104
|
+
expectEqualData(data[0], DATA)
|
|
214
105
|
}, 180000)
|
|
215
106
|
})
|
|
@@ -3,20 +3,14 @@ import { Message, MessageType, NodeType, PeerDescriptor, RouteMessageWrapper } f
|
|
|
3
3
|
import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
|
|
4
4
|
import { Logger, runAndWaitForEvents3, waitForCondition } from '@streamr/utils'
|
|
5
5
|
import { createMockConnectionDhtNode, createWrappedClosestPeersRequest } from '../utils/utils'
|
|
6
|
-
import { PeerID, PeerIDKey } from '../../src/helpers/PeerID'
|
|
7
6
|
import { Simulator } from '../../src/connection/simulator/Simulator'
|
|
8
7
|
import { v4 } from 'uuid'
|
|
9
8
|
import { Any } from '../../src/proto/google/protobuf/any'
|
|
10
9
|
import { RoutingMode } from '../../src/dht/routing/RoutingSession'
|
|
11
|
-
import {
|
|
10
|
+
import { DhtAddress, createRandomDhtAddress, getRawFromDhtAddress } from '../../src/identifiers'
|
|
12
11
|
|
|
13
12
|
const logger = new Logger(module)
|
|
14
13
|
|
|
15
|
-
// TODO refactor the test to not to use PeerID
|
|
16
|
-
const getPeerId = (node: DhtNode) => {
|
|
17
|
-
return PeerID.fromValue(getRawFromDhtAddress(node.getNodeId()))
|
|
18
|
-
}
|
|
19
|
-
|
|
20
14
|
const NUM_NODES = 30
|
|
21
15
|
|
|
22
16
|
describe('Route Message With Mock Connections', () => {
|
|
@@ -27,7 +21,6 @@ describe('Route Message With Mock Connections', () => {
|
|
|
27
21
|
let routerNodes: DhtNode[]
|
|
28
22
|
let simulator: Simulator
|
|
29
23
|
let entryPointDescriptor: PeerDescriptor
|
|
30
|
-
const receiveMatrix: Array<Array<number>> = []
|
|
31
24
|
|
|
32
25
|
beforeEach(async () => {
|
|
33
26
|
routerNodes = []
|
|
@@ -43,7 +36,7 @@ describe('Route Message With Mock Connections', () => {
|
|
|
43
36
|
destinationNode = await createMockConnectionDhtNode(simulator, createRandomDhtAddress())
|
|
44
37
|
|
|
45
38
|
for (let i = 1; i < NUM_NODES; i++) {
|
|
46
|
-
const node = await createMockConnectionDhtNode(simulator,
|
|
39
|
+
const node = await createMockConnectionDhtNode(simulator, createRandomDhtAddress())
|
|
47
40
|
routerNodes.push(node)
|
|
48
41
|
}
|
|
49
42
|
|
|
@@ -87,21 +80,21 @@ describe('Route Message With Mock Connections', () => {
|
|
|
87
80
|
requestId: v4(),
|
|
88
81
|
sourcePeer: sourceNode.getLocalPeerDescriptor(),
|
|
89
82
|
reachableThrough: [],
|
|
90
|
-
routingPath: []
|
|
91
|
-
|
|
83
|
+
routingPath: [],
|
|
84
|
+
parallelRootNodeIds: []
|
|
92
85
|
})
|
|
93
86
|
}], [[destinationNode, 'message']], 20000)
|
|
94
87
|
}, 30000)
|
|
95
88
|
|
|
96
89
|
it('Receives multiple messages', async () => {
|
|
97
|
-
const
|
|
90
|
+
const messageCount = 20
|
|
98
91
|
let receivedMessages = 0
|
|
99
92
|
destinationNode.on('message', () => {
|
|
100
93
|
receivedMessages += 1
|
|
101
94
|
})
|
|
102
95
|
const rpcWrapper = createWrappedClosestPeersRequest(sourceNode.getLocalPeerDescriptor())
|
|
103
96
|
|
|
104
|
-
for (let i = 0; i <
|
|
97
|
+
for (let i = 0; i < messageCount; i++) {
|
|
105
98
|
const message: Message = {
|
|
106
99
|
serviceId: 'unknown',
|
|
107
100
|
messageId: v4(),
|
|
@@ -119,40 +112,22 @@ describe('Route Message With Mock Connections', () => {
|
|
|
119
112
|
requestId: v4(),
|
|
120
113
|
sourcePeer: sourceNode.getLocalPeerDescriptor(),
|
|
121
114
|
reachableThrough: [],
|
|
122
|
-
routingPath: []
|
|
115
|
+
routingPath: [],
|
|
116
|
+
parallelRootNodeIds: []
|
|
123
117
|
})
|
|
124
118
|
}
|
|
125
|
-
await waitForCondition(() => receivedMessages ===
|
|
119
|
+
await waitForCondition(() => receivedMessages === messageCount)
|
|
126
120
|
})
|
|
127
121
|
|
|
128
122
|
it('From all to all', async () => {
|
|
129
|
-
|
|
130
|
-
for (const i in routerNodes) {
|
|
131
|
-
const arr: Array<number> = []
|
|
132
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
133
|
-
for (const j in routerNodes) {
|
|
134
|
-
arr.push(0)
|
|
135
|
-
}
|
|
136
|
-
receiveMatrix.push(arr)
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
const numsOfReceivedMessages: Record<PeerIDKey, number> = {}
|
|
123
|
+
const receivedMessageCounts: Record<DhtAddress, number> = {}
|
|
140
124
|
routerNodes.forEach((node) => {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
const target = receiveMatrix[parseInt(getPeerId(node).toString()) - 1]
|
|
146
|
-
target[parseInt(PeerID.fromValue(msg.sourceDescriptor!.nodeId).toString()) - 1]++
|
|
147
|
-
} catch (e) {
|
|
148
|
-
console.error(e)
|
|
149
|
-
}
|
|
150
|
-
if (parseInt(getPeerId(node).toString()) > routerNodes.length || parseInt(getPeerId(node).toString()) === 0) {
|
|
151
|
-
console.error(getPeerId(node).toString())
|
|
152
|
-
}
|
|
125
|
+
const key = node.getNodeId()
|
|
126
|
+
receivedMessageCounts[key] = 0
|
|
127
|
+
node.on('message', () => {
|
|
128
|
+
receivedMessageCounts[key] = receivedMessageCounts[key] + 1
|
|
153
129
|
})
|
|
154
|
-
}
|
|
155
|
-
)
|
|
130
|
+
})
|
|
156
131
|
await Promise.all(
|
|
157
132
|
routerNodes.map(async (node) =>
|
|
158
133
|
Promise.all(routerNodes.map(async (receiver) => {
|
|
@@ -175,17 +150,17 @@ describe('Route Message With Mock Connections', () => {
|
|
|
175
150
|
sourcePeer: node.getLocalPeerDescriptor(),
|
|
176
151
|
requestId: v4(),
|
|
177
152
|
reachableThrough: [],
|
|
178
|
-
routingPath: []
|
|
153
|
+
routingPath: [],
|
|
154
|
+
parallelRootNodeIds: []
|
|
179
155
|
})
|
|
180
156
|
}
|
|
181
157
|
}))
|
|
182
158
|
)
|
|
183
159
|
)
|
|
184
|
-
await waitForCondition(() =>
|
|
185
|
-
, 30000)
|
|
160
|
+
await waitForCondition(() => receivedMessageCounts[routerNodes[0].getNodeId()] >= routerNodes.length - 1, 30000)
|
|
186
161
|
await Promise.all(
|
|
187
|
-
Object.keys(
|
|
188
|
-
waitForCondition(() =>
|
|
162
|
+
Object.keys(receivedMessageCounts).map(async (key) =>
|
|
163
|
+
waitForCondition(() => receivedMessageCounts[key as DhtAddress] >= routerNodes.length - 1, 30000)
|
|
189
164
|
)
|
|
190
165
|
)
|
|
191
166
|
|
|
@@ -211,7 +186,8 @@ describe('Route Message With Mock Connections', () => {
|
|
|
211
186
|
requestId: v4(),
|
|
212
187
|
sourcePeer: sourceNode.getLocalPeerDescriptor(),
|
|
213
188
|
reachableThrough: [entryPointDescriptor],
|
|
214
|
-
routingPath: []
|
|
189
|
+
routingPath: [],
|
|
190
|
+
parallelRootNodeIds: []
|
|
215
191
|
}
|
|
216
192
|
|
|
217
193
|
const rpcMessage: RpcMessage = {
|
|
@@ -241,7 +217,8 @@ describe('Route Message With Mock Connections', () => {
|
|
|
241
217
|
sourcePeer: sourceNode.getLocalPeerDescriptor(),
|
|
242
218
|
target: entryPoint.getLocalPeerDescriptor()!.nodeId,
|
|
243
219
|
reachableThrough: [],
|
|
244
|
-
routingPath: []
|
|
220
|
+
routingPath: [],
|
|
221
|
+
parallelRootNodeIds: []
|
|
245
222
|
}
|
|
246
223
|
|
|
247
224
|
await runAndWaitForEvents3<DhtNodeEvents>([() => {
|
|
@@ -4,14 +4,15 @@ import { Message, MessageType, RouteMessageAck, RouteMessageWrapper } from '../.
|
|
|
4
4
|
import { RouterRpcClient } from '../../src/proto/packages/dht/protos/DhtRpc.client'
|
|
5
5
|
import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
|
|
6
6
|
import { createMockPeerDescriptor, createWrappedClosestPeersRequest, mockRouterRpc } from '../utils/utils'
|
|
7
|
+
import { DhtCallContext } from '../../src/rpc-protocol/DhtCallContext'
|
|
7
8
|
|
|
8
9
|
const SERVICE_ID = 'test'
|
|
9
10
|
|
|
10
11
|
describe('RemoteRouter', () => {
|
|
11
12
|
|
|
12
13
|
let remoteRouter: RouterRpcRemote
|
|
13
|
-
let clientRpcCommunicator: RpcCommunicator
|
|
14
|
-
let serverRpcCommunicator: RpcCommunicator
|
|
14
|
+
let clientRpcCommunicator: RpcCommunicator<DhtCallContext>
|
|
15
|
+
let serverRpcCommunicator: RpcCommunicator<DhtCallContext>
|
|
15
16
|
const clientPeerDescriptor = createMockPeerDescriptor()
|
|
16
17
|
const serverPeerDescriptor = createMockPeerDescriptor()
|
|
17
18
|
|
|
@@ -45,7 +46,8 @@ describe('RemoteRouter', () => {
|
|
|
45
46
|
sourcePeer: clientPeerDescriptor,
|
|
46
47
|
target: serverPeerDescriptor.nodeId,
|
|
47
48
|
reachableThrough: [],
|
|
48
|
-
routingPath: []
|
|
49
|
+
routingPath: [],
|
|
50
|
+
parallelRootNodeIds: []
|
|
49
51
|
})
|
|
50
52
|
expect(routable).toEqual(true)
|
|
51
53
|
})
|
|
@@ -68,7 +70,8 @@ describe('RemoteRouter', () => {
|
|
|
68
70
|
sourcePeer: clientPeerDescriptor,
|
|
69
71
|
target: serverPeerDescriptor.nodeId,
|
|
70
72
|
reachableThrough: [],
|
|
71
|
-
routingPath: []
|
|
73
|
+
routingPath: [],
|
|
74
|
+
parallelRootNodeIds: []
|
|
72
75
|
})
|
|
73
76
|
expect(routable).toEqual(false)
|
|
74
77
|
})
|
|
@@ -2,10 +2,9 @@ import { LatencyType, Simulator } from '../../src/connection/simulator/Simulator
|
|
|
2
2
|
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
|
-
import { areEqualPeerDescriptors, getNodeIdFromPeerDescriptor } from '../../src/helpers/peerIdFromPeerDescriptor'
|
|
6
5
|
import { Logger } from '@streamr/utils'
|
|
7
6
|
import { getRandomRegion } from '../../src/connection/simulator/pings'
|
|
8
|
-
import { createRandomDhtAddress, getRawFromDhtAddress } from '../../src/identifiers'
|
|
7
|
+
import { areEqualPeerDescriptors, createRandomDhtAddress, getNodeIdFromPeerDescriptor, getRawFromDhtAddress } from '../../src/identifiers'
|
|
9
8
|
|
|
10
9
|
const logger = new Logger(module)
|
|
11
10
|
|
|
@@ -55,7 +54,7 @@ describe('Scaling down a Dht network', () => {
|
|
|
55
54
|
const stoppingPeerDescriptor = nodes[nodeIndex].getLocalPeerDescriptor()
|
|
56
55
|
await nodes[nodeIndex].stop()
|
|
57
56
|
const nodeIsCleaned = nodes.every((node) =>
|
|
58
|
-
node.
|
|
57
|
+
node.getConnections().every((peer) => {
|
|
59
58
|
if (areEqualPeerDescriptors(peer, stoppingPeerDescriptor)) {
|
|
60
59
|
logger.error(getNodeIdFromPeerDescriptor(node.getLocalPeerDescriptor()) + ', '
|
|
61
60
|
+ getNodeIdFromPeerDescriptor(stoppingPeerDescriptor) + ' cleaning up failed')
|
|
@@ -8,6 +8,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
10
|
import { MockTransport } from '../utils/mock/Transport'
|
|
11
|
+
import { getNodeIdFromPeerDescriptor } from '../../src/identifiers'
|
|
11
12
|
|
|
12
13
|
const BASE_MESSAGE: Message = {
|
|
13
14
|
serviceId: 'serviceId',
|
|
@@ -78,8 +79,8 @@ describe('SimultaneousConnections', () => {
|
|
|
78
79
|
simTransport1.send(msg1),
|
|
79
80
|
simTransport2.send(msg2)
|
|
80
81
|
])
|
|
81
|
-
await waitForCondition(() => simTransport2.hasConnection(peerDescriptor1))
|
|
82
|
-
await waitForCondition(() => simTransport1.hasConnection(peerDescriptor2))
|
|
82
|
+
await waitForCondition(() => simTransport2.hasConnection(getNodeIdFromPeerDescriptor(peerDescriptor1)))
|
|
83
|
+
await waitForCondition(() => simTransport1.hasConnection(getNodeIdFromPeerDescriptor(peerDescriptor2)))
|
|
83
84
|
})
|
|
84
85
|
|
|
85
86
|
describe('Websocket 2 servers', () => {
|
|
@@ -159,8 +160,8 @@ describe('SimultaneousConnections', () => {
|
|
|
159
160
|
connectionManager2.send(msg2)
|
|
160
161
|
])
|
|
161
162
|
|
|
162
|
-
await waitForCondition(() => connectionManager1.hasConnection(wsPeerDescriptor2))
|
|
163
|
-
await waitForCondition(() => connectionManager2.hasConnection(wsPeerDescriptor1))
|
|
163
|
+
await waitForCondition(() => connectionManager1.hasConnection(getNodeIdFromPeerDescriptor(wsPeerDescriptor2)))
|
|
164
|
+
await waitForCondition(() => connectionManager2.hasConnection(getNodeIdFromPeerDescriptor(wsPeerDescriptor1)))
|
|
164
165
|
})
|
|
165
166
|
})
|
|
166
167
|
|
|
@@ -239,8 +240,8 @@ describe('SimultaneousConnections', () => {
|
|
|
239
240
|
connectionManager2.send(msg2)
|
|
240
241
|
])
|
|
241
242
|
|
|
242
|
-
await waitForCondition(() => connectionManager1.hasConnection(wsPeerDescriptor2))
|
|
243
|
-
await waitForCondition(() => connectionManager2.hasConnection(wsPeerDescriptor1))
|
|
243
|
+
await waitForCondition(() => connectionManager1.hasConnection(getNodeIdFromPeerDescriptor(wsPeerDescriptor2)))
|
|
244
|
+
await waitForCondition(() => connectionManager2.hasConnection(getNodeIdFromPeerDescriptor(wsPeerDescriptor1)))
|
|
244
245
|
})
|
|
245
246
|
})
|
|
246
247
|
|
|
@@ -307,8 +308,8 @@ describe('SimultaneousConnections', () => {
|
|
|
307
308
|
connectionManager2.send(msg2)
|
|
308
309
|
])
|
|
309
310
|
|
|
310
|
-
await waitForCondition(() => connectionManager1.hasConnection(wrtcPeerDescriptor2))
|
|
311
|
-
await waitForCondition(() => connectionManager2.hasConnection(wrtcPeerDescriptor1))
|
|
311
|
+
await waitForCondition(() => connectionManager1.hasConnection(getNodeIdFromPeerDescriptor(wrtcPeerDescriptor2)))
|
|
312
|
+
await waitForCondition(() => connectionManager2.hasConnection(getNodeIdFromPeerDescriptor(wrtcPeerDescriptor1)))
|
|
312
313
|
})
|
|
313
314
|
})
|
|
314
315
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { LatencyType, Simulator } from '../../src/connection/simulator/Simulator'
|
|
2
2
|
import { DhtNode } from '../../src/dht/DhtNode'
|
|
3
|
-
import { getDhtAddressFromRaw } from '../../src/identifiers'
|
|
4
|
-
import { getNodeIdFromPeerDescriptor } from '../../src/helpers/peerIdFromPeerDescriptor'
|
|
3
|
+
import { getDhtAddressFromRaw, getNodeIdFromPeerDescriptor } from '../../src/identifiers'
|
|
5
4
|
import { PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
6
5
|
import { createMockDataEntry, expectEqualData } from '../utils/mock/mockDataEntry'
|
|
7
6
|
import { createMockConnectionDhtNode, createMockPeerDescriptor, waitConnectionManagersReadyForTesting } from '../utils/utils'
|
|
@@ -4,6 +4,7 @@ import { createMockConnectionDhtNode, waitConnectionManagersReadyForTesting } fr
|
|
|
4
4
|
import { createMockDataEntry, expectEqualData } from '../utils/mock/mockDataEntry'
|
|
5
5
|
import { createRandomDhtAddress } from '../../src/identifiers'
|
|
6
6
|
import { getDhtAddressFromRaw } from '../../src/identifiers'
|
|
7
|
+
import { wait } from '@streamr/utils'
|
|
7
8
|
|
|
8
9
|
const NUM_NODES = 5
|
|
9
10
|
const MAX_CONNECTIONS = 5
|
|
@@ -42,6 +43,8 @@ describe('Storing data in DHT', () => {
|
|
|
42
43
|
const successfulStorers = await storingNode.storeDataToDht(getDhtAddressFromRaw(entry.key), entry.data!)
|
|
43
44
|
expect(successfulStorers.length).toBeGreaterThan(4)
|
|
44
45
|
await storingNode.deleteDataFromDht(getDhtAddressFromRaw(entry.key), true)
|
|
46
|
+
// Wait for the delete operation to propagate
|
|
47
|
+
await wait(500)
|
|
45
48
|
const fetchingNode = getRandomNode()
|
|
46
49
|
const results = await fetchingNode.getDataFromDht(getDhtAddressFromRaw(entry.key))
|
|
47
50
|
results.forEach((result) => {
|
|
@@ -56,6 +59,8 @@ describe('Storing data in DHT', () => {
|
|
|
56
59
|
const successfulStorers1 = await storingNode.storeDataToDht(getDhtAddressFromRaw(entry.key), entry.data!)
|
|
57
60
|
expect(successfulStorers1.length).toBeGreaterThan(4)
|
|
58
61
|
await storingNode.deleteDataFromDht(getDhtAddressFromRaw(entry.key), true)
|
|
62
|
+
// Wait for the delete operation to propagate
|
|
63
|
+
await wait(500)
|
|
59
64
|
const fetchingNode = getRandomNode()
|
|
60
65
|
const results1 = await fetchingNode.getDataFromDht(getDhtAddressFromRaw(entry.key))
|
|
61
66
|
results1.forEach((result) => {
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { createMockConnectionDhtNode } from '../utils/utils'
|
|
2
|
+
import { DhtNode } from '../../src/dht/DhtNode'
|
|
3
|
+
import { Simulator } from '../../src/connection/simulator/Simulator'
|
|
4
|
+
import { createMockDataEntry, expectEqualData } from '../utils/mock/mockDataEntry'
|
|
5
|
+
import { getDhtAddressFromRaw } from '../../src/identifiers'
|
|
6
|
+
|
|
7
|
+
describe('Storing data in DHT with two peers', () => {
|
|
8
|
+
|
|
9
|
+
let entryPoint: DhtNode
|
|
10
|
+
let node1: DhtNode
|
|
11
|
+
let node2: DhtNode
|
|
12
|
+
let simulator: Simulator | undefined
|
|
13
|
+
|
|
14
|
+
beforeEach(async () => {
|
|
15
|
+
simulator = new Simulator()
|
|
16
|
+
entryPoint = await createMockConnectionDhtNode(simulator)
|
|
17
|
+
node1 = await createMockConnectionDhtNode(simulator)
|
|
18
|
+
node2 = await createMockConnectionDhtNode(simulator)
|
|
19
|
+
|
|
20
|
+
await entryPoint.start()
|
|
21
|
+
await node1.start()
|
|
22
|
+
await node2.start()
|
|
23
|
+
|
|
24
|
+
await entryPoint.joinDht([entryPoint.getLocalPeerDescriptor()])
|
|
25
|
+
node1.joinDht([entryPoint.getLocalPeerDescriptor()]).catch(() => {})
|
|
26
|
+
node2.joinDht([entryPoint.getLocalPeerDescriptor()]).catch(() => {})
|
|
27
|
+
await Promise.all([
|
|
28
|
+
node1.waitForNetworkConnectivity(),
|
|
29
|
+
node2.waitForNetworkConnectivity()
|
|
30
|
+
])
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
afterEach(async () => {
|
|
34
|
+
await entryPoint.stop()
|
|
35
|
+
await node1.stop()
|
|
36
|
+
await node2.stop()
|
|
37
|
+
simulator?.stop()
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
it('Node can store on three peer DHT', async () => {
|
|
41
|
+
const storedData1 = createMockDataEntry()
|
|
42
|
+
const storedData2 = createMockDataEntry()
|
|
43
|
+
// Here we effectively test that fetching "null" data doesn't take too long. A test timeout here indicates an issue.
|
|
44
|
+
await node1.getDataFromDht(getDhtAddressFromRaw(storedData1.key))
|
|
45
|
+
await node2.getDataFromDht(getDhtAddressFromRaw(storedData1.key))
|
|
46
|
+
|
|
47
|
+
await node1.storeDataToDht(getDhtAddressFromRaw(storedData1.key), storedData1.data!)
|
|
48
|
+
await node2.storeDataToDht(getDhtAddressFromRaw(storedData1.key), storedData1.data!)
|
|
49
|
+
await entryPoint.storeDataToDht(getDhtAddressFromRaw(storedData2.key), storedData2.data!)
|
|
50
|
+
const foundData1 = await node1.getDataFromDht(getDhtAddressFromRaw(storedData1.key))
|
|
51
|
+
const foundData2 = await node2.getDataFromDht(getDhtAddressFromRaw(storedData1.key))
|
|
52
|
+
const foundData3 = await entryPoint.getDataFromDht(getDhtAddressFromRaw(storedData2.key))
|
|
53
|
+
expectEqualData(foundData1[0], storedData1)
|
|
54
|
+
expectEqualData(foundData1[1], storedData1)
|
|
55
|
+
expectEqualData(foundData2[0], storedData1)
|
|
56
|
+
expectEqualData(foundData2[1], storedData1)
|
|
57
|
+
expectEqualData(foundData3[0], storedData2)
|
|
58
|
+
}, 30000)
|
|
59
|
+
})
|
|
@@ -42,7 +42,7 @@ describe('Storing data in DHT with two peers', () => {
|
|
|
42
42
|
|
|
43
43
|
it('Can store on one peer DHT', async () => {
|
|
44
44
|
await otherNode.stop()
|
|
45
|
-
await waitForCondition(() => entryPoint.
|
|
45
|
+
await waitForCondition(() => entryPoint.getNeighborCount() === 0)
|
|
46
46
|
const storedData = createMockDataEntry()
|
|
47
47
|
await entryPoint.storeDataToDht(getDhtAddressFromRaw(storedData.key), storedData.data!)
|
|
48
48
|
const foundData = await entryPoint.getDataFromDht(getDhtAddressFromRaw(storedData.key))
|