@streamr/dht 100.0.0-testnet-one.4 → 100.0.0-testnet-two.1
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/package.json +66 -0
- 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/Handshaker.d.ts +1 -1
- package/dist/src/connection/Handshaker.js +14 -5
- package/dist/src/connection/Handshaker.js.map +1 -1
- package/dist/src/connection/ManagedConnection.d.ts +4 -7
- package/dist/src/connection/ManagedConnection.js +9 -13
- 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 +21 -14
- 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 +48 -44
- 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 +41 -54
- package/dist/src/dht/DhtNode.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcLocal.d.ts +2 -3
- package/dist/src/dht/DhtNodeRpcLocal.js +1 -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 +9 -11
- 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 -23
- 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/helpers/versionCompatibility.d.ts +2 -0
- package/dist/src/helpers/versionCompatibility.js +18 -0
- package/dist/src/helpers/versionCompatibility.js.map +1 -0
- 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 +49 -65
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +43 -58
- 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 +20 -24
- 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/Handshaker.ts +21 -6
- package/src/connection/ManagedConnection.ts +20 -34
- 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 +25 -18
- 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 +57 -61
- 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 +69 -71
- package/src/dht/DhtNodeRpcLocal.ts +1 -3
- package/src/dht/DhtNodeRpcRemote.ts +14 -18
- 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 -27
- 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/helpers/versionCompatibility.ts +13 -0
- 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 +67 -90
- 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/unit/versionCompatibility.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/tsconfig.browser.json +2 -1
- package/tsconfig.jest.json +2 -1
- package/tsconfig.node.json +2 -1
- 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,35 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RandomContactList = void 0;
|
|
4
|
+
const nodeId_1 = require("../../helpers/nodeId");
|
|
4
5
|
const ContactList_1 = require("./ContactList");
|
|
5
6
|
class RandomContactList extends ContactList_1.ContactList {
|
|
6
|
-
constructor(
|
|
7
|
-
super(
|
|
7
|
+
constructor(localNodeId, maxSize, randomness = 0.20, defaultContactQueryLimit) {
|
|
8
|
+
super(localNodeId, maxSize, defaultContactQueryLimit);
|
|
8
9
|
this.randomness = randomness;
|
|
9
10
|
}
|
|
10
11
|
addContact(contact) {
|
|
11
|
-
if (this.
|
|
12
|
+
if ((0, nodeId_1.areEqualNodeIds)(this.localNodeId, contact.getNodeId())) {
|
|
12
13
|
return;
|
|
13
14
|
}
|
|
14
|
-
if (!this.contactsById.has(contact.
|
|
15
|
+
if (!this.contactsById.has(contact.getNodeId())) {
|
|
15
16
|
const roll = Math.random();
|
|
16
17
|
if (roll < this.randomness) {
|
|
17
18
|
if (this.getSize() === this.maxSize && this.getSize() > 0) {
|
|
18
19
|
const toRemove = this.contactIds[0];
|
|
19
20
|
this.removeContact(toRemove);
|
|
20
21
|
}
|
|
21
|
-
this.contactIds.push(contact.
|
|
22
|
-
this.contactsById.set(contact.
|
|
22
|
+
this.contactIds.push(contact.getNodeId());
|
|
23
|
+
this.contactsById.set(contact.getNodeId(), new ContactList_1.ContactState(contact));
|
|
23
24
|
this.emit('newContact', contact, this.getContacts());
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
27
|
}
|
|
27
28
|
removeContact(id) {
|
|
28
|
-
if (this.contactsById.has(id
|
|
29
|
-
const removed = this.contactsById.get(id
|
|
30
|
-
const index = this.contactIds.findIndex((
|
|
29
|
+
if (this.contactsById.has(id)) {
|
|
30
|
+
const removed = this.contactsById.get(id).contact;
|
|
31
|
+
const index = this.contactIds.findIndex((nodeId) => (0, nodeId_1.areEqualNodeIds)(nodeId, id));
|
|
31
32
|
this.contactIds.splice(index, 1);
|
|
32
|
-
this.contactsById.delete(id
|
|
33
|
+
this.contactsById.delete(id);
|
|
33
34
|
this.emit('contactRemoved', removed, this.getContacts());
|
|
34
35
|
return true;
|
|
35
36
|
}
|
|
@@ -38,7 +39,7 @@ class RandomContactList extends ContactList_1.ContactList {
|
|
|
38
39
|
getContacts(limit = this.defaultContactQueryLimit) {
|
|
39
40
|
const ret = [];
|
|
40
41
|
this.contactIds.forEach((contactId) => {
|
|
41
|
-
const contact = this.contactsById.get(contactId
|
|
42
|
+
const contact = this.contactsById.get(contactId);
|
|
42
43
|
if (contact) {
|
|
43
44
|
ret.push(contact.contact);
|
|
44
45
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RandomContactList.js","sourceRoot":"","sources":["../../../../src/dht/contact/RandomContactList.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"RandomContactList.js","sourceRoot":"","sources":["../../../../src/dht/contact/RandomContactList.ts"],"names":[],"mappings":";;;AAAA,iDAA8D;AAC9D,+CAAyD;AAEzD,MAAa,iBAAyD,SAAQ,yBAAc;IAIxF,YACI,WAAmB,EACnB,OAAe,EACf,UAAU,GAAG,IAAI,EACjB,wBAAiC;QAEjC,KAAK,CAAC,WAAW,EAAE,OAAO,EAAE,wBAAwB,CAAC,CAAA;QACrD,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;IAChC,CAAC;IAED,UAAU,CAAC,OAAU;QACjB,IAAI,IAAA,wBAAe,EAAC,IAAI,CAAC,WAAW,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC,EAAE;YACxD,OAAM;SACT;QACD,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,EAAE;YAC7C,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,EAAE,CAAA;YAC1B,IAAI,IAAI,GAAG,IAAI,CAAC,UAAU,EAAE;gBACxB,IAAI,IAAI,CAAC,OAAO,EAAE,KAAK,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,EAAE,GAAG,CAAC,EAAE;oBACvD,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAA;oBACnC,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAA;iBAC/B;gBACD,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,CAAA;gBACzC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,IAAI,0BAAY,CAAC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
1
|
+
import type { ServiceInfo } from '@protobuf-ts/runtime-rpc';
|
|
2
|
+
import { ClassType, ClientTransport, ProtoRpcClient, RpcCommunicator } from '@streamr/proto-rpc';
|
|
1
3
|
import { PeerDescriptor } from '../../proto/packages/dht/protos/DhtRpc';
|
|
2
|
-
import { ProtoRpcClient } from '@streamr/proto-rpc';
|
|
3
4
|
import { DhtRpcOptions } from '../../rpc-protocol/DhtRpcOptions';
|
|
4
5
|
import { ServiceID } from '../../types/ServiceID';
|
|
5
6
|
export declare const EXISTING_CONNECTION_TIMEOUT = 5000;
|
|
6
|
-
export declare abstract class RpcRemote<T> {
|
|
7
|
+
export declare abstract class RpcRemote<T extends ServiceInfo & ClassType> {
|
|
7
8
|
private readonly localPeerDescriptor;
|
|
8
9
|
private readonly remotePeerDescriptor;
|
|
9
10
|
private readonly serviceId;
|
|
10
11
|
private readonly client;
|
|
11
12
|
private readonly timeout?;
|
|
12
|
-
constructor(localPeerDescriptor: PeerDescriptor, remotePeerDescriptor: PeerDescriptor, serviceId: ServiceID,
|
|
13
|
+
constructor(localPeerDescriptor: PeerDescriptor, remotePeerDescriptor: PeerDescriptor, serviceId: ServiceID, rpcCommunicator: RpcCommunicator, clientClass: {
|
|
14
|
+
new (clientTransport: ClientTransport): T;
|
|
15
|
+
}, timeout?: number);
|
|
13
16
|
getPeerDescriptor(): PeerDescriptor;
|
|
14
17
|
getLocalPeerDescriptor(): PeerDescriptor;
|
|
15
|
-
getServiceId():
|
|
18
|
+
getServiceId(): ServiceID;
|
|
16
19
|
getClient(): ProtoRpcClient<T>;
|
|
17
20
|
formDhtRpcOptions(opts?: Omit<DhtRpcOptions, 'sourceDescriptor' | 'targetDescriptor'>): DhtRpcOptions;
|
|
18
21
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RpcRemote = exports.EXISTING_CONNECTION_TIMEOUT = void 0;
|
|
4
|
+
const proto_rpc_1 = require("@streamr/proto-rpc");
|
|
4
5
|
const IConnection_1 = require("../../connection/IConnection");
|
|
5
6
|
const Connectivity_1 = require("../../helpers/Connectivity");
|
|
6
7
|
// Should connect directly to the server, timeout can be low
|
|
@@ -26,10 +27,12 @@ const getTimeout = (localPeerDescriptor, remotePeerDescriptor) => {
|
|
|
26
27
|
return WEBRTC_TIMEOUT;
|
|
27
28
|
};
|
|
28
29
|
class RpcRemote {
|
|
29
|
-
constructor(localPeerDescriptor, remotePeerDescriptor, serviceId,
|
|
30
|
+
constructor(localPeerDescriptor, remotePeerDescriptor, serviceId, rpcCommunicator,
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/prefer-function-type
|
|
32
|
+
clientClass, timeout) {
|
|
30
33
|
this.localPeerDescriptor = localPeerDescriptor;
|
|
31
34
|
this.remotePeerDescriptor = remotePeerDescriptor;
|
|
32
|
-
this.client =
|
|
35
|
+
this.client = (0, proto_rpc_1.toProtoRpcClient)(new clientClass(rpcCommunicator.getRpcClientTransport()));
|
|
33
36
|
this.serviceId = serviceId;
|
|
34
37
|
this.timeout = timeout;
|
|
35
38
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RpcRemote.js","sourceRoot":"","sources":["../../../../src/dht/contact/RpcRemote.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"RpcRemote.js","sourceRoot":"","sources":["../../../../src/dht/contact/RpcRemote.ts"],"names":[],"mappings":";;;AACA,kDAAkH;AAClH,8DAA6D;AAC7D,6DAAmE;AAKnE,4DAA4D;AAC5D,MAAM,wBAAwB,GAAG,IAAI,CAAA;AACrC,uGAAuG;AACvG,kDAAkD;AAClD,MAAM,wBAAwB,GAAG,IAAI,CAAA;AACrC,sFAAsF;AACtF,MAAM,cAAc,GAAG,KAAK,CAAA;AAC5B,2CAA2C;AAC9B,QAAA,2BAA2B,GAAG,IAAI,CAAA;AAE/C,MAAM,UAAU,GAAG,CAAC,mBAAmC,EA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AU,CAAC,IAAI,CAAC,mBAAmB,EAAE,IAAI,CAAC,oBAAoB,CAAC;YACxF,GAAG,IAAI;SACV,CAAA;IACL,CAAC;CACJ;AAhDD,8BAgDC"}
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import { PeerID } from '../../helpers/PeerID';
|
|
2
1
|
import { ContactState, Events } from './ContactList';
|
|
3
2
|
import EventEmitter from 'eventemitter3';
|
|
3
|
+
import { NodeID } from '../../helpers/nodeId';
|
|
4
4
|
export interface SortedContactListConfig {
|
|
5
|
-
referenceId:
|
|
5
|
+
referenceId: NodeID;
|
|
6
6
|
allowToContainReferenceId: boolean;
|
|
7
7
|
emitEvents: boolean;
|
|
8
8
|
maxSize?: number;
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
nodeIdDistanceLimit?: NodeID;
|
|
10
|
+
excludedNodeIds?: Set<NodeID>;
|
|
11
11
|
}
|
|
12
12
|
export declare class SortedContactList<C extends {
|
|
13
|
-
|
|
13
|
+
getNodeId: () => NodeID;
|
|
14
14
|
}> extends EventEmitter<Events<C>> {
|
|
15
15
|
private config;
|
|
16
16
|
private contactsById;
|
|
17
17
|
private contactIds;
|
|
18
18
|
constructor(config: SortedContactListConfig);
|
|
19
|
-
getClosestContactId():
|
|
20
|
-
getContactIds():
|
|
19
|
+
getClosestContactId(): NodeID;
|
|
20
|
+
getContactIds(): NodeID[];
|
|
21
21
|
addContact(contact: C): void;
|
|
22
22
|
addContacts(contacts: C[]): void;
|
|
23
|
-
getContact(id:
|
|
24
|
-
setContacted(contactId:
|
|
25
|
-
setActive(contactId:
|
|
23
|
+
getContact(id: NodeID): ContactState<C> | undefined;
|
|
24
|
+
setContacted(contactId: NodeID): void;
|
|
25
|
+
setActive(contactId: NodeID): void;
|
|
26
26
|
getClosestContacts(limit?: number): C[];
|
|
27
27
|
getUncontactedContacts(num: number): C[];
|
|
28
28
|
getActiveContacts(limit?: number): C[];
|
|
29
|
-
compareIds(id1:
|
|
29
|
+
compareIds(id1: NodeID, id2: NodeID): number;
|
|
30
30
|
private distanceToReferenceId;
|
|
31
|
-
removeContact(id:
|
|
32
|
-
isActive(id:
|
|
31
|
+
removeContact(id: NodeID): boolean;
|
|
32
|
+
isActive(id: NodeID): boolean;
|
|
33
33
|
getAllContacts(): C[];
|
|
34
34
|
getSize(): number;
|
|
35
35
|
clear(): void;
|
|
@@ -8,6 +8,7 @@ const ContactList_1 = require("./ContactList");
|
|
|
8
8
|
const lodash_1 = require("lodash");
|
|
9
9
|
const eventemitter3_1 = __importDefault(require("eventemitter3"));
|
|
10
10
|
const PeerManager_1 = require("../PeerManager");
|
|
11
|
+
const nodeId_1 = require("../../helpers/nodeId");
|
|
11
12
|
class SortedContactList extends eventemitter3_1.default {
|
|
12
13
|
constructor(config) {
|
|
13
14
|
super();
|
|
@@ -23,27 +24,28 @@ class SortedContactList extends eventemitter3_1.default {
|
|
|
23
24
|
return this.contactIds;
|
|
24
25
|
}
|
|
25
26
|
addContact(contact) {
|
|
26
|
-
if (this.config.
|
|
27
|
-
&& this.config.excludedPeerIDs.some((peerId) => contact.getPeerId().equals(peerId))) {
|
|
27
|
+
if (this.config.excludedNodeIds !== undefined && this.config.excludedNodeIds.has(contact.getNodeId())) {
|
|
28
28
|
return;
|
|
29
29
|
}
|
|
30
|
-
if ((!this.config.allowToContainReferenceId && this.config.referenceId
|
|
31
|
-
(this.config.
|
|
30
|
+
if ((!this.config.allowToContainReferenceId && (0, nodeId_1.areEqualNodeIds)(this.config.referenceId, contact.getNodeId())) ||
|
|
31
|
+
(this.config.nodeIdDistanceLimit !== undefined && this.compareIds(this.config.nodeIdDistanceLimit, contact.getNodeId()) < 0)) {
|
|
32
32
|
return;
|
|
33
33
|
}
|
|
34
|
-
if (!this.contactsById.has(contact.
|
|
34
|
+
if (!this.contactsById.has(contact.getNodeId())) {
|
|
35
35
|
if ((this.config.maxSize === undefined) || (this.contactIds.length < this.config.maxSize)) {
|
|
36
|
-
this.contactsById.set(contact.
|
|
37
|
-
|
|
38
|
-
this.contactIds.
|
|
36
|
+
this.contactsById.set(contact.getNodeId(), new ContactList_1.ContactState(contact));
|
|
37
|
+
// eslint-disable-next-line max-len
|
|
38
|
+
const index = (0, lodash_1.sortedIndexBy)(this.contactIds, contact.getNodeId(), (id) => { return this.distanceToReferenceId(id); });
|
|
39
|
+
this.contactIds.splice(index, 0, contact.getNodeId());
|
|
39
40
|
}
|
|
40
|
-
else if (this.compareIds(this.contactIds[this.config.maxSize - 1], contact.
|
|
41
|
+
else if (this.compareIds(this.contactIds[this.config.maxSize - 1], contact.getNodeId()) > 0) {
|
|
41
42
|
const removedId = this.contactIds.pop();
|
|
42
|
-
const removedContact = this.contactsById.get(removedId
|
|
43
|
-
this.contactsById.delete(removedId
|
|
44
|
-
this.contactsById.set(contact.
|
|
45
|
-
|
|
46
|
-
this.contactIds.
|
|
43
|
+
const removedContact = this.contactsById.get(removedId).contact;
|
|
44
|
+
this.contactsById.delete(removedId);
|
|
45
|
+
this.contactsById.set(contact.getNodeId(), new ContactList_1.ContactState(contact));
|
|
46
|
+
// eslint-disable-next-line max-len
|
|
47
|
+
const index = (0, lodash_1.sortedIndexBy)(this.contactIds, contact.getNodeId(), (id) => { return this.distanceToReferenceId(id); });
|
|
48
|
+
this.contactIds.splice(index, 0, contact.getNodeId());
|
|
47
49
|
if (this.config.emitEvents) {
|
|
48
50
|
this.emit('contactRemoved', removedContact, this.getClosestContacts());
|
|
49
51
|
}
|
|
@@ -57,22 +59,22 @@ class SortedContactList extends eventemitter3_1.default {
|
|
|
57
59
|
contacts.forEach((contact) => this.addContact(contact));
|
|
58
60
|
}
|
|
59
61
|
getContact(id) {
|
|
60
|
-
return this.contactsById.get(id
|
|
62
|
+
return this.contactsById.get(id);
|
|
61
63
|
}
|
|
62
64
|
setContacted(contactId) {
|
|
63
|
-
if (this.contactsById.has(contactId
|
|
64
|
-
this.contactsById.get(contactId
|
|
65
|
+
if (this.contactsById.has(contactId)) {
|
|
66
|
+
this.contactsById.get(contactId).contacted = true;
|
|
65
67
|
}
|
|
66
68
|
}
|
|
67
69
|
setActive(contactId) {
|
|
68
|
-
if (this.contactsById.has(contactId
|
|
69
|
-
this.contactsById.get(contactId
|
|
70
|
+
if (this.contactsById.has(contactId)) {
|
|
71
|
+
this.contactsById.get(contactId).active = true;
|
|
70
72
|
}
|
|
71
73
|
}
|
|
72
74
|
getClosestContacts(limit) {
|
|
73
75
|
const ret = [];
|
|
74
76
|
this.contactIds.forEach((contactId) => {
|
|
75
|
-
const contact = this.contactsById.get(contactId
|
|
77
|
+
const contact = this.contactsById.get(contactId);
|
|
76
78
|
if (contact) {
|
|
77
79
|
ret.push(contact.contact);
|
|
78
80
|
}
|
|
@@ -87,7 +89,7 @@ class SortedContactList extends eventemitter3_1.default {
|
|
|
87
89
|
getUncontactedContacts(num) {
|
|
88
90
|
const ret = [];
|
|
89
91
|
for (const contactId of this.contactIds) {
|
|
90
|
-
const contact = this.contactsById.get(contactId
|
|
92
|
+
const contact = this.contactsById.get(contactId);
|
|
91
93
|
if (contact && !contact.contacted) {
|
|
92
94
|
ret.push(contact.contact);
|
|
93
95
|
if (ret.length >= num) {
|
|
@@ -100,7 +102,7 @@ class SortedContactList extends eventemitter3_1.default {
|
|
|
100
102
|
getActiveContacts(limit) {
|
|
101
103
|
const ret = [];
|
|
102
104
|
this.contactIds.forEach((contactId) => {
|
|
103
|
-
const contact = this.contactsById.get(contactId
|
|
105
|
+
const contact = this.contactsById.get(contactId);
|
|
104
106
|
if (contact && contact.active) {
|
|
105
107
|
ret.push(contact.contact);
|
|
106
108
|
}
|
|
@@ -119,14 +121,16 @@ class SortedContactList extends eventemitter3_1.default {
|
|
|
119
121
|
}
|
|
120
122
|
// TODO inline this method?
|
|
121
123
|
distanceToReferenceId(id) {
|
|
122
|
-
|
|
124
|
+
// TODO maybe this class should store the referenceId also as UInt8Array so that we don't need to convert it here?
|
|
125
|
+
return (0, PeerManager_1.getDistance)(this.config.referenceId, id);
|
|
123
126
|
}
|
|
124
127
|
removeContact(id) {
|
|
125
|
-
if (this.contactsById.has(id
|
|
126
|
-
const removed = this.contactsById.get(id
|
|
127
|
-
|
|
128
|
+
if (this.contactsById.has(id)) {
|
|
129
|
+
const removed = this.contactsById.get(id).contact;
|
|
130
|
+
// TODO use sortedIndexBy?
|
|
131
|
+
const index = this.contactIds.findIndex((nodeId) => (0, nodeId_1.areEqualNodeIds)(nodeId, id));
|
|
128
132
|
this.contactIds.splice(index, 1);
|
|
129
|
-
this.contactsById.delete(id
|
|
133
|
+
this.contactsById.delete(id);
|
|
130
134
|
if (this.config.emitEvents) {
|
|
131
135
|
this.emit('contactRemoved', removed, this.getClosestContacts());
|
|
132
136
|
}
|
|
@@ -135,10 +139,10 @@ class SortedContactList extends eventemitter3_1.default {
|
|
|
135
139
|
return false;
|
|
136
140
|
}
|
|
137
141
|
isActive(id) {
|
|
138
|
-
return this.contactsById.has(id
|
|
142
|
+
return this.contactsById.has(id) ? this.contactsById.get(id).active : false;
|
|
139
143
|
}
|
|
140
144
|
getAllContacts() {
|
|
141
|
-
return this.contactIds.map((
|
|
145
|
+
return this.contactIds.map((nodeId) => this.contactsById.get(nodeId).contact);
|
|
142
146
|
}
|
|
143
147
|
getSize() {
|
|
144
148
|
return this.contactIds.length;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SortedContactList.js","sourceRoot":"","sources":["../../../../src/dht/contact/SortedContactList.ts"],"names":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"SortedContactList.js","sourceRoot":"","sources":["../../../../src/dht/contact/SortedContactList.ts"],"names":[],"mappings":";;;;;;AAAA,+CAAoD;AACpD,mCAAsC;AACtC,kEAAwC;AACxC,gDAA4C;AAC5C,iDAA8D;AAe9D,MAAa,iBAAyD,SAAQ,uBAAuB;IAMjG,YACI,MAA+B;QAE/B,KAAK,EAAE,CAAA;QANH,iBAAY,GAAiC,IAAI,GAAG,EAAE,CAAA;QACtD,eAAU,GAAa,EAAE,CAAA;QAM7B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V,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAA;IACjC,CAAC;IAEM,KAAK;QACR,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,CAAA;QACzB,IAAI,CAAC,UAAU,GAAG,EAAE,CAAA;IACxB,CAAC;IAEM,IAAI;QACP,IAAI,CAAC,kBAAkB,EAAE,CAAA;QACzB,IAAI,CAAC,KAAK,EAAE,CAAA;IAChB,CAAC;CACJ;AArLD,8CAqLC"}
|
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
import { PeerIDKey } from '../../helpers/PeerID';
|
|
2
1
|
import { PeerManager } from '../PeerManager';
|
|
3
2
|
interface DiscoverySessionConfig {
|
|
4
3
|
targetId: Uint8Array;
|
|
5
4
|
parallelism: number;
|
|
6
5
|
noProgressLimit: number;
|
|
7
6
|
peerManager: PeerManager;
|
|
8
|
-
contactedPeers: Set<PeerIDKey>;
|
|
9
7
|
}
|
|
10
8
|
export declare class DiscoverySession {
|
|
11
|
-
readonly
|
|
9
|
+
readonly id: string;
|
|
12
10
|
private stopped;
|
|
13
11
|
private emitter;
|
|
14
|
-
private outgoingClosestPeersRequestsCounter;
|
|
15
12
|
private noProgressCounter;
|
|
16
13
|
private ongoingClosestPeersRequests;
|
|
14
|
+
private contactedPeers;
|
|
17
15
|
private readonly config;
|
|
18
16
|
constructor(config: DiscoverySessionConfig);
|
|
19
17
|
private addNewContacts;
|
|
@@ -9,15 +9,16 @@ const eventemitter3_1 = __importDefault(require("eventemitter3"));
|
|
|
9
9
|
const uuid_1 = require("uuid");
|
|
10
10
|
const PeerManager_1 = require("../PeerManager");
|
|
11
11
|
const peerIdFromPeerDescriptor_1 = require("../../helpers/peerIdFromPeerDescriptor");
|
|
12
|
+
const nodeId_1 = require("../../helpers/nodeId");
|
|
12
13
|
const logger = new utils_1.Logger(module);
|
|
13
14
|
class DiscoverySession {
|
|
14
15
|
constructor(config) {
|
|
15
|
-
this.
|
|
16
|
+
this.id = (0, uuid_1.v4)();
|
|
16
17
|
this.stopped = false;
|
|
17
18
|
this.emitter = new eventemitter3_1.default();
|
|
18
|
-
this.outgoingClosestPeersRequestsCounter = 0;
|
|
19
19
|
this.noProgressCounter = 0;
|
|
20
20
|
this.ongoingClosestPeersRequests = new Set();
|
|
21
|
+
this.contactedPeers = new Set();
|
|
21
22
|
this.config = config;
|
|
22
23
|
}
|
|
23
24
|
addNewContacts(contacts) {
|
|
@@ -31,41 +32,37 @@ class DiscoverySession {
|
|
|
31
32
|
return [];
|
|
32
33
|
}
|
|
33
34
|
logger.trace(`Getting closest peers from contact: ${(0, peerIdFromPeerDescriptor_1.getNodeIdFromPeerDescriptor)(contact.getPeerDescriptor())}`);
|
|
34
|
-
this.
|
|
35
|
-
this.config.contactedPeers.add(contact.getPeerId().toKey());
|
|
35
|
+
this.contactedPeers.add(contact.getNodeId());
|
|
36
36
|
const returnedContacts = await contact.getClosestPeers(this.config.targetId);
|
|
37
|
-
this.config.peerManager.handlePeerActive(contact.
|
|
37
|
+
this.config.peerManager.handlePeerActive(contact.getNodeId());
|
|
38
38
|
return returnedContacts;
|
|
39
39
|
}
|
|
40
|
-
onClosestPeersRequestSucceeded(
|
|
41
|
-
if (!this.ongoingClosestPeersRequests.has(
|
|
40
|
+
onClosestPeersRequestSucceeded(nodeId, contacts) {
|
|
41
|
+
if (!this.ongoingClosestPeersRequests.has(nodeId)) {
|
|
42
42
|
return;
|
|
43
43
|
}
|
|
44
|
-
this.ongoingClosestPeersRequests.delete(
|
|
45
|
-
const oldClosestNeighbor = this.config.peerManager.getClosestNeighborsTo(this.config.targetId, 1)[0];
|
|
46
|
-
const oldClosestDistance = (0, PeerManager_1.getDistance)(this.config.targetId, oldClosestNeighbor.
|
|
44
|
+
this.ongoingClosestPeersRequests.delete(nodeId);
|
|
45
|
+
const oldClosestNeighbor = this.config.peerManager.getClosestNeighborsTo((0, nodeId_1.getNodeIdFromBinary)(this.config.targetId), 1)[0];
|
|
46
|
+
const oldClosestDistance = (0, PeerManager_1.getDistance)((0, nodeId_1.getNodeIdFromBinary)(this.config.targetId), oldClosestNeighbor.getNodeId());
|
|
47
47
|
this.addNewContacts(contacts);
|
|
48
|
-
const newClosestNeighbor = this.config.peerManager.getClosestNeighborsTo(this.config.targetId, 1)[0];
|
|
49
|
-
const newClosestDistance = (0, PeerManager_1.getDistance)(this.config.targetId, newClosestNeighbor.
|
|
48
|
+
const newClosestNeighbor = this.config.peerManager.getClosestNeighborsTo((0, nodeId_1.getNodeIdFromBinary)(this.config.targetId), 1)[0];
|
|
49
|
+
const newClosestDistance = (0, PeerManager_1.getDistance)((0, nodeId_1.getNodeIdFromBinary)(this.config.targetId), newClosestNeighbor.getNodeId());
|
|
50
50
|
if (newClosestDistance >= oldClosestDistance) {
|
|
51
51
|
this.noProgressCounter++;
|
|
52
52
|
}
|
|
53
|
-
else {
|
|
54
|
-
this.noProgressCounter = 0;
|
|
55
|
-
}
|
|
56
53
|
}
|
|
57
54
|
onClosestPeersRequestFailed(peer) {
|
|
58
|
-
if (!this.ongoingClosestPeersRequests.has(peer.
|
|
55
|
+
if (!this.ongoingClosestPeersRequests.has(peer.getNodeId())) {
|
|
59
56
|
return;
|
|
60
57
|
}
|
|
61
|
-
this.ongoingClosestPeersRequests.delete(peer.
|
|
62
|
-
this.config.peerManager.handlePeerUnresponsive(peer.
|
|
58
|
+
this.ongoingClosestPeersRequests.delete(peer.getNodeId());
|
|
59
|
+
this.config.peerManager.handlePeerUnresponsive(peer.getNodeId());
|
|
63
60
|
}
|
|
64
61
|
findMoreContacts() {
|
|
65
62
|
if (this.stopped) {
|
|
66
63
|
return;
|
|
67
64
|
}
|
|
68
|
-
const uncontacted = this.config.peerManager.getClosestContactsTo(this.config.targetId, this.config.parallelism, this.
|
|
65
|
+
const uncontacted = this.config.peerManager.getClosestContactsTo((0, nodeId_1.getNodeIdFromBinary)(this.config.targetId), this.config.parallelism, this.contactedPeers);
|
|
69
66
|
if (uncontacted.length === 0 || this.noProgressCounter >= this.config.noProgressLimit) {
|
|
70
67
|
this.emitter.emit('discoveryCompleted');
|
|
71
68
|
this.stopped = true;
|
|
@@ -75,19 +72,18 @@ class DiscoverySession {
|
|
|
75
72
|
if (this.ongoingClosestPeersRequests.size >= this.config.parallelism) {
|
|
76
73
|
break;
|
|
77
74
|
}
|
|
78
|
-
this.ongoingClosestPeersRequests.add(nextPeer.
|
|
75
|
+
this.ongoingClosestPeersRequests.add(nextPeer.getNodeId());
|
|
79
76
|
// eslint-disable-next-line promise/catch-or-return
|
|
80
77
|
this.getClosestPeersFromContact(nextPeer)
|
|
81
|
-
.then((contacts) => this.onClosestPeersRequestSucceeded(nextPeer.
|
|
78
|
+
.then((contacts) => this.onClosestPeersRequestSucceeded(nextPeer.getNodeId(), contacts))
|
|
82
79
|
.catch(() => this.onClosestPeersRequestFailed(nextPeer))
|
|
83
80
|
.finally(() => {
|
|
84
|
-
this.outgoingClosestPeersRequestsCounter--;
|
|
85
81
|
this.findMoreContacts();
|
|
86
82
|
});
|
|
87
83
|
}
|
|
88
84
|
}
|
|
89
85
|
async findClosestNodes(timeout) {
|
|
90
|
-
if (this.config.peerManager.getNumberOfContacts(this.
|
|
86
|
+
if (this.config.peerManager.getNumberOfContacts(this.contactedPeers) === 0) {
|
|
91
87
|
return;
|
|
92
88
|
}
|
|
93
89
|
// TODO add abortController and signal it in stop()
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DiscoverySession.js","sourceRoot":"","sources":["../../../../src/dht/discovery/DiscoverySession.ts"],"names":[],"mappings":";;;;;;AAAA,0CAA6D;AAC7D,kEAAwC;AACxC,+BAAyB;
|
|
1
|
+
{"version":3,"file":"DiscoverySession.js","sourceRoot":"","sources":["../../../../src/dht/discovery/DiscoverySession.ts"],"names":[],"mappings":";;;;;;AAAA,0CAA6D;AAC7D,kEAAwC;AACxC,+BAAyB;AAEzB,gDAAyD;AAEzD,qFAAoF;AACpF,iDAAkE;AAElE,MAAM,MAAM,GAAG,IAAI,cAAM,CAAC,MAAM,C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B,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,EAClC,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,oBAAoB,CAAC,CAAC,EACtC,OAAO,CACV,CAAA;IACL,CAAC;IAEM,IAAI;QACP,IAAI,CAAC,OAAO,GAAG,IAAI,CAAA;QACnB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAA;QACvC,IAAI,CAAC,OAAO,CAAC,kBAAkB,EAAE,CAAA;IACrC,CAAC;CACJ;AArGD,4CAqGC"}
|
|
@@ -2,7 +2,6 @@ import { PeerDescriptor } from '../../proto/packages/dht/protos/DhtRpc';
|
|
|
2
2
|
import { ConnectionManager } from '../../connection/ConnectionManager';
|
|
3
3
|
import { PeerManager } from '../PeerManager';
|
|
4
4
|
import { ServiceID } from '../../types/ServiceID';
|
|
5
|
-
import { PeerIDKey } from '../../helpers/PeerID';
|
|
6
5
|
interface PeerDiscoveryConfig {
|
|
7
6
|
localPeerDescriptor: PeerDescriptor;
|
|
8
7
|
joinNoProgressLimit: number;
|
|
@@ -14,16 +13,14 @@ interface PeerDiscoveryConfig {
|
|
|
14
13
|
peerManager: PeerManager;
|
|
15
14
|
}
|
|
16
15
|
export declare class PeerDiscovery {
|
|
17
|
-
private readonly config;
|
|
18
16
|
private ongoingDiscoverySessions;
|
|
19
17
|
private rejoinOngoing;
|
|
20
18
|
private joinCalled;
|
|
21
|
-
private rejoinTimeoutRef?;
|
|
22
19
|
private readonly abortController;
|
|
23
20
|
private recoveryIntervalStarted;
|
|
21
|
+
private readonly config;
|
|
24
22
|
constructor(config: PeerDiscoveryConfig);
|
|
25
|
-
joinDht(
|
|
26
|
-
joinThroughEntryPoint(entryPointDescriptor: PeerDescriptor, contactedPeers: Set<PeerIDKey>, doAdditionalRandomPeerDiscovery?: boolean, retry?: boolean): Promise<void>;
|
|
23
|
+
joinDht(entryPointDescriptor: PeerDescriptor, doAdditionalRandomPeerDiscovery?: boolean, retry?: boolean): Promise<void>;
|
|
27
24
|
private createSession;
|
|
28
25
|
private runSessions;
|
|
29
26
|
rejoinDht(entryPoint: PeerDescriptor): Promise<void>;
|
|
@@ -15,13 +15,7 @@ class PeerDiscovery {
|
|
|
15
15
|
this.config = config;
|
|
16
16
|
this.abortController = new AbortController();
|
|
17
17
|
}
|
|
18
|
-
async joinDht(
|
|
19
|
-
const contactedPeers = new Set();
|
|
20
|
-
await Promise.all(entryPoints.map((entryPoint) => this.joinThroughEntryPoint(entryPoint, contactedPeers, doAdditionalRandomPeerDiscovery, retry)));
|
|
21
|
-
}
|
|
22
|
-
async joinThroughEntryPoint(entryPointDescriptor,
|
|
23
|
-
// Note that this set is mutated by DiscoverySession
|
|
24
|
-
contactedPeers, doAdditionalRandomPeerDiscovery = true, retry = true) {
|
|
18
|
+
async joinDht(entryPointDescriptor, doAdditionalRandomPeerDiscovery = true, retry = true) {
|
|
25
19
|
if (this.isStopped()) {
|
|
26
20
|
return;
|
|
27
21
|
}
|
|
@@ -34,27 +28,26 @@ class PeerDiscovery {
|
|
|
34
28
|
this.config.connectionManager?.lockConnection(entryPointDescriptor, `${this.config.serviceId}::joinDht`);
|
|
35
29
|
this.config.peerManager.handleNewPeers([entryPointDescriptor]);
|
|
36
30
|
const targetId = (0, peerIdFromPeerDescriptor_1.peerIdFromPeerDescriptor)(this.config.localPeerDescriptor).value;
|
|
37
|
-
const sessions = [this.createSession(targetId
|
|
31
|
+
const sessions = [this.createSession(targetId)];
|
|
38
32
|
if (doAdditionalRandomPeerDiscovery) {
|
|
39
|
-
sessions.push(this.createSession((0, nodeId_1.createRandomNodeId)()
|
|
33
|
+
sessions.push(this.createSession((0, nodeId_1.createRandomNodeId)()));
|
|
40
34
|
}
|
|
41
35
|
await this.runSessions(sessions, entryPointDescriptor, retry);
|
|
42
36
|
this.config.connectionManager?.unlockConnection(entryPointDescriptor, `${this.config.serviceId}::joinDht`);
|
|
43
37
|
}
|
|
44
|
-
createSession(targetId
|
|
38
|
+
createSession(targetId) {
|
|
45
39
|
const sessionOptions = {
|
|
46
40
|
targetId,
|
|
47
41
|
parallelism: this.config.parallelism,
|
|
48
42
|
noProgressLimit: this.config.joinNoProgressLimit,
|
|
49
|
-
peerManager: this.config.peerManager
|
|
50
|
-
contactedPeers
|
|
43
|
+
peerManager: this.config.peerManager
|
|
51
44
|
};
|
|
52
45
|
return new DiscoverySession_1.DiscoverySession(sessionOptions);
|
|
53
46
|
}
|
|
54
47
|
async runSessions(sessions, entryPointDescriptor, retry) {
|
|
55
48
|
try {
|
|
56
49
|
for (const session of sessions) {
|
|
57
|
-
this.ongoingDiscoverySessions.set(session.
|
|
50
|
+
this.ongoingDiscoverySessions.set(session.id, session);
|
|
58
51
|
await session.findClosestNodes(this.config.joinTimeout);
|
|
59
52
|
}
|
|
60
53
|
}
|
|
@@ -66,6 +59,7 @@ class PeerDiscovery {
|
|
|
66
59
|
if (this.config.peerManager.getNumberOfNeighbors() === 0) {
|
|
67
60
|
if (retry) {
|
|
68
61
|
// TODO should we catch possible promise rejection?
|
|
62
|
+
// TODO use config option or named constant?
|
|
69
63
|
(0, utils_1.setAbortableTimeout)(() => this.rejoinDht(entryPointDescriptor), 1000, this.abortController.signal);
|
|
70
64
|
}
|
|
71
65
|
}
|
|
@@ -73,7 +67,7 @@ class PeerDiscovery {
|
|
|
73
67
|
await this.ensureRecoveryIntervalIsRunning();
|
|
74
68
|
}
|
|
75
69
|
}
|
|
76
|
-
sessions.forEach((session) => this.ongoingDiscoverySessions.delete(session.
|
|
70
|
+
sessions.forEach((session) => this.ongoingDiscoverySessions.delete(session.id));
|
|
77
71
|
}
|
|
78
72
|
}
|
|
79
73
|
async rejoinDht(entryPoint) {
|
|
@@ -83,13 +77,14 @@ class PeerDiscovery {
|
|
|
83
77
|
logger.debug(`Rejoining DHT ${this.config.serviceId}`);
|
|
84
78
|
this.rejoinOngoing = true;
|
|
85
79
|
try {
|
|
86
|
-
await this.
|
|
80
|
+
await this.joinDht(entryPoint);
|
|
87
81
|
logger.debug(`Rejoined DHT successfully ${this.config.serviceId}!`);
|
|
88
82
|
}
|
|
89
83
|
catch (err) {
|
|
90
84
|
logger.warn(`Rejoining DHT ${this.config.serviceId} failed`);
|
|
91
85
|
if (!this.isStopped()) {
|
|
92
86
|
// TODO should we catch possible promise rejection?
|
|
87
|
+
// TODO use config option or named constant?
|
|
93
88
|
(0, utils_1.setAbortableTimeout)(() => this.rejoinDht(entryPoint), 5000, this.abortController.signal);
|
|
94
89
|
}
|
|
95
90
|
}
|
|
@@ -100,6 +95,7 @@ class PeerDiscovery {
|
|
|
100
95
|
async ensureRecoveryIntervalIsRunning() {
|
|
101
96
|
if (!this.recoveryIntervalStarted) {
|
|
102
97
|
this.recoveryIntervalStarted = true;
|
|
98
|
+
// TODO use config option or named constant?
|
|
103
99
|
await (0, utils_1.scheduleAtInterval)(() => this.fetchClosestPeersFromBucket(), 60000, true, this.abortController.signal);
|
|
104
100
|
}
|
|
105
101
|
}
|
|
@@ -107,7 +103,7 @@ class PeerDiscovery {
|
|
|
107
103
|
if (this.isStopped()) {
|
|
108
104
|
return;
|
|
109
105
|
}
|
|
110
|
-
const nodes = this.config.peerManager.getClosestNeighborsTo(this.config.localPeerDescriptor
|
|
106
|
+
const nodes = this.config.peerManager.getClosestNeighborsTo((0, peerIdFromPeerDescriptor_1.getNodeIdFromPeerDescriptor)(this.config.localPeerDescriptor), this.config.parallelism);
|
|
111
107
|
await Promise.allSettled(nodes.map(async (peer) => {
|
|
112
108
|
const contacts = await peer.getClosestPeers(this.config.localPeerDescriptor.nodeId);
|
|
113
109
|
this.config.peerManager.handleNewPeers(contacts);
|
|
@@ -124,10 +120,6 @@ class PeerDiscovery {
|
|
|
124
120
|
}
|
|
125
121
|
stop() {
|
|
126
122
|
this.abortController.abort();
|
|
127
|
-
if (this.rejoinTimeoutRef) {
|
|
128
|
-
clearTimeout(this.rejoinTimeoutRef);
|
|
129
|
-
this.rejoinTimeoutRef = undefined;
|
|
130
|
-
}
|
|
131
123
|
this.ongoingDiscoverySessions.forEach((session) => {
|
|
132
124
|
session.stop();
|
|
133
125
|
});
|