@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
|
@@ -7,6 +7,7 @@ import type { ExternalStoreDataRequest } from "./DhtRpc";
|
|
|
7
7
|
import type { ExternalFetchDataResponse } from "./DhtRpc";
|
|
8
8
|
import type { ExternalFetchDataRequest } from "./DhtRpc";
|
|
9
9
|
import { ConnectionLockRpc } from "./DhtRpc";
|
|
10
|
+
import type { SetPrivateRequest } from "./DhtRpc";
|
|
10
11
|
import type { DisconnectNotice } from "./DhtRpc";
|
|
11
12
|
import type { UnlockRequest } from "./DhtRpc";
|
|
12
13
|
import type { LockResponse } from "./DhtRpc";
|
|
@@ -336,6 +337,10 @@ export interface IConnectionLockRpcClient {
|
|
|
336
337
|
* @generated from protobuf rpc: gracefulDisconnect(dht.DisconnectNotice) returns (google.protobuf.Empty);
|
|
337
338
|
*/
|
|
338
339
|
gracefulDisconnect(input: DisconnectNotice, options?: RpcOptions): UnaryCall<DisconnectNotice, Empty>;
|
|
340
|
+
/**
|
|
341
|
+
* @generated from protobuf rpc: setPrivate(dht.SetPrivateRequest) returns (google.protobuf.Empty);
|
|
342
|
+
*/
|
|
343
|
+
setPrivate(input: SetPrivateRequest, options?: RpcOptions): UnaryCall<SetPrivateRequest, Empty>;
|
|
339
344
|
}
|
|
340
345
|
/**
|
|
341
346
|
* @generated from protobuf service dht.ConnectionLockRpc
|
|
@@ -367,6 +372,13 @@ export class ConnectionLockRpcClient implements IConnectionLockRpcClient, Servic
|
|
|
367
372
|
const method = this.methods[2], opt = this._transport.mergeOptions(options);
|
|
368
373
|
return stackIntercept<DisconnectNotice, Empty>("unary", this._transport, method, opt, input);
|
|
369
374
|
}
|
|
375
|
+
/**
|
|
376
|
+
* @generated from protobuf rpc: setPrivate(dht.SetPrivateRequest) returns (google.protobuf.Empty);
|
|
377
|
+
*/
|
|
378
|
+
setPrivate(input: SetPrivateRequest, options?: RpcOptions): UnaryCall<SetPrivateRequest, Empty> {
|
|
379
|
+
const method = this.methods[3], opt = this._transport.mergeOptions(options);
|
|
380
|
+
return stackIntercept<SetPrivateRequest, Empty>("unary", this._transport, method, opt, input);
|
|
381
|
+
}
|
|
370
382
|
}
|
|
371
383
|
/**
|
|
372
384
|
* @generated from protobuf service dht.ExternalApiRpc
|
|
@@ -5,6 +5,7 @@ import { ExternalStoreDataResponse } from "./DhtRpc";
|
|
|
5
5
|
import { ExternalStoreDataRequest } from "./DhtRpc";
|
|
6
6
|
import { ExternalFetchDataResponse } from "./DhtRpc";
|
|
7
7
|
import { ExternalFetchDataRequest } from "./DhtRpc";
|
|
8
|
+
import { SetPrivateRequest } from "./DhtRpc";
|
|
8
9
|
import { DisconnectNotice } from "./DhtRpc";
|
|
9
10
|
import { UnlockRequest } from "./DhtRpc";
|
|
10
11
|
import { LockResponse } from "./DhtRpc";
|
|
@@ -144,6 +145,10 @@ export interface IConnectionLockRpc<T = ServerCallContext> {
|
|
|
144
145
|
* @generated from protobuf rpc: gracefulDisconnect(dht.DisconnectNotice) returns (google.protobuf.Empty);
|
|
145
146
|
*/
|
|
146
147
|
gracefulDisconnect(request: DisconnectNotice, context: T): Promise<Empty>;
|
|
148
|
+
/**
|
|
149
|
+
* @generated from protobuf rpc: setPrivate(dht.SetPrivateRequest) returns (google.protobuf.Empty);
|
|
150
|
+
*/
|
|
151
|
+
setPrivate(request: SetPrivateRequest, context: T): Promise<Empty>;
|
|
147
152
|
}
|
|
148
153
|
/**
|
|
149
154
|
* @generated from protobuf service dht.ExternalApiRpc
|
|
@@ -582,6 +582,15 @@ export interface DisconnectNotice {
|
|
|
582
582
|
*/
|
|
583
583
|
disconnectMode: DisconnectMode;
|
|
584
584
|
}
|
|
585
|
+
/**
|
|
586
|
+
* @generated from protobuf message dht.SetPrivateRequest
|
|
587
|
+
*/
|
|
588
|
+
export interface SetPrivateRequest {
|
|
589
|
+
/**
|
|
590
|
+
* @generated from protobuf field: bool isPrivate = 1;
|
|
591
|
+
*/
|
|
592
|
+
isPrivate: boolean;
|
|
593
|
+
}
|
|
585
594
|
/**
|
|
586
595
|
* @generated from protobuf message dht.ExternalFetchDataRequest
|
|
587
596
|
*/
|
|
@@ -1154,6 +1163,18 @@ class DisconnectNotice$Type extends MessageType<DisconnectNotice> {
|
|
|
1154
1163
|
*/
|
|
1155
1164
|
export const DisconnectNotice = new DisconnectNotice$Type();
|
|
1156
1165
|
// @generated message type with reflection information, may provide speed optimized methods
|
|
1166
|
+
class SetPrivateRequest$Type extends MessageType<SetPrivateRequest> {
|
|
1167
|
+
constructor() {
|
|
1168
|
+
super("dht.SetPrivateRequest", [
|
|
1169
|
+
{ no: 1, name: "isPrivate", kind: "scalar", T: 8 /*ScalarType.BOOL*/ }
|
|
1170
|
+
]);
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
/**
|
|
1174
|
+
* @generated MessageType for protobuf message dht.SetPrivateRequest
|
|
1175
|
+
*/
|
|
1176
|
+
export const SetPrivateRequest = new SetPrivateRequest$Type();
|
|
1177
|
+
// @generated message type with reflection information, may provide speed optimized methods
|
|
1157
1178
|
class ExternalFetchDataRequest$Type extends MessageType<ExternalFetchDataRequest> {
|
|
1158
1179
|
constructor() {
|
|
1159
1180
|
super("dht.ExternalFetchDataRequest", [
|
|
@@ -1233,7 +1254,8 @@ export const WebrtcConnectorRpc = new ServiceType("dht.WebrtcConnectorRpc", [
|
|
|
1233
1254
|
export const ConnectionLockRpc = new ServiceType("dht.ConnectionLockRpc", [
|
|
1234
1255
|
{ name: "lockRequest", options: {}, I: LockRequest, O: LockResponse },
|
|
1235
1256
|
{ name: "unlockRequest", options: {}, I: UnlockRequest, O: Empty },
|
|
1236
|
-
{ name: "gracefulDisconnect", options: {}, I: DisconnectNotice, O: Empty }
|
|
1257
|
+
{ name: "gracefulDisconnect", options: {}, I: DisconnectNotice, O: Empty },
|
|
1258
|
+
{ name: "setPrivate", options: {}, I: SetPrivateRequest, O: Empty }
|
|
1237
1259
|
]);
|
|
1238
1260
|
/**
|
|
1239
1261
|
* @generated ServiceType for protobuf service dht.ExternalApiRpc
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@streamr/dht",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "102.0.0-beta.0",
|
|
4
4
|
"description": "Streamr Network DHT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"generate-protoc-code": "./proto.sh",
|
|
16
16
|
"build": "tsc -b tsconfig.node.json",
|
|
17
17
|
"build-browser": "webpack --mode=development --progress",
|
|
18
|
-
"check": "tsc -p ./tsconfig.jest.json
|
|
18
|
+
"check": "tsc -p ./tsconfig.jest.json",
|
|
19
19
|
"clean": "jest --clearCache || true; rm -rf dist *.tsbuildinfo node_modules/.cache || true",
|
|
20
20
|
"eslint": "eslint --cache --cache-location=node_modules/.cache/.eslintcache/ '*/**/*.{js,ts}'",
|
|
21
21
|
"test": "npm run test-unit && npm run test-integration && npm run test-end-to-end",
|
|
@@ -29,17 +29,17 @@
|
|
|
29
29
|
"@js-sdsl/ordered-map": "^4.4.2",
|
|
30
30
|
"@protobuf-ts/runtime": "^2.8.2",
|
|
31
31
|
"@protobuf-ts/runtime-rpc": "^2.8.2",
|
|
32
|
-
"@streamr/autocertifier-client": "
|
|
33
|
-
"@streamr/cdn-location": "
|
|
34
|
-
"@streamr/geoip-location": "
|
|
35
|
-
"@streamr/proto-rpc": "
|
|
36
|
-
"@streamr/utils": "
|
|
32
|
+
"@streamr/autocertifier-client": "102.0.0-beta.0",
|
|
33
|
+
"@streamr/cdn-location": "102.0.0-beta.0",
|
|
34
|
+
"@streamr/geoip-location": "102.0.0-beta.0",
|
|
35
|
+
"@streamr/proto-rpc": "102.0.0-beta.0",
|
|
36
|
+
"@streamr/utils": "102.0.0-beta.0",
|
|
37
37
|
"eventemitter3": "^5.0.0",
|
|
38
38
|
"heap": "^0.2.6",
|
|
39
39
|
"ipaddr.js": "^2.0.1",
|
|
40
40
|
"k-bucket": "^5.1.0",
|
|
41
41
|
"lodash": "^4.17.21",
|
|
42
|
-
"lru-cache": "11.0.
|
|
42
|
+
"lru-cache": "11.0.1",
|
|
43
43
|
"node-datachannel": "^0.10.1",
|
|
44
44
|
"querystring": "0.2.1",
|
|
45
45
|
"uuid": "^10.0.0",
|
|
@@ -48,15 +48,15 @@
|
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@streamr/browser-test-runner": "^0.0.1",
|
|
51
|
-
"@streamr/test-utils": "
|
|
51
|
+
"@streamr/test-utils": "102.0.0-beta.0",
|
|
52
52
|
"@types/heap": "^0.2.34",
|
|
53
53
|
"@types/k-bucket": "^5.0.1",
|
|
54
|
-
"@types/lodash": "^4.17.
|
|
54
|
+
"@types/lodash": "^4.17.10",
|
|
55
55
|
"@types/uuid": "^10.0.0",
|
|
56
56
|
"@types/websocket": "^1.0.10",
|
|
57
57
|
"@types/ws": "^8.5.12",
|
|
58
58
|
"jest-leak-detector": "^27.3.1",
|
|
59
|
-
"jest-matcher-utils": "^29.
|
|
59
|
+
"jest-matcher-utils": "^29.7.0",
|
|
60
60
|
"ts-essentials": "^10.0.2"
|
|
61
61
|
},
|
|
62
62
|
"optionalDependencies": {
|
package/proto.sh
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
mkdir -p ./
|
|
2
|
-
|
|
3
|
-
npx protoc --ts_out ./src/proto --ts_opt server_generic,generate_dependencies,long_type_number --proto_path ../.. packages/dht/protos/DhtRpc.proto
|
|
1
|
+
mkdir -p ./generated
|
|
2
|
+
npx protoc --ts_out ./generated --ts_opt server_generic,generate_dependencies,long_type_number --proto_path ../.. packages/dht/protos/DhtRpc.proto
|
package/protos/DhtRpc.proto
CHANGED
|
@@ -50,6 +50,7 @@ service ConnectionLockRpc {
|
|
|
50
50
|
rpc lockRequest (LockRequest) returns (LockResponse);
|
|
51
51
|
rpc unlockRequest (UnlockRequest) returns (google.protobuf.Empty);
|
|
52
52
|
rpc gracefulDisconnect (DisconnectNotice) returns (google.protobuf.Empty);
|
|
53
|
+
rpc setPrivate (SetPrivateRequest) returns (google.protobuf.Empty);
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
service ExternalApiRpc {
|
|
@@ -301,6 +302,10 @@ message DisconnectNotice {
|
|
|
301
302
|
DisconnectMode disconnectMode = 1;
|
|
302
303
|
}
|
|
303
304
|
|
|
305
|
+
message SetPrivateRequest {
|
|
306
|
+
bool isPrivate = 1;
|
|
307
|
+
}
|
|
308
|
+
|
|
304
309
|
message ExternalFetchDataRequest {
|
|
305
310
|
bytes key = 1;
|
|
306
311
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import EventEmitter from 'eventemitter3'
|
|
2
|
-
import { PeerDescriptor } from '
|
|
2
|
+
import { PeerDescriptor } from '../../generated/packages/dht/protos/DhtRpc'
|
|
3
3
|
import { ConnectionID, ConnectionType, ConnectionEvents } from './IConnection'
|
|
4
4
|
import { v4 as uuid } from 'uuid'
|
|
5
5
|
|
|
@@ -1,25 +1,27 @@
|
|
|
1
1
|
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
2
2
|
import { Logger } from '@streamr/utils'
|
|
3
|
-
import { Empty } from '
|
|
3
|
+
import { Empty } from '../../generated/google/protobuf/empty'
|
|
4
4
|
import {
|
|
5
5
|
DisconnectMode,
|
|
6
6
|
DisconnectNotice,
|
|
7
7
|
LockRequest,
|
|
8
8
|
LockResponse,
|
|
9
9
|
PeerDescriptor,
|
|
10
|
-
UnlockRequest
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
UnlockRequest,
|
|
11
|
+
SetPrivateRequest
|
|
12
|
+
} from '../../generated/packages/dht/protos/DhtRpc'
|
|
13
|
+
import { IConnectionLockRpc } from '../../generated/packages/dht/protos/DhtRpc.server'
|
|
13
14
|
import { DhtCallContext } from '../rpc-protocol/DhtCallContext'
|
|
14
15
|
import { getNodeIdOrUnknownFromPeerDescriptor } from './ConnectionManager'
|
|
15
16
|
import { LockID } from './ConnectionLockStates'
|
|
16
|
-
import { DhtAddress, areEqualPeerDescriptors,
|
|
17
|
+
import { DhtAddress, areEqualPeerDescriptors, toNodeId } from '../identifiers'
|
|
17
18
|
|
|
18
19
|
interface ConnectionLockRpcLocalOptions {
|
|
19
20
|
addRemoteLocked: (id: DhtAddress, lockId: LockID) => void
|
|
20
21
|
removeRemoteLocked: (id: DhtAddress, lockId: LockID) => void
|
|
21
22
|
closeConnection: (peerDescriptor: PeerDescriptor, gracefulLeave: boolean, reason?: string) => Promise<void>
|
|
22
23
|
getLocalPeerDescriptor: () => PeerDescriptor
|
|
24
|
+
setPrivate: (id: DhtAddress, isPrivate: boolean) => void
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
const logger = new Logger(module)
|
|
@@ -40,7 +42,7 @@ export class ConnectionLockRpcLocal implements IConnectionLockRpc {
|
|
|
40
42
|
}
|
|
41
43
|
return response
|
|
42
44
|
}
|
|
43
|
-
const remoteNodeId =
|
|
45
|
+
const remoteNodeId = toNodeId(senderPeerDescriptor)
|
|
44
46
|
this.options.addRemoteLocked(remoteNodeId, lockRequest.lockId)
|
|
45
47
|
const response: LockResponse = {
|
|
46
48
|
accepted: true
|
|
@@ -50,7 +52,7 @@ export class ConnectionLockRpcLocal implements IConnectionLockRpc {
|
|
|
50
52
|
|
|
51
53
|
async unlockRequest(unlockRequest: UnlockRequest, context: ServerCallContext): Promise<Empty> {
|
|
52
54
|
const senderPeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
|
|
53
|
-
const nodeId =
|
|
55
|
+
const nodeId = toNodeId(senderPeerDescriptor)
|
|
54
56
|
this.options.removeRemoteLocked(nodeId, unlockRequest.lockId)
|
|
55
57
|
return {}
|
|
56
58
|
}
|
|
@@ -66,4 +68,11 @@ export class ConnectionLockRpcLocal implements IConnectionLockRpc {
|
|
|
66
68
|
}
|
|
67
69
|
return {}
|
|
68
70
|
}
|
|
71
|
+
|
|
72
|
+
async setPrivate(request: SetPrivateRequest, context: ServerCallContext): Promise<Empty> {
|
|
73
|
+
const senderPeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
|
|
74
|
+
const senderId = toNodeId(senderPeerDescriptor)
|
|
75
|
+
this.options.setPrivate(senderId, request.isPrivate)
|
|
76
|
+
return {}
|
|
77
|
+
}
|
|
69
78
|
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { Logger } from '@streamr/utils'
|
|
2
2
|
import { RpcRemote } from '../dht/contact/RpcRemote'
|
|
3
|
-
import { DisconnectMode, DisconnectNotice, LockRequest, UnlockRequest } from '
|
|
4
|
-
import { ConnectionLockRpcClient } from '
|
|
3
|
+
import { DisconnectMode, DisconnectNotice, LockRequest, UnlockRequest, SetPrivateRequest } from '../../generated/packages/dht/protos/DhtRpc'
|
|
4
|
+
import { ConnectionLockRpcClient } from '../../generated/packages/dht/protos/DhtRpc.client'
|
|
5
5
|
import { LockID } from './ConnectionLockStates'
|
|
6
|
-
import {
|
|
6
|
+
import { toNodeId } from '../identifiers'
|
|
7
7
|
|
|
8
8
|
const logger = new Logger(module)
|
|
9
9
|
|
|
10
10
|
export class ConnectionLockRpcRemote extends RpcRemote<ConnectionLockRpcClient> {
|
|
11
11
|
|
|
12
12
|
public async lockRequest(lockId: LockID): Promise<boolean> {
|
|
13
|
-
logger.trace(`Requesting locked connection to ${
|
|
13
|
+
logger.trace(`Requesting locked connection to ${toNodeId(this.getPeerDescriptor())}`)
|
|
14
14
|
const request: LockRequest = {
|
|
15
15
|
lockId
|
|
16
16
|
}
|
|
@@ -25,7 +25,7 @@ export class ConnectionLockRpcRemote extends RpcRemote<ConnectionLockRpcClient>
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
public unlockRequest(lockId: LockID): void {
|
|
28
|
-
logger.trace(`Requesting connection to be unlocked from ${
|
|
28
|
+
logger.trace(`Requesting connection to be unlocked from ${toNodeId(this.getPeerDescriptor())}`)
|
|
29
29
|
const request: UnlockRequest = {
|
|
30
30
|
lockId
|
|
31
31
|
}
|
|
@@ -38,7 +38,7 @@ export class ConnectionLockRpcRemote extends RpcRemote<ConnectionLockRpcClient>
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
public async gracefulDisconnect(disconnectMode: DisconnectMode): Promise<void> {
|
|
41
|
-
logger.trace(`Notifying a graceful disconnect to ${
|
|
41
|
+
logger.trace(`Notifying a graceful disconnect to ${toNodeId(this.getPeerDescriptor())}`)
|
|
42
42
|
const request: DisconnectNotice = {
|
|
43
43
|
disconnectMode
|
|
44
44
|
}
|
|
@@ -49,4 +49,16 @@ export class ConnectionLockRpcRemote extends RpcRemote<ConnectionLockRpcClient>
|
|
|
49
49
|
})
|
|
50
50
|
await this.getClient().gracefulDisconnect(request, options)
|
|
51
51
|
}
|
|
52
|
+
|
|
53
|
+
public async setPrivate(isPrivate: boolean): Promise<void> {
|
|
54
|
+
logger.trace(`Setting isPrivate: ${isPrivate} for ${toNodeId(this.getPeerDescriptor())}`)
|
|
55
|
+
const request: SetPrivateRequest = {
|
|
56
|
+
isPrivate
|
|
57
|
+
}
|
|
58
|
+
const options = this.formDhtRpcOptions({
|
|
59
|
+
connect: false,
|
|
60
|
+
notification: true
|
|
61
|
+
})
|
|
62
|
+
await this.getClient().setPrivate(request, options)
|
|
63
|
+
}
|
|
52
64
|
}
|
|
@@ -12,6 +12,8 @@ export class ConnectionLockStates {
|
|
|
12
12
|
// TODO: remove weakLocks use localLocks instead. When opening weakLocks from the ConnectioManager,
|
|
13
13
|
// simply do not send lock requests.
|
|
14
14
|
private weakLocks: Map<DhtAddress, Set<LockID>> = new Map()
|
|
15
|
+
// Used to filter proxy connections from the connections view
|
|
16
|
+
private remotePrivateConnections: Set<DhtAddress> = new Set()
|
|
15
17
|
|
|
16
18
|
public getLocalLockedConnectionCount(): number {
|
|
17
19
|
return this.localLocks.size
|
|
@@ -99,6 +101,22 @@ export class ConnectionLockStates {
|
|
|
99
101
|
}
|
|
100
102
|
}
|
|
101
103
|
|
|
104
|
+
public addPrivate(id: DhtAddress): void {
|
|
105
|
+
this.remotePrivateConnections.add(id)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
public removePrivate(id: DhtAddress): void {
|
|
109
|
+
this.remotePrivateConnections.delete(id)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
public getPrivateConnections(): Set<DhtAddress> {
|
|
113
|
+
return this.remotePrivateConnections
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
public isPrivate(id: DhtAddress): boolean {
|
|
117
|
+
return this.remotePrivateConnections.has(id)
|
|
118
|
+
}
|
|
119
|
+
|
|
102
120
|
public clearAllLocks(id: DhtAddress): void {
|
|
103
121
|
this.localLocks.delete(id)
|
|
104
122
|
this.remoteLocks.delete(id)
|
|
@@ -10,9 +10,10 @@ import {
|
|
|
10
10
|
LockResponse,
|
|
11
11
|
Message,
|
|
12
12
|
PeerDescriptor,
|
|
13
|
-
UnlockRequest
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
UnlockRequest,
|
|
14
|
+
SetPrivateRequest
|
|
15
|
+
} from '../../generated/packages/dht/protos/DhtRpc'
|
|
16
|
+
import { ConnectionLockRpcClient } from '../../generated/packages/dht/protos/DhtRpc.client'
|
|
16
17
|
import { DEFAULT_SEND_OPTIONS, ITransport, SendOptions, TransportEvents } from '../transport/ITransport'
|
|
17
18
|
import { RoutingRpcCommunicator } from '../transport/RoutingRpcCommunicator'
|
|
18
19
|
import { ConnectionLockStates, LockID } from './ConnectionLockStates'
|
|
@@ -21,7 +22,7 @@ import { ManagedConnection, Events as ManagedConnectionEvents } from './ManagedC
|
|
|
21
22
|
import { ConnectionLockRpcRemote } from './ConnectionLockRpcRemote'
|
|
22
23
|
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
23
24
|
import { ConnectionLockRpcLocal } from './ConnectionLockRpcLocal'
|
|
24
|
-
import { DhtAddress, areEqualPeerDescriptors,
|
|
25
|
+
import { DhtAddress, areEqualPeerDescriptors, toNodeId } from '../identifiers'
|
|
25
26
|
import { getOfferer } from '../helpers/offering'
|
|
26
27
|
import { ConnectionsView } from './ConnectionsView'
|
|
27
28
|
import { OutputBuffer } from './OutputBuffer'
|
|
@@ -31,6 +32,7 @@ import { PendingConnection } from './PendingConnection'
|
|
|
31
32
|
export interface ConnectionManagerOptions {
|
|
32
33
|
maxConnections?: number
|
|
33
34
|
metricsContext: MetricsContext
|
|
35
|
+
allowIncomingPrivateConnections: boolean
|
|
34
36
|
createConnectorFacade: () => ConnectorFacade
|
|
35
37
|
}
|
|
36
38
|
|
|
@@ -108,7 +110,7 @@ const INTERNAL_SERVICE_ID = 'system/connection-manager'
|
|
|
108
110
|
// - if ManagedConnection#peerDescriptor is never undefined
|
|
109
111
|
export const getNodeIdOrUnknownFromPeerDescriptor = (peerDescriptor: PeerDescriptor | undefined): string => {
|
|
110
112
|
if (peerDescriptor !== undefined) {
|
|
111
|
-
return
|
|
113
|
+
return toNodeId(peerDescriptor)
|
|
112
114
|
} else {
|
|
113
115
|
return 'unknown'
|
|
114
116
|
}
|
|
@@ -127,6 +129,7 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
127
129
|
private rpcCommunicator?: RoutingRpcCommunicator
|
|
128
130
|
private disconnectorIntervalRef?: NodeJS.Timeout
|
|
129
131
|
private state = ConnectionManagerState.IDLE
|
|
132
|
+
private privateClientMode = false
|
|
130
133
|
|
|
131
134
|
constructor(options: ConnectionManagerOptions) {
|
|
132
135
|
super()
|
|
@@ -154,7 +157,18 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
154
157
|
removeRemoteLocked: (id: DhtAddress, lockId: LockID) => this.locks.removeRemoteLocked(id, lockId),
|
|
155
158
|
closeConnection: (peerDescriptor: PeerDescriptor, gracefulLeave: boolean, reason?: string) =>
|
|
156
159
|
this.closeConnection(peerDescriptor, gracefulLeave, reason),
|
|
157
|
-
getLocalPeerDescriptor: () => this.getLocalPeerDescriptor()
|
|
160
|
+
getLocalPeerDescriptor: () => this.getLocalPeerDescriptor(),
|
|
161
|
+
setPrivate: (id: DhtAddress, isPrivate: boolean) => {
|
|
162
|
+
if (!this.options.allowIncomingPrivateConnections) {
|
|
163
|
+
logger.debug(`node ${id} attemted to set a connection as private, but it is not allowed`)
|
|
164
|
+
return
|
|
165
|
+
}
|
|
166
|
+
if (isPrivate) {
|
|
167
|
+
this.locks.addPrivate(id)
|
|
168
|
+
} else {
|
|
169
|
+
this.locks.removePrivate(id)
|
|
170
|
+
}
|
|
171
|
+
}
|
|
158
172
|
})
|
|
159
173
|
this.rpcCommunicator.registerRpcMethod(LockRequest, LockResponse, 'lockRequest',
|
|
160
174
|
(req: LockRequest, context: ServerCallContext) => lockRpcLocal.lockRequest(req, context))
|
|
@@ -162,6 +176,8 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
162
176
|
(req: UnlockRequest, context: ServerCallContext) => lockRpcLocal.unlockRequest(req, context))
|
|
163
177
|
this.rpcCommunicator.registerRpcNotification(DisconnectNotice, 'gracefulDisconnect',
|
|
164
178
|
(req: DisconnectNotice, context: ServerCallContext) => lockRpcLocal.gracefulDisconnect(req, context))
|
|
179
|
+
this.rpcCommunicator.registerRpcNotification(SetPrivateRequest, 'setPrivate',
|
|
180
|
+
(req: SetPrivateRequest, context: ServerCallContext) => lockRpcLocal.setPrivate(req, context))
|
|
165
181
|
}
|
|
166
182
|
|
|
167
183
|
/*
|
|
@@ -173,14 +189,15 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
173
189
|
return
|
|
174
190
|
}
|
|
175
191
|
const disconnectionCandidates = new SortedContactList<ManagedConnection>({
|
|
176
|
-
referenceId:
|
|
192
|
+
referenceId: toNodeId(this.getLocalPeerDescriptor()),
|
|
177
193
|
maxSize: 100000, // TODO use options option or named constant?
|
|
178
194
|
allowToContainReferenceId: false
|
|
179
195
|
})
|
|
180
196
|
this.endpoints.forEach((endpoint) => {
|
|
181
197
|
if (endpoint.connected) {
|
|
182
198
|
const connection = endpoint.connection
|
|
183
|
-
|
|
199
|
+
const nodeId = connection.getNodeId()
|
|
200
|
+
if (!this.locks.isLocked(nodeId) && !this.locks.isPrivate(nodeId) && Date.now() - connection.getLastUsedTimestamp() > maxIdleTime) {
|
|
184
201
|
logger.trace('disconnecting in timeout interval: ' + getNodeIdOrUnknownFromPeerDescriptor(connection.getPeerDescriptor()))
|
|
185
202
|
disconnectionCandidates.addContact(connection)
|
|
186
203
|
}
|
|
@@ -189,7 +206,7 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
189
206
|
const disconnectables = disconnectionCandidates.getFurthestContacts(this.endpoints.size - maxConnections)
|
|
190
207
|
for (const disconnectable of disconnectables) {
|
|
191
208
|
const peerDescriptor = disconnectable.getPeerDescriptor()!
|
|
192
|
-
logger.trace('garbageCollecting ' +
|
|
209
|
+
logger.trace('garbageCollecting ' + toNodeId(peerDescriptor))
|
|
193
210
|
this.gracefullyDisconnectAsync(peerDescriptor, DisconnectMode.NORMAL).catch((_e) => { })
|
|
194
211
|
}
|
|
195
212
|
}
|
|
@@ -273,7 +290,7 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
273
290
|
if (this.isConnectionToSelf(peerDescriptor)) {
|
|
274
291
|
throw new Err.CannotConnectToSelf('Cannot send to self')
|
|
275
292
|
}
|
|
276
|
-
const nodeId =
|
|
293
|
+
const nodeId = toNodeId(peerDescriptor)
|
|
277
294
|
logger.trace(`Sending message to: ${nodeId}`)
|
|
278
295
|
message = {
|
|
279
296
|
...message,
|
|
@@ -283,7 +300,7 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
283
300
|
if (!connection && opts.connect) {
|
|
284
301
|
connection = this.connectorFacade.createConnection(peerDescriptor)
|
|
285
302
|
this.onNewConnection(connection)
|
|
286
|
-
} else if (!connection) {
|
|
303
|
+
} else if (!connection || (connection && !this.endpoints.get(nodeId)!.connected && !opts.connect)) {
|
|
287
304
|
throw new Err.SendFailed('No connection to target, connect flag is false')
|
|
288
305
|
}
|
|
289
306
|
const binary = Message.toBinary(message)
|
|
@@ -317,7 +334,7 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
317
334
|
|
|
318
335
|
public hasConnection(nodeId: DhtAddress): boolean {
|
|
319
336
|
// TODO if we remove filtering in getConnections, this can just be this.connection.has(nodeId)
|
|
320
|
-
return this.getConnections().some((c) =>
|
|
337
|
+
return this.getConnections().some((c) => toNodeId(c) == nodeId)
|
|
321
338
|
}
|
|
322
339
|
|
|
323
340
|
public getConnectionCount(): number {
|
|
@@ -341,7 +358,7 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
341
358
|
return
|
|
342
359
|
}
|
|
343
360
|
if (this.duplicateMessageDetector.isMostLikelyDuplicate(message.messageId)) {
|
|
344
|
-
logger.trace('handleMessage filtered duplicate ' +
|
|
361
|
+
logger.trace('handleMessage filtered duplicate ' + toNodeId(message.sourceDescriptor!)
|
|
345
362
|
+ ' ' + message.serviceId + ' ' + message.messageId)
|
|
346
363
|
return
|
|
347
364
|
}
|
|
@@ -349,7 +366,7 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
349
366
|
if (message.serviceId === INTERNAL_SERVICE_ID) {
|
|
350
367
|
this.rpcCommunicator?.handleMessageFromPeer(message)
|
|
351
368
|
} else {
|
|
352
|
-
logger.trace('emit "message" ' +
|
|
369
|
+
logger.trace('emit "message" ' + toNodeId(message.sourceDescriptor!)
|
|
353
370
|
+ ' ' + message.serviceId + ' ' + message.messageId)
|
|
354
371
|
this.emit('message', message)
|
|
355
372
|
}
|
|
@@ -365,6 +382,7 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
365
382
|
try {
|
|
366
383
|
message = Message.fromBinary(data)
|
|
367
384
|
} catch (e) {
|
|
385
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
368
386
|
logger.debug(`Parsing incoming data into Message failed: ${e}`)
|
|
369
387
|
return
|
|
370
388
|
}
|
|
@@ -372,6 +390,7 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
372
390
|
try {
|
|
373
391
|
this.handleMessage(message)
|
|
374
392
|
} catch (e) {
|
|
393
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
375
394
|
logger.debug(`Handling incoming data failed: ${e}`)
|
|
376
395
|
}
|
|
377
396
|
}
|
|
@@ -381,7 +400,7 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
381
400
|
managedConnection.on('managedData', this.onData)
|
|
382
401
|
managedConnection.once('disconnected', (gracefulLeave: boolean) => this.onDisconnected(peerDescriptor, gracefulLeave))
|
|
383
402
|
|
|
384
|
-
const nodeId =
|
|
403
|
+
const nodeId = toNodeId(peerDescriptor)
|
|
385
404
|
const endpoint = this.endpoints.get(nodeId)! as ConnectingEndpoint
|
|
386
405
|
const outputBuffer = endpoint.buffer
|
|
387
406
|
const pendingConnection = endpoint.connection
|
|
@@ -396,12 +415,15 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
396
415
|
connected: true,
|
|
397
416
|
connection: managedConnection
|
|
398
417
|
})
|
|
418
|
+
if (this.privateClientMode) {
|
|
419
|
+
this.setPrivateForConnection(peerDescriptor, this.privateClientMode).catch(() => {})
|
|
420
|
+
}
|
|
399
421
|
this.emit('connected', peerDescriptor)
|
|
400
422
|
this.onConnectionCountChange()
|
|
401
423
|
}
|
|
402
424
|
|
|
403
425
|
private onDisconnected(peerDescriptor: PeerDescriptor, gracefulLeave: boolean) {
|
|
404
|
-
const nodeId =
|
|
426
|
+
const nodeId = toNodeId(peerDescriptor)
|
|
405
427
|
logger.trace(nodeId + ' onDisconnected() gracefulLeave: ' + gracefulLeave)
|
|
406
428
|
const endpoint = this.endpoints.get(nodeId)
|
|
407
429
|
if (endpoint) {
|
|
@@ -430,10 +452,10 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
430
452
|
}
|
|
431
453
|
|
|
432
454
|
private acceptNewConnection(newConnection: PendingConnection): boolean {
|
|
433
|
-
const nodeId =
|
|
455
|
+
const nodeId = toNodeId(newConnection.getPeerDescriptor())
|
|
434
456
|
logger.trace(nodeId + ' acceptNewConnection()')
|
|
435
457
|
if (this.endpoints.has(nodeId)) {
|
|
436
|
-
if (getOfferer(
|
|
458
|
+
if (getOfferer(toNodeId(this.getLocalPeerDescriptor()), nodeId) === 'remote') {
|
|
437
459
|
let buffer: OutputBuffer | undefined
|
|
438
460
|
const endpoint = this.endpoints.get(nodeId)!
|
|
439
461
|
// This is a rare occurance but it does happen from time to time.
|
|
@@ -467,7 +489,7 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
467
489
|
}
|
|
468
490
|
|
|
469
491
|
private async closeConnection(peerDescriptor: PeerDescriptor, gracefulLeave: boolean, reason?: string): Promise<void> {
|
|
470
|
-
const nodeId =
|
|
492
|
+
const nodeId = toNodeId(peerDescriptor)
|
|
471
493
|
logger.trace(nodeId + ' ' + 'closeConnection() ' + reason)
|
|
472
494
|
this.locks.clearAllLocks(nodeId)
|
|
473
495
|
if (this.endpoints.has(nodeId)) {
|
|
@@ -483,7 +505,7 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
483
505
|
if (this.state === ConnectionManagerState.STOPPED || areEqualPeerDescriptors(targetDescriptor, this.getLocalPeerDescriptor())) {
|
|
484
506
|
return
|
|
485
507
|
}
|
|
486
|
-
const nodeId =
|
|
508
|
+
const nodeId = toNodeId(targetDescriptor)
|
|
487
509
|
const rpcRemote = new ConnectionLockRpcRemote(
|
|
488
510
|
this.getLocalPeerDescriptor(),
|
|
489
511
|
targetDescriptor,
|
|
@@ -500,7 +522,7 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
500
522
|
if (this.state === ConnectionManagerState.STOPPED || areEqualPeerDescriptors(targetDescriptor, this.getLocalPeerDescriptor())) {
|
|
501
523
|
return
|
|
502
524
|
}
|
|
503
|
-
const nodeId =
|
|
525
|
+
const nodeId = toNodeId(targetDescriptor)
|
|
504
526
|
this.locks.removeLocalLocked(nodeId, lockId)
|
|
505
527
|
const rpcRemote = new ConnectionLockRpcRemote(
|
|
506
528
|
this.getLocalPeerDescriptor(),
|
|
@@ -514,21 +536,55 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
514
536
|
}
|
|
515
537
|
|
|
516
538
|
public weakLockConnection(nodeId: DhtAddress, lockId: LockID): void {
|
|
517
|
-
if (this.state === ConnectionManagerState.STOPPED || (nodeId ===
|
|
539
|
+
if (this.state === ConnectionManagerState.STOPPED || (nodeId === toNodeId(this.getLocalPeerDescriptor()))) {
|
|
518
540
|
return
|
|
519
541
|
}
|
|
520
542
|
this.locks.addWeakLocked(nodeId, lockId)
|
|
521
543
|
}
|
|
522
544
|
|
|
523
545
|
public weakUnlockConnection(nodeId: DhtAddress, lockId: LockID): void {
|
|
524
|
-
if (this.state === ConnectionManagerState.STOPPED || (nodeId ===
|
|
546
|
+
if (this.state === ConnectionManagerState.STOPPED || (nodeId === toNodeId(this.getLocalPeerDescriptor()))) {
|
|
525
547
|
return
|
|
526
548
|
}
|
|
527
549
|
this.locks.removeWeakLocked(nodeId, lockId)
|
|
528
550
|
}
|
|
529
551
|
|
|
552
|
+
public async enablePrivateClientMode(): Promise<void> {
|
|
553
|
+
this.privateClientMode = true
|
|
554
|
+
await Promise.all(Array.from(this.endpoints.values()).map((endpoint) => {
|
|
555
|
+
if (endpoint.connected) {
|
|
556
|
+
const peerDescription = endpoint.connection.getPeerDescriptor()
|
|
557
|
+
return this.setPrivateForConnection(peerDescription!, true)
|
|
558
|
+
}
|
|
559
|
+
}))
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
public async disablePrivateClientMode(): Promise<void> {
|
|
563
|
+
this.privateClientMode = false
|
|
564
|
+
await Promise.all(Array.from(this.endpoints.values()).map((endpoint) => {
|
|
565
|
+
if (endpoint.connected) {
|
|
566
|
+
const peerDescription = endpoint.connection.getPeerDescriptor()
|
|
567
|
+
return this.setPrivateForConnection(peerDescription!, false)
|
|
568
|
+
}
|
|
569
|
+
}))
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
public isPrivateClientMode(): boolean {
|
|
573
|
+
return this.privateClientMode
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
private async setPrivateForConnection(targetDescriptor: PeerDescriptor, isPrivate: boolean): Promise<void> {
|
|
577
|
+
const rpcRemote = new ConnectionLockRpcRemote(
|
|
578
|
+
this.getLocalPeerDescriptor(),
|
|
579
|
+
targetDescriptor,
|
|
580
|
+
this.rpcCommunicator!,
|
|
581
|
+
ConnectionLockRpcClient
|
|
582
|
+
)
|
|
583
|
+
await rpcRemote.setPrivate(isPrivate)
|
|
584
|
+
}
|
|
585
|
+
|
|
530
586
|
private async gracefullyDisconnectAsync(targetDescriptor: PeerDescriptor, disconnectMode: DisconnectMode): Promise<void> {
|
|
531
|
-
const endpoint = this.endpoints.get(
|
|
587
|
+
const endpoint = this.endpoints.get(toNodeId(targetDescriptor))
|
|
532
588
|
|
|
533
589
|
if (!endpoint) {
|
|
534
590
|
logger.debug('gracefullyDisconnectedAsync() tried on a non-existing connection')
|
|
@@ -565,7 +621,7 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
565
621
|
}
|
|
566
622
|
|
|
567
623
|
private async doGracefullyDisconnectAsync(targetDescriptor: PeerDescriptor, disconnectMode: DisconnectMode): Promise<void> {
|
|
568
|
-
const nodeId =
|
|
624
|
+
const nodeId = toNodeId(targetDescriptor)
|
|
569
625
|
logger.trace(nodeId + ' gracefullyDisconnectAsync()')
|
|
570
626
|
const rpcRemote = new ConnectionLockRpcRemote(
|
|
571
627
|
this.getLocalPeerDescriptor(),
|
|
@@ -585,11 +641,21 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
585
641
|
.map((endpoint) => endpoint)
|
|
586
642
|
// TODO is this filtering needed? (if it is, should we do the same filtering e.g.
|
|
587
643
|
// in getConnection() or in other methods which access this.endpoints directly?)
|
|
588
|
-
.filter((endpoint) => endpoint.connected)
|
|
644
|
+
.filter((endpoint) => endpoint.connected && !this.locks.isPrivate(toNodeId(endpoint.connection.getPeerDescriptor()!)))
|
|
589
645
|
.map((endpoint) => endpoint.connection.getPeerDescriptor()!)
|
|
590
646
|
}
|
|
591
647
|
|
|
592
648
|
private onConnectionCountChange() {
|
|
593
649
|
this.metrics.connectionAverageCount.record(this.endpoints.size)
|
|
594
650
|
}
|
|
651
|
+
|
|
652
|
+
public getDiagnosticInfo(): Record<string, unknown> {
|
|
653
|
+
const managedConnections: ManagedConnection[] = Array.from(this.endpoints.values())
|
|
654
|
+
.filter((endpoint) => endpoint.connected)
|
|
655
|
+
.map((endpoint) => endpoint.connection as ManagedConnection)
|
|
656
|
+
return {
|
|
657
|
+
connections: managedConnections.map((connection) => connection.getDiagnosticInfo()),
|
|
658
|
+
connectionCount: this.endpoints.size
|
|
659
|
+
}
|
|
660
|
+
}
|
|
595
661
|
}
|