@streamr/dht 100.0.0-pretestnet.2 → 100.0.0-pretestnet.3
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 +6 -6
- package/dist/src/connection/ConnectionLockRpcRemote.js.map +1 -1
- package/dist/src/connection/ConnectionManager.d.ts +5 -8
- package/dist/src/connection/ConnectionManager.js +77 -107
- package/dist/src/connection/ConnectionManager.js.map +1 -1
- package/dist/src/connection/ConnectivityChecker.d.ts +7 -6
- package/dist/src/connection/ConnectivityChecker.js +23 -20
- package/dist/src/connection/ConnectivityChecker.js.map +1 -1
- package/dist/src/connection/ConnectorFacade.d.ts +15 -12
- package/dist/src/connection/ConnectorFacade.js +61 -26
- package/dist/src/connection/ConnectorFacade.js.map +1 -1
- package/dist/src/connection/Handshaker.d.ts +2 -2
- package/dist/src/connection/Handshaker.js +28 -28
- 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 +3 -4
- package/dist/src/connection/ManagedConnection.js +30 -30
- 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 +22 -22
- package/dist/src/connection/simulator/SimulatorConnection.js.map +1 -0
- package/dist/src/connection/{Simulator → simulator}/SimulatorConnector.d.ts +2 -2
- package/dist/src/connection/{Simulator → simulator}/SimulatorConnector.js +11 -11
- package/dist/src/connection/{Simulator → simulator}/SimulatorConnector.js.map +1 -1
- 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} +36 -36
- 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} +20 -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} +23 -27
- package/dist/src/connection/websocket/ServerWebsocket.js.map +1 -0
- package/dist/src/connection/{WebSocket/WebSocketConnectorRpcLocal.d.ts → websocket/WebsocketConnector.d.ts} +23 -15
- package/dist/src/connection/{WebSocket/WebSocketConnectorRpcLocal.js → websocket/WebsocketConnector.js} +107 -101
- 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} +5 -10
- package/dist/src/connection/{WebSocket/WebSocketConnectorRpcRemote.js.map → websocket/WebsocketConnectorRpcRemote.js.map} +1 -1
- 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 +119 -150
- 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} +17 -21
- 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 +8 -8
- 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 +5 -5
- 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 +47 -90
- 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 +15 -43
- 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 +25 -24
- package/dist/src/dht/store/StoreRpcLocal.js.map +1 -1
- package/dist/src/dht/store/StoreRpcRemote.js +3 -7
- 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/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 +64 -84
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +64 -66
- 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 +32 -35
- package/src/connection/ConnectionLockHandler.ts +19 -17
- package/src/connection/ConnectionLockRpcLocal.ts +74 -0
- package/src/connection/ConnectionLockRpcRemote.ts +7 -6
- package/src/connection/ConnectionManager.ts +59 -95
- package/src/connection/ConnectivityChecker.ts +30 -26
- package/src/connection/ConnectorFacade.ts +74 -34
- package/src/connection/Handshaker.ts +9 -9
- package/src/connection/IConnection.ts +5 -6
- package/src/connection/ManagedConnection.ts +21 -22
- package/src/connection/{ManagedWebRtcConnection.ts → ManagedWebrtcConnection.ts} +9 -9
- package/src/connection/{Simulator → simulator}/Simulator.ts +4 -4
- package/src/connection/{Simulator → simulator}/SimulatorConnection.ts +23 -24
- package/src/connection/{Simulator → simulator}/SimulatorConnector.ts +13 -13
- package/src/connection/{Simulator → simulator}/SimulatorTransport.ts +2 -2
- package/src/connection/{WebRTC/BrowserWebRtcConnection.ts → webrtc/BrowserWebrtcConnection.ts} +12 -13
- package/src/connection/{WebRTC/IWebRtcConnection.ts → webrtc/IWebrtcConnection.ts} +2 -2
- package/src/connection/{WebRTC/NodeWebRtcConnection.ts → webrtc/NodeWebrtcConnection.ts} +32 -33
- package/src/connection/webrtc/WebrtcConnector.ts +225 -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} +19 -17
- package/src/connection/{WebSocket/ServerWebSocket.ts → websocket/ServerWebsocket.ts} +21 -27
- package/src/connection/{WebSocket/WebSocketConnectorRpcLocal.ts → websocket/WebsocketConnector.ts} +109 -100
- package/src/connection/websocket/WebsocketConnectorRpcLocal.ts +41 -0
- package/src/connection/{WebSocket/WebSocketConnectorRpcRemote.ts → websocket/WebsocketConnectorRpcRemote.ts} +6 -12
- package/src/connection/{WebSocket/WebSocketServer.ts → websocket/WebsocketServer.ts} +40 -22
- package/src/dht/DhtNode.ts +144 -179
- package/src/dht/DhtNodeRpcLocal.ts +68 -0
- package/src/dht/{RemoteDhtNode.ts → DhtNodeRpcRemote.ts} +12 -13
- 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 +23 -20
- package/src/dht/discovery/PeerDiscovery.ts +14 -17
- 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 +69 -105
- package/src/dht/routing/RouterRpcLocal.ts +81 -0
- package/src/dht/routing/RouterRpcRemote.ts +15 -45
- package/src/dht/routing/RoutingSession.ts +56 -61
- package/src/dht/routing/getPreviousPeer.ts +6 -0
- package/src/dht/store/StoreRpcLocal.ts +44 -37
- package/src/dht/store/StoreRpcRemote.ts +4 -8
- package/src/exports.ts +11 -5
- package/src/helpers/Connectivity.ts +19 -0
- package/src/helpers/errors.ts +3 -3
- 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 +87 -114
- 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} +6 -6
- package/test/benchmark/KademliaCorrectness.test.ts +2 -2
- 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 +24 -6
- 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 +4 -4
- package/test/integration/ConnectionManager.test.ts +37 -28
- 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} +3 -3
- package/test/integration/Layer1-scale.test.ts +1 -1
- package/test/integration/MigrateData.test.ts +6 -5
- package/test/integration/Mock-Layer1-Layer0.test.ts +1 -1
- package/test/integration/MultipleEntryPointJoining.test.ts +6 -6
- package/test/integration/RouteMessage.test.ts +26 -26
- package/test/integration/RpcErrors.test.ts +10 -10
- package/test/integration/ScaleDownDht.test.ts +3 -3
- package/test/integration/SimultaneousConnections.test.ts +10 -7
- package/test/integration/Store.test.ts +1 -1
- package/test/integration/StoreAndDelete.test.ts +1 -1
- package/test/integration/StoreOnDhtWithTwoNodes.test.ts +12 -12
- package/test/integration/{WebRtcConnectionManagement.test.ts → WebrtcConnectionManagement.test.ts} +4 -4
- 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 +14 -24
- 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/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.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/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
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
2
|
+
import { toProtoRpcClient } from '@streamr/proto-rpc'
|
|
3
|
+
import { Logger } from '@streamr/utils'
|
|
4
|
+
import { getAddressFromIceCandidate, isPrivateIPv4 } from '../../helpers/AddressTools'
|
|
5
|
+
import { PeerIDKey } from '../../helpers/PeerID'
|
|
6
|
+
import { keyFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
|
|
7
|
+
import { Empty } from '../../proto/google/protobuf/empty'
|
|
8
|
+
import {
|
|
9
|
+
IceCandidate,
|
|
10
|
+
PeerDescriptor,
|
|
11
|
+
RtcAnswer,
|
|
12
|
+
RtcOffer
|
|
13
|
+
} from '../../proto/packages/dht/protos/DhtRpc'
|
|
14
|
+
import { WebrtcConnectorRpcClient } from '../../proto/packages/dht/protos/DhtRpc.client'
|
|
15
|
+
import { IWebrtcConnectorRpc } from '../../proto/packages/dht/protos/DhtRpc.server'
|
|
16
|
+
import { DhtCallContext } from '../../rpc-protocol/DhtCallContext'
|
|
17
|
+
import { ListeningRpcCommunicator } from '../../transport/ListeningRpcCommunicator'
|
|
18
|
+
import { ManagedConnection } from '../ManagedConnection'
|
|
19
|
+
import { ManagedWebrtcConnection } from '../ManagedWebrtcConnection'
|
|
20
|
+
import { NodeWebrtcConnection } from './NodeWebrtcConnection'
|
|
21
|
+
import { WebrtcConnectorRpcRemote } from './WebrtcConnectorRpcRemote'
|
|
22
|
+
|
|
23
|
+
const logger = new Logger(module)
|
|
24
|
+
|
|
25
|
+
interface WebrtcConnectorRpcLocalConfig {
|
|
26
|
+
connect: (targetPeerDescriptor: PeerDescriptor) => ManagedConnection
|
|
27
|
+
onIncomingConnection: (connection: ManagedConnection) => boolean
|
|
28
|
+
// TODO pass accessor methods instead of passing a mutable entity
|
|
29
|
+
ongoingConnectAttempts: Map<PeerIDKey, ManagedWebrtcConnection>
|
|
30
|
+
rpcCommunicator: ListeningRpcCommunicator
|
|
31
|
+
getLocalPeerDescriptor: () => PeerDescriptor
|
|
32
|
+
allowPrivateAddresses: boolean
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export class WebrtcConnectorRpcLocal implements IWebrtcConnectorRpc {
|
|
36
|
+
|
|
37
|
+
private readonly config: WebrtcConnectorRpcLocalConfig
|
|
38
|
+
|
|
39
|
+
constructor(config: WebrtcConnectorRpcLocalConfig) {
|
|
40
|
+
this.config = config
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async requestConnection(context: ServerCallContext): Promise<Empty> {
|
|
44
|
+
const targetPeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
|
|
45
|
+
if (this.config.ongoingConnectAttempts.has(keyFromPeerDescriptor(targetPeerDescriptor))) {
|
|
46
|
+
return {}
|
|
47
|
+
}
|
|
48
|
+
const managedConnection = this.config.connect(targetPeerDescriptor)
|
|
49
|
+
managedConnection.setPeerDescriptor(targetPeerDescriptor)
|
|
50
|
+
this.config.onIncomingConnection(managedConnection)
|
|
51
|
+
return {}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async rtcOffer(request: RtcOffer, context: ServerCallContext): Promise<Empty> {
|
|
55
|
+
const remotePeer = (context as DhtCallContext).incomingSourceDescriptor!
|
|
56
|
+
const peerKey = keyFromPeerDescriptor(remotePeer)
|
|
57
|
+
let managedConnection = this.config.ongoingConnectAttempts.get(peerKey)
|
|
58
|
+
let connection = managedConnection?.getWebrtcConnection()
|
|
59
|
+
|
|
60
|
+
if (!managedConnection) {
|
|
61
|
+
connection = new NodeWebrtcConnection({ remotePeerDescriptor: remotePeer })
|
|
62
|
+
managedConnection = new ManagedWebrtcConnection(this.config.getLocalPeerDescriptor(), undefined, connection)
|
|
63
|
+
managedConnection.setPeerDescriptor(remotePeer)
|
|
64
|
+
this.config.ongoingConnectAttempts.set(peerKey, managedConnection)
|
|
65
|
+
this.config.onIncomingConnection(managedConnection)
|
|
66
|
+
const remoteConnector = new WebrtcConnectorRpcRemote(
|
|
67
|
+
this.config.getLocalPeerDescriptor(),
|
|
68
|
+
remotePeer,
|
|
69
|
+
toProtoRpcClient(new WebrtcConnectorRpcClient(this.config.rpcCommunicator.getRpcClientTransport()))
|
|
70
|
+
)
|
|
71
|
+
connection.on('localCandidate', (candidate: string, mid: string) => {
|
|
72
|
+
remoteConnector.sendIceCandidate(candidate, mid, connection!.connectionId.toString())
|
|
73
|
+
})
|
|
74
|
+
connection.once('localDescription', (description: string) => {
|
|
75
|
+
remoteConnector.sendRtcAnswer(description, connection!.connectionId.toString())
|
|
76
|
+
})
|
|
77
|
+
connection.start(false)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Always use offerers connectionId
|
|
81
|
+
connection!.setConnectionId(request.connectionId)
|
|
82
|
+
connection!.setRemoteDescription(request.description, 'offer')
|
|
83
|
+
|
|
84
|
+
managedConnection.on('handshakeRequest', () => {
|
|
85
|
+
if (this.config.ongoingConnectAttempts.has(peerKey)) {
|
|
86
|
+
this.config.ongoingConnectAttempts.delete(peerKey)
|
|
87
|
+
}
|
|
88
|
+
managedConnection!.acceptHandshake()
|
|
89
|
+
})
|
|
90
|
+
return {}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async rtcAnswer(request: RtcAnswer, context: ServerCallContext): Promise<Empty> {
|
|
94
|
+
const remotePeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
|
|
95
|
+
const peerKey = keyFromPeerDescriptor(remotePeerDescriptor)
|
|
96
|
+
const connection = this.config.ongoingConnectAttempts.get(peerKey)?.getWebrtcConnection()
|
|
97
|
+
if (!connection) {
|
|
98
|
+
return {}
|
|
99
|
+
} else if (connection.connectionId.toString() !== request.connectionId) {
|
|
100
|
+
logger.trace(`Ignoring RTC answer due to connectionId mismatch`)
|
|
101
|
+
return {}
|
|
102
|
+
}
|
|
103
|
+
connection.setRemoteDescription(request.description, 'answer')
|
|
104
|
+
return {}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async iceCandidate(request: IceCandidate, context: ServerCallContext): Promise<Empty> {
|
|
108
|
+
const remotePeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
|
|
109
|
+
const peerKey = keyFromPeerDescriptor(remotePeerDescriptor)
|
|
110
|
+
const connection = this.config.ongoingConnectAttempts.get(peerKey)?.getWebrtcConnection()
|
|
111
|
+
|
|
112
|
+
if (!connection) {
|
|
113
|
+
return {}
|
|
114
|
+
} else if (connection.connectionId.toString() !== request.connectionId) {
|
|
115
|
+
logger.trace(`Ignoring remote candidate due to connectionId mismatch`)
|
|
116
|
+
return {}
|
|
117
|
+
} else if (this.isIceCandidateAllowed(request.candidate)) {
|
|
118
|
+
connection.addRemoteCandidate(request.candidate, request.mid)
|
|
119
|
+
}
|
|
120
|
+
return {}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
private isIceCandidateAllowed(candidate: string): boolean {
|
|
124
|
+
if (!this.config.allowPrivateAddresses) {
|
|
125
|
+
const address = getAddressFromIceCandidate(candidate)
|
|
126
|
+
if (address && isPrivateIPv4(address)) {
|
|
127
|
+
return false
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return true
|
|
131
|
+
}
|
|
132
|
+
}
|
package/src/connection/{WebRTC/WebRtcConnectorRpcRemote.ts → webrtc/WebrtcConnectorRpcRemote.ts}
RENAMED
|
@@ -4,27 +4,26 @@ import {
|
|
|
4
4
|
PeerDescriptor,
|
|
5
5
|
RtcAnswer,
|
|
6
6
|
RtcOffer,
|
|
7
|
-
|
|
7
|
+
WebrtcConnectionRequest
|
|
8
8
|
} from '../../proto/packages/dht/protos/DhtRpc'
|
|
9
|
-
import {
|
|
9
|
+
import { IWebrtcConnectorRpcClient } from '../../proto/packages/dht/protos/DhtRpc.client'
|
|
10
10
|
import { ProtoRpcClient } from '@streamr/proto-rpc'
|
|
11
11
|
import { Logger } from '@streamr/utils'
|
|
12
12
|
|
|
13
13
|
const logger = new Logger(module)
|
|
14
14
|
|
|
15
|
-
export class
|
|
15
|
+
export class WebrtcConnectorRpcRemote extends Remote<IWebrtcConnectorRpcClient> {
|
|
16
16
|
|
|
17
17
|
constructor(
|
|
18
18
|
localPeerDescriptor: PeerDescriptor,
|
|
19
19
|
remotePeerDescriptor: PeerDescriptor,
|
|
20
|
-
client: ProtoRpcClient<
|
|
20
|
+
client: ProtoRpcClient<IWebrtcConnectorRpcClient>
|
|
21
21
|
) {
|
|
22
22
|
super(localPeerDescriptor, remotePeerDescriptor, 'DUMMY', client)
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
requestConnection(
|
|
26
|
-
const request:
|
|
27
|
-
connectionId
|
|
25
|
+
requestConnection(): void {
|
|
26
|
+
const request: WebrtcConnectionRequest = {
|
|
28
27
|
}
|
|
29
28
|
const options = this.formDhtRpcOptions({
|
|
30
29
|
notification: true
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AutoCertifierClient,
|
|
3
|
+
HasSessionRequest,
|
|
4
|
+
HasSessionResponse,
|
|
5
|
+
CertifiedSubdomain,
|
|
6
|
+
SERVICE_ID as AUTO_CERTIFIER_SERVICE_ID,
|
|
7
|
+
HasSession
|
|
8
|
+
} from '@streamr/autocertifier-client'
|
|
9
|
+
import { ListeningRpcCommunicator } from '../../transport/ListeningRpcCommunicator'
|
|
10
|
+
import { Logger, waitForEvent3 } from '@streamr/utils'
|
|
11
|
+
import { ITransport } from '../../transport/ITransport'
|
|
12
|
+
|
|
13
|
+
const START_TIMEOUT = 60 * 1000
|
|
14
|
+
|
|
15
|
+
const defaultAutoCertifierClientFactory = (
|
|
16
|
+
configFile: string,
|
|
17
|
+
autoCertifierUrl: string,
|
|
18
|
+
autoCertifierRpcCommunicator: ListeningRpcCommunicator,
|
|
19
|
+
wsServerPort: number
|
|
20
|
+
) => new AutoCertifierClient(
|
|
21
|
+
configFile,
|
|
22
|
+
wsServerPort,
|
|
23
|
+
autoCertifierUrl,
|
|
24
|
+
(_serviceId: string, rpcMethodName: string, method: HasSession) => {
|
|
25
|
+
autoCertifierRpcCommunicator.registerRpcMethod(
|
|
26
|
+
HasSessionRequest,
|
|
27
|
+
HasSessionResponse,
|
|
28
|
+
rpcMethodName,
|
|
29
|
+
method
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
export interface IAutoCertifierClient {
|
|
35
|
+
start(): Promise<void>
|
|
36
|
+
stop(): void
|
|
37
|
+
on(eventName: string, cb: (subdomain: CertifiedSubdomain) => void): void
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
interface AutoCertifierClientFacadeConfig {
|
|
41
|
+
url: string
|
|
42
|
+
configFile: string
|
|
43
|
+
transport: ITransport
|
|
44
|
+
wsServerPort: number
|
|
45
|
+
// TODO: setHost and updateCertificate could be passed in a single onCertificateUpdated function.
|
|
46
|
+
setHost: (host: string) => void
|
|
47
|
+
updateCertificate: (certificate: string, privateKey: string) => void
|
|
48
|
+
// TOD: could just pass the client?
|
|
49
|
+
createClientFactory?: () => IAutoCertifierClient
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const logger = new Logger(module)
|
|
53
|
+
|
|
54
|
+
export class AutoCertifierClientFacade {
|
|
55
|
+
|
|
56
|
+
private autoCertifierClient: IAutoCertifierClient
|
|
57
|
+
private readonly rpcCommunicator: ListeningRpcCommunicator
|
|
58
|
+
private readonly setHost: (host: string) => void
|
|
59
|
+
private readonly updateCertificate: (certificate: string, privateKey: string) => void
|
|
60
|
+
|
|
61
|
+
constructor(config: AutoCertifierClientFacadeConfig) {
|
|
62
|
+
this.setHost = config.setHost
|
|
63
|
+
this.updateCertificate = config.updateCertificate
|
|
64
|
+
this.rpcCommunicator = new ListeningRpcCommunicator(AUTO_CERTIFIER_SERVICE_ID, config.transport)
|
|
65
|
+
this.autoCertifierClient = config.createClientFactory ? config.createClientFactory()
|
|
66
|
+
: defaultAutoCertifierClientFactory(
|
|
67
|
+
config.configFile,
|
|
68
|
+
config.url,
|
|
69
|
+
this.rpcCommunicator,
|
|
70
|
+
config.wsServerPort
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async start(): Promise<void> {
|
|
75
|
+
this.autoCertifierClient.on('updatedCertificate', (subdomain: CertifiedSubdomain) => {
|
|
76
|
+
this.setHost(subdomain.fqdn)
|
|
77
|
+
this.updateCertificate(subdomain.certificate, subdomain.privateKey)
|
|
78
|
+
logger.trace(`Updated certificate`)
|
|
79
|
+
})
|
|
80
|
+
await Promise.all([
|
|
81
|
+
waitForEvent3(this.autoCertifierClient as any, 'updatedCertificate', START_TIMEOUT),
|
|
82
|
+
this.autoCertifierClient.start()
|
|
83
|
+
])
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
stop(): void {
|
|
87
|
+
this.autoCertifierClient.stop()
|
|
88
|
+
this.rpcCommunicator.destroy()
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
}
|
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
import { IConnection, ConnectionID, ConnectionType, ConnectionEvents } from '../IConnection'
|
|
2
|
-
import { w3cwebsocket as WebSocket, ICloseEvent, IMessageEvent } from 'websocket'
|
|
3
|
-
import EventEmitter from 'eventemitter3'
|
|
4
1
|
import { Logger } from '@streamr/utils'
|
|
5
|
-
import
|
|
2
|
+
import EventEmitter from 'eventemitter3'
|
|
3
|
+
import { ICloseEvent, IMessageEvent, w3cwebsocket as Websocket } from 'websocket'
|
|
4
|
+
import { ConnectionEvents, ConnectionID, ConnectionType, IConnection } from '../IConnection'
|
|
6
5
|
|
|
7
6
|
const logger = new Logger(module)
|
|
8
7
|
|
|
8
|
+
// https://kapeli.com/cheat_sheets/WebSocket_Status_Codes.docset/Contents/Resources/Documents/index
|
|
9
|
+
// Browsers send this automatically when closing a tab
|
|
10
|
+
export const GOING_AWAY = 1001
|
|
11
|
+
|
|
9
12
|
const BINARY_TYPE = 'arraybuffer'
|
|
10
13
|
|
|
11
|
-
export class
|
|
14
|
+
export class ClientWebsocket extends EventEmitter<ConnectionEvents> implements IConnection {
|
|
12
15
|
public readonly connectionId: ConnectionID
|
|
13
|
-
private socket?:
|
|
16
|
+
private socket?: Websocket
|
|
14
17
|
public connectionType = ConnectionType.WEBSOCKET_CLIENT
|
|
15
18
|
|
|
16
19
|
private destroyed = false
|
|
@@ -20,14 +23,13 @@ export class ClientWebSocket extends EventEmitter<ConnectionEvents> implements I
|
|
|
20
23
|
this.connectionId = new ConnectionID()
|
|
21
24
|
}
|
|
22
25
|
|
|
23
|
-
public connect(address: string): void {
|
|
26
|
+
public connect(address: string, selfSigned?: boolean): void {
|
|
24
27
|
if (!this.destroyed) {
|
|
25
|
-
this.socket = new
|
|
28
|
+
this.socket = new Websocket(address, undefined, undefined, undefined, { rejectUnauthorized: !selfSigned })
|
|
26
29
|
this.socket.binaryType = BINARY_TYPE
|
|
27
|
-
|
|
28
30
|
this.socket.onerror = (error: Error) => {
|
|
29
31
|
if (!this.destroyed) {
|
|
30
|
-
logger.trace('WebSocket Client error: ' + error)
|
|
32
|
+
logger.trace('WebSocket Client error: ' + error?.message, { error })
|
|
31
33
|
this.emit('error', error.name)
|
|
32
34
|
}
|
|
33
35
|
}
|
|
@@ -44,7 +46,7 @@ export class ClientWebSocket extends EventEmitter<ConnectionEvents> implements I
|
|
|
44
46
|
this.socket.onclose = (event: ICloseEvent) => {
|
|
45
47
|
if (!this.destroyed) {
|
|
46
48
|
logger.trace('Websocket Closed')
|
|
47
|
-
this.doDisconnect(
|
|
49
|
+
this.doDisconnect(event.code, event.reason)
|
|
48
50
|
}
|
|
49
51
|
}
|
|
50
52
|
|
|
@@ -62,12 +64,12 @@ export class ClientWebSocket extends EventEmitter<ConnectionEvents> implements I
|
|
|
62
64
|
}
|
|
63
65
|
}
|
|
64
66
|
|
|
65
|
-
private doDisconnect(
|
|
67
|
+
private doDisconnect(code?: number, reason?: string) {
|
|
66
68
|
this.destroyed = true
|
|
67
69
|
this.stopListening()
|
|
68
70
|
this.socket = undefined
|
|
69
|
-
|
|
70
|
-
this.emit('disconnected',
|
|
71
|
+
const gracefulLeave = code === GOING_AWAY
|
|
72
|
+
this.emit('disconnected', gracefulLeave, code, reason)
|
|
71
73
|
this.removeAllListeners()
|
|
72
74
|
}
|
|
73
75
|
|
|
@@ -77,17 +79,17 @@ export class ClientWebSocket extends EventEmitter<ConnectionEvents> implements I
|
|
|
77
79
|
logger.trace(`Sending data with size ${data.byteLength}`)
|
|
78
80
|
this.socket?.send(data.buffer)
|
|
79
81
|
} else {
|
|
80
|
-
logger.
|
|
82
|
+
logger.debug('Tried to send data on a non-open connection')
|
|
81
83
|
}
|
|
82
84
|
} else {
|
|
83
85
|
logger.debug('Tried to send() on stopped connection')
|
|
84
86
|
}
|
|
85
87
|
}
|
|
86
88
|
|
|
87
|
-
public async close(): Promise<void> {
|
|
89
|
+
public async close(gracefulLeave: boolean): Promise<void> {
|
|
88
90
|
if (!this.destroyed) {
|
|
89
91
|
logger.trace(`Closing socket for connection ${this.connectionId.toString()}`)
|
|
90
|
-
this.socket?.close()
|
|
92
|
+
this.socket?.close(gracefulLeave === true ? GOING_AWAY : undefined)
|
|
91
93
|
} else {
|
|
92
94
|
logger.debug('Tried to close() a stopped connection')
|
|
93
95
|
}
|
|
@@ -2,8 +2,8 @@ import EventEmitter from 'eventemitter3'
|
|
|
2
2
|
import { IConnection, ConnectionID, ConnectionEvents, ConnectionType } from '../IConnection'
|
|
3
3
|
import { connection as WsConnection } from 'websocket'
|
|
4
4
|
import { Logger } from '@streamr/utils'
|
|
5
|
-
import { DisconnectionType } from '../../transport/ITransport'
|
|
6
5
|
import { Url } from 'url'
|
|
6
|
+
import { GOING_AWAY } from './ClientWebsocket'
|
|
7
7
|
|
|
8
8
|
const logger = new Logger(module)
|
|
9
9
|
|
|
@@ -18,7 +18,7 @@ enum MessageType {
|
|
|
18
18
|
BINARY = 'binary'
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
export class
|
|
21
|
+
export class ServerWebsocket extends EventEmitter<ConnectionEvents> implements IConnection {
|
|
22
22
|
|
|
23
23
|
public readonly connectionId: ConnectionID
|
|
24
24
|
public readonly connectionType = ConnectionType.WEBSOCKET_SERVER
|
|
@@ -33,40 +33,34 @@ export class ServerWebSocket extends EventEmitter<ConnectionEvents> implements I
|
|
|
33
33
|
this.connectionId = new ConnectionID()
|
|
34
34
|
|
|
35
35
|
socket.on('message', (message) => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
message.binaryData.byteLength / Uint8Array.BYTES_PER_ELEMENT))
|
|
45
|
-
}
|
|
36
|
+
logger.trace('ServerWebsocket::onMessage')
|
|
37
|
+
if (message.type === MessageType.UTF8) {
|
|
38
|
+
logger.debug('Received string Message: ' + message.utf8Data)
|
|
39
|
+
} else if (message.type === MessageType.BINARY) {
|
|
40
|
+
logger.trace('Received Binary Message of ' + message.binaryData.length + ' bytes')
|
|
41
|
+
this.emit('data',
|
|
42
|
+
new Uint8Array(message.binaryData.buffer, message.binaryData.byteOffset,
|
|
43
|
+
message.binaryData.byteLength / Uint8Array.BYTES_PER_ELEMENT))
|
|
46
44
|
}
|
|
47
45
|
})
|
|
48
46
|
socket.on('close', (reasonCode, description) => {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
this.doDisconnect('OTHER', reasonCode, description)
|
|
52
|
-
}
|
|
47
|
+
logger.trace('Peer ' + socket.remoteAddress + ' disconnected.')
|
|
48
|
+
this.doDisconnect(reasonCode, description)
|
|
53
49
|
})
|
|
54
50
|
|
|
55
51
|
socket.on('error', (error) => {
|
|
56
|
-
|
|
57
|
-
this.emit('error', error.name)
|
|
58
|
-
}
|
|
52
|
+
this.emit('error', error.name)
|
|
59
53
|
})
|
|
60
54
|
|
|
61
55
|
this.socket = socket
|
|
62
56
|
}
|
|
63
57
|
|
|
64
|
-
private doDisconnect(
|
|
58
|
+
private doDisconnect(reasonCode: number, description: string): void {
|
|
65
59
|
this.stopped = true
|
|
66
60
|
this.socket?.removeAllListeners()
|
|
67
61
|
this.socket = undefined
|
|
68
|
-
|
|
69
|
-
this.emit('disconnected',
|
|
62
|
+
const gracefulLeave = reasonCode === GOING_AWAY
|
|
63
|
+
this.emit('disconnected', gracefulLeave, reasonCode, description)
|
|
70
64
|
}
|
|
71
65
|
|
|
72
66
|
public send(data: Uint8Array): void {
|
|
@@ -80,16 +74,16 @@ export class ServerWebSocket extends EventEmitter<ConnectionEvents> implements I
|
|
|
80
74
|
this.socket.sendBytes(Buffer.from(data))
|
|
81
75
|
}
|
|
82
76
|
} else {
|
|
83
|
-
logger.
|
|
77
|
+
logger.debug('Tried to call send() on a stopped socket')
|
|
84
78
|
}
|
|
85
79
|
|
|
86
80
|
}
|
|
87
81
|
|
|
88
|
-
public async close(): Promise<void> {
|
|
82
|
+
public async close(gracefulLeave: boolean): Promise<void> {
|
|
89
83
|
if (!this.stopped) {
|
|
90
|
-
this.socket?.close()
|
|
84
|
+
this.socket?.close(gracefulLeave === true ? GOING_AWAY : undefined)
|
|
91
85
|
} else {
|
|
92
|
-
logger.
|
|
86
|
+
logger.debug('Tried to close a stopped connection')
|
|
93
87
|
}
|
|
94
88
|
}
|
|
95
89
|
|
|
@@ -103,7 +97,7 @@ export class ServerWebSocket extends EventEmitter<ConnectionEvents> implements I
|
|
|
103
97
|
}
|
|
104
98
|
this.stopped = true
|
|
105
99
|
} else {
|
|
106
|
-
logger.
|
|
100
|
+
logger.debug('Tried to destroy() a stopped connection')
|
|
107
101
|
}
|
|
108
102
|
}
|
|
109
103
|
|