@streamr/dht 100.0.0-pretestnet.6 → 100.0.0-rc.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/README.md +90 -8
- package/dist/package.json +70 -0
- package/dist/src/connection/Connection.d.ts +1 -0
- package/dist/src/connection/Connection.js +10 -3
- package/dist/src/connection/Connection.js.map +1 -1
- package/dist/src/connection/ConnectionLockHandler.d.ts +14 -14
- package/dist/src/connection/ConnectionLockHandler.js +22 -16
- package/dist/src/connection/ConnectionLockHandler.js.map +1 -1
- package/dist/src/connection/ConnectionLockRpcLocal.d.ts +3 -3
- package/dist/src/connection/ConnectionLockRpcLocal.js +7 -6
- package/dist/src/connection/ConnectionLockRpcLocal.js.map +1 -1
- package/dist/src/connection/ConnectionLockRpcRemote.d.ts +4 -6
- package/dist/src/connection/ConnectionLockRpcRemote.js +10 -37
- package/dist/src/connection/ConnectionLockRpcRemote.js.map +1 -1
- package/dist/src/connection/ConnectionManager.d.ts +19 -20
- package/dist/src/connection/ConnectionManager.js +132 -117
- package/dist/src/connection/ConnectionManager.js.map +1 -1
- package/dist/src/connection/ConnectorFacade.d.ts +3 -2
- package/dist/src/connection/ConnectorFacade.js +10 -3
- package/dist/src/connection/ConnectorFacade.js.map +1 -1
- package/dist/src/connection/Handshaker.d.ts +3 -1
- package/dist/src/connection/Handshaker.js +19 -10
- package/dist/src/connection/Handshaker.js.map +1 -1
- package/dist/src/connection/IConnection.d.ts +2 -7
- package/dist/src/connection/IConnection.js +1 -8
- package/dist/src/connection/IConnection.js.map +1 -1
- package/dist/src/connection/ManagedConnection.d.ts +5 -7
- package/dist/src/connection/ManagedConnection.js +42 -26
- package/dist/src/connection/ManagedConnection.js.map +1 -1
- package/dist/src/connection/ManagedWebrtcConnection.js.map +1 -1
- package/dist/src/connection/connectivityChecker.d.ts +9 -0
- package/dist/src/connection/connectivityChecker.js +130 -0
- package/dist/src/connection/connectivityChecker.js.map +1 -0
- package/dist/src/connection/connectivityRequestHandler.d.ts +3 -0
- package/dist/src/connection/connectivityRequestHandler.js +101 -0
- package/dist/src/connection/connectivityRequestHandler.js.map +1 -0
- package/dist/src/connection/simulator/Simulator.d.ts +0 -3
- package/dist/src/connection/simulator/Simulator.js +34 -69
- package/dist/src/connection/simulator/Simulator.js.map +1 -1
- package/dist/src/connection/simulator/SimulatorConnection.js +27 -25
- package/dist/src/connection/simulator/SimulatorConnection.js.map +1 -1
- package/dist/src/connection/simulator/SimulatorConnector.js +16 -12
- package/dist/src/connection/simulator/SimulatorConnector.js.map +1 -1
- package/dist/src/connection/simulator/pings.js.map +1 -1
- package/dist/src/connection/webrtc/NodeWebrtcConnection.d.ts +2 -3
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js +40 -27
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnector.d.ts +1 -2
- package/dist/src/connection/webrtc/WebrtcConnector.js +36 -32
- package/dist/src/connection/webrtc/WebrtcConnector.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.d.ts +4 -2
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js +28 -22
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.d.ts +3 -6
- package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.js +2 -5
- package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.js.map +1 -1
- package/dist/src/connection/webrtc/iceServerAsString.js +1 -1
- package/dist/src/connection/webrtc/iceServerAsString.js.map +1 -1
- package/dist/src/connection/websocket/AutoCertifierClientFacade.d.ts +1 -2
- package/dist/src/connection/websocket/AutoCertifierClientFacade.js +6 -4
- package/dist/src/connection/websocket/AutoCertifierClientFacade.js.map +1 -1
- package/dist/src/connection/websocket/ClientWebsocket.d.ts +1 -0
- package/dist/src/connection/websocket/ClientWebsocket.js +14 -7
- package/dist/src/connection/websocket/ClientWebsocket.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnector.d.ts +3 -9
- package/dist/src/connection/websocket/WebsocketConnector.js +142 -74
- package/dist/src/connection/websocket/WebsocketConnector.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.d.ts +5 -3
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.js +9 -12
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.d.ts +4 -7
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.js +7 -44
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketServer.d.ts +1 -4
- package/dist/src/connection/websocket/WebsocketServer.js +49 -40
- package/dist/src/connection/websocket/WebsocketServer.js.map +1 -1
- package/dist/src/connection/websocket/{ServerWebsocket.d.ts → WebsocketServerConnection.d.ts} +8 -4
- package/dist/src/connection/websocket/WebsocketServerConnection.js +97 -0
- package/dist/src/connection/websocket/WebsocketServerConnection.js.map +1 -0
- package/dist/src/dht/DhtNode.d.ts +45 -49
- package/dist/src/dht/DhtNode.js +229 -317
- package/dist/src/dht/DhtNode.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcLocal.d.ts +10 -9
- package/dist/src/dht/DhtNodeRpcLocal.js +19 -11
- package/dist/src/dht/DhtNodeRpcLocal.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcRemote.d.ts +15 -10
- package/dist/src/dht/DhtNodeRpcRemote.js +38 -21
- package/dist/src/dht/DhtNodeRpcRemote.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcLocal.d.ts +7 -6
- package/dist/src/dht/ExternalApiRpcLocal.js +9 -13
- package/dist/src/dht/ExternalApiRpcLocal.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcRemote.d.ts +6 -5
- package/dist/src/dht/ExternalApiRpcRemote.js +10 -7
- package/dist/src/dht/ExternalApiRpcRemote.js.map +1 -1
- package/dist/src/dht/PeerManager.d.ts +61 -0
- package/dist/src/dht/PeerManager.js +288 -0
- package/dist/src/dht/PeerManager.js.map +1 -0
- package/dist/src/dht/contact/Contact.d.ts +2 -2
- package/dist/src/dht/contact/Contact.js +4 -3
- package/dist/src/dht/contact/Contact.js.map +1 -1
- package/dist/src/dht/contact/ContactList.d.ts +8 -8
- package/dist/src/dht/contact/ContactList.js +12 -7
- package/dist/src/dht/contact/ContactList.js.map +1 -1
- package/dist/src/dht/contact/RandomContactList.d.ts +4 -4
- package/dist/src/dht/contact/RandomContactList.js +13 -12
- package/dist/src/dht/contact/RandomContactList.js.map +1 -1
- package/dist/src/dht/contact/RingContactList.d.ts +31 -0
- package/dist/src/dht/contact/RingContactList.js +133 -0
- package/dist/src/dht/contact/RingContactList.js.map +1 -0
- package/dist/src/dht/contact/{Remote.d.ts → RpcRemote.d.ts} +8 -7
- package/dist/src/dht/contact/{Remote.js → RpcRemote.js} +16 -13
- package/dist/src/dht/contact/RpcRemote.js.map +1 -0
- package/dist/src/dht/contact/SortedContactList.d.ts +29 -15
- package/dist/src/dht/contact/SortedContactList.js +79 -42
- package/dist/src/dht/contact/SortedContactList.js.map +1 -1
- package/dist/src/dht/contact/ringIdentifiers.d.ts +16 -0
- package/dist/src/dht/contact/ringIdentifiers.js +54 -0
- package/dist/src/dht/contact/ringIdentifiers.js.map +1 -0
- package/dist/src/dht/discovery/DiscoverySession.d.ts +8 -18
- package/dist/src/dht/discovery/DiscoverySession.js +32 -48
- package/dist/src/dht/discovery/DiscoverySession.js.map +1 -1
- package/dist/src/dht/discovery/PeerDiscovery.d.ts +16 -12
- package/dist/src/dht/discovery/PeerDiscovery.js +82 -39
- package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -1
- package/dist/src/dht/discovery/RingDiscoverySession.d.ts +29 -0
- package/dist/src/dht/discovery/RingDiscoverySession.js +123 -0
- package/dist/src/dht/discovery/RingDiscoverySession.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.d.ts +36 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.js +166 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.d.ts +14 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.js +26 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.d.ts +6 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js +44 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.d.ts +44 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.js +187 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.d.ts +14 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js +20 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.d.ts +6 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.js +21 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.js.map +1 -0
- package/dist/src/dht/routing/DuplicateDetector.d.ts +2 -4
- package/dist/src/dht/routing/DuplicateDetector.js +10 -15
- package/dist/src/dht/routing/DuplicateDetector.js.map +1 -1
- package/dist/src/dht/routing/Router.d.ts +11 -27
- package/dist/src/dht/routing/Router.js +92 -58
- package/dist/src/dht/routing/Router.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcLocal.d.ts +3 -4
- package/dist/src/dht/routing/RouterRpcLocal.js +17 -16
- package/dist/src/dht/routing/RouterRpcLocal.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcRemote.d.ts +3 -3
- package/dist/src/dht/routing/RouterRpcRemote.js +29 -20
- package/dist/src/dht/routing/RouterRpcRemote.js.map +1 -1
- package/dist/src/dht/routing/RoutingSession.d.ts +29 -21
- package/dist/src/dht/routing/RoutingSession.js +93 -68
- package/dist/src/dht/routing/RoutingSession.js.map +1 -1
- package/dist/src/dht/routing/RoutingTablesCache.d.ts +24 -0
- package/dist/src/dht/routing/RoutingTablesCache.js +46 -0
- package/dist/src/dht/routing/RoutingTablesCache.js.map +1 -0
- package/dist/src/dht/routing/getPreviousPeer.js.map +1 -1
- package/dist/src/dht/store/LocalDataStore.d.ts +9 -14
- package/dist/src/dht/store/LocalDataStore.js +46 -72
- package/dist/src/dht/store/LocalDataStore.js.map +1 -1
- package/dist/src/dht/store/StoreManager.d.ts +33 -0
- package/dist/src/dht/store/StoreManager.js +182 -0
- package/dist/src/dht/store/StoreManager.js.map +1 -0
- package/dist/src/dht/store/StoreRpcLocal.d.ts +11 -41
- package/dist/src/dht/store/StoreRpcLocal.js +27 -234
- package/dist/src/dht/store/StoreRpcLocal.js.map +1 -1
- package/dist/src/dht/store/StoreRpcRemote.d.ts +6 -7
- package/dist/src/dht/store/StoreRpcRemote.js +10 -20
- package/dist/src/dht/store/StoreRpcRemote.js.map +1 -1
- package/dist/src/exports.d.ts +5 -3
- package/dist/src/exports.js +10 -8
- package/dist/src/exports.js.map +1 -1
- package/dist/src/helpers/AddressTools.js +2 -0
- package/dist/src/helpers/AddressTools.js.map +1 -1
- package/dist/src/helpers/Connectivity.js.map +1 -1
- package/dist/src/helpers/MapWithTtl.d.ts +14 -0
- package/dist/src/helpers/MapWithTtl.js +60 -0
- package/dist/src/helpers/MapWithTtl.js.map +1 -0
- package/dist/src/helpers/createPeerDescriptor.d.ts +3 -0
- package/dist/src/helpers/createPeerDescriptor.js +57 -0
- package/dist/src/helpers/createPeerDescriptor.js.map +1 -0
- package/dist/src/helpers/createPeerDescriptorSignaturePayload.d.ts +2 -0
- package/dist/src/helpers/createPeerDescriptorSignaturePayload.js +30 -0
- package/dist/src/helpers/createPeerDescriptorSignaturePayload.js.map +1 -0
- package/dist/src/helpers/debugHelpers.js.map +1 -1
- package/dist/src/helpers/errors.js +2 -0
- package/dist/src/helpers/errors.js.map +1 -1
- package/dist/src/helpers/offering.d.ts +4 -0
- package/dist/src/helpers/offering.js +18 -0
- package/dist/src/helpers/offering.js.map +1 -0
- package/dist/src/helpers/protoClasses.js +2 -3
- package/dist/src/helpers/protoClasses.js.map +1 -1
- package/dist/src/helpers/protoToString.js.map +1 -1
- package/dist/src/helpers/version.d.ts +6 -0
- package/dist/src/helpers/version.js +38 -0
- package/dist/src/helpers/version.js.map +1 -0
- package/dist/src/identifiers.d.ts +10 -0
- package/dist/src/identifiers.js +31 -0
- package/dist/src/identifiers.js.map +1 -0
- package/dist/src/proto/google/protobuf/any.js +8 -8
- package/dist/src/proto/google/protobuf/any.js.map +1 -1
- package/dist/src/proto/google/protobuf/empty.js +2 -4
- package/dist/src/proto/google/protobuf/empty.js.map +1 -1
- package/dist/src/proto/google/protobuf/timestamp.js +10 -10
- package/dist/src/proto/google/protobuf/timestamp.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +46 -49
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +63 -54
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +226 -232
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +146 -168
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +26 -29
- package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.js +1 -1
- package/dist/src/rpc-protocol/DhtCallContext.d.ts +2 -2
- package/dist/src/rpc-protocol/DhtCallContext.js +8 -0
- package/dist/src/rpc-protocol/DhtCallContext.js.map +1 -1
- package/dist/src/rpc-protocol/DhtRpcOptions.d.ts +2 -1
- package/dist/src/transport/ITransport.d.ts +10 -2
- package/dist/src/transport/ITransport.js +5 -0
- package/dist/src/transport/ITransport.js.map +1 -1
- package/dist/src/transport/ListeningRpcCommunicator.js +3 -1
- package/dist/src/transport/ListeningRpcCommunicator.js.map +1 -1
- package/dist/src/transport/RoutingRpcCommunicator.d.ts +4 -2
- package/dist/src/transport/RoutingRpcCommunicator.js +19 -12
- package/dist/src/transport/RoutingRpcCommunicator.js.map +1 -1
- package/jest.config.js +4 -1
- package/karma-setup.js +2 -0
- package/karma.config.js +13 -9
- package/package.json +17 -14
- package/protos/DhtRpc.proto +76 -76
- package/src/connection/Connection.ts +6 -1
- package/src/connection/ConnectionLockHandler.ts +30 -22
- package/src/connection/ConnectionLockRpcLocal.ts +7 -12
- package/src/connection/ConnectionLockRpcRemote.ts +9 -19
- package/src/connection/ConnectionManager.ts +132 -138
- package/src/connection/ConnectorFacade.ts +10 -9
- package/src/connection/Handshaker.ts +24 -12
- package/src/connection/IConnection.ts +2 -8
- package/src/connection/ManagedConnection.ts +34 -35
- package/src/connection/connectivityChecker.ts +109 -0
- package/src/connection/connectivityRequestHandler.ts +103 -0
- package/src/connection/simulator/Simulator.ts +6 -37
- package/src/connection/simulator/SimulatorConnection.ts +23 -25
- package/src/connection/simulator/SimulatorConnector.ts +11 -11
- package/src/connection/webrtc/BrowserWebrtcConnection.ts +17 -25
- package/src/connection/webrtc/NodeWebrtcConnection.ts +25 -27
- package/src/connection/webrtc/WebrtcConnector.ts +31 -36
- package/src/connection/webrtc/WebrtcConnectorRpcLocal.ts +31 -25
- package/src/connection/webrtc/WebrtcConnectorRpcRemote.ts +4 -14
- package/src/connection/webrtc/iceServerAsString.ts +1 -1
- package/src/connection/websocket/AutoCertifierClientFacade.ts +4 -6
- package/src/connection/websocket/ClientWebsocket.ts +10 -4
- package/src/connection/websocket/WebsocketConnector.ts +120 -97
- package/src/connection/websocket/WebsocketConnectorRpcLocal.ts +13 -15
- package/src/connection/websocket/WebsocketConnectorRpcRemote.ts +7 -27
- package/src/connection/websocket/WebsocketServer.ts +50 -53
- package/src/connection/websocket/WebsocketServerConnection.ts +104 -0
- package/src/dht/DhtNode.ts +289 -410
- package/src/dht/DhtNodeRpcLocal.ts +25 -17
- package/src/dht/DhtNodeRpcRemote.ts +43 -27
- package/src/dht/ExternalApiRpcLocal.ts +30 -17
- package/src/dht/ExternalApiRpcRemote.ts +14 -11
- package/src/dht/PeerManager.ts +339 -0
- package/src/dht/contact/Contact.ts +4 -4
- package/src/dht/contact/ContactList.ts +11 -10
- package/src/dht/contact/RandomContactList.ts +15 -15
- package/src/dht/contact/RingContactList.ts +151 -0
- package/src/dht/contact/{Remote.ts → RpcRemote.ts} +16 -19
- package/src/dht/contact/SortedContactList.ts +120 -72
- package/src/dht/contact/ringIdentifiers.ts +62 -0
- package/src/dht/discovery/DiscoverySession.ts +36 -61
- package/src/dht/discovery/PeerDiscovery.ts +98 -43
- package/src/dht/discovery/RingDiscoverySession.ts +160 -0
- package/src/dht/recursive-operation/RecursiveOperationManager.ts +246 -0
- package/src/dht/recursive-operation/RecursiveOperationRpcLocal.ts +34 -0
- package/src/dht/recursive-operation/RecursiveOperationRpcRemote.ts +43 -0
- package/src/dht/recursive-operation/RecursiveOperationSession.ts +232 -0
- package/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.ts +35 -0
- package/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.ts +30 -0
- package/src/dht/routing/DuplicateDetector.ts +9 -21
- package/src/dht/routing/Router.ts +95 -92
- package/src/dht/routing/RouterRpcLocal.ts +16 -18
- package/src/dht/routing/RouterRpcRemote.ts +26 -24
- package/src/dht/routing/RoutingSession.ts +119 -98
- package/src/dht/routing/RoutingTablesCache.ts +58 -0
- package/src/dht/routing/getPreviousPeer.ts +1 -1
- package/src/dht/store/LocalDataStore.ts +47 -77
- package/src/dht/store/StoreManager.ts +209 -0
- package/src/dht/store/StoreRpcLocal.ts +39 -308
- package/src/dht/store/StoreRpcRemote.ts +13 -31
- package/src/exports.ts +13 -3
- package/src/helpers/AddressTools.ts +2 -0
- package/src/helpers/MapWithTtl.ts +71 -0
- package/src/helpers/createPeerDescriptor.ts +57 -0
- package/src/helpers/createPeerDescriptorSignaturePayload.ts +28 -0
- package/src/helpers/offering.ts +15 -0
- package/src/helpers/protoClasses.ts +4 -6
- package/src/helpers/version.ts +32 -0
- package/src/identifiers.ts +29 -0
- package/src/proto/google/protobuf/any.ts +4 -4
- package/src/proto/google/protobuf/empty.ts +2 -4
- package/src/proto/google/protobuf/timestamp.ts +4 -4
- package/src/proto/packages/dht/protos/DhtRpc.client.ts +65 -68
- package/src/proto/packages/dht/protos/DhtRpc.server.ts +27 -30
- package/src/proto/packages/dht/protos/DhtRpc.ts +297 -313
- package/src/proto/packages/proto-rpc/protos/ProtoRpc.ts +1 -1
- package/src/rpc-protocol/DhtCallContext.ts +2 -2
- package/src/rpc-protocol/DhtRpcOptions.ts +2 -1
- package/src/transport/ITransport.ts +11 -2
- package/src/transport/ListeningRpcCommunicator.ts +1 -1
- package/src/transport/RoutingRpcCommunicator.ts +21 -14
- package/test/RandomGraphSimulation.ts +3 -2
- package/test/benchmark/Find.test.ts +13 -28
- package/test/benchmark/KademliaCorrectness.test.ts +24 -28
- package/test/benchmark/RingCorrectness.test.ts +157 -0
- package/test/benchmark/SortedContactListBenchmark.test.ts +151 -0
- package/test/benchmark/WebsocketServerMemoryLeak.test.ts +41 -0
- package/test/benchmark/hybrid-network-simulation/RingContactList.test.ts +72 -0
- package/test/benchmark/kademlia-simulation/Contact.ts +9 -9
- package/test/benchmark/kademlia-simulation/KademliaSimulation.ts +11 -11
- package/test/benchmark/kademlia-simulation/SimulationNode.ts +29 -25
- package/test/data/generateGroundTruthData.ts +7 -6
- package/test/end-to-end/Layer0-Layer1.test.ts +11 -15
- package/test/end-to-end/Layer0.test.ts +19 -22
- package/test/end-to-end/Layer0MixedConnectionTypes.test.ts +19 -21
- package/test/end-to-end/Layer0Webrtc-Layer1.test.ts +26 -28
- package/test/end-to-end/Layer0Webrtc.test.ts +19 -19
- package/test/end-to-end/Layer1-Scale-WebSocket.test.ts +10 -18
- package/test/end-to-end/Layer1-Scale-Webrtc.test.ts +8 -15
- package/test/end-to-end/RecoveryFromFailedAutoCertification.test.ts +2 -2
- package/test/end-to-end/WebsocketConnectionRequest.test.ts +8 -9
- package/test/end-to-end/memory-leak.test.ts +19 -24
- package/test/integration/ConnectionLocking.test.ts +66 -60
- package/test/integration/ConnectionManager.test.ts +43 -63
- package/test/integration/ConnectivityChecking.test.ts +52 -0
- package/test/integration/DhtJoinPeerDiscovery.test.ts +8 -12
- package/test/integration/DhtNodeExternalAPI.test.ts +17 -21
- package/test/integration/DhtNodeRpcRemote.test.ts +19 -26
- package/test/integration/DhtRpc.test.ts +20 -24
- package/test/integration/Find.test.ts +10 -12
- package/test/integration/Layer1-scale.test.ts +25 -37
- package/test/integration/Mock-Layer1-Layer0.test.ts +39 -59
- package/test/integration/MultipleEntryPointJoining.test.ts +14 -14
- package/test/integration/ReplicateData.test.ts +106 -0
- package/test/integration/RouteMessage.test.ts +42 -68
- package/test/integration/RouterRpcRemote.test.ts +19 -24
- package/test/integration/ScaleDownDht.test.ts +14 -12
- package/test/integration/SimultaneousConnections.test.ts +112 -111
- package/test/integration/Store.test.ts +43 -27
- package/test/integration/StoreAndDelete.test.ts +36 -48
- package/test/integration/StoreOnDhtWithThreeNodes.test.ts +59 -0
- package/test/integration/StoreOnDhtWithTwoNodes.test.ts +17 -37
- package/test/integration/StoreRpcRemote.test.ts +20 -32
- package/test/integration/WebrtcConnectionManagement.test.ts +39 -25
- package/test/integration/WebrtcConnectorRpc.test.ts +6 -11
- package/test/integration/WebsocketConnectionManagement.test.ts +87 -22
- package/test/integration/WebsocketConnectorRpc.test.ts +14 -24
- package/test/integration/{RpcErrors.test.ts → rpc-connections-over-webrpc.test.ts} +15 -26
- package/test/unit/AddressTools.test.ts +4 -0
- package/test/unit/ConnectivityHelpers.test.ts +9 -17
- package/test/unit/DuplicateDetector.test.ts +8 -5
- package/test/unit/LocalDataStore.test.ts +78 -75
- package/test/unit/PeerManager.test.ts +33 -0
- package/test/unit/RandomContactList.test.ts +12 -9
- package/test/unit/RecursiveOperationManager.test.ts +157 -0
- package/test/unit/RecursiveOperationSession.test.ts +68 -0
- package/test/unit/Router.test.ts +52 -35
- package/test/unit/RoutingSession.test.ts +79 -0
- package/test/unit/SortedContactList.test.ts +61 -30
- package/test/unit/StoreManager.test.ts +138 -0
- package/test/unit/WebsocketConnector.test.ts +27 -35
- package/test/unit/connectivityRequestHandler.test.ts +104 -0
- package/test/unit/createPeerDescriptor.test.ts +69 -0
- package/test/unit/customMatchers.test.ts +16 -0
- package/test/unit/version.test.ts +18 -0
- package/test/utils/FakeTransport.ts +47 -0
- package/test/utils/customMatchers.ts +71 -0
- package/test/utils/mock/MockRpcCommunicator.ts +7 -0
- package/test/utils/mock/Router.ts +13 -3
- package/test/utils/mock/Transport.ts +1 -1
- package/test/utils/mock/mockDataEntry.ts +38 -0
- package/test/utils/utils.ts +104 -107
- package/tsconfig.browser.json +2 -1
- package/tsconfig.jest.json +4 -2
- package/tsconfig.node.json +4 -2
- package/dist/src/connection/ConnectivityChecker.d.ts +0 -17
- package/dist/src/connection/ConnectivityChecker.js +0 -208
- package/dist/src/connection/ConnectivityChecker.js.map +0 -1
- package/dist/src/connection/websocket/ServerWebsocket.js +0 -100
- package/dist/src/connection/websocket/ServerWebsocket.js.map +0 -1
- package/dist/src/dht/contact/Remote.js.map +0 -1
- package/dist/src/dht/find/FindRpcLocal.d.ts +0 -14
- package/dist/src/dht/find/FindRpcLocal.js +0 -25
- package/dist/src/dht/find/FindRpcLocal.js.map +0 -1
- package/dist/src/dht/find/FindSession.d.ts +0 -44
- package/dist/src/dht/find/FindSession.js +0 -145
- package/dist/src/dht/find/FindSession.js.map +0 -1
- package/dist/src/dht/find/FindSessionRpcLocal.d.ts +0 -12
- package/dist/src/dht/find/FindSessionRpcLocal.js +0 -17
- package/dist/src/dht/find/FindSessionRpcLocal.js.map +0 -1
- package/dist/src/dht/find/FindSessionRpcRemote.d.ts +0 -6
- package/dist/src/dht/find/FindSessionRpcRemote.js +0 -21
- package/dist/src/dht/find/FindSessionRpcRemote.js.map +0 -1
- package/dist/src/dht/find/Finder.d.ts +0 -49
- package/dist/src/dht/find/Finder.js +0 -184
- package/dist/src/dht/find/Finder.js.map +0 -1
- package/dist/src/dht/routing/FindRpcRemote.d.ts +0 -6
- package/dist/src/dht/routing/FindRpcRemote.js +0 -41
- package/dist/src/dht/routing/FindRpcRemote.js.map +0 -1
- package/dist/src/helpers/PeerID.d.ts +0 -24
- package/dist/src/helpers/PeerID.js +0 -78
- package/dist/src/helpers/PeerID.js.map +0 -1
- package/dist/src/helpers/UUID.d.ts +0 -8
- package/dist/src/helpers/UUID.js +0 -36
- package/dist/src/helpers/UUID.js.map +0 -1
- package/dist/src/helpers/kademliaId.d.ts +0 -1
- package/dist/src/helpers/kademliaId.js +0 -14
- package/dist/src/helpers/kademliaId.js.map +0 -1
- package/dist/src/helpers/peerIdFromPeerDescriptor.d.ts +0 -6
- package/dist/src/helpers/peerIdFromPeerDescriptor.js +0 -23
- package/dist/src/helpers/peerIdFromPeerDescriptor.js.map +0 -1
- package/src/connection/ConnectivityChecker.ts +0 -199
- package/src/connection/websocket/ServerWebsocket.ts +0 -114
- package/src/dht/find/FindRpcLocal.ts +0 -35
- package/src/dht/find/FindSession.ts +0 -178
- package/src/dht/find/FindSessionRpcLocal.ts +0 -25
- package/src/dht/find/FindSessionRpcRemote.ts +0 -30
- package/src/dht/find/Finder.ts +0 -275
- package/src/dht/routing/FindRpcRemote.ts +0 -40
- package/src/helpers/PeerID.ts +0 -88
- package/src/helpers/UUID.ts +0 -35
- package/src/helpers/kademliaId.ts +0 -8
- package/src/helpers/peerIdFromPeerDescriptor.ts +0 -20
- package/test/integration/MigrateData.test.ts +0 -204
- package/test/unit/Finder.test.ts +0 -110
- package/test/unit/PeerID.test.ts +0 -22
- package/test/unit/UUID.test.ts +0 -55
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
2
|
-
import { toProtoRpcClient } from '@streamr/proto-rpc'
|
|
3
2
|
import { Logger } from '@streamr/utils'
|
|
4
3
|
import { getAddressFromIceCandidate, isPrivateIPv4 } from '../../helpers/AddressTools'
|
|
5
|
-
import { PeerIDKey } from '../../helpers/PeerID'
|
|
6
|
-
import { keyFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
|
|
7
4
|
import { Empty } from '../../proto/google/protobuf/empty'
|
|
8
5
|
import {
|
|
6
|
+
HandshakeError,
|
|
9
7
|
IceCandidate,
|
|
10
8
|
PeerDescriptor,
|
|
11
9
|
RtcAnswer,
|
|
@@ -19,14 +17,18 @@ import { ManagedConnection } from '../ManagedConnection'
|
|
|
19
17
|
import { ManagedWebrtcConnection } from '../ManagedWebrtcConnection'
|
|
20
18
|
import { NodeWebrtcConnection } from './NodeWebrtcConnection'
|
|
21
19
|
import { WebrtcConnectorRpcRemote } from './WebrtcConnectorRpcRemote'
|
|
20
|
+
import { DhtAddress, getNodeIdFromPeerDescriptor } from '../../identifiers'
|
|
21
|
+
import { isMaybeSupportedVersion } from '../../helpers/version'
|
|
22
|
+
import { ConnectionID } from '../IConnection'
|
|
22
23
|
|
|
23
24
|
const logger = new Logger(module)
|
|
24
25
|
|
|
25
26
|
interface WebrtcConnectorRpcLocalConfig {
|
|
27
|
+
createConnection: (targetPeerDescriptor: PeerDescriptor) => NodeWebrtcConnection
|
|
26
28
|
connect: (targetPeerDescriptor: PeerDescriptor) => ManagedConnection
|
|
27
29
|
onNewConnection: (connection: ManagedConnection) => boolean
|
|
28
30
|
// TODO pass accessor methods instead of passing a mutable entity
|
|
29
|
-
ongoingConnectAttempts: Map<
|
|
31
|
+
ongoingConnectAttempts: Map<DhtAddress, ManagedWebrtcConnection>
|
|
30
32
|
rpcCommunicator: ListeningRpcCommunicator
|
|
31
33
|
getLocalPeerDescriptor: () => PeerDescriptor
|
|
32
34
|
allowPrivateAddresses: boolean
|
|
@@ -42,7 +44,7 @@ export class WebrtcConnectorRpcLocal implements IWebrtcConnectorRpc {
|
|
|
42
44
|
|
|
43
45
|
async requestConnection(context: ServerCallContext): Promise<Empty> {
|
|
44
46
|
const targetPeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
|
|
45
|
-
if (this.config.ongoingConnectAttempts.has(
|
|
47
|
+
if (this.config.ongoingConnectAttempts.has(getNodeIdFromPeerDescriptor(targetPeerDescriptor))) {
|
|
46
48
|
return {}
|
|
47
49
|
}
|
|
48
50
|
const managedConnection = this.config.connect(targetPeerDescriptor)
|
|
@@ -53,50 +55,55 @@ export class WebrtcConnectorRpcLocal implements IWebrtcConnectorRpc {
|
|
|
53
55
|
|
|
54
56
|
async rtcOffer(request: RtcOffer, context: ServerCallContext): Promise<Empty> {
|
|
55
57
|
const remotePeer = (context as DhtCallContext).incomingSourceDescriptor!
|
|
56
|
-
const
|
|
57
|
-
let managedConnection = this.config.ongoingConnectAttempts.get(
|
|
58
|
+
const nodeId = getNodeIdFromPeerDescriptor(remotePeer)
|
|
59
|
+
let managedConnection = this.config.ongoingConnectAttempts.get(nodeId)
|
|
58
60
|
let connection = managedConnection?.getWebrtcConnection()
|
|
59
61
|
|
|
60
62
|
if (!managedConnection) {
|
|
61
|
-
connection =
|
|
63
|
+
connection = this.config.createConnection(remotePeer)
|
|
62
64
|
managedConnection = new ManagedWebrtcConnection(this.config.getLocalPeerDescriptor(), undefined, connection)
|
|
63
65
|
managedConnection.setRemotePeerDescriptor(remotePeer)
|
|
64
|
-
this.config.ongoingConnectAttempts.set(
|
|
66
|
+
this.config.ongoingConnectAttempts.set(nodeId, managedConnection)
|
|
65
67
|
this.config.onNewConnection(managedConnection)
|
|
66
68
|
const remoteConnector = new WebrtcConnectorRpcRemote(
|
|
67
69
|
this.config.getLocalPeerDescriptor(),
|
|
68
70
|
remotePeer,
|
|
69
|
-
|
|
71
|
+
this.config.rpcCommunicator,
|
|
72
|
+
WebrtcConnectorRpcClient
|
|
70
73
|
)
|
|
71
74
|
connection.on('localCandidate', (candidate: string, mid: string) => {
|
|
72
|
-
remoteConnector.sendIceCandidate(candidate, mid, connection!.connectionId
|
|
75
|
+
remoteConnector.sendIceCandidate(candidate, mid, connection!.connectionId)
|
|
73
76
|
})
|
|
74
77
|
connection.once('localDescription', (description: string) => {
|
|
75
|
-
remoteConnector.sendRtcAnswer(description, connection!.connectionId
|
|
78
|
+
remoteConnector.sendRtcAnswer(description, connection!.connectionId)
|
|
76
79
|
})
|
|
77
80
|
connection.start(false)
|
|
78
81
|
}
|
|
79
82
|
|
|
80
83
|
// Always use offerers connectionId
|
|
81
|
-
connection!.setConnectionId(request.connectionId)
|
|
84
|
+
connection!.setConnectionId(request.connectionId as ConnectionID)
|
|
82
85
|
connection!.setRemoteDescription(request.description, 'offer')
|
|
83
86
|
|
|
84
|
-
managedConnection.on('handshakeRequest', () => {
|
|
85
|
-
if (this.config.ongoingConnectAttempts.has(
|
|
86
|
-
this.config.ongoingConnectAttempts.delete(
|
|
87
|
+
managedConnection.on('handshakeRequest', (_sourceDescriptor: PeerDescriptor, remoteVersion: string) => {
|
|
88
|
+
if (this.config.ongoingConnectAttempts.has(nodeId)) {
|
|
89
|
+
this.config.ongoingConnectAttempts.delete(nodeId)
|
|
90
|
+
}
|
|
91
|
+
if (!isMaybeSupportedVersion(remoteVersion)) {
|
|
92
|
+
managedConnection!.rejectHandshake(HandshakeError.UNSUPPORTED_VERSION)
|
|
93
|
+
} else {
|
|
94
|
+
managedConnection!.acceptHandshake()
|
|
87
95
|
}
|
|
88
|
-
managedConnection!.acceptHandshake()
|
|
89
96
|
})
|
|
90
97
|
return {}
|
|
91
98
|
}
|
|
92
99
|
|
|
93
100
|
async rtcAnswer(request: RtcAnswer, context: ServerCallContext): Promise<Empty> {
|
|
94
101
|
const remotePeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
|
|
95
|
-
const
|
|
96
|
-
const connection = this.config.ongoingConnectAttempts.get(
|
|
102
|
+
const nodeId = getNodeIdFromPeerDescriptor(remotePeerDescriptor)
|
|
103
|
+
const connection = this.config.ongoingConnectAttempts.get(nodeId)?.getWebrtcConnection()
|
|
97
104
|
if (!connection) {
|
|
98
105
|
return {}
|
|
99
|
-
} else if (connection.connectionId
|
|
106
|
+
} else if (connection.connectionId !== request.connectionId) {
|
|
100
107
|
logger.trace(`Ignoring RTC answer due to connectionId mismatch`)
|
|
101
108
|
return {}
|
|
102
109
|
}
|
|
@@ -106,12 +113,11 @@ export class WebrtcConnectorRpcLocal implements IWebrtcConnectorRpc {
|
|
|
106
113
|
|
|
107
114
|
async iceCandidate(request: IceCandidate, context: ServerCallContext): Promise<Empty> {
|
|
108
115
|
const remotePeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
|
|
109
|
-
const
|
|
110
|
-
const connection = this.config.ongoingConnectAttempts.get(
|
|
111
|
-
|
|
116
|
+
const nodeId = getNodeIdFromPeerDescriptor(remotePeerDescriptor)
|
|
117
|
+
const connection = this.config.ongoingConnectAttempts.get(nodeId)?.getWebrtcConnection()
|
|
112
118
|
if (!connection) {
|
|
113
119
|
return {}
|
|
114
|
-
} else if (connection.connectionId
|
|
120
|
+
} else if (connection.connectionId !== request.connectionId) {
|
|
115
121
|
logger.trace(`Ignoring remote candidate due to connectionId mismatch`)
|
|
116
122
|
return {}
|
|
117
123
|
} else if (this.isIceCandidateAllowed(request.candidate)) {
|
|
@@ -123,7 +129,7 @@ export class WebrtcConnectorRpcLocal implements IWebrtcConnectorRpc {
|
|
|
123
129
|
private isIceCandidateAllowed(candidate: string): boolean {
|
|
124
130
|
if (!this.config.allowPrivateAddresses) {
|
|
125
131
|
const address = getAddressFromIceCandidate(candidate)
|
|
126
|
-
if (address && isPrivateIPv4(address)) {
|
|
132
|
+
if ((address !== undefined) && isPrivateIPv4(address)) {
|
|
127
133
|
return false
|
|
128
134
|
}
|
|
129
135
|
}
|
|
@@ -1,26 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Logger } from '@streamr/utils'
|
|
2
|
+
import { RpcRemote } from '../../dht/contact/RpcRemote'
|
|
2
3
|
import {
|
|
3
4
|
IceCandidate,
|
|
4
|
-
PeerDescriptor,
|
|
5
5
|
RtcAnswer,
|
|
6
6
|
RtcOffer,
|
|
7
7
|
WebrtcConnectionRequest
|
|
8
8
|
} from '../../proto/packages/dht/protos/DhtRpc'
|
|
9
|
-
import {
|
|
10
|
-
import { ProtoRpcClient } from '@streamr/proto-rpc'
|
|
11
|
-
import { Logger } from '@streamr/utils'
|
|
9
|
+
import { WebrtcConnectorRpcClient } from '../../proto/packages/dht/protos/DhtRpc.client'
|
|
12
10
|
|
|
13
11
|
const logger = new Logger(module)
|
|
14
12
|
|
|
15
|
-
export class WebrtcConnectorRpcRemote extends
|
|
16
|
-
|
|
17
|
-
constructor(
|
|
18
|
-
localPeerDescriptor: PeerDescriptor,
|
|
19
|
-
remotePeerDescriptor: PeerDescriptor,
|
|
20
|
-
client: ProtoRpcClient<IWebrtcConnectorRpcClient>
|
|
21
|
-
) {
|
|
22
|
-
super(localPeerDescriptor, remotePeerDescriptor, 'DUMMY', client)
|
|
23
|
-
}
|
|
13
|
+
export class WebrtcConnectorRpcRemote extends RpcRemote<WebrtcConnectorRpcClient> {
|
|
24
14
|
|
|
25
15
|
requestConnection(): void {
|
|
26
16
|
const request: WebrtcConnectionRequest = {
|
|
@@ -9,7 +9,7 @@ export function iceServerAsString({ url, port, username, password, tcp }: IceSer
|
|
|
9
9
|
return `${protocol}:${hostname}:${port}`
|
|
10
10
|
}
|
|
11
11
|
if (username !== undefined && password !== undefined) {
|
|
12
|
-
return `${protocol}:${username}:${password}@${hostname}:${port}${tcp ? '?transport=tcp' : ''}`
|
|
12
|
+
return `${protocol}:${username}:${password}@${hostname}:${port}${(tcp !== undefined) ? '?transport=tcp' : ''}`
|
|
13
13
|
}
|
|
14
14
|
throw new Error(`username (${username}) and password (${password}) must be supplied together`)
|
|
15
15
|
}
|
|
@@ -55,12 +55,10 @@ export class AutoCertifierClientFacade {
|
|
|
55
55
|
|
|
56
56
|
private autoCertifierClient: IAutoCertifierClient
|
|
57
57
|
private readonly rpcCommunicator: ListeningRpcCommunicator
|
|
58
|
-
private readonly
|
|
59
|
-
private readonly updateCertificate: (certificate: string, privateKey: string) => void
|
|
58
|
+
private readonly config: AutoCertifierClientFacadeConfig
|
|
60
59
|
|
|
61
60
|
constructor(config: AutoCertifierClientFacadeConfig) {
|
|
62
|
-
this.
|
|
63
|
-
this.updateCertificate = config.updateCertificate
|
|
61
|
+
this.config = config
|
|
64
62
|
this.rpcCommunicator = new ListeningRpcCommunicator(AUTO_CERTIFIER_SERVICE_ID, config.transport)
|
|
65
63
|
this.autoCertifierClient = config.createClientFactory ? config.createClientFactory()
|
|
66
64
|
: defaultAutoCertifierClientFactory(
|
|
@@ -73,8 +71,8 @@ export class AutoCertifierClientFacade {
|
|
|
73
71
|
|
|
74
72
|
async start(): Promise<void> {
|
|
75
73
|
this.autoCertifierClient.on('updatedCertificate', (subdomain: CertifiedSubdomain) => {
|
|
76
|
-
this.setHost(subdomain.fqdn)
|
|
77
|
-
this.updateCertificate(subdomain.certificate, subdomain.privateKey)
|
|
74
|
+
this.config.setHost(subdomain.fqdn)
|
|
75
|
+
this.config.updateCertificate(subdomain.certificate, subdomain.privateKey)
|
|
78
76
|
logger.trace(`Updated certificate`)
|
|
79
77
|
})
|
|
80
78
|
await Promise.all([
|
|
@@ -2,16 +2,21 @@ import { Logger } from '@streamr/utils'
|
|
|
2
2
|
import EventEmitter from 'eventemitter3'
|
|
3
3
|
import { ICloseEvent, IMessageEvent, w3cwebsocket as Websocket } from 'websocket'
|
|
4
4
|
import { ConnectionEvents, ConnectionID, ConnectionType, IConnection } from '../IConnection'
|
|
5
|
+
import { createRandomConnectionId } from '../Connection'
|
|
5
6
|
|
|
6
7
|
const logger = new Logger(module)
|
|
7
8
|
|
|
8
9
|
// https://kapeli.com/cheat_sheets/WebSocket_Status_Codes.docset/Contents/Resources/Documents/index
|
|
9
10
|
// Browsers send this automatically when closing a tab
|
|
10
11
|
export const GOING_AWAY = 1001
|
|
12
|
+
// The GOING_AWAY is a reserved code and we shouldn't send that from the application. Therefore
|
|
13
|
+
// we have a custom counterpart
|
|
14
|
+
export const CUSTOM_GOING_AWAY = 3001
|
|
11
15
|
|
|
12
16
|
const BINARY_TYPE = 'arraybuffer'
|
|
13
17
|
|
|
14
18
|
export class ClientWebsocket extends EventEmitter<ConnectionEvents> implements IConnection {
|
|
19
|
+
|
|
15
20
|
public readonly connectionId: ConnectionID
|
|
16
21
|
private socket?: Websocket
|
|
17
22
|
public connectionType = ConnectionType.WEBSOCKET_CLIENT
|
|
@@ -20,9 +25,10 @@ export class ClientWebsocket extends EventEmitter<ConnectionEvents> implements I
|
|
|
20
25
|
|
|
21
26
|
constructor() {
|
|
22
27
|
super()
|
|
23
|
-
this.connectionId =
|
|
28
|
+
this.connectionId = createRandomConnectionId()
|
|
24
29
|
}
|
|
25
30
|
|
|
31
|
+
// TODO explicit default value for "selfSigned" or make it required
|
|
26
32
|
public connect(address: string, selfSigned?: boolean): void {
|
|
27
33
|
if (!this.destroyed) {
|
|
28
34
|
this.socket = new Websocket(address, undefined, undefined, undefined, { rejectUnauthorized: !selfSigned })
|
|
@@ -68,7 +74,7 @@ export class ClientWebsocket extends EventEmitter<ConnectionEvents> implements I
|
|
|
68
74
|
this.destroyed = true
|
|
69
75
|
this.stopListening()
|
|
70
76
|
this.socket = undefined
|
|
71
|
-
const gracefulLeave = code === GOING_AWAY
|
|
77
|
+
const gracefulLeave = (code === GOING_AWAY) || (code === CUSTOM_GOING_AWAY)
|
|
72
78
|
this.emit('disconnected', gracefulLeave, code, reason)
|
|
73
79
|
this.removeAllListeners()
|
|
74
80
|
}
|
|
@@ -90,8 +96,8 @@ export class ClientWebsocket extends EventEmitter<ConnectionEvents> implements I
|
|
|
90
96
|
this.emit('disconnected', gracefulLeave, undefined, 'close() called')
|
|
91
97
|
this.removeAllListeners()
|
|
92
98
|
if (!this.destroyed) {
|
|
93
|
-
logger.trace(`Closing socket for connection ${this.connectionId
|
|
94
|
-
this.socket?.close(gracefulLeave
|
|
99
|
+
logger.trace(`Closing socket for connection ${this.connectionId}`)
|
|
100
|
+
this.socket?.close(gracefulLeave ? CUSTOM_GOING_AWAY : undefined)
|
|
95
101
|
} else {
|
|
96
102
|
logger.debug('Tried to close() a stopped connection')
|
|
97
103
|
}
|
|
@@ -9,26 +9,28 @@ import {
|
|
|
9
9
|
ConnectivityResponse,
|
|
10
10
|
HandshakeError,
|
|
11
11
|
PeerDescriptor,
|
|
12
|
-
WebsocketConnectionRequest
|
|
13
|
-
WebsocketConnectionResponse
|
|
12
|
+
WebsocketConnectionRequest
|
|
14
13
|
} from '../../proto/packages/dht/protos/DhtRpc'
|
|
15
14
|
import { WebsocketConnectorRpcClient } from '../../proto/packages/dht/protos/DhtRpc.client'
|
|
16
|
-
import {
|
|
15
|
+
import { ipv4ToNumber, Logger, wait } from '@streamr/utils'
|
|
17
16
|
import { ManagedConnection } from '../ManagedConnection'
|
|
18
17
|
import { WebsocketServer } from './WebsocketServer'
|
|
19
|
-
import {
|
|
18
|
+
import { sendConnectivityRequest } from '../connectivityChecker'
|
|
20
19
|
import { NatType, PortRange, TlsCertificate } from '../ConnectionManager'
|
|
21
|
-
import {
|
|
22
|
-
import { ServerWebsocket } from './ServerWebsocket'
|
|
23
|
-
import { toProtoRpcClient } from '@streamr/proto-rpc'
|
|
20
|
+
import { WebsocketServerConnection } from './WebsocketServerConnection'
|
|
24
21
|
import { Handshaker } from '../Handshaker'
|
|
25
|
-
import
|
|
26
|
-
import { ParsedUrlQuery } from 'querystring'
|
|
22
|
+
import queryString from 'querystring'
|
|
27
23
|
import { range, sample } from 'lodash'
|
|
28
24
|
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
29
25
|
import { expectedConnectionType } from '../../helpers/Connectivity'
|
|
30
26
|
import { WebsocketServerStartError } from '../../helpers/errors'
|
|
31
27
|
import { AutoCertifierClientFacade } from './AutoCertifierClientFacade'
|
|
28
|
+
import { DISABLE_CONNECTIVITY_PROBE, attachConnectivityRequestHandler } from '../connectivityRequestHandler'
|
|
29
|
+
import * as Err from '../../helpers/errors'
|
|
30
|
+
import { Empty } from '../../proto/google/protobuf/empty'
|
|
31
|
+
import { DhtAddress, areEqualPeerDescriptors, getNodeIdFromPeerDescriptor } from '../../identifiers'
|
|
32
|
+
import { LOCAL_PROTOCOL_VERSION, isMaybeSupportedVersion } from '../../helpers/version'
|
|
33
|
+
|
|
32
34
|
const logger = new Logger(module)
|
|
33
35
|
|
|
34
36
|
export type Action = 'connectivityRequest' | 'connectivityProbe'
|
|
@@ -38,11 +40,10 @@ export const connectivityMethodToWebsocketUrl = (ws: ConnectivityMethod, action?
|
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
const ENTRY_POINT_CONNECTION_ATTEMPTS = 5
|
|
41
|
-
|
|
42
43
|
export interface WebsocketConnectorConfig {
|
|
43
44
|
transport: ITransport
|
|
44
|
-
canConnect: (peerDescriptor: PeerDescriptor) => boolean
|
|
45
45
|
onNewConnection: (connection: ManagedConnection) => boolean
|
|
46
|
+
hasConnection: (nodeId: DhtAddress) => boolean
|
|
46
47
|
portRange?: PortRange
|
|
47
48
|
maxMessageSize?: number
|
|
48
49
|
host?: string
|
|
@@ -59,59 +60,55 @@ export class WebsocketConnector {
|
|
|
59
60
|
private static readonly WEBSOCKET_CONNECTOR_SERVICE_ID = 'system/websocket-connector'
|
|
60
61
|
private readonly rpcCommunicator: ListeningRpcCommunicator
|
|
61
62
|
private readonly websocketServer?: WebsocketServer
|
|
62
|
-
private
|
|
63
|
-
private readonly ongoingConnectRequests: Map<PeerIDKey, ManagedConnection> = new Map()
|
|
64
|
-
private onNewConnection: (connection: ManagedConnection) => boolean
|
|
63
|
+
private readonly ongoingConnectRequests: Map<DhtAddress, ManagedConnection> = new Map()
|
|
65
64
|
private host?: string
|
|
66
|
-
private readonly entrypoints?: PeerDescriptor[]
|
|
67
|
-
private readonly tlsCertificate?: TlsCertificate
|
|
68
|
-
private readonly autoCertifierTransport: ITransport
|
|
69
|
-
private readonly autoCertifierUrl: string
|
|
70
|
-
private readonly autoCertifierConfigFile: string
|
|
71
|
-
private readonly serverEnableTls: boolean
|
|
72
65
|
private autoCertifierClient?: AutoCertifierClientFacade
|
|
73
66
|
private selectedPort?: number
|
|
74
67
|
private localPeerDescriptor?: PeerDescriptor
|
|
75
|
-
private connectingConnections: Map<
|
|
68
|
+
private connectingConnections: Map<DhtAddress, ManagedConnection> = new Map()
|
|
76
69
|
private abortController = new AbortController()
|
|
70
|
+
private readonly config: WebsocketConnectorConfig
|
|
77
71
|
|
|
78
72
|
constructor(config: WebsocketConnectorConfig) {
|
|
73
|
+
this.config = config
|
|
79
74
|
this.websocketServer = config.portRange ? new WebsocketServer({
|
|
80
|
-
portRange: config.portRange
|
|
75
|
+
portRange: config.portRange,
|
|
81
76
|
tlsCertificate: config.tlsCertificate,
|
|
82
77
|
maxMessageSize: config.maxMessageSize,
|
|
83
78
|
enableTls: config.serverEnableTls
|
|
84
79
|
}) : undefined
|
|
85
|
-
this.onNewConnection = config.onNewConnection
|
|
86
80
|
this.host = config.host
|
|
87
|
-
this.entrypoints = config.entrypoints
|
|
88
|
-
this.tlsCertificate = config.tlsCertificate
|
|
89
|
-
this.autoCertifierTransport = config.autoCertifierTransport
|
|
90
|
-
this.autoCertifierUrl = config.autoCertifierUrl
|
|
91
|
-
this.autoCertifierConfigFile = config.autoCertifierConfigFile
|
|
92
|
-
this.serverEnableTls = config.serverEnableTls
|
|
93
81
|
this.rpcCommunicator = new ListeningRpcCommunicator(WebsocketConnector.WEBSOCKET_CONNECTOR_SERVICE_ID, config.transport, {
|
|
94
|
-
rpcRequestTimeout: 15000
|
|
82
|
+
rpcRequestTimeout: 15000 // TODO use config option or named constant?
|
|
95
83
|
})
|
|
96
84
|
this.registerLocalRpcMethods(config)
|
|
97
85
|
}
|
|
98
86
|
|
|
99
87
|
private registerLocalRpcMethods(config: WebsocketConnectorConfig) {
|
|
100
88
|
const rpcLocal = new WebsocketConnectorRpcLocal({
|
|
101
|
-
canConnect: (peerDescriptor: PeerDescriptor) => config.canConnect(peerDescriptor),
|
|
102
89
|
connect: (targetPeerDescriptor: PeerDescriptor) => this.connect(targetPeerDescriptor),
|
|
90
|
+
hasConnection: (nodeId: DhtAddress): boolean => {
|
|
91
|
+
if (this.connectingConnections.has(nodeId)
|
|
92
|
+
|| this.connectingConnections.has(nodeId)
|
|
93
|
+
|| this.ongoingConnectRequests.has(nodeId)
|
|
94
|
+
|| config.hasConnection(nodeId)
|
|
95
|
+
) {
|
|
96
|
+
return true
|
|
97
|
+
} else {
|
|
98
|
+
return false
|
|
99
|
+
}
|
|
100
|
+
},
|
|
103
101
|
onNewConnection: (connection: ManagedConnection) => config.onNewConnection(connection),
|
|
104
102
|
abortSignal: this.abortController.signal
|
|
105
103
|
})
|
|
106
|
-
this.rpcCommunicator.
|
|
104
|
+
this.rpcCommunicator.registerRpcNotification(
|
|
107
105
|
WebsocketConnectionRequest,
|
|
108
|
-
WebsocketConnectionResponse,
|
|
109
106
|
'requestConnection',
|
|
110
|
-
async (req: WebsocketConnectionRequest, context: ServerCallContext) => {
|
|
107
|
+
async (req: WebsocketConnectionRequest, context: ServerCallContext): Promise<Empty> => {
|
|
111
108
|
if (!this.abortController.signal.aborted) {
|
|
112
109
|
return rpcLocal.requestConnection(req, context)
|
|
113
110
|
} else {
|
|
114
|
-
return {
|
|
111
|
+
return {}
|
|
115
112
|
}
|
|
116
113
|
}
|
|
117
114
|
)
|
|
@@ -119,82 +116,100 @@ export class WebsocketConnector {
|
|
|
119
116
|
|
|
120
117
|
private attachHandshaker(connection: IConnection) {
|
|
121
118
|
const handshaker = new Handshaker(this.localPeerDescriptor!, connection)
|
|
122
|
-
handshaker.once('handshakeRequest', (localPeerDescriptor: PeerDescriptor, remotePeerDescriptor?: PeerDescriptor) => {
|
|
123
|
-
this.onServerSocketHandshakeRequest(localPeerDescriptor, connection, remotePeerDescriptor)
|
|
119
|
+
handshaker.once('handshakeRequest', (localPeerDescriptor: PeerDescriptor, sourceVersion: string, remotePeerDescriptor?: PeerDescriptor) => {
|
|
120
|
+
this.onServerSocketHandshakeRequest(localPeerDescriptor, connection, sourceVersion, remotePeerDescriptor)
|
|
124
121
|
})
|
|
125
122
|
}
|
|
126
123
|
|
|
127
124
|
public async autoCertify(): Promise<void> {
|
|
128
125
|
this.autoCertifierClient = new AutoCertifierClientFacade({
|
|
129
|
-
configFile: this.autoCertifierConfigFile,
|
|
130
|
-
transport: this.autoCertifierTransport,
|
|
131
|
-
url: this.autoCertifierUrl,
|
|
126
|
+
configFile: this.config.autoCertifierConfigFile,
|
|
127
|
+
transport: this.config.autoCertifierTransport,
|
|
128
|
+
url: this.config.autoCertifierUrl,
|
|
132
129
|
wsServerPort: this.selectedPort!,
|
|
133
130
|
setHost: (hostName: string) => this.setHost(hostName),
|
|
134
131
|
updateCertificate: (certificate: string, privateKey: string) => this.websocketServer!.updateCertificate(certificate, privateKey)
|
|
135
132
|
})
|
|
136
133
|
logger.trace(`AutoCertifying subdomain...`)
|
|
137
|
-
await this.autoCertifierClient
|
|
134
|
+
await this.autoCertifierClient.start()
|
|
138
135
|
}
|
|
139
136
|
|
|
140
137
|
private setHost(hostName: string): void {
|
|
141
138
|
logger.trace(`Setting host name to ${hostName}`)
|
|
142
139
|
this.host = hostName
|
|
143
|
-
this.connectivityChecker!.setHost(hostName)
|
|
144
140
|
}
|
|
145
141
|
|
|
146
142
|
public async start(): Promise<void> {
|
|
147
143
|
if (!this.abortController.signal.aborted && this.websocketServer) {
|
|
148
144
|
this.websocketServer.on('connected', (connection: IConnection) => {
|
|
149
|
-
const serverSocket = connection as unknown as
|
|
150
|
-
const query = serverSocket.resourceURL.query as
|
|
151
|
-
const action = query
|
|
152
|
-
logger.trace('WebSocket client connected', { action, remoteAddress: serverSocket.
|
|
145
|
+
const serverSocket = connection as unknown as WebsocketServerConnection
|
|
146
|
+
const query = queryString.parse(serverSocket.resourceURL.query as string ?? '')
|
|
147
|
+
const action = query.action as (Action | undefined)
|
|
148
|
+
logger.trace('WebSocket client connected', { action, remoteAddress: serverSocket.remoteIpAddress })
|
|
153
149
|
if (action === 'connectivityRequest') {
|
|
154
|
-
|
|
150
|
+
attachConnectivityRequestHandler(serverSocket)
|
|
155
151
|
} else if (action === 'connectivityProbe') {
|
|
156
152
|
// no-op
|
|
157
153
|
} else {
|
|
158
|
-
|
|
154
|
+
// The localPeerDescriptor can be undefined here as the WS server is used for connectivity checks
|
|
155
|
+
// before the localPeerDescriptor is set during start.
|
|
156
|
+
// Handshaked connections should be rejected before the localPeerDescriptor is set.
|
|
157
|
+
if (this.localPeerDescriptor !== undefined) {
|
|
158
|
+
this.attachHandshaker(connection)
|
|
159
|
+
} else {
|
|
160
|
+
logger.trace('incoming Websocket connection before localPeerDescriptor was set, closing connection')
|
|
161
|
+
connection.close(false).catch(() => {})
|
|
162
|
+
}
|
|
159
163
|
}
|
|
160
164
|
})
|
|
161
165
|
const port = await this.websocketServer.start()
|
|
162
166
|
this.selectedPort = port
|
|
163
|
-
this.connectivityChecker = new ConnectivityChecker(this.selectedPort, this.serverEnableTls, this.host)
|
|
164
167
|
}
|
|
165
168
|
}
|
|
166
169
|
|
|
167
170
|
public async checkConnectivity(selfSigned: boolean): Promise<ConnectivityResponse> {
|
|
168
|
-
// TODO: this could throw
|
|
169
|
-
const noServerConnectivityResponse: ConnectivityResponse = {
|
|
170
|
-
host: '127.0.0.1',
|
|
171
|
-
natType: NatType.UNKNOWN
|
|
172
|
-
}
|
|
171
|
+
// TODO: this could throw?
|
|
173
172
|
if (this.abortController.signal.aborted) {
|
|
174
|
-
return
|
|
173
|
+
return {
|
|
174
|
+
host: '127.0.0.1',
|
|
175
|
+
natType: NatType.UNKNOWN,
|
|
176
|
+
ipAddress: ipv4ToNumber('127.0.0.1'),
|
|
177
|
+
version: LOCAL_PROTOCOL_VERSION
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
if (!this.config.entrypoints || this.config.entrypoints.length === 0) {
|
|
181
|
+
// return connectivity info given in config
|
|
182
|
+
return {
|
|
183
|
+
host: this.host!,
|
|
184
|
+
natType: NatType.OPEN_INTERNET,
|
|
185
|
+
websocket: {
|
|
186
|
+
host: this.host!,
|
|
187
|
+
port: this.selectedPort!,
|
|
188
|
+
tls: this.config.tlsCertificate !== undefined
|
|
189
|
+
},
|
|
190
|
+
// TODO: Resolve the given host name or or use as is if IP was given.
|
|
191
|
+
ipAddress: ipv4ToNumber('127.0.0.1'),
|
|
192
|
+
version: LOCAL_PROTOCOL_VERSION
|
|
193
|
+
}
|
|
175
194
|
}
|
|
176
195
|
for (const reattempt of range(ENTRY_POINT_CONNECTION_ATTEMPTS)) {
|
|
177
|
-
const entryPoint = sample(this.entrypoints)!
|
|
196
|
+
const entryPoint = sample(this.config.entrypoints)!
|
|
178
197
|
try {
|
|
179
|
-
|
|
180
|
-
|
|
198
|
+
// Do real connectivity checking
|
|
199
|
+
const connectivityRequest = {
|
|
200
|
+
port: this.selectedPort ?? DISABLE_CONNECTIVITY_PROBE,
|
|
201
|
+
host: this.host,
|
|
202
|
+
tls: this.websocketServer ? this.config.serverEnableTls : false,
|
|
203
|
+
selfSigned
|
|
204
|
+
}
|
|
205
|
+
if (!this.abortController.signal.aborted) {
|
|
206
|
+
return await sendConnectivityRequest(connectivityRequest, entryPoint)
|
|
181
207
|
} else {
|
|
182
|
-
|
|
183
|
-
// return connectivity info given in config
|
|
184
|
-
const preconfiguredConnectivityResponse: ConnectivityResponse = {
|
|
185
|
-
host: this.host!,
|
|
186
|
-
natType: NatType.OPEN_INTERNET,
|
|
187
|
-
websocket: { host: this.host!, port: this.selectedPort!, tls: this.tlsCertificate !== undefined }
|
|
188
|
-
}
|
|
189
|
-
return preconfiguredConnectivityResponse
|
|
190
|
-
} else {
|
|
191
|
-
// Do real connectivity checking
|
|
192
|
-
return await this.connectivityChecker!.sendConnectivityRequest(entryPoint, selfSigned)
|
|
193
|
-
}
|
|
208
|
+
throw new Err.ConnectionFailed('ConnectivityChecker is destroyed')
|
|
194
209
|
}
|
|
195
210
|
} catch (err) {
|
|
196
211
|
if (reattempt < ENTRY_POINT_CONNECTION_ATTEMPTS) {
|
|
197
|
-
const error = `Failed to connect to entrypoint with id ${
|
|
212
|
+
const error = `Failed to connect to entrypoint with id ${getNodeIdFromPeerDescriptor(entryPoint)} `
|
|
198
213
|
+ `and URL ${connectivityMethodToWebsocketUrl(entryPoint.websocket!)}`
|
|
199
214
|
logger.error(error, { error: err })
|
|
200
215
|
await wait(2000)
|
|
@@ -210,8 +225,8 @@ export class WebsocketConnector {
|
|
|
210
225
|
}
|
|
211
226
|
|
|
212
227
|
public connect(targetPeerDescriptor: PeerDescriptor): ManagedConnection {
|
|
213
|
-
const
|
|
214
|
-
const existingConnection = this.connectingConnections.get(
|
|
228
|
+
const nodeId = getNodeIdFromPeerDescriptor(targetPeerDescriptor)
|
|
229
|
+
const existingConnection = this.connectingConnections.get(nodeId)
|
|
215
230
|
if (existingConnection) {
|
|
216
231
|
return existingConnection
|
|
217
232
|
}
|
|
@@ -232,11 +247,11 @@ export class WebsocketConnector {
|
|
|
232
247
|
)
|
|
233
248
|
managedConnection.setRemotePeerDescriptor(targetPeerDescriptor)
|
|
234
249
|
|
|
235
|
-
this.connectingConnections.set(
|
|
250
|
+
this.connectingConnections.set(nodeId, managedConnection)
|
|
236
251
|
|
|
237
252
|
const delFunc = () => {
|
|
238
|
-
if (this.connectingConnections.has(
|
|
239
|
-
this.connectingConnections.delete(
|
|
253
|
+
if (this.connectingConnections.has(nodeId)) {
|
|
254
|
+
this.connectingConnections.delete(nodeId)
|
|
240
255
|
}
|
|
241
256
|
socket.off('disconnected', delFunc)
|
|
242
257
|
managedConnection.off('handshakeCompleted', delFunc)
|
|
@@ -255,9 +270,17 @@ export class WebsocketConnector {
|
|
|
255
270
|
const remoteConnector = new WebsocketConnectorRpcRemote(
|
|
256
271
|
localPeerDescriptor,
|
|
257
272
|
targetPeerDescriptor,
|
|
258
|
-
|
|
273
|
+
this.rpcCommunicator,
|
|
274
|
+
WebsocketConnectorRpcClient
|
|
259
275
|
)
|
|
260
|
-
remoteConnector.requestConnection(
|
|
276
|
+
remoteConnector.requestConnection().then(() => {
|
|
277
|
+
logger.trace('Sent WebsocketConnectionRequest notification to peer', { targetPeerDescriptor })
|
|
278
|
+
return
|
|
279
|
+
}, (err) => {
|
|
280
|
+
logger.debug('Failed to send WebsocketConnectionRequest notification to peer ', {
|
|
281
|
+
error: err, targetPeerDescriptor
|
|
282
|
+
})
|
|
283
|
+
})
|
|
261
284
|
})
|
|
262
285
|
const managedConnection = new ManagedConnection(
|
|
263
286
|
this.localPeerDescriptor!,
|
|
@@ -265,43 +288,44 @@ export class WebsocketConnector {
|
|
|
265
288
|
undefined,
|
|
266
289
|
undefined,
|
|
267
290
|
targetPeerDescriptor
|
|
268
|
-
)
|
|
269
|
-
|
|
291
|
+
)
|
|
292
|
+
const nodeId = getNodeIdFromPeerDescriptor(targetPeerDescriptor)
|
|
293
|
+
managedConnection.on('disconnected', () => this.ongoingConnectRequests.delete(nodeId))
|
|
270
294
|
managedConnection.setRemotePeerDescriptor(targetPeerDescriptor)
|
|
271
|
-
this.ongoingConnectRequests.set(
|
|
295
|
+
this.ongoingConnectRequests.set(nodeId, managedConnection)
|
|
272
296
|
return managedConnection
|
|
273
297
|
}
|
|
274
298
|
|
|
275
299
|
private onServerSocketHandshakeRequest(
|
|
276
|
-
sourcePeerDescriptor: PeerDescriptor,
|
|
277
|
-
|
|
300
|
+
sourcePeerDescriptor: PeerDescriptor,
|
|
301
|
+
websocketServerConnection: IConnection,
|
|
302
|
+
remoteVersion: string,
|
|
278
303
|
targetPeerDescriptor?: PeerDescriptor
|
|
279
304
|
) {
|
|
280
|
-
const
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
if (targetPeerDescriptor && !areEqualPeerDescriptors(this.localPeerDescriptor!, targetPeerDescriptor)) {
|
|
286
|
-
ongoingConnectRequest.rejectHandshake(HandshakeError.INVALID_TARGET_PEER_DESCRIPTOR)
|
|
305
|
+
const nodeId = getNodeIdFromPeerDescriptor(sourcePeerDescriptor)
|
|
306
|
+
if (this.ongoingConnectRequests.has(nodeId)) {
|
|
307
|
+
const ongoingConnectRequest = this.ongoingConnectRequests.get(nodeId)!
|
|
308
|
+
if (!isMaybeSupportedVersion(remoteVersion)) {
|
|
309
|
+
ongoingConnectRequest.rejectHandshake(HandshakeError.UNSUPPORTED_VERSION)
|
|
287
310
|
} else {
|
|
311
|
+
ongoingConnectRequest.attachImplementation(websocketServerConnection)
|
|
288
312
|
ongoingConnectRequest.acceptHandshake()
|
|
289
|
-
this.ongoingConnectRequests.delete(peerId.toKey())
|
|
290
313
|
}
|
|
314
|
+
this.ongoingConnectRequests.delete(nodeId)
|
|
291
315
|
} else {
|
|
292
316
|
const managedConnection = new ManagedConnection(
|
|
293
317
|
this.localPeerDescriptor!,
|
|
294
318
|
ConnectionType.WEBSOCKET_SERVER,
|
|
295
319
|
undefined,
|
|
296
|
-
|
|
320
|
+
websocketServerConnection,
|
|
297
321
|
targetPeerDescriptor
|
|
298
322
|
)
|
|
299
|
-
|
|
300
323
|
managedConnection.setRemotePeerDescriptor(sourcePeerDescriptor)
|
|
301
|
-
|
|
302
|
-
|
|
324
|
+
if (!isMaybeSupportedVersion(remoteVersion)) {
|
|
325
|
+
managedConnection.rejectHandshake(HandshakeError.UNSUPPORTED_VERSION)
|
|
326
|
+
} else if (targetPeerDescriptor && !areEqualPeerDescriptors(this.localPeerDescriptor!, targetPeerDescriptor)) {
|
|
303
327
|
managedConnection.rejectHandshake(HandshakeError.INVALID_TARGET_PEER_DESCRIPTOR)
|
|
304
|
-
} else if (this.onNewConnection(managedConnection)) {
|
|
328
|
+
} else if (this.config.onNewConnection(managedConnection)) {
|
|
305
329
|
managedConnection.acceptHandshake()
|
|
306
330
|
} else {
|
|
307
331
|
managedConnection.rejectHandshake(HandshakeError.DUPLICATE_CONNECTION)
|
|
@@ -322,7 +346,6 @@ export class WebsocketConnector {
|
|
|
322
346
|
|
|
323
347
|
const attempts = Array.from(this.connectingConnections.values())
|
|
324
348
|
await Promise.allSettled(attempts.map((conn) => conn.close(false)))
|
|
325
|
-
this.connectivityChecker?.destroy()
|
|
326
349
|
await this.websocketServer?.stop()
|
|
327
350
|
}
|
|
328
351
|
}
|