@streamr/dht 101.1.2 → 102.0.0-beta.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 +1 -1
- package/dist/{src/proto → generated}/google/protobuf/any.d.ts +11 -4
- package/dist/generated/google/protobuf/any.js.map +1 -0
- package/dist/{src/proto → generated}/google/protobuf/empty.d.ts +0 -1
- package/dist/generated/google/protobuf/empty.js.map +1 -0
- package/dist/{src/proto → generated}/google/protobuf/timestamp.d.ts +9 -3
- package/dist/generated/google/protobuf/timestamp.js.map +1 -0
- package/dist/{src/proto → generated}/packages/dht/protos/DhtRpc.client.d.ts +9 -0
- package/dist/{src/proto → generated}/packages/dht/protos/DhtRpc.client.js +7 -0
- package/dist/generated/packages/dht/protos/DhtRpc.client.js.map +1 -0
- package/dist/{src/proto → generated}/packages/dht/protos/DhtRpc.d.ts +16 -0
- package/dist/{src/proto → generated}/packages/dht/protos/DhtRpc.js +16 -2
- package/dist/generated/packages/dht/protos/DhtRpc.js.map +1 -0
- package/dist/{src/proto → generated}/packages/dht/protos/DhtRpc.server.d.ts +5 -0
- package/dist/generated/packages/dht/protos/DhtRpc.server.js.map +1 -0
- package/dist/generated/packages/proto-rpc/protos/ProtoRpc.js.map +1 -0
- package/dist/package.json +11 -11
- package/dist/src/connection/Connection.d.ts +1 -1
- package/dist/src/connection/ConnectionLockRpcLocal.d.ts +5 -3
- package/dist/src/connection/ConnectionLockRpcLocal.js +9 -3
- package/dist/src/connection/ConnectionLockRpcLocal.js.map +1 -1
- package/dist/src/connection/ConnectionLockRpcRemote.d.ts +3 -2
- package/dist/src/connection/ConnectionLockRpcRemote.js +14 -3
- package/dist/src/connection/ConnectionLockRpcRemote.js.map +1 -1
- package/dist/src/connection/ConnectionLockStates.d.ts +5 -0
- package/dist/src/connection/ConnectionLockStates.js +14 -0
- package/dist/src/connection/ConnectionLockStates.js.map +1 -1
- package/dist/src/connection/ConnectionManager.d.ts +8 -1
- package/dist/src/connection/ConnectionManager.js +78 -24
- package/dist/src/connection/ConnectionManager.js.map +1 -1
- package/dist/src/connection/ConnectionsView.d.ts +1 -1
- package/dist/src/connection/ConnectorFacade.d.ts +1 -1
- package/dist/src/connection/Handshaker.d.ts +1 -1
- package/dist/src/connection/Handshaker.js +2 -2
- package/dist/src/connection/Handshaker.js.map +1 -1
- package/dist/src/connection/ManagedConnection.d.ts +7 -1
- package/dist/src/connection/ManagedConnection.js +24 -1
- package/dist/src/connection/ManagedConnection.js.map +1 -1
- package/dist/src/connection/PendingConnection.d.ts +1 -1
- package/dist/src/connection/connectivityChecker.d.ts +1 -1
- package/dist/src/connection/connectivityChecker.js +2 -1
- package/dist/src/connection/connectivityChecker.js.map +1 -1
- package/dist/src/connection/connectivityRequestHandler.js +1 -1
- package/dist/src/connection/connectivityRequestHandler.js.map +1 -1
- package/dist/src/connection/simulator/Simulator.d.ts +1 -1
- package/dist/src/connection/simulator/Simulator.js +2 -2
- package/dist/src/connection/simulator/Simulator.js.map +1 -1
- package/dist/src/connection/simulator/SimulatorConnection.d.ts +1 -1
- package/dist/src/connection/simulator/SimulatorConnection.js +9 -9
- package/dist/src/connection/simulator/SimulatorConnection.js.map +1 -1
- package/dist/src/connection/simulator/SimulatorConnector.d.ts +1 -1
- package/dist/src/connection/simulator/SimulatorConnector.js +4 -4
- package/dist/src/connection/simulator/SimulatorConnector.js.map +1 -1
- package/dist/src/connection/simulator/SimulatorTransport.d.ts +1 -1
- package/dist/src/connection/simulator/SimulatorTransport.js +2 -1
- package/dist/src/connection/simulator/SimulatorTransport.js.map +1 -1
- package/dist/src/connection/webrtc/NodeWebrtcConnection.d.ts +2 -1
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js +13 -6
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnector.d.ts +2 -1
- package/dist/src/connection/webrtc/WebrtcConnector.js +9 -8
- package/dist/src/connection/webrtc/WebrtcConnector.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.d.ts +3 -3
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js +4 -4
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.d.ts +1 -1
- package/dist/src/connection/websocket/AbstractWebsocketClientConnection.d.ts +1 -0
- package/dist/src/connection/websocket/WebsocketClientConnector.d.ts +1 -1
- package/dist/src/connection/websocket/WebsocketClientConnector.js +3 -3
- package/dist/src/connection/websocket/WebsocketClientConnector.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketClientConnectorRpcLocal.d.ts +3 -3
- package/dist/src/connection/websocket/WebsocketClientConnectorRpcLocal.js +1 -1
- package/dist/src/connection/websocket/WebsocketClientConnectorRpcLocal.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketClientConnectorRpcRemote.d.ts +1 -1
- package/dist/src/connection/websocket/WebsocketClientConnectorRpcRemote.js +1 -1
- package/dist/src/connection/websocket/WebsocketClientConnectorRpcRemote.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketServerConnector.d.ts +1 -1
- package/dist/src/connection/websocket/WebsocketServerConnector.js +7 -7
- package/dist/src/connection/websocket/WebsocketServerConnector.js.map +1 -1
- package/dist/src/dht/DhtNode.d.ts +4 -2
- package/dist/src/dht/DhtNode.js +17 -6
- package/dist/src/dht/DhtNode.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcLocal.d.ts +3 -3
- package/dist/src/dht/DhtNodeRpcLocal.js +3 -3
- package/dist/src/dht/DhtNodeRpcLocal.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcRemote.d.ts +2 -2
- package/dist/src/dht/DhtNodeRpcRemote.js +3 -3
- package/dist/src/dht/DhtNodeRpcRemote.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcLocal.d.ts +3 -3
- package/dist/src/dht/ExternalApiRpcLocal.js +3 -3
- package/dist/src/dht/ExternalApiRpcLocal.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcRemote.d.ts +3 -3
- package/dist/src/dht/ExternalApiRpcRemote.js +2 -2
- package/dist/src/dht/ExternalApiRpcRemote.js.map +1 -1
- package/dist/src/dht/PeerManager.d.ts +1 -1
- package/dist/src/dht/PeerManager.js +10 -10
- package/dist/src/dht/PeerManager.js.map +1 -1
- package/dist/src/dht/contact/Contact.d.ts +1 -1
- package/dist/src/dht/contact/Contact.js +1 -1
- package/dist/src/dht/contact/Contact.js.map +1 -1
- package/dist/src/dht/contact/RingContactList.d.ts +1 -1
- package/dist/src/dht/contact/RingContactList.js +1 -1
- package/dist/src/dht/contact/RingContactList.js.map +1 -1
- package/dist/src/dht/contact/RpcRemote.d.ts +1 -1
- package/dist/src/dht/contact/SortedContactList.js +1 -1
- package/dist/src/dht/contact/SortedContactList.js.map +1 -1
- package/dist/src/dht/contact/ringIdentifiers.d.ts +1 -1
- package/dist/src/dht/discovery/DiscoverySession.d.ts +1 -1
- package/dist/src/dht/discovery/DiscoverySession.js +3 -3
- package/dist/src/dht/discovery/DiscoverySession.js.map +1 -1
- package/dist/src/dht/discovery/PeerDiscovery.d.ts +1 -1
- package/dist/src/dht/discovery/PeerDiscovery.js +7 -7
- package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -1
- package/dist/src/dht/discovery/RingDiscoverySession.js +1 -1
- package/dist/src/dht/discovery/RingDiscoverySession.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.d.ts +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.js +8 -8
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.d.ts +2 -2
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.js +2 -2
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.d.ts +2 -2
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js +3 -3
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.d.ts +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.js +7 -7
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.d.ts +3 -3
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.d.ts +2 -2
- package/dist/src/dht/routing/Router.d.ts +4 -1
- package/dist/src/dht/routing/Router.js +17 -9
- package/dist/src/dht/routing/Router.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcLocal.d.ts +2 -2
- package/dist/src/dht/routing/RouterRpcLocal.js +5 -5
- package/dist/src/dht/routing/RouterRpcLocal.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcRemote.d.ts +2 -2
- package/dist/src/dht/routing/RouterRpcRemote.js +7 -7
- package/dist/src/dht/routing/RouterRpcRemote.js.map +1 -1
- package/dist/src/dht/routing/RoutingSession.d.ts +1 -1
- package/dist/src/dht/routing/RoutingSession.js +5 -6
- package/dist/src/dht/routing/RoutingSession.js.map +1 -1
- package/dist/src/dht/routing/getPreviousPeer.d.ts +1 -1
- package/dist/src/dht/store/LocalDataStore.d.ts +1 -1
- package/dist/src/dht/store/LocalDataStore.js +2 -2
- package/dist/src/dht/store/LocalDataStore.js.map +1 -1
- package/dist/src/dht/store/StoreManager.d.ts +2 -2
- package/dist/src/dht/store/StoreManager.js +8 -8
- package/dist/src/dht/store/StoreManager.js.map +1 -1
- package/dist/src/dht/store/StoreRpcLocal.d.ts +3 -3
- package/dist/src/dht/store/StoreRpcLocal.js +4 -4
- package/dist/src/dht/store/StoreRpcLocal.js.map +1 -1
- package/dist/src/dht/store/StoreRpcRemote.d.ts +3 -3
- package/dist/src/dht/store/StoreRpcRemote.js +7 -4
- package/dist/src/dht/store/StoreRpcRemote.js.map +1 -1
- package/dist/src/exports.d.ts +2 -2
- package/dist/src/exports.js +6 -6
- package/dist/src/exports.js.map +1 -1
- package/dist/src/helpers/Connectivity.d.ts +1 -1
- package/dist/src/helpers/Connectivity.js +1 -1
- package/dist/src/helpers/Connectivity.js.map +1 -1
- package/dist/src/helpers/createPeerDescriptor.d.ts +1 -1
- package/dist/src/helpers/createPeerDescriptor.js +2 -2
- package/dist/src/helpers/createPeerDescriptor.js.map +1 -1
- package/dist/src/helpers/createPeerDescriptorSignaturePayload.d.ts +1 -1
- package/dist/src/helpers/createPeerDescriptorSignaturePayload.js +1 -1
- package/dist/src/helpers/createPeerDescriptorSignaturePayload.js.map +1 -1
- package/dist/src/helpers/protoClasses.js +1 -1
- package/dist/src/helpers/protoClasses.js.map +1 -1
- package/dist/src/identifiers.d.ts +5 -5
- package/dist/src/identifiers.js +11 -11
- package/dist/src/identifiers.js.map +1 -1
- package/dist/src/rpc-protocol/DhtCallContext.d.ts +1 -1
- package/dist/src/rpc-protocol/DhtRpcOptions.d.ts +1 -1
- package/dist/src/transport/ITransport.d.ts +2 -1
- package/dist/src/transport/ListeningRpcCommunicator.d.ts +2 -1
- package/dist/src/transport/ListeningRpcCommunicator.js +13 -4
- package/dist/src/transport/ListeningRpcCommunicator.js.map +1 -1
- package/dist/src/transport/RoutingRpcCommunicator.d.ts +1 -1
- package/{src/proto → generated}/google/protobuf/any.ts +11 -4
- package/{src/proto → generated}/google/protobuf/empty.ts +0 -1
- package/{src/proto → generated}/google/protobuf/timestamp.ts +9 -3
- package/{src/proto → generated}/packages/dht/protos/DhtRpc.client.ts +12 -0
- package/{src/proto → generated}/packages/dht/protos/DhtRpc.server.ts +5 -0
- package/{src/proto → generated}/packages/dht/protos/DhtRpc.ts +23 -1
- package/package.json +11 -11
- package/proto.sh +2 -3
- package/protos/DhtRpc.proto +5 -0
- package/src/connection/Connection.ts +1 -1
- package/src/connection/ConnectionLockRpcLocal.ts +16 -7
- package/src/connection/ConnectionLockRpcRemote.ts +18 -6
- package/src/connection/ConnectionLockStates.ts +18 -0
- package/src/connection/ConnectionManager.ts +92 -26
- package/src/connection/ConnectionsView.ts +1 -1
- package/src/connection/ConnectorFacade.ts +1 -1
- package/src/connection/Handshaker.ts +3 -3
- package/src/connection/ManagedConnection.ts +28 -3
- package/src/connection/PendingConnection.ts +1 -1
- package/src/connection/connectivityChecker.ts +2 -1
- package/src/connection/connectivityRequestHandler.ts +1 -1
- package/src/connection/simulator/Simulator.ts +4 -4
- package/src/connection/simulator/SimulatorConnection.ts +10 -10
- package/src/connection/simulator/SimulatorConnector.ts +5 -5
- package/src/connection/simulator/SimulatorTransport.ts +3 -2
- package/src/connection/webrtc/BrowserWebrtcConnection.ts +10 -1
- package/src/connection/webrtc/NodeWebrtcConnection.ts +15 -9
- package/src/connection/webrtc/WebrtcConnector.ts +10 -8
- package/src/connection/webrtc/WebrtcConnectorRpcLocal.ts +8 -8
- package/src/connection/webrtc/WebrtcConnectorRpcRemote.ts +2 -2
- package/src/connection/websocket/WebsocketClientConnector.ts +5 -5
- package/src/connection/websocket/WebsocketClientConnectorRpcLocal.ts +5 -5
- package/src/connection/websocket/WebsocketClientConnectorRpcRemote.ts +4 -4
- package/src/connection/websocket/WebsocketServerConnector.ts +8 -8
- package/src/dht/DhtNode.ts +21 -8
- package/src/dht/DhtNodeRpcLocal.ts +7 -7
- package/src/dht/DhtNodeRpcRemote.ts +5 -5
- package/src/dht/ExternalApiRpcLocal.ts +8 -8
- package/src/dht/ExternalApiRpcRemote.ts +6 -6
- package/src/dht/PeerManager.ts +12 -12
- package/src/dht/contact/Contact.ts +3 -3
- package/src/dht/contact/RingContactList.ts +3 -3
- package/src/dht/contact/RpcRemote.ts +1 -1
- package/src/dht/contact/SortedContactList.ts +2 -2
- package/src/dht/contact/ringIdentifiers.ts +1 -1
- package/src/dht/discovery/DiscoverySession.ts +5 -5
- package/src/dht/discovery/PeerDiscovery.ts +12 -12
- package/src/dht/discovery/RingDiscoverySession.ts +3 -3
- package/src/dht/recursive-operation/RecursiveOperationManager.ts +9 -9
- package/src/dht/recursive-operation/RecursiveOperationRpcLocal.ts +4 -4
- package/src/dht/recursive-operation/RecursiveOperationRpcRemote.ts +6 -6
- package/src/dht/recursive-operation/RecursiveOperationSession.ts +8 -8
- package/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.ts +5 -5
- package/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.ts +2 -2
- package/src/dht/routing/Router.ts +19 -10
- package/src/dht/routing/RouterRpcLocal.ts +7 -7
- package/src/dht/routing/RouterRpcRemote.ts +9 -9
- package/src/dht/routing/RoutingSession.ts +7 -8
- package/src/dht/routing/getPreviousPeer.ts +1 -1
- package/src/dht/store/LocalDataStore.ts +4 -4
- package/src/dht/store/StoreManager.ts +12 -12
- package/src/dht/store/StoreRpcLocal.ts +8 -8
- package/src/dht/store/StoreRpcRemote.ts +10 -7
- package/src/exports.ts +5 -5
- package/src/helpers/Connectivity.ts +1 -1
- package/src/helpers/createPeerDescriptor.ts +3 -3
- package/src/helpers/createPeerDescriptorSignaturePayload.ts +1 -1
- package/src/helpers/protoClasses.ts +1 -1
- package/src/identifiers.ts +7 -7
- package/src/rpc-protocol/DhtCallContext.ts +1 -1
- package/src/rpc-protocol/DhtRpcOptions.ts +1 -1
- package/src/transport/ITransport.ts +2 -1
- package/src/transport/ListeningRpcCommunicator.ts +14 -6
- package/src/transport/RoutingRpcCommunicator.ts +2 -2
- package/test/benchmark/Find.test.ts +6 -6
- package/test/benchmark/KademliaCorrectness.test.ts +5 -5
- package/test/benchmark/RingCorrectness.test.ts +5 -5
- package/test/benchmark/SortedContactListBenchmark.test.ts +10 -10
- package/test/benchmark/hybrid-network-simulation/RingContactList.test.ts +1 -1
- package/test/end-to-end/Layer0Webrtc-Layer1.test.ts +6 -6
- package/test/end-to-end/Layer0Webrtc.test.ts +6 -6
- package/test/end-to-end/RecoveryFromFailedAutoCertification.test.ts +1 -1
- package/test/end-to-end/WebsocketConnectionRequest.test.ts +1 -1
- package/test/end-to-end/memory-leak.test.ts +4 -4
- package/test/integration/ConnectionLocking.test.ts +16 -15
- package/test/integration/ConnectionManager.test.ts +62 -6
- package/test/integration/ConnectivityChecking.test.ts +2 -1
- package/test/integration/DhtJoinPeerDiscovery.test.ts +2 -2
- package/test/integration/DhtNode.test.ts +4 -4
- package/test/integration/DhtNodeExternalAPI.test.ts +7 -7
- package/test/integration/DhtNodeRpcRemote.test.ts +9 -9
- package/test/integration/DhtRpc.test.ts +12 -13
- package/test/integration/Find.test.ts +5 -5
- package/test/integration/GeoIpConnectivityChecking.test.ts +2 -1
- package/test/integration/Layer1-scale.test.ts +2 -2
- package/test/integration/Mock-Layer1-Layer0.test.ts +6 -6
- package/test/integration/MultipleEntryPointJoining.test.ts +1 -1
- package/test/integration/ReplicateData.test.ts +10 -11
- package/test/integration/RouteMessage.test.ts +9 -9
- package/test/integration/RouterRpcRemote.test.ts +7 -7
- package/test/integration/SimultaneousConnections.test.ts +13 -12
- package/test/integration/Store.test.ts +9 -9
- package/test/integration/StoreAndDelete.test.ts +10 -10
- package/test/integration/StoreOnDhtWithThreeNodes.test.ts +9 -9
- package/test/integration/StoreOnDhtWithTwoNodes.test.ts +7 -7
- package/test/integration/StoreRpcRemote.test.ts +10 -10
- package/test/integration/WebrtcConnectionManagement.test.ts +4 -3
- package/test/integration/WebrtcConnectorRpc.test.ts +9 -9
- package/test/integration/Websocket.test.ts +0 -2
- package/test/integration/WebsocketClientConnectorRpc.test.ts +8 -8
- package/test/integration/WebsocketConnectionManagement.test.ts +8 -9
- package/test/integration/{rpc-connections-over-webrpc.test.ts → rpc-connections-over-webrtc.test.ts} +4 -3
- package/test/unit/ConnectionManager.test.ts +4 -3
- package/test/unit/ConnectivityHelpers.test.ts +1 -1
- package/test/unit/DiscoverySession.test.ts +6 -6
- package/test/unit/Handshaker.test.ts +1 -1
- package/test/unit/ListeningRpcCommunicator.test.ts +52 -0
- package/test/unit/LocalDataStore.test.ts +21 -21
- package/test/unit/PeerManager.test.ts +13 -13
- package/test/unit/PendingConnection.test.ts +1 -1
- package/test/unit/ProtobufMessage.test.ts +1 -1
- package/test/unit/RandomContactList.test.ts +2 -2
- package/test/unit/RecursiveOperationManager.test.ts +3 -3
- package/test/unit/RecursiveOperationSession.test.ts +4 -4
- package/test/unit/Router.test.ts +6 -6
- package/test/unit/RoutingSession.test.ts +6 -6
- package/test/unit/SortedContactList.test.ts +5 -5
- package/test/unit/StoreManager.test.ts +10 -10
- package/test/unit/StoreRpcLocal.test.ts +9 -9
- package/test/unit/WebrtcConnection.test.ts +29 -0
- package/test/unit/WebsocketClientConnector.test.ts +1 -1
- package/test/unit/WebsocketServerConnector.test.ts +1 -1
- package/test/unit/connectivityRequestHandler.test.ts +1 -1
- package/test/unit/createPeerDescriptor.test.ts +4 -4
- package/test/unit/getClosestNodes.test.ts +5 -5
- package/test/utils/FakeConnectorFacade.ts +1 -1
- package/test/utils/FakeTransport.ts +12 -9
- package/test/utils/customMatchers.ts +3 -3
- package/test/utils/mock/MockConnectionsView.ts +1 -1
- package/test/utils/mock/MockRouter.ts +5 -1
- package/test/utils/mock/MockTransport.ts +6 -1
- package/test/utils/mock/mockDataEntry.ts +6 -6
- package/test/utils/topology.ts +3 -3
- package/test/utils/utils.ts +9 -9
- package/tsconfig.jest.json +2 -1
- package/tsconfig.node.json +1 -0
- package/dist/src/proto/google/protobuf/any.js.map +0 -1
- package/dist/src/proto/google/protobuf/empty.js.map +0 -1
- package/dist/src/proto/google/protobuf/timestamp.js.map +0 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +0 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +0 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.js.map +0 -1
- package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.js.map +0 -1
- package/dist/src/proto/tests.d.ts +0 -39
- package/dist/src/proto/tests.js +0 -34
- package/dist/src/proto/tests.js.map +0 -1
- package/src/proto/tests.ts +0 -52
- package/test/benchmark/any.test.ts +0 -28
- /package/dist/{src/proto → generated}/google/protobuf/any.js +0 -0
- /package/dist/{src/proto → generated}/google/protobuf/empty.js +0 -0
- /package/dist/{src/proto → generated}/google/protobuf/timestamp.js +0 -0
- /package/dist/{src/proto → generated}/packages/dht/protos/DhtRpc.server.js +0 -0
- /package/dist/{src/proto → generated}/packages/proto-rpc/protos/ProtoRpc.d.ts +0 -0
- /package/dist/{src/proto → generated}/packages/proto-rpc/protos/ProtoRpc.js +0 -0
- /package/{src/proto → generated}/packages/proto-rpc/protos/ProtoRpc.ts +0 -0
- /package/{src/types/glogal.d.ts → test/types/global.d.ts} +0 -0
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
RouteMessageAck,
|
|
7
7
|
RouteMessageError,
|
|
8
8
|
RouteMessageWrapper
|
|
9
|
-
} from '
|
|
9
|
+
} from '../../../generated/packages/dht/protos/DhtRpc'
|
|
10
10
|
import { Router } from '../routing/Router'
|
|
11
11
|
import { RoutingMode } from '../routing/RoutingSession'
|
|
12
12
|
import { Logger, areEqualBinaries, runAndWaitForEvents3, wait } from '@streamr/utils'
|
|
@@ -17,13 +17,13 @@ import { DhtNodeRpcRemote } from '../DhtNodeRpcRemote'
|
|
|
17
17
|
import { ITransport } from '../../transport/ITransport'
|
|
18
18
|
import { LocalDataStore } from '../store/LocalDataStore'
|
|
19
19
|
import { ListeningRpcCommunicator } from '../../transport/ListeningRpcCommunicator'
|
|
20
|
-
import { RecursiveOperationSessionRpcClient } from '
|
|
20
|
+
import { RecursiveOperationSessionRpcClient } from '../../../generated/packages/dht/protos/DhtRpc.client'
|
|
21
21
|
import { SortedContactList } from '../contact/SortedContactList'
|
|
22
22
|
import { getPreviousPeer } from '../routing/getPreviousPeer'
|
|
23
23
|
import { createRouteMessageAck } from '../routing/RouterRpcLocal'
|
|
24
24
|
import { ServiceID } from '../../types/ServiceID'
|
|
25
25
|
import { RecursiveOperationRpcLocal } from './RecursiveOperationRpcLocal'
|
|
26
|
-
import { DhtAddress, areEqualPeerDescriptors,
|
|
26
|
+
import { DhtAddress, areEqualPeerDescriptors, toDhtAddress, toNodeId, toDhtAddressRaw } from '../../identifiers'
|
|
27
27
|
import { getDistance } from '../PeerManager'
|
|
28
28
|
import { ConnectionsView } from '../../exports'
|
|
29
29
|
|
|
@@ -99,7 +99,7 @@ export class RecursiveOperationManager {
|
|
|
99
99
|
if (this.options.connectionsView.getConnectionCount() === 0) {
|
|
100
100
|
const dataEntries = Array.from(this.options.localDataStore.values(targetId))
|
|
101
101
|
session.onResponseReceived(
|
|
102
|
-
|
|
102
|
+
toNodeId(this.options.localPeerDescriptor),
|
|
103
103
|
[this.options.localPeerDescriptor],
|
|
104
104
|
[this.options.localPeerDescriptor],
|
|
105
105
|
dataEntries,
|
|
@@ -131,7 +131,7 @@ export class RecursiveOperationManager {
|
|
|
131
131
|
this.sendResponse([this.options.localPeerDescriptor], this.options.localPeerDescriptor, session.getId(), [], dataEntries, true)
|
|
132
132
|
}
|
|
133
133
|
} else if (operation === RecursiveOperation.DELETE_DATA) {
|
|
134
|
-
this.options.localDataStore.markAsDeleted(targetId,
|
|
134
|
+
this.options.localDataStore.markAsDeleted(targetId, toNodeId(this.options.localPeerDescriptor))
|
|
135
135
|
}
|
|
136
136
|
this.ongoingSessions.delete(session.getId())
|
|
137
137
|
session.stop()
|
|
@@ -150,7 +150,7 @@ export class RecursiveOperationManager {
|
|
|
150
150
|
if (isOwnNode && this.ongoingSessions.has(serviceId)) {
|
|
151
151
|
this.ongoingSessions.get(serviceId)!
|
|
152
152
|
.onResponseReceived(
|
|
153
|
-
|
|
153
|
+
toNodeId(this.options.localPeerDescriptor),
|
|
154
154
|
routingPath,
|
|
155
155
|
closestConnectedNodes,
|
|
156
156
|
dataEntries,
|
|
@@ -180,7 +180,7 @@ export class RecursiveOperationManager {
|
|
|
180
180
|
if (this.stopped) {
|
|
181
181
|
return createRouteMessageAck(routedMessage, RouteMessageError.STOPPED)
|
|
182
182
|
}
|
|
183
|
-
const targetId =
|
|
183
|
+
const targetId = toDhtAddress(routedMessage.target)
|
|
184
184
|
const request = (routedMessage.message!.body as { recursiveOperationRequest: RecursiveOperationRequest }).recursiveOperationRequest
|
|
185
185
|
// TODO use options option or named constant?
|
|
186
186
|
const closestConnectedNodes = this.getClosestConnectedNodes(targetId, 5)
|
|
@@ -188,7 +188,7 @@ export class RecursiveOperationManager {
|
|
|
188
188
|
? Array.from(this.options.localDataStore.values(targetId))
|
|
189
189
|
: []
|
|
190
190
|
if (request.operation === RecursiveOperation.DELETE_DATA) {
|
|
191
|
-
this.options.localDataStore.markAsDeleted(targetId,
|
|
191
|
+
this.options.localDataStore.markAsDeleted(targetId, toNodeId(routedMessage.sourcePeer!))
|
|
192
192
|
}
|
|
193
193
|
if (areEqualBinaries(this.options.localPeerDescriptor.nodeId, routedMessage.target)) {
|
|
194
194
|
// TODO this is also very similar case to what we do at line 255, could simplify the code paths?
|
|
@@ -235,7 +235,7 @@ export class RecursiveOperationManager {
|
|
|
235
235
|
}
|
|
236
236
|
|
|
237
237
|
private isPeerCloserToIdThanSelf(peer: PeerDescriptor, nodeIdOrDataKey: DhtAddress): boolean {
|
|
238
|
-
const nodeIdOrDataKeyRaw =
|
|
238
|
+
const nodeIdOrDataKeyRaw = toDhtAddressRaw(nodeIdOrDataKey)
|
|
239
239
|
const distance1 = getDistance(peer.nodeId, nodeIdOrDataKeyRaw)
|
|
240
240
|
const distance2 = getDistance(this.options.localPeerDescriptor.nodeId, nodeIdOrDataKeyRaw)
|
|
241
241
|
return distance1 < distance2
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Logger } from '@streamr/utils'
|
|
2
|
-
import { PeerDescriptor, RouteMessageAck, RouteMessageError, RouteMessageWrapper } from '
|
|
3
|
-
import { IRecursiveOperationRpc } from '
|
|
2
|
+
import { PeerDescriptor, RouteMessageAck, RouteMessageError, RouteMessageWrapper } from '../../../generated/packages/dht/protos/DhtRpc'
|
|
3
|
+
import { IRecursiveOperationRpc } from '../../../generated/packages/dht/protos/DhtRpc.server'
|
|
4
4
|
import { createRouteMessageAck } from '../routing/RouterRpcLocal'
|
|
5
5
|
import { getPreviousPeer } from '../routing/getPreviousPeer'
|
|
6
|
-
import {
|
|
6
|
+
import { toNodeId } from '../../identifiers'
|
|
7
7
|
|
|
8
8
|
const logger = new Logger(module)
|
|
9
9
|
|
|
@@ -26,7 +26,7 @@ export class RecursiveOperationRpcLocal implements IRecursiveOperationRpc {
|
|
|
26
26
|
if (this.options.isMostLikelyDuplicate(routedMessage.requestId)) {
|
|
27
27
|
return createRouteMessageAck(routedMessage, RouteMessageError.DUPLICATE)
|
|
28
28
|
}
|
|
29
|
-
const remoteNodeId =
|
|
29
|
+
const remoteNodeId = toNodeId(getPreviousPeer(routedMessage) ?? routedMessage.sourcePeer!)
|
|
30
30
|
logger.trace(`Received routeRequest call from ${remoteNodeId}`)
|
|
31
31
|
this.options.addToDuplicateDetector(routedMessage.requestId)
|
|
32
32
|
return this.options.doRouteRequest(routedMessage)
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Logger } from '@streamr/utils'
|
|
2
2
|
import { v4 } from 'uuid'
|
|
3
|
-
import { RouteMessageWrapper } from '
|
|
4
|
-
import { RecursiveOperationRpcClient } from '
|
|
3
|
+
import { RouteMessageWrapper } from '../../../generated/packages/dht/protos/DhtRpc'
|
|
4
|
+
import { RecursiveOperationRpcClient } from '../../../generated/packages/dht/protos/DhtRpc.client'
|
|
5
5
|
import { RpcRemote } from '../contact/RpcRemote'
|
|
6
6
|
import { getPreviousPeer } from '../routing/getPreviousPeer'
|
|
7
|
-
import {
|
|
7
|
+
import { toNodeId } from '../../identifiers'
|
|
8
8
|
|
|
9
9
|
const logger = new Logger(module)
|
|
10
10
|
|
|
@@ -32,9 +32,9 @@ export class RecursiveOperationRpcRemote extends RpcRemote<RecursiveOperationRpc
|
|
|
32
32
|
} catch (err) {
|
|
33
33
|
const previousPeer = getPreviousPeer(params)
|
|
34
34
|
const fromNode = previousPeer
|
|
35
|
-
?
|
|
36
|
-
:
|
|
37
|
-
const toNode =
|
|
35
|
+
? toNodeId(previousPeer)
|
|
36
|
+
: toNodeId(params.sourcePeer!)
|
|
37
|
+
const toNode = toNodeId(this.getPeerDescriptor())
|
|
38
38
|
logger.debug(`Failed to send routeRequest message from ${fromNode} to ${toNode}`, { err })
|
|
39
39
|
return false
|
|
40
40
|
}
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
RouteMessageAck,
|
|
10
10
|
RecursiveOperationRequest,
|
|
11
11
|
Message
|
|
12
|
-
} from '
|
|
12
|
+
} from '../../../generated/packages/dht/protos/DhtRpc'
|
|
13
13
|
import { ITransport } from '../../transport/ITransport'
|
|
14
14
|
import { ListeningRpcCommunicator } from '../../transport/ListeningRpcCommunicator'
|
|
15
15
|
import { Contact } from '../contact/Contact'
|
|
@@ -17,7 +17,7 @@ import { SortedContactList } from '../contact/SortedContactList'
|
|
|
17
17
|
import { RecursiveOperationResult } from './RecursiveOperationManager'
|
|
18
18
|
import { ServiceID } from '../../types/ServiceID'
|
|
19
19
|
import { RecursiveOperationSessionRpcLocal } from './RecursiveOperationSessionRpcLocal'
|
|
20
|
-
import { DhtAddress,
|
|
20
|
+
import { DhtAddress, toDhtAddress, toNodeId, toDhtAddressRaw } from '../../identifiers'
|
|
21
21
|
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
22
22
|
|
|
23
23
|
export interface RecursiveOperationSessionEvents {
|
|
@@ -100,7 +100,7 @@ export class RecursiveOperationSession extends EventEmitter<RecursiveOperationSe
|
|
|
100
100
|
const routeMessage: RouteMessageWrapper = {
|
|
101
101
|
message: msg,
|
|
102
102
|
requestId: v4(),
|
|
103
|
-
target:
|
|
103
|
+
target: toDhtAddressRaw(this.options.targetId),
|
|
104
104
|
sourcePeer: this.options.localPeerDescriptor,
|
|
105
105
|
reachableThrough: [],
|
|
106
106
|
routingPath: [],
|
|
@@ -151,9 +151,9 @@ export class RecursiveOperationSession extends EventEmitter<RecursiveOperationSe
|
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
private addKnownHops(routingPath: PeerDescriptor[]) {
|
|
154
|
-
const localNodeId =
|
|
154
|
+
const localNodeId = toNodeId(this.options.localPeerDescriptor)
|
|
155
155
|
routingPath.forEach((desc) => {
|
|
156
|
-
const newNodeId =
|
|
156
|
+
const newNodeId = toNodeId(desc)
|
|
157
157
|
if (localNodeId !== newNodeId) {
|
|
158
158
|
this.allKnownHops.add(newNodeId)
|
|
159
159
|
}
|
|
@@ -161,8 +161,8 @@ export class RecursiveOperationSession extends EventEmitter<RecursiveOperationSe
|
|
|
161
161
|
}
|
|
162
162
|
|
|
163
163
|
private setHopAsReported(desc: PeerDescriptor) {
|
|
164
|
-
const localNodeId =
|
|
165
|
-
const newNodeId =
|
|
164
|
+
const localNodeId = toNodeId(this.options.localPeerDescriptor)
|
|
165
|
+
const newNodeId = toNodeId(desc)
|
|
166
166
|
if (localNodeId !== newNodeId) {
|
|
167
167
|
this.reportedHops.add(newNodeId)
|
|
168
168
|
}
|
|
@@ -180,7 +180,7 @@ export class RecursiveOperationSession extends EventEmitter<RecursiveOperationSe
|
|
|
180
180
|
|
|
181
181
|
private processFoundData(dataEntries: DataEntry[]): void {
|
|
182
182
|
dataEntries.forEach((entry) => {
|
|
183
|
-
const creatorNodeId =
|
|
183
|
+
const creatorNodeId = toDhtAddress(entry.creator)
|
|
184
184
|
const existingEntry = this.foundData.get(creatorNodeId)
|
|
185
185
|
if (!existingEntry || existingEntry.createdAt! < entry.createdAt!
|
|
186
186
|
|| (existingEntry.createdAt! <= entry.createdAt! && entry.deleted)) {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { IRecursiveOperationSessionRpc } from '
|
|
2
|
-
import { Empty } from '
|
|
3
|
-
import { DataEntry, RecursiveOperationResponse, PeerDescriptor } from '
|
|
1
|
+
import { IRecursiveOperationSessionRpc } from '../../../generated/packages/dht/protos/DhtRpc.server'
|
|
2
|
+
import { Empty } from '../../../generated/google/protobuf/empty'
|
|
3
|
+
import { DataEntry, RecursiveOperationResponse, PeerDescriptor } from '../../../generated/packages/dht/protos/DhtRpc'
|
|
4
4
|
import { Logger } from '@streamr/utils'
|
|
5
5
|
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
6
6
|
import { DhtCallContext } from '../../rpc-protocol/DhtCallContext'
|
|
7
|
-
import { DhtAddress,
|
|
7
|
+
import { DhtAddress, toNodeId } from '../../identifiers'
|
|
8
8
|
|
|
9
9
|
const logger = new Logger(module)
|
|
10
10
|
|
|
@@ -27,7 +27,7 @@ export class RecursiveOperationSessionRpcLocal implements IRecursiveOperationSes
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
async sendResponse(report: RecursiveOperationResponse, context: ServerCallContext): Promise<Empty> {
|
|
30
|
-
const remoteNodeId =
|
|
30
|
+
const remoteNodeId = toNodeId((context as DhtCallContext).incomingSourceDescriptor!)
|
|
31
31
|
logger.trace('RecursiveOperationResponse arrived: ' + JSON.stringify(report))
|
|
32
32
|
this.options.onResponseReceived(remoteNodeId, report.routingPath, report.closestConnectedNodes, report.dataEntries, report.noCloserNodesFound)
|
|
33
33
|
return {}
|
|
@@ -3,8 +3,8 @@ import {
|
|
|
3
3
|
DataEntry,
|
|
4
4
|
PeerDescriptor,
|
|
5
5
|
RecursiveOperationResponse
|
|
6
|
-
} from '
|
|
7
|
-
import { RecursiveOperationSessionRpcClient } from '
|
|
6
|
+
} from '../../../generated/packages/dht/protos/DhtRpc'
|
|
7
|
+
import { RecursiveOperationSessionRpcClient } from '../../../generated/packages/dht/protos/DhtRpc.client'
|
|
8
8
|
import { RpcRemote } from '../contact/RpcRemote'
|
|
9
9
|
|
|
10
10
|
const logger = new Logger(module)
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Message, PeerDescriptor, RouteMessageAck, RouteMessageError, RouteMessageWrapper } from '
|
|
1
|
+
import { Message, PeerDescriptor, RouteMessageAck, RouteMessageError, RouteMessageWrapper } from '../../../generated/packages/dht/protos/DhtRpc'
|
|
2
2
|
import { RoutingMode, RoutingRemoteContact, RoutingSession, RoutingSessionEvents } from './RoutingSession'
|
|
3
3
|
import { Logger, executeSafePromise, raceEvents3, withTimeout } from '@streamr/utils'
|
|
4
4
|
import { RoutingRpcCommunicator } from '../../transport/RoutingRpcCommunicator'
|
|
5
5
|
import { DuplicateDetector } from './DuplicateDetector'
|
|
6
6
|
import { v4 } from 'uuid'
|
|
7
7
|
import { RouterRpcLocal, createRouteMessageAck } from './RouterRpcLocal'
|
|
8
|
-
import { DhtAddress, areEqualPeerDescriptors,
|
|
8
|
+
import { DhtAddress, areEqualPeerDescriptors, toDhtAddress, toNodeId } from '../../identifiers'
|
|
9
9
|
import { RoutingTablesCache } from './RoutingTablesCache'
|
|
10
10
|
|
|
11
11
|
export interface RouterOptions {
|
|
@@ -31,6 +31,8 @@ export class Router {
|
|
|
31
31
|
private readonly duplicateRequestDetector: DuplicateDetector = new DuplicateDetector(10000)
|
|
32
32
|
private stopped = false
|
|
33
33
|
private readonly options: RouterOptions
|
|
34
|
+
private messagesRouted = 0
|
|
35
|
+
private messagesSent = 0
|
|
34
36
|
|
|
35
37
|
constructor(options: RouterOptions) {
|
|
36
38
|
this.options = options
|
|
@@ -73,7 +75,7 @@ export class Router {
|
|
|
73
75
|
public send(msg: Message, reachableThrough: PeerDescriptor[]): void {
|
|
74
76
|
msg.sourceDescriptor = this.options.localPeerDescriptor
|
|
75
77
|
const targetPeerDescriptor = msg.targetDescriptor!
|
|
76
|
-
const forwardingEntry = this.forwardingTable.get(
|
|
78
|
+
const forwardingEntry = this.forwardingTable.get(toNodeId(targetPeerDescriptor))
|
|
77
79
|
if (forwardingEntry && forwardingEntry.peerDescriptors.length > 0) {
|
|
78
80
|
const forwardedMessage: RouteMessageWrapper = {
|
|
79
81
|
message: msg,
|
|
@@ -107,22 +109,21 @@ export class Router {
|
|
|
107
109
|
throw new Error(error)
|
|
108
110
|
}
|
|
109
111
|
}
|
|
112
|
+
this.messagesSent += 1
|
|
110
113
|
}
|
|
111
114
|
|
|
112
115
|
public doRouteMessage(routedMessage: RouteMessageWrapper, mode = RoutingMode.ROUTE, excludedPeer?: DhtAddress): RouteMessageAck {
|
|
113
116
|
if (this.stopped) {
|
|
114
117
|
return createRouteMessageAck(routedMessage, RouteMessageError.STOPPED)
|
|
115
118
|
}
|
|
116
|
-
logger.trace(`Routing message ${routedMessage.requestId} from ${
|
|
117
|
-
+ `to ${
|
|
119
|
+
logger.trace(`Routing message ${routedMessage.requestId} from ${toNodeId(routedMessage.sourcePeer!)} `
|
|
120
|
+
+ `to ${toDhtAddress(routedMessage.target)}`)
|
|
118
121
|
const session = this.createRoutingSession(routedMessage, mode, excludedPeer)
|
|
119
122
|
const contacts = session.updateAndGetRoutablePeers()
|
|
120
123
|
if (contacts.length > 0) {
|
|
121
124
|
this.addRoutingSession(session)
|
|
122
|
-
// eslint-disable-next-line promise/catch-or-return
|
|
123
125
|
logger.trace('starting to raceEvents from routingSession: ' + session.sessionId)
|
|
124
126
|
let eventReceived: Promise<unknown>
|
|
125
|
-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
126
127
|
executeSafePromise(async () => {
|
|
127
128
|
eventReceived = raceEvents3<RoutingSessionEvents>(
|
|
128
129
|
session,
|
|
@@ -142,6 +143,7 @@ export class Router {
|
|
|
142
143
|
this.removeRoutingSession(session.sessionId)
|
|
143
144
|
})
|
|
144
145
|
session.sendMoreRequests(contacts)
|
|
146
|
+
this.messagesRouted += 1
|
|
145
147
|
return createRouteMessageAck(routedMessage)
|
|
146
148
|
} else {
|
|
147
149
|
logger.trace('no targets', { sessionId: session.sessionId })
|
|
@@ -150,7 +152,7 @@ export class Router {
|
|
|
150
152
|
}
|
|
151
153
|
|
|
152
154
|
private createRoutingSession(routedMessage: RouteMessageWrapper, mode: RoutingMode, excludedNode?: DhtAddress): RoutingSession {
|
|
153
|
-
const excludedNodeIds = new Set<DhtAddress>(routedMessage.routingPath.map((descriptor) =>
|
|
155
|
+
const excludedNodeIds = new Set<DhtAddress>(routedMessage.routingPath.map((descriptor) => toNodeId(descriptor)))
|
|
154
156
|
if (excludedNode) {
|
|
155
157
|
excludedNodeIds.add(excludedNode)
|
|
156
158
|
}
|
|
@@ -192,7 +194,7 @@ export class Router {
|
|
|
192
194
|
}
|
|
193
195
|
|
|
194
196
|
onNodeDisconnected(peerDescriptor: PeerDescriptor): void {
|
|
195
|
-
this.routingTablesCache.onNodeDisconnected(
|
|
197
|
+
this.routingTablesCache.onNodeDisconnected(toNodeId(peerDescriptor))
|
|
196
198
|
}
|
|
197
199
|
|
|
198
200
|
public resetCache(): void {
|
|
@@ -213,13 +215,20 @@ export class Router {
|
|
|
213
215
|
this.routingTablesCache.reset()
|
|
214
216
|
}
|
|
215
217
|
|
|
218
|
+
getDiagnosticInfo(): Record<string, unknown> {
|
|
219
|
+
return {
|
|
220
|
+
messagesRouted: this.messagesRouted,
|
|
221
|
+
messagesSent: this.messagesSent
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
216
225
|
private setForwardingEntries(routedMessage: RouteMessageWrapper): void {
|
|
217
226
|
const reachableThroughWithoutSelf = routedMessage.reachableThrough.filter((peer) => {
|
|
218
227
|
return !areEqualPeerDescriptors(peer, this.options.localPeerDescriptor)
|
|
219
228
|
})
|
|
220
229
|
|
|
221
230
|
if (reachableThroughWithoutSelf.length > 0) {
|
|
222
|
-
const sourceNodeId =
|
|
231
|
+
const sourceNodeId = toNodeId(routedMessage.sourcePeer!)
|
|
223
232
|
if (this.forwardingTable.has(sourceNodeId)) {
|
|
224
233
|
const oldEntry = this.forwardingTable.get(sourceNodeId)
|
|
225
234
|
clearTimeout(oldEntry!.timeout)
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Logger, areEqualBinaries } from '@streamr/utils'
|
|
2
|
-
import { Message, PeerDescriptor, RouteMessageAck, RouteMessageError, RouteMessageWrapper } from '
|
|
3
|
-
import { IRouterRpc } from '
|
|
2
|
+
import { Message, PeerDescriptor, RouteMessageAck, RouteMessageError, RouteMessageWrapper } from '../../../generated/packages/dht/protos/DhtRpc'
|
|
3
|
+
import { IRouterRpc } from '../../../generated/packages/dht/protos/DhtRpc.server'
|
|
4
4
|
import { DuplicateDetector } from './DuplicateDetector'
|
|
5
5
|
import { RoutingMode } from './RoutingSession'
|
|
6
|
-
import { areEqualPeerDescriptors,
|
|
6
|
+
import { areEqualPeerDescriptors, toDhtAddress, toNodeId } from '../../identifiers'
|
|
7
7
|
import { v4 } from 'uuid'
|
|
8
8
|
|
|
9
9
|
interface RouterRpcLocalOptions {
|
|
@@ -34,8 +34,8 @@ export class RouterRpcLocal implements IRouterRpc {
|
|
|
34
34
|
|
|
35
35
|
async routeMessage(routedMessage: RouteMessageWrapper): Promise<RouteMessageAck> {
|
|
36
36
|
if (this.options.duplicateRequestDetector.isMostLikelyDuplicate(routedMessage.requestId)) {
|
|
37
|
-
logger.trace(`Routing message ${routedMessage.requestId} from ${
|
|
38
|
-
+ `to ${
|
|
37
|
+
logger.trace(`Routing message ${routedMessage.requestId} from ${toNodeId(routedMessage.sourcePeer!)} `
|
|
38
|
+
+ `to ${toDhtAddress(routedMessage.target)} is likely a duplicate`)
|
|
39
39
|
return createRouteMessageAck(routedMessage, RouteMessageError.DUPLICATE)
|
|
40
40
|
}
|
|
41
41
|
logger.trace(`Processing received routeMessage ${routedMessage.requestId}`)
|
|
@@ -52,8 +52,8 @@ export class RouterRpcLocal implements IRouterRpc {
|
|
|
52
52
|
|
|
53
53
|
async forwardMessage(forwardMessage: RouteMessageWrapper): Promise<RouteMessageAck> {
|
|
54
54
|
if (this.options.duplicateRequestDetector.isMostLikelyDuplicate(forwardMessage.requestId)) {
|
|
55
|
-
logger.trace(`Forwarding message ${forwardMessage.requestId} from ${
|
|
56
|
-
+ `to ${
|
|
55
|
+
logger.trace(`Forwarding message ${forwardMessage.requestId} from ${toNodeId(forwardMessage.sourcePeer!)} `
|
|
56
|
+
+ `to ${toDhtAddress(forwardMessage.target)} is likely a duplicate`)
|
|
57
57
|
return createRouteMessageAck(forwardMessage, RouteMessageError.DUPLICATE)
|
|
58
58
|
}
|
|
59
59
|
logger.trace(`Processing received forward routeMessage ${forwardMessage.requestId}`)
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Logger, areEqualBinaries } from '@streamr/utils'
|
|
2
2
|
import { v4 } from 'uuid'
|
|
3
|
-
import { RouteMessageError, RouteMessageWrapper } from '
|
|
4
|
-
import { RouterRpcClient } from '
|
|
3
|
+
import { RouteMessageError, RouteMessageWrapper } from '../../../generated/packages/dht/protos/DhtRpc'
|
|
4
|
+
import { RouterRpcClient } from '../../../generated/packages/dht/protos/DhtRpc.client'
|
|
5
5
|
import { RpcRemote } from '../contact/RpcRemote'
|
|
6
6
|
import { getPreviousPeer } from './getPreviousPeer'
|
|
7
|
-
import {
|
|
7
|
+
import { toNodeId } from '../../identifiers'
|
|
8
8
|
|
|
9
9
|
const logger = new Logger(module)
|
|
10
10
|
|
|
@@ -39,9 +39,9 @@ export class RouterRpcRemote extends RpcRemote<RouterRpcClient> {
|
|
|
39
39
|
} catch (err) {
|
|
40
40
|
const previousPeer = getPreviousPeer(params)
|
|
41
41
|
const fromNode = previousPeer
|
|
42
|
-
?
|
|
43
|
-
:
|
|
44
|
-
const toNode =
|
|
42
|
+
? toNodeId(previousPeer)
|
|
43
|
+
: toNodeId(params.sourcePeer!)
|
|
44
|
+
const toNode = toNodeId(this.getPeerDescriptor())
|
|
45
45
|
logger.trace(`Failed to send routeMessage from ${fromNode} to ${toNode}`, { err })
|
|
46
46
|
return false
|
|
47
47
|
}
|
|
@@ -69,9 +69,9 @@ export class RouterRpcRemote extends RpcRemote<RouterRpcClient> {
|
|
|
69
69
|
} catch (err) {
|
|
70
70
|
const previousPeer = getPreviousPeer(params)
|
|
71
71
|
const fromNode = previousPeer
|
|
72
|
-
?
|
|
73
|
-
:
|
|
74
|
-
const toNode =
|
|
72
|
+
? toNodeId(previousPeer)
|
|
73
|
+
: toNodeId(params.sourcePeer!)
|
|
74
|
+
const toNode = toNodeId(this.getPeerDescriptor())
|
|
75
75
|
logger.trace(`Failed to send forwardMessage from ${fromNode} to ${toNode}`, { err })
|
|
76
76
|
return false
|
|
77
77
|
}
|
|
@@ -2,14 +2,14 @@ import { SortedContactList } from '../contact/SortedContactList'
|
|
|
2
2
|
import { Logger } from '@streamr/utils'
|
|
3
3
|
import EventEmitter from 'eventemitter3'
|
|
4
4
|
import { v4 } from 'uuid'
|
|
5
|
-
import { PeerDescriptor, RouteMessageWrapper } from '
|
|
5
|
+
import { PeerDescriptor, RouteMessageWrapper } from '../../../generated/packages/dht/protos/DhtRpc'
|
|
6
6
|
import { RouterRpcRemote, ROUTING_TIMEOUT } from './RouterRpcRemote'
|
|
7
7
|
import { RoutingRpcCommunicator } from '../../transport/RoutingRpcCommunicator'
|
|
8
|
-
import { RecursiveOperationRpcClient, RouterRpcClient } from '
|
|
8
|
+
import { RecursiveOperationRpcClient, RouterRpcClient } from '../../../generated/packages/dht/protos/DhtRpc.client'
|
|
9
9
|
import { Contact } from '../contact/Contact'
|
|
10
10
|
import { RecursiveOperationRpcRemote } from '../recursive-operation/RecursiveOperationRpcRemote'
|
|
11
11
|
import { getPreviousPeer } from './getPreviousPeer'
|
|
12
|
-
import { DhtAddress, areEqualPeerDescriptors,
|
|
12
|
+
import { DhtAddress, areEqualPeerDescriptors, toDhtAddress, toNodeId } from '../../identifiers'
|
|
13
13
|
import { pull } from 'lodash'
|
|
14
14
|
import { RoutingTable, RoutingTablesCache } from './RoutingTablesCache'
|
|
15
15
|
|
|
@@ -160,14 +160,14 @@ export class RoutingSession extends EventEmitter<RoutingSessionEvents> {
|
|
|
160
160
|
updateAndGetRoutablePeers(): RoutingRemoteContact[] {
|
|
161
161
|
logger.trace('getRoutablePeers() sessionId: ' + this.sessionId)
|
|
162
162
|
const previousPeer = getPreviousPeer(this.options.routedMessage)
|
|
163
|
-
const previousId = previousPeer ?
|
|
164
|
-
const targetId =
|
|
163
|
+
const previousId = previousPeer ? toNodeId(previousPeer) : undefined
|
|
164
|
+
const targetId = toDhtAddress(this.options.routedMessage.target)
|
|
165
165
|
let routingTable: RoutingTable
|
|
166
166
|
if (this.options.routingTablesCache.has(targetId, previousId)) {
|
|
167
167
|
routingTable = this.options.routingTablesCache.get(targetId, previousId)!
|
|
168
168
|
} else {
|
|
169
169
|
routingTable = new SortedContactList<RoutingRemoteContact>({
|
|
170
|
-
referenceId:
|
|
170
|
+
referenceId: toDhtAddress(this.options.routedMessage.target),
|
|
171
171
|
maxSize: ROUTING_TABLE_MAX_SIZE,
|
|
172
172
|
allowToContainReferenceId: true,
|
|
173
173
|
nodeIdDistanceLimit: previousId
|
|
@@ -196,8 +196,7 @@ export class RoutingSession extends EventEmitter<RoutingSessionEvents> {
|
|
|
196
196
|
}
|
|
197
197
|
while ((this.ongoingRequests.size < this.options.parallelism) && (uncontacted.length > 0) && !this.stopped) {
|
|
198
198
|
const nextPeer = uncontacted.shift()
|
|
199
|
-
|
|
200
|
-
logger.trace(`Sending routeMessage request to contact: ${getNodeIdFromPeerDescriptor(nextPeer!.getPeerDescriptor())} (sessionId=${this.sessionId})`)
|
|
199
|
+
logger.trace(`Sending routeMessage request to contact: ${toNodeId(nextPeer!.getPeerDescriptor())} (sessionId=${this.sessionId})`)
|
|
201
200
|
this.contactedPeers.add(nextPeer!.getNodeId())
|
|
202
201
|
this.ongoingRequests.add(nextPeer!.getNodeId())
|
|
203
202
|
this.addParallelRootIfSource(nextPeer!.getNodeId())
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { last } from 'lodash'
|
|
2
|
-
import { PeerDescriptor, RouteMessageWrapper } from '
|
|
2
|
+
import { PeerDescriptor, RouteMessageWrapper } from '../../../generated/packages/dht/protos/DhtRpc'
|
|
3
3
|
|
|
4
4
|
export const getPreviousPeer = (routeMessage: RouteMessageWrapper): PeerDescriptor | undefined => {
|
|
5
5
|
return last(routeMessage.routingPath)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DataEntry } from '
|
|
2
|
-
import { DhtAddress,
|
|
1
|
+
import { DataEntry } from '../../../generated/packages/dht/protos/DhtRpc'
|
|
2
|
+
import { DhtAddress, toDhtAddress } from '../../identifiers'
|
|
3
3
|
import { MapWithTtl } from '@streamr/utils'
|
|
4
4
|
|
|
5
5
|
export class LocalDataStore {
|
|
@@ -16,8 +16,8 @@ export class LocalDataStore {
|
|
|
16
16
|
private store: Map<DhtAddress, MapWithTtl<DhtAddress, DataEntry>> = new Map()
|
|
17
17
|
|
|
18
18
|
public storeEntry(dataEntry: DataEntry): boolean {
|
|
19
|
-
const key =
|
|
20
|
-
const creatorNodeId =
|
|
19
|
+
const key = toDhtAddress(dataEntry.key)
|
|
20
|
+
const creatorNodeId = toDhtAddress(dataEntry.creator)
|
|
21
21
|
if (!this.store.has(key)) {
|
|
22
22
|
this.store.set(key, new MapWithTtl((e) => Math.min(e.ttl, this.maxTtl)))
|
|
23
23
|
}
|
|
@@ -3,19 +3,19 @@ import { Logger } from '@streamr/utils'
|
|
|
3
3
|
import {
|
|
4
4
|
DhtAddress,
|
|
5
5
|
areEqualPeerDescriptors,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
toDhtAddress,
|
|
7
|
+
toNodeId,
|
|
8
|
+
toDhtAddressRaw
|
|
9
9
|
} from '../../identifiers'
|
|
10
|
-
import { Any } from '
|
|
11
|
-
import { Timestamp } from '
|
|
10
|
+
import { Any } from '../../../generated/google/protobuf/any'
|
|
11
|
+
import { Timestamp } from '../../../generated/google/protobuf/timestamp'
|
|
12
12
|
import {
|
|
13
13
|
DataEntry,
|
|
14
14
|
PeerDescriptor,
|
|
15
15
|
RecursiveOperation,
|
|
16
16
|
ReplicateDataRequest,
|
|
17
17
|
StoreDataRequest, StoreDataResponse
|
|
18
|
-
} from '
|
|
18
|
+
} from '../../../generated/packages/dht/protos/DhtRpc'
|
|
19
19
|
import { RoutingRpcCommunicator } from '../../transport/RoutingRpcCommunicator'
|
|
20
20
|
import { ServiceID } from '../../types/ServiceID'
|
|
21
21
|
import { getClosestNodes } from '../contact/getClosestNodes'
|
|
@@ -85,7 +85,7 @@ export class StoreManager {
|
|
|
85
85
|
private async replicateDataToContact(dataEntry: DataEntry, contact: PeerDescriptor): Promise<void> {
|
|
86
86
|
const rpcRemote = this.options.createRpcRemote(contact)
|
|
87
87
|
try {
|
|
88
|
-
await rpcRemote.replicateData({ entry: dataEntry })
|
|
88
|
+
await rpcRemote.replicateData({ entry: dataEntry }, true)
|
|
89
89
|
} catch (e) {
|
|
90
90
|
logger.trace('replicateData() threw an exception ' + e)
|
|
91
91
|
}
|
|
@@ -99,8 +99,8 @@ export class StoreManager {
|
|
|
99
99
|
const ttl = this.options.highestTtl // ToDo: make TTL decrease according to some nice curve
|
|
100
100
|
const createdAt = Timestamp.now()
|
|
101
101
|
for (let i = 0; i < closestNodes.length && successfulNodes.length < this.options.redundancyFactor; i++) {
|
|
102
|
-
const keyRaw =
|
|
103
|
-
const creatorRaw =
|
|
102
|
+
const keyRaw = toDhtAddressRaw(key)
|
|
103
|
+
const creatorRaw = toDhtAddressRaw(creator)
|
|
104
104
|
if (areEqualPeerDescriptors(this.options.localPeerDescriptor, closestNodes[i])) {
|
|
105
105
|
this.options.localDataStore.storeEntry({
|
|
106
106
|
key: keyRaw,
|
|
@@ -136,7 +136,7 @@ export class StoreManager {
|
|
|
136
136
|
private async replicateDataToClosestNodes(): Promise<void> {
|
|
137
137
|
const dataEntries = Array.from(this.options.localDataStore.values())
|
|
138
138
|
await Promise.all(dataEntries.map(async (dataEntry) => {
|
|
139
|
-
const dataKey =
|
|
139
|
+
const dataKey = toDhtAddress(dataEntry.key)
|
|
140
140
|
const neighbors = getClosestNodes(
|
|
141
141
|
dataKey,
|
|
142
142
|
this.options.getNeighbors(),
|
|
@@ -145,7 +145,7 @@ export class StoreManager {
|
|
|
145
145
|
await Promise.all(neighbors.map(async (neighbor) => {
|
|
146
146
|
const rpcRemote = this.options.createRpcRemote(neighbor)
|
|
147
147
|
try {
|
|
148
|
-
await rpcRemote.replicateData({ entry: dataEntry })
|
|
148
|
+
await rpcRemote.replicateData({ entry: dataEntry }, false)
|
|
149
149
|
} catch (err) {
|
|
150
150
|
logger.trace('Failed to replicate data in replicateDataToClosestNodes', { err })
|
|
151
151
|
}
|
|
@@ -159,7 +159,7 @@ export class StoreManager {
|
|
|
159
159
|
[...this.options.getNeighbors(), this.options.localPeerDescriptor],
|
|
160
160
|
{
|
|
161
161
|
maxCount: this.options.redundancyFactor,
|
|
162
|
-
excludedNodeIds: excludedNode !== undefined ? new Set([
|
|
162
|
+
excludedNodeIds: excludedNode !== undefined ? new Set([toNodeId(excludedNode)]) : undefined
|
|
163
163
|
}
|
|
164
164
|
)
|
|
165
165
|
}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
2
2
|
import { Logger, executeSafePromise } from '@streamr/utils'
|
|
3
|
-
import { Empty } from '
|
|
4
|
-
import { Timestamp } from '
|
|
3
|
+
import { Empty } from '../../../generated/google/protobuf/empty'
|
|
4
|
+
import { Timestamp } from '../../../generated/google/protobuf/timestamp'
|
|
5
5
|
import {
|
|
6
6
|
DataEntry,
|
|
7
7
|
PeerDescriptor,
|
|
8
8
|
ReplicateDataRequest,
|
|
9
9
|
StoreDataRequest, StoreDataResponse
|
|
10
|
-
} from '
|
|
11
|
-
import { IStoreRpc } from '
|
|
10
|
+
} from '../../../generated/packages/dht/protos/DhtRpc'
|
|
11
|
+
import { IStoreRpc } from '../../../generated/packages/dht/protos/DhtRpc.server'
|
|
12
12
|
import { DhtCallContext } from '../../rpc-protocol/DhtCallContext'
|
|
13
13
|
import { LocalDataStore } from './LocalDataStore'
|
|
14
|
-
import { areEqualPeerDescriptors, DhtAddress,
|
|
14
|
+
import { areEqualPeerDescriptors, DhtAddress, toDhtAddress } from '../../identifiers'
|
|
15
15
|
|
|
16
16
|
interface StoreRpcLocalOptions {
|
|
17
17
|
localDataStore: LocalDataStore
|
|
@@ -32,7 +32,7 @@ export class StoreRpcLocal implements IStoreRpc {
|
|
|
32
32
|
|
|
33
33
|
async storeData(request: StoreDataRequest): Promise<StoreDataResponse> {
|
|
34
34
|
logger.trace('storeData()')
|
|
35
|
-
const key =
|
|
35
|
+
const key = toDhtAddress(request.key)
|
|
36
36
|
const isLocalNodeStorer = this.isLocalNodeStorer(key)
|
|
37
37
|
this.options.localDataStore.storeEntry({
|
|
38
38
|
key: request.key,
|
|
@@ -57,7 +57,7 @@ export class StoreRpcLocal implements IStoreRpc {
|
|
|
57
57
|
if (wasStored) {
|
|
58
58
|
this.replicateDataToNeighbors((context as DhtCallContext).incomingSourceDescriptor!, request.entry!)
|
|
59
59
|
}
|
|
60
|
-
const key =
|
|
60
|
+
const key = toDhtAddress(dataEntry.key)
|
|
61
61
|
if (!this.isLocalNodeStorer(key)) {
|
|
62
62
|
this.options.localDataStore.setAllEntriesAsStale(key)
|
|
63
63
|
}
|
|
@@ -70,7 +70,7 @@ export class StoreRpcLocal implements IStoreRpc {
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
private replicateDataToNeighbors(requestor: PeerDescriptor, dataEntry: DataEntry): void {
|
|
73
|
-
const dataKey =
|
|
73
|
+
const dataKey = toDhtAddress(dataEntry.key)
|
|
74
74
|
const storers = this.options.getStorers(dataKey)
|
|
75
75
|
const isLocalNodePrimaryStorer = areEqualPeerDescriptors(storers[0], this.options.localPeerDescriptor)
|
|
76
76
|
// If we are the closest to the data, get storageRedundancyFactor - 1 nearest node to the data, and
|