@streamr/dht 100.0.0-testnet-one.3 → 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,9 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
RecursiveOperation,
|
|
3
3
|
Message,
|
|
4
4
|
MessageType,
|
|
5
|
-
NodeType,
|
|
6
|
-
PeerDescriptor,
|
|
7
5
|
RouteMessageAck,
|
|
8
6
|
RouteMessageError,
|
|
9
7
|
RouteMessageWrapper
|
|
@@ -11,19 +9,20 @@ import {
|
|
|
11
9
|
import { PeerID } from '../../src/helpers/PeerID'
|
|
12
10
|
import {
|
|
13
11
|
createWrappedClosestPeersRequest,
|
|
14
|
-
createFindRequest
|
|
12
|
+
createFindRequest,
|
|
13
|
+
createMockPeerDescriptor
|
|
15
14
|
} from '../utils/utils'
|
|
16
|
-
import {
|
|
15
|
+
import { RecursiveOperationManager } from '../../src/dht/recursive-operation/RecursiveOperationManager'
|
|
17
16
|
import { LocalDataStore } from '../../src/dht/store/LocalDataStore'
|
|
18
17
|
import { v4 } from 'uuid'
|
|
19
18
|
import { MockRouter } from '../utils/mock/Router'
|
|
20
19
|
import { MockTransport } from '../utils/mock/Transport'
|
|
21
20
|
import { areEqualPeerDescriptors } from '../../src/helpers/peerIdFromPeerDescriptor'
|
|
22
21
|
import { FakeRpcCommunicator } from '../utils/FakeRpcCommunicator'
|
|
23
|
-
import {
|
|
22
|
+
import { Router } from '../../src/dht/routing/Router'
|
|
24
23
|
import { ITransport } from '../../src/exports'
|
|
25
24
|
|
|
26
|
-
const createMockRouter = (error?: RouteMessageError): Partial<
|
|
25
|
+
const createMockRouter = (error?: RouteMessageError): Partial<Router> => {
|
|
27
26
|
return {
|
|
28
27
|
doRouteMessage: (routedMessage: RouteMessageWrapper) => {
|
|
29
28
|
return {
|
|
@@ -35,24 +34,18 @@ const createMockRouter = (error?: RouteMessageError): Partial<IRouter> => {
|
|
|
35
34
|
addToDuplicateDetector: () => {}
|
|
36
35
|
}
|
|
37
36
|
}
|
|
38
|
-
describe('
|
|
37
|
+
describe('RecursiveOperationManager', () => {
|
|
39
38
|
|
|
40
|
-
const peerDescriptor1
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
const peerDescriptor2: PeerDescriptor = {
|
|
45
|
-
nodeId: PeerID.fromString('destination').value,
|
|
46
|
-
type: NodeType.NODEJS
|
|
47
|
-
}
|
|
48
|
-
const findRequest = createFindRequest(FindAction.NODE)
|
|
39
|
+
const peerDescriptor1 = createMockPeerDescriptor()
|
|
40
|
+
const peerDescriptor2 = createMockPeerDescriptor()
|
|
41
|
+
const recursiveOperationRequest = createFindRequest()
|
|
49
42
|
const message: Message = {
|
|
50
43
|
serviceId: 'unknown',
|
|
51
44
|
messageId: v4(),
|
|
52
45
|
messageType: MessageType.RPC,
|
|
53
46
|
body: {
|
|
54
|
-
oneofKind: '
|
|
55
|
-
|
|
47
|
+
oneofKind: 'recursiveOperationRequest',
|
|
48
|
+
recursiveOperationRequest
|
|
56
49
|
},
|
|
57
50
|
sourceDescriptor: peerDescriptor1,
|
|
58
51
|
targetDescriptor: peerDescriptor2
|
|
@@ -63,40 +56,42 @@ describe('Finder', () => {
|
|
|
63
56
|
routingPath: [],
|
|
64
57
|
reachableThrough: [],
|
|
65
58
|
sourcePeer: peerDescriptor1,
|
|
66
|
-
|
|
59
|
+
target: peerDescriptor2.nodeId
|
|
67
60
|
}
|
|
68
61
|
const rpcCommunicator = new FakeRpcCommunicator()
|
|
69
62
|
|
|
70
|
-
const
|
|
71
|
-
|
|
63
|
+
const createRecursiveOperationManager = (
|
|
64
|
+
router: Router = new MockRouter() as any,
|
|
65
|
+
transport: ITransport = new MockTransport()
|
|
66
|
+
): RecursiveOperationManager => {
|
|
67
|
+
return new RecursiveOperationManager({
|
|
72
68
|
localPeerDescriptor: peerDescriptor1,
|
|
73
69
|
router,
|
|
74
70
|
connections: new Map(),
|
|
75
|
-
serviceId: '
|
|
76
|
-
localDataStore: new LocalDataStore(),
|
|
71
|
+
serviceId: 'RecursiveOperationManager',
|
|
72
|
+
localDataStore: new LocalDataStore(30 * 100),
|
|
77
73
|
sessionTransport: transport,
|
|
78
74
|
addContact: () => {},
|
|
79
|
-
isPeerCloserToIdThanSelf: (_peer1, _compareToId) => true,
|
|
80
75
|
rpcCommunicator: rpcCommunicator as any
|
|
81
76
|
})
|
|
82
77
|
}
|
|
83
78
|
|
|
84
|
-
it('
|
|
85
|
-
const
|
|
86
|
-
const res = await rpcCommunicator.callRpcMethod('
|
|
79
|
+
it('RecursiveOperationManager server', async () => {
|
|
80
|
+
const recursiveOperationManager = createRecursiveOperationManager()
|
|
81
|
+
const res = await rpcCommunicator.callRpcMethod('routeRequest', routedMessage) as RouteMessageAck
|
|
87
82
|
expect(res.error).toBeUndefined()
|
|
88
|
-
|
|
83
|
+
recursiveOperationManager.stop()
|
|
89
84
|
})
|
|
90
85
|
|
|
91
86
|
it('startFind with mode Node returns self if no peers', async () => {
|
|
92
|
-
const
|
|
93
|
-
const res = await
|
|
87
|
+
const recursiveOperationManager = createRecursiveOperationManager()
|
|
88
|
+
const res = await recursiveOperationManager.execute(PeerID.fromString('find').value, RecursiveOperation.FIND_NODE)
|
|
94
89
|
expect(areEqualPeerDescriptors(res.closestNodes[0], peerDescriptor1)).toEqual(true)
|
|
95
|
-
|
|
90
|
+
recursiveOperationManager.stop()
|
|
96
91
|
})
|
|
97
92
|
|
|
98
|
-
it('
|
|
99
|
-
const
|
|
93
|
+
it('RecursiveOperationManager server throws if payload is not RecursiveOperationRequest', async () => {
|
|
94
|
+
const manager = createRecursiveOperationManager(new MockRouter() as any)
|
|
100
95
|
const rpcWrapper = createWrappedClosestPeersRequest(peerDescriptor1)
|
|
101
96
|
const badMessage: Message = {
|
|
102
97
|
serviceId: 'unknown',
|
|
@@ -109,15 +104,15 @@ describe('Finder', () => {
|
|
|
109
104
|
sourceDescriptor: peerDescriptor1,
|
|
110
105
|
targetDescriptor: peerDescriptor2
|
|
111
106
|
}
|
|
112
|
-
await expect(() => rpcCommunicator.callRpcMethod('
|
|
107
|
+
await expect(() => rpcCommunicator.callRpcMethod('routeRequest', {
|
|
113
108
|
message: badMessage,
|
|
114
109
|
requestId: 'REQ',
|
|
115
110
|
routingPath: [],
|
|
116
111
|
reachableThrough: [],
|
|
117
|
-
|
|
112
|
+
target: peerDescriptor1.nodeId,
|
|
118
113
|
sourcePeer: peerDescriptor2
|
|
119
114
|
})).rejects.toThrow()
|
|
120
|
-
|
|
115
|
+
manager.stop()
|
|
121
116
|
})
|
|
122
117
|
|
|
123
118
|
it('no targets', async () => {
|
|
@@ -128,14 +123,14 @@ describe('Finder', () => {
|
|
|
128
123
|
on: () => {},
|
|
129
124
|
off: () => {}
|
|
130
125
|
}
|
|
131
|
-
const
|
|
132
|
-
const ack = await rpcCommunicator.callRpcMethod('
|
|
126
|
+
const recursiveOperationManager = createRecursiveOperationManager(router as any, transport as any)
|
|
127
|
+
const ack = await rpcCommunicator.callRpcMethod('routeRequest', routedMessage)
|
|
133
128
|
expect(ack).toEqual({
|
|
134
129
|
requestId: routedMessage.requestId,
|
|
135
130
|
error: RouteMessageError.NO_TARGETS
|
|
136
131
|
})
|
|
137
132
|
expect(send).toHaveBeenCalledTimes(1)
|
|
138
|
-
|
|
133
|
+
recursiveOperationManager.stop()
|
|
139
134
|
})
|
|
140
135
|
|
|
141
136
|
it('error', async () => {
|
|
@@ -144,13 +139,13 @@ describe('Finder', () => {
|
|
|
144
139
|
const transport = {
|
|
145
140
|
send
|
|
146
141
|
}
|
|
147
|
-
const
|
|
148
|
-
const ack = await rpcCommunicator.callRpcMethod('
|
|
142
|
+
const recursiveOperationManager = createRecursiveOperationManager(router as any, transport as any)
|
|
143
|
+
const ack = await rpcCommunicator.callRpcMethod('routeRequest', routedMessage)
|
|
149
144
|
expect(ack).toEqual({
|
|
150
145
|
requestId: routedMessage.requestId,
|
|
151
146
|
error: RouteMessageError.DUPLICATE
|
|
152
147
|
})
|
|
153
148
|
expect(send).not.toHaveBeenCalled()
|
|
154
|
-
|
|
149
|
+
recursiveOperationManager.stop()
|
|
155
150
|
})
|
|
156
151
|
})
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { waitForCondition } from '@streamr/utils'
|
|
2
|
+
import { range } from 'lodash'
|
|
3
|
+
import { RecursiveOperationSession } from '../../src/dht/recursive-operation/RecursiveOperationSession'
|
|
4
|
+
import { RecursiveOperationSessionRpcRemote } from '../../src/dht/recursive-operation/RecursiveOperationSessionRpcRemote'
|
|
5
|
+
import { ServiceID } from '../../src/exports'
|
|
6
|
+
import { createRandomNodeId } from '../../src/helpers/nodeId'
|
|
7
|
+
import { Message, PeerDescriptor, RecursiveOperation } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
8
|
+
import { RecursiveOperationSessionRpcClient } from '../../src/proto/packages/dht/protos/DhtRpc.client'
|
|
9
|
+
import { RoutingRpcCommunicator } from '../../src/transport/RoutingRpcCommunicator'
|
|
10
|
+
import { FakeEnvironment } from '../utils/FakeTransport'
|
|
11
|
+
import { createMockPeerDescriptor } from '../utils/utils'
|
|
12
|
+
|
|
13
|
+
describe('RecursiveOperationSession', () => {
|
|
14
|
+
|
|
15
|
+
let environment: FakeEnvironment
|
|
16
|
+
let localPeerDescriptor: PeerDescriptor
|
|
17
|
+
|
|
18
|
+
const createRpcRemote = (serviceId: ServiceID) => {
|
|
19
|
+
const transport = environment.createTransport()
|
|
20
|
+
const send = (msg: Message) => transport.send(msg)
|
|
21
|
+
return new RecursiveOperationSessionRpcRemote(
|
|
22
|
+
createMockPeerDescriptor(),
|
|
23
|
+
localPeerDescriptor,
|
|
24
|
+
serviceId,
|
|
25
|
+
new RoutingRpcCommunicator(serviceId, send),
|
|
26
|
+
RecursiveOperationSessionRpcClient
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
beforeEach(() => {
|
|
31
|
+
environment = new FakeEnvironment()
|
|
32
|
+
localPeerDescriptor = createMockPeerDescriptor()
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it('happy path', async () => {
|
|
36
|
+
const doRouteRequest = jest.fn()
|
|
37
|
+
const session = new RecursiveOperationSession({
|
|
38
|
+
transport: environment.createTransport(),
|
|
39
|
+
targetId: createRandomNodeId(),
|
|
40
|
+
localPeerDescriptor,
|
|
41
|
+
waitedRoutingPathCompletions: 3,
|
|
42
|
+
operation: RecursiveOperation.FIND_NODE,
|
|
43
|
+
doRouteRequest
|
|
44
|
+
})
|
|
45
|
+
const onCompleted = jest.fn()
|
|
46
|
+
session.on('completed', onCompleted)
|
|
47
|
+
|
|
48
|
+
session.start('')
|
|
49
|
+
expect(doRouteRequest).toHaveBeenCalled()
|
|
50
|
+
range(3).forEach(() => {
|
|
51
|
+
const remote = createRpcRemote(session.getId())
|
|
52
|
+
remote.sendResponse(
|
|
53
|
+
[createMockPeerDescriptor(), createMockPeerDescriptor()],
|
|
54
|
+
[createMockPeerDescriptor(), createMockPeerDescriptor()],
|
|
55
|
+
[],
|
|
56
|
+
true
|
|
57
|
+
)
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
// TODO now waits for the 4s timeout, could setup test so that it completes by receiving
|
|
61
|
+
// all data it wants
|
|
62
|
+
await waitForCondition(() => onCompleted.mock.calls.length > 0)
|
|
63
|
+
const result = session.getResults()
|
|
64
|
+
// TODO assert peer descriptors
|
|
65
|
+
expect(result.closestNodes).toHaveLength(6)
|
|
66
|
+
expect(result.dataEntries).toEqual([])
|
|
67
|
+
})
|
|
68
|
+
})
|
package/test/unit/Router.test.ts
CHANGED
|
@@ -1,31 +1,25 @@
|
|
|
1
1
|
import { v4 } from 'uuid'
|
|
2
2
|
import { DhtNodeRpcRemote } from '../../src/dht/DhtNodeRpcRemote'
|
|
3
3
|
import { Router } from '../../src/dht/routing/Router'
|
|
4
|
-
import { PeerID
|
|
4
|
+
import { PeerID } from '../../src/helpers/PeerID'
|
|
5
5
|
import {
|
|
6
6
|
Message,
|
|
7
7
|
MessageType,
|
|
8
|
-
NodeType,
|
|
9
8
|
PeerDescriptor,
|
|
10
9
|
RouteMessageAck,
|
|
11
10
|
RouteMessageError,
|
|
12
11
|
RouteMessageWrapper
|
|
13
12
|
} from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
14
|
-
import { createWrappedClosestPeersRequest } from '../utils/utils'
|
|
13
|
+
import { createMockPeerDescriptor, createWrappedClosestPeersRequest } from '../utils/utils'
|
|
15
14
|
import { FakeRpcCommunicator } from '../utils/FakeRpcCommunicator'
|
|
15
|
+
import { NodeID } from '../../src/helpers/nodeId'
|
|
16
|
+
import { MockRpcCommunicator } from '../utils/mock/MockRpcCommunicator'
|
|
16
17
|
|
|
17
18
|
describe('Router', () => {
|
|
18
|
-
let router: Router
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
const peerDescriptor1
|
|
22
|
-
|
|
23
|
-
type: NodeType.NODEJS
|
|
24
|
-
}
|
|
25
|
-
const peerDescriptor2: PeerDescriptor = {
|
|
26
|
-
nodeId: PeerID.fromString('destination').value,
|
|
27
|
-
type: NodeType.NODEJS
|
|
28
|
-
}
|
|
20
|
+
let router: Router
|
|
21
|
+
const peerDescriptor1 = createMockPeerDescriptor()
|
|
22
|
+
const peerDescriptor2 = createMockPeerDescriptor()
|
|
29
23
|
const rpcWrapper = createWrappedClosestPeersRequest(peerDescriptor1)
|
|
30
24
|
const message: Message = {
|
|
31
25
|
serviceId: 'unknown',
|
|
@@ -43,14 +37,14 @@ describe('Router', () => {
|
|
|
43
37
|
requestId: 'REQ',
|
|
44
38
|
routingPath: [],
|
|
45
39
|
reachableThrough: [],
|
|
46
|
-
|
|
40
|
+
target: peerDescriptor1.nodeId,
|
|
47
41
|
sourcePeer: peerDescriptor2
|
|
48
42
|
}
|
|
49
|
-
let connections: Map<
|
|
43
|
+
let connections: Map<NodeID, DhtNodeRpcRemote>
|
|
50
44
|
const rpcCommunicator = new FakeRpcCommunicator()
|
|
51
45
|
|
|
52
46
|
const createMockDhtNodeRpcRemote = (destination: PeerDescriptor): DhtNodeRpcRemote => {
|
|
53
|
-
return new DhtNodeRpcRemote(peerDescriptor1, destination,
|
|
47
|
+
return new DhtNodeRpcRemote(peerDescriptor1, destination, undefined as any, new MockRpcCommunicator())
|
|
54
48
|
}
|
|
55
49
|
|
|
56
50
|
beforeEach(() => {
|
|
@@ -59,7 +53,6 @@ describe('Router', () => {
|
|
|
59
53
|
localPeerDescriptor: peerDescriptor1,
|
|
60
54
|
rpcCommunicator: rpcCommunicator as any,
|
|
61
55
|
addContact: (_contact) => {},
|
|
62
|
-
serviceId: 'router',
|
|
63
56
|
connections
|
|
64
57
|
})
|
|
65
58
|
})
|
|
@@ -71,7 +64,7 @@ describe('Router', () => {
|
|
|
71
64
|
it('doRouteMessage without connections', async () => {
|
|
72
65
|
const ack = await rpcCommunicator.callRpcMethod('routeMessage', {
|
|
73
66
|
message,
|
|
74
|
-
|
|
67
|
+
target: peerDescriptor2.nodeId,
|
|
75
68
|
requestId: v4(),
|
|
76
69
|
sourcePeer: peerDescriptor1,
|
|
77
70
|
reachableThrough: [],
|
|
@@ -81,10 +74,10 @@ describe('Router', () => {
|
|
|
81
74
|
})
|
|
82
75
|
|
|
83
76
|
it('doRouteMessage with connections', async () => {
|
|
84
|
-
connections.set(PeerID.fromString('test').
|
|
77
|
+
connections.set(PeerID.fromString('test').toNodeId(), createMockDhtNodeRpcRemote(peerDescriptor2))
|
|
85
78
|
const ack = await rpcCommunicator.callRpcMethod('routeMessage', {
|
|
86
79
|
message,
|
|
87
|
-
|
|
80
|
+
target: peerDescriptor2.nodeId,
|
|
88
81
|
requestId: v4(),
|
|
89
82
|
sourcePeer: peerDescriptor1,
|
|
90
83
|
reachableThrough: [],
|
|
@@ -99,7 +92,7 @@ describe('Router', () => {
|
|
|
99
92
|
})
|
|
100
93
|
|
|
101
94
|
it('route server with connections', async () => {
|
|
102
|
-
connections.set(PeerID.fromString('test').
|
|
95
|
+
connections.set(PeerID.fromString('test').toNodeId(), createMockDhtNodeRpcRemote(peerDescriptor2))
|
|
103
96
|
const ack = await rpcCommunicator.callRpcMethod('routeMessage', routedMessage) as RouteMessageAck
|
|
104
97
|
expect(ack.error).toBeUndefined()
|
|
105
98
|
})
|
|
@@ -116,7 +109,7 @@ describe('Router', () => {
|
|
|
116
109
|
})
|
|
117
110
|
|
|
118
111
|
it('forward server with connections', async () => {
|
|
119
|
-
connections.set(PeerID.fromString('test').
|
|
112
|
+
connections.set(PeerID.fromString('test').toNodeId(), createMockDhtNodeRpcRemote(peerDescriptor2))
|
|
120
113
|
const ack = await rpcCommunicator.callRpcMethod('forwardMessage', routedMessage) as RouteMessageAck
|
|
121
114
|
expect(ack.error).toBeUndefined()
|
|
122
115
|
})
|
|
@@ -1,29 +1,20 @@
|
|
|
1
1
|
import { v4 } from 'uuid'
|
|
2
|
-
import { RoutingSession } from '../../src/dht/routing/RoutingSession'
|
|
3
|
-
import { Message, MessageType,
|
|
4
|
-
import { createWrappedClosestPeersRequest } from '../utils/utils'
|
|
5
|
-
import { hexToBinary } from '@streamr/utils'
|
|
6
|
-
import { PeerIDKey } from '../../src/helpers/PeerID'
|
|
2
|
+
import { RoutingMode, RoutingSession } from '../../src/dht/routing/RoutingSession'
|
|
3
|
+
import { Message, MessageType, PeerDescriptor, RouteMessageWrapper } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
4
|
+
import { createMockPeerDescriptor, createWrappedClosestPeersRequest } from '../utils/utils'
|
|
7
5
|
import { DhtNodeRpcRemote } from '../../src/dht/DhtNodeRpcRemote'
|
|
8
6
|
import { RoutingRpcCommunicator } from '../../src/transport/RoutingRpcCommunicator'
|
|
9
|
-
import {
|
|
7
|
+
import { getNodeIdFromPeerDescriptor } from '../../src/helpers/peerIdFromPeerDescriptor'
|
|
8
|
+
import { NodeID } from '../../src/helpers/nodeId'
|
|
9
|
+
import { MockRpcCommunicator } from '../utils/mock/MockRpcCommunicator'
|
|
10
10
|
|
|
11
11
|
describe('RoutingSession', () => {
|
|
12
12
|
|
|
13
13
|
let session: RoutingSession
|
|
14
|
-
let connections: Map<
|
|
14
|
+
let connections: Map<NodeID, DhtNodeRpcRemote>
|
|
15
15
|
let rpcCommunicator: RoutingRpcCommunicator
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
nodeId: hexToBinary('eee1'),
|
|
19
|
-
type: NodeType.NODEJS
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const mockPeerDescriptor2 = {
|
|
23
|
-
nodeId: hexToBinary('eee2'),
|
|
24
|
-
type: NodeType.NODEJS
|
|
25
|
-
}
|
|
26
|
-
|
|
16
|
+
const mockPeerDescriptor1 = createMockPeerDescriptor()
|
|
17
|
+
const mockPeerDescriptor2 = createMockPeerDescriptor()
|
|
27
18
|
const rpcWrapper = createWrappedClosestPeersRequest(mockPeerDescriptor1)
|
|
28
19
|
const message: Message = {
|
|
29
20
|
serviceId: 'unknown',
|
|
@@ -41,18 +32,25 @@ describe('RoutingSession', () => {
|
|
|
41
32
|
requestId: 'REQ',
|
|
42
33
|
routingPath: [],
|
|
43
34
|
reachableThrough: [],
|
|
44
|
-
|
|
35
|
+
target: mockPeerDescriptor1.nodeId,
|
|
45
36
|
sourcePeer: mockPeerDescriptor2
|
|
46
37
|
}
|
|
47
38
|
|
|
48
39
|
const createMockDhtNodeRpcRemote = (destination: PeerDescriptor): DhtNodeRpcRemote => {
|
|
49
|
-
return new DhtNodeRpcRemote(mockPeerDescriptor1, destination,
|
|
40
|
+
return new DhtNodeRpcRemote(mockPeerDescriptor1, destination, undefined as any, rpcCommunicator)
|
|
50
41
|
}
|
|
51
42
|
|
|
52
43
|
beforeEach(() => {
|
|
53
|
-
rpcCommunicator = new
|
|
44
|
+
rpcCommunicator = new MockRpcCommunicator()
|
|
54
45
|
connections = new Map()
|
|
55
|
-
session = new RoutingSession(
|
|
46
|
+
session = new RoutingSession({
|
|
47
|
+
rpcCommunicator: rpcCommunicator,
|
|
48
|
+
localPeerDescriptor: mockPeerDescriptor1,
|
|
49
|
+
routedMessage,
|
|
50
|
+
connections,
|
|
51
|
+
parallelism: 2,
|
|
52
|
+
mode: RoutingMode.ROUTE
|
|
53
|
+
})
|
|
56
54
|
})
|
|
57
55
|
|
|
58
56
|
afterEach(() => {
|
|
@@ -61,15 +59,15 @@ describe('RoutingSession', () => {
|
|
|
61
59
|
})
|
|
62
60
|
|
|
63
61
|
it('findMoreContacts', () => {
|
|
64
|
-
connections.set(
|
|
62
|
+
connections.set(getNodeIdFromPeerDescriptor(mockPeerDescriptor2), createMockDhtNodeRpcRemote(mockPeerDescriptor2))
|
|
65
63
|
const contacts = session.updateAndGetRoutablePeers()
|
|
66
64
|
expect(contacts.length).toBe(1)
|
|
67
65
|
})
|
|
68
66
|
|
|
69
67
|
it('findMoreContacts peer disconnects', () => {
|
|
70
|
-
connections.set(
|
|
68
|
+
connections.set(getNodeIdFromPeerDescriptor(mockPeerDescriptor2), createMockDhtNodeRpcRemote(mockPeerDescriptor2))
|
|
71
69
|
expect(session.updateAndGetRoutablePeers().length).toBe(1)
|
|
72
|
-
connections.delete(
|
|
70
|
+
connections.delete(getNodeIdFromPeerDescriptor(mockPeerDescriptor2))
|
|
73
71
|
expect(session.updateAndGetRoutablePeers().length).toBe(0)
|
|
74
72
|
})
|
|
75
73
|
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { SortedContactList } from '../../src/dht/contact/SortedContactList'
|
|
2
2
|
import { PeerID } from '../../src/helpers/PeerID'
|
|
3
|
+
import { NodeID, createRandomNodeId, 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('SortedContactList', () => {
|
|
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,19 +18,19 @@ describe('SortedContactList', () => {
|
|
|
13
18
|
const item4 = createItem(new Uint8Array([0, 0, 0, 4]))
|
|
14
19
|
|
|
15
20
|
it('compares Ids correctly', async () => {
|
|
16
|
-
const list = new SortedContactList({ referenceId: item0.
|
|
17
|
-
expect(list.compareIds(item0.
|
|
18
|
-
expect(list.compareIds(item1.
|
|
19
|
-
expect(list.compareIds(item0.
|
|
20
|
-
expect(list.compareIds(item0.
|
|
21
|
-
expect(list.compareIds(item1.
|
|
22
|
-
expect(list.compareIds(item2.
|
|
23
|
-
expect(list.compareIds(item2.
|
|
24
|
-
expect(list.compareIds(item1.
|
|
21
|
+
const list = new SortedContactList({ referenceId: item0.getNodeId(), maxSize: 10, allowToContainReferenceId: true, emitEvents: false })
|
|
22
|
+
expect(list.compareIds(item0.getNodeId(), item0.getNodeId())).toBe(0)
|
|
23
|
+
expect(list.compareIds(item1.getNodeId(), item1.getNodeId())).toBe(0)
|
|
24
|
+
expect(list.compareIds(item0.getNodeId(), item1.getNodeId())).toBe(-1)
|
|
25
|
+
expect(list.compareIds(item0.getNodeId(), item2.getNodeId())).toBe(-2)
|
|
26
|
+
expect(list.compareIds(item1.getNodeId(), item0.getNodeId())).toBe(1)
|
|
27
|
+
expect(list.compareIds(item2.getNodeId(), item0.getNodeId())).toBe(2)
|
|
28
|
+
expect(list.compareIds(item2.getNodeId(), item3.getNodeId())).toBe(-1)
|
|
29
|
+
expect(list.compareIds(item1.getNodeId(), item4.getNodeId())).toBe(-3)
|
|
25
30
|
})
|
|
26
31
|
|
|
27
32
|
it('orders itself correctly', async () => {
|
|
28
|
-
const list = new SortedContactList({ referenceId: item0.
|
|
33
|
+
const list = new SortedContactList({ referenceId: item0.getNodeId(), maxSize: 10, allowToContainReferenceId: true, emitEvents: false })
|
|
29
34
|
list.addContact(item3)
|
|
30
35
|
list.addContact(item2)
|
|
31
36
|
list.addContact(item1)
|
|
@@ -37,11 +42,11 @@ describe('SortedContactList', () => {
|
|
|
37
42
|
})
|
|
38
43
|
|
|
39
44
|
it('handles contacted nodes correctly', async () => {
|
|
40
|
-
const list = new SortedContactList({ referenceId: item0.
|
|
45
|
+
const list = new SortedContactList({ referenceId: item0.getNodeId(), maxSize: 10, allowToContainReferenceId: false, emitEvents: false })
|
|
41
46
|
list.addContact(item3)
|
|
42
47
|
list.addContact(item2)
|
|
43
48
|
list.addContact(item1)
|
|
44
|
-
list.setContacted(item2.
|
|
49
|
+
list.setContacted(item2.getNodeId())
|
|
45
50
|
const contacts = list.getUncontactedContacts(3)
|
|
46
51
|
expect(contacts.length).toEqual(2)
|
|
47
52
|
expect(contacts[0]).toEqual(item1)
|
|
@@ -49,7 +54,7 @@ describe('SortedContactList', () => {
|
|
|
49
54
|
})
|
|
50
55
|
|
|
51
56
|
it('cannot exceed maxSize', async () => {
|
|
52
|
-
const list = new SortedContactList({ referenceId: item0.
|
|
57
|
+
const list = new SortedContactList({ referenceId: item0.getNodeId(), maxSize: 3, allowToContainReferenceId: false, emitEvents: true })
|
|
53
58
|
const onContactRemoved = jest.fn()
|
|
54
59
|
list.on('contactRemoved', onContactRemoved)
|
|
55
60
|
list.addContact(item1)
|
|
@@ -57,31 +62,41 @@ describe('SortedContactList', () => {
|
|
|
57
62
|
list.addContact(item3)
|
|
58
63
|
list.addContact(item2)
|
|
59
64
|
expect(list.getSize()).toEqual(3)
|
|
65
|
+
expect(list.getAllContacts()).toEqual([item1, item2, item3])
|
|
66
|
+
expect(list.getContactIds()).toEqual([item1.getNodeId(), item2.getNodeId(), item3.getNodeId()])
|
|
60
67
|
expect(onContactRemoved).toBeCalledWith(item4, [item1, item2, item3])
|
|
61
|
-
expect(list.getContact(item4.
|
|
68
|
+
expect(list.getContact(item4.getNodeId())).toBeFalsy()
|
|
62
69
|
})
|
|
63
70
|
|
|
64
71
|
it('removing contacts', async () => {
|
|
65
|
-
const list = new SortedContactList({ referenceId: item0.
|
|
72
|
+
const list = new SortedContactList({ referenceId: item0.getNodeId(), maxSize: 8, allowToContainReferenceId: false, emitEvents: true })
|
|
66
73
|
const onContactRemoved = jest.fn()
|
|
67
74
|
list.on('contactRemoved', onContactRemoved)
|
|
75
|
+
list.removeContact(getNodeIdFromBinary(createRandomNodeId()))
|
|
76
|
+
list.addContact(item3)
|
|
77
|
+
list.removeContact(item3.getNodeId())
|
|
68
78
|
list.addContact(item4)
|
|
69
79
|
list.addContact(item3)
|
|
70
80
|
list.addContact(item2)
|
|
71
81
|
list.addContact(item1)
|
|
72
|
-
list.removeContact(item2.
|
|
82
|
+
list.removeContact(item2.getNodeId())
|
|
73
83
|
expect(list.getSize()).toEqual(3)
|
|
74
|
-
expect(list.getContact(item2.
|
|
84
|
+
expect(list.getContact(item2.getNodeId())).toBeFalsy()
|
|
75
85
|
expect(list.getContactIds()).toEqual(list.getContactIds().sort(list.compareIds))
|
|
76
86
|
expect(list.getAllContacts()).toEqual([item1, item3, item4])
|
|
77
|
-
|
|
78
|
-
const ret = list.removeContact(PeerID.fromValue(Buffer.from([0, 0, 0, 6])))
|
|
87
|
+
const ret = list.removeContact(getNodeIdFromBinary(Buffer.from([0, 0, 0, 6])))
|
|
79
88
|
expect(ret).toEqual(false)
|
|
89
|
+
list.removeContact(item3.getNodeId())
|
|
90
|
+
list.removeContact(getNodeIdFromBinary(createRandomNodeId()))
|
|
91
|
+
expect(list.getAllContacts()).toEqual([item1, item4])
|
|
92
|
+
expect(onContactRemoved).toHaveBeenNthCalledWith(1, item3, [])
|
|
93
|
+
expect(onContactRemoved).toHaveBeenNthCalledWith(2, item2, [item1, item3, item4])
|
|
94
|
+
expect(onContactRemoved).toHaveBeenNthCalledWith(3, item3, [item1, item4])
|
|
80
95
|
})
|
|
81
96
|
|
|
82
97
|
it('get closest contacts', () => {
|
|
83
98
|
const list = new SortedContactList({
|
|
84
|
-
referenceId: item0.
|
|
99
|
+
referenceId: item0.getNodeId(),
|
|
85
100
|
maxSize: 8,
|
|
86
101
|
allowToContainReferenceId: false,
|
|
87
102
|
emitEvents: false
|
|
@@ -95,14 +110,14 @@ describe('SortedContactList', () => {
|
|
|
95
110
|
})
|
|
96
111
|
|
|
97
112
|
it('get active contacts', () => {
|
|
98
|
-
const list = new SortedContactList({ referenceId: item0.
|
|
113
|
+
const list = new SortedContactList({ referenceId: item0.getNodeId(), maxSize: 8, allowToContainReferenceId: false, emitEvents: false })
|
|
99
114
|
list.addContact(item1)
|
|
100
115
|
list.addContact(item3)
|
|
101
116
|
list.addContact(item4)
|
|
102
117
|
list.addContact(item2)
|
|
103
|
-
list.setActive(item2.
|
|
104
|
-
list.setActive(item3.
|
|
105
|
-
list.setActive(item4.
|
|
118
|
+
list.setActive(item2.getNodeId())
|
|
119
|
+
list.setActive(item3.getNodeId())
|
|
120
|
+
list.setActive(item4.getNodeId())
|
|
106
121
|
expect(list.getActiveContacts()).toEqual([item2, item3, item4])
|
|
107
122
|
})
|
|
108
123
|
})
|