@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,24 +1,17 @@
|
|
|
1
1
|
import { DhtNode } from '../../src/dht/DhtNode'
|
|
2
|
-
import {
|
|
3
|
-
import { PeerID } from '../../src/helpers/PeerID'
|
|
2
|
+
import { createMockPeerDescriptor } from '../utils/utils'
|
|
4
3
|
|
|
4
|
+
const STREAM_ID = 'stream'
|
|
5
|
+
const NUM_OF_NODES = 16
|
|
5
6
|
const NUM_OF_NODES_PER_KBUCKET = 8
|
|
6
7
|
|
|
7
8
|
describe('Layer1 Scale', () => {
|
|
8
|
-
const epPeerDescriptor: PeerDescriptor = {
|
|
9
|
-
nodeId: PeerID.fromString('0').value,
|
|
10
|
-
type: NodeType.NODEJS,
|
|
11
|
-
websocket: { host: '127.0.0.1', port: 43228, tls: false }
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const STREAM_ID = 'stream'
|
|
15
|
-
|
|
16
|
-
const NUM_OF_NODES = 16
|
|
17
9
|
|
|
10
|
+
const epPeerDescriptor = createMockPeerDescriptor({
|
|
11
|
+
websocket: { host: '127.0.0.1', port: 43228, tls: false }
|
|
12
|
+
})
|
|
18
13
|
let layer0Nodes: DhtNode[]
|
|
19
|
-
|
|
20
14
|
let layer1Nodes: DhtNode[]
|
|
21
|
-
|
|
22
15
|
let epLayer0Node: DhtNode
|
|
23
16
|
let epLayer1Node: DhtNode
|
|
24
17
|
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
2
2
|
import { DhtNode } from '../../src/dht/DhtNode'
|
|
3
3
|
import { ConnectionManager } from '../../src/connection/ConnectionManager'
|
|
4
|
-
import { PeerID } from '../../src/helpers/PeerID'
|
|
5
4
|
import { waitForCondition } from '@streamr/utils'
|
|
6
5
|
import { areEqualPeerDescriptors } from '../../src/helpers/peerIdFromPeerDescriptor'
|
|
6
|
+
import { createMockPeerDescriptor } from '../utils/utils'
|
|
7
7
|
|
|
8
8
|
describe('Websocket IConnection Requests', () => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
type: NodeType.NODEJS,
|
|
9
|
+
|
|
10
|
+
const epPeerDescriptor = createMockPeerDescriptor({
|
|
12
11
|
websocket: { host: '127.0.0.1', port: 10021, tls: false }
|
|
13
|
-
}
|
|
12
|
+
})
|
|
14
13
|
let epDhtNode: DhtNode
|
|
15
14
|
let node1: DhtNode
|
|
16
15
|
let node2: DhtNode
|
|
@@ -1,30 +1,28 @@
|
|
|
1
1
|
import LeakDetector from 'jest-leak-detector'
|
|
2
2
|
import { binaryToHex, waitForCondition } from '@streamr/utils'
|
|
3
|
-
import { randomBytes } from 'crypto'
|
|
4
3
|
import { DhtNode } from '../../src/dht/DhtNode'
|
|
5
|
-
import { Message, MessageType
|
|
4
|
+
import { Message, MessageType } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
6
5
|
import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
|
|
6
|
+
import { createMockPeerDescriptor } from '../utils/utils'
|
|
7
7
|
|
|
8
8
|
const MESSAGE_ID = 'mock-message-id'
|
|
9
9
|
|
|
10
10
|
describe('memory leak', () => {
|
|
11
11
|
|
|
12
12
|
it('send message', async () => {
|
|
13
|
-
const entryPointDescriptor = {
|
|
14
|
-
nodeId: randomBytes(10),
|
|
15
|
-
type: NodeType.NODEJS,
|
|
13
|
+
const entryPointDescriptor = createMockPeerDescriptor({
|
|
16
14
|
websocket: {
|
|
17
15
|
host: '127.0.0.1',
|
|
18
16
|
port: 11224,
|
|
19
17
|
tls: false
|
|
20
18
|
}
|
|
21
|
-
}
|
|
19
|
+
})
|
|
22
20
|
let entryPoint: DhtNode | undefined = new DhtNode({
|
|
23
21
|
peerId: binaryToHex(entryPointDescriptor.nodeId),
|
|
24
22
|
websocketHost: entryPointDescriptor.websocket!.host,
|
|
25
23
|
websocketPortRange: {
|
|
26
|
-
min: entryPointDescriptor.websocket
|
|
27
|
-
max: entryPointDescriptor.websocket
|
|
24
|
+
min: entryPointDescriptor.websocket!.port,
|
|
25
|
+
max: entryPointDescriptor.websocket!.port
|
|
28
26
|
},
|
|
29
27
|
entryPoints: [entryPointDescriptor],
|
|
30
28
|
websocketServerEnableTls: false
|
|
@@ -4,9 +4,9 @@ import { DefaultConnectorFacade } from '../../src/connection/ConnectorFacade'
|
|
|
4
4
|
import { LatencyType, Simulator } from '../../src/connection/simulator/Simulator'
|
|
5
5
|
import { SimulatorTransport } from '../../src/connection/simulator/SimulatorTransport'
|
|
6
6
|
import { ITransport } from '../../src/exports'
|
|
7
|
-
import {
|
|
8
|
-
import { NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
7
|
+
import { PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
9
8
|
import { getRandomRegion } from '../../dist/src/connection/simulator/pings'
|
|
9
|
+
import { createMockPeerDescriptor } from '../utils/utils'
|
|
10
10
|
|
|
11
11
|
const createConnectionManager = (localPeerDescriptor: PeerDescriptor, transport: ITransport) => {
|
|
12
12
|
return new ConnectionManager({
|
|
@@ -20,23 +20,16 @@ const createConnectionManager = (localPeerDescriptor: PeerDescriptor, transport:
|
|
|
20
20
|
|
|
21
21
|
describe('Connection Locking', () => {
|
|
22
22
|
|
|
23
|
-
const mockPeerDescriptor1
|
|
24
|
-
nodeId: PeerID.fromString('mock1').value,
|
|
25
|
-
type: NodeType.NODEJS,
|
|
23
|
+
const mockPeerDescriptor1 = createMockPeerDescriptor({
|
|
26
24
|
region: getRandomRegion()
|
|
27
|
-
}
|
|
28
|
-
const mockPeerDescriptor2
|
|
29
|
-
nodeId: PeerID.fromString('mock2').value,
|
|
30
|
-
type: NodeType.NODEJS,
|
|
25
|
+
})
|
|
26
|
+
const mockPeerDescriptor2 = createMockPeerDescriptor({
|
|
31
27
|
region: getRandomRegion()
|
|
32
|
-
}
|
|
33
|
-
|
|
28
|
+
})
|
|
34
29
|
let mockConnectorTransport1: ConnectionManager
|
|
35
30
|
let mockConnectorTransport2: ConnectionManager
|
|
36
|
-
|
|
37
31
|
let connectionManager1: ConnectionManager
|
|
38
32
|
let connectionManager2: ConnectionManager
|
|
39
|
-
|
|
40
33
|
let simulator: Simulator
|
|
41
34
|
|
|
42
35
|
beforeEach(async () => {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ConnectionManager } from '../../src/connection/ConnectionManager'
|
|
2
2
|
import { ConnectivityResponse, Message, MessageType, NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
3
|
-
import { PeerID } from '../../src/helpers/PeerID'
|
|
4
3
|
import { Simulator } from '../../src/connection/simulator/Simulator'
|
|
5
4
|
import { createPeerDescriptor } from '../../src/dht/DhtNode'
|
|
6
5
|
import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
|
|
@@ -8,38 +7,25 @@ import { Logger, MetricsContext, waitForEvent3 } from '@streamr/utils'
|
|
|
8
7
|
import { SimulatorTransport } from '../../src/exports'
|
|
9
8
|
import { DefaultConnectorFacade, DefaultConnectorFacadeConfig } from '../../src/connection/ConnectorFacade'
|
|
10
9
|
import { MarkOptional } from 'ts-essentials'
|
|
11
|
-
import { createRandomNodeId } from '../../src/helpers/nodeId'
|
|
12
10
|
import { TransportEvents } from '../../src/transport/ITransport'
|
|
11
|
+
import { createMockPeerDescriptor } from '../utils/utils'
|
|
12
|
+
import { createRandomNodeId } from '../../src/helpers/nodeId'
|
|
13
|
+
|
|
14
|
+
const SERVICE_ID = 'demo'
|
|
13
15
|
|
|
14
16
|
const logger = new Logger(module)
|
|
15
17
|
|
|
16
18
|
// TODO: refactor this test file to use beforeEach and AfterEach for proper teardown
|
|
17
19
|
describe('ConnectionManager', () => {
|
|
18
|
-
const serviceId = 'demo'
|
|
19
|
-
|
|
20
|
-
const mockPeerDescriptor1: PeerDescriptor = {
|
|
21
|
-
nodeId: PeerID.fromString('tester1').value,
|
|
22
|
-
type: NodeType.NODEJS
|
|
23
|
-
}
|
|
24
|
-
const mockPeerDescriptor2: PeerDescriptor = {
|
|
25
|
-
nodeId: PeerID.fromString('tester2').value,
|
|
26
|
-
type: NodeType.NODEJS
|
|
27
|
-
}
|
|
28
20
|
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const mockPeerDescriptor4: PeerDescriptor = {
|
|
34
|
-
nodeId: PeerID.fromString('tester4').value,
|
|
35
|
-
type: NodeType.NODEJS
|
|
36
|
-
}
|
|
21
|
+
const mockPeerDescriptor1 = createMockPeerDescriptor()
|
|
22
|
+
const mockPeerDescriptor2 = createMockPeerDescriptor()
|
|
23
|
+
const mockPeerDescriptor3 = createMockPeerDescriptor()
|
|
24
|
+
const mockPeerDescriptor4 = createMockPeerDescriptor()
|
|
37
25
|
const simulator = new Simulator()
|
|
38
|
-
|
|
39
26
|
const mockTransport = new SimulatorTransport(mockPeerDescriptor1, simulator)
|
|
40
27
|
const mockConnectorTransport1 = new SimulatorTransport(mockPeerDescriptor1, simulator)
|
|
41
28
|
const mockConnectorTransport2 = new SimulatorTransport(mockPeerDescriptor2, simulator)
|
|
42
|
-
|
|
43
29
|
let createLocalPeerDescriptor: jest.Mock<PeerDescriptor, [ConnectivityResponse]>
|
|
44
30
|
|
|
45
31
|
const createConnectionManager = (opts: MarkOptional<DefaultConnectorFacadeConfig, 'createLocalPeerDescriptor'>) => {
|
|
@@ -85,12 +71,13 @@ describe('ConnectionManager', () => {
|
|
|
85
71
|
|
|
86
72
|
it('Throws an async exception if fails to connect to entrypoints', async () => {
|
|
87
73
|
|
|
74
|
+
const entryPoint = createMockPeerDescriptor({
|
|
75
|
+
websocket: { host: '127.0.0.1', port: 12345, tls: false }
|
|
76
|
+
})
|
|
88
77
|
const connectionManager = createConnectionManager({
|
|
89
78
|
transport: mockTransport,
|
|
90
79
|
websocketPortRange: { min: 9992, max: 9992 },
|
|
91
|
-
entryPoints: [
|
|
92
|
-
{ nodeId: Uint8Array.from([1, 2, 3]), type: NodeType.NODEJS, websocket: { host: '127.0.0.1', port: 12345, tls: false } }
|
|
93
|
-
]
|
|
80
|
+
entryPoints: [entryPoint]
|
|
94
81
|
})
|
|
95
82
|
|
|
96
83
|
await expect(connectionManager.start()).rejects.toThrow('Failed to connect to the entrypoints')
|
|
@@ -108,12 +95,13 @@ describe('ConnectionManager', () => {
|
|
|
108
95
|
await connectionManager1.start()
|
|
109
96
|
expect(createLocalPeerDescriptor.mock.calls[0][0].host).toEqual('127.0.0.1')
|
|
110
97
|
|
|
98
|
+
const entryPoint = createMockPeerDescriptor({
|
|
99
|
+
websocket: { host: '127.0.0.1', port: 9993, tls: false }
|
|
100
|
+
})
|
|
111
101
|
const connectionManager2 = createConnectionManager({
|
|
112
102
|
transport: mockConnectorTransport2,
|
|
113
103
|
websocketPortRange: { min: 9994, max: 9994 },
|
|
114
|
-
entryPoints: [
|
|
115
|
-
{ nodeId: Uint8Array.from([1, 2, 3]), type: NodeType.NODEJS, websocket: { host: '127.0.0.1', port: 9993, tls: false } }
|
|
116
|
-
]
|
|
104
|
+
entryPoints: [entryPoint]
|
|
117
105
|
})
|
|
118
106
|
|
|
119
107
|
await connectionManager2.start()
|
|
@@ -145,7 +133,7 @@ describe('ConnectionManager', () => {
|
|
|
145
133
|
expect(createLocalPeerDescriptor.mock.calls[1][0].host).toEqual('127.0.0.1')
|
|
146
134
|
|
|
147
135
|
const msg: Message = {
|
|
148
|
-
serviceId,
|
|
136
|
+
serviceId: SERVICE_ID,
|
|
149
137
|
messageType: MessageType.RPC,
|
|
150
138
|
messageId: '1',
|
|
151
139
|
body: {
|
|
@@ -204,7 +192,7 @@ describe('ConnectionManager', () => {
|
|
|
204
192
|
await connectionManager2.start()
|
|
205
193
|
|
|
206
194
|
const msg: Message = {
|
|
207
|
-
serviceId,
|
|
195
|
+
serviceId: SERVICE_ID,
|
|
208
196
|
messageType: MessageType.RPC,
|
|
209
197
|
messageId: '1',
|
|
210
198
|
body: {
|
|
@@ -255,7 +243,7 @@ describe('ConnectionManager', () => {
|
|
|
255
243
|
await connectionManager4.start()
|
|
256
244
|
|
|
257
245
|
const msg: Message = {
|
|
258
|
-
serviceId,
|
|
246
|
+
serviceId: SERVICE_ID,
|
|
259
247
|
messageType: MessageType.RPC,
|
|
260
248
|
messageId: '1',
|
|
261
249
|
body: {
|
|
@@ -319,7 +307,7 @@ describe('ConnectionManager', () => {
|
|
|
319
307
|
const peerDescriptor = connectionManager1.getLocalPeerDescriptor()
|
|
320
308
|
peerDescriptor.nodeId = new Uint8Array([12, 12, 12, 12])
|
|
321
309
|
const msg: Message = {
|
|
322
|
-
serviceId,
|
|
310
|
+
serviceId: SERVICE_ID,
|
|
323
311
|
messageType: MessageType.RPC,
|
|
324
312
|
messageId: '1',
|
|
325
313
|
targetDescriptor: peerDescriptor,
|
|
@@ -337,25 +325,20 @@ describe('ConnectionManager', () => {
|
|
|
337
325
|
|
|
338
326
|
it('Cannot send to a WebSocketServer if nodeIds do not match', async () => {
|
|
339
327
|
|
|
340
|
-
const peerDescriptor1 = {
|
|
341
|
-
nodeId: createRandomNodeId(),
|
|
342
|
-
type: NodeType.NODEJS,
|
|
328
|
+
const peerDescriptor1 = createMockPeerDescriptor({
|
|
343
329
|
websocket: {
|
|
344
330
|
host: '127.0.0.1',
|
|
345
331
|
port: 10002,
|
|
346
332
|
tls: false
|
|
347
333
|
}
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
const peerDescriptor2 = {
|
|
351
|
-
nodeId: createRandomNodeId(),
|
|
352
|
-
type: NodeType.NODEJS,
|
|
334
|
+
})
|
|
335
|
+
const peerDescriptor2 = createMockPeerDescriptor({
|
|
353
336
|
websocket: {
|
|
354
337
|
host: '127.0.0.1',
|
|
355
338
|
port: 10003,
|
|
356
339
|
tls: false
|
|
357
340
|
}
|
|
358
|
-
}
|
|
341
|
+
})
|
|
359
342
|
const connectionManager1 = createConnectionManager({
|
|
360
343
|
transport: mockTransport,
|
|
361
344
|
websocketHost: '127.0.0.1',
|
|
@@ -375,12 +358,12 @@ describe('ConnectionManager', () => {
|
|
|
375
358
|
await connectionManager2.start()
|
|
376
359
|
|
|
377
360
|
const msg: Message = {
|
|
378
|
-
serviceId,
|
|
361
|
+
serviceId: SERVICE_ID,
|
|
379
362
|
messageType: MessageType.RPC,
|
|
380
363
|
messageId: '1',
|
|
381
364
|
targetDescriptor: {
|
|
382
365
|
// This is not the correct nodeId of peerDescriptor2
|
|
383
|
-
nodeId:
|
|
366
|
+
nodeId: createRandomNodeId(),
|
|
384
367
|
type: NodeType.NODEJS,
|
|
385
368
|
websocket: peerDescriptor2.websocket
|
|
386
369
|
},
|
|
@@ -1,24 +1,19 @@
|
|
|
1
1
|
import { LatencyType, Simulator } from '../../src/connection/simulator/Simulator'
|
|
2
2
|
import { getRandomRegion } from '../../src/connection/simulator/pings'
|
|
3
3
|
import { DhtNode } from '../../src/dht/DhtNode'
|
|
4
|
-
import {
|
|
5
|
-
import { createMockConnectionDhtNode } from '../utils/utils'
|
|
4
|
+
import { createMockConnectionDhtNode, createMockPeerDescriptor } from '../utils/utils'
|
|
6
5
|
|
|
7
6
|
const NUM_OF_NODES_PER_KBUCKET = 8
|
|
8
7
|
|
|
9
8
|
const runTest = async (latencyType: LatencyType) => {
|
|
10
9
|
const simulator = new Simulator(latencyType)
|
|
11
|
-
const
|
|
12
|
-
const entryPoint = await createMockConnectionDhtNode(entryPointId, simulator, undefined, NUM_OF_NODES_PER_KBUCKET)
|
|
13
|
-
const entrypointDescriptor = {
|
|
14
|
-
nodeId: entryPoint.getNodeId().value,
|
|
15
|
-
type: NodeType.NODEJS,
|
|
10
|
+
const entrypointDescriptor = createMockPeerDescriptor({
|
|
16
11
|
region: getRandomRegion()
|
|
17
|
-
}
|
|
12
|
+
})
|
|
13
|
+
const entryPoint = await createMockConnectionDhtNode(simulator, entrypointDescriptor.nodeId, NUM_OF_NODES_PER_KBUCKET)
|
|
18
14
|
const nodes: DhtNode[] = []
|
|
19
15
|
for (let i = 1; i < 100; i++) {
|
|
20
|
-
const
|
|
21
|
-
const node = await createMockConnectionDhtNode(nodeId, simulator, undefined, NUM_OF_NODES_PER_KBUCKET)
|
|
16
|
+
const node = await createMockConnectionDhtNode(simulator, undefined, NUM_OF_NODES_PER_KBUCKET)
|
|
22
17
|
nodes.push(node)
|
|
23
18
|
}
|
|
24
19
|
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { DhtNode } from '../../src/dht/DhtNode'
|
|
2
1
|
import { LatencyType, Simulator } from '../../src/connection/simulator/Simulator'
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
2
|
+
import { DhtNode } from '../../src/dht/DhtNode'
|
|
3
|
+
import { createRandomNodeId, getNodeIdFromBinary } from '../../src/helpers/nodeId'
|
|
4
|
+
import { getNodeIdFromPeerDescriptor } from '../../src/helpers/peerIdFromPeerDescriptor'
|
|
5
|
+
import { createMockDataEntry, expectEqualData } from '../utils/mock/mockDataEntry'
|
|
6
|
+
import { createMockConnectionDhtNode } from '../utils/utils'
|
|
8
7
|
|
|
9
8
|
describe('DhtNodeExternalApi', () => {
|
|
10
9
|
|
|
@@ -14,8 +13,8 @@ describe('DhtNodeExternalApi', () => {
|
|
|
14
13
|
|
|
15
14
|
beforeEach(async () => {
|
|
16
15
|
simulator = new Simulator(LatencyType.NONE)
|
|
17
|
-
dhtNode1 = await createMockConnectionDhtNode(
|
|
18
|
-
remote = await createMockConnectionDhtNode(
|
|
16
|
+
dhtNode1 = await createMockConnectionDhtNode(simulator)
|
|
17
|
+
remote = await createMockConnectionDhtNode(simulator)
|
|
19
18
|
await dhtNode1.joinDht([dhtNode1.getLocalPeerDescriptor()])
|
|
20
19
|
})
|
|
21
20
|
|
|
@@ -28,12 +27,10 @@ describe('DhtNodeExternalApi', () => {
|
|
|
28
27
|
})
|
|
29
28
|
|
|
30
29
|
it('findData happy path', async () => {
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
await
|
|
34
|
-
|
|
35
|
-
const foundData = await remote.findDataViaPeer(key, dhtNode1.getLocalPeerDescriptor())
|
|
36
|
-
expect(Any.unpack(foundData[0].data!, PeerDescriptor)).toEqual(dhtNode1.getLocalPeerDescriptor())
|
|
30
|
+
const entry = createMockDataEntry()
|
|
31
|
+
await dhtNode1.storeDataToDht(entry.key, entry.data!)
|
|
32
|
+
const foundData = await remote.findDataViaPeer(entry.key, dhtNode1.getLocalPeerDescriptor())
|
|
33
|
+
expectEqualData(foundData[0], entry)
|
|
37
34
|
})
|
|
38
35
|
|
|
39
36
|
it('findData returns empty array if no data found', async () => {
|
|
@@ -42,14 +39,11 @@ describe('DhtNodeExternalApi', () => {
|
|
|
42
39
|
})
|
|
43
40
|
|
|
44
41
|
it('external store data happy path', async () => {
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const foundData = await remote.findDataViaPeer(key, dhtNode1.getLocalPeerDescriptor())
|
|
51
|
-
expect(areEqualPeerDescriptors(Any.unpack(foundData[0].data!, PeerDescriptor), storedPeerDescriptor)).toEqual(true)
|
|
52
|
-
expect(areEqualPeerDescriptors(foundData[0].creator!, remote.getLocalPeerDescriptor())).toEqual(true)
|
|
42
|
+
const entry = createMockDataEntry()
|
|
43
|
+
await remote.storeDataViaPeer(entry.key, entry.data!, dhtNode1.getLocalPeerDescriptor())
|
|
44
|
+
const foundData = await remote.findDataViaPeer(entry.key, dhtNode1.getLocalPeerDescriptor())
|
|
45
|
+
expectEqualData(foundData[0], entry)
|
|
46
|
+
expect(getNodeIdFromBinary(foundData[0].creator)).toEqual(getNodeIdFromPeerDescriptor(remote.getLocalPeerDescriptor()))
|
|
53
47
|
})
|
|
54
48
|
|
|
55
49
|
})
|
|
@@ -1,46 +1,37 @@
|
|
|
1
1
|
import { DhtNodeRpcRemote } from '../../src/dht/DhtNodeRpcRemote'
|
|
2
|
-
import { RpcCommunicator
|
|
3
|
-
import {
|
|
2
|
+
import { RpcCommunicator } from '@streamr/proto-rpc'
|
|
3
|
+
import { createMockDhtRpc, createMockPeerDescriptor, createMockPeers } from '../utils/utils'
|
|
4
4
|
import {
|
|
5
5
|
ClosestPeersRequest,
|
|
6
6
|
ClosestPeersResponse,
|
|
7
|
-
NodeType,
|
|
8
|
-
PeerDescriptor,
|
|
9
7
|
PingRequest,
|
|
10
8
|
PingResponse
|
|
11
9
|
} from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
12
10
|
import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
|
|
12
|
+
const SERVICE_ID = 'test'
|
|
15
13
|
|
|
16
14
|
describe('DhtNodeRpcRemote', () => {
|
|
17
15
|
|
|
18
16
|
let rpcRemote: DhtNodeRpcRemote
|
|
19
17
|
let clientRpcCommunicator: RpcCommunicator
|
|
20
18
|
let serverRpcCommunicator: RpcCommunicator
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
type: NodeType.NODEJS
|
|
25
|
-
}
|
|
26
|
-
const serverPeerDescriptor: PeerDescriptor = {
|
|
27
|
-
nodeId: generateId('server'),
|
|
28
|
-
type: NodeType.NODEJS
|
|
29
|
-
}
|
|
19
|
+
const clientPeerDescriptor = createMockPeerDescriptor()
|
|
20
|
+
const serverPeerDescriptor = createMockPeerDescriptor()
|
|
21
|
+
const mockDhtRpc = createMockDhtRpc(createMockPeers())
|
|
30
22
|
|
|
31
23
|
beforeEach(() => {
|
|
32
24
|
clientRpcCommunicator = new RpcCommunicator()
|
|
33
25
|
serverRpcCommunicator = new RpcCommunicator()
|
|
34
|
-
serverRpcCommunicator.registerRpcMethod(ClosestPeersRequest, ClosestPeersResponse, 'getClosestPeers',
|
|
35
|
-
serverRpcCommunicator.registerRpcMethod(PingRequest, PingResponse, 'ping',
|
|
26
|
+
serverRpcCommunicator.registerRpcMethod(ClosestPeersRequest, ClosestPeersResponse, 'getClosestPeers', mockDhtRpc.getClosestPeers)
|
|
27
|
+
serverRpcCommunicator.registerRpcMethod(PingRequest, PingResponse, 'ping', mockDhtRpc.ping)
|
|
36
28
|
clientRpcCommunicator.on('outgoingMessage', (message: RpcMessage) => {
|
|
37
29
|
serverRpcCommunicator.handleIncomingMessage(message)
|
|
38
30
|
})
|
|
39
31
|
serverRpcCommunicator.on('outgoingMessage', (message: RpcMessage) => {
|
|
40
32
|
clientRpcCommunicator.handleIncomingMessage(message)
|
|
41
33
|
})
|
|
42
|
-
|
|
43
|
-
rpcRemote = new DhtNodeRpcRemote(clientPeerDescriptor, serverPeerDescriptor, client, serviceId)
|
|
34
|
+
rpcRemote = new DhtNodeRpcRemote(clientPeerDescriptor, serverPeerDescriptor, SERVICE_ID, clientRpcCommunicator)
|
|
44
35
|
})
|
|
45
36
|
|
|
46
37
|
afterEach(() => {
|
|
@@ -55,17 +46,17 @@ describe('DhtNodeRpcRemote', () => {
|
|
|
55
46
|
|
|
56
47
|
it('getClosestPeers happy path', async () => {
|
|
57
48
|
const neighbors = await rpcRemote.getClosestPeers(clientPeerDescriptor.nodeId)
|
|
58
|
-
expect(neighbors.length).toEqual(
|
|
49
|
+
expect(neighbors.length).toEqual(createMockPeers().length)
|
|
59
50
|
})
|
|
60
51
|
|
|
61
52
|
it('ping error path', async () => {
|
|
62
|
-
serverRpcCommunicator.registerRpcMethod(PingRequest, PingResponse, 'ping',
|
|
53
|
+
serverRpcCommunicator.registerRpcMethod(PingRequest, PingResponse, 'ping', mockDhtRpc.throwPingError)
|
|
63
54
|
const active = await rpcRemote.ping()
|
|
64
55
|
expect(active).toEqual(false)
|
|
65
56
|
})
|
|
66
57
|
|
|
67
58
|
it('getClosestPeers error path', async () => {
|
|
68
|
-
serverRpcCommunicator.registerRpcMethod(ClosestPeersRequest, ClosestPeersResponse, 'getClosestPeers',
|
|
59
|
+
serverRpcCommunicator.registerRpcMethod(ClosestPeersRequest, ClosestPeersResponse, 'getClosestPeers', mockDhtRpc.throwGetClosestPeersError)
|
|
69
60
|
await expect(rpcRemote.getClosestPeers(clientPeerDescriptor.nodeId))
|
|
70
61
|
.rejects.toThrow('Closest peers error')
|
|
71
62
|
})
|
|
@@ -1,26 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createMockDhtRpc, createMockPeerDescriptor, createMockPeers } from '../utils/utils'
|
|
2
2
|
import { ProtoRpcClient, RpcCommunicator, RpcError, toProtoRpcClient } from '@streamr/proto-rpc'
|
|
3
3
|
import { DhtNodeRpcClient } from '../../src/proto/packages/dht/protos/DhtRpc.client'
|
|
4
|
-
import {
|
|
5
|
-
import { ClosestPeersRequest, ClosestPeersResponse, NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
4
|
+
import { ClosestPeersRequest, ClosestPeersResponse } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
6
5
|
import { wait } from '@streamr/utils'
|
|
7
6
|
import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
|
|
7
|
+
import { getNodeIdFromPeerDescriptor } from '../../src/helpers/peerIdFromPeerDescriptor'
|
|
8
8
|
|
|
9
9
|
describe('DhtRpc', () => {
|
|
10
|
+
|
|
10
11
|
let rpcCommunicator1: RpcCommunicator
|
|
11
12
|
let rpcCommunicator2: RpcCommunicator
|
|
12
13
|
let client1: ProtoRpcClient<DhtNodeRpcClient>
|
|
13
14
|
let client2: ProtoRpcClient<DhtNodeRpcClient>
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const peerDescriptor2: PeerDescriptor = {
|
|
21
|
-
nodeId: generateId('peer2'),
|
|
22
|
-
type: NodeType.NODEJS
|
|
23
|
-
}
|
|
15
|
+
const peerDescriptor1 = createMockPeerDescriptor()
|
|
16
|
+
const peerDescriptor2 = createMockPeerDescriptor()
|
|
17
|
+
const neighbors = createMockPeers()
|
|
18
|
+
const mockDhtRpc = createMockDhtRpc(neighbors)
|
|
24
19
|
|
|
25
20
|
const outgoingListener2 = (message: RpcMessage) => {
|
|
26
21
|
rpcCommunicator1.handleIncomingMessage(message)
|
|
@@ -28,10 +23,10 @@ describe('DhtRpc', () => {
|
|
|
28
23
|
|
|
29
24
|
beforeEach(() => {
|
|
30
25
|
rpcCommunicator1 = new RpcCommunicator()
|
|
31
|
-
rpcCommunicator1.registerRpcMethod(ClosestPeersRequest, ClosestPeersResponse, 'getClosestPeers',
|
|
26
|
+
rpcCommunicator1.registerRpcMethod(ClosestPeersRequest, ClosestPeersResponse, 'getClosestPeers', mockDhtRpc.getClosestPeers)
|
|
32
27
|
|
|
33
28
|
rpcCommunicator2 = new RpcCommunicator()
|
|
34
|
-
rpcCommunicator2.registerRpcMethod(ClosestPeersRequest, ClosestPeersResponse, 'getClosestPeers',
|
|
29
|
+
rpcCommunicator2.registerRpcMethod(ClosestPeersRequest, ClosestPeersResponse, 'getClosestPeers', mockDhtRpc.getClosestPeers)
|
|
35
30
|
|
|
36
31
|
rpcCommunicator1.on('outgoingMessage', (message: RpcMessage) => {
|
|
37
32
|
rpcCommunicator2.handleIncomingMessage(message)
|
|
@@ -57,7 +52,7 @@ describe('DhtRpc', () => {
|
|
|
57
52
|
}
|
|
58
53
|
)
|
|
59
54
|
const res1 = await response1
|
|
60
|
-
expect(res1.peers).toEqual(
|
|
55
|
+
expect(res1.peers.map((p) => getNodeIdFromPeerDescriptor(p))).toEqual(neighbors.map((n) => getNodeIdFromPeerDescriptor(n)))
|
|
61
56
|
|
|
62
57
|
const response2 = client2.getClosestPeers(
|
|
63
58
|
{ nodeId: peerDescriptor2.nodeId, requestId: '1' },
|
|
@@ -67,7 +62,7 @@ describe('DhtRpc', () => {
|
|
|
67
62
|
}
|
|
68
63
|
)
|
|
69
64
|
const res2 = await response2
|
|
70
|
-
expect(res2.peers).toEqual(
|
|
65
|
+
expect(res2.peers.map((p) => getNodeIdFromPeerDescriptor(p))).toEqual(neighbors.map((n) => getNodeIdFromPeerDescriptor(n)))
|
|
71
66
|
})
|
|
72
67
|
|
|
73
68
|
it('Default RPC timeout, client side', async () => {
|
|
@@ -91,7 +86,7 @@ describe('DhtRpc', () => {
|
|
|
91
86
|
let timeout: NodeJS.Timeout
|
|
92
87
|
|
|
93
88
|
async function respondGetClosestPeersWithTimeout(): Promise<ClosestPeersResponse> {
|
|
94
|
-
const neighbors =
|
|
89
|
+
const neighbors = createMockPeers()
|
|
95
90
|
const response: ClosestPeersResponse = {
|
|
96
91
|
peers: neighbors,
|
|
97
92
|
requestId: 'why am i still here'
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { LatencyType, Simulator } from '../../src/connection/simulator/Simulator'
|
|
2
2
|
import { DhtNode } from '../../src/dht/DhtNode'
|
|
3
|
-
import { PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
3
|
+
import { PeerDescriptor, RecursiveOperation } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
4
4
|
import { createMockConnectionDhtNode, waitConnectionManagersReadyForTesting } from '../utils/utils'
|
|
5
5
|
import { PeerID } from '../../src/helpers/PeerID'
|
|
6
6
|
import { peerIdFromPeerDescriptor } from '../../src/helpers/peerIdFromPeerDescriptor'
|
|
7
|
+
import { hexToBinary } from '@streamr/utils'
|
|
8
|
+
|
|
9
|
+
const NUM_NODES = 100
|
|
10
|
+
const K = 2
|
|
7
11
|
|
|
8
12
|
describe('Find correctness', () => {
|
|
9
13
|
|
|
@@ -11,18 +15,14 @@ describe('Find correctness', () => {
|
|
|
11
15
|
let nodes: DhtNode[]
|
|
12
16
|
let entrypointDescriptor: PeerDescriptor
|
|
13
17
|
const simulator = new Simulator(LatencyType.REAL)
|
|
14
|
-
const NUM_NODES = 100
|
|
15
|
-
const K = 2
|
|
16
18
|
|
|
17
19
|
beforeEach(async () => {
|
|
18
20
|
nodes = []
|
|
19
|
-
|
|
20
|
-
entryPoint = await createMockConnectionDhtNode(entryPointId, simulator, undefined, K)
|
|
21
|
+
entryPoint = await createMockConnectionDhtNode(simulator, undefined, K)
|
|
21
22
|
nodes.push(entryPoint)
|
|
22
23
|
entrypointDescriptor = entryPoint.getLocalPeerDescriptor()
|
|
23
24
|
for (let i = 1; i < NUM_NODES; i++) {
|
|
24
|
-
const
|
|
25
|
-
const node = await createMockConnectionDhtNode(nodeId, simulator, undefined, K, 20, 60000)
|
|
25
|
+
const node = await createMockConnectionDhtNode(simulator, undefined, K, 20, 60000)
|
|
26
26
|
nodes.push(node)
|
|
27
27
|
}
|
|
28
28
|
await entryPoint.joinDht([entrypointDescriptor])
|
|
@@ -38,10 +38,10 @@ describe('Find correctness', () => {
|
|
|
38
38
|
})
|
|
39
39
|
|
|
40
40
|
it('Entrypoint can find a node from the network (exact match)', async () => {
|
|
41
|
-
const
|
|
42
|
-
const results = await entryPoint.
|
|
41
|
+
const targetId = hexToBinary(nodes[45].getNodeId())
|
|
42
|
+
const results = await entryPoint.executeRecursiveOperation(targetId, RecursiveOperation.FIND_NODE)
|
|
43
43
|
expect(results.closestNodes.length).toBeGreaterThanOrEqual(5)
|
|
44
|
-
expect(PeerID.fromValue(
|
|
44
|
+
expect(PeerID.fromValue(targetId).equals(peerIdFromPeerDescriptor(results.closestNodes[0])))
|
|
45
45
|
}, 30000)
|
|
46
46
|
|
|
47
47
|
})
|