@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
|
@@ -1,69 +1,78 @@
|
|
|
1
1
|
import { ConnectionEvents, ConnectionID, ConnectionType, IConnection } from './IConnection'
|
|
2
2
|
import * as Err from '../helpers/errors'
|
|
3
3
|
import { Handshaker } from './Handshaker'
|
|
4
|
-
import { PeerDescriptor } from '../proto/packages/dht/protos/DhtRpc'
|
|
5
|
-
import { Logger,
|
|
4
|
+
import { HandshakeError, PeerDescriptor } from '../proto/packages/dht/protos/DhtRpc'
|
|
5
|
+
import { Logger, runAndRaceEvents3, RunAndRaceEventsReturnType } from '@streamr/utils'
|
|
6
6
|
import EventEmitter from 'eventemitter3'
|
|
7
7
|
import { PeerIDKey } from '../helpers/PeerID'
|
|
8
8
|
import { keyFromPeerDescriptor } from '../helpers/peerIdFromPeerDescriptor'
|
|
9
|
-
import {
|
|
10
|
-
import { keyOrUnknownFromPeerDescriptor } from './ConnectionManager'
|
|
9
|
+
import { getNodeIdOrUnknownFromPeerDescriptor } from './ConnectionManager'
|
|
11
10
|
|
|
12
11
|
export interface ManagedConnectionEvents {
|
|
13
12
|
managedData: (bytes: Uint8Array, remotePeerDescriptor: PeerDescriptor) => void
|
|
14
|
-
handshakeRequest: (
|
|
13
|
+
handshakeRequest: (source: PeerDescriptor, target?: PeerDescriptor) => void
|
|
15
14
|
handshakeCompleted: (peerDescriptor: PeerDescriptor) => void
|
|
16
15
|
handshakeFailed: () => void
|
|
17
16
|
bufferSentByOtherConnection: () => void
|
|
18
17
|
closing: () => void
|
|
19
|
-
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface OutpuBufferEvents {
|
|
21
|
+
bufferSent: () => void
|
|
22
|
+
bufferSendingFailed: () => void
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface OutpuBufferEvents {
|
|
26
|
+
bufferSent: () => void
|
|
27
|
+
bufferSendingFailed: () => void
|
|
20
28
|
}
|
|
21
29
|
|
|
22
30
|
const logger = new Logger(module)
|
|
23
31
|
|
|
24
32
|
export type Events = ManagedConnectionEvents & ConnectionEvents
|
|
33
|
+
|
|
25
34
|
export class ManagedConnection extends EventEmitter<Events> {
|
|
26
35
|
|
|
27
36
|
private implementation?: IConnection
|
|
28
37
|
|
|
38
|
+
private outputBufferEmitter = new EventEmitter<OutpuBufferEvents>()
|
|
29
39
|
private outputBuffer: Uint8Array[] = []
|
|
40
|
+
|
|
30
41
|
private inputBuffer: Uint8Array[] = []
|
|
31
42
|
|
|
32
43
|
public connectionId: ConnectionID
|
|
33
|
-
private
|
|
44
|
+
private remotePeerDescriptor?: PeerDescriptor
|
|
34
45
|
public connectionType: ConnectionType
|
|
35
46
|
|
|
36
47
|
private handshaker?: Handshaker
|
|
37
48
|
private handshakeCompleted = false
|
|
38
|
-
private doNotEmitDisconnected = false
|
|
39
49
|
|
|
40
50
|
private lastUsed: number = Date.now()
|
|
41
51
|
private stopped = false
|
|
42
52
|
public offeredAsIncoming = false
|
|
43
|
-
public rejectedAsIncoming = false
|
|
44
53
|
private bufferSentbyOtherConnection = false
|
|
45
54
|
private closing = false
|
|
46
55
|
public replacedByOtherConnection = false
|
|
47
|
-
private
|
|
56
|
+
private localPeerDescriptor: PeerDescriptor
|
|
48
57
|
protected outgoingConnection?: IConnection
|
|
49
58
|
protected incomingConnection?: IConnection
|
|
50
59
|
|
|
51
60
|
constructor(
|
|
52
|
-
|
|
61
|
+
localPeerDescriptor: PeerDescriptor,
|
|
53
62
|
connectionType: ConnectionType,
|
|
54
63
|
outgoingConnection?: IConnection,
|
|
55
64
|
incomingConnection?: IConnection,
|
|
65
|
+
targetPeerDescriptor?: PeerDescriptor
|
|
56
66
|
) {
|
|
57
67
|
super()
|
|
58
68
|
|
|
59
|
-
this.
|
|
60
|
-
|
|
61
|
-
this.ownPeerDescriptor = ownPeerDescriptor
|
|
69
|
+
this.localPeerDescriptor = localPeerDescriptor
|
|
62
70
|
this.outgoingConnection = outgoingConnection
|
|
63
71
|
this.incomingConnection = incomingConnection
|
|
64
72
|
this.connectionType = connectionType
|
|
65
73
|
this.connectionId = new ConnectionID()
|
|
66
74
|
|
|
75
|
+
this.send = this.send.bind(this)
|
|
67
76
|
this.onDisconnected = this.onDisconnected.bind(this)
|
|
68
77
|
|
|
69
78
|
logger.trace('creating ManagedConnection of type: ' + connectionType)
|
|
@@ -72,33 +81,37 @@ export class ManagedConnection extends EventEmitter<Events> {
|
|
|
72
81
|
}
|
|
73
82
|
|
|
74
83
|
if (outgoingConnection) {
|
|
75
|
-
this.handshaker = new Handshaker(this.
|
|
84
|
+
this.handshaker = new Handshaker(this.localPeerDescriptor, outgoingConnection)
|
|
76
85
|
|
|
77
|
-
this.handshaker.once('handshakeFailed', (
|
|
78
|
-
|
|
79
|
-
|
|
86
|
+
this.handshaker.once('handshakeFailed', (error) => {
|
|
87
|
+
if (error === HandshakeError.INVALID_TARGET_PEER_DESCRIPTOR) {
|
|
88
|
+
this.close(false)
|
|
89
|
+
} else {
|
|
90
|
+
logger.trace(getNodeIdOrUnknownFromPeerDescriptor(this.remotePeerDescriptor) + ' handshakeFailed: ' + error)
|
|
91
|
+
this.emit('handshakeFailed')
|
|
92
|
+
}
|
|
80
93
|
})
|
|
81
94
|
|
|
82
95
|
this.handshaker.on('handshakeCompleted', (peerDescriptor: PeerDescriptor) => {
|
|
83
96
|
logger.trace('handshake completed for outgoing connection '
|
|
84
|
-
+ ', ' +
|
|
97
|
+
+ ', ' + getNodeIdOrUnknownFromPeerDescriptor(this.remotePeerDescriptor)
|
|
85
98
|
+ ' outputBuffer.length: ' + this.outputBuffer.length)
|
|
86
99
|
this.attachImplementation(outgoingConnection)
|
|
87
100
|
this.onHandshakeCompleted(peerDescriptor)
|
|
88
101
|
})
|
|
89
102
|
|
|
90
103
|
outgoingConnection.once('connected', () => {
|
|
91
|
-
this.handshaker!.sendHandshakeRequest()
|
|
104
|
+
this.handshaker!.sendHandshakeRequest(targetPeerDescriptor)
|
|
92
105
|
this.emit('connected')
|
|
93
106
|
})
|
|
94
107
|
outgoingConnection.once('disconnected', this.onDisconnected)
|
|
95
108
|
|
|
96
109
|
} else {
|
|
97
110
|
if (incomingConnection) {
|
|
98
|
-
this.handshaker = new Handshaker(this.
|
|
99
|
-
this.handshaker.on('handshakeRequest', (
|
|
100
|
-
this.
|
|
101
|
-
this.emit('handshakeRequest',
|
|
111
|
+
this.handshaker = new Handshaker(this.localPeerDescriptor, incomingConnection)
|
|
112
|
+
this.handshaker.on('handshakeRequest', (sourcePeerDescriptor: PeerDescriptor, targetPeerDescriptor?: PeerDescriptor) => {
|
|
113
|
+
this.setRemotePeerDescriptor(sourcePeerDescriptor)
|
|
114
|
+
this.emit('handshakeRequest', sourcePeerDescriptor, targetPeerDescriptor)
|
|
102
115
|
})
|
|
103
116
|
|
|
104
117
|
incomingConnection.on('disconnected', this.onDisconnected)
|
|
@@ -150,32 +163,32 @@ export class ManagedConnection extends EventEmitter<Events> {
|
|
|
150
163
|
}
|
|
151
164
|
|
|
152
165
|
public get peerIdKey(): PeerIDKey {
|
|
153
|
-
return keyFromPeerDescriptor(this.
|
|
166
|
+
return keyFromPeerDescriptor(this.remotePeerDescriptor!)
|
|
154
167
|
}
|
|
155
168
|
|
|
156
169
|
public getLastUsed(): number {
|
|
157
170
|
return this.lastUsed
|
|
158
171
|
}
|
|
159
172
|
|
|
160
|
-
public
|
|
161
|
-
this.
|
|
173
|
+
public setRemotePeerDescriptor(peerDescriptor: PeerDescriptor): void {
|
|
174
|
+
this.remotePeerDescriptor = peerDescriptor
|
|
162
175
|
}
|
|
163
176
|
|
|
164
177
|
public getPeerDescriptor(): PeerDescriptor | undefined {
|
|
165
|
-
return this.
|
|
178
|
+
return this.remotePeerDescriptor
|
|
166
179
|
}
|
|
167
180
|
|
|
168
|
-
private onHandshakeCompleted
|
|
181
|
+
private onHandshakeCompleted(peerDescriptor: PeerDescriptor) {
|
|
169
182
|
this.lastUsed = Date.now()
|
|
170
183
|
|
|
171
|
-
this.
|
|
184
|
+
this.setRemotePeerDescriptor(peerDescriptor)
|
|
172
185
|
this.handshakeCompleted = true
|
|
173
186
|
|
|
174
187
|
while (this.outputBuffer.length > 0) {
|
|
175
188
|
logger.trace('emptying outputBuffer')
|
|
176
189
|
this.implementation!.send(this.outputBuffer.shift()!)
|
|
177
190
|
}
|
|
178
|
-
|
|
191
|
+
this.outputBufferEmitter.emit('bufferSent')
|
|
179
192
|
logger.trace('emitting handshake_completed')
|
|
180
193
|
this.emit('handshakeCompleted', peerDescriptor)
|
|
181
194
|
}
|
|
@@ -186,8 +199,7 @@ export class ManagedConnection extends EventEmitter<Events> {
|
|
|
186
199
|
|
|
187
200
|
impl.on('data', (bytes: Uint8Array) => {
|
|
188
201
|
this.lastUsed = Date.now()
|
|
189
|
-
if (this.listenerCount('managedData')
|
|
190
|
-
|
|
202
|
+
if (this.listenerCount('managedData') === 0) {
|
|
191
203
|
this.inputBuffer.push(bytes)
|
|
192
204
|
} else {
|
|
193
205
|
this.emit('managedData', bytes, this.getPeerDescriptor()!)
|
|
@@ -203,25 +215,26 @@ export class ManagedConnection extends EventEmitter<Events> {
|
|
|
203
215
|
this.emit('connected')
|
|
204
216
|
})
|
|
205
217
|
|
|
218
|
+
//ensure that we have subscribed to the event only once
|
|
206
219
|
impl.off('disconnected', this.onDisconnected)
|
|
207
220
|
impl.on('disconnected', this.onDisconnected)
|
|
208
221
|
}
|
|
209
222
|
|
|
210
|
-
private onDisconnected(
|
|
211
|
-
logger.trace(
|
|
223
|
+
private onDisconnected(gracefulLeave: boolean): void {
|
|
224
|
+
logger.trace(getNodeIdOrUnknownFromPeerDescriptor(this.remotePeerDescriptor) + ' onDisconnected() ' + gracefulLeave)
|
|
212
225
|
if (this.bufferSentbyOtherConnection) {
|
|
213
226
|
return
|
|
214
227
|
}
|
|
215
|
-
this.emit('
|
|
216
|
-
this.
|
|
228
|
+
this.outputBufferEmitter.emit('bufferSendingFailed')
|
|
229
|
+
this.emit('disconnected', gracefulLeave)
|
|
217
230
|
}
|
|
218
231
|
|
|
219
232
|
async send(data: Uint8Array, doNotConnect = false): Promise<void> {
|
|
220
233
|
if (this.stopped) {
|
|
221
|
-
|
|
234
|
+
throw new Err.SendFailed('ManagedConnection is stopped')
|
|
222
235
|
}
|
|
223
236
|
if (this.closing) {
|
|
224
|
-
|
|
237
|
+
throw new Err.SendFailed('ManagedConnection is closing')
|
|
225
238
|
}
|
|
226
239
|
this.lastUsed = Date.now()
|
|
227
240
|
|
|
@@ -232,52 +245,20 @@ export class ManagedConnection extends EventEmitter<Events> {
|
|
|
232
245
|
} else {
|
|
233
246
|
logger.trace('adding data to outputBuffer')
|
|
234
247
|
|
|
235
|
-
let result: RunAndRaceEventsReturnType<
|
|
236
|
-
|
|
237
|
-
this.doNotEmitDisconnected = true
|
|
248
|
+
let result: RunAndRaceEventsReturnType<OutpuBufferEvents>
|
|
238
249
|
|
|
239
250
|
try {
|
|
240
|
-
result = await runAndRaceEvents3<
|
|
241
|
-
|
|
251
|
+
result = await runAndRaceEvents3<OutpuBufferEvents>([() => { this.outputBuffer.push(data) }],
|
|
252
|
+
this.outputBufferEmitter, ['bufferSent', 'bufferSendingFailed'], 15000)
|
|
242
253
|
} catch (e) {
|
|
243
|
-
logger.debug(`Connection to ${
|
|
244
|
-
throw
|
|
254
|
+
logger.debug(`Connection to ${getNodeIdOrUnknownFromPeerDescriptor(this.remotePeerDescriptor)} timed out`)
|
|
255
|
+
throw new Err.SendFailed('Sending buffer timed out')
|
|
245
256
|
}
|
|
246
257
|
|
|
247
|
-
if (result.winnerName === '
|
|
248
|
-
|
|
249
|
-
this.doDisconnect('OTHER')
|
|
250
|
-
} else if (result.winnerName === 'handshakeFailed') {
|
|
251
|
-
logger.trace(keyOrUnknownFromPeerDescriptor(this.peerDescriptor) + ' handshakeFailed received')
|
|
252
|
-
|
|
253
|
-
if (this.bufferSentbyOtherConnection) {
|
|
254
|
-
logger.trace('bufferSentByOtherConnection already true')
|
|
255
|
-
this.doNotEmitDisconnected = false
|
|
256
|
-
this.doDisconnect('OTHER')
|
|
257
|
-
} else {
|
|
258
|
-
let result2: RunAndRaceEventsReturnType<Events>
|
|
259
|
-
|
|
260
|
-
try {
|
|
261
|
-
result2 = await raceEvents3<Events>(this,
|
|
262
|
-
['bufferSentByOtherConnection', 'closing', 'disconnected'], 15000)
|
|
263
|
-
} catch (ex) {
|
|
264
|
-
logger.trace(keyOrUnknownFromPeerDescriptor(this.peerDescriptor)
|
|
265
|
-
+ ' Exception from raceEvents3 while waiting bufferSentByOtherConnection or closing ' + ex)
|
|
266
|
-
throw ex
|
|
267
|
-
}
|
|
268
|
-
if (result2.winnerName === 'bufferSentByOtherConnection') {
|
|
269
|
-
logger.trace('bufferSentByOtherConnection received')
|
|
270
|
-
this.doNotEmitDisconnected = false
|
|
271
|
-
this.doDisconnect('OTHER')
|
|
272
|
-
} else if (result2.winnerName === 'closing') {
|
|
273
|
-
logger.trace('bufferSentByOtherConnection not received, instead received a closing event')
|
|
274
|
-
} else if (result2.winnerName === 'disconnected') {
|
|
275
|
-
logger.trace('disconnected while in raceEvents3')
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
} else {
|
|
279
|
-
this.doNotEmitDisconnected = false
|
|
258
|
+
if (result.winnerName === 'bufferSendingFailed') {
|
|
259
|
+
throw new Err.SendFailed('Sending buffer failed')
|
|
280
260
|
}
|
|
261
|
+
// buffer was sent successfully, return normally
|
|
281
262
|
}
|
|
282
263
|
}
|
|
283
264
|
|
|
@@ -292,12 +273,13 @@ export class ManagedConnection extends EventEmitter<Events> {
|
|
|
292
273
|
}
|
|
293
274
|
|
|
294
275
|
public reportBufferSentByOtherConnection(): void {
|
|
295
|
-
logger.trace(
|
|
276
|
+
logger.trace(getNodeIdOrUnknownFromPeerDescriptor(this.remotePeerDescriptor) + ' reportBufferSentByOtherConnection')
|
|
296
277
|
if (this.handshaker) {
|
|
297
278
|
this.handshaker.removeAllListeners()
|
|
298
279
|
}
|
|
299
280
|
logger.trace('bufferSentByOtherConnection reported')
|
|
300
281
|
this.bufferSentbyOtherConnection = true
|
|
282
|
+
this.outputBufferEmitter.emit('bufferSent')
|
|
301
283
|
this.emit('bufferSentByOtherConnection')
|
|
302
284
|
}
|
|
303
285
|
|
|
@@ -305,7 +287,7 @@ export class ManagedConnection extends EventEmitter<Events> {
|
|
|
305
287
|
// This happens when connectionRequest has been made and answered
|
|
306
288
|
if (this.implementation) {
|
|
307
289
|
if (!this.handshaker) {
|
|
308
|
-
this.handshaker = new Handshaker(this.
|
|
290
|
+
this.handshaker = new Handshaker(this.localPeerDescriptor, this.implementation)
|
|
309
291
|
}
|
|
310
292
|
|
|
311
293
|
this.handshaker.sendHandshakeResponse()
|
|
@@ -315,44 +297,37 @@ export class ManagedConnection extends EventEmitter<Events> {
|
|
|
315
297
|
this.attachImplementation(this.incomingConnection!)
|
|
316
298
|
}
|
|
317
299
|
|
|
318
|
-
this.onHandshakeCompleted(this.
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
public rejectHandshake(errorMessage: string): void {
|
|
322
|
-
this.handshaker!.sendHandshakeResponse(errorMessage)
|
|
300
|
+
this.onHandshakeCompleted(this.remotePeerDescriptor!)
|
|
323
301
|
}
|
|
324
302
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
if (!this.doNotEmitDisconnected) {
|
|
329
|
-
logger.trace(keyOrUnknownFromPeerDescriptor(this.peerDescriptor) + ' emitting disconnected')
|
|
330
|
-
this.emit('disconnected', disconnectionType)
|
|
331
|
-
} else {
|
|
332
|
-
logger.trace(keyOrUnknownFromPeerDescriptor(this.peerDescriptor) + ' not emitting disconnected because doNotEmitDisconnected flag is set')
|
|
333
|
-
}
|
|
303
|
+
public rejectHandshake(error: HandshakeError): void {
|
|
304
|
+
this.handshaker!.sendHandshakeResponse(error)
|
|
305
|
+
this.destroy()
|
|
334
306
|
}
|
|
335
307
|
|
|
336
|
-
public async close(
|
|
308
|
+
public async close(gracefulLeave: boolean): Promise<void> {
|
|
337
309
|
if (this.replacedByOtherConnection) {
|
|
338
310
|
logger.trace('close() called on replaced connection')
|
|
339
311
|
}
|
|
340
312
|
this.closing = true
|
|
313
|
+
|
|
314
|
+
this.outputBufferEmitter.emit('bufferSendingFailed')
|
|
341
315
|
this.emit('closing')
|
|
342
|
-
|
|
316
|
+
|
|
343
317
|
if (this.implementation) {
|
|
344
|
-
await this.implementation?.close(
|
|
318
|
+
await this.implementation?.close(gracefulLeave)
|
|
345
319
|
} else if (this.outgoingConnection) {
|
|
346
|
-
await this.outgoingConnection?.close(
|
|
320
|
+
await this.outgoingConnection?.close(gracefulLeave)
|
|
347
321
|
} else if (this.incomingConnection) {
|
|
348
|
-
await this.incomingConnection?.close(
|
|
322
|
+
await this.incomingConnection?.close(gracefulLeave)
|
|
349
323
|
} else {
|
|
350
|
-
this.
|
|
324
|
+
this.emit('disconnected', gracefulLeave)
|
|
351
325
|
}
|
|
352
326
|
}
|
|
353
327
|
|
|
354
328
|
public destroy(): void {
|
|
355
329
|
this.closing = true
|
|
330
|
+
|
|
356
331
|
this.emit('closing')
|
|
357
332
|
if (!this.stopped) {
|
|
358
333
|
this.stopped = true
|
|
@@ -1,25 +1,27 @@
|
|
|
1
1
|
import { PeerDescriptor } from '../proto/packages/dht/protos/DhtRpc'
|
|
2
2
|
import { ConnectionType } from './IConnection'
|
|
3
3
|
import { ManagedConnection } from './ManagedConnection'
|
|
4
|
-
import {
|
|
4
|
+
import { NodeWebrtcConnection } from './webrtc/NodeWebrtcConnection'
|
|
5
5
|
|
|
6
|
-
export class
|
|
6
|
+
export class ManagedWebrtcConnection extends ManagedConnection {
|
|
7
7
|
|
|
8
|
-
constructor(
|
|
9
|
-
connectingConnection?:
|
|
10
|
-
connectedConnection?:
|
|
8
|
+
constructor(localPeerDescriptor: PeerDescriptor,
|
|
9
|
+
connectingConnection?: NodeWebrtcConnection,
|
|
10
|
+
connectedConnection?: NodeWebrtcConnection
|
|
11
|
+
) {
|
|
11
12
|
super(
|
|
12
|
-
|
|
13
|
+
localPeerDescriptor,
|
|
13
14
|
ConnectionType.WEBRTC,
|
|
14
15
|
connectingConnection,
|
|
15
|
-
connectedConnection
|
|
16
|
+
connectedConnection
|
|
17
|
+
)
|
|
16
18
|
}
|
|
17
19
|
|
|
18
|
-
public
|
|
20
|
+
public getWebrtcConnection(): NodeWebrtcConnection {
|
|
19
21
|
if (this.outgoingConnection) {
|
|
20
|
-
return this.outgoingConnection as unknown as
|
|
22
|
+
return this.outgoingConnection as unknown as NodeWebrtcConnection
|
|
21
23
|
} else {
|
|
22
|
-
return this.incomingConnection as unknown as
|
|
24
|
+
return this.incomingConnection as unknown as NodeWebrtcConnection
|
|
23
25
|
}
|
|
24
26
|
}
|
|
25
27
|
}
|
|
@@ -333,7 +333,7 @@ export class Simulator extends EventEmitter<ConnectionSourceEvents> {
|
|
|
333
333
|
const association = new Association(sourceConnection, undefined, connectedCallback)
|
|
334
334
|
this.associations.set(sourceConnection.connectionId, association)
|
|
335
335
|
|
|
336
|
-
const executionTime = this.generateExecutionTime(association, sourceConnection.
|
|
336
|
+
const executionTime = this.generateExecutionTime(association, sourceConnection.localPeerDescriptor.region, targetDescriptor.region)
|
|
337
337
|
association.setLastOperationAt(executionTime)
|
|
338
338
|
|
|
339
339
|
const operation = new ConnectOperation(executionTime, association,
|
|
@@ -356,7 +356,7 @@ export class Simulator extends EventEmitter<ConnectionSourceEvents> {
|
|
|
356
356
|
association.setClosing()
|
|
357
357
|
|
|
358
358
|
const executionTime = this.generateExecutionTime(association,
|
|
359
|
-
sourceConnection.
|
|
359
|
+
sourceConnection.localPeerDescriptor.region,
|
|
360
360
|
sourceConnection.getPeerDescriptor()?.region)
|
|
361
361
|
association.setLastOperationAt(executionTime)
|
|
362
362
|
|
|
@@ -382,8 +382,8 @@ export class Simulator extends EventEmitter<ConnectionSourceEvents> {
|
|
|
382
382
|
}
|
|
383
383
|
|
|
384
384
|
const executionTime = this.generateExecutionTime(association,
|
|
385
|
-
sourceConnection.
|
|
386
|
-
association.destinationConnection!.
|
|
385
|
+
sourceConnection.localPeerDescriptor.region,
|
|
386
|
+
association.destinationConnection!.localPeerDescriptor.region)
|
|
387
387
|
|
|
388
388
|
association.setLastOperationAt(executionTime)
|
|
389
389
|
|
|
@@ -4,27 +4,26 @@ import { Message, PeerDescriptor } from '../../proto/packages/dht/protos/DhtRpc'
|
|
|
4
4
|
import { Connection } from '../Connection'
|
|
5
5
|
import { Logger } from '@streamr/utils'
|
|
6
6
|
import { protoToString } from '../../helpers/protoToString'
|
|
7
|
-
import {
|
|
8
|
-
import { keyFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
|
|
7
|
+
import { getNodeIdFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
|
|
9
8
|
|
|
10
9
|
const logger = new Logger(module)
|
|
11
10
|
|
|
12
11
|
export class SimulatorConnection extends Connection implements IConnection {
|
|
13
12
|
|
|
14
13
|
private stopped = false
|
|
15
|
-
public
|
|
14
|
+
public localPeerDescriptor: PeerDescriptor
|
|
16
15
|
private targetPeerDescriptor: PeerDescriptor
|
|
17
16
|
private simulator: Simulator
|
|
18
17
|
|
|
19
18
|
constructor(
|
|
20
|
-
|
|
19
|
+
localPeerDescriptor: PeerDescriptor,
|
|
21
20
|
targetPeerDescriptor: PeerDescriptor,
|
|
22
21
|
connectionType: ConnectionType,
|
|
23
22
|
simulator: Simulator
|
|
24
23
|
) {
|
|
25
24
|
super(connectionType)
|
|
26
25
|
|
|
27
|
-
this.
|
|
26
|
+
this.localPeerDescriptor = localPeerDescriptor
|
|
28
27
|
this.setPeerDescriptor(targetPeerDescriptor)
|
|
29
28
|
this.targetPeerDescriptor = targetPeerDescriptor
|
|
30
29
|
this.connectionType = connectionType
|
|
@@ -46,36 +45,37 @@ export class SimulatorConnection extends Connection implements IConnection {
|
|
|
46
45
|
this.simulator.send(this, data)
|
|
47
46
|
|
|
48
47
|
} else {
|
|
49
|
-
logger.error(
|
|
48
|
+
logger.error(getNodeIdFromPeerDescriptor(this.localPeerDescriptor) + ', ' + getNodeIdFromPeerDescriptor(this.targetPeerDescriptor) +
|
|
50
49
|
'tried to send() on a stopped connection')
|
|
51
50
|
}
|
|
52
51
|
}
|
|
53
52
|
|
|
54
|
-
public async close(
|
|
55
|
-
logger.trace(
|
|
53
|
+
public async close(gracefulLeave: boolean): Promise<void> {
|
|
54
|
+
logger.trace(getNodeIdFromPeerDescriptor(this.localPeerDescriptor)
|
|
55
|
+
+ ', ' + getNodeIdFromPeerDescriptor(this.targetPeerDescriptor) + ' close()')
|
|
56
56
|
|
|
57
57
|
if (!this.stopped) {
|
|
58
|
-
logger.trace(
|
|
59
|
-
+
|
|
58
|
+
logger.trace(getNodeIdFromPeerDescriptor(this.localPeerDescriptor) + ', '
|
|
59
|
+
+ getNodeIdFromPeerDescriptor(this.targetPeerDescriptor) + ' close() not stopped')
|
|
60
60
|
this.stopped = true
|
|
61
61
|
|
|
62
62
|
try {
|
|
63
|
-
logger.trace(
|
|
63
|
+
logger.trace(getNodeIdFromPeerDescriptor(this.localPeerDescriptor) + ', ' + getNodeIdFromPeerDescriptor(this.targetPeerDescriptor) +
|
|
64
64
|
' close() calling simulator.disconnect()')
|
|
65
65
|
this.simulator.close(this)
|
|
66
|
-
logger.trace(
|
|
66
|
+
logger.trace(getNodeIdFromPeerDescriptor(this.localPeerDescriptor) + ', ' + getNodeIdFromPeerDescriptor(this.targetPeerDescriptor) +
|
|
67
67
|
' close() simulator.disconnect returned')
|
|
68
68
|
} catch (e) {
|
|
69
|
-
logger.trace(
|
|
69
|
+
logger.trace(getNodeIdFromPeerDescriptor(this.localPeerDescriptor) + ', ' + getNodeIdFromPeerDescriptor(this.targetPeerDescriptor) +
|
|
70
70
|
'close aborted' + e)
|
|
71
71
|
} finally {
|
|
72
|
-
logger.trace(
|
|
72
|
+
logger.trace(getNodeIdFromPeerDescriptor(this.localPeerDescriptor) + ', ' + getNodeIdFromPeerDescriptor(this.targetPeerDescriptor) +
|
|
73
73
|
' calling this.doDisconnect')
|
|
74
|
-
this.doDisconnect(
|
|
74
|
+
this.doDisconnect(gracefulLeave)
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
} else {
|
|
78
|
-
logger.trace(
|
|
78
|
+
logger.trace(getNodeIdFromPeerDescriptor(this.localPeerDescriptor) + ', ' + getNodeIdFromPeerDescriptor(this.targetPeerDescriptor) +
|
|
79
79
|
' close() tried to close a stopped connection')
|
|
80
80
|
}
|
|
81
81
|
}
|
|
@@ -87,7 +87,7 @@ export class SimulatorConnection extends Connection implements IConnection {
|
|
|
87
87
|
this.simulator.connect(this, this.targetPeerDescriptor, (error?: string) => {
|
|
88
88
|
if (error) {
|
|
89
89
|
logger.trace(error)
|
|
90
|
-
this.doDisconnect(
|
|
90
|
+
this.doDisconnect(false)
|
|
91
91
|
} else {
|
|
92
92
|
this.emit('connected')
|
|
93
93
|
}
|
|
@@ -109,9 +109,9 @@ export class SimulatorConnection extends Connection implements IConnection {
|
|
|
109
109
|
|
|
110
110
|
public handleIncomingDisconnection(): void {
|
|
111
111
|
if (!this.stopped) {
|
|
112
|
-
logger.trace(
|
|
112
|
+
logger.trace(getNodeIdFromPeerDescriptor(this.localPeerDescriptor) + ' handleIncomingDisconnection()')
|
|
113
113
|
this.stopped = true
|
|
114
|
-
this.doDisconnect(
|
|
114
|
+
this.doDisconnect(false)
|
|
115
115
|
} else {
|
|
116
116
|
logger.trace('tried to call handleIncomingDisconnection() a stopped connection')
|
|
117
117
|
}
|
|
@@ -119,22 +119,22 @@ export class SimulatorConnection extends Connection implements IConnection {
|
|
|
119
119
|
|
|
120
120
|
public destroy(): void {
|
|
121
121
|
if (!this.stopped) {
|
|
122
|
-
logger.trace(
|
|
122
|
+
logger.trace(getNodeIdFromPeerDescriptor(this.localPeerDescriptor) + ' destroy()')
|
|
123
123
|
this.removeAllListeners()
|
|
124
|
-
this.close(
|
|
124
|
+
this.close(false).catch((_e) => { })
|
|
125
125
|
} else {
|
|
126
|
-
logger.trace(
|
|
126
|
+
logger.trace(getNodeIdFromPeerDescriptor(this.localPeerDescriptor) + ' tried to call destroy() a stopped connection')
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
-
private doDisconnect(
|
|
131
|
-
logger.trace(
|
|
130
|
+
private doDisconnect(gracefulLeave: boolean) {
|
|
131
|
+
logger.trace(getNodeIdFromPeerDescriptor(this.localPeerDescriptor) + ' doDisconnect()')
|
|
132
132
|
this.stopped = true
|
|
133
133
|
|
|
134
|
-
logger.trace(
|
|
135
|
-
+
|
|
134
|
+
logger.trace(getNodeIdFromPeerDescriptor(this.localPeerDescriptor) + ', '
|
|
135
|
+
+ getNodeIdFromPeerDescriptor(this.targetPeerDescriptor) + ' doDisconnect emitting')
|
|
136
136
|
|
|
137
|
-
this.emit('disconnected',
|
|
137
|
+
this.emit('disconnected', gracefulLeave)
|
|
138
138
|
|
|
139
139
|
}
|
|
140
140
|
}
|