@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/dist/src/dht/DhtNode.js
CHANGED
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.DhtNode = exports.createPeerDescriptor = void 0;
|
|
7
|
-
const
|
|
7
|
+
const DhtNodeRpcRemote_1 = require("./DhtNodeRpcRemote");
|
|
8
8
|
const k_bucket_1 = __importDefault(require("k-bucket"));
|
|
9
9
|
const eventemitter3_1 = require("eventemitter3");
|
|
10
10
|
const SortedContactList_1 = require("./contact/SortedContactList");
|
|
@@ -18,16 +18,17 @@ const proto_rpc_1 = require("@streamr/proto-rpc");
|
|
|
18
18
|
const RandomContactList_1 = require("./contact/RandomContactList");
|
|
19
19
|
const peerIdFromPeerDescriptor_1 = require("../helpers/peerIdFromPeerDescriptor");
|
|
20
20
|
const Router_1 = require("./routing/Router");
|
|
21
|
-
const
|
|
21
|
+
const Finder_1 = require("./find/Finder");
|
|
22
22
|
const StoreRpcLocal_1 = require("./store/StoreRpcLocal");
|
|
23
23
|
const PeerDiscovery_1 = require("./discovery/PeerDiscovery");
|
|
24
24
|
const LocalDataStore_1 = require("./store/LocalDataStore");
|
|
25
|
-
const registerExternalApiRpcMethods_1 = require("./registerExternalApiRpcMethods");
|
|
26
25
|
const ExternalApiRpcRemote_1 = require("./ExternalApiRpcRemote");
|
|
27
26
|
const UUID_1 = require("../helpers/UUID");
|
|
28
27
|
const isBrowserEnvironment_1 = require("../helpers/browser/isBrowserEnvironment");
|
|
29
28
|
const lodash_1 = require("lodash");
|
|
30
29
|
const ConnectorFacade_1 = require("../connection/ConnectorFacade");
|
|
30
|
+
const DhtNodeRpcLocal_1 = require("./DhtNodeRpcLocal");
|
|
31
|
+
const ExternalApiRpcLocal_1 = require("./ExternalApiRpcLocal");
|
|
31
32
|
const logger = new utils_1.Logger(module);
|
|
32
33
|
const createPeerDescriptor = (msg, peerId) => {
|
|
33
34
|
let kademliaId;
|
|
@@ -41,7 +42,6 @@ const createPeerDescriptor = (msg, peerId) => {
|
|
|
41
42
|
const ret = { kademliaId, type: nodeType };
|
|
42
43
|
if (msg && msg.websocket) {
|
|
43
44
|
ret.websocket = { host: msg.websocket.host, port: msg.websocket.port, tls: msg.websocket.tls };
|
|
44
|
-
ret.openInternet = true;
|
|
45
45
|
}
|
|
46
46
|
return ret;
|
|
47
47
|
};
|
|
@@ -53,54 +53,6 @@ class DhtNode extends eventemitter3_1.EventEmitter {
|
|
|
53
53
|
this.localDataStore = new LocalDataStore_1.LocalDataStore();
|
|
54
54
|
this.started = false;
|
|
55
55
|
this.stopped = false;
|
|
56
|
-
this.initKBuckets = (selfId) => {
|
|
57
|
-
this.bucket = new k_bucket_1.default({
|
|
58
|
-
localNodeId: selfId.value,
|
|
59
|
-
numberOfNodesPerKBucket: this.config.numberOfNodesPerKBucket,
|
|
60
|
-
numberOfNodesToPing: this.config.numberOfNodesPerKBucket
|
|
61
|
-
});
|
|
62
|
-
this.bucket.on('ping', (oldContacts, newContact) => this.onKBucketPing(oldContacts, newContact));
|
|
63
|
-
this.bucket.on('removed', (contact) => this.onKBucketRemoved(contact));
|
|
64
|
-
this.bucket.on('added', (contact) => this.onKBucketAdded(contact));
|
|
65
|
-
this.bucket.on('updated', () => {
|
|
66
|
-
// TODO: Update contact info to the connection manager and reconnect
|
|
67
|
-
});
|
|
68
|
-
this.neighborList = new SortedContactList_1.SortedContactList(selfId, this.config.maxNeighborListSize);
|
|
69
|
-
this.neighborList.on('contactRemoved', (removedContact, activeContacts) => {
|
|
70
|
-
if (this.stopped) {
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
this.emit('contactRemoved', removedContact.getPeerDescriptor(), activeContacts.map((c) => c.getPeerDescriptor()));
|
|
74
|
-
this.randomPeers.addContact(new RemoteDhtNode_1.RemoteDhtNode(this.ownPeerDescriptor, removedContact.getPeerDescriptor(), (0, proto_rpc_1.toProtoRpcClient)(new DhtRpc_client_1.DhtRpcServiceClient(this.rpcCommunicator.getRpcClientTransport())), this.config.serviceId));
|
|
75
|
-
});
|
|
76
|
-
this.neighborList.on('newContact', (newContact, activeContacts) => this.emit('newContact', newContact.getPeerDescriptor(), activeContacts.map((c) => c.getPeerDescriptor())));
|
|
77
|
-
this.openInternetPeers = new SortedContactList_1.SortedContactList(selfId, this.config.maxNeighborListSize / 2);
|
|
78
|
-
this.openInternetPeers.on('contactRemoved', (removedContact, activeContacts) => this.emit('openInternetContactRemoved', removedContact.getPeerDescriptor(), activeContacts.map((c) => c.getPeerDescriptor())));
|
|
79
|
-
this.openInternetPeers.on('newContact', (newContact, activeContacts) => this.emit('newOpenInternetContact', newContact.getPeerDescriptor(), activeContacts.map((c) => c.getPeerDescriptor())));
|
|
80
|
-
this.transport.on('connected', (peerDescriptor) => this.onTransportConnected(peerDescriptor));
|
|
81
|
-
this.transport.on('disconnected', (peerDescriptor, disonnectionType) => {
|
|
82
|
-
this.onTransportDisconnected(peerDescriptor, disonnectionType);
|
|
83
|
-
});
|
|
84
|
-
this.transport.getAllConnectionPeerDescriptors().forEach((peer) => {
|
|
85
|
-
const remoteDhtNode = new RemoteDhtNode_1.RemoteDhtNode(this.ownPeerDescriptor, peer, (0, proto_rpc_1.toProtoRpcClient)(new DhtRpc_client_1.DhtRpcServiceClient(this.rpcCommunicator.getRpcClientTransport())), this.config.serviceId);
|
|
86
|
-
if ((0, peerIdFromPeerDescriptor_1.areEqualPeerDescriptors)(peer, this.ownPeerDescriptor)) {
|
|
87
|
-
logger.error('own peerdescriptor added to connections in initKBucket');
|
|
88
|
-
}
|
|
89
|
-
this.connections.set((0, peerIdFromPeerDescriptor_1.keyFromPeerDescriptor)(peer), remoteDhtNode);
|
|
90
|
-
});
|
|
91
|
-
this.randomPeers = new RandomContactList_1.RandomContactList(selfId, this.config.maxNeighborListSize);
|
|
92
|
-
this.randomPeers.on('contactRemoved', (removedContact, activeContacts) => this.emit('randomContactRemoved', removedContact.getPeerDescriptor(), activeContacts.map((c) => c.getPeerDescriptor())));
|
|
93
|
-
this.randomPeers.on('newContact', (newContact, activeContacts) => this.emit('newRandomContact', newContact.getPeerDescriptor(), activeContacts.map((c) => c.getPeerDescriptor())));
|
|
94
|
-
};
|
|
95
|
-
this.generatePeerDescriptorCallBack = (connectivityResponse) => {
|
|
96
|
-
if (this.config.peerDescriptor) {
|
|
97
|
-
this.ownPeerDescriptor = this.config.peerDescriptor;
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
this.ownPeerDescriptor = (0, exports.createPeerDescriptor)(connectivityResponse, this.config.peerId);
|
|
101
|
-
}
|
|
102
|
-
return this.ownPeerDescriptor;
|
|
103
|
-
};
|
|
104
56
|
this.config = (0, utils_1.merge)({
|
|
105
57
|
serviceId: 'layer0',
|
|
106
58
|
joinParallelism: 3,
|
|
@@ -134,7 +86,7 @@ class DhtNode extends eventemitter3_1.EventEmitter {
|
|
|
134
86
|
// If transport is given, do not create a ConnectionManager
|
|
135
87
|
if (this.config.transport) {
|
|
136
88
|
this.transport = this.config.transport;
|
|
137
|
-
this.
|
|
89
|
+
this.localPeerDescriptor = this.transport.getLocalPeerDescriptor();
|
|
138
90
|
if (this.config.transport instanceof ConnectionManager_1.ConnectionManager) {
|
|
139
91
|
this.connectionManager = this.config.transport;
|
|
140
92
|
}
|
|
@@ -150,9 +102,12 @@ class DhtNode extends eventemitter3_1.EventEmitter {
|
|
|
150
102
|
webrtcNewConnectionTimeout: this.config.webrtcNewConnectionTimeout,
|
|
151
103
|
webrtcPortRange: this.config.webrtcPortRange,
|
|
152
104
|
maxMessageSize: this.config.maxMessageSize,
|
|
105
|
+
websocketServerEnableTls: this.config.websocketServerEnableTls,
|
|
153
106
|
tlsCertificate: this.config.tlsCertificate,
|
|
154
107
|
externalIp: this.config.externalIp,
|
|
155
|
-
|
|
108
|
+
autoCertifierUrl: this.config.autoCertifierUrl,
|
|
109
|
+
autoCertifierConfigFile: this.config.autoCertifierConfigFile,
|
|
110
|
+
createLocalPeerDescriptor: (connectivityResponse) => this.generatePeerDescriptorCallBack(connectivityResponse),
|
|
156
111
|
};
|
|
157
112
|
// If own PeerDescriptor is given in config, create a ConnectionManager with ws server
|
|
158
113
|
if (this.config.peerDescriptor?.websocket) {
|
|
@@ -178,38 +133,35 @@ class DhtNode extends eventemitter3_1.EventEmitter {
|
|
|
178
133
|
}
|
|
179
134
|
this.rpcCommunicator = new RoutingRpcCommunicator_1.RoutingRpcCommunicator(this.config.serviceId, this.transport.send, { rpcRequestTimeout: this.config.rpcRequestTimeout });
|
|
180
135
|
this.transport.on('message', (message) => this.handleMessage(message));
|
|
181
|
-
this.
|
|
182
|
-
this.initKBuckets((0, peerIdFromPeerDescriptor_1.peerIdFromPeerDescriptor)(this.ownPeerDescriptor));
|
|
136
|
+
this.initKBuckets((0, peerIdFromPeerDescriptor_1.peerIdFromPeerDescriptor)(this.localPeerDescriptor));
|
|
183
137
|
this.peerDiscovery = new PeerDiscovery_1.PeerDiscovery({
|
|
184
138
|
rpcCommunicator: this.rpcCommunicator,
|
|
185
|
-
|
|
139
|
+
localPeerDescriptor: this.localPeerDescriptor,
|
|
186
140
|
bucket: this.bucket,
|
|
187
|
-
connections: this.connections,
|
|
188
141
|
neighborList: this.neighborList,
|
|
189
|
-
randomPeers: this.randomPeers,
|
|
190
|
-
openInternetPeers: this.openInternetPeers,
|
|
191
142
|
joinNoProgressLimit: this.config.joinNoProgressLimit,
|
|
192
143
|
peerDiscoveryQueryBatchSize: this.config.peerDiscoveryQueryBatchSize,
|
|
193
144
|
joinTimeout: this.config.dhtJoinTimeout,
|
|
194
145
|
serviceId: this.config.serviceId,
|
|
195
146
|
parallelism: this.config.joinParallelism,
|
|
196
147
|
addContact: this.addNewContact.bind(this),
|
|
197
|
-
connectionManager: this.connectionManager
|
|
148
|
+
connectionManager: this.connectionManager,
|
|
149
|
+
rpcRequestTimeout: this.config.rpcRequestTimeout
|
|
198
150
|
});
|
|
199
151
|
this.router = new Router_1.Router({
|
|
200
152
|
rpcCommunicator: this.rpcCommunicator,
|
|
201
153
|
connections: this.connections,
|
|
202
|
-
|
|
154
|
+
localPeerDescriptor: this.localPeerDescriptor,
|
|
203
155
|
addContact: this.addNewContact.bind(this),
|
|
204
156
|
serviceId: this.config.serviceId,
|
|
205
157
|
connectionManager: this.connectionManager
|
|
206
158
|
});
|
|
207
|
-
this.
|
|
159
|
+
this.finder = new Finder_1.Finder({
|
|
208
160
|
rpcCommunicator: this.rpcCommunicator,
|
|
209
161
|
router: this.router,
|
|
210
162
|
sessionTransport: this,
|
|
211
163
|
connections: this.connections,
|
|
212
|
-
|
|
164
|
+
localPeerDescriptor: this.localPeerDescriptor,
|
|
213
165
|
serviceId: this.config.serviceId,
|
|
214
166
|
addContact: this.addNewContact.bind(this),
|
|
215
167
|
isPeerCloserToIdThanSelf: this.isPeerCloserToIdThanSelf.bind(this),
|
|
@@ -217,8 +169,8 @@ class DhtNode extends eventemitter3_1.EventEmitter {
|
|
|
217
169
|
});
|
|
218
170
|
this.storeRpcLocal = new StoreRpcLocal_1.StoreRpcLocal({
|
|
219
171
|
rpcCommunicator: this.rpcCommunicator,
|
|
220
|
-
|
|
221
|
-
|
|
172
|
+
finder: this.finder,
|
|
173
|
+
localPeerDescriptor: this.localPeerDescriptor,
|
|
222
174
|
serviceId: this.config.serviceId,
|
|
223
175
|
highestTtl: this.config.storeHighestTtl,
|
|
224
176
|
maxTtl: this.config.storeMaxTtl,
|
|
@@ -227,73 +179,130 @@ class DhtNode extends eventemitter3_1.EventEmitter {
|
|
|
227
179
|
dhtNodeEmitter: this,
|
|
228
180
|
getNodesClosestToIdFromBucket: (id, n) => {
|
|
229
181
|
return this.bucket.closest(id, n);
|
|
230
|
-
}
|
|
182
|
+
},
|
|
183
|
+
rpcRequestTimeout: this.config.rpcRequestTimeout
|
|
231
184
|
});
|
|
232
|
-
|
|
185
|
+
this.bindRpcLocalMethods();
|
|
233
186
|
if (this.connectionManager && this.config.entryPoints && this.config.entryPoints.length > 0
|
|
234
|
-
&& !(0, peerIdFromPeerDescriptor_1.areEqualPeerDescriptors)(this.config.entryPoints[0], this.
|
|
187
|
+
&& !(0, peerIdFromPeerDescriptor_1.areEqualPeerDescriptors)(this.config.entryPoints[0], this.localPeerDescriptor)) {
|
|
235
188
|
this.connectToEntryPoint(this.config.entryPoints[0]);
|
|
236
189
|
}
|
|
237
190
|
}
|
|
191
|
+
initKBuckets(selfId) {
|
|
192
|
+
this.bucket = new k_bucket_1.default({
|
|
193
|
+
localNodeId: selfId.value,
|
|
194
|
+
numberOfNodesPerKBucket: this.config.numberOfNodesPerKBucket,
|
|
195
|
+
numberOfNodesToPing: this.config.numberOfNodesPerKBucket
|
|
196
|
+
});
|
|
197
|
+
this.bucket.on('ping', (oldContacts, newContact) => this.onKBucketPing(oldContacts, newContact));
|
|
198
|
+
this.bucket.on('removed', (contact) => this.onKBucketRemoved(contact));
|
|
199
|
+
this.bucket.on('added', (contact) => this.onKBucketAdded(contact));
|
|
200
|
+
this.bucket.on('updated', () => {
|
|
201
|
+
// TODO: Update contact info to the connection manager and reconnect
|
|
202
|
+
});
|
|
203
|
+
this.neighborList = new SortedContactList_1.SortedContactList(selfId, this.config.maxNeighborListSize);
|
|
204
|
+
this.neighborList.on('contactRemoved', (removedContact, activeContacts) => {
|
|
205
|
+
if (this.stopped) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
this.emit('contactRemoved', removedContact.getPeerDescriptor(), activeContacts.map((c) => c.getPeerDescriptor()));
|
|
209
|
+
this.randomPeers.addContact(new DhtNodeRpcRemote_1.DhtNodeRpcRemote(this.localPeerDescriptor, removedContact.getPeerDescriptor(), (0, proto_rpc_1.toProtoRpcClient)(new DhtRpc_client_1.DhtNodeRpcClient(this.rpcCommunicator.getRpcClientTransport())), this.config.serviceId, this.config.rpcRequestTimeout));
|
|
210
|
+
});
|
|
211
|
+
this.neighborList.on('newContact', (newContact, activeContacts) => this.emit('newContact', newContact.getPeerDescriptor(), activeContacts.map((c) => c.getPeerDescriptor())));
|
|
212
|
+
this.transport.on('connected', (peerDescriptor) => this.onTransportConnected(peerDescriptor));
|
|
213
|
+
this.transport.on('disconnected', (peerDescriptor, gracefulLeave) => {
|
|
214
|
+
this.onTransportDisconnected(peerDescriptor, gracefulLeave);
|
|
215
|
+
});
|
|
216
|
+
this.transport.getAllConnectionPeerDescriptors().forEach((peer) => {
|
|
217
|
+
const rpcRemote = new DhtNodeRpcRemote_1.DhtNodeRpcRemote(this.localPeerDescriptor, peer, (0, proto_rpc_1.toProtoRpcClient)(new DhtRpc_client_1.DhtNodeRpcClient(this.rpcCommunicator.getRpcClientTransport())), this.config.serviceId, this.config.rpcRequestTimeout);
|
|
218
|
+
if ((0, peerIdFromPeerDescriptor_1.areEqualPeerDescriptors)(peer, this.localPeerDescriptor)) {
|
|
219
|
+
logger.error('own peerdescriptor added to connections in initKBucket');
|
|
220
|
+
}
|
|
221
|
+
this.connections.set((0, peerIdFromPeerDescriptor_1.keyFromPeerDescriptor)(peer), rpcRemote);
|
|
222
|
+
});
|
|
223
|
+
this.randomPeers = new RandomContactList_1.RandomContactList(selfId, this.config.maxNeighborListSize);
|
|
224
|
+
this.randomPeers.on('contactRemoved', (removedContact, activeContacts) => this.emit('randomContactRemoved', removedContact.getPeerDescriptor(), activeContacts.map((c) => c.getPeerDescriptor())));
|
|
225
|
+
this.randomPeers.on('newContact', (newContact, activeContacts) => this.emit('newRandomContact', newContact.getPeerDescriptor(), activeContacts.map((c) => c.getPeerDescriptor())));
|
|
226
|
+
}
|
|
238
227
|
onTransportConnected(peerDescriptor) {
|
|
239
|
-
if ((0, peerIdFromPeerDescriptor_1.areEqualPeerDescriptors)(this.
|
|
228
|
+
if ((0, peerIdFromPeerDescriptor_1.areEqualPeerDescriptors)(this.localPeerDescriptor, peerDescriptor)) {
|
|
240
229
|
logger.error('onTransportConnected() to self');
|
|
241
230
|
}
|
|
242
|
-
const
|
|
243
|
-
if (!this.connections.has(PeerID_1.PeerID.fromValue(
|
|
244
|
-
this.connections.set(PeerID_1.PeerID.fromValue(
|
|
231
|
+
const rpcRemote = new DhtNodeRpcRemote_1.DhtNodeRpcRemote(this.localPeerDescriptor, peerDescriptor, (0, proto_rpc_1.toProtoRpcClient)(new DhtRpc_client_1.DhtNodeRpcClient(this.rpcCommunicator.getRpcClientTransport())), this.config.serviceId, this.config.rpcRequestTimeout);
|
|
232
|
+
if (!this.connections.has(PeerID_1.PeerID.fromValue(rpcRemote.id).toKey())) {
|
|
233
|
+
this.connections.set(PeerID_1.PeerID.fromValue(rpcRemote.id).toKey(), rpcRemote);
|
|
245
234
|
logger.trace('connectionschange add ' + this.connections.size);
|
|
246
235
|
}
|
|
247
236
|
else {
|
|
248
237
|
logger.trace('new connection not set to connections, there is already a connection with the peer ID');
|
|
249
238
|
}
|
|
250
|
-
logger.trace('connected: ' + (0, peerIdFromPeerDescriptor_1.
|
|
239
|
+
logger.trace('connected: ' + (0, peerIdFromPeerDescriptor_1.getNodeIdFromPeerDescriptor)(peerDescriptor) + ' ' + this.connections.size);
|
|
251
240
|
this.emit('connected', peerDescriptor);
|
|
252
241
|
}
|
|
253
|
-
onTransportDisconnected(peerDescriptor,
|
|
254
|
-
logger.trace('disconnected: ' + (0, peerIdFromPeerDescriptor_1.
|
|
242
|
+
onTransportDisconnected(peerDescriptor, gracefulLeave) {
|
|
243
|
+
logger.trace('disconnected: ' + (0, peerIdFromPeerDescriptor_1.getNodeIdFromPeerDescriptor)(peerDescriptor));
|
|
255
244
|
this.connections.delete((0, peerIdFromPeerDescriptor_1.keyFromPeerDescriptor)(peerDescriptor));
|
|
256
245
|
// only remove from bucket if we are on layer 0
|
|
257
246
|
if (this.connectionManager) {
|
|
258
247
|
this.bucket.remove(peerDescriptor.kademliaId);
|
|
259
|
-
if (
|
|
260
|
-
logger.trace((0, peerIdFromPeerDescriptor_1.
|
|
261
|
-
this.removeContact(peerDescriptor
|
|
248
|
+
if (gracefulLeave === true) {
|
|
249
|
+
logger.trace((0, peerIdFromPeerDescriptor_1.getNodeIdFromPeerDescriptor)(peerDescriptor) + ' ' + 'onTransportDisconnected with gracefulLeave ' + gracefulLeave);
|
|
250
|
+
this.removeContact(peerDescriptor);
|
|
262
251
|
}
|
|
263
252
|
else {
|
|
264
|
-
logger.trace((0, peerIdFromPeerDescriptor_1.
|
|
253
|
+
logger.trace((0, peerIdFromPeerDescriptor_1.getNodeIdFromPeerDescriptor)(peerDescriptor) + ' ' + 'onTransportDisconnected with gracefulLeave ' + gracefulLeave);
|
|
265
254
|
}
|
|
266
255
|
}
|
|
267
|
-
this.emit('disconnected', peerDescriptor,
|
|
256
|
+
this.emit('disconnected', peerDescriptor, gracefulLeave);
|
|
268
257
|
}
|
|
269
|
-
|
|
258
|
+
bindRpcLocalMethods() {
|
|
270
259
|
if (!this.started || this.stopped) {
|
|
271
260
|
return;
|
|
272
261
|
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
262
|
+
const dhtNodeRpcLocal = new DhtNodeRpcLocal_1.DhtNodeRpcLocal({
|
|
263
|
+
bucket: this.bucket,
|
|
264
|
+
serviceId: this.config.serviceId,
|
|
265
|
+
peerDiscoveryQueryBatchSize: this.config.peerDiscoveryQueryBatchSize,
|
|
266
|
+
addNewContact: (contact) => this.addNewContact(contact),
|
|
267
|
+
removeContact: (contact) => this.removeContact(contact)
|
|
268
|
+
});
|
|
269
|
+
this.rpcCommunicator.registerRpcMethod(DhtRpc_1.ClosestPeersRequest, DhtRpc_1.ClosestPeersResponse, 'getClosestPeers', (req, context) => dhtNodeRpcLocal.getClosestPeers(req, context));
|
|
270
|
+
this.rpcCommunicator.registerRpcMethod(DhtRpc_1.PingRequest, DhtRpc_1.PingResponse, 'ping', (req, context) => dhtNodeRpcLocal.ping(req, context));
|
|
271
|
+
this.rpcCommunicator.registerRpcNotification(DhtRpc_1.LeaveNotice, 'leaveNotice', (req, context) => dhtNodeRpcLocal.leaveNotice(req, context));
|
|
272
|
+
const externalApiRpcLocal = new ExternalApiRpcLocal_1.ExternalApiRpcLocal({
|
|
273
|
+
startFind: (idToFind, fetchData, excludedPeer) => {
|
|
274
|
+
return this.startFind(idToFind, fetchData, excludedPeer);
|
|
275
|
+
},
|
|
276
|
+
storeDataToDht: (key, data) => this.storeDataToDht(key, data)
|
|
277
|
+
});
|
|
278
|
+
this.rpcCommunicator.registerRpcMethod(DhtRpc_1.ExternalFindDataRequest, DhtRpc_1.ExternalFindDataResponse, 'externalFindData', (req, context) => externalApiRpcLocal.externalFindData(req, context), { timeout: 10000 });
|
|
279
|
+
this.rpcCommunicator.registerRpcMethod(DhtRpc_1.ExternalStoreDataRequest, DhtRpc_1.ExternalStoreDataResponse, 'externalStoreData', (req) => externalApiRpcLocal.externalStoreData(req), { timeout: 10000 });
|
|
277
280
|
}
|
|
278
281
|
isPeerCloserToIdThanSelf(peer1, compareToId) {
|
|
279
282
|
const distance1 = this.bucket.distance(peer1.kademliaId, compareToId.value);
|
|
280
|
-
const distance2 = this.bucket.distance(this.
|
|
283
|
+
const distance2 = this.bucket.distance(this.localPeerDescriptor.kademliaId, compareToId.value);
|
|
281
284
|
return distance1 < distance2;
|
|
282
285
|
}
|
|
283
286
|
handleMessage(message) {
|
|
284
287
|
if (message.serviceId === this.config.serviceId) {
|
|
285
|
-
logger.trace('callig this.handleMessageFromPeer ' + (0, peerIdFromPeerDescriptor_1.
|
|
288
|
+
logger.trace('callig this.handleMessageFromPeer ' + (0, peerIdFromPeerDescriptor_1.getNodeIdFromPeerDescriptor)(message.sourceDescriptor)
|
|
286
289
|
+ ' ' + message.serviceId + ' ' + message.messageId);
|
|
287
290
|
this.rpcCommunicator?.handleMessageFromPeer(message);
|
|
288
291
|
}
|
|
289
292
|
else {
|
|
290
|
-
logger.trace('emit "message" ' + (0, peerIdFromPeerDescriptor_1.
|
|
293
|
+
logger.trace('emit "message" ' + (0, peerIdFromPeerDescriptor_1.getNodeIdFromPeerDescriptor)(message.sourceDescriptor)
|
|
294
|
+
+ ' ' + message.serviceId + ' ' + message.messageId);
|
|
291
295
|
this.emit('message', message);
|
|
292
296
|
}
|
|
293
297
|
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
298
|
+
generatePeerDescriptorCallBack(connectivityResponse) {
|
|
299
|
+
if (this.config.peerDescriptor) {
|
|
300
|
+
this.localPeerDescriptor = this.config.peerDescriptor;
|
|
301
|
+
}
|
|
302
|
+
else {
|
|
303
|
+
this.localPeerDescriptor = (0, exports.createPeerDescriptor)(connectivityResponse, this.config.peerId);
|
|
304
|
+
}
|
|
305
|
+
return this.localPeerDescriptor;
|
|
297
306
|
}
|
|
298
307
|
onKBucketPing(oldContacts, newContact) {
|
|
299
308
|
if (this.stopped) {
|
|
@@ -311,8 +320,7 @@ class DhtNode extends eventemitter3_1.EventEmitter {
|
|
|
311
320
|
return;
|
|
312
321
|
}
|
|
313
322
|
this.connectionManager?.weakUnlockConnection(contact.getPeerDescriptor());
|
|
314
|
-
logger.trace(`Removed contact ${(0, peerIdFromPeerDescriptor_1.
|
|
315
|
-
this.emit('kbucketContactRemoved', contact.getPeerDescriptor());
|
|
323
|
+
logger.trace(`Removed contact ${(0, peerIdFromPeerDescriptor_1.getNodeIdFromPeerDescriptor)(contact.getPeerDescriptor())}`);
|
|
316
324
|
if (this.bucket.count() === 0
|
|
317
325
|
&& !this.peerDiscovery.isJoinOngoing()
|
|
318
326
|
&& this.config.entryPoints
|
|
@@ -326,22 +334,20 @@ class DhtNode extends eventemitter3_1.EventEmitter {
|
|
|
326
334
|
if (this.stopped) {
|
|
327
335
|
return;
|
|
328
336
|
}
|
|
329
|
-
if (!
|
|
337
|
+
if (!contact.getPeerId().equals(this.getNodeId())) {
|
|
330
338
|
// Important to lock here, before the ping result is known
|
|
331
339
|
this.connectionManager?.weakLockConnection(contact.getPeerDescriptor());
|
|
332
340
|
if (this.connections.has(contact.getPeerId().toKey())) {
|
|
333
|
-
logger.trace(`Added new contact ${(0, peerIdFromPeerDescriptor_1.
|
|
334
|
-
this.emit('newKbucketContact', contact.getPeerDescriptor(), this.neighborList.getClosestContacts(this.config.peerDiscoveryQueryBatchSize).map((peer) => peer.getPeerDescriptor()));
|
|
341
|
+
logger.trace(`Added new contact ${(0, peerIdFromPeerDescriptor_1.getNodeIdFromPeerDescriptor)(contact.getPeerDescriptor())}`);
|
|
335
342
|
}
|
|
336
343
|
else { // open connection by pinging
|
|
337
|
-
logger.trace('starting ping ' + (0, peerIdFromPeerDescriptor_1.
|
|
344
|
+
logger.trace('starting ping ' + (0, peerIdFromPeerDescriptor_1.getNodeIdFromPeerDescriptor)(contact.getPeerDescriptor()));
|
|
338
345
|
contact.ping().then((result) => {
|
|
339
346
|
if (result) {
|
|
340
|
-
logger.trace(`Added new contact ${(0, peerIdFromPeerDescriptor_1.
|
|
341
|
-
this.emit('newKbucketContact', contact.getPeerDescriptor(), this.neighborList.getClosestContacts(this.config.peerDiscoveryQueryBatchSize).map((peer) => peer.getPeerDescriptor()));
|
|
347
|
+
logger.trace(`Added new contact ${(0, peerIdFromPeerDescriptor_1.getNodeIdFromPeerDescriptor)(contact.getPeerDescriptor())}`);
|
|
342
348
|
}
|
|
343
349
|
else {
|
|
344
|
-
logger.trace('ping failed ' + (0, peerIdFromPeerDescriptor_1.
|
|
350
|
+
logger.trace('ping failed ' + (0, peerIdFromPeerDescriptor_1.getNodeIdFromPeerDescriptor)(contact.getPeerDescriptor()));
|
|
345
351
|
this.connectionManager?.weakUnlockConnection(contact.getPeerDescriptor());
|
|
346
352
|
this.removeContact(contact.getPeerDescriptor());
|
|
347
353
|
this.addClosestContactToBucket();
|
|
@@ -376,7 +382,7 @@ class DhtNode extends eventemitter3_1.EventEmitter {
|
|
|
376
382
|
return this.neighborList.getClosestContacts(maxCount).map((c) => c.getPeerDescriptor());
|
|
377
383
|
}
|
|
378
384
|
getNodeId() {
|
|
379
|
-
return (0, peerIdFromPeerDescriptor_1.peerIdFromPeerDescriptor)(this.
|
|
385
|
+
return (0, peerIdFromPeerDescriptor_1.peerIdFromPeerDescriptor)(this.localPeerDescriptor);
|
|
380
386
|
}
|
|
381
387
|
getBucketSize() {
|
|
382
388
|
return this.bucket.count();
|
|
@@ -385,23 +391,19 @@ class DhtNode extends eventemitter3_1.EventEmitter {
|
|
|
385
391
|
if (!this.started || this.stopped) {
|
|
386
392
|
return;
|
|
387
393
|
}
|
|
388
|
-
if (!(0, peerIdFromPeerDescriptor_1.areEqualPeerDescriptors)(contact, this.
|
|
389
|
-
logger.trace(`Adding new contact ${(0, peerIdFromPeerDescriptor_1.
|
|
390
|
-
const
|
|
394
|
+
if (!(0, peerIdFromPeerDescriptor_1.areEqualPeerDescriptors)(contact, this.localPeerDescriptor)) {
|
|
395
|
+
logger.trace(`Adding new contact ${(0, peerIdFromPeerDescriptor_1.getNodeIdFromPeerDescriptor)(contact)}`);
|
|
396
|
+
const rpcRemote = new DhtNodeRpcRemote_1.DhtNodeRpcRemote(this.localPeerDescriptor, contact, (0, proto_rpc_1.toProtoRpcClient)(new DhtRpc_client_1.DhtNodeRpcClient(this.rpcCommunicator.getRpcClientTransport())), this.config.serviceId, this.config.rpcRequestTimeout);
|
|
391
397
|
if (!this.bucket.get(contact.kademliaId) && !this.neighborList.getContact((0, peerIdFromPeerDescriptor_1.peerIdFromPeerDescriptor)(contact))) {
|
|
392
|
-
this.neighborList.addContact(
|
|
393
|
-
if (contact.openInternet) {
|
|
394
|
-
this.openInternetPeers.addContact(remoteDhtNode);
|
|
395
|
-
}
|
|
398
|
+
this.neighborList.addContact(rpcRemote);
|
|
396
399
|
if (setActive) {
|
|
397
400
|
const peerId = (0, peerIdFromPeerDescriptor_1.peerIdFromPeerDescriptor)(contact);
|
|
398
401
|
this.neighborList.setActive(peerId);
|
|
399
|
-
this.openInternetPeers.setActive(peerId);
|
|
400
402
|
}
|
|
401
|
-
this.bucket.add(
|
|
403
|
+
this.bucket.add(rpcRemote);
|
|
402
404
|
}
|
|
403
405
|
else {
|
|
404
|
-
this.randomPeers.addContact(
|
|
406
|
+
this.randomPeers.addContact(rpcRemote);
|
|
405
407
|
}
|
|
406
408
|
}
|
|
407
409
|
}
|
|
@@ -411,24 +413,21 @@ class DhtNode extends eventemitter3_1.EventEmitter {
|
|
|
411
413
|
this.connectionManager.unlockConnection(entryPoint, 'temporary-layer0-connection');
|
|
412
414
|
}, 10 * 1000);
|
|
413
415
|
}
|
|
414
|
-
removeContact(contact
|
|
416
|
+
removeContact(contact) {
|
|
415
417
|
if (!this.started || this.stopped) {
|
|
416
418
|
return;
|
|
417
419
|
}
|
|
418
|
-
logger.trace(`Removing contact ${(0, peerIdFromPeerDescriptor_1.
|
|
420
|
+
logger.trace(`Removing contact ${(0, peerIdFromPeerDescriptor_1.getNodeIdFromPeerDescriptor)(contact)}`);
|
|
419
421
|
const peerId = (0, peerIdFromPeerDescriptor_1.peerIdFromPeerDescriptor)(contact);
|
|
420
422
|
this.bucket.remove(peerId.value);
|
|
421
423
|
this.neighborList.removeContact(peerId);
|
|
422
424
|
this.randomPeers.removeContact(peerId);
|
|
423
|
-
if (removeFromOpenInternetPeers) {
|
|
424
|
-
this.openInternetPeers.removeContact(peerId);
|
|
425
|
-
}
|
|
426
425
|
}
|
|
427
426
|
async send(msg) {
|
|
428
427
|
if (!this.started || this.stopped) {
|
|
429
428
|
return;
|
|
430
429
|
}
|
|
431
|
-
const reachableThrough = this.peerDiscovery.isJoinOngoing() ? this.config.entryPoints
|
|
430
|
+
const reachableThrough = this.peerDiscovery.isJoinOngoing() ? this.config.entryPoints ?? [] : [];
|
|
432
431
|
await this.router.send(msg, reachableThrough);
|
|
433
432
|
}
|
|
434
433
|
async joinDht(entryPointDescriptors, doAdditionalRandomPeerDiscovery, retry) {
|
|
@@ -437,8 +436,8 @@ class DhtNode extends eventemitter3_1.EventEmitter {
|
|
|
437
436
|
}
|
|
438
437
|
await Promise.all(entryPointDescriptors.map((entryPoint) => this.peerDiscovery.joinDht(entryPoint, doAdditionalRandomPeerDiscovery, retry)));
|
|
439
438
|
}
|
|
440
|
-
async
|
|
441
|
-
return this.
|
|
439
|
+
async startFind(idToFind, fetchData, excludedPeer) {
|
|
440
|
+
return this.finder.startFind(idToFind, fetchData, excludedPeer);
|
|
442
441
|
}
|
|
443
442
|
async storeDataToDht(key, data) {
|
|
444
443
|
if (this.peerDiscovery.isJoinOngoing() && this.config.entryPoints && this.config.entryPoints.length > 0) {
|
|
@@ -447,14 +446,14 @@ class DhtNode extends eventemitter3_1.EventEmitter {
|
|
|
447
446
|
return this.storeRpcLocal.storeDataToDht(key, data);
|
|
448
447
|
}
|
|
449
448
|
async storeDataViaPeer(key, data, peer) {
|
|
450
|
-
const rpcRemote = new ExternalApiRpcRemote_1.ExternalApiRpcRemote(this.
|
|
449
|
+
const rpcRemote = new ExternalApiRpcRemote_1.ExternalApiRpcRemote(this.localPeerDescriptor, peer, this.config.serviceId, (0, proto_rpc_1.toProtoRpcClient)(new DhtRpc_client_1.ExternalApiRpcClient(this.rpcCommunicator.getRpcClientTransport())));
|
|
451
450
|
return await rpcRemote.storeData(key, data);
|
|
452
451
|
}
|
|
453
452
|
async getDataFromDht(idToFind) {
|
|
454
453
|
if (this.peerDiscovery.isJoinOngoing() && this.config.entryPoints && this.config.entryPoints.length > 0) {
|
|
455
454
|
return this.findDataViaPeer(idToFind, (0, lodash_1.sample)(this.config.entryPoints));
|
|
456
455
|
}
|
|
457
|
-
const result = await this.
|
|
456
|
+
const result = await this.finder.startFind(idToFind, true);
|
|
458
457
|
return result.dataEntries ?? [];
|
|
459
458
|
}
|
|
460
459
|
async deleteDataFromDht(idToDelete) {
|
|
@@ -463,23 +462,20 @@ class DhtNode extends eventemitter3_1.EventEmitter {
|
|
|
463
462
|
}
|
|
464
463
|
}
|
|
465
464
|
async findDataViaPeer(idToFind, peer) {
|
|
466
|
-
const rpcRemote = new ExternalApiRpcRemote_1.ExternalApiRpcRemote(this.
|
|
467
|
-
return await rpcRemote.
|
|
468
|
-
}
|
|
469
|
-
getRpcCommunicator() {
|
|
470
|
-
return this.rpcCommunicator;
|
|
465
|
+
const rpcRemote = new ExternalApiRpcRemote_1.ExternalApiRpcRemote(this.localPeerDescriptor, peer, this.config.serviceId, (0, proto_rpc_1.toProtoRpcClient)(new DhtRpc_client_1.ExternalApiRpcClient(this.rpcCommunicator.getRpcClientTransport())));
|
|
466
|
+
return await rpcRemote.externalFindData(idToFind);
|
|
471
467
|
}
|
|
472
468
|
getTransport() {
|
|
473
469
|
return this.transport;
|
|
474
470
|
}
|
|
475
|
-
|
|
476
|
-
return this.
|
|
471
|
+
getLocalPeerDescriptor() {
|
|
472
|
+
return this.localPeerDescriptor;
|
|
477
473
|
}
|
|
478
474
|
getAllConnectionPeerDescriptors() {
|
|
479
475
|
return Array.from(this.connections.values()).map((peer) => peer.getPeerDescriptor());
|
|
480
476
|
}
|
|
481
477
|
getKBucketPeers() {
|
|
482
|
-
return this.bucket.toArray().map((
|
|
478
|
+
return this.bucket.toArray().map((rpcRemote) => rpcRemote.getPeerDescriptor());
|
|
483
479
|
}
|
|
484
480
|
getNumberOfConnections() {
|
|
485
481
|
return this.connections.size;
|
|
@@ -508,52 +504,28 @@ class DhtNode extends eventemitter3_1.EventEmitter {
|
|
|
508
504
|
if (this.entryPointDisconnectTimeout) {
|
|
509
505
|
clearTimeout(this.entryPointDisconnectTimeout);
|
|
510
506
|
}
|
|
511
|
-
this.bucket.toArray().forEach((
|
|
507
|
+
this.bucket.toArray().forEach((rpcRemote) => {
|
|
508
|
+
rpcRemote.leaveNotice();
|
|
509
|
+
this.bucket.remove(rpcRemote.id);
|
|
510
|
+
});
|
|
512
511
|
this.bucket.removeAllListeners();
|
|
513
512
|
this.localDataStore.clear();
|
|
514
513
|
this.neighborList.stop();
|
|
515
514
|
this.randomPeers.stop();
|
|
516
|
-
this.openInternetPeers.stop();
|
|
517
515
|
this.rpcCommunicator.stop();
|
|
518
516
|
this.router.stop();
|
|
519
|
-
this.
|
|
517
|
+
this.finder.stop();
|
|
520
518
|
this.peerDiscovery.stop();
|
|
521
|
-
if (this.
|
|
522
|
-
|
|
519
|
+
if (this.config.transport === undefined) {
|
|
520
|
+
// if the transport was not given in config, the instance was created in start() and
|
|
521
|
+
// this component is responsible for stopping it
|
|
522
|
+
await this.transport.stop();
|
|
523
523
|
}
|
|
524
524
|
this.transport = undefined;
|
|
525
525
|
this.connectionManager = undefined;
|
|
526
526
|
this.connections.clear();
|
|
527
527
|
this.removeAllListeners();
|
|
528
528
|
}
|
|
529
|
-
// IDHTRpcService implementation
|
|
530
|
-
async getClosestPeers(request, context) {
|
|
531
|
-
this.addNewContact(context.incomingSourceDescriptor);
|
|
532
|
-
const response = {
|
|
533
|
-
peers: this.getClosestPeerDescriptors(request.kademliaId, this.config.peerDiscoveryQueryBatchSize),
|
|
534
|
-
requestId: request.requestId
|
|
535
|
-
};
|
|
536
|
-
return response;
|
|
537
|
-
}
|
|
538
|
-
// IDHTRpcService implementation
|
|
539
|
-
async ping(request, context) {
|
|
540
|
-
logger.trace('received ping request: ' + (0, peerIdFromPeerDescriptor_1.keyFromPeerDescriptor)(context.incomingSourceDescriptor));
|
|
541
|
-
setImmediate(() => {
|
|
542
|
-
this.addNewContact(context.incomingSourceDescriptor);
|
|
543
|
-
});
|
|
544
|
-
const response = {
|
|
545
|
-
requestId: request.requestId
|
|
546
|
-
};
|
|
547
|
-
return response;
|
|
548
|
-
}
|
|
549
|
-
// IDHTRpcService implementation
|
|
550
|
-
async leaveNotice(request, context) {
|
|
551
|
-
// TODO check signature??
|
|
552
|
-
if (request.serviceId === this.config.serviceId) {
|
|
553
|
-
this.removeContact(context.incomingSourceDescriptor);
|
|
554
|
-
}
|
|
555
|
-
return {};
|
|
556
|
-
}
|
|
557
529
|
}
|
|
558
530
|
exports.DhtNode = DhtNode;
|
|
559
531
|
//# sourceMappingURL=DhtNode.js.map
|