@streamr/dht 101.1.2 → 102.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/package.json +17 -18
- 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 +96 -32
- 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 +2 -2
- package/dist/src/connection/Handshaker.js +11 -7
- package/dist/src/connection/Handshaker.js.map +1 -1
- package/dist/src/connection/ManagedConnection.d.ts +7 -1
- package/dist/src/connection/ManagedConnection.js +41 -8
- 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 +22 -11
- package/dist/src/connection/connectivityChecker.js.map +1 -1
- package/dist/src/connection/connectivityRequestHandler.js +4 -4
- 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 +5 -4
- 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/simulator/pings.d.ts +1 -1
- package/dist/src/connection/simulator/pings.js +3 -3
- package/dist/src/connection/simulator/pings.js.map +1 -1
- package/dist/src/connection/webrtc/NodeWebrtcConnection.d.ts +2 -1
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js +13 -8
- 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 +28 -17
- 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/webrtc/iceServerAsString.js +1 -2
- package/dist/src/connection/webrtc/iceServerAsString.js.map +1 -1
- package/dist/src/connection/websocket/AbstractWebsocketClientConnection.d.ts +0 -1
- 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 -4
- 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/WebsocketServerConnection.d.ts +0 -1
- package/dist/src/connection/websocket/WebsocketServerConnector.d.ts +1 -1
- package/dist/src/connection/websocket/WebsocketServerConnector.js +34 -24
- package/dist/src/connection/websocket/WebsocketServerConnector.js.map +1 -1
- package/dist/src/dht/DhtNode.d.ts +5 -2
- package/dist/src/dht/DhtNode.js +20 -8
- package/dist/src/dht/DhtNode.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcLocal.d.ts +4 -4
- 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 +3 -2
- package/dist/src/dht/PeerManager.js +12 -11
- 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 +2 -2
- 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 -2
- 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 -2
- 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.d.ts +0 -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 +3 -3
- 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/DuplicateDetector.js.map +1 -1
- 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 +7 -8
- package/dist/src/dht/routing/RoutingSession.js.map +1 -1
- package/dist/src/dht/routing/RoutingTablesCache.d.ts +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 +3 -3
- package/dist/src/dht/store/LocalDataStore.js.map +1 -1
- package/dist/src/dht/store/StoreManager.d.ts +3 -3
- 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 +4 -4
- 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/AddressTools.js +2 -3
- package/dist/src/helpers/AddressTools.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/debugHelpers.js +2 -2
- package/dist/src/helpers/debugHelpers.js.map +1 -1
- package/dist/src/helpers/protoClasses.d.ts +1 -1
- package/dist/src/helpers/protoClasses.js +1 -1
- package/dist/src/helpers/protoClasses.js.map +1 -1
- package/dist/src/helpers/protoToString.js +1 -2
- package/dist/src/helpers/protoToString.js.map +1 -1
- package/dist/src/helpers/version.d.ts +1 -1
- package/dist/src/helpers/version.js +4 -4
- package/dist/src/helpers/version.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/eslint.config.mjs +12 -0
- package/jest.config.ts +12 -0
- package/package.json +17 -18
- package/proto.sh +2 -3
- package/protos/DhtRpc.proto +11 -4
- 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 +93 -27
- package/src/connection/ConnectionsView.ts +1 -1
- package/src/connection/ConnectorFacade.ts +1 -1
- package/src/connection/Handshaker.ts +18 -14
- package/src/connection/ManagedConnection.ts +28 -3
- package/src/connection/PendingConnection.ts +1 -1
- package/src/connection/connectivityChecker.ts +6 -5
- package/src/connection/connectivityRequestHandler.ts +4 -4
- package/src/connection/simulator/Simulator.ts +8 -7
- 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/simulator/pings.ts +1 -1
- package/src/connection/webrtc/BrowserWebrtcConnection.ts +10 -1
- package/src/connection/webrtc/NodeWebrtcConnection.ts +15 -11
- package/src/connection/webrtc/WebrtcConnector.ts +13 -11
- 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 +24 -20
- package/src/dht/DhtNode.ts +29 -11
- package/src/dht/DhtNodeRpcLocal.ts +8 -8
- 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 +16 -14
- 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 +3 -3
- 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 +10 -10
- 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/DuplicateDetector.ts +1 -1
- 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 +9 -10
- package/src/dht/routing/RoutingTablesCache.ts +1 -1
- package/src/dht/routing/getPreviousPeer.ts +1 -1
- package/src/dht/store/LocalDataStore.ts +5 -5
- package/src/dht/store/StoreManager.ts +13 -13
- package/src/dht/store/StoreRpcLocal.ts +9 -9
- 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 +2 -2
- package/src/helpers/version.ts +2 -2
- 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 +9 -9
- package/test/benchmark/KademliaCorrectness.test.ts +7 -7
- package/test/benchmark/RingCorrectness.test.ts +8 -8
- package/test/benchmark/SortedContactListBenchmark.test.ts +10 -10
- package/test/benchmark/hybrid-network-simulation/RingContactList.test.ts +3 -3
- 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 +3 -3
- package/test/end-to-end/memory-leak.test.ts +6 -6
- package/test/integration/ConnectionLocking.test.ts +48 -37
- package/test/integration/ConnectionManager.test.ts +62 -6
- package/test/integration/ConnectivityChecking.test.ts +3 -2
- package/test/integration/DhtJoinPeerDiscovery.test.ts +2 -2
- package/test/integration/DhtNode.test.ts +6 -6
- 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 +8 -7
- package/test/integration/Layer1-scale.test.ts +3 -3
- 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 +13 -13
- package/test/integration/RouterRpcRemote.test.ts +7 -7
- package/test/integration/SimultaneousConnections.test.ts +14 -13
- package/test/integration/Store.test.ts +9 -9
- package/test/integration/StoreAndDelete.test.ts +10 -10
- package/test/integration/StoreOnDhtWithThreeNodes.test.ts +10 -10
- package/test/integration/StoreOnDhtWithTwoNodes.test.ts +10 -10
- package/test/integration/StoreRpcRemote.test.ts +11 -11
- package/test/integration/WebrtcConnectionManagement.test.ts +4 -31
- package/test/integration/WebrtcConnectorRpc.test.ts +14 -14
- package/test/integration/Websocket.test.ts +0 -2
- package/test/integration/WebsocketClientConnectorRpc.test.ts +8 -8
- package/test/integration/WebsocketConnectionManagement.test.ts +11 -12
- package/test/integration/{rpc-connections-over-webrpc.test.ts → rpc-connections-over-webrtc.test.ts} +12 -46
- package/test/unit/AutoCertifierClientFacade.test.ts +6 -6
- 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 +2 -2
- package/test/unit/ListeningRpcCommunicator.test.ts +52 -0
- package/test/unit/LocalDataStore.test.ts +21 -21
- package/test/unit/PeerManager.test.ts +15 -15
- 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 +6 -6
- package/test/unit/Router.test.ts +6 -6
- package/test/unit/RoutingSession.test.ts +13 -6
- package/test/unit/SortedContactList.test.ts +8 -8
- package/test/unit/StoreManager.test.ts +12 -12
- 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 +6 -6
- package/test/unit/createPeerDescriptor.test.ts +4 -4
- package/test/unit/customMatchers.test.ts +18 -0
- package/test/unit/getClosestNodes.test.ts +5 -5
- package/test/unit/version.test.ts +9 -9
- package/test/utils/FakeConnectorFacade.ts +1 -1
- package/test/utils/FakeTransport.ts +12 -9
- package/test/utils/customMatchers.ts +9 -9
- 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 -4
- package/test/utils/utils.ts +11 -11
- package/tsconfig.jest.json +2 -1
- package/tsconfig.node.json +1 -0
- package/.eslintignore +0 -5
- package/.eslintrc +0 -3
- package/dist/src/proto/google/protobuf/any.d.ts +0 -173
- package/dist/src/proto/google/protobuf/any.js +0 -155
- package/dist/src/proto/google/protobuf/any.js.map +0 -1
- package/dist/src/proto/google/protobuf/empty.d.ts +0 -32
- package/dist/src/proto/google/protobuf/empty.js +0 -32
- package/dist/src/proto/google/protobuf/empty.js.map +0 -1
- package/dist/src/proto/google/protobuf/timestamp.d.ts +0 -149
- package/dist/src/proto/google/protobuf/timestamp.js +0 -136
- package/dist/src/proto/google/protobuf/timestamp.js.map +0 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +0 -352
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +0 -278
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +0 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +0 -975
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +0 -661
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +0 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +0 -157
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.js +0 -3
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.js.map +0 -1
- package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.d.ts +0 -87
- package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.js +0 -66
- 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/jest.config.js +0 -5
- package/src/proto/google/protobuf/any.ts +0 -319
- package/src/proto/google/protobuf/empty.ts +0 -82
- package/src/proto/google/protobuf/timestamp.ts +0 -281
- package/src/proto/packages/dht/protos/DhtRpc.client.ts +0 -407
- package/src/proto/packages/dht/protos/DhtRpc.server.ts +0 -160
- package/src/proto/packages/dht/protos/DhtRpc.ts +0 -1244
- package/src/proto/packages/proto-rpc/protos/ProtoRpc.ts +0 -108
- package/src/proto/tests.ts +0 -52
- package/test/benchmark/any.test.ts +0 -28
- /package/{src/types/glogal.d.ts → test/types/global.d.ts} +0 -0
|
@@ -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)
|
|
@@ -291,7 +308,7 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
291
308
|
this.metrics.sendMessagesPerSecond.record(1)
|
|
292
309
|
|
|
293
310
|
if (this.endpoints.get(nodeId)!.connected) {
|
|
294
|
-
|
|
311
|
+
(connection as ManagedConnection).send(binary)
|
|
295
312
|
} else {
|
|
296
313
|
return (this.endpoints.get(nodeId)! as ConnectingEndpoint).buffer.push(binary)
|
|
297
314
|
}
|
|
@@ -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)
|
|
656
|
+
return {
|
|
657
|
+
connections: managedConnections.map((connection) => connection.getDiagnosticInfo()),
|
|
658
|
+
connectionCount: this.endpoints.size
|
|
659
|
+
}
|
|
660
|
+
}
|
|
595
661
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DhtAddress } from '../identifiers'
|
|
2
|
-
import { PeerDescriptor } from '
|
|
2
|
+
import { PeerDescriptor } from '../../generated/packages/dht/protos/DhtRpc'
|
|
3
3
|
|
|
4
4
|
export interface ConnectionsView {
|
|
5
5
|
getConnections: () => PeerDescriptor[]
|
|
@@ -2,7 +2,7 @@ import { Logger } from '@streamr/utils'
|
|
|
2
2
|
import {
|
|
3
3
|
ConnectivityResponse,
|
|
4
4
|
PeerDescriptor
|
|
5
|
-
} from '
|
|
5
|
+
} from '../../generated/packages/dht/protos/DhtRpc'
|
|
6
6
|
import { ITransport } from '../transport/ITransport'
|
|
7
7
|
import { PortRange, TlsCertificate } from './ConnectionManager'
|
|
8
8
|
import { Simulator } from './simulator/Simulator'
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { Logger } from '@streamr/utils'
|
|
2
2
|
import { EventEmitter } from 'eventemitter3'
|
|
3
3
|
import { v4 } from 'uuid'
|
|
4
|
-
import { Message, HandshakeRequest, HandshakeResponse, PeerDescriptor, HandshakeError } from '
|
|
4
|
+
import { Message, HandshakeRequest, HandshakeResponse, PeerDescriptor, HandshakeError } from '../../generated/packages/dht/protos/DhtRpc'
|
|
5
5
|
import { IConnection } from './IConnection'
|
|
6
|
-
import { LOCAL_PROTOCOL_VERSION,
|
|
7
|
-
import {
|
|
6
|
+
import { LOCAL_PROTOCOL_VERSION, isMaybeSupportedProtocolVersion } from '../helpers/version'
|
|
7
|
+
import { toNodeId } from '../identifiers'
|
|
8
8
|
import { PendingConnection } from './PendingConnection'
|
|
9
|
+
import { version as applicationVersion } from '../../package.json'
|
|
9
10
|
|
|
10
11
|
const logger = new Logger(module)
|
|
11
12
|
|
|
12
13
|
interface HandshakerEvents {
|
|
13
|
-
handshakeRequest: (source: PeerDescriptor,
|
|
14
|
+
handshakeRequest: (source: PeerDescriptor, protocolVersion: string, target?: PeerDescriptor) => void
|
|
14
15
|
handshakeCompleted: (remote: PeerDescriptor) => void
|
|
15
16
|
handshakeFailed: (error?: HandshakeError) => void
|
|
16
17
|
}
|
|
@@ -35,7 +36,7 @@ export const createOutgoingHandshaker = (
|
|
|
35
36
|
pendingConnection.off('disconnected', managedConnectionDisconnectedListener)
|
|
36
37
|
}
|
|
37
38
|
const handshakeFailedListener = (error?: HandshakeError) => {
|
|
38
|
-
if (error === HandshakeError.INVALID_TARGET_PEER_DESCRIPTOR || error === HandshakeError.
|
|
39
|
+
if (error === HandshakeError.INVALID_TARGET_PEER_DESCRIPTOR || error === HandshakeError.UNSUPPORTED_PROTOCOL_VERSION) {
|
|
39
40
|
pendingConnection.close(false)
|
|
40
41
|
stopHandshaker()
|
|
41
42
|
} else {
|
|
@@ -43,12 +44,12 @@ export const createOutgoingHandshaker = (
|
|
|
43
44
|
}
|
|
44
45
|
}
|
|
45
46
|
const handshakeCompletedListener = (peerDescriptor: PeerDescriptor) => {
|
|
46
|
-
logger.trace('handshake completed for outgoing connection, ' +
|
|
47
|
+
logger.trace('handshake completed for outgoing connection, ' + toNodeId(peerDescriptor))
|
|
47
48
|
pendingConnection.onHandshakeCompleted(connection)
|
|
48
49
|
stopHandshaker()
|
|
49
50
|
}
|
|
50
51
|
const connectedListener = () => handshaker.sendHandshakeRequest(targetPeerDescriptor)
|
|
51
|
-
const disconnectedListener = (graceful: boolean) => {
|
|
52
|
+
const disconnectedListener = (graceful: boolean) => {
|
|
52
53
|
pendingConnection.close(graceful)
|
|
53
54
|
stopHandshaker()
|
|
54
55
|
}
|
|
@@ -112,7 +113,8 @@ export const createHandshakeRequest = (localPeerDescriptor: PeerDescriptor, remo
|
|
|
112
113
|
const outgoingHandshake: HandshakeRequest = {
|
|
113
114
|
sourcePeerDescriptor: localPeerDescriptor,
|
|
114
115
|
targetPeerDescriptor: remotePeerDescriptor,
|
|
115
|
-
|
|
116
|
+
protocolVersion: LOCAL_PROTOCOL_VERSION,
|
|
117
|
+
applicationVersion
|
|
116
118
|
}
|
|
117
119
|
return {
|
|
118
120
|
serviceId: Handshaker.HANDSHAKER_SERVICE_ID,
|
|
@@ -122,13 +124,14 @@ export const createHandshakeRequest = (localPeerDescriptor: PeerDescriptor, remo
|
|
|
122
124
|
handshakeRequest: outgoingHandshake
|
|
123
125
|
}
|
|
124
126
|
}
|
|
125
|
-
}
|
|
127
|
+
}
|
|
126
128
|
|
|
127
129
|
export const createHandshakeResponse = (localPeerDescriptor: PeerDescriptor, error?: HandshakeError): Message => {
|
|
128
130
|
const outgoingHandshakeResponse: HandshakeResponse = {
|
|
129
131
|
sourcePeerDescriptor: localPeerDescriptor,
|
|
130
132
|
error,
|
|
131
|
-
|
|
133
|
+
protocolVersion: LOCAL_PROTOCOL_VERSION,
|
|
134
|
+
applicationVersion
|
|
132
135
|
}
|
|
133
136
|
return {
|
|
134
137
|
serviceId: Handshaker.HANDSHAKER_SERVICE_ID,
|
|
@@ -165,15 +168,16 @@ export class Handshaker extends EventEmitter<HandshakerEvents> {
|
|
|
165
168
|
const handshake = message.body.handshakeRequest
|
|
166
169
|
this.emit(
|
|
167
170
|
'handshakeRequest',
|
|
168
|
-
handshake.sourcePeerDescriptor!,
|
|
169
|
-
handshake.
|
|
171
|
+
handshake.sourcePeerDescriptor!,
|
|
172
|
+
handshake.protocolVersion,
|
|
170
173
|
handshake.targetPeerDescriptor
|
|
171
174
|
)
|
|
172
175
|
}
|
|
173
176
|
if (message.body.oneofKind === 'handshakeResponse') {
|
|
174
177
|
logger.trace('handshake response received')
|
|
175
178
|
const handshake = message.body.handshakeResponse
|
|
176
|
-
const error = !
|
|
179
|
+
const error = !isMaybeSupportedProtocolVersion(handshake.protocolVersion)
|
|
180
|
+
? HandshakeError.UNSUPPORTED_PROTOCOL_VERSION : handshake.error
|
|
177
181
|
if (error !== undefined) {
|
|
178
182
|
this.emit('handshakeFailed', error)
|
|
179
183
|
} else {
|
|
@@ -183,7 +187,7 @@ export class Handshaker extends EventEmitter<HandshakerEvents> {
|
|
|
183
187
|
} catch (err) {
|
|
184
188
|
logger.debug('error while parsing handshake message', err)
|
|
185
189
|
}
|
|
186
|
-
|
|
190
|
+
|
|
187
191
|
}
|
|
188
192
|
|
|
189
193
|
public sendHandshakeRequest(remotePeerDescriptor?: PeerDescriptor): void {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { ConnectionID, IConnection } from './IConnection'
|
|
2
2
|
import * as Err from '../helpers/errors'
|
|
3
|
-
import { PeerDescriptor } from '
|
|
3
|
+
import { PeerDescriptor } from '../../generated/packages/dht/protos/DhtRpc'
|
|
4
4
|
import { Logger } from '@streamr/utils'
|
|
5
5
|
import EventEmitter from 'eventemitter3'
|
|
6
6
|
import { getNodeIdOrUnknownFromPeerDescriptor } from './ConnectionManager'
|
|
7
|
-
import { DhtAddress,
|
|
7
|
+
import { DhtAddress, toNodeId } from '../identifiers'
|
|
8
8
|
import { createRandomConnectionId } from './Connection'
|
|
9
9
|
|
|
10
10
|
export interface ManagedConnectionEvents {
|
|
@@ -26,6 +26,11 @@ export class ManagedConnection extends EventEmitter<ManagedConnectionEvents> {
|
|
|
26
26
|
private lastUsedTimestamp: number = Date.now()
|
|
27
27
|
private replacedAsDuplicate = false
|
|
28
28
|
private stopped = false
|
|
29
|
+
private openedAt = Date.now()
|
|
30
|
+
private bytesSent = 0
|
|
31
|
+
private bytesReceived = 0
|
|
32
|
+
private messagesSent = 0
|
|
33
|
+
private messagesReceived = 0
|
|
29
34
|
|
|
30
35
|
constructor(peerDescriptor: PeerDescriptor, connection: IConnection) {
|
|
31
36
|
super()
|
|
@@ -34,6 +39,8 @@ export class ManagedConnection extends EventEmitter<ManagedConnectionEvents> {
|
|
|
34
39
|
|
|
35
40
|
connection.on('data', (bytes: Uint8Array) => {
|
|
36
41
|
this.lastUsedTimestamp = Date.now()
|
|
42
|
+
this.messagesReceived += 1
|
|
43
|
+
this.bytesReceived += bytes.length
|
|
37
44
|
this.emit('managedData', bytes, this.getPeerDescriptor()!)
|
|
38
45
|
})
|
|
39
46
|
connection.on('disconnected', (gracefulLeave) => this.onDisconnected(gracefulLeave))
|
|
@@ -62,6 +69,8 @@ export class ManagedConnection extends EventEmitter<ManagedConnectionEvents> {
|
|
|
62
69
|
throw new Err.SendFailed('ManagedConnection is stopped')
|
|
63
70
|
}
|
|
64
71
|
this.lastUsedTimestamp = Date.now()
|
|
72
|
+
this.messagesSent += 1
|
|
73
|
+
this.bytesSent += data.length
|
|
65
74
|
this.connection.send(data)
|
|
66
75
|
}
|
|
67
76
|
|
|
@@ -74,7 +83,7 @@ export class ManagedConnection extends EventEmitter<ManagedConnectionEvents> {
|
|
|
74
83
|
}
|
|
75
84
|
|
|
76
85
|
getNodeId(): DhtAddress {
|
|
77
|
-
return
|
|
86
|
+
return toNodeId(this.remotePeerDescriptor)
|
|
78
87
|
}
|
|
79
88
|
|
|
80
89
|
getLastUsedTimestamp(): number {
|
|
@@ -85,4 +94,20 @@ export class ManagedConnection extends EventEmitter<ManagedConnectionEvents> {
|
|
|
85
94
|
return this.remotePeerDescriptor
|
|
86
95
|
}
|
|
87
96
|
|
|
97
|
+
getDiagnosticInfo(): Record<string, unknown> {
|
|
98
|
+
return {
|
|
99
|
+
remotePeerDescriptor: this.remotePeerDescriptor,
|
|
100
|
+
lastUsedTimestamp: this.lastUsedTimestamp,
|
|
101
|
+
replacedAsDuplicate: this.replacedAsDuplicate,
|
|
102
|
+
stopped: this.stopped,
|
|
103
|
+
openedAt: this.openedAt,
|
|
104
|
+
bytesSent: this.bytesSent,
|
|
105
|
+
bytesReceived: this.bytesReceived,
|
|
106
|
+
messagesSent: this.messagesSent,
|
|
107
|
+
messagesReceived: this.messagesReceived
|
|
108
|
+
// Add connection type?
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
}
|
|
112
|
+
|
|
88
113
|
}
|
|
@@ -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 { Logger, setAbortableTimeout } from '@streamr/utils'
|
|
4
4
|
import { getNodeIdOrUnknownFromPeerDescriptor } from './ConnectionManager'
|
|
5
5
|
import { IConnection } from './IConnection'
|
|
@@ -4,11 +4,11 @@ import * as Err from '../helpers/errors'
|
|
|
4
4
|
import {
|
|
5
5
|
ConnectivityRequest, ConnectivityResponse,
|
|
6
6
|
Message, PeerDescriptor
|
|
7
|
-
} from '
|
|
7
|
+
} from '../../generated/packages/dht/protos/DhtRpc'
|
|
8
8
|
import { ConnectionEvents, IConnection } from './IConnection'
|
|
9
9
|
import { WebsocketClientConnection } from './websocket/NodeWebsocketClientConnection'
|
|
10
10
|
import { connectivityMethodToWebsocketUrl } from './websocket/WebsocketClientConnector'
|
|
11
|
-
import {
|
|
11
|
+
import { isMaybeSupportedProtocolVersion } from '../helpers/version'
|
|
12
12
|
|
|
13
13
|
const logger = new Logger(module)
|
|
14
14
|
|
|
@@ -79,13 +79,14 @@ export const sendConnectivityRequest = async (
|
|
|
79
79
|
if (message.body.oneofKind === 'connectivityResponse') {
|
|
80
80
|
logger.debug('ConnectivityResponse received: ' + JSON.stringify(Message.toJson(message)))
|
|
81
81
|
const connectivityResponseMessage = message.body.connectivityResponse
|
|
82
|
-
const
|
|
82
|
+
const remoteProtocolVersion = connectivityResponseMessage.protocolVersion
|
|
83
83
|
outgoingConnection!.off('data', listener)
|
|
84
84
|
clearTimeout(timeoutId)
|
|
85
|
-
if (
|
|
85
|
+
if (isMaybeSupportedProtocolVersion(remoteProtocolVersion)) {
|
|
86
86
|
resolve(connectivityResponseMessage)
|
|
87
87
|
} else {
|
|
88
|
-
|
|
88
|
+
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
|
|
89
|
+
reject(`Unsupported version: ${remoteProtocolVersion}`)
|
|
89
90
|
}
|
|
90
91
|
}
|
|
91
92
|
} catch (err) {
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
ConnectivityRequest,
|
|
5
5
|
ConnectivityResponse,
|
|
6
6
|
Message
|
|
7
|
-
} from '
|
|
7
|
+
} from '../../generated/packages/dht/protos/DhtRpc'
|
|
8
8
|
import { NatType } from './ConnectionManager'
|
|
9
9
|
import { CONNECTIVITY_CHECKER_SERVICE_ID, connectAsync } from './connectivityChecker'
|
|
10
10
|
import { IConnection } from './IConnection'
|
|
@@ -54,7 +54,7 @@ const handleIncomingConnectivityRequest = async (
|
|
|
54
54
|
host,
|
|
55
55
|
natType: NatType.UNKNOWN,
|
|
56
56
|
ipAddress: ipv4ToNumber(ipAddress),
|
|
57
|
-
|
|
57
|
+
protocolVersion: LOCAL_PROTOCOL_VERSION
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
if (geoIpLocator !== undefined) {
|
|
@@ -97,7 +97,7 @@ const connectivityProbe = async (connectivityRequest: ConnectivityRequest, ipAdd
|
|
|
97
97
|
natType: NatType.OPEN_INTERNET,
|
|
98
98
|
websocket: { host, port: connectivityRequest.port, tls: connectivityRequest.tls },
|
|
99
99
|
ipAddress: ipv4ToNumber(ipAddress),
|
|
100
|
-
|
|
100
|
+
protocolVersion: LOCAL_PROTOCOL_VERSION
|
|
101
101
|
}
|
|
102
102
|
} catch (err) {
|
|
103
103
|
logger.debug('error', { err })
|
|
@@ -105,7 +105,7 @@ const connectivityProbe = async (connectivityRequest: ConnectivityRequest, ipAdd
|
|
|
105
105
|
host,
|
|
106
106
|
natType: NatType.UNKNOWN,
|
|
107
107
|
ipAddress: ipv4ToNumber(ipAddress),
|
|
108
|
-
|
|
108
|
+
protocolVersion: LOCAL_PROTOCOL_VERSION
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
if (outgoingConnection) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/parameter-properties */
|
|
2
|
-
import { PeerDescriptor } from '
|
|
2
|
+
import { PeerDescriptor } from '../../../generated/packages/dht/protos/DhtRpc'
|
|
3
3
|
import { SimulatorConnector } from './SimulatorConnector'
|
|
4
4
|
import { SimulatorConnection } from './SimulatorConnection'
|
|
5
5
|
import { ConnectionID } from '../IConnection'
|
|
@@ -7,7 +7,7 @@ import { Logger } from '@streamr/utils'
|
|
|
7
7
|
import { getRegionDelayMatrix } from './pings'
|
|
8
8
|
import Heap from 'heap'
|
|
9
9
|
import { debugVars } from '../../helpers/debugHelpers'
|
|
10
|
-
import { DhtAddress,
|
|
10
|
+
import { DhtAddress, toNodeId } from '../../identifiers'
|
|
11
11
|
|
|
12
12
|
const logger = new Logger(module)
|
|
13
13
|
|
|
@@ -90,7 +90,7 @@ class CloseOperation extends SimulatorOperation {
|
|
|
90
90
|
export class Simulator {
|
|
91
91
|
private stopped = false
|
|
92
92
|
private connectors: Map<DhtAddress, SimulatorConnector> = new Map()
|
|
93
|
-
private latencyTable?:
|
|
93
|
+
private latencyTable?: number[][]
|
|
94
94
|
private associations: Map<ConnectionID, Association> = new Map()
|
|
95
95
|
|
|
96
96
|
private latencyType: LatencyType
|
|
@@ -183,15 +183,16 @@ export class Simulator {
|
|
|
183
183
|
}
|
|
184
184
|
|
|
185
185
|
public addConnector(connector: SimulatorConnector): void {
|
|
186
|
-
this.connectors.set(
|
|
186
|
+
this.connectors.set(toNodeId(connector.getPeerDescriptor()), connector)
|
|
187
187
|
}
|
|
188
188
|
|
|
189
189
|
private executeConnectOperation(operation: ConnectOperation): void {
|
|
190
|
-
const target = this.connectors.get(
|
|
190
|
+
const target = this.connectors.get(toNodeId(operation.targetDescriptor))
|
|
191
191
|
|
|
192
192
|
if (!target) {
|
|
193
193
|
logger.error('Target connector not found when executing connect operation')
|
|
194
|
-
|
|
194
|
+
operation.association.connectedCallback!('Target connector not found')
|
|
195
|
+
return
|
|
195
196
|
}
|
|
196
197
|
|
|
197
198
|
target.handleIncomingConnection(operation.sourceConnection)
|
|
@@ -293,7 +294,7 @@ export class Simulator {
|
|
|
293
294
|
logger.error('connect() called on a stopped simulator ' + (new Error().stack))
|
|
294
295
|
return
|
|
295
296
|
}
|
|
296
|
-
debugVars
|
|
297
|
+
debugVars.simulatorHeapSize = this.operationQueue.size()
|
|
297
298
|
|
|
298
299
|
const association = new Association(sourceConnection, undefined, connectedCallback)
|
|
299
300
|
this.associations.set(sourceConnection.connectionId, association)
|