@streamr/dht 100.0.0-testnet-one.4 → 100.0.0-testnet-two.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/connection/ConnectionLockHandler.d.ts +11 -11
- package/dist/src/connection/ConnectionLockHandler.js.map +1 -1
- package/dist/src/connection/ConnectionLockRpcLocal.d.ts +3 -3
- package/dist/src/connection/ConnectionLockRpcLocal.js +4 -4
- package/dist/src/connection/ConnectionLockRpcLocal.js.map +1 -1
- package/dist/src/connection/ConnectionLockRpcRemote.d.ts +3 -5
- package/dist/src/connection/ConnectionLockRpcRemote.js +4 -7
- package/dist/src/connection/ConnectionLockRpcRemote.js.map +1 -1
- package/dist/src/connection/ConnectionManager.d.ts +4 -6
- package/dist/src/connection/ConnectionManager.js +48 -46
- package/dist/src/connection/ConnectionManager.js.map +1 -1
- package/dist/src/connection/ConnectorFacade.d.ts +2 -2
- package/dist/src/connection/ConnectorFacade.js +2 -1
- package/dist/src/connection/ConnectorFacade.js.map +1 -1
- package/dist/src/connection/ManagedConnection.d.ts +3 -6
- package/dist/src/connection/ManagedConnection.js +6 -10
- package/dist/src/connection/ManagedConnection.js.map +1 -1
- package/dist/src/connection/connectivityChecker.js +1 -0
- package/dist/src/connection/connectivityChecker.js.map +1 -1
- package/dist/src/connection/simulator/Simulator.d.ts +0 -3
- package/dist/src/connection/simulator/Simulator.js +3 -51
- package/dist/src/connection/simulator/Simulator.js.map +1 -1
- package/dist/src/connection/simulator/SimulatorConnector.js +5 -5
- package/dist/src/connection/simulator/SimulatorConnector.js.map +1 -1
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js +2 -2
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnector.d.ts +0 -1
- package/dist/src/connection/webrtc/WebrtcConnector.js +7 -9
- package/dist/src/connection/webrtc/WebrtcConnector.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.d.ts +2 -2
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js +11 -12
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.d.ts +2 -5
- package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.js +1 -4
- package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.js.map +1 -1
- package/dist/src/connection/websocket/AutoCertifierClientFacade.d.ts +1 -2
- package/dist/src/connection/websocket/AutoCertifierClientFacade.js +3 -4
- package/dist/src/connection/websocket/AutoCertifierClientFacade.js.map +1 -1
- package/dist/src/connection/websocket/ClientWebsocket.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnector.d.ts +2 -7
- package/dist/src/connection/websocket/WebsocketConnector.js +32 -38
- package/dist/src/connection/websocket/WebsocketConnector.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.d.ts +3 -2
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.js +8 -10
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.d.ts +3 -6
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.js +0 -3
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketServer.d.ts +1 -4
- package/dist/src/connection/websocket/WebsocketServer.js +11 -12
- package/dist/src/connection/websocket/WebsocketServer.js.map +1 -1
- package/dist/src/dht/DhtNode.d.ts +10 -13
- package/dist/src/dht/DhtNode.js +39 -52
- package/dist/src/dht/DhtNode.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcLocal.d.ts +0 -1
- package/dist/src/dht/DhtNodeRpcLocal.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcRemote.d.ts +7 -7
- package/dist/src/dht/DhtNodeRpcRemote.js +8 -7
- package/dist/src/dht/DhtNodeRpcRemote.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcLocal.d.ts +5 -4
- package/dist/src/dht/ExternalApiRpcLocal.js +3 -2
- package/dist/src/dht/ExternalApiRpcLocal.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcRemote.d.ts +2 -2
- package/dist/src/dht/ExternalApiRpcRemote.js +2 -0
- package/dist/src/dht/ExternalApiRpcRemote.js.map +1 -1
- package/dist/src/dht/PeerManager.d.ts +13 -14
- package/dist/src/dht/PeerManager.js +45 -60
- package/dist/src/dht/PeerManager.js.map +1 -1
- package/dist/src/dht/contact/Contact.d.ts +2 -2
- package/dist/src/dht/contact/Contact.js +2 -2
- package/dist/src/dht/contact/Contact.js.map +1 -1
- package/dist/src/dht/contact/ContactList.d.ts +7 -7
- package/dist/src/dht/contact/ContactList.js +3 -3
- package/dist/src/dht/contact/ContactList.js.map +1 -1
- package/dist/src/dht/contact/RandomContactList.d.ts +4 -4
- package/dist/src/dht/contact/RandomContactList.js +12 -11
- package/dist/src/dht/contact/RandomContactList.js.map +1 -1
- package/dist/src/dht/contact/RpcRemote.d.ts +7 -4
- package/dist/src/dht/contact/RpcRemote.js +5 -2
- package/dist/src/dht/contact/RpcRemote.js.map +1 -1
- package/dist/src/dht/contact/SortedContactList.d.ts +13 -13
- package/dist/src/dht/contact/SortedContactList.js +33 -29
- package/dist/src/dht/contact/SortedContactList.js.map +1 -1
- package/dist/src/dht/discovery/DiscoverySession.d.ts +2 -4
- package/dist/src/dht/discovery/DiscoverySession.js +19 -20
- package/dist/src/dht/discovery/DiscoverySession.js.map +1 -1
- package/dist/src/dht/discovery/PeerDiscovery.d.ts +2 -5
- package/dist/src/dht/discovery/PeerDiscovery.js +12 -20
- package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.d.ts +36 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.js +165 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.d.ts +14 -0
- package/dist/src/dht/{find/FindRpcLocal.js → recursive-operation/RecursiveOperationRpcLocal.js} +7 -7
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.d.ts +6 -0
- package/dist/src/dht/{routing/FindRpcRemote.js → recursive-operation/RecursiveOperationRpcRemote.js} +11 -11
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.d.ts +42 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.js +182 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.d.ts +12 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js +17 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.d.ts +6 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.js +21 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.js.map +1 -0
- package/dist/src/dht/routing/Router.d.ts +4 -19
- package/dist/src/dht/routing/Router.js +41 -33
- package/dist/src/dht/routing/Router.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcLocal.js +6 -5
- package/dist/src/dht/routing/RouterRpcLocal.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcRemote.d.ts +2 -2
- package/dist/src/dht/routing/RouterRpcRemote.js +7 -7
- package/dist/src/dht/routing/RouterRpcRemote.js.map +1 -1
- package/dist/src/dht/routing/RoutingSession.d.ts +20 -16
- package/dist/src/dht/routing/RoutingSession.js +37 -45
- package/dist/src/dht/routing/RoutingSession.js.map +1 -1
- package/dist/src/dht/store/LocalDataStore.d.ts +11 -13
- package/dist/src/dht/store/LocalDataStore.js +36 -56
- package/dist/src/dht/store/LocalDataStore.js.map +1 -1
- package/dist/src/dht/store/StoreManager.d.ts +33 -0
- package/dist/src/dht/store/StoreManager.js +186 -0
- package/dist/src/dht/store/StoreManager.js.map +1 -0
- package/dist/src/dht/store/StoreRpcLocal.d.ts +8 -40
- package/dist/src/dht/store/StoreRpcLocal.js +13 -229
- package/dist/src/dht/store/StoreRpcLocal.js.map +1 -1
- package/dist/src/dht/store/StoreRpcRemote.d.ts +5 -5
- package/dist/src/dht/store/StoreRpcRemote.js +4 -5
- package/dist/src/dht/store/StoreRpcRemote.js.map +1 -1
- package/dist/src/exports.d.ts +2 -0
- package/dist/src/exports.js.map +1 -1
- package/dist/src/helpers/MapWithTtl.d.ts +14 -0
- package/dist/src/helpers/MapWithTtl.js +59 -0
- package/dist/src/helpers/MapWithTtl.js.map +1 -0
- package/dist/src/helpers/PeerID.d.ts +2 -0
- package/dist/src/helpers/PeerID.js +4 -0
- package/dist/src/helpers/PeerID.js.map +1 -1
- package/dist/src/helpers/nodeId.d.ts +5 -0
- package/dist/src/helpers/nodeId.js +18 -1
- package/dist/src/helpers/nodeId.js.map +1 -1
- package/dist/src/helpers/peerIdFromPeerDescriptor.d.ts +2 -1
- package/dist/src/helpers/peerIdFromPeerDescriptor.js +2 -1
- package/dist/src/helpers/peerIdFromPeerDescriptor.js.map +1 -1
- package/dist/src/helpers/protoClasses.js +2 -3
- package/dist/src/helpers/protoClasses.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +21 -22
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +18 -18
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +36 -60
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +34 -53
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +11 -12
- package/dist/src/rpc-protocol/DhtCallContext.d.ts +2 -1
- package/dist/src/rpc-protocol/DhtCallContext.js.map +1 -1
- package/dist/src/rpc-protocol/DhtRpcOptions.d.ts +2 -1
- package/dist/src/transport/ITransport.d.ts +9 -1
- package/dist/src/transport/ITransport.js +5 -0
- package/dist/src/transport/ITransport.js.map +1 -1
- package/dist/src/transport/ListeningRpcCommunicator.js +1 -1
- package/dist/src/transport/ListeningRpcCommunicator.js.map +1 -1
- package/dist/src/transport/RoutingRpcCommunicator.d.ts +2 -1
- package/dist/src/transport/RoutingRpcCommunicator.js +16 -11
- package/dist/src/transport/RoutingRpcCommunicator.js.map +1 -1
- package/jest.config.js +4 -1
- package/karma-setup.js +2 -0
- package/karma.config.js +11 -7
- package/package.json +6 -7
- package/protos/DhtRpc.proto +17 -23
- package/src/connection/ConnectionLockHandler.ts +15 -15
- package/src/connection/ConnectionLockRpcLocal.ts +8 -9
- package/src/connection/ConnectionLockRpcRemote.ts +7 -16
- package/src/connection/ConnectionManager.ts +58 -55
- package/src/connection/ConnectorFacade.ts +3 -0
- package/src/connection/ManagedConnection.ts +12 -30
- package/src/connection/connectivityChecker.ts +1 -0
- package/src/connection/simulator/Simulator.ts +5 -36
- package/src/connection/simulator/SimulatorConnector.ts +8 -8
- package/src/connection/webrtc/BrowserWebrtcConnection.ts +0 -3
- package/src/connection/webrtc/NodeWebrtcConnection.ts +3 -4
- package/src/connection/webrtc/WebrtcConnector.ts +11 -13
- package/src/connection/webrtc/WebrtcConnectorRpcLocal.ts +16 -16
- package/src/connection/webrtc/WebrtcConnectorRpcRemote.ts +3 -13
- package/src/connection/websocket/AutoCertifierClientFacade.ts +4 -6
- package/src/connection/websocket/ClientWebsocket.ts +1 -0
- package/src/connection/websocket/WebsocketConnector.ts +43 -56
- package/src/connection/websocket/WebsocketConnectorRpcLocal.ts +11 -13
- package/src/connection/websocket/WebsocketConnectorRpcRemote.ts +4 -15
- package/src/connection/websocket/WebsocketServer.ts +14 -17
- package/src/dht/DhtNode.ts +67 -69
- package/src/dht/DhtNodeRpcLocal.ts +0 -1
- package/src/dht/DhtNodeRpcRemote.ts +13 -13
- package/src/dht/ExternalApiRpcLocal.ts +16 -6
- package/src/dht/ExternalApiRpcRemote.ts +5 -3
- package/src/dht/PeerManager.ts +73 -90
- package/src/dht/contact/Contact.ts +5 -4
- package/src/dht/contact/ContactList.ts +9 -9
- package/src/dht/contact/RandomContactList.ts +14 -14
- package/src/dht/contact/RpcRemote.ts +10 -7
- package/src/dht/contact/SortedContactList.ts +48 -45
- package/src/dht/discovery/DiscoverySession.ts +25 -25
- package/src/dht/discovery/PeerDiscovery.ts +16 -37
- package/src/dht/recursive-operation/RecursiveOperationManager.ts +240 -0
- package/src/dht/{find/FindRpcLocal.ts → recursive-operation/RecursiveOperationRpcLocal.ts} +9 -9
- package/src/dht/{routing/FindRpcRemote.ts → recursive-operation/RecursiveOperationRpcRemote.ts} +10 -10
- package/src/dht/recursive-operation/RecursiveOperationSession.ts +224 -0
- package/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.ts +25 -0
- package/src/dht/{find/FindSessionRpcRemote.ts → recursive-operation/RecursiveOperationSessionRpcRemote.ts} +8 -8
- package/src/dht/routing/Router.ts +45 -64
- package/src/dht/routing/RouterRpcLocal.ts +7 -6
- package/src/dht/routing/RouterRpcRemote.ts +9 -10
- package/src/dht/routing/RoutingSession.ts +59 -68
- package/src/dht/store/LocalDataStore.ts +47 -66
- package/src/dht/store/StoreManager.ts +217 -0
- package/src/dht/store/StoreRpcLocal.ts +26 -302
- package/src/dht/store/StoreRpcRemote.ts +9 -11
- package/src/exports.ts +2 -0
- package/src/helpers/MapWithTtl.ts +71 -0
- package/src/helpers/PeerID.ts +5 -0
- package/src/helpers/nodeId.ts +20 -0
- package/src/helpers/peerIdFromPeerDescriptor.ts +5 -3
- package/src/helpers/protoClasses.ts +4 -6
- package/src/proto/packages/dht/protos/DhtRpc.client.ts +31 -32
- package/src/proto/packages/dht/protos/DhtRpc.server.ts +11 -12
- package/src/proto/packages/dht/protos/DhtRpc.ts +49 -80
- package/src/rpc-protocol/DhtCallContext.ts +2 -1
- package/src/rpc-protocol/DhtRpcOptions.ts +2 -1
- package/src/transport/ITransport.ts +10 -1
- package/src/transport/ListeningRpcCommunicator.ts +1 -1
- package/src/transport/RoutingRpcCommunicator.ts +18 -12
- package/test/benchmark/Find.test.ts +8 -21
- package/test/benchmark/KademliaCorrectness.test.ts +11 -20
- package/test/benchmark/SortedContactListBenchmark.test.ts +9 -9
- package/test/benchmark/kademlia-simulation/Contact.ts +9 -8
- package/test/benchmark/kademlia-simulation/KademliaSimulation.ts +2 -2
- package/test/benchmark/kademlia-simulation/SimulationNode.ts +17 -17
- package/test/end-to-end/Layer0-Layer1.test.ts +10 -14
- package/test/end-to-end/Layer0.test.ts +15 -18
- package/test/end-to-end/Layer0MixedConnectionTypes.test.ts +7 -9
- package/test/end-to-end/Layer0Webrtc-Layer1.test.ts +4 -10
- package/test/end-to-end/Layer0Webrtc.test.ts +5 -6
- package/test/end-to-end/Layer1-Scale-WebSocket.test.ts +8 -16
- package/test/end-to-end/Layer1-Scale-Webrtc.test.ts +6 -13
- package/test/end-to-end/WebsocketConnectionRequest.test.ts +5 -6
- package/test/end-to-end/memory-leak.test.ts +6 -8
- package/test/integration/ConnectionLocking.test.ts +6 -13
- package/test/integration/ConnectionManager.test.ts +26 -43
- package/test/integration/DhtJoinPeerDiscovery.test.ts +5 -10
- package/test/integration/DhtNodeExternalAPI.test.ts +16 -22
- package/test/integration/DhtNodeRpcRemote.test.ts +13 -22
- package/test/integration/DhtRpc.test.ts +13 -18
- package/test/integration/Find.test.ts +10 -10
- package/test/integration/Layer1-scale.test.ts +17 -28
- package/test/integration/Mock-Layer1-Layer0.test.ts +25 -43
- package/test/integration/MultipleEntryPointJoining.test.ts +7 -7
- package/test/integration/ReplicateData.test.ts +28 -30
- package/test/integration/RouteMessage.test.ts +30 -27
- package/test/integration/RouterRpcRemote.test.ts +12 -18
- package/test/integration/RpcErrors.test.ts +8 -21
- package/test/integration/ScaleDownDht.test.ts +11 -10
- package/test/integration/SimultaneousConnections.test.ts +43 -67
- package/test/integration/Store.test.ts +23 -36
- package/test/integration/StoreAndDelete.test.ts +30 -50
- package/test/integration/StoreOnDhtWithTwoNodes.test.ts +16 -37
- package/test/integration/StoreRpcRemote.test.ts +20 -30
- package/test/integration/WebrtcConnectionManagement.test.ts +3 -13
- package/test/integration/WebrtcConnectorRpc.test.ts +3 -9
- package/test/integration/WebsocketConnectionManagement.test.ts +7 -10
- package/test/integration/WebsocketConnectorRpc.test.ts +8 -17
- package/test/unit/ConnectivityHelpers.test.ts +9 -17
- package/test/unit/DuplicateDetector.test.ts +7 -4
- package/test/unit/LocalDataStore.test.ts +66 -77
- package/test/unit/PeerManager.test.ts +31 -0
- package/test/unit/RandomContactList.test.ts +13 -8
- package/test/unit/{Finder.test.ts → RecursiveOperationManager.test.ts} +38 -43
- package/test/unit/RecursiveOperationSession.test.ts +68 -0
- package/test/unit/Router.test.ts +15 -22
- package/test/unit/RoutingSession.test.ts +23 -25
- package/test/unit/SortedContactList.test.ts +41 -26
- package/test/unit/StoreManager.test.ts +132 -0
- package/test/unit/WebsocketConnector.test.ts +27 -35
- package/test/unit/customMatchers.test.ts +16 -0
- package/test/utils/FakeTransport.ts +44 -0
- package/test/utils/customMatchers.ts +70 -0
- package/test/utils/mock/MockRpcCommunicator.ts +7 -0
- package/test/utils/mock/Router.ts +3 -2
- package/test/utils/mock/mockDataEntry.ts +36 -0
- package/test/utils/utils.ts +49 -87
- package/dist/src/dht/find/FindRpcLocal.d.ts +0 -14
- package/dist/src/dht/find/FindRpcLocal.js.map +0 -1
- package/dist/src/dht/find/FindSession.d.ts +0 -44
- package/dist/src/dht/find/FindSession.js +0 -150
- package/dist/src/dht/find/FindSession.js.map +0 -1
- package/dist/src/dht/find/FindSessionRpcLocal.d.ts +0 -12
- package/dist/src/dht/find/FindSessionRpcLocal.js +0 -17
- package/dist/src/dht/find/FindSessionRpcLocal.js.map +0 -1
- package/dist/src/dht/find/FindSessionRpcRemote.d.ts +0 -6
- package/dist/src/dht/find/FindSessionRpcRemote.js +0 -21
- package/dist/src/dht/find/FindSessionRpcRemote.js.map +0 -1
- package/dist/src/dht/find/Finder.d.ts +0 -49
- package/dist/src/dht/find/Finder.js +0 -197
- package/dist/src/dht/find/Finder.js.map +0 -1
- package/dist/src/dht/routing/FindRpcRemote.d.ts +0 -6
- package/dist/src/dht/routing/FindRpcRemote.js.map +0 -1
- package/src/dht/find/FindSession.ts +0 -183
- package/src/dht/find/FindSessionRpcLocal.ts +0 -25
- package/src/dht/find/Finder.ts +0 -295
package/src/dht/DhtNode.ts
CHANGED
|
@@ -17,11 +17,11 @@ import {
|
|
|
17
17
|
ExternalFindDataResponse,
|
|
18
18
|
ExternalStoreDataRequest,
|
|
19
19
|
ExternalStoreDataResponse,
|
|
20
|
-
|
|
20
|
+
RecursiveOperation,
|
|
21
21
|
} from '../proto/packages/dht/protos/DhtRpc'
|
|
22
22
|
import { ITransport, TransportEvents } from '../transport/ITransport'
|
|
23
23
|
import { ConnectionManager, PortRange, TlsCertificate } from '../connection/ConnectionManager'
|
|
24
|
-
import {
|
|
24
|
+
import { ExternalApiRpcClient, StoreRpcClient } from '../proto/packages/dht/protos/DhtRpc.client'
|
|
25
25
|
import {
|
|
26
26
|
Logger,
|
|
27
27
|
MetricsContext,
|
|
@@ -29,16 +29,13 @@ import {
|
|
|
29
29
|
merge,
|
|
30
30
|
waitForCondition
|
|
31
31
|
} from '@streamr/utils'
|
|
32
|
-
import { toProtoRpcClient } from '@streamr/proto-rpc'
|
|
33
32
|
import { Any } from '../proto/google/protobuf/any'
|
|
34
33
|
import {
|
|
35
|
-
|
|
36
|
-
getNodeIdFromPeerDescriptor,
|
|
37
|
-
peerIdFromPeerDescriptor
|
|
34
|
+
getNodeIdFromPeerDescriptor
|
|
38
35
|
} from '../helpers/peerIdFromPeerDescriptor'
|
|
39
36
|
import { Router } from './routing/Router'
|
|
40
|
-
import {
|
|
41
|
-
import {
|
|
37
|
+
import { RecursiveOperationManager, RecursiveOperationResult } from './recursive-operation/RecursiveOperationManager'
|
|
38
|
+
import { StoreManager } from './store/StoreManager'
|
|
42
39
|
import { PeerDiscovery } from './discovery/PeerDiscovery'
|
|
43
40
|
import { LocalDataStore } from './store/LocalDataStore'
|
|
44
41
|
import { IceServer } from '../connection/webrtc/WebrtcConnector'
|
|
@@ -51,18 +48,20 @@ import { MarkRequired } from 'ts-essentials'
|
|
|
51
48
|
import { DhtNodeRpcLocal } from './DhtNodeRpcLocal'
|
|
52
49
|
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
53
50
|
import { ExternalApiRpcLocal } from './ExternalApiRpcLocal'
|
|
54
|
-
import { PeerManager
|
|
51
|
+
import { PeerManager } from './PeerManager'
|
|
52
|
+
import { ServiceID } from '../types/ServiceID'
|
|
53
|
+
import { NodeID, getNodeIdFromBinary } from '../helpers/nodeId'
|
|
54
|
+
import { StoreRpcRemote } from './store/StoreRpcRemote'
|
|
55
55
|
|
|
56
56
|
export interface DhtNodeEvents {
|
|
57
57
|
newContact: (peerDescriptor: PeerDescriptor, closestPeers: PeerDescriptor[]) => void
|
|
58
58
|
contactRemoved: (peerDescriptor: PeerDescriptor, closestPeers: PeerDescriptor[]) => void
|
|
59
|
-
joinCompleted: () => void
|
|
60
59
|
newRandomContact: (peerDescriptor: PeerDescriptor, closestPeers: PeerDescriptor[]) => void
|
|
61
60
|
randomContactRemoved: (peerDescriptor: PeerDescriptor, closestPeers: PeerDescriptor[]) => void
|
|
62
61
|
}
|
|
63
62
|
|
|
64
63
|
export interface DhtNodeOptions {
|
|
65
|
-
serviceId?:
|
|
64
|
+
serviceId?: ServiceID
|
|
66
65
|
joinParallelism?: number
|
|
67
66
|
maxNeighborListSize?: number
|
|
68
67
|
numberOfNodesPerKBucket?: number
|
|
@@ -140,16 +139,14 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
140
139
|
private transport?: ITransport
|
|
141
140
|
private localPeerDescriptor?: PeerDescriptor
|
|
142
141
|
public router?: Router
|
|
143
|
-
private
|
|
144
|
-
private localDataStore
|
|
145
|
-
private
|
|
142
|
+
private storeManager?: StoreManager
|
|
143
|
+
private localDataStore: LocalDataStore
|
|
144
|
+
private recursiveOperationManager?: RecursiveOperationManager
|
|
146
145
|
private peerDiscovery?: PeerDiscovery
|
|
147
146
|
private peerManager?: PeerManager
|
|
148
|
-
|
|
149
147
|
public connectionManager?: ConnectionManager
|
|
150
148
|
private started = false
|
|
151
149
|
private abortController = new AbortController()
|
|
152
|
-
private entryPointDisconnectTimeout?: NodeJS.Timeout
|
|
153
150
|
|
|
154
151
|
constructor(conf: DhtNodeOptions) {
|
|
155
152
|
super()
|
|
@@ -169,6 +166,7 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
169
166
|
metricsContext: new MetricsContext(),
|
|
170
167
|
peerId: new UUID().toHex()
|
|
171
168
|
}, conf)
|
|
169
|
+
this.localDataStore = new LocalDataStore(this.config.storeMaxTtl)
|
|
172
170
|
this.send = this.send.bind(this)
|
|
173
171
|
}
|
|
174
172
|
|
|
@@ -258,10 +256,9 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
258
256
|
connections: this.peerManager!.connections,
|
|
259
257
|
localPeerDescriptor: this.localPeerDescriptor!,
|
|
260
258
|
addContact: (contact: PeerDescriptor, setActive?: boolean) => this.peerManager!.handleNewPeers([contact], setActive),
|
|
261
|
-
serviceId: this.config.serviceId,
|
|
262
259
|
connectionManager: this.connectionManager
|
|
263
260
|
})
|
|
264
|
-
this.
|
|
261
|
+
this.recursiveOperationManager = new RecursiveOperationManager({
|
|
265
262
|
rpcCommunicator: this.rpcCommunicator,
|
|
266
263
|
router: this.router,
|
|
267
264
|
sessionTransport: this,
|
|
@@ -269,36 +266,41 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
269
266
|
localPeerDescriptor: this.localPeerDescriptor!,
|
|
270
267
|
serviceId: this.config.serviceId,
|
|
271
268
|
addContact: (contact: PeerDescriptor) => this.peerManager!.handleNewPeers([contact]),
|
|
272
|
-
isPeerCloserToIdThanSelf: this.isPeerCloserToIdThanSelf.bind(this),
|
|
273
269
|
localDataStore: this.localDataStore
|
|
274
270
|
})
|
|
275
|
-
this.
|
|
271
|
+
this.storeManager = new StoreManager({
|
|
276
272
|
rpcCommunicator: this.rpcCommunicator,
|
|
277
|
-
|
|
273
|
+
recursiveOperationManager: this.recursiveOperationManager,
|
|
278
274
|
localPeerDescriptor: this.localPeerDescriptor!,
|
|
279
275
|
serviceId: this.config.serviceId,
|
|
280
276
|
highestTtl: this.config.storeHighestTtl,
|
|
281
|
-
maxTtl: this.config.storeMaxTtl,
|
|
282
277
|
redundancyFactor: this.config.storageRedundancyFactor,
|
|
283
278
|
localDataStore: this.localDataStore,
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
return this.peerManager!.getClosestNeighborsTo(id, n)
|
|
279
|
+
getClosestNeighborsTo: (id: Uint8Array, n?: number) => {
|
|
280
|
+
return this.peerManager!.getClosestNeighborsTo(getNodeIdFromBinary(id), n).map((n) => n.getPeerDescriptor())
|
|
287
281
|
},
|
|
288
|
-
|
|
282
|
+
createRpcRemote: (contact: PeerDescriptor) => {
|
|
283
|
+
return new StoreRpcRemote(
|
|
284
|
+
this.localPeerDescriptor!,
|
|
285
|
+
contact,
|
|
286
|
+
this.config.serviceId,
|
|
287
|
+
this.rpcCommunicator!,
|
|
288
|
+
StoreRpcClient,
|
|
289
|
+
this.config.rpcRequestTimeout
|
|
290
|
+
)
|
|
291
|
+
}
|
|
292
|
+
})
|
|
293
|
+
this.on('newContact', (peerDescriptor: PeerDescriptor) => {
|
|
294
|
+
this.storeManager!.onNewContact(peerDescriptor)
|
|
289
295
|
})
|
|
290
296
|
this.bindRpcLocalMethods()
|
|
291
|
-
if ((this.connectionManager !== undefined) && (this.config.entryPoints !== undefined) && this.config.entryPoints.length > 0
|
|
292
|
-
&& !areEqualPeerDescriptors(this.config.entryPoints[0], this.localPeerDescriptor!)) {
|
|
293
|
-
this.connectToEntryPoint(this.config.entryPoints[0])
|
|
294
|
-
}
|
|
295
297
|
}
|
|
296
298
|
|
|
297
299
|
private initPeerManager() {
|
|
298
300
|
this.peerManager = new PeerManager({
|
|
299
301
|
numberOfNodesPerKBucket: this.config.numberOfNodesPerKBucket,
|
|
300
302
|
maxContactListSize: this.config.maxNeighborListSize,
|
|
301
|
-
|
|
303
|
+
localNodeId: this.getNodeId(),
|
|
302
304
|
connectionManager: this.connectionManager!,
|
|
303
305
|
peerDiscoveryQueryBatchSize: this.config.peerDiscoveryQueryBatchSize,
|
|
304
306
|
isLayer0: (this.connectionManager !== undefined),
|
|
@@ -347,10 +349,9 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
347
349
|
return
|
|
348
350
|
}
|
|
349
351
|
const dhtNodeRpcLocal = new DhtNodeRpcLocal({
|
|
350
|
-
serviceId: this.config.serviceId,
|
|
351
352
|
peerDiscoveryQueryBatchSize: this.config.peerDiscoveryQueryBatchSize,
|
|
352
353
|
getClosestPeersTo: (kademliaId: Uint8Array, limit: number) => {
|
|
353
|
-
return this.peerManager!.getClosestNeighborsTo(kademliaId, limit)
|
|
354
|
+
return this.peerManager!.getClosestNeighborsTo(getNodeIdFromBinary(kademliaId), limit)
|
|
354
355
|
.map((dhtPeer: DhtNodeRpcRemote) => dhtPeer.getPeerDescriptor())
|
|
355
356
|
},
|
|
356
357
|
addNewContact: (contact: PeerDescriptor) => this.peerManager!.handleNewPeers([contact]),
|
|
@@ -363,33 +364,27 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
363
364
|
this.rpcCommunicator!.registerRpcNotification(LeaveNotice, 'leaveNotice',
|
|
364
365
|
(req: LeaveNotice, context) => dhtNodeRpcLocal.leaveNotice(req, context))
|
|
365
366
|
const externalApiRpcLocal = new ExternalApiRpcLocal({
|
|
366
|
-
|
|
367
|
-
return this.
|
|
367
|
+
executeRecursiveOperation: (key: Uint8Array, operation: RecursiveOperation, excludedPeer: PeerDescriptor) => {
|
|
368
|
+
return this.executeRecursiveOperation(key, operation, excludedPeer)
|
|
368
369
|
},
|
|
369
|
-
storeDataToDht: (key: Uint8Array, data: Any, creator?:
|
|
370
|
+
storeDataToDht: (key: Uint8Array, data: Any, creator?: NodeID) => this.storeDataToDht(key, data, creator)
|
|
370
371
|
})
|
|
371
372
|
this.rpcCommunicator!.registerRpcMethod(
|
|
372
373
|
ExternalFindDataRequest,
|
|
373
374
|
ExternalFindDataResponse,
|
|
374
375
|
'externalFindData',
|
|
375
376
|
(req: ExternalFindDataRequest, context: ServerCallContext) => externalApiRpcLocal.externalFindData(req, context),
|
|
376
|
-
{ timeout: 10000 }
|
|
377
|
+
{ timeout: 10000 } // TODO use config option or named constant?
|
|
377
378
|
)
|
|
378
379
|
this.rpcCommunicator!.registerRpcMethod(
|
|
379
380
|
ExternalStoreDataRequest,
|
|
380
381
|
ExternalStoreDataResponse,
|
|
381
382
|
'externalStoreData',
|
|
382
383
|
(req: ExternalStoreDataRequest, context: ServerCallContext) => externalApiRpcLocal.externalStoreData(req, context),
|
|
383
|
-
{ timeout: 10000 }
|
|
384
|
+
{ timeout: 10000 } // TODO use config option or named constant?
|
|
384
385
|
)
|
|
385
386
|
}
|
|
386
387
|
|
|
387
|
-
private isPeerCloserToIdThanSelf(peer1: PeerDescriptor, compareToId: PeerID): boolean {
|
|
388
|
-
const distance1 = getDistance(peer1.nodeId, compareToId.value)
|
|
389
|
-
const distance2 = getDistance(this.localPeerDescriptor!.nodeId, compareToId.value)
|
|
390
|
-
return distance1 < distance2
|
|
391
|
-
}
|
|
392
|
-
|
|
393
388
|
private handleMessage(message: Message): void {
|
|
394
389
|
if (message.serviceId === this.config.serviceId) {
|
|
395
390
|
logger.trace('callig this.handleMessageFromPeer ' + getNodeIdFromPeerDescriptor(message.sourceDescriptor!)
|
|
@@ -412,24 +407,20 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
412
407
|
}
|
|
413
408
|
|
|
414
409
|
public getClosestContacts(limit?: number): PeerDescriptor[] {
|
|
415
|
-
return this.peerManager!.getClosestContactsTo(
|
|
410
|
+
return this.peerManager!.getClosestContactsTo(
|
|
411
|
+
getNodeIdFromPeerDescriptor(this.localPeerDescriptor!),
|
|
412
|
+
limit).map((peer) => peer.getPeerDescriptor()
|
|
413
|
+
)
|
|
416
414
|
}
|
|
417
415
|
|
|
418
|
-
public getNodeId():
|
|
419
|
-
return
|
|
416
|
+
public getNodeId(): NodeID {
|
|
417
|
+
return getNodeIdFromPeerDescriptor(this.localPeerDescriptor!)
|
|
420
418
|
}
|
|
421
419
|
|
|
422
420
|
public getNumberOfNeighbors(): number {
|
|
423
421
|
return this.peerManager!.getNumberOfNeighbors()
|
|
424
422
|
}
|
|
425
423
|
|
|
426
|
-
private connectToEntryPoint(entryPoint: PeerDescriptor): void {
|
|
427
|
-
this.connectionManager!.lockConnection(entryPoint, 'temporary-layer0-connection')
|
|
428
|
-
this.entryPointDisconnectTimeout = setTimeout(() => {
|
|
429
|
-
this.connectionManager!.unlockConnection(entryPoint, 'temporary-layer0-connection')
|
|
430
|
-
}, 10 * 1000)
|
|
431
|
-
}
|
|
432
|
-
|
|
433
424
|
public removeContact(contact: PeerDescriptor): void {
|
|
434
425
|
if (!this.started) { // the stopped state is checked in PeerManager
|
|
435
426
|
return
|
|
@@ -449,18 +440,26 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
449
440
|
if (!this.started) {
|
|
450
441
|
throw new Error('Cannot join DHT before calling start() on DhtNode')
|
|
451
442
|
}
|
|
452
|
-
await
|
|
443
|
+
await Promise.all(entryPointDescriptors.map((entryPoint) =>
|
|
444
|
+
this.peerDiscovery!.joinDht(entryPoint, doAdditionalRandomPeerDiscovery, retry)
|
|
445
|
+
))
|
|
453
446
|
}
|
|
454
447
|
|
|
455
|
-
|
|
456
|
-
|
|
448
|
+
// TODO make this private and unify the public API of find/fetch/store/delete methods
|
|
449
|
+
// (we already have storeDataToDht etc. here)
|
|
450
|
+
public async executeRecursiveOperation(
|
|
451
|
+
key: Uint8Array,
|
|
452
|
+
operation: RecursiveOperation,
|
|
453
|
+
excludedPeer?: PeerDescriptor
|
|
454
|
+
): Promise<RecursiveOperationResult> {
|
|
455
|
+
return this.recursiveOperationManager!.execute(key, operation, excludedPeer)
|
|
457
456
|
}
|
|
458
457
|
|
|
459
|
-
public async storeDataToDht(key: Uint8Array, data: Any, creator?:
|
|
458
|
+
public async storeDataToDht(key: Uint8Array, data: Any, creator?: NodeID): Promise<PeerDescriptor[]> {
|
|
460
459
|
if (this.peerDiscovery!.isJoinOngoing() && this.config.entryPoints && this.config.entryPoints.length > 0) {
|
|
461
460
|
return this.storeDataViaPeer(key, data, sample(this.config.entryPoints)!)
|
|
462
461
|
}
|
|
463
|
-
return this.
|
|
462
|
+
return this.storeManager!.storeDataToDht(key, data, creator ?? getNodeIdFromPeerDescriptor(this.localPeerDescriptor!))
|
|
464
463
|
}
|
|
465
464
|
|
|
466
465
|
public async storeDataViaPeer(key: Uint8Array, data: Any, peer: PeerDescriptor): Promise<PeerDescriptor[]> {
|
|
@@ -468,7 +467,8 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
468
467
|
this.localPeerDescriptor!,
|
|
469
468
|
peer,
|
|
470
469
|
this.config.serviceId,
|
|
471
|
-
|
|
470
|
+
this.rpcCommunicator!,
|
|
471
|
+
ExternalApiRpcClient
|
|
472
472
|
)
|
|
473
473
|
return await rpcRemote.storeData(key, data)
|
|
474
474
|
}
|
|
@@ -477,13 +477,13 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
477
477
|
if (this.peerDiscovery!.isJoinOngoing() && this.config.entryPoints && this.config.entryPoints.length > 0) {
|
|
478
478
|
return this.findDataViaPeer(key, sample(this.config.entryPoints)!)
|
|
479
479
|
}
|
|
480
|
-
const result = await this.
|
|
480
|
+
const result = await this.recursiveOperationManager!.execute(key, RecursiveOperation.FETCH_DATA)
|
|
481
481
|
return result.dataEntries ?? [] // TODO is this fallback needed?
|
|
482
482
|
}
|
|
483
483
|
|
|
484
484
|
public async deleteDataFromDht(key: Uint8Array, waitForCompletion: boolean): Promise<void> {
|
|
485
485
|
if (!this.abortController.signal.aborted) {
|
|
486
|
-
await this.
|
|
486
|
+
await this.recursiveOperationManager!.execute(key, RecursiveOperation.DELETE_DATA, undefined, waitForCompletion)
|
|
487
487
|
}
|
|
488
488
|
}
|
|
489
489
|
|
|
@@ -492,7 +492,8 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
492
492
|
this.localPeerDescriptor!,
|
|
493
493
|
peer,
|
|
494
494
|
this.config.serviceId,
|
|
495
|
-
|
|
495
|
+
this.rpcCommunicator!,
|
|
496
|
+
ExternalApiRpcClient
|
|
496
497
|
)
|
|
497
498
|
return await rpcRemote.externalFindData(key)
|
|
498
499
|
}
|
|
@@ -550,15 +551,12 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
550
551
|
}
|
|
551
552
|
logger.trace('stop()')
|
|
552
553
|
this.abortController.abort()
|
|
553
|
-
await this.
|
|
554
|
-
if (this.entryPointDisconnectTimeout) {
|
|
555
|
-
clearTimeout(this.entryPointDisconnectTimeout)
|
|
556
|
-
}
|
|
554
|
+
await this.storeManager!.destroy()
|
|
557
555
|
this.localDataStore.clear()
|
|
558
556
|
this.peerManager?.stop()
|
|
559
557
|
this.rpcCommunicator!.stop()
|
|
560
558
|
this.router!.stop()
|
|
561
|
-
this.
|
|
559
|
+
this.recursiveOperationManager!.stop()
|
|
562
560
|
this.peerDiscovery!.stop()
|
|
563
561
|
if (this.config.transport === undefined) {
|
|
564
562
|
// if the transport was not given in config, the instance was created in start() and
|
|
@@ -574,8 +572,8 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
574
572
|
return new DhtNodeRpcRemote(
|
|
575
573
|
this.localPeerDescriptor!,
|
|
576
574
|
peerDescriptor,
|
|
577
|
-
toProtoRpcClient(new DhtNodeRpcClient(this.rpcCommunicator!.getRpcClientTransport())),
|
|
578
575
|
this.config.serviceId,
|
|
576
|
+
this.rpcCommunicator!,
|
|
579
577
|
this.config.rpcRequestTimeout
|
|
580
578
|
)
|
|
581
579
|
}
|
|
@@ -14,7 +14,6 @@ import { IDhtNodeRpc } from '../proto/packages/dht/protos/DhtRpc.server'
|
|
|
14
14
|
import { DhtCallContext } from '../rpc-protocol/DhtCallContext'
|
|
15
15
|
|
|
16
16
|
interface DhtNodeRpcLocalConfig {
|
|
17
|
-
serviceId: string
|
|
18
17
|
peerDiscoveryQueryBatchSize: number
|
|
19
18
|
getClosestPeersTo: (nodeId: Uint8Array, limit: number) => PeerDescriptor[]
|
|
20
19
|
addNewContact: (contact: PeerDescriptor) => void
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RpcCommunicator } from '@streamr/proto-rpc'
|
|
2
|
+
import { Logger } from '@streamr/utils'
|
|
3
|
+
import { v4 } from 'uuid'
|
|
4
|
+
import { NodeID } from '../helpers/nodeId'
|
|
5
|
+
import { getNodeIdFromPeerDescriptor } from '../helpers/peerIdFromPeerDescriptor'
|
|
2
6
|
import {
|
|
3
7
|
ClosestPeersRequest,
|
|
4
8
|
LeaveNotice,
|
|
5
9
|
PeerDescriptor,
|
|
6
10
|
PingRequest
|
|
7
11
|
} from '../proto/packages/dht/protos/DhtRpc'
|
|
8
|
-
import {
|
|
9
|
-
import { Logger } from '@streamr/utils'
|
|
10
|
-
import { ProtoRpcClient } from '@streamr/proto-rpc'
|
|
11
|
-
import { RpcRemote } from './contact/RpcRemote'
|
|
12
|
-
import { PeerID } from '../helpers/PeerID'
|
|
13
|
-
import { getNodeIdFromPeerDescriptor, peerIdFromPeerDescriptor } from '../helpers/peerIdFromPeerDescriptor'
|
|
12
|
+
import { DhtNodeRpcClient } from '../proto/packages/dht/protos/DhtRpc.client'
|
|
14
13
|
import { ServiceID } from '../types/ServiceID'
|
|
14
|
+
import { RpcRemote } from './contact/RpcRemote'
|
|
15
15
|
|
|
16
16
|
const logger = new Logger(module)
|
|
17
17
|
|
|
@@ -21,7 +21,7 @@ export interface KBucketContact {
|
|
|
21
21
|
vectorClock: number
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
export class DhtNodeRpcRemote extends RpcRemote<
|
|
24
|
+
export class DhtNodeRpcRemote extends RpcRemote<DhtNodeRpcClient> implements KBucketContact {
|
|
25
25
|
|
|
26
26
|
private static counter = 0
|
|
27
27
|
public vectorClock: number
|
|
@@ -30,12 +30,12 @@ export class DhtNodeRpcRemote extends RpcRemote<IDhtNodeRpcClient> implements KB
|
|
|
30
30
|
constructor(
|
|
31
31
|
localPeerDescriptor: PeerDescriptor,
|
|
32
32
|
peerDescriptor: PeerDescriptor,
|
|
33
|
-
client: ProtoRpcClient<IDhtNodeRpcClient>,
|
|
34
33
|
serviceId: ServiceID,
|
|
34
|
+
rpcCommunicator: RpcCommunicator,
|
|
35
35
|
rpcRequestTimeout?: number
|
|
36
36
|
) {
|
|
37
|
-
super(localPeerDescriptor, peerDescriptor, serviceId,
|
|
38
|
-
this.id = this.
|
|
37
|
+
super(localPeerDescriptor, peerDescriptor, serviceId, rpcCommunicator, DhtNodeRpcClient, rpcRequestTimeout)
|
|
38
|
+
this.id = this.getPeerDescriptor().nodeId
|
|
39
39
|
this.vectorClock = DhtNodeRpcRemote.counter++
|
|
40
40
|
}
|
|
41
41
|
|
|
@@ -84,7 +84,7 @@ export class DhtNodeRpcRemote extends RpcRemote<IDhtNodeRpcClient> implements KB
|
|
|
84
84
|
})
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
|
|
88
|
-
return
|
|
87
|
+
getNodeId(): NodeID {
|
|
88
|
+
return getNodeIdFromPeerDescriptor(this.getPeerDescriptor())
|
|
89
89
|
}
|
|
90
90
|
}
|
|
@@ -4,17 +4,27 @@ import {
|
|
|
4
4
|
ExternalFindDataResponse,
|
|
5
5
|
ExternalStoreDataRequest,
|
|
6
6
|
ExternalStoreDataResponse,
|
|
7
|
-
|
|
7
|
+
RecursiveOperation,
|
|
8
8
|
PeerDescriptor
|
|
9
9
|
} from '../proto/packages/dht/protos/DhtRpc'
|
|
10
10
|
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
11
11
|
import { DhtCallContext } from '../rpc-protocol/DhtCallContext'
|
|
12
|
-
import {
|
|
12
|
+
import { RecursiveOperationResult } from './recursive-operation/RecursiveOperationManager'
|
|
13
13
|
import { Any } from '../proto/google/protobuf/any'
|
|
14
|
+
import { NodeID } from '../helpers/nodeId'
|
|
15
|
+
import { getNodeIdFromPeerDescriptor } from '../helpers/peerIdFromPeerDescriptor'
|
|
14
16
|
|
|
15
17
|
interface ExternalApiRpcLocalConfig {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
executeRecursiveOperation: (
|
|
19
|
+
targetId: Uint8Array,
|
|
20
|
+
operation: RecursiveOperation,
|
|
21
|
+
excludedPeer: PeerDescriptor
|
|
22
|
+
) => Promise<RecursiveOperationResult>
|
|
23
|
+
storeDataToDht: (
|
|
24
|
+
key: Uint8Array,
|
|
25
|
+
data: Any,
|
|
26
|
+
creator: NodeID
|
|
27
|
+
) => Promise<PeerDescriptor[]>
|
|
18
28
|
}
|
|
19
29
|
|
|
20
30
|
export class ExternalApiRpcLocal implements IExternalApiRpc {
|
|
@@ -27,13 +37,13 @@ export class ExternalApiRpcLocal implements IExternalApiRpc {
|
|
|
27
37
|
|
|
28
38
|
async externalFindData(findDataRequest: ExternalFindDataRequest, context: ServerCallContext): Promise<ExternalFindDataResponse> {
|
|
29
39
|
const senderPeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
|
|
30
|
-
const result = await this.config.
|
|
40
|
+
const result = await this.config.executeRecursiveOperation(findDataRequest.key, RecursiveOperation.FETCH_DATA, senderPeerDescriptor)
|
|
31
41
|
return ExternalFindDataResponse.create({ entries: result.dataEntries ?? [] })
|
|
32
42
|
}
|
|
33
43
|
|
|
34
44
|
async externalStoreData(request: ExternalStoreDataRequest, context: ServerCallContext): Promise<ExternalStoreDataResponse> {
|
|
35
45
|
const senderPeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
|
|
36
|
-
const result = await this.config.storeDataToDht(request.key, request.data!, senderPeerDescriptor)
|
|
46
|
+
const result = await this.config.storeDataToDht(request.key, request.data!, getNodeIdFromPeerDescriptor(senderPeerDescriptor))
|
|
37
47
|
return ExternalStoreDataResponse.create({
|
|
38
48
|
storers: result
|
|
39
49
|
})
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { Any } from '../proto/google/protobuf/any'
|
|
2
|
-
import { DataEntry,
|
|
3
|
-
import {
|
|
2
|
+
import { DataEntry, ExternalFindDataRequest, ExternalStoreDataRequest, PeerDescriptor } from '../proto/packages/dht/protos/DhtRpc'
|
|
3
|
+
import { ExternalApiRpcClient } from '../proto/packages/dht/protos/DhtRpc.client'
|
|
4
4
|
import { RpcRemote } from './contact/RpcRemote'
|
|
5
5
|
|
|
6
|
-
export class ExternalApiRpcRemote extends RpcRemote<
|
|
6
|
+
export class ExternalApiRpcRemote extends RpcRemote<ExternalApiRpcClient> {
|
|
7
7
|
|
|
8
8
|
async externalFindData(key: Uint8Array): Promise<DataEntry[]> {
|
|
9
9
|
const request: ExternalFindDataRequest = {
|
|
10
10
|
key
|
|
11
11
|
}
|
|
12
12
|
const options = this.formDhtRpcOptions({
|
|
13
|
+
// TODO use config option or named constant?
|
|
13
14
|
timeout: 10000
|
|
14
15
|
})
|
|
15
16
|
try {
|
|
@@ -26,6 +27,7 @@ export class ExternalApiRpcRemote extends RpcRemote<IExternalApiRpcClient> {
|
|
|
26
27
|
data
|
|
27
28
|
}
|
|
28
29
|
const options = this.formDhtRpcOptions({
|
|
30
|
+
// TODO use config option or named constant?
|
|
29
31
|
timeout: 10000
|
|
30
32
|
})
|
|
31
33
|
try {
|