@streamr/dht 100.0.0-pretestnet.4 → 100.0.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +18 -9
- 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 +0 -2
- package/dist/src/connection/webrtc/WebrtcConnector.js +24 -25
- package/dist/src/connection/webrtc/WebrtcConnector.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.d.ts +2 -2
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js +27 -20
- 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 +16 -13
- 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 +23 -11
- 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 +24 -26
- package/src/connection/webrtc/WebrtcConnector.ts +18 -29
- package/src/connection/webrtc/WebrtcConnectorRpcLocal.ts +29 -24
- 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
|
@@ -7,16 +7,20 @@ const WebrtcConnector_1 = require("./webrtc/WebrtcConnector");
|
|
|
7
7
|
const WebsocketConnector_1 = require("./websocket/WebsocketConnector");
|
|
8
8
|
const logger = new utils_1.Logger(module);
|
|
9
9
|
class DefaultConnectorFacade {
|
|
10
|
+
config;
|
|
11
|
+
localPeerDescriptor;
|
|
12
|
+
websocketConnector;
|
|
13
|
+
webrtcConnector;
|
|
10
14
|
constructor(config) {
|
|
11
15
|
this.config = config;
|
|
12
16
|
}
|
|
13
|
-
async start(onNewConnection,
|
|
17
|
+
async start(onNewConnection, hasConnection, autoCertifierTransport) {
|
|
14
18
|
logger.trace(`Creating WebsocketConnectorRpcLocal`);
|
|
15
19
|
const webSocketConnectorConfig = {
|
|
16
20
|
transport: this.config.transport,
|
|
17
21
|
// TODO should we use canConnect also for WebrtcConnector? (NET-1142)
|
|
18
|
-
canConnect: (peerDescriptor) => canConnect(peerDescriptor),
|
|
19
22
|
onNewConnection,
|
|
23
|
+
hasConnection,
|
|
20
24
|
portRange: this.config.websocketPortRange,
|
|
21
25
|
host: this.config.websocketHost,
|
|
22
26
|
entrypoints: this.config.entryPoints,
|
|
@@ -66,7 +70,7 @@ class DefaultConnectorFacade {
|
|
|
66
70
|
}
|
|
67
71
|
}
|
|
68
72
|
catch (err) {
|
|
69
|
-
logger.warn('Failed to auto-certify, disabling WebSocket server TLS');
|
|
73
|
+
logger.warn('Failed to auto-certify, disabling WebSocket server TLS', { error: err });
|
|
70
74
|
await this.restartWebsocketConnector({
|
|
71
75
|
...webSocketConnectorConfig,
|
|
72
76
|
serverEnableTls: false
|
|
@@ -105,6 +109,9 @@ class DefaultConnectorFacade {
|
|
|
105
109
|
}
|
|
106
110
|
exports.DefaultConnectorFacade = DefaultConnectorFacade;
|
|
107
111
|
class SimulatorConnectorFacade {
|
|
112
|
+
localPeerDescriptor;
|
|
113
|
+
simulatorConnector;
|
|
114
|
+
simulator;
|
|
108
115
|
constructor(localPeerDescriptor, simulator) {
|
|
109
116
|
this.localPeerDescriptor = localPeerDescriptor;
|
|
110
117
|
this.simulator = simulator;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConnectorFacade.js","sourceRoot":"","sources":["../../../src/connection/ConnectorFacade.ts"],"names":[],"mappings":";;;AAAA,0CAAuC;AASvC,uEAAmE;AACnE,8DAAqE;AACrE,uEAA6F;
|
|
1
|
+
{"version":3,"file":"ConnectorFacade.js","sourceRoot":"","sources":["../../../src/connection/ConnectorFacade.ts"],"names":[],"mappings":";;;AAAA,0CAAuC;AASvC,uEAAmE;AACnE,8DAAqE;AACrE,uEAA6F;AAc7F,MAAM,MAAM,GAAG,IAAI,cAAM,CAAC,MAAM,CAAC,CAAA;AAwBjC,MAAa,sBAAsB;IAEd,MAAM,CAA8B;IAC7C,mBAAmB,CAAiB;IACpC,kBAAkB,CAAqB;IACvC,eAAe,CAAkB;IACzC,YAAY,MAAoC;QAC5C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACxB,CAAC;IAED,KAAK,CAAC,KAAK,CACP,eAA2D,EAC3D,aAA8C,EAC9C,sBAAkC;QAElC,MAAM,CAAC,KAAK,CAAC,qCAAqC,CAAC,CAAA;QACnD,MAAM,wBAAwB,GAAG;YAC7B,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS;YAChC,qEAAqE;YACrE,eAAe;YACf,aAAa;YACb,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,kBAAkB;YACzC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,aAAa;YAC/B,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW;YACpC,cAAc,EAAE,IAAI,CAAC,MAAM,CAAC,cAAc;YAC1C,eAAe,EAAE,IAAI,CAAC,MAAM,CAAC,wBAAyB;YACtD,gBAAgB,EAAE,IAAI,CAAC,MAAM,CAAC,gBAAiB;YAC/C,uBAAuB,EAAE,IAAI,CAAC,M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C,CAAA;QAC3C,IAAI,CAAC,kBAAkB,GAAG,IAAI,uCAAkB,CAC5C,IAAI,CAAC,mBAAmB,EACxB,IAAI,CAAC,SAAS,EACd,eAAe,CAClB,CAAA;QACD,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAA;IACxD,CAAC;IAED,gBAAgB,CAAC,cAA8B;QAC3C,OAAO,IAAI,CAAC,kBAAmB,CAAC,OAAO,CAAC,cAAc,CAAC,CAAA;IAC3D,CAAC;IAED,sBAAsB;QAClB,OAAO,IAAI,CAAC,mBAAmB,CAAA;IACnC,CAAC;IAED,KAAK,CAAC,IAAI;QACN,MAAM,IAAI,CAAC,kBAAmB,CAAC,IAAI,EAAE,CAAA;IACzC,CAAC;CACJ;AAhCD,4DAgCC"}
|
|
@@ -2,7 +2,7 @@ import { EventEmitter } from 'eventemitter3';
|
|
|
2
2
|
import { PeerDescriptor, HandshakeError } from '../proto/packages/dht/protos/DhtRpc';
|
|
3
3
|
import { IConnection } from './IConnection';
|
|
4
4
|
interface HandshakerEvents {
|
|
5
|
-
handshakeRequest: (source: PeerDescriptor, target?: PeerDescriptor) => void;
|
|
5
|
+
handshakeRequest: (source: PeerDescriptor, version: string, target?: PeerDescriptor) => void;
|
|
6
6
|
handshakeCompleted: (remote: PeerDescriptor) => void;
|
|
7
7
|
handshakeFailed: (error?: HandshakeError) => void;
|
|
8
8
|
}
|
|
@@ -10,9 +10,11 @@ export declare class Handshaker extends EventEmitter<HandshakerEvents> {
|
|
|
10
10
|
private static readonly HANDSHAKER_SERVICE_ID;
|
|
11
11
|
private localPeerDescriptor;
|
|
12
12
|
private connection;
|
|
13
|
+
private readonly onDataListener;
|
|
13
14
|
constructor(localPeerDescriptor: PeerDescriptor, connection: IConnection);
|
|
14
15
|
private onData;
|
|
15
16
|
sendHandshakeRequest(remotePeerDescriptor?: PeerDescriptor): void;
|
|
16
17
|
sendHandshakeResponse(error?: HandshakeError): void;
|
|
18
|
+
stop(): void;
|
|
17
19
|
}
|
|
18
20
|
export {};
|
|
@@ -5,13 +5,19 @@ const utils_1 = require("@streamr/utils");
|
|
|
5
5
|
const eventemitter3_1 = require("eventemitter3");
|
|
6
6
|
const uuid_1 = require("uuid");
|
|
7
7
|
const DhtRpc_1 = require("../proto/packages/dht/protos/DhtRpc");
|
|
8
|
+
const version_1 = require("../helpers/version");
|
|
8
9
|
const logger = new utils_1.Logger(module);
|
|
9
10
|
class Handshaker extends eventemitter3_1.EventEmitter {
|
|
11
|
+
static HANDSHAKER_SERVICE_ID = 'system/handshaker';
|
|
12
|
+
localPeerDescriptor;
|
|
13
|
+
connection;
|
|
14
|
+
onDataListener;
|
|
10
15
|
constructor(localPeerDescriptor, connection) {
|
|
11
16
|
super();
|
|
12
17
|
this.localPeerDescriptor = localPeerDescriptor;
|
|
13
18
|
this.connection = connection;
|
|
14
|
-
this.
|
|
19
|
+
this.onDataListener = (data) => this.onData(data);
|
|
20
|
+
this.connection.on('data', this.onDataListener);
|
|
15
21
|
}
|
|
16
22
|
onData(data) {
|
|
17
23
|
try {
|
|
@@ -19,13 +25,14 @@ class Handshaker extends eventemitter3_1.EventEmitter {
|
|
|
19
25
|
if (message.body.oneofKind === 'handshakeRequest') {
|
|
20
26
|
logger.trace('handshake request received');
|
|
21
27
|
const handshake = message.body.handshakeRequest;
|
|
22
|
-
this.emit('handshakeRequest', handshake.sourcePeerDescriptor, handshake.targetPeerDescriptor);
|
|
28
|
+
this.emit('handshakeRequest', handshake.sourcePeerDescriptor, handshake.version, handshake.targetPeerDescriptor);
|
|
23
29
|
}
|
|
24
30
|
if (message.body.oneofKind === 'handshakeResponse') {
|
|
25
31
|
logger.trace('handshake response received');
|
|
26
32
|
const handshake = message.body.handshakeResponse;
|
|
27
|
-
|
|
28
|
-
|
|
33
|
+
const error = !(0, version_1.isMaybeSupportedVersion)(handshake.version) ? DhtRpc_1.HandshakeError.UNSUPPORTED_VERSION : handshake.error;
|
|
34
|
+
if (error !== undefined) {
|
|
35
|
+
this.emit('handshakeFailed', error);
|
|
29
36
|
}
|
|
30
37
|
else {
|
|
31
38
|
this.emit('handshakeCompleted', handshake.sourcePeerDescriptor);
|
|
@@ -39,11 +46,11 @@ class Handshaker extends eventemitter3_1.EventEmitter {
|
|
|
39
46
|
sendHandshakeRequest(remotePeerDescriptor) {
|
|
40
47
|
const outgoingHandshake = {
|
|
41
48
|
sourcePeerDescriptor: this.localPeerDescriptor,
|
|
42
|
-
targetPeerDescriptor: remotePeerDescriptor
|
|
49
|
+
targetPeerDescriptor: remotePeerDescriptor,
|
|
50
|
+
version: version_1.LOCAL_PROTOCOL_VERSION
|
|
43
51
|
};
|
|
44
52
|
const msg = {
|
|
45
53
|
serviceId: Handshaker.HANDSHAKER_SERVICE_ID,
|
|
46
|
-
messageType: DhtRpc_1.MessageType.HANDSHAKE_REQUEST,
|
|
47
54
|
messageId: (0, uuid_1.v4)(),
|
|
48
55
|
body: {
|
|
49
56
|
oneofKind: 'handshakeRequest',
|
|
@@ -56,11 +63,11 @@ class Handshaker extends eventemitter3_1.EventEmitter {
|
|
|
56
63
|
sendHandshakeResponse(error) {
|
|
57
64
|
const outgoingHandshakeResponse = {
|
|
58
65
|
sourcePeerDescriptor: this.localPeerDescriptor,
|
|
59
|
-
error
|
|
66
|
+
error,
|
|
67
|
+
version: version_1.LOCAL_PROTOCOL_VERSION
|
|
60
68
|
};
|
|
61
69
|
const msg = {
|
|
62
70
|
serviceId: Handshaker.HANDSHAKER_SERVICE_ID,
|
|
63
|
-
messageType: DhtRpc_1.MessageType.HANDSHAKE_RESPONSE,
|
|
64
71
|
messageId: (0, uuid_1.v4)(),
|
|
65
72
|
body: {
|
|
66
73
|
oneofKind: 'handshakeResponse',
|
|
@@ -70,7 +77,9 @@ class Handshaker extends eventemitter3_1.EventEmitter {
|
|
|
70
77
|
this.connection.send(DhtRpc_1.Message.toBinary(msg));
|
|
71
78
|
logger.trace('handshake response sent');
|
|
72
79
|
}
|
|
80
|
+
stop() {
|
|
81
|
+
this.connection.off('data', this.onDataListener);
|
|
82
|
+
}
|
|
73
83
|
}
|
|
74
84
|
exports.Handshaker = Handshaker;
|
|
75
|
-
Handshaker.HANDSHAKER_SERVICE_ID = 'system/handshaker';
|
|
76
85
|
//# sourceMappingURL=Handshaker.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Handshaker.js","sourceRoot":"","sources":["../../../src/connection/Handshaker.ts"],"names":[],"mappings":";;;AAAA,0CAAuC;AACvC,iDAA4C;AAC5C,+BAAyB;AACzB,
|
|
1
|
+
{"version":3,"file":"Handshaker.js","sourceRoot":"","sources":["../../../src/connection/Handshaker.ts"],"names":[],"mappings":";;;AAAA,0CAAuC;AACvC,iDAA4C;AAC5C,+BAAyB;AACzB,gEAAkI;AAElI,gDAAoF;AAEpF,MAAM,MAAM,GAAG,IAAI,cAAM,CAAC,MAAM,CAAC,CAAA;AAQjC,MAAa,UAAW,SAAQ,4BAA8B;IAElD,MAAM,CAAU,qBAAqB,GAAG,mBAAmB,CAAA;IAC3D,mBAAmB,CAAgB;IACnC,UAAU,CAAa;IACd,cAAc,CAA4B;IAC3D,YACI,mBAAmC,EACnC,UAAuB;QAEvB,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,mBAAmB,GAAG,mBAAmB,CAAA;QAC9C,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,cAAc,GAAG,CAAC,IAAgB,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;QAC7D,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,IAAI,CAAC,cAAc,CAAC,CAAA;IACnD,CAAC;IAEO,MAAM,CAAC,IAAgB;QAC3B,IAAI,CAAC;YACD,MAAM,OAAO,GAAG,gBAAO,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA;YACxC,IAAI,OAAO,CAAC,IAAI,CAAC,SAAS,KAAK,kBAAkB,EAAE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AAE;YACf,IAAI,EAAE;gBACF,SAAS,EAAE,kBAAkB;gBAC7B,gBAAgB,EAAE,iBAAiB;aACtC;SACJ,CAAA;QACD,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,gBAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAA;QAC3C,MAAM,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAA;IAC1C,CAAC;IAEM,qBAAqB,CAAC,KAAsB;QAC/C,MAAM,yBAAyB,GAAsB;YACjD,oBAAoB,EAAE,IAAI,CAAC,mBAAmB;YAC9C,KAAK;YACL,OAAO,EAAE,gCAAsB;SAClC,CAAA;QACD,MAAM,GAAG,GAAY;YACjB,SAAS,EAAE,UAAU,CAAC,qBAAqB;YAC3C,SAAS,EAAE,IAAA,SAAE,GAAE;YACf,IAAI,EAAE;gBACF,SAAS,EAAE,mBAAmB;gBAC9B,iBAAiB,EAAE,yBAAyB;aAC/C;SACJ,CAAA;QACD,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,gBAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAA;QAC3C,MAAM,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAA;IAC3C,CAAC;IAEM,IAAI;QACP,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,cAAc,CAAC,CAAA;IACpD,CAAC;;AApFL,gCAqFC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BrandedString } from '@streamr/utils';
|
|
2
2
|
export interface ConnectionEvents {
|
|
3
3
|
data: (bytes: Uint8Array) => void;
|
|
4
4
|
connected: () => void;
|
|
@@ -12,12 +12,7 @@ export declare enum ConnectionType {
|
|
|
12
12
|
SIMULATOR_SERVER = "simulator-server",
|
|
13
13
|
SIMULATOR_CLIENT = "simulator-client"
|
|
14
14
|
}
|
|
15
|
-
export type
|
|
16
|
-
readonly __brand: 'connectionIDKey';
|
|
17
|
-
};
|
|
18
|
-
export declare class ConnectionID extends UUID {
|
|
19
|
-
toMapKey(): ConnectionIDKey;
|
|
20
|
-
}
|
|
15
|
+
export type ConnectionID = BrandedString<'ConnectionID'>;
|
|
21
16
|
export interface IConnection {
|
|
22
17
|
on(event: 'data', listener: (bytes: Uint8Array) => void): this;
|
|
23
18
|
on(event: 'error', listener: (name: string) => void): this;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const UUID_1 = require("../helpers/UUID");
|
|
3
|
+
exports.ConnectionType = void 0;
|
|
5
4
|
var ConnectionType;
|
|
6
5
|
(function (ConnectionType) {
|
|
7
6
|
ConnectionType["WEBSOCKET_SERVER"] = "websocket-server";
|
|
@@ -10,10 +9,4 @@ var ConnectionType;
|
|
|
10
9
|
ConnectionType["SIMULATOR_SERVER"] = "simulator-server";
|
|
11
10
|
ConnectionType["SIMULATOR_CLIENT"] = "simulator-client";
|
|
12
11
|
})(ConnectionType || (exports.ConnectionType = ConnectionType = {}));
|
|
13
|
-
class ConnectionID extends UUID_1.UUID {
|
|
14
|
-
toMapKey() {
|
|
15
|
-
return this.toString();
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
exports.ConnectionID = ConnectionID;
|
|
19
12
|
//# sourceMappingURL=IConnection.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IConnection.js","sourceRoot":"","sources":["../../../src/connection/IConnection.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"IConnection.js","sourceRoot":"","sources":["../../../src/connection/IConnection.ts"],"names":[],"mappings":";;;AASA,IAAY,cAMX;AAND,WAAY,cAAc;IACtB,uDAAqC,CAAA;IACrC,uDAAqC,CAAA;IACrC,mCAAiB,CAAA;IACjB,uDAAqC,CAAA;IACrC,uDAAqC,CAAA;AACzC,CAAC,EANW,cAAc,8BAAd,cAAc,QAMzB"}
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { ConnectionEvents, ConnectionID, ConnectionType, IConnection } from './IConnection';
|
|
2
2
|
import { HandshakeError, PeerDescriptor } from '../proto/packages/dht/protos/DhtRpc';
|
|
3
3
|
import EventEmitter from 'eventemitter3';
|
|
4
|
-
import {
|
|
4
|
+
import { DhtAddress } from '../identifiers';
|
|
5
5
|
export interface ManagedConnectionEvents {
|
|
6
6
|
managedData: (bytes: Uint8Array, remotePeerDescriptor: PeerDescriptor) => void;
|
|
7
|
-
handshakeRequest: (source: PeerDescriptor, target?: PeerDescriptor) => void;
|
|
7
|
+
handshakeRequest: (source: PeerDescriptor, version: string, target?: PeerDescriptor) => void;
|
|
8
8
|
handshakeCompleted: (peerDescriptor: PeerDescriptor) => void;
|
|
9
9
|
handshakeFailed: () => void;
|
|
10
|
-
bufferSentByOtherConnection: () => void;
|
|
11
|
-
closing: () => void;
|
|
12
10
|
}
|
|
13
11
|
export type Events = ManagedConnectionEvents & ConnectionEvents;
|
|
14
12
|
export declare class ManagedConnection extends EventEmitter<Events> {
|
|
@@ -23,24 +21,24 @@ export declare class ManagedConnection extends EventEmitter<Events> {
|
|
|
23
21
|
private handshakeCompleted;
|
|
24
22
|
private lastUsed;
|
|
25
23
|
private stopped;
|
|
26
|
-
offeredAsIncoming: boolean;
|
|
27
24
|
private bufferSentbyOtherConnection;
|
|
28
25
|
private closing;
|
|
29
26
|
replacedByOtherConnection: boolean;
|
|
30
27
|
private localPeerDescriptor;
|
|
31
28
|
protected outgoingConnection?: IConnection;
|
|
32
29
|
protected incomingConnection?: IConnection;
|
|
30
|
+
private created;
|
|
33
31
|
constructor(localPeerDescriptor: PeerDescriptor, connectionType: ConnectionType, outgoingConnection?: IConnection, incomingConnection?: IConnection, targetPeerDescriptor?: PeerDescriptor);
|
|
34
32
|
on(event: keyof Events, fn: (...args: any) => void, context?: any): this;
|
|
35
33
|
once(event: keyof Events, fn: (...args: any) => void, context?: any): this;
|
|
36
|
-
|
|
34
|
+
getNodeId(): DhtAddress;
|
|
37
35
|
getLastUsed(): number;
|
|
38
36
|
setRemotePeerDescriptor(peerDescriptor: PeerDescriptor): void;
|
|
39
37
|
getPeerDescriptor(): PeerDescriptor | undefined;
|
|
40
38
|
private onHandshakeCompleted;
|
|
41
39
|
attachImplementation(impl: IConnection): void;
|
|
42
40
|
private onDisconnected;
|
|
43
|
-
send(data: Uint8Array,
|
|
41
|
+
send(data: Uint8Array, connect: boolean): Promise<void>;
|
|
44
42
|
sendNoWait(data: Uint8Array): void;
|
|
45
43
|
reportBufferSentByOtherConnection(): void;
|
|
46
44
|
acceptHandshake(): void;
|
|
@@ -27,33 +27,42 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.ManagedConnection = void 0;
|
|
30
|
-
const IConnection_1 = require("./IConnection");
|
|
31
30
|
const Err = __importStar(require("../helpers/errors"));
|
|
32
31
|
const Handshaker_1 = require("./Handshaker");
|
|
33
32
|
const DhtRpc_1 = require("../proto/packages/dht/protos/DhtRpc");
|
|
34
33
|
const utils_1 = require("@streamr/utils");
|
|
35
34
|
const eventemitter3_1 = __importDefault(require("eventemitter3"));
|
|
36
|
-
const peerIdFromPeerDescriptor_1 = require("../helpers/peerIdFromPeerDescriptor");
|
|
37
35
|
const ConnectionManager_1 = require("./ConnectionManager");
|
|
36
|
+
const identifiers_1 = require("../identifiers");
|
|
37
|
+
const Connection_1 = require("./Connection");
|
|
38
38
|
const logger = new utils_1.Logger(module);
|
|
39
39
|
class ManagedConnection extends eventemitter3_1.default {
|
|
40
|
+
implementation;
|
|
41
|
+
outputBufferEmitter = new eventemitter3_1.default();
|
|
42
|
+
outputBuffer = [];
|
|
43
|
+
inputBuffer = [];
|
|
44
|
+
connectionId;
|
|
45
|
+
remotePeerDescriptor;
|
|
46
|
+
connectionType;
|
|
47
|
+
handshaker;
|
|
48
|
+
handshakeCompleted = false;
|
|
49
|
+
lastUsed = Date.now();
|
|
50
|
+
stopped = false;
|
|
51
|
+
bufferSentbyOtherConnection = false;
|
|
52
|
+
closing = false;
|
|
53
|
+
replacedByOtherConnection = false;
|
|
54
|
+
localPeerDescriptor;
|
|
55
|
+
outgoingConnection;
|
|
56
|
+
incomingConnection;
|
|
57
|
+
// TODO: Temporary debug variable, should be removed in the future.
|
|
58
|
+
created = Date.now();
|
|
40
59
|
constructor(localPeerDescriptor, connectionType, outgoingConnection, incomingConnection, targetPeerDescriptor) {
|
|
41
60
|
super();
|
|
42
|
-
this.outputBufferEmitter = new eventemitter3_1.default();
|
|
43
|
-
this.outputBuffer = [];
|
|
44
|
-
this.inputBuffer = [];
|
|
45
|
-
this.handshakeCompleted = false;
|
|
46
|
-
this.lastUsed = Date.now();
|
|
47
|
-
this.stopped = false;
|
|
48
|
-
this.offeredAsIncoming = false;
|
|
49
|
-
this.bufferSentbyOtherConnection = false;
|
|
50
|
-
this.closing = false;
|
|
51
|
-
this.replacedByOtherConnection = false;
|
|
52
61
|
this.localPeerDescriptor = localPeerDescriptor;
|
|
53
62
|
this.outgoingConnection = outgoingConnection;
|
|
54
63
|
this.incomingConnection = incomingConnection;
|
|
55
64
|
this.connectionType = connectionType;
|
|
56
|
-
this.connectionId =
|
|
65
|
+
this.connectionId = (0, Connection_1.createRandomConnectionId)();
|
|
57
66
|
this.send = this.send.bind(this);
|
|
58
67
|
this.onDisconnected = this.onDisconnected.bind(this);
|
|
59
68
|
logger.trace('creating ManagedConnection of type: ' + connectionType);
|
|
@@ -63,7 +72,8 @@ class ManagedConnection extends eventemitter3_1.default {
|
|
|
63
72
|
if (outgoingConnection) {
|
|
64
73
|
this.handshaker = new Handshaker_1.Handshaker(this.localPeerDescriptor, outgoingConnection);
|
|
65
74
|
this.handshaker.once('handshakeFailed', (error) => {
|
|
66
|
-
if (error === DhtRpc_1.HandshakeError.INVALID_TARGET_PEER_DESCRIPTOR) {
|
|
75
|
+
if (error === DhtRpc_1.HandshakeError.INVALID_TARGET_PEER_DESCRIPTOR || error === DhtRpc_1.HandshakeError.UNSUPPORTED_VERSION) {
|
|
76
|
+
// TODO should we have some handling for this floating promise?
|
|
67
77
|
this.close(false);
|
|
68
78
|
}
|
|
69
79
|
else {
|
|
@@ -87,9 +97,9 @@ class ManagedConnection extends eventemitter3_1.default {
|
|
|
87
97
|
else {
|
|
88
98
|
if (incomingConnection) {
|
|
89
99
|
this.handshaker = new Handshaker_1.Handshaker(this.localPeerDescriptor, incomingConnection);
|
|
90
|
-
this.handshaker.on('handshakeRequest', (sourcePeerDescriptor, targetPeerDescriptor) => {
|
|
100
|
+
this.handshaker.on('handshakeRequest', (sourcePeerDescriptor, version, targetPeerDescriptor) => {
|
|
91
101
|
this.setRemotePeerDescriptor(sourcePeerDescriptor);
|
|
92
|
-
this.emit('handshakeRequest', sourcePeerDescriptor, targetPeerDescriptor);
|
|
102
|
+
this.emit('handshakeRequest', sourcePeerDescriptor, version, targetPeerDescriptor);
|
|
93
103
|
});
|
|
94
104
|
incomingConnection.on('disconnected', this.onDisconnected);
|
|
95
105
|
}
|
|
@@ -129,8 +139,8 @@ class ManagedConnection extends eventemitter3_1.default {
|
|
|
129
139
|
}
|
|
130
140
|
return this;
|
|
131
141
|
}
|
|
132
|
-
|
|
133
|
-
return (0,
|
|
142
|
+
getNodeId() {
|
|
143
|
+
return (0, identifiers_1.getNodeIdFromPeerDescriptor)(this.remotePeerDescriptor);
|
|
134
144
|
}
|
|
135
145
|
getLastUsed() {
|
|
136
146
|
return this.lastUsed;
|
|
@@ -145,6 +155,7 @@ class ManagedConnection extends eventemitter3_1.default {
|
|
|
145
155
|
this.lastUsed = Date.now();
|
|
146
156
|
this.setRemotePeerDescriptor(peerDescriptor);
|
|
147
157
|
this.handshakeCompleted = true;
|
|
158
|
+
this.handshaker.stop();
|
|
148
159
|
while (this.outputBuffer.length > 0) {
|
|
149
160
|
logger.trace('emptying outputBuffer');
|
|
150
161
|
this.implementation.send(this.outputBuffer.shift());
|
|
@@ -185,7 +196,7 @@ class ManagedConnection extends eventemitter3_1.default {
|
|
|
185
196
|
this.outputBufferEmitter.emit('bufferSendingFailed');
|
|
186
197
|
this.emit('disconnected', gracefulLeave);
|
|
187
198
|
}
|
|
188
|
-
async send(data,
|
|
199
|
+
async send(data, connect) {
|
|
189
200
|
if (this.stopped) {
|
|
190
201
|
throw new Err.SendFailed('ManagedConnection is stopped');
|
|
191
202
|
}
|
|
@@ -193,8 +204,8 @@ class ManagedConnection extends eventemitter3_1.default {
|
|
|
193
204
|
throw new Err.SendFailed('ManagedConnection is closing');
|
|
194
205
|
}
|
|
195
206
|
this.lastUsed = Date.now();
|
|
196
|
-
if (
|
|
197
|
-
throw new Err.ConnectionNotOpen('Connection not open when calling send() with
|
|
207
|
+
if (!connect && !this.implementation) {
|
|
208
|
+
throw new Err.ConnectionNotOpen('Connection not open when calling send() with connect flag as false');
|
|
198
209
|
}
|
|
199
210
|
else if (this.implementation) {
|
|
200
211
|
this.implementation.send(data);
|
|
@@ -203,10 +214,15 @@ class ManagedConnection extends eventemitter3_1.default {
|
|
|
203
214
|
logger.trace('adding data to outputBuffer');
|
|
204
215
|
let result;
|
|
205
216
|
try {
|
|
206
|
-
result = await (0, utils_1.runAndRaceEvents3)([() => { this.outputBuffer.push(data); }], this.outputBufferEmitter, ['bufferSent', 'bufferSendingFailed'], 15000);
|
|
217
|
+
result = await (0, utils_1.runAndRaceEvents3)([() => { this.outputBuffer.push(data); }], this.outputBufferEmitter, ['bufferSent', 'bufferSendingFailed'], 15000); // TODO use config option or named constant?
|
|
207
218
|
}
|
|
208
219
|
catch (e) {
|
|
209
|
-
logger.debug(`Connection to ${(0, ConnectionManager_1.getNodeIdOrUnknownFromPeerDescriptor)(this.remotePeerDescriptor)} timed out
|
|
220
|
+
logger.debug(`Connection to ${(0, ConnectionManager_1.getNodeIdOrUnknownFromPeerDescriptor)(this.remotePeerDescriptor)} timed out`, {
|
|
221
|
+
peerDescriptor: this.remotePeerDescriptor,
|
|
222
|
+
type: this.connectionType,
|
|
223
|
+
lifetime: Date.now() - this.created
|
|
224
|
+
});
|
|
225
|
+
await this.close(false);
|
|
210
226
|
throw new Err.SendFailed('Sending buffer timed out');
|
|
211
227
|
}
|
|
212
228
|
if (result.winnerName === 'bufferSendingFailed') {
|
|
@@ -233,7 +249,6 @@ class ManagedConnection extends eventemitter3_1.default {
|
|
|
233
249
|
logger.trace('bufferSentByOtherConnection reported');
|
|
234
250
|
this.bufferSentbyOtherConnection = true;
|
|
235
251
|
this.outputBufferEmitter.emit('bufferSent');
|
|
236
|
-
this.emit('bufferSentByOtherConnection');
|
|
237
252
|
}
|
|
238
253
|
acceptHandshake() {
|
|
239
254
|
// This happens when connectionRequest has been made and answered
|
|
@@ -254,12 +269,14 @@ class ManagedConnection extends eventemitter3_1.default {
|
|
|
254
269
|
this.destroy();
|
|
255
270
|
}
|
|
256
271
|
async close(gracefulLeave) {
|
|
272
|
+
if (this.closing) {
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
257
275
|
if (this.replacedByOtherConnection) {
|
|
258
276
|
logger.trace('close() called on replaced connection');
|
|
259
277
|
}
|
|
260
278
|
this.closing = true;
|
|
261
279
|
this.outputBufferEmitter.emit('bufferSendingFailed');
|
|
262
|
-
this.emit('closing');
|
|
263
280
|
if (this.implementation) {
|
|
264
281
|
await this.implementation?.close(gracefulLeave);
|
|
265
282
|
}
|
|
@@ -275,7 +292,6 @@ class ManagedConnection extends eventemitter3_1.default {
|
|
|
275
292
|
}
|
|
276
293
|
destroy() {
|
|
277
294
|
this.closing = true;
|
|
278
|
-
this.emit('closing');
|
|
279
295
|
if (!this.stopped) {
|
|
280
296
|
this.stopped = true;
|
|
281
297
|
this.removeAllListeners();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ManagedConnection.js","sourceRoot":"","sources":["../../../src/connection/ManagedConnection.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
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IAAI,CAAC,cAAc,EAAE,OAAO,EAAE,CAAA;YAClC,CAAC;iBAAM,IAAI,IAAI,CAAC,kBAAkB,EAAE,CAAC;gBACjC,IAAI,CAAC,kBAAkB,EAAE,OAAO,EAAE,CAAA;YACtC,CAAC;iBAAM,IAAI,IAAI,CAAC,kBAAkB,EAAE,CAAC;gBACjC,IAAI,CAAC,kBAAkB,EAAE,OAAO,EAAE,CAAA;YACtC,CAAC;QACL,CAAC;IACL,CAAC;IAED,oBAAoB;QAChB,OAAO,IAAI,CAAC,kBAAkB,CAAA;IAClC,CAAC;IAED,iBAAiB;QACb,MAAM,GAAG,GAAG,IAAI,CAAC,YAAY,CAAA;QAC7B,IAAI,CAAC,YAAY,GAAG,EAAE,CAAA;QACtB,OAAO,GAAG,CAAA;IACd,CAAC;CACJ;AAvUD,8CAuUC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ManagedWebrtcConnection.js","sourceRoot":"","sources":["../../../src/connection/ManagedWebrtcConnection.ts"],"names":[],"mappings":";;;AACA,+CAA8C;AAC9C,2DAAuD;AAGvD,MAAa,uBAAwB,SAAQ,qCAAiB;IAE1D,YAAY,mBAAmC,EAC3C,oBAA2C,EAC3C,mBAA0C;QAE1C,KAAK,CACD,mBAAmB,EACnB,4BAAc,CAAC,MAAM,EACrB,oBAAoB,EACpB,mBAAmB,CACtB,CAAA;IACL,CAAC;IAEM,mBAAmB;QACtB,IAAI,IAAI,CAAC,kBAAkB,EAAE;
|
|
1
|
+
{"version":3,"file":"ManagedWebrtcConnection.js","sourceRoot":"","sources":["../../../src/connection/ManagedWebrtcConnection.ts"],"names":[],"mappings":";;;AACA,+CAA8C;AAC9C,2DAAuD;AAGvD,MAAa,uBAAwB,SAAQ,qCAAiB;IAE1D,YAAY,mBAAmC,EAC3C,oBAA2C,EAC3C,mBAA0C;QAE1C,KAAK,CACD,mBAAmB,EACnB,4BAAc,CAAC,MAAM,EACrB,oBAAoB,EACpB,mBAAmB,CACtB,CAAA;IACL,CAAC;IAEM,mBAAmB;QACtB,IAAI,IAAI,CAAC,kBAAkB,EAAE,CAAC;YAC1B,OAAO,IAAI,CAAC,kBAAqD,CAAA;QACrE,CAAC;aAAM,CAAC;YACJ,OAAO,IAAI,CAAC,kBAAqD,CAAA;QACrE,CAAC;IACL,CAAC;CACJ;AArBD,0DAqBC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ConnectivityRequest, ConnectivityResponse, PeerDescriptor } from '../proto/packages/dht/protos/DhtRpc';
|
|
2
|
+
import { IConnection } from './IConnection';
|
|
3
|
+
export declare const connectAsync: ({ url, selfSigned, timeoutMs }: {
|
|
4
|
+
url: string;
|
|
5
|
+
selfSigned: boolean;
|
|
6
|
+
timeoutMs?: number | undefined;
|
|
7
|
+
}) => Promise<IConnection>;
|
|
8
|
+
export declare const CONNECTIVITY_CHECKER_SERVICE_ID = "system/connectivity-checker";
|
|
9
|
+
export declare const sendConnectivityRequest: (request: ConnectivityRequest, entryPoint: PeerDescriptor) => Promise<ConnectivityResponse>;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.sendConnectivityRequest = exports.CONNECTIVITY_CHECKER_SERVICE_ID = exports.connectAsync = void 0;
|
|
27
|
+
const utils_1 = require("@streamr/utils");
|
|
28
|
+
const uuid_1 = require("uuid");
|
|
29
|
+
const Err = __importStar(require("../helpers/errors"));
|
|
30
|
+
const DhtRpc_1 = require("../proto/packages/dht/protos/DhtRpc");
|
|
31
|
+
const ClientWebsocket_1 = require("./websocket/ClientWebsocket");
|
|
32
|
+
const WebsocketConnector_1 = require("./websocket/WebsocketConnector");
|
|
33
|
+
const version_1 = require("../helpers/version");
|
|
34
|
+
const logger = new utils_1.Logger(module);
|
|
35
|
+
// TODO use config option or named constant?
|
|
36
|
+
const connectAsync = async ({ url, selfSigned, timeoutMs = 1000 }) => {
|
|
37
|
+
const socket = new ClientWebsocket_1.ClientWebsocket();
|
|
38
|
+
let result;
|
|
39
|
+
try {
|
|
40
|
+
result = await (0, utils_1.runAndRaceEvents3)([
|
|
41
|
+
() => { socket.connect(url, selfSigned); }
|
|
42
|
+
], socket, ['connected', 'error'], timeoutMs);
|
|
43
|
+
}
|
|
44
|
+
catch (e) {
|
|
45
|
+
throw new Err.ConnectionFailed('WebSocket connection timed out');
|
|
46
|
+
}
|
|
47
|
+
if (result.winnerName === 'error') {
|
|
48
|
+
throw new Err.ConnectionFailed('Could not open WebSocket connection');
|
|
49
|
+
}
|
|
50
|
+
return socket;
|
|
51
|
+
};
|
|
52
|
+
exports.connectAsync = connectAsync;
|
|
53
|
+
exports.CONNECTIVITY_CHECKER_SERVICE_ID = 'system/connectivity-checker';
|
|
54
|
+
const CONNECTIVITY_CHECKER_TIMEOUT = 5000;
|
|
55
|
+
const sendConnectivityRequest = async (request, entryPoint) => {
|
|
56
|
+
let outgoingConnection;
|
|
57
|
+
const wsServerInfo = {
|
|
58
|
+
host: entryPoint.websocket.host,
|
|
59
|
+
port: entryPoint.websocket.port,
|
|
60
|
+
tls: entryPoint.websocket.tls,
|
|
61
|
+
};
|
|
62
|
+
const url = (0, WebsocketConnector_1.connectivityMethodToWebsocketUrl)(wsServerInfo, 'connectivityRequest');
|
|
63
|
+
logger.debug(`Attempting connectivity check with entrypoint ${url}`);
|
|
64
|
+
try {
|
|
65
|
+
outgoingConnection = await (0, exports.connectAsync)({
|
|
66
|
+
url,
|
|
67
|
+
selfSigned: request.selfSigned
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
catch (e) {
|
|
71
|
+
throw new Err.ConnectionFailed(`Failed to connect to entrypoint for connectivity check: ${url}`, e);
|
|
72
|
+
}
|
|
73
|
+
// send connectivity request
|
|
74
|
+
const msg = {
|
|
75
|
+
serviceId: exports.CONNECTIVITY_CHECKER_SERVICE_ID,
|
|
76
|
+
messageId: (0, uuid_1.v4)(),
|
|
77
|
+
body: {
|
|
78
|
+
oneofKind: 'connectivityRequest',
|
|
79
|
+
connectivityRequest: request
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
const responseAwaiter = () => {
|
|
83
|
+
return new Promise((resolve, reject) => {
|
|
84
|
+
const timeoutId = setTimeout(() => {
|
|
85
|
+
// TODO should we have some handling for this floating promise?
|
|
86
|
+
outgoingConnection.close(false);
|
|
87
|
+
reject(new Err.ConnectivityResponseTimeout('timeout'));
|
|
88
|
+
}, CONNECTIVITY_CHECKER_TIMEOUT);
|
|
89
|
+
const listener = (bytes) => {
|
|
90
|
+
// TODO should we have some handling for this floating promise?
|
|
91
|
+
outgoingConnection.close(false);
|
|
92
|
+
try {
|
|
93
|
+
const message = DhtRpc_1.Message.fromBinary(bytes);
|
|
94
|
+
if (message.body.oneofKind === 'connectivityResponse') {
|
|
95
|
+
logger.debug('ConnectivityResponse received: ' + JSON.stringify(DhtRpc_1.Message.toJson(message)));
|
|
96
|
+
const connectivityResponseMessage = message.body.connectivityResponse;
|
|
97
|
+
const remoteVersion = connectivityResponseMessage.version;
|
|
98
|
+
outgoingConnection.off('data', listener);
|
|
99
|
+
clearTimeout(timeoutId);
|
|
100
|
+
if ((0, version_1.isMaybeSupportedVersion)(remoteVersion)) {
|
|
101
|
+
resolve(connectivityResponseMessage);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
reject(`Unsupported version: ${remoteVersion}`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
catch (err) {
|
|
112
|
+
logger.trace(`Could not parse message: ${err}`);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
outgoingConnection.on('data', listener);
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
try {
|
|
119
|
+
const retPromise = responseAwaiter();
|
|
120
|
+
outgoingConnection.send(DhtRpc_1.Message.toBinary(msg));
|
|
121
|
+
logger.trace('ConnectivityRequest sent: ' + JSON.stringify(DhtRpc_1.Message.toJson(msg)));
|
|
122
|
+
return await retPromise;
|
|
123
|
+
}
|
|
124
|
+
catch (e) {
|
|
125
|
+
logger.error('error getting connectivityresponse');
|
|
126
|
+
throw e;
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
exports.sendConnectivityRequest = sendConnectivityRequest;
|
|
130
|
+
//# sourceMappingURL=connectivityChecker.js.map
|