@streamr/dht 0.0.1-tatum.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/.eslintignore +5 -0
- package/.eslintrc +3 -0
- package/README.md +38 -0
- package/dist/src/connection/Connection.d.ts +11 -0
- package/dist/src/connection/Connection.js +23 -0
- package/dist/src/connection/Connection.js.map +1 -0
- package/dist/src/connection/ConnectionLockHandler.d.ts +23 -0
- package/dist/src/connection/ConnectionLockHandler.js +94 -0
- package/dist/src/connection/ConnectionLockHandler.js.map +1 -0
- package/dist/src/connection/ConnectionManager.d.ts +94 -0
- package/dist/src/connection/ConnectionManager.js +554 -0
- package/dist/src/connection/ConnectionManager.js.map +1 -0
- package/dist/src/connection/ConnectivityChecker.d.ts +17 -0
- package/dist/src/connection/ConnectivityChecker.js +187 -0
- package/dist/src/connection/ConnectivityChecker.js.map +1 -0
- package/dist/src/connection/Handshaker.d.ts +19 -0
- package/dist/src/connection/Handshaker.js +77 -0
- package/dist/src/connection/Handshaker.js.map +1 -0
- package/dist/src/connection/IConnection.d.ts +38 -0
- package/dist/src/connection/IConnection.js +19 -0
- package/dist/src/connection/IConnection.js.map +1 -0
- package/dist/src/connection/IConnectionSource.d.ts +4 -0
- package/dist/src/connection/IConnectionSource.js +3 -0
- package/dist/src/connection/IConnectionSource.js.map +1 -0
- package/dist/src/connection/ManagedConnection.d.ts +60 -0
- package/dist/src/connection/ManagedConnection.js +352 -0
- package/dist/src/connection/ManagedConnection.js.map +1 -0
- package/dist/src/connection/ManagedWebRtcConnection.d.ts +7 -0
- package/dist/src/connection/ManagedWebRtcConnection.js +20 -0
- package/dist/src/connection/ManagedWebRtcConnection.js.map +1 -0
- package/dist/src/connection/RemoteConnectionLocker.d.ts +14 -0
- package/dist/src/connection/RemoteConnectionLocker.js +93 -0
- package/dist/src/connection/RemoteConnectionLocker.js.map +1 -0
- package/dist/src/connection/Simulator/Simulator.d.ts +42 -0
- package/dist/src/connection/Simulator/Simulator.js +325 -0
- package/dist/src/connection/Simulator/Simulator.js.map +1 -0
- package/dist/src/connection/Simulator/SimulatorConnection.d.ts +19 -0
- package/dist/src/connection/Simulator/SimulatorConnection.js +118 -0
- package/dist/src/connection/Simulator/SimulatorConnection.js.map +1 -0
- package/dist/src/connection/Simulator/SimulatorConnector.d.ts +17 -0
- package/dist/src/connection/Simulator/SimulatorConnector.js +72 -0
- package/dist/src/connection/Simulator/SimulatorConnector.js.map +1 -0
- package/dist/src/connection/Simulator/SimulatorTransport.d.ts +6 -0
- package/dist/src/connection/Simulator/SimulatorTransport.js +11 -0
- package/dist/src/connection/Simulator/SimulatorTransport.js.map +1 -0
- package/dist/src/connection/Simulator/pings.d.ts +21 -0
- package/dist/src/connection/Simulator/pings.js +61 -0
- package/dist/src/connection/Simulator/pings.js.map +1 -0
- package/dist/src/connection/WebRTC/IWebRtcConnection.d.ts +20 -0
- package/dist/src/connection/WebRTC/IWebRtcConnection.js +9 -0
- package/dist/src/connection/WebRTC/IWebRtcConnection.js.map +1 -0
- package/dist/src/connection/WebRTC/NodeWebRtcConnection.d.ts +47 -0
- package/dist/src/connection/WebRTC/NodeWebRtcConnection.js +233 -0
- package/dist/src/connection/WebRTC/NodeWebRtcConnection.js.map +1 -0
- package/dist/src/connection/WebRTC/RemoteWebrtcConnector.d.ts +12 -0
- package/dist/src/connection/WebRTC/RemoteWebrtcConnector.js +74 -0
- package/dist/src/connection/WebRTC/RemoteWebrtcConnector.js.map +1 -0
- package/dist/src/connection/WebRTC/WebRtcConnector.d.ts +47 -0
- package/dist/src/connection/WebRTC/WebRtcConnector.js +227 -0
- package/dist/src/connection/WebRTC/WebRtcConnector.js.map +1 -0
- package/dist/src/connection/WebRTC/iceServerAsString.d.ts +2 -0
- package/dist/src/connection/WebRTC/iceServerAsString.js +18 -0
- package/dist/src/connection/WebRTC/iceServerAsString.js.map +1 -0
- package/dist/src/connection/WebSocket/ClientWebSocket.d.ts +15 -0
- package/dist/src/connection/WebSocket/ClientWebSocket.js +113 -0
- package/dist/src/connection/WebSocket/ClientWebSocket.js.map +1 -0
- package/dist/src/connection/WebSocket/RemoteWebSocketConnector.d.ts +9 -0
- package/dist/src/connection/WebSocket/RemoteWebSocketConnector.js +63 -0
- package/dist/src/connection/WebSocket/RemoteWebSocketConnector.js.map +1 -0
- package/dist/src/connection/WebSocket/ServerWebSocket.d.ts +18 -0
- package/dist/src/connection/WebSocket/ServerWebSocket.js +103 -0
- package/dist/src/connection/WebSocket/ServerWebSocket.js.map +1 -0
- package/dist/src/connection/WebSocket/WebSocketConnector.d.ts +31 -0
- package/dist/src/connection/WebSocket/WebSocketConnector.js +202 -0
- package/dist/src/connection/WebSocket/WebSocketConnector.js.map +1 -0
- package/dist/src/connection/WebSocket/WebSocketServer.d.ts +9 -0
- package/dist/src/connection/WebSocket/WebSocketServer.js +101 -0
- package/dist/src/connection/WebSocket/WebSocketServer.js.map +1 -0
- package/dist/src/dht/DhtNode.d.ts +153 -0
- package/dist/src/dht/DhtNode.js +599 -0
- package/dist/src/dht/DhtNode.js.map +1 -0
- package/dist/src/dht/DhtPeer.d.ts +18 -0
- package/dist/src/dht/DhtPeer.js +74 -0
- package/dist/src/dht/DhtPeer.js.map +1 -0
- package/dist/src/dht/ExternalApi.d.ts +8 -0
- package/dist/src/dht/ExternalApi.js +26 -0
- package/dist/src/dht/ExternalApi.js.map +1 -0
- package/dist/src/dht/RemoteExternalApi.d.ts +6 -0
- package/dist/src/dht/RemoteExternalApi.js +26 -0
- package/dist/src/dht/RemoteExternalApi.js.map +1 -0
- package/dist/src/dht/contact/Contact.d.ts +22 -0
- package/dist/src/dht/contact/Contact.js +25 -0
- package/dist/src/dht/contact/Contact.js.map +1 -0
- package/dist/src/dht/contact/RandomContactList.d.ts +20 -0
- package/dist/src/dht/contact/RandomContactList.js +78 -0
- package/dist/src/dht/contact/RandomContactList.js.map +1 -0
- package/dist/src/dht/contact/Remote.d.ts +15 -0
- package/dist/src/dht/contact/Remote.js +24 -0
- package/dist/src/dht/contact/Remote.js.map +1 -0
- package/dist/src/dht/contact/SortedContactList.d.ts +35 -0
- package/dist/src/dht/contact/SortedContactList.js +156 -0
- package/dist/src/dht/contact/SortedContactList.js.map +1 -0
- package/dist/src/dht/discovery/DiscoverySession.d.ts +36 -0
- package/dist/src/dht/discovery/DiscoverySession.js +116 -0
- package/dist/src/dht/discovery/DiscoverySession.js.map +1 -0
- package/dist/src/dht/discovery/PeerDiscovery.d.ts +42 -0
- package/dist/src/dht/discovery/PeerDiscovery.js +157 -0
- package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -0
- package/dist/src/dht/find/RecursiveFindSession.d.ts +46 -0
- package/dist/src/dht/find/RecursiveFindSession.js +142 -0
- package/dist/src/dht/find/RecursiveFindSession.js.map +1 -0
- package/dist/src/dht/find/RecursiveFinder.d.ts +54 -0
- package/dist/src/dht/find/RecursiveFinder.js +180 -0
- package/dist/src/dht/find/RecursiveFinder.js.map +1 -0
- package/dist/src/dht/find/RemoteRecursiveFindSession.d.ts +6 -0
- package/dist/src/dht/find/RemoteRecursiveFindSession.js +25 -0
- package/dist/src/dht/find/RemoteRecursiveFindSession.js.map +1 -0
- package/dist/src/dht/routing/DuplicateDetector.d.ts +13 -0
- package/dist/src/dht/routing/DuplicateDetector.js +41 -0
- package/dist/src/dht/routing/DuplicateDetector.js.map +1 -0
- package/dist/src/dht/routing/RemoteRouter.d.ts +8 -0
- package/dist/src/dht/routing/RemoteRouter.js +106 -0
- package/dist/src/dht/routing/RemoteRouter.js.map +1 -0
- package/dist/src/dht/routing/Router.d.ts +60 -0
- package/dist/src/dht/routing/Router.js +207 -0
- package/dist/src/dht/routing/Router.js.map +1 -0
- package/dist/src/dht/routing/RoutingSession.d.ts +42 -0
- package/dist/src/dht/routing/RoutingSession.js +178 -0
- package/dist/src/dht/routing/RoutingSession.js.map +1 -0
- package/dist/src/dht/store/DataStore.d.ts +45 -0
- package/dist/src/dht/store/DataStore.js +244 -0
- package/dist/src/dht/store/DataStore.js.map +1 -0
- package/dist/src/dht/store/LocalDataStore.d.ts +19 -0
- package/dist/src/dht/store/LocalDataStore.js +104 -0
- package/dist/src/dht/store/LocalDataStore.js.map +1 -0
- package/dist/src/dht/store/RemoteStore.d.ts +8 -0
- package/dist/src/dht/store/RemoteStore.js +44 -0
- package/dist/src/dht/store/RemoteStore.js.map +1 -0
- package/dist/src/exports.d.ts +19 -0
- package/dist/src/exports.js +41 -0
- package/dist/src/exports.js.map +1 -0
- package/dist/src/helpers/AddressTools.d.ts +2 -0
- package/dist/src/helpers/AddressTools.js +31 -0
- package/dist/src/helpers/AddressTools.js.map +1 -0
- package/dist/src/helpers/PeerID.d.ts +25 -0
- package/dist/src/helpers/PeerID.js +84 -0
- package/dist/src/helpers/PeerID.js.map +1 -0
- package/dist/src/helpers/UUID.d.ts +7 -0
- package/dist/src/helpers/UUID.js +32 -0
- package/dist/src/helpers/UUID.js.map +1 -0
- package/dist/src/helpers/debugHelpers.d.ts +3 -0
- package/dist/src/helpers/debugHelpers.js +11 -0
- package/dist/src/helpers/debugHelpers.js.map +1 -0
- package/dist/src/helpers/errors.d.ts +72 -0
- package/dist/src/helpers/errors.js +95 -0
- package/dist/src/helpers/errors.js.map +1 -0
- package/dist/src/helpers/peerIdFromPeerDescriptor.d.ts +5 -0
- package/dist/src/helpers/peerIdFromPeerDescriptor.js +17 -0
- package/dist/src/helpers/peerIdFromPeerDescriptor.js.map +1 -0
- package/dist/src/helpers/protoClasses.d.ts +2 -0
- package/dist/src/helpers/protoClasses.js +35 -0
- package/dist/src/helpers/protoClasses.js.map +1 -0
- package/dist/src/helpers/protoToString.d.ts +2 -0
- package/dist/src/helpers/protoToString.js +20 -0
- package/dist/src/helpers/protoToString.js.map +1 -0
- package/dist/src/proto/google/protobuf/any.d.ts +173 -0
- package/dist/src/proto/google/protobuf/any.js +155 -0
- package/dist/src/proto/google/protobuf/any.js.map +1 -0
- package/dist/src/proto/google/protobuf/empty.d.ts +32 -0
- package/dist/src/proto/google/protobuf/empty.js +34 -0
- package/dist/src/proto/google/protobuf/empty.js.map +1 -0
- package/dist/src/proto/google/protobuf/timestamp.d.ts +149 -0
- package/dist/src/proto/google/protobuf/timestamp.js +136 -0
- package/dist/src/proto/google/protobuf/timestamp.js.map +1 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +320 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +245 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +1089 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +710 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +145 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.js +3 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.js.map +1 -0
- package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.d.ts +87 -0
- package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.js +66 -0
- package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.js.map +1 -0
- package/dist/src/proto/tests.d.ts +39 -0
- package/dist/src/proto/tests.js +34 -0
- package/dist/src/proto/tests.js.map +1 -0
- package/dist/src/rpc-protocol/DhtCallContext.d.ts +12 -0
- package/dist/src/rpc-protocol/DhtCallContext.js +8 -0
- package/dist/src/rpc-protocol/DhtCallContext.js.map +1 -0
- package/dist/src/rpc-protocol/DhtRpcOptions.d.ts +8 -0
- package/dist/src/rpc-protocol/DhtRpcOptions.js +3 -0
- package/dist/src/rpc-protocol/DhtRpcOptions.js.map +1 -0
- package/dist/src/transport/ITransport.d.ts +22 -0
- package/dist/src/transport/ITransport.js +3 -0
- package/dist/src/transport/ITransport.js.map +1 -0
- package/dist/src/transport/ListeningRpcCommunicator.d.ts +6 -0
- package/dist/src/transport/ListeningRpcCommunicator.js +14 -0
- package/dist/src/transport/ListeningRpcCommunicator.js.map +1 -0
- package/dist/src/transport/RoutingRpcCommunicator.d.ts +8 -0
- package/dist/src/transport/RoutingRpcCommunicator.js +52 -0
- package/dist/src/transport/RoutingRpcCommunicator.js.map +1 -0
- package/jest.config.js +2 -0
- package/karma.config.js +20 -0
- package/package.json +64 -0
- package/proto.sh +3 -0
- package/protos/DhtRpc.proto +330 -0
- package/protos/tests.proto +16 -0
- package/src/connection/Connection.ts +23 -0
- package/src/connection/ConnectionLockHandler.ts +105 -0
- package/src/connection/ConnectionManager.ts +676 -0
- package/src/connection/ConnectivityChecker.ts +173 -0
- package/src/connection/Handshaker.ts +92 -0
- package/src/connection/IConnection.ts +47 -0
- package/src/connection/IConnectionSource.ts +6 -0
- package/src/connection/ManagedConnection.ts +398 -0
- package/src/connection/ManagedWebRtcConnection.ts +27 -0
- package/src/connection/RemoteConnectionLocker.ts +88 -0
- package/src/connection/Simulator/Simulator.ts +399 -0
- package/src/connection/Simulator/SimulatorConnection.ts +137 -0
- package/src/connection/Simulator/SimulatorConnector.ts +104 -0
- package/src/connection/Simulator/SimulatorTransport.ts +9 -0
- package/src/connection/Simulator/pings.ts +42 -0
- package/src/connection/WebRTC/BrowserWebRtcConnection.ts +227 -0
- package/src/connection/WebRTC/IWebRtcConnection.ts +24 -0
- package/src/connection/WebRTC/NodeWebRtcConnection.ts +256 -0
- package/src/connection/WebRTC/RemoteWebrtcConnector.ts +93 -0
- package/src/connection/WebRTC/WebRtcConnector.ts +306 -0
- package/src/connection/WebRTC/iceServerAsString.ts +15 -0
- package/src/connection/WebSocket/ClientWebSocket.ts +118 -0
- package/src/connection/WebSocket/RemoteWebSocketConnector.ts +49 -0
- package/src/connection/WebSocket/ServerWebSocket.ts +119 -0
- package/src/connection/WebSocket/WebSocketConnector.ts +264 -0
- package/src/connection/WebSocket/WebSocketServer.ts +97 -0
- package/src/dht/DhtNode.ts +776 -0
- package/src/dht/DhtPeer.ts +96 -0
- package/src/dht/ExternalApi.ts +29 -0
- package/src/dht/RemoteExternalApi.ts +25 -0
- package/src/dht/contact/Contact.ts +36 -0
- package/src/dht/contact/RandomContactList.ts +92 -0
- package/src/dht/contact/Remote.ts +40 -0
- package/src/dht/contact/SortedContactList.ts +196 -0
- package/src/dht/discovery/DiscoverySession.ts +150 -0
- package/src/dht/discovery/PeerDiscovery.ts +162 -0
- package/src/dht/find/RecursiveFindSession.ts +178 -0
- package/src/dht/find/RecursiveFinder.ts +272 -0
- package/src/dht/find/RemoteRecursiveFindSession.ts +33 -0
- package/src/dht/routing/DuplicateDetector.ts +53 -0
- package/src/dht/routing/RemoteRouter.ts +115 -0
- package/src/dht/routing/Router.ts +266 -0
- package/src/dht/routing/RoutingSession.ts +222 -0
- package/src/dht/store/DataStore.ts +321 -0
- package/src/dht/store/LocalDataStore.ts +114 -0
- package/src/dht/store/RemoteStore.ts +58 -0
- package/src/exports.ts +19 -0
- package/src/helpers/AddressTools.ts +26 -0
- package/src/helpers/PeerID.ts +95 -0
- package/src/helpers/UUID.ts +30 -0
- package/src/helpers/debugHelpers.ts +9 -0
- package/src/helpers/errors.ts +49 -0
- package/src/helpers/peerIdFromPeerDescriptor.ts +14 -0
- package/src/helpers/protoClasses.ts +63 -0
- package/src/helpers/protoToString.ts +21 -0
- package/src/proto/google/protobuf/any.ts +319 -0
- package/src/proto/google/protobuf/empty.ts +84 -0
- package/src/proto/google/protobuf/timestamp.ts +281 -0
- package/src/proto/packages/dht/protos/DhtRpc.client.ts +373 -0
- package/src/proto/packages/dht/protos/DhtRpc.server.ts +148 -0
- package/src/proto/packages/dht/protos/DhtRpc.ts +1399 -0
- package/src/proto/packages/proto-rpc/protos/ProtoRpc.ts +108 -0
- package/src/proto/tests.ts +52 -0
- package/src/rpc-protocol/DhtCallContext.ts +15 -0
- package/src/rpc-protocol/DhtRpcOptions.ts +9 -0
- package/src/transport/ITransport.ts +31 -0
- package/src/transport/ListeningRpcCommunicator.ts +14 -0
- package/src/transport/RoutingRpcCommunicator.ts +59 -0
- package/src/types/glogal.d.ts +1 -0
- package/src/types/textencoding.d.ts +7 -0
- package/test/RandomGraphSimulation.ts +52 -0
- package/test/benchmark/KademliaCorrectness.test.ts +115 -0
- package/test/benchmark/RecursiveFind.test.ts +87 -0
- package/test/benchmark/any.test.ts +28 -0
- package/test/benchmark/kademlia-simulation/Contact.ts +32 -0
- package/test/benchmark/kademlia-simulation/KademliaSimulation.ts +94 -0
- package/test/benchmark/kademlia-simulation/SimulationNode.ts +125 -0
- package/test/data/generateGroundTruthData.ts +70 -0
- package/test/end-to-end/Layer0-Layer1.test.ts +87 -0
- package/test/end-to-end/Layer0.test.ts +60 -0
- package/test/end-to-end/Layer0MixedConnectionTypes.test.ts +94 -0
- package/test/end-to-end/Layer0WebRTC-Layer1.test.ts +134 -0
- package/test/end-to-end/Layer0WebRTC.test.ts +98 -0
- package/test/end-to-end/Layer1-Scale-WebRTC.test.ts +69 -0
- package/test/end-to-end/Layer1-Scale-WebSocket.test.ts +73 -0
- package/test/end-to-end/WebSocketConnectionRequest.test.ts +62 -0
- package/test/integration/ConnectionLocking.test.ts +166 -0
- package/test/integration/ConnectionManager.test.ts +291 -0
- package/test/integration/DhtNodeExternalAPI.test.ts +43 -0
- package/test/integration/DhtPeer.test.ts +73 -0
- package/test/integration/DhtRpc.test.ts +131 -0
- package/test/integration/DhtWithMockConnectionLatencies.test.ts +46 -0
- package/test/integration/DhtWithMockConnections.test.ts +46 -0
- package/test/integration/DhtWithRealConnectionLatencies.test.ts +47 -0
- package/test/integration/Layer1-scale.test.ts +200 -0
- package/test/integration/MigrateData.test.ts +203 -0
- package/test/integration/Mock-Layer1-Layer0.test.ts +106 -0
- package/test/integration/MultipleEntryPointJoining.test.ts +105 -0
- package/test/integration/RecursiveFind.test.ts +50 -0
- package/test/integration/RemoteRouter.test.ts +83 -0
- package/test/integration/RemoteStore.test.ts +66 -0
- package/test/integration/RouteMessage.test.ts +254 -0
- package/test/integration/RpcErrors.test.ts +153 -0
- package/test/integration/ScaleDownDht.test.ts +66 -0
- package/test/integration/SimultaneousConnections.test.ts +308 -0
- package/test/integration/Store.test.ts +72 -0
- package/test/integration/StoreAndDelete.test.ts +93 -0
- package/test/integration/StoreOnDhtWithTwoNodes.test.ts +71 -0
- package/test/integration/WebRtcConnectionManagement.test.ts +205 -0
- package/test/integration/WebRtcConnectorRpc.test.ts +145 -0
- package/test/integration/WebSocket.test.ts +64 -0
- package/test/integration/WebSocketConnectionManagement.test.ts +131 -0
- package/test/integration/WebSocketConnectorRpc.test.ts +86 -0
- package/test/kademlia-simulation/data/nodeids.json +13002 -0
- package/test/kademlia-simulation/data/orderedneighbors.json +1001 -0
- package/test/unit/AddressTools.test.ts +40 -0
- package/test/unit/DuplicateDetector.test.ts +29 -0
- package/test/unit/LocalDataStore.test.ts +107 -0
- package/test/unit/PeerID.test.ts +22 -0
- package/test/unit/ProtobufMessage.test.ts +21 -0
- package/test/unit/RandomContactList.test.ts +87 -0
- package/test/unit/RecursiveFinder.test.ts +112 -0
- package/test/unit/Router.test.ts +124 -0
- package/test/unit/SortedContactList.test.ts +127 -0
- package/test/unit/UUID.test.ts +49 -0
- package/test/unit/WebSocketServer.test.ts +42 -0
- package/test/utils/mock/RecursiveFinder.ts +19 -0
- package/test/utils/mock/Router.ts +53 -0
- package/test/utils/mock/Transport.ts +26 -0
- package/test/utils/utils.ts +311 -0
- package/tsconfig.browser.json +15 -0
- package/tsconfig.jest.json +19 -0
- package/tsconfig.json +3 -0
- package/tsconfig.node.json +18 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RecursiveFinder = void 0;
|
|
4
|
+
const DhtRpc_1 = require("../../proto/packages/dht/protos/DhtRpc");
|
|
5
|
+
const PeerID_1 = require("../../helpers/PeerID");
|
|
6
|
+
const Router_1 = require("../routing/Router");
|
|
7
|
+
const RoutingSession_1 = require("../routing/RoutingSession");
|
|
8
|
+
const peerIdFromPeerDescriptor_1 = require("../../helpers/peerIdFromPeerDescriptor");
|
|
9
|
+
const utils_1 = require("@streamr/utils");
|
|
10
|
+
const RemoteRecursiveFindSession_1 = require("./RemoteRecursiveFindSession");
|
|
11
|
+
const uuid_1 = require("uuid");
|
|
12
|
+
const RecursiveFindSession_1 = require("./RecursiveFindSession");
|
|
13
|
+
const ListeningRpcCommunicator_1 = require("../../transport/ListeningRpcCommunicator");
|
|
14
|
+
const DhtRpc_client_1 = require("../../proto/packages/dht/protos/DhtRpc.client");
|
|
15
|
+
const proto_rpc_1 = require("@streamr/proto-rpc");
|
|
16
|
+
const SortedContactList_1 = require("../contact/SortedContactList");
|
|
17
|
+
const logger = new utils_1.Logger(module);
|
|
18
|
+
class RecursiveFinder {
|
|
19
|
+
constructor(config) {
|
|
20
|
+
this.ongoingSessions = new Map();
|
|
21
|
+
this.stopped = false;
|
|
22
|
+
this.rpcCommunicator = config.rpcCommunicator;
|
|
23
|
+
this.sessionTransport = config.sessionTransport;
|
|
24
|
+
this.connections = config.connections;
|
|
25
|
+
this.router = config.router;
|
|
26
|
+
this.ownPeerDescriptor = config.ownPeerDescriptor;
|
|
27
|
+
this.ownPeerId = config.ownPeerId;
|
|
28
|
+
this.serviceId = config.serviceId;
|
|
29
|
+
this.localDataStore = config.localDataStore;
|
|
30
|
+
this.addContact = config.addContact;
|
|
31
|
+
this.isPeerCloserToIdThanSelf = config.isPeerCloserToIdThanSelf;
|
|
32
|
+
this.rpcCommunicator.registerRpcMethod(DhtRpc_1.RouteMessageWrapper, DhtRpc_1.RouteMessageAck, 'findRecursively', (routedMessage) => this.findRecursively(routedMessage));
|
|
33
|
+
}
|
|
34
|
+
async startRecursiveFind(idToFind, findMode = DhtRpc_1.FindMode.NODE, excludedPeer) {
|
|
35
|
+
if (this.stopped) {
|
|
36
|
+
return { closestNodes: [] };
|
|
37
|
+
}
|
|
38
|
+
const sessionId = (0, uuid_1.v4)();
|
|
39
|
+
const recursiveFindSession = new RecursiveFindSession_1.RecursiveFindSession({
|
|
40
|
+
serviceId: sessionId,
|
|
41
|
+
rpcTransport: this.sessionTransport,
|
|
42
|
+
kademliaIdToFind: idToFind,
|
|
43
|
+
ownPeerID: this.ownPeerId,
|
|
44
|
+
waitedRoutingPathCompletions: this.connections.size > 1 ? 2 : 1,
|
|
45
|
+
mode: findMode
|
|
46
|
+
});
|
|
47
|
+
if (this.connections.size === 0) {
|
|
48
|
+
const data = this.localDataStore.getEntry(PeerID_1.PeerID.fromValue(idToFind));
|
|
49
|
+
recursiveFindSession.doReportRecursiveFindResult([this.ownPeerDescriptor], [this.ownPeerDescriptor], data ? Array.from(data.values()) : [], true);
|
|
50
|
+
return recursiveFindSession.getResults();
|
|
51
|
+
}
|
|
52
|
+
const routeMessage = this.wrapRecursiveFindRequest(idToFind, sessionId, findMode);
|
|
53
|
+
this.ongoingSessions.set(sessionId, recursiveFindSession);
|
|
54
|
+
try {
|
|
55
|
+
await (0, utils_1.runAndWaitForEvents3)([() => this.doFindRecursevily(routeMessage, excludedPeer)], [[recursiveFindSession, 'findCompleted']], 15000);
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
logger.debug(`doFindRecursively failed with error ${this.ownPeerDescriptor.nodeName} ${err}`);
|
|
59
|
+
}
|
|
60
|
+
this.findAndReportLocalData(idToFind, findMode, [], this.ownPeerDescriptor, sessionId);
|
|
61
|
+
this.ongoingSessions.delete(sessionId);
|
|
62
|
+
recursiveFindSession.stop();
|
|
63
|
+
return recursiveFindSession.getResults();
|
|
64
|
+
}
|
|
65
|
+
wrapRecursiveFindRequest(idToFind, sessionId, findMode) {
|
|
66
|
+
const targetDescriptor = {
|
|
67
|
+
kademliaId: idToFind,
|
|
68
|
+
type: DhtRpc_1.NodeType.VIRTUAL
|
|
69
|
+
};
|
|
70
|
+
const request = {
|
|
71
|
+
recursiveFindSessionId: sessionId,
|
|
72
|
+
findMode
|
|
73
|
+
};
|
|
74
|
+
const msg = {
|
|
75
|
+
messageType: DhtRpc_1.MessageType.RECURSIVE_FIND_REQUEST,
|
|
76
|
+
messageId: (0, uuid_1.v4)(),
|
|
77
|
+
serviceId: this.serviceId,
|
|
78
|
+
body: {
|
|
79
|
+
oneofKind: 'recursiveFindRequest',
|
|
80
|
+
recursiveFindRequest: request
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
const routeMessage = {
|
|
84
|
+
message: msg,
|
|
85
|
+
requestId: (0, uuid_1.v4)(),
|
|
86
|
+
destinationPeer: targetDescriptor,
|
|
87
|
+
sourcePeer: this.ownPeerDescriptor,
|
|
88
|
+
reachableThrough: [],
|
|
89
|
+
routingPath: []
|
|
90
|
+
};
|
|
91
|
+
return routeMessage;
|
|
92
|
+
}
|
|
93
|
+
findAndReportLocalData(idToFind, findMode, routingPath, sourcePeer, sessionId) {
|
|
94
|
+
if (findMode === DhtRpc_1.FindMode.DATA) {
|
|
95
|
+
const data = this.localDataStore.getEntry(PeerID_1.PeerID.fromValue(idToFind));
|
|
96
|
+
if (data.size > 0) {
|
|
97
|
+
this.reportRecursiveFindResult(routingPath, sourcePeer, sessionId, [], data, true);
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
findLocalData(idToFind, findMode) {
|
|
104
|
+
if (findMode === DhtRpc_1.FindMode.DATA) {
|
|
105
|
+
return this.localDataStore.getEntry(PeerID_1.PeerID.fromValue(idToFind));
|
|
106
|
+
}
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
reportRecursiveFindResult(routingPath, targetPeerDescriptor, serviceId, closestNodes, data, noCloserNodesFound = false) {
|
|
110
|
+
const dataEntries = data ? Array.from(data.values(), DhtRpc_1.DataEntry.create.bind(DhtRpc_1.DataEntry)) : [];
|
|
111
|
+
const isOwnPeerId = this.ownPeerId.equals(PeerID_1.PeerID.fromValue(targetPeerDescriptor.kademliaId));
|
|
112
|
+
if (isOwnPeerId && this.ongoingSessions.has(serviceId)) {
|
|
113
|
+
this.ongoingSessions.get(serviceId)
|
|
114
|
+
.doReportRecursiveFindResult(routingPath, closestNodes, dataEntries, noCloserNodesFound);
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
const remoteCommunicator = new ListeningRpcCommunicator_1.ListeningRpcCommunicator(serviceId, this.sessionTransport, { rpcRequestTimeout: 15000 });
|
|
118
|
+
const remoteSession = new RemoteRecursiveFindSession_1.RemoteRecursiveFindSession(this.ownPeerDescriptor, targetPeerDescriptor, (0, proto_rpc_1.toProtoRpcClient)(new DhtRpc_client_1.RecursiveFindSessionServiceClient(remoteCommunicator.getRpcClientTransport())), serviceId);
|
|
119
|
+
remoteSession.reportRecursiveFindResult(routingPath, closestNodes, dataEntries, noCloserNodesFound);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
doFindRecursevily(routedMessage, excludedPeer) {
|
|
123
|
+
if (this.stopped) {
|
|
124
|
+
return (0, Router_1.createRouteMessageAck)(routedMessage, 'DhtNode Stopped');
|
|
125
|
+
}
|
|
126
|
+
const idToFind = PeerID_1.PeerID.fromValue(routedMessage.destinationPeer.kademliaId);
|
|
127
|
+
const msg = routedMessage.message;
|
|
128
|
+
const recursiveFindRequest = msg?.body.oneofKind === 'recursiveFindRequest' ? msg.body.recursiveFindRequest : undefined;
|
|
129
|
+
const closestPeersToDestination = this.getClosestConnections(routedMessage.destinationPeer.kademliaId, 5);
|
|
130
|
+
const data = this.findLocalData(idToFind.value, recursiveFindRequest.findMode);
|
|
131
|
+
if (this.ownPeerId.equals(idToFind)) {
|
|
132
|
+
this.reportRecursiveFindResult(routedMessage.routingPath, routedMessage.sourcePeer, recursiveFindRequest.recursiveFindSessionId, closestPeersToDestination, data, true);
|
|
133
|
+
return (0, Router_1.createRouteMessageAck)(routedMessage);
|
|
134
|
+
}
|
|
135
|
+
const ack = this.router.doRouteMessage(routedMessage, RoutingSession_1.RoutingMode.RECURSIVE_FIND, excludedPeer);
|
|
136
|
+
if (ack.error === Router_1.RoutingErrors.NO_CANDIDATES_FOUND) {
|
|
137
|
+
logger.trace(`findRecursively Node ${this.ownPeerDescriptor.nodeName} found no candidates`);
|
|
138
|
+
this.reportRecursiveFindResult(routedMessage.routingPath, routedMessage.sourcePeer, recursiveFindRequest.recursiveFindSessionId, closestPeersToDestination, data, true);
|
|
139
|
+
}
|
|
140
|
+
else if (ack.error) {
|
|
141
|
+
return ack;
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
const noCloserContactsFound = (closestPeersToDestination.length > 0
|
|
145
|
+
&& routedMessage.previousPeer
|
|
146
|
+
&& !this.isPeerCloserToIdThanSelf(closestPeersToDestination[0], idToFind));
|
|
147
|
+
this.reportRecursiveFindResult(routedMessage.routingPath, routedMessage.sourcePeer, recursiveFindRequest.recursiveFindSessionId, closestPeersToDestination, data, noCloserContactsFound);
|
|
148
|
+
}
|
|
149
|
+
return ack;
|
|
150
|
+
}
|
|
151
|
+
getClosestConnections(kademliaId, limit) {
|
|
152
|
+
const connectedPeers = Array.from(this.connections.values());
|
|
153
|
+
const closestPeers = new SortedContactList_1.SortedContactList(PeerID_1.PeerID.fromValue(kademliaId), limit, undefined, true, undefined);
|
|
154
|
+
closestPeers.addContacts(connectedPeers);
|
|
155
|
+
return closestPeers.getClosestContacts(limit).map((peer) => peer.getPeerDescriptor());
|
|
156
|
+
}
|
|
157
|
+
// IRoutingService method
|
|
158
|
+
async findRecursively(routedMessage) {
|
|
159
|
+
if (this.stopped) {
|
|
160
|
+
return (0, Router_1.createRouteMessageAck)(routedMessage, 'findRecursively() service is not running');
|
|
161
|
+
}
|
|
162
|
+
else if (this.router.checkDuplicate(routedMessage.requestId)) {
|
|
163
|
+
return (0, Router_1.createRouteMessageAck)(routedMessage, 'message given to findRecursively() service is likely a duplicate');
|
|
164
|
+
}
|
|
165
|
+
const senderKey = (0, peerIdFromPeerDescriptor_1.keyFromPeerDescriptor)(routedMessage.previousPeer || routedMessage.sourcePeer);
|
|
166
|
+
logger.trace(`Node ${this.ownPeerId.toKey()} received findRecursively call from ${senderKey}`);
|
|
167
|
+
this.addContact(routedMessage.sourcePeer, true);
|
|
168
|
+
this.router.addToDuplicateDetector(routedMessage.requestId, (0, peerIdFromPeerDescriptor_1.keyFromPeerDescriptor)(routedMessage.sourcePeer));
|
|
169
|
+
return this.doFindRecursevily(routedMessage);
|
|
170
|
+
}
|
|
171
|
+
stop() {
|
|
172
|
+
this.stopped = true;
|
|
173
|
+
this.ongoingSessions.forEach((session, _id) => {
|
|
174
|
+
session.stop();
|
|
175
|
+
});
|
|
176
|
+
this.ongoingSessions.clear();
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
exports.RecursiveFinder = RecursiveFinder;
|
|
180
|
+
//# sourceMappingURL=RecursiveFinder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RecursiveFinder.js","sourceRoot":"","sources":["../../../../src/dht/find/RecursiveFinder.ts"],"names":[],"mappings":";;;AAAA,mEAU+C;AAC/C,iDAAwD;AACxD,8CAAiF;AACjF,8DAAuD;AACvD,qFAA8E;AAC9E,0CAA6D;AAE7D,6EAAyE;AACzE,+BAAyB;AACzB,iEAAyF;AAKzF,uFAAmF;AACnF,iFAAiG;AACjG,kDAAqD;AACrD,oEAAgE;AAuBhE,MAAM,MAAM,GAAG,IAAI,cAAM,CAAC,MAAM,CAAC,CAAA;AAEjC,MAAa,eAAe;IAexB,YAAY,MAA6B;QAHjC,oBAAe,GAAsC,IAAI,GAAG,EAAE,CAAA;QAC9D,YAAO,GAAG,KAAK,CAAA;QAGnB,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC,eAAe,CAAA;QAC7C,IAAI,CAAC,gBAAgB,GAAG,MAAM,CAAC,gBAAgB,CAAA;QAC/C,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,CAAA;QACrC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAA;QAC3B,IAAI,CAAC,iBAAiB,GAAG,MAAM,CAAC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AA,gDAAqB,EAAC,aAAa,CAAC,YAAY,IAAI,aAAa,CAAC,UAAW,CAAC,CAAA;QAChG,MAAM,CAAC,KAAK,CAAC,QAAQ,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,uCAAuC,SAAS,EAAE,CAAC,CAAA;QAC9F,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,UAAW,EAAE,IAAI,CAAC,CAAA;QAChD,IAAI,CAAC,MAAO,CAAC,sBAAsB,CAAC,aAAa,CAAC,SAAS,EAAE,IAAA,gDAAqB,EAAC,aAAa,CAAC,UAAW,CAAC,CAAC,CAAA;QAC9G,OAAO,IAAI,CAAC,iBAAiB,CAAC,aAAa,CAAC,CAAA;IAChD,CAAC;IAEM,IAAI;QACP,IAAI,CAAC,OAAO,GAAG,IAAI,CAAA;QACnB,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,GAAG,EAAE,EAAE;YAC1C,OAAO,CAAC,IAAI,EAAE,CAAA;QAClB,CAAC,CAAC,CAAA;QACF,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,CAAA;IAChC,CAAC;CACJ;AA3ND,0CA2NC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DataEntry, PeerDescriptor } from '../../proto/packages/dht/protos/DhtRpc';
|
|
2
|
+
import { IRecursiveFindSessionServiceClient } from '../../proto/packages/dht/protos/DhtRpc.client';
|
|
3
|
+
import { Remote } from '../contact/Remote';
|
|
4
|
+
export declare class RemoteRecursiveFindSession extends Remote<IRecursiveFindSessionServiceClient> {
|
|
5
|
+
reportRecursiveFindResult(routingPath: PeerDescriptor[], closestNodes: PeerDescriptor[], dataEntries: DataEntry[], noCloserNodesFound: boolean): void;
|
|
6
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RemoteRecursiveFindSession = void 0;
|
|
4
|
+
const utils_1 = require("@streamr/utils");
|
|
5
|
+
const Remote_1 = require("../contact/Remote");
|
|
6
|
+
const logger = new utils_1.Logger(module);
|
|
7
|
+
class RemoteRecursiveFindSession extends Remote_1.Remote {
|
|
8
|
+
reportRecursiveFindResult(routingPath, closestNodes, dataEntries, noCloserNodesFound) {
|
|
9
|
+
const report = {
|
|
10
|
+
routingPath,
|
|
11
|
+
nodes: closestNodes,
|
|
12
|
+
dataEntries,
|
|
13
|
+
noCloserNodesFound
|
|
14
|
+
};
|
|
15
|
+
const options = {
|
|
16
|
+
sourceDescriptor: this.ownPeerDescriptor,
|
|
17
|
+
targetDescriptor: this.peerDescriptor
|
|
18
|
+
};
|
|
19
|
+
this.client.reportRecursiveFindResult(report, options).catch((_e) => {
|
|
20
|
+
logger.trace('Failed to send RecursiveFindResult');
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.RemoteRecursiveFindSession = RemoteRecursiveFindSession;
|
|
25
|
+
//# sourceMappingURL=RemoteRecursiveFindSession.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RemoteRecursiveFindSession.js","sourceRoot":"","sources":["../../../../src/dht/find/RemoteRecursiveFindSession.ts"],"names":[],"mappings":";;;AAOA,0CAAuC;AACvC,8CAA0C;AAE1C,MAAM,MAAM,GAAG,IAAI,cAAM,CAAC,MAAM,CAAC,CAAA;AAEjC,MAAa,0BAA2B,SAAQ,eAA0C;IAEtF,yBAAyB,CAAC,WAA6B,EAAE,YAA8B,EACnF,WAAwB,EAAE,kBAA2B;QAErD,MAAM,MAAM,GAAwB;YAChC,WAAW;YACX,KAAK,EAAE,YAAY;YACnB,WAAW;YACX,kBAAkB;SACrB,CAAA;QACD,MAAM,OAAO,GAAkB;YAC3B,gBAAgB,EAAE,IAAI,CAAC,iBAAiB;YACxC,gBAAgB,EAAE,IAAI,CAAC,cAAc;SACxC,CAAA;QAED,IAAI,CAAC,MAAM,CAAC,yBAAyB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,EAAE;YAChE,MAAM,CAAC,KAAK,CAAC,oCAAoC,CAAC,CAAA;QACtD,CAAC,CAAC,CAAA;IACN,CAAC;CACJ;AApBD,gEAoBC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Message } from '../../proto/packages/dht/protos/DhtRpc';
|
|
2
|
+
export declare class DuplicateDetector {
|
|
3
|
+
private values;
|
|
4
|
+
private queue;
|
|
5
|
+
private maxAge;
|
|
6
|
+
private maxNumberOfValues;
|
|
7
|
+
constructor(maxNumberOfValues: number, maxAgeInSeconds: number);
|
|
8
|
+
add(value: string, senderId: string, message?: Message): void;
|
|
9
|
+
isMostLikelyDuplicate(value: string): boolean;
|
|
10
|
+
private cleanUp;
|
|
11
|
+
size(): number;
|
|
12
|
+
clear(): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DuplicateDetector = void 0;
|
|
4
|
+
class DuplicateDetector {
|
|
5
|
+
constructor(maxNumberOfValues, maxAgeInSeconds) {
|
|
6
|
+
this.values = new Set();
|
|
7
|
+
this.queue = [];
|
|
8
|
+
this.maxNumberOfValues = maxNumberOfValues;
|
|
9
|
+
this.maxAge = maxAgeInSeconds * 1000;
|
|
10
|
+
}
|
|
11
|
+
add(value, senderId, message) {
|
|
12
|
+
this.values.add(value);
|
|
13
|
+
if (message) {
|
|
14
|
+
this.queue.push([Date.now(), value, senderId, message]);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
this.queue.push([Date.now(), value, senderId]);
|
|
18
|
+
}
|
|
19
|
+
this.cleanUp();
|
|
20
|
+
}
|
|
21
|
+
isMostLikelyDuplicate(value) {
|
|
22
|
+
return this.values.has(value);
|
|
23
|
+
}
|
|
24
|
+
cleanUp() {
|
|
25
|
+
const currentTime = Date.now();
|
|
26
|
+
while (this.queue.length > 0 && (this.queue.length > this.maxNumberOfValues ||
|
|
27
|
+
(currentTime - this.queue[0][0]) > this.maxAge)) {
|
|
28
|
+
const oldestEntry = this.queue.shift();
|
|
29
|
+
this.values.delete(oldestEntry[1]);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
size() {
|
|
33
|
+
return this.values.size;
|
|
34
|
+
}
|
|
35
|
+
clear() {
|
|
36
|
+
this.values.clear();
|
|
37
|
+
this.queue = [];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.DuplicateDetector = DuplicateDetector;
|
|
41
|
+
//# sourceMappingURL=DuplicateDetector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DuplicateDetector.js","sourceRoot":"","sources":["../../../../src/dht/routing/DuplicateDetector.ts"],"names":[],"mappings":";;;AAIA,MAAa,iBAAiB;IAO1B,YACI,iBAAyB,EACzB,eAAuB;QAPnB,WAAM,GAAgB,IAAI,GAAG,EAAE,CAAA;QAC/B,UAAK,GAAsB,EAAE,CAAA;QAQjC,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAA;QAC1C,IAAI,CAAC,MAAM,GAAG,eAAe,GAAG,IAAI,CAAA;IACxC,CAAC;IAEM,GAAG,CAAC,KAAa,EAAE,QAAgB,EAAE,OAAiB;QACzD,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;QACtB,IAAI,OAAO,EAAE;YACT,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAA;SAC1D;aAAM;YACH,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAA;SACjD;QACD,IAAI,CAAC,OAAO,EAAE,CAAA;IAClB,CAAC;IAEM,qBAAqB,CAAC,KAAa;QACtC,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;IACjC,CAAC;IAEO,OAAO;QACX,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QAE9B,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,iBAAiB;YACvE,CAAC,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,EAAE;YACjD,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAA;YACtC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,WAAY,CAAC,CAAC,CAAC,CAAC,CAAA;SACtC;IACL,CAAC;IAEM,IAAI;QACP,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAA;IAC3B,CAAC;IAEM,KAAK;QACR,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAA;QACnB,IAAI,CAAC,KAAK,GAAG,EAAE,CAAA;IACnB,CAAC;CAEJ;AAhDD,8CAgDC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { RouteMessageWrapper } from '../../proto/packages/dht/protos/DhtRpc';
|
|
2
|
+
import { IRoutingServiceClient } from '../../proto/packages/dht/protos/DhtRpc.client';
|
|
3
|
+
import { Remote } from '../contact/Remote';
|
|
4
|
+
export declare class RemoteRouter extends Remote<IRoutingServiceClient> {
|
|
5
|
+
routeMessage(params: RouteMessageWrapper): Promise<boolean>;
|
|
6
|
+
forwardMessage(params: RouteMessageWrapper): Promise<boolean>;
|
|
7
|
+
findRecursively(params: RouteMessageWrapper): Promise<boolean>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RemoteRouter = void 0;
|
|
4
|
+
const uuid_1 = require("uuid");
|
|
5
|
+
const peerIdFromPeerDescriptor_1 = require("../../helpers/peerIdFromPeerDescriptor");
|
|
6
|
+
const Remote_1 = require("../contact/Remote");
|
|
7
|
+
const utils_1 = require("@streamr/utils");
|
|
8
|
+
const logger = new utils_1.Logger(module);
|
|
9
|
+
class RemoteRouter extends Remote_1.Remote {
|
|
10
|
+
async routeMessage(params) {
|
|
11
|
+
const message = {
|
|
12
|
+
destinationPeer: params.destinationPeer,
|
|
13
|
+
sourcePeer: params.sourcePeer,
|
|
14
|
+
previousPeer: params.previousPeer,
|
|
15
|
+
message: params.message,
|
|
16
|
+
requestId: params.requestId || (0, uuid_1.v4)(),
|
|
17
|
+
reachableThrough: params.reachableThrough || [],
|
|
18
|
+
routingPath: params.routingPath
|
|
19
|
+
};
|
|
20
|
+
const options = {
|
|
21
|
+
sourceDescriptor: params.previousPeer,
|
|
22
|
+
targetDescriptor: this.peerDescriptor,
|
|
23
|
+
timeout: 10000
|
|
24
|
+
};
|
|
25
|
+
try {
|
|
26
|
+
logger.trace('calling dhtClient.routeMessage');
|
|
27
|
+
const ack = await this.client.routeMessage(message, options);
|
|
28
|
+
logger.trace('dhtClient.routeMessage returned');
|
|
29
|
+
// Success signal if sent to destination and error includes duplicate
|
|
30
|
+
if ((0, peerIdFromPeerDescriptor_1.isSamePeerDescriptor)(params.destinationPeer, this.peerDescriptor)
|
|
31
|
+
&& ack.error.includes('duplicate')) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
else if (ack.error.length > 0) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
catch (err) {
|
|
39
|
+
const fromNode = params.previousPeer ?
|
|
40
|
+
(0, peerIdFromPeerDescriptor_1.peerIdFromPeerDescriptor)(params.previousPeer) : (0, peerIdFromPeerDescriptor_1.keyFromPeerDescriptor)(params.sourcePeer);
|
|
41
|
+
logger.debug(`Failed to send routeMessage from ${fromNode} to ${this.peerId.toKey()} with: ${err}`);
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
async forwardMessage(params) {
|
|
47
|
+
const message = {
|
|
48
|
+
destinationPeer: params.destinationPeer,
|
|
49
|
+
sourcePeer: params.sourcePeer,
|
|
50
|
+
previousPeer: params.previousPeer,
|
|
51
|
+
message: params.message,
|
|
52
|
+
requestId: params.requestId || (0, uuid_1.v4)(),
|
|
53
|
+
reachableThrough: params.reachableThrough || [],
|
|
54
|
+
routingPath: params.routingPath
|
|
55
|
+
};
|
|
56
|
+
const options = {
|
|
57
|
+
sourceDescriptor: params.previousPeer,
|
|
58
|
+
targetDescriptor: this.peerDescriptor,
|
|
59
|
+
timeout: 10000
|
|
60
|
+
};
|
|
61
|
+
try {
|
|
62
|
+
const ack = await this.client.forwardMessage(message, options);
|
|
63
|
+
if (ack.error.length > 0) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
const fromNode = params.previousPeer ?
|
|
69
|
+
(0, peerIdFromPeerDescriptor_1.keyFromPeerDescriptor)(params.previousPeer) : (0, peerIdFromPeerDescriptor_1.keyFromPeerDescriptor)(params.sourcePeer);
|
|
70
|
+
logger.debug(`Failed to send forwardMessage from ${fromNode} to ${this.peerId.toKey()} with: ${err}`);
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
async findRecursively(params) {
|
|
76
|
+
const message = {
|
|
77
|
+
destinationPeer: params.destinationPeer,
|
|
78
|
+
sourcePeer: params.sourcePeer,
|
|
79
|
+
previousPeer: params.previousPeer,
|
|
80
|
+
message: params.message,
|
|
81
|
+
requestId: params.requestId || (0, uuid_1.v4)(),
|
|
82
|
+
reachableThrough: params.reachableThrough || [],
|
|
83
|
+
routingPath: params.routingPath
|
|
84
|
+
};
|
|
85
|
+
const options = {
|
|
86
|
+
sourceDescriptor: params.previousPeer,
|
|
87
|
+
targetDescriptor: this.peerDescriptor,
|
|
88
|
+
timeout: 10000
|
|
89
|
+
};
|
|
90
|
+
try {
|
|
91
|
+
const ack = await this.client.findRecursively(message, options);
|
|
92
|
+
if (ack.error.length > 0) {
|
|
93
|
+
logger.debug('Next hop responded with error ' + ack.error);
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
catch (err) {
|
|
98
|
+
const fromNode = params.previousPeer ? (0, peerIdFromPeerDescriptor_1.keyFromPeerDescriptor)(params.previousPeer) : (0, peerIdFromPeerDescriptor_1.keyFromPeerDescriptor)(params.sourcePeer);
|
|
99
|
+
logger.debug(`Failed to send recursiveFind message from ${fromNode} to ${this.peerId.toKey()} with: ${err}`);
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
exports.RemoteRouter = RemoteRouter;
|
|
106
|
+
//# sourceMappingURL=RemoteRouter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RemoteRouter.js","sourceRoot":"","sources":["../../../../src/dht/routing/RemoteRouter.ts"],"names":[],"mappings":";;;AACA,+BAAyB;AAEzB,qFAI+C;AAE/C,8CAA0C;AAC1C,0CAAuC;AAEvC,MAAM,MAAM,GAAG,IAAI,cAAM,CAAC,MAAM,CAAC,CAAA;AAEjC,MAAa,YAAa,SAAQ,eAA6B;IAE3D,KAAK,CAAC,YAAY,CAAC,MAA2B;QAC1C,MAAM,OAAO,GAAwB;YACjC,eAAe,EAAE,MAAM,CAAC,eAAe;YACvC,UAAU,EAAE,MAAM,CAAC,UAAU;YAC7B,YAAY,EAAE,MAAM,CAAC,YAAY;YACjC,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,SAAS,EAAE,MAAM,CAAC,SAAS,IAAI,IAAA,SAAE,GAAE;YACnC,gBAAgB,EAA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YACnC,gBAAgB,EAAE,MAAM,CAAC,gBAAgB,IAAI,EAAE;YAC/C,WAAW,EAAE,MAAM,CAAC,WAAW;SAClC,CAAA;QACD,MAAM,OAAO,GAAkB;YAC3B,gBAAgB,EAAE,MAAM,CAAC,YAA8B;YACvD,gBAAgB,EAAE,IAAI,CAAC,cAAgC;YACvD,OAAO,EAAE,KAAK;SACjB,CAAA;QACD,IAAI;YACA,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;YAC/D,IAAI,GAAG,CAAC,KAAM,CAAC,MAAM,GAAG,CAAC,EAAE;gBACvB,MAAM,CAAC,KAAK,CAAC,gCAAgC,GAAG,GAAG,CAAC,KAAK,CAAC,CAAA;gBAC1D,OAAO,KAAK,CAAA;aACf;SACJ;QAAC,OAAO,GAAG,EAAE;YACV,MAAM,QAAQ,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,IAAA,gDAAqB,EAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAA,gDAAqB,EAAC,MAAM,CAAC,UAAW,CAAC,CAAA;YAC7H,MAAM,CAAC,KAAK,CAAC,6CAA6C,QAAQ,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,EAAE,CAAC,CAAA;YAC5G,OAAO,KAAK,CAAA;SACf;QACD,OAAO,IAAI,CAAA;IACf,CAAC;CAEJ;AApGD,oCAoGC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Message, PeerDescriptor, RouteMessageAck, RouteMessageWrapper } from '../../proto/packages/dht/protos/DhtRpc';
|
|
2
|
+
import { ServerCallContext } from '@protobuf-ts/runtime-rpc';
|
|
3
|
+
import { RoutingMode, RoutingSession } from './RoutingSession';
|
|
4
|
+
import { RoutingRpcCommunicator } from '../../transport/RoutingRpcCommunicator';
|
|
5
|
+
import { PeerID, PeerIDKey } from '../../helpers/PeerID';
|
|
6
|
+
import { ConnectionManager } from '../../connection/ConnectionManager';
|
|
7
|
+
import { DhtPeer } from '../DhtPeer';
|
|
8
|
+
import { IRoutingService } from '../../proto/packages/dht/protos/DhtRpc.server';
|
|
9
|
+
export declare const createRouteMessageAck: (routedMessage: RouteMessageWrapper, error?: string) => RouteMessageAck;
|
|
10
|
+
export declare enum RoutingErrors {
|
|
11
|
+
NO_CANDIDATES_FOUND = "No routing candidates found",
|
|
12
|
+
STOPPED = "DhtNode Stopped"
|
|
13
|
+
}
|
|
14
|
+
export interface RouterConfig {
|
|
15
|
+
rpcCommunicator: RoutingRpcCommunicator;
|
|
16
|
+
ownPeerDescriptor: PeerDescriptor;
|
|
17
|
+
ownPeerId: PeerID;
|
|
18
|
+
connections: Map<PeerIDKey, DhtPeer>;
|
|
19
|
+
addContact: (contact: PeerDescriptor, setActive?: boolean) => void;
|
|
20
|
+
serviceId: string;
|
|
21
|
+
connectionManager?: ConnectionManager;
|
|
22
|
+
}
|
|
23
|
+
interface IRouterFunc {
|
|
24
|
+
doRouteMessage(routedMessage: RouteMessageWrapper, mode: RoutingMode, excludedPeer?: PeerDescriptor): RouteMessageAck;
|
|
25
|
+
send(msg: Message, reachableThrough: PeerDescriptor[]): Promise<void>;
|
|
26
|
+
checkDuplicate(messageId: string): boolean;
|
|
27
|
+
addToDuplicateDetector(messageId: string, senderId: string, message?: Message): void;
|
|
28
|
+
addRoutingSession(session: RoutingSession): void;
|
|
29
|
+
removeRoutingSession(sessionId: string): void;
|
|
30
|
+
stop(): void;
|
|
31
|
+
}
|
|
32
|
+
export interface IRouter extends Omit<IRoutingService, 'findRecursively'>, IRouterFunc {
|
|
33
|
+
}
|
|
34
|
+
export declare class Router implements IRouter {
|
|
35
|
+
private readonly rpcCommunicator;
|
|
36
|
+
private readonly ownPeerDescriptor;
|
|
37
|
+
private readonly ownPeerId;
|
|
38
|
+
private readonly connections;
|
|
39
|
+
private readonly addContact;
|
|
40
|
+
private readonly serviceId;
|
|
41
|
+
private readonly connectionManager?;
|
|
42
|
+
private readonly forwardingTable;
|
|
43
|
+
private ongoingRoutingSessions;
|
|
44
|
+
private readonly routerDuplicateDetector;
|
|
45
|
+
private stopped;
|
|
46
|
+
constructor(config: RouterConfig);
|
|
47
|
+
send(msg: Message, reachableThrough: PeerDescriptor[]): Promise<void>;
|
|
48
|
+
doRouteMessage(routedMessage: RouteMessageWrapper, mode?: RoutingMode, excludedPeer?: PeerDescriptor): RouteMessageAck;
|
|
49
|
+
private createRoutingSession;
|
|
50
|
+
checkDuplicate(messageId: string): boolean;
|
|
51
|
+
addToDuplicateDetector(messageId: string, senderId: string, message?: Message): void;
|
|
52
|
+
addRoutingSession(session: RoutingSession): void;
|
|
53
|
+
removeRoutingSession(sessionId: string): void;
|
|
54
|
+
stop(): void;
|
|
55
|
+
routeMessage(routedMessage: RouteMessageWrapper, _context: ServerCallContext): Promise<RouteMessageAck>;
|
|
56
|
+
private setForwardingEntries;
|
|
57
|
+
forwardMessage(forwardMessage: RouteMessageWrapper, _context: ServerCallContext): Promise<RouteMessageAck>;
|
|
58
|
+
private forwardToDestination;
|
|
59
|
+
}
|
|
60
|
+
export {};
|