@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,36 +1,33 @@
|
|
|
1
|
-
import { Logger } from '@streamr/utils'
|
|
2
1
|
import EventEmitter from 'eventemitter3'
|
|
3
2
|
import { PeerID, PeerIDKey } from '../../helpers/PeerID'
|
|
4
3
|
import { DataEntry, PeerDescriptor, FindResponse } from '../../proto/packages/dht/protos/DhtRpc'
|
|
5
|
-
import { IRecursiveFindSessionService } from '../../proto/packages/dht/protos/DhtRpc.server'
|
|
6
|
-
import { Empty } from '../../proto/google/protobuf/empty'
|
|
7
4
|
import { ITransport } from '../../transport/ITransport'
|
|
8
5
|
import { ListeningRpcCommunicator } from '../../transport/ListeningRpcCommunicator'
|
|
9
6
|
import { Contact } from '../contact/Contact'
|
|
10
7
|
import { SortedContactList } from '../contact/SortedContactList'
|
|
11
|
-
import {
|
|
8
|
+
import { FindResult } from './Finder'
|
|
12
9
|
import { keyFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
|
|
10
|
+
import { ServiceID } from '../../types/ServiceID'
|
|
11
|
+
import { FindSessionRpcLocal } from './FindSessionRpcLocal'
|
|
13
12
|
|
|
14
|
-
export interface
|
|
13
|
+
export interface FindSessionEvents {
|
|
15
14
|
findCompleted: (results: PeerDescriptor[]) => void
|
|
16
15
|
}
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
export interface RecursiveFindSessionConfig {
|
|
21
|
-
serviceId: string
|
|
17
|
+
export interface FindSessionConfig {
|
|
18
|
+
serviceId: ServiceID
|
|
22
19
|
transport: ITransport
|
|
23
20
|
kademliaIdToFind: Uint8Array
|
|
24
|
-
|
|
21
|
+
localPeerId: PeerID
|
|
25
22
|
waitedRoutingPathCompletions: number
|
|
26
23
|
fetchData: boolean
|
|
27
24
|
}
|
|
28
25
|
|
|
29
|
-
export class
|
|
30
|
-
private readonly serviceId:
|
|
26
|
+
export class FindSession extends EventEmitter<FindSessionEvents> {
|
|
27
|
+
private readonly serviceId: ServiceID
|
|
31
28
|
private readonly transport: ITransport
|
|
32
29
|
private readonly kademliaIdToFind: Uint8Array
|
|
33
|
-
private readonly
|
|
30
|
+
private readonly localPeerId: PeerID
|
|
34
31
|
private readonly waitedRoutingPathCompletions: number
|
|
35
32
|
private readonly rpcCommunicator: ListeningRpcCommunicator
|
|
36
33
|
private readonly fetchData: boolean
|
|
@@ -42,20 +39,29 @@ export class RecursiveFindSession extends EventEmitter<RecursiveFindSessionEvent
|
|
|
42
39
|
private findCompletedEmitted = false
|
|
43
40
|
private noCloserNodesReceivedCounter = 0
|
|
44
41
|
|
|
45
|
-
constructor(config:
|
|
42
|
+
constructor(config: FindSessionConfig) {
|
|
46
43
|
super()
|
|
47
44
|
this.serviceId = config.serviceId
|
|
48
45
|
this.transport = config.transport
|
|
49
46
|
this.kademliaIdToFind = config.kademliaIdToFind
|
|
50
|
-
this.
|
|
47
|
+
this.localPeerId = config.localPeerId
|
|
51
48
|
this.waitedRoutingPathCompletions = config.waitedRoutingPathCompletions
|
|
52
49
|
this.results = new SortedContactList(PeerID.fromValue(this.kademliaIdToFind), 10, undefined, true)
|
|
53
50
|
this.fetchData = config.fetchData
|
|
54
51
|
this.rpcCommunicator = new ListeningRpcCommunicator(this.serviceId, this.transport, {
|
|
55
52
|
rpcRequestTimeout: 15000
|
|
56
53
|
})
|
|
54
|
+
this.registerLocalRpcMethods()
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
private registerLocalRpcMethods() {
|
|
58
|
+
const rpcLocal = new FindSessionRpcLocal({
|
|
59
|
+
doSendFindResponse: (routingPath: PeerDescriptor[], nodes: PeerDescriptor[], dataEntries: DataEntry[], noCloserNodesFound?: boolean) => {
|
|
60
|
+
this.doSendFindResponse(routingPath, nodes, dataEntries, noCloserNodesFound)
|
|
61
|
+
}
|
|
62
|
+
})
|
|
57
63
|
this.rpcCommunicator.registerRpcNotification(FindResponse, 'sendFindResponse',
|
|
58
|
-
(req: FindResponse) =>
|
|
64
|
+
(req: FindResponse) => rpcLocal.sendFindResponse(req))
|
|
59
65
|
}
|
|
60
66
|
|
|
61
67
|
private isFindCompleted(): boolean {
|
|
@@ -101,7 +107,7 @@ export class RecursiveFindSession extends EventEmitter<RecursiveFindSessionEvent
|
|
|
101
107
|
private addKnownHops(routingPath: PeerDescriptor[]) {
|
|
102
108
|
routingPath.forEach((desc) => {
|
|
103
109
|
const newPeerId = PeerID.fromValue(desc.kademliaId)
|
|
104
|
-
if (!this.
|
|
110
|
+
if (!this.localPeerId.equals(newPeerId)) {
|
|
105
111
|
this.allKnownHops.add(newPeerId.toKey())
|
|
106
112
|
}
|
|
107
113
|
})
|
|
@@ -109,7 +115,7 @@ export class RecursiveFindSession extends EventEmitter<RecursiveFindSessionEvent
|
|
|
109
115
|
|
|
110
116
|
private setHopAsReported(desc: PeerDescriptor) {
|
|
111
117
|
const newPeerId = PeerID.fromValue(desc.kademliaId)
|
|
112
|
-
if (!this.
|
|
118
|
+
if (!this.localPeerId.equals(newPeerId)) {
|
|
113
119
|
this.reportedHops.add(newPeerId.toKey())
|
|
114
120
|
}
|
|
115
121
|
if (this.isFindCompleted()) {
|
|
@@ -156,13 +162,7 @@ export class RecursiveFindSession extends EventEmitter<RecursiveFindSessionEvent
|
|
|
156
162
|
}
|
|
157
163
|
}
|
|
158
164
|
|
|
159
|
-
public
|
|
160
|
-
logger.trace('recursiveFindReport arrived: ' + JSON.stringify(report))
|
|
161
|
-
this.doSendFindResponse(report.routingPath, report.closestConnectedPeers, report.dataEntries, report.noCloserNodesFound)
|
|
162
|
-
return {}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
public getResults = (): RecursiveFindResult => ({
|
|
165
|
+
public getResults = (): FindResult => ({
|
|
166
166
|
closestNodes: this.results.getAllContacts().map((contact) => contact.getPeerDescriptor()),
|
|
167
167
|
dataEntries: (this.foundData && this.foundData.size > 0) ? Array.from(this.foundData.values()) : undefined
|
|
168
168
|
})
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { IFindSessionRpc } from '../../proto/packages/dht/protos/DhtRpc.server'
|
|
2
|
+
import { Empty } from '../../proto/google/protobuf/empty'
|
|
3
|
+
import { DataEntry, FindResponse, PeerDescriptor } from '../../proto/packages/dht/protos/DhtRpc'
|
|
4
|
+
import { Logger } from '@streamr/utils'
|
|
5
|
+
|
|
6
|
+
const logger = new Logger(module)
|
|
7
|
+
|
|
8
|
+
interface FindSessionRpcLocalConfig {
|
|
9
|
+
doSendFindResponse: (routingPath: PeerDescriptor[], nodes: PeerDescriptor[], dataEntries: DataEntry[], noCloserNodesFound?: boolean) => void
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class FindSessionRpcLocal implements IFindSessionRpc {
|
|
13
|
+
|
|
14
|
+
private readonly config: FindSessionRpcLocalConfig
|
|
15
|
+
|
|
16
|
+
constructor(config: FindSessionRpcLocalConfig) {
|
|
17
|
+
this.config = config
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async sendFindResponse(report: FindResponse): Promise<Empty> {
|
|
21
|
+
logger.trace('FindResponse arrived: ' + JSON.stringify(report))
|
|
22
|
+
this.config.doSendFindResponse(report.routingPath, report.closestConnectedPeers, report.dataEntries, report.noCloserNodesFound)
|
|
23
|
+
return {}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -3,16 +3,20 @@ import {
|
|
|
3
3
|
PeerDescriptor,
|
|
4
4
|
FindResponse
|
|
5
5
|
} from '../../proto/packages/dht/protos/DhtRpc'
|
|
6
|
-
import {
|
|
6
|
+
import { IFindSessionRpcClient } from '../../proto/packages/dht/protos/DhtRpc.client'
|
|
7
7
|
import { Logger } from '@streamr/utils'
|
|
8
8
|
import { Remote } from '../contact/Remote'
|
|
9
9
|
|
|
10
10
|
const logger = new Logger(module)
|
|
11
11
|
|
|
12
|
-
export class
|
|
12
|
+
export class FindSessionRpcRemote extends Remote<IFindSessionRpcClient> {
|
|
13
13
|
|
|
14
|
-
sendFindResponse(
|
|
15
|
-
|
|
14
|
+
sendFindResponse(
|
|
15
|
+
routingPath: PeerDescriptor[],
|
|
16
|
+
closestNodes: PeerDescriptor[],
|
|
17
|
+
dataEntries: DataEntry[],
|
|
18
|
+
noCloserNodesFound: boolean
|
|
19
|
+
): void {
|
|
16
20
|
const report: FindResponse = {
|
|
17
21
|
routingPath,
|
|
18
22
|
closestConnectedPeers: closestNodes,
|
|
@@ -20,7 +24,7 @@ export class RemoteRecursiveFindSession extends Remote<IRecursiveFindSessionServ
|
|
|
20
24
|
noCloserNodesFound
|
|
21
25
|
}
|
|
22
26
|
this.getClient().sendFindResponse(report, this.formDhtRpcOptions()).catch((_e) => {
|
|
23
|
-
logger.trace('Failed to send
|
|
27
|
+
logger.trace('Failed to send FindResponse')
|
|
24
28
|
})
|
|
25
29
|
}
|
|
26
30
|
}
|
|
@@ -9,115 +9,134 @@ import {
|
|
|
9
9
|
RouteMessageWrapper
|
|
10
10
|
} from '../../proto/packages/dht/protos/DhtRpc'
|
|
11
11
|
import { PeerID, PeerIDKey } from '../../helpers/PeerID'
|
|
12
|
-
import {
|
|
12
|
+
import { RoutingErrors, IRouter } from '../routing/Router'
|
|
13
13
|
import { RoutingMode } from '../routing/RoutingSession'
|
|
14
|
-
import { areEqualPeerDescriptors,
|
|
14
|
+
import { areEqualPeerDescriptors, peerIdFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
|
|
15
15
|
import { Logger, runAndWaitForEvents3 } from '@streamr/utils'
|
|
16
16
|
import { RoutingRpcCommunicator } from '../../transport/RoutingRpcCommunicator'
|
|
17
|
-
import {
|
|
17
|
+
import { FindSessionRpcRemote } from './FindSessionRpcRemote'
|
|
18
18
|
import { v4 } from 'uuid'
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
19
|
+
import { FindSession, FindSessionEvents } from './FindSession'
|
|
20
|
+
import { DhtNodeRpcRemote } from '../DhtNodeRpcRemote'
|
|
21
21
|
import { ITransport } from '../../transport/ITransport'
|
|
22
22
|
import { LocalDataStore } from '../store/LocalDataStore'
|
|
23
|
-
import { IRouterRpc } from '../../proto/packages/dht/protos/DhtRpc.server'
|
|
24
23
|
import { ListeningRpcCommunicator } from '../../transport/ListeningRpcCommunicator'
|
|
25
|
-
import {
|
|
24
|
+
import { FindSessionRpcClient } from '../../proto/packages/dht/protos/DhtRpc.client'
|
|
26
25
|
import { toProtoRpcClient } from '@streamr/proto-rpc'
|
|
27
26
|
import { SortedContactList } from '../contact/SortedContactList'
|
|
27
|
+
import { getPreviousPeer } from '../routing/getPreviousPeer'
|
|
28
|
+
import { createRouteMessageAck } from '../routing/RouterRpcLocal'
|
|
29
|
+
import { ServiceID } from '../../types/ServiceID'
|
|
30
|
+
import { FindRpcLocal } from './FindRpcLocal'
|
|
28
31
|
|
|
29
|
-
interface
|
|
32
|
+
interface FinderConfig {
|
|
30
33
|
rpcCommunicator: RoutingRpcCommunicator
|
|
31
34
|
sessionTransport: ITransport
|
|
32
|
-
connections: Map<PeerIDKey,
|
|
35
|
+
connections: Map<PeerIDKey, DhtNodeRpcRemote>
|
|
33
36
|
router: IRouter
|
|
34
|
-
|
|
35
|
-
serviceId:
|
|
37
|
+
localPeerDescriptor: PeerDescriptor
|
|
38
|
+
serviceId: ServiceID
|
|
36
39
|
localDataStore: LocalDataStore
|
|
37
40
|
addContact: (contact: PeerDescriptor, setActive?: boolean) => void
|
|
38
41
|
isPeerCloserToIdThanSelf: (peer1: PeerDescriptor, compareToId: PeerID) => boolean
|
|
39
42
|
}
|
|
40
43
|
|
|
41
|
-
interface
|
|
42
|
-
|
|
44
|
+
export interface IFinder {
|
|
45
|
+
startFind(idToFind: Uint8Array, fetchData?: boolean): Promise<FindResult>
|
|
43
46
|
}
|
|
44
47
|
|
|
45
|
-
export interface
|
|
46
|
-
|
|
47
|
-
export interface RecursiveFindResult { closestNodes: Array<PeerDescriptor>, dataEntries?: Array<DataEntry> }
|
|
48
|
+
export interface FindResult { closestNodes: Array<PeerDescriptor>, dataEntries?: Array<DataEntry> }
|
|
48
49
|
|
|
49
50
|
const logger = new Logger(module)
|
|
50
51
|
|
|
51
|
-
export class
|
|
52
|
+
export class Finder implements IFinder {
|
|
52
53
|
|
|
53
54
|
private readonly rpcCommunicator: RoutingRpcCommunicator
|
|
54
55
|
private readonly sessionTransport: ITransport
|
|
55
|
-
private readonly connections: Map<PeerIDKey,
|
|
56
|
+
private readonly connections: Map<PeerIDKey, DhtNodeRpcRemote>
|
|
56
57
|
private readonly router: IRouter
|
|
57
|
-
private readonly
|
|
58
|
-
private readonly serviceId:
|
|
58
|
+
private readonly localPeerDescriptor: PeerDescriptor
|
|
59
|
+
private readonly serviceId: ServiceID
|
|
59
60
|
private readonly localDataStore: LocalDataStore
|
|
60
|
-
private readonly addContact: (contact: PeerDescriptor, setActive?: boolean) => void
|
|
61
61
|
private readonly isPeerCloserToIdThanSelf: (peer1: PeerDescriptor, compareToId: PeerID) => boolean
|
|
62
|
-
private ongoingSessions: Map<string,
|
|
62
|
+
private ongoingSessions: Map<string, FindSession> = new Map()
|
|
63
63
|
private stopped = false
|
|
64
64
|
|
|
65
|
-
constructor(config:
|
|
65
|
+
constructor(config: FinderConfig) {
|
|
66
66
|
this.rpcCommunicator = config.rpcCommunicator
|
|
67
67
|
this.sessionTransport = config.sessionTransport
|
|
68
68
|
this.connections = config.connections
|
|
69
69
|
this.router = config.router
|
|
70
|
-
this.
|
|
70
|
+
this.localPeerDescriptor = config.localPeerDescriptor
|
|
71
71
|
this.serviceId = config.serviceId
|
|
72
72
|
this.localDataStore = config.localDataStore
|
|
73
|
-
this.addContact = config.addContact
|
|
74
73
|
this.isPeerCloserToIdThanSelf = config.isPeerCloserToIdThanSelf
|
|
75
|
-
this.
|
|
76
|
-
|
|
74
|
+
this.registerLocalRpcMethods(config)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
private registerLocalRpcMethods(config: FinderConfig) {
|
|
78
|
+
const rpcLocal = new FindRpcLocal({
|
|
79
|
+
doRouteFindRequest: (routedMessage: RouteMessageWrapper) => this.doRouteFindRequest(routedMessage),
|
|
80
|
+
addContact: (contact: PeerDescriptor, setActive?: boolean) => config.addContact(contact, setActive),
|
|
81
|
+
isMostLikelyDuplicate: (requestId: string) => this.router.isMostLikelyDuplicate(requestId),
|
|
82
|
+
addToDuplicateDetector: (requestId: string) => this.router.addToDuplicateDetector(requestId)
|
|
83
|
+
})
|
|
84
|
+
this.rpcCommunicator.registerRpcMethod(
|
|
85
|
+
RouteMessageWrapper,
|
|
86
|
+
RouteMessageAck,
|
|
87
|
+
'routeFindRequest',
|
|
88
|
+
async (routedMessage: RouteMessageWrapper) => {
|
|
89
|
+
if (this.stopped) {
|
|
90
|
+
return createRouteMessageAck(routedMessage, 'routeFindRequest() service is not running')
|
|
91
|
+
} else {
|
|
92
|
+
return rpcLocal.routeFindRequest(routedMessage)
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
)
|
|
77
96
|
}
|
|
78
97
|
|
|
79
|
-
public async
|
|
98
|
+
public async startFind(
|
|
80
99
|
idToFind: Uint8Array,
|
|
81
100
|
fetchData: boolean = false,
|
|
82
101
|
excludedPeer?: PeerDescriptor
|
|
83
|
-
): Promise<
|
|
102
|
+
): Promise<FindResult> {
|
|
84
103
|
if (this.stopped) {
|
|
85
104
|
return { closestNodes: [] }
|
|
86
105
|
}
|
|
87
106
|
const sessionId = v4()
|
|
88
|
-
const
|
|
107
|
+
const session = new FindSession({
|
|
89
108
|
serviceId: sessionId,
|
|
90
109
|
transport: this.sessionTransport,
|
|
91
110
|
kademliaIdToFind: idToFind,
|
|
92
|
-
|
|
111
|
+
localPeerId: peerIdFromPeerDescriptor(this.localPeerDescriptor),
|
|
93
112
|
waitedRoutingPathCompletions: this.connections.size > 1 ? 2 : 1,
|
|
94
113
|
fetchData
|
|
95
114
|
})
|
|
96
115
|
if (this.connections.size === 0) {
|
|
97
116
|
const data = this.localDataStore.getEntry(PeerID.fromValue(idToFind))
|
|
98
|
-
|
|
99
|
-
[this.
|
|
100
|
-
[this.
|
|
117
|
+
session.doSendFindResponse(
|
|
118
|
+
[this.localPeerDescriptor],
|
|
119
|
+
[this.localPeerDescriptor],
|
|
101
120
|
data ? Array.from(data.values()) : [],
|
|
102
121
|
true
|
|
103
122
|
)
|
|
104
|
-
return
|
|
123
|
+
return session.getResults()
|
|
105
124
|
}
|
|
106
125
|
const routeMessage = this.wrapFindRequest(idToFind, sessionId, fetchData)
|
|
107
|
-
this.ongoingSessions.set(sessionId,
|
|
126
|
+
this.ongoingSessions.set(sessionId, session)
|
|
108
127
|
try {
|
|
109
|
-
await runAndWaitForEvents3<
|
|
110
|
-
[() => this.
|
|
111
|
-
[[
|
|
128
|
+
await runAndWaitForEvents3<FindSessionEvents>(
|
|
129
|
+
[() => this.doRouteFindRequest(routeMessage, excludedPeer)],
|
|
130
|
+
[[session, 'findCompleted']],
|
|
112
131
|
15000
|
|
113
132
|
)
|
|
114
133
|
} catch (err) {
|
|
115
|
-
logger.debug(`
|
|
134
|
+
logger.debug(`doRouteFindRequest failed with error ${err}`)
|
|
116
135
|
}
|
|
117
|
-
this.findAndReportLocalData(idToFind, fetchData, [], this.
|
|
136
|
+
this.findAndReportLocalData(idToFind, fetchData, [], this.localPeerDescriptor, sessionId)
|
|
118
137
|
this.ongoingSessions.delete(sessionId)
|
|
119
|
-
|
|
120
|
-
return
|
|
138
|
+
session.stop()
|
|
139
|
+
return session.getResults()
|
|
121
140
|
}
|
|
122
141
|
|
|
123
142
|
private wrapFindRequest(idToFind: Uint8Array, sessionId: string, fetchData: boolean): RouteMessageWrapper {
|
|
@@ -130,7 +149,7 @@ export class RecursiveFinder implements IRecursiveFinder {
|
|
|
130
149
|
fetchData
|
|
131
150
|
}
|
|
132
151
|
const msg: Message = {
|
|
133
|
-
messageType: MessageType.
|
|
152
|
+
messageType: MessageType.FIND_REQUEST,
|
|
134
153
|
messageId: v4(),
|
|
135
154
|
serviceId: this.serviceId,
|
|
136
155
|
body: {
|
|
@@ -142,7 +161,7 @@ export class RecursiveFinder implements IRecursiveFinder {
|
|
|
142
161
|
message: msg,
|
|
143
162
|
requestId: v4(),
|
|
144
163
|
destinationPeer: targetDescriptor,
|
|
145
|
-
sourcePeer: this.
|
|
164
|
+
sourcePeer: this.localPeerDescriptor,
|
|
146
165
|
reachableThrough: [],
|
|
147
166
|
routingPath: []
|
|
148
167
|
}
|
|
@@ -176,30 +195,31 @@ export class RecursiveFinder implements IRecursiveFinder {
|
|
|
176
195
|
private sendFindResponse(
|
|
177
196
|
routingPath: PeerDescriptor[],
|
|
178
197
|
targetPeerDescriptor: PeerDescriptor,
|
|
179
|
-
serviceId:
|
|
198
|
+
serviceId: ServiceID,
|
|
180
199
|
closestNodes: PeerDescriptor[],
|
|
181
200
|
data: Map<PeerIDKey, DataEntry> | undefined,
|
|
182
201
|
noCloserNodesFound: boolean = false
|
|
183
202
|
): void {
|
|
184
203
|
const dataEntries = data ? Array.from(data.values(), DataEntry.create.bind(DataEntry)) : []
|
|
185
|
-
const isOwnNode = areEqualPeerDescriptors(this.
|
|
204
|
+
const isOwnNode = areEqualPeerDescriptors(this.localPeerDescriptor, targetPeerDescriptor)
|
|
186
205
|
if (isOwnNode && this.ongoingSessions.has(serviceId)) {
|
|
187
206
|
this.ongoingSessions.get(serviceId)!
|
|
188
207
|
.doSendFindResponse(routingPath, closestNodes, dataEntries, noCloserNodesFound)
|
|
189
208
|
} else {
|
|
190
209
|
const remoteCommunicator = new ListeningRpcCommunicator(serviceId, this.sessionTransport, { rpcRequestTimeout: 15000 })
|
|
191
|
-
const
|
|
192
|
-
this.
|
|
210
|
+
const rpcRemote = new FindSessionRpcRemote(
|
|
211
|
+
this.localPeerDescriptor,
|
|
193
212
|
targetPeerDescriptor,
|
|
194
213
|
serviceId,
|
|
195
|
-
toProtoRpcClient(new
|
|
214
|
+
toProtoRpcClient(new FindSessionRpcClient(remoteCommunicator.getRpcClientTransport())),
|
|
215
|
+
10000
|
|
196
216
|
)
|
|
197
|
-
|
|
217
|
+
rpcRemote.sendFindResponse(routingPath, closestNodes, dataEntries, noCloserNodesFound)
|
|
198
218
|
remoteCommunicator.destroy()
|
|
199
219
|
}
|
|
200
220
|
}
|
|
201
221
|
|
|
202
|
-
private
|
|
222
|
+
private doRouteFindRequest(routedMessage: RouteMessageWrapper, excludedPeer?: PeerDescriptor): RouteMessageAck {
|
|
203
223
|
if (this.stopped) {
|
|
204
224
|
return createRouteMessageAck(routedMessage, 'DhtNode Stopped')
|
|
205
225
|
}
|
|
@@ -208,14 +228,14 @@ export class RecursiveFinder implements IRecursiveFinder {
|
|
|
208
228
|
const findRequest = msg?.body.oneofKind === 'findRequest' ? msg.body.findRequest : undefined
|
|
209
229
|
const closestPeersToDestination = this.getClosestConnections(routedMessage.destinationPeer!.kademliaId, 5)
|
|
210
230
|
const data = this.findLocalData(idToFind.value, findRequest!.fetchData)
|
|
211
|
-
if (areEqualPeerDescriptors(this.
|
|
231
|
+
if (areEqualPeerDescriptors(this.localPeerDescriptor, routedMessage.destinationPeer!)) {
|
|
212
232
|
this.sendFindResponse(routedMessage.routingPath, routedMessage.sourcePeer!, findRequest!.sessionId,
|
|
213
233
|
closestPeersToDestination, data, true)
|
|
214
234
|
return createRouteMessageAck(routedMessage)
|
|
215
235
|
}
|
|
216
|
-
const ack = this.router.doRouteMessage(routedMessage, RoutingMode.
|
|
236
|
+
const ack = this.router.doRouteMessage(routedMessage, RoutingMode.FIND, excludedPeer)
|
|
217
237
|
if (ack.error === RoutingErrors.NO_CANDIDATES_FOUND) {
|
|
218
|
-
logger.trace(`
|
|
238
|
+
logger.trace(`routeFindRequest Node found no candidates`)
|
|
219
239
|
this.sendFindResponse(routedMessage.routingPath, routedMessage.sourcePeer!, findRequest!.sessionId,
|
|
220
240
|
closestPeersToDestination, data, true)
|
|
221
241
|
} else if (ack.error) {
|
|
@@ -223,7 +243,7 @@ export class RecursiveFinder implements IRecursiveFinder {
|
|
|
223
243
|
} else {
|
|
224
244
|
const noCloserContactsFound = (
|
|
225
245
|
closestPeersToDestination.length > 0
|
|
226
|
-
&& routedMessage
|
|
246
|
+
&& getPreviousPeer(routedMessage)
|
|
227
247
|
&& !this.isPeerCloserToIdThanSelf(closestPeersToDestination[0], idToFind)
|
|
228
248
|
)
|
|
229
249
|
this.sendFindResponse(routedMessage.routingPath, routedMessage.sourcePeer!, findRequest!.sessionId,
|
|
@@ -234,7 +254,7 @@ export class RecursiveFinder implements IRecursiveFinder {
|
|
|
234
254
|
|
|
235
255
|
private getClosestConnections(kademliaId: Uint8Array, limit: number): PeerDescriptor[] {
|
|
236
256
|
const connectedPeers = Array.from(this.connections.values())
|
|
237
|
-
const closestPeers = new SortedContactList<
|
|
257
|
+
const closestPeers = new SortedContactList<DhtNodeRpcRemote>(
|
|
238
258
|
PeerID.fromValue(kademliaId),
|
|
239
259
|
limit,
|
|
240
260
|
undefined,
|
|
@@ -245,20 +265,6 @@ export class RecursiveFinder implements IRecursiveFinder {
|
|
|
245
265
|
return closestPeers.getClosestContacts(limit).map((peer) => peer.getPeerDescriptor())
|
|
246
266
|
}
|
|
247
267
|
|
|
248
|
-
// IRouterRpc method
|
|
249
|
-
async findRecursively(routedMessage: RouteMessageWrapper): Promise<RouteMessageAck> {
|
|
250
|
-
if (this.stopped) {
|
|
251
|
-
return createRouteMessageAck(routedMessage, 'findRecursively() service is not running')
|
|
252
|
-
} else if (this.router.isMostLikelyDuplicate(routedMessage.requestId)) {
|
|
253
|
-
return createRouteMessageAck(routedMessage, 'message given to findRecursively() service is likely a duplicate')
|
|
254
|
-
}
|
|
255
|
-
const senderKey = keyFromPeerDescriptor(routedMessage.previousPeer || routedMessage.sourcePeer!)
|
|
256
|
-
logger.trace(`Received findRecursively call from ${senderKey}`)
|
|
257
|
-
this.addContact(routedMessage.sourcePeer!, true)
|
|
258
|
-
this.router.addToDuplicateDetector(routedMessage.requestId)
|
|
259
|
-
return this.doFindRecursevily(routedMessage)
|
|
260
|
-
}
|
|
261
|
-
|
|
262
268
|
public stop(): void {
|
|
263
269
|
this.stopped = true
|
|
264
270
|
this.ongoingSessions.forEach((session, _id) => {
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { RouteMessageWrapper } from '../../proto/packages/dht/protos/DhtRpc'
|
|
2
|
+
import { v4 } from 'uuid'
|
|
3
|
+
import { getNodeIdFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
|
|
4
|
+
import { Remote } from '../contact/Remote'
|
|
5
|
+
import { Logger } from '@streamr/utils'
|
|
6
|
+
import { IFindRpcClient } from '../../proto/packages/dht/protos/DhtRpc.client'
|
|
7
|
+
import { getPreviousPeer } from './getPreviousPeer'
|
|
8
|
+
|
|
9
|
+
const logger = new Logger(module)
|
|
10
|
+
|
|
11
|
+
export class FindRpcRemote extends Remote<IFindRpcClient> {
|
|
12
|
+
|
|
13
|
+
async routeFindRequest(params: RouteMessageWrapper): Promise<boolean> {
|
|
14
|
+
const message: RouteMessageWrapper = {
|
|
15
|
+
destinationPeer: params.destinationPeer,
|
|
16
|
+
sourcePeer: params.sourcePeer,
|
|
17
|
+
message: params.message,
|
|
18
|
+
requestId: params.requestId ?? v4(),
|
|
19
|
+
reachableThrough: params.reachableThrough ?? [],
|
|
20
|
+
routingPath: params.routingPath
|
|
21
|
+
}
|
|
22
|
+
const options = this.formDhtRpcOptions()
|
|
23
|
+
try {
|
|
24
|
+
const ack = await this.getClient().routeFindRequest(message, options)
|
|
25
|
+
if (ack.error.length > 0) {
|
|
26
|
+
logger.debug('Next hop responded with error ' + ack.error)
|
|
27
|
+
return false
|
|
28
|
+
}
|
|
29
|
+
} catch (err) {
|
|
30
|
+
const previousPeer = getPreviousPeer(params)
|
|
31
|
+
const fromNode = previousPeer
|
|
32
|
+
? getNodeIdFromPeerDescriptor(previousPeer)
|
|
33
|
+
: getNodeIdFromPeerDescriptor(params.sourcePeer!)
|
|
34
|
+
// eslint-disable-next-line max-len
|
|
35
|
+
logger.debug(`Failed to send routeFindRequest message from ${fromNode} to ${getNodeIdFromPeerDescriptor(this.getPeerDescriptor())} with: ${err}`)
|
|
36
|
+
return false
|
|
37
|
+
}
|
|
38
|
+
return true
|
|
39
|
+
}
|
|
40
|
+
}
|