@streamr/dht 100.0.0-testnet-one.3 → 100.0.0-testnet-two.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/connection/ConnectionLockHandler.d.ts +11 -11
- package/dist/src/connection/ConnectionLockHandler.js.map +1 -1
- package/dist/src/connection/ConnectionLockRpcLocal.d.ts +3 -3
- package/dist/src/connection/ConnectionLockRpcLocal.js +4 -4
- package/dist/src/connection/ConnectionLockRpcLocal.js.map +1 -1
- package/dist/src/connection/ConnectionLockRpcRemote.d.ts +3 -5
- package/dist/src/connection/ConnectionLockRpcRemote.js +4 -7
- package/dist/src/connection/ConnectionLockRpcRemote.js.map +1 -1
- package/dist/src/connection/ConnectionManager.d.ts +4 -6
- package/dist/src/connection/ConnectionManager.js +48 -46
- package/dist/src/connection/ConnectionManager.js.map +1 -1
- package/dist/src/connection/ConnectorFacade.d.ts +2 -2
- package/dist/src/connection/ConnectorFacade.js +2 -1
- package/dist/src/connection/ConnectorFacade.js.map +1 -1
- package/dist/src/connection/ManagedConnection.d.ts +3 -6
- package/dist/src/connection/ManagedConnection.js +6 -10
- package/dist/src/connection/ManagedConnection.js.map +1 -1
- package/dist/src/connection/connectivityChecker.js +1 -0
- package/dist/src/connection/connectivityChecker.js.map +1 -1
- package/dist/src/connection/simulator/Simulator.d.ts +0 -3
- package/dist/src/connection/simulator/Simulator.js +3 -51
- package/dist/src/connection/simulator/Simulator.js.map +1 -1
- package/dist/src/connection/simulator/SimulatorConnector.js +5 -5
- package/dist/src/connection/simulator/SimulatorConnector.js.map +1 -1
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js +2 -2
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnector.d.ts +0 -1
- package/dist/src/connection/webrtc/WebrtcConnector.js +7 -9
- package/dist/src/connection/webrtc/WebrtcConnector.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.d.ts +2 -2
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js +11 -12
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.d.ts +2 -5
- package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.js +1 -4
- package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.js.map +1 -1
- package/dist/src/connection/websocket/AutoCertifierClientFacade.d.ts +1 -2
- package/dist/src/connection/websocket/AutoCertifierClientFacade.js +3 -4
- package/dist/src/connection/websocket/AutoCertifierClientFacade.js.map +1 -1
- package/dist/src/connection/websocket/ClientWebsocket.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnector.d.ts +2 -7
- package/dist/src/connection/websocket/WebsocketConnector.js +32 -38
- package/dist/src/connection/websocket/WebsocketConnector.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.d.ts +3 -2
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.js +8 -10
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.d.ts +3 -6
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.js +0 -3
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketServer.d.ts +1 -4
- package/dist/src/connection/websocket/WebsocketServer.js +11 -12
- package/dist/src/connection/websocket/WebsocketServer.js.map +1 -1
- package/dist/src/dht/DhtNode.d.ts +10 -13
- package/dist/src/dht/DhtNode.js +39 -52
- package/dist/src/dht/DhtNode.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcLocal.d.ts +0 -1
- package/dist/src/dht/DhtNodeRpcLocal.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcRemote.d.ts +7 -7
- package/dist/src/dht/DhtNodeRpcRemote.js +8 -7
- package/dist/src/dht/DhtNodeRpcRemote.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcLocal.d.ts +5 -4
- package/dist/src/dht/ExternalApiRpcLocal.js +3 -2
- package/dist/src/dht/ExternalApiRpcLocal.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcRemote.d.ts +2 -2
- package/dist/src/dht/ExternalApiRpcRemote.js +2 -0
- package/dist/src/dht/ExternalApiRpcRemote.js.map +1 -1
- package/dist/src/dht/PeerManager.d.ts +13 -14
- package/dist/src/dht/PeerManager.js +45 -60
- package/dist/src/dht/PeerManager.js.map +1 -1
- package/dist/src/dht/contact/Contact.d.ts +2 -2
- package/dist/src/dht/contact/Contact.js +2 -2
- package/dist/src/dht/contact/Contact.js.map +1 -1
- package/dist/src/dht/contact/ContactList.d.ts +7 -7
- package/dist/src/dht/contact/ContactList.js +3 -3
- package/dist/src/dht/contact/ContactList.js.map +1 -1
- package/dist/src/dht/contact/RandomContactList.d.ts +4 -4
- package/dist/src/dht/contact/RandomContactList.js +12 -11
- package/dist/src/dht/contact/RandomContactList.js.map +1 -1
- package/dist/src/dht/contact/RpcRemote.d.ts +7 -4
- package/dist/src/dht/contact/RpcRemote.js +5 -2
- package/dist/src/dht/contact/RpcRemote.js.map +1 -1
- package/dist/src/dht/contact/SortedContactList.d.ts +13 -13
- package/dist/src/dht/contact/SortedContactList.js +33 -29
- package/dist/src/dht/contact/SortedContactList.js.map +1 -1
- package/dist/src/dht/discovery/DiscoverySession.d.ts +2 -4
- package/dist/src/dht/discovery/DiscoverySession.js +19 -20
- package/dist/src/dht/discovery/DiscoverySession.js.map +1 -1
- package/dist/src/dht/discovery/PeerDiscovery.d.ts +2 -5
- package/dist/src/dht/discovery/PeerDiscovery.js +12 -20
- package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.d.ts +36 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.js +165 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.d.ts +14 -0
- package/dist/src/dht/{find/FindRpcLocal.js → recursive-operation/RecursiveOperationRpcLocal.js} +7 -7
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.d.ts +6 -0
- package/dist/src/dht/{routing/FindRpcRemote.js → recursive-operation/RecursiveOperationRpcRemote.js} +11 -11
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.d.ts +42 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.js +182 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.d.ts +12 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js +17 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.d.ts +6 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.js +21 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.js.map +1 -0
- package/dist/src/dht/routing/Router.d.ts +4 -19
- package/dist/src/dht/routing/Router.js +41 -33
- package/dist/src/dht/routing/Router.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcLocal.js +6 -5
- package/dist/src/dht/routing/RouterRpcLocal.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcRemote.d.ts +2 -2
- package/dist/src/dht/routing/RouterRpcRemote.js +7 -7
- package/dist/src/dht/routing/RouterRpcRemote.js.map +1 -1
- package/dist/src/dht/routing/RoutingSession.d.ts +20 -16
- package/dist/src/dht/routing/RoutingSession.js +37 -45
- package/dist/src/dht/routing/RoutingSession.js.map +1 -1
- package/dist/src/dht/store/LocalDataStore.d.ts +11 -13
- package/dist/src/dht/store/LocalDataStore.js +36 -56
- package/dist/src/dht/store/LocalDataStore.js.map +1 -1
- package/dist/src/dht/store/StoreManager.d.ts +33 -0
- package/dist/src/dht/store/StoreManager.js +186 -0
- package/dist/src/dht/store/StoreManager.js.map +1 -0
- package/dist/src/dht/store/StoreRpcLocal.d.ts +8 -40
- package/dist/src/dht/store/StoreRpcLocal.js +13 -229
- package/dist/src/dht/store/StoreRpcLocal.js.map +1 -1
- package/dist/src/dht/store/StoreRpcRemote.d.ts +5 -5
- package/dist/src/dht/store/StoreRpcRemote.js +4 -5
- package/dist/src/dht/store/StoreRpcRemote.js.map +1 -1
- package/dist/src/exports.d.ts +2 -0
- package/dist/src/exports.js.map +1 -1
- package/dist/src/helpers/MapWithTtl.d.ts +14 -0
- package/dist/src/helpers/MapWithTtl.js +59 -0
- package/dist/src/helpers/MapWithTtl.js.map +1 -0
- package/dist/src/helpers/PeerID.d.ts +2 -0
- package/dist/src/helpers/PeerID.js +4 -0
- package/dist/src/helpers/PeerID.js.map +1 -1
- package/dist/src/helpers/nodeId.d.ts +5 -0
- package/dist/src/helpers/nodeId.js +18 -1
- package/dist/src/helpers/nodeId.js.map +1 -1
- package/dist/src/helpers/peerIdFromPeerDescriptor.d.ts +2 -1
- package/dist/src/helpers/peerIdFromPeerDescriptor.js +2 -1
- package/dist/src/helpers/peerIdFromPeerDescriptor.js.map +1 -1
- package/dist/src/helpers/protoClasses.js +2 -3
- package/dist/src/helpers/protoClasses.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +21 -22
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +18 -18
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +36 -60
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +34 -53
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +11 -12
- package/dist/src/rpc-protocol/DhtCallContext.d.ts +2 -1
- package/dist/src/rpc-protocol/DhtCallContext.js.map +1 -1
- package/dist/src/rpc-protocol/DhtRpcOptions.d.ts +2 -1
- package/dist/src/transport/ITransport.d.ts +9 -1
- package/dist/src/transport/ITransport.js +5 -0
- package/dist/src/transport/ITransport.js.map +1 -1
- package/dist/src/transport/ListeningRpcCommunicator.js +1 -1
- package/dist/src/transport/ListeningRpcCommunicator.js.map +1 -1
- package/dist/src/transport/RoutingRpcCommunicator.d.ts +2 -1
- package/dist/src/transport/RoutingRpcCommunicator.js +16 -11
- package/dist/src/transport/RoutingRpcCommunicator.js.map +1 -1
- package/jest.config.js +4 -1
- package/karma-setup.js +2 -0
- package/karma.config.js +11 -7
- package/package.json +6 -7
- package/protos/DhtRpc.proto +17 -23
- package/src/connection/ConnectionLockHandler.ts +15 -15
- package/src/connection/ConnectionLockRpcLocal.ts +8 -9
- package/src/connection/ConnectionLockRpcRemote.ts +7 -16
- package/src/connection/ConnectionManager.ts +58 -55
- package/src/connection/ConnectorFacade.ts +3 -0
- package/src/connection/ManagedConnection.ts +12 -30
- package/src/connection/connectivityChecker.ts +1 -0
- package/src/connection/simulator/Simulator.ts +5 -36
- package/src/connection/simulator/SimulatorConnector.ts +8 -8
- package/src/connection/webrtc/BrowserWebrtcConnection.ts +0 -3
- package/src/connection/webrtc/NodeWebrtcConnection.ts +3 -4
- package/src/connection/webrtc/WebrtcConnector.ts +11 -13
- package/src/connection/webrtc/WebrtcConnectorRpcLocal.ts +16 -16
- package/src/connection/webrtc/WebrtcConnectorRpcRemote.ts +3 -13
- package/src/connection/websocket/AutoCertifierClientFacade.ts +4 -6
- package/src/connection/websocket/ClientWebsocket.ts +1 -0
- package/src/connection/websocket/WebsocketConnector.ts +43 -56
- package/src/connection/websocket/WebsocketConnectorRpcLocal.ts +11 -13
- package/src/connection/websocket/WebsocketConnectorRpcRemote.ts +4 -15
- package/src/connection/websocket/WebsocketServer.ts +14 -17
- package/src/dht/DhtNode.ts +67 -69
- package/src/dht/DhtNodeRpcLocal.ts +0 -1
- package/src/dht/DhtNodeRpcRemote.ts +13 -13
- package/src/dht/ExternalApiRpcLocal.ts +16 -6
- package/src/dht/ExternalApiRpcRemote.ts +5 -3
- package/src/dht/PeerManager.ts +73 -90
- package/src/dht/contact/Contact.ts +5 -4
- package/src/dht/contact/ContactList.ts +9 -9
- package/src/dht/contact/RandomContactList.ts +14 -14
- package/src/dht/contact/RpcRemote.ts +10 -7
- package/src/dht/contact/SortedContactList.ts +48 -45
- package/src/dht/discovery/DiscoverySession.ts +25 -25
- package/src/dht/discovery/PeerDiscovery.ts +16 -37
- package/src/dht/recursive-operation/RecursiveOperationManager.ts +240 -0
- package/src/dht/{find/FindRpcLocal.ts → recursive-operation/RecursiveOperationRpcLocal.ts} +9 -9
- package/src/dht/{routing/FindRpcRemote.ts → recursive-operation/RecursiveOperationRpcRemote.ts} +10 -10
- package/src/dht/recursive-operation/RecursiveOperationSession.ts +224 -0
- package/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.ts +25 -0
- package/src/dht/{find/FindSessionRpcRemote.ts → recursive-operation/RecursiveOperationSessionRpcRemote.ts} +8 -8
- package/src/dht/routing/Router.ts +45 -64
- package/src/dht/routing/RouterRpcLocal.ts +7 -6
- package/src/dht/routing/RouterRpcRemote.ts +9 -10
- package/src/dht/routing/RoutingSession.ts +59 -68
- package/src/dht/store/LocalDataStore.ts +47 -66
- package/src/dht/store/StoreManager.ts +217 -0
- package/src/dht/store/StoreRpcLocal.ts +26 -302
- package/src/dht/store/StoreRpcRemote.ts +9 -11
- package/src/exports.ts +2 -0
- package/src/helpers/MapWithTtl.ts +71 -0
- package/src/helpers/PeerID.ts +5 -0
- package/src/helpers/nodeId.ts +20 -0
- package/src/helpers/peerIdFromPeerDescriptor.ts +5 -3
- package/src/helpers/protoClasses.ts +4 -6
- package/src/proto/packages/dht/protos/DhtRpc.client.ts +31 -32
- package/src/proto/packages/dht/protos/DhtRpc.server.ts +11 -12
- package/src/proto/packages/dht/protos/DhtRpc.ts +49 -80
- package/src/rpc-protocol/DhtCallContext.ts +2 -1
- package/src/rpc-protocol/DhtRpcOptions.ts +2 -1
- package/src/transport/ITransport.ts +10 -1
- package/src/transport/ListeningRpcCommunicator.ts +1 -1
- package/src/transport/RoutingRpcCommunicator.ts +18 -12
- package/test/benchmark/Find.test.ts +8 -21
- package/test/benchmark/KademliaCorrectness.test.ts +11 -20
- package/test/benchmark/SortedContactListBenchmark.test.ts +9 -9
- package/test/benchmark/kademlia-simulation/Contact.ts +9 -8
- package/test/benchmark/kademlia-simulation/KademliaSimulation.ts +2 -2
- package/test/benchmark/kademlia-simulation/SimulationNode.ts +17 -17
- package/test/end-to-end/Layer0-Layer1.test.ts +10 -14
- package/test/end-to-end/Layer0.test.ts +15 -18
- package/test/end-to-end/Layer0MixedConnectionTypes.test.ts +7 -9
- package/test/end-to-end/Layer0Webrtc-Layer1.test.ts +4 -10
- package/test/end-to-end/Layer0Webrtc.test.ts +5 -6
- package/test/end-to-end/Layer1-Scale-WebSocket.test.ts +8 -16
- package/test/end-to-end/Layer1-Scale-Webrtc.test.ts +6 -13
- package/test/end-to-end/WebsocketConnectionRequest.test.ts +5 -6
- package/test/end-to-end/memory-leak.test.ts +6 -8
- package/test/integration/ConnectionLocking.test.ts +6 -13
- package/test/integration/ConnectionManager.test.ts +26 -43
- package/test/integration/DhtJoinPeerDiscovery.test.ts +5 -10
- package/test/integration/DhtNodeExternalAPI.test.ts +16 -22
- package/test/integration/DhtNodeRpcRemote.test.ts +13 -22
- package/test/integration/DhtRpc.test.ts +13 -18
- package/test/integration/Find.test.ts +10 -10
- package/test/integration/Layer1-scale.test.ts +17 -28
- package/test/integration/Mock-Layer1-Layer0.test.ts +25 -43
- package/test/integration/MultipleEntryPointJoining.test.ts +7 -7
- package/test/integration/ReplicateData.test.ts +28 -30
- package/test/integration/RouteMessage.test.ts +30 -27
- package/test/integration/RouterRpcRemote.test.ts +12 -18
- package/test/integration/RpcErrors.test.ts +8 -21
- package/test/integration/ScaleDownDht.test.ts +11 -10
- package/test/integration/SimultaneousConnections.test.ts +43 -67
- package/test/integration/Store.test.ts +23 -36
- package/test/integration/StoreAndDelete.test.ts +30 -50
- package/test/integration/StoreOnDhtWithTwoNodes.test.ts +16 -37
- package/test/integration/StoreRpcRemote.test.ts +20 -30
- package/test/integration/WebrtcConnectionManagement.test.ts +3 -13
- package/test/integration/WebrtcConnectorRpc.test.ts +3 -9
- package/test/integration/WebsocketConnectionManagement.test.ts +7 -10
- package/test/integration/WebsocketConnectorRpc.test.ts +8 -17
- package/test/unit/ConnectivityHelpers.test.ts +9 -17
- package/test/unit/DuplicateDetector.test.ts +7 -4
- package/test/unit/LocalDataStore.test.ts +66 -77
- package/test/unit/PeerManager.test.ts +31 -0
- package/test/unit/RandomContactList.test.ts +13 -8
- package/test/unit/{Finder.test.ts → RecursiveOperationManager.test.ts} +38 -43
- package/test/unit/RecursiveOperationSession.test.ts +68 -0
- package/test/unit/Router.test.ts +15 -22
- package/test/unit/RoutingSession.test.ts +23 -25
- package/test/unit/SortedContactList.test.ts +41 -26
- package/test/unit/StoreManager.test.ts +132 -0
- package/test/unit/WebsocketConnector.test.ts +27 -35
- package/test/unit/customMatchers.test.ts +16 -0
- package/test/utils/FakeTransport.ts +44 -0
- package/test/utils/customMatchers.ts +70 -0
- package/test/utils/mock/MockRpcCommunicator.ts +7 -0
- package/test/utils/mock/Router.ts +3 -2
- package/test/utils/mock/mockDataEntry.ts +36 -0
- package/test/utils/utils.ts +49 -87
- package/dist/src/dht/find/FindRpcLocal.d.ts +0 -14
- package/dist/src/dht/find/FindRpcLocal.js.map +0 -1
- package/dist/src/dht/find/FindSession.d.ts +0 -44
- package/dist/src/dht/find/FindSession.js +0 -150
- package/dist/src/dht/find/FindSession.js.map +0 -1
- package/dist/src/dht/find/FindSessionRpcLocal.d.ts +0 -12
- package/dist/src/dht/find/FindSessionRpcLocal.js +0 -17
- package/dist/src/dht/find/FindSessionRpcLocal.js.map +0 -1
- package/dist/src/dht/find/FindSessionRpcRemote.d.ts +0 -6
- package/dist/src/dht/find/FindSessionRpcRemote.js +0 -21
- package/dist/src/dht/find/FindSessionRpcRemote.js.map +0 -1
- package/dist/src/dht/find/Finder.d.ts +0 -49
- package/dist/src/dht/find/Finder.js +0 -197
- package/dist/src/dht/find/Finder.js.map +0 -1
- package/dist/src/dht/routing/FindRpcRemote.d.ts +0 -6
- package/dist/src/dht/routing/FindRpcRemote.js.map +0 -1
- package/src/dht/find/FindSession.ts +0 -183
- package/src/dht/find/FindSessionRpcLocal.ts +0 -25
- package/src/dht/find/Finder.ts +0 -295
|
@@ -1,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":["../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,YAAY,CAAC,GAAG,CAAC,EAAE,CAAE,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAA;IAChF,CAAC;IAEM,cAAc;QACjB,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,MAAM,CAAE,CAAC,OAAO,CAAC,CAAA;IAClF,CAAC;IAEM,OAAO;QACV,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,22 +32,21 @@ 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
|
}
|
|
@@ -55,17 +55,17 @@ class DiscoverySession {
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
onClosestPeersRequestFailed(peer) {
|
|
58
|
-
if (!this.ongoingClosestPeersRequests.has(peer.
|
|
58
|
+
if (!this.ongoingClosestPeersRequests.has(peer.getNodeId())) {
|
|
59
59
|
return;
|
|
60
60
|
}
|
|
61
|
-
this.ongoingClosestPeersRequests.delete(peer.
|
|
62
|
-
this.config.peerManager.handlePeerUnresponsive(peer.
|
|
61
|
+
this.ongoingClosestPeersRequests.delete(peer.getNodeId());
|
|
62
|
+
this.config.peerManager.handlePeerUnresponsive(peer.getNodeId());
|
|
63
63
|
}
|
|
64
64
|
findMoreContacts() {
|
|
65
65
|
if (this.stopped) {
|
|
66
66
|
return;
|
|
67
67
|
}
|
|
68
|
-
const uncontacted = this.config.peerManager.getClosestContactsTo(this.config.targetId, this.config.parallelism, this.
|
|
68
|
+
const uncontacted = this.config.peerManager.getClosestContactsTo((0, nodeId_1.getNodeIdFromBinary)(this.config.targetId), this.config.parallelism, this.contactedPeers);
|
|
69
69
|
if (uncontacted.length === 0 || this.noProgressCounter >= this.config.noProgressLimit) {
|
|
70
70
|
this.emitter.emit('discoveryCompleted');
|
|
71
71
|
this.stopped = true;
|
|
@@ -75,19 +75,18 @@ class DiscoverySession {
|
|
|
75
75
|
if (this.ongoingClosestPeersRequests.size >= this.config.parallelism) {
|
|
76
76
|
break;
|
|
77
77
|
}
|
|
78
|
-
this.ongoingClosestPeersRequests.add(nextPeer.
|
|
78
|
+
this.ongoingClosestPeersRequests.add(nextPeer.getNodeId());
|
|
79
79
|
// eslint-disable-next-line promise/catch-or-return
|
|
80
80
|
this.getClosestPeersFromContact(nextPeer)
|
|
81
|
-
.then((contacts) => this.onClosestPeersRequestSucceeded(nextPeer.
|
|
81
|
+
.then((contacts) => this.onClosestPeersRequestSucceeded(nextPeer.getNodeId(), contacts))
|
|
82
82
|
.catch(() => this.onClosestPeersRequestFailed(nextPeer))
|
|
83
83
|
.finally(() => {
|
|
84
|
-
this.outgoingClosestPeersRequestsCounter--;
|
|
85
84
|
this.findMoreContacts();
|
|
86
85
|
});
|
|
87
86
|
}
|
|
88
87
|
}
|
|
89
88
|
async findClosestNodes(timeout) {
|
|
90
|
-
if (this.config.peerManager.getNumberOfContacts(this.
|
|
89
|
+
if (this.config.peerManager.getNumberOfContacts(this.contactedPeers) === 0) {
|
|
91
90
|
return;
|
|
92
91
|
}
|
|
93
92
|
// 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,0CAA6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AO,CAAC,GAAG,EAAE;gBACV,IAAI,CAAC,gBAAgB,EAAE,CAAA;YAC3B,CAAC,CAAC,CAAA;SACT;IACL,CAAC;IAEM,KAAK,CAAC,gBAAgB,CAAC,OAAe;QACzC,IAAI,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,mBAAmB,CAAC,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE;YACxE,OAAM;SACT;QACD,mDAAmD;QACnD,MAAM,IAAA,4BAAoB,EACtB,CAAC,IAAI,CAAC,gBAAgB,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;AAvGD,4CAuGC"}
|
|
@@ -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
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PeerDiscovery.js","sourceRoot":"","sources":["../../../../src/dht/discovery/PeerDiscovery.ts"],"names":[],"mappings":";;;AAAA,yDAAqD;AAErD,qFAAuI;AAEvI,0CAAgF;AAGhF,iDAAyD;
|
|
1
|
+
{"version":3,"file":"PeerDiscovery.js","sourceRoot":"","sources":["../../../../src/dht/discovery/PeerDiscovery.ts"],"names":[],"mappings":";;;AAAA,yDAAqD;AAErD,qFAAuI;AAEvI,0CAAgF;AAGhF,iDAAyD;AAczD,MAAM,MAAM,GAAG,IAAI,cAAM,CAAC,MAAM,CAAC,CAAA;AAEjC,MAAa,aAAa;IAStB,YAAY,MAA2B;QAP/B,6BAAwB,GAAkC,IAAI,GAAG,EAAE,CAAA;QACnE,kBAAa,GAAG,KAAK,CAAA;QACrB,eAAU,GAAG,KAAK,CAAA;QAElB,4BAAuB,GAAG,KAAK,CAAA;QAInC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,eAAe,GAAG,IAAI,eAAe,EAAE,CAAA;IAChD,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,oBAAoC,EAAE,+BAA+B,GAAG,IAAI,EAAE,KAAK,GAAG,IAAI;QACpG,IAAI,IAAI,CAAC,SAAS,EAAE,EAAE;YAClB,OAAM;SACT;QACD,I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IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC,EAC5D,IAAI,CAAC,MAAM,CAAC,WAAW,CAC1B,CAAA;QACD,MAAM,OAAO,CAAC,UAAU,CACpB,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,IAAsB,EAAE,EAAE;YACvC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC,MAAO,CAAC,CAAA;YACpF,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAA;QACpD,CAAC,CAAC,CACL,CAAA;IACL,CAAC;IAEM,aAAa;QAChB,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,wBAAwB,CAAC,IAAI,GAAG,CAAC,CAAA;IAC3E,CAAC;IAEM,YAAY;QACf,OAAO,IAAI,CAAC,UAAU,CAAA;IAC1B,CAAC;IAEO,SAAS;QACb,OAAO,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,OAAO,CAAA;IAC9C,CAAC;IAEM,IAAI;QACP,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,CAAA;QAC5B,IAAI,CAAC,wBAAwB,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAC9C,OAAO,CAAC,IAAI,EAAE,CAAA;QAClB,CAAC,CAAC,CAAA;IACN,CAAC;CACJ;AAvID,sCAuIC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { DataEntry, PeerDescriptor, RecursiveOperation } from '../../proto/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 { NodeID } from '../../helpers/nodeId';
|
|
9
|
+
interface RecursiveOperationManagerConfig {
|
|
10
|
+
rpcCommunicator: RoutingRpcCommunicator;
|
|
11
|
+
sessionTransport: ITransport;
|
|
12
|
+
connections: Map<NodeID, DhtNodeRpcRemote>;
|
|
13
|
+
router: Router;
|
|
14
|
+
localPeerDescriptor: PeerDescriptor;
|
|
15
|
+
serviceId: ServiceID;
|
|
16
|
+
localDataStore: LocalDataStore;
|
|
17
|
+
addContact: (contact: PeerDescriptor) => void;
|
|
18
|
+
}
|
|
19
|
+
export interface RecursiveOperationResult {
|
|
20
|
+
closestNodes: Array<PeerDescriptor>;
|
|
21
|
+
dataEntries?: Array<DataEntry>;
|
|
22
|
+
}
|
|
23
|
+
export declare class RecursiveOperationManager {
|
|
24
|
+
private ongoingSessions;
|
|
25
|
+
private stopped;
|
|
26
|
+
private readonly config;
|
|
27
|
+
constructor(config: RecursiveOperationManagerConfig);
|
|
28
|
+
private registerLocalRpcMethods;
|
|
29
|
+
execute(targetId: Uint8Array, operation: RecursiveOperation, excludedPeer?: PeerDescriptor, waitForCompletion?: boolean): Promise<RecursiveOperationResult>;
|
|
30
|
+
private sendResponse;
|
|
31
|
+
private doRouteRequest;
|
|
32
|
+
private getClosestConnections;
|
|
33
|
+
private isPeerCloserToIdThanSelf;
|
|
34
|
+
stop(): void;
|
|
35
|
+
}
|
|
36
|
+
export {};
|