@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
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ConnectionManager } from '../../src/connection/ConnectionManager'
|
|
2
2
|
import { LatencyType, Simulator } from '../../src/connection/simulator/Simulator'
|
|
3
|
-
import { PeerID } from '../../src/helpers/PeerID'
|
|
4
3
|
import { ITransport } from '../../src/transport/ITransport'
|
|
5
4
|
import { v4 } from 'uuid'
|
|
6
5
|
import { SimulatorTransport } from '../../src/connection/simulator/SimulatorTransport'
|
|
@@ -8,9 +7,12 @@ import { DhtRpcOptions } from '../../src/rpc-protocol/DhtRpcOptions'
|
|
|
8
7
|
import { ListeningRpcCommunicator } from '../../src/transport/ListeningRpcCommunicator'
|
|
9
8
|
import { ProtoRpcClient, toProtoRpcClient } from '@streamr/proto-rpc'
|
|
10
9
|
import { DhtNodeRpcClient } from '../../src/proto/packages/dht/protos/DhtRpc.client'
|
|
11
|
-
import {
|
|
10
|
+
import { PeerDescriptor, PingRequest, PingResponse } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
12
11
|
import { DefaultConnectorFacade } from '../../src/connection/ConnectorFacade'
|
|
13
12
|
import { MetricsContext } from '@streamr/utils'
|
|
13
|
+
import { createMockPeerDescriptor } from '../utils/utils'
|
|
14
|
+
|
|
15
|
+
const SERVICE_ID = 'test'
|
|
14
16
|
|
|
15
17
|
const createConnectionManager = (localPeerDescriptor: PeerDescriptor, transport: ITransport) => {
|
|
16
18
|
return new ConnectionManager({
|
|
@@ -26,43 +28,28 @@ describe('RPC errors', () => {
|
|
|
26
28
|
|
|
27
29
|
let manager1: ConnectionManager
|
|
28
30
|
let manager2: ConnectionManager
|
|
29
|
-
|
|
30
31
|
let rpcCommunicator1: ListeningRpcCommunicator
|
|
31
32
|
let rpcCommunicator2: ListeningRpcCommunicator
|
|
32
|
-
|
|
33
33
|
let client1: ProtoRpcClient<DhtNodeRpcClient>
|
|
34
|
-
//let client2: ProtoRpcClient<DhtNodeRpcClient>
|
|
35
|
-
|
|
36
34
|
let simulator: Simulator
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
nodeId: PeerID.fromString('peer1').value,
|
|
40
|
-
type: NodeType.NODEJS,
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const peerDescriptor2: PeerDescriptor = {
|
|
44
|
-
nodeId: PeerID.fromString('peer2').value,
|
|
45
|
-
type: NodeType.NODEJS,
|
|
46
|
-
}
|
|
47
|
-
|
|
35
|
+
const peerDescriptor1 = createMockPeerDescriptor()
|
|
36
|
+
const peerDescriptor2 = createMockPeerDescriptor()
|
|
48
37
|
let connectorTransport1: SimulatorTransport
|
|
49
38
|
let connectorTransport2: SimulatorTransport
|
|
50
39
|
|
|
51
|
-
const serviceId = 'test'
|
|
52
|
-
|
|
53
40
|
beforeEach(async () => {
|
|
54
41
|
|
|
55
42
|
simulator = new Simulator(LatencyType.FIXED, 50)
|
|
56
43
|
connectorTransport1 = new SimulatorTransport(peerDescriptor1, simulator)
|
|
57
44
|
await connectorTransport1.start()
|
|
58
45
|
manager1 = createConnectionManager(peerDescriptor1, connectorTransport1)
|
|
59
|
-
rpcCommunicator1 = new ListeningRpcCommunicator(
|
|
46
|
+
rpcCommunicator1 = new ListeningRpcCommunicator(SERVICE_ID, manager1)
|
|
60
47
|
client1 = toProtoRpcClient(new DhtNodeRpcClient(rpcCommunicator1.getRpcClientTransport()))
|
|
61
48
|
|
|
62
49
|
connectorTransport2 = new SimulatorTransport(peerDescriptor2, simulator)
|
|
63
50
|
await connectorTransport2.start()
|
|
64
51
|
manager2 = createConnectionManager(peerDescriptor2, connectorTransport2)
|
|
65
|
-
rpcCommunicator2 = new ListeningRpcCommunicator(
|
|
52
|
+
rpcCommunicator2 = new ListeningRpcCommunicator(SERVICE_ID, manager2)
|
|
66
53
|
//client2 = toProtoRpcClient(new DhtNodeRpcClient(rpcCommunicator2.getRpcClientTransport()))
|
|
67
54
|
|
|
68
55
|
await manager1.start()
|
|
@@ -3,36 +3,37 @@ import { DhtNode } from '../../src/dht/DhtNode'
|
|
|
3
3
|
import { NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
4
4
|
import { createMockConnectionDhtNode } from '../utils/utils'
|
|
5
5
|
import { areEqualPeerDescriptors, getNodeIdFromPeerDescriptor } from '../../src/helpers/peerIdFromPeerDescriptor'
|
|
6
|
-
import { Logger } from '@streamr/utils'
|
|
6
|
+
import { Logger, hexToBinary } from '@streamr/utils'
|
|
7
7
|
import { getRandomRegion } from '../../src/connection/simulator/pings'
|
|
8
|
+
import { createRandomNodeId } from '../../src/helpers/nodeId'
|
|
8
9
|
|
|
9
10
|
const logger = new Logger(module)
|
|
10
11
|
|
|
12
|
+
const NUM_NODES = 80
|
|
13
|
+
const MAX_CONNECTIONS = 15
|
|
14
|
+
const K = 2
|
|
15
|
+
|
|
11
16
|
describe('Scaling down a Dht network', () => {
|
|
17
|
+
|
|
12
18
|
let entryPoint: DhtNode
|
|
13
19
|
let nodes: DhtNode[]
|
|
14
20
|
let entrypointDescriptor: PeerDescriptor
|
|
15
21
|
const simulator = new Simulator(LatencyType.REAL)
|
|
16
|
-
const NUM_NODES = 80
|
|
17
|
-
const MAX_CONNECTIONS = 15
|
|
18
|
-
const K = 2
|
|
19
22
|
|
|
20
23
|
beforeEach(async () => {
|
|
21
24
|
nodes = []
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
undefined, K, MAX_CONNECTIONS)
|
|
25
|
+
entryPoint = await createMockConnectionDhtNode(simulator,
|
|
26
|
+
createRandomNodeId(), K, MAX_CONNECTIONS)
|
|
25
27
|
nodes.push(entryPoint)
|
|
26
28
|
|
|
27
29
|
entrypointDescriptor = {
|
|
28
|
-
nodeId: entryPoint.getNodeId()
|
|
30
|
+
nodeId: hexToBinary(entryPoint.getNodeId()),
|
|
29
31
|
type: NodeType.NODEJS,
|
|
30
32
|
region: getRandomRegion()
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
for (let i = 1; i < NUM_NODES; i++) {
|
|
34
|
-
const
|
|
35
|
-
const node = await createMockConnectionDhtNode(nodeId, simulator, undefined, K, MAX_CONNECTIONS)
|
|
36
|
+
const node = await createMockConnectionDhtNode(simulator, undefined, K, MAX_CONNECTIONS)
|
|
36
37
|
nodes.push(node)
|
|
37
38
|
}
|
|
38
39
|
await Promise.all(nodes.map((node) => node.joinDht([entrypointDescriptor])))
|
|
@@ -1,11 +1,24 @@
|
|
|
1
1
|
import { MetricsContext, waitForCondition } from '@streamr/utils'
|
|
2
2
|
import { ConnectionManager } from '../../src/connection/ConnectionManager'
|
|
3
3
|
import { DefaultConnectorFacade, DefaultConnectorFacadeConfig } from '../../src/connection/ConnectorFacade'
|
|
4
|
-
import { Simulator } from '../../src/connection/simulator/Simulator'
|
|
4
|
+
import { LatencyType, Simulator } from '../../src/connection/simulator/Simulator'
|
|
5
5
|
import { SimulatorTransport } from '../../src/connection/simulator/SimulatorTransport'
|
|
6
|
-
import { PeerID } from '../../src/helpers/PeerID'
|
|
7
6
|
import { Message, MessageType, NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
8
7
|
import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
|
|
8
|
+
import { createMockPeerDescriptor } from '../utils/utils'
|
|
9
|
+
import { getRandomRegion } from '../../src/connection/simulator/pings'
|
|
10
|
+
import { createRandomNodeId } from '../../src/helpers/nodeId'
|
|
11
|
+
import { MockTransport } from '../utils/mock/Transport'
|
|
12
|
+
|
|
13
|
+
const BASE_MESSAGE: Message = {
|
|
14
|
+
serviceId: 'serviceId',
|
|
15
|
+
messageType: MessageType.RPC,
|
|
16
|
+
messageId: '1',
|
|
17
|
+
body: {
|
|
18
|
+
oneofKind: 'rpcMessage',
|
|
19
|
+
rpcMessage: RpcMessage.create()
|
|
20
|
+
}
|
|
21
|
+
}
|
|
9
22
|
|
|
10
23
|
const createConnectionManager = (localPeerDescriptor: PeerDescriptor, opts: Omit<DefaultConnectorFacadeConfig, 'createLocalPeerDescriptor'>) => {
|
|
11
24
|
return new ConnectionManager({
|
|
@@ -22,29 +35,11 @@ describe('SimultaneousConnections', () => {
|
|
|
22
35
|
let simulator: Simulator
|
|
23
36
|
let simTransport1: SimulatorTransport
|
|
24
37
|
let simTransport2: SimulatorTransport
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
nodeId: PeerID.fromString('mock1').value,
|
|
28
|
-
type: NodeType.NODEJS
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const peerDescriptor2 = {
|
|
32
|
-
nodeId: PeerID.fromString('mock2').value,
|
|
33
|
-
type: NodeType.NODEJS
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const baseMsg: Message = {
|
|
37
|
-
serviceId: 'serviceId',
|
|
38
|
-
messageType: MessageType.RPC,
|
|
39
|
-
messageId: '1',
|
|
40
|
-
body: {
|
|
41
|
-
oneofKind: 'rpcMessage',
|
|
42
|
-
rpcMessage: RpcMessage.create()
|
|
43
|
-
}
|
|
44
|
-
}
|
|
38
|
+
const peerDescriptor1 = createMockPeerDescriptor({ region: getRandomRegion() })
|
|
39
|
+
const peerDescriptor2 = createMockPeerDescriptor({ region: getRandomRegion() })
|
|
45
40
|
|
|
46
41
|
beforeEach(async () => {
|
|
47
|
-
simulator = new Simulator()
|
|
42
|
+
simulator = new Simulator(LatencyType.REAL)
|
|
48
43
|
simTransport1 = new SimulatorTransport(peerDescriptor1, simulator)
|
|
49
44
|
await simTransport1.start()
|
|
50
45
|
simTransport2 = new SimulatorTransport(peerDescriptor2, simulator)
|
|
@@ -58,11 +53,11 @@ describe('SimultaneousConnections', () => {
|
|
|
58
53
|
|
|
59
54
|
it('simultanous simulated connection', async () => {
|
|
60
55
|
const msg1: Message = {
|
|
61
|
-
...
|
|
56
|
+
...BASE_MESSAGE,
|
|
62
57
|
targetDescriptor: peerDescriptor2
|
|
63
58
|
}
|
|
64
59
|
const msg2: Message = {
|
|
65
|
-
...
|
|
60
|
+
...BASE_MESSAGE,
|
|
66
61
|
targetDescriptor: peerDescriptor1
|
|
67
62
|
}
|
|
68
63
|
|
|
@@ -90,50 +85,42 @@ describe('SimultaneousConnections', () => {
|
|
|
90
85
|
|
|
91
86
|
describe('Websocket 2 servers', () => {
|
|
92
87
|
|
|
93
|
-
let simTransport1: SimulatorTransport
|
|
94
|
-
let simTransport2: SimulatorTransport
|
|
95
88
|
let connectionManager1: ConnectionManager
|
|
96
89
|
let connectionManager2: ConnectionManager
|
|
97
90
|
|
|
98
91
|
const wsPeerDescriptor1: PeerDescriptor = {
|
|
99
|
-
nodeId:
|
|
92
|
+
nodeId: createRandomNodeId(),
|
|
100
93
|
type: NodeType.NODEJS,
|
|
101
94
|
websocket: {
|
|
102
95
|
host: '127.0.0.1',
|
|
103
96
|
port: 43432,
|
|
104
97
|
tls: false
|
|
105
|
-
}
|
|
98
|
+
},
|
|
99
|
+
region: getRandomRegion()
|
|
106
100
|
}
|
|
107
101
|
|
|
108
102
|
const wsPeerDescriptor2: PeerDescriptor = {
|
|
109
|
-
nodeId:
|
|
103
|
+
nodeId: createRandomNodeId(),
|
|
110
104
|
type: NodeType.NODEJS,
|
|
111
105
|
websocket: {
|
|
112
106
|
host: '127.0.0.1',
|
|
113
107
|
port: 43433,
|
|
114
108
|
tls: false
|
|
115
|
-
}
|
|
109
|
+
},
|
|
110
|
+
region: getRandomRegion()
|
|
116
111
|
}
|
|
117
112
|
|
|
118
113
|
beforeEach(async () => {
|
|
119
|
-
|
|
120
|
-
// SimulatorTransport needs to have exatly same peerDescriptor as ConnectionManager
|
|
121
|
-
// that is why we need to create new SimulatorTransports here
|
|
122
|
-
simulator = new Simulator()
|
|
123
|
-
simTransport1 = new SimulatorTransport(wsPeerDescriptor1, simulator)
|
|
124
|
-
await simTransport1.start()
|
|
125
|
-
simTransport2 = new SimulatorTransport(wsPeerDescriptor2, simulator)
|
|
126
|
-
await simTransport2.start()
|
|
127
|
-
|
|
114
|
+
|
|
128
115
|
const websocketPortRange = { min: 43432, max: 43433 }
|
|
129
116
|
connectionManager1 = createConnectionManager(wsPeerDescriptor1, {
|
|
130
|
-
transport:
|
|
117
|
+
transport: new MockTransport(),
|
|
131
118
|
websocketPortRange,
|
|
132
119
|
entryPoints: [wsPeerDescriptor1],
|
|
133
120
|
websocketServerEnableTls: false
|
|
134
121
|
})
|
|
135
122
|
connectionManager2 = createConnectionManager(wsPeerDescriptor2, {
|
|
136
|
-
transport:
|
|
123
|
+
transport: new MockTransport(),
|
|
137
124
|
websocketPortRange,
|
|
138
125
|
entryPoints: [wsPeerDescriptor1],
|
|
139
126
|
websocketServerEnableTls: false
|
|
@@ -145,17 +132,15 @@ describe('SimultaneousConnections', () => {
|
|
|
145
132
|
afterEach(async () => {
|
|
146
133
|
await connectionManager1.stop()
|
|
147
134
|
await connectionManager2.stop()
|
|
148
|
-
await simTransport1.stop()
|
|
149
|
-
await simTransport2.stop()
|
|
150
135
|
})
|
|
151
136
|
|
|
152
137
|
it('Simultaneous Connections', async () => {
|
|
153
138
|
const msg1: Message = {
|
|
154
|
-
...
|
|
139
|
+
...BASE_MESSAGE,
|
|
155
140
|
targetDescriptor: wsPeerDescriptor2
|
|
156
141
|
}
|
|
157
142
|
const msg2: Message = {
|
|
158
|
-
...
|
|
143
|
+
...BASE_MESSAGE,
|
|
159
144
|
targetDescriptor: wsPeerDescriptor1
|
|
160
145
|
}
|
|
161
146
|
|
|
@@ -192,22 +177,20 @@ describe('SimultaneousConnections', () => {
|
|
|
192
177
|
let connectionManager2: ConnectionManager
|
|
193
178
|
|
|
194
179
|
const wsPeerDescriptor1: PeerDescriptor = {
|
|
195
|
-
nodeId:
|
|
180
|
+
nodeId: createRandomNodeId(),
|
|
196
181
|
type: NodeType.NODEJS,
|
|
197
182
|
websocket: {
|
|
198
183
|
host: '127.0.0.1',
|
|
199
184
|
port: 43432,
|
|
200
185
|
tls: false
|
|
201
|
-
}
|
|
186
|
+
},
|
|
187
|
+
region: getRandomRegion()
|
|
202
188
|
}
|
|
203
189
|
|
|
204
|
-
const wsPeerDescriptor2
|
|
205
|
-
nodeId: PeerID.fromString('mock2').value,
|
|
206
|
-
type: NodeType.NODEJS
|
|
207
|
-
}
|
|
190
|
+
const wsPeerDescriptor2 = createMockPeerDescriptor({ region: getRandomRegion() })
|
|
208
191
|
|
|
209
192
|
beforeEach(async () => {
|
|
210
|
-
simulator = new Simulator()
|
|
193
|
+
simulator = new Simulator(LatencyType.REAL)
|
|
211
194
|
simTransport1 = new SimulatorTransport(wsPeerDescriptor1, simulator)
|
|
212
195
|
await simTransport1.start()
|
|
213
196
|
simTransport2 = new SimulatorTransport(wsPeerDescriptor2, simulator)
|
|
@@ -235,11 +218,11 @@ describe('SimultaneousConnections', () => {
|
|
|
235
218
|
|
|
236
219
|
it('Simultaneous Connections', async () => {
|
|
237
220
|
const msg1: Message = {
|
|
238
|
-
...
|
|
221
|
+
...BASE_MESSAGE,
|
|
239
222
|
targetDescriptor: wsPeerDescriptor2
|
|
240
223
|
}
|
|
241
224
|
const msg2: Message = {
|
|
242
|
-
...
|
|
225
|
+
...BASE_MESSAGE,
|
|
243
226
|
targetDescriptor: wsPeerDescriptor1
|
|
244
227
|
}
|
|
245
228
|
|
|
@@ -275,18 +258,11 @@ describe('SimultaneousConnections', () => {
|
|
|
275
258
|
let connectionManager1: ConnectionManager
|
|
276
259
|
let connectionManager2: ConnectionManager
|
|
277
260
|
|
|
278
|
-
const wrtcPeerDescriptor1
|
|
279
|
-
|
|
280
|
-
type: NodeType.NODEJS
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
const wrtcPeerDescriptor2: PeerDescriptor = {
|
|
284
|
-
nodeId: PeerID.fromString('mock2').value,
|
|
285
|
-
type: NodeType.NODEJS
|
|
286
|
-
}
|
|
261
|
+
const wrtcPeerDescriptor1 = createMockPeerDescriptor({ region: getRandomRegion() })
|
|
262
|
+
const wrtcPeerDescriptor2 = createMockPeerDescriptor({ region: getRandomRegion() })
|
|
287
263
|
|
|
288
264
|
beforeEach(async () => {
|
|
289
|
-
simulator = new Simulator()
|
|
265
|
+
simulator = new Simulator(LatencyType.REAL)
|
|
290
266
|
simTransport1 = new SimulatorTransport(wrtcPeerDescriptor1, simulator)
|
|
291
267
|
await simTransport1.start()
|
|
292
268
|
simTransport2 = new SimulatorTransport(wrtcPeerDescriptor2, simulator)
|
|
@@ -310,11 +286,11 @@ describe('SimultaneousConnections', () => {
|
|
|
310
286
|
|
|
311
287
|
it('Simultaneous Connections', async () => {
|
|
312
288
|
const msg1: Message = {
|
|
313
|
-
...
|
|
289
|
+
...BASE_MESSAGE,
|
|
314
290
|
targetDescriptor: wrtcPeerDescriptor2
|
|
315
291
|
}
|
|
316
292
|
const msg2: Message = {
|
|
317
|
-
...
|
|
293
|
+
...BASE_MESSAGE,
|
|
318
294
|
targetDescriptor: wrtcPeerDescriptor1
|
|
319
295
|
}
|
|
320
296
|
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import { LatencyType, Simulator } from '../../src/connection/simulator/Simulator'
|
|
2
2
|
import { DhtNode } from '../../src/dht/DhtNode'
|
|
3
|
+
import { getNodeIdFromBinary } from '../../src/helpers/nodeId'
|
|
4
|
+
import { getNodeIdFromPeerDescriptor } from '../../src/helpers/peerIdFromPeerDescriptor'
|
|
3
5
|
import { PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
6
|
+
import { createMockDataEntry, expectEqualData } from '../utils/mock/mockDataEntry'
|
|
4
7
|
import { createMockConnectionDhtNode, createMockPeerDescriptor, waitConnectionManagersReadyForTesting } from '../utils/utils'
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
|
|
9
|
+
const NUM_NODES = 100
|
|
10
|
+
const MAX_CONNECTIONS = 20
|
|
11
|
+
const K = 4
|
|
8
12
|
|
|
9
13
|
describe('Storing data in DHT', () => {
|
|
14
|
+
|
|
10
15
|
let entryPoint: DhtNode
|
|
11
16
|
let nodes: DhtNode[]
|
|
12
17
|
let entrypointDescriptor: PeerDescriptor
|
|
13
18
|
const simulator = new Simulator(LatencyType.REAL)
|
|
14
|
-
const NUM_NODES = 100
|
|
15
|
-
const MAX_CONNECTIONS = 20
|
|
16
|
-
const K = 4
|
|
17
|
-
const nodeIndicesById: Record<string, number> = {}
|
|
18
19
|
|
|
19
20
|
const getRandomNode = () => {
|
|
20
21
|
return nodes[Math.floor(Math.random() * nodes.length)]
|
|
@@ -22,18 +23,14 @@ describe('Storing data in DHT', () => {
|
|
|
22
23
|
|
|
23
24
|
beforeEach(async () => {
|
|
24
25
|
nodes = []
|
|
25
|
-
|
|
26
|
-
entryPoint = await createMockConnectionDhtNode(entryPointId, simulator,
|
|
26
|
+
entryPoint = await createMockConnectionDhtNode(simulator,
|
|
27
27
|
undefined, K, MAX_CONNECTIONS)
|
|
28
28
|
nodes.push(entryPoint)
|
|
29
|
-
nodeIndicesById[entryPoint.getNodeId().toKey()] = 0
|
|
30
29
|
entrypointDescriptor = entryPoint.getLocalPeerDescriptor()
|
|
31
30
|
nodes.push(entryPoint)
|
|
32
31
|
for (let i = 1; i < NUM_NODES; i++) {
|
|
33
|
-
const
|
|
34
|
-
const node = await createMockConnectionDhtNode(nodeId, simulator,
|
|
32
|
+
const node = await createMockConnectionDhtNode(simulator,
|
|
35
33
|
undefined, K, MAX_CONNECTIONS, 60000)
|
|
36
|
-
nodeIndicesById[node.getNodeId().toKey()] = i
|
|
37
34
|
nodes.push(node)
|
|
38
35
|
}
|
|
39
36
|
await Promise.all(nodes.map((node) => node.joinDht([entrypointDescriptor])))
|
|
@@ -46,44 +43,34 @@ describe('Storing data in DHT', () => {
|
|
|
46
43
|
|
|
47
44
|
it('Storing data works', async () => {
|
|
48
45
|
const storingNodeIndex = 34
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
const data = Any.pack(storedData, PeerDescriptor)
|
|
52
|
-
const successfulStorers = await nodes[storingNodeIndex].storeDataToDht(dataKey, data)
|
|
46
|
+
const entry = createMockDataEntry()
|
|
47
|
+
const successfulStorers = await nodes[storingNodeIndex].storeDataToDht(entry.key, entry.data!)
|
|
53
48
|
expect(successfulStorers.length).toBeGreaterThan(4)
|
|
54
49
|
}, 30000)
|
|
55
50
|
|
|
56
51
|
it('Storing and getting data works', async () => {
|
|
57
52
|
const storingNode = getRandomNode()
|
|
58
|
-
const
|
|
59
|
-
const
|
|
60
|
-
const data = Any.pack(storedData, PeerDescriptor)
|
|
61
|
-
const successfulStorers = await storingNode.storeDataToDht(dataKey, data)
|
|
53
|
+
const entry = createMockDataEntry()
|
|
54
|
+
const successfulStorers = await storingNode.storeDataToDht(entry.key, entry.data!)
|
|
62
55
|
expect(successfulStorers.length).toBeGreaterThan(4)
|
|
63
|
-
|
|
64
56
|
const fetchingNode = getRandomNode()
|
|
65
|
-
const results = await fetchingNode.getDataFromDht(
|
|
66
|
-
results.forEach((
|
|
67
|
-
|
|
68
|
-
expect(areEqualPeerDescriptors(foundData, storedData)).toBeTrue()
|
|
57
|
+
const results = await fetchingNode.getDataFromDht(entry.key)
|
|
58
|
+
results.forEach((result) => {
|
|
59
|
+
expectEqualData(result, entry)
|
|
69
60
|
})
|
|
70
61
|
}, 30000)
|
|
71
62
|
|
|
72
63
|
it('storing with explicit creator', async () => {
|
|
73
64
|
const storingNode = getRandomNode()
|
|
74
|
-
const
|
|
75
|
-
const storedData = createMockPeerDescriptor()
|
|
76
|
-
const data = Any.pack(storedData, PeerDescriptor)
|
|
65
|
+
const entry = createMockDataEntry()
|
|
77
66
|
const requestor = createMockPeerDescriptor()
|
|
78
|
-
const successfulStorers = await storingNode.storeDataToDht(
|
|
67
|
+
const successfulStorers = await storingNode.storeDataToDht(entry.key, entry.data!, getNodeIdFromBinary(requestor.nodeId))
|
|
79
68
|
expect(successfulStorers.length).toBeGreaterThan(4)
|
|
80
|
-
|
|
81
69
|
const fetchingNode = getRandomNode()
|
|
82
|
-
const results = await fetchingNode.getDataFromDht(
|
|
83
|
-
results.forEach((
|
|
84
|
-
|
|
85
|
-
expect(
|
|
86
|
-
expect(areEqualPeerDescriptors(entry.creator!, requestor)).toBeTrue()
|
|
70
|
+
const results = await fetchingNode.getDataFromDht(entry.key)
|
|
71
|
+
results.forEach((result) => {
|
|
72
|
+
expectEqualData(result, entry)
|
|
73
|
+
expect(getNodeIdFromBinary(result.creator)).toEqual(getNodeIdFromPeerDescriptor(requestor))
|
|
87
74
|
})
|
|
88
75
|
}, 30000)
|
|
89
76
|
})
|
|
@@ -1,20 +1,17 @@
|
|
|
1
1
|
import { LatencyType, Simulator } from '../../src/connection/simulator/Simulator'
|
|
2
2
|
import { DhtNode } from '../../src/dht/DhtNode'
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { areEqualPeerDescriptors } from '../../src/helpers/peerIdFromPeerDescriptor'
|
|
6
|
-
import { Any } from '../../src/proto/google/protobuf/any'
|
|
3
|
+
import { createMockConnectionDhtNode, waitConnectionManagersReadyForTesting } from '../utils/utils'
|
|
4
|
+
import { createMockDataEntry, expectEqualData } from '../utils/mock/mockDataEntry'
|
|
7
5
|
import { createRandomNodeId } from '../../src/helpers/nodeId'
|
|
8
6
|
|
|
7
|
+
const NUM_NODES = 5
|
|
8
|
+
const MAX_CONNECTIONS = 5
|
|
9
|
+
const K = 4
|
|
10
|
+
|
|
9
11
|
describe('Storing data in DHT', () => {
|
|
10
|
-
|
|
12
|
+
|
|
11
13
|
let nodes: DhtNode[]
|
|
12
|
-
let entrypointDescriptor: PeerDescriptor
|
|
13
14
|
const simulator = new Simulator(LatencyType.REAL)
|
|
14
|
-
const NUM_NODES = 5
|
|
15
|
-
const MAX_CONNECTIONS = 5
|
|
16
|
-
const K = 4
|
|
17
|
-
const nodeIndicesById: Record<string, number> = {}
|
|
18
15
|
|
|
19
16
|
const getRandomNode = () => {
|
|
20
17
|
return nodes[Math.floor(Math.random() * nodes.length)]
|
|
@@ -22,21 +19,15 @@ describe('Storing data in DHT', () => {
|
|
|
22
19
|
|
|
23
20
|
beforeEach(async () => {
|
|
24
21
|
nodes = []
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
undefined, K, MAX_CONNECTIONS)
|
|
28
|
-
nodes.push(entryPoint)
|
|
29
|
-
nodeIndicesById[entryPoint.getNodeId().toKey()] = 0
|
|
30
|
-
entrypointDescriptor = entryPoint.getLocalPeerDescriptor()
|
|
22
|
+
const entryPoint = await createMockConnectionDhtNode(simulator,
|
|
23
|
+
createRandomNodeId(), K, MAX_CONNECTIONS)
|
|
31
24
|
nodes.push(entryPoint)
|
|
32
25
|
for (let i = 1; i < NUM_NODES; i++) {
|
|
33
|
-
const
|
|
34
|
-
const node = await createMockConnectionDhtNode(nodeId, simulator,
|
|
26
|
+
const node = await createMockConnectionDhtNode(simulator,
|
|
35
27
|
undefined, K, MAX_CONNECTIONS, 60000)
|
|
36
|
-
nodeIndicesById[node.getNodeId().toKey()] = i
|
|
37
28
|
nodes.push(node)
|
|
38
29
|
}
|
|
39
|
-
await Promise.all(nodes.map((node) => node.joinDht([
|
|
30
|
+
await Promise.all(nodes.map((node) => node.joinDht([entryPoint.getLocalPeerDescriptor()])))
|
|
40
31
|
await waitConnectionManagersReadyForTesting(nodes.map((node) => node.connectionManager!), MAX_CONNECTIONS)
|
|
41
32
|
}, 90000)
|
|
42
33
|
|
|
@@ -46,47 +37,36 @@ describe('Storing data in DHT', () => {
|
|
|
46
37
|
|
|
47
38
|
it('Data can be deleted', async () => {
|
|
48
39
|
const storingNode = getRandomNode()
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
const data = Any.pack(storedData, PeerDescriptor)
|
|
52
|
-
const successfulStorers = await storingNode.storeDataToDht(dataKey, data)
|
|
40
|
+
const entry = createMockDataEntry()
|
|
41
|
+
const successfulStorers = await storingNode.storeDataToDht(entry.key, entry.data!)
|
|
53
42
|
expect(successfulStorers.length).toBeGreaterThan(4)
|
|
54
|
-
await storingNode.deleteDataFromDht(
|
|
55
|
-
|
|
43
|
+
await storingNode.deleteDataFromDht(entry.key, true)
|
|
56
44
|
const fetchingNode = getRandomNode()
|
|
57
|
-
const results = await fetchingNode.getDataFromDht(
|
|
58
|
-
results.forEach((
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
expect(areEqualPeerDescriptors(fetchedDescriptor, storedData)).toBeTrue()
|
|
45
|
+
const results = await fetchingNode.getDataFromDht(entry.key)
|
|
46
|
+
results.forEach((result) => {
|
|
47
|
+
expect(result.deleted).toBeTrue()
|
|
48
|
+
expectEqualData(result, entry)
|
|
62
49
|
})
|
|
63
50
|
}, 90000)
|
|
64
51
|
|
|
65
52
|
it('Data can be deleted and re-stored', async () => {
|
|
66
53
|
const storingNode = getRandomNode()
|
|
67
|
-
const
|
|
68
|
-
const
|
|
69
|
-
const data = Any.pack(storedData, PeerDescriptor)
|
|
70
|
-
const successfulStorers1 = await storingNode.storeDataToDht(dataKey, data)
|
|
54
|
+
const entry = createMockDataEntry()
|
|
55
|
+
const successfulStorers1 = await storingNode.storeDataToDht(entry.key, entry.data!)
|
|
71
56
|
expect(successfulStorers1.length).toBeGreaterThan(4)
|
|
72
|
-
await storingNode.deleteDataFromDht(
|
|
73
|
-
|
|
57
|
+
await storingNode.deleteDataFromDht(entry.key, true)
|
|
74
58
|
const fetchingNode = getRandomNode()
|
|
75
|
-
const results1 = await fetchingNode.getDataFromDht(
|
|
76
|
-
results1.forEach((
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
expect(areEqualPeerDescriptors(fetchedDescriptor, storedData)).toBeTrue()
|
|
59
|
+
const results1 = await fetchingNode.getDataFromDht(entry.key)
|
|
60
|
+
results1.forEach((result) => {
|
|
61
|
+
expect(result.deleted).toBeTrue()
|
|
62
|
+
expectEqualData(result, entry)
|
|
80
63
|
})
|
|
81
|
-
|
|
82
|
-
const successfulStorers2 = await storingNode.storeDataToDht(dataKey, data)
|
|
64
|
+
const successfulStorers2 = await storingNode.storeDataToDht(entry.key, entry.data!)
|
|
83
65
|
expect(successfulStorers2.length).toBeGreaterThan(4)
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
expect(entry.deleted).toBeFalse()
|
|
89
|
-
expect(areEqualPeerDescriptors(fetchedDescriptor, storedData)).toBeTrue()
|
|
66
|
+
const results2 = await fetchingNode.getDataFromDht(entry.key)
|
|
67
|
+
results2.forEach((result) => {
|
|
68
|
+
expect(result.deleted).toBeFalse()
|
|
69
|
+
expectEqualData(result, entry)
|
|
90
70
|
})
|
|
91
71
|
}, 90000)
|
|
92
72
|
})
|
|
@@ -1,31 +1,19 @@
|
|
|
1
|
-
import { createMockConnectionDhtNode
|
|
1
|
+
import { createMockConnectionDhtNode } from '../utils/utils'
|
|
2
2
|
import { DhtNode } from '../../src/dht/DhtNode'
|
|
3
3
|
import { Simulator } from '../../src/connection/simulator/Simulator'
|
|
4
|
-
import { Any } from '../../src/proto/google/protobuf/any'
|
|
5
|
-
import { PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
6
|
-
import { areEqualPeerDescriptors } from '../../src/helpers/peerIdFromPeerDescriptor'
|
|
7
4
|
import { waitForCondition } from '@streamr/utils'
|
|
8
|
-
import {
|
|
5
|
+
import { createMockDataEntry, expectEqualData } from '../utils/mock/mockDataEntry'
|
|
9
6
|
|
|
10
7
|
describe('Storing data in DHT with two peers', () => {
|
|
11
8
|
|
|
12
9
|
let entryPoint: DhtNode
|
|
13
10
|
let otherNode: DhtNode
|
|
14
|
-
|
|
15
11
|
let simulator: Simulator | undefined
|
|
16
12
|
|
|
17
13
|
beforeEach(async () => {
|
|
18
14
|
simulator = new Simulator()
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
entryPoint = await createMockConnectionDhtNode(
|
|
22
|
-
entryPointId,
|
|
23
|
-
simulator,
|
|
24
|
-
)
|
|
25
|
-
otherNode = await createMockConnectionDhtNode(
|
|
26
|
-
otherNodeId,
|
|
27
|
-
simulator
|
|
28
|
-
)
|
|
15
|
+
entryPoint = await createMockConnectionDhtNode(simulator)
|
|
16
|
+
otherNode = await createMockConnectionDhtNode(simulator)
|
|
29
17
|
|
|
30
18
|
await entryPoint.start()
|
|
31
19
|
await otherNode.start()
|
|
@@ -41,31 +29,22 @@ describe('Storing data in DHT with two peers', () => {
|
|
|
41
29
|
})
|
|
42
30
|
|
|
43
31
|
it('Node can store on two peer DHT', async () => {
|
|
44
|
-
const storedData1 =
|
|
45
|
-
const storedData2 =
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
await entryPoint.storeDataToDht(dataKey2, data2)
|
|
53
|
-
|
|
54
|
-
const foundData1 = await otherNode.getDataFromDht(dataKey1)
|
|
55
|
-
const foundData2 = await entryPoint.getDataFromDht(dataKey2)
|
|
56
|
-
expect(areEqualPeerDescriptors(storedData1, Any.unpack(foundData1[0]!.data!, PeerDescriptor))).toBeTrue()
|
|
57
|
-
expect(areEqualPeerDescriptors(storedData2, Any.unpack(foundData2[0]!.data!, PeerDescriptor))).toBeTrue()
|
|
32
|
+
const storedData1 = createMockDataEntry()
|
|
33
|
+
const storedData2 = createMockDataEntry()
|
|
34
|
+
await otherNode.storeDataToDht(storedData1.key, storedData1.data!)
|
|
35
|
+
await entryPoint.storeDataToDht(storedData2.key, storedData2.data!)
|
|
36
|
+
const foundData1 = await otherNode.getDataFromDht(storedData1.key)
|
|
37
|
+
const foundData2 = await entryPoint.getDataFromDht(storedData2.key)
|
|
38
|
+
expectEqualData(foundData1[0], storedData1)
|
|
39
|
+
expectEqualData(foundData2[0], storedData2)
|
|
58
40
|
})
|
|
59
41
|
|
|
60
42
|
it('Can store on one peer DHT', async () => {
|
|
61
43
|
await otherNode.stop()
|
|
62
44
|
await waitForCondition(() => entryPoint.getNumberOfNeighbors() === 0)
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const foundData = await entryPoint.getDataFromDht(dataKey)
|
|
69
|
-
expect(areEqualPeerDescriptors(storedData, Any.unpack(foundData[0]!.data!, PeerDescriptor))).toBeTrue()
|
|
45
|
+
const storedData = createMockDataEntry()
|
|
46
|
+
await entryPoint.storeDataToDht(storedData.key, storedData.data!)
|
|
47
|
+
const foundData = await entryPoint.getDataFromDht(storedData.key)
|
|
48
|
+
expectEqualData(foundData[0], storedData)
|
|
70
49
|
}, 60000)
|
|
71
50
|
})
|