@streamr/dht 100.0.0-pretestnet.2 → 100.0.0-pretestnet.3
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 +6 -6
- package/dist/src/connection/ConnectionLockRpcRemote.js.map +1 -1
- package/dist/src/connection/ConnectionManager.d.ts +5 -8
- package/dist/src/connection/ConnectionManager.js +77 -107
- package/dist/src/connection/ConnectionManager.js.map +1 -1
- package/dist/src/connection/ConnectivityChecker.d.ts +7 -6
- package/dist/src/connection/ConnectivityChecker.js +23 -20
- package/dist/src/connection/ConnectivityChecker.js.map +1 -1
- package/dist/src/connection/ConnectorFacade.d.ts +15 -12
- package/dist/src/connection/ConnectorFacade.js +61 -26
- package/dist/src/connection/ConnectorFacade.js.map +1 -1
- package/dist/src/connection/Handshaker.d.ts +2 -2
- package/dist/src/connection/Handshaker.js +28 -28
- 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 +3 -4
- package/dist/src/connection/ManagedConnection.js +30 -30
- 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 +22 -22
- package/dist/src/connection/simulator/SimulatorConnection.js.map +1 -0
- package/dist/src/connection/{Simulator → simulator}/SimulatorConnector.d.ts +2 -2
- package/dist/src/connection/{Simulator → simulator}/SimulatorConnector.js +11 -11
- package/dist/src/connection/{Simulator → simulator}/SimulatorConnector.js.map +1 -1
- 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} +36 -36
- 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} +20 -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} +23 -27
- package/dist/src/connection/websocket/ServerWebsocket.js.map +1 -0
- package/dist/src/connection/{WebSocket/WebSocketConnectorRpcLocal.d.ts → websocket/WebsocketConnector.d.ts} +23 -15
- package/dist/src/connection/{WebSocket/WebSocketConnectorRpcLocal.js → websocket/WebsocketConnector.js} +107 -101
- 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} +5 -10
- package/dist/src/connection/{WebSocket/WebSocketConnectorRpcRemote.js.map → websocket/WebsocketConnectorRpcRemote.js.map} +1 -1
- 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 +119 -150
- 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} +17 -21
- 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 +8 -8
- 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 +5 -5
- 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 +47 -90
- 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 +15 -43
- 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 +25 -24
- package/dist/src/dht/store/StoreRpcLocal.js.map +1 -1
- package/dist/src/dht/store/StoreRpcRemote.js +3 -7
- 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/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 +64 -84
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +64 -66
- 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 +32 -35
- package/src/connection/ConnectionLockHandler.ts +19 -17
- package/src/connection/ConnectionLockRpcLocal.ts +74 -0
- package/src/connection/ConnectionLockRpcRemote.ts +7 -6
- package/src/connection/ConnectionManager.ts +59 -95
- package/src/connection/ConnectivityChecker.ts +30 -26
- package/src/connection/ConnectorFacade.ts +74 -34
- package/src/connection/Handshaker.ts +9 -9
- package/src/connection/IConnection.ts +5 -6
- package/src/connection/ManagedConnection.ts +21 -22
- package/src/connection/{ManagedWebRtcConnection.ts → ManagedWebrtcConnection.ts} +9 -9
- package/src/connection/{Simulator → simulator}/Simulator.ts +4 -4
- package/src/connection/{Simulator → simulator}/SimulatorConnection.ts +23 -24
- package/src/connection/{Simulator → simulator}/SimulatorConnector.ts +13 -13
- package/src/connection/{Simulator → simulator}/SimulatorTransport.ts +2 -2
- package/src/connection/{WebRTC/BrowserWebRtcConnection.ts → webrtc/BrowserWebrtcConnection.ts} +12 -13
- package/src/connection/{WebRTC/IWebRtcConnection.ts → webrtc/IWebrtcConnection.ts} +2 -2
- package/src/connection/{WebRTC/NodeWebRtcConnection.ts → webrtc/NodeWebrtcConnection.ts} +32 -33
- package/src/connection/webrtc/WebrtcConnector.ts +225 -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} +19 -17
- package/src/connection/{WebSocket/ServerWebSocket.ts → websocket/ServerWebsocket.ts} +21 -27
- package/src/connection/{WebSocket/WebSocketConnectorRpcLocal.ts → websocket/WebsocketConnector.ts} +109 -100
- package/src/connection/websocket/WebsocketConnectorRpcLocal.ts +41 -0
- package/src/connection/{WebSocket/WebSocketConnectorRpcRemote.ts → websocket/WebsocketConnectorRpcRemote.ts} +6 -12
- package/src/connection/{WebSocket/WebSocketServer.ts → websocket/WebsocketServer.ts} +40 -22
- package/src/dht/DhtNode.ts +144 -179
- package/src/dht/DhtNodeRpcLocal.ts +68 -0
- package/src/dht/{RemoteDhtNode.ts → DhtNodeRpcRemote.ts} +12 -13
- 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 +23 -20
- package/src/dht/discovery/PeerDiscovery.ts +14 -17
- 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 +69 -105
- package/src/dht/routing/RouterRpcLocal.ts +81 -0
- package/src/dht/routing/RouterRpcRemote.ts +15 -45
- package/src/dht/routing/RoutingSession.ts +56 -61
- package/src/dht/routing/getPreviousPeer.ts +6 -0
- package/src/dht/store/StoreRpcLocal.ts +44 -37
- package/src/dht/store/StoreRpcRemote.ts +4 -8
- package/src/exports.ts +11 -5
- package/src/helpers/Connectivity.ts +19 -0
- package/src/helpers/errors.ts +3 -3
- 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 +87 -114
- 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} +6 -6
- package/test/benchmark/KademliaCorrectness.test.ts +2 -2
- 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 +24 -6
- 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 +4 -4
- package/test/integration/ConnectionManager.test.ts +37 -28
- 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} +3 -3
- package/test/integration/Layer1-scale.test.ts +1 -1
- package/test/integration/MigrateData.test.ts +6 -5
- package/test/integration/Mock-Layer1-Layer0.test.ts +1 -1
- package/test/integration/MultipleEntryPointJoining.test.ts +6 -6
- package/test/integration/RouteMessage.test.ts +26 -26
- package/test/integration/RpcErrors.test.ts +10 -10
- package/test/integration/ScaleDownDht.test.ts +3 -3
- package/test/integration/SimultaneousConnections.test.ts +10 -7
- package/test/integration/Store.test.ts +1 -1
- package/test/integration/StoreAndDelete.test.ts +1 -1
- package/test/integration/StoreOnDhtWithTwoNodes.test.ts +12 -12
- package/test/integration/{WebRtcConnectionManagement.test.ts → WebrtcConnectionManagement.test.ts} +4 -4
- 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 +14 -24
- 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/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.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/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/test/integration/{WebRtcConnectionManagement.test.ts → WebrtcConnectionManagement.test.ts}
RENAMED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { ConnectionManager } from '../../src/connection/ConnectionManager'
|
|
2
|
-
import { LatencyType, Simulator } from '../../src/connection/
|
|
2
|
+
import { LatencyType, Simulator } from '../../src/connection/simulator/Simulator'
|
|
3
3
|
import { Message, MessageType, NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
4
4
|
import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
|
|
5
5
|
import { PeerID } from '../../src/helpers/PeerID'
|
|
6
6
|
import { ConnectionType } from '../../src/connection/IConnection'
|
|
7
7
|
import { ITransport } from '../../src/transport/ITransport'
|
|
8
8
|
import * as Err from '../../src/helpers/errors'
|
|
9
|
-
import { SimulatorTransport } from '../../src/connection/
|
|
9
|
+
import { SimulatorTransport } from '../../src/connection/simulator/SimulatorTransport'
|
|
10
10
|
import { DefaultConnectorFacade } from '../../src/connection/ConnectorFacade'
|
|
11
11
|
import { MetricsContext } from '@streamr/utils'
|
|
12
12
|
|
|
13
|
-
const createConnectionManager = (
|
|
13
|
+
const createConnectionManager = (localPeerDescriptor: PeerDescriptor, transport: ITransport) => {
|
|
14
14
|
return new ConnectionManager({
|
|
15
15
|
createConnectorFacade: () => new DefaultConnectorFacade({
|
|
16
16
|
transport,
|
|
17
|
-
|
|
17
|
+
createLocalPeerDescriptor: () => localPeerDescriptor
|
|
18
18
|
}),
|
|
19
19
|
metricsContext: new MetricsContext()
|
|
20
20
|
})
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import { ProtoRpcClient, RpcCommunicator, toProtoRpcClient } from '@streamr/proto-rpc'
|
|
2
|
-
import {
|
|
2
|
+
import { WebrtcConnectorRpcClient } from '../../src/proto/packages/dht/protos/DhtRpc.client'
|
|
3
3
|
import {
|
|
4
4
|
IceCandidate,
|
|
5
5
|
NodeType,
|
|
6
6
|
PeerDescriptor,
|
|
7
7
|
RtcAnswer,
|
|
8
8
|
RtcOffer,
|
|
9
|
-
|
|
9
|
+
WebrtcConnectionRequest
|
|
10
10
|
} from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
11
11
|
import { Empty } from '../../src/proto/google/protobuf/empty'
|
|
12
12
|
import { generateId } from '../utils/utils'
|
|
13
|
-
import {
|
|
13
|
+
import { IWebrtcConnectorRpc } from '../../src/proto/packages/dht/protos/DhtRpc.server'
|
|
14
14
|
import { waitForCondition } from '@streamr/utils'
|
|
15
15
|
import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
|
|
16
16
|
|
|
17
17
|
describe('WebRTC rpc messages', () => {
|
|
18
18
|
let rpcCommunicator1: RpcCommunicator
|
|
19
19
|
let rpcCommunicator2: RpcCommunicator
|
|
20
|
-
let client: ProtoRpcClient<
|
|
20
|
+
let client: ProtoRpcClient<WebrtcConnectorRpcClient>
|
|
21
21
|
|
|
22
22
|
let requestConnectionCounter: number
|
|
23
23
|
let rtcOfferCounter: number
|
|
@@ -36,7 +36,7 @@ describe('WebRTC rpc messages', () => {
|
|
|
36
36
|
iceCandidateCounter = 0
|
|
37
37
|
|
|
38
38
|
rpcCommunicator1 = new RpcCommunicator()
|
|
39
|
-
const serverFunctions:
|
|
39
|
+
const serverFunctions: IWebrtcConnectorRpc = {
|
|
40
40
|
|
|
41
41
|
requestConnection: async (): Promise<Empty> => {
|
|
42
42
|
requestConnectionCounter += 1
|
|
@@ -67,7 +67,7 @@ describe('WebRTC rpc messages', () => {
|
|
|
67
67
|
rpcCommunicator2.registerRpcNotification(RtcOffer, 'rtcOffer', serverFunctions.rtcOffer)
|
|
68
68
|
rpcCommunicator2.registerRpcNotification(RtcAnswer, 'rtcAnswer', serverFunctions.rtcAnswer)
|
|
69
69
|
rpcCommunicator2.registerRpcNotification(IceCandidate, 'iceCandidate', serverFunctions.iceCandidate)
|
|
70
|
-
rpcCommunicator2.registerRpcNotification(
|
|
70
|
+
rpcCommunicator2.registerRpcNotification(WebrtcConnectionRequest, 'requestConnection', serverFunctions.requestConnection)
|
|
71
71
|
|
|
72
72
|
rpcCommunicator1.on('outgoingMessage', (message: RpcMessage) => {
|
|
73
73
|
rpcCommunicator2.handleIncomingMessage(message)
|
|
@@ -77,7 +77,7 @@ describe('WebRTC rpc messages', () => {
|
|
|
77
77
|
rpcCommunicator1.handleIncomingMessage(message)
|
|
78
78
|
})
|
|
79
79
|
|
|
80
|
-
client = toProtoRpcClient(new
|
|
80
|
+
client = toProtoRpcClient(new WebrtcConnectorRpcClient(rpcCommunicator1.getRpcClientTransport()))
|
|
81
81
|
})
|
|
82
82
|
|
|
83
83
|
afterEach(async () => {
|
|
@@ -87,7 +87,6 @@ describe('WebRTC rpc messages', () => {
|
|
|
87
87
|
|
|
88
88
|
it('send connectionRequest', async () => {
|
|
89
89
|
client.requestConnection({
|
|
90
|
-
connectionId: 'connectionRequest'
|
|
91
90
|
},
|
|
92
91
|
{ targetDescriptor, notification: true }
|
|
93
92
|
)
|
|
@@ -1,26 +1,27 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { WebsocketServer } from '../../src/connection/websocket/WebsocketServer'
|
|
4
4
|
import { IConnection } from '../../src/connection/IConnection'
|
|
5
|
-
import {
|
|
5
|
+
import { ClientWebsocket } from '../../src/connection/websocket/ClientWebsocket'
|
|
6
6
|
import { Logger } from '@streamr/utils'
|
|
7
7
|
|
|
8
8
|
const logger = new Logger(module)
|
|
9
9
|
|
|
10
|
-
describe('
|
|
10
|
+
describe('Websocket', () => {
|
|
11
11
|
|
|
12
|
-
const
|
|
13
|
-
portRange: { min:
|
|
12
|
+
const websocketServer = new WebsocketServer({
|
|
13
|
+
portRange: { min: 9977, max: 9977 },
|
|
14
|
+
enableTls: false
|
|
14
15
|
})
|
|
15
|
-
const
|
|
16
|
+
const clientWebsocket = new ClientWebsocket()
|
|
16
17
|
|
|
17
18
|
beforeAll(async () => {
|
|
18
|
-
await
|
|
19
|
+
await websocketServer.start()
|
|
19
20
|
})
|
|
20
21
|
|
|
21
22
|
it('Happy path', (done) => {
|
|
22
23
|
|
|
23
|
-
|
|
24
|
+
websocketServer.on('connected', (serverConnection: IConnection) => {
|
|
24
25
|
const time = Date.now()
|
|
25
26
|
logger.info('server side sendind msg at ' + time)
|
|
26
27
|
serverConnection.send(Uint8Array.from([1, 2, 3, 4]))
|
|
@@ -40,11 +41,11 @@ describe('WebSocket', () => {
|
|
|
40
41
|
})
|
|
41
42
|
})
|
|
42
43
|
|
|
43
|
-
|
|
44
|
+
clientWebsocket.on('connected', () => {
|
|
44
45
|
const time = Date.now()
|
|
45
46
|
logger.info('client side setting listeners at ' + time)
|
|
46
47
|
|
|
47
|
-
|
|
48
|
+
clientWebsocket.on('data', (bytes: Uint8Array) => {
|
|
48
49
|
const time = Date.now()
|
|
49
50
|
logger.info('client side receiving message at ' + time)
|
|
50
51
|
|
|
@@ -53,14 +54,14 @@ describe('WebSocket', () => {
|
|
|
53
54
|
|
|
54
55
|
const time2 = Date.now()
|
|
55
56
|
logger.info('client side sendind msg at ' + time2)
|
|
56
|
-
|
|
57
|
+
clientWebsocket.send(Uint8Array.from([1, 2, 3, 4]))
|
|
57
58
|
})
|
|
58
59
|
})
|
|
59
60
|
|
|
60
|
-
|
|
61
|
+
clientWebsocket.connect('ws://127.0.0.1:9977')
|
|
61
62
|
})
|
|
62
63
|
|
|
63
64
|
afterAll(async () => {
|
|
64
|
-
await
|
|
65
|
+
await websocketServer.stop()
|
|
65
66
|
})
|
|
66
67
|
})
|
|
@@ -4,24 +4,24 @@ import { MetricsContext, waitForCondition } from '@streamr/utils'
|
|
|
4
4
|
import { ConnectionManager } from '../../src/connection/ConnectionManager'
|
|
5
5
|
import { DefaultConnectorFacade, DefaultConnectorFacadeConfig } from '../../src/connection/ConnectorFacade'
|
|
6
6
|
import { ConnectionType } from '../../src/connection/IConnection'
|
|
7
|
-
import { Simulator } from '../../src/connection/
|
|
7
|
+
import { Simulator } from '../../src/connection/simulator/Simulator'
|
|
8
8
|
import { SimulatorTransport } from '../../src/exports'
|
|
9
9
|
import { PeerID } from '../../src/helpers/PeerID'
|
|
10
10
|
import * as Err from '../../src/helpers/errors'
|
|
11
11
|
import { Message, MessageType, NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
12
12
|
import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
|
|
13
13
|
|
|
14
|
-
const createConfig = (
|
|
14
|
+
const createConfig = (localPeerDescriptor: PeerDescriptor, opts: Omit<DefaultConnectorFacadeConfig, 'createLocalPeerDescriptor'>) => {
|
|
15
15
|
return {
|
|
16
16
|
createConnectorFacade: () => new DefaultConnectorFacade({
|
|
17
|
-
|
|
17
|
+
createLocalPeerDescriptor: () => localPeerDescriptor,
|
|
18
18
|
...opts
|
|
19
19
|
}),
|
|
20
20
|
metricsContext: new MetricsContext()
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
describe('
|
|
24
|
+
describe('Websocket Connection Management', () => {
|
|
25
25
|
|
|
26
26
|
const serviceId = 'test'
|
|
27
27
|
let wsServerManager: ConnectionManager
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { ProtoRpcClient, RpcCommunicator, toProtoRpcClient } from '@streamr/proto-rpc'
|
|
2
|
-
import {
|
|
2
|
+
import { WebsocketConnectorRpcClient } from '../../src/proto/packages/dht/protos/DhtRpc.client'
|
|
3
3
|
import { generateId } from '../utils/utils'
|
|
4
4
|
import {
|
|
5
5
|
NodeType,
|
|
6
6
|
PeerDescriptor,
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
WebsocketConnectionRequest,
|
|
8
|
+
WebsocketConnectionResponse
|
|
9
9
|
} from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
10
|
-
import {
|
|
10
|
+
import { mockWebsocketConnectorRpc } from '../utils/utils'
|
|
11
11
|
import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
|
|
12
12
|
|
|
13
|
-
describe('
|
|
13
|
+
describe('WebsocketConnectorRpc', () => {
|
|
14
14
|
let rpcCommunicator1: RpcCommunicator
|
|
15
15
|
let rpcCommunicator2: RpcCommunicator
|
|
16
|
-
let client1: ProtoRpcClient<
|
|
17
|
-
let client2: ProtoRpcClient<
|
|
16
|
+
let client1: ProtoRpcClient<WebsocketConnectorRpcClient>
|
|
17
|
+
let client2: ProtoRpcClient<WebsocketConnectorRpcClient>
|
|
18
18
|
|
|
19
19
|
const peerDescriptor1: PeerDescriptor = {
|
|
20
20
|
kademliaId: generateId('peer1'),
|
|
@@ -29,18 +29,18 @@ describe('WebSocketConnectorRpc', () => {
|
|
|
29
29
|
beforeEach(() => {
|
|
30
30
|
rpcCommunicator1 = new RpcCommunicator()
|
|
31
31
|
rpcCommunicator1.registerRpcMethod(
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
WebsocketConnectionRequest,
|
|
33
|
+
WebsocketConnectionResponse,
|
|
34
34
|
'requestConnection',
|
|
35
|
-
|
|
35
|
+
mockWebsocketConnectorRpc.requestConnection
|
|
36
36
|
)
|
|
37
37
|
|
|
38
38
|
rpcCommunicator2 = new RpcCommunicator()
|
|
39
39
|
rpcCommunicator2.registerRpcMethod(
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
WebsocketConnectionRequest,
|
|
41
|
+
WebsocketConnectionResponse,
|
|
42
42
|
'requestConnection',
|
|
43
|
-
|
|
43
|
+
mockWebsocketConnectorRpc.requestConnection
|
|
44
44
|
)
|
|
45
45
|
|
|
46
46
|
rpcCommunicator1.on('outgoingMessage', (message: RpcMessage) => {
|
|
@@ -51,8 +51,8 @@ describe('WebSocketConnectorRpc', () => {
|
|
|
51
51
|
rpcCommunicator1.handleIncomingMessage(message)
|
|
52
52
|
})
|
|
53
53
|
|
|
54
|
-
client1 = toProtoRpcClient(new
|
|
55
|
-
client2 = toProtoRpcClient(new
|
|
54
|
+
client1 = toProtoRpcClient(new WebsocketConnectorRpcClient(rpcCommunicator1.getRpcClientTransport()))
|
|
55
|
+
client2 = toProtoRpcClient(new WebsocketConnectorRpcClient(rpcCommunicator2.getRpcClientTransport()))
|
|
56
56
|
})
|
|
57
57
|
|
|
58
58
|
afterEach(async () => {
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import EventEmitter from 'eventemitter3'
|
|
2
|
+
import { AutoCertifierClientFacade, IAutoCertifierClient } from '../../src/connection/websocket/AutoCertifierClientFacade'
|
|
3
|
+
import { MockTransport } from '../utils/mock/Transport'
|
|
4
|
+
|
|
5
|
+
class MockAutoCertifierClient extends EventEmitter {
|
|
6
|
+
start = async () => {
|
|
7
|
+
this.emit('updatedCertificate', {})
|
|
8
|
+
}
|
|
9
|
+
// eslint-disable-next-line class-methods-use-this
|
|
10
|
+
stop = () => {}
|
|
11
|
+
emitUpdateSubdomain = () => {
|
|
12
|
+
this.emit('updatedCertificate', {})
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
describe('AutoCertifierClientFacade', () => {
|
|
17
|
+
|
|
18
|
+
let client: AutoCertifierClientFacade
|
|
19
|
+
let mockClient: IAutoCertifierClient
|
|
20
|
+
let setHost: jest.Mock
|
|
21
|
+
let updateCertificate: jest.Mock
|
|
22
|
+
|
|
23
|
+
beforeEach(() => {
|
|
24
|
+
mockClient = new MockAutoCertifierClient()
|
|
25
|
+
const mockClientFactory = (): IAutoCertifierClient => mockClient
|
|
26
|
+
setHost = jest.fn()
|
|
27
|
+
updateCertificate = jest.fn()
|
|
28
|
+
client = new AutoCertifierClientFacade({
|
|
29
|
+
url: '',
|
|
30
|
+
configFile: '',
|
|
31
|
+
transport: new MockTransport(),
|
|
32
|
+
wsServerPort: 0,
|
|
33
|
+
setHost,
|
|
34
|
+
updateCertificate,
|
|
35
|
+
createClientFactory: mockClientFactory
|
|
36
|
+
})
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
afterEach(() => {
|
|
40
|
+
client.stop()
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
it('start', async () => {
|
|
44
|
+
await client.start()
|
|
45
|
+
expect(setHost).toBeCalled()
|
|
46
|
+
expect(updateCertificate).toBeCalled()
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
it('updated events are processed', async () => {
|
|
50
|
+
await client.start()
|
|
51
|
+
expect(setHost).toBeCalledTimes(1)
|
|
52
|
+
expect(updateCertificate).toBeCalledTimes(1);
|
|
53
|
+
(mockClient as MockAutoCertifierClient).emitUpdateSubdomain()
|
|
54
|
+
expect(setHost).toBeCalledTimes(2)
|
|
55
|
+
expect(updateCertificate).toBeCalledTimes(2)
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
})
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { NodeType } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
2
|
+
import { expectedConnectionType } from '../../src/helpers/Connectivity'
|
|
3
|
+
import { ConnectionType } from '../../src/connection/IConnection'
|
|
4
|
+
|
|
5
|
+
describe('Connectivity helpers', () => {
|
|
6
|
+
|
|
7
|
+
const tlsServerPeerDescriptor = {
|
|
8
|
+
kademliaId: new Uint8Array(1),
|
|
9
|
+
type: NodeType.NODEJS,
|
|
10
|
+
websocket: {
|
|
11
|
+
host: 'mock',
|
|
12
|
+
port: 1234,
|
|
13
|
+
tls: true
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const noTlsServerPeerDescriptor = {
|
|
18
|
+
kademliaId: new Uint8Array(1),
|
|
19
|
+
type: NodeType.NODEJS,
|
|
20
|
+
websocket: {
|
|
21
|
+
host: 'mock',
|
|
22
|
+
port: 1234,
|
|
23
|
+
tls: false
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const browserPeerDescriptor = {
|
|
28
|
+
kademliaId: new Uint8Array(2),
|
|
29
|
+
type: NodeType.BROWSER
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const noServerPeerDescriptor = {
|
|
33
|
+
kademliaId: new Uint8Array(3),
|
|
34
|
+
type: NodeType.NODEJS
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
it('two server peers', () => {
|
|
38
|
+
expect(expectedConnectionType(tlsServerPeerDescriptor, tlsServerPeerDescriptor)).toBe(ConnectionType.WEBSOCKET_CLIENT)
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it('server to noServer', () => {
|
|
42
|
+
expect(expectedConnectionType(tlsServerPeerDescriptor, noServerPeerDescriptor)).toBe(ConnectionType.WEBSOCKET_SERVER)
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
it('no server to server', () => {
|
|
46
|
+
expect(expectedConnectionType(noServerPeerDescriptor, tlsServerPeerDescriptor)).toBe(ConnectionType.WEBSOCKET_CLIENT)
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
it('no server to no server', () => {
|
|
50
|
+
expect(expectedConnectionType(noServerPeerDescriptor, noServerPeerDescriptor)).toBe(ConnectionType.WEBRTC)
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('browser to tls server', () => {
|
|
54
|
+
expect(expectedConnectionType(browserPeerDescriptor, tlsServerPeerDescriptor)).toBe(ConnectionType.WEBSOCKET_CLIENT)
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
it('tls server to browser', () => {
|
|
58
|
+
expect(expectedConnectionType(tlsServerPeerDescriptor, browserPeerDescriptor)).toBe(ConnectionType.WEBSOCKET_SERVER)
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
it('browser to no tls server', () => {
|
|
62
|
+
expect(expectedConnectionType(browserPeerDescriptor, noTlsServerPeerDescriptor)).toBe(ConnectionType.WEBRTC)
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
it('no tls server to browser', () => {
|
|
66
|
+
expect(expectedConnectionType(noTlsServerPeerDescriptor, browserPeerDescriptor)).toBe(ConnectionType.WEBRTC)
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
})
|
|
@@ -3,26 +3,27 @@ import {
|
|
|
3
3
|
MessageType,
|
|
4
4
|
NodeType,
|
|
5
5
|
PeerDescriptor,
|
|
6
|
+
RouteMessageAck,
|
|
6
7
|
RouteMessageWrapper
|
|
7
8
|
} from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
8
9
|
import { PeerID, PeerIDKey } from '../../src/helpers/PeerID'
|
|
9
10
|
import {
|
|
10
|
-
createMockRoutingRpcCommunicator,
|
|
11
11
|
createWrappedClosestPeersRequest,
|
|
12
12
|
createFindRequest
|
|
13
13
|
} from '../utils/utils'
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
14
|
+
import { Finder } from '../../src/dht/find/Finder'
|
|
15
|
+
import { DhtNodeRpcRemote } from '../../src/dht/DhtNodeRpcRemote'
|
|
16
16
|
import { LocalDataStore } from '../../src/dht/store/LocalDataStore'
|
|
17
17
|
import { v4 } from 'uuid'
|
|
18
18
|
import { MockRouter } from '../utils/mock/Router'
|
|
19
19
|
import { MockTransport } from '../utils/mock/Transport'
|
|
20
20
|
import { areEqualPeerDescriptors } from '../../src/helpers/peerIdFromPeerDescriptor'
|
|
21
|
+
import { FakeRpcCommunicator } from '../utils/FakeRpcCommunicator'
|
|
21
22
|
|
|
22
|
-
describe('
|
|
23
|
+
describe('Finder', () => {
|
|
23
24
|
|
|
24
|
-
let
|
|
25
|
-
let connections: Map<PeerIDKey,
|
|
25
|
+
let finder: Finder
|
|
26
|
+
let connections: Map<PeerIDKey, DhtNodeRpcRemote>
|
|
26
27
|
|
|
27
28
|
const peerDescriptor1: PeerDescriptor = {
|
|
28
29
|
kademliaId: PeerID.fromString('peerid').value,
|
|
@@ -52,37 +53,38 @@ describe('RecursiveFinder', () => {
|
|
|
52
53
|
destinationPeer: peerDescriptor1,
|
|
53
54
|
sourcePeer: peerDescriptor2
|
|
54
55
|
}
|
|
56
|
+
const rpcCommunicator = new FakeRpcCommunicator()
|
|
55
57
|
|
|
56
58
|
beforeEach(() => {
|
|
57
59
|
connections = new Map()
|
|
58
|
-
|
|
59
|
-
|
|
60
|
+
finder = new Finder({
|
|
61
|
+
localPeerDescriptor: peerDescriptor1,
|
|
60
62
|
router: new MockRouter(),
|
|
61
63
|
connections,
|
|
62
|
-
serviceId: '
|
|
64
|
+
serviceId: 'Finder',
|
|
63
65
|
localDataStore: new LocalDataStore(),
|
|
64
66
|
sessionTransport: new MockTransport(),
|
|
65
67
|
addContact: (_contact, _setActive) => {},
|
|
66
68
|
isPeerCloserToIdThanSelf: (_peer1, _compareToId) => true,
|
|
67
|
-
rpcCommunicator:
|
|
69
|
+
rpcCommunicator: rpcCommunicator as any
|
|
68
70
|
})
|
|
69
71
|
})
|
|
70
72
|
|
|
71
73
|
afterEach(() => {
|
|
72
|
-
|
|
74
|
+
finder.stop()
|
|
73
75
|
})
|
|
74
76
|
|
|
75
|
-
it('
|
|
76
|
-
const res = await
|
|
77
|
+
it('Finder server', async () => {
|
|
78
|
+
const res = await rpcCommunicator.callRpcMethod('routeFindRequest', routedMessage) as RouteMessageAck
|
|
77
79
|
expect(res.error).toEqual('')
|
|
78
80
|
})
|
|
79
81
|
|
|
80
|
-
it('
|
|
81
|
-
const res = await
|
|
82
|
+
it('startFind with mode Node returns self if no peers', async () => {
|
|
83
|
+
const res = await finder.startFind(PeerID.fromString('find').value)
|
|
82
84
|
expect(areEqualPeerDescriptors(res.closestNodes[0], peerDescriptor1)).toEqual(true)
|
|
83
85
|
})
|
|
84
86
|
|
|
85
|
-
it('
|
|
87
|
+
it('Finder server throws if payload is not FindRequest', async () => {
|
|
86
88
|
const rpcWrapper = createWrappedClosestPeersRequest(peerDescriptor1)
|
|
87
89
|
const badMessage: Message = {
|
|
88
90
|
serviceId: 'unknown',
|
|
@@ -95,7 +97,7 @@ describe('RecursiveFinder', () => {
|
|
|
95
97
|
sourceDescriptor: peerDescriptor1,
|
|
96
98
|
targetDescriptor: peerDescriptor2
|
|
97
99
|
}
|
|
98
|
-
await expect(
|
|
100
|
+
await expect(() => rpcCommunicator.callRpcMethod('routeFindRequest', {
|
|
99
101
|
message: badMessage,
|
|
100
102
|
requestId: 'REQ',
|
|
101
103
|
routingPath: [],
|
package/test/unit/Router.test.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { v4 } from 'uuid'
|
|
2
|
+
import { DhtNodeRpcRemote } from '../../src/dht/DhtNodeRpcRemote'
|
|
1
3
|
import { Router } from '../../src/dht/routing/Router'
|
|
2
|
-
import { Message, MessageType, NodeType, PeerDescriptor, RouteMessageWrapper } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
3
4
|
import { PeerID, PeerIDKey } from '../../src/helpers/PeerID'
|
|
4
|
-
import {
|
|
5
|
-
import { createWrappedClosestPeersRequest
|
|
6
|
-
import {
|
|
5
|
+
import { Message, MessageType, NodeType, PeerDescriptor, RouteMessageAck, RouteMessageWrapper } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
6
|
+
import { createWrappedClosestPeersRequest } from '../utils/utils'
|
|
7
|
+
import { FakeRpcCommunicator } from '../utils/FakeRpcCommunicator'
|
|
7
8
|
|
|
8
9
|
describe('Router', () => {
|
|
9
10
|
let router: Router
|
|
@@ -37,18 +38,18 @@ describe('Router', () => {
|
|
|
37
38
|
destinationPeer: peerDescriptor1,
|
|
38
39
|
sourcePeer: peerDescriptor2
|
|
39
40
|
}
|
|
40
|
-
let connections: Map<PeerIDKey,
|
|
41
|
-
const
|
|
41
|
+
let connections: Map<PeerIDKey, DhtNodeRpcRemote>
|
|
42
|
+
const rpcCommunicator = new FakeRpcCommunicator()
|
|
42
43
|
|
|
43
|
-
const
|
|
44
|
-
return new
|
|
44
|
+
const createMockDhtNodeRpcRemote = (destination: PeerDescriptor): DhtNodeRpcRemote => {
|
|
45
|
+
return new DhtNodeRpcRemote(peerDescriptor1, destination, {} as any, 'router')
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
beforeEach(() => {
|
|
48
49
|
connections = new Map()
|
|
49
50
|
router = new Router({
|
|
50
|
-
|
|
51
|
-
rpcCommunicator:
|
|
51
|
+
localPeerDescriptor: peerDescriptor1,
|
|
52
|
+
rpcCommunicator: rpcCommunicator as any,
|
|
52
53
|
addContact: (_contact) => {},
|
|
53
54
|
serviceId: 'router',
|
|
54
55
|
connections
|
|
@@ -59,63 +60,62 @@ describe('Router', () => {
|
|
|
59
60
|
router.stop()
|
|
60
61
|
})
|
|
61
62
|
|
|
62
|
-
it('doRouteMessage without connections', () => {
|
|
63
|
-
const ack =
|
|
63
|
+
it('doRouteMessage without connections', async () => {
|
|
64
|
+
const ack = await rpcCommunicator.callRpcMethod('routeMessage', {
|
|
64
65
|
message,
|
|
65
66
|
destinationPeer: peerDescriptor2,
|
|
66
67
|
requestId: v4(),
|
|
67
68
|
sourcePeer: peerDescriptor1,
|
|
68
69
|
reachableThrough: [],
|
|
69
70
|
routingPath: []
|
|
70
|
-
})
|
|
71
|
+
}) as RouteMessageAck
|
|
71
72
|
expect(ack.error).toEqual('No routing candidates found')
|
|
72
73
|
})
|
|
73
74
|
|
|
74
|
-
it('doRouteMessage with connections', () => {
|
|
75
|
-
connections.set(PeerID.fromString('test').toKey(),
|
|
76
|
-
const ack =
|
|
75
|
+
it('doRouteMessage with connections', async () => {
|
|
76
|
+
connections.set(PeerID.fromString('test').toKey(), createMockDhtNodeRpcRemote(peerDescriptor2))
|
|
77
|
+
const ack = await rpcCommunicator.callRpcMethod('routeMessage', {
|
|
77
78
|
message,
|
|
78
79
|
destinationPeer: peerDescriptor2,
|
|
79
80
|
requestId: v4(),
|
|
80
81
|
sourcePeer: peerDescriptor1,
|
|
81
82
|
reachableThrough: [],
|
|
82
83
|
routingPath: []
|
|
83
|
-
})
|
|
84
|
+
}) as RouteMessageAck
|
|
84
85
|
expect(ack.error).toEqual('')
|
|
85
86
|
})
|
|
86
87
|
|
|
87
88
|
it('route server is destination without connections', async () => {
|
|
88
|
-
const ack = await
|
|
89
|
+
const ack = await rpcCommunicator.callRpcMethod('routeMessage', routedMessage) as RouteMessageAck
|
|
89
90
|
expect(ack.error).toEqual('')
|
|
90
91
|
})
|
|
91
92
|
|
|
92
93
|
it('route server with connections', async () => {
|
|
93
|
-
connections.set(PeerID.fromString('test').toKey(),
|
|
94
|
-
const ack = await
|
|
94
|
+
connections.set(PeerID.fromString('test').toKey(), createMockDhtNodeRpcRemote(peerDescriptor2))
|
|
95
|
+
const ack = await rpcCommunicator.callRpcMethod('routeMessage', routedMessage) as RouteMessageAck
|
|
95
96
|
expect(ack.error).toEqual('')
|
|
96
97
|
})
|
|
97
98
|
|
|
98
99
|
it('route server on duplicate message', async () => {
|
|
99
100
|
router.addToDuplicateDetector(routedMessage.requestId)
|
|
100
|
-
const ack = await
|
|
101
|
+
const ack = await rpcCommunicator.callRpcMethod('routeMessage', routedMessage) as RouteMessageAck
|
|
101
102
|
expect(ack.error).toEqual('message given to routeMessage() service is likely a duplicate')
|
|
102
103
|
})
|
|
103
104
|
|
|
104
105
|
it('forward server no connections', async () => {
|
|
105
|
-
const ack = await
|
|
106
|
+
const ack = await rpcCommunicator.callRpcMethod('forwardMessage', routedMessage) as RouteMessageAck
|
|
106
107
|
expect(ack.error).toEqual('No routing candidates found')
|
|
107
108
|
})
|
|
108
109
|
|
|
109
110
|
it('forward server with connections', async () => {
|
|
110
|
-
connections.set(PeerID.fromString('test').toKey(),
|
|
111
|
-
const ack = await
|
|
111
|
+
connections.set(PeerID.fromString('test').toKey(), createMockDhtNodeRpcRemote(peerDescriptor2))
|
|
112
|
+
const ack = await rpcCommunicator.callRpcMethod('forwardMessage', routedMessage) as RouteMessageAck
|
|
112
113
|
expect(ack.error).toEqual('')
|
|
113
114
|
})
|
|
114
115
|
|
|
115
116
|
it('forward server on duplicate message', async () => {
|
|
116
117
|
router.addToDuplicateDetector(routedMessage.requestId)
|
|
117
|
-
const ack = await
|
|
118
|
+
const ack = await rpcCommunicator.callRpcMethod('forwardMessage', routedMessage) as RouteMessageAck
|
|
118
119
|
expect(ack.error).toEqual('message given to forwardMessage() service is likely a duplicate')
|
|
119
120
|
})
|
|
120
|
-
|
|
121
121
|
})
|
package/test/unit/UUID.test.ts
CHANGED
|
@@ -32,7 +32,7 @@ describe('UUID', () => {
|
|
|
32
32
|
})
|
|
33
33
|
|
|
34
34
|
it('Throws if incorrect string is given as uuid string parameter', () => {
|
|
35
|
-
expect(()=> {new UUID('äå%')}).toThrow(TypeError)
|
|
35
|
+
expect(() => {new UUID('äå%')}).toThrow(TypeError)
|
|
36
36
|
})
|
|
37
37
|
|
|
38
38
|
it('Uses passed UUID as id', () => {
|