@streamr/dht 0.0.1-tatum.0
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/.eslintignore +5 -0
- package/.eslintrc +3 -0
- package/README.md +38 -0
- package/dist/src/connection/Connection.d.ts +11 -0
- package/dist/src/connection/Connection.js +23 -0
- package/dist/src/connection/Connection.js.map +1 -0
- package/dist/src/connection/ConnectionLockHandler.d.ts +23 -0
- package/dist/src/connection/ConnectionLockHandler.js +94 -0
- package/dist/src/connection/ConnectionLockHandler.js.map +1 -0
- package/dist/src/connection/ConnectionManager.d.ts +94 -0
- package/dist/src/connection/ConnectionManager.js +554 -0
- package/dist/src/connection/ConnectionManager.js.map +1 -0
- package/dist/src/connection/ConnectivityChecker.d.ts +17 -0
- package/dist/src/connection/ConnectivityChecker.js +187 -0
- package/dist/src/connection/ConnectivityChecker.js.map +1 -0
- package/dist/src/connection/Handshaker.d.ts +19 -0
- package/dist/src/connection/Handshaker.js +77 -0
- package/dist/src/connection/Handshaker.js.map +1 -0
- package/dist/src/connection/IConnection.d.ts +38 -0
- package/dist/src/connection/IConnection.js +19 -0
- package/dist/src/connection/IConnection.js.map +1 -0
- package/dist/src/connection/IConnectionSource.d.ts +4 -0
- package/dist/src/connection/IConnectionSource.js +3 -0
- package/dist/src/connection/IConnectionSource.js.map +1 -0
- package/dist/src/connection/ManagedConnection.d.ts +60 -0
- package/dist/src/connection/ManagedConnection.js +352 -0
- package/dist/src/connection/ManagedConnection.js.map +1 -0
- 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/RemoteConnectionLocker.d.ts +14 -0
- package/dist/src/connection/RemoteConnectionLocker.js +93 -0
- package/dist/src/connection/RemoteConnectionLocker.js.map +1 -0
- package/dist/src/connection/Simulator/Simulator.d.ts +42 -0
- package/dist/src/connection/Simulator/Simulator.js +325 -0
- package/dist/src/connection/Simulator/Simulator.js.map +1 -0
- package/dist/src/connection/Simulator/SimulatorConnection.d.ts +19 -0
- package/dist/src/connection/Simulator/SimulatorConnection.js +118 -0
- package/dist/src/connection/Simulator/SimulatorConnection.js.map +1 -0
- package/dist/src/connection/Simulator/SimulatorConnector.d.ts +17 -0
- package/dist/src/connection/Simulator/SimulatorConnector.js +72 -0
- package/dist/src/connection/Simulator/SimulatorConnector.js.map +1 -0
- package/dist/src/connection/Simulator/SimulatorTransport.d.ts +6 -0
- package/dist/src/connection/Simulator/SimulatorTransport.js +11 -0
- package/dist/src/connection/Simulator/SimulatorTransport.js.map +1 -0
- package/dist/src/connection/Simulator/pings.d.ts +21 -0
- package/dist/src/connection/Simulator/pings.js +61 -0
- package/dist/src/connection/Simulator/pings.js.map +1 -0
- package/dist/src/connection/WebRTC/IWebRtcConnection.d.ts +20 -0
- package/dist/src/connection/WebRTC/IWebRtcConnection.js +9 -0
- package/dist/src/connection/WebRTC/IWebRtcConnection.js.map +1 -0
- package/dist/src/connection/WebRTC/NodeWebRtcConnection.d.ts +47 -0
- package/dist/src/connection/WebRTC/NodeWebRtcConnection.js +233 -0
- package/dist/src/connection/WebRTC/NodeWebRtcConnection.js.map +1 -0
- package/dist/src/connection/WebRTC/RemoteWebrtcConnector.d.ts +12 -0
- package/dist/src/connection/WebRTC/RemoteWebrtcConnector.js +74 -0
- package/dist/src/connection/WebRTC/RemoteWebrtcConnector.js.map +1 -0
- package/dist/src/connection/WebRTC/WebRtcConnector.d.ts +47 -0
- package/dist/src/connection/WebRTC/WebRtcConnector.js +227 -0
- package/dist/src/connection/WebRTC/WebRtcConnector.js.map +1 -0
- package/dist/src/connection/WebRTC/iceServerAsString.d.ts +2 -0
- package/dist/src/connection/WebRTC/iceServerAsString.js +18 -0
- package/dist/src/connection/WebRTC/iceServerAsString.js.map +1 -0
- package/dist/src/connection/WebSocket/ClientWebSocket.d.ts +15 -0
- package/dist/src/connection/WebSocket/ClientWebSocket.js +113 -0
- package/dist/src/connection/WebSocket/ClientWebSocket.js.map +1 -0
- package/dist/src/connection/WebSocket/RemoteWebSocketConnector.d.ts +9 -0
- package/dist/src/connection/WebSocket/RemoteWebSocketConnector.js +63 -0
- package/dist/src/connection/WebSocket/RemoteWebSocketConnector.js.map +1 -0
- package/dist/src/connection/WebSocket/ServerWebSocket.d.ts +18 -0
- package/dist/src/connection/WebSocket/ServerWebSocket.js +103 -0
- package/dist/src/connection/WebSocket/ServerWebSocket.js.map +1 -0
- package/dist/src/connection/WebSocket/WebSocketConnector.d.ts +31 -0
- package/dist/src/connection/WebSocket/WebSocketConnector.js +202 -0
- package/dist/src/connection/WebSocket/WebSocketConnector.js.map +1 -0
- package/dist/src/connection/WebSocket/WebSocketServer.d.ts +9 -0
- package/dist/src/connection/WebSocket/WebSocketServer.js +101 -0
- package/dist/src/connection/WebSocket/WebSocketServer.js.map +1 -0
- package/dist/src/dht/DhtNode.d.ts +153 -0
- package/dist/src/dht/DhtNode.js +599 -0
- package/dist/src/dht/DhtNode.js.map +1 -0
- package/dist/src/dht/DhtPeer.d.ts +18 -0
- package/dist/src/dht/DhtPeer.js +74 -0
- package/dist/src/dht/DhtPeer.js.map +1 -0
- package/dist/src/dht/ExternalApi.d.ts +8 -0
- package/dist/src/dht/ExternalApi.js +26 -0
- package/dist/src/dht/ExternalApi.js.map +1 -0
- package/dist/src/dht/RemoteExternalApi.d.ts +6 -0
- package/dist/src/dht/RemoteExternalApi.js +26 -0
- package/dist/src/dht/RemoteExternalApi.js.map +1 -0
- package/dist/src/dht/contact/Contact.d.ts +22 -0
- package/dist/src/dht/contact/Contact.js +25 -0
- package/dist/src/dht/contact/Contact.js.map +1 -0
- package/dist/src/dht/contact/RandomContactList.d.ts +20 -0
- package/dist/src/dht/contact/RandomContactList.js +78 -0
- package/dist/src/dht/contact/RandomContactList.js.map +1 -0
- package/dist/src/dht/contact/Remote.d.ts +15 -0
- package/dist/src/dht/contact/Remote.js +24 -0
- package/dist/src/dht/contact/Remote.js.map +1 -0
- package/dist/src/dht/contact/SortedContactList.d.ts +35 -0
- package/dist/src/dht/contact/SortedContactList.js +156 -0
- package/dist/src/dht/contact/SortedContactList.js.map +1 -0
- package/dist/src/dht/discovery/DiscoverySession.d.ts +36 -0
- package/dist/src/dht/discovery/DiscoverySession.js +116 -0
- package/dist/src/dht/discovery/DiscoverySession.js.map +1 -0
- package/dist/src/dht/discovery/PeerDiscovery.d.ts +42 -0
- package/dist/src/dht/discovery/PeerDiscovery.js +157 -0
- package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -0
- package/dist/src/dht/find/RecursiveFindSession.d.ts +46 -0
- package/dist/src/dht/find/RecursiveFindSession.js +142 -0
- package/dist/src/dht/find/RecursiveFindSession.js.map +1 -0
- package/dist/src/dht/find/RecursiveFinder.d.ts +54 -0
- package/dist/src/dht/find/RecursiveFinder.js +180 -0
- package/dist/src/dht/find/RecursiveFinder.js.map +1 -0
- package/dist/src/dht/find/RemoteRecursiveFindSession.d.ts +6 -0
- package/dist/src/dht/find/RemoteRecursiveFindSession.js +25 -0
- package/dist/src/dht/find/RemoteRecursiveFindSession.js.map +1 -0
- package/dist/src/dht/routing/DuplicateDetector.d.ts +13 -0
- package/dist/src/dht/routing/DuplicateDetector.js +41 -0
- package/dist/src/dht/routing/DuplicateDetector.js.map +1 -0
- package/dist/src/dht/routing/RemoteRouter.d.ts +8 -0
- package/dist/src/dht/routing/RemoteRouter.js +106 -0
- package/dist/src/dht/routing/RemoteRouter.js.map +1 -0
- package/dist/src/dht/routing/Router.d.ts +60 -0
- package/dist/src/dht/routing/Router.js +207 -0
- package/dist/src/dht/routing/Router.js.map +1 -0
- package/dist/src/dht/routing/RoutingSession.d.ts +42 -0
- package/dist/src/dht/routing/RoutingSession.js +178 -0
- package/dist/src/dht/routing/RoutingSession.js.map +1 -0
- package/dist/src/dht/store/DataStore.d.ts +45 -0
- package/dist/src/dht/store/DataStore.js +244 -0
- package/dist/src/dht/store/DataStore.js.map +1 -0
- package/dist/src/dht/store/LocalDataStore.d.ts +19 -0
- package/dist/src/dht/store/LocalDataStore.js +104 -0
- package/dist/src/dht/store/LocalDataStore.js.map +1 -0
- package/dist/src/dht/store/RemoteStore.d.ts +8 -0
- package/dist/src/dht/store/RemoteStore.js +44 -0
- package/dist/src/dht/store/RemoteStore.js.map +1 -0
- package/dist/src/exports.d.ts +19 -0
- package/dist/src/exports.js +41 -0
- package/dist/src/exports.js.map +1 -0
- package/dist/src/helpers/AddressTools.d.ts +2 -0
- package/dist/src/helpers/AddressTools.js +31 -0
- package/dist/src/helpers/AddressTools.js.map +1 -0
- package/dist/src/helpers/PeerID.d.ts +25 -0
- package/dist/src/helpers/PeerID.js +84 -0
- package/dist/src/helpers/PeerID.js.map +1 -0
- package/dist/src/helpers/UUID.d.ts +7 -0
- package/dist/src/helpers/UUID.js +32 -0
- package/dist/src/helpers/UUID.js.map +1 -0
- package/dist/src/helpers/debugHelpers.d.ts +3 -0
- package/dist/src/helpers/debugHelpers.js +11 -0
- package/dist/src/helpers/debugHelpers.js.map +1 -0
- package/dist/src/helpers/errors.d.ts +72 -0
- package/dist/src/helpers/errors.js +95 -0
- package/dist/src/helpers/errors.js.map +1 -0
- package/dist/src/helpers/peerIdFromPeerDescriptor.d.ts +5 -0
- package/dist/src/helpers/peerIdFromPeerDescriptor.js +17 -0
- package/dist/src/helpers/peerIdFromPeerDescriptor.js.map +1 -0
- package/dist/src/helpers/protoClasses.d.ts +2 -0
- package/dist/src/helpers/protoClasses.js +35 -0
- package/dist/src/helpers/protoClasses.js.map +1 -0
- package/dist/src/helpers/protoToString.d.ts +2 -0
- package/dist/src/helpers/protoToString.js +20 -0
- package/dist/src/helpers/protoToString.js.map +1 -0
- package/dist/src/proto/google/protobuf/any.d.ts +173 -0
- package/dist/src/proto/google/protobuf/any.js +155 -0
- package/dist/src/proto/google/protobuf/any.js.map +1 -0
- package/dist/src/proto/google/protobuf/empty.d.ts +32 -0
- package/dist/src/proto/google/protobuf/empty.js +34 -0
- package/dist/src/proto/google/protobuf/empty.js.map +1 -0
- package/dist/src/proto/google/protobuf/timestamp.d.ts +149 -0
- package/dist/src/proto/google/protobuf/timestamp.js +136 -0
- package/dist/src/proto/google/protobuf/timestamp.js.map +1 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +320 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +245 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +1089 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +710 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +145 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.js +3 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.js.map +1 -0
- package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.d.ts +87 -0
- package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.js +66 -0
- package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.js.map +1 -0
- package/dist/src/proto/tests.d.ts +39 -0
- package/dist/src/proto/tests.js +34 -0
- package/dist/src/proto/tests.js.map +1 -0
- package/dist/src/rpc-protocol/DhtCallContext.d.ts +12 -0
- package/dist/src/rpc-protocol/DhtCallContext.js +8 -0
- package/dist/src/rpc-protocol/DhtCallContext.js.map +1 -0
- package/dist/src/rpc-protocol/DhtRpcOptions.d.ts +8 -0
- package/dist/src/rpc-protocol/DhtRpcOptions.js +3 -0
- package/dist/src/rpc-protocol/DhtRpcOptions.js.map +1 -0
- package/dist/src/transport/ITransport.d.ts +22 -0
- package/dist/src/transport/ITransport.js +3 -0
- package/dist/src/transport/ITransport.js.map +1 -0
- package/dist/src/transport/ListeningRpcCommunicator.d.ts +6 -0
- package/dist/src/transport/ListeningRpcCommunicator.js +14 -0
- package/dist/src/transport/ListeningRpcCommunicator.js.map +1 -0
- package/dist/src/transport/RoutingRpcCommunicator.d.ts +8 -0
- package/dist/src/transport/RoutingRpcCommunicator.js +52 -0
- package/dist/src/transport/RoutingRpcCommunicator.js.map +1 -0
- package/jest.config.js +2 -0
- package/karma.config.js +20 -0
- package/package.json +64 -0
- package/proto.sh +3 -0
- package/protos/DhtRpc.proto +330 -0
- package/protos/tests.proto +16 -0
- package/src/connection/Connection.ts +23 -0
- package/src/connection/ConnectionLockHandler.ts +105 -0
- package/src/connection/ConnectionManager.ts +676 -0
- package/src/connection/ConnectivityChecker.ts +173 -0
- package/src/connection/Handshaker.ts +92 -0
- package/src/connection/IConnection.ts +47 -0
- package/src/connection/IConnectionSource.ts +6 -0
- package/src/connection/ManagedConnection.ts +398 -0
- package/src/connection/ManagedWebRtcConnection.ts +27 -0
- package/src/connection/RemoteConnectionLocker.ts +88 -0
- package/src/connection/Simulator/Simulator.ts +399 -0
- package/src/connection/Simulator/SimulatorConnection.ts +137 -0
- package/src/connection/Simulator/SimulatorConnector.ts +104 -0
- package/src/connection/Simulator/SimulatorTransport.ts +9 -0
- package/src/connection/Simulator/pings.ts +42 -0
- package/src/connection/WebRTC/BrowserWebRtcConnection.ts +227 -0
- package/src/connection/WebRTC/IWebRtcConnection.ts +24 -0
- package/src/connection/WebRTC/NodeWebRtcConnection.ts +256 -0
- package/src/connection/WebRTC/RemoteWebrtcConnector.ts +93 -0
- package/src/connection/WebRTC/WebRtcConnector.ts +306 -0
- package/src/connection/WebRTC/iceServerAsString.ts +15 -0
- package/src/connection/WebSocket/ClientWebSocket.ts +118 -0
- package/src/connection/WebSocket/RemoteWebSocketConnector.ts +49 -0
- package/src/connection/WebSocket/ServerWebSocket.ts +119 -0
- package/src/connection/WebSocket/WebSocketConnector.ts +264 -0
- package/src/connection/WebSocket/WebSocketServer.ts +97 -0
- package/src/dht/DhtNode.ts +776 -0
- package/src/dht/DhtPeer.ts +96 -0
- package/src/dht/ExternalApi.ts +29 -0
- package/src/dht/RemoteExternalApi.ts +25 -0
- package/src/dht/contact/Contact.ts +36 -0
- package/src/dht/contact/RandomContactList.ts +92 -0
- package/src/dht/contact/Remote.ts +40 -0
- package/src/dht/contact/SortedContactList.ts +196 -0
- package/src/dht/discovery/DiscoverySession.ts +150 -0
- package/src/dht/discovery/PeerDiscovery.ts +162 -0
- package/src/dht/find/RecursiveFindSession.ts +178 -0
- package/src/dht/find/RecursiveFinder.ts +272 -0
- package/src/dht/find/RemoteRecursiveFindSession.ts +33 -0
- package/src/dht/routing/DuplicateDetector.ts +53 -0
- package/src/dht/routing/RemoteRouter.ts +115 -0
- package/src/dht/routing/Router.ts +266 -0
- package/src/dht/routing/RoutingSession.ts +222 -0
- package/src/dht/store/DataStore.ts +321 -0
- package/src/dht/store/LocalDataStore.ts +114 -0
- package/src/dht/store/RemoteStore.ts +58 -0
- package/src/exports.ts +19 -0
- package/src/helpers/AddressTools.ts +26 -0
- package/src/helpers/PeerID.ts +95 -0
- package/src/helpers/UUID.ts +30 -0
- package/src/helpers/debugHelpers.ts +9 -0
- package/src/helpers/errors.ts +49 -0
- package/src/helpers/peerIdFromPeerDescriptor.ts +14 -0
- package/src/helpers/protoClasses.ts +63 -0
- package/src/helpers/protoToString.ts +21 -0
- package/src/proto/google/protobuf/any.ts +319 -0
- package/src/proto/google/protobuf/empty.ts +84 -0
- package/src/proto/google/protobuf/timestamp.ts +281 -0
- package/src/proto/packages/dht/protos/DhtRpc.client.ts +373 -0
- package/src/proto/packages/dht/protos/DhtRpc.server.ts +148 -0
- package/src/proto/packages/dht/protos/DhtRpc.ts +1399 -0
- package/src/proto/packages/proto-rpc/protos/ProtoRpc.ts +108 -0
- package/src/proto/tests.ts +52 -0
- package/src/rpc-protocol/DhtCallContext.ts +15 -0
- package/src/rpc-protocol/DhtRpcOptions.ts +9 -0
- package/src/transport/ITransport.ts +31 -0
- package/src/transport/ListeningRpcCommunicator.ts +14 -0
- package/src/transport/RoutingRpcCommunicator.ts +59 -0
- package/src/types/glogal.d.ts +1 -0
- package/src/types/textencoding.d.ts +7 -0
- package/test/RandomGraphSimulation.ts +52 -0
- package/test/benchmark/KademliaCorrectness.test.ts +115 -0
- package/test/benchmark/RecursiveFind.test.ts +87 -0
- package/test/benchmark/any.test.ts +28 -0
- package/test/benchmark/kademlia-simulation/Contact.ts +32 -0
- package/test/benchmark/kademlia-simulation/KademliaSimulation.ts +94 -0
- package/test/benchmark/kademlia-simulation/SimulationNode.ts +125 -0
- package/test/data/generateGroundTruthData.ts +70 -0
- package/test/end-to-end/Layer0-Layer1.test.ts +87 -0
- package/test/end-to-end/Layer0.test.ts +60 -0
- package/test/end-to-end/Layer0MixedConnectionTypes.test.ts +94 -0
- package/test/end-to-end/Layer0WebRTC-Layer1.test.ts +134 -0
- package/test/end-to-end/Layer0WebRTC.test.ts +98 -0
- package/test/end-to-end/Layer1-Scale-WebRTC.test.ts +69 -0
- package/test/end-to-end/Layer1-Scale-WebSocket.test.ts +73 -0
- package/test/end-to-end/WebSocketConnectionRequest.test.ts +62 -0
- package/test/integration/ConnectionLocking.test.ts +166 -0
- package/test/integration/ConnectionManager.test.ts +291 -0
- package/test/integration/DhtNodeExternalAPI.test.ts +43 -0
- package/test/integration/DhtPeer.test.ts +73 -0
- package/test/integration/DhtRpc.test.ts +131 -0
- package/test/integration/DhtWithMockConnectionLatencies.test.ts +46 -0
- package/test/integration/DhtWithMockConnections.test.ts +46 -0
- package/test/integration/DhtWithRealConnectionLatencies.test.ts +47 -0
- package/test/integration/Layer1-scale.test.ts +200 -0
- package/test/integration/MigrateData.test.ts +203 -0
- package/test/integration/Mock-Layer1-Layer0.test.ts +106 -0
- package/test/integration/MultipleEntryPointJoining.test.ts +105 -0
- package/test/integration/RecursiveFind.test.ts +50 -0
- package/test/integration/RemoteRouter.test.ts +83 -0
- package/test/integration/RemoteStore.test.ts +66 -0
- package/test/integration/RouteMessage.test.ts +254 -0
- package/test/integration/RpcErrors.test.ts +153 -0
- package/test/integration/ScaleDownDht.test.ts +66 -0
- package/test/integration/SimultaneousConnections.test.ts +308 -0
- package/test/integration/Store.test.ts +72 -0
- package/test/integration/StoreAndDelete.test.ts +93 -0
- package/test/integration/StoreOnDhtWithTwoNodes.test.ts +71 -0
- package/test/integration/WebRtcConnectionManagement.test.ts +205 -0
- package/test/integration/WebRtcConnectorRpc.test.ts +145 -0
- package/test/integration/WebSocket.test.ts +64 -0
- package/test/integration/WebSocketConnectionManagement.test.ts +131 -0
- package/test/integration/WebSocketConnectorRpc.test.ts +86 -0
- package/test/kademlia-simulation/data/nodeids.json +13002 -0
- package/test/kademlia-simulation/data/orderedneighbors.json +1001 -0
- package/test/unit/AddressTools.test.ts +40 -0
- package/test/unit/DuplicateDetector.test.ts +29 -0
- package/test/unit/LocalDataStore.test.ts +107 -0
- package/test/unit/PeerID.test.ts +22 -0
- package/test/unit/ProtobufMessage.test.ts +21 -0
- package/test/unit/RandomContactList.test.ts +87 -0
- package/test/unit/RecursiveFinder.test.ts +112 -0
- package/test/unit/Router.test.ts +124 -0
- package/test/unit/SortedContactList.test.ts +127 -0
- package/test/unit/UUID.test.ts +49 -0
- package/test/unit/WebSocketServer.test.ts +42 -0
- package/test/utils/mock/RecursiveFinder.ts +19 -0
- package/test/utils/mock/Router.ts +53 -0
- package/test/utils/mock/Transport.ts +26 -0
- package/test/utils/utils.ts +311 -0
- package/tsconfig.browser.json +15 -0
- package/tsconfig.jest.json +19 -0
- package/tsconfig.json +3 -0
- package/tsconfig.node.json +18 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { RpcCommunicator, toProtoRpcClient } from '@streamr/proto-rpc'
|
|
2
|
+
import { RemoteRouter } from '../../src/dht/routing/RemoteRouter'
|
|
3
|
+
import { Message, MessageType, PeerDescriptor, RouteMessageAck, RouteMessageWrapper } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
4
|
+
import { RoutingServiceClient } from '../../src/proto/packages/dht/protos/DhtRpc.client'
|
|
5
|
+
import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
|
|
6
|
+
import { DhtCallContext } from '../../src/rpc-protocol/DhtCallContext'
|
|
7
|
+
import { createWrappedClosestPeersRequest, generateId, MockRoutingService } from '../utils/utils'
|
|
8
|
+
|
|
9
|
+
describe('RemoteRouter', () => {
|
|
10
|
+
|
|
11
|
+
let remoteRouter: RemoteRouter
|
|
12
|
+
let clientRpcCommunicator: RpcCommunicator
|
|
13
|
+
let serverRpcCommunicator: RpcCommunicator
|
|
14
|
+
const serviceId = 'test'
|
|
15
|
+
const clientPeerDescriptor: PeerDescriptor = {
|
|
16
|
+
kademliaId: generateId('dhtPeer'),
|
|
17
|
+
type: 0
|
|
18
|
+
}
|
|
19
|
+
const serverPeerDescriptor: PeerDescriptor = {
|
|
20
|
+
kademliaId: generateId('server'),
|
|
21
|
+
type: 0
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
beforeEach(() => {
|
|
25
|
+
clientRpcCommunicator = new RpcCommunicator()
|
|
26
|
+
serverRpcCommunicator = new RpcCommunicator()
|
|
27
|
+
serverRpcCommunicator.registerRpcMethod(RouteMessageWrapper, RouteMessageAck, 'routeMessage', MockRoutingService.routeMessage)
|
|
28
|
+
clientRpcCommunicator.on('outgoingMessage', (message: RpcMessage, _requestId: string, _ucallContext?: DhtCallContext) => {
|
|
29
|
+
serverRpcCommunicator.handleIncomingMessage(message)
|
|
30
|
+
})
|
|
31
|
+
serverRpcCommunicator.on('outgoingMessage', (message: RpcMessage, _requestId: string, _ucallContext?: DhtCallContext) => {
|
|
32
|
+
clientRpcCommunicator.handleIncomingMessage(message)
|
|
33
|
+
})
|
|
34
|
+
const client = toProtoRpcClient(new RoutingServiceClient(clientRpcCommunicator.getRpcClientTransport()))
|
|
35
|
+
remoteRouter = new RemoteRouter(clientPeerDescriptor, serverPeerDescriptor, client, serviceId)
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
it('routeMessage happy path', async () => {
|
|
39
|
+
const rpcWrapper = createWrappedClosestPeersRequest(clientPeerDescriptor, serverPeerDescriptor)
|
|
40
|
+
const routed: Message = {
|
|
41
|
+
serviceId: serviceId,
|
|
42
|
+
messageId: 'routed',
|
|
43
|
+
messageType: MessageType.RPC,
|
|
44
|
+
body: {
|
|
45
|
+
oneofKind: 'rpcMessage',
|
|
46
|
+
rpcMessage: rpcWrapper
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const routable = await remoteRouter.routeMessage({
|
|
50
|
+
requestId: 'routed',
|
|
51
|
+
message: routed,
|
|
52
|
+
sourcePeer: clientPeerDescriptor,
|
|
53
|
+
destinationPeer: serverPeerDescriptor,
|
|
54
|
+
reachableThrough: [],
|
|
55
|
+
routingPath: []
|
|
56
|
+
})
|
|
57
|
+
expect(routable).toEqual(true)
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
it('routeMessage error path', async () => {
|
|
61
|
+
serverRpcCommunicator.registerRpcMethod(RouteMessageWrapper, RouteMessageAck, 'routeMessage', MockRoutingService.throwRouteMessageError)
|
|
62
|
+
const rpcWrapper = createWrappedClosestPeersRequest(clientPeerDescriptor, serverPeerDescriptor)
|
|
63
|
+
const routed: Message = {
|
|
64
|
+
serviceId: serviceId,
|
|
65
|
+
messageId: 'routed',
|
|
66
|
+
messageType: MessageType.RPC,
|
|
67
|
+
body: {
|
|
68
|
+
oneofKind: 'rpcMessage',
|
|
69
|
+
rpcMessage: rpcWrapper
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const routable = await remoteRouter.routeMessage({
|
|
73
|
+
requestId: 'routed',
|
|
74
|
+
message: routed,
|
|
75
|
+
sourcePeer: clientPeerDescriptor,
|
|
76
|
+
destinationPeer: serverPeerDescriptor,
|
|
77
|
+
reachableThrough: [],
|
|
78
|
+
routingPath: []
|
|
79
|
+
})
|
|
80
|
+
expect(routable).toEqual(false)
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
})
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { RpcCommunicator, toProtoRpcClient } from '@streamr/proto-rpc'
|
|
2
|
+
import {
|
|
3
|
+
PeerDescriptor,
|
|
4
|
+
StoreDataRequest,
|
|
5
|
+
StoreDataResponse
|
|
6
|
+
} from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
7
|
+
import { generateId, MockStoreService } from '../utils/utils'
|
|
8
|
+
import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
|
|
9
|
+
import { DhtCallContext } from '../../src/rpc-protocol/DhtCallContext'
|
|
10
|
+
import { StoreServiceClient } from '../../src/proto/packages/dht/protos/DhtRpc.client'
|
|
11
|
+
import { RemoteStore } from '../../src/dht/store/RemoteStore'
|
|
12
|
+
import { Any } from '../../src/proto/google/protobuf/any'
|
|
13
|
+
|
|
14
|
+
describe('RemoteStore', () => {
|
|
15
|
+
|
|
16
|
+
let remoteStore: RemoteStore
|
|
17
|
+
let clientRpcCommunicator: RpcCommunicator
|
|
18
|
+
let serverRpcCommunicator: RpcCommunicator
|
|
19
|
+
const serviceId = 'test'
|
|
20
|
+
const clientPeerDescriptor: PeerDescriptor = {
|
|
21
|
+
kademliaId: generateId('dhtPeer'),
|
|
22
|
+
type: 0
|
|
23
|
+
}
|
|
24
|
+
const serverPeerDescriptor: PeerDescriptor = {
|
|
25
|
+
kademliaId: generateId('server'),
|
|
26
|
+
type: 0
|
|
27
|
+
}
|
|
28
|
+
const data = Any.pack(clientPeerDescriptor, PeerDescriptor)
|
|
29
|
+
const request: StoreDataRequest = {
|
|
30
|
+
kademliaId: clientPeerDescriptor.kademliaId,
|
|
31
|
+
data,
|
|
32
|
+
ttl: 10
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
beforeEach(() => {
|
|
36
|
+
clientRpcCommunicator = new RpcCommunicator()
|
|
37
|
+
serverRpcCommunicator = new RpcCommunicator()
|
|
38
|
+
serverRpcCommunicator.registerRpcMethod(StoreDataRequest, StoreDataResponse, 'storeData', MockStoreService.storeData)
|
|
39
|
+
clientRpcCommunicator.on('outgoingMessage', (message: RpcMessage, _requestId: string, _ucallContext?: DhtCallContext) => {
|
|
40
|
+
serverRpcCommunicator.handleIncomingMessage(message)
|
|
41
|
+
})
|
|
42
|
+
serverRpcCommunicator.on('outgoingMessage', (message: RpcMessage, _requestId: string, _ucallContext?: DhtCallContext) => {
|
|
43
|
+
clientRpcCommunicator.handleIncomingMessage(message)
|
|
44
|
+
})
|
|
45
|
+
const client = toProtoRpcClient(new StoreServiceClient(clientRpcCommunicator.getRpcClientTransport()))
|
|
46
|
+
remoteStore = new RemoteStore(clientPeerDescriptor, serverPeerDescriptor, client, serviceId)
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
it('storeData happy path', async () => {
|
|
50
|
+
const response = await remoteStore.storeData(request)
|
|
51
|
+
expect(response.error).toBeEmpty()
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it('storeData rejects', async () => {
|
|
55
|
+
serverRpcCommunicator.registerRpcMethod(StoreDataRequest, StoreDataResponse, 'storeData', MockStoreService.throwStoreDataError)
|
|
56
|
+
await expect(remoteStore.storeData(request))
|
|
57
|
+
.rejects.toThrowError('Could not store data to 736572766572 from 64687450656572 Error: Mock')
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
it('storeData response error', async () => {
|
|
61
|
+
serverRpcCommunicator.registerRpcMethod(StoreDataRequest, StoreDataResponse, 'storeData', MockStoreService.storeDataErrorString)
|
|
62
|
+
const response = await remoteStore.storeData(request)
|
|
63
|
+
expect(response.error).toEqual('Mock')
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
})
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { DhtNode, Events as DhtNodeEvents } from '../../src/dht/DhtNode'
|
|
2
|
+
import { Message, MessageType, PeerDescriptor, RouteMessageWrapper } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
3
|
+
import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
|
|
4
|
+
import { Logger, runAndWaitForEvents3, waitForCondition } from '@streamr/utils'
|
|
5
|
+
import { createMockConnectionDhtNode, createWrappedClosestPeersRequest } from '../utils/utils'
|
|
6
|
+
import { PeerID } from '../../src/helpers/PeerID'
|
|
7
|
+
import { Simulator } from '../../src/connection/Simulator/Simulator'
|
|
8
|
+
import { v4 } from 'uuid'
|
|
9
|
+
import { UUID } from '../../src/helpers/UUID'
|
|
10
|
+
import { Any } from '../../src/proto/google/protobuf/any'
|
|
11
|
+
import { RoutingMode } from '../../src/dht/routing/RoutingSession'
|
|
12
|
+
|
|
13
|
+
const logger = new Logger(module)
|
|
14
|
+
|
|
15
|
+
describe('Route Message With Mock Connections', () => {
|
|
16
|
+
let entryPoint: DhtNode
|
|
17
|
+
let sourceNode: DhtNode
|
|
18
|
+
let destinationNode: DhtNode
|
|
19
|
+
let routerNodes: DhtNode[]
|
|
20
|
+
let simulator: Simulator
|
|
21
|
+
let entryPointDescriptor: PeerDescriptor
|
|
22
|
+
|
|
23
|
+
const entryPointId = '0'
|
|
24
|
+
const sourceId = 'eeeeeeeee'
|
|
25
|
+
const destinationId = '000000000'
|
|
26
|
+
const NUM_NODES = 30
|
|
27
|
+
|
|
28
|
+
const receiveMatrix: Array<Array<number>> = []
|
|
29
|
+
|
|
30
|
+
beforeEach(async () => {
|
|
31
|
+
routerNodes = []
|
|
32
|
+
simulator = new Simulator()
|
|
33
|
+
entryPoint = await createMockConnectionDhtNode(entryPointId, simulator)
|
|
34
|
+
|
|
35
|
+
entryPointDescriptor = {
|
|
36
|
+
kademliaId: entryPoint.getNodeId().value,
|
|
37
|
+
nodeName: 'entrypoint',
|
|
38
|
+
type: 0
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
sourceNode = await createMockConnectionDhtNode(sourceId, simulator)
|
|
42
|
+
destinationNode = await createMockConnectionDhtNode(destinationId, simulator)
|
|
43
|
+
|
|
44
|
+
for (let i = 1; i < NUM_NODES; i++) {
|
|
45
|
+
const nodeId = `${i}`
|
|
46
|
+
const node = await createMockConnectionDhtNode(nodeId, simulator)
|
|
47
|
+
routerNodes.push(node)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
await destinationNode.joinDht([entryPointDescriptor])
|
|
51
|
+
await sourceNode.joinDht([entryPointDescriptor])
|
|
52
|
+
await Promise.all(routerNodes.map((node) => node.joinDht([entryPointDescriptor])))
|
|
53
|
+
await entryPoint.joinDht([entryPointDescriptor])
|
|
54
|
+
}, 15000)
|
|
55
|
+
|
|
56
|
+
afterEach(async () => {
|
|
57
|
+
await Promise.allSettled(routerNodes.map((node) => node.stop()))
|
|
58
|
+
await Promise.allSettled([
|
|
59
|
+
entryPoint.stop(),
|
|
60
|
+
destinationNode.stop(),
|
|
61
|
+
sourceNode.stop()
|
|
62
|
+
])
|
|
63
|
+
|
|
64
|
+
logger.info('calling simulator stop')
|
|
65
|
+
simulator.stop()
|
|
66
|
+
logger.info('simulator stop called')
|
|
67
|
+
}, 10000)
|
|
68
|
+
|
|
69
|
+
it('Happy path', async () => {
|
|
70
|
+
const rpcWrapper = createWrappedClosestPeersRequest(sourceNode.getPeerDescriptor(), destinationNode.getPeerDescriptor())
|
|
71
|
+
const message: Message = {
|
|
72
|
+
serviceId: 'unknown',
|
|
73
|
+
messageId: v4(),
|
|
74
|
+
messageType: MessageType.RPC,
|
|
75
|
+
body: {
|
|
76
|
+
oneofKind: 'rpcMessage',
|
|
77
|
+
rpcMessage: rpcWrapper
|
|
78
|
+
},
|
|
79
|
+
sourceDescriptor: sourceNode.getPeerDescriptor(),
|
|
80
|
+
targetDescriptor: destinationNode.getPeerDescriptor()
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
await runAndWaitForEvents3<DhtNodeEvents>([() => {
|
|
84
|
+
sourceNode.router!.doRouteMessage({
|
|
85
|
+
message: message,
|
|
86
|
+
destinationPeer: destinationNode.getPeerDescriptor(),
|
|
87
|
+
requestId: v4(),
|
|
88
|
+
sourcePeer: sourceNode.getPeerDescriptor(),
|
|
89
|
+
reachableThrough: [],
|
|
90
|
+
routingPath: []
|
|
91
|
+
|
|
92
|
+
})
|
|
93
|
+
}], [[destinationNode, 'message']], 20000)
|
|
94
|
+
}, 30000)
|
|
95
|
+
|
|
96
|
+
it('Receives multiple messages', async () => {
|
|
97
|
+
const numOfMessages = 20
|
|
98
|
+
let receivedMessages = 0
|
|
99
|
+
destinationNode.on('message', (_message: Message) => {
|
|
100
|
+
receivedMessages += 1
|
|
101
|
+
})
|
|
102
|
+
const rpcWrapper = createWrappedClosestPeersRequest(sourceNode.getPeerDescriptor(), destinationNode.getPeerDescriptor())
|
|
103
|
+
|
|
104
|
+
for (let i = 0; i < numOfMessages; i++) {
|
|
105
|
+
const message: Message = {
|
|
106
|
+
serviceId: 'unknown',
|
|
107
|
+
messageId: v4(),
|
|
108
|
+
messageType: MessageType.RPC,
|
|
109
|
+
body: {
|
|
110
|
+
oneofKind: 'rpcMessage',
|
|
111
|
+
rpcMessage: rpcWrapper
|
|
112
|
+
},
|
|
113
|
+
sourceDescriptor: sourceNode.getPeerDescriptor(),
|
|
114
|
+
targetDescriptor: destinationNode.getPeerDescriptor()
|
|
115
|
+
}
|
|
116
|
+
await sourceNode.router!.doRouteMessage({
|
|
117
|
+
message: message,
|
|
118
|
+
destinationPeer: destinationNode.getPeerDescriptor(),
|
|
119
|
+
requestId: v4(),
|
|
120
|
+
sourcePeer: sourceNode.getPeerDescriptor(),
|
|
121
|
+
reachableThrough: [],
|
|
122
|
+
routingPath: []
|
|
123
|
+
})
|
|
124
|
+
}
|
|
125
|
+
await waitForCondition(() => receivedMessages === numOfMessages)
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
it('From all to all', async () => {
|
|
129
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
130
|
+
for (const i in routerNodes) {
|
|
131
|
+
const arr: Array<number> = []
|
|
132
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
133
|
+
for (const j in routerNodes) {
|
|
134
|
+
arr.push(0)
|
|
135
|
+
}
|
|
136
|
+
receiveMatrix.push(arr)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const numsOfReceivedMessages: Record<string, number> = {}
|
|
140
|
+
routerNodes.map((node) => {
|
|
141
|
+
numsOfReceivedMessages[node.getNodeId().toKey()] = 0
|
|
142
|
+
node.on('message', (msg: Message) => {
|
|
143
|
+
numsOfReceivedMessages[node.getNodeId().toKey()] = numsOfReceivedMessages[node.getNodeId().toKey()] + 1
|
|
144
|
+
try {
|
|
145
|
+
const target = receiveMatrix[parseInt(node.getNodeId().toString()) - 1]
|
|
146
|
+
target[parseInt(PeerID.fromValue(msg.sourceDescriptor!.kademliaId!).toString()) - 1]++
|
|
147
|
+
} catch (e) {
|
|
148
|
+
console.error(e)
|
|
149
|
+
}
|
|
150
|
+
if (parseInt(node.getNodeId().toString()) > routerNodes.length || parseInt(node.getNodeId().toString()) < 1) {
|
|
151
|
+
console.error(node.getNodeId().toString())
|
|
152
|
+
}
|
|
153
|
+
})
|
|
154
|
+
}
|
|
155
|
+
)
|
|
156
|
+
await Promise.all(
|
|
157
|
+
routerNodes.map(async (node) =>
|
|
158
|
+
Promise.all(routerNodes.map(async (receiver) => {
|
|
159
|
+
if (!node.getNodeId().equals(receiver.getNodeId())) {
|
|
160
|
+
const rpcWrapper = createWrappedClosestPeersRequest(sourceNode.getPeerDescriptor(), destinationNode.getPeerDescriptor())
|
|
161
|
+
const message: Message = {
|
|
162
|
+
serviceId: 'nonexisting_service',
|
|
163
|
+
messageId: v4(),
|
|
164
|
+
messageType: MessageType.RPC,
|
|
165
|
+
body: {
|
|
166
|
+
oneofKind: 'rpcMessage',
|
|
167
|
+
rpcMessage: rpcWrapper
|
|
168
|
+
},
|
|
169
|
+
sourceDescriptor: node.getPeerDescriptor(),
|
|
170
|
+
targetDescriptor: destinationNode.getPeerDescriptor()
|
|
171
|
+
}
|
|
172
|
+
await node.router!.doRouteMessage({
|
|
173
|
+
message: message,
|
|
174
|
+
destinationPeer: receiver.getPeerDescriptor(),
|
|
175
|
+
sourcePeer: node.getPeerDescriptor(),
|
|
176
|
+
requestId: v4(),
|
|
177
|
+
reachableThrough: [],
|
|
178
|
+
routingPath: []
|
|
179
|
+
})
|
|
180
|
+
}
|
|
181
|
+
}))
|
|
182
|
+
)
|
|
183
|
+
)
|
|
184
|
+
await waitForCondition(() => numsOfReceivedMessages[PeerID.fromString('1').toKey()] >= routerNodes.length - 1
|
|
185
|
+
, 30000)
|
|
186
|
+
await Promise.all(
|
|
187
|
+
Object.keys(numsOfReceivedMessages).map(async (key) =>
|
|
188
|
+
waitForCondition(() => numsOfReceivedMessages[key] >= routerNodes.length - 1, 30000)
|
|
189
|
+
)
|
|
190
|
+
)
|
|
191
|
+
|
|
192
|
+
}, 90000)
|
|
193
|
+
|
|
194
|
+
it('Destination receives forwarded message', async () => {
|
|
195
|
+
const closestPeersRequest = createWrappedClosestPeersRequest(sourceNode.getPeerDescriptor(), destinationNode.getPeerDescriptor())
|
|
196
|
+
const closestPeersRequestMessage: Message = {
|
|
197
|
+
serviceId: 'unknown',
|
|
198
|
+
messageId: v4(),
|
|
199
|
+
messageType: MessageType.RPC,
|
|
200
|
+
body: {
|
|
201
|
+
oneofKind: 'rpcMessage',
|
|
202
|
+
rpcMessage: closestPeersRequest
|
|
203
|
+
},
|
|
204
|
+
sourceDescriptor: sourceNode.getPeerDescriptor()!,
|
|
205
|
+
targetDescriptor: destinationNode.getPeerDescriptor()!
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const routeMessageWrapper: RouteMessageWrapper = {
|
|
209
|
+
message: closestPeersRequestMessage,
|
|
210
|
+
destinationPeer: destinationNode.getPeerDescriptor(),
|
|
211
|
+
requestId: new UUID().toString(),
|
|
212
|
+
sourcePeer: sourceNode.getPeerDescriptor(),
|
|
213
|
+
reachableThrough: [entryPointDescriptor],
|
|
214
|
+
routingPath: []
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const rpcMessage: RpcMessage = {
|
|
218
|
+
body: Any.pack(routeMessageWrapper, RouteMessageWrapper),
|
|
219
|
+
header: {
|
|
220
|
+
method: 'routeMessage',
|
|
221
|
+
request: 'request'
|
|
222
|
+
},
|
|
223
|
+
requestId: v4()
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const requestMessage: Message = {
|
|
227
|
+
serviceId: 'layer0',
|
|
228
|
+
messageId: v4(),
|
|
229
|
+
messageType: MessageType.RPC,
|
|
230
|
+
body: {
|
|
231
|
+
oneofKind: 'rpcMessage',
|
|
232
|
+
rpcMessage: rpcMessage
|
|
233
|
+
},
|
|
234
|
+
sourceDescriptor: sourceNode.getPeerDescriptor()!,
|
|
235
|
+
targetDescriptor: entryPoint.getPeerDescriptor()!
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const forwardedMessage: RouteMessageWrapper = {
|
|
239
|
+
message: requestMessage,
|
|
240
|
+
requestId: v4(),
|
|
241
|
+
sourcePeer: sourceNode.getPeerDescriptor(),
|
|
242
|
+
destinationPeer: entryPoint.getPeerDescriptor()!,
|
|
243
|
+
reachableThrough: [],
|
|
244
|
+
routingPath: []
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
await runAndWaitForEvents3<DhtNodeEvents>([() => {
|
|
248
|
+
sourceNode.router!.doRouteMessage(forwardedMessage, RoutingMode.FORWARD)
|
|
249
|
+
}], [[destinationNode, 'message']])
|
|
250
|
+
|
|
251
|
+
})
|
|
252
|
+
|
|
253
|
+
})
|
|
254
|
+
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { ConnectionManager } from '../../src/connection/ConnectionManager'
|
|
2
|
+
import { LatencyType, Simulator } from '../../src/connection/Simulator/Simulator'
|
|
3
|
+
import { PeerID } from '../../src/helpers/PeerID'
|
|
4
|
+
import { ITransport } from '../../src/transport/ITransport'
|
|
5
|
+
import { v4 } from 'uuid'
|
|
6
|
+
import { DhtRpcOptions, ListeningRpcCommunicator, SimulatorTransport } from '../../src/exports'
|
|
7
|
+
import { ProtoRpcClient, toProtoRpcClient } from '@streamr/proto-rpc'
|
|
8
|
+
import { DhtRpcServiceClient } from '../../src/proto/packages/dht/protos/DhtRpc.client'
|
|
9
|
+
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
10
|
+
import { NodeType, PeerDescriptor, PingRequest, PingResponse } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
11
|
+
|
|
12
|
+
describe('RPC errors', () => {
|
|
13
|
+
|
|
14
|
+
let manager1: ConnectionManager
|
|
15
|
+
let manager2: ConnectionManager
|
|
16
|
+
|
|
17
|
+
let rpcCommunicator1: ListeningRpcCommunicator
|
|
18
|
+
let rpcCommunicator2: ListeningRpcCommunicator
|
|
19
|
+
|
|
20
|
+
let client1: ProtoRpcClient<DhtRpcServiceClient>
|
|
21
|
+
//let client2: ProtoRpcClient<DhtRpcServiceClient>
|
|
22
|
+
|
|
23
|
+
let simulator: Simulator
|
|
24
|
+
|
|
25
|
+
const peerDescriptor1: PeerDescriptor = {
|
|
26
|
+
kademliaId: PeerID.fromString('peer1').value,
|
|
27
|
+
type: NodeType.NODEJS,
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const peerDescriptor2: PeerDescriptor = {
|
|
31
|
+
kademliaId: PeerID.fromString('peer2').value,
|
|
32
|
+
type: NodeType.NODEJS,
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
let connectorTransport1: ITransport
|
|
36
|
+
let connectorTransport2: ITransport
|
|
37
|
+
|
|
38
|
+
const serviceId = 'test'
|
|
39
|
+
|
|
40
|
+
beforeEach(async () => {
|
|
41
|
+
|
|
42
|
+
simulator = new Simulator(LatencyType.FIXED, 50)
|
|
43
|
+
connectorTransport1 = new SimulatorTransport(peerDescriptor1, simulator)
|
|
44
|
+
manager1 = new ConnectionManager({ transportLayer: connectorTransport1 })
|
|
45
|
+
rpcCommunicator1 = new ListeningRpcCommunicator(serviceId, manager1)
|
|
46
|
+
client1 = toProtoRpcClient(new DhtRpcServiceClient(rpcCommunicator1.getRpcClientTransport()))
|
|
47
|
+
|
|
48
|
+
connectorTransport2 = new SimulatorTransport(peerDescriptor2, simulator)
|
|
49
|
+
manager2 = new ConnectionManager({ transportLayer: connectorTransport2 })
|
|
50
|
+
rpcCommunicator2 = new ListeningRpcCommunicator(serviceId, manager2)
|
|
51
|
+
//client2 = toProtoRpcClient(new DhtRpcServiceClient(rpcCommunicator2.getRpcClientTransport()))
|
|
52
|
+
|
|
53
|
+
await manager1.start((_msg) => peerDescriptor1)
|
|
54
|
+
await manager2.start((_msg) => peerDescriptor2)
|
|
55
|
+
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
afterEach(async () => {
|
|
59
|
+
await connectorTransport1.stop()
|
|
60
|
+
await connectorTransport2.stop()
|
|
61
|
+
await manager1.stop()
|
|
62
|
+
await manager2.stop()
|
|
63
|
+
simulator.stop()
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
it('Can make a RPC call over WebRTC', async () => {
|
|
67
|
+
const ping = async (request: PingRequest, _context: ServerCallContext):
|
|
68
|
+
Promise<PingResponse> => {
|
|
69
|
+
const response: PingResponse = {
|
|
70
|
+
requestId: request.requestId
|
|
71
|
+
}
|
|
72
|
+
return response
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
rpcCommunicator2.registerRpcMethod(PingRequest, PingResponse, 'ping', ping)
|
|
76
|
+
|
|
77
|
+
const request: PingRequest = {
|
|
78
|
+
requestId: v4()
|
|
79
|
+
}
|
|
80
|
+
const options: DhtRpcOptions = {
|
|
81
|
+
sourceDescriptor: peerDescriptor1,
|
|
82
|
+
targetDescriptor: peerDescriptor2
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const response = await client1.ping(request, options)
|
|
86
|
+
|
|
87
|
+
expect(response.requestId).toEqual(request.requestId)
|
|
88
|
+
}, 60000)
|
|
89
|
+
|
|
90
|
+
it('Throws an exception if RPC method is not defined', async () => {
|
|
91
|
+
|
|
92
|
+
const request: PingRequest = {
|
|
93
|
+
requestId: v4()
|
|
94
|
+
}
|
|
95
|
+
const options: DhtRpcOptions = {
|
|
96
|
+
sourceDescriptor: peerDescriptor1,
|
|
97
|
+
targetDescriptor: peerDescriptor2
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
await expect(client1.ping(request, options))
|
|
101
|
+
.rejects.toThrow('Server does not implement method ping')
|
|
102
|
+
}, 60000)
|
|
103
|
+
|
|
104
|
+
/*
|
|
105
|
+
it.only('Throws a client-side exception if WebRTC connection fails', async () => {
|
|
106
|
+
|
|
107
|
+
const request: PingRequest = {
|
|
108
|
+
requestId: v4()
|
|
109
|
+
}
|
|
110
|
+
const options: DhtRpcOptions = {
|
|
111
|
+
sourceDescriptor: peerDescriptor1,
|
|
112
|
+
targetDescriptor: peerDescriptor2
|
|
113
|
+
}
|
|
114
|
+
await connectorTransport1.stop()
|
|
115
|
+
await manager2.stop()
|
|
116
|
+
|
|
117
|
+
const result = await client1.ping(request, options)
|
|
118
|
+
|
|
119
|
+
}, 60000)
|
|
120
|
+
|
|
121
|
+
it('Disconnects WebRtcConnection while being connected', async () => {
|
|
122
|
+
|
|
123
|
+
const rpcMessage: RpcMessage = {
|
|
124
|
+
header: {},
|
|
125
|
+
body: new Uint8Array(10),
|
|
126
|
+
requestId: v4()
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const msg: Message = {
|
|
130
|
+
serviceId: serviceId,
|
|
131
|
+
messageType: MessageType.RPC,
|
|
132
|
+
messageId: '1',
|
|
133
|
+
body: RpcMessage.toBinary(rpcMessage)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const disconnectedPromise1 = new Promise<void>((resolve, _reject) => {
|
|
137
|
+
manager1.on('disconnected', (_peerDescriptor: PeerDescriptor) => {
|
|
138
|
+
//expect(message.messageType).toBe(MessageType.RPC)
|
|
139
|
+
resolve()
|
|
140
|
+
})
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
msg.targetDescriptor = peerDescriptor2
|
|
144
|
+
manager1.send(msg).catch((e) => {
|
|
145
|
+
expect(e.code).toEqual('CONNECTION_FAILED')
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
manager1.disconnect(peerDescriptor2!, undefined, 100)
|
|
149
|
+
await disconnectedPromise1
|
|
150
|
+
|
|
151
|
+
}, 20000)
|
|
152
|
+
*/
|
|
153
|
+
})
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { LatencyType, Simulator } from '../../src/connection/Simulator/Simulator'
|
|
2
|
+
import { DhtNode } from '../../src/dht/DhtNode'
|
|
3
|
+
import { NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
4
|
+
import { createMockConnectionDhtNode } from '../utils/utils'
|
|
5
|
+
import { isSamePeerDescriptor } from '../../src/helpers/peerIdFromPeerDescriptor'
|
|
6
|
+
import { Logger } from '@streamr/utils'
|
|
7
|
+
|
|
8
|
+
const logger = new Logger(module)
|
|
9
|
+
|
|
10
|
+
describe('Scaling down a Dht network', () => {
|
|
11
|
+
let entryPoint: DhtNode
|
|
12
|
+
let nodes: DhtNode[]
|
|
13
|
+
let entrypointDescriptor: PeerDescriptor
|
|
14
|
+
const simulator = new Simulator(LatencyType.RANDOM)
|
|
15
|
+
const NUM_NODES = 80
|
|
16
|
+
const MAX_CONNECTIONS = 15
|
|
17
|
+
const K = 2
|
|
18
|
+
|
|
19
|
+
beforeEach(async () => {
|
|
20
|
+
nodes = []
|
|
21
|
+
const entryPointId = '0'
|
|
22
|
+
entryPoint = await createMockConnectionDhtNode(entryPointId, simulator,
|
|
23
|
+
undefined, K, entryPointId, MAX_CONNECTIONS)
|
|
24
|
+
nodes.push(entryPoint)
|
|
25
|
+
|
|
26
|
+
entrypointDescriptor = {
|
|
27
|
+
kademliaId: entryPoint.getNodeId().value,
|
|
28
|
+
type: NodeType.NODEJS,
|
|
29
|
+
nodeName: entryPointId
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
for (let i = 1; i < NUM_NODES; i++) {
|
|
33
|
+
const nodeId = `${i}`
|
|
34
|
+
const node = await createMockConnectionDhtNode(nodeId, simulator, undefined, K, nodeId, MAX_CONNECTIONS)
|
|
35
|
+
nodes.push(node)
|
|
36
|
+
}
|
|
37
|
+
await Promise.all(nodes.map((node) => node.joinDht([entrypointDescriptor])))
|
|
38
|
+
}, 60000)
|
|
39
|
+
|
|
40
|
+
afterEach(async () => {
|
|
41
|
+
await Promise.all(nodes.map((node) => node.stop()))
|
|
42
|
+
}, 10000)
|
|
43
|
+
|
|
44
|
+
it('Remaining nodes cleaned up stopped nodes from states', async () => {
|
|
45
|
+
const randomIndices = []
|
|
46
|
+
for (let i = 1; i < nodes.length; i++) {
|
|
47
|
+
randomIndices.push(i)
|
|
48
|
+
}
|
|
49
|
+
while (randomIndices.length > 1) {
|
|
50
|
+
const index = Math.floor(Math.random() * randomIndices.length)
|
|
51
|
+
const nodeIndex = randomIndices[index]
|
|
52
|
+
randomIndices.splice(index, 1)
|
|
53
|
+
const stoppingPeerDescriptor = nodes[nodeIndex].getPeerDescriptor()
|
|
54
|
+
await nodes[nodeIndex].stop()
|
|
55
|
+
const nodeIsCleaned = nodes.every((node) =>
|
|
56
|
+
node.getAllConnectionPeerDescriptors().every((peer) => {
|
|
57
|
+
if (isSamePeerDescriptor(peer, stoppingPeerDescriptor)) {
|
|
58
|
+
logger.error(' ' + node.getNodeName() + ', ' + stoppingPeerDescriptor.nodeName + ' cleaning up failed')
|
|
59
|
+
}
|
|
60
|
+
return !isSamePeerDescriptor(peer, stoppingPeerDescriptor)
|
|
61
|
+
})
|
|
62
|
+
)
|
|
63
|
+
expect(nodeIsCleaned).toEqual(true)
|
|
64
|
+
}
|
|
65
|
+
}, 180000)
|
|
66
|
+
})
|