@streamr/dht 103.1.2 → 103.2.0-experiment.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/exports-browser.cjs +7636 -0
- package/dist/exports-browser.cjs.map +1 -0
- package/dist/exports-browser.d.ts +1321 -0
- package/dist/exports-browser.js +7611 -0
- package/dist/exports-browser.js.map +1 -0
- package/dist/exports-nodejs.cjs +7833 -0
- package/dist/exports-nodejs.cjs.map +1 -0
- package/dist/exports-nodejs.d.ts +1321 -0
- package/dist/exports-nodejs.js +7808 -0
- package/dist/exports-nodejs.js.map +1 -0
- package/package.json +41 -25
- package/dist/generated/google/protobuf/any.d.ts +0 -180
- package/dist/generated/google/protobuf/any.js +0 -155
- package/dist/generated/google/protobuf/any.js.map +0 -1
- package/dist/generated/google/protobuf/empty.d.ts +0 -31
- package/dist/generated/google/protobuf/empty.js +0 -45
- package/dist/generated/google/protobuf/empty.js.map +0 -1
- package/dist/generated/google/protobuf/timestamp.d.ts +0 -156
- package/dist/generated/google/protobuf/timestamp.js +0 -136
- package/dist/generated/google/protobuf/timestamp.js.map +0 -1
- package/dist/generated/packages/dht/protos/DhtRpc.client.d.ts +0 -371
- package/dist/generated/packages/dht/protos/DhtRpc.client.js +0 -292
- package/dist/generated/packages/dht/protos/DhtRpc.client.js.map +0 -1
- package/dist/generated/packages/dht/protos/DhtRpc.d.ts +0 -1031
- package/dist/generated/packages/dht/protos/DhtRpc.js +0 -702
- package/dist/generated/packages/dht/protos/DhtRpc.js.map +0 -1
- package/dist/generated/packages/dht/protos/DhtRpc.server.d.ts +0 -168
- package/dist/generated/packages/dht/protos/DhtRpc.server.js +0 -3
- package/dist/generated/packages/dht/protos/DhtRpc.server.js.map +0 -1
- package/dist/generated/packages/proto-rpc/protos/ProtoRpc.d.ts +0 -87
- package/dist/generated/packages/proto-rpc/protos/ProtoRpc.js +0 -66
- package/dist/generated/packages/proto-rpc/protos/ProtoRpc.js.map +0 -1
- package/dist/package.json +0 -61
- package/dist/src/connection/Connection.d.ts +0 -12
- package/dist/src/connection/Connection.js +0 -30
- package/dist/src/connection/Connection.js.map +0 -1
- package/dist/src/connection/ConnectionLockRpcLocal.d.ts +0 -22
- package/dist/src/connection/ConnectionLockRpcLocal.js +0 -54
- package/dist/src/connection/ConnectionLockRpcLocal.js.map +0 -1
- package/dist/src/connection/ConnectionLockRpcRemote.d.ts +0 -10
- package/dist/src/connection/ConnectionLockRpcRemote.js +0 -61
- package/dist/src/connection/ConnectionLockRpcRemote.js.map +0 -1
- package/dist/src/connection/ConnectionLockStates.d.ts +0 -27
- package/dist/src/connection/ConnectionLockStates.js +0 -114
- package/dist/src/connection/ConnectionLockStates.js.map +0 -1
- package/dist/src/connection/ConnectionManager.d.ts +0 -85
- package/dist/src/connection/ConnectionManager.js +0 -569
- package/dist/src/connection/ConnectionManager.js.map +0 -1
- package/dist/src/connection/ConnectionsView.d.ts +0 -7
- package/dist/src/connection/ConnectionsView.js +0 -3
- package/dist/src/connection/ConnectionsView.js.map +0 -1
- package/dist/src/connection/ConnectorFacade.d.ts +0 -58
- package/dist/src/connection/ConnectorFacade.js +0 -154
- package/dist/src/connection/ConnectorFacade.js.map +0 -1
- package/dist/src/connection/Handshaker.d.ts +0 -27
- package/dist/src/connection/Handshaker.js +0 -179
- package/dist/src/connection/Handshaker.js.map +0 -1
- package/dist/src/connection/IConnection.d.ts +0 -32
- package/dist/src/connection/IConnection.js +0 -12
- package/dist/src/connection/IConnection.js.map +0 -1
- package/dist/src/connection/ManagedConnection.d.ts +0 -30
- package/dist/src/connection/ManagedConnection.js +0 -129
- package/dist/src/connection/ManagedConnection.js.map +0 -1
- package/dist/src/connection/OutputBuffer.d.ts +0 -9
- package/dist/src/connection/OutputBuffer.js +0 -26
- package/dist/src/connection/OutputBuffer.js.map +0 -1
- package/dist/src/connection/PendingConnection.d.ts +0 -19
- package/dist/src/connection/PendingConnection.js +0 -59
- package/dist/src/connection/PendingConnection.js.map +0 -1
- package/dist/src/connection/connectivityChecker.d.ts +0 -9
- package/dist/src/connection/connectivityChecker.js +0 -138
- package/dist/src/connection/connectivityChecker.js.map +0 -1
- package/dist/src/connection/connectivityRequestHandler.d.ts +0 -4
- package/dist/src/connection/connectivityRequestHandler.js +0 -108
- package/dist/src/connection/connectivityRequestHandler.js.map +0 -1
- package/dist/src/connection/simulator/Simulator.d.ts +0 -36
- package/dist/src/connection/simulator/Simulator.js +0 -290
- package/dist/src/connection/simulator/Simulator.js.map +0 -1
- package/dist/src/connection/simulator/SimulatorConnection.d.ts +0 -18
- package/dist/src/connection/simulator/SimulatorConnection.js +0 -123
- package/dist/src/connection/simulator/SimulatorConnection.js.map +0 -1
- package/dist/src/connection/simulator/SimulatorConnector.d.ts +0 -16
- package/dist/src/connection/simulator/SimulatorConnector.js +0 -80
- package/dist/src/connection/simulator/SimulatorConnector.js.map +0 -1
- package/dist/src/connection/simulator/SimulatorTransport.d.ts +0 -6
- package/dist/src/connection/simulator/SimulatorTransport.js +0 -17
- package/dist/src/connection/simulator/SimulatorTransport.js.map +0 -1
- package/dist/src/connection/simulator/pings.d.ts +0 -21
- package/dist/src/connection/simulator/pings.js +0 -61
- package/dist/src/connection/simulator/pings.js.map +0 -1
- package/dist/src/connection/webrtc/BrowserWebrtcConnection.d.ts +0 -37
- package/dist/src/connection/webrtc/BrowserWebrtcConnection.js +0 -229
- package/dist/src/connection/webrtc/BrowserWebrtcConnection.js.map +0 -1
- package/dist/src/connection/webrtc/IWebrtcConnection.d.ts +0 -21
- package/dist/src/connection/webrtc/IWebrtcConnection.js +0 -9
- package/dist/src/connection/webrtc/IWebrtcConnection.js.map +0 -1
- package/dist/src/connection/webrtc/NodeWebrtcConnection.d.ts +0 -45
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js +0 -229
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js.map +0 -1
- package/dist/src/connection/webrtc/WebrtcConnector.d.ts +0 -43
- package/dist/src/connection/webrtc/WebrtcConnector.js +0 -208
- package/dist/src/connection/webrtc/WebrtcConnector.js.map +0 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.d.ts +0 -26
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js +0 -82
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js.map +0 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.d.ts +0 -8
- package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.js +0 -50
- package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.js.map +0 -1
- package/dist/src/connection/webrtc/iceServerAsString.d.ts +0 -2
- package/dist/src/connection/webrtc/iceServerAsString.js +0 -17
- package/dist/src/connection/webrtc/iceServerAsString.js.map +0 -1
- package/dist/src/connection/websocket/AbstractWebsocketClientConnection.d.ts +0 -27
- package/dist/src/connection/websocket/AbstractWebsocketClientConnection.js +0 -107
- package/dist/src/connection/websocket/AbstractWebsocketClientConnection.js.map +0 -1
- package/dist/src/connection/websocket/AutoCertifierClientFacade.d.ts +0 -26
- package/dist/src/connection/websocket/AutoCertifierClientFacade.js +0 -39
- package/dist/src/connection/websocket/AutoCertifierClientFacade.js.map +0 -1
- package/dist/src/connection/websocket/BrowserWebsocketClientConnection.d.ts +0 -7
- package/dist/src/connection/websocket/BrowserWebsocketClientConnection.js +0 -44
- package/dist/src/connection/websocket/BrowserWebsocketClientConnection.js.map +0 -1
- package/dist/src/connection/websocket/NodeWebsocketClientConnection.d.ts +0 -7
- package/dist/src/connection/websocket/NodeWebsocketClientConnection.js +0 -39
- package/dist/src/connection/websocket/NodeWebsocketClientConnection.js.map +0 -1
- package/dist/src/connection/websocket/WebsocketClientConnector.d.ts +0 -26
- package/dist/src/connection/websocket/WebsocketClientConnector.js +0 -86
- package/dist/src/connection/websocket/WebsocketClientConnector.js.map +0 -1
- package/dist/src/connection/websocket/WebsocketClientConnectorRpcLocal.d.ts +0 -18
- package/dist/src/connection/websocket/WebsocketClientConnectorRpcLocal.js +0 -23
- package/dist/src/connection/websocket/WebsocketClientConnectorRpcLocal.js.map +0 -1
- package/dist/src/connection/websocket/WebsocketClientConnectorRpcRemote.d.ts +0 -5
- package/dist/src/connection/websocket/WebsocketClientConnectorRpcRemote.js +0 -17
- package/dist/src/connection/websocket/WebsocketClientConnectorRpcRemote.js.map +0 -1
- package/dist/src/connection/websocket/WebsocketServer.d.ts +0 -25
- package/dist/src/connection/websocket/WebsocketServer.js +0 -146
- package/dist/src/connection/websocket/WebsocketServer.js.map +0 -1
- package/dist/src/connection/websocket/WebsocketServerConnection.d.ts +0 -22
- package/dist/src/connection/websocket/WebsocketServerConnection.js +0 -101
- package/dist/src/connection/websocket/WebsocketServerConnection.js.map +0 -1
- package/dist/src/connection/websocket/WebsocketServerConnector.d.ts +0 -44
- package/dist/src/connection/websocket/WebsocketServerConnector.js +0 -279
- package/dist/src/connection/websocket/WebsocketServerConnector.js.map +0 -1
- package/dist/src/dht/DhtNode.d.ts +0 -119
- package/dist/src/dht/DhtNode.js +0 -500
- package/dist/src/dht/DhtNode.js.map +0 -1
- package/dist/src/dht/DhtNodeRpcLocal.d.ts +0 -23
- package/dist/src/dht/DhtNodeRpcLocal.js +0 -54
- package/dist/src/dht/DhtNodeRpcLocal.js.map +0 -1
- package/dist/src/dht/DhtNodeRpcRemote.d.ts +0 -25
- package/dist/src/dht/DhtNodeRpcRemote.js +0 -83
- package/dist/src/dht/DhtNodeRpcRemote.js.map +0 -1
- package/dist/src/dht/ExternalApiRpcLocal.d.ts +0 -18
- package/dist/src/dht/ExternalApiRpcLocal.js +0 -32
- package/dist/src/dht/ExternalApiRpcLocal.js.map +0 -1
- package/dist/src/dht/ExternalApiRpcRemote.d.ts +0 -10
- package/dist/src/dht/ExternalApiRpcRemote.js +0 -58
- package/dist/src/dht/ExternalApiRpcRemote.js.map +0 -1
- package/dist/src/dht/PeerManager.d.ts +0 -63
- package/dist/src/dht/PeerManager.js +0 -251
- package/dist/src/dht/PeerManager.js.map +0 -1
- package/dist/src/dht/contact/Contact.d.ts +0 -8
- package/dist/src/dht/contact/Contact.js +0 -18
- package/dist/src/dht/contact/Contact.js.map +0 -1
- package/dist/src/dht/contact/ContactList.d.ts +0 -19
- package/dist/src/dht/contact/ContactList.js +0 -35
- package/dist/src/dht/contact/ContactList.js.map +0 -1
- package/dist/src/dht/contact/RandomContactList.d.ts +0 -11
- package/dist/src/dht/contact/RandomContactList.js +0 -47
- package/dist/src/dht/contact/RandomContactList.js.map +0 -1
- package/dist/src/dht/contact/RingContactList.d.ts +0 -28
- package/dist/src/dht/contact/RingContactList.js +0 -126
- package/dist/src/dht/contact/RingContactList.js.map +0 -1
- package/dist/src/dht/contact/RpcRemote.d.ts +0 -19
- package/dist/src/dht/contact/RpcRemote.js +0 -61
- package/dist/src/dht/contact/RpcRemote.js.map +0 -1
- package/dist/src/dht/contact/SortedContactList.d.ts +0 -37
- package/dist/src/dht/contact/SortedContactList.js +0 -134
- package/dist/src/dht/contact/SortedContactList.js.map +0 -1
- package/dist/src/dht/contact/getClosestNodes.d.ts +0 -6
- package/dist/src/dht/contact/getClosestNodes.js +0 -19
- package/dist/src/dht/contact/getClosestNodes.js.map +0 -1
- package/dist/src/dht/contact/ringIdentifiers.d.ts +0 -16
- package/dist/src/dht/contact/ringIdentifiers.js +0 -54
- package/dist/src/dht/contact/ringIdentifiers.js.map +0 -1
- package/dist/src/dht/discovery/DiscoverySession.d.ts +0 -29
- package/dist/src/dht/discovery/DiscoverySession.js +0 -102
- package/dist/src/dht/discovery/DiscoverySession.js.map +0 -1
- package/dist/src/dht/discovery/PeerDiscovery.d.ts +0 -42
- package/dist/src/dht/discovery/PeerDiscovery.js +0 -193
- package/dist/src/dht/discovery/PeerDiscovery.js.map +0 -1
- package/dist/src/dht/discovery/RingDiscoverySession.d.ts +0 -28
- package/dist/src/dht/discovery/RingDiscoverySession.js +0 -116
- package/dist/src/dht/discovery/RingDiscoverySession.js.map +0 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.d.ts +0 -38
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.js +0 -165
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.js.map +0 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.d.ts +0 -14
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.js +0 -26
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.js.map +0 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.d.ts +0 -6
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js +0 -44
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js.map +0 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.d.ts +0 -45
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.js +0 -185
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.js.map +0 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.d.ts +0 -14
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js +0 -20
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js.map +0 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.d.ts +0 -6
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.js +0 -21
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.js.map +0 -1
- package/dist/src/dht/routing/DuplicateDetector.d.ts +0 -10
- package/dist/src/dht/routing/DuplicateDetector.js +0 -31
- package/dist/src/dht/routing/DuplicateDetector.js.map +0 -1
- package/dist/src/dht/routing/Router.d.ts +0 -35
- package/dist/src/dht/routing/Router.js +0 -204
- package/dist/src/dht/routing/Router.js.map +0 -1
- package/dist/src/dht/routing/RouterRpcLocal.d.ts +0 -20
- package/dist/src/dht/routing/RouterRpcLocal.js +0 -67
- package/dist/src/dht/routing/RouterRpcLocal.js.map +0 -1
- package/dist/src/dht/routing/RouterRpcRemote.d.ts +0 -8
- package/dist/src/dht/routing/RouterRpcRemote.js +0 -81
- package/dist/src/dht/routing/RouterRpcRemote.js.map +0 -1
- package/dist/src/dht/routing/RoutingSession.d.ts +0 -56
- package/dist/src/dht/routing/RoutingSession.js +0 -201
- package/dist/src/dht/routing/RoutingSession.js.map +0 -1
- package/dist/src/dht/routing/RoutingTablesCache.d.ts +0 -24
- package/dist/src/dht/routing/RoutingTablesCache.js +0 -46
- package/dist/src/dht/routing/RoutingTablesCache.js.map +0 -1
- package/dist/src/dht/routing/getPreviousPeer.d.ts +0 -2
- package/dist/src/dht/routing/getPreviousPeer.js +0 -12
- package/dist/src/dht/routing/getPreviousPeer.js.map +0 -1
- package/dist/src/dht/store/LocalDataStore.d.ts +0 -14
- package/dist/src/dht/store/LocalDataStore.js +0 -78
- package/dist/src/dht/store/LocalDataStore.js.map +0 -1
- package/dist/src/dht/store/StoreManager.d.ts +0 -32
- package/dist/src/dht/store/StoreManager.js +0 -126
- package/dist/src/dht/store/StoreManager.js.map +0 -1
- package/dist/src/dht/store/StoreRpcLocal.d.ts +0 -21
- package/dist/src/dht/store/StoreRpcLocal.js +0 -65
- package/dist/src/dht/store/StoreRpcLocal.js.map +0 -1
- package/dist/src/dht/store/StoreRpcRemote.d.ts +0 -7
- package/dist/src/dht/store/StoreRpcRemote.js +0 -29
- package/dist/src/dht/store/StoreRpcRemote.js.map +0 -1
- package/dist/src/exports.d.ts +0 -25
- package/dist/src/exports.js +0 -48
- package/dist/src/exports.js.map +0 -1
- package/dist/src/helpers/AddressTools.d.ts +0 -2
- package/dist/src/helpers/AddressTools.js +0 -32
- package/dist/src/helpers/AddressTools.js.map +0 -1
- package/dist/src/helpers/Connectivity.d.ts +0 -4
- package/dist/src/helpers/Connectivity.js +0 -24
- package/dist/src/helpers/Connectivity.js.map +0 -1
- package/dist/src/helpers/browser/isBrowserEnvironment.d.ts +0 -1
- package/dist/src/helpers/browser/isBrowserEnvironment.js +0 -6
- package/dist/src/helpers/browser/isBrowserEnvironment.js.map +0 -1
- package/dist/src/helpers/browser/isBrowserEnvironment_override.d.ts +0 -1
- package/dist/src/helpers/browser/isBrowserEnvironment_override.js +0 -7
- package/dist/src/helpers/browser/isBrowserEnvironment_override.js.map +0 -1
- package/dist/src/helpers/createPeerDescriptor.d.ts +0 -3
- package/dist/src/helpers/createPeerDescriptor.js +0 -58
- package/dist/src/helpers/createPeerDescriptor.js.map +0 -1
- package/dist/src/helpers/createPeerDescriptorSignaturePayload.d.ts +0 -2
- package/dist/src/helpers/createPeerDescriptorSignaturePayload.js +0 -30
- package/dist/src/helpers/createPeerDescriptorSignaturePayload.js.map +0 -1
- package/dist/src/helpers/debugHelpers.d.ts +0 -3
- package/dist/src/helpers/debugHelpers.js +0 -11
- package/dist/src/helpers/debugHelpers.js.map +0 -1
- package/dist/src/helpers/errors.d.ts +0 -72
- package/dist/src/helpers/errors.js +0 -97
- package/dist/src/helpers/errors.js.map +0 -1
- package/dist/src/helpers/offering.d.ts +0 -4
- package/dist/src/helpers/offering.js +0 -18
- package/dist/src/helpers/offering.js.map +0 -1
- package/dist/src/helpers/protoClasses.d.ts +0 -2
- package/dist/src/helpers/protoClasses.js +0 -32
- package/dist/src/helpers/protoClasses.js.map +0 -1
- package/dist/src/helpers/protoToString.d.ts +0 -2
- package/dist/src/helpers/protoToString.js +0 -19
- package/dist/src/helpers/protoToString.js.map +0 -1
- package/dist/src/helpers/version.d.ts +0 -6
- package/dist/src/helpers/version.js +0 -38
- package/dist/src/helpers/version.js.map +0 -1
- package/dist/src/identifiers.d.ts +0 -10
- package/dist/src/identifiers.js +0 -31
- package/dist/src/identifiers.js.map +0 -1
- package/dist/src/rpc-protocol/DhtCallContext.d.ts +0 -12
- package/dist/src/rpc-protocol/DhtCallContext.js +0 -17
- package/dist/src/rpc-protocol/DhtCallContext.js.map +0 -1
- package/dist/src/rpc-protocol/DhtRpcOptions.d.ts +0 -10
- package/dist/src/rpc-protocol/DhtRpcOptions.js +0 -3
- package/dist/src/rpc-protocol/DhtRpcOptions.js.map +0 -1
- package/dist/src/transport/ITransport.d.ts +0 -31
- package/dist/src/transport/ITransport.js +0 -9
- package/dist/src/transport/ITransport.js.map +0 -1
- package/dist/src/transport/ListeningRpcCommunicator.d.ts +0 -11
- package/dist/src/transport/ListeningRpcCommunicator.js +0 -31
- package/dist/src/transport/ListeningRpcCommunicator.js.map +0 -1
- package/dist/src/transport/RoutingRpcCommunicator.d.ts +0 -10
- package/dist/src/transport/RoutingRpcCommunicator.js +0 -60
- package/dist/src/transport/RoutingRpcCommunicator.js.map +0 -1
- package/dist/src/types/ServiceID.d.ts +0 -1
- package/dist/src/types/ServiceID.js +0 -3
- package/dist/src/types/ServiceID.js.map +0 -1
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DiscoverySession = void 0;
|
|
4
|
-
const utils_1 = require("@streamr/utils");
|
|
5
|
-
const uuid_1 = require("uuid");
|
|
6
|
-
const identifiers_1 = require("../../identifiers");
|
|
7
|
-
const PeerManager_1 = require("../PeerManager");
|
|
8
|
-
const getClosestNodes_1 = require("../contact/getClosestNodes");
|
|
9
|
-
const logger = new utils_1.Logger(module);
|
|
10
|
-
class DiscoverySession {
|
|
11
|
-
id = (0, uuid_1.v4)();
|
|
12
|
-
noProgressCounter = 0;
|
|
13
|
-
ongoingRequests = new Set();
|
|
14
|
-
doneGate = new utils_1.Gate(false);
|
|
15
|
-
options;
|
|
16
|
-
constructor(options) {
|
|
17
|
-
this.options = options;
|
|
18
|
-
}
|
|
19
|
-
addContacts(contacts) {
|
|
20
|
-
if (this.options.abortSignal.aborted || this.doneGate.isOpen()) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
for (const contact of contacts) {
|
|
24
|
-
this.options.peerManager.addContact(contact);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
async fetchClosestNeighborsFromRemote(peerDescriptor) {
|
|
28
|
-
if (this.options.abortSignal.aborted || this.doneGate.isOpen()) {
|
|
29
|
-
return [];
|
|
30
|
-
}
|
|
31
|
-
const nodeId = (0, identifiers_1.toNodeId)(peerDescriptor);
|
|
32
|
-
logger.trace(`Getting closest neighbors from remote: ${nodeId}`);
|
|
33
|
-
this.options.contactedPeers.add(nodeId);
|
|
34
|
-
const remote = this.options.createDhtNodeRpcRemote(peerDescriptor);
|
|
35
|
-
const returnedContacts = await remote.getClosestPeers(this.options.targetId);
|
|
36
|
-
this.options.peerManager.setContactActive(nodeId);
|
|
37
|
-
return returnedContacts;
|
|
38
|
-
}
|
|
39
|
-
onRequestSucceeded(nodeId, contacts) {
|
|
40
|
-
if (!this.ongoingRequests.has(nodeId)) {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
this.ongoingRequests.delete(nodeId);
|
|
44
|
-
const targetId = (0, identifiers_1.toDhtAddressRaw)(this.options.targetId);
|
|
45
|
-
const oldClosestNeighbor = this.getClosestNeighbor();
|
|
46
|
-
const oldClosestDistance = (0, PeerManager_1.getDistance)(targetId, oldClosestNeighbor.nodeId);
|
|
47
|
-
this.addContacts(contacts);
|
|
48
|
-
const newClosestNeighbor = this.getClosestNeighbor();
|
|
49
|
-
const newClosestDistance = (0, PeerManager_1.getDistance)(targetId, newClosestNeighbor.nodeId);
|
|
50
|
-
if (newClosestDistance >= oldClosestDistance) {
|
|
51
|
-
this.noProgressCounter++;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
getClosestNeighbor() {
|
|
55
|
-
return (0, getClosestNodes_1.getClosestNodes)(this.options.targetId, this.options.peerManager.getNeighbors().map((n) => n.getPeerDescriptor()), { maxCount: 1 })[0];
|
|
56
|
-
}
|
|
57
|
-
onRequestFailed(nodeId) {
|
|
58
|
-
if (!this.ongoingRequests.has(nodeId)) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
this.ongoingRequests.delete(nodeId);
|
|
62
|
-
this.options.peerManager.removeContact(nodeId);
|
|
63
|
-
}
|
|
64
|
-
findMoreContacts() {
|
|
65
|
-
if (this.options.abortSignal.aborted || this.doneGate.isOpen()) {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
const uncontacted = (0, getClosestNodes_1.getClosestNodes)(this.options.targetId, Array.from(this.options.peerManager.getNearbyContacts().getAllContactsInUndefinedOrder(), (c) => c.getPeerDescriptor()), {
|
|
69
|
-
maxCount: this.options.parallelism,
|
|
70
|
-
excludedNodeIds: this.options.contactedPeers
|
|
71
|
-
});
|
|
72
|
-
if ((uncontacted.length === 0 && this.ongoingRequests.size === 0) || (this.noProgressCounter >= this.options.noProgressLimit)) {
|
|
73
|
-
this.doneGate.open();
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
for (const node of uncontacted) {
|
|
77
|
-
if (this.ongoingRequests.size >= this.options.parallelism) {
|
|
78
|
-
break;
|
|
79
|
-
}
|
|
80
|
-
const nodeId = (0, identifiers_1.toNodeId)(node);
|
|
81
|
-
this.ongoingRequests.add(nodeId);
|
|
82
|
-
// eslint-disable-next-line promise/catch-or-return
|
|
83
|
-
this.fetchClosestNeighborsFromRemote(node)
|
|
84
|
-
.then((contacts) => this.onRequestSucceeded(nodeId, contacts))
|
|
85
|
-
.catch(() => this.onRequestFailed(nodeId))
|
|
86
|
-
.finally(() => {
|
|
87
|
-
this.findMoreContacts();
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
async findClosestNodes(timeout) {
|
|
92
|
-
if (this.options.peerManager.getNearbyContactCount(this.options.contactedPeers) === 0) {
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
setImmediate(() => {
|
|
96
|
-
this.findMoreContacts();
|
|
97
|
-
});
|
|
98
|
-
await (0, utils_1.withTimeout)(this.doneGate.waitUntilOpen(), timeout, 'discovery session timed out', this.options.abortSignal);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
exports.DiscoverySession = DiscoverySession;
|
|
102
|
-
//# sourceMappingURL=DiscoverySession.js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,CAAC,IAAI,IAAI,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;gBACxD,MAAK;YACT,CAAC;YACD,MAAM,MAAM,GAAG,IAAA,sBAAQ,EAAC,IAAI,CAAC,CAAA;YAC7B,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;YAChC,mDAAmD;YACnD,IAAI,CAAC,+BAA+B,CAAC,IAAI,CAAC;iBACrC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,kBAAkB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;iBAC7D,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;iBACzC,OAAO,CAAC,GAAG,EAAE;gBACV,IAAI,CAAC,gBAAgB,EAAE,CAAA;YAC3B,CAAC,CAAC,CAAA;QACV,CAAC;IACL,CAAC;IAEM,KAAK,CAAC,gBAAgB,CAAC,OAAe;QACzC,IAAI,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,qBAAqB,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,CAAC;YACpF,OAAM;QACV,CAAC;QACD,YAAY,CAAC,GAAG,EAAE;YACd,IAAI,CAAC,gBAAgB,EAAE,CAAA;QAC3B,CAAC,CAAC,CAAA;QACF,MAAM,IAAA,mBAAW,EAAC,IAAI,CAAC,QAAQ,CAAC,aAAa,EAAE,EAAE,OAAO,EAAE,6BAA6B,EAAE,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAA;IACtH,CAAC;CACJ;AA3GD,4CA2GC"}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { ConnectionLocker } from '../../connection/ConnectionManager';
|
|
2
|
-
import { DhtAddress } from '../../identifiers';
|
|
3
|
-
import { PeerDescriptor } from '../../../generated/packages/dht/protos/DhtRpc';
|
|
4
|
-
import { ServiceID } from '../../types/ServiceID';
|
|
5
|
-
import { DhtNodeRpcRemote } from '../DhtNodeRpcRemote';
|
|
6
|
-
import { PeerManager } from '../PeerManager';
|
|
7
|
-
interface PeerDiscoveryOptions {
|
|
8
|
-
localPeerDescriptor: PeerDescriptor;
|
|
9
|
-
joinNoProgressLimit: number;
|
|
10
|
-
serviceId: ServiceID;
|
|
11
|
-
parallelism: number;
|
|
12
|
-
joinTimeout: number;
|
|
13
|
-
connectionLocker?: ConnectionLocker;
|
|
14
|
-
peerManager: PeerManager;
|
|
15
|
-
abortSignal: AbortSignal;
|
|
16
|
-
createDhtNodeRpcRemote: (peerDescriptor: PeerDescriptor) => DhtNodeRpcRemote;
|
|
17
|
-
}
|
|
18
|
-
export declare const createDistantDhtAddress: (address: DhtAddress) => DhtAddress;
|
|
19
|
-
export declare class PeerDiscovery {
|
|
20
|
-
private ongoingDiscoverySessions;
|
|
21
|
-
private ongoingRingDiscoverySessions;
|
|
22
|
-
private rejoinOngoing;
|
|
23
|
-
private joinCalled;
|
|
24
|
-
private recoveryIntervalStarted;
|
|
25
|
-
private readonly options;
|
|
26
|
-
constructor(options: PeerDiscoveryOptions);
|
|
27
|
-
joinDht(entryPoints: PeerDescriptor[], doAdditionalDistantPeerDiscovery?: boolean, retry?: boolean): Promise<void>;
|
|
28
|
-
private joinThroughEntryPoint;
|
|
29
|
-
joinRing(): Promise<void>;
|
|
30
|
-
private createSession;
|
|
31
|
-
private createRingSession;
|
|
32
|
-
private runSessions;
|
|
33
|
-
private runRingSessions;
|
|
34
|
-
rejoinDht(entryPoint: PeerDescriptor, contactedPeers?: Set<DhtAddress>, distantJoinContactPeers?: Set<DhtAddress>): Promise<void>;
|
|
35
|
-
private ensureRecoveryIntervalIsRunning;
|
|
36
|
-
private fetchClosestAndRandomNeighbors;
|
|
37
|
-
private getClosestNeighbors;
|
|
38
|
-
isJoinOngoing(): boolean;
|
|
39
|
-
isJoinCalled(): boolean;
|
|
40
|
-
private isStopped;
|
|
41
|
-
}
|
|
42
|
-
export {};
|
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PeerDiscovery = exports.createDistantDhtAddress = void 0;
|
|
4
|
-
const utils_1 = require("@streamr/utils");
|
|
5
|
-
const identifiers_1 = require("../../identifiers");
|
|
6
|
-
const getClosestNodes_1 = require("../contact/getClosestNodes");
|
|
7
|
-
const ringIdentifiers_1 = require("../contact/ringIdentifiers");
|
|
8
|
-
const DiscoverySession_1 = require("./DiscoverySession");
|
|
9
|
-
const RingDiscoverySession_1 = require("./RingDiscoverySession");
|
|
10
|
-
const DhtNode_1 = require("../DhtNode");
|
|
11
|
-
const createDistantDhtAddress = (address) => {
|
|
12
|
-
const raw = (0, identifiers_1.toDhtAddressRaw)(address);
|
|
13
|
-
const flipped = raw.map((val) => ~val);
|
|
14
|
-
return (0, identifiers_1.toDhtAddress)(flipped);
|
|
15
|
-
};
|
|
16
|
-
exports.createDistantDhtAddress = createDistantDhtAddress;
|
|
17
|
-
const logger = new utils_1.Logger(module);
|
|
18
|
-
class PeerDiscovery {
|
|
19
|
-
ongoingDiscoverySessions = new Map();
|
|
20
|
-
ongoingRingDiscoverySessions = new Map();
|
|
21
|
-
rejoinOngoing = false;
|
|
22
|
-
joinCalled = false;
|
|
23
|
-
recoveryIntervalStarted = false;
|
|
24
|
-
options;
|
|
25
|
-
constructor(options) {
|
|
26
|
-
this.options = options;
|
|
27
|
-
}
|
|
28
|
-
async joinDht(entryPoints, doAdditionalDistantPeerDiscovery = true, retry = true) {
|
|
29
|
-
const contactedPeers = new Set();
|
|
30
|
-
const distantJoinOptions = doAdditionalDistantPeerDiscovery
|
|
31
|
-
? { enabled: true, contactedPeers: new Set() } : { enabled: false };
|
|
32
|
-
await Promise.all(entryPoints.map((entryPoint) => this.joinThroughEntryPoint(entryPoint, contactedPeers, distantJoinOptions, retry)));
|
|
33
|
-
}
|
|
34
|
-
async joinThroughEntryPoint(entryPointDescriptor,
|
|
35
|
-
// Note that this set is mutated by DiscoverySession
|
|
36
|
-
contactedPeers, additionalDistantJoin, retry = true) {
|
|
37
|
-
if (this.isStopped()) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
this.joinCalled = true;
|
|
41
|
-
logger.debug(`Joining ${this.options.serviceId === DhtNode_1.CONTROL_LAYER_NODE_SERVICE_ID
|
|
42
|
-
? 'The Streamr Network' : `Control Layer for ${this.options.serviceId}`}`
|
|
43
|
-
+ ` via entrypoint ${(0, identifiers_1.toNodeId)(entryPointDescriptor)}`);
|
|
44
|
-
if ((0, identifiers_1.areEqualPeerDescriptors)(entryPointDescriptor, this.options.localPeerDescriptor)) {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
this.options.connectionLocker?.lockConnection(entryPointDescriptor, `${this.options.serviceId}::joinDht`);
|
|
48
|
-
this.options.peerManager.addContact(entryPointDescriptor);
|
|
49
|
-
const targetId = (0, identifiers_1.toNodeId)(this.options.localPeerDescriptor);
|
|
50
|
-
const sessions = [this.createSession(targetId, contactedPeers)];
|
|
51
|
-
if (additionalDistantJoin.enabled) {
|
|
52
|
-
sessions.push(this.createSession((0, exports.createDistantDhtAddress)(targetId), additionalDistantJoin.contactedPeers));
|
|
53
|
-
}
|
|
54
|
-
await this.runSessions(sessions, entryPointDescriptor, retry);
|
|
55
|
-
this.options.connectionLocker?.unlockConnection(entryPointDescriptor, `${this.options.serviceId}::joinDht`);
|
|
56
|
-
}
|
|
57
|
-
async joinRing() {
|
|
58
|
-
const contactedPeers = new Set();
|
|
59
|
-
const sessions = [this.createRingSession((0, ringIdentifiers_1.getRingIdRawFromPeerDescriptor)(this.options.localPeerDescriptor), contactedPeers)];
|
|
60
|
-
await this.runRingSessions(sessions);
|
|
61
|
-
}
|
|
62
|
-
createSession(targetId, contactedPeers) {
|
|
63
|
-
const sessionOptions = {
|
|
64
|
-
targetId,
|
|
65
|
-
parallelism: this.options.parallelism,
|
|
66
|
-
noProgressLimit: this.options.joinNoProgressLimit,
|
|
67
|
-
peerManager: this.options.peerManager,
|
|
68
|
-
contactedPeers,
|
|
69
|
-
abortSignal: this.options.abortSignal,
|
|
70
|
-
createDhtNodeRpcRemote: this.options.createDhtNodeRpcRemote
|
|
71
|
-
};
|
|
72
|
-
return new DiscoverySession_1.DiscoverySession(sessionOptions);
|
|
73
|
-
}
|
|
74
|
-
createRingSession(targetId, contactedPeers) {
|
|
75
|
-
const sessionOptions = {
|
|
76
|
-
targetId,
|
|
77
|
-
parallelism: this.options.parallelism,
|
|
78
|
-
noProgressLimit: this.options.joinNoProgressLimit,
|
|
79
|
-
peerManager: this.options.peerManager,
|
|
80
|
-
contactedPeers,
|
|
81
|
-
abortSignal: this.options.abortSignal,
|
|
82
|
-
createDhtNodeRpcRemote: this.options.createDhtNodeRpcRemote
|
|
83
|
-
};
|
|
84
|
-
return new RingDiscoverySession_1.RingDiscoverySession(sessionOptions);
|
|
85
|
-
}
|
|
86
|
-
async runSessions(sessions, entryPointDescriptor, retry) {
|
|
87
|
-
try {
|
|
88
|
-
for (const session of sessions) {
|
|
89
|
-
this.ongoingDiscoverySessions.set(session.id, session);
|
|
90
|
-
await session.findClosestNodes(this.options.joinTimeout);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
catch (_e) {
|
|
94
|
-
logger.debug(`DHT join on ${this.options.serviceId} timed out`);
|
|
95
|
-
}
|
|
96
|
-
finally {
|
|
97
|
-
if (!this.isStopped()) {
|
|
98
|
-
if (this.options.peerManager.getNeighborCount() === 0) {
|
|
99
|
-
if (retry) {
|
|
100
|
-
// TODO should we catch possible promise rejection?
|
|
101
|
-
// TODO use options option or named constant?
|
|
102
|
-
(0, utils_1.setAbortableTimeout)(() => this.rejoinDht(entryPointDescriptor), 1000, this.options.abortSignal);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
await this.ensureRecoveryIntervalIsRunning();
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
sessions.forEach((session) => this.ongoingDiscoverySessions.delete(session.id));
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
async runRingSessions(sessions) {
|
|
113
|
-
try {
|
|
114
|
-
for (const session of sessions) {
|
|
115
|
-
this.ongoingRingDiscoverySessions.set(session.id, session);
|
|
116
|
-
await session.findClosestNodes(this.options.joinTimeout);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
catch (_e) {
|
|
120
|
-
logger.debug(`Ring join on ${this.options.serviceId} timed out`);
|
|
121
|
-
}
|
|
122
|
-
finally {
|
|
123
|
-
sessions.forEach((session) => this.ongoingDiscoverySessions.delete(session.id));
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
async rejoinDht(entryPoint, contactedPeers = new Set(), distantJoinContactPeers = new Set()) {
|
|
127
|
-
if (this.isStopped() || this.rejoinOngoing) {
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
logger.debug(`Rejoining DHT ${this.options.serviceId}`);
|
|
131
|
-
this.rejoinOngoing = true;
|
|
132
|
-
try {
|
|
133
|
-
await this.joinThroughEntryPoint(entryPoint, contactedPeers, { enabled: true, contactedPeers: distantJoinContactPeers });
|
|
134
|
-
logger.debug(`Rejoined DHT successfully ${this.options.serviceId}!`);
|
|
135
|
-
}
|
|
136
|
-
catch {
|
|
137
|
-
logger.warn(`Rejoining DHT ${this.options.serviceId} failed`);
|
|
138
|
-
if (!this.isStopped()) {
|
|
139
|
-
// TODO should we catch possible promise rejection?
|
|
140
|
-
// TODO use options option or named constant?
|
|
141
|
-
(0, utils_1.setAbortableTimeout)(() => this.rejoinDht(entryPoint), 5000, this.options.abortSignal);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
finally {
|
|
145
|
-
this.rejoinOngoing = false;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
async ensureRecoveryIntervalIsRunning() {
|
|
149
|
-
if (!this.recoveryIntervalStarted) {
|
|
150
|
-
this.recoveryIntervalStarted = true;
|
|
151
|
-
// TODO use options option or named constant?
|
|
152
|
-
await (0, utils_1.scheduleAtInterval)(() => this.fetchClosestAndRandomNeighbors(), 60000, true, this.options.abortSignal);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
async fetchClosestAndRandomNeighbors() {
|
|
156
|
-
if (this.isStopped()) {
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
const localNodeId = (0, identifiers_1.toNodeId)(this.options.localPeerDescriptor);
|
|
160
|
-
const nodes = this.getClosestNeighbors(localNodeId, this.options.parallelism);
|
|
161
|
-
const randomNodes = this.getClosestNeighbors((0, identifiers_1.randomDhtAddress)(), 1);
|
|
162
|
-
await Promise.allSettled([
|
|
163
|
-
...nodes.map(async (node) => {
|
|
164
|
-
const remote = this.options.createDhtNodeRpcRemote(node);
|
|
165
|
-
const contacts = await remote.getClosestPeers(localNodeId);
|
|
166
|
-
for (const contact of contacts) {
|
|
167
|
-
this.options.peerManager.addContact(contact);
|
|
168
|
-
}
|
|
169
|
-
}),
|
|
170
|
-
...randomNodes.map(async (node) => {
|
|
171
|
-
const remote = this.options.createDhtNodeRpcRemote(node);
|
|
172
|
-
const contacts = await remote.getClosestPeers((0, identifiers_1.randomDhtAddress)());
|
|
173
|
-
for (const contact of contacts) {
|
|
174
|
-
this.options.peerManager.addContact(contact);
|
|
175
|
-
}
|
|
176
|
-
})
|
|
177
|
-
]);
|
|
178
|
-
}
|
|
179
|
-
getClosestNeighbors(referenceId, maxCount) {
|
|
180
|
-
return (0, getClosestNodes_1.getClosestNodes)(referenceId, this.options.peerManager.getNeighbors().map((n) => n.getPeerDescriptor()), { maxCount });
|
|
181
|
-
}
|
|
182
|
-
isJoinOngoing() {
|
|
183
|
-
return !this.joinCalled ? true : this.ongoingDiscoverySessions.size > 0;
|
|
184
|
-
}
|
|
185
|
-
isJoinCalled() {
|
|
186
|
-
return this.joinCalled;
|
|
187
|
-
}
|
|
188
|
-
isStopped() {
|
|
189
|
-
return this.options.abortSignal.aborted;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
exports.PeerDiscovery = PeerDiscovery;
|
|
193
|
-
//# sourceMappingURL=PeerDiscovery.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PeerDiscovery.js","sourceRoot":"","sources":["../../../../src/dht/discovery/PeerDiscovery.ts"],"names":[],"mappings":";;;AAAA,0CAAgF;AAEhF,mDAO0B;AAK1B,gEAA4D;AAC5D,gEAAsF;AACtF,yDAAqD;AACrD,iEAA6D;AAC7D,wCAA0D;AAcnD,MAAM,uBAAuB,GAAG,CAAC,OAAmB,EAAc,EAAE;IACvE,MAAM,GAAG,GAAG,IAAA,6BAAe,EAAC,OAAO,CAAC,CAAA;IACpC,MAAM,OAAO,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAA;IACtC,OAAO,IAAA,0BAAY,EAAC,OAAO,CAAC,CAAA;AAChC,CAAC,CAAA;AAJY,QAAA,uBAAuB,2BAInC;AAED,MAAM,MAAM,GAAG,IAAI,cAAM,CAAC,MAAM,CAAC,CAAA;AAEjC,MAAa,aAAa;IAEd,wBAAwB,GAAkC,IAAI,GAAG,EAAE,CAAA;IACnE,4BAA4B,GAAsC,IAAI,GAAG,EAAE,CAAA;IAE3E,aAAa,GAAG,KAAK,CAAA;IACrB,UAAU,GAAG,KAAK,CAAA;IAClB,uBAAuB,GAAG,KAAK,CAAA;IACtB,OAAO,CAAsB;IAE9C,YAAY,OAA6B;QACrC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IAC1B,CAAC;IAED,KAAK,CAAC,OAAO,CACT,WAA6B,EAC7B,gCAAgC,GAAG,IAAI,EACvC,KAAK,GAAG,IAAI;QAEZ,MAAM,cAAc,GAAG,IAAI,GAAG,EAAc,CAAA;QAC5C,MAAM,kBAAkB,GAAG,gCAAgC;YACvD,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EA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AAC,CAAA;IAC3E,CAAC;IAEM,YAAY;QACf,OAAO,IAAI,CAAC,UAAU,CAAA;IAC1B,CAAC;IAEO,SAAS;QACb,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,OAAO,CAAA;IAC3C,CAAC;CACJ;AA3MD,sCA2MC"}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { DhtAddress } from '../../identifiers';
|
|
2
|
-
import { PeerManager } from '../PeerManager';
|
|
3
|
-
import { RingIdRaw } from '../contact/ringIdentifiers';
|
|
4
|
-
interface RingDiscoverySessionOptions {
|
|
5
|
-
targetId: RingIdRaw;
|
|
6
|
-
parallelism: number;
|
|
7
|
-
noProgressLimit: number;
|
|
8
|
-
peerManager: PeerManager;
|
|
9
|
-
contactedPeers: Set<DhtAddress>;
|
|
10
|
-
abortSignal: AbortSignal;
|
|
11
|
-
}
|
|
12
|
-
export declare class RingDiscoverySession {
|
|
13
|
-
readonly id: string;
|
|
14
|
-
private noProgressCounter;
|
|
15
|
-
private ongoingRequests;
|
|
16
|
-
private doneGate;
|
|
17
|
-
private readonly options;
|
|
18
|
-
private numContactedPeers;
|
|
19
|
-
private targetIdAsRingId;
|
|
20
|
-
constructor(options: RingDiscoverySessionOptions);
|
|
21
|
-
private addContacts;
|
|
22
|
-
private fetchClosestContactsFromRemote;
|
|
23
|
-
private onRequestSucceeded;
|
|
24
|
-
private onRequestFailed;
|
|
25
|
-
private findMoreContacts;
|
|
26
|
-
findClosestNodes(timeout: number): Promise<void>;
|
|
27
|
-
}
|
|
28
|
-
export {};
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RingDiscoverySession = void 0;
|
|
4
|
-
const utils_1 = require("@streamr/utils");
|
|
5
|
-
const uuid_1 = require("uuid");
|
|
6
|
-
const identifiers_1 = require("../../identifiers");
|
|
7
|
-
const ringIdentifiers_1 = require("../contact/ringIdentifiers");
|
|
8
|
-
const logger = new utils_1.Logger(module);
|
|
9
|
-
class RingDiscoverySession {
|
|
10
|
-
id = (0, uuid_1.v4)();
|
|
11
|
-
noProgressCounter = 0;
|
|
12
|
-
ongoingRequests = new Set();
|
|
13
|
-
doneGate = new utils_1.Gate(false);
|
|
14
|
-
options;
|
|
15
|
-
numContactedPeers = 0;
|
|
16
|
-
targetIdAsRingId;
|
|
17
|
-
constructor(options) {
|
|
18
|
-
this.options = options;
|
|
19
|
-
this.targetIdAsRingId = (0, ringIdentifiers_1.getRingIdFromRaw)(this.options.targetId);
|
|
20
|
-
}
|
|
21
|
-
addContacts(contacts) {
|
|
22
|
-
if (this.options.abortSignal.aborted || this.doneGate.isOpen()) {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
for (const contact of contacts) {
|
|
26
|
-
this.options.peerManager.addContact(contact);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
async fetchClosestContactsFromRemote(contact) {
|
|
30
|
-
if (this.options.abortSignal.aborted || this.doneGate.isOpen()) {
|
|
31
|
-
return { left: [], right: [] };
|
|
32
|
-
}
|
|
33
|
-
logger.trace(`Getting closest ring peers from contact: ${(0, identifiers_1.toNodeId)(contact.getPeerDescriptor())}`);
|
|
34
|
-
this.numContactedPeers++;
|
|
35
|
-
this.options.contactedPeers.add(contact.getNodeId());
|
|
36
|
-
const returnedContacts = await contact.getClosestRingPeers(this.options.targetId);
|
|
37
|
-
this.options.peerManager.setContactActive(contact.getNodeId());
|
|
38
|
-
return returnedContacts;
|
|
39
|
-
}
|
|
40
|
-
onRequestSucceeded(nodeId, contacts) {
|
|
41
|
-
if (!this.ongoingRequests.has(nodeId)) {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
this.ongoingRequests.delete(nodeId);
|
|
45
|
-
const oldClosestContacts = this.options.peerManager.getClosestRingContactsTo(this.options.targetId, 1);
|
|
46
|
-
const oldClosestLeftDistance = (0, ringIdentifiers_1.getLeftDistance)(this.targetIdAsRingId, (0, ringIdentifiers_1.getRingIdFromPeerDescriptor)(oldClosestContacts.left[0].getPeerDescriptor()));
|
|
47
|
-
const oldClosestRightDistance = (0, ringIdentifiers_1.getLeftDistance)(this.targetIdAsRingId, (0, ringIdentifiers_1.getRingIdFromPeerDescriptor)(oldClosestContacts.right[0].getPeerDescriptor()));
|
|
48
|
-
this.addContacts(contacts.left.concat(contacts.right));
|
|
49
|
-
const newClosestContacts = this.options.peerManager.getClosestRingContactsTo(this.options.targetId, 1);
|
|
50
|
-
const newClosestLeftDistance = (0, ringIdentifiers_1.getLeftDistance)(this.targetIdAsRingId, (0, ringIdentifiers_1.getRingIdFromPeerDescriptor)(newClosestContacts.left[0].getPeerDescriptor()));
|
|
51
|
-
const newClosestRightDistance = (0, ringIdentifiers_1.getLeftDistance)(this.targetIdAsRingId, (0, ringIdentifiers_1.getRingIdFromPeerDescriptor)(newClosestContacts.right[0].getPeerDescriptor()));
|
|
52
|
-
if (newClosestLeftDistance >= oldClosestLeftDistance && newClosestRightDistance >= oldClosestRightDistance) {
|
|
53
|
-
this.noProgressCounter++;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
onRequestFailed(peer) {
|
|
57
|
-
if (!this.ongoingRequests.has(peer.getNodeId())) {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
this.ongoingRequests.delete(peer.getNodeId());
|
|
61
|
-
this.options.peerManager.removeContact(peer.getNodeId());
|
|
62
|
-
}
|
|
63
|
-
findMoreContacts() {
|
|
64
|
-
if (this.options.abortSignal.aborted || this.doneGate.isOpen()) {
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
const uncontacted = this.options.peerManager.getClosestRingContactsTo(this.options.targetId, this.options.parallelism, this.options.contactedPeers);
|
|
68
|
-
if ((uncontacted.left.length === 0 && uncontacted.right.length === 0)
|
|
69
|
-
|| this.noProgressCounter >= this.options.noProgressLimit) {
|
|
70
|
-
this.doneGate.open();
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
// ask from both sides equally
|
|
74
|
-
const merged = [];
|
|
75
|
-
const alreadyInMerged = new Set();
|
|
76
|
-
const length = Math.max(uncontacted.left.length, uncontacted.right.length);
|
|
77
|
-
for (let i = 0; i < length; i++) {
|
|
78
|
-
if (i < uncontacted.left.length) {
|
|
79
|
-
if (!alreadyInMerged.has(uncontacted.left[i].getNodeId())) {
|
|
80
|
-
merged.push(uncontacted.left[i]);
|
|
81
|
-
alreadyInMerged.add(uncontacted.left[i].getNodeId());
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
if (i < uncontacted.right.length) {
|
|
85
|
-
if (!alreadyInMerged.has(uncontacted.right[i].getNodeId())) {
|
|
86
|
-
merged.push(uncontacted.right[i]);
|
|
87
|
-
alreadyInMerged.add(uncontacted.right[i].getNodeId());
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
for (const nextPeer of merged) {
|
|
92
|
-
if (this.ongoingRequests.size >= this.options.parallelism) {
|
|
93
|
-
break;
|
|
94
|
-
}
|
|
95
|
-
this.ongoingRequests.add(nextPeer.getNodeId());
|
|
96
|
-
// eslint-disable-next-line promise/catch-or-return
|
|
97
|
-
this.fetchClosestContactsFromRemote(nextPeer)
|
|
98
|
-
.then((contacts) => this.onRequestSucceeded(nextPeer.getNodeId(), contacts))
|
|
99
|
-
.catch(() => this.onRequestFailed(nextPeer))
|
|
100
|
-
.finally(() => {
|
|
101
|
-
this.findMoreContacts();
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
async findClosestNodes(timeout) {
|
|
106
|
-
if (this.options.peerManager.getNearbyContactCount(this.options.contactedPeers) === 0) {
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
setImmediate(() => {
|
|
110
|
-
this.findMoreContacts();
|
|
111
|
-
});
|
|
112
|
-
await (0, utils_1.withTimeout)(this.doneGate.waitUntilOpen(), timeout, 'discovery session timed out', this.options.abortSignal);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
exports.RingDiscoverySession = RingDiscoverySession;
|
|
116
|
-
//# sourceMappingURL=RingDiscoverySession.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RingDiscoverySession.js","sourceRoot":"","sources":["../../../../src/dht/discovery/RingDiscoverySession.ts"],"names":[],"mappings":";;;AAAA,0CAA0D;AAC1D,+BAAyB;AACzB,mDAAwD;AAKxD,gEAA8H;AAE9H,MAAM,MAAM,GAAG,IAAI,cAAM,CAAC,MAAM,CAAC,CAAA;AAYjC,MAAa,oBAAoB;IAEb,EAAE,GAAG,IAAA,SAAE,GAAE,CAAA;IACjB,iBAAiB,GAAG,CAAC,CAAA;IACrB,eAAe,GAAoB,IAAI,GAAG,EAAE,CAAA;IAC5C,QAAQ,GAAG,IAAI,YAAI,CAAC,KAAK,CAAC,CAAA;IACjB,OAAO,CAA6B;IAC7C,iBAAiB,GAAG,CAAC,CAAA;IACrB,gBAAgB,CAAQ;IAEhC,YAAY,OAAoC;QAC5C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,gBAAgB,GAAG,IAAA,kCAAgB,EAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;IACnE,CAAC;IAEO,WAAW,CAAC,QAA0B;QAC1C,IAAI,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,OAAO,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC;YAC7D,OAAM;QACV,CAAC;QACD,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;YAC7B,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,UAAU,CAAC,OAAO,CAAC,CAAA;QAChD,CAAC;IACL,CAAC;IAEO,KAAK,CAAC,8BAA8B,CAAC,OAAyB;QAClE,IAAI,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,OAAO,IAAI,IAAI,CAAC,QAAQ,CAAC,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AAC,IAAI,CAAC,QAAQ,CAAC,aAAa,EAAE,EAAE,OAAO,EAAE,6BAA6B,EAAE,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAA;IACtH,CAAC;CACJ;AA9HD,oDA8HC"}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { DataEntry, PeerDescriptor, RecursiveOperation } from '../../../generated/packages/dht/protos/DhtRpc';
|
|
2
|
-
import { Router } from '../routing/Router';
|
|
3
|
-
import { RoutingRpcCommunicator } from '../../transport/RoutingRpcCommunicator';
|
|
4
|
-
import { DhtNodeRpcRemote } from '../DhtNodeRpcRemote';
|
|
5
|
-
import { ITransport } from '../../transport/ITransport';
|
|
6
|
-
import { LocalDataStore } from '../store/LocalDataStore';
|
|
7
|
-
import { ServiceID } from '../../types/ServiceID';
|
|
8
|
-
import { DhtAddress } from '../../identifiers';
|
|
9
|
-
import { ConnectionsView } from '../../exports';
|
|
10
|
-
interface RecursiveOperationManagerOptions {
|
|
11
|
-
rpcCommunicator: RoutingRpcCommunicator;
|
|
12
|
-
sessionTransport: ITransport;
|
|
13
|
-
router: Router;
|
|
14
|
-
connectionsView: ConnectionsView;
|
|
15
|
-
localPeerDescriptor: PeerDescriptor;
|
|
16
|
-
serviceId: ServiceID;
|
|
17
|
-
localDataStore: LocalDataStore;
|
|
18
|
-
addContact: (contact: PeerDescriptor) => void;
|
|
19
|
-
createDhtNodeRpcRemote: (peerDescriptor: PeerDescriptor) => DhtNodeRpcRemote;
|
|
20
|
-
}
|
|
21
|
-
export interface RecursiveOperationResult {
|
|
22
|
-
closestNodes: PeerDescriptor[];
|
|
23
|
-
dataEntries?: DataEntry[];
|
|
24
|
-
}
|
|
25
|
-
export declare class RecursiveOperationManager {
|
|
26
|
-
private ongoingSessions;
|
|
27
|
-
private stopped;
|
|
28
|
-
private readonly options;
|
|
29
|
-
constructor(options: RecursiveOperationManagerOptions);
|
|
30
|
-
private registerLocalRpcMethods;
|
|
31
|
-
execute(targetId: DhtAddress, operation: RecursiveOperation, excludedPeer?: DhtAddress, waitForCompletion?: boolean): Promise<RecursiveOperationResult>;
|
|
32
|
-
private sendResponse;
|
|
33
|
-
private doRouteRequest;
|
|
34
|
-
private getClosestConnectedNodes;
|
|
35
|
-
private isPeerCloserToIdThanSelf;
|
|
36
|
-
stop(): void;
|
|
37
|
-
}
|
|
38
|
-
export {};
|