@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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ServiceID.js","sourceRoot":"","sources":["../../../src/types/ServiceID.ts"],"names":[],"mappings":""}
|
package/karma.config.js
CHANGED
|
@@ -5,16 +5,16 @@ const { createKarmaConfig, createWebpackConfig } = require('@streamr/browser-tes
|
|
|
5
5
|
const TEST_PATHS = [
|
|
6
6
|
'test/unit/**/*.ts',
|
|
7
7
|
'./test/integration/**/!(DhtWith*|MigrateData*).ts/',
|
|
8
|
-
'test/end-to-end
|
|
8
|
+
'./test/end-to-end/**/!(RecoveryFromFailedAutoCertification*|memory-leak*).ts'
|
|
9
9
|
]
|
|
10
10
|
|
|
11
|
-
const
|
|
12
|
-
const
|
|
11
|
+
const NodeWebrtcConnection = path.resolve(__dirname, 'src/connection/webrtc/NodeWebrtcConnection.ts')
|
|
12
|
+
const BrowserWebrtcConnection = path.resolve(__dirname, 'src/connection/webrtc/BrowserWebrtcConnection.ts')
|
|
13
13
|
|
|
14
14
|
module.exports = createKarmaConfig(TEST_PATHS, createWebpackConfig({
|
|
15
15
|
entry: './src/exports.ts',
|
|
16
16
|
libraryName: 'dht',
|
|
17
17
|
alias: {
|
|
18
|
-
[
|
|
18
|
+
[NodeWebrtcConnection]: BrowserWebrtcConnection
|
|
19
19
|
}
|
|
20
20
|
}))
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@streamr/dht",
|
|
3
|
-
"version": "100.0.0-pretestnet.
|
|
3
|
+
"version": "100.0.0-pretestnet.4",
|
|
4
4
|
"description": "Streamr Network DHT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -31,8 +31,9 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@protobuf-ts/runtime": "^2.8.2",
|
|
33
33
|
"@protobuf-ts/runtime-rpc": "^2.8.2",
|
|
34
|
-
"@streamr/
|
|
35
|
-
"@streamr/
|
|
34
|
+
"@streamr/autocertifier-client": "100.0.0-pretestnet.4",
|
|
35
|
+
"@streamr/proto-rpc": "100.0.0-pretestnet.4",
|
|
36
|
+
"@streamr/utils": "100.0.0-pretestnet.4",
|
|
36
37
|
"eventemitter3": "^5.0.0",
|
|
37
38
|
"heap": "^0.2.6",
|
|
38
39
|
"ipaddr.js": "^2.0.1",
|
|
@@ -45,15 +46,16 @@
|
|
|
45
46
|
},
|
|
46
47
|
"devDependencies": {
|
|
47
48
|
"@streamr/browser-test-runner": "^0.0.1",
|
|
48
|
-
"@streamr/test-utils": "100.0.0-pretestnet.
|
|
49
|
-
"@types/express": "^4.17.
|
|
50
|
-
"@types/heap": "^0.2.
|
|
49
|
+
"@streamr/test-utils": "100.0.0-pretestnet.4",
|
|
50
|
+
"@types/express": "^4.17.21",
|
|
51
|
+
"@types/heap": "^0.2.34",
|
|
51
52
|
"@types/k-bucket": "^5.0.1",
|
|
52
|
-
"@types/lodash": "^4.14.
|
|
53
|
+
"@types/lodash": "^4.14.201",
|
|
53
54
|
"@types/sinon": "^10.0.15",
|
|
54
|
-
"@types/uuid": "^9.0.
|
|
55
|
+
"@types/uuid": "^9.0.7",
|
|
55
56
|
"@types/websocket": "^1.0.3",
|
|
56
57
|
"express": "^4.17.1",
|
|
58
|
+
"jest-leak-detector": "^27.3.1",
|
|
57
59
|
"patch-package": "^8.0.0",
|
|
58
60
|
"ts-essentials": "^9.4.1",
|
|
59
61
|
"ts-node": "^10.9.1"
|
package/protos/DhtRpc.proto
CHANGED
|
@@ -8,7 +8,7 @@ import "google/protobuf/any.proto";
|
|
|
8
8
|
import "google/protobuf/timestamp.proto";
|
|
9
9
|
import "packages/proto-rpc/protos/ProtoRpc.proto";
|
|
10
10
|
|
|
11
|
-
service
|
|
11
|
+
service DhtNodeRpc {
|
|
12
12
|
rpc getClosestPeers (ClosestPeersRequest) returns (ClosestPeersResponse);
|
|
13
13
|
rpc ping (PingRequest) returns (PingResponse);
|
|
14
14
|
rpc leaveNotice (LeaveNotice) returns (google.protobuf.Empty);
|
|
@@ -17,7 +17,10 @@ service DhtRpcService {
|
|
|
17
17
|
service RouterRpc {
|
|
18
18
|
rpc routeMessage (RouteMessageWrapper) returns (RouteMessageAck);
|
|
19
19
|
rpc forwardMessage (RouteMessageWrapper) returns (RouteMessageAck);
|
|
20
|
-
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
service FindRpc {
|
|
23
|
+
rpc routeFindRequest (RouteMessageWrapper) returns (RouteMessageAck);
|
|
21
24
|
}
|
|
22
25
|
|
|
23
26
|
service StoreRpc {
|
|
@@ -26,16 +29,16 @@ service StoreRpc {
|
|
|
26
29
|
rpc deleteData (DeleteDataRequest) returns (DeleteDataResponse);
|
|
27
30
|
}
|
|
28
31
|
|
|
29
|
-
service
|
|
32
|
+
service FindSessionRpc {
|
|
30
33
|
rpc sendFindResponse(FindResponse) returns (google.protobuf.Empty);
|
|
31
34
|
}
|
|
32
35
|
|
|
33
|
-
service
|
|
34
|
-
rpc requestConnection (
|
|
36
|
+
service WebsocketConnectorRpc {
|
|
37
|
+
rpc requestConnection (WebsocketConnectionRequest) returns (WebsocketConnectionResponse);
|
|
35
38
|
}
|
|
36
39
|
|
|
37
|
-
service
|
|
38
|
-
rpc requestConnection (
|
|
40
|
+
service WebrtcConnectorRpc {
|
|
41
|
+
rpc requestConnection (WebrtcConnectionRequest) returns (google.protobuf.Empty);
|
|
39
42
|
rpc rtcOffer (RtcOffer) returns (google.protobuf.Empty);
|
|
40
43
|
rpc rtcAnswer (RtcAnswer) returns (google.protobuf.Empty);
|
|
41
44
|
rpc iceCandidate (IceCandidate) returns (google.protobuf.Empty);
|
|
@@ -48,7 +51,7 @@ service ConnectionLockRpc {
|
|
|
48
51
|
}
|
|
49
52
|
|
|
50
53
|
service ExternalApiRpc {
|
|
51
|
-
rpc
|
|
54
|
+
rpc externalFindData (ExternalFindDataRequest) returns (ExternalFindDataResponse);
|
|
52
55
|
rpc externalStoreData (ExternalStoreDataRequest) returns (ExternalStoreDataResponse);
|
|
53
56
|
}
|
|
54
57
|
|
|
@@ -141,8 +144,7 @@ message PeerDescriptor {
|
|
|
141
144
|
ConnectivityMethod udp = 3;
|
|
142
145
|
ConnectivityMethod tcp = 4;
|
|
143
146
|
ConnectivityMethod websocket = 5;
|
|
144
|
-
optional
|
|
145
|
-
optional uint32 region = 7;
|
|
147
|
+
optional uint32 region = 6;
|
|
146
148
|
}
|
|
147
149
|
|
|
148
150
|
message ConnectivityMethod {
|
|
@@ -168,10 +170,9 @@ message RouteMessageWrapper {
|
|
|
168
170
|
PeerDescriptor sourcePeer = 1;
|
|
169
171
|
string requestId = 2;
|
|
170
172
|
PeerDescriptor destinationPeer = 3;
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
repeated PeerDescriptor
|
|
174
|
-
repeated PeerDescriptor routingPath = 7;
|
|
173
|
+
Message message = 4;
|
|
174
|
+
repeated PeerDescriptor reachableThrough = 5;
|
|
175
|
+
repeated PeerDescriptor routingPath = 6;
|
|
175
176
|
}
|
|
176
177
|
|
|
177
178
|
message RouteMessageAck {
|
|
@@ -185,35 +186,39 @@ message ConnectivityRequest {
|
|
|
185
186
|
uint32 port = 1;
|
|
186
187
|
bool tls = 2;
|
|
187
188
|
optional string host = 3;
|
|
189
|
+
bool selfSigned = 4;
|
|
188
190
|
}
|
|
189
191
|
|
|
190
192
|
message ConnectivityResponse {
|
|
191
|
-
|
|
192
|
-
string
|
|
193
|
-
|
|
194
|
-
ConnectivityMethod websocket = 4;
|
|
193
|
+
string host = 1;
|
|
194
|
+
string natType = 2;
|
|
195
|
+
ConnectivityMethod websocket = 3;
|
|
195
196
|
}
|
|
196
197
|
|
|
197
198
|
message HandshakeRequest {
|
|
198
|
-
|
|
199
|
-
PeerDescriptor
|
|
199
|
+
PeerDescriptor sourcePeerDescriptor = 1;
|
|
200
|
+
optional PeerDescriptor targetPeerDescriptor = 2;
|
|
200
201
|
}
|
|
201
202
|
|
|
202
203
|
message HandshakeResponse {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
204
|
+
PeerDescriptor sourcePeerDescriptor = 1;
|
|
205
|
+
optional HandshakeError error = 2;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
enum HandshakeError {
|
|
209
|
+
DUPLICATE_CONNECTION = 0;
|
|
210
|
+
INVALID_TARGET_PEER_DESCRIPTOR = 1;
|
|
206
211
|
}
|
|
207
212
|
|
|
208
213
|
// Wraps all messages
|
|
209
214
|
|
|
210
215
|
enum MessageType {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
216
|
+
RPC = 0;
|
|
217
|
+
CONNECTIVITY_REQUEST = 1;
|
|
218
|
+
CONNECTIVITY_RESPONSE = 2;
|
|
219
|
+
HANDSHAKE_REQUEST = 3;
|
|
220
|
+
HANDSHAKE_RESPONSE = 4;
|
|
221
|
+
FIND_REQUEST = 5;
|
|
217
222
|
}
|
|
218
223
|
|
|
219
224
|
message Message {
|
|
@@ -235,19 +240,15 @@ message Message {
|
|
|
235
240
|
// Connector Messages
|
|
236
241
|
|
|
237
242
|
// WebSocket
|
|
238
|
-
message
|
|
239
|
-
string ip = 1;
|
|
240
|
-
uint32 port = 2;
|
|
243
|
+
message WebsocketConnectionRequest {
|
|
241
244
|
}
|
|
242
245
|
|
|
243
|
-
message
|
|
246
|
+
message WebsocketConnectionResponse {
|
|
244
247
|
bool accepted = 1;
|
|
245
|
-
optional string reason = 2;
|
|
246
248
|
}
|
|
247
249
|
|
|
248
250
|
// WebRTC
|
|
249
|
-
message
|
|
250
|
-
string connectionId = 1;
|
|
251
|
+
message WebrtcConnectionRequest {
|
|
251
252
|
}
|
|
252
253
|
|
|
253
254
|
message RtcOffer {
|
|
@@ -267,11 +268,11 @@ message IceCandidate {
|
|
|
267
268
|
}
|
|
268
269
|
|
|
269
270
|
message LockRequest {
|
|
270
|
-
string
|
|
271
|
+
string lockId = 1;
|
|
271
272
|
}
|
|
272
273
|
|
|
273
274
|
message UnlockRequest {
|
|
274
|
-
string
|
|
275
|
+
string lockId = 1;
|
|
275
276
|
}
|
|
276
277
|
|
|
277
278
|
message LockResponse {
|
|
@@ -291,11 +292,11 @@ message DisconnectNotice {
|
|
|
291
292
|
message DisconnectNoticeResponse {
|
|
292
293
|
}
|
|
293
294
|
|
|
294
|
-
message
|
|
295
|
+
message ExternalFindDataRequest {
|
|
295
296
|
bytes kademliaId = 1;
|
|
296
297
|
}
|
|
297
298
|
|
|
298
|
-
message
|
|
299
|
+
message ExternalFindDataResponse {
|
|
299
300
|
repeated DataEntry dataEntries = 1;
|
|
300
301
|
optional string error = 2;
|
|
301
302
|
}
|
|
@@ -3,12 +3,14 @@
|
|
|
3
3
|
|
|
4
4
|
import { PeerIDKey } from '../helpers/PeerID'
|
|
5
5
|
|
|
6
|
-
type
|
|
6
|
+
export type LockID = string
|
|
7
7
|
|
|
8
8
|
export class ConnectionLockHandler {
|
|
9
9
|
|
|
10
|
-
private localLocks: Map<PeerIDKey, Set<
|
|
11
|
-
private remoteLocks: Map<PeerIDKey, Set<
|
|
10
|
+
private localLocks: Map<PeerIDKey, Set<LockID>> = new Map()
|
|
11
|
+
private remoteLocks: Map<PeerIDKey, Set<LockID>> = new Map()
|
|
12
|
+
// TODO: remove weakLocks use localLocks instead. When opening weakLocks from the ConnectioManager,
|
|
13
|
+
// simply do not send lock requests.
|
|
12
14
|
private weakLocks: Set<PeerIDKey> = new Set()
|
|
13
15
|
|
|
14
16
|
public getNumberOfLocalLockedConnections(): number {
|
|
@@ -23,19 +25,19 @@ export class ConnectionLockHandler {
|
|
|
23
25
|
return this.weakLocks.size
|
|
24
26
|
}
|
|
25
27
|
|
|
26
|
-
public isLocalLocked(id: PeerIDKey,
|
|
27
|
-
if (!
|
|
28
|
+
public isLocalLocked(id: PeerIDKey, lockId?: LockID): boolean {
|
|
29
|
+
if (!lockId) {
|
|
28
30
|
return this.localLocks.has(id)
|
|
29
31
|
} else {
|
|
30
|
-
return this.localLocks.has(id) && this.localLocks.get(id)!.has(
|
|
32
|
+
return this.localLocks.has(id) && this.localLocks.get(id)!.has(lockId)
|
|
31
33
|
}
|
|
32
34
|
}
|
|
33
35
|
|
|
34
|
-
public isRemoteLocked(id: PeerIDKey,
|
|
35
|
-
if (!
|
|
36
|
+
public isRemoteLocked(id: PeerIDKey, lockId?: LockID): boolean {
|
|
37
|
+
if (!lockId) {
|
|
36
38
|
return this.remoteLocks.has(id)
|
|
37
39
|
} else {
|
|
38
|
-
if (this.remoteLocks.has(id) && this.remoteLocks.get(id)!.has(
|
|
40
|
+
if (this.remoteLocks.has(id) && this.remoteLocks.get(id)!.has(lockId)) {
|
|
39
41
|
return true
|
|
40
42
|
} else {
|
|
41
43
|
return false
|
|
@@ -51,36 +53,36 @@ export class ConnectionLockHandler {
|
|
|
51
53
|
return (this.isLocalLocked(id) || this.isRemoteLocked(id) || this.isWeakLocked(id))
|
|
52
54
|
}
|
|
53
55
|
|
|
54
|
-
public addLocalLocked(id: PeerIDKey,
|
|
56
|
+
public addLocalLocked(id: PeerIDKey, lockId: LockID): void {
|
|
55
57
|
if (!this.localLocks.has(id)) {
|
|
56
58
|
this.localLocks.set(id, new Set())
|
|
57
59
|
}
|
|
58
|
-
this.localLocks.get(id)!.add(
|
|
60
|
+
this.localLocks.get(id)!.add(lockId)
|
|
59
61
|
}
|
|
60
62
|
|
|
61
|
-
public addRemoteLocked(id: PeerIDKey,
|
|
63
|
+
public addRemoteLocked(id: PeerIDKey, lockId: LockID): void {
|
|
62
64
|
if (!this.remoteLocks.has(id)) {
|
|
63
65
|
this.remoteLocks.set(id, new Set())
|
|
64
66
|
}
|
|
65
|
-
this.remoteLocks.get(id)!.add(
|
|
67
|
+
this.remoteLocks.get(id)!.add(lockId)
|
|
66
68
|
}
|
|
67
69
|
|
|
68
70
|
public addWeakLocked(id: PeerIDKey): void {
|
|
69
71
|
this.weakLocks.add(id)
|
|
70
72
|
}
|
|
71
73
|
|
|
72
|
-
public removeLocalLocked(id: PeerIDKey,
|
|
74
|
+
public removeLocalLocked(id: PeerIDKey, lockId: LockID): void {
|
|
73
75
|
if (this.localLocks.has(id)) {
|
|
74
|
-
this.localLocks.get(id)?.delete(
|
|
76
|
+
this.localLocks.get(id)?.delete(lockId)
|
|
75
77
|
if (this.localLocks.get(id)?.size === 0) {
|
|
76
78
|
this.localLocks.delete(id)
|
|
77
79
|
}
|
|
78
80
|
}
|
|
79
81
|
}
|
|
80
82
|
|
|
81
|
-
public removeRemoteLocked(id: PeerIDKey,
|
|
83
|
+
public removeRemoteLocked(id: PeerIDKey, lockId: LockID): void {
|
|
82
84
|
if (this.remoteLocks.has(id)) {
|
|
83
|
-
this.remoteLocks.get(id)?.delete(
|
|
85
|
+
this.remoteLocks.get(id)?.delete(lockId)
|
|
84
86
|
if (this.remoteLocks.get(id)?.size === 0) {
|
|
85
87
|
this.remoteLocks.delete(id)
|
|
86
88
|
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
2
|
+
import { Logger } from '@streamr/utils'
|
|
3
|
+
import {
|
|
4
|
+
areEqualPeerDescriptors,
|
|
5
|
+
keyFromPeerDescriptor,
|
|
6
|
+
peerIdFromPeerDescriptor
|
|
7
|
+
} from '../helpers/peerIdFromPeerDescriptor'
|
|
8
|
+
import { Empty } from '../proto/google/protobuf/empty'
|
|
9
|
+
import {
|
|
10
|
+
DisconnectMode,
|
|
11
|
+
DisconnectNotice,
|
|
12
|
+
LockRequest,
|
|
13
|
+
LockResponse,
|
|
14
|
+
PeerDescriptor,
|
|
15
|
+
UnlockRequest
|
|
16
|
+
} from '../proto/packages/dht/protos/DhtRpc'
|
|
17
|
+
import { IConnectionLockRpc } from '../proto/packages/dht/protos/DhtRpc.server'
|
|
18
|
+
import { DhtCallContext } from '../rpc-protocol/DhtCallContext'
|
|
19
|
+
import { PeerIDKey } from '../helpers/PeerID'
|
|
20
|
+
import { getNodeIdOrUnknownFromPeerDescriptor } from './ConnectionManager'
|
|
21
|
+
import { LockID } from './ConnectionLockHandler'
|
|
22
|
+
|
|
23
|
+
interface ConnectionLockRpcLocalConfig {
|
|
24
|
+
addRemoteLocked: (id: PeerIDKey, lockId: LockID) => void
|
|
25
|
+
removeRemoteLocked: (id: PeerIDKey, lockId: LockID) => void
|
|
26
|
+
closeConnection: (peerDescriptor: PeerDescriptor, gracefulLeave: boolean, reason?: string) => void
|
|
27
|
+
getLocalPeerDescriptor: () => PeerDescriptor
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const logger = new Logger(module)
|
|
31
|
+
|
|
32
|
+
export class ConnectionLockRpcLocal implements IConnectionLockRpc {
|
|
33
|
+
|
|
34
|
+
private readonly config: ConnectionLockRpcLocalConfig
|
|
35
|
+
|
|
36
|
+
constructor(config: ConnectionLockRpcLocalConfig) {
|
|
37
|
+
this.config = config
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async lockRequest(lockRequest: LockRequest, context: ServerCallContext): Promise<LockResponse> {
|
|
41
|
+
const senderPeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
|
|
42
|
+
const remotePeerId = peerIdFromPeerDescriptor(senderPeerDescriptor)
|
|
43
|
+
if (areEqualPeerDescriptors(senderPeerDescriptor, this.config.getLocalPeerDescriptor())) {
|
|
44
|
+
const response: LockResponse = {
|
|
45
|
+
accepted: false
|
|
46
|
+
}
|
|
47
|
+
return response
|
|
48
|
+
}
|
|
49
|
+
this.config.addRemoteLocked(remotePeerId.toKey(), lockRequest.lockId)
|
|
50
|
+
const response: LockResponse = {
|
|
51
|
+
accepted: true
|
|
52
|
+
}
|
|
53
|
+
return response
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async unlockRequest(unlockRequest: UnlockRequest, context: ServerCallContext): Promise<Empty> {
|
|
57
|
+
const senderPeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
|
|
58
|
+
const peerIdKey = keyFromPeerDescriptor(senderPeerDescriptor)
|
|
59
|
+
this.config.removeRemoteLocked(peerIdKey, unlockRequest.lockId)
|
|
60
|
+
return {}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async gracefulDisconnect(disconnectNotice: DisconnectNotice, context: ServerCallContext): Promise<Empty> {
|
|
64
|
+
const senderPeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
|
|
65
|
+
logger.trace(getNodeIdOrUnknownFromPeerDescriptor(senderPeerDescriptor) + ' received gracefulDisconnect notice')
|
|
66
|
+
|
|
67
|
+
if (disconnectNotice.disconnectMode === DisconnectMode.LEAVING) {
|
|
68
|
+
this.config.closeConnection(senderPeerDescriptor, true, 'graceful leave notified')
|
|
69
|
+
} else {
|
|
70
|
+
this.config.closeConnection(senderPeerDescriptor, false, 'graceful disconnect notified')
|
|
71
|
+
}
|
|
72
|
+
return {}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -2,27 +2,27 @@ import { Logger } from '@streamr/utils'
|
|
|
2
2
|
import { ProtoRpcClient } from '@streamr/proto-rpc'
|
|
3
3
|
import { IConnectionLockRpcClient } from '../proto/packages/dht/protos/DhtRpc.client'
|
|
4
4
|
import { LockRequest, UnlockRequest, PeerDescriptor, DisconnectNotice, DisconnectMode } from '../proto/packages/dht/protos/DhtRpc'
|
|
5
|
-
|
|
6
5
|
import * as Err from '../helpers/errors'
|
|
7
|
-
import {
|
|
6
|
+
import { getNodeIdFromPeerDescriptor } from '../helpers/peerIdFromPeerDescriptor'
|
|
8
7
|
import { Remote } from '../dht/contact/Remote'
|
|
8
|
+
import { LockID } from './ConnectionLockHandler'
|
|
9
9
|
|
|
10
10
|
const logger = new Logger(module)
|
|
11
11
|
|
|
12
12
|
export class ConnectionLockRpcRemote extends Remote<IConnectionLockRpcClient> {
|
|
13
13
|
|
|
14
14
|
constructor(
|
|
15
|
-
|
|
15
|
+
localPeerDescriptor: PeerDescriptor,
|
|
16
16
|
targetPeerDescriptor: PeerDescriptor,
|
|
17
17
|
client: ProtoRpcClient<IConnectionLockRpcClient>
|
|
18
18
|
) {
|
|
19
|
-
super(
|
|
19
|
+
super(localPeerDescriptor, targetPeerDescriptor, 'DUMMY', client)
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
public async lockRequest(
|
|
23
|
-
logger.trace(`Requesting locked connection to ${
|
|
22
|
+
public async lockRequest(lockId: LockID): Promise<boolean> {
|
|
23
|
+
logger.trace(`Requesting locked connection to ${getNodeIdFromPeerDescriptor(this.getPeerDescriptor())}`)
|
|
24
24
|
const request: LockRequest = {
|
|
25
|
-
|
|
25
|
+
lockId
|
|
26
26
|
}
|
|
27
27
|
const options = this.formDhtRpcOptions()
|
|
28
28
|
try {
|
|
@@ -34,10 +34,10 @@ export class ConnectionLockRpcRemote extends Remote<IConnectionLockRpcClient> {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
public unlockRequest(
|
|
38
|
-
logger.trace(`Requesting connection to be unlocked from ${
|
|
37
|
+
public unlockRequest(lockId: LockID): void {
|
|
38
|
+
logger.trace(`Requesting connection to be unlocked from ${getNodeIdFromPeerDescriptor(this.getPeerDescriptor())}`)
|
|
39
39
|
const request: UnlockRequest = {
|
|
40
|
-
|
|
40
|
+
lockId
|
|
41
41
|
}
|
|
42
42
|
const options = this.formDhtRpcOptions({
|
|
43
43
|
notification: true
|
|
@@ -48,7 +48,7 @@ export class ConnectionLockRpcRemote extends Remote<IConnectionLockRpcClient> {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
public async gracefulDisconnect(disconnectMode: DisconnectMode): Promise<void> {
|
|
51
|
-
logger.trace(`Notifying a graceful disconnect to ${
|
|
51
|
+
logger.trace(`Notifying a graceful disconnect to ${getNodeIdFromPeerDescriptor(this.getPeerDescriptor())}`)
|
|
52
52
|
const request: DisconnectNotice = {
|
|
53
53
|
disconnectMode
|
|
54
54
|
}
|