@streamr/dht 100.0.0-pretestnet.2 → 100.0.0-pretestnet.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/connection/ConnectionLockHandler.d.ts +7 -8
- package/dist/src/connection/ConnectionLockHandler.js +16 -14
- package/dist/src/connection/ConnectionLockHandler.js.map +1 -1
- package/dist/src/connection/ConnectionLockRpcLocal.d.ts +20 -0
- package/dist/src/connection/ConnectionLockRpcLocal.js +47 -0
- package/dist/src/connection/ConnectionLockRpcLocal.js.map +1 -0
- package/dist/src/connection/ConnectionLockRpcRemote.d.ts +4 -3
- package/dist/src/connection/ConnectionLockRpcRemote.js +9 -9
- package/dist/src/connection/ConnectionLockRpcRemote.js.map +1 -1
- package/dist/src/connection/ConnectionManager.d.ts +9 -16
- package/dist/src/connection/ConnectionManager.js +101 -132
- package/dist/src/connection/ConnectionManager.js.map +1 -1
- package/dist/src/connection/ConnectivityChecker.d.ts +7 -10
- package/dist/src/connection/ConnectivityChecker.js +30 -32
- package/dist/src/connection/ConnectivityChecker.js.map +1 -1
- package/dist/src/connection/ConnectorFacade.d.ts +19 -13
- package/dist/src/connection/ConnectorFacade.js +74 -29
- package/dist/src/connection/ConnectorFacade.js.map +1 -1
- package/dist/src/connection/Handshaker.d.ts +8 -8
- package/dist/src/connection/Handshaker.js +30 -33
- package/dist/src/connection/Handshaker.js.map +1 -1
- package/dist/src/connection/IConnection.d.ts +5 -6
- package/dist/src/connection/IConnection.js.map +1 -1
- package/dist/src/connection/ManagedConnection.d.ts +9 -13
- package/dist/src/connection/ManagedConnection.js +63 -99
- package/dist/src/connection/ManagedConnection.js.map +1 -1
- package/dist/src/connection/ManagedWebrtcConnection.d.ts +7 -0
- package/dist/src/connection/ManagedWebrtcConnection.js +20 -0
- package/dist/src/connection/ManagedWebrtcConnection.js.map +1 -0
- package/dist/src/connection/{Simulator → simulator}/Simulator.js +3 -3
- package/dist/src/connection/{Simulator → simulator}/Simulator.js.map +1 -1
- package/dist/src/connection/{Simulator → simulator}/SimulatorConnection.d.ts +3 -4
- package/dist/src/connection/{Simulator → simulator}/SimulatorConnection.js +25 -24
- package/dist/src/connection/simulator/SimulatorConnection.js.map +1 -0
- package/dist/src/connection/{Simulator → simulator}/SimulatorConnector.d.ts +3 -3
- package/dist/src/connection/{Simulator → simulator}/SimulatorConnector.js +17 -18
- package/dist/src/connection/simulator/SimulatorConnector.js.map +1 -0
- package/dist/src/connection/{Simulator → simulator}/SimulatorTransport.d.ts +1 -1
- package/dist/src/connection/{Simulator → simulator}/SimulatorTransport.js +2 -2
- package/dist/src/connection/simulator/SimulatorTransport.js.map +1 -0
- package/dist/src/connection/{Simulator → simulator}/pings.js.map +1 -1
- package/dist/src/connection/{WebRTC/IWebRtcConnection.d.ts → webrtc/IWebrtcConnection.d.ts} +2 -2
- package/dist/src/connection/{WebRTC/IWebRtcConnection.js → webrtc/IWebrtcConnection.js} +1 -1
- package/dist/src/connection/webrtc/IWebrtcConnection.js.map +1 -0
- package/dist/src/connection/{WebRTC/NodeWebRtcConnection.d.ts → webrtc/NodeWebrtcConnection.d.ts} +6 -7
- package/dist/src/connection/{WebRTC/NodeWebRtcConnection.js → webrtc/NodeWebrtcConnection.js} +41 -42
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js.map +1 -0
- package/dist/src/connection/webrtc/WebrtcConnector.d.ts +38 -0
- package/dist/src/connection/webrtc/WebrtcConnector.js +178 -0
- package/dist/src/connection/webrtc/WebrtcConnector.js.map +1 -0
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.d.ts +26 -0
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js +99 -0
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js.map +1 -0
- package/dist/src/connection/{WebRTC/WebRtcConnectorRpcRemote.d.ts → webrtc/WebrtcConnectorRpcRemote.d.ts} +4 -4
- package/dist/src/connection/{WebRTC/WebRtcConnectorRpcRemote.js → webrtc/WebrtcConnectorRpcRemote.js} +6 -8
- package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.js.map +1 -0
- package/dist/src/connection/{WebRTC → webrtc}/iceServerAsString.d.ts +1 -1
- package/dist/src/connection/{WebRTC → webrtc}/iceServerAsString.js.map +1 -1
- package/dist/src/connection/websocket/AutoCertifierClientFacade.d.ts +26 -0
- package/dist/src/connection/websocket/AutoCertifierClientFacade.js +37 -0
- package/dist/src/connection/websocket/AutoCertifierClientFacade.js.map +1 -0
- package/dist/src/connection/{WebSocket/ClientWebSocket.d.ts → websocket/ClientWebsocket.d.ts} +5 -4
- package/dist/src/connection/{WebSocket/ClientWebSocket.js → websocket/ClientWebsocket.js} +23 -16
- package/dist/src/connection/websocket/ClientWebsocket.js.map +1 -0
- package/dist/src/connection/{WebSocket/ServerWebSocket.d.ts → websocket/ServerWebsocket.d.ts} +2 -2
- package/dist/src/connection/{WebSocket/ServerWebSocket.js → websocket/ServerWebsocket.js} +25 -27
- package/dist/src/connection/websocket/ServerWebsocket.js.map +1 -0
- package/dist/src/connection/websocket/WebsocketConnector.d.ts +53 -0
- package/dist/src/connection/websocket/WebsocketConnector.js +242 -0
- package/dist/src/connection/websocket/WebsocketConnector.js.map +1 -0
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.d.ts +17 -0
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.js +26 -0
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.js.map +1 -0
- package/dist/src/connection/{WebSocket/WebSocketConnectorRpcRemote.d.ts → websocket/WebsocketConnectorRpcRemote.d.ts} +3 -3
- package/dist/src/connection/{WebSocket/WebSocketConnectorRpcRemote.js → websocket/WebsocketConnectorRpcRemote.js} +6 -11
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.js.map +1 -0
- package/dist/src/connection/{WebSocket/WebSocketServer.d.ts → websocket/WebsocketServer.d.ts} +6 -3
- package/dist/src/connection/{WebSocket/WebSocketServer.js → websocket/WebsocketServer.js} +39 -19
- package/dist/src/connection/websocket/WebsocketServer.js.map +1 -0
- package/dist/src/dht/DhtNode.d.ts +11 -19
- package/dist/src/dht/DhtNode.js +135 -163
- package/dist/src/dht/DhtNode.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcLocal.d.ts +22 -0
- package/dist/src/dht/DhtNodeRpcLocal.js +42 -0
- package/dist/src/dht/DhtNodeRpcLocal.js.map +1 -0
- package/dist/src/dht/{RemoteDhtNode.d.ts → DhtNodeRpcRemote.d.ts} +5 -3
- package/dist/src/dht/{RemoteDhtNode.js → DhtNodeRpcRemote.js} +20 -24
- package/dist/src/dht/DhtNodeRpcRemote.js.map +1 -0
- package/dist/src/dht/ExternalApiRpcLocal.d.ts +16 -0
- package/dist/src/dht/ExternalApiRpcLocal.js +30 -0
- package/dist/src/dht/ExternalApiRpcLocal.js.map +1 -0
- package/dist/src/dht/ExternalApiRpcRemote.d.ts +1 -1
- package/dist/src/dht/ExternalApiRpcRemote.js +2 -2
- package/dist/src/dht/ExternalApiRpcRemote.js.map +1 -1
- package/dist/src/dht/contact/Remote.d.ts +4 -1
- package/dist/src/dht/contact/Remote.js +28 -2
- package/dist/src/dht/contact/Remote.js.map +1 -1
- package/dist/src/dht/contact/SortedContactList.d.ts +2 -2
- package/dist/src/dht/contact/SortedContactList.js +3 -3
- package/dist/src/dht/contact/SortedContactList.js.map +1 -1
- package/dist/src/dht/discovery/DiscoverySession.d.ts +9 -7
- package/dist/src/dht/discovery/DiscoverySession.js +9 -9
- package/dist/src/dht/discovery/DiscoverySession.js.map +1 -1
- package/dist/src/dht/discovery/PeerDiscovery.d.ts +7 -10
- package/dist/src/dht/discovery/PeerDiscovery.js +6 -6
- package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -1
- package/dist/src/dht/find/FindRpcLocal.d.ts +14 -0
- package/dist/src/dht/find/FindRpcLocal.js +25 -0
- package/dist/src/dht/find/FindRpcLocal.js.map +1 -0
- package/dist/src/dht/find/{RecursiveFindSession.d.ts → FindSession.d.ts} +12 -13
- package/dist/src/dht/find/{RecursiveFindSession.js → FindSession.js} +17 -15
- package/dist/src/dht/find/FindSession.js.map +1 -0
- package/dist/src/dht/find/FindSessionRpcLocal.d.ts +12 -0
- package/dist/src/dht/find/FindSessionRpcLocal.js +17 -0
- package/dist/src/dht/find/FindSessionRpcLocal.js.map +1 -0
- package/dist/src/dht/find/{RemoteRecursiveFindSession.d.ts → FindSessionRpcRemote.d.ts} +2 -2
- package/dist/src/dht/find/{RemoteRecursiveFindSession.js → FindSessionRpcRemote.js} +5 -5
- package/dist/src/dht/find/FindSessionRpcRemote.js.map +1 -0
- package/dist/src/dht/find/{RecursiveFinder.d.ts → Finder.d.ts} +16 -19
- package/dist/src/dht/find/{RecursiveFinder.js → Finder.js} +50 -46
- package/dist/src/dht/find/Finder.js.map +1 -0
- package/dist/src/dht/routing/FindRpcRemote.d.ts +6 -0
- package/dist/src/dht/routing/FindRpcRemote.js +41 -0
- package/dist/src/dht/routing/FindRpcRemote.js.map +1 -0
- package/dist/src/dht/routing/Router.d.ts +10 -17
- package/dist/src/dht/routing/Router.js +50 -93
- package/dist/src/dht/routing/Router.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcLocal.d.ts +22 -0
- package/dist/src/dht/routing/RouterRpcLocal.js +66 -0
- package/dist/src/dht/routing/RouterRpcLocal.js.map +1 -0
- package/dist/src/dht/routing/RouterRpcRemote.d.ts +0 -1
- package/dist/src/dht/routing/RouterRpcRemote.js +17 -45
- package/dist/src/dht/routing/RouterRpcRemote.js.map +1 -1
- package/dist/src/dht/routing/RoutingSession.d.ts +17 -8
- package/dist/src/dht/routing/RoutingSession.js +124 -131
- package/dist/src/dht/routing/RoutingSession.js.map +1 -1
- package/dist/src/dht/routing/getPreviousPeer.d.ts +2 -0
- package/dist/src/dht/routing/getPreviousPeer.js +9 -0
- package/dist/src/dht/routing/getPreviousPeer.js.map +1 -0
- package/dist/src/dht/store/StoreRpcLocal.d.ts +11 -8
- package/dist/src/dht/store/StoreRpcLocal.js +26 -25
- package/dist/src/dht/store/StoreRpcLocal.js.map +1 -1
- package/dist/src/dht/store/StoreRpcRemote.js +6 -10
- package/dist/src/dht/store/StoreRpcRemote.js.map +1 -1
- package/dist/src/exports.d.ts +11 -5
- package/dist/src/exports.js +17 -4
- package/dist/src/exports.js.map +1 -1
- package/dist/src/helpers/Connectivity.d.ts +4 -0
- package/dist/src/helpers/Connectivity.js +24 -0
- package/dist/src/helpers/Connectivity.js.map +1 -0
- package/dist/src/helpers/errors.d.ts +3 -3
- package/dist/src/helpers/errors.js +7 -7
- package/dist/src/helpers/peerIdFromPeerDescriptor.d.ts +1 -0
- package/dist/src/helpers/peerIdFromPeerDescriptor.js +7 -1
- package/dist/src/helpers/peerIdFromPeerDescriptor.js.map +1 -1
- package/dist/src/helpers/protoClasses.js +3 -3
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +56 -39
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +49 -36
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +85 -96
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +82 -71
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +26 -21
- package/dist/src/rpc-protocol/DhtCallContext.d.ts +0 -1
- package/dist/src/rpc-protocol/DhtCallContext.js.map +1 -1
- package/dist/src/transport/ITransport.d.ts +5 -6
- package/dist/src/transport/ListeningRpcCommunicator.d.ts +2 -1
- package/dist/src/transport/ListeningRpcCommunicator.js.map +1 -1
- package/dist/src/transport/RoutingRpcCommunicator.d.ts +2 -1
- package/dist/src/transport/RoutingRpcCommunicator.js +0 -1
- package/dist/src/transport/RoutingRpcCommunicator.js.map +1 -1
- package/dist/src/types/ServiceID.d.ts +1 -0
- package/dist/src/types/ServiceID.js +3 -0
- package/dist/src/types/ServiceID.js.map +1 -0
- package/karma.config.js +4 -4
- package/package.json +10 -8
- package/protos/DhtRpc.proto +41 -40
- package/src/connection/ConnectionLockHandler.ts +19 -17
- package/src/connection/ConnectionLockRpcLocal.ts +74 -0
- package/src/connection/ConnectionLockRpcRemote.ts +11 -11
- package/src/connection/ConnectionManager.ts +88 -130
- package/src/connection/ConnectivityChecker.ts +36 -34
- package/src/connection/ConnectorFacade.ts +91 -40
- package/src/connection/Handshaker.ts +20 -23
- package/src/connection/IConnection.ts +5 -6
- package/src/connection/ManagedConnection.ts +76 -101
- package/src/connection/{ManagedWebRtcConnection.ts → ManagedWebrtcConnection.ts} +12 -10
- package/src/connection/{Simulator → simulator}/Simulator.ts +4 -4
- package/src/connection/{Simulator → simulator}/SimulatorConnection.ts +27 -27
- package/src/connection/{Simulator → simulator}/SimulatorConnector.ts +22 -23
- package/src/connection/{Simulator → simulator}/SimulatorTransport.ts +2 -2
- package/src/connection/{WebRTC/BrowserWebRtcConnection.ts → webrtc/BrowserWebrtcConnection.ts} +13 -14
- package/src/connection/{WebRTC/IWebRtcConnection.ts → webrtc/IWebrtcConnection.ts} +2 -2
- package/src/connection/{WebRTC/NodeWebRtcConnection.ts → webrtc/NodeWebrtcConnection.ts} +38 -40
- package/src/connection/webrtc/WebrtcConnector.ts +226 -0
- package/src/connection/webrtc/WebrtcConnectorRpcLocal.ts +132 -0
- package/src/connection/{WebRTC/WebRtcConnectorRpcRemote.ts → webrtc/WebrtcConnectorRpcRemote.ts} +6 -7
- package/src/connection/{WebRTC → webrtc}/iceServerAsString.ts +1 -1
- package/src/connection/websocket/AutoCertifierClientFacade.ts +91 -0
- package/src/connection/{WebSocket/ClientWebSocket.ts → websocket/ClientWebsocket.ts} +22 -17
- package/src/connection/{WebSocket/ServerWebSocket.ts → websocket/ServerWebsocket.ts} +23 -27
- package/src/connection/websocket/WebsocketConnector.ts +328 -0
- package/src/connection/websocket/WebsocketConnectorRpcLocal.ts +41 -0
- package/src/connection/{WebSocket/WebSocketConnectorRpcRemote.ts → websocket/WebsocketConnectorRpcRemote.ts} +8 -14
- package/src/connection/{WebSocket/WebSocketServer.ts → websocket/WebsocketServer.ts} +40 -22
- package/src/dht/DhtNode.ts +166 -193
- package/src/dht/DhtNodeRpcLocal.ts +68 -0
- package/src/dht/{RemoteDhtNode.ts → DhtNodeRpcRemote.ts} +17 -18
- package/src/dht/ExternalApiRpcLocal.ts +46 -0
- package/src/dht/ExternalApiRpcRemote.ts +4 -4
- package/src/dht/contact/Remote.ts +32 -4
- package/src/dht/contact/SortedContactList.ts +4 -4
- package/src/dht/discovery/DiscoverySession.ts +25 -22
- package/src/dht/discovery/PeerDiscovery.ts +16 -19
- package/src/dht/find/FindRpcLocal.ts +35 -0
- package/src/dht/find/{RecursiveFindSession.ts → FindSession.ts} +25 -25
- package/src/dht/find/FindSessionRpcLocal.ts +25 -0
- package/src/dht/find/{RemoteRecursiveFindSession.ts → FindSessionRpcRemote.ts} +9 -5
- package/src/dht/find/{RecursiveFinder.ts → Finder.ts} +77 -71
- package/src/dht/routing/FindRpcRemote.ts +40 -0
- package/src/dht/routing/Router.ts +78 -109
- package/src/dht/routing/RouterRpcLocal.ts +81 -0
- package/src/dht/routing/RouterRpcRemote.ts +18 -49
- package/src/dht/routing/RoutingSession.ts +58 -63
- package/src/dht/routing/getPreviousPeer.ts +6 -0
- package/src/dht/store/StoreRpcLocal.ts +46 -39
- package/src/dht/store/StoreRpcRemote.ts +8 -12
- package/src/exports.ts +11 -5
- package/src/helpers/Connectivity.ts +19 -0
- package/src/helpers/errors.ts +3 -3
- package/src/helpers/peerIdFromPeerDescriptor.ts +6 -0
- package/src/helpers/protoClasses.ts +6 -6
- package/src/proto/packages/dht/protos/DhtRpc.client.ts +75 -59
- package/src/proto/packages/dht/protos/DhtRpc.server.ts +26 -21
- package/src/proto/packages/dht/protos/DhtRpc.ts +112 -131
- package/src/rpc-protocol/DhtCallContext.ts +0 -1
- package/src/transport/ITransport.ts +5 -8
- package/src/transport/ListeningRpcCommunicator.ts +2 -1
- package/src/transport/RoutingRpcCommunicator.ts +3 -4
- package/src/types/ServiceID.ts +1 -0
- package/test/benchmark/{RecursiveFind.test.ts → Find.test.ts} +7 -7
- package/test/benchmark/KademliaCorrectness.test.ts +3 -3
- package/test/benchmark/kademlia-simulation/SimulationNode.ts +3 -3
- package/test/end-to-end/Layer0-Layer1.test.ts +13 -5
- package/test/end-to-end/Layer0.test.ts +35 -17
- package/test/end-to-end/Layer0MixedConnectionTypes.test.ts +28 -9
- package/test/end-to-end/{Layer0WebRTC-Layer1.test.ts → Layer0Webrtc-Layer1.test.ts} +1 -1
- package/test/end-to-end/{Layer0WebRTC.test.ts → Layer0Webrtc.test.ts} +14 -10
- package/test/end-to-end/Layer1-Scale-WebSocket.test.ts +8 -4
- package/test/end-to-end/{Layer1-Scale-WebRTC.test.ts → Layer1-Scale-Webrtc.test.ts} +2 -2
- package/test/end-to-end/RecoveryFromFailedAutoCertification.test.ts +52 -0
- package/test/end-to-end/{WebSocketConnectionRequest.test.ts → WebsocketConnectionRequest.test.ts} +16 -8
- package/test/end-to-end/memory-leak.test.ts +85 -0
- package/test/integration/ConnectionLocking.test.ts +10 -7
- package/test/integration/ConnectionManager.test.ts +107 -30
- package/test/integration/DhtJoinPeerDiscovery.test.ts +2 -2
- package/test/integration/DhtNodeExternalAPI.test.ts +10 -10
- package/test/integration/{RemoteDhtNode.test.ts → DhtNodeRpcRemote.test.ts} +10 -10
- package/test/integration/DhtRpc.test.ts +5 -5
- package/test/integration/{RecursiveFind.test.ts → Find.test.ts} +6 -9
- package/test/integration/Layer1-scale.test.ts +1 -1
- package/test/integration/MigrateData.test.ts +8 -7
- package/test/integration/Mock-Layer1-Layer0.test.ts +1 -1
- package/test/integration/MultipleEntryPointJoining.test.ts +8 -8
- package/test/integration/RouteMessage.test.ts +26 -26
- package/test/integration/RpcErrors.test.ts +10 -10
- package/test/integration/ScaleDownDht.test.ts +6 -6
- package/test/integration/SimultaneousConnections.test.ts +10 -7
- package/test/integration/Store.test.ts +4 -7
- package/test/integration/StoreAndDelete.test.ts +4 -7
- package/test/integration/StoreOnDhtWithTwoNodes.test.ts +12 -12
- package/test/integration/{WebRtcConnectionManagement.test.ts → WebrtcConnectionManagement.test.ts} +5 -5
- package/test/integration/{WebRtcConnectorRpc.test.ts → WebrtcConnectorRpc.test.ts} +7 -8
- package/test/integration/{WebSocket.test.ts → Websocket.test.ts} +14 -13
- package/test/integration/{WebSocketConnectionManagement.test.ts → WebsocketConnectionManagement.test.ts} +4 -4
- package/test/integration/{WebSocketConnectorRpc.test.ts → WebsocketConnectorRpc.test.ts} +15 -15
- package/test/unit/AutoCertifierClientFacade.test.ts +58 -0
- package/test/unit/ConnectivityHelpers.test.ts +69 -0
- package/test/unit/{RecursiveFinder.test.ts → Finder.test.ts} +19 -17
- package/test/unit/Router.test.ts +26 -26
- package/test/unit/UUID.test.ts +1 -1
- package/test/unit/{WebSocketConnectorRpcLocal.test.ts → WebsocketConnector.test.ts} +8 -8
- package/test/unit/{WebSocketServer.test.ts → WebsocketServer.test.ts} +20 -14
- package/test/unit/webrtcReplaceInternalIpWithExternalIp.test.ts +1 -1
- package/test/utils/FakeRpcCommunicator.ts +23 -0
- package/test/utils/mock/Transport.ts +1 -1
- package/test/utils/utils.ts +22 -26
- package/tsconfig.browser.json +1 -1
- package/tsconfig.jest.json +3 -2
- package/tsconfig.node.json +3 -2
- package/dist/src/connection/ManagedWebRtcConnection.d.ts +0 -7
- package/dist/src/connection/ManagedWebRtcConnection.js +0 -20
- package/dist/src/connection/ManagedWebRtcConnection.js.map +0 -1
- package/dist/src/connection/Simulator/SimulatorConnection.js.map +0 -1
- package/dist/src/connection/Simulator/SimulatorConnector.js.map +0 -1
- package/dist/src/connection/Simulator/SimulatorTransport.js.map +0 -1
- package/dist/src/connection/WebRTC/IWebRtcConnection.js.map +0 -1
- package/dist/src/connection/WebRTC/NodeWebRtcConnection.js.map +0 -1
- package/dist/src/connection/WebRTC/WebRtcConnectorRpcLocal.d.ts +0 -51
- package/dist/src/connection/WebRTC/WebRtcConnectorRpcLocal.js +0 -249
- package/dist/src/connection/WebRTC/WebRtcConnectorRpcLocal.js.map +0 -1
- package/dist/src/connection/WebRTC/WebRtcConnectorRpcRemote.js.map +0 -1
- package/dist/src/connection/WebSocket/ClientWebSocket.js.map +0 -1
- package/dist/src/connection/WebSocket/ServerWebSocket.js.map +0 -1
- package/dist/src/connection/WebSocket/WebSocketConnectorRpcLocal.d.ts +0 -45
- package/dist/src/connection/WebSocket/WebSocketConnectorRpcLocal.js +0 -234
- package/dist/src/connection/WebSocket/WebSocketConnectorRpcLocal.js.map +0 -1
- package/dist/src/connection/WebSocket/WebSocketConnectorRpcRemote.js.map +0 -1
- package/dist/src/connection/WebSocket/WebSocketServer.js.map +0 -1
- package/dist/src/dht/RemoteDhtNode.js.map +0 -1
- package/dist/src/dht/find/RecursiveFindSession.js.map +0 -1
- package/dist/src/dht/find/RecursiveFinder.js.map +0 -1
- package/dist/src/dht/find/RemoteRecursiveFindSession.js.map +0 -1
- package/dist/src/dht/registerExternalApiRpcMethods.d.ts +0 -2
- package/dist/src/dht/registerExternalApiRpcMethods.js +0 -32
- package/dist/src/dht/registerExternalApiRpcMethods.js.map +0 -1
- package/src/connection/WebRTC/WebRtcConnectorRpcLocal.ts +0 -335
- package/src/connection/WebSocket/WebSocketConnectorRpcLocal.ts +0 -295
- package/src/dht/registerExternalApiRpcMethods.ts +0 -44
- package/test/utils/mock/RecursiveFinder.ts +0 -19
- /package/dist/src/connection/{Simulator → simulator}/Simulator.d.ts +0 -0
- /package/dist/src/connection/{Simulator → simulator}/pings.d.ts +0 -0
- /package/dist/src/connection/{Simulator → simulator}/pings.js +0 -0
- /package/dist/src/connection/{WebRTC → webrtc}/iceServerAsString.js +0 -0
- /package/src/connection/{Simulator → simulator}/pings.ts +0 -0
|
@@ -23,50 +23,47 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.ConnectivityChecker =
|
|
26
|
+
exports.ConnectivityChecker = void 0;
|
|
27
27
|
const DhtRpc_1 = require("../proto/packages/dht/protos/DhtRpc");
|
|
28
28
|
const utils_1 = require("@streamr/utils");
|
|
29
29
|
const Err = __importStar(require("../helpers/errors"));
|
|
30
|
-
const
|
|
30
|
+
const ClientWebsocket_1 = require("./websocket/ClientWebsocket");
|
|
31
31
|
const uuid_1 = require("uuid");
|
|
32
32
|
const ConnectionManager_1 = require("./ConnectionManager");
|
|
33
|
-
const
|
|
33
|
+
const WebsocketConnector_1 = require("./websocket/WebsocketConnector");
|
|
34
34
|
const logger = new utils_1.Logger(module);
|
|
35
35
|
// Class for handling both client and server side of the connectivity
|
|
36
|
-
// checks. This is attached to all
|
|
36
|
+
// checks. This is attached to all ServerWebsockets to listen to
|
|
37
37
|
// ConnectivityRequest messages.
|
|
38
|
-
var ConnectionMode;
|
|
39
|
-
(function (ConnectionMode) {
|
|
40
|
-
ConnectionMode["REQUEST"] = "connectivityRequest";
|
|
41
|
-
ConnectionMode["PROBE"] = "connectivityProbe";
|
|
42
|
-
})(ConnectionMode || (exports.ConnectionMode = ConnectionMode = {}));
|
|
43
38
|
class ConnectivityChecker {
|
|
44
|
-
constructor(
|
|
39
|
+
constructor(websocketPort, tls, host) {
|
|
45
40
|
this.destroyed = false;
|
|
46
|
-
this.
|
|
41
|
+
this.websocketPort = websocketPort;
|
|
47
42
|
this.tls = tls;
|
|
48
43
|
this.host = host;
|
|
49
44
|
}
|
|
50
|
-
async sendConnectivityRequest(entryPoint) {
|
|
45
|
+
async sendConnectivityRequest(entryPoint, selfSigned) {
|
|
51
46
|
if (this.destroyed) {
|
|
52
47
|
throw new Err.ConnectionFailed('ConnectivityChecker is destroyed');
|
|
53
48
|
}
|
|
54
49
|
let outgoingConnection;
|
|
50
|
+
const wsServerInfo = {
|
|
51
|
+
host: entryPoint.websocket.host,
|
|
52
|
+
port: entryPoint.websocket.port,
|
|
53
|
+
tls: entryPoint.websocket.tls,
|
|
54
|
+
};
|
|
55
|
+
const url = (0, WebsocketConnector_1.connectivityMethodToWebsocketUrl)(wsServerInfo, 'connectivityRequest');
|
|
55
56
|
try {
|
|
56
57
|
outgoingConnection = await this.connectAsync({
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
port: entryPoint.websocket.port,
|
|
60
|
-
tls: entryPoint.websocket.tls,
|
|
61
|
-
},
|
|
62
|
-
mode: ConnectionMode.REQUEST
|
|
58
|
+
url,
|
|
59
|
+
selfSigned
|
|
63
60
|
});
|
|
64
61
|
}
|
|
65
62
|
catch (e) {
|
|
66
|
-
throw new Err.ConnectionFailed(`Failed to connect to the entrypoint ${
|
|
63
|
+
throw new Err.ConnectionFailed(`Failed to connect to the entrypoint ${url}`, e);
|
|
67
64
|
}
|
|
68
65
|
// send connectivity request
|
|
69
|
-
const connectivityRequestMessage = { port: this.
|
|
66
|
+
const connectivityRequestMessage = { port: this.websocketPort, host: this.host, tls: this.tls, selfSigned };
|
|
70
67
|
const msg = {
|
|
71
68
|
serviceId: ConnectivityChecker.CONNECTIVITY_CHECKER_SERVICE_ID,
|
|
72
69
|
messageType: DhtRpc_1.MessageType.CONNECTIVITY_REQUEST, messageId: (0, uuid_1.v4)(),
|
|
@@ -78,11 +75,11 @@ class ConnectivityChecker {
|
|
|
78
75
|
const responseAwaiter = () => {
|
|
79
76
|
return new Promise((resolve, reject) => {
|
|
80
77
|
const timeoutId = setTimeout(() => {
|
|
81
|
-
outgoingConnection.close(
|
|
78
|
+
outgoingConnection.close(false);
|
|
82
79
|
reject(new Err.ConnectivityResponseTimeout('timeout'));
|
|
83
80
|
}, ConnectivityChecker.CONNECTIVITY_CHECKER_TIMEOUT);
|
|
84
81
|
const listener = (bytes) => {
|
|
85
|
-
outgoingConnection.close(
|
|
82
|
+
outgoingConnection.close(false);
|
|
86
83
|
try {
|
|
87
84
|
const message = DhtRpc_1.Message.fromBinary(bytes);
|
|
88
85
|
if (message.body.oneofKind === 'connectivityResponse') {
|
|
@@ -114,6 +111,9 @@ class ConnectivityChecker {
|
|
|
114
111
|
throw e;
|
|
115
112
|
}
|
|
116
113
|
}
|
|
114
|
+
setHost(hostName) {
|
|
115
|
+
this.host = hostName;
|
|
116
|
+
}
|
|
117
117
|
listenToIncomingConnectivityRequests(connectionToListenTo) {
|
|
118
118
|
connectionToListenTo.on('data', (data) => {
|
|
119
119
|
logger.trace('server received data');
|
|
@@ -147,25 +147,24 @@ class ConnectivityChecker {
|
|
|
147
147
|
port: connectivityRequest.port,
|
|
148
148
|
tls: connectivityRequest.tls
|
|
149
149
|
};
|
|
150
|
-
|
|
150
|
+
const url = (0, WebsocketConnector_1.connectivityMethodToWebsocketUrl)(wsServerInfo, 'connectivityProbe');
|
|
151
|
+
logger.trace(`Attempting Connectivity Check to ${url}`);
|
|
151
152
|
outgoingConnection = await this.connectAsync({
|
|
152
|
-
|
|
153
|
-
|
|
153
|
+
url,
|
|
154
|
+
selfSigned: connectivityRequest.selfSigned
|
|
154
155
|
});
|
|
155
156
|
}
|
|
156
157
|
catch (err) {
|
|
157
158
|
logger.debug('error', { err });
|
|
158
159
|
connectivityResponseMessage = {
|
|
159
|
-
openInternet: false,
|
|
160
160
|
host,
|
|
161
161
|
natType: ConnectionManager_1.NatType.UNKNOWN
|
|
162
162
|
};
|
|
163
163
|
}
|
|
164
164
|
if (outgoingConnection) {
|
|
165
|
-
outgoingConnection.close(
|
|
165
|
+
outgoingConnection.close(false);
|
|
166
166
|
logger.trace('Connectivity test produced positive result, communicating reply to the requester ' + host + ':' + connectivityRequest.port);
|
|
167
167
|
connectivityResponseMessage = {
|
|
168
|
-
openInternet: true,
|
|
169
168
|
host,
|
|
170
169
|
natType: ConnectionManager_1.NatType.OPEN_INTERNET,
|
|
171
170
|
websocket: { host, port: connectivityRequest.port, tls: connectivityRequest.tls }
|
|
@@ -183,13 +182,12 @@ class ConnectivityChecker {
|
|
|
183
182
|
logger.trace('ConnectivityResponse sent: ' + JSON.stringify(DhtRpc_1.Message.toJson(msg)));
|
|
184
183
|
}
|
|
185
184
|
// eslint-disable-next-line class-methods-use-this
|
|
186
|
-
async connectAsync({
|
|
187
|
-
const socket = new
|
|
188
|
-
const url = `${(0, WebSocketConnectorRpcLocal_1.connectivityMethodToWebSocketUrl)(wsServerInfo)}?${mode}=true`;
|
|
185
|
+
async connectAsync({ url, selfSigned, timeoutMs = 1000, }) {
|
|
186
|
+
const socket = new ClientWebsocket_1.ClientWebsocket();
|
|
189
187
|
let result;
|
|
190
188
|
try {
|
|
191
189
|
result = await (0, utils_1.runAndRaceEvents3)([
|
|
192
|
-
() => { socket.connect(url); }
|
|
190
|
+
() => { socket.connect(url, selfSigned); }
|
|
193
191
|
], socket, ['connected', 'error'], timeoutMs);
|
|
194
192
|
}
|
|
195
193
|
catch (e) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConnectivityChecker.js","sourceRoot":"","sources":["../../../src/connection/ConnectivityChecker.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"ConnectivityChecker.js","sourceRoot":"","sources":["../../../src/connection/ConnectivityChecker.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gEAG4C;AAE5C,0CAAsF;AACtF,uDAAwC;AACxC,iEAA6D;AAC7D,+BAAyB;AACzB,2DAA6C;AAE7C,uEAAiF;AAEjF,MAAM,MAAM,GAAG,IAAI,cAAM,CAAC,MAAM,CAAC,CAAA;AAEjC,qEAAqE;AACrE,gEAAgE;AAChE,iCAAiC;AAEjC,MAAa,mBAAmB;IAS5B,YAAY,aAAqB,EAAE,GAAY,EAAE,IAAa;QALtD,cAAS,GAAG,KAAK,CAAA;QAMrB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAA;QAClC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IACp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P,CAAO"}
|
|
@@ -2,12 +2,13 @@ import { ConnectivityResponse, PeerDescriptor } from '../proto/packages/dht/prot
|
|
|
2
2
|
import { ITransport } from '../transport/ITransport';
|
|
3
3
|
import { PortRange, TlsCertificate } from './ConnectionManager';
|
|
4
4
|
import { ManagedConnection } from './ManagedConnection';
|
|
5
|
-
import { Simulator } from './
|
|
6
|
-
import { IceServer } from './
|
|
5
|
+
import { Simulator } from './simulator/Simulator';
|
|
6
|
+
import { IceServer } from './webrtc/WebrtcConnector';
|
|
7
|
+
import { WebsocketConnectorConfig } from './websocket/WebsocketConnector';
|
|
7
8
|
export interface ConnectorFacade {
|
|
8
9
|
createConnection: (peerDescriptor: PeerDescriptor) => ManagedConnection;
|
|
9
|
-
|
|
10
|
-
start: (
|
|
10
|
+
getLocalPeerDescriptor: () => PeerDescriptor | undefined;
|
|
11
|
+
start: (onNewConnection: (connection: ManagedConnection) => boolean, canConnect: (peerDescriptor: PeerDescriptor) => boolean, autoCertifierTransport: ITransport) => Promise<void>;
|
|
11
12
|
stop: () => Promise<void>;
|
|
12
13
|
}
|
|
13
14
|
export interface DefaultConnectorFacadeConfig {
|
|
@@ -24,26 +25,31 @@ export interface DefaultConnectorFacadeConfig {
|
|
|
24
25
|
webrtcPortRange?: PortRange;
|
|
25
26
|
maxMessageSize?: number;
|
|
26
27
|
tlsCertificate?: TlsCertificate;
|
|
27
|
-
|
|
28
|
+
websocketServerEnableTls?: boolean;
|
|
29
|
+
autoCertifierUrl?: string;
|
|
30
|
+
autoCertifierConfigFile?: string;
|
|
31
|
+
createLocalPeerDescriptor: (connectivityResponse: ConnectivityResponse) => PeerDescriptor;
|
|
28
32
|
}
|
|
29
33
|
export declare class DefaultConnectorFacade implements ConnectorFacade {
|
|
30
34
|
private readonly config;
|
|
31
|
-
private
|
|
32
|
-
private
|
|
35
|
+
private localPeerDescriptor?;
|
|
36
|
+
private websocketConnector?;
|
|
33
37
|
private webrtcConnector?;
|
|
34
38
|
constructor(config: DefaultConnectorFacadeConfig);
|
|
35
|
-
start(
|
|
39
|
+
start(onNewConnection: (connection: ManagedConnection) => boolean, canConnect: (peerDescriptor: PeerDescriptor) => boolean, autoCertifierTransport: ITransport): Promise<void>;
|
|
40
|
+
private setLocalPeerDescriptor;
|
|
41
|
+
restartWebsocketConnector(webSocketConnectorConfig: WebsocketConnectorConfig): Promise<void>;
|
|
36
42
|
createConnection(peerDescriptor: PeerDescriptor): ManagedConnection;
|
|
37
|
-
|
|
43
|
+
getLocalPeerDescriptor(): PeerDescriptor | undefined;
|
|
38
44
|
stop(): Promise<void>;
|
|
39
45
|
}
|
|
40
46
|
export declare class SimulatorConnectorFacade implements ConnectorFacade {
|
|
41
|
-
private readonly
|
|
47
|
+
private readonly localPeerDescriptor;
|
|
42
48
|
private simulatorConnector?;
|
|
43
49
|
private simulator;
|
|
44
|
-
constructor(
|
|
45
|
-
start(
|
|
50
|
+
constructor(localPeerDescriptor: PeerDescriptor, simulator: Simulator);
|
|
51
|
+
start(onNewConnection: (connection: ManagedConnection) => boolean): Promise<void>;
|
|
46
52
|
createConnection(peerDescriptor: PeerDescriptor): ManagedConnection;
|
|
47
|
-
|
|
53
|
+
getLocalPeerDescriptor(): PeerDescriptor;
|
|
48
54
|
stop(): Promise<void>;
|
|
49
55
|
}
|
|
@@ -2,29 +2,34 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SimulatorConnectorFacade = exports.DefaultConnectorFacade = void 0;
|
|
4
4
|
const utils_1 = require("@streamr/utils");
|
|
5
|
-
const SimulatorConnector_1 = require("./
|
|
6
|
-
const
|
|
7
|
-
const
|
|
5
|
+
const SimulatorConnector_1 = require("./simulator/SimulatorConnector");
|
|
6
|
+
const WebrtcConnector_1 = require("./webrtc/WebrtcConnector");
|
|
7
|
+
const WebsocketConnector_1 = require("./websocket/WebsocketConnector");
|
|
8
8
|
const logger = new utils_1.Logger(module);
|
|
9
9
|
class DefaultConnectorFacade {
|
|
10
10
|
constructor(config) {
|
|
11
11
|
this.config = config;
|
|
12
12
|
}
|
|
13
|
-
async start(
|
|
14
|
-
logger.trace(`Creating
|
|
15
|
-
|
|
13
|
+
async start(onNewConnection, canConnect, autoCertifierTransport) {
|
|
14
|
+
logger.trace(`Creating WebsocketConnectorRpcLocal`);
|
|
15
|
+
const webSocketConnectorConfig = {
|
|
16
16
|
transport: this.config.transport,
|
|
17
|
-
// TODO should we use canConnect also for
|
|
17
|
+
// TODO should we use canConnect also for WebrtcConnector? (NET-1142)
|
|
18
18
|
canConnect: (peerDescriptor) => canConnect(peerDescriptor),
|
|
19
|
-
|
|
19
|
+
onNewConnection,
|
|
20
20
|
portRange: this.config.websocketPortRange,
|
|
21
21
|
host: this.config.websocketHost,
|
|
22
22
|
entrypoints: this.config.entryPoints,
|
|
23
23
|
tlsCertificate: this.config.tlsCertificate,
|
|
24
|
+
serverEnableTls: this.config.websocketServerEnableTls,
|
|
25
|
+
autoCertifierUrl: this.config.autoCertifierUrl,
|
|
26
|
+
autoCertifierConfigFile: this.config.autoCertifierConfigFile,
|
|
27
|
+
autoCertifierTransport,
|
|
24
28
|
maxMessageSize: this.config.maxMessageSize
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
29
|
+
};
|
|
30
|
+
this.websocketConnector = new WebsocketConnector_1.WebsocketConnector(webSocketConnectorConfig);
|
|
31
|
+
logger.trace(`Creating WebRtcConnectorRpcLocal`);
|
|
32
|
+
this.webrtcConnector = new WebrtcConnector_1.WebrtcConnector({
|
|
28
33
|
transport: this.config.transport,
|
|
29
34
|
iceServers: this.config.iceServers,
|
|
30
35
|
allowPrivateAddresses: this.config.webrtcAllowPrivateAddresses,
|
|
@@ -34,46 +39,86 @@ class DefaultConnectorFacade {
|
|
|
34
39
|
externalIp: this.config.externalIp,
|
|
35
40
|
portRange: this.config.webrtcPortRange,
|
|
36
41
|
maxMessageSize: this.config.maxMessageSize
|
|
37
|
-
},
|
|
38
|
-
await this.
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
this.
|
|
42
|
+
}, onNewConnection);
|
|
43
|
+
await this.websocketConnector.start();
|
|
44
|
+
// TODO: generate a PeerDescriptor in a single function. Requires changes to the createOwnPeerDescriptor
|
|
45
|
+
// function in the config. Currently it's given by the DhtNode and it sets the PeerDescriptor for the
|
|
46
|
+
// DhtNode in each call.
|
|
47
|
+
// LocalPeerDescriptor could be stored in one place and passed from there to the connectors
|
|
48
|
+
const temporarilySelfSigned = (!this.config.tlsCertificate && this.config.websocketServerEnableTls === true);
|
|
49
|
+
const connectivityResponse = await this.websocketConnector.checkConnectivity(temporarilySelfSigned);
|
|
50
|
+
const localPeerDescriptor = this.config.createLocalPeerDescriptor(connectivityResponse);
|
|
51
|
+
this.setLocalPeerDescriptor(localPeerDescriptor);
|
|
52
|
+
if (localPeerDescriptor.websocket && !this.config.tlsCertificate && this.config.websocketServerEnableTls) {
|
|
53
|
+
try {
|
|
54
|
+
await this.websocketConnector.autoCertify();
|
|
55
|
+
const connectivityResponse = await this.websocketConnector.checkConnectivity(false);
|
|
56
|
+
const autocertifiedLocalPeerDescriptor = this.config.createLocalPeerDescriptor(connectivityResponse);
|
|
57
|
+
if (autocertifiedLocalPeerDescriptor.websocket !== undefined) {
|
|
58
|
+
this.setLocalPeerDescriptor(autocertifiedLocalPeerDescriptor);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
logger.warn('Connectivity check failed after auto-certification, disabling WebSocket server TLS');
|
|
62
|
+
await this.restartWebsocketConnector({
|
|
63
|
+
...webSocketConnectorConfig,
|
|
64
|
+
serverEnableTls: false
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
catch (err) {
|
|
69
|
+
logger.warn('Failed to auto-certify, disabling WebSocket server TLS');
|
|
70
|
+
await this.restartWebsocketConnector({
|
|
71
|
+
...webSocketConnectorConfig,
|
|
72
|
+
serverEnableTls: false
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
setLocalPeerDescriptor(peerDescriptor) {
|
|
78
|
+
this.localPeerDescriptor = peerDescriptor;
|
|
79
|
+
this.websocketConnector.setLocalPeerDescriptor(peerDescriptor);
|
|
80
|
+
this.webrtcConnector.setLocalPeerDescriptor(peerDescriptor);
|
|
81
|
+
}
|
|
82
|
+
async restartWebsocketConnector(webSocketConnectorConfig) {
|
|
83
|
+
await this.websocketConnector.destroy();
|
|
84
|
+
this.websocketConnector = new WebsocketConnector_1.WebsocketConnector(webSocketConnectorConfig);
|
|
85
|
+
await this.websocketConnector.start();
|
|
86
|
+
const connectivityResponse = await this.websocketConnector.checkConnectivity(false);
|
|
87
|
+
const localPeerDescriptor = this.config.createLocalPeerDescriptor(connectivityResponse);
|
|
88
|
+
this.setLocalPeerDescriptor(localPeerDescriptor);
|
|
44
89
|
}
|
|
45
90
|
createConnection(peerDescriptor) {
|
|
46
|
-
if (this.
|
|
47
|
-
return this.
|
|
91
|
+
if (this.websocketConnector.isPossibleToFormConnection(peerDescriptor)) {
|
|
92
|
+
return this.websocketConnector.connect(peerDescriptor);
|
|
48
93
|
}
|
|
49
94
|
else {
|
|
50
95
|
return this.webrtcConnector.connect(peerDescriptor);
|
|
51
96
|
}
|
|
52
97
|
}
|
|
53
|
-
|
|
54
|
-
return this.
|
|
98
|
+
getLocalPeerDescriptor() {
|
|
99
|
+
return this.localPeerDescriptor;
|
|
55
100
|
}
|
|
56
101
|
async stop() {
|
|
57
|
-
await this.
|
|
102
|
+
await this.websocketConnector.destroy();
|
|
58
103
|
await this.webrtcConnector.stop();
|
|
59
104
|
}
|
|
60
105
|
}
|
|
61
106
|
exports.DefaultConnectorFacade = DefaultConnectorFacade;
|
|
62
107
|
class SimulatorConnectorFacade {
|
|
63
|
-
constructor(
|
|
64
|
-
this.
|
|
108
|
+
constructor(localPeerDescriptor, simulator) {
|
|
109
|
+
this.localPeerDescriptor = localPeerDescriptor;
|
|
65
110
|
this.simulator = simulator;
|
|
66
111
|
}
|
|
67
|
-
async start(
|
|
112
|
+
async start(onNewConnection) {
|
|
68
113
|
logger.trace(`Creating SimulatorConnector`);
|
|
69
|
-
this.simulatorConnector = new SimulatorConnector_1.SimulatorConnector(this.
|
|
114
|
+
this.simulatorConnector = new SimulatorConnector_1.SimulatorConnector(this.localPeerDescriptor, this.simulator, onNewConnection);
|
|
70
115
|
this.simulator.addConnector(this.simulatorConnector);
|
|
71
116
|
}
|
|
72
117
|
createConnection(peerDescriptor) {
|
|
73
118
|
return this.simulatorConnector.connect(peerDescriptor);
|
|
74
119
|
}
|
|
75
|
-
|
|
76
|
-
return this.
|
|
120
|
+
getLocalPeerDescriptor() {
|
|
121
|
+
return this.localPeerDescriptor;
|
|
77
122
|
}
|
|
78
123
|
async stop() {
|
|
79
124
|
await this.simulatorConnector.stop();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConnectorFacade.js","sourceRoot":"","sources":["../../../src/connection/ConnectorFacade.ts"],"names":[],"mappings":";;;AAAA,0CAAuC;AASvC,uEAAmE;AACnE,
|
|
1
|
+
{"version":3,"file":"ConnectorFacade.js","sourceRoot":"","sources":["../../../src/connection/ConnectorFacade.ts"],"names":[],"mappings":";;;AAAA,0CAAuC;AASvC,uEAAmE;AACnE,8DAAqE;AACrE,uEAA6F;AAa7F,MAAM,MAAM,GAAG,IAAI,cAAM,CAAC,MAAM,CAAC,CAAA;AAuBjC,MAAa,sBAAsB;IAO/B,YAAY,MAAoC;QAC5C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACxB,CAAC;IAED,KAAK,CAAC,KAAK,CACP,eAA2D,EAC3D,UAAuD,EACvD,sBAAkC;QAElC,MAAM,CAAC,KAAK,CAAC,qCAAqC,CAAC,CAAA;QACnD,MAAM,wBAAwB,GAAG;YAC7B,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,SAAU;YACjC,qEAAqE;YACrE,UAAU,EAAE,CAAC,cAA8B,EA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mBAAmC,EAAE,SAAoB;QACjE,IAAI,CAAC,mBAAmB,GAAG,mBAAmB,CAAA;QAC9C,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;IAC9B,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,eAA2D;QACnE,MAAM,CAAC,KAAK,CAAC,6BAA6B,CAAC,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"}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { EventEmitter } from 'eventemitter3';
|
|
2
|
-
import { PeerDescriptor } from '../proto/packages/dht/protos/DhtRpc';
|
|
2
|
+
import { PeerDescriptor, HandshakeError } from '../proto/packages/dht/protos/DhtRpc';
|
|
3
3
|
import { IConnection } from './IConnection';
|
|
4
4
|
interface HandshakerEvents {
|
|
5
|
-
handshakeRequest: (
|
|
6
|
-
handshakeCompleted: (
|
|
7
|
-
handshakeFailed: (
|
|
5
|
+
handshakeRequest: (source: PeerDescriptor, target?: PeerDescriptor) => void;
|
|
6
|
+
handshakeCompleted: (remote: PeerDescriptor) => void;
|
|
7
|
+
handshakeFailed: (error?: HandshakeError) => void;
|
|
8
8
|
}
|
|
9
9
|
export declare class Handshaker extends EventEmitter<HandshakerEvents> {
|
|
10
10
|
private static readonly HANDSHAKER_SERVICE_ID;
|
|
11
|
-
private
|
|
11
|
+
private localPeerDescriptor;
|
|
12
12
|
private connection;
|
|
13
|
-
constructor(
|
|
13
|
+
constructor(localPeerDescriptor: PeerDescriptor, connection: IConnection);
|
|
14
14
|
private onData;
|
|
15
|
-
sendHandshakeRequest(): void;
|
|
16
|
-
sendHandshakeResponse(error?:
|
|
15
|
+
sendHandshakeRequest(remotePeerDescriptor?: PeerDescriptor): void;
|
|
16
|
+
sendHandshakeResponse(error?: HandshakeError): void;
|
|
17
17
|
}
|
|
18
18
|
export {};
|
|
@@ -7,39 +7,39 @@ const uuid_1 = require("uuid");
|
|
|
7
7
|
const DhtRpc_1 = require("../proto/packages/dht/protos/DhtRpc");
|
|
8
8
|
const logger = new utils_1.Logger(module);
|
|
9
9
|
class Handshaker extends eventemitter3_1.EventEmitter {
|
|
10
|
-
constructor(
|
|
10
|
+
constructor(localPeerDescriptor, connection) {
|
|
11
11
|
super();
|
|
12
|
-
this.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
this.localPeerDescriptor = localPeerDescriptor;
|
|
13
|
+
this.connection = connection;
|
|
14
|
+
this.connection.on('data', (data) => this.onData(data));
|
|
15
|
+
}
|
|
16
|
+
onData(data) {
|
|
17
|
+
try {
|
|
18
|
+
const message = DhtRpc_1.Message.fromBinary(data);
|
|
19
|
+
if (message.body.oneofKind === 'handshakeRequest') {
|
|
20
|
+
logger.trace('handshake request received');
|
|
21
|
+
const handshake = message.body.handshakeRequest;
|
|
22
|
+
this.emit('handshakeRequest', handshake.sourcePeerDescriptor, handshake.targetPeerDescriptor);
|
|
23
|
+
}
|
|
24
|
+
if (message.body.oneofKind === 'handshakeResponse') {
|
|
25
|
+
logger.trace('handshake response received');
|
|
26
|
+
const handshake = message.body.handshakeResponse;
|
|
27
|
+
if (handshake.error !== undefined) {
|
|
28
|
+
this.emit('handshakeFailed', handshake.error);
|
|
19
29
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const handshake = message.body.handshakeResponse;
|
|
23
|
-
if (handshake.responseError) {
|
|
24
|
-
this.emit('handshakeFailed', handshake.responseError);
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
this.emit('handshakeCompleted', handshake.peerDescriptor);
|
|
28
|
-
}
|
|
30
|
+
else {
|
|
31
|
+
this.emit('handshakeCompleted', handshake.sourcePeerDescriptor);
|
|
29
32
|
}
|
|
30
33
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
this.ownPeerDescriptor = ownPeerDescriptor;
|
|
36
|
-
this.connection = connection;
|
|
37
|
-
this.connection.on('data', this.onData);
|
|
34
|
+
}
|
|
35
|
+
catch (err) {
|
|
36
|
+
logger.error('error while parsing handshake message', err);
|
|
37
|
+
}
|
|
38
38
|
}
|
|
39
|
-
sendHandshakeRequest() {
|
|
39
|
+
sendHandshakeRequest(remotePeerDescriptor) {
|
|
40
40
|
const outgoingHandshake = {
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
sourcePeerDescriptor: this.localPeerDescriptor,
|
|
42
|
+
targetPeerDescriptor: remotePeerDescriptor
|
|
43
43
|
};
|
|
44
44
|
const msg = {
|
|
45
45
|
serviceId: Handshaker.HANDSHAKER_SERVICE_ID,
|
|
@@ -55,12 +55,9 @@ class Handshaker extends eventemitter3_1.EventEmitter {
|
|
|
55
55
|
}
|
|
56
56
|
sendHandshakeResponse(error) {
|
|
57
57
|
const outgoingHandshakeResponse = {
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
sourcePeerDescriptor: this.localPeerDescriptor,
|
|
59
|
+
error
|
|
60
60
|
};
|
|
61
|
-
if (error) {
|
|
62
|
-
outgoingHandshakeResponse.responseError = error;
|
|
63
|
-
}
|
|
64
61
|
const msg = {
|
|
65
62
|
serviceId: Handshaker.HANDSHAKER_SERVICE_ID,
|
|
66
63
|
messageType: DhtRpc_1.MessageType.HANDSHAKE_RESPONSE,
|
|
@@ -71,7 +68,7 @@ class Handshaker extends eventemitter3_1.EventEmitter {
|
|
|
71
68
|
}
|
|
72
69
|
};
|
|
73
70
|
this.connection.send(DhtRpc_1.Message.toBinary(msg));
|
|
74
|
-
logger.trace('handshake
|
|
71
|
+
logger.trace('handshake response sent');
|
|
75
72
|
}
|
|
76
73
|
}
|
|
77
74
|
exports.Handshaker = Handshaker;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Handshaker.js","sourceRoot":"","sources":["../../../src/connection/Handshaker.ts"],"names":[],"mappings":";;;AAAA,0CAAuC;AACvC,iDAA4C;AAC5C,+BAAyB;AACzB,gEAA+
|
|
1
|
+
{"version":3,"file":"Handshaker.js","sourceRoot":"","sources":["../../../src/connection/Handshaker.ts"],"names":[],"mappings":";;;AAAA,0CAAuC;AACvC,iDAA4C;AAC5C,+BAAyB;AACzB,gEAA+I;AAG/I,MAAM,MAAM,GAAG,IAAI,cAAM,CAAC,MAAM,CAAC,CAAA;AAQjC,MAAa,UAAW,SAAQ,4BAA8B;IAM1D,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,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAgB,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAA;IACvE,CAAC;IAEO,MAAM,CAAC,IAAgB;QAC3B,IAAI;YACA,MAAM,OAAO,GAAG,gBAAO,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA;YACxC,IAAI,OAAO,CAAC,IAAI,CAAC,SAAS,KAAK,kBAAkB,EAAE;gBAC/C,MAAM,CAAC,KAAK,CAAC,4BAA4B,CAAC,CAAA;gBAC1C,MAAM,SAAS,GAAG,OAAO,CAAC,I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AyB,GAAsB;YACjD,oBAAoB,EAAE,IAAI,CAAC,mBAAmB;YAC9C,KAAK;SACR,CAAA;QACD,MAAM,GAAG,GAAY;YACjB,SAAS,EAAE,UAAU,CAAC,qBAAqB;YAC3C,WAAW,EAAE,oBAAW,CAAC,kBAAkB;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;;AAzEL,gCA0EC;AAxE2B,gCAAqB,GAAG,mBAAmB,CAAA"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { UUID } from '../helpers/UUID';
|
|
2
|
-
import { DisconnectionType } from '../transport/ITransport';
|
|
3
2
|
export interface ConnectionEvents {
|
|
4
3
|
data: (bytes: Uint8Array) => void;
|
|
5
4
|
connected: () => void;
|
|
6
|
-
disconnected: (
|
|
5
|
+
disconnected: (gracefulLeave: boolean, code?: number, reason?: string) => void;
|
|
7
6
|
error: (name: string) => void;
|
|
8
7
|
}
|
|
9
8
|
export declare enum ConnectionType {
|
|
@@ -23,16 +22,16 @@ export interface IConnection {
|
|
|
23
22
|
on(event: 'data', listener: (bytes: Uint8Array) => void): this;
|
|
24
23
|
on(event: 'error', listener: (name: string) => void): this;
|
|
25
24
|
on(event: 'connected', listener: () => void): this;
|
|
26
|
-
on(event: 'disconnected', listener: (
|
|
25
|
+
on(event: 'disconnected', listener: (gracefulLeave: boolean, code?: number, reason?: string) => void): this;
|
|
27
26
|
once(event: 'data', listener: (bytes: Uint8Array) => void): this;
|
|
28
27
|
once(event: 'error', listener: (name: string) => void): this;
|
|
29
28
|
once(event: 'connected', listener: () => void): this;
|
|
30
|
-
once(event: 'disconnected', listener: (
|
|
29
|
+
once(event: 'disconnected', listener: (gracefulLeave: boolean, code?: number, reason?: string) => void): this;
|
|
31
30
|
off(event: 'data', listener: (bytes: Uint8Array) => void): void;
|
|
32
31
|
off(event: 'error', listener: (name: string) => void): void;
|
|
33
32
|
off(event: 'connected', listener: () => void): void;
|
|
34
|
-
off(event: 'disconnected', listener: (
|
|
33
|
+
off(event: 'disconnected', listener: (gracefulLeave: boolean, code?: number, reason?: string) => void): void;
|
|
35
34
|
send(data: Uint8Array): void;
|
|
36
|
-
close(
|
|
35
|
+
close(gracefulLeave: boolean): Promise<void>;
|
|
37
36
|
destroy(): void;
|
|
38
37
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IConnection.js","sourceRoot":"","sources":["../../../src/connection/IConnection.ts"],"names":[],"mappings":";;;AAAA,0CAAsC;
|
|
1
|
+
{"version":3,"file":"IConnection.js","sourceRoot":"","sources":["../../../src/connection/IConnection.ts"],"names":[],"mappings":";;;AAAA,0CAAsC;AAStC,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;AAID,MAAa,YAAa,SAAQ,WAAI;IAClC,QAAQ;QACJ,OAAO,IAAI,CAAC,QAAQ,EAAqB,CAAA;IAC7C,CAAC;CACJ;AAJD,oCAIC"}
|