@streamr/dht 100.0.0-testnet-one.4 → 100.0.0-testnet-two.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/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/ConnectionLockRpcLocal.js +4 -4
- package/dist/src/connection/ConnectionLockRpcLocal.js.map +1 -1
- package/dist/src/connection/ConnectionLockRpcRemote.d.ts +3 -5
- package/dist/src/connection/ConnectionLockRpcRemote.js +4 -7
- package/dist/src/connection/ConnectionLockRpcRemote.js.map +1 -1
- package/dist/src/connection/ConnectionManager.d.ts +4 -6
- package/dist/src/connection/ConnectionManager.js +48 -46
- package/dist/src/connection/ConnectionManager.js.map +1 -1
- package/dist/src/connection/ConnectorFacade.d.ts +2 -2
- package/dist/src/connection/ConnectorFacade.js +2 -1
- package/dist/src/connection/ConnectorFacade.js.map +1 -1
- package/dist/src/connection/ManagedConnection.d.ts +3 -6
- package/dist/src/connection/ManagedConnection.js +6 -10
- package/dist/src/connection/ManagedConnection.js.map +1 -1
- package/dist/src/connection/connectivityChecker.js +1 -0
- package/dist/src/connection/connectivityChecker.js.map +1 -1
- package/dist/src/connection/simulator/Simulator.d.ts +0 -3
- package/dist/src/connection/simulator/Simulator.js +3 -51
- package/dist/src/connection/simulator/Simulator.js.map +1 -1
- package/dist/src/connection/simulator/SimulatorConnector.js +5 -5
- package/dist/src/connection/simulator/SimulatorConnector.js.map +1 -1
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js +2 -2
- 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 +7 -9
- 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 -12
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.d.ts +2 -5
- package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.js +1 -4
- package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.js.map +1 -1
- package/dist/src/connection/websocket/AutoCertifierClientFacade.d.ts +1 -2
- package/dist/src/connection/websocket/AutoCertifierClientFacade.js +3 -4
- package/dist/src/connection/websocket/AutoCertifierClientFacade.js.map +1 -1
- package/dist/src/connection/websocket/ClientWebsocket.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnector.d.ts +2 -7
- package/dist/src/connection/websocket/WebsocketConnector.js +32 -38
- package/dist/src/connection/websocket/WebsocketConnector.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.d.ts +3 -2
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.js +8 -10
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.d.ts +3 -6
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.js +0 -3
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketServer.d.ts +1 -4
- package/dist/src/connection/websocket/WebsocketServer.js +11 -12
- package/dist/src/connection/websocket/WebsocketServer.js.map +1 -1
- package/dist/src/dht/DhtNode.d.ts +10 -13
- package/dist/src/dht/DhtNode.js +39 -52
- package/dist/src/dht/DhtNode.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcLocal.d.ts +0 -1
- package/dist/src/dht/DhtNodeRpcLocal.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcRemote.d.ts +7 -7
- package/dist/src/dht/DhtNodeRpcRemote.js +8 -7
- package/dist/src/dht/DhtNodeRpcRemote.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcLocal.d.ts +5 -4
- package/dist/src/dht/ExternalApiRpcLocal.js +3 -2
- package/dist/src/dht/ExternalApiRpcLocal.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcRemote.d.ts +2 -2
- package/dist/src/dht/ExternalApiRpcRemote.js +2 -0
- package/dist/src/dht/ExternalApiRpcRemote.js.map +1 -1
- package/dist/src/dht/PeerManager.d.ts +13 -14
- package/dist/src/dht/PeerManager.js +45 -60
- package/dist/src/dht/PeerManager.js.map +1 -1
- package/dist/src/dht/contact/Contact.d.ts +2 -2
- package/dist/src/dht/contact/Contact.js +2 -2
- package/dist/src/dht/contact/Contact.js.map +1 -1
- package/dist/src/dht/contact/ContactList.d.ts +7 -7
- package/dist/src/dht/contact/ContactList.js +3 -3
- 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 +12 -11
- package/dist/src/dht/contact/RandomContactList.js.map +1 -1
- package/dist/src/dht/contact/RpcRemote.d.ts +7 -4
- package/dist/src/dht/contact/RpcRemote.js +5 -2
- 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 +33 -29
- package/dist/src/dht/contact/SortedContactList.js.map +1 -1
- package/dist/src/dht/discovery/DiscoverySession.d.ts +2 -4
- package/dist/src/dht/discovery/DiscoverySession.js +19 -20
- package/dist/src/dht/discovery/DiscoverySession.js.map +1 -1
- package/dist/src/dht/discovery/PeerDiscovery.d.ts +2 -5
- package/dist/src/dht/discovery/PeerDiscovery.js +12 -20
- package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.d.ts +36 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.js +165 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.d.ts +14 -0
- package/dist/src/dht/{find/FindRpcLocal.js → recursive-operation/RecursiveOperationRpcLocal.js} +7 -7
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.d.ts +6 -0
- package/dist/src/dht/{routing/FindRpcRemote.js → recursive-operation/RecursiveOperationRpcRemote.js} +11 -11
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.d.ts +42 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.js +182 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.d.ts +12 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js +17 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.d.ts +6 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.js +21 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.js.map +1 -0
- package/dist/src/dht/routing/Router.d.ts +4 -19
- package/dist/src/dht/routing/Router.js +41 -33
- package/dist/src/dht/routing/Router.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcLocal.js +6 -5
- package/dist/src/dht/routing/RouterRpcLocal.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcRemote.d.ts +2 -2
- package/dist/src/dht/routing/RouterRpcRemote.js +7 -7
- package/dist/src/dht/routing/RouterRpcRemote.js.map +1 -1
- package/dist/src/dht/routing/RoutingSession.d.ts +20 -16
- package/dist/src/dht/routing/RoutingSession.js +37 -45
- package/dist/src/dht/routing/RoutingSession.js.map +1 -1
- package/dist/src/dht/store/LocalDataStore.d.ts +11 -13
- package/dist/src/dht/store/LocalDataStore.js +36 -56
- package/dist/src/dht/store/LocalDataStore.js.map +1 -1
- package/dist/src/dht/store/StoreManager.d.ts +33 -0
- package/dist/src/dht/store/StoreManager.js +186 -0
- package/dist/src/dht/store/StoreManager.js.map +1 -0
- package/dist/src/dht/store/StoreRpcLocal.d.ts +8 -40
- package/dist/src/dht/store/StoreRpcLocal.js +13 -229
- package/dist/src/dht/store/StoreRpcLocal.js.map +1 -1
- package/dist/src/dht/store/StoreRpcRemote.d.ts +5 -5
- package/dist/src/dht/store/StoreRpcRemote.js +4 -5
- package/dist/src/dht/store/StoreRpcRemote.js.map +1 -1
- package/dist/src/exports.d.ts +2 -0
- package/dist/src/exports.js.map +1 -1
- package/dist/src/helpers/MapWithTtl.d.ts +14 -0
- package/dist/src/helpers/MapWithTtl.js +59 -0
- package/dist/src/helpers/MapWithTtl.js.map +1 -0
- package/dist/src/helpers/PeerID.d.ts +2 -0
- package/dist/src/helpers/PeerID.js +4 -0
- package/dist/src/helpers/PeerID.js.map +1 -1
- package/dist/src/helpers/nodeId.d.ts +5 -0
- package/dist/src/helpers/nodeId.js +18 -1
- package/dist/src/helpers/nodeId.js.map +1 -1
- package/dist/src/helpers/peerIdFromPeerDescriptor.d.ts +2 -1
- package/dist/src/helpers/peerIdFromPeerDescriptor.js +2 -1
- package/dist/src/helpers/peerIdFromPeerDescriptor.js.map +1 -1
- package/dist/src/helpers/protoClasses.js +2 -3
- package/dist/src/helpers/protoClasses.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +21 -22
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +18 -18
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +36 -60
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +34 -53
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +11 -12
- package/dist/src/rpc-protocol/DhtCallContext.d.ts +2 -1
- package/dist/src/rpc-protocol/DhtCallContext.js.map +1 -1
- package/dist/src/rpc-protocol/DhtRpcOptions.d.ts +2 -1
- package/dist/src/transport/ITransport.d.ts +9 -1
- package/dist/src/transport/ITransport.js +5 -0
- package/dist/src/transport/ITransport.js.map +1 -1
- package/dist/src/transport/ListeningRpcCommunicator.js +1 -1
- package/dist/src/transport/ListeningRpcCommunicator.js.map +1 -1
- package/dist/src/transport/RoutingRpcCommunicator.d.ts +2 -1
- package/dist/src/transport/RoutingRpcCommunicator.js +16 -11
- package/dist/src/transport/RoutingRpcCommunicator.js.map +1 -1
- package/jest.config.js +4 -1
- package/karma-setup.js +2 -0
- package/karma.config.js +11 -7
- package/package.json +6 -7
- package/protos/DhtRpc.proto +17 -23
- package/src/connection/ConnectionLockHandler.ts +15 -15
- package/src/connection/ConnectionLockRpcLocal.ts +8 -9
- package/src/connection/ConnectionLockRpcRemote.ts +7 -16
- package/src/connection/ConnectionManager.ts +58 -55
- package/src/connection/ConnectorFacade.ts +3 -0
- package/src/connection/ManagedConnection.ts +12 -30
- package/src/connection/connectivityChecker.ts +1 -0
- package/src/connection/simulator/Simulator.ts +5 -36
- package/src/connection/simulator/SimulatorConnector.ts +8 -8
- package/src/connection/webrtc/BrowserWebrtcConnection.ts +0 -3
- package/src/connection/webrtc/NodeWebrtcConnection.ts +3 -4
- package/src/connection/webrtc/WebrtcConnector.ts +11 -13
- package/src/connection/webrtc/WebrtcConnectorRpcLocal.ts +16 -16
- package/src/connection/webrtc/WebrtcConnectorRpcRemote.ts +3 -13
- package/src/connection/websocket/AutoCertifierClientFacade.ts +4 -6
- package/src/connection/websocket/ClientWebsocket.ts +1 -0
- package/src/connection/websocket/WebsocketConnector.ts +43 -56
- package/src/connection/websocket/WebsocketConnectorRpcLocal.ts +11 -13
- package/src/connection/websocket/WebsocketConnectorRpcRemote.ts +4 -15
- package/src/connection/websocket/WebsocketServer.ts +14 -17
- package/src/dht/DhtNode.ts +67 -69
- package/src/dht/DhtNodeRpcLocal.ts +0 -1
- package/src/dht/DhtNodeRpcRemote.ts +13 -13
- package/src/dht/ExternalApiRpcLocal.ts +16 -6
- package/src/dht/ExternalApiRpcRemote.ts +5 -3
- package/src/dht/PeerManager.ts +73 -90
- package/src/dht/contact/Contact.ts +5 -4
- package/src/dht/contact/ContactList.ts +9 -9
- package/src/dht/contact/RandomContactList.ts +14 -14
- package/src/dht/contact/RpcRemote.ts +10 -7
- package/src/dht/contact/SortedContactList.ts +48 -45
- package/src/dht/discovery/DiscoverySession.ts +25 -25
- package/src/dht/discovery/PeerDiscovery.ts +16 -37
- package/src/dht/recursive-operation/RecursiveOperationManager.ts +240 -0
- package/src/dht/{find/FindRpcLocal.ts → recursive-operation/RecursiveOperationRpcLocal.ts} +9 -9
- package/src/dht/{routing/FindRpcRemote.ts → recursive-operation/RecursiveOperationRpcRemote.ts} +10 -10
- package/src/dht/recursive-operation/RecursiveOperationSession.ts +224 -0
- package/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.ts +25 -0
- package/src/dht/{find/FindSessionRpcRemote.ts → recursive-operation/RecursiveOperationSessionRpcRemote.ts} +8 -8
- package/src/dht/routing/Router.ts +45 -64
- package/src/dht/routing/RouterRpcLocal.ts +7 -6
- package/src/dht/routing/RouterRpcRemote.ts +9 -10
- package/src/dht/routing/RoutingSession.ts +59 -68
- package/src/dht/store/LocalDataStore.ts +47 -66
- package/src/dht/store/StoreManager.ts +217 -0
- package/src/dht/store/StoreRpcLocal.ts +26 -302
- package/src/dht/store/StoreRpcRemote.ts +9 -11
- package/src/exports.ts +2 -0
- package/src/helpers/MapWithTtl.ts +71 -0
- package/src/helpers/PeerID.ts +5 -0
- package/src/helpers/nodeId.ts +20 -0
- package/src/helpers/peerIdFromPeerDescriptor.ts +5 -3
- package/src/helpers/protoClasses.ts +4 -6
- package/src/proto/packages/dht/protos/DhtRpc.client.ts +31 -32
- package/src/proto/packages/dht/protos/DhtRpc.server.ts +11 -12
- package/src/proto/packages/dht/protos/DhtRpc.ts +49 -80
- package/src/rpc-protocol/DhtCallContext.ts +2 -1
- package/src/rpc-protocol/DhtRpcOptions.ts +2 -1
- package/src/transport/ITransport.ts +10 -1
- package/src/transport/ListeningRpcCommunicator.ts +1 -1
- package/src/transport/RoutingRpcCommunicator.ts +18 -12
- package/test/benchmark/Find.test.ts +8 -21
- package/test/benchmark/KademliaCorrectness.test.ts +11 -20
- package/test/benchmark/SortedContactListBenchmark.test.ts +9 -9
- package/test/benchmark/kademlia-simulation/Contact.ts +9 -8
- package/test/benchmark/kademlia-simulation/KademliaSimulation.ts +2 -2
- package/test/benchmark/kademlia-simulation/SimulationNode.ts +17 -17
- package/test/end-to-end/Layer0-Layer1.test.ts +10 -14
- package/test/end-to-end/Layer0.test.ts +15 -18
- package/test/end-to-end/Layer0MixedConnectionTypes.test.ts +7 -9
- package/test/end-to-end/Layer0Webrtc-Layer1.test.ts +4 -10
- package/test/end-to-end/Layer0Webrtc.test.ts +5 -6
- package/test/end-to-end/Layer1-Scale-WebSocket.test.ts +8 -16
- package/test/end-to-end/Layer1-Scale-Webrtc.test.ts +6 -13
- package/test/end-to-end/WebsocketConnectionRequest.test.ts +5 -6
- package/test/end-to-end/memory-leak.test.ts +6 -8
- package/test/integration/ConnectionLocking.test.ts +6 -13
- package/test/integration/ConnectionManager.test.ts +26 -43
- package/test/integration/DhtJoinPeerDiscovery.test.ts +5 -10
- package/test/integration/DhtNodeExternalAPI.test.ts +16 -22
- package/test/integration/DhtNodeRpcRemote.test.ts +13 -22
- package/test/integration/DhtRpc.test.ts +13 -18
- package/test/integration/Find.test.ts +10 -10
- package/test/integration/Layer1-scale.test.ts +17 -28
- package/test/integration/Mock-Layer1-Layer0.test.ts +25 -43
- package/test/integration/MultipleEntryPointJoining.test.ts +7 -7
- package/test/integration/ReplicateData.test.ts +28 -30
- package/test/integration/RouteMessage.test.ts +30 -27
- package/test/integration/RouterRpcRemote.test.ts +12 -18
- package/test/integration/RpcErrors.test.ts +8 -21
- package/test/integration/ScaleDownDht.test.ts +11 -10
- package/test/integration/SimultaneousConnections.test.ts +43 -67
- package/test/integration/Store.test.ts +23 -36
- package/test/integration/StoreAndDelete.test.ts +30 -50
- package/test/integration/StoreOnDhtWithTwoNodes.test.ts +16 -37
- package/test/integration/StoreRpcRemote.test.ts +20 -30
- package/test/integration/WebrtcConnectionManagement.test.ts +3 -13
- package/test/integration/WebrtcConnectorRpc.test.ts +3 -9
- package/test/integration/WebsocketConnectionManagement.test.ts +7 -10
- package/test/integration/WebsocketConnectorRpc.test.ts +8 -17
- package/test/unit/ConnectivityHelpers.test.ts +9 -17
- package/test/unit/DuplicateDetector.test.ts +7 -4
- package/test/unit/LocalDataStore.test.ts +66 -77
- package/test/unit/PeerManager.test.ts +31 -0
- package/test/unit/RandomContactList.test.ts +13 -8
- package/test/unit/{Finder.test.ts → RecursiveOperationManager.test.ts} +38 -43
- package/test/unit/RecursiveOperationSession.test.ts +68 -0
- package/test/unit/Router.test.ts +15 -22
- package/test/unit/RoutingSession.test.ts +23 -25
- package/test/unit/SortedContactList.test.ts +41 -26
- package/test/unit/StoreManager.test.ts +132 -0
- package/test/unit/WebsocketConnector.test.ts +27 -35
- package/test/unit/customMatchers.test.ts +16 -0
- package/test/utils/FakeTransport.ts +44 -0
- package/test/utils/customMatchers.ts +70 -0
- package/test/utils/mock/MockRpcCommunicator.ts +7 -0
- package/test/utils/mock/Router.ts +3 -2
- package/test/utils/mock/mockDataEntry.ts +36 -0
- package/test/utils/utils.ts +49 -87
- package/dist/src/dht/find/FindRpcLocal.d.ts +0 -14
- package/dist/src/dht/find/FindRpcLocal.js.map +0 -1
- package/dist/src/dht/find/FindSession.d.ts +0 -44
- package/dist/src/dht/find/FindSession.js +0 -150
- package/dist/src/dht/find/FindSession.js.map +0 -1
- package/dist/src/dht/find/FindSessionRpcLocal.d.ts +0 -12
- package/dist/src/dht/find/FindSessionRpcLocal.js +0 -17
- package/dist/src/dht/find/FindSessionRpcLocal.js.map +0 -1
- package/dist/src/dht/find/FindSessionRpcRemote.d.ts +0 -6
- package/dist/src/dht/find/FindSessionRpcRemote.js +0 -21
- package/dist/src/dht/find/FindSessionRpcRemote.js.map +0 -1
- package/dist/src/dht/find/Finder.d.ts +0 -49
- package/dist/src/dht/find/Finder.js +0 -197
- package/dist/src/dht/find/Finder.js.map +0 -1
- package/dist/src/dht/routing/FindRpcRemote.d.ts +0 -6
- package/dist/src/dht/routing/FindRpcRemote.js.map +0 -1
- package/src/dht/find/FindSession.ts +0 -183
- package/src/dht/find/FindSessionRpcLocal.ts +0 -25
- package/src/dht/find/Finder.ts +0 -295
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { wait, waitForCondition } from '@streamr/utils'
|
|
2
|
+
import crypto from 'crypto'
|
|
3
|
+
import { range, sortBy } from 'lodash'
|
|
4
|
+
import { Key } from 'readline'
|
|
5
|
+
import { getDistance } from '../../src/dht/PeerManager'
|
|
6
|
+
import { StoreManager } from '../../src/dht/store/StoreManager'
|
|
7
|
+
import { NodeID, createRandomNodeId, getNodeIdFromBinary } from '../../src/helpers/nodeId'
|
|
8
|
+
import { NodeType, ReplicateDataRequest } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
9
|
+
|
|
10
|
+
const DATA_ENTRY = {
|
|
11
|
+
key: createRandomNodeId(),
|
|
12
|
+
creator: crypto.randomBytes(20)
|
|
13
|
+
}
|
|
14
|
+
const NODES_CLOSEST_TO_DATA = sortBy(
|
|
15
|
+
range(5).map(() => createRandomNodeId()),
|
|
16
|
+
(id: Uint8Array) => getDistance(getNodeIdFromBinary(id), getNodeIdFromBinary(DATA_ENTRY.key))
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
describe('StoreManager', () => {
|
|
20
|
+
|
|
21
|
+
describe('new contact', () => {
|
|
22
|
+
|
|
23
|
+
const createStoreManager = (
|
|
24
|
+
localNodeId: Uint8Array,
|
|
25
|
+
closestNeighbors: Uint8Array[],
|
|
26
|
+
replicateData: (request: ReplicateDataRequest) => unknown,
|
|
27
|
+
setStale: (key: Key, creator: NodeID, stale: boolean) => unknown
|
|
28
|
+
): StoreManager => {
|
|
29
|
+
const getClosestNeighborsTo = () => {
|
|
30
|
+
return closestNeighbors.map((nodeId) => ({ nodeId, type: NodeType.NODEJS }))
|
|
31
|
+
}
|
|
32
|
+
return new StoreManager({
|
|
33
|
+
rpcCommunicator: {
|
|
34
|
+
registerRpcMethod: () => {},
|
|
35
|
+
registerRpcNotification: () => {}
|
|
36
|
+
} as any,
|
|
37
|
+
recursiveOperationManager: undefined as any,
|
|
38
|
+
localPeerDescriptor: { nodeId: localNodeId, type: NodeType.NODEJS },
|
|
39
|
+
localDataStore: { values: () => [DATA_ENTRY], setStale } as any,
|
|
40
|
+
serviceId: undefined as any,
|
|
41
|
+
highestTtl: undefined as any,
|
|
42
|
+
redundancyFactor: 3,
|
|
43
|
+
getClosestNeighborsTo,
|
|
44
|
+
createRpcRemote: () => ({ replicateData } as any)
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
describe('this node is primary storer', () => {
|
|
49
|
+
|
|
50
|
+
it('new node is within redundancy factor', async () => {
|
|
51
|
+
const replicateData = jest.fn<undefined, [ReplicateDataRequest]>()
|
|
52
|
+
const setStale = jest.fn<undefined, [Key, NodeID]>()
|
|
53
|
+
const manager = createStoreManager(
|
|
54
|
+
NODES_CLOSEST_TO_DATA[0],
|
|
55
|
+
[NODES_CLOSEST_TO_DATA[1], NODES_CLOSEST_TO_DATA[3], NODES_CLOSEST_TO_DATA[4]],
|
|
56
|
+
replicateData,
|
|
57
|
+
setStale
|
|
58
|
+
)
|
|
59
|
+
manager.onNewContact({ nodeId: NODES_CLOSEST_TO_DATA[2], type: NodeType.NODEJS })
|
|
60
|
+
await waitForCondition(() => replicateData.mock.calls.length === 1)
|
|
61
|
+
expect(replicateData).toHaveBeenCalledWith({
|
|
62
|
+
entry: DATA_ENTRY
|
|
63
|
+
})
|
|
64
|
+
expect(setStale).not.toHaveBeenCalled()
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
it('new node is not within redundancy factor', async () => {
|
|
68
|
+
const replicateData = jest.fn<undefined, [ReplicateDataRequest]>()
|
|
69
|
+
const setStale = jest.fn<undefined, [Key, NodeID]>()
|
|
70
|
+
const manager = createStoreManager(
|
|
71
|
+
NODES_CLOSEST_TO_DATA[0],
|
|
72
|
+
[NODES_CLOSEST_TO_DATA[1], NODES_CLOSEST_TO_DATA[2], NODES_CLOSEST_TO_DATA[3]],
|
|
73
|
+
replicateData,
|
|
74
|
+
setStale
|
|
75
|
+
)
|
|
76
|
+
manager.onNewContact({ nodeId: NODES_CLOSEST_TO_DATA[4], type: NodeType.NODEJS })
|
|
77
|
+
await wait(50)
|
|
78
|
+
expect(replicateData).not.toHaveBeenCalled()
|
|
79
|
+
expect(setStale).not.toHaveBeenCalled()
|
|
80
|
+
})
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
describe('this node is not primary storer', () => {
|
|
84
|
+
|
|
85
|
+
it('this node is within redundancy factor', async () => {
|
|
86
|
+
const replicateData = jest.fn<undefined, [ReplicateDataRequest]>()
|
|
87
|
+
const setStale = jest.fn<undefined, [Key, NodeID]>()
|
|
88
|
+
const manager = createStoreManager(
|
|
89
|
+
NODES_CLOSEST_TO_DATA[1],
|
|
90
|
+
[NODES_CLOSEST_TO_DATA[0], NODES_CLOSEST_TO_DATA[2], NODES_CLOSEST_TO_DATA[3]],
|
|
91
|
+
replicateData,
|
|
92
|
+
setStale
|
|
93
|
+
)
|
|
94
|
+
manager.onNewContact({ nodeId: NODES_CLOSEST_TO_DATA[4], type: NodeType.NODEJS })
|
|
95
|
+
await wait(50)
|
|
96
|
+
expect(replicateData).not.toHaveBeenCalled()
|
|
97
|
+
expect(setStale).not.toHaveBeenCalled()
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
it('this node is not within redundancy factor', async () => {
|
|
101
|
+
const replicateData = jest.fn<undefined, [ReplicateDataRequest]>()
|
|
102
|
+
const setStale = jest.fn<undefined, [Key, NodeID]>()
|
|
103
|
+
const manager = createStoreManager(
|
|
104
|
+
NODES_CLOSEST_TO_DATA[3],
|
|
105
|
+
[NODES_CLOSEST_TO_DATA[0], NODES_CLOSEST_TO_DATA[1], NODES_CLOSEST_TO_DATA[2]],
|
|
106
|
+
replicateData,
|
|
107
|
+
setStale
|
|
108
|
+
)
|
|
109
|
+
manager.onNewContact({ nodeId: NODES_CLOSEST_TO_DATA[4], type: NodeType.NODEJS })
|
|
110
|
+
await wait(50)
|
|
111
|
+
expect(replicateData).not.toHaveBeenCalled()
|
|
112
|
+
expect(setStale).toHaveBeenCalledTimes(1)
|
|
113
|
+
expect(setStale).toHaveBeenCalledWith(DATA_ENTRY.key, getNodeIdFromBinary(DATA_ENTRY.creator), true)
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
it('this node has less than redundancyFactor neighbors', async () => {
|
|
117
|
+
const replicateData = jest.fn<undefined, [ReplicateDataRequest]>()
|
|
118
|
+
const setStale = jest.fn<undefined, [Key, NodeID]>()
|
|
119
|
+
const manager = createStoreManager(
|
|
120
|
+
NODES_CLOSEST_TO_DATA[3],
|
|
121
|
+
[NODES_CLOSEST_TO_DATA[0], NODES_CLOSEST_TO_DATA[1]],
|
|
122
|
+
replicateData,
|
|
123
|
+
setStale
|
|
124
|
+
)
|
|
125
|
+
manager.onNewContact({ nodeId: NODES_CLOSEST_TO_DATA[4], type: NodeType.NODEJS })
|
|
126
|
+
await wait(50)
|
|
127
|
+
expect(replicateData).not.toHaveBeenCalled()
|
|
128
|
+
expect(setStale).toHaveBeenCalledTimes(0)
|
|
129
|
+
})
|
|
130
|
+
})
|
|
131
|
+
})
|
|
132
|
+
})
|
|
@@ -1,16 +1,8 @@
|
|
|
1
1
|
/* eslint-disable max-len */
|
|
2
2
|
import { WebsocketConnector } from '../../src/connection/websocket/WebsocketConnector'
|
|
3
|
-
import {
|
|
4
|
-
import crypto from 'crypto'
|
|
3
|
+
import { NodeType } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
5
4
|
import { MockTransport } from '../utils/mock/Transport'
|
|
6
|
-
|
|
7
|
-
const createMockPeerDescriptor = (nodeType: NodeType, websocket?: ConnectivityMethod): PeerDescriptor => {
|
|
8
|
-
return {
|
|
9
|
-
nodeId: crypto.randomBytes(10),
|
|
10
|
-
type: nodeType,
|
|
11
|
-
websocket
|
|
12
|
-
}
|
|
13
|
-
}
|
|
5
|
+
import { createMockPeerDescriptor } from '../utils/utils'
|
|
14
6
|
|
|
15
7
|
describe('WebsocketConnector', () => {
|
|
16
8
|
|
|
@@ -22,43 +14,43 @@ describe('WebsocketConnector', () => {
|
|
|
22
14
|
} as any)
|
|
23
15
|
|
|
24
16
|
it('node without server', () => {
|
|
25
|
-
connector.setLocalPeerDescriptor(createMockPeerDescriptor(NodeType.NODEJS))
|
|
26
|
-
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor(NodeType.NODEJS, { host: '2.2.2.2', port: 22, tls: false }))).toBe(true)
|
|
27
|
-
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor(NodeType.NODEJS, { host: '2.2.2.2', port: 22, tls: true }))).toBe(true)
|
|
28
|
-
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor(NodeType.NODEJS))).toBe(false)
|
|
29
|
-
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor(NodeType.BROWSER))).toBe(false)
|
|
17
|
+
connector.setLocalPeerDescriptor(createMockPeerDescriptor({ type: NodeType.NODEJS }))
|
|
18
|
+
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor({ type: NodeType.NODEJS, websocket: { host: '2.2.2.2', port: 22, tls: false } }))).toBe(true)
|
|
19
|
+
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor({ type: NodeType.NODEJS, websocket: { host: '2.2.2.2', port: 22, tls: true } }))).toBe(true)
|
|
20
|
+
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor({ type: NodeType.NODEJS }))).toBe(false)
|
|
21
|
+
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor({ type: NodeType.BROWSER }))).toBe(false)
|
|
30
22
|
})
|
|
31
23
|
|
|
32
24
|
it('node with TLS server', () => {
|
|
33
|
-
connector.setLocalPeerDescriptor(createMockPeerDescriptor(NodeType.NODEJS, { host: '1.1.1.1', port: 11, tls: true }))
|
|
34
|
-
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor(NodeType.NODEJS, { host: '2.2.2.2', port: 22, tls: false }))).toBe(true)
|
|
35
|
-
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor(NodeType.NODEJS, { host: '2.2.2.2', port: 22, tls: true }))).toBe(true)
|
|
36
|
-
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor(NodeType.NODEJS))).toBe(true)
|
|
37
|
-
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor(NodeType.BROWSER))).toBe(true)
|
|
25
|
+
connector.setLocalPeerDescriptor(createMockPeerDescriptor({ type: NodeType.NODEJS, websocket: { host: '1.1.1.1', port: 11, tls: true } }))
|
|
26
|
+
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor({ type: NodeType.NODEJS, websocket: { host: '2.2.2.2', port: 22, tls: false } }))).toBe(true)
|
|
27
|
+
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor({ type: NodeType.NODEJS, websocket: { host: '2.2.2.2', port: 22, tls: true } }))).toBe(true)
|
|
28
|
+
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor({ type: NodeType.NODEJS }))).toBe(true)
|
|
29
|
+
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor({ type: NodeType.BROWSER }))).toBe(true)
|
|
38
30
|
})
|
|
39
31
|
|
|
40
32
|
it('node with non-TLS server', () => {
|
|
41
|
-
connector.setLocalPeerDescriptor(createMockPeerDescriptor(NodeType.NODEJS, { host: '1.1.1.1', port: 11, tls: false }))
|
|
42
|
-
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor(NodeType.NODEJS, { host: '2.2.2.2', port: 22, tls: false }))).toBe(true)
|
|
43
|
-
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor(NodeType.NODEJS, { host: '2.2.2.2', port: 22, tls: true }))).toBe(true)
|
|
44
|
-
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor(NodeType.NODEJS))).toBe(true)
|
|
45
|
-
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor(NodeType.BROWSER))).toBe(false)
|
|
33
|
+
connector.setLocalPeerDescriptor(createMockPeerDescriptor({ type: NodeType.NODEJS, websocket: { host: '1.1.1.1', port: 11, tls: false } }))
|
|
34
|
+
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor({ type: NodeType.NODEJS, websocket: { host: '2.2.2.2', port: 22, tls: false } }))).toBe(true)
|
|
35
|
+
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor({ type: NodeType.NODEJS, websocket: { host: '2.2.2.2', port: 22, tls: true } }))).toBe(true)
|
|
36
|
+
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor({ type: NodeType.NODEJS }))).toBe(true)
|
|
37
|
+
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor({ type: NodeType.BROWSER }))).toBe(false)
|
|
46
38
|
})
|
|
47
39
|
|
|
48
40
|
it('node with non-TLS server in local network', () => {
|
|
49
|
-
connector.setLocalPeerDescriptor(createMockPeerDescriptor(NodeType.NODEJS, { host: '192.168.11.11', port: 11, tls: false }))
|
|
50
|
-
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor(NodeType.NODEJS, { host: '2.2.2.2', port: 22, tls: false }))).toBe(true)
|
|
51
|
-
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor(NodeType.NODEJS, { host: '2.2.2.2', port: 22, tls: true }))).toBe(true)
|
|
52
|
-
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor(NodeType.NODEJS))).toBe(true)
|
|
53
|
-
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor(NodeType.BROWSER))).toBe(true)
|
|
41
|
+
connector.setLocalPeerDescriptor(createMockPeerDescriptor({ type: NodeType.NODEJS, websocket: { host: '192.168.11.11', port: 11, tls: false } }))
|
|
42
|
+
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor({ type: NodeType.NODEJS, websocket: { host: '2.2.2.2', port: 22, tls: false } }))).toBe(true)
|
|
43
|
+
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor({ type: NodeType.NODEJS, websocket: { host: '2.2.2.2', port: 22, tls: true } }))).toBe(true)
|
|
44
|
+
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor({ type: NodeType.NODEJS }))).toBe(true)
|
|
45
|
+
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor({ type: NodeType.BROWSER }))).toBe(true)
|
|
54
46
|
})
|
|
55
47
|
|
|
56
48
|
it('browser', () => {
|
|
57
|
-
connector.setLocalPeerDescriptor(createMockPeerDescriptor(NodeType.BROWSER))
|
|
58
|
-
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor(NodeType.NODEJS, { host: '2.2.2.2', port: 22, tls: false }))).toBe(false)
|
|
59
|
-
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor(NodeType.NODEJS, { host: '2.2.2.2', port: 22, tls: true }))).toBe(true)
|
|
60
|
-
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor(NodeType.NODEJS))).toBe(false)
|
|
61
|
-
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor(NodeType.BROWSER))).toBe(false)
|
|
49
|
+
connector.setLocalPeerDescriptor(createMockPeerDescriptor({ type: NodeType.BROWSER }))
|
|
50
|
+
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor({ type: NodeType.NODEJS, websocket: { host: '2.2.2.2', port: 22, tls: false } }))).toBe(false)
|
|
51
|
+
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor({ type: NodeType.NODEJS, websocket: { host: '2.2.2.2', port: 22, tls: true } }))).toBe(true)
|
|
52
|
+
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor({ type: NodeType.NODEJS }))).toBe(false)
|
|
53
|
+
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor({ type: NodeType.BROWSER }))).toBe(false)
|
|
62
54
|
})
|
|
63
55
|
})
|
|
64
56
|
})
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { cloneDeep } from 'lodash'
|
|
2
|
+
import { createMockPeerDescriptor } from '../utils/utils'
|
|
3
|
+
|
|
4
|
+
describe('custom matchers', () => {
|
|
5
|
+
|
|
6
|
+
it('happy path', () => {
|
|
7
|
+
const peerDescriptor = createMockPeerDescriptor({
|
|
8
|
+
websocket: { port: 1, host: 'x', tls: true }
|
|
9
|
+
})
|
|
10
|
+
expect(peerDescriptor).toEqualPeerDescriptor(cloneDeep(peerDescriptor))
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
it('no match', () => {
|
|
14
|
+
expect(createMockPeerDescriptor()).not.toEqualPeerDescriptor(createMockPeerDescriptor())
|
|
15
|
+
})
|
|
16
|
+
})
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { EventEmitter } from 'eventemitter3'
|
|
2
|
+
import { ITransport, TransportEvents } from '../../src/transport/ITransport'
|
|
3
|
+
import { Message, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
4
|
+
|
|
5
|
+
class FakeTransport extends EventEmitter<TransportEvents> implements ITransport {
|
|
6
|
+
|
|
7
|
+
private onSend: (msg: Message) => void
|
|
8
|
+
|
|
9
|
+
constructor(onSend: (msg: Message) => void) {
|
|
10
|
+
super()
|
|
11
|
+
this.onSend = onSend
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async send(msg: Message): Promise<void> {
|
|
15
|
+
this.onSend(msg)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// eslint-disable-next-line class-methods-use-this
|
|
19
|
+
getLocalPeerDescriptor(): PeerDescriptor {
|
|
20
|
+
throw new Error('not implemented')
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// eslint-disable-next-line class-methods-use-this
|
|
24
|
+
getAllConnectionPeerDescriptors(): PeerDescriptor[] {
|
|
25
|
+
throw new Error('not implemented')
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// eslint-disable-next-line class-methods-use-this
|
|
29
|
+
stop(): void | Promise<void> {
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export class FakeEnvironment {
|
|
34
|
+
|
|
35
|
+
private transports: FakeTransport[] = []
|
|
36
|
+
|
|
37
|
+
createTransport(): ITransport {
|
|
38
|
+
const transport = new FakeTransport((msg) => {
|
|
39
|
+
this.transports.forEach((t) => t.emit('message', msg))
|
|
40
|
+
})
|
|
41
|
+
this.transports.push(transport)
|
|
42
|
+
return transport
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { areEqualBinaries, binaryToHex } from '@streamr/utils'
|
|
2
|
+
import { printExpected, printReceived } from 'jest-matcher-utils'
|
|
3
|
+
import { isEqual } from 'lodash'
|
|
4
|
+
import { ConnectivityMethod, NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
5
|
+
|
|
6
|
+
// we could ES2015 module syntax (https://jestjs.io/docs/expect#expectextendmatchers),
|
|
7
|
+
// but the IDE doesn't find custom matchers if we do that
|
|
8
|
+
declare global {
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
10
|
+
namespace jest {
|
|
11
|
+
interface Matchers<R> {
|
|
12
|
+
toEqualPeerDescriptor(expected: PeerDescriptor): R
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const formErrorMessage = (description: string, expected: string | number | undefined, actual: string | number | undefined): string => {
|
|
18
|
+
return `${description}\nExpected: ${printExpected(expected)}\nReceived: ${printReceived(actual)}`
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const toEqualPeerDescriptor = (
|
|
22
|
+
actual: PeerDescriptor,
|
|
23
|
+
expected: PeerDescriptor
|
|
24
|
+
): jest.CustomMatcherResult => {
|
|
25
|
+
const messages: string[] = []
|
|
26
|
+
if (!areEqualBinaries(expected.nodeId, actual.nodeId)) {
|
|
27
|
+
messages.push(formErrorMessage('nodeId', binaryToHex(expected.nodeId), binaryToHex(actual.nodeId)))
|
|
28
|
+
}
|
|
29
|
+
if (!isEqual(expected.type, actual.type)) {
|
|
30
|
+
const typeNames = { [NodeType.NODEJS]: 'NODEJS', [NodeType.BROWSER]: 'BROWSER' }
|
|
31
|
+
messages.push(formErrorMessage('type', typeNames[expected.type], typeNames[actual.type]))
|
|
32
|
+
}
|
|
33
|
+
expectEqualConnectivityMethod('udp', expected.udp, actual.udp, messages)
|
|
34
|
+
expectEqualConnectivityMethod('tpc', expected.tcp, actual.tcp, messages)
|
|
35
|
+
expectEqualConnectivityMethod('websocket', expected.websocket, actual.websocket, messages)
|
|
36
|
+
if (expected.region !== actual.region) {
|
|
37
|
+
messages.push(formErrorMessage('region', expected?.region, actual?.region))
|
|
38
|
+
}
|
|
39
|
+
if (messages.length > 0) {
|
|
40
|
+
return {
|
|
41
|
+
pass: false,
|
|
42
|
+
message: () => messages.join('\n\n')
|
|
43
|
+
}
|
|
44
|
+
} else {
|
|
45
|
+
return {
|
|
46
|
+
pass: true,
|
|
47
|
+
message: () => `Expected not to throw ${printReceived('StreamrClientError')}`
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const expectEqualConnectivityMethod = (
|
|
53
|
+
description: string,
|
|
54
|
+
method1: ConnectivityMethod | undefined,
|
|
55
|
+
method2: ConnectivityMethod | undefined,
|
|
56
|
+
messages: string[]
|
|
57
|
+
) => {
|
|
58
|
+
const toOutput = (method?: ConnectivityMethod) => {
|
|
59
|
+
return (method !== undefined)
|
|
60
|
+
? `{port: ${method.port}, host: '${method.host}', tls: ${method.tls}}`
|
|
61
|
+
: undefined
|
|
62
|
+
}
|
|
63
|
+
if (!isEqual(method1, method2)) {
|
|
64
|
+
messages.push(formErrorMessage(description, toOutput(method1), toOutput(method2)))
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
expect.extend({
|
|
69
|
+
toEqualPeerDescriptor
|
|
70
|
+
})
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Methods } from '@streamr/test-utils'
|
|
2
|
+
import { Router } from '../../../src/dht/routing/Router'
|
|
2
3
|
import { RouteMessageAck } from '../../../src/proto/packages/dht/protos/DhtRpc'
|
|
3
4
|
|
|
4
|
-
export class MockRouter implements
|
|
5
|
+
export class MockRouter implements Methods<Router> {
|
|
5
6
|
|
|
6
7
|
// eslint-disable-next-line class-methods-use-this
|
|
7
8
|
addRoutingSession(): void {
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { MessageType as MessageType$, ScalarType } from '@protobuf-ts/runtime'
|
|
2
|
+
import { randomString } from '@streamr/utils'
|
|
3
|
+
import crypto from 'crypto'
|
|
4
|
+
import { Timestamp } from '../../../src/proto/google/protobuf/timestamp'
|
|
5
|
+
import { Any } from '../../../src/proto/google/protobuf/any'
|
|
6
|
+
import { DataEntry } from '../../../src/proto/packages/dht/protos/DhtRpc'
|
|
7
|
+
import { createRandomNodeId } from '../../../src/helpers/nodeId'
|
|
8
|
+
|
|
9
|
+
const MockData = new class extends MessageType$<{ foo: string }> {
|
|
10
|
+
constructor() {
|
|
11
|
+
super('MockData', [
|
|
12
|
+
{ no: 1, name: 'foo', kind: 'scalar', opt: false, T: ScalarType.STRING }
|
|
13
|
+
])
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const createMockDataEntry = (entry: Partial<DataEntry> = {}): DataEntry => {
|
|
18
|
+
return {
|
|
19
|
+
key: crypto.randomBytes(10),
|
|
20
|
+
data: Any.pack({ foo: randomString(5) }, MockData),
|
|
21
|
+
creator: entry.creator ?? createRandomNodeId(),
|
|
22
|
+
ttl: 10000,
|
|
23
|
+
stale: false,
|
|
24
|
+
deleted: false,
|
|
25
|
+
createdAt: Timestamp.now(),
|
|
26
|
+
...entry
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const unpackData = (entry: DataEntry): { foo: string } => {
|
|
31
|
+
return Any.unpack(entry.data!, MockData)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const expectEqualData = (entry1: DataEntry, entry2: DataEntry): void => {
|
|
35
|
+
expect(unpackData(entry1).foo).toBe(unpackData(entry2).foo)
|
|
36
|
+
}
|
package/test/utils/utils.ts
CHANGED
|
@@ -10,12 +10,10 @@ import {
|
|
|
10
10
|
RouteMessageWrapper,
|
|
11
11
|
StoreDataRequest,
|
|
12
12
|
StoreDataResponse,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
FindAction
|
|
13
|
+
RecursiveOperationRequest,
|
|
14
|
+
RecursiveOperation
|
|
16
15
|
} from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
17
16
|
import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
|
|
18
|
-
import { PeerID } from '../../src/helpers/PeerID'
|
|
19
17
|
import {
|
|
20
18
|
IDhtNodeRpc,
|
|
21
19
|
IRouterRpc,
|
|
@@ -32,33 +30,23 @@ import { wait, waitForCondition } from '@streamr/utils'
|
|
|
32
30
|
import { SimulatorTransport } from '../../src/connection/simulator/SimulatorTransport'
|
|
33
31
|
import { createRandomNodeId } from '../../src/helpers/nodeId'
|
|
34
32
|
|
|
35
|
-
export const
|
|
36
|
-
return PeerID.fromString(stringId).value
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export const createMockPeerDescriptor = (): PeerDescriptor => {
|
|
33
|
+
export const createMockPeerDescriptor = (opts?: Partial<Omit<PeerDescriptor, 'nodeId'>>): PeerDescriptor => {
|
|
40
34
|
return {
|
|
41
35
|
nodeId: createRandomNodeId(),
|
|
42
36
|
type: NodeType.NODEJS,
|
|
43
|
-
|
|
37
|
+
...opts
|
|
38
|
+
}
|
|
44
39
|
}
|
|
45
40
|
|
|
46
41
|
export const createMockConnectionDhtNode = async (
|
|
47
|
-
stringId: string,
|
|
48
42
|
simulator: Simulator,
|
|
49
|
-
|
|
43
|
+
nodeId?: Uint8Array,
|
|
50
44
|
numberOfNodesPerKBucket?: number,
|
|
51
45
|
maxConnections = 80,
|
|
52
46
|
dhtJoinTimeout = 45000
|
|
53
47
|
): Promise<DhtNode> => {
|
|
54
|
-
let id: PeerID
|
|
55
|
-
if (binaryId) {
|
|
56
|
-
id = PeerID.fromValue(binaryId)
|
|
57
|
-
} else {
|
|
58
|
-
id = PeerID.fromString(stringId)
|
|
59
|
-
}
|
|
60
48
|
const peerDescriptor: PeerDescriptor = {
|
|
61
|
-
nodeId:
|
|
49
|
+
nodeId: nodeId ?? createRandomNodeId(),
|
|
62
50
|
type: NodeType.NODEJS,
|
|
63
51
|
region: getRandomRegion()
|
|
64
52
|
}
|
|
@@ -83,14 +71,12 @@ export const createMockConnectionDhtNode = async (
|
|
|
83
71
|
}
|
|
84
72
|
|
|
85
73
|
export const createMockConnectionLayer1Node = async (
|
|
86
|
-
stringId: string,
|
|
87
74
|
layer0Node: DhtNode,
|
|
88
75
|
serviceId?: string,
|
|
89
76
|
numberOfNodesPerKBucket = 8
|
|
90
77
|
): Promise<DhtNode> => {
|
|
91
|
-
const id = PeerID.fromString(stringId)
|
|
92
78
|
const descriptor: PeerDescriptor = {
|
|
93
|
-
nodeId:
|
|
79
|
+
nodeId: layer0Node.getLocalPeerDescriptor().nodeId,
|
|
94
80
|
type: NodeType.NODEJS,
|
|
95
81
|
}
|
|
96
82
|
const node = new DhtNode({
|
|
@@ -121,11 +107,9 @@ export const createWrappedClosestPeersRequest = (
|
|
|
121
107
|
return rpcWrapper
|
|
122
108
|
}
|
|
123
109
|
|
|
124
|
-
export const createFindRequest = (
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
const request: FindRequest = {
|
|
128
|
-
action,
|
|
110
|
+
export const createFindRequest = (): RecursiveOperationRequest => {
|
|
111
|
+
const request: RecursiveOperationRequest = {
|
|
112
|
+
operation: RecursiveOperation.FIND_NODE,
|
|
129
113
|
sessionId: v4()
|
|
130
114
|
}
|
|
131
115
|
return request
|
|
@@ -137,36 +121,37 @@ interface IDhtRpcWithError extends IDhtNodeRpc {
|
|
|
137
121
|
throwGetClosestPeersError: (request: ClosestPeersRequest) => Promise<ClosestPeersResponse>
|
|
138
122
|
}
|
|
139
123
|
|
|
140
|
-
export const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
124
|
+
export const createMockDhtRpc = (neighbors: PeerDescriptor[]): IDhtRpcWithError => {
|
|
125
|
+
return {
|
|
126
|
+
async getClosestPeers(): Promise<ClosestPeersResponse> {
|
|
127
|
+
const response: ClosestPeersResponse = {
|
|
128
|
+
peers: neighbors,
|
|
129
|
+
requestId: 'why am i still here'
|
|
130
|
+
}
|
|
131
|
+
return response
|
|
132
|
+
},
|
|
133
|
+
async ping(request: PingRequest): Promise<PingResponse> {
|
|
134
|
+
const response: PingResponse = {
|
|
135
|
+
requestId: request.requestId
|
|
136
|
+
}
|
|
137
|
+
return response
|
|
138
|
+
},
|
|
139
|
+
async leaveNotice(): Promise<Empty> {
|
|
140
|
+
return {}
|
|
141
|
+
},
|
|
142
|
+
async throwPingError(): Promise<PingResponse> {
|
|
143
|
+
throw new Error()
|
|
144
|
+
},
|
|
145
|
+
async respondPingWithTimeout(request: PingRequest): Promise<PingResponse> {
|
|
146
|
+
const response: PingResponse = {
|
|
147
|
+
requestId: request.requestId
|
|
148
|
+
}
|
|
149
|
+
await wait(2000)
|
|
150
|
+
return response
|
|
151
|
+
},
|
|
152
|
+
async throwGetClosestPeersError(): Promise<ClosestPeersResponse> {
|
|
153
|
+
throw new Error('Closest peers error')
|
|
164
154
|
}
|
|
165
|
-
await wait(2000)
|
|
166
|
-
return response
|
|
167
|
-
},
|
|
168
|
-
async throwGetClosestPeersError(): Promise<ClosestPeersResponse> {
|
|
169
|
-
throw new Error('Closest peers error')
|
|
170
155
|
}
|
|
171
156
|
}
|
|
172
157
|
|
|
@@ -194,54 +179,31 @@ export const mockRouterRpc: IRouterRpcWithError = {
|
|
|
194
179
|
|
|
195
180
|
interface IStoreRpcWithError extends IStoreRpc {
|
|
196
181
|
throwStoreDataError: (request: StoreDataRequest) => Promise<StoreDataResponse>
|
|
197
|
-
storeDataErrorString: (request: StoreDataRequest) => Promise<StoreDataResponse>
|
|
198
182
|
}
|
|
199
183
|
|
|
200
184
|
export const mockStoreRpc: IStoreRpcWithError = {
|
|
201
185
|
async storeData(): Promise<StoreDataResponse> {
|
|
202
|
-
return {
|
|
203
|
-
error: ''
|
|
204
|
-
}
|
|
186
|
+
return {}
|
|
205
187
|
},
|
|
206
188
|
async throwStoreDataError(): Promise<StoreDataResponse> {
|
|
207
189
|
throw new Error('Mock')
|
|
208
190
|
},
|
|
209
|
-
async storeDataErrorString(): Promise<StoreDataResponse> {
|
|
210
|
-
return {
|
|
211
|
-
error: 'Mock'
|
|
212
|
-
}
|
|
213
|
-
},
|
|
214
191
|
async replicateData(): Promise<Empty> {
|
|
215
192
|
return {}
|
|
216
193
|
}
|
|
217
194
|
}
|
|
218
195
|
|
|
219
196
|
export const mockWebsocketConnectorRpc: IWebsocketConnectorRpc = {
|
|
220
|
-
async requestConnection(): Promise<
|
|
221
|
-
|
|
222
|
-
accepted: true
|
|
223
|
-
}
|
|
224
|
-
return responseConnection
|
|
197
|
+
async requestConnection(): Promise<Empty> {
|
|
198
|
+
return {}
|
|
225
199
|
}
|
|
226
200
|
}
|
|
227
201
|
|
|
228
|
-
export const
|
|
229
|
-
const n1
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
const n2: PeerDescriptor = {
|
|
234
|
-
nodeId: generateId('Neighbor2'),
|
|
235
|
-
type: NodeType.NODEJS,
|
|
236
|
-
}
|
|
237
|
-
const n3: PeerDescriptor = {
|
|
238
|
-
nodeId: generateId('Neighbor3'),
|
|
239
|
-
type: NodeType.NODEJS,
|
|
240
|
-
}
|
|
241
|
-
const n4: PeerDescriptor = {
|
|
242
|
-
nodeId: generateId('Neighbor4'),
|
|
243
|
-
type: NodeType.NODEJS,
|
|
244
|
-
}
|
|
202
|
+
export const createMockPeers = (): PeerDescriptor[] => {
|
|
203
|
+
const n1 = createMockPeerDescriptor()
|
|
204
|
+
const n2 = createMockPeerDescriptor()
|
|
205
|
+
const n3 = createMockPeerDescriptor()
|
|
206
|
+
const n4 = createMockPeerDescriptor()
|
|
245
207
|
return [
|
|
246
208
|
n1, n2, n3, n4
|
|
247
209
|
]
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { PeerDescriptor, RouteMessageAck, RouteMessageWrapper } from '../../proto/packages/dht/protos/DhtRpc';
|
|
2
|
-
import { IFindRpc } from '../../proto/packages/dht/protos/DhtRpc.server';
|
|
3
|
-
interface FindRpcLocalConfig {
|
|
4
|
-
doRouteFindRequest: (routedMessage: RouteMessageWrapper) => RouteMessageAck;
|
|
5
|
-
addContact: (contact: PeerDescriptor, setActive?: boolean) => void;
|
|
6
|
-
isMostLikelyDuplicate: (requestId: string) => boolean;
|
|
7
|
-
addToDuplicateDetector: (requestId: string) => void;
|
|
8
|
-
}
|
|
9
|
-
export declare class FindRpcLocal implements IFindRpc {
|
|
10
|
-
private readonly config;
|
|
11
|
-
constructor(config: FindRpcLocalConfig);
|
|
12
|
-
routeFindRequest(routedMessage: RouteMessageWrapper): Promise<RouteMessageAck>;
|
|
13
|
-
}
|
|
14
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FindRpcLocal.js","sourceRoot":"","sources":["../../../../src/dht/find/FindRpcLocal.ts"],"names":[],"mappings":";;;AAAA,0CAAuC;AACvC,mEAAgI;AAEhI,qFAAoF;AACpF,8DAAiE;AACjE,gEAA4D;AAE5D,MAAM,MAAM,GAAG,IAAI,cAAM,CAAC,MAAM,CAAC,CAAA;AASjC,MAAa,YAAY;IAIrB,YAAY,MAA0B;QAClC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACxB,CAAC;IAED,KAAK,CAAC,gBAAgB,CAAC,aAAkC;QACrD,IAAI,IAAI,CAAC,MAAM,CAAC,qBAAqB,CAAC,aAAa,CAAC,SAAS,CAAC,EAAE;YAC5D,OAAO,IAAA,sCAAqB,EAAC,aAAa,EAAE,0BAAiB,CAAC,SAAS,CAAC,CAAA;SAC3E;QACD,MAAM,QAAQ,GAAG,IAAA,sDAA2B,EAAC,IAAA,iCAAe,EAAC,aAAa,CAAC,IAAI,aAAa,CAAC,UAAW,CAAC,CAAA;QACzG,MAAM,CAAC,KAAK,CAAC,uCAAuC,QAAQ,EAAE,CAAC,CAAA;QAC/D,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,aAAa,CAAC,UAAW,EAAE,IAAI,CAAC,CAAA;QACvD,IAAI,CAAC,MAAM,CAAC,sBAAsB,CAAC,aAAa,CAAC,SAAS,CAAC,CAAA;QAC3D,OAAO,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC,aAAa,CAAC,CAAA;IACxD,CAAC;CACJ;AAlBD,oCAkBC"}
|