@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
package/src/dht/DhtNode.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DhtNodeRpcRemote } from './DhtNodeRpcRemote'
|
|
2
2
|
import KBucket from 'k-bucket'
|
|
3
3
|
import { EventEmitter } from 'eventemitter3'
|
|
4
4
|
import { SortedContactList } from './contact/SortedContactList'
|
|
5
5
|
import { RoutingRpcCommunicator } from '../transport/RoutingRpcCommunicator'
|
|
6
|
-
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
7
6
|
import { PeerID, PeerIDKey } from '../helpers/PeerID'
|
|
8
7
|
import {
|
|
9
8
|
ClosestPeersRequest,
|
|
@@ -16,10 +15,14 @@ import {
|
|
|
16
15
|
PingRequest,
|
|
17
16
|
PingResponse,
|
|
18
17
|
DataEntry,
|
|
18
|
+
ExternalFindDataRequest,
|
|
19
|
+
ExternalFindDataResponse,
|
|
20
|
+
ExternalStoreDataRequest,
|
|
21
|
+
ExternalStoreDataResponse,
|
|
19
22
|
} from '../proto/packages/dht/protos/DhtRpc'
|
|
20
|
-
import {
|
|
23
|
+
import { ITransport, TransportEvents } from '../transport/ITransport'
|
|
21
24
|
import { ConnectionManager, PortRange, TlsCertificate } from '../connection/ConnectionManager'
|
|
22
|
-
import {
|
|
25
|
+
import { DhtNodeRpcClient, ExternalApiRpcClient } from '../proto/packages/dht/protos/DhtRpc.client'
|
|
23
26
|
import {
|
|
24
27
|
Logger,
|
|
25
28
|
MetricsContext,
|
|
@@ -29,32 +32,33 @@ import {
|
|
|
29
32
|
} from '@streamr/utils'
|
|
30
33
|
import { toProtoRpcClient } from '@streamr/proto-rpc'
|
|
31
34
|
import { RandomContactList } from './contact/RandomContactList'
|
|
32
|
-
import { Empty } from '../proto/google/protobuf/empty'
|
|
33
|
-
import { DhtCallContext } from '../rpc-protocol/DhtCallContext'
|
|
34
35
|
import { Any } from '../proto/google/protobuf/any'
|
|
35
|
-
import {
|
|
36
|
+
import {
|
|
37
|
+
areEqualPeerDescriptors,
|
|
38
|
+
getNodeIdFromPeerDescriptor,
|
|
39
|
+
keyFromPeerDescriptor,
|
|
40
|
+
peerIdFromPeerDescriptor
|
|
41
|
+
} from '../helpers/peerIdFromPeerDescriptor'
|
|
36
42
|
import { Router } from './routing/Router'
|
|
37
|
-
import {
|
|
43
|
+
import { Finder, FindResult } from './find/Finder'
|
|
38
44
|
import { StoreRpcLocal } from './store/StoreRpcLocal'
|
|
39
45
|
import { PeerDiscovery } from './discovery/PeerDiscovery'
|
|
40
46
|
import { LocalDataStore } from './store/LocalDataStore'
|
|
41
|
-
import { IceServer } from '../connection/
|
|
42
|
-
import { registerExternalApiRpcMethods } from './registerExternalApiRpcMethods'
|
|
47
|
+
import { IceServer } from '../connection/webrtc/WebrtcConnector'
|
|
43
48
|
import { ExternalApiRpcRemote } from './ExternalApiRpcRemote'
|
|
44
49
|
import { UUID } from '../helpers/UUID'
|
|
45
50
|
import { isBrowserEnvironment } from '../helpers/browser/isBrowserEnvironment'
|
|
46
51
|
import { sample } from 'lodash'
|
|
47
52
|
import { DefaultConnectorFacade, DefaultConnectorFacadeConfig } from '../connection/ConnectorFacade'
|
|
48
53
|
import { MarkRequired } from 'ts-essentials'
|
|
54
|
+
import { DhtNodeRpcLocal } from './DhtNodeRpcLocal'
|
|
55
|
+
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
56
|
+
import { ExternalApiRpcLocal } from './ExternalApiRpcLocal'
|
|
49
57
|
|
|
50
58
|
export interface DhtNodeEvents {
|
|
51
59
|
newContact: (peerDescriptor: PeerDescriptor, closestPeers: PeerDescriptor[]) => void
|
|
52
60
|
contactRemoved: (peerDescriptor: PeerDescriptor, closestPeers: PeerDescriptor[]) => void
|
|
53
61
|
joinCompleted: () => void
|
|
54
|
-
newKbucketContact: (peerDescriptor: PeerDescriptor, closestPeers: PeerDescriptor[]) => void
|
|
55
|
-
kbucketContactRemoved: (peerDescriptor: PeerDescriptor) => void
|
|
56
|
-
newOpenInternetContact: (peerDescriptor: PeerDescriptor, closestPeers: PeerDescriptor[]) => void
|
|
57
|
-
openInternetContactRemoved: (peerDescriptor: PeerDescriptor, closestPeers: PeerDescriptor[]) => void
|
|
58
62
|
newRandomContact: (peerDescriptor: PeerDescriptor, closestPeers: PeerDescriptor[]) => void
|
|
59
63
|
randomContactRemoved: (peerDescriptor: PeerDescriptor, closestPeers: PeerDescriptor[]) => void
|
|
60
64
|
}
|
|
@@ -78,6 +82,7 @@ export interface DhtNodeOptions {
|
|
|
78
82
|
entryPoints?: PeerDescriptor[]
|
|
79
83
|
websocketHost?: string
|
|
80
84
|
websocketPortRange?: PortRange
|
|
85
|
+
websocketServerEnableTls?: boolean
|
|
81
86
|
peerId?: string
|
|
82
87
|
|
|
83
88
|
rpcRequestTimeout?: number
|
|
@@ -91,6 +96,8 @@ export interface DhtNodeOptions {
|
|
|
91
96
|
maxConnections?: number
|
|
92
97
|
tlsCertificate?: TlsCertificate
|
|
93
98
|
externalIp?: string
|
|
99
|
+
autoCertifierUrl?: string
|
|
100
|
+
autoCertifierConfigFile?: string
|
|
94
101
|
}
|
|
95
102
|
|
|
96
103
|
type StrictDhtNodeOptions = MarkRequired<DhtNodeOptions,
|
|
@@ -124,7 +131,6 @@ export const createPeerDescriptor = (msg?: ConnectivityResponse, peerId?: string
|
|
|
124
131
|
const ret: PeerDescriptor = { kademliaId, type: nodeType }
|
|
125
132
|
if (msg && msg.websocket) {
|
|
126
133
|
ret.websocket = { host: msg.websocket.host, port: msg.websocket.port, tls: msg.websocket.tls }
|
|
127
|
-
ret.openInternet = true
|
|
128
134
|
}
|
|
129
135
|
return ret
|
|
130
136
|
}
|
|
@@ -132,18 +138,17 @@ export const createPeerDescriptor = (msg?: ConnectivityResponse, peerId?: string
|
|
|
132
138
|
export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
133
139
|
|
|
134
140
|
private readonly config: StrictDhtNodeOptions
|
|
135
|
-
private bucket?: KBucket<
|
|
136
|
-
private connections: Map<PeerIDKey,
|
|
137
|
-
private neighborList?: SortedContactList<
|
|
138
|
-
private
|
|
139
|
-
private randomPeers?: RandomContactList<RemoteDhtNode>
|
|
141
|
+
private bucket?: KBucket<DhtNodeRpcRemote>
|
|
142
|
+
private connections: Map<PeerIDKey, DhtNodeRpcRemote> = new Map()
|
|
143
|
+
private neighborList?: SortedContactList<DhtNodeRpcRemote>
|
|
144
|
+
private randomPeers?: RandomContactList<DhtNodeRpcRemote>
|
|
140
145
|
private rpcCommunicator?: RoutingRpcCommunicator
|
|
141
146
|
private transport?: ITransport
|
|
142
|
-
private
|
|
147
|
+
private localPeerDescriptor?: PeerDescriptor
|
|
143
148
|
public router?: Router
|
|
144
149
|
private storeRpcLocal?: StoreRpcLocal
|
|
145
150
|
private localDataStore = new LocalDataStore()
|
|
146
|
-
private
|
|
151
|
+
private finder?: Finder
|
|
147
152
|
private peerDiscovery?: PeerDiscovery
|
|
148
153
|
|
|
149
154
|
public connectionManager?: ConnectionManager
|
|
@@ -188,7 +193,7 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
188
193
|
// If transport is given, do not create a ConnectionManager
|
|
189
194
|
if (this.config.transport) {
|
|
190
195
|
this.transport = this.config.transport
|
|
191
|
-
this.
|
|
196
|
+
this.localPeerDescriptor = this.transport.getLocalPeerDescriptor()
|
|
192
197
|
if (this.config.transport instanceof ConnectionManager) {
|
|
193
198
|
this.connectionManager = this.config.transport
|
|
194
199
|
}
|
|
@@ -203,9 +208,12 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
203
208
|
webrtcNewConnectionTimeout: this.config.webrtcNewConnectionTimeout,
|
|
204
209
|
webrtcPortRange: this.config.webrtcPortRange,
|
|
205
210
|
maxMessageSize: this.config.maxMessageSize,
|
|
211
|
+
websocketServerEnableTls: this.config.websocketServerEnableTls,
|
|
206
212
|
tlsCertificate: this.config.tlsCertificate,
|
|
207
213
|
externalIp: this.config.externalIp,
|
|
208
|
-
|
|
214
|
+
autoCertifierUrl: this.config.autoCertifierUrl,
|
|
215
|
+
autoCertifierConfigFile: this.config.autoCertifierConfigFile,
|
|
216
|
+
createLocalPeerDescriptor: (connectivityResponse: ConnectivityResponse) => this.generatePeerDescriptorCallBack(connectivityResponse),
|
|
209
217
|
}
|
|
210
218
|
// If own PeerDescriptor is given in config, create a ConnectionManager with ws server
|
|
211
219
|
if (this.config.peerDescriptor?.websocket) {
|
|
@@ -238,38 +246,35 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
238
246
|
|
|
239
247
|
this.transport.on('message', (message: Message) => this.handleMessage(message))
|
|
240
248
|
|
|
241
|
-
this.
|
|
242
|
-
this.initKBuckets(peerIdFromPeerDescriptor(this.ownPeerDescriptor!))
|
|
249
|
+
this.initKBuckets(peerIdFromPeerDescriptor(this.localPeerDescriptor!))
|
|
243
250
|
this.peerDiscovery = new PeerDiscovery({
|
|
244
251
|
rpcCommunicator: this.rpcCommunicator,
|
|
245
|
-
|
|
252
|
+
localPeerDescriptor: this.localPeerDescriptor!,
|
|
246
253
|
bucket: this.bucket!,
|
|
247
|
-
connections: this.connections,
|
|
248
254
|
neighborList: this.neighborList!,
|
|
249
|
-
randomPeers: this.randomPeers!,
|
|
250
|
-
openInternetPeers: this.openInternetPeers!,
|
|
251
255
|
joinNoProgressLimit: this.config.joinNoProgressLimit,
|
|
252
256
|
peerDiscoveryQueryBatchSize: this.config.peerDiscoveryQueryBatchSize,
|
|
253
257
|
joinTimeout: this.config.dhtJoinTimeout,
|
|
254
258
|
serviceId: this.config.serviceId,
|
|
255
259
|
parallelism: this.config.joinParallelism,
|
|
256
260
|
addContact: this.addNewContact.bind(this),
|
|
257
|
-
connectionManager: this.connectionManager
|
|
261
|
+
connectionManager: this.connectionManager,
|
|
262
|
+
rpcRequestTimeout: this.config.rpcRequestTimeout
|
|
258
263
|
})
|
|
259
264
|
this.router = new Router({
|
|
260
265
|
rpcCommunicator: this.rpcCommunicator,
|
|
261
266
|
connections: this.connections,
|
|
262
|
-
|
|
267
|
+
localPeerDescriptor: this.localPeerDescriptor!,
|
|
263
268
|
addContact: this.addNewContact.bind(this),
|
|
264
269
|
serviceId: this.config.serviceId,
|
|
265
270
|
connectionManager: this.connectionManager
|
|
266
271
|
})
|
|
267
|
-
this.
|
|
272
|
+
this.finder = new Finder({
|
|
268
273
|
rpcCommunicator: this.rpcCommunicator,
|
|
269
274
|
router: this.router,
|
|
270
275
|
sessionTransport: this,
|
|
271
276
|
connections: this.connections,
|
|
272
|
-
|
|
277
|
+
localPeerDescriptor: this.localPeerDescriptor!,
|
|
273
278
|
serviceId: this.config.serviceId,
|
|
274
279
|
addContact: this.addNewContact.bind(this),
|
|
275
280
|
isPeerCloserToIdThanSelf: this.isPeerCloserToIdThanSelf.bind(this),
|
|
@@ -277,8 +282,8 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
277
282
|
})
|
|
278
283
|
this.storeRpcLocal = new StoreRpcLocal({
|
|
279
284
|
rpcCommunicator: this.rpcCommunicator,
|
|
280
|
-
|
|
281
|
-
|
|
285
|
+
finder: this.finder,
|
|
286
|
+
localPeerDescriptor: this.localPeerDescriptor!,
|
|
282
287
|
serviceId: this.config.serviceId,
|
|
283
288
|
highestTtl: this.config.storeHighestTtl,
|
|
284
289
|
maxTtl: this.config.storeMaxTtl,
|
|
@@ -287,168 +292,187 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
287
292
|
dhtNodeEmitter: this,
|
|
288
293
|
getNodesClosestToIdFromBucket: (id: Uint8Array, n?: number) => {
|
|
289
294
|
return this.bucket!.closest(id, n)
|
|
290
|
-
}
|
|
295
|
+
},
|
|
296
|
+
rpcRequestTimeout: this.config.rpcRequestTimeout
|
|
291
297
|
})
|
|
292
|
-
|
|
298
|
+
this.bindRpcLocalMethods()
|
|
293
299
|
if (this.connectionManager! && this.config.entryPoints && this.config.entryPoints.length > 0
|
|
294
|
-
&& !areEqualPeerDescriptors(this.config.entryPoints[0], this.
|
|
300
|
+
&& !areEqualPeerDescriptors(this.config.entryPoints[0], this.localPeerDescriptor!)) {
|
|
295
301
|
this.connectToEntryPoint(this.config.entryPoints[0])
|
|
296
302
|
}
|
|
297
303
|
}
|
|
298
304
|
|
|
299
|
-
private initKBuckets
|
|
300
|
-
this.bucket = new KBucket<
|
|
305
|
+
private initKBuckets(selfId: PeerID) {
|
|
306
|
+
this.bucket = new KBucket<DhtNodeRpcRemote>({
|
|
301
307
|
localNodeId: selfId.value,
|
|
302
308
|
numberOfNodesPerKBucket: this.config.numberOfNodesPerKBucket,
|
|
303
309
|
numberOfNodesToPing: this.config.numberOfNodesPerKBucket
|
|
304
310
|
})
|
|
305
|
-
this.bucket.on('ping', (oldContacts:
|
|
306
|
-
this.bucket.on('removed', (contact:
|
|
307
|
-
this.bucket.on('added', (contact:
|
|
311
|
+
this.bucket.on('ping', (oldContacts: DhtNodeRpcRemote[], newContact: DhtNodeRpcRemote) => this.onKBucketPing(oldContacts, newContact))
|
|
312
|
+
this.bucket.on('removed', (contact: DhtNodeRpcRemote) => this.onKBucketRemoved(contact))
|
|
313
|
+
this.bucket.on('added', (contact: DhtNodeRpcRemote) => this.onKBucketAdded(contact))
|
|
308
314
|
this.bucket.on('updated', () => {
|
|
309
315
|
// TODO: Update contact info to the connection manager and reconnect
|
|
310
316
|
})
|
|
311
317
|
this.neighborList = new SortedContactList(selfId, this.config.maxNeighborListSize)
|
|
312
|
-
this.neighborList.on('contactRemoved', (removedContact:
|
|
318
|
+
this.neighborList.on('contactRemoved', (removedContact: DhtNodeRpcRemote, activeContacts: DhtNodeRpcRemote[]) => {
|
|
313
319
|
if (this.stopped) {
|
|
314
320
|
return
|
|
315
321
|
}
|
|
316
322
|
this.emit('contactRemoved', removedContact.getPeerDescriptor(), activeContacts.map((c) => c.getPeerDescriptor()))
|
|
317
323
|
this.randomPeers!.addContact(
|
|
318
|
-
new
|
|
319
|
-
this.
|
|
324
|
+
new DhtNodeRpcRemote(
|
|
325
|
+
this.localPeerDescriptor!,
|
|
320
326
|
removedContact.getPeerDescriptor(),
|
|
321
|
-
toProtoRpcClient(new
|
|
322
|
-
this.config.serviceId
|
|
327
|
+
toProtoRpcClient(new DhtNodeRpcClient(this.rpcCommunicator!.getRpcClientTransport())),
|
|
328
|
+
this.config.serviceId,
|
|
329
|
+
this.config.rpcRequestTimeout
|
|
323
330
|
)
|
|
324
331
|
)
|
|
325
332
|
})
|
|
326
|
-
this.neighborList.on('newContact', (newContact:
|
|
333
|
+
this.neighborList.on('newContact', (newContact: DhtNodeRpcRemote, activeContacts: DhtNodeRpcRemote[]) =>
|
|
327
334
|
this.emit('newContact', newContact.getPeerDescriptor(), activeContacts.map((c) => c.getPeerDescriptor()))
|
|
328
335
|
)
|
|
329
|
-
this.openInternetPeers = new SortedContactList(selfId, this.config.maxNeighborListSize / 2)
|
|
330
|
-
this.openInternetPeers.on('contactRemoved', (removedContact: RemoteDhtNode, activeContacts: RemoteDhtNode[]) =>
|
|
331
|
-
this.emit('openInternetContactRemoved', removedContact.getPeerDescriptor(), activeContacts.map((c) => c.getPeerDescriptor()))
|
|
332
|
-
)
|
|
333
|
-
this.openInternetPeers.on('newContact', (newContact: RemoteDhtNode, activeContacts: RemoteDhtNode[]) =>
|
|
334
|
-
this.emit('newOpenInternetContact', newContact.getPeerDescriptor(), activeContacts.map((c) => c.getPeerDescriptor()))
|
|
335
|
-
)
|
|
336
336
|
this.transport!.on('connected', (peerDescriptor: PeerDescriptor) => this.onTransportConnected(peerDescriptor))
|
|
337
337
|
|
|
338
|
-
this.transport!.on('disconnected', (peerDescriptor: PeerDescriptor,
|
|
339
|
-
this.onTransportDisconnected(peerDescriptor,
|
|
338
|
+
this.transport!.on('disconnected', (peerDescriptor: PeerDescriptor, gracefulLeave: boolean) => {
|
|
339
|
+
this.onTransportDisconnected(peerDescriptor, gracefulLeave)
|
|
340
340
|
})
|
|
341
341
|
|
|
342
342
|
this.transport!.getAllConnectionPeerDescriptors().forEach((peer) => {
|
|
343
|
-
const
|
|
344
|
-
this.
|
|
343
|
+
const rpcRemote = new DhtNodeRpcRemote(
|
|
344
|
+
this.localPeerDescriptor!,
|
|
345
345
|
peer,
|
|
346
|
-
toProtoRpcClient(new
|
|
347
|
-
this.config.serviceId
|
|
346
|
+
toProtoRpcClient(new DhtNodeRpcClient(this.rpcCommunicator!.getRpcClientTransport())),
|
|
347
|
+
this.config.serviceId,
|
|
348
|
+
this.config.rpcRequestTimeout
|
|
348
349
|
)
|
|
349
|
-
if (areEqualPeerDescriptors(peer, this.
|
|
350
|
+
if (areEqualPeerDescriptors(peer, this.localPeerDescriptor!)) {
|
|
350
351
|
logger.error('own peerdescriptor added to connections in initKBucket')
|
|
351
352
|
}
|
|
352
|
-
this.connections.set(keyFromPeerDescriptor(peer),
|
|
353
|
+
this.connections.set(keyFromPeerDescriptor(peer), rpcRemote)
|
|
353
354
|
})
|
|
354
355
|
this.randomPeers = new RandomContactList(selfId, this.config.maxNeighborListSize)
|
|
355
|
-
this.randomPeers.on('contactRemoved', (removedContact:
|
|
356
|
+
this.randomPeers.on('contactRemoved', (removedContact: DhtNodeRpcRemote, activeContacts: DhtNodeRpcRemote[]) =>
|
|
356
357
|
this.emit('randomContactRemoved', removedContact.getPeerDescriptor(), activeContacts.map((c) => c.getPeerDescriptor()))
|
|
357
358
|
)
|
|
358
|
-
this.randomPeers.on('newContact', (newContact:
|
|
359
|
+
this.randomPeers.on('newContact', (newContact: DhtNodeRpcRemote, activeContacts: DhtNodeRpcRemote[]) =>
|
|
359
360
|
this.emit('newRandomContact', newContact.getPeerDescriptor(), activeContacts.map((c) => c.getPeerDescriptor()))
|
|
360
361
|
)
|
|
361
362
|
}
|
|
362
363
|
|
|
363
364
|
private onTransportConnected(peerDescriptor: PeerDescriptor): void {
|
|
364
365
|
|
|
365
|
-
if (areEqualPeerDescriptors(this.
|
|
366
|
+
if (areEqualPeerDescriptors(this.localPeerDescriptor!, peerDescriptor)) {
|
|
366
367
|
logger.error('onTransportConnected() to self')
|
|
367
368
|
}
|
|
368
369
|
|
|
369
|
-
const
|
|
370
|
-
this.
|
|
370
|
+
const rpcRemote = new DhtNodeRpcRemote(
|
|
371
|
+
this.localPeerDescriptor!,
|
|
371
372
|
peerDescriptor,
|
|
372
|
-
toProtoRpcClient(new
|
|
373
|
-
this.config.serviceId
|
|
373
|
+
toProtoRpcClient(new DhtNodeRpcClient(this.rpcCommunicator!.getRpcClientTransport())),
|
|
374
|
+
this.config.serviceId,
|
|
375
|
+
this.config.rpcRequestTimeout
|
|
374
376
|
)
|
|
375
|
-
if (!this.connections.has(PeerID.fromValue(
|
|
376
|
-
this.connections.set(PeerID.fromValue(
|
|
377
|
+
if (!this.connections.has(PeerID.fromValue(rpcRemote.id).toKey())) {
|
|
378
|
+
this.connections.set(PeerID.fromValue(rpcRemote.id).toKey(), rpcRemote)
|
|
377
379
|
logger.trace('connectionschange add ' + this.connections.size)
|
|
378
380
|
} else {
|
|
379
381
|
logger.trace('new connection not set to connections, there is already a connection with the peer ID')
|
|
380
382
|
}
|
|
381
|
-
logger.trace('connected: ' +
|
|
383
|
+
logger.trace('connected: ' + getNodeIdFromPeerDescriptor(peerDescriptor) + ' ' + this.connections.size)
|
|
382
384
|
this.emit('connected', peerDescriptor)
|
|
383
385
|
}
|
|
384
386
|
|
|
385
|
-
private onTransportDisconnected(peerDescriptor: PeerDescriptor,
|
|
386
|
-
logger.trace('disconnected: ' +
|
|
387
|
+
private onTransportDisconnected(peerDescriptor: PeerDescriptor, gracefulLeave: boolean): void {
|
|
388
|
+
logger.trace('disconnected: ' + getNodeIdFromPeerDescriptor(peerDescriptor))
|
|
387
389
|
this.connections.delete(keyFromPeerDescriptor(peerDescriptor))
|
|
388
390
|
// only remove from bucket if we are on layer 0
|
|
389
391
|
if (this.connectionManager) {
|
|
390
392
|
this.bucket!.remove(peerDescriptor.kademliaId)
|
|
391
393
|
|
|
392
|
-
if (
|
|
393
|
-
logger.trace(
|
|
394
|
-
this.removeContact(peerDescriptor
|
|
394
|
+
if (gracefulLeave === true) {
|
|
395
|
+
logger.trace(getNodeIdFromPeerDescriptor(peerDescriptor) + ' ' + 'onTransportDisconnected with gracefulLeave ' + gracefulLeave)
|
|
396
|
+
this.removeContact(peerDescriptor)
|
|
395
397
|
} else {
|
|
396
|
-
logger.trace(
|
|
398
|
+
logger.trace(getNodeIdFromPeerDescriptor(peerDescriptor) + ' ' + 'onTransportDisconnected with gracefulLeave ' + gracefulLeave)
|
|
397
399
|
}
|
|
398
400
|
}
|
|
399
401
|
|
|
400
|
-
this.emit('disconnected', peerDescriptor,
|
|
402
|
+
this.emit('disconnected', peerDescriptor, gracefulLeave)
|
|
401
403
|
}
|
|
402
404
|
|
|
403
|
-
private
|
|
405
|
+
private bindRpcLocalMethods(): void {
|
|
404
406
|
if (!this.started || this.stopped) {
|
|
405
407
|
return
|
|
406
408
|
}
|
|
407
|
-
|
|
409
|
+
const dhtNodeRpcLocal = new DhtNodeRpcLocal({
|
|
410
|
+
bucket: this.bucket!,
|
|
411
|
+
serviceId: this.config.serviceId,
|
|
412
|
+
peerDiscoveryQueryBatchSize: this.config.peerDiscoveryQueryBatchSize,
|
|
413
|
+
addNewContact: (contact: PeerDescriptor) => this.addNewContact(contact),
|
|
414
|
+
removeContact: (contact: PeerDescriptor) => this.removeContact(contact)
|
|
415
|
+
})
|
|
408
416
|
this.rpcCommunicator!.registerRpcMethod(ClosestPeersRequest, ClosestPeersResponse, 'getClosestPeers',
|
|
409
|
-
(req: ClosestPeersRequest, context) =>
|
|
417
|
+
(req: ClosestPeersRequest, context) => dhtNodeRpcLocal.getClosestPeers(req, context))
|
|
410
418
|
this.rpcCommunicator!.registerRpcMethod(PingRequest, PingResponse, 'ping',
|
|
411
|
-
(req: PingRequest, context) =>
|
|
419
|
+
(req: PingRequest, context) => dhtNodeRpcLocal.ping(req, context))
|
|
412
420
|
this.rpcCommunicator!.registerRpcNotification(LeaveNotice, 'leaveNotice',
|
|
413
|
-
(req: LeaveNotice, context) =>
|
|
421
|
+
(req: LeaveNotice, context) => dhtNodeRpcLocal.leaveNotice(req, context))
|
|
422
|
+
const externalApiRpcLocal = new ExternalApiRpcLocal({
|
|
423
|
+
startFind: (idToFind: Uint8Array, fetchData: boolean, excludedPeer: PeerDescriptor) => {
|
|
424
|
+
return this.startFind(idToFind, fetchData, excludedPeer)
|
|
425
|
+
},
|
|
426
|
+
storeDataToDht: (key: Uint8Array, data: Any) => this.storeDataToDht(key, data)
|
|
427
|
+
})
|
|
428
|
+
this.rpcCommunicator!.registerRpcMethod(
|
|
429
|
+
ExternalFindDataRequest,
|
|
430
|
+
ExternalFindDataResponse,
|
|
431
|
+
'externalFindData',
|
|
432
|
+
(req: ExternalFindDataRequest, context: ServerCallContext) => externalApiRpcLocal.externalFindData(req, context),
|
|
433
|
+
{ timeout: 10000 }
|
|
434
|
+
)
|
|
435
|
+
this.rpcCommunicator!.registerRpcMethod(
|
|
436
|
+
ExternalStoreDataRequest,
|
|
437
|
+
ExternalStoreDataResponse,
|
|
438
|
+
'externalStoreData',
|
|
439
|
+
(req: ExternalStoreDataRequest) => externalApiRpcLocal.externalStoreData(req),
|
|
440
|
+
{ timeout: 10000 }
|
|
441
|
+
)
|
|
414
442
|
}
|
|
415
443
|
|
|
416
444
|
private isPeerCloserToIdThanSelf(peer1: PeerDescriptor, compareToId: PeerID): boolean {
|
|
417
445
|
const distance1 = this.bucket!.distance(peer1.kademliaId, compareToId.value)
|
|
418
|
-
const distance2 = this.bucket!.distance(this.
|
|
446
|
+
const distance2 = this.bucket!.distance(this.localPeerDescriptor!.kademliaId, compareToId.value)
|
|
419
447
|
return distance1 < distance2
|
|
420
448
|
}
|
|
421
449
|
|
|
422
450
|
private handleMessage(message: Message): void {
|
|
423
451
|
if (message.serviceId === this.config.serviceId) {
|
|
424
|
-
logger.trace('callig this.handleMessageFromPeer ' +
|
|
452
|
+
logger.trace('callig this.handleMessageFromPeer ' + getNodeIdFromPeerDescriptor(message.sourceDescriptor!)
|
|
425
453
|
+ ' ' + message.serviceId + ' ' + message.messageId)
|
|
426
454
|
this.rpcCommunicator?.handleMessageFromPeer(message)
|
|
427
455
|
} else {
|
|
428
|
-
logger.trace('emit "message" ' +
|
|
456
|
+
logger.trace('emit "message" ' + getNodeIdFromPeerDescriptor(message.sourceDescriptor!)
|
|
457
|
+
+ ' ' + message.serviceId + ' ' + message.messageId)
|
|
429
458
|
this.emit('message', message)
|
|
430
459
|
}
|
|
431
460
|
}
|
|
432
461
|
|
|
433
|
-
private generatePeerDescriptorCallBack
|
|
462
|
+
private generatePeerDescriptorCallBack(connectivityResponse: ConnectivityResponse) {
|
|
434
463
|
if (this.config.peerDescriptor) {
|
|
435
|
-
this.
|
|
464
|
+
this.localPeerDescriptor = this.config.peerDescriptor
|
|
436
465
|
} else {
|
|
437
|
-
this.
|
|
466
|
+
this.localPeerDescriptor = createPeerDescriptor(connectivityResponse, this.config.peerId)
|
|
438
467
|
}
|
|
439
|
-
return this.
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
private getClosestPeerDescriptors(kademliaId: Uint8Array, limit: number): PeerDescriptor[] {
|
|
443
|
-
const closestPeers = this.bucket!.closest(kademliaId, limit)
|
|
444
|
-
return closestPeers.map((remoteDhtNode: RemoteDhtNode) => remoteDhtNode.getPeerDescriptor())
|
|
468
|
+
return this.localPeerDescriptor
|
|
445
469
|
}
|
|
446
470
|
|
|
447
|
-
private onKBucketPing(oldContacts:
|
|
471
|
+
private onKBucketPing(oldContacts: DhtNodeRpcRemote[], newContact: DhtNodeRpcRemote): void {
|
|
448
472
|
if (this.stopped) {
|
|
449
473
|
return
|
|
450
474
|
}
|
|
451
|
-
const sortingList: SortedContactList<
|
|
475
|
+
const sortingList: SortedContactList<DhtNodeRpcRemote> = new SortedContactList(this.getNodeId(), 100)
|
|
452
476
|
sortingList.addContacts(oldContacts)
|
|
453
477
|
const sortedContacts = sortingList.getAllContacts()
|
|
454
478
|
this.connectionManager?.weakUnlockConnection(sortedContacts[sortedContacts.length - 1].getPeerDescriptor())
|
|
@@ -456,16 +480,12 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
456
480
|
this.bucket!.add(newContact)
|
|
457
481
|
}
|
|
458
482
|
|
|
459
|
-
private onKBucketRemoved(contact:
|
|
483
|
+
private onKBucketRemoved(contact: DhtNodeRpcRemote): void {
|
|
460
484
|
if (this.stopped) {
|
|
461
485
|
return
|
|
462
486
|
}
|
|
463
487
|
this.connectionManager?.weakUnlockConnection(contact.getPeerDescriptor())
|
|
464
|
-
logger.trace(`Removed contact ${
|
|
465
|
-
this.emit(
|
|
466
|
-
'kbucketContactRemoved',
|
|
467
|
-
contact.getPeerDescriptor()
|
|
468
|
-
)
|
|
488
|
+
logger.trace(`Removed contact ${getNodeIdFromPeerDescriptor(contact.getPeerDescriptor())}`)
|
|
469
489
|
if (this.bucket!.count() === 0
|
|
470
490
|
&& !this.peerDiscovery!.isJoinOngoing()
|
|
471
491
|
&& this.config.entryPoints
|
|
@@ -479,32 +499,22 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
479
499
|
}
|
|
480
500
|
}
|
|
481
501
|
|
|
482
|
-
private onKBucketAdded(contact:
|
|
502
|
+
private onKBucketAdded(contact: DhtNodeRpcRemote): void {
|
|
483
503
|
if (this.stopped) {
|
|
484
504
|
return
|
|
485
505
|
}
|
|
486
|
-
if (!
|
|
506
|
+
if (!contact.getPeerId().equals(this.getNodeId())) {
|
|
487
507
|
// Important to lock here, before the ping result is known
|
|
488
508
|
this.connectionManager?.weakLockConnection(contact.getPeerDescriptor())
|
|
489
509
|
if (this.connections.has(contact.getPeerId().toKey())) {
|
|
490
|
-
logger.trace(`Added new contact ${
|
|
491
|
-
this.emit(
|
|
492
|
-
'newKbucketContact',
|
|
493
|
-
contact.getPeerDescriptor(),
|
|
494
|
-
this.neighborList!.getClosestContacts(this.config.peerDiscoveryQueryBatchSize).map((peer) => peer.getPeerDescriptor())
|
|
495
|
-
)
|
|
510
|
+
logger.trace(`Added new contact ${getNodeIdFromPeerDescriptor(contact.getPeerDescriptor())}`)
|
|
496
511
|
} else { // open connection by pinging
|
|
497
|
-
logger.trace('starting ping ' +
|
|
512
|
+
logger.trace('starting ping ' + getNodeIdFromPeerDescriptor(contact.getPeerDescriptor()))
|
|
498
513
|
contact.ping().then((result) => {
|
|
499
514
|
if (result) {
|
|
500
|
-
logger.trace(`Added new contact ${
|
|
501
|
-
this.emit(
|
|
502
|
-
'newKbucketContact',
|
|
503
|
-
contact.getPeerDescriptor(),
|
|
504
|
-
this.neighborList!.getClosestContacts(this.config.peerDiscoveryQueryBatchSize).map((peer) => peer.getPeerDescriptor())
|
|
505
|
-
)
|
|
515
|
+
logger.trace(`Added new contact ${getNodeIdFromPeerDescriptor(contact.getPeerDescriptor())}`)
|
|
506
516
|
} else {
|
|
507
|
-
logger.trace('ping failed ' +
|
|
517
|
+
logger.trace('ping failed ' + getNodeIdFromPeerDescriptor(contact.getPeerDescriptor()))
|
|
508
518
|
this.connectionManager?.weakUnlockConnection(contact.getPeerDescriptor())
|
|
509
519
|
this.removeContact(contact.getPeerDescriptor())
|
|
510
520
|
this.addClosestContactToBucket()
|
|
@@ -529,7 +539,7 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
529
539
|
}
|
|
530
540
|
}
|
|
531
541
|
|
|
532
|
-
private getClosestActiveContactNotInBucket():
|
|
542
|
+
private getClosestActiveContactNotInBucket(): DhtNodeRpcRemote | undefined {
|
|
533
543
|
for (const contactId of this.neighborList!.getContactIds()) {
|
|
534
544
|
if (!this.bucket!.get(contactId.value) && this.neighborList!.isActive(contactId)) {
|
|
535
545
|
return this.neighborList!.getContact(contactId).contact
|
|
@@ -543,7 +553,7 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
543
553
|
}
|
|
544
554
|
|
|
545
555
|
public getNodeId(): PeerID {
|
|
546
|
-
return peerIdFromPeerDescriptor(this.
|
|
556
|
+
return peerIdFromPeerDescriptor(this.localPeerDescriptor!)
|
|
547
557
|
}
|
|
548
558
|
|
|
549
559
|
public getBucketSize(): number {
|
|
@@ -554,27 +564,24 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
554
564
|
if (!this.started || this.stopped) {
|
|
555
565
|
return
|
|
556
566
|
}
|
|
557
|
-
if (!areEqualPeerDescriptors(contact, this.
|
|
558
|
-
logger.trace(`Adding new contact ${
|
|
559
|
-
const
|
|
560
|
-
this.
|
|
567
|
+
if (!areEqualPeerDescriptors(contact, this.localPeerDescriptor!)) {
|
|
568
|
+
logger.trace(`Adding new contact ${getNodeIdFromPeerDescriptor(contact)}`)
|
|
569
|
+
const rpcRemote = new DhtNodeRpcRemote(
|
|
570
|
+
this.localPeerDescriptor!,
|
|
561
571
|
contact,
|
|
562
|
-
toProtoRpcClient(new
|
|
563
|
-
this.config.serviceId
|
|
572
|
+
toProtoRpcClient(new DhtNodeRpcClient(this.rpcCommunicator!.getRpcClientTransport())),
|
|
573
|
+
this.config.serviceId,
|
|
574
|
+
this.config.rpcRequestTimeout
|
|
564
575
|
)
|
|
565
576
|
if (!this.bucket!.get(contact.kademliaId) && !this.neighborList!.getContact(peerIdFromPeerDescriptor(contact))) {
|
|
566
|
-
this.neighborList!.addContact(
|
|
567
|
-
if (contact.openInternet) {
|
|
568
|
-
this.openInternetPeers!.addContact(remoteDhtNode)
|
|
569
|
-
}
|
|
577
|
+
this.neighborList!.addContact(rpcRemote)
|
|
570
578
|
if (setActive) {
|
|
571
579
|
const peerId = peerIdFromPeerDescriptor(contact)
|
|
572
580
|
this.neighborList!.setActive(peerId)
|
|
573
|
-
this.openInternetPeers!.setActive(peerId)
|
|
574
581
|
}
|
|
575
|
-
this.bucket!.add(
|
|
582
|
+
this.bucket!.add(rpcRemote)
|
|
576
583
|
} else {
|
|
577
|
-
this.randomPeers!.addContact(
|
|
584
|
+
this.randomPeers!.addContact(rpcRemote)
|
|
578
585
|
}
|
|
579
586
|
}
|
|
580
587
|
}
|
|
@@ -586,25 +593,22 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
586
593
|
}, 10 * 1000)
|
|
587
594
|
}
|
|
588
595
|
|
|
589
|
-
public removeContact(contact: PeerDescriptor
|
|
596
|
+
public removeContact(contact: PeerDescriptor): void {
|
|
590
597
|
if (!this.started || this.stopped) {
|
|
591
598
|
return
|
|
592
599
|
}
|
|
593
|
-
logger.trace(`Removing contact ${
|
|
600
|
+
logger.trace(`Removing contact ${getNodeIdFromPeerDescriptor(contact)}`)
|
|
594
601
|
const peerId = peerIdFromPeerDescriptor(contact)
|
|
595
602
|
this.bucket!.remove(peerId.value)
|
|
596
603
|
this.neighborList!.removeContact(peerId)
|
|
597
604
|
this.randomPeers!.removeContact(peerId)
|
|
598
|
-
if (removeFromOpenInternetPeers) {
|
|
599
|
-
this.openInternetPeers!.removeContact(peerId)
|
|
600
|
-
}
|
|
601
605
|
}
|
|
602
606
|
|
|
603
607
|
public async send(msg: Message): Promise<void> {
|
|
604
608
|
if (!this.started || this.stopped) {
|
|
605
609
|
return
|
|
606
610
|
}
|
|
607
|
-
const reachableThrough = this.peerDiscovery!.isJoinOngoing() ? this.config.entryPoints
|
|
611
|
+
const reachableThrough = this.peerDiscovery!.isJoinOngoing() ? this.config.entryPoints ?? [] : []
|
|
608
612
|
await this.router!.send(msg, reachableThrough)
|
|
609
613
|
}
|
|
610
614
|
|
|
@@ -617,8 +621,8 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
617
621
|
))
|
|
618
622
|
}
|
|
619
623
|
|
|
620
|
-
public async
|
|
621
|
-
return this.
|
|
624
|
+
public async startFind(idToFind: Uint8Array, fetchData?: boolean, excludedPeer?: PeerDescriptor): Promise<FindResult> {
|
|
625
|
+
return this.finder!.startFind(idToFind, fetchData, excludedPeer)
|
|
622
626
|
}
|
|
623
627
|
|
|
624
628
|
public async storeDataToDht(key: Uint8Array, data: Any): Promise<PeerDescriptor[]> {
|
|
@@ -630,7 +634,7 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
630
634
|
|
|
631
635
|
public async storeDataViaPeer(key: Uint8Array, data: Any, peer: PeerDescriptor): Promise<PeerDescriptor[]> {
|
|
632
636
|
const rpcRemote = new ExternalApiRpcRemote(
|
|
633
|
-
this.
|
|
637
|
+
this.localPeerDescriptor!,
|
|
634
638
|
peer,
|
|
635
639
|
this.config.serviceId,
|
|
636
640
|
toProtoRpcClient(new ExternalApiRpcClient(this.rpcCommunicator!.getRpcClientTransport()))
|
|
@@ -642,7 +646,7 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
642
646
|
if (this.peerDiscovery!.isJoinOngoing() && this.config.entryPoints && this.config.entryPoints.length > 0) {
|
|
643
647
|
return this.findDataViaPeer(idToFind, sample(this.config.entryPoints)!)
|
|
644
648
|
}
|
|
645
|
-
const result = await this.
|
|
649
|
+
const result = await this.finder!.startFind(idToFind, true)
|
|
646
650
|
return result.dataEntries ?? []
|
|
647
651
|
}
|
|
648
652
|
|
|
@@ -654,24 +658,20 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
654
658
|
|
|
655
659
|
public async findDataViaPeer(idToFind: Uint8Array, peer: PeerDescriptor): Promise<DataEntry[]> {
|
|
656
660
|
const rpcRemote = new ExternalApiRpcRemote(
|
|
657
|
-
this.
|
|
661
|
+
this.localPeerDescriptor!,
|
|
658
662
|
peer,
|
|
659
663
|
this.config.serviceId,
|
|
660
664
|
toProtoRpcClient(new ExternalApiRpcClient(this.rpcCommunicator!.getRpcClientTransport()))
|
|
661
665
|
)
|
|
662
|
-
return await rpcRemote.
|
|
663
|
-
}
|
|
664
|
-
|
|
665
|
-
public getRpcCommunicator(): RoutingRpcCommunicator {
|
|
666
|
-
return this.rpcCommunicator!
|
|
666
|
+
return await rpcRemote.externalFindData(idToFind)
|
|
667
667
|
}
|
|
668
668
|
|
|
669
669
|
public getTransport(): ITransport {
|
|
670
670
|
return this.transport!
|
|
671
671
|
}
|
|
672
672
|
|
|
673
|
-
public
|
|
674
|
-
return this.
|
|
673
|
+
public getLocalPeerDescriptor(): PeerDescriptor {
|
|
674
|
+
return this.localPeerDescriptor!
|
|
675
675
|
}
|
|
676
676
|
|
|
677
677
|
public getAllConnectionPeerDescriptors(): PeerDescriptor[] {
|
|
@@ -679,7 +679,7 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
679
679
|
}
|
|
680
680
|
|
|
681
681
|
public getKBucketPeers(): PeerDescriptor[] {
|
|
682
|
-
return this.bucket!.toArray().map((
|
|
682
|
+
return this.bucket!.toArray().map((rpcRemote: DhtNodeRpcRemote) => rpcRemote.getPeerDescriptor())
|
|
683
683
|
}
|
|
684
684
|
|
|
685
685
|
public getNumberOfConnections(): number {
|
|
@@ -716,53 +716,26 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
716
716
|
if (this.entryPointDisconnectTimeout) {
|
|
717
717
|
clearTimeout(this.entryPointDisconnectTimeout)
|
|
718
718
|
}
|
|
719
|
-
this.bucket!.toArray().forEach((
|
|
719
|
+
this.bucket!.toArray().forEach((rpcRemote: DhtNodeRpcRemote) => {
|
|
720
|
+
rpcRemote.leaveNotice()
|
|
721
|
+
this.bucket!.remove(rpcRemote.id)
|
|
722
|
+
})
|
|
720
723
|
this.bucket!.removeAllListeners()
|
|
721
724
|
this.localDataStore.clear()
|
|
722
725
|
this.neighborList!.stop()
|
|
723
726
|
this.randomPeers!.stop()
|
|
724
|
-
this.openInternetPeers!.stop()
|
|
725
727
|
this.rpcCommunicator!.stop()
|
|
726
728
|
this.router!.stop()
|
|
727
|
-
this.
|
|
729
|
+
this.finder!.stop()
|
|
728
730
|
this.peerDiscovery!.stop()
|
|
729
|
-
if (this.
|
|
730
|
-
|
|
731
|
+
if (this.config.transport === undefined) {
|
|
732
|
+
// if the transport was not given in config, the instance was created in start() and
|
|
733
|
+
// this component is responsible for stopping it
|
|
734
|
+
await this.transport!.stop()
|
|
731
735
|
}
|
|
732
736
|
this.transport = undefined
|
|
733
737
|
this.connectionManager = undefined
|
|
734
738
|
this.connections.clear()
|
|
735
739
|
this.removeAllListeners()
|
|
736
740
|
}
|
|
737
|
-
|
|
738
|
-
// IDHTRpcService implementation
|
|
739
|
-
private async getClosestPeers(request: ClosestPeersRequest, context: ServerCallContext): Promise<ClosestPeersResponse> {
|
|
740
|
-
this.addNewContact((context as DhtCallContext).incomingSourceDescriptor!)
|
|
741
|
-
const response = {
|
|
742
|
-
peers: this.getClosestPeerDescriptors(request.kademliaId, this.config.peerDiscoveryQueryBatchSize),
|
|
743
|
-
requestId: request.requestId
|
|
744
|
-
}
|
|
745
|
-
return response
|
|
746
|
-
}
|
|
747
|
-
|
|
748
|
-
// IDHTRpcService implementation
|
|
749
|
-
private async ping(request: PingRequest, context: ServerCallContext): Promise<PingResponse> {
|
|
750
|
-
logger.trace('received ping request: ' + keyFromPeerDescriptor((context as DhtCallContext).incomingSourceDescriptor!))
|
|
751
|
-
setImmediate(() => {
|
|
752
|
-
this.addNewContact((context as DhtCallContext).incomingSourceDescriptor!)
|
|
753
|
-
})
|
|
754
|
-
const response: PingResponse = {
|
|
755
|
-
requestId: request.requestId
|
|
756
|
-
}
|
|
757
|
-
return response
|
|
758
|
-
}
|
|
759
|
-
|
|
760
|
-
// IDHTRpcService implementation
|
|
761
|
-
private async leaveNotice(request: LeaveNotice, context: ServerCallContext): Promise<Empty> {
|
|
762
|
-
// TODO check signature??
|
|
763
|
-
if (request.serviceId === this.config.serviceId) {
|
|
764
|
-
this.removeContact((context as DhtCallContext).incomingSourceDescriptor!)
|
|
765
|
-
}
|
|
766
|
-
return {}
|
|
767
|
-
}
|
|
768
741
|
}
|