@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
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { ConnectionType, IConnection } from '../IConnection'
|
|
2
2
|
import { Simulator } from './Simulator'
|
|
3
|
-
import { Message, PeerDescriptor } from '
|
|
3
|
+
import { Message, PeerDescriptor } from '../../../generated/packages/dht/protos/DhtRpc'
|
|
4
4
|
import { Connection } from '../Connection'
|
|
5
5
|
import { Logger } from '@streamr/utils'
|
|
6
6
|
import { protoToString } from '../../helpers/protoToString'
|
|
7
|
-
import {
|
|
7
|
+
import { toNodeId } from '../../identifiers'
|
|
8
8
|
|
|
9
9
|
const logger = new Logger(module)
|
|
10
10
|
|
|
@@ -45,15 +45,15 @@ export class SimulatorConnection extends Connection implements IConnection {
|
|
|
45
45
|
this.simulator.send(this, data)
|
|
46
46
|
|
|
47
47
|
} else {
|
|
48
|
-
const localNodeId =
|
|
49
|
-
const targetNodeId =
|
|
48
|
+
const localNodeId = toNodeId(this.localPeerDescriptor)
|
|
49
|
+
const targetNodeId = toNodeId(this.targetPeerDescriptor)
|
|
50
50
|
logger.error(localNodeId + ', ' + targetNodeId + 'tried to send() on a stopped connection')
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
public async close(gracefulLeave: boolean): Promise<void> {
|
|
55
|
-
const localNodeId =
|
|
56
|
-
const targetNodeId =
|
|
55
|
+
const localNodeId = toNodeId(this.localPeerDescriptor)
|
|
56
|
+
const targetNodeId = toNodeId(this.targetPeerDescriptor)
|
|
57
57
|
|
|
58
58
|
logger.trace(localNodeId + ', ' + targetNodeId + ' close()')
|
|
59
59
|
if (!this.stopped) {
|
|
@@ -104,7 +104,7 @@ export class SimulatorConnection extends Connection implements IConnection {
|
|
|
104
104
|
|
|
105
105
|
public handleIncomingDisconnection(): void {
|
|
106
106
|
if (!this.stopped) {
|
|
107
|
-
const localNodeId =
|
|
107
|
+
const localNodeId = toNodeId(this.localPeerDescriptor)
|
|
108
108
|
logger.trace(localNodeId + ' handleIncomingDisconnection()')
|
|
109
109
|
this.stopped = true
|
|
110
110
|
this.doDisconnect(false)
|
|
@@ -114,7 +114,7 @@ export class SimulatorConnection extends Connection implements IConnection {
|
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
public destroy(): void {
|
|
117
|
-
const localNodeId =
|
|
117
|
+
const localNodeId = toNodeId(this.localPeerDescriptor)
|
|
118
118
|
if (!this.stopped) {
|
|
119
119
|
logger.trace(localNodeId + ' destroy()')
|
|
120
120
|
this.removeAllListeners()
|
|
@@ -125,8 +125,8 @@ export class SimulatorConnection extends Connection implements IConnection {
|
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
private doDisconnect(gracefulLeave: boolean) {
|
|
128
|
-
const localNodeId =
|
|
129
|
-
const targetNodeId =
|
|
128
|
+
const localNodeId = toNodeId(this.localPeerDescriptor)
|
|
129
|
+
const targetNodeId = toNodeId(this.targetPeerDescriptor)
|
|
130
130
|
logger.trace(localNodeId + ' doDisconnect()')
|
|
131
131
|
this.stopped = true
|
|
132
132
|
|
|
@@ -3,11 +3,11 @@ import { ConnectionType } from '../IConnection'
|
|
|
3
3
|
import {
|
|
4
4
|
HandshakeError,
|
|
5
5
|
PeerDescriptor,
|
|
6
|
-
} from '
|
|
6
|
+
} from '../../../generated/packages/dht/protos/DhtRpc'
|
|
7
7
|
import { Logger } from '@streamr/utils'
|
|
8
8
|
import { Simulator } from './Simulator'
|
|
9
9
|
import { SimulatorConnection } from './SimulatorConnection'
|
|
10
|
-
import { DhtAddress,
|
|
10
|
+
import { DhtAddress, toNodeId } from '../../identifiers'
|
|
11
11
|
import { acceptHandshake, createIncomingHandshaker, createOutgoingHandshaker, rejectHandshake } from '../Handshaker'
|
|
12
12
|
import { PendingConnection } from '../PendingConnection'
|
|
13
13
|
|
|
@@ -32,8 +32,8 @@ export class SimulatorConnector {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
public connect(targetPeerDescriptor: PeerDescriptor): PendingConnection {
|
|
35
|
-
logger.trace('connect() ' +
|
|
36
|
-
const nodeId =
|
|
35
|
+
logger.trace('connect() ' + toNodeId(targetPeerDescriptor))
|
|
36
|
+
const nodeId = toNodeId(targetPeerDescriptor)
|
|
37
37
|
const existingConnection = this.connectingConnections.get(nodeId)
|
|
38
38
|
if (existingConnection) {
|
|
39
39
|
return existingConnection
|
|
@@ -65,7 +65,7 @@ export class SimulatorConnector {
|
|
|
65
65
|
public handleIncomingConnection(sourceConnection: SimulatorConnection): void {
|
|
66
66
|
// connection is incoming, so remotePeerDescriptor is localPeerDescriptor
|
|
67
67
|
const remotePeerDescriptor = sourceConnection.localPeerDescriptor
|
|
68
|
-
const remoteNodeId =
|
|
68
|
+
const remoteNodeId = toNodeId(sourceConnection.localPeerDescriptor)
|
|
69
69
|
logger.trace(remoteNodeId + ' incoming connection, stopped: ' + this.stopped)
|
|
70
70
|
if (this.stopped) {
|
|
71
71
|
return
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MetricsContext } from '@streamr/utils'
|
|
2
|
-
import { PeerDescriptor } from '
|
|
2
|
+
import { PeerDescriptor } from '../../../generated/packages/dht/protos/DhtRpc'
|
|
3
3
|
import { ConnectionManager } from '../ConnectionManager'
|
|
4
4
|
import { Simulator } from './Simulator'
|
|
5
5
|
import { SimulatorConnectorFacade } from '../ConnectorFacade'
|
|
@@ -8,7 +8,8 @@ export class SimulatorTransport extends ConnectionManager {
|
|
|
8
8
|
constructor(localPeerDescriptor: PeerDescriptor, simulator: Simulator) {
|
|
9
9
|
super({
|
|
10
10
|
createConnectorFacade: () => new SimulatorConnectorFacade(localPeerDescriptor, simulator),
|
|
11
|
-
metricsContext: new MetricsContext()
|
|
11
|
+
metricsContext: new MetricsContext(),
|
|
12
|
+
allowIncomingPrivateConnections: false
|
|
12
13
|
})
|
|
13
14
|
}
|
|
14
15
|
}
|
|
@@ -25,7 +25,7 @@ export const regionPingMatrix = [
|
|
|
25
25
|
[205.555, 178.082, 186.533, 195.774, 216.701, 117.089, 128.001, 175.761, 176.018, 125.551, 303.904, 285.782, 323.15, 309.618, 255.904, 0.262]
|
|
26
26
|
]
|
|
27
27
|
|
|
28
|
-
export function getRegionDelayMatrix():
|
|
28
|
+
export function getRegionDelayMatrix(): number[][] {
|
|
29
29
|
const ret = []
|
|
30
30
|
for (let i = 0; i < regionPingMatrix.length; i++) {
|
|
31
31
|
const row = []
|
|
@@ -2,7 +2,7 @@ import EventEmitter from 'eventemitter3'
|
|
|
2
2
|
import { WebrtcConnectionEvents, IWebrtcConnection, RtcDescription } from './IWebrtcConnection'
|
|
3
3
|
import { IConnection, ConnectionID, ConnectionEvents, ConnectionType } from '../IConnection'
|
|
4
4
|
import { Logger } from '@streamr/utils'
|
|
5
|
-
import { IceServer } from './WebrtcConnector'
|
|
5
|
+
import { EARLY_TIMEOUT, IceServer } from './WebrtcConnector'
|
|
6
6
|
import { createRandomConnectionId } from '../Connection'
|
|
7
7
|
|
|
8
8
|
enum DisconnectedRtcPeerConnectionStateEnum {
|
|
@@ -32,11 +32,15 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IWebrt
|
|
|
32
32
|
private makingOffer = false
|
|
33
33
|
private isOffering = false
|
|
34
34
|
private closed = false
|
|
35
|
+
private earlyTimeout: NodeJS.Timeout
|
|
35
36
|
|
|
36
37
|
constructor(params: Params) {
|
|
37
38
|
super()
|
|
38
39
|
this.connectionId = createRandomConnectionId()
|
|
39
40
|
this.iceServers = params.iceServers ?? []
|
|
41
|
+
this.earlyTimeout = setTimeout(() => {
|
|
42
|
+
this.doClose(false, 'timed out due to remote descriptor not being set')
|
|
43
|
+
}, EARLY_TIMEOUT)
|
|
40
44
|
}
|
|
41
45
|
|
|
42
46
|
public start(isOffering: boolean): void {
|
|
@@ -55,6 +59,7 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IWebrt
|
|
|
55
59
|
}
|
|
56
60
|
|
|
57
61
|
this.peerConnection.onicegatheringstatechange = () => {
|
|
62
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
58
63
|
logger.trace(`conn.onGatheringStateChange: ${this.peerConnection?.iceGatheringState}`)
|
|
59
64
|
}
|
|
60
65
|
|
|
@@ -95,6 +100,7 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IWebrt
|
|
|
95
100
|
}
|
|
96
101
|
try {
|
|
97
102
|
await this.peerConnection?.setRemoteDescription({ sdp: description, type: type.toLowerCase() as RTCSdpType })
|
|
103
|
+
clearTimeout(this.earlyTimeout)
|
|
98
104
|
} catch (err) {
|
|
99
105
|
logger.warn('Failed to set remote description', { err })
|
|
100
106
|
}
|
|
@@ -132,6 +138,7 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IWebrt
|
|
|
132
138
|
if (!this.closed) {
|
|
133
139
|
this.closed = true
|
|
134
140
|
this.lastState = 'closed'
|
|
141
|
+
clearTimeout(this.earlyTimeout)
|
|
135
142
|
|
|
136
143
|
this.stopListening()
|
|
137
144
|
this.emit('disconnected', gracefulLeave, undefined, reason)
|
|
@@ -175,6 +182,8 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IWebrt
|
|
|
175
182
|
|
|
176
183
|
private setupDataChannel(dataChannel: RTCDataChannel): void {
|
|
177
184
|
this.dataChannel = dataChannel
|
|
185
|
+
this.dataChannel.binaryType = 'arraybuffer'
|
|
186
|
+
|
|
178
187
|
dataChannel.onopen = () => {
|
|
179
188
|
logger.trace('dc.onOpen')
|
|
180
189
|
this.onDataChannelOpen()
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import { IWebrtcConnection, WebrtcConnectionEvents } from './IWebrtcConnection'
|
|
2
2
|
import { ConnectionType, IConnection, ConnectionID, ConnectionEvents } from '../IConnection'
|
|
3
|
-
import { PeerDescriptor } from '
|
|
3
|
+
import { PeerDescriptor } from '../../../generated/packages/dht/protos/DhtRpc'
|
|
4
4
|
import EventEmitter from 'eventemitter3'
|
|
5
|
-
// TODO: why does eslint import rule plugin not work?
|
|
6
|
-
// eslint-disable-next-line import/no-unresolved
|
|
7
5
|
import { DataChannel, DescriptionType, PeerConnection, initLogger } from 'node-datachannel'
|
|
8
6
|
import { Logger } from '@streamr/utils'
|
|
9
7
|
import { IllegalRtcPeerConnectionState } from '../../helpers/errors'
|
|
10
8
|
import { iceServerAsString } from './iceServerAsString'
|
|
11
|
-
import { IceServer } from './WebrtcConnector'
|
|
9
|
+
import { IceServer, EARLY_TIMEOUT } from './WebrtcConnector'
|
|
12
10
|
import { PortRange } from '../ConnectionManager'
|
|
13
|
-
import {
|
|
11
|
+
import { toNodeId } from '../../identifiers'
|
|
14
12
|
import { createRandomConnectionId } from '../Connection'
|
|
15
13
|
|
|
16
14
|
const logger = new Logger(module)
|
|
@@ -58,6 +56,7 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IConne
|
|
|
58
56
|
private readonly maxMessageSize?: number
|
|
59
57
|
private closed = false
|
|
60
58
|
private offering?: boolean
|
|
59
|
+
private readonly earlyTimeout: NodeJS.Timeout
|
|
61
60
|
|
|
62
61
|
constructor(params: Params) {
|
|
63
62
|
super()
|
|
@@ -69,10 +68,13 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IConne
|
|
|
69
68
|
this.remotePeerDescriptor = params.remotePeerDescriptor
|
|
70
69
|
this.maxMessageSize = params.maxMessageSize ?? 1048576
|
|
71
70
|
this.portRange = params.portRange
|
|
71
|
+
this.earlyTimeout = setTimeout(() => {
|
|
72
|
+
this.doClose(false, 'timed out due to remote descriptor not being set')
|
|
73
|
+
}, EARLY_TIMEOUT)
|
|
72
74
|
}
|
|
73
75
|
|
|
74
76
|
public start(isOffering: boolean): void {
|
|
75
|
-
const nodeId =
|
|
77
|
+
const nodeId = toNodeId(this.remotePeerDescriptor)
|
|
76
78
|
this.offering = isOffering
|
|
77
79
|
logger.trace(`Starting new connection for peer ${nodeId}`, { isOffering })
|
|
78
80
|
this.connection = new PeerConnection(nodeId, {
|
|
@@ -101,7 +103,8 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IConne
|
|
|
101
103
|
|
|
102
104
|
public async setRemoteDescription(description: string, type: string): Promise<void> {
|
|
103
105
|
if (this.connection) {
|
|
104
|
-
|
|
106
|
+
clearTimeout(this.earlyTimeout)
|
|
107
|
+
const remoteNodeId = toNodeId(this.remotePeerDescriptor)
|
|
105
108
|
try {
|
|
106
109
|
logger.trace(`Setting remote descriptor for peer: ${remoteNodeId}`)
|
|
107
110
|
this.connection.setRemoteDescription(description, type as DescriptionType)
|
|
@@ -117,7 +120,7 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IConne
|
|
|
117
120
|
public addRemoteCandidate(candidate: string, mid: string): void {
|
|
118
121
|
if (this.connection) {
|
|
119
122
|
if (this.remoteDescriptionSet) {
|
|
120
|
-
const remoteNodeId =
|
|
123
|
+
const remoteNodeId = toNodeId(this.remotePeerDescriptor)
|
|
121
124
|
try {
|
|
122
125
|
logger.trace(`Setting remote candidate for peer: ${remoteNodeId}`)
|
|
123
126
|
this.connection.addRemoteCandidate(candidate, mid)
|
|
@@ -138,7 +141,7 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IConne
|
|
|
138
141
|
try {
|
|
139
142
|
this.dataChannel!.sendMessageBinary(data as Buffer)
|
|
140
143
|
} catch (err) {
|
|
141
|
-
const remoteNodeId =
|
|
144
|
+
const remoteNodeId = toNodeId(this.remotePeerDescriptor)
|
|
142
145
|
logger.debug('Failed to send binary message to ' + remoteNodeId + err)
|
|
143
146
|
}
|
|
144
147
|
}
|
|
@@ -150,7 +153,8 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IConne
|
|
|
150
153
|
|
|
151
154
|
private doClose(gracefulLeave: boolean, reason?: string): void {
|
|
152
155
|
if (!this.closed) {
|
|
153
|
-
|
|
156
|
+
clearTimeout(this.earlyTimeout)
|
|
157
|
+
const remoteNodeId = toNodeId(this.remotePeerDescriptor)
|
|
154
158
|
logger.trace(`Closing Node WebRTC Connection to ${remoteNodeId}` + `${(reason !== undefined) ? `, reason: ${reason}` : ''}`)
|
|
155
159
|
|
|
156
160
|
this.closed = true
|
|
@@ -210,7 +214,7 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IConne
|
|
|
210
214
|
}
|
|
211
215
|
|
|
212
216
|
private onDataChannelOpen(): void {
|
|
213
|
-
logger.trace(`DataChannel opened for peer ${
|
|
217
|
+
logger.trace(`DataChannel opened for peer ${toNodeId(this.remotePeerDescriptor)}`)
|
|
214
218
|
this.emit('connected')
|
|
215
219
|
}
|
|
216
220
|
|
|
@@ -4,21 +4,21 @@ import {
|
|
|
4
4
|
PeerDescriptor,
|
|
5
5
|
RtcAnswer,
|
|
6
6
|
RtcOffer, WebrtcConnectionRequest
|
|
7
|
-
} from '
|
|
7
|
+
} from '../../../generated/packages/dht/protos/DhtRpc'
|
|
8
8
|
import { ITransport } from '../../transport/ITransport'
|
|
9
9
|
import { ListeningRpcCommunicator } from '../../transport/ListeningRpcCommunicator'
|
|
10
10
|
import { NodeWebrtcConnection } from './NodeWebrtcConnection'
|
|
11
11
|
import { WebrtcConnectorRpcRemote } from './WebrtcConnectorRpcRemote'
|
|
12
|
-
import { WebrtcConnectorRpcClient } from '
|
|
12
|
+
import { WebrtcConnectorRpcClient } from '../../../generated/packages/dht/protos/DhtRpc.client'
|
|
13
13
|
import { Logger } from '@streamr/utils'
|
|
14
14
|
import * as Err from '../../helpers/errors'
|
|
15
15
|
import { PortRange } from '../ConnectionManager'
|
|
16
16
|
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
17
17
|
import { WebrtcConnectorRpcLocal } from './WebrtcConnectorRpcLocal'
|
|
18
|
-
import { DhtAddress, areEqualPeerDescriptors,
|
|
18
|
+
import { DhtAddress, areEqualPeerDescriptors, toNodeId } from '../../identifiers'
|
|
19
19
|
import { getOfferer } from '../../helpers/offering'
|
|
20
20
|
import { acceptHandshake, createIncomingHandshaker, createOutgoingHandshaker, rejectHandshake } from '../Handshaker'
|
|
21
|
-
import {
|
|
21
|
+
import { isMaybeSupportedProtocolVersion } from '../../helpers/version'
|
|
22
22
|
import { PendingConnection } from '../PendingConnection'
|
|
23
23
|
|
|
24
24
|
const logger = new Logger(module)
|
|
@@ -32,6 +32,8 @@ export const replaceInternalIpWithExternalIp = (candidate: string, ip: string):
|
|
|
32
32
|
return parsed.join(' ')
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
export const EARLY_TIMEOUT = 5000
|
|
36
|
+
|
|
35
37
|
export interface WebrtcConnectorOptions {
|
|
36
38
|
onNewConnection: (connection: PendingConnection) => boolean
|
|
37
39
|
transport: ITransport
|
|
@@ -127,9 +129,9 @@ export class WebrtcConnector {
|
|
|
127
129
|
throw new Err.CannotConnectToSelf('Cannot open WebRTC Connection to self')
|
|
128
130
|
}
|
|
129
131
|
|
|
130
|
-
logger.trace(`Opening WebRTC connection to ${
|
|
132
|
+
logger.trace(`Opening WebRTC connection to ${toNodeId(targetPeerDescriptor)}`)
|
|
131
133
|
|
|
132
|
-
const nodeId =
|
|
134
|
+
const nodeId = toNodeId(targetPeerDescriptor)
|
|
133
135
|
const existingConnection = this.ongoingConnectAttempts.get(nodeId)
|
|
134
136
|
if (existingConnection) {
|
|
135
137
|
return existingConnection.managedConnection
|
|
@@ -137,8 +139,8 @@ export class WebrtcConnector {
|
|
|
137
139
|
|
|
138
140
|
const connection = this.createConnection(targetPeerDescriptor)
|
|
139
141
|
|
|
140
|
-
const localNodeId =
|
|
141
|
-
const targetNodeId =
|
|
142
|
+
const localNodeId = toNodeId(this.localPeerDescriptor!)
|
|
143
|
+
const targetNodeId = toNodeId(targetPeerDescriptor)
|
|
142
144
|
const offering = (getOfferer(localNodeId, targetNodeId) === 'local')
|
|
143
145
|
let pendingConnection: PendingConnection
|
|
144
146
|
const remoteConnector = new WebrtcConnectorRpcRemote(
|
|
@@ -167,8 +169,8 @@ export class WebrtcConnector {
|
|
|
167
169
|
remoteConnector.sendRtcAnswer(description, connection.connectionId)
|
|
168
170
|
})
|
|
169
171
|
handshaker.on('handshakeRequest', (_sourceDescriptor: PeerDescriptor, remoteVersion: string) => {
|
|
170
|
-
if (!
|
|
171
|
-
rejectHandshake(pendingConnection!, connection, handshaker, HandshakeError.
|
|
172
|
+
if (!isMaybeSupportedProtocolVersion(remoteVersion)) {
|
|
173
|
+
rejectHandshake(pendingConnection!, connection, handshaker, HandshakeError.UNSUPPORTED_PROTOCOL_VERSION)
|
|
172
174
|
} else {
|
|
173
175
|
acceptHandshake(handshaker, pendingConnection, connection)
|
|
174
176
|
}
|
|
@@ -224,7 +226,7 @@ export class WebrtcConnector {
|
|
|
224
226
|
const attempts = Array.from(this.ongoingConnectAttempts.values())
|
|
225
227
|
await Promise.allSettled(attempts.map(async (conn) => {
|
|
226
228
|
conn.connection.destroy()
|
|
227
|
-
|
|
229
|
+
conn.managedConnection.close(false)
|
|
228
230
|
}))
|
|
229
231
|
|
|
230
232
|
this.rpcCommunicator.destroy()
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
2
2
|
import { Logger } from '@streamr/utils'
|
|
3
3
|
import { getAddressFromIceCandidate, isPrivateIPv4 } from '../../helpers/AddressTools'
|
|
4
|
-
import { Empty } from '
|
|
4
|
+
import { Empty } from '../../../generated/google/protobuf/empty'
|
|
5
5
|
import {
|
|
6
6
|
IceCandidate,
|
|
7
7
|
PeerDescriptor,
|
|
8
8
|
RtcAnswer,
|
|
9
9
|
RtcOffer
|
|
10
|
-
} from '
|
|
11
|
-
import { IWebrtcConnectorRpc } from '
|
|
10
|
+
} from '../../../generated/packages/dht/protos/DhtRpc'
|
|
11
|
+
import { IWebrtcConnectorRpc } from '../../../generated/packages/dht/protos/DhtRpc.server'
|
|
12
12
|
import { DhtCallContext } from '../../rpc-protocol/DhtCallContext'
|
|
13
13
|
import { ListeningRpcCommunicator } from '../../transport/ListeningRpcCommunicator'
|
|
14
14
|
import { NodeWebrtcConnection } from './NodeWebrtcConnection'
|
|
15
|
-
import { DhtAddress,
|
|
15
|
+
import { DhtAddress, toNodeId } from '../../identifiers'
|
|
16
16
|
import { ConnectionID } from '../IConnection'
|
|
17
17
|
import { ConnectingConnection } from './WebrtcConnector'
|
|
18
18
|
import { PendingConnection } from '../PendingConnection'
|
|
@@ -39,7 +39,7 @@ export class WebrtcConnectorRpcLocal implements IWebrtcConnectorRpc {
|
|
|
39
39
|
|
|
40
40
|
async requestConnection(context: ServerCallContext): Promise<Empty> {
|
|
41
41
|
const targetPeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
|
|
42
|
-
if (this.options.ongoingConnectAttempts.has(
|
|
42
|
+
if (this.options.ongoingConnectAttempts.has(toNodeId(targetPeerDescriptor))) {
|
|
43
43
|
return {}
|
|
44
44
|
}
|
|
45
45
|
const pendingConnection = this.options.connect(targetPeerDescriptor, false)
|
|
@@ -49,7 +49,7 @@ export class WebrtcConnectorRpcLocal implements IWebrtcConnectorRpc {
|
|
|
49
49
|
|
|
50
50
|
async rtcOffer(request: RtcOffer, context: ServerCallContext): Promise<Empty> {
|
|
51
51
|
const remotePeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
|
|
52
|
-
const nodeId =
|
|
52
|
+
const nodeId = toNodeId(remotePeerDescriptor)
|
|
53
53
|
let connection: NodeWebrtcConnection
|
|
54
54
|
let pendingConnection: PendingConnection
|
|
55
55
|
|
|
@@ -69,7 +69,7 @@ export class WebrtcConnectorRpcLocal implements IWebrtcConnectorRpc {
|
|
|
69
69
|
|
|
70
70
|
async rtcAnswer(request: RtcAnswer, context: ServerCallContext): Promise<Empty> {
|
|
71
71
|
const remotePeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
|
|
72
|
-
const nodeId =
|
|
72
|
+
const nodeId = toNodeId(remotePeerDescriptor)
|
|
73
73
|
const connection = this.options.ongoingConnectAttempts.get(nodeId)?.connection
|
|
74
74
|
if (!connection) {
|
|
75
75
|
return {}
|
|
@@ -83,7 +83,7 @@ export class WebrtcConnectorRpcLocal implements IWebrtcConnectorRpc {
|
|
|
83
83
|
|
|
84
84
|
async iceCandidate(request: IceCandidate, context: ServerCallContext): Promise<Empty> {
|
|
85
85
|
const remotePeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
|
|
86
|
-
const nodeId =
|
|
86
|
+
const nodeId = toNodeId(remotePeerDescriptor)
|
|
87
87
|
const connection = this.options.ongoingConnectAttempts.get(nodeId)?.connection
|
|
88
88
|
if (!connection) {
|
|
89
89
|
return {}
|
|
@@ -5,8 +5,8 @@ import {
|
|
|
5
5
|
RtcAnswer,
|
|
6
6
|
RtcOffer,
|
|
7
7
|
WebrtcConnectionRequest
|
|
8
|
-
} from '
|
|
9
|
-
import { WebrtcConnectorRpcClient } from '
|
|
8
|
+
} from '../../../generated/packages/dht/protos/DhtRpc'
|
|
9
|
+
import { WebrtcConnectorRpcClient } from '../../../generated/packages/dht/protos/DhtRpc.client'
|
|
10
10
|
|
|
11
11
|
const logger = new Logger(module)
|
|
12
12
|
|
|
@@ -6,13 +6,13 @@ import {
|
|
|
6
6
|
ConnectivityMethod,
|
|
7
7
|
PeerDescriptor,
|
|
8
8
|
WebsocketConnectionRequest
|
|
9
|
-
} from '
|
|
9
|
+
} from '../../../generated/packages/dht/protos/DhtRpc'
|
|
10
10
|
import { WebsocketServer } from './WebsocketServer'
|
|
11
11
|
import { createOutgoingHandshaker } from '../Handshaker'
|
|
12
12
|
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
13
13
|
import { expectedConnectionType } from '../../helpers/Connectivity'
|
|
14
|
-
import { Empty } from '
|
|
15
|
-
import { DhtAddress,
|
|
14
|
+
import { Empty } from '../../../generated/google/protobuf/empty'
|
|
15
|
+
import { DhtAddress, toNodeId } from '../../identifiers'
|
|
16
16
|
import { GeoIpLocator } from '@streamr/geoip-location'
|
|
17
17
|
import { PendingConnection } from '../PendingConnection'
|
|
18
18
|
|
|
@@ -73,7 +73,7 @@ export class WebsocketClientConnector {
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
public connect(targetPeerDescriptor: PeerDescriptor): PendingConnection {
|
|
76
|
-
const nodeId =
|
|
76
|
+
const nodeId = toNodeId(targetPeerDescriptor)
|
|
77
77
|
const existingConnection = this.connectingConnections.get(nodeId)
|
|
78
78
|
if (existingConnection) {
|
|
79
79
|
return existingConnection
|
|
@@ -114,6 +114,6 @@ export class WebsocketClientConnector {
|
|
|
114
114
|
await Promise.allSettled(requests.map((conn) => conn.close(true)))
|
|
115
115
|
|
|
116
116
|
await this.websocketServer?.stop()
|
|
117
|
-
|
|
117
|
+
this.geoIpLocator?.stop()
|
|
118
118
|
}
|
|
119
119
|
}
|
|
@@ -2,11 +2,11 @@ import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
|
2
2
|
import {
|
|
3
3
|
PeerDescriptor,
|
|
4
4
|
WebsocketConnectionRequest
|
|
5
|
-
} from '
|
|
6
|
-
import { IWebsocketClientConnectorRpc } from '
|
|
5
|
+
} from '../../../generated/packages/dht/protos/DhtRpc'
|
|
6
|
+
import { IWebsocketClientConnectorRpc } from '../../../generated/packages/dht/protos/DhtRpc.server'
|
|
7
7
|
import { DhtCallContext } from '../../rpc-protocol/DhtCallContext'
|
|
8
|
-
import { Empty } from '
|
|
9
|
-
import {
|
|
8
|
+
import { Empty } from '../../../generated/google/protobuf/empty'
|
|
9
|
+
import { toNodeId, DhtAddress } from '../../identifiers'
|
|
10
10
|
import { PendingConnection } from '../PendingConnection'
|
|
11
11
|
|
|
12
12
|
interface WebsocketClientConnectorRpcLocalOptions {
|
|
@@ -29,7 +29,7 @@ export class WebsocketClientConnectorRpcLocal implements IWebsocketClientConnect
|
|
|
29
29
|
return {}
|
|
30
30
|
}
|
|
31
31
|
const senderPeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
|
|
32
|
-
if (!this.options.hasConnection(
|
|
32
|
+
if (!this.options.hasConnection(toNodeId(senderPeerDescriptor))) {
|
|
33
33
|
const connection = this.options.connect(senderPeerDescriptor)
|
|
34
34
|
this.options.onNewConnection(connection)
|
|
35
35
|
}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import {
|
|
2
2
|
WebsocketConnectionRequest
|
|
3
|
-
} from '
|
|
3
|
+
} from '../../../generated/packages/dht/protos/DhtRpc'
|
|
4
4
|
import { Logger } from '@streamr/utils'
|
|
5
5
|
import { RpcRemote } from '../../dht/contact/RpcRemote'
|
|
6
|
-
import { WebsocketClientConnectorRpcClient } from '
|
|
7
|
-
import {
|
|
6
|
+
import { WebsocketClientConnectorRpcClient } from '../../../generated/packages/dht/protos/DhtRpc.client'
|
|
7
|
+
import { toNodeId } from '../../identifiers'
|
|
8
8
|
|
|
9
9
|
const logger = new Logger(module)
|
|
10
10
|
|
|
11
11
|
export class WebsocketClientConnectorRpcRemote extends RpcRemote<WebsocketClientConnectorRpcClient> {
|
|
12
12
|
|
|
13
13
|
async requestConnection(): Promise<void> {
|
|
14
|
-
logger.trace(`Requesting WebSocket connection from ${
|
|
14
|
+
logger.trace(`Requesting WebSocket connection from ${toNodeId(this.getLocalPeerDescriptor())}`)
|
|
15
15
|
const request: WebsocketConnectionRequest = {}
|
|
16
16
|
const options = this.formDhtRpcOptions()
|
|
17
17
|
return this.getClient().requestConnection(request, options)
|
|
@@ -2,9 +2,9 @@ import { GeoIpLocator } from '@streamr/geoip-location'
|
|
|
2
2
|
import { ListeningRpcCommunicator } from '../../transport/ListeningRpcCommunicator'
|
|
3
3
|
import { Action, connectivityMethodToWebsocketUrl } from './WebsocketClientConnector'
|
|
4
4
|
import { WebsocketServer } from './WebsocketServer'
|
|
5
|
-
import { areEqualPeerDescriptors, DhtAddress,
|
|
5
|
+
import { areEqualPeerDescriptors, DhtAddress, toNodeId } from '../../identifiers'
|
|
6
6
|
import { AutoCertifierClientFacade } from './AutoCertifierClientFacade'
|
|
7
|
-
import { ConnectivityResponse, HandshakeError, PeerDescriptor } from '
|
|
7
|
+
import { ConnectivityResponse, HandshakeError, PeerDescriptor } from '../../../generated/packages/dht/protos/DhtRpc'
|
|
8
8
|
import { NatType, PortRange, TlsCertificate } from '../ConnectionManager'
|
|
9
9
|
import { ITransport } from '../../transport/ITransport'
|
|
10
10
|
import { ipv4ToNumber, Logger, wait } from '@streamr/utils'
|
|
@@ -12,12 +12,12 @@ import { attachConnectivityRequestHandler, DISABLE_CONNECTIVITY_PROBE } from '..
|
|
|
12
12
|
import { WebsocketServerConnection } from './WebsocketServerConnection'
|
|
13
13
|
import { ConnectionType, IConnection } from '../IConnection'
|
|
14
14
|
import queryString from 'querystring'
|
|
15
|
-
import {
|
|
15
|
+
import { isMaybeSupportedProtocolVersion, LOCAL_PROTOCOL_VERSION } from '../../helpers/version'
|
|
16
16
|
import { shuffle } from 'lodash'
|
|
17
17
|
import { sendConnectivityRequest } from '../connectivityChecker'
|
|
18
18
|
import { acceptHandshake, Handshaker, rejectHandshake } from '../Handshaker'
|
|
19
19
|
import { WebsocketClientConnectorRpcRemote } from './WebsocketClientConnectorRpcRemote'
|
|
20
|
-
import { WebsocketClientConnectorRpcClient } from '
|
|
20
|
+
import { WebsocketClientConnectorRpcClient } from '../../../generated/packages/dht/protos/DhtRpc.client'
|
|
21
21
|
import { WebsocketServerStartError } from '../../helpers/errors'
|
|
22
22
|
import * as Err from '../../helpers/errors'
|
|
23
23
|
import { expectedConnectionType } from '../../helpers/Connectivity'
|
|
@@ -114,23 +114,27 @@ export class WebsocketServerConnector {
|
|
|
114
114
|
private attachHandshaker(connection: IConnection) {
|
|
115
115
|
// TODO: use createIncomingHandshaker here?
|
|
116
116
|
const handshaker = new Handshaker(this.localPeerDescriptor!, connection)
|
|
117
|
-
handshaker.once('handshakeRequest', (
|
|
118
|
-
|
|
117
|
+
handshaker.once('handshakeRequest', (
|
|
118
|
+
localPeerDescriptor: PeerDescriptor,
|
|
119
|
+
remoteProtocolVersion: string,
|
|
120
|
+
remotePeerDescriptor?: PeerDescriptor
|
|
121
|
+
) => {
|
|
122
|
+
this.onServerSocketHandshakeRequest(localPeerDescriptor, connection, handshaker, remoteProtocolVersion, remotePeerDescriptor)
|
|
119
123
|
})
|
|
120
124
|
}
|
|
121
125
|
|
|
122
126
|
private onServerSocketHandshakeRequest(
|
|
123
|
-
|
|
127
|
+
remotePeerDescriptor: PeerDescriptor,
|
|
124
128
|
websocketServerConnection: IConnection,
|
|
125
129
|
handshaker: Handshaker,
|
|
126
|
-
|
|
130
|
+
remoteProtocolVersion: string,
|
|
127
131
|
targetPeerDescriptor?: PeerDescriptor
|
|
128
132
|
) {
|
|
129
|
-
const nodeId =
|
|
133
|
+
const nodeId = toNodeId(remotePeerDescriptor)
|
|
130
134
|
if (this.ongoingConnectRequests.has(nodeId)) {
|
|
131
135
|
const { pendingConnection, delFunc } = this.ongoingConnectRequests.get(nodeId)!
|
|
132
|
-
if (!
|
|
133
|
-
rejectHandshake(pendingConnection, websocketServerConnection, handshaker, HandshakeError.
|
|
136
|
+
if (!isMaybeSupportedProtocolVersion(remoteProtocolVersion)) {
|
|
137
|
+
rejectHandshake(pendingConnection, websocketServerConnection, handshaker, HandshakeError.UNSUPPORTED_PROTOCOL_VERSION)
|
|
134
138
|
delFunc()
|
|
135
139
|
} else if (targetPeerDescriptor && !areEqualPeerDescriptors(this.localPeerDescriptor!, targetPeerDescriptor)) {
|
|
136
140
|
rejectHandshake(pendingConnection, websocketServerConnection, handshaker, HandshakeError.INVALID_TARGET_PEER_DESCRIPTOR)
|
|
@@ -139,10 +143,10 @@ export class WebsocketServerConnector {
|
|
|
139
143
|
acceptHandshake(handshaker, pendingConnection, websocketServerConnection)
|
|
140
144
|
}
|
|
141
145
|
} else {
|
|
142
|
-
const pendingConnection = new PendingConnection(
|
|
146
|
+
const pendingConnection = new PendingConnection(remotePeerDescriptor)
|
|
143
147
|
|
|
144
|
-
if (!
|
|
145
|
-
rejectHandshake(pendingConnection, websocketServerConnection, handshaker, HandshakeError.
|
|
148
|
+
if (!isMaybeSupportedProtocolVersion(remoteProtocolVersion)) {
|
|
149
|
+
rejectHandshake(pendingConnection, websocketServerConnection, handshaker, HandshakeError.UNSUPPORTED_PROTOCOL_VERSION)
|
|
146
150
|
} else if (targetPeerDescriptor && !areEqualPeerDescriptors(this.localPeerDescriptor!, targetPeerDescriptor)) {
|
|
147
151
|
rejectHandshake(pendingConnection, websocketServerConnection, handshaker, HandshakeError.INVALID_TARGET_PEER_DESCRIPTOR)
|
|
148
152
|
} else if (this.options.onNewConnection(pendingConnection)) {
|
|
@@ -160,7 +164,7 @@ export class WebsocketServerConnector {
|
|
|
160
164
|
host: '127.0.0.1',
|
|
161
165
|
natType: NatType.UNKNOWN,
|
|
162
166
|
ipAddress: ipv4ToNumber('127.0.0.1'),
|
|
163
|
-
|
|
167
|
+
protocolVersion: LOCAL_PROTOCOL_VERSION
|
|
164
168
|
}
|
|
165
169
|
}
|
|
166
170
|
if (!this.options.entrypoints || this.options.entrypoints.length === 0) {
|
|
@@ -175,7 +179,7 @@ export class WebsocketServerConnector {
|
|
|
175
179
|
},
|
|
176
180
|
// TODO: Resolve the given host name or or use as is if IP was given.
|
|
177
181
|
ipAddress: ipv4ToNumber('127.0.0.1'),
|
|
178
|
-
|
|
182
|
+
protocolVersion: LOCAL_PROTOCOL_VERSION
|
|
179
183
|
}
|
|
180
184
|
}
|
|
181
185
|
const shuffledEntrypoints = shuffle(this.options.entrypoints)
|
|
@@ -195,7 +199,7 @@ export class WebsocketServerConnector {
|
|
|
195
199
|
throw new Err.ConnectionFailed('ConnectivityChecker is destroyed')
|
|
196
200
|
}
|
|
197
201
|
} catch (err) {
|
|
198
|
-
const error = `Failed to connect to entrypoint with id ${
|
|
202
|
+
const error = `Failed to connect to entrypoint with id ${toNodeId(entryPoint)} `
|
|
199
203
|
+ `and URL ${connectivityMethodToWebsocketUrl(entryPoint.websocket!)}`
|
|
200
204
|
logger.error(error, { err })
|
|
201
205
|
shuffledEntrypoints.shift()
|
|
@@ -227,7 +231,7 @@ export class WebsocketServerConnector {
|
|
|
227
231
|
}
|
|
228
232
|
|
|
229
233
|
public connect(targetPeerDescriptor: PeerDescriptor): PendingConnection {
|
|
230
|
-
const nodeId =
|
|
234
|
+
const nodeId = toNodeId(targetPeerDescriptor)
|
|
231
235
|
if (this.ongoingConnectRequests.has(nodeId)) {
|
|
232
236
|
return this.ongoingConnectRequests.get(nodeId)!.pendingConnection
|
|
233
237
|
}
|
|
@@ -251,7 +255,7 @@ export class WebsocketServerConnector {
|
|
|
251
255
|
})
|
|
252
256
|
})
|
|
253
257
|
const pendingConnection = new PendingConnection(targetPeerDescriptor)
|
|
254
|
-
const nodeId =
|
|
258
|
+
const nodeId = toNodeId(targetPeerDescriptor)
|
|
255
259
|
// TODO: can this leak?
|
|
256
260
|
const delFunc = () => {
|
|
257
261
|
pendingConnection.off('connected', delFunc)
|
|
@@ -280,7 +284,7 @@ export class WebsocketServerConnector {
|
|
|
280
284
|
await Promise.allSettled(requests.map((ongoingConnectRequest) => ongoingConnectRequest.pendingConnection.close(true)))
|
|
281
285
|
|
|
282
286
|
await this.websocketServer?.stop()
|
|
283
|
-
|
|
287
|
+
this.geoIpLocator?.stop()
|
|
284
288
|
}
|
|
285
289
|
|
|
286
290
|
}
|