@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,34 +1,30 @@
|
|
|
1
|
-
import { RpcCommunicator
|
|
1
|
+
import { RpcCommunicator } from '@streamr/proto-rpc'
|
|
2
2
|
import {
|
|
3
|
-
NodeType,
|
|
4
|
-
PeerDescriptor,
|
|
5
3
|
StoreDataRequest,
|
|
6
4
|
StoreDataResponse
|
|
7
5
|
} from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
8
|
-
import {
|
|
6
|
+
import { createMockPeerDescriptor, mockStoreRpc } from '../utils/utils'
|
|
9
7
|
import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
|
|
10
8
|
import { StoreRpcClient } from '../../src/proto/packages/dht/protos/DhtRpc.client'
|
|
11
9
|
import { StoreRpcRemote } from '../../src/dht/store/StoreRpcRemote'
|
|
12
|
-
import {
|
|
10
|
+
import { createMockDataEntry } from '../utils/mock/mockDataEntry'
|
|
11
|
+
import { getNodeIdFromPeerDescriptor } from '../../src/helpers/peerIdFromPeerDescriptor'
|
|
12
|
+
import { createRandomNodeId } from '../../src/helpers/nodeId'
|
|
13
|
+
|
|
14
|
+
const SERVICE_ID = 'test'
|
|
13
15
|
|
|
14
16
|
describe('StoreRpcRemote', () => {
|
|
15
17
|
|
|
16
18
|
let rpcRemote: StoreRpcRemote
|
|
17
19
|
let clientRpcCommunicator: RpcCommunicator
|
|
18
20
|
let serverRpcCommunicator: RpcCommunicator
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
type: NodeType.NODEJS
|
|
23
|
-
}
|
|
24
|
-
const serverPeerDescriptor: PeerDescriptor = {
|
|
25
|
-
nodeId: generateId('server'),
|
|
26
|
-
type: NodeType.NODEJS
|
|
27
|
-
}
|
|
28
|
-
const data = Any.pack(clientPeerDescriptor, PeerDescriptor)
|
|
21
|
+
const clientPeerDescriptor = createMockPeerDescriptor()
|
|
22
|
+
const serverPeerDescriptor = createMockPeerDescriptor()
|
|
23
|
+
const data = createMockDataEntry()
|
|
29
24
|
const request: StoreDataRequest = {
|
|
30
|
-
key:
|
|
31
|
-
data,
|
|
25
|
+
key: data.key,
|
|
26
|
+
data: data.data,
|
|
27
|
+
creator: createRandomNodeId(),
|
|
32
28
|
ttl: 10
|
|
33
29
|
}
|
|
34
30
|
|
|
@@ -42,25 +38,19 @@ describe('StoreRpcRemote', () => {
|
|
|
42
38
|
serverRpcCommunicator.on('outgoingMessage', (message: RpcMessage) => {
|
|
43
39
|
clientRpcCommunicator.handleIncomingMessage(message)
|
|
44
40
|
})
|
|
45
|
-
|
|
46
|
-
rpcRemote = new StoreRpcRemote(clientPeerDescriptor, serverPeerDescriptor, serviceId, client)
|
|
41
|
+
rpcRemote = new StoreRpcRemote(clientPeerDescriptor, serverPeerDescriptor, SERVICE_ID, clientRpcCommunicator, StoreRpcClient)
|
|
47
42
|
})
|
|
48
43
|
|
|
49
44
|
it('storeData happy path', async () => {
|
|
50
|
-
|
|
51
|
-
expect(response.error).toBeEmpty()
|
|
45
|
+
await expect(rpcRemote.storeData(request)).toResolve()
|
|
52
46
|
})
|
|
53
47
|
|
|
54
48
|
it('storeData rejects', async () => {
|
|
55
49
|
serverRpcCommunicator.registerRpcMethod(StoreDataRequest, StoreDataResponse, 'storeData', mockStoreRpc.throwStoreDataError)
|
|
56
|
-
await expect(rpcRemote.storeData(request))
|
|
57
|
-
|
|
50
|
+
await expect(rpcRemote.storeData(request)).rejects.toThrowError(
|
|
51
|
+
'Could not store data to'
|
|
52
|
+
+ ` ${getNodeIdFromPeerDescriptor(serverPeerDescriptor)} from ${getNodeIdFromPeerDescriptor(clientPeerDescriptor)}`
|
|
53
|
+
+ ' Error: Mock'
|
|
54
|
+
)
|
|
58
55
|
})
|
|
59
|
-
|
|
60
|
-
it('storeData response error', async () => {
|
|
61
|
-
serverRpcCommunicator.registerRpcMethod(StoreDataRequest, StoreDataResponse, 'storeData', mockStoreRpc.storeDataErrorString)
|
|
62
|
-
const response = await rpcRemote.storeData(request)
|
|
63
|
-
expect(response.error).toEqual('Mock')
|
|
64
|
-
})
|
|
65
|
-
|
|
66
56
|
})
|
|
@@ -2,13 +2,13 @@ import { ConnectionManager } from '../../src/connection/ConnectionManager'
|
|
|
2
2
|
import { LatencyType, Simulator } from '../../src/connection/simulator/Simulator'
|
|
3
3
|
import { Message, MessageType, NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
4
4
|
import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
|
|
5
|
-
import { PeerID } from '../../src/helpers/PeerID'
|
|
6
5
|
import { ConnectionType } from '../../src/connection/IConnection'
|
|
7
6
|
import { ITransport } from '../../src/transport/ITransport'
|
|
8
7
|
import * as Err from '../../src/helpers/errors'
|
|
9
8
|
import { SimulatorTransport } from '../../src/connection/simulator/SimulatorTransport'
|
|
10
9
|
import { DefaultConnectorFacade } from '../../src/connection/ConnectorFacade'
|
|
11
10
|
import { MetricsContext } from '@streamr/utils'
|
|
11
|
+
import { createMockPeerDescriptor } from '../utils/utils'
|
|
12
12
|
|
|
13
13
|
const createConnectionManager = (localPeerDescriptor: PeerDescriptor, transport: ITransport) => {
|
|
14
14
|
return new ConnectionManager({
|
|
@@ -24,19 +24,9 @@ describe('WebRTC Connection Management', () => {
|
|
|
24
24
|
|
|
25
25
|
let manager1: ConnectionManager
|
|
26
26
|
let manager2: ConnectionManager
|
|
27
|
-
|
|
28
27
|
let simulator: Simulator
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
nodeId: PeerID.fromString('peer1').value,
|
|
32
|
-
type: NodeType.NODEJS,
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const peerDescriptor2: PeerDescriptor = {
|
|
36
|
-
nodeId: PeerID.fromString('peer2').value,
|
|
37
|
-
type: NodeType.NODEJS,
|
|
38
|
-
}
|
|
39
|
-
|
|
28
|
+
const peerDescriptor1 = createMockPeerDescriptor()
|
|
29
|
+
const peerDescriptor2 = createMockPeerDescriptor()
|
|
40
30
|
let connectorTransport1: SimulatorTransport
|
|
41
31
|
let connectorTransport2: SimulatorTransport
|
|
42
32
|
|
|
@@ -2,32 +2,26 @@ import { ProtoRpcClient, RpcCommunicator, toProtoRpcClient } from '@streamr/prot
|
|
|
2
2
|
import { WebrtcConnectorRpcClient } from '../../src/proto/packages/dht/protos/DhtRpc.client'
|
|
3
3
|
import {
|
|
4
4
|
IceCandidate,
|
|
5
|
-
NodeType,
|
|
6
|
-
PeerDescriptor,
|
|
7
5
|
RtcAnswer,
|
|
8
6
|
RtcOffer,
|
|
9
7
|
WebrtcConnectionRequest
|
|
10
8
|
} from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
11
9
|
import { Empty } from '../../src/proto/google/protobuf/empty'
|
|
12
|
-
import {
|
|
10
|
+
import { createMockPeerDescriptor } from '../utils/utils'
|
|
13
11
|
import { IWebrtcConnectorRpc } from '../../src/proto/packages/dht/protos/DhtRpc.server'
|
|
14
12
|
import { waitForCondition } from '@streamr/utils'
|
|
15
13
|
import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
|
|
16
14
|
|
|
17
15
|
describe('WebRTC rpc messages', () => {
|
|
16
|
+
|
|
18
17
|
let rpcCommunicator1: RpcCommunicator
|
|
19
18
|
let rpcCommunicator2: RpcCommunicator
|
|
20
19
|
let client: ProtoRpcClient<WebrtcConnectorRpcClient>
|
|
21
|
-
|
|
22
20
|
let requestConnectionCounter: number
|
|
23
21
|
let rtcOfferCounter: number
|
|
24
22
|
let rtcAnswerCounter: number
|
|
25
23
|
let iceCandidateCounter: number
|
|
26
|
-
|
|
27
|
-
const targetDescriptor: PeerDescriptor = {
|
|
28
|
-
nodeId: generateId('peer'),
|
|
29
|
-
type: NodeType.NODEJS
|
|
30
|
-
}
|
|
24
|
+
const targetDescriptor = createMockPeerDescriptor()
|
|
31
25
|
|
|
32
26
|
beforeEach(() => {
|
|
33
27
|
requestConnectionCounter = 0
|
|
@@ -12,6 +12,8 @@ import { Message, MessageType, NodeType, PeerDescriptor } from '../../src/proto/
|
|
|
12
12
|
import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
|
|
13
13
|
import { TransportEvents } from '../../src/transport/ITransport'
|
|
14
14
|
|
|
15
|
+
const SERVICE_ID = 'test'
|
|
16
|
+
|
|
15
17
|
const createConfig = (localPeerDescriptor: PeerDescriptor, opts: Omit<DefaultConnectorFacadeConfig, 'createLocalPeerDescriptor'>) => {
|
|
16
18
|
return {
|
|
17
19
|
createConnectorFacade: () => new DefaultConnectorFacade({
|
|
@@ -24,13 +26,10 @@ const createConfig = (localPeerDescriptor: PeerDescriptor, opts: Omit<DefaultCon
|
|
|
24
26
|
|
|
25
27
|
describe('Websocket Connection Management', () => {
|
|
26
28
|
|
|
27
|
-
const serviceId = 'test'
|
|
28
29
|
let wsServerManager: ConnectionManager
|
|
29
30
|
let noWsServerManager: ConnectionManager
|
|
30
31
|
let biggerNoWsServerManager: ConnectionManager
|
|
31
|
-
|
|
32
32
|
const simulator = new Simulator()
|
|
33
|
-
|
|
34
33
|
const wsServerConnectorPeerDescriptor: PeerDescriptor = {
|
|
35
34
|
nodeId: PeerID.fromString('2').value,
|
|
36
35
|
type: NodeType.NODEJS,
|
|
@@ -40,12 +39,10 @@ describe('Websocket Connection Management', () => {
|
|
|
40
39
|
tls: false
|
|
41
40
|
}
|
|
42
41
|
}
|
|
43
|
-
|
|
44
42
|
const noWsServerConnectorPeerDescriptor: PeerDescriptor = {
|
|
45
43
|
nodeId: PeerID.fromString('1').value,
|
|
46
44
|
type: NodeType.NODEJS,
|
|
47
45
|
}
|
|
48
|
-
|
|
49
46
|
const biggerNoWsServerConnectorPeerDescriptor: PeerDescriptor = {
|
|
50
47
|
nodeId: PeerID.fromString('3').value,
|
|
51
48
|
type: NodeType.NODEJS,
|
|
@@ -96,7 +93,7 @@ describe('Websocket Connection Management', () => {
|
|
|
96
93
|
|
|
97
94
|
it('Can open connections to serverless peer with smaller peerId', (done) => {
|
|
98
95
|
const dummyMessage: Message = {
|
|
99
|
-
serviceId,
|
|
96
|
+
serviceId: SERVICE_ID,
|
|
100
97
|
body: {
|
|
101
98
|
oneofKind: 'rpcMessage',
|
|
102
99
|
rpcMessage: RpcMessage.create()
|
|
@@ -118,7 +115,7 @@ describe('Websocket Connection Management', () => {
|
|
|
118
115
|
|
|
119
116
|
it('Can open connections to serverless peer with bigger peerId', (done) => {
|
|
120
117
|
const dummyMessage: Message = {
|
|
121
|
-
serviceId,
|
|
118
|
+
serviceId: SERVICE_ID,
|
|
122
119
|
body: {
|
|
123
120
|
oneofKind: 'rpcMessage',
|
|
124
121
|
rpcMessage: RpcMessage.create()
|
|
@@ -140,7 +137,7 @@ describe('Websocket Connection Management', () => {
|
|
|
140
137
|
|
|
141
138
|
it('Failed connection requests are cleaned up', async () => {
|
|
142
139
|
const dummyMessage: Message = {
|
|
143
|
-
serviceId,
|
|
140
|
+
serviceId: SERVICE_ID,
|
|
144
141
|
body: {
|
|
145
142
|
oneofKind: 'rpcMessage',
|
|
146
143
|
rpcMessage: RpcMessage.create()
|
|
@@ -162,7 +159,7 @@ describe('Websocket Connection Management', () => {
|
|
|
162
159
|
|
|
163
160
|
it('Can open connections to peer with server', async () => {
|
|
164
161
|
const dummyMessage: Message = {
|
|
165
|
-
serviceId,
|
|
162
|
+
serviceId: SERVICE_ID,
|
|
166
163
|
body: {
|
|
167
164
|
oneofKind: 'rpcMessage',
|
|
168
165
|
rpcMessage: RpcMessage.create()
|
|
@@ -185,7 +182,7 @@ describe('Websocket Connection Management', () => {
|
|
|
185
182
|
|
|
186
183
|
it('Connecting to self throws', async () => {
|
|
187
184
|
const dummyMessage: Message = {
|
|
188
|
-
serviceId,
|
|
185
|
+
serviceId: SERVICE_ID,
|
|
189
186
|
body: {
|
|
190
187
|
oneofKind: 'rpcMessage',
|
|
191
188
|
rpcMessage: RpcMessage.create()
|
|
@@ -1,36 +1,27 @@
|
|
|
1
1
|
import { ProtoRpcClient, RpcCommunicator, toProtoRpcClient } from '@streamr/proto-rpc'
|
|
2
2
|
import { WebsocketConnectorRpcClient } from '../../src/proto/packages/dht/protos/DhtRpc.client'
|
|
3
|
-
import {
|
|
3
|
+
import { createMockPeerDescriptor } from '../utils/utils'
|
|
4
4
|
import {
|
|
5
|
-
|
|
6
|
-
PeerDescriptor,
|
|
7
|
-
WebsocketConnectionRequest,
|
|
8
|
-
WebsocketConnectionResponse
|
|
5
|
+
WebsocketConnectionRequest
|
|
9
6
|
} from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
10
7
|
import { mockWebsocketConnectorRpc } from '../utils/utils'
|
|
11
8
|
import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
|
|
9
|
+
import { Empty } from '../../src/proto/google/protobuf/empty'
|
|
12
10
|
|
|
13
11
|
describe('WebsocketConnectorRpc', () => {
|
|
12
|
+
|
|
14
13
|
let rpcCommunicator1: RpcCommunicator
|
|
15
14
|
let rpcCommunicator2: RpcCommunicator
|
|
16
15
|
let client1: ProtoRpcClient<WebsocketConnectorRpcClient>
|
|
17
16
|
let client2: ProtoRpcClient<WebsocketConnectorRpcClient>
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
nodeId: generateId('peer1'),
|
|
21
|
-
type: NodeType.NODEJS
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const peerDescriptor2: PeerDescriptor = {
|
|
25
|
-
nodeId: generateId('peer2'),
|
|
26
|
-
type: NodeType.NODEJS
|
|
27
|
-
}
|
|
17
|
+
const peerDescriptor1 = createMockPeerDescriptor()
|
|
18
|
+
const peerDescriptor2 = createMockPeerDescriptor()
|
|
28
19
|
|
|
29
20
|
beforeEach(() => {
|
|
30
21
|
rpcCommunicator1 = new RpcCommunicator()
|
|
31
22
|
rpcCommunicator1.registerRpcMethod(
|
|
32
23
|
WebsocketConnectionRequest,
|
|
33
|
-
|
|
24
|
+
Empty,
|
|
34
25
|
'requestConnection',
|
|
35
26
|
mockWebsocketConnectorRpc.requestConnection
|
|
36
27
|
)
|
|
@@ -38,7 +29,7 @@ describe('WebsocketConnectorRpc', () => {
|
|
|
38
29
|
rpcCommunicator2 = new RpcCommunicator()
|
|
39
30
|
rpcCommunicator2.registerRpcMethod(
|
|
40
31
|
WebsocketConnectionRequest,
|
|
41
|
-
|
|
32
|
+
Empty,
|
|
42
33
|
'requestConnection',
|
|
43
34
|
mockWebsocketConnectorRpc.requestConnection
|
|
44
35
|
)
|
|
@@ -1,38 +1,30 @@
|
|
|
1
1
|
import { NodeType } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
2
2
|
import { expectedConnectionType } from '../../src/helpers/Connectivity'
|
|
3
3
|
import { ConnectionType } from '../../src/connection/IConnection'
|
|
4
|
+
import { createMockPeerDescriptor } from '../utils/utils'
|
|
4
5
|
|
|
5
6
|
describe('Connectivity helpers', () => {
|
|
6
7
|
|
|
7
|
-
const tlsServerPeerDescriptor = {
|
|
8
|
-
nodeId: new Uint8Array(1),
|
|
9
|
-
type: NodeType.NODEJS,
|
|
8
|
+
const tlsServerPeerDescriptor = createMockPeerDescriptor({
|
|
10
9
|
websocket: {
|
|
11
10
|
host: 'mock',
|
|
12
11
|
port: 1234,
|
|
13
12
|
tls: true
|
|
14
13
|
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const noTlsServerPeerDescriptor = {
|
|
18
|
-
nodeId: new Uint8Array(1),
|
|
19
|
-
type: NodeType.NODEJS,
|
|
14
|
+
})
|
|
15
|
+
const noTlsServerPeerDescriptor = createMockPeerDescriptor({
|
|
20
16
|
websocket: {
|
|
21
17
|
host: 'mock',
|
|
22
18
|
port: 1234,
|
|
23
19
|
tls: false
|
|
24
20
|
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const browserPeerDescriptor = {
|
|
28
|
-
nodeId: new Uint8Array(2),
|
|
21
|
+
})
|
|
22
|
+
const browserPeerDescriptor = createMockPeerDescriptor({
|
|
29
23
|
type: NodeType.BROWSER
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const noServerPeerDescriptor = {
|
|
33
|
-
nodeId: new Uint8Array(3),
|
|
24
|
+
})
|
|
25
|
+
const noServerPeerDescriptor = createMockPeerDescriptor({
|
|
34
26
|
type: NodeType.NODEJS
|
|
35
|
-
}
|
|
27
|
+
})
|
|
36
28
|
|
|
37
29
|
it('two server peers', () => {
|
|
38
30
|
expect(expectedConnectionType(tlsServerPeerDescriptor, tlsServerPeerDescriptor)).toBe(ConnectionType.WEBSOCKET_CLIENT)
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { DuplicateDetector } from '../../src/dht/routing/DuplicateDetector'
|
|
2
2
|
|
|
3
|
+
const MAX_VALUE_COUNT = 10
|
|
4
|
+
|
|
3
5
|
describe('Duplicate Detector', () => {
|
|
6
|
+
|
|
4
7
|
let detector: DuplicateDetector
|
|
5
|
-
|
|
8
|
+
|
|
6
9
|
beforeEach(async () => {
|
|
7
|
-
detector = new DuplicateDetector(
|
|
10
|
+
detector = new DuplicateDetector(MAX_VALUE_COUNT, 100)
|
|
8
11
|
})
|
|
9
12
|
|
|
10
13
|
it('detects duplicates', async () => {
|
|
@@ -14,10 +17,10 @@ describe('Duplicate Detector', () => {
|
|
|
14
17
|
})
|
|
15
18
|
|
|
16
19
|
it('resets on resetLimit', () => {
|
|
17
|
-
for (let i = 0; i <
|
|
20
|
+
for (let i = 0; i < MAX_VALUE_COUNT; i++) {
|
|
18
21
|
detector.add(`test${i}`)
|
|
19
22
|
}
|
|
20
|
-
for (let i = 0; i <
|
|
23
|
+
for (let i = 0; i < MAX_VALUE_COUNT; i++) {
|
|
21
24
|
expect(detector.isMostLikelyDuplicate(`test${i}`)).toEqual(true)
|
|
22
25
|
}
|
|
23
26
|
detector.add('test10')
|
|
@@ -1,29 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { wait } from '@streamr/utils'
|
|
2
|
+
import { LocalDataStore } from '../../src/dht/store/LocalDataStore'
|
|
3
3
|
import {
|
|
4
|
-
|
|
5
|
-
keyFromPeerDescriptor,
|
|
4
|
+
getNodeIdFromPeerDescriptor,
|
|
6
5
|
peerIdFromPeerDescriptor
|
|
7
6
|
} from '../../src/helpers/peerIdFromPeerDescriptor'
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
7
|
+
import { createMockPeerDescriptor } from '../utils/utils'
|
|
8
|
+
import { createMockDataEntry, expectEqualData } from '../utils/mock/mockDataEntry'
|
|
9
|
+
import { createRandomNodeId, getNodeIdFromBinary } from '../../src/helpers/nodeId'
|
|
11
10
|
|
|
12
11
|
describe('LocalDataStore', () => {
|
|
12
|
+
|
|
13
13
|
let localDataStore: LocalDataStore
|
|
14
|
-
const creator1: PeerDescriptor = {
|
|
15
|
-
nodeId: new Uint8Array([1, 2, 3]),
|
|
16
|
-
type: NodeType.NODEJS
|
|
17
|
-
}
|
|
18
|
-
const creator2: PeerDescriptor = {
|
|
19
|
-
nodeId: new Uint8Array([3, 2, 1]),
|
|
20
|
-
type: NodeType.NODEJS
|
|
21
|
-
}
|
|
22
|
-
const data1 = Any.pack(creator1, PeerDescriptor)
|
|
23
|
-
const data2 = Any.pack(creator2, PeerDescriptor)
|
|
24
14
|
|
|
15
|
+
const getEntryArray = (key: Uint8Array) => {
|
|
16
|
+
return Array.from(localDataStore.getEntries(key).values())
|
|
17
|
+
}
|
|
18
|
+
|
|
25
19
|
beforeEach(() => {
|
|
26
|
-
localDataStore = new LocalDataStore()
|
|
20
|
+
localDataStore = new LocalDataStore(30 * 1000)
|
|
27
21
|
})
|
|
28
22
|
|
|
29
23
|
afterEach(() => {
|
|
@@ -31,91 +25,86 @@ describe('LocalDataStore', () => {
|
|
|
31
25
|
})
|
|
32
26
|
|
|
33
27
|
it('can store', () => {
|
|
34
|
-
const
|
|
35
|
-
localDataStore.storeEntry(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const fetchedDescriptor = Any.unpack(entry.data!, PeerDescriptor)
|
|
40
|
-
expect(areEqualPeerDescriptors(fetchedDescriptor, creator1)).toBeTrue()
|
|
41
|
-
})
|
|
28
|
+
const storedEntry = createMockDataEntry()
|
|
29
|
+
localDataStore.storeEntry(storedEntry)
|
|
30
|
+
const fetchedEntries = getEntryArray(storedEntry.key)
|
|
31
|
+
expect(fetchedEntries).toHaveLength(1)
|
|
32
|
+
expectEqualData(fetchedEntries[0], storedEntry)
|
|
42
33
|
})
|
|
43
34
|
|
|
44
35
|
it('multiple storers behind one key', () => {
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
36
|
+
const creator1 = createRandomNodeId()
|
|
37
|
+
const creator2 = createRandomNodeId()
|
|
38
|
+
const key = createRandomNodeId()
|
|
39
|
+
const storedEntry1 = createMockDataEntry({ key, creator: creator1 })
|
|
40
|
+
const storedEntry2 = createMockDataEntry({ key, creator: creator2 })
|
|
41
|
+
localDataStore.storeEntry(storedEntry1)
|
|
42
|
+
localDataStore.storeEntry(storedEntry2)
|
|
43
|
+
const fetchedEntries = localDataStore.getEntries(key)
|
|
44
|
+
expect(fetchedEntries.size).toBe(2)
|
|
45
|
+
expectEqualData(fetchedEntries.get(getNodeIdFromBinary(creator1))!, storedEntry1)
|
|
46
|
+
expectEqualData(fetchedEntries.get(getNodeIdFromBinary(creator2))!, storedEntry2)
|
|
55
47
|
})
|
|
56
48
|
|
|
57
49
|
it('can remove data entries', () => {
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
localDataStore.
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
50
|
+
const creator1 = createRandomNodeId()
|
|
51
|
+
const creator2 = createRandomNodeId()
|
|
52
|
+
const key = createRandomNodeId()
|
|
53
|
+
const storedEntry1 = createMockDataEntry({ key, creator: creator1 })
|
|
54
|
+
const storedEntry2 = createMockDataEntry({ key, creator: creator2 })
|
|
55
|
+
localDataStore.storeEntry(storedEntry1)
|
|
56
|
+
localDataStore.storeEntry(storedEntry2)
|
|
57
|
+
localDataStore.deleteEntry(key, getNodeIdFromBinary(creator1))
|
|
58
|
+
const fetchedEntries = getEntryArray(key)
|
|
59
|
+
expect(fetchedEntries).toHaveLength(1)
|
|
60
|
+
expectEqualData(fetchedEntries[0], storedEntry2)
|
|
69
61
|
})
|
|
70
62
|
|
|
71
63
|
it('can remove all data entries', () => {
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
localDataStore.
|
|
78
|
-
localDataStore.
|
|
79
|
-
|
|
80
|
-
|
|
64
|
+
const creator1 = createRandomNodeId()
|
|
65
|
+
const creator2 = createRandomNodeId()
|
|
66
|
+
const key = createRandomNodeId()
|
|
67
|
+
const storedEntry1 = createMockDataEntry({ key, creator: creator1 })
|
|
68
|
+
const storedEntry2 = createMockDataEntry({ key, creator: creator2 })
|
|
69
|
+
localDataStore.storeEntry(storedEntry1)
|
|
70
|
+
localDataStore.storeEntry(storedEntry2)
|
|
71
|
+
localDataStore.deleteEntry(key, getNodeIdFromBinary(creator1))
|
|
72
|
+
localDataStore.deleteEntry(key, getNodeIdFromBinary(creator2))
|
|
73
|
+
expect(getEntryArray(key)).toHaveLength(0)
|
|
81
74
|
})
|
|
82
75
|
|
|
83
76
|
it('data is deleted after TTL', async () => {
|
|
84
|
-
const
|
|
85
|
-
localDataStore.storeEntry(
|
|
86
|
-
|
|
87
|
-
const intitialStore = localDataStore.getEntry(dataKey)
|
|
88
|
-
expect(intitialStore.size).toBe(1)
|
|
77
|
+
const storedEntry = createMockDataEntry({ ttl: 1000 })
|
|
78
|
+
localDataStore.storeEntry(storedEntry)
|
|
79
|
+
expect(getEntryArray(storedEntry.key)).toHaveLength(1)
|
|
89
80
|
await wait(1100)
|
|
90
|
-
|
|
91
|
-
expect(fetchedData.size).toBe(0)
|
|
81
|
+
expect(getEntryArray(storedEntry.key)).toHaveLength(0)
|
|
92
82
|
})
|
|
93
83
|
|
|
94
84
|
describe('mark data as deleted', () => {
|
|
95
85
|
|
|
96
86
|
it('happy path', () => {
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const notDeletedData = localDataStore.
|
|
101
|
-
expect(notDeletedData.get(
|
|
102
|
-
const returnValue = localDataStore.markAsDeleted(
|
|
87
|
+
const creator1 = createRandomNodeId()
|
|
88
|
+
const storedEntry = createMockDataEntry({ creator: creator1 })
|
|
89
|
+
localDataStore.storeEntry(storedEntry)
|
|
90
|
+
const notDeletedData = localDataStore.getEntries(storedEntry.key)
|
|
91
|
+
expect(notDeletedData.get(getNodeIdFromBinary(creator1))!.deleted).toBeFalse()
|
|
92
|
+
const returnValue = localDataStore.markAsDeleted(storedEntry.key, getNodeIdFromBinary(creator1))
|
|
103
93
|
expect(returnValue).toBe(true)
|
|
104
|
-
const deletedData = localDataStore.
|
|
105
|
-
expect(deletedData.get(
|
|
94
|
+
const deletedData = localDataStore.getEntries(storedEntry.key)
|
|
95
|
+
expect(deletedData.get(getNodeIdFromBinary(creator1))!.deleted).toBeTrue()
|
|
106
96
|
})
|
|
107
97
|
|
|
108
98
|
it('data not stored', () => {
|
|
109
|
-
const dataKey = peerIdFromPeerDescriptor(
|
|
110
|
-
const returnValue = localDataStore.markAsDeleted(dataKey.value,
|
|
99
|
+
const dataKey = peerIdFromPeerDescriptor(createMockPeerDescriptor())
|
|
100
|
+
const returnValue = localDataStore.markAsDeleted(dataKey.value, getNodeIdFromPeerDescriptor(createMockPeerDescriptor()))
|
|
111
101
|
expect(returnValue).toBe(false)
|
|
112
102
|
})
|
|
113
103
|
|
|
114
104
|
it('data not stored by the given creator', () => {
|
|
115
|
-
const
|
|
116
|
-
localDataStore.storeEntry(
|
|
117
|
-
|
|
118
|
-
const returnValue = localDataStore.markAsDeleted(dataKey.value, peerIdFromPeerDescriptor(creator2))
|
|
105
|
+
const storedEntry = createMockDataEntry()
|
|
106
|
+
localDataStore.storeEntry(storedEntry)
|
|
107
|
+
const returnValue = localDataStore.markAsDeleted(storedEntry.key, getNodeIdFromPeerDescriptor(createMockPeerDescriptor()))
|
|
119
108
|
expect(returnValue).toBe(false)
|
|
120
109
|
})
|
|
121
110
|
})
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { hexToBinary } from '@streamr/utils'
|
|
2
|
+
import { PeerManager, getDistance } from '../../src/dht/PeerManager'
|
|
3
|
+
import { NodeID, createRandomNodeId, getNodeIdFromBinary } from '../../src/helpers/nodeId'
|
|
4
|
+
import { NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
5
|
+
import { range, sampleSize, sortBy, without } from 'lodash'
|
|
6
|
+
import { DhtNodeRpcRemote } from '../../src/dht/DhtNodeRpcRemote'
|
|
7
|
+
import { MockRpcCommunicator } from '../utils/mock/MockRpcCommunicator'
|
|
8
|
+
|
|
9
|
+
describe('PeerManager', () => {
|
|
10
|
+
|
|
11
|
+
it('getClosestContactsTo', () => {
|
|
12
|
+
const nodeIds = range(10).map(() => getNodeIdFromBinary(createRandomNodeId()))
|
|
13
|
+
const manager = new PeerManager({
|
|
14
|
+
localNodeId: getNodeIdFromBinary(createRandomNodeId()),
|
|
15
|
+
createDhtNodeRpcRemote: (peerDescriptor: PeerDescriptor) => {
|
|
16
|
+
return new DhtNodeRpcRemote(undefined as any, peerDescriptor, undefined as any, new MockRpcCommunicator())
|
|
17
|
+
}
|
|
18
|
+
} as any)
|
|
19
|
+
manager.handleNewPeers(nodeIds.map((n) => ({ nodeId: hexToBinary(n), type: NodeType.NODEJS })))
|
|
20
|
+
|
|
21
|
+
const referenceId = getNodeIdFromBinary(createRandomNodeId())
|
|
22
|
+
const excluded = new Set<NodeID>(sampleSize(nodeIds, 2)!)
|
|
23
|
+
const actual = manager.getClosestContactsTo(referenceId, 5, excluded)
|
|
24
|
+
|
|
25
|
+
const expected = sortBy(
|
|
26
|
+
without(nodeIds, ...Array.from(excluded.values())),
|
|
27
|
+
(n: NodeID) => getDistance(n, referenceId)
|
|
28
|
+
).slice(0, 5)
|
|
29
|
+
expect(actual.map((n) => n.getNodeId())).toEqual(expected)
|
|
30
|
+
})
|
|
31
|
+
})
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { RandomContactList } from '../../src/dht/contact/RandomContactList'
|
|
2
2
|
import { PeerID } from '../../src/helpers/PeerID'
|
|
3
|
+
import { NodeID, getNodeIdFromBinary } from '../../src/helpers/nodeId'
|
|
3
4
|
|
|
4
|
-
const createItem = (nodeId: Uint8Array): { getPeerId: () => PeerID } => {
|
|
5
|
-
return {
|
|
5
|
+
const createItem = (nodeId: Uint8Array): { getNodeId: () => NodeID, getPeerId: () => PeerID } => {
|
|
6
|
+
return {
|
|
7
|
+
getNodeId: () => getNodeIdFromBinary(nodeId),
|
|
8
|
+
getPeerId: () => PeerID.fromValue(nodeId)
|
|
9
|
+
}
|
|
6
10
|
}
|
|
7
11
|
|
|
8
12
|
describe('RandomContactList', () => {
|
|
13
|
+
|
|
9
14
|
const item0 = createItem(new Uint8Array([0, 0, 0, 0]))
|
|
10
15
|
const item1 = createItem(new Uint8Array([0, 0, 0, 1]))
|
|
11
16
|
const item2 = createItem(new Uint8Array([0, 0, 0, 2]))
|
|
@@ -13,7 +18,7 @@ describe('RandomContactList', () => {
|
|
|
13
18
|
const item4 = createItem(new Uint8Array([0, 0, 0, 4]))
|
|
14
19
|
|
|
15
20
|
it('adds contacts correctly', () => {
|
|
16
|
-
const list = new RandomContactList(item0.
|
|
21
|
+
const list = new RandomContactList(item0.getNodeId(), 5, 1)
|
|
17
22
|
list.addContact(item1)
|
|
18
23
|
list.addContact(item2)
|
|
19
24
|
list.addContact(item3)
|
|
@@ -27,15 +32,15 @@ describe('RandomContactList', () => {
|
|
|
27
32
|
})
|
|
28
33
|
|
|
29
34
|
it('removes contacts correctly', () => {
|
|
30
|
-
const list = new RandomContactList(item0.
|
|
35
|
+
const list = new RandomContactList(item0.getNodeId(), 5, 1)
|
|
31
36
|
list.addContact(item1)
|
|
32
37
|
list.addContact(item2)
|
|
33
38
|
list.addContact(item3)
|
|
34
39
|
list.addContact(item4)
|
|
35
|
-
list.removeContact(item2.
|
|
36
|
-
expect(list.getContact(item1.
|
|
37
|
-
expect(list.getContact(item3.
|
|
38
|
-
expect(list.getContact(item4.
|
|
40
|
+
list.removeContact(item2.getNodeId())
|
|
41
|
+
expect(list.getContact(item1.getNodeId())).toBeTruthy()
|
|
42
|
+
expect(list.getContact(item3.getNodeId())).toBeTruthy()
|
|
43
|
+
expect(list.getContact(item4.getNodeId())).toBeTruthy()
|
|
39
44
|
expect(list.getContacts()).toEqual(
|
|
40
45
|
[item1, item3, item4]
|
|
41
46
|
)
|