@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,183 +0,0 @@
|
|
|
1
|
-
import EventEmitter from 'eventemitter3'
|
|
2
|
-
import { PeerID, PeerIDKey } from '../../helpers/PeerID'
|
|
3
|
-
import { DataEntry, PeerDescriptor, FindResponse, FindAction } from '../../proto/packages/dht/protos/DhtRpc'
|
|
4
|
-
import { ITransport } from '../../transport/ITransport'
|
|
5
|
-
import { ListeningRpcCommunicator } from '../../transport/ListeningRpcCommunicator'
|
|
6
|
-
import { Contact } from '../contact/Contact'
|
|
7
|
-
import { SortedContactList } from '../contact/SortedContactList'
|
|
8
|
-
import { FindResult } from './Finder'
|
|
9
|
-
import { keyFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
|
|
10
|
-
import { ServiceID } from '../../types/ServiceID'
|
|
11
|
-
import { FindSessionRpcLocal } from './FindSessionRpcLocal'
|
|
12
|
-
|
|
13
|
-
export interface FindSessionEvents {
|
|
14
|
-
findCompleted: (results: PeerDescriptor[]) => void
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface FindSessionConfig {
|
|
18
|
-
serviceId: ServiceID
|
|
19
|
-
transport: ITransport
|
|
20
|
-
nodeIdToFind: Uint8Array
|
|
21
|
-
localPeerId: PeerID
|
|
22
|
-
waitedRoutingPathCompletions: number
|
|
23
|
-
action: FindAction
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export class FindSession extends EventEmitter<FindSessionEvents> {
|
|
27
|
-
private readonly serviceId: ServiceID
|
|
28
|
-
private readonly transport: ITransport
|
|
29
|
-
private readonly nodeIdToFind: Uint8Array
|
|
30
|
-
private readonly localPeerId: PeerID
|
|
31
|
-
private readonly waitedRoutingPathCompletions: number
|
|
32
|
-
private readonly rpcCommunicator: ListeningRpcCommunicator
|
|
33
|
-
private readonly action: FindAction
|
|
34
|
-
private results: SortedContactList<Contact>
|
|
35
|
-
private foundData: Map<string, DataEntry> = new Map()
|
|
36
|
-
private allKnownHops: Set<PeerIDKey> = new Set()
|
|
37
|
-
private reportedHops: Set<PeerIDKey> = new Set()
|
|
38
|
-
private reportFindCompletedTimeout?: NodeJS.Timeout
|
|
39
|
-
private findCompletedEmitted = false
|
|
40
|
-
private noCloserNodesReceivedCounter = 0
|
|
41
|
-
|
|
42
|
-
constructor(config: FindSessionConfig) {
|
|
43
|
-
super()
|
|
44
|
-
this.serviceId = config.serviceId
|
|
45
|
-
this.transport = config.transport
|
|
46
|
-
this.nodeIdToFind = config.nodeIdToFind
|
|
47
|
-
this.localPeerId = config.localPeerId
|
|
48
|
-
this.waitedRoutingPathCompletions = config.waitedRoutingPathCompletions
|
|
49
|
-
this.results = new SortedContactList({
|
|
50
|
-
referenceId: PeerID.fromValue(this.nodeIdToFind),
|
|
51
|
-
maxSize: 10, // TODO use config option or named constant?
|
|
52
|
-
allowToContainReferenceId: true,
|
|
53
|
-
emitEvents: false
|
|
54
|
-
})
|
|
55
|
-
this.action = config.action
|
|
56
|
-
this.rpcCommunicator = new ListeningRpcCommunicator(this.serviceId, this.transport, {
|
|
57
|
-
rpcRequestTimeout: 15000
|
|
58
|
-
})
|
|
59
|
-
this.registerLocalRpcMethods()
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
private registerLocalRpcMethods() {
|
|
63
|
-
const rpcLocal = new FindSessionRpcLocal({
|
|
64
|
-
doSendFindResponse: (routingPath: PeerDescriptor[], nodes: PeerDescriptor[], dataEntries: DataEntry[], noCloserNodesFound: boolean) => {
|
|
65
|
-
this.doSendFindResponse(routingPath, nodes, dataEntries, noCloserNodesFound)
|
|
66
|
-
}
|
|
67
|
-
})
|
|
68
|
-
this.rpcCommunicator.registerRpcNotification(FindResponse, 'sendFindResponse',
|
|
69
|
-
(req: FindResponse) => rpcLocal.sendFindResponse(req))
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
private isFindCompleted(): boolean {
|
|
73
|
-
const unreportedHops: Set<PeerIDKey> = new Set(this.allKnownHops)
|
|
74
|
-
this.reportedHops.forEach((id) => {
|
|
75
|
-
unreportedHops.delete(id)
|
|
76
|
-
})
|
|
77
|
-
if (this.noCloserNodesReceivedCounter >= 1 && unreportedHops.size === 0) {
|
|
78
|
-
if (this.action === FindAction.FETCH_DATA
|
|
79
|
-
&& (this.hasNonStaleData() || this.noCloserNodesReceivedCounter >= this.waitedRoutingPathCompletions)) {
|
|
80
|
-
return true
|
|
81
|
-
} else if (this.action === FindAction.FETCH_DATA) {
|
|
82
|
-
return false
|
|
83
|
-
}
|
|
84
|
-
return true
|
|
85
|
-
}
|
|
86
|
-
return false
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
private hasNonStaleData(): boolean {
|
|
90
|
-
return Array.from(this.foundData.values()).some((entry) => entry.stale === false)
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
public doSendFindResponse(
|
|
94
|
-
routingPath: PeerDescriptor[],
|
|
95
|
-
nodes: PeerDescriptor[],
|
|
96
|
-
dataEntries: DataEntry[],
|
|
97
|
-
noCloserNodesFound: boolean
|
|
98
|
-
): void {
|
|
99
|
-
this.addKnownHops(routingPath)
|
|
100
|
-
if (routingPath.length >= 1) {
|
|
101
|
-
this.setHopAsReported(routingPath[routingPath.length - 1])
|
|
102
|
-
}
|
|
103
|
-
nodes.forEach((descriptor: PeerDescriptor) => {
|
|
104
|
-
this.results.addContact(new Contact(descriptor))
|
|
105
|
-
})
|
|
106
|
-
this.processFoundData(dataEntries)
|
|
107
|
-
if (noCloserNodesFound) {
|
|
108
|
-
this.onNoCloserPeersFound()
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
private addKnownHops(routingPath: PeerDescriptor[]) {
|
|
113
|
-
routingPath.forEach((desc) => {
|
|
114
|
-
const newPeerId = PeerID.fromValue(desc.nodeId)
|
|
115
|
-
if (!this.localPeerId.equals(newPeerId)) {
|
|
116
|
-
this.allKnownHops.add(newPeerId.toKey())
|
|
117
|
-
}
|
|
118
|
-
})
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
private setHopAsReported(desc: PeerDescriptor) {
|
|
122
|
-
const newPeerId = PeerID.fromValue(desc.nodeId)
|
|
123
|
-
if (!this.localPeerId.equals(newPeerId)) {
|
|
124
|
-
this.reportedHops.add(newPeerId.toKey())
|
|
125
|
-
}
|
|
126
|
-
if (this.isFindCompleted()) {
|
|
127
|
-
if (!this.findCompletedEmitted && this.isFindCompleted()) {
|
|
128
|
-
if (this.reportFindCompletedTimeout) {
|
|
129
|
-
clearTimeout(this.reportFindCompletedTimeout)
|
|
130
|
-
this.reportFindCompletedTimeout = undefined
|
|
131
|
-
}
|
|
132
|
-
this.emit('findCompleted', this.results.getAllContacts().map((contact) => contact.getPeerDescriptor()))
|
|
133
|
-
this.findCompletedEmitted = true
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
private processFoundData(dataEntries: DataEntry[]): void {
|
|
139
|
-
dataEntries.forEach((entry) => {
|
|
140
|
-
const creatorKey = keyFromPeerDescriptor(entry.creator!)
|
|
141
|
-
const existingEntry = this.foundData.get(creatorKey)
|
|
142
|
-
if (!existingEntry || existingEntry.createdAt! < entry.createdAt!
|
|
143
|
-
|| (existingEntry.createdAt! <= entry.createdAt! && entry.deleted)) {
|
|
144
|
-
this.foundData.set(creatorKey, entry)
|
|
145
|
-
}
|
|
146
|
-
})
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
private onNoCloserPeersFound(): void {
|
|
150
|
-
this.noCloserNodesReceivedCounter += 1
|
|
151
|
-
if (this.isFindCompleted()) {
|
|
152
|
-
this.emit('findCompleted', this.results.getAllContacts().map((contact) => contact.getPeerDescriptor()))
|
|
153
|
-
this.findCompletedEmitted = true
|
|
154
|
-
if (this.reportFindCompletedTimeout) {
|
|
155
|
-
clearTimeout(this.reportFindCompletedTimeout)
|
|
156
|
-
this.reportFindCompletedTimeout = undefined
|
|
157
|
-
}
|
|
158
|
-
} else {
|
|
159
|
-
if (!this.reportFindCompletedTimeout && !this.findCompletedEmitted) {
|
|
160
|
-
this.reportFindCompletedTimeout = setTimeout(() => {
|
|
161
|
-
if (!this.findCompletedEmitted) {
|
|
162
|
-
this.emit('findCompleted', this.results.getAllContacts().map((contact) => contact.getPeerDescriptor()))
|
|
163
|
-
this.findCompletedEmitted = true
|
|
164
|
-
}
|
|
165
|
-
}, 4000)
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
public getResults = (): FindResult => ({
|
|
171
|
-
closestNodes: this.results.getAllContacts().map((contact) => contact.getPeerDescriptor()),
|
|
172
|
-
dataEntries: Array.from(this.foundData.values())
|
|
173
|
-
})
|
|
174
|
-
|
|
175
|
-
public stop(): void {
|
|
176
|
-
if (this.reportFindCompletedTimeout) {
|
|
177
|
-
clearTimeout(this.reportFindCompletedTimeout)
|
|
178
|
-
this.reportFindCompletedTimeout = undefined
|
|
179
|
-
}
|
|
180
|
-
this.rpcCommunicator.destroy()
|
|
181
|
-
this.emit('findCompleted', [])
|
|
182
|
-
}
|
|
183
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { IFindSessionRpc } from '../../proto/packages/dht/protos/DhtRpc.server'
|
|
2
|
-
import { Empty } from '../../proto/google/protobuf/empty'
|
|
3
|
-
import { DataEntry, FindResponse, PeerDescriptor } from '../../proto/packages/dht/protos/DhtRpc'
|
|
4
|
-
import { Logger } from '@streamr/utils'
|
|
5
|
-
|
|
6
|
-
const logger = new Logger(module)
|
|
7
|
-
|
|
8
|
-
interface FindSessionRpcLocalConfig {
|
|
9
|
-
doSendFindResponse: (routingPath: PeerDescriptor[], nodes: PeerDescriptor[], dataEntries: DataEntry[], noCloserNodesFound: boolean) => void
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export class FindSessionRpcLocal implements IFindSessionRpc {
|
|
13
|
-
|
|
14
|
-
private readonly config: FindSessionRpcLocalConfig
|
|
15
|
-
|
|
16
|
-
constructor(config: FindSessionRpcLocalConfig) {
|
|
17
|
-
this.config = config
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
async sendFindResponse(report: FindResponse): Promise<Empty> {
|
|
21
|
-
logger.trace('FindResponse arrived: ' + JSON.stringify(report))
|
|
22
|
-
this.config.doSendFindResponse(report.routingPath, report.closestConnectedPeers, report.dataEntries, report.noCloserNodesFound)
|
|
23
|
-
return {}
|
|
24
|
-
}
|
|
25
|
-
}
|
package/src/dht/find/Finder.ts
DELETED
|
@@ -1,295 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DataEntry,
|
|
3
|
-
Message,
|
|
4
|
-
MessageType,
|
|
5
|
-
NodeType,
|
|
6
|
-
PeerDescriptor,
|
|
7
|
-
FindRequest,
|
|
8
|
-
RouteMessageAck,
|
|
9
|
-
RouteMessageWrapper,
|
|
10
|
-
RouteMessageError,
|
|
11
|
-
FindAction
|
|
12
|
-
} from '../../proto/packages/dht/protos/DhtRpc'
|
|
13
|
-
import { PeerID, PeerIDKey } from '../../helpers/PeerID'
|
|
14
|
-
import { IRouter } from '../routing/Router'
|
|
15
|
-
import { RoutingMode } from '../routing/RoutingSession'
|
|
16
|
-
import { areEqualPeerDescriptors, peerIdFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
|
|
17
|
-
import { Logger, runAndWaitForEvents3, wait } from '@streamr/utils'
|
|
18
|
-
import { RoutingRpcCommunicator } from '../../transport/RoutingRpcCommunicator'
|
|
19
|
-
import { FindSessionRpcRemote } from './FindSessionRpcRemote'
|
|
20
|
-
import { v4 } from 'uuid'
|
|
21
|
-
import { FindSession, FindSessionEvents } from './FindSession'
|
|
22
|
-
import { DhtNodeRpcRemote } from '../DhtNodeRpcRemote'
|
|
23
|
-
import { ITransport } from '../../transport/ITransport'
|
|
24
|
-
import { LocalDataStore } from '../store/LocalDataStore'
|
|
25
|
-
import { ListeningRpcCommunicator } from '../../transport/ListeningRpcCommunicator'
|
|
26
|
-
import { FindSessionRpcClient } from '../../proto/packages/dht/protos/DhtRpc.client'
|
|
27
|
-
import { toProtoRpcClient } from '@streamr/proto-rpc'
|
|
28
|
-
import { SortedContactList } from '../contact/SortedContactList'
|
|
29
|
-
import { getPreviousPeer } from '../routing/getPreviousPeer'
|
|
30
|
-
import { createRouteMessageAck } from '../routing/RouterRpcLocal'
|
|
31
|
-
import { ServiceID } from '../../types/ServiceID'
|
|
32
|
-
import { FindRpcLocal } from './FindRpcLocal'
|
|
33
|
-
|
|
34
|
-
interface FinderConfig {
|
|
35
|
-
rpcCommunicator: RoutingRpcCommunicator
|
|
36
|
-
sessionTransport: ITransport
|
|
37
|
-
connections: Map<PeerIDKey, DhtNodeRpcRemote>
|
|
38
|
-
router: IRouter
|
|
39
|
-
localPeerDescriptor: PeerDescriptor
|
|
40
|
-
serviceId: ServiceID
|
|
41
|
-
localDataStore: LocalDataStore
|
|
42
|
-
addContact: (contact: PeerDescriptor) => void
|
|
43
|
-
isPeerCloserToIdThanSelf: (peer1: PeerDescriptor, compareToId: PeerID) => boolean
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export interface IFinder {
|
|
47
|
-
startFind(idToFind: Uint8Array, action?: FindAction): Promise<FindResult>
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export interface FindResult { closestNodes: Array<PeerDescriptor>, dataEntries?: Array<DataEntry> }
|
|
51
|
-
|
|
52
|
-
const logger = new Logger(module)
|
|
53
|
-
|
|
54
|
-
export class Finder implements IFinder {
|
|
55
|
-
|
|
56
|
-
private readonly rpcCommunicator: RoutingRpcCommunicator
|
|
57
|
-
private readonly sessionTransport: ITransport
|
|
58
|
-
private readonly connections: Map<PeerIDKey, DhtNodeRpcRemote>
|
|
59
|
-
private readonly router: IRouter
|
|
60
|
-
private readonly localPeerDescriptor: PeerDescriptor
|
|
61
|
-
private readonly serviceId: ServiceID
|
|
62
|
-
private readonly localDataStore: LocalDataStore
|
|
63
|
-
private readonly isPeerCloserToIdThanSelf: (peer1: PeerDescriptor, compareToId: PeerID) => boolean
|
|
64
|
-
private ongoingSessions: Map<string, FindSession> = new Map()
|
|
65
|
-
private stopped = false
|
|
66
|
-
|
|
67
|
-
constructor(config: FinderConfig) {
|
|
68
|
-
this.rpcCommunicator = config.rpcCommunicator
|
|
69
|
-
this.sessionTransport = config.sessionTransport
|
|
70
|
-
this.connections = config.connections
|
|
71
|
-
this.router = config.router
|
|
72
|
-
this.localPeerDescriptor = config.localPeerDescriptor
|
|
73
|
-
this.serviceId = config.serviceId
|
|
74
|
-
this.localDataStore = config.localDataStore
|
|
75
|
-
this.isPeerCloserToIdThanSelf = config.isPeerCloserToIdThanSelf
|
|
76
|
-
this.registerLocalRpcMethods(config)
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
private registerLocalRpcMethods(config: FinderConfig) {
|
|
80
|
-
const rpcLocal = new FindRpcLocal({
|
|
81
|
-
doRouteFindRequest: (routedMessage: RouteMessageWrapper) => this.doRouteFindRequest(routedMessage),
|
|
82
|
-
addContact: (contact: PeerDescriptor) => config.addContact(contact),
|
|
83
|
-
isMostLikelyDuplicate: (requestId: string) => this.router.isMostLikelyDuplicate(requestId),
|
|
84
|
-
addToDuplicateDetector: (requestId: string) => this.router.addToDuplicateDetector(requestId)
|
|
85
|
-
})
|
|
86
|
-
this.rpcCommunicator.registerRpcMethod(
|
|
87
|
-
RouteMessageWrapper,
|
|
88
|
-
RouteMessageAck,
|
|
89
|
-
'routeFindRequest',
|
|
90
|
-
async (routedMessage: RouteMessageWrapper) => {
|
|
91
|
-
if (this.stopped) {
|
|
92
|
-
return createRouteMessageAck(routedMessage, RouteMessageError.STOPPED)
|
|
93
|
-
} else {
|
|
94
|
-
return rpcLocal.routeFindRequest(routedMessage)
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
)
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
public async startFind(
|
|
101
|
-
idToFind: Uint8Array,
|
|
102
|
-
action: FindAction = FindAction.NODE,
|
|
103
|
-
excludedPeer?: PeerDescriptor,
|
|
104
|
-
waitForCompletion = true
|
|
105
|
-
): Promise<FindResult> {
|
|
106
|
-
if (this.stopped) {
|
|
107
|
-
return { closestNodes: [] }
|
|
108
|
-
}
|
|
109
|
-
const sessionId = v4()
|
|
110
|
-
const session = new FindSession({
|
|
111
|
-
serviceId: sessionId,
|
|
112
|
-
transport: this.sessionTransport,
|
|
113
|
-
nodeIdToFind: idToFind,
|
|
114
|
-
localPeerId: peerIdFromPeerDescriptor(this.localPeerDescriptor),
|
|
115
|
-
waitedRoutingPathCompletions: this.connections.size > 1 ? 2 : 1,
|
|
116
|
-
action
|
|
117
|
-
})
|
|
118
|
-
if (this.connections.size === 0) {
|
|
119
|
-
const data = this.localDataStore.getEntry(PeerID.fromValue(idToFind))
|
|
120
|
-
session.doSendFindResponse(
|
|
121
|
-
[this.localPeerDescriptor],
|
|
122
|
-
[this.localPeerDescriptor],
|
|
123
|
-
Array.from(data.values()),
|
|
124
|
-
true
|
|
125
|
-
)
|
|
126
|
-
return session.getResults()
|
|
127
|
-
}
|
|
128
|
-
const routeMessage = this.wrapFindRequest(idToFind, sessionId, action)
|
|
129
|
-
this.ongoingSessions.set(sessionId, session)
|
|
130
|
-
if (waitForCompletion === true) {
|
|
131
|
-
try {
|
|
132
|
-
await runAndWaitForEvents3<FindSessionEvents>(
|
|
133
|
-
[() => this.doRouteFindRequest(routeMessage, excludedPeer)],
|
|
134
|
-
[[session, 'findCompleted']],
|
|
135
|
-
15000
|
|
136
|
-
)
|
|
137
|
-
} catch (err) {
|
|
138
|
-
logger.debug(`doRouteFindRequest failed with error ${err}`)
|
|
139
|
-
}
|
|
140
|
-
} else {
|
|
141
|
-
this.doRouteFindRequest(routeMessage, excludedPeer)
|
|
142
|
-
// Wait for delete operation to be sent out by the router
|
|
143
|
-
// TODO: Add a feature to wait for the router to pass the message?
|
|
144
|
-
await wait(50)
|
|
145
|
-
}
|
|
146
|
-
if (action === FindAction.FETCH_DATA) {
|
|
147
|
-
this.findAndReportLocalData(idToFind, [], this.localPeerDescriptor, sessionId)
|
|
148
|
-
} else if (action === FindAction.DELETE_DATA) {
|
|
149
|
-
this.localDataStore.markAsDeleted(idToFind, peerIdFromPeerDescriptor(this.localPeerDescriptor))
|
|
150
|
-
}
|
|
151
|
-
this.ongoingSessions.delete(sessionId)
|
|
152
|
-
session.stop()
|
|
153
|
-
return session.getResults()
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
private wrapFindRequest(idToFind: Uint8Array, sessionId: string, action: FindAction): RouteMessageWrapper {
|
|
157
|
-
const targetDescriptor: PeerDescriptor = {
|
|
158
|
-
nodeId: idToFind,
|
|
159
|
-
type: NodeType.VIRTUAL
|
|
160
|
-
}
|
|
161
|
-
const request: FindRequest = {
|
|
162
|
-
sessionId,
|
|
163
|
-
action
|
|
164
|
-
}
|
|
165
|
-
const msg: Message = {
|
|
166
|
-
messageType: MessageType.FIND_REQUEST,
|
|
167
|
-
messageId: v4(),
|
|
168
|
-
serviceId: this.serviceId,
|
|
169
|
-
body: {
|
|
170
|
-
oneofKind: 'findRequest',
|
|
171
|
-
findRequest: request
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
const routeMessage: RouteMessageWrapper = {
|
|
175
|
-
message: msg,
|
|
176
|
-
requestId: v4(),
|
|
177
|
-
destinationPeer: targetDescriptor,
|
|
178
|
-
sourcePeer: this.localPeerDescriptor,
|
|
179
|
-
reachableThrough: [],
|
|
180
|
-
routingPath: []
|
|
181
|
-
}
|
|
182
|
-
return routeMessage
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
private findAndReportLocalData(
|
|
186
|
-
idToFind: Uint8Array,
|
|
187
|
-
routingPath: PeerDescriptor[],
|
|
188
|
-
sourcePeer: PeerDescriptor,
|
|
189
|
-
sessionId: string
|
|
190
|
-
): void {
|
|
191
|
-
const data = this.localDataStore.getEntry(PeerID.fromValue(idToFind))
|
|
192
|
-
if (data.size > 0) {
|
|
193
|
-
this.sendFindResponse(routingPath, sourcePeer, sessionId, [], data, true)
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
private findLocalData(idToFind: Uint8Array, fetchData: boolean): Map<PeerIDKey, DataEntry> | undefined {
|
|
198
|
-
if (fetchData) {
|
|
199
|
-
return this.localDataStore.getEntry(PeerID.fromValue(idToFind))
|
|
200
|
-
}
|
|
201
|
-
return undefined
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
private sendFindResponse(
|
|
205
|
-
routingPath: PeerDescriptor[],
|
|
206
|
-
targetPeerDescriptor: PeerDescriptor,
|
|
207
|
-
serviceId: ServiceID,
|
|
208
|
-
closestNodes: PeerDescriptor[],
|
|
209
|
-
data: Map<PeerIDKey, DataEntry> | undefined,
|
|
210
|
-
noCloserNodesFound: boolean = false
|
|
211
|
-
): void {
|
|
212
|
-
const dataEntries = data ? Array.from(data.values(), DataEntry.create.bind(DataEntry)) : []
|
|
213
|
-
const isOwnNode = areEqualPeerDescriptors(this.localPeerDescriptor, targetPeerDescriptor)
|
|
214
|
-
if (isOwnNode && this.ongoingSessions.has(serviceId)) {
|
|
215
|
-
this.ongoingSessions.get(serviceId)!
|
|
216
|
-
.doSendFindResponse(routingPath, closestNodes, dataEntries, noCloserNodesFound)
|
|
217
|
-
} else {
|
|
218
|
-
const remoteCommunicator = new ListeningRpcCommunicator(serviceId, this.sessionTransport, { rpcRequestTimeout: 15000 })
|
|
219
|
-
const rpcRemote = new FindSessionRpcRemote(
|
|
220
|
-
this.localPeerDescriptor,
|
|
221
|
-
targetPeerDescriptor,
|
|
222
|
-
serviceId,
|
|
223
|
-
toProtoRpcClient(new FindSessionRpcClient(remoteCommunicator.getRpcClientTransport())),
|
|
224
|
-
10000
|
|
225
|
-
)
|
|
226
|
-
rpcRemote.sendFindResponse(routingPath, closestNodes, dataEntries, noCloserNodesFound)
|
|
227
|
-
remoteCommunicator.destroy()
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
private doRouteFindRequest(routedMessage: RouteMessageWrapper, excludedPeer?: PeerDescriptor): RouteMessageAck {
|
|
232
|
-
if (this.stopped) {
|
|
233
|
-
return createRouteMessageAck(routedMessage, RouteMessageError.STOPPED)
|
|
234
|
-
}
|
|
235
|
-
const idToFind = peerIdFromPeerDescriptor(routedMessage.destinationPeer!)
|
|
236
|
-
const msg = routedMessage.message
|
|
237
|
-
const findRequest = msg?.body.oneofKind === 'findRequest' ? msg.body.findRequest : undefined
|
|
238
|
-
const closestPeersToDestination = this.getClosestConnections(routedMessage.destinationPeer!.nodeId, 5)
|
|
239
|
-
const data = this.findLocalData(idToFind.value, findRequest!.action === FindAction.FETCH_DATA)
|
|
240
|
-
if (findRequest!.action === FindAction.DELETE_DATA) {
|
|
241
|
-
this.localDataStore.markAsDeleted(idToFind.value, peerIdFromPeerDescriptor(routedMessage.sourcePeer!))
|
|
242
|
-
}
|
|
243
|
-
if (areEqualPeerDescriptors(this.localPeerDescriptor, routedMessage.destinationPeer!)) {
|
|
244
|
-
// TODO this is also very similar case to what we do at line 255, could simplify the code paths?
|
|
245
|
-
this.sendFindResponse(
|
|
246
|
-
routedMessage.routingPath,
|
|
247
|
-
routedMessage.sourcePeer!,
|
|
248
|
-
findRequest!.sessionId,
|
|
249
|
-
closestPeersToDestination,
|
|
250
|
-
data,
|
|
251
|
-
true
|
|
252
|
-
)
|
|
253
|
-
return createRouteMessageAck(routedMessage)
|
|
254
|
-
} else {
|
|
255
|
-
const ack = this.router.doRouteMessage(routedMessage, RoutingMode.FIND, excludedPeer)
|
|
256
|
-
if ((ack.error === undefined) || (ack.error === RouteMessageError.NO_TARGETS)) {
|
|
257
|
-
const noCloserContactsFound = (ack.error === RouteMessageError.NO_TARGETS) ||
|
|
258
|
-
(
|
|
259
|
-
closestPeersToDestination.length > 0
|
|
260
|
-
&& getPreviousPeer(routedMessage)
|
|
261
|
-
&& !this.isPeerCloserToIdThanSelf(closestPeersToDestination[0], idToFind)
|
|
262
|
-
)
|
|
263
|
-
this.sendFindResponse(
|
|
264
|
-
routedMessage.routingPath,
|
|
265
|
-
routedMessage.sourcePeer!,
|
|
266
|
-
findRequest!.sessionId,
|
|
267
|
-
closestPeersToDestination,
|
|
268
|
-
data,
|
|
269
|
-
noCloserContactsFound
|
|
270
|
-
)
|
|
271
|
-
}
|
|
272
|
-
return ack
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
private getClosestConnections(nodeId: Uint8Array, limit: number): PeerDescriptor[] {
|
|
277
|
-
const connectedPeers = Array.from(this.connections.values())
|
|
278
|
-
const closestPeers = new SortedContactList<DhtNodeRpcRemote>({
|
|
279
|
-
referenceId: PeerID.fromValue(nodeId),
|
|
280
|
-
maxSize: limit,
|
|
281
|
-
allowToContainReferenceId: true,
|
|
282
|
-
emitEvents: false
|
|
283
|
-
})
|
|
284
|
-
closestPeers.addContacts(connectedPeers)
|
|
285
|
-
return closestPeers.getClosestContacts(limit).map((peer) => peer.getPeerDescriptor())
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
public stop(): void {
|
|
289
|
-
this.stopped = true
|
|
290
|
-
this.ongoingSessions.forEach((session, _id) => {
|
|
291
|
-
session.stop()
|
|
292
|
-
})
|
|
293
|
-
this.ongoingSessions.clear()
|
|
294
|
-
}
|
|
295
|
-
}
|