@streamr/dht 100.0.0-pretestnet.4 → 100.0.0-rc.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/README.md +90 -8
- package/dist/package.json +70 -0
- package/dist/src/connection/Connection.d.ts +1 -0
- package/dist/src/connection/Connection.js +10 -3
- package/dist/src/connection/Connection.js.map +1 -1
- package/dist/src/connection/ConnectionLockHandler.d.ts +14 -14
- package/dist/src/connection/ConnectionLockHandler.js +22 -16
- package/dist/src/connection/ConnectionLockHandler.js.map +1 -1
- package/dist/src/connection/ConnectionLockRpcLocal.d.ts +3 -3
- package/dist/src/connection/ConnectionLockRpcLocal.js +7 -6
- package/dist/src/connection/ConnectionLockRpcLocal.js.map +1 -1
- package/dist/src/connection/ConnectionLockRpcRemote.d.ts +4 -6
- package/dist/src/connection/ConnectionLockRpcRemote.js +10 -37
- package/dist/src/connection/ConnectionLockRpcRemote.js.map +1 -1
- package/dist/src/connection/ConnectionManager.d.ts +19 -20
- package/dist/src/connection/ConnectionManager.js +132 -117
- package/dist/src/connection/ConnectionManager.js.map +1 -1
- package/dist/src/connection/ConnectorFacade.d.ts +3 -2
- package/dist/src/connection/ConnectorFacade.js +10 -3
- package/dist/src/connection/ConnectorFacade.js.map +1 -1
- package/dist/src/connection/Handshaker.d.ts +3 -1
- package/dist/src/connection/Handshaker.js +18 -9
- package/dist/src/connection/Handshaker.js.map +1 -1
- package/dist/src/connection/IConnection.d.ts +2 -7
- package/dist/src/connection/IConnection.js +1 -8
- package/dist/src/connection/IConnection.js.map +1 -1
- package/dist/src/connection/ManagedConnection.d.ts +5 -7
- package/dist/src/connection/ManagedConnection.js +42 -26
- package/dist/src/connection/ManagedConnection.js.map +1 -1
- package/dist/src/connection/ManagedWebrtcConnection.js.map +1 -1
- package/dist/src/connection/connectivityChecker.d.ts +9 -0
- package/dist/src/connection/connectivityChecker.js +130 -0
- package/dist/src/connection/connectivityChecker.js.map +1 -0
- package/dist/src/connection/connectivityRequestHandler.d.ts +3 -0
- package/dist/src/connection/connectivityRequestHandler.js +101 -0
- package/dist/src/connection/connectivityRequestHandler.js.map +1 -0
- package/dist/src/connection/simulator/Simulator.d.ts +0 -3
- package/dist/src/connection/simulator/Simulator.js +34 -69
- package/dist/src/connection/simulator/Simulator.js.map +1 -1
- package/dist/src/connection/simulator/SimulatorConnection.js +27 -25
- package/dist/src/connection/simulator/SimulatorConnection.js.map +1 -1
- package/dist/src/connection/simulator/SimulatorConnector.js +16 -12
- package/dist/src/connection/simulator/SimulatorConnector.js.map +1 -1
- package/dist/src/connection/simulator/pings.js.map +1 -1
- package/dist/src/connection/webrtc/NodeWebrtcConnection.d.ts +2 -3
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js +40 -27
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnector.d.ts +0 -2
- package/dist/src/connection/webrtc/WebrtcConnector.js +24 -25
- 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 +27 -20
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.d.ts +3 -6
- package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.js +2 -5
- package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.js.map +1 -1
- package/dist/src/connection/webrtc/iceServerAsString.js +1 -1
- package/dist/src/connection/webrtc/iceServerAsString.js.map +1 -1
- package/dist/src/connection/websocket/AutoCertifierClientFacade.d.ts +1 -2
- package/dist/src/connection/websocket/AutoCertifierClientFacade.js +6 -4
- package/dist/src/connection/websocket/AutoCertifierClientFacade.js.map +1 -1
- package/dist/src/connection/websocket/ClientWebsocket.d.ts +1 -0
- package/dist/src/connection/websocket/ClientWebsocket.js +14 -7
- package/dist/src/connection/websocket/ClientWebsocket.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnector.d.ts +3 -9
- package/dist/src/connection/websocket/WebsocketConnector.js +142 -74
- package/dist/src/connection/websocket/WebsocketConnector.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.d.ts +5 -3
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.js +9 -12
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.d.ts +4 -7
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.js +7 -44
- 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 +49 -40
- package/dist/src/connection/websocket/WebsocketServer.js.map +1 -1
- package/dist/src/connection/websocket/{ServerWebsocket.d.ts → WebsocketServerConnection.d.ts} +8 -4
- package/dist/src/connection/websocket/WebsocketServerConnection.js +97 -0
- package/dist/src/connection/websocket/WebsocketServerConnection.js.map +1 -0
- package/dist/src/dht/DhtNode.d.ts +45 -49
- package/dist/src/dht/DhtNode.js +229 -317
- package/dist/src/dht/DhtNode.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcLocal.d.ts +10 -9
- package/dist/src/dht/DhtNodeRpcLocal.js +19 -11
- package/dist/src/dht/DhtNodeRpcLocal.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcRemote.d.ts +15 -10
- package/dist/src/dht/DhtNodeRpcRemote.js +38 -21
- package/dist/src/dht/DhtNodeRpcRemote.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcLocal.d.ts +7 -6
- package/dist/src/dht/ExternalApiRpcLocal.js +9 -13
- package/dist/src/dht/ExternalApiRpcLocal.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcRemote.d.ts +6 -5
- package/dist/src/dht/ExternalApiRpcRemote.js +10 -7
- package/dist/src/dht/ExternalApiRpcRemote.js.map +1 -1
- package/dist/src/dht/PeerManager.d.ts +61 -0
- package/dist/src/dht/PeerManager.js +288 -0
- package/dist/src/dht/PeerManager.js.map +1 -0
- package/dist/src/dht/contact/Contact.d.ts +2 -2
- package/dist/src/dht/contact/Contact.js +4 -3
- package/dist/src/dht/contact/Contact.js.map +1 -1
- package/dist/src/dht/contact/ContactList.d.ts +8 -8
- package/dist/src/dht/contact/ContactList.js +12 -7
- 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 +13 -12
- package/dist/src/dht/contact/RandomContactList.js.map +1 -1
- package/dist/src/dht/contact/RingContactList.d.ts +31 -0
- package/dist/src/dht/contact/RingContactList.js +133 -0
- package/dist/src/dht/contact/RingContactList.js.map +1 -0
- package/dist/src/dht/contact/{Remote.d.ts → RpcRemote.d.ts} +8 -7
- package/dist/src/dht/contact/{Remote.js → RpcRemote.js} +16 -13
- package/dist/src/dht/contact/RpcRemote.js.map +1 -0
- package/dist/src/dht/contact/SortedContactList.d.ts +29 -15
- package/dist/src/dht/contact/SortedContactList.js +79 -42
- package/dist/src/dht/contact/SortedContactList.js.map +1 -1
- package/dist/src/dht/contact/ringIdentifiers.d.ts +16 -0
- package/dist/src/dht/contact/ringIdentifiers.js +54 -0
- package/dist/src/dht/contact/ringIdentifiers.js.map +1 -0
- package/dist/src/dht/discovery/DiscoverySession.d.ts +8 -18
- package/dist/src/dht/discovery/DiscoverySession.js +32 -48
- package/dist/src/dht/discovery/DiscoverySession.js.map +1 -1
- package/dist/src/dht/discovery/PeerDiscovery.d.ts +16 -12
- package/dist/src/dht/discovery/PeerDiscovery.js +82 -39
- package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -1
- package/dist/src/dht/discovery/RingDiscoverySession.d.ts +29 -0
- package/dist/src/dht/discovery/RingDiscoverySession.js +123 -0
- package/dist/src/dht/discovery/RingDiscoverySession.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.d.ts +36 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.js +166 -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/recursive-operation/RecursiveOperationRpcLocal.js +26 -0
- 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/recursive-operation/RecursiveOperationRpcRemote.js +44 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.d.ts +44 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.js +187 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.d.ts +14 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js +20 -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/DuplicateDetector.d.ts +2 -4
- package/dist/src/dht/routing/DuplicateDetector.js +10 -15
- package/dist/src/dht/routing/DuplicateDetector.js.map +1 -1
- package/dist/src/dht/routing/Router.d.ts +11 -27
- package/dist/src/dht/routing/Router.js +92 -58
- package/dist/src/dht/routing/Router.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcLocal.d.ts +3 -4
- package/dist/src/dht/routing/RouterRpcLocal.js +17 -16
- package/dist/src/dht/routing/RouterRpcLocal.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcRemote.d.ts +3 -3
- package/dist/src/dht/routing/RouterRpcRemote.js +29 -20
- package/dist/src/dht/routing/RouterRpcRemote.js.map +1 -1
- package/dist/src/dht/routing/RoutingSession.d.ts +29 -21
- package/dist/src/dht/routing/RoutingSession.js +93 -68
- package/dist/src/dht/routing/RoutingSession.js.map +1 -1
- package/dist/src/dht/routing/RoutingTablesCache.d.ts +24 -0
- package/dist/src/dht/routing/RoutingTablesCache.js +46 -0
- package/dist/src/dht/routing/RoutingTablesCache.js.map +1 -0
- package/dist/src/dht/routing/getPreviousPeer.js.map +1 -1
- package/dist/src/dht/store/LocalDataStore.d.ts +9 -14
- package/dist/src/dht/store/LocalDataStore.js +46 -72
- 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 +182 -0
- package/dist/src/dht/store/StoreManager.js.map +1 -0
- package/dist/src/dht/store/StoreRpcLocal.d.ts +11 -41
- package/dist/src/dht/store/StoreRpcLocal.js +27 -234
- package/dist/src/dht/store/StoreRpcLocal.js.map +1 -1
- package/dist/src/dht/store/StoreRpcRemote.d.ts +6 -7
- package/dist/src/dht/store/StoreRpcRemote.js +10 -20
- package/dist/src/dht/store/StoreRpcRemote.js.map +1 -1
- package/dist/src/exports.d.ts +5 -3
- package/dist/src/exports.js +10 -8
- package/dist/src/exports.js.map +1 -1
- package/dist/src/helpers/AddressTools.js +2 -0
- package/dist/src/helpers/AddressTools.js.map +1 -1
- package/dist/src/helpers/Connectivity.js.map +1 -1
- package/dist/src/helpers/MapWithTtl.d.ts +14 -0
- package/dist/src/helpers/MapWithTtl.js +60 -0
- package/dist/src/helpers/MapWithTtl.js.map +1 -0
- package/dist/src/helpers/createPeerDescriptor.d.ts +3 -0
- package/dist/src/helpers/createPeerDescriptor.js +57 -0
- package/dist/src/helpers/createPeerDescriptor.js.map +1 -0
- package/dist/src/helpers/createPeerDescriptorSignaturePayload.d.ts +2 -0
- package/dist/src/helpers/createPeerDescriptorSignaturePayload.js +30 -0
- package/dist/src/helpers/createPeerDescriptorSignaturePayload.js.map +1 -0
- package/dist/src/helpers/debugHelpers.js.map +1 -1
- package/dist/src/helpers/errors.js +2 -0
- package/dist/src/helpers/errors.js.map +1 -1
- package/dist/src/helpers/offering.d.ts +4 -0
- package/dist/src/helpers/offering.js +18 -0
- package/dist/src/helpers/offering.js.map +1 -0
- package/dist/src/helpers/protoClasses.js +2 -3
- package/dist/src/helpers/protoClasses.js.map +1 -1
- package/dist/src/helpers/protoToString.js.map +1 -1
- package/dist/src/helpers/version.d.ts +6 -0
- package/dist/src/helpers/version.js +38 -0
- package/dist/src/helpers/version.js.map +1 -0
- package/dist/src/identifiers.d.ts +10 -0
- package/dist/src/identifiers.js +31 -0
- package/dist/src/identifiers.js.map +1 -0
- package/dist/src/proto/google/protobuf/any.js +8 -8
- package/dist/src/proto/google/protobuf/any.js.map +1 -1
- package/dist/src/proto/google/protobuf/empty.js +2 -4
- package/dist/src/proto/google/protobuf/empty.js.map +1 -1
- package/dist/src/proto/google/protobuf/timestamp.js +10 -10
- package/dist/src/proto/google/protobuf/timestamp.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +46 -49
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +63 -54
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +226 -232
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +146 -168
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +26 -29
- package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.js +1 -1
- package/dist/src/rpc-protocol/DhtCallContext.d.ts +2 -2
- package/dist/src/rpc-protocol/DhtCallContext.js +8 -0
- 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 +10 -2
- package/dist/src/transport/ITransport.js +5 -0
- package/dist/src/transport/ITransport.js.map +1 -1
- package/dist/src/transport/ListeningRpcCommunicator.js +3 -1
- package/dist/src/transport/ListeningRpcCommunicator.js.map +1 -1
- package/dist/src/transport/RoutingRpcCommunicator.d.ts +4 -2
- package/dist/src/transport/RoutingRpcCommunicator.js +19 -12
- 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 +13 -9
- package/package.json +16 -13
- package/protos/DhtRpc.proto +76 -76
- package/src/connection/Connection.ts +6 -1
- package/src/connection/ConnectionLockHandler.ts +30 -22
- package/src/connection/ConnectionLockRpcLocal.ts +7 -12
- package/src/connection/ConnectionLockRpcRemote.ts +9 -19
- package/src/connection/ConnectionManager.ts +132 -138
- package/src/connection/ConnectorFacade.ts +10 -9
- package/src/connection/Handshaker.ts +23 -11
- package/src/connection/IConnection.ts +2 -8
- package/src/connection/ManagedConnection.ts +34 -35
- package/src/connection/connectivityChecker.ts +109 -0
- package/src/connection/connectivityRequestHandler.ts +103 -0
- package/src/connection/simulator/Simulator.ts +6 -37
- package/src/connection/simulator/SimulatorConnection.ts +23 -25
- package/src/connection/simulator/SimulatorConnector.ts +11 -11
- package/src/connection/webrtc/BrowserWebrtcConnection.ts +17 -25
- package/src/connection/webrtc/NodeWebrtcConnection.ts +24 -26
- package/src/connection/webrtc/WebrtcConnector.ts +18 -29
- package/src/connection/webrtc/WebrtcConnectorRpcLocal.ts +29 -24
- package/src/connection/webrtc/WebrtcConnectorRpcRemote.ts +4 -14
- package/src/connection/webrtc/iceServerAsString.ts +1 -1
- package/src/connection/websocket/AutoCertifierClientFacade.ts +4 -6
- package/src/connection/websocket/ClientWebsocket.ts +10 -4
- package/src/connection/websocket/WebsocketConnector.ts +120 -97
- package/src/connection/websocket/WebsocketConnectorRpcLocal.ts +13 -15
- package/src/connection/websocket/WebsocketConnectorRpcRemote.ts +7 -27
- package/src/connection/websocket/WebsocketServer.ts +50 -53
- package/src/connection/websocket/WebsocketServerConnection.ts +104 -0
- package/src/dht/DhtNode.ts +289 -410
- package/src/dht/DhtNodeRpcLocal.ts +25 -17
- package/src/dht/DhtNodeRpcRemote.ts +43 -27
- package/src/dht/ExternalApiRpcLocal.ts +30 -17
- package/src/dht/ExternalApiRpcRemote.ts +14 -11
- package/src/dht/PeerManager.ts +339 -0
- package/src/dht/contact/Contact.ts +4 -4
- package/src/dht/contact/ContactList.ts +11 -10
- package/src/dht/contact/RandomContactList.ts +15 -15
- package/src/dht/contact/RingContactList.ts +151 -0
- package/src/dht/contact/{Remote.ts → RpcRemote.ts} +16 -19
- package/src/dht/contact/SortedContactList.ts +120 -72
- package/src/dht/contact/ringIdentifiers.ts +62 -0
- package/src/dht/discovery/DiscoverySession.ts +36 -61
- package/src/dht/discovery/PeerDiscovery.ts +98 -43
- package/src/dht/discovery/RingDiscoverySession.ts +160 -0
- package/src/dht/recursive-operation/RecursiveOperationManager.ts +246 -0
- package/src/dht/recursive-operation/RecursiveOperationRpcLocal.ts +34 -0
- package/src/dht/recursive-operation/RecursiveOperationRpcRemote.ts +43 -0
- package/src/dht/recursive-operation/RecursiveOperationSession.ts +232 -0
- package/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.ts +35 -0
- package/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.ts +30 -0
- package/src/dht/routing/DuplicateDetector.ts +9 -21
- package/src/dht/routing/Router.ts +95 -92
- package/src/dht/routing/RouterRpcLocal.ts +16 -18
- package/src/dht/routing/RouterRpcRemote.ts +26 -24
- package/src/dht/routing/RoutingSession.ts +119 -98
- package/src/dht/routing/RoutingTablesCache.ts +58 -0
- package/src/dht/routing/getPreviousPeer.ts +1 -1
- package/src/dht/store/LocalDataStore.ts +47 -77
- package/src/dht/store/StoreManager.ts +209 -0
- package/src/dht/store/StoreRpcLocal.ts +39 -308
- package/src/dht/store/StoreRpcRemote.ts +13 -31
- package/src/exports.ts +13 -3
- package/src/helpers/AddressTools.ts +2 -0
- package/src/helpers/MapWithTtl.ts +71 -0
- package/src/helpers/createPeerDescriptor.ts +57 -0
- package/src/helpers/createPeerDescriptorSignaturePayload.ts +28 -0
- package/src/helpers/offering.ts +15 -0
- package/src/helpers/protoClasses.ts +4 -6
- package/src/helpers/version.ts +32 -0
- package/src/identifiers.ts +29 -0
- package/src/proto/google/protobuf/any.ts +4 -4
- package/src/proto/google/protobuf/empty.ts +2 -4
- package/src/proto/google/protobuf/timestamp.ts +4 -4
- package/src/proto/packages/dht/protos/DhtRpc.client.ts +65 -68
- package/src/proto/packages/dht/protos/DhtRpc.server.ts +27 -30
- package/src/proto/packages/dht/protos/DhtRpc.ts +297 -313
- package/src/proto/packages/proto-rpc/protos/ProtoRpc.ts +1 -1
- package/src/rpc-protocol/DhtCallContext.ts +2 -2
- package/src/rpc-protocol/DhtRpcOptions.ts +2 -1
- package/src/transport/ITransport.ts +11 -2
- package/src/transport/ListeningRpcCommunicator.ts +1 -1
- package/src/transport/RoutingRpcCommunicator.ts +21 -14
- package/test/RandomGraphSimulation.ts +3 -2
- package/test/benchmark/Find.test.ts +13 -28
- package/test/benchmark/KademliaCorrectness.test.ts +24 -28
- package/test/benchmark/RingCorrectness.test.ts +157 -0
- package/test/benchmark/SortedContactListBenchmark.test.ts +151 -0
- package/test/benchmark/WebsocketServerMemoryLeak.test.ts +41 -0
- package/test/benchmark/hybrid-network-simulation/RingContactList.test.ts +72 -0
- package/test/benchmark/kademlia-simulation/Contact.ts +9 -9
- package/test/benchmark/kademlia-simulation/KademliaSimulation.ts +11 -11
- package/test/benchmark/kademlia-simulation/SimulationNode.ts +29 -25
- package/test/data/generateGroundTruthData.ts +7 -6
- package/test/end-to-end/Layer0-Layer1.test.ts +11 -15
- package/test/end-to-end/Layer0.test.ts +19 -22
- package/test/end-to-end/Layer0MixedConnectionTypes.test.ts +19 -21
- package/test/end-to-end/Layer0Webrtc-Layer1.test.ts +26 -28
- package/test/end-to-end/Layer0Webrtc.test.ts +19 -19
- package/test/end-to-end/Layer1-Scale-WebSocket.test.ts +10 -18
- package/test/end-to-end/Layer1-Scale-Webrtc.test.ts +8 -15
- package/test/end-to-end/RecoveryFromFailedAutoCertification.test.ts +2 -2
- package/test/end-to-end/WebsocketConnectionRequest.test.ts +8 -9
- package/test/end-to-end/memory-leak.test.ts +19 -24
- package/test/integration/ConnectionLocking.test.ts +66 -60
- package/test/integration/ConnectionManager.test.ts +43 -63
- package/test/integration/ConnectivityChecking.test.ts +52 -0
- package/test/integration/DhtJoinPeerDiscovery.test.ts +8 -12
- package/test/integration/DhtNodeExternalAPI.test.ts +17 -21
- package/test/integration/DhtNodeRpcRemote.test.ts +19 -26
- package/test/integration/DhtRpc.test.ts +20 -24
- package/test/integration/Find.test.ts +10 -12
- package/test/integration/Layer1-scale.test.ts +25 -37
- package/test/integration/Mock-Layer1-Layer0.test.ts +39 -59
- package/test/integration/MultipleEntryPointJoining.test.ts +14 -14
- package/test/integration/ReplicateData.test.ts +106 -0
- package/test/integration/RouteMessage.test.ts +42 -68
- package/test/integration/RouterRpcRemote.test.ts +19 -24
- package/test/integration/ScaleDownDht.test.ts +14 -12
- package/test/integration/SimultaneousConnections.test.ts +112 -111
- package/test/integration/Store.test.ts +43 -27
- package/test/integration/StoreAndDelete.test.ts +36 -48
- package/test/integration/StoreOnDhtWithThreeNodes.test.ts +59 -0
- package/test/integration/StoreOnDhtWithTwoNodes.test.ts +17 -37
- package/test/integration/StoreRpcRemote.test.ts +20 -32
- package/test/integration/WebrtcConnectionManagement.test.ts +39 -25
- package/test/integration/WebrtcConnectorRpc.test.ts +6 -11
- package/test/integration/WebsocketConnectionManagement.test.ts +87 -22
- package/test/integration/WebsocketConnectorRpc.test.ts +14 -24
- package/test/integration/{RpcErrors.test.ts → rpc-connections-over-webrpc.test.ts} +15 -26
- package/test/unit/AddressTools.test.ts +4 -0
- package/test/unit/ConnectivityHelpers.test.ts +9 -17
- package/test/unit/DuplicateDetector.test.ts +8 -5
- package/test/unit/LocalDataStore.test.ts +78 -75
- package/test/unit/PeerManager.test.ts +33 -0
- package/test/unit/RandomContactList.test.ts +12 -9
- package/test/unit/RecursiveOperationManager.test.ts +157 -0
- package/test/unit/RecursiveOperationSession.test.ts +68 -0
- package/test/unit/Router.test.ts +52 -35
- package/test/unit/RoutingSession.test.ts +79 -0
- package/test/unit/SortedContactList.test.ts +61 -30
- package/test/unit/StoreManager.test.ts +138 -0
- package/test/unit/WebsocketConnector.test.ts +27 -35
- package/test/unit/connectivityRequestHandler.test.ts +104 -0
- package/test/unit/createPeerDescriptor.test.ts +69 -0
- package/test/unit/customMatchers.test.ts +16 -0
- package/test/unit/version.test.ts +18 -0
- package/test/utils/FakeTransport.ts +47 -0
- package/test/utils/customMatchers.ts +71 -0
- package/test/utils/mock/MockRpcCommunicator.ts +7 -0
- package/test/utils/mock/Router.ts +13 -3
- package/test/utils/mock/Transport.ts +1 -1
- package/test/utils/mock/mockDataEntry.ts +38 -0
- package/test/utils/utils.ts +104 -107
- package/tsconfig.browser.json +2 -1
- package/tsconfig.jest.json +4 -2
- package/tsconfig.node.json +4 -2
- package/dist/src/connection/ConnectivityChecker.d.ts +0 -17
- package/dist/src/connection/ConnectivityChecker.js +0 -208
- package/dist/src/connection/ConnectivityChecker.js.map +0 -1
- package/dist/src/connection/websocket/ServerWebsocket.js +0 -100
- package/dist/src/connection/websocket/ServerWebsocket.js.map +0 -1
- package/dist/src/dht/contact/Remote.js.map +0 -1
- package/dist/src/dht/find/FindRpcLocal.d.ts +0 -14
- package/dist/src/dht/find/FindRpcLocal.js +0 -25
- 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 -145
- 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 -184
- 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 +0 -41
- package/dist/src/dht/routing/FindRpcRemote.js.map +0 -1
- package/dist/src/helpers/PeerID.d.ts +0 -24
- package/dist/src/helpers/PeerID.js +0 -78
- package/dist/src/helpers/PeerID.js.map +0 -1
- package/dist/src/helpers/UUID.d.ts +0 -8
- package/dist/src/helpers/UUID.js +0 -36
- package/dist/src/helpers/UUID.js.map +0 -1
- package/dist/src/helpers/kademliaId.d.ts +0 -1
- package/dist/src/helpers/kademliaId.js +0 -14
- package/dist/src/helpers/kademliaId.js.map +0 -1
- package/dist/src/helpers/peerIdFromPeerDescriptor.d.ts +0 -6
- package/dist/src/helpers/peerIdFromPeerDescriptor.js +0 -23
- package/dist/src/helpers/peerIdFromPeerDescriptor.js.map +0 -1
- package/src/connection/ConnectivityChecker.ts +0 -199
- package/src/connection/websocket/ServerWebsocket.ts +0 -114
- package/src/dht/find/FindRpcLocal.ts +0 -35
- package/src/dht/find/FindSession.ts +0 -178
- package/src/dht/find/FindSessionRpcLocal.ts +0 -25
- package/src/dht/find/FindSessionRpcRemote.ts +0 -30
- package/src/dht/find/Finder.ts +0 -275
- package/src/dht/routing/FindRpcRemote.ts +0 -40
- package/src/helpers/PeerID.ts +0 -88
- package/src/helpers/UUID.ts +0 -35
- package/src/helpers/kademliaId.ts +0 -8
- package/src/helpers/peerIdFromPeerDescriptor.ts +0 -20
- package/test/integration/MigrateData.test.ts +0 -204
- package/test/unit/Finder.test.ts +0 -110
- package/test/unit/PeerID.test.ts +0 -22
- package/test/unit/UUID.test.ts +0 -55
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RoutingSession.js","sourceRoot":"","sources":["../../../../src/dht/routing/RoutingSession.ts"],"names":[],"mappings":";;;;;;AACA,oEAAgE;AAChE,
|
|
1
|
+
{"version":3,"file":"RoutingSession.js","sourceRoot":"","sources":["../../../../src/dht/routing/RoutingSession.ts"],"names":[],"mappings":";;;;;;AACA,oEAAgE;AAChE,0CAAuC;AACvC,kEAAwC;AACxC,+BAAyB;AAEzB,uDAAmD;AAEnD,iFAA4G;AAC5G,gDAA4C;AAC5C,oGAAgG;AAChG,oDAAkE;AAClE,uDAAmD;AACnD,mDAA0H;AAC1H,mCAA6B;AAG7B,MAAM,MAAM,GAAG,IAAI,cAAM,CAAC,MAAM,CAAC,CAAA;AAEjC,MAAM,eAAe,GAAG,CAAC,CAAA;AACzB,MAAM,sBAAsB,GAAG,EAAE,CAAA;AAEjC,MAAa,oBAAqB,SAAQ,iBAAO;IAErC,eAAe,CAAiB;IAChC,2BAA2B,CAA6B;IAEhE,YAAY,IAAoB,EAAE,mBAAmC,EAAE,eAAuC;QAC1G,KAAK,CAAC,IAAI,CAAC,CAAA;QACX,IAAI,CAAC,eAAe,GAAG,IAAI,iCAAe,CACtC,mBAAmB,EACnB,IAAI,EACJ,eAAe,EACf,+BAAe,EACf,uCAA2B,CAC9B,CAAA;QACD,IAAI,CAAC,2BAA2B,GAAG,IAAI,yDAA2B,CAC9D,mBAAmB,EACnB,IAAI,EACJ,eAAe,EACf,2CAA2B,EAC3B,uCAA2B,CAC9B,CAAA;IACL,CAAC;IAED,kBAAkB;QACd,OAAO,IAAI,CAAC,eAAe,CAAA;IAC/B,CAAC;IAED,8BAA8B;QAC1B,OAAO,IAAI,CAAC,2BAA2B,CAAA;IAC3C,CAAC;CACJ;AA9BD,oDA8BC;AAaD,IAAY,WAAyC;AAArD,WAAY,WAAW;IAAG,+CAAK,CAAA;IAAE,mDAAO,CAA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,EAAE,CAAC,CAAA;gBAC1D,CAAC;wBAAS,CAAC;oBACP,MAAM,CAAC,KAAK,CAAC,kCAAkC,CAAC,CAAA;gBACpD,CAAC;YACL,CAAC,CAAC,CAAA;QACN,CAAC;IACL,CAAC;IAEO,uBAAuB,CAAC,MAAkB;QAC9C,IACI,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,WAAW,CAAC,SAAS;eACvC,IAAA,qCAAuB,EAAC,IAAI,CAAC,MAAM,CAAC,mBAAmB,EAAE,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,UAAW,CAAC,EACpG,CAAC;YACC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,mBAAmB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QAC9D,CAAC;IACL,CAAC;IAEO,0BAA0B,CAAC,MAAkB;QACjD,IACI,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,WAAW,CAAC,SAAS;eACvC,IAAA,qCAAuB,EAAC,IAAI,CAAC,MAAM,CAAC,mBAAmB,EAAE,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,UAAW,CAAC,EACpG,CAAC;YACC,IAAA,aAAI,EAAC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,mBAAmB,EAAE,MAAM,CAAC,CAAA;QAC/D,CAAC;IACL,CAAC;IAEM,IAAI;QACP,IAAI,CAAC,OAAO,GAAG,IAAI,CAAA;QACnB,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;QACpB,IAAI,CAAC,kBAAkB,EAAE,CAAA;IAC7B,CAAC;CACJ;AAxKD,wCAwKC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { DhtAddress } from '../../identifiers';
|
|
2
|
+
import { SortedContactList } from '../contact/SortedContactList';
|
|
3
|
+
import { RoutingRemoteContact } from './RoutingSession';
|
|
4
|
+
export type RoutingTable = Pick<SortedContactList<RoutingRemoteContact>, 'getAllContacts' | 'addContacts' | 'addContact' | 'removeContact' | 'stop'>;
|
|
5
|
+
/**
|
|
6
|
+
* RoutingTablesCache is a cache for routing tables.
|
|
7
|
+
* It is used to store the routing tables for a specific targetId and previousId.
|
|
8
|
+
* Storing the previousId is important as it is used as a minimum distance for the contacts in the table.
|
|
9
|
+
* Calculating a RoutingTable from scratch is an O(n log n) operation (n = number of connections of a node)
|
|
10
|
+
* However,
|
|
11
|
+
* - Adding a contact to a RoutingTable is an O(log n) operation.
|
|
12
|
+
* - Deleting a contact from a RoutingTable is an O(1) operation.
|
|
13
|
+
* Thus, holding the most frequently used routing tables in memory to be updated on
|
|
14
|
+
* connections and disconnections is hugely beneficial in terms of performance.
|
|
15
|
+
*/
|
|
16
|
+
export declare class RoutingTablesCache {
|
|
17
|
+
private readonly tables;
|
|
18
|
+
get(targetId: DhtAddress, previousId?: DhtAddress): RoutingTable | undefined;
|
|
19
|
+
set(targetId: DhtAddress, table: RoutingTable, previousId?: DhtAddress): void;
|
|
20
|
+
has(targetId: DhtAddress, previousId?: DhtAddress): boolean;
|
|
21
|
+
onNodeDisconnected(nodeId: DhtAddress): void;
|
|
22
|
+
onNodeConnected(remote: RoutingRemoteContact): void;
|
|
23
|
+
reset(): void;
|
|
24
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RoutingTablesCache = void 0;
|
|
4
|
+
const lru_cache_1 = require("lru-cache");
|
|
5
|
+
const createRoutingTableId = (targetId, previousId) => {
|
|
6
|
+
return targetId + (previousId ? previousId : '');
|
|
7
|
+
};
|
|
8
|
+
const DEFAULT_LRU_OPTIONS = {
|
|
9
|
+
max: 1000,
|
|
10
|
+
maxAge: 15 * 1000
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* RoutingTablesCache is a cache for routing tables.
|
|
14
|
+
* It is used to store the routing tables for a specific targetId and previousId.
|
|
15
|
+
* Storing the previousId is important as it is used as a minimum distance for the contacts in the table.
|
|
16
|
+
* Calculating a RoutingTable from scratch is an O(n log n) operation (n = number of connections of a node)
|
|
17
|
+
* However,
|
|
18
|
+
* - Adding a contact to a RoutingTable is an O(log n) operation.
|
|
19
|
+
* - Deleting a contact from a RoutingTable is an O(1) operation.
|
|
20
|
+
* Thus, holding the most frequently used routing tables in memory to be updated on
|
|
21
|
+
* connections and disconnections is hugely beneficial in terms of performance.
|
|
22
|
+
*/
|
|
23
|
+
class RoutingTablesCache {
|
|
24
|
+
tables = new lru_cache_1.LRUCache(DEFAULT_LRU_OPTIONS);
|
|
25
|
+
get(targetId, previousId) {
|
|
26
|
+
return this.tables.get(createRoutingTableId(targetId, previousId));
|
|
27
|
+
}
|
|
28
|
+
set(targetId, table, previousId) {
|
|
29
|
+
this.tables.set(createRoutingTableId(targetId, previousId), table);
|
|
30
|
+
}
|
|
31
|
+
has(targetId, previousId) {
|
|
32
|
+
return this.tables.has(createRoutingTableId(targetId, previousId));
|
|
33
|
+
}
|
|
34
|
+
onNodeDisconnected(nodeId) {
|
|
35
|
+
this.tables.forEach((table) => table.removeContact(nodeId));
|
|
36
|
+
}
|
|
37
|
+
onNodeConnected(remote) {
|
|
38
|
+
this.tables.forEach((table) => table.addContact(remote));
|
|
39
|
+
}
|
|
40
|
+
reset() {
|
|
41
|
+
this.tables.forEach((table) => table.stop());
|
|
42
|
+
this.tables.clear();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.RoutingTablesCache = RoutingTablesCache;
|
|
46
|
+
//# sourceMappingURL=RoutingTablesCache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RoutingTablesCache.js","sourceRoot":"","sources":["../../../../src/dht/routing/RoutingTablesCache.ts"],"names":[],"mappings":";;;AAGA,yCAAoC;AAKpC,MAAM,oBAAoB,GAAG,CAAC,QAAoB,EAAE,UAAuB,EAAkB,EAAE;IAC3F,OAAO,QAAQ,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAA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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getPreviousPeer.js","sourceRoot":"","sources":["../../../../src/dht/routing/getPreviousPeer.ts"],"names":[],"mappings":";;;AAAA,mCAA6B;AAGtB,MAAM,eAAe,GAAG,CAAC,YAAiC,EAA8B,EAAE;IAC7F,OAAO,IAAA,aAAI,EAAC,YAAY,CAAC,
|
|
1
|
+
{"version":3,"file":"getPreviousPeer.js","sourceRoot":"","sources":["../../../../src/dht/routing/getPreviousPeer.ts"],"names":[],"mappings":";;;AAAA,mCAA6B;AAGtB,MAAM,eAAe,GAAG,CAAC,YAAiC,EAA8B,EAAE;IAC7F,OAAO,IAAA,aAAI,EAAC,YAAY,CAAC,WAAW,CAAC,CAAA;AACzC,CAAC,CAAA;AAFY,QAAA,eAAe,mBAE3B"}
|
|
@@ -1,19 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import { DataEntry, PeerDescriptor } from '../../proto/packages/dht/protos/DhtRpc';
|
|
4
|
-
interface LocalDataEntry {
|
|
5
|
-
dataEntry: DataEntry;
|
|
6
|
-
ttlTimeout: NodeJS.Timeout;
|
|
7
|
-
}
|
|
1
|
+
import { DataEntry } from '../../proto/packages/dht/protos/DhtRpc';
|
|
2
|
+
import { DhtAddress } from '../../identifiers';
|
|
8
3
|
export declare class LocalDataStore {
|
|
4
|
+
private readonly maxTtl;
|
|
5
|
+
constructor(maxTtl: number);
|
|
9
6
|
private store;
|
|
10
7
|
storeEntry(dataEntry: DataEntry): boolean;
|
|
11
|
-
markAsDeleted(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
deleteEntry(key: PeerID, storer: PeerDescriptor): void;
|
|
8
|
+
markAsDeleted(key: DhtAddress, creator: DhtAddress): boolean;
|
|
9
|
+
values(key?: DhtAddress): IterableIterator<DataEntry>;
|
|
10
|
+
keys(): IterableIterator<DhtAddress>;
|
|
11
|
+
setAllEntriesAsStale(key: DhtAddress): void;
|
|
12
|
+
deleteEntry(key: DhtAddress, creator: DhtAddress): void;
|
|
17
13
|
clear(): void;
|
|
18
14
|
}
|
|
19
|
-
export {};
|
|
@@ -1,102 +1,76 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LocalDataStore = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const MIN_TTL = 1 * 1000;
|
|
7
|
-
const MAX_TTL = 300 * 1000;
|
|
8
|
-
const createTtlValue = (ttl) => {
|
|
9
|
-
if (ttl < MIN_TTL) {
|
|
10
|
-
return MIN_TTL;
|
|
11
|
-
}
|
|
12
|
-
else if (ttl > MAX_TTL) {
|
|
13
|
-
return MAX_TTL;
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
return ttl;
|
|
17
|
-
}
|
|
18
|
-
};
|
|
4
|
+
const MapWithTtl_1 = require("../../helpers/MapWithTtl");
|
|
5
|
+
const identifiers_1 = require("../../identifiers");
|
|
19
6
|
class LocalDataStore {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
// PeerID of the storer of the data
|
|
24
|
-
this.store = new Map();
|
|
7
|
+
maxTtl;
|
|
8
|
+
constructor(maxTtl) {
|
|
9
|
+
this.maxTtl = maxTtl;
|
|
25
10
|
}
|
|
11
|
+
// A map into which each node can store one value per data key
|
|
12
|
+
// The first key is the key of the data, the second key is the
|
|
13
|
+
// DhtAddress of the creator of the data
|
|
14
|
+
store = new Map();
|
|
26
15
|
storeEntry(dataEntry) {
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
if (!this.store.has(
|
|
30
|
-
this.store.set(
|
|
16
|
+
const key = (0, identifiers_1.getDhtAddressFromRaw)(dataEntry.key);
|
|
17
|
+
const creatorNodeId = (0, identifiers_1.getDhtAddressFromRaw)(dataEntry.creator);
|
|
18
|
+
if (!this.store.has(key)) {
|
|
19
|
+
this.store.set(key, new MapWithTtl_1.MapWithTtl((e) => Math.min(e.ttl, this.maxTtl)));
|
|
31
20
|
}
|
|
32
|
-
if (this.store.get(
|
|
33
|
-
const storedMillis = (dataEntry.
|
|
34
|
-
const oldLocalEntry = this.store.get(
|
|
35
|
-
const oldStoredMillis = (oldLocalEntry.
|
|
36
|
-
// do nothing if old entry is newer than the one being
|
|
21
|
+
if (this.store.get(key).has(creatorNodeId)) {
|
|
22
|
+
const storedMillis = (dataEntry.createdAt.seconds * 1000) + (dataEntry.createdAt.nanos / 1000000);
|
|
23
|
+
const oldLocalEntry = this.store.get(key).get(creatorNodeId);
|
|
24
|
+
const oldStoredMillis = (oldLocalEntry.createdAt.seconds * 1000) + (oldLocalEntry.createdAt.nanos / 1000000);
|
|
25
|
+
// do nothing if old entry is newer than the one being replicated
|
|
37
26
|
if (oldStoredMillis >= storedMillis) {
|
|
38
27
|
return false;
|
|
39
28
|
}
|
|
40
|
-
else {
|
|
41
|
-
clearTimeout(oldLocalEntry.ttlTimeout);
|
|
42
|
-
}
|
|
43
29
|
}
|
|
44
|
-
this.store.get(
|
|
45
|
-
dataEntry,
|
|
46
|
-
ttlTimeout: setTimeout(() => {
|
|
47
|
-
this.deleteEntry(PeerID_1.PeerID.fromValue(dataEntry.kademliaId), dataEntry.storer);
|
|
48
|
-
}, createTtlValue(dataEntry.ttl))
|
|
49
|
-
});
|
|
30
|
+
this.store.get(key).set(creatorNodeId, dataEntry);
|
|
50
31
|
return true;
|
|
51
32
|
}
|
|
52
|
-
markAsDeleted(
|
|
53
|
-
const
|
|
54
|
-
if (!
|
|
33
|
+
markAsDeleted(key, creator) {
|
|
34
|
+
const item = this.store.get(key);
|
|
35
|
+
if ((item === undefined) || !item.has(creator)) {
|
|
55
36
|
return false;
|
|
56
37
|
}
|
|
57
|
-
const storedEntry =
|
|
58
|
-
storedEntry.
|
|
38
|
+
const storedEntry = item.get(creator);
|
|
39
|
+
storedEntry.deleted = true;
|
|
59
40
|
return true;
|
|
60
41
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
dataEntries.set(key, value.dataEntry);
|
|
68
|
-
});
|
|
69
|
-
return dataEntries;
|
|
70
|
-
}
|
|
71
|
-
setStale(key, storer, stale) {
|
|
72
|
-
const storerKey = (0, peerIdFromPeerDescriptor_1.keyFromPeerDescriptor)(storer);
|
|
73
|
-
const storedEntry = this.store.get(key.toKey())?.get(storerKey);
|
|
74
|
-
if (storedEntry) {
|
|
75
|
-
storedEntry.dataEntry.stale = stale;
|
|
42
|
+
*values(key) {
|
|
43
|
+
if (key !== undefined) {
|
|
44
|
+
const map = this.store.get(key);
|
|
45
|
+
if (map !== undefined) {
|
|
46
|
+
yield* map.values();
|
|
47
|
+
}
|
|
76
48
|
}
|
|
49
|
+
else {
|
|
50
|
+
for (const v of this.store.values()) {
|
|
51
|
+
yield* v.values();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
keys() {
|
|
56
|
+
return this.store.keys();
|
|
77
57
|
}
|
|
78
58
|
setAllEntriesAsStale(key) {
|
|
79
|
-
this.store.get(key
|
|
80
|
-
value.
|
|
59
|
+
this.store.get(key)?.forEach((value) => {
|
|
60
|
+
value.stale = true;
|
|
81
61
|
});
|
|
82
62
|
}
|
|
83
|
-
deleteEntry(key,
|
|
84
|
-
const
|
|
85
|
-
const storedEntry = this.store.get(key.toKey())?.get(storerKey);
|
|
63
|
+
deleteEntry(key, creator) {
|
|
64
|
+
const storedEntry = this.store.get(key)?.get(creator);
|
|
86
65
|
if (storedEntry) {
|
|
87
|
-
|
|
88
|
-
this.store.get(key
|
|
89
|
-
|
|
90
|
-
this.store.delete(key.toKey());
|
|
66
|
+
this.store.get(key)?.delete(creator);
|
|
67
|
+
if (this.store.get(key)?.size() === 0) {
|
|
68
|
+
this.store.delete(key);
|
|
91
69
|
}
|
|
92
70
|
}
|
|
93
71
|
}
|
|
94
72
|
clear() {
|
|
95
|
-
this.store.forEach((value) =>
|
|
96
|
-
value.forEach((value) => {
|
|
97
|
-
clearTimeout(value.ttlTimeout);
|
|
98
|
-
});
|
|
99
|
-
});
|
|
73
|
+
this.store.forEach((value) => value.clear());
|
|
100
74
|
this.store.clear();
|
|
101
75
|
}
|
|
102
76
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LocalDataStore.js","sourceRoot":"","sources":["../../../../src/dht/store/LocalDataStore.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"LocalDataStore.js","sourceRoot":"","sources":["../../../../src/dht/store/LocalDataStore.ts"],"names":[],"mappings":";;;AACA,yDAAqD;AACrD,mDAAoE;AAEpE,MAAa,cAAc;IAEN,MAAM,CAAQ;IAE/B,YAAY,MAAc;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACxB,CAAC;IAED,8DAA8D;IAC9D,8DAA8D;IAC9D,wCAAwC;IAChC,KAAK,GAAuD,IAAI,GAAG,EAAE,CAAA;IAEtE,UAAU,CAAC,SAAoB;QAClC,MAAM,GAAG,GAAG,IAAA,kCAAoB,EAAC,SAAS,CAAC,GAAG,CAAC,CAAA;QAC/C,MAAM,aAAa,GAAG,IAAA,kCAAoB,EAAC,SAAS,CAAC,OAAO,CAAC,CAAA;QAC7D,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YACvB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,uBAAU,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;QAC5E,CAAC;QACD,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAE,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE,CAAC;YAC1C,MAAM,YAAY,GAAG,CAAC,SAAS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ages/dht/protos/DhtRpc';
|
|
2
|
+
import { Any } from '../../proto/google/protobuf/any';
|
|
3
|
+
import { RoutingRpcCommunicator } from '../../transport/RoutingRpcCommunicator';
|
|
4
|
+
import { RecursiveOperationManager } from '../recursive-operation/RecursiveOperationManager';
|
|
5
|
+
import { LocalDataStore } from './LocalDataStore';
|
|
6
|
+
import { StoreRpcRemote } from './StoreRpcRemote';
|
|
7
|
+
import { ServiceID } from '../../types/ServiceID';
|
|
8
|
+
import { DhtAddress } from '../../identifiers';
|
|
9
|
+
interface StoreManagerConfig {
|
|
10
|
+
rpcCommunicator: RoutingRpcCommunicator;
|
|
11
|
+
recursiveOperationManager: RecursiveOperationManager;
|
|
12
|
+
localPeerDescriptor: PeerDescriptor;
|
|
13
|
+
localDataStore: LocalDataStore;
|
|
14
|
+
serviceId: ServiceID;
|
|
15
|
+
highestTtl: number;
|
|
16
|
+
redundancyFactor: number;
|
|
17
|
+
getClosestNeighborsTo: (dataKey: DhtAddress, n?: number) => PeerDescriptor[];
|
|
18
|
+
createRpcRemote: (contact: PeerDescriptor) => StoreRpcRemote;
|
|
19
|
+
}
|
|
20
|
+
export declare class StoreManager {
|
|
21
|
+
private readonly config;
|
|
22
|
+
constructor(config: StoreManagerConfig);
|
|
23
|
+
private registerLocalRpcMethods;
|
|
24
|
+
onContactAdded(peerDescriptor: PeerDescriptor): void;
|
|
25
|
+
private replicateAndUpdateStaleState;
|
|
26
|
+
private replicateDataToContact;
|
|
27
|
+
storeDataToDht(key: DhtAddress, data: Any, creator: DhtAddress): Promise<PeerDescriptor[]>;
|
|
28
|
+
private selfIsWithinRedundancyFactor;
|
|
29
|
+
private replicateDataToClosestNodes;
|
|
30
|
+
private replicateDataToNeighbors;
|
|
31
|
+
destroy(): Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StoreManager = void 0;
|
|
4
|
+
const DhtRpc_1 = require("../../proto/packages/dht/protos/DhtRpc");
|
|
5
|
+
const utils_1 = require("@streamr/utils");
|
|
6
|
+
const timestamp_1 = require("../../proto/google/protobuf/timestamp");
|
|
7
|
+
const SortedContactList_1 = require("../contact/SortedContactList");
|
|
8
|
+
const Contact_1 = require("../contact/Contact");
|
|
9
|
+
const identifiers_1 = require("../../identifiers");
|
|
10
|
+
const StoreRpcLocal_1 = require("./StoreRpcLocal");
|
|
11
|
+
const PeerManager_1 = require("../PeerManager");
|
|
12
|
+
const logger = new utils_1.Logger(module);
|
|
13
|
+
class StoreManager {
|
|
14
|
+
config;
|
|
15
|
+
constructor(config) {
|
|
16
|
+
this.config = config;
|
|
17
|
+
this.registerLocalRpcMethods();
|
|
18
|
+
}
|
|
19
|
+
registerLocalRpcMethods() {
|
|
20
|
+
const rpcLocal = new StoreRpcLocal_1.StoreRpcLocal({
|
|
21
|
+
localDataStore: this.config.localDataStore,
|
|
22
|
+
replicateDataToNeighbors: (incomingPeer, dataEntry) => this.replicateDataToNeighbors(incomingPeer, dataEntry),
|
|
23
|
+
selfIsWithinRedundancyFactor: (key) => this.selfIsWithinRedundancyFactor(key)
|
|
24
|
+
});
|
|
25
|
+
this.config.rpcCommunicator.registerRpcMethod(DhtRpc_1.StoreDataRequest, DhtRpc_1.StoreDataResponse, 'storeData', (request) => rpcLocal.storeData(request));
|
|
26
|
+
this.config.rpcCommunicator.registerRpcNotification(DhtRpc_1.ReplicateDataRequest, 'replicateData', (request, context) => rpcLocal.replicateData(request, context));
|
|
27
|
+
}
|
|
28
|
+
onContactAdded(peerDescriptor) {
|
|
29
|
+
for (const key of this.config.localDataStore.keys()) {
|
|
30
|
+
this.replicateAndUpdateStaleState(key, peerDescriptor);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
replicateAndUpdateStaleState(key, newNode) {
|
|
34
|
+
const newNodeId = (0, identifiers_1.getNodeIdFromPeerDescriptor)(newNode);
|
|
35
|
+
const closestToData = this.config.getClosestNeighborsTo(key, this.config.redundancyFactor);
|
|
36
|
+
const sortedList = new SortedContactList_1.SortedContactList({
|
|
37
|
+
referenceId: key,
|
|
38
|
+
maxSize: this.config.redundancyFactor,
|
|
39
|
+
allowToContainReferenceId: true,
|
|
40
|
+
emitEvents: false
|
|
41
|
+
});
|
|
42
|
+
sortedList.addContact(new Contact_1.Contact(this.config.localPeerDescriptor));
|
|
43
|
+
closestToData.forEach((neighbor) => {
|
|
44
|
+
if (newNodeId !== (0, identifiers_1.getNodeIdFromPeerDescriptor)(neighbor)) {
|
|
45
|
+
sortedList.addContact(new Contact_1.Contact(neighbor));
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
const selfIsPrimaryStorer = (sortedList.getClosestContactId() === (0, identifiers_1.getNodeIdFromPeerDescriptor)(this.config.localPeerDescriptor));
|
|
49
|
+
if (selfIsPrimaryStorer) {
|
|
50
|
+
sortedList.addContact(new Contact_1.Contact(newNode));
|
|
51
|
+
if (sortedList.getContact(newNodeId) !== undefined) {
|
|
52
|
+
setImmediate(async () => {
|
|
53
|
+
const dataEntries = Array.from(this.config.localDataStore.values(key));
|
|
54
|
+
await Promise.all(dataEntries.map(async (dataEntry) => this.replicateDataToContact(dataEntry, newNode)));
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
else if (!this.selfIsWithinRedundancyFactor(key)) {
|
|
59
|
+
this.config.localDataStore.setAllEntriesAsStale(key);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
async replicateDataToContact(dataEntry, contact) {
|
|
63
|
+
const rpcRemote = this.config.createRpcRemote(contact);
|
|
64
|
+
try {
|
|
65
|
+
await rpcRemote.replicateData({ entry: dataEntry });
|
|
66
|
+
}
|
|
67
|
+
catch (e) {
|
|
68
|
+
logger.trace('replicateData() threw an exception ' + e);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
async storeDataToDht(key, data, creator) {
|
|
72
|
+
logger.debug(`Storing data to DHT ${this.config.serviceId}`);
|
|
73
|
+
const result = await this.config.recursiveOperationManager.execute(key, DhtRpc_1.RecursiveOperation.FIND_CLOSEST_NODES);
|
|
74
|
+
const closestNodes = result.closestNodes;
|
|
75
|
+
const successfulNodes = [];
|
|
76
|
+
const ttl = this.config.highestTtl; // ToDo: make TTL decrease according to some nice curve
|
|
77
|
+
const createdAt = timestamp_1.Timestamp.now();
|
|
78
|
+
for (let i = 0; i < closestNodes.length && successfulNodes.length < this.config.redundancyFactor; i++) {
|
|
79
|
+
const keyRaw = (0, identifiers_1.getRawFromDhtAddress)(key);
|
|
80
|
+
const creatorRaw = (0, identifiers_1.getRawFromDhtAddress)(creator);
|
|
81
|
+
if ((0, identifiers_1.areEqualPeerDescriptors)(this.config.localPeerDescriptor, closestNodes[i])) {
|
|
82
|
+
this.config.localDataStore.storeEntry({
|
|
83
|
+
key: keyRaw,
|
|
84
|
+
data,
|
|
85
|
+
creator: creatorRaw,
|
|
86
|
+
createdAt,
|
|
87
|
+
storedAt: timestamp_1.Timestamp.now(),
|
|
88
|
+
ttl,
|
|
89
|
+
stale: false,
|
|
90
|
+
deleted: false,
|
|
91
|
+
});
|
|
92
|
+
successfulNodes.push(closestNodes[i]);
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
const rpcRemote = this.config.createRpcRemote(closestNodes[i]);
|
|
96
|
+
try {
|
|
97
|
+
await rpcRemote.storeData({
|
|
98
|
+
key: keyRaw,
|
|
99
|
+
data,
|
|
100
|
+
creator: creatorRaw,
|
|
101
|
+
createdAt,
|
|
102
|
+
ttl
|
|
103
|
+
});
|
|
104
|
+
successfulNodes.push(closestNodes[i]);
|
|
105
|
+
logger.trace('remote.storeData() success');
|
|
106
|
+
}
|
|
107
|
+
catch (e) {
|
|
108
|
+
logger.trace('remote.storeData() threw an exception ' + e);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return successfulNodes;
|
|
112
|
+
}
|
|
113
|
+
selfIsWithinRedundancyFactor(dataKey) {
|
|
114
|
+
const closestNeighbors = this.config.getClosestNeighborsTo(dataKey, this.config.redundancyFactor);
|
|
115
|
+
if (closestNeighbors.length < this.config.redundancyFactor) {
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
const furthestCloseNeighbor = closestNeighbors[closestNeighbors.length - 1];
|
|
120
|
+
const dataKeyRaw = (0, identifiers_1.getRawFromDhtAddress)(dataKey);
|
|
121
|
+
return (0, PeerManager_1.getDistance)(dataKeyRaw, this.config.localPeerDescriptor.nodeId) < (0, PeerManager_1.getDistance)(dataKeyRaw, furthestCloseNeighbor.nodeId);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
async replicateDataToClosestNodes() {
|
|
125
|
+
const dataEntries = Array.from(this.config.localDataStore.values());
|
|
126
|
+
await Promise.all(dataEntries.map(async (dataEntry) => {
|
|
127
|
+
const neighbors = this.config.getClosestNeighborsTo((0, identifiers_1.getDhtAddressFromRaw)(dataEntry.key), this.config.redundancyFactor);
|
|
128
|
+
await Promise.all(neighbors.map(async (neighbor) => {
|
|
129
|
+
const rpcRemote = this.config.createRpcRemote(neighbor);
|
|
130
|
+
try {
|
|
131
|
+
await rpcRemote.replicateData({ entry: dataEntry });
|
|
132
|
+
}
|
|
133
|
+
catch (err) {
|
|
134
|
+
logger.trace('Failed to replicate data in replicateDataToClosestNodes', { error: err });
|
|
135
|
+
}
|
|
136
|
+
}));
|
|
137
|
+
}));
|
|
138
|
+
}
|
|
139
|
+
replicateDataToNeighbors(incomingPeer, dataEntry) {
|
|
140
|
+
// sort own contact list according to data id
|
|
141
|
+
const localNodeId = (0, identifiers_1.getNodeIdFromPeerDescriptor)(this.config.localPeerDescriptor);
|
|
142
|
+
const incomingNodeId = (0, identifiers_1.getNodeIdFromPeerDescriptor)(incomingPeer);
|
|
143
|
+
const key = (0, identifiers_1.getDhtAddressFromRaw)(dataEntry.key);
|
|
144
|
+
// TODO use config option or named constant?
|
|
145
|
+
const closestToData = this.config.getClosestNeighborsTo(key, 10);
|
|
146
|
+
const sortedList = new SortedContactList_1.SortedContactList({
|
|
147
|
+
referenceId: key,
|
|
148
|
+
maxSize: this.config.redundancyFactor,
|
|
149
|
+
allowToContainReferenceId: true,
|
|
150
|
+
emitEvents: false
|
|
151
|
+
});
|
|
152
|
+
sortedList.addContact(new Contact_1.Contact(this.config.localPeerDescriptor));
|
|
153
|
+
closestToData.forEach((neighbor) => {
|
|
154
|
+
sortedList.addContact(new Contact_1.Contact(neighbor));
|
|
155
|
+
});
|
|
156
|
+
const selfIsPrimaryStorer = (sortedList.getClosestContactId() === localNodeId);
|
|
157
|
+
const targets = selfIsPrimaryStorer
|
|
158
|
+
// if we are the closest to the data, replicate to all storageRedundancyFactor nearest
|
|
159
|
+
? sortedList.getAllContacts()
|
|
160
|
+
// if we are not the closest node to the data, replicate only to the closest one to the data
|
|
161
|
+
: [sortedList.getAllContacts()[0]];
|
|
162
|
+
targets.forEach((contact) => {
|
|
163
|
+
const contactNodeId = contact.getNodeId();
|
|
164
|
+
if ((incomingNodeId !== contactNodeId) && (localNodeId !== contactNodeId)) {
|
|
165
|
+
setImmediate(() => {
|
|
166
|
+
(0, utils_1.executeSafePromise)(async () => {
|
|
167
|
+
await this.replicateDataToContact(dataEntry, contact.getPeerDescriptor());
|
|
168
|
+
logger.trace('replicateDataToContact() returned', {
|
|
169
|
+
node: contactNodeId,
|
|
170
|
+
replicateOnlyToClosest: !selfIsPrimaryStorer
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
async destroy() {
|
|
178
|
+
await this.replicateDataToClosestNodes();
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
exports.StoreManager = StoreManager;
|
|
182
|
+
//# sourceMappingURL=StoreManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StoreManager.js","sourceRoot":"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AAC,UAAU,CAAC,mBAAmB,EAAE,KAAK,WAAW,CAAC,CAAA;QAC9E,MAAM,OAAO,GAAG,mBAAmB;YAC/B,sFAAsF;YACtF,CAAC,CAAC,UAAU,CAAC,cAAc,EAAE;YAC7B,4FAA4F;YAC5F,CAAC,CAAC,CAAC,UAAU,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;QACtC,OAAO,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YACxB,MAAM,aAAa,GAAG,OAAO,CAAC,SAAS,EAAE,CAAA;YACzC,IAAI,CAAC,cAAc,KAAK,aAAa,CAAC,IAAI,CAAC,WAAW,KAAK,aAAa,CAAC,EAAE,CAAC;gBACxE,YAAY,CAAC,GAAG,EAAE;oBACd,IAAA,0BAAkB,EAAC,KAAK,IAAI,EAAE;wBAC1B,MAAM,IAAI,CAAC,sBAAsB,CAAC,SAAS,EAAE,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAAA;wBACzE,MAAM,CAAC,KAAK,CAAC,mCAAmC,EAAE;4BAC9C,IAAI,EAAE,aAAa;4BACnB,sBAAsB,EAAE,CAAC,mBAAmB;yBAC/C,CAAC,CAAA;oBACN,CAAC,CAAC,CAAA;gBACN,CAAC,CAAC,CAAA;YACN,CAAC;QACL,CAAC,CAAC,CAAA;IACN,CAAC;IAED,KAAK,CAAC,OAAO;QACT,MAAM,IAAI,CAAC,2BAA2B,EAAE,CAAA;IAC5C,CAAC;CACJ;AA/KD,oCA+KC"}
|
|
@@ -1,48 +1,18 @@
|
|
|
1
|
-
import { DeleteDataRequest, DeleteDataResponse, MigrateDataRequest, MigrateDataResponse, PeerDescriptor, StoreDataRequest, StoreDataResponse } from '../../proto/packages/dht/protos/DhtRpc';
|
|
2
|
-
import { Any } from '../../proto/google/protobuf/any';
|
|
3
1
|
import { ServerCallContext } from '@protobuf-ts/runtime-rpc';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { LocalDataStore } from './LocalDataStore';
|
|
2
|
+
import { Empty } from '../../proto/google/protobuf/empty';
|
|
3
|
+
import { DataEntry, PeerDescriptor, ReplicateDataRequest, StoreDataRequest, StoreDataResponse } from '../../proto/packages/dht/protos/DhtRpc';
|
|
7
4
|
import { IStoreRpc } from '../../proto/packages/dht/protos/DhtRpc.server';
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
import { ServiceID } from '../../types/ServiceID';
|
|
12
|
-
interface DataStoreConfig {
|
|
13
|
-
rpcCommunicator: RoutingRpcCommunicator;
|
|
14
|
-
finder: IFinder;
|
|
15
|
-
localPeerDescriptor: PeerDescriptor;
|
|
5
|
+
import { LocalDataStore } from './LocalDataStore';
|
|
6
|
+
import { DhtAddress } from '../../identifiers';
|
|
7
|
+
interface StoreRpcLocalConfig {
|
|
16
8
|
localDataStore: LocalDataStore;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
highestTtl: number;
|
|
20
|
-
redundancyFactor: number;
|
|
21
|
-
dhtNodeEmitter: EventEmitter<Events>;
|
|
22
|
-
getNodesClosestToIdFromBucket: (id: Uint8Array, n?: number) => DhtNodeRpcRemote[];
|
|
23
|
-
rpcRequestTimeout?: number;
|
|
9
|
+
replicateDataToNeighbors: (incomingPeer: PeerDescriptor, dataEntry: DataEntry) => void;
|
|
10
|
+
selfIsWithinRedundancyFactor: (key: DhtAddress) => boolean;
|
|
24
11
|
}
|
|
25
12
|
export declare class StoreRpcLocal implements IStoreRpc {
|
|
26
|
-
private readonly
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
private readonly serviceId;
|
|
31
|
-
private readonly maxTtl;
|
|
32
|
-
private readonly highestTtl;
|
|
33
|
-
private readonly redundancyFactor;
|
|
34
|
-
private readonly dhtNodeEmitter;
|
|
35
|
-
private readonly getNodesClosestToIdFromBucket;
|
|
36
|
-
private readonly rpcRequestTimeout?;
|
|
37
|
-
constructor(config: DataStoreConfig);
|
|
38
|
-
private shouldMigrateDataToNewNode;
|
|
39
|
-
private migrateDataToContact;
|
|
40
|
-
storeDataToDht(key: Uint8Array, data: Any): Promise<PeerDescriptor[]>;
|
|
41
|
-
private selfIsOneOfClosestPeers;
|
|
42
|
-
deleteDataFromDht(key: Uint8Array): Promise<void>;
|
|
43
|
-
storeData(request: StoreDataRequest, context: ServerCallContext): Promise<StoreDataResponse>;
|
|
44
|
-
deleteData(request: DeleteDataRequest, context: ServerCallContext): Promise<DeleteDataResponse>;
|
|
45
|
-
migrateData(request: MigrateDataRequest, context: ServerCallContext): Promise<MigrateDataResponse>;
|
|
46
|
-
private migrateDataToNeighborsIfNeeded;
|
|
13
|
+
private readonly config;
|
|
14
|
+
constructor(config: StoreRpcLocalConfig);
|
|
15
|
+
storeData(request: StoreDataRequest): Promise<StoreDataResponse>;
|
|
16
|
+
replicateData(request: ReplicateDataRequest, context: ServerCallContext): Promise<Empty>;
|
|
47
17
|
}
|
|
48
18
|
export {};
|