@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,68 @@
|
|
|
1
|
+
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
2
|
+
import { Logger } from '@streamr/utils'
|
|
3
|
+
import KBucket from 'k-bucket'
|
|
4
|
+
import { getNodeIdFromPeerDescriptor } from '../helpers/peerIdFromPeerDescriptor'
|
|
5
|
+
import { Empty } from '../proto/google/protobuf/empty'
|
|
6
|
+
import {
|
|
7
|
+
ClosestPeersRequest,
|
|
8
|
+
ClosestPeersResponse,
|
|
9
|
+
LeaveNotice,
|
|
10
|
+
PeerDescriptor,
|
|
11
|
+
PingRequest,
|
|
12
|
+
PingResponse
|
|
13
|
+
} from '../proto/packages/dht/protos/DhtRpc'
|
|
14
|
+
import { IDhtNodeRpc } from '../proto/packages/dht/protos/DhtRpc.server'
|
|
15
|
+
import { DhtCallContext } from '../rpc-protocol/DhtCallContext'
|
|
16
|
+
import { DhtNodeRpcRemote } from './DhtNodeRpcRemote'
|
|
17
|
+
|
|
18
|
+
interface DhtNodeRpcLocalConfig {
|
|
19
|
+
bucket: KBucket<DhtNodeRpcRemote>
|
|
20
|
+
serviceId: string
|
|
21
|
+
peerDiscoveryQueryBatchSize: number
|
|
22
|
+
addNewContact: (contact: PeerDescriptor) => void
|
|
23
|
+
removeContact: (contact: PeerDescriptor) => void
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const logger = new Logger(module)
|
|
27
|
+
|
|
28
|
+
export class DhtNodeRpcLocal implements IDhtNodeRpc {
|
|
29
|
+
|
|
30
|
+
private readonly config: DhtNodeRpcLocalConfig
|
|
31
|
+
|
|
32
|
+
constructor(config: DhtNodeRpcLocalConfig) {
|
|
33
|
+
this.config = config
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async getClosestPeers(request: ClosestPeersRequest, context: ServerCallContext): Promise<ClosestPeersResponse> {
|
|
37
|
+
this.config.addNewContact((context as DhtCallContext).incomingSourceDescriptor!)
|
|
38
|
+
const response = {
|
|
39
|
+
peers: this.getClosestPeerDescriptors(request.kademliaId, this.config.peerDiscoveryQueryBatchSize),
|
|
40
|
+
requestId: request.requestId
|
|
41
|
+
}
|
|
42
|
+
return response
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
private getClosestPeerDescriptors(kademliaId: Uint8Array, limit: number): PeerDescriptor[] {
|
|
46
|
+
const closestPeers = this.config.bucket.closest(kademliaId, limit)
|
|
47
|
+
return closestPeers.map((rpcRemote: DhtNodeRpcRemote) => rpcRemote.getPeerDescriptor())
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async ping(request: PingRequest, context: ServerCallContext): Promise<PingResponse> {
|
|
51
|
+
logger.trace('received ping request: ' + getNodeIdFromPeerDescriptor((context as DhtCallContext).incomingSourceDescriptor!))
|
|
52
|
+
setImmediate(() => {
|
|
53
|
+
this.config.addNewContact((context as DhtCallContext).incomingSourceDescriptor!)
|
|
54
|
+
})
|
|
55
|
+
const response: PingResponse = {
|
|
56
|
+
requestId: request.requestId
|
|
57
|
+
}
|
|
58
|
+
return response
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async leaveNotice(_request: LeaveNotice, context: ServerCallContext): Promise<Empty> {
|
|
62
|
+
// TODO check signature??
|
|
63
|
+
const sender = (context as DhtCallContext).incomingSourceDescriptor!
|
|
64
|
+
logger.trace('received leave notice: ' + getNodeIdFromPeerDescriptor(sender))
|
|
65
|
+
this.config.removeContact(sender)
|
|
66
|
+
return {}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IDhtNodeRpcClient } from '../proto/packages/dht/protos/DhtRpc.client'
|
|
2
2
|
import {
|
|
3
3
|
ClosestPeersRequest,
|
|
4
|
+
LeaveNotice,
|
|
4
5
|
PeerDescriptor,
|
|
5
6
|
PingRequest
|
|
6
7
|
} from '../proto/packages/dht/protos/DhtRpc'
|
|
@@ -9,7 +10,8 @@ import { Logger } from '@streamr/utils'
|
|
|
9
10
|
import { ProtoRpcClient } from '@streamr/proto-rpc'
|
|
10
11
|
import { Remote } from './contact/Remote'
|
|
11
12
|
import { PeerID } from '../helpers/PeerID'
|
|
12
|
-
import {
|
|
13
|
+
import { getNodeIdFromPeerDescriptor, peerIdFromPeerDescriptor } from '../helpers/peerIdFromPeerDescriptor'
|
|
14
|
+
import { ServiceID } from '../types/ServiceID'
|
|
13
15
|
|
|
14
16
|
const logger = new Logger(module)
|
|
15
17
|
|
|
@@ -19,25 +21,26 @@ export interface KBucketContact {
|
|
|
19
21
|
vectorClock: number
|
|
20
22
|
}
|
|
21
23
|
|
|
22
|
-
export class
|
|
24
|
+
export class DhtNodeRpcRemote extends Remote<IDhtNodeRpcClient> implements KBucketContact {
|
|
23
25
|
|
|
24
26
|
private static counter = 0
|
|
25
27
|
public vectorClock: number
|
|
26
28
|
public readonly id: Uint8Array
|
|
27
29
|
|
|
28
30
|
constructor(
|
|
29
|
-
|
|
31
|
+
localPeerDescriptor: PeerDescriptor,
|
|
30
32
|
peerDescriptor: PeerDescriptor,
|
|
31
|
-
client: ProtoRpcClient<
|
|
32
|
-
serviceId:
|
|
33
|
+
client: ProtoRpcClient<IDhtNodeRpcClient>,
|
|
34
|
+
serviceId: ServiceID,
|
|
35
|
+
rpcRequestTimeout?: number
|
|
33
36
|
) {
|
|
34
|
-
super(
|
|
37
|
+
super(localPeerDescriptor, peerDescriptor, serviceId, client, rpcRequestTimeout)
|
|
35
38
|
this.id = this.getPeerId().value
|
|
36
|
-
this.vectorClock =
|
|
39
|
+
this.vectorClock = DhtNodeRpcRemote.counter++
|
|
37
40
|
}
|
|
38
41
|
|
|
39
42
|
async getClosestPeers(kademliaId: Uint8Array): Promise<PeerDescriptor[]> {
|
|
40
|
-
logger.trace(`Requesting getClosestPeers on ${this.getServiceId()} from ${
|
|
43
|
+
logger.trace(`Requesting getClosestPeers on ${this.getServiceId()} from ${getNodeIdFromPeerDescriptor(this.getPeerDescriptor())}`)
|
|
41
44
|
const request: ClosestPeersRequest = {
|
|
42
45
|
kademliaId,
|
|
43
46
|
requestId: v4()
|
|
@@ -52,28 +55,24 @@ export class RemoteDhtNode extends Remote<IDhtRpcServiceClient> implements KBuck
|
|
|
52
55
|
}
|
|
53
56
|
|
|
54
57
|
async ping(): Promise<boolean> {
|
|
55
|
-
logger.trace(`Requesting ping on ${this.getServiceId()} from ${
|
|
58
|
+
logger.trace(`Requesting ping on ${this.getServiceId()} from ${getNodeIdFromPeerDescriptor(this.getPeerDescriptor())}`)
|
|
56
59
|
const request: PingRequest = {
|
|
57
60
|
requestId: v4()
|
|
58
61
|
}
|
|
59
|
-
const options = this.formDhtRpcOptions(
|
|
60
|
-
timeout: 10000
|
|
61
|
-
})
|
|
62
|
+
const options = this.formDhtRpcOptions()
|
|
62
63
|
try {
|
|
63
64
|
const pong = await this.getClient().ping(request, options)
|
|
64
65
|
if (pong.requestId === request.requestId) {
|
|
65
66
|
return true
|
|
66
67
|
}
|
|
67
68
|
} catch (err) {
|
|
68
|
-
logger.trace(`ping failed on ${this.getServiceId()} to ${
|
|
69
|
+
logger.trace(`ping failed on ${this.getServiceId()} to ${getNodeIdFromPeerDescriptor(this.getPeerDescriptor())}: ${err}`)
|
|
69
70
|
}
|
|
70
71
|
return false
|
|
71
72
|
}
|
|
72
73
|
|
|
73
|
-
/*
|
|
74
|
-
TODO remove or start using this method in NET-1131
|
|
75
74
|
leaveNotice(): void {
|
|
76
|
-
logger.trace(`Sending leaveNotice on ${this.getServiceId()} from ${
|
|
75
|
+
logger.trace(`Sending leaveNotice on ${this.getServiceId()} from ${getNodeIdFromPeerDescriptor(this.getPeerDescriptor())}`)
|
|
77
76
|
const request: LeaveNotice = {
|
|
78
77
|
serviceId: this.getServiceId()
|
|
79
78
|
}
|
|
@@ -83,7 +82,7 @@ export class RemoteDhtNode extends Remote<IDhtRpcServiceClient> implements KBuck
|
|
|
83
82
|
this.getClient().leaveNotice(request, options).catch((e) => {
|
|
84
83
|
logger.trace('Failed to send leaveNotice' + e)
|
|
85
84
|
})
|
|
86
|
-
}
|
|
85
|
+
}
|
|
87
86
|
|
|
88
87
|
getPeerId(): PeerID {
|
|
89
88
|
return peerIdFromPeerDescriptor(this.getPeerDescriptor())
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { IExternalApiRpc } from '../proto/packages/dht/protos/DhtRpc.server'
|
|
2
|
+
import {
|
|
3
|
+
ExternalFindDataRequest,
|
|
4
|
+
ExternalFindDataResponse,
|
|
5
|
+
ExternalStoreDataRequest,
|
|
6
|
+
ExternalStoreDataResponse,
|
|
7
|
+
PeerDescriptor
|
|
8
|
+
} from '../proto/packages/dht/protos/DhtRpc'
|
|
9
|
+
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
10
|
+
import { DhtCallContext } from '../rpc-protocol/DhtCallContext'
|
|
11
|
+
import { FindResult } from './find/Finder'
|
|
12
|
+
import { Any } from '../proto/google/protobuf/any'
|
|
13
|
+
|
|
14
|
+
interface ExternalApiRpcLocalConfig {
|
|
15
|
+
startFind: (idToFind: Uint8Array, fetchData: boolean, excludedPeer: PeerDescriptor) => Promise<FindResult>
|
|
16
|
+
storeDataToDht: (key: Uint8Array, data: Any) => Promise<PeerDescriptor[]>
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export class ExternalApiRpcLocal implements IExternalApiRpc {
|
|
20
|
+
|
|
21
|
+
private readonly config: ExternalApiRpcLocalConfig
|
|
22
|
+
|
|
23
|
+
constructor(config: ExternalApiRpcLocalConfig) {
|
|
24
|
+
this.config = config
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async externalFindData(findDataRequest: ExternalFindDataRequest, context: ServerCallContext): Promise<ExternalFindDataResponse> {
|
|
28
|
+
const senderPeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
|
|
29
|
+
const result = await this.config.startFind(findDataRequest.kademliaId, true, senderPeerDescriptor)
|
|
30
|
+
if (result.dataEntries) {
|
|
31
|
+
return ExternalFindDataResponse.create({ dataEntries: result.dataEntries })
|
|
32
|
+
} else {
|
|
33
|
+
return ExternalFindDataResponse.create({
|
|
34
|
+
dataEntries: [],
|
|
35
|
+
error: 'Could not find data with the given key'
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async externalStoreData(request: ExternalStoreDataRequest): Promise<ExternalStoreDataResponse> {
|
|
41
|
+
const result = await this.config.storeDataToDht(request.key, request.data!)
|
|
42
|
+
return ExternalStoreDataResponse.create({
|
|
43
|
+
storers: result
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { Any } from '../proto/google/protobuf/any'
|
|
2
|
-
import { DataEntry, ExternalStoreDataRequest,
|
|
2
|
+
import { DataEntry, ExternalStoreDataRequest, ExternalFindDataRequest, PeerDescriptor } from '../proto/packages/dht/protos/DhtRpc'
|
|
3
3
|
import { IExternalApiRpcClient } from '../proto/packages/dht/protos/DhtRpc.client'
|
|
4
4
|
import { Remote } from './contact/Remote'
|
|
5
5
|
|
|
6
6
|
export class ExternalApiRpcRemote extends Remote<IExternalApiRpcClient> {
|
|
7
7
|
|
|
8
|
-
async
|
|
9
|
-
const request:
|
|
8
|
+
async externalFindData(idToFind: Uint8Array): Promise<DataEntry[]> {
|
|
9
|
+
const request: ExternalFindDataRequest = {
|
|
10
10
|
kademliaId: idToFind
|
|
11
11
|
}
|
|
12
12
|
const options = this.formDhtRpcOptions({
|
|
13
13
|
timeout: 10000
|
|
14
14
|
})
|
|
15
15
|
try {
|
|
16
|
-
const data = await this.getClient().
|
|
16
|
+
const data = await this.getClient().externalFindData(request, options)
|
|
17
17
|
return data.dataEntries
|
|
18
18
|
} catch (err) {
|
|
19
19
|
return []
|
|
@@ -1,24 +1,51 @@
|
|
|
1
1
|
import { PeerDescriptor } from '../../proto/packages/dht/protos/DhtRpc'
|
|
2
2
|
import { ProtoRpcClient } from '@streamr/proto-rpc'
|
|
3
3
|
import { DhtRpcOptions } from '../../rpc-protocol/DhtRpcOptions'
|
|
4
|
+
import { ServiceID } from '../../types/ServiceID'
|
|
5
|
+
import { ConnectionType } from '../../connection/IConnection'
|
|
6
|
+
import { expectedConnectionType } from '../../helpers/Connectivity'
|
|
7
|
+
|
|
8
|
+
// Should connect directly to the server, timeout can be low
|
|
9
|
+
const WEBSOCKET_CLIENT_TIMEOUT = 5000
|
|
10
|
+
// Requires a WebsocketConnectionRequest to be routed to the client before the connection can be opened
|
|
11
|
+
// takes a little bit longer than WEBSOCKET_CLIENT
|
|
12
|
+
const WEBSOCKET_SERVER_TIMEOUT = 7500
|
|
13
|
+
// WebRTC connections require lots of signalling to open and might take a longer time.
|
|
14
|
+
const WEBRTC_TIMEOUT = 15000
|
|
15
|
+
// default timeout for existing connections
|
|
16
|
+
export const EXISTING_CONNECTION_TIMEOUT = 5000
|
|
17
|
+
|
|
18
|
+
const getRpcTimeout = (localPeerDescriptor: PeerDescriptor, remotePeerDescriptor: PeerDescriptor): number => {
|
|
19
|
+
const connectionType = expectedConnectionType(localPeerDescriptor, remotePeerDescriptor)
|
|
20
|
+
if (connectionType === ConnectionType.WEBSOCKET_CLIENT) {
|
|
21
|
+
return WEBSOCKET_CLIENT_TIMEOUT
|
|
22
|
+
} else if (connectionType === ConnectionType.WEBSOCKET_SERVER) {
|
|
23
|
+
return WEBSOCKET_SERVER_TIMEOUT
|
|
24
|
+
} else if (connectionType === ConnectionType.WEBRTC) {
|
|
25
|
+
return WEBRTC_TIMEOUT
|
|
26
|
+
}
|
|
27
|
+
return WEBRTC_TIMEOUT
|
|
28
|
+
}
|
|
4
29
|
|
|
5
30
|
export abstract class Remote<T> {
|
|
6
31
|
|
|
7
32
|
private readonly localPeerDescriptor: PeerDescriptor
|
|
8
33
|
private readonly remotePeerDescriptor: PeerDescriptor
|
|
9
|
-
private readonly serviceId:
|
|
34
|
+
private readonly serviceId: ServiceID
|
|
10
35
|
private readonly client: ProtoRpcClient<T>
|
|
11
|
-
|
|
36
|
+
private readonly rpcTimeout?: number
|
|
12
37
|
constructor(
|
|
13
38
|
localPeerDescriptor: PeerDescriptor,
|
|
14
39
|
remotePeerDescriptor: PeerDescriptor,
|
|
15
|
-
serviceId:
|
|
16
|
-
client: ProtoRpcClient<T
|
|
40
|
+
serviceId: ServiceID,
|
|
41
|
+
client: ProtoRpcClient<T>,
|
|
42
|
+
rpcTimeout?: number
|
|
17
43
|
) {
|
|
18
44
|
this.localPeerDescriptor = localPeerDescriptor
|
|
19
45
|
this.remotePeerDescriptor = remotePeerDescriptor
|
|
20
46
|
this.client = client
|
|
21
47
|
this.serviceId = serviceId
|
|
48
|
+
this.rpcTimeout = rpcTimeout
|
|
22
49
|
}
|
|
23
50
|
|
|
24
51
|
getPeerDescriptor(): PeerDescriptor {
|
|
@@ -41,6 +68,7 @@ export abstract class Remote<T> {
|
|
|
41
68
|
return {
|
|
42
69
|
sourceDescriptor: this.localPeerDescriptor,
|
|
43
70
|
targetDescriptor: this.remotePeerDescriptor,
|
|
71
|
+
timeout: this.rpcTimeout ?? getRpcTimeout(this.localPeerDescriptor, this.remotePeerDescriptor),
|
|
44
72
|
...opts
|
|
45
73
|
}
|
|
46
74
|
}
|
|
@@ -4,7 +4,7 @@ import { ContactList, ContactState } from './ContactList'
|
|
|
4
4
|
|
|
5
5
|
export class SortedContactList<C extends { getPeerId: () => PeerID }> extends ContactList<C> {
|
|
6
6
|
|
|
7
|
-
private
|
|
7
|
+
private allowLocalPeerId: boolean
|
|
8
8
|
private peerIdDistanceLimit?: PeerID
|
|
9
9
|
private excludedPeerIDs?: PeerID[]
|
|
10
10
|
|
|
@@ -12,13 +12,13 @@ export class SortedContactList<C extends { getPeerId: () => PeerID }> extends Co
|
|
|
12
12
|
ownId: PeerID,
|
|
13
13
|
maxSize: number,
|
|
14
14
|
defaultContactQueryLimit?: number,
|
|
15
|
-
|
|
15
|
+
allowLocalPeerId = false,
|
|
16
16
|
peerIdDistanceLimit?: PeerID,
|
|
17
17
|
excludedPeerIDs?: PeerID[]
|
|
18
18
|
) {
|
|
19
19
|
super(ownId, maxSize, defaultContactQueryLimit)
|
|
20
20
|
this.compareIds = this.compareIds.bind(this)
|
|
21
|
-
this.
|
|
21
|
+
this.allowLocalPeerId = allowLocalPeerId
|
|
22
22
|
this.peerIdDistanceLimit = peerIdDistanceLimit
|
|
23
23
|
this.excludedPeerIDs = excludedPeerIDs
|
|
24
24
|
}
|
|
@@ -37,7 +37,7 @@ export class SortedContactList<C extends { getPeerId: () => PeerID }> extends Co
|
|
|
37
37
|
return
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
if ((!this.
|
|
40
|
+
if ((!this.allowLocalPeerId && this.ownId.equals(contact.getPeerId())) ||
|
|
41
41
|
(this.peerIdDistanceLimit !== undefined && this.compareIds(this.peerIdDistanceLimit, contact.getPeerId()) < 0)) {
|
|
42
42
|
return
|
|
43
43
|
}
|
|
@@ -5,10 +5,11 @@ import KBucket from 'k-bucket'
|
|
|
5
5
|
import { v4 } from 'uuid'
|
|
6
6
|
import { PeerID } from '../../helpers/PeerID'
|
|
7
7
|
import { PeerDescriptor } from '../../proto/packages/dht/protos/DhtRpc'
|
|
8
|
-
import {
|
|
8
|
+
import { DhtNodeRpcClient } from '../../proto/packages/dht/protos/DhtRpc.client'
|
|
9
9
|
import { SortedContactList } from '../contact/SortedContactList'
|
|
10
|
-
import {
|
|
11
|
-
import { areEqualPeerDescriptors,
|
|
10
|
+
import { DhtNodeRpcRemote } from '../DhtNodeRpcRemote'
|
|
11
|
+
import { areEqualPeerDescriptors, getNodeIdFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
|
|
12
|
+
import { ServiceID } from '../../types/ServiceID'
|
|
12
13
|
|
|
13
14
|
const logger = new Logger(module)
|
|
14
15
|
|
|
@@ -17,15 +18,16 @@ interface DiscoverySessionEvents {
|
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
interface DiscoverySessionConfig {
|
|
20
|
-
bucket: KBucket<
|
|
21
|
-
neighborList: SortedContactList<
|
|
21
|
+
bucket: KBucket<DhtNodeRpcRemote>
|
|
22
|
+
neighborList: SortedContactList<DhtNodeRpcRemote>
|
|
22
23
|
targetId: Uint8Array
|
|
23
|
-
|
|
24
|
-
serviceId:
|
|
24
|
+
localPeerDescriptor: PeerDescriptor
|
|
25
|
+
serviceId: ServiceID
|
|
25
26
|
rpcCommunicator: RpcCommunicator
|
|
26
27
|
parallelism: number
|
|
27
28
|
noProgressLimit: number
|
|
28
|
-
newContactListener?: (
|
|
29
|
+
newContactListener?: (rpcRemote: DhtNodeRpcRemote) => void
|
|
30
|
+
rpcRequestTimeout?: number
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
export class DiscoverySession {
|
|
@@ -47,28 +49,29 @@ export class DiscoverySession {
|
|
|
47
49
|
return
|
|
48
50
|
}
|
|
49
51
|
contacts.forEach((contact) => {
|
|
50
|
-
if (!areEqualPeerDescriptors(contact, this.config.
|
|
51
|
-
const
|
|
52
|
-
this.config.
|
|
52
|
+
if (!areEqualPeerDescriptors(contact, this.config.localPeerDescriptor)) {
|
|
53
|
+
const rpcRemote = new DhtNodeRpcRemote(
|
|
54
|
+
this.config.localPeerDescriptor,
|
|
53
55
|
contact,
|
|
54
|
-
toProtoRpcClient(new
|
|
55
|
-
this.config.serviceId
|
|
56
|
+
toProtoRpcClient(new DhtNodeRpcClient(this.config.rpcCommunicator.getRpcClientTransport())),
|
|
57
|
+
this.config.serviceId,
|
|
58
|
+
this.config.rpcRequestTimeout
|
|
56
59
|
)
|
|
57
60
|
if (this.config.newContactListener) {
|
|
58
|
-
this.config.newContactListener(
|
|
61
|
+
this.config.newContactListener(rpcRemote)
|
|
59
62
|
}
|
|
60
|
-
if (!this.config.neighborList.getContact(
|
|
61
|
-
this.config.neighborList.addContact(
|
|
63
|
+
if (!this.config.neighborList.getContact(rpcRemote.getPeerId())) {
|
|
64
|
+
this.config.neighborList.addContact(rpcRemote)
|
|
62
65
|
}
|
|
63
66
|
}
|
|
64
67
|
})
|
|
65
68
|
}
|
|
66
69
|
|
|
67
|
-
private async getClosestPeersFromContact(contact:
|
|
70
|
+
private async getClosestPeersFromContact(contact: DhtNodeRpcRemote): Promise<PeerDescriptor[]> {
|
|
68
71
|
if (this.stopped) {
|
|
69
72
|
return []
|
|
70
73
|
}
|
|
71
|
-
logger.trace(`Getting closest peers from contact: ${
|
|
74
|
+
logger.trace(`Getting closest peers from contact: ${getNodeIdFromPeerDescriptor(contact.getPeerDescriptor())}`)
|
|
72
75
|
this.outgoingClosestPeersRequestsCounter++
|
|
73
76
|
this.config.neighborList.setContacted(contact.getPeerId())
|
|
74
77
|
const returnedContacts = await contact.getClosestPeers(this.config.targetId)
|
|
@@ -90,7 +93,7 @@ export class DiscoverySession {
|
|
|
90
93
|
}
|
|
91
94
|
}
|
|
92
95
|
|
|
93
|
-
private onClosestPeersRequestFailed(peer:
|
|
96
|
+
private onClosestPeersRequestFailed(peer: DhtNodeRpcRemote) {
|
|
94
97
|
if (!this.ongoingClosestPeersRequests.has(peer.getPeerId().toKey())) {
|
|
95
98
|
return
|
|
96
99
|
}
|
|
@@ -104,7 +107,7 @@ export class DiscoverySession {
|
|
|
104
107
|
return
|
|
105
108
|
}
|
|
106
109
|
const uncontacted = this.config.neighborList.getUncontactedContacts(this.config.parallelism)
|
|
107
|
-
if (uncontacted.length
|
|
110
|
+
if (uncontacted.length === 0 || this.noProgressCounter >= this.config.noProgressLimit) {
|
|
108
111
|
this.emitter.emit('discoveryCompleted')
|
|
109
112
|
this.stopped = true
|
|
110
113
|
return
|
|
@@ -125,8 +128,8 @@ export class DiscoverySession {
|
|
|
125
128
|
}
|
|
126
129
|
}
|
|
127
130
|
|
|
128
|
-
public async findClosestNodes(timeout: number): Promise<SortedContactList<
|
|
129
|
-
if (this.config.neighborList.getUncontactedContacts(this.config.parallelism).length
|
|
131
|
+
public async findClosestNodes(timeout: number): Promise<SortedContactList<DhtNodeRpcRemote>> {
|
|
132
|
+
if (this.config.neighborList.getUncontactedContacts(this.config.parallelism).length === 0) {
|
|
130
133
|
logger.trace('getUncontactedContacts length was 0 in beginning of discovery, this.neighborList.size: '
|
|
131
134
|
+ this.config.neighborList.getSize())
|
|
132
135
|
return this.config.neighborList
|
|
@@ -1,31 +1,28 @@
|
|
|
1
1
|
import { DiscoverySession } from './DiscoverySession'
|
|
2
|
-
import {
|
|
3
|
-
import { areEqualPeerDescriptors,
|
|
2
|
+
import { DhtNodeRpcRemote } from '../DhtNodeRpcRemote'
|
|
3
|
+
import { areEqualPeerDescriptors, getNodeIdFromPeerDescriptor, peerIdFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
|
|
4
4
|
import { PeerDescriptor } from '../../proto/packages/dht/protos/DhtRpc'
|
|
5
5
|
import { Logger, scheduleAtInterval, setAbortableTimeout } from '@streamr/utils'
|
|
6
6
|
import KBucket from 'k-bucket'
|
|
7
7
|
import { SortedContactList } from '../contact/SortedContactList'
|
|
8
8
|
import { ConnectionManager } from '../../connection/ConnectionManager'
|
|
9
|
-
import { PeerIDKey } from '../../helpers/PeerID'
|
|
10
9
|
import { RoutingRpcCommunicator } from '../../transport/RoutingRpcCommunicator'
|
|
11
|
-
import { RandomContactList } from '../contact/RandomContactList'
|
|
12
10
|
import { createRandomKademliaId } from '../../helpers/kademliaId'
|
|
11
|
+
import { ServiceID } from '../../types/ServiceID'
|
|
13
12
|
|
|
14
13
|
interface PeerDiscoveryConfig {
|
|
15
14
|
rpcCommunicator: RoutingRpcCommunicator
|
|
16
|
-
|
|
17
|
-
bucket: KBucket<
|
|
18
|
-
|
|
19
|
-
neighborList: SortedContactList<RemoteDhtNode>
|
|
20
|
-
randomPeers: RandomContactList<RemoteDhtNode>
|
|
21
|
-
openInternetPeers: SortedContactList<RemoteDhtNode>
|
|
15
|
+
localPeerDescriptor: PeerDescriptor
|
|
16
|
+
bucket: KBucket<DhtNodeRpcRemote>
|
|
17
|
+
neighborList: SortedContactList<DhtNodeRpcRemote>
|
|
22
18
|
joinNoProgressLimit: number
|
|
23
19
|
peerDiscoveryQueryBatchSize: number
|
|
24
|
-
serviceId:
|
|
20
|
+
serviceId: ServiceID
|
|
25
21
|
parallelism: number
|
|
26
22
|
joinTimeout: number
|
|
27
23
|
addContact: (contact: PeerDescriptor, setActive?: boolean) => void
|
|
28
24
|
connectionManager?: ConnectionManager
|
|
25
|
+
rpcRequestTimeout?: number
|
|
29
26
|
}
|
|
30
27
|
|
|
31
28
|
const logger = new Logger(module)
|
|
@@ -52,14 +49,14 @@ export class PeerDiscovery {
|
|
|
52
49
|
this.joinCalled = true
|
|
53
50
|
logger.debug(
|
|
54
51
|
`Joining ${this.config.serviceId === 'layer0' ? 'The Streamr Network' : `Control Layer for ${this.config.serviceId}`}`
|
|
55
|
-
+ ` via entrypoint ${
|
|
52
|
+
+ ` via entrypoint ${getNodeIdFromPeerDescriptor(entryPointDescriptor)}`
|
|
56
53
|
)
|
|
57
|
-
if (areEqualPeerDescriptors(entryPointDescriptor, this.config.
|
|
54
|
+
if (areEqualPeerDescriptors(entryPointDescriptor, this.config.localPeerDescriptor)) {
|
|
58
55
|
return
|
|
59
56
|
}
|
|
60
57
|
this.config.connectionManager?.lockConnection(entryPointDescriptor, `${this.config.serviceId}::joinDht`)
|
|
61
58
|
this.config.addContact(entryPointDescriptor)
|
|
62
|
-
const targetId = peerIdFromPeerDescriptor(this.config.
|
|
59
|
+
const targetId = peerIdFromPeerDescriptor(this.config.localPeerDescriptor).value
|
|
63
60
|
const closest = this.config.bucket.closest(targetId, this.config.peerDiscoveryQueryBatchSize)
|
|
64
61
|
this.config.neighborList.addContacts(closest)
|
|
65
62
|
const sessions = [this.createSession(targetId)]
|
|
@@ -76,12 +73,12 @@ export class PeerDiscovery {
|
|
|
76
73
|
bucket: this.config.bucket,
|
|
77
74
|
neighborList: this.config.neighborList,
|
|
78
75
|
targetId,
|
|
79
|
-
|
|
76
|
+
localPeerDescriptor: this.config.localPeerDescriptor,
|
|
80
77
|
serviceId: this.config.serviceId,
|
|
81
78
|
rpcCommunicator: this.config.rpcCommunicator,
|
|
82
79
|
parallelism: this.config.parallelism,
|
|
83
80
|
noProgressLimit: this.config.joinNoProgressLimit,
|
|
84
|
-
newContactListener: (newPeer:
|
|
81
|
+
newContactListener: (newPeer: DhtNodeRpcRemote) => this.config.addContact(newPeer.getPeerDescriptor())
|
|
85
82
|
}
|
|
86
83
|
return new DiscoverySession(sessionOptions)
|
|
87
84
|
}
|
|
@@ -139,9 +136,9 @@ export class PeerDiscovery {
|
|
|
139
136
|
if (this.isStopped()) {
|
|
140
137
|
return
|
|
141
138
|
}
|
|
142
|
-
const nodes = this.config.bucket.closest(peerIdFromPeerDescriptor(this.config.
|
|
143
|
-
await Promise.allSettled(nodes.map(async (peer:
|
|
144
|
-
const contacts = await peer.getClosestPeers(this.config.
|
|
139
|
+
const nodes = this.config.bucket.closest(peerIdFromPeerDescriptor(this.config.localPeerDescriptor).value, this.config.parallelism)
|
|
140
|
+
await Promise.allSettled(nodes.map(async (peer: DhtNodeRpcRemote) => {
|
|
141
|
+
const contacts = await peer.getClosestPeers(this.config.localPeerDescriptor.kademliaId)
|
|
145
142
|
contacts.forEach((contact) => {
|
|
146
143
|
this.config.addContact(contact)
|
|
147
144
|
})
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Logger } from '@streamr/utils'
|
|
2
|
+
import { PeerDescriptor, RouteMessageAck, RouteMessageWrapper } from '../../proto/packages/dht/protos/DhtRpc'
|
|
3
|
+
import { IFindRpc } from '../../proto/packages/dht/protos/DhtRpc.server'
|
|
4
|
+
import { getNodeIdFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
|
|
5
|
+
import { createRouteMessageAck } from '../routing/RouterRpcLocal'
|
|
6
|
+
import { getPreviousPeer } from '../routing/getPreviousPeer'
|
|
7
|
+
|
|
8
|
+
const logger = new Logger(module)
|
|
9
|
+
|
|
10
|
+
interface FindRpcLocalConfig {
|
|
11
|
+
doRouteFindRequest: (routedMessage: RouteMessageWrapper) => RouteMessageAck
|
|
12
|
+
addContact: (contact: PeerDescriptor, setActive?: boolean) => void
|
|
13
|
+
isMostLikelyDuplicate: (requestId: string) => boolean
|
|
14
|
+
addToDuplicateDetector: (requestId: string) => void
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export class FindRpcLocal implements IFindRpc {
|
|
18
|
+
|
|
19
|
+
private readonly config: FindRpcLocalConfig
|
|
20
|
+
|
|
21
|
+
constructor(config: FindRpcLocalConfig) {
|
|
22
|
+
this.config = config
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async routeFindRequest(routedMessage: RouteMessageWrapper): Promise<RouteMessageAck> {
|
|
26
|
+
if (this.config.isMostLikelyDuplicate(routedMessage.requestId)) {
|
|
27
|
+
return createRouteMessageAck(routedMessage, 'message given to routeFindRequest() service is likely a duplicate')
|
|
28
|
+
}
|
|
29
|
+
const senderId = getNodeIdFromPeerDescriptor(getPreviousPeer(routedMessage) ?? routedMessage.sourcePeer!)
|
|
30
|
+
logger.trace(`Received routeFindRequest call from ${senderId}`)
|
|
31
|
+
this.config.addContact(routedMessage.sourcePeer!, true)
|
|
32
|
+
this.config.addToDuplicateDetector(routedMessage.requestId)
|
|
33
|
+
return this.config.doRouteFindRequest(routedMessage)
|
|
34
|
+
}
|
|
35
|
+
}
|