@streamr/dht 100.0.0-pretestnet.4 → 100.0.0-rc.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/README.md +90 -8
- package/dist/package.json +70 -0
- package/dist/src/connection/Connection.d.ts +1 -0
- package/dist/src/connection/Connection.js +10 -3
- package/dist/src/connection/Connection.js.map +1 -1
- package/dist/src/connection/ConnectionLockHandler.d.ts +14 -14
- package/dist/src/connection/ConnectionLockHandler.js +22 -16
- package/dist/src/connection/ConnectionLockHandler.js.map +1 -1
- package/dist/src/connection/ConnectionLockRpcLocal.d.ts +3 -3
- package/dist/src/connection/ConnectionLockRpcLocal.js +7 -6
- package/dist/src/connection/ConnectionLockRpcLocal.js.map +1 -1
- package/dist/src/connection/ConnectionLockRpcRemote.d.ts +4 -6
- package/dist/src/connection/ConnectionLockRpcRemote.js +10 -37
- package/dist/src/connection/ConnectionLockRpcRemote.js.map +1 -1
- package/dist/src/connection/ConnectionManager.d.ts +19 -20
- package/dist/src/connection/ConnectionManager.js +132 -117
- package/dist/src/connection/ConnectionManager.js.map +1 -1
- package/dist/src/connection/ConnectorFacade.d.ts +3 -2
- package/dist/src/connection/ConnectorFacade.js +10 -3
- package/dist/src/connection/ConnectorFacade.js.map +1 -1
- package/dist/src/connection/Handshaker.d.ts +3 -1
- package/dist/src/connection/Handshaker.js +18 -9
- package/dist/src/connection/Handshaker.js.map +1 -1
- package/dist/src/connection/IConnection.d.ts +2 -7
- package/dist/src/connection/IConnection.js +1 -8
- package/dist/src/connection/IConnection.js.map +1 -1
- package/dist/src/connection/ManagedConnection.d.ts +5 -7
- package/dist/src/connection/ManagedConnection.js +42 -26
- package/dist/src/connection/ManagedConnection.js.map +1 -1
- package/dist/src/connection/ManagedWebrtcConnection.js.map +1 -1
- package/dist/src/connection/connectivityChecker.d.ts +9 -0
- package/dist/src/connection/connectivityChecker.js +130 -0
- package/dist/src/connection/connectivityChecker.js.map +1 -0
- package/dist/src/connection/connectivityRequestHandler.d.ts +3 -0
- package/dist/src/connection/connectivityRequestHandler.js +101 -0
- package/dist/src/connection/connectivityRequestHandler.js.map +1 -0
- package/dist/src/connection/simulator/Simulator.d.ts +0 -3
- package/dist/src/connection/simulator/Simulator.js +34 -69
- package/dist/src/connection/simulator/Simulator.js.map +1 -1
- package/dist/src/connection/simulator/SimulatorConnection.js +27 -25
- package/dist/src/connection/simulator/SimulatorConnection.js.map +1 -1
- package/dist/src/connection/simulator/SimulatorConnector.js +16 -12
- package/dist/src/connection/simulator/SimulatorConnector.js.map +1 -1
- package/dist/src/connection/simulator/pings.js.map +1 -1
- package/dist/src/connection/webrtc/NodeWebrtcConnection.d.ts +2 -3
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js +40 -27
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnector.d.ts +0 -2
- package/dist/src/connection/webrtc/WebrtcConnector.js +24 -25
- package/dist/src/connection/webrtc/WebrtcConnector.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.d.ts +2 -2
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js +27 -20
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.d.ts +3 -6
- package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.js +2 -5
- package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.js.map +1 -1
- package/dist/src/connection/webrtc/iceServerAsString.js +1 -1
- package/dist/src/connection/webrtc/iceServerAsString.js.map +1 -1
- package/dist/src/connection/websocket/AutoCertifierClientFacade.d.ts +1 -2
- package/dist/src/connection/websocket/AutoCertifierClientFacade.js +6 -4
- package/dist/src/connection/websocket/AutoCertifierClientFacade.js.map +1 -1
- package/dist/src/connection/websocket/ClientWebsocket.d.ts +1 -0
- package/dist/src/connection/websocket/ClientWebsocket.js +14 -7
- package/dist/src/connection/websocket/ClientWebsocket.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnector.d.ts +3 -9
- package/dist/src/connection/websocket/WebsocketConnector.js +142 -74
- package/dist/src/connection/websocket/WebsocketConnector.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.d.ts +5 -3
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.js +9 -12
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.d.ts +4 -7
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.js +7 -44
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketServer.d.ts +1 -4
- package/dist/src/connection/websocket/WebsocketServer.js +49 -40
- package/dist/src/connection/websocket/WebsocketServer.js.map +1 -1
- package/dist/src/connection/websocket/{ServerWebsocket.d.ts → WebsocketServerConnection.d.ts} +8 -4
- package/dist/src/connection/websocket/WebsocketServerConnection.js +97 -0
- package/dist/src/connection/websocket/WebsocketServerConnection.js.map +1 -0
- package/dist/src/dht/DhtNode.d.ts +45 -49
- package/dist/src/dht/DhtNode.js +229 -317
- package/dist/src/dht/DhtNode.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcLocal.d.ts +10 -9
- package/dist/src/dht/DhtNodeRpcLocal.js +19 -11
- package/dist/src/dht/DhtNodeRpcLocal.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcRemote.d.ts +15 -10
- package/dist/src/dht/DhtNodeRpcRemote.js +38 -21
- package/dist/src/dht/DhtNodeRpcRemote.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcLocal.d.ts +7 -6
- package/dist/src/dht/ExternalApiRpcLocal.js +9 -13
- package/dist/src/dht/ExternalApiRpcLocal.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcRemote.d.ts +6 -5
- package/dist/src/dht/ExternalApiRpcRemote.js +10 -7
- package/dist/src/dht/ExternalApiRpcRemote.js.map +1 -1
- package/dist/src/dht/PeerManager.d.ts +61 -0
- package/dist/src/dht/PeerManager.js +288 -0
- package/dist/src/dht/PeerManager.js.map +1 -0
- package/dist/src/dht/contact/Contact.d.ts +2 -2
- package/dist/src/dht/contact/Contact.js +4 -3
- package/dist/src/dht/contact/Contact.js.map +1 -1
- package/dist/src/dht/contact/ContactList.d.ts +8 -8
- package/dist/src/dht/contact/ContactList.js +12 -7
- package/dist/src/dht/contact/ContactList.js.map +1 -1
- package/dist/src/dht/contact/RandomContactList.d.ts +4 -4
- package/dist/src/dht/contact/RandomContactList.js +13 -12
- package/dist/src/dht/contact/RandomContactList.js.map +1 -1
- package/dist/src/dht/contact/RingContactList.d.ts +31 -0
- package/dist/src/dht/contact/RingContactList.js +133 -0
- package/dist/src/dht/contact/RingContactList.js.map +1 -0
- package/dist/src/dht/contact/{Remote.d.ts → RpcRemote.d.ts} +8 -7
- package/dist/src/dht/contact/{Remote.js → RpcRemote.js} +16 -13
- package/dist/src/dht/contact/RpcRemote.js.map +1 -0
- package/dist/src/dht/contact/SortedContactList.d.ts +29 -15
- package/dist/src/dht/contact/SortedContactList.js +79 -42
- package/dist/src/dht/contact/SortedContactList.js.map +1 -1
- package/dist/src/dht/contact/ringIdentifiers.d.ts +16 -0
- package/dist/src/dht/contact/ringIdentifiers.js +54 -0
- package/dist/src/dht/contact/ringIdentifiers.js.map +1 -0
- package/dist/src/dht/discovery/DiscoverySession.d.ts +8 -18
- package/dist/src/dht/discovery/DiscoverySession.js +32 -48
- package/dist/src/dht/discovery/DiscoverySession.js.map +1 -1
- package/dist/src/dht/discovery/PeerDiscovery.d.ts +16 -12
- package/dist/src/dht/discovery/PeerDiscovery.js +82 -39
- package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -1
- package/dist/src/dht/discovery/RingDiscoverySession.d.ts +29 -0
- package/dist/src/dht/discovery/RingDiscoverySession.js +123 -0
- package/dist/src/dht/discovery/RingDiscoverySession.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.d.ts +36 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.js +166 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.d.ts +14 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.js +26 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.d.ts +6 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js +44 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.d.ts +44 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.js +187 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.d.ts +14 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js +20 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.d.ts +6 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.js +21 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.js.map +1 -0
- package/dist/src/dht/routing/DuplicateDetector.d.ts +2 -4
- package/dist/src/dht/routing/DuplicateDetector.js +10 -15
- package/dist/src/dht/routing/DuplicateDetector.js.map +1 -1
- package/dist/src/dht/routing/Router.d.ts +11 -27
- package/dist/src/dht/routing/Router.js +92 -58
- package/dist/src/dht/routing/Router.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcLocal.d.ts +3 -4
- package/dist/src/dht/routing/RouterRpcLocal.js +17 -16
- package/dist/src/dht/routing/RouterRpcLocal.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcRemote.d.ts +3 -3
- package/dist/src/dht/routing/RouterRpcRemote.js +29 -20
- package/dist/src/dht/routing/RouterRpcRemote.js.map +1 -1
- package/dist/src/dht/routing/RoutingSession.d.ts +29 -21
- package/dist/src/dht/routing/RoutingSession.js +93 -68
- package/dist/src/dht/routing/RoutingSession.js.map +1 -1
- package/dist/src/dht/routing/RoutingTablesCache.d.ts +24 -0
- package/dist/src/dht/routing/RoutingTablesCache.js +46 -0
- package/dist/src/dht/routing/RoutingTablesCache.js.map +1 -0
- package/dist/src/dht/routing/getPreviousPeer.js.map +1 -1
- package/dist/src/dht/store/LocalDataStore.d.ts +9 -14
- package/dist/src/dht/store/LocalDataStore.js +46 -72
- package/dist/src/dht/store/LocalDataStore.js.map +1 -1
- package/dist/src/dht/store/StoreManager.d.ts +33 -0
- package/dist/src/dht/store/StoreManager.js +182 -0
- package/dist/src/dht/store/StoreManager.js.map +1 -0
- package/dist/src/dht/store/StoreRpcLocal.d.ts +11 -41
- package/dist/src/dht/store/StoreRpcLocal.js +27 -234
- package/dist/src/dht/store/StoreRpcLocal.js.map +1 -1
- package/dist/src/dht/store/StoreRpcRemote.d.ts +6 -7
- package/dist/src/dht/store/StoreRpcRemote.js +10 -20
- package/dist/src/dht/store/StoreRpcRemote.js.map +1 -1
- package/dist/src/exports.d.ts +5 -3
- package/dist/src/exports.js +10 -8
- package/dist/src/exports.js.map +1 -1
- package/dist/src/helpers/AddressTools.js +2 -0
- package/dist/src/helpers/AddressTools.js.map +1 -1
- package/dist/src/helpers/Connectivity.js.map +1 -1
- package/dist/src/helpers/MapWithTtl.d.ts +14 -0
- package/dist/src/helpers/MapWithTtl.js +60 -0
- package/dist/src/helpers/MapWithTtl.js.map +1 -0
- package/dist/src/helpers/createPeerDescriptor.d.ts +3 -0
- package/dist/src/helpers/createPeerDescriptor.js +57 -0
- package/dist/src/helpers/createPeerDescriptor.js.map +1 -0
- package/dist/src/helpers/createPeerDescriptorSignaturePayload.d.ts +2 -0
- package/dist/src/helpers/createPeerDescriptorSignaturePayload.js +30 -0
- package/dist/src/helpers/createPeerDescriptorSignaturePayload.js.map +1 -0
- package/dist/src/helpers/debugHelpers.js.map +1 -1
- package/dist/src/helpers/errors.js +2 -0
- package/dist/src/helpers/errors.js.map +1 -1
- package/dist/src/helpers/offering.d.ts +4 -0
- package/dist/src/helpers/offering.js +18 -0
- package/dist/src/helpers/offering.js.map +1 -0
- package/dist/src/helpers/protoClasses.js +2 -3
- package/dist/src/helpers/protoClasses.js.map +1 -1
- package/dist/src/helpers/protoToString.js.map +1 -1
- package/dist/src/helpers/version.d.ts +6 -0
- package/dist/src/helpers/version.js +38 -0
- package/dist/src/helpers/version.js.map +1 -0
- package/dist/src/identifiers.d.ts +10 -0
- package/dist/src/identifiers.js +31 -0
- package/dist/src/identifiers.js.map +1 -0
- package/dist/src/proto/google/protobuf/any.js +8 -8
- package/dist/src/proto/google/protobuf/any.js.map +1 -1
- package/dist/src/proto/google/protobuf/empty.js +2 -4
- package/dist/src/proto/google/protobuf/empty.js.map +1 -1
- package/dist/src/proto/google/protobuf/timestamp.js +10 -10
- package/dist/src/proto/google/protobuf/timestamp.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +46 -49
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +63 -54
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +226 -232
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +146 -168
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +26 -29
- package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.js +1 -1
- package/dist/src/rpc-protocol/DhtCallContext.d.ts +2 -2
- package/dist/src/rpc-protocol/DhtCallContext.js +8 -0
- package/dist/src/rpc-protocol/DhtCallContext.js.map +1 -1
- package/dist/src/rpc-protocol/DhtRpcOptions.d.ts +2 -1
- package/dist/src/transport/ITransport.d.ts +10 -2
- package/dist/src/transport/ITransport.js +5 -0
- package/dist/src/transport/ITransport.js.map +1 -1
- package/dist/src/transport/ListeningRpcCommunicator.js +3 -1
- package/dist/src/transport/ListeningRpcCommunicator.js.map +1 -1
- package/dist/src/transport/RoutingRpcCommunicator.d.ts +4 -2
- package/dist/src/transport/RoutingRpcCommunicator.js +19 -12
- package/dist/src/transport/RoutingRpcCommunicator.js.map +1 -1
- package/jest.config.js +4 -1
- package/karma-setup.js +2 -0
- package/karma.config.js +13 -9
- package/package.json +16 -13
- package/protos/DhtRpc.proto +76 -76
- package/src/connection/Connection.ts +6 -1
- package/src/connection/ConnectionLockHandler.ts +30 -22
- package/src/connection/ConnectionLockRpcLocal.ts +7 -12
- package/src/connection/ConnectionLockRpcRemote.ts +9 -19
- package/src/connection/ConnectionManager.ts +132 -138
- package/src/connection/ConnectorFacade.ts +10 -9
- package/src/connection/Handshaker.ts +23 -11
- package/src/connection/IConnection.ts +2 -8
- package/src/connection/ManagedConnection.ts +34 -35
- package/src/connection/connectivityChecker.ts +109 -0
- package/src/connection/connectivityRequestHandler.ts +103 -0
- package/src/connection/simulator/Simulator.ts +6 -37
- package/src/connection/simulator/SimulatorConnection.ts +23 -25
- package/src/connection/simulator/SimulatorConnector.ts +11 -11
- package/src/connection/webrtc/BrowserWebrtcConnection.ts +17 -25
- package/src/connection/webrtc/NodeWebrtcConnection.ts +24 -26
- package/src/connection/webrtc/WebrtcConnector.ts +18 -29
- package/src/connection/webrtc/WebrtcConnectorRpcLocal.ts +29 -24
- package/src/connection/webrtc/WebrtcConnectorRpcRemote.ts +4 -14
- package/src/connection/webrtc/iceServerAsString.ts +1 -1
- package/src/connection/websocket/AutoCertifierClientFacade.ts +4 -6
- package/src/connection/websocket/ClientWebsocket.ts +10 -4
- package/src/connection/websocket/WebsocketConnector.ts +120 -97
- package/src/connection/websocket/WebsocketConnectorRpcLocal.ts +13 -15
- package/src/connection/websocket/WebsocketConnectorRpcRemote.ts +7 -27
- package/src/connection/websocket/WebsocketServer.ts +50 -53
- package/src/connection/websocket/WebsocketServerConnection.ts +104 -0
- package/src/dht/DhtNode.ts +289 -410
- package/src/dht/DhtNodeRpcLocal.ts +25 -17
- package/src/dht/DhtNodeRpcRemote.ts +43 -27
- package/src/dht/ExternalApiRpcLocal.ts +30 -17
- package/src/dht/ExternalApiRpcRemote.ts +14 -11
- package/src/dht/PeerManager.ts +339 -0
- package/src/dht/contact/Contact.ts +4 -4
- package/src/dht/contact/ContactList.ts +11 -10
- package/src/dht/contact/RandomContactList.ts +15 -15
- package/src/dht/contact/RingContactList.ts +151 -0
- package/src/dht/contact/{Remote.ts → RpcRemote.ts} +16 -19
- package/src/dht/contact/SortedContactList.ts +120 -72
- package/src/dht/contact/ringIdentifiers.ts +62 -0
- package/src/dht/discovery/DiscoverySession.ts +36 -61
- package/src/dht/discovery/PeerDiscovery.ts +98 -43
- package/src/dht/discovery/RingDiscoverySession.ts +160 -0
- package/src/dht/recursive-operation/RecursiveOperationManager.ts +246 -0
- package/src/dht/recursive-operation/RecursiveOperationRpcLocal.ts +34 -0
- package/src/dht/recursive-operation/RecursiveOperationRpcRemote.ts +43 -0
- package/src/dht/recursive-operation/RecursiveOperationSession.ts +232 -0
- package/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.ts +35 -0
- package/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.ts +30 -0
- package/src/dht/routing/DuplicateDetector.ts +9 -21
- package/src/dht/routing/Router.ts +95 -92
- package/src/dht/routing/RouterRpcLocal.ts +16 -18
- package/src/dht/routing/RouterRpcRemote.ts +26 -24
- package/src/dht/routing/RoutingSession.ts +119 -98
- package/src/dht/routing/RoutingTablesCache.ts +58 -0
- package/src/dht/routing/getPreviousPeer.ts +1 -1
- package/src/dht/store/LocalDataStore.ts +47 -77
- package/src/dht/store/StoreManager.ts +209 -0
- package/src/dht/store/StoreRpcLocal.ts +39 -308
- package/src/dht/store/StoreRpcRemote.ts +13 -31
- package/src/exports.ts +13 -3
- package/src/helpers/AddressTools.ts +2 -0
- package/src/helpers/MapWithTtl.ts +71 -0
- package/src/helpers/createPeerDescriptor.ts +57 -0
- package/src/helpers/createPeerDescriptorSignaturePayload.ts +28 -0
- package/src/helpers/offering.ts +15 -0
- package/src/helpers/protoClasses.ts +4 -6
- package/src/helpers/version.ts +32 -0
- package/src/identifiers.ts +29 -0
- package/src/proto/google/protobuf/any.ts +4 -4
- package/src/proto/google/protobuf/empty.ts +2 -4
- package/src/proto/google/protobuf/timestamp.ts +4 -4
- package/src/proto/packages/dht/protos/DhtRpc.client.ts +65 -68
- package/src/proto/packages/dht/protos/DhtRpc.server.ts +27 -30
- package/src/proto/packages/dht/protos/DhtRpc.ts +297 -313
- package/src/proto/packages/proto-rpc/protos/ProtoRpc.ts +1 -1
- package/src/rpc-protocol/DhtCallContext.ts +2 -2
- package/src/rpc-protocol/DhtRpcOptions.ts +2 -1
- package/src/transport/ITransport.ts +11 -2
- package/src/transport/ListeningRpcCommunicator.ts +1 -1
- package/src/transport/RoutingRpcCommunicator.ts +21 -14
- package/test/RandomGraphSimulation.ts +3 -2
- package/test/benchmark/Find.test.ts +13 -28
- package/test/benchmark/KademliaCorrectness.test.ts +24 -28
- package/test/benchmark/RingCorrectness.test.ts +157 -0
- package/test/benchmark/SortedContactListBenchmark.test.ts +151 -0
- package/test/benchmark/WebsocketServerMemoryLeak.test.ts +41 -0
- package/test/benchmark/hybrid-network-simulation/RingContactList.test.ts +72 -0
- package/test/benchmark/kademlia-simulation/Contact.ts +9 -9
- package/test/benchmark/kademlia-simulation/KademliaSimulation.ts +11 -11
- package/test/benchmark/kademlia-simulation/SimulationNode.ts +29 -25
- package/test/data/generateGroundTruthData.ts +7 -6
- package/test/end-to-end/Layer0-Layer1.test.ts +11 -15
- package/test/end-to-end/Layer0.test.ts +19 -22
- package/test/end-to-end/Layer0MixedConnectionTypes.test.ts +19 -21
- package/test/end-to-end/Layer0Webrtc-Layer1.test.ts +26 -28
- package/test/end-to-end/Layer0Webrtc.test.ts +19 -19
- package/test/end-to-end/Layer1-Scale-WebSocket.test.ts +10 -18
- package/test/end-to-end/Layer1-Scale-Webrtc.test.ts +8 -15
- package/test/end-to-end/RecoveryFromFailedAutoCertification.test.ts +2 -2
- package/test/end-to-end/WebsocketConnectionRequest.test.ts +8 -9
- package/test/end-to-end/memory-leak.test.ts +19 -24
- package/test/integration/ConnectionLocking.test.ts +66 -60
- package/test/integration/ConnectionManager.test.ts +43 -63
- package/test/integration/ConnectivityChecking.test.ts +52 -0
- package/test/integration/DhtJoinPeerDiscovery.test.ts +8 -12
- package/test/integration/DhtNodeExternalAPI.test.ts +17 -21
- package/test/integration/DhtNodeRpcRemote.test.ts +19 -26
- package/test/integration/DhtRpc.test.ts +20 -24
- package/test/integration/Find.test.ts +10 -12
- package/test/integration/Layer1-scale.test.ts +25 -37
- package/test/integration/Mock-Layer1-Layer0.test.ts +39 -59
- package/test/integration/MultipleEntryPointJoining.test.ts +14 -14
- package/test/integration/ReplicateData.test.ts +106 -0
- package/test/integration/RouteMessage.test.ts +42 -68
- package/test/integration/RouterRpcRemote.test.ts +19 -24
- package/test/integration/ScaleDownDht.test.ts +14 -12
- package/test/integration/SimultaneousConnections.test.ts +112 -111
- package/test/integration/Store.test.ts +43 -27
- package/test/integration/StoreAndDelete.test.ts +36 -48
- package/test/integration/StoreOnDhtWithThreeNodes.test.ts +59 -0
- package/test/integration/StoreOnDhtWithTwoNodes.test.ts +17 -37
- package/test/integration/StoreRpcRemote.test.ts +20 -32
- package/test/integration/WebrtcConnectionManagement.test.ts +39 -25
- package/test/integration/WebrtcConnectorRpc.test.ts +6 -11
- package/test/integration/WebsocketConnectionManagement.test.ts +87 -22
- package/test/integration/WebsocketConnectorRpc.test.ts +14 -24
- package/test/integration/{RpcErrors.test.ts → rpc-connections-over-webrpc.test.ts} +15 -26
- package/test/unit/AddressTools.test.ts +4 -0
- package/test/unit/ConnectivityHelpers.test.ts +9 -17
- package/test/unit/DuplicateDetector.test.ts +8 -5
- package/test/unit/LocalDataStore.test.ts +78 -75
- package/test/unit/PeerManager.test.ts +33 -0
- package/test/unit/RandomContactList.test.ts +12 -9
- package/test/unit/RecursiveOperationManager.test.ts +157 -0
- package/test/unit/RecursiveOperationSession.test.ts +68 -0
- package/test/unit/Router.test.ts +52 -35
- package/test/unit/RoutingSession.test.ts +79 -0
- package/test/unit/SortedContactList.test.ts +61 -30
- package/test/unit/StoreManager.test.ts +138 -0
- package/test/unit/WebsocketConnector.test.ts +27 -35
- package/test/unit/connectivityRequestHandler.test.ts +104 -0
- package/test/unit/createPeerDescriptor.test.ts +69 -0
- package/test/unit/customMatchers.test.ts +16 -0
- package/test/unit/version.test.ts +18 -0
- package/test/utils/FakeTransport.ts +47 -0
- package/test/utils/customMatchers.ts +71 -0
- package/test/utils/mock/MockRpcCommunicator.ts +7 -0
- package/test/utils/mock/Router.ts +13 -3
- package/test/utils/mock/Transport.ts +1 -1
- package/test/utils/mock/mockDataEntry.ts +38 -0
- package/test/utils/utils.ts +104 -107
- package/tsconfig.browser.json +2 -1
- package/tsconfig.jest.json +4 -2
- package/tsconfig.node.json +4 -2
- package/dist/src/connection/ConnectivityChecker.d.ts +0 -17
- package/dist/src/connection/ConnectivityChecker.js +0 -208
- package/dist/src/connection/ConnectivityChecker.js.map +0 -1
- package/dist/src/connection/websocket/ServerWebsocket.js +0 -100
- package/dist/src/connection/websocket/ServerWebsocket.js.map +0 -1
- package/dist/src/dht/contact/Remote.js.map +0 -1
- package/dist/src/dht/find/FindRpcLocal.d.ts +0 -14
- package/dist/src/dht/find/FindRpcLocal.js +0 -25
- package/dist/src/dht/find/FindRpcLocal.js.map +0 -1
- package/dist/src/dht/find/FindSession.d.ts +0 -44
- package/dist/src/dht/find/FindSession.js +0 -145
- package/dist/src/dht/find/FindSession.js.map +0 -1
- package/dist/src/dht/find/FindSessionRpcLocal.d.ts +0 -12
- package/dist/src/dht/find/FindSessionRpcLocal.js +0 -17
- package/dist/src/dht/find/FindSessionRpcLocal.js.map +0 -1
- package/dist/src/dht/find/FindSessionRpcRemote.d.ts +0 -6
- package/dist/src/dht/find/FindSessionRpcRemote.js +0 -21
- package/dist/src/dht/find/FindSessionRpcRemote.js.map +0 -1
- package/dist/src/dht/find/Finder.d.ts +0 -49
- package/dist/src/dht/find/Finder.js +0 -184
- package/dist/src/dht/find/Finder.js.map +0 -1
- package/dist/src/dht/routing/FindRpcRemote.d.ts +0 -6
- package/dist/src/dht/routing/FindRpcRemote.js +0 -41
- package/dist/src/dht/routing/FindRpcRemote.js.map +0 -1
- package/dist/src/helpers/PeerID.d.ts +0 -24
- package/dist/src/helpers/PeerID.js +0 -78
- package/dist/src/helpers/PeerID.js.map +0 -1
- package/dist/src/helpers/UUID.d.ts +0 -8
- package/dist/src/helpers/UUID.js +0 -36
- package/dist/src/helpers/UUID.js.map +0 -1
- package/dist/src/helpers/kademliaId.d.ts +0 -1
- package/dist/src/helpers/kademliaId.js +0 -14
- package/dist/src/helpers/kademliaId.js.map +0 -1
- package/dist/src/helpers/peerIdFromPeerDescriptor.d.ts +0 -6
- package/dist/src/helpers/peerIdFromPeerDescriptor.js +0 -23
- package/dist/src/helpers/peerIdFromPeerDescriptor.js.map +0 -1
- package/src/connection/ConnectivityChecker.ts +0 -199
- package/src/connection/websocket/ServerWebsocket.ts +0 -114
- package/src/dht/find/FindRpcLocal.ts +0 -35
- package/src/dht/find/FindSession.ts +0 -178
- package/src/dht/find/FindSessionRpcLocal.ts +0 -25
- package/src/dht/find/FindSessionRpcRemote.ts +0 -30
- package/src/dht/find/Finder.ts +0 -275
- package/src/dht/routing/FindRpcRemote.ts +0 -40
- package/src/helpers/PeerID.ts +0 -88
- package/src/helpers/UUID.ts +0 -35
- package/src/helpers/kademliaId.ts +0 -8
- package/src/helpers/peerIdFromPeerDescriptor.ts +0 -20
- package/test/integration/MigrateData.test.ts +0 -204
- package/test/unit/Finder.test.ts +0 -110
- package/test/unit/PeerID.test.ts +0 -22
- package/test/unit/UUID.test.ts +0 -55
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
import { LatencyType, Simulator } from '../../src/connection/simulator/Simulator'
|
|
3
|
+
import { DhtNode } from '../../src/dht/DhtNode'
|
|
4
|
+
import { createMockConnectionDhtNode, waitNodesReadyForTesting } from '../utils/utils'
|
|
5
|
+
import { SortedContactList } from '../../src/dht/contact/SortedContactList'
|
|
6
|
+
import { createMockDataEntry, expectEqualData } from '../utils/mock/mockDataEntry'
|
|
7
|
+
import { DhtAddress, createRandomDhtAddress, getDhtAddressFromRaw, getNodeIdFromPeerDescriptor } from '../../src/identifiers'
|
|
8
|
+
import { sample } from 'lodash'
|
|
9
|
+
import { DataEntry, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
10
|
+
|
|
11
|
+
const DATA = createMockDataEntry()
|
|
12
|
+
const NUM_NODES = 100
|
|
13
|
+
const MAX_CONNECTIONS = 80
|
|
14
|
+
const K = 8
|
|
15
|
+
const ENTRY_POINT_INDEX = 0
|
|
16
|
+
|
|
17
|
+
const getDataEntries = (node: DhtNode): DataEntry[] => {
|
|
18
|
+
// @ts-expect-error private field
|
|
19
|
+
const store = node.localDataStore
|
|
20
|
+
return Array.from(store.values(getDhtAddressFromRaw(DATA.key)))
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
describe('Replicate data from node to node in DHT', () => {
|
|
24
|
+
|
|
25
|
+
let nodes: DhtNode[]
|
|
26
|
+
let entryPointDescriptor: PeerDescriptor
|
|
27
|
+
const simulator = new Simulator(LatencyType.FIXED, 20)
|
|
28
|
+
|
|
29
|
+
beforeEach(async () => {
|
|
30
|
+
const entryPoint = await createMockConnectionDhtNode(simulator, createRandomDhtAddress(), K, MAX_CONNECTIONS)
|
|
31
|
+
entryPointDescriptor = entryPoint.getLocalPeerDescriptor()
|
|
32
|
+
await entryPoint.joinDht([entryPointDescriptor])
|
|
33
|
+
nodes = []
|
|
34
|
+
nodes.push(entryPoint)
|
|
35
|
+
for (let i = 1; i < NUM_NODES; i++) {
|
|
36
|
+
const node = await createMockConnectionDhtNode(
|
|
37
|
+
simulator,
|
|
38
|
+
createRandomDhtAddress(),
|
|
39
|
+
K,
|
|
40
|
+
MAX_CONNECTIONS
|
|
41
|
+
)
|
|
42
|
+
nodes.push(node)
|
|
43
|
+
}
|
|
44
|
+
}, 60000)
|
|
45
|
+
|
|
46
|
+
afterEach(async () => {
|
|
47
|
+
await Promise.all(nodes.map(async (node) => await node.stop()))
|
|
48
|
+
}, 60000)
|
|
49
|
+
|
|
50
|
+
afterAll(async () => {
|
|
51
|
+
simulator.stop()
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it('Data replicates to the closest node no matter where it is stored', async () => {
|
|
55
|
+
// calculate offline which node is closest to the data
|
|
56
|
+
const sortedList = new SortedContactList<DhtNode>({
|
|
57
|
+
referenceId: getDhtAddressFromRaw(DATA.key),
|
|
58
|
+
maxSize: 10000,
|
|
59
|
+
allowToContainReferenceId: true,
|
|
60
|
+
emitEvents: false
|
|
61
|
+
})
|
|
62
|
+
nodes.forEach((node) => sortedList.addContact(node))
|
|
63
|
+
|
|
64
|
+
const closest = sortedList.getAllContacts()
|
|
65
|
+
const successfulStorers = await nodes[0].storeDataToDht(getDhtAddressFromRaw(DATA.key), DATA.data!)
|
|
66
|
+
expect(successfulStorers.length).toBe(1)
|
|
67
|
+
|
|
68
|
+
await Promise.all(
|
|
69
|
+
nodes.map(async (node, i) => {
|
|
70
|
+
if (i !== ENTRY_POINT_INDEX) {
|
|
71
|
+
await node.joinDht([entryPointDescriptor])
|
|
72
|
+
}
|
|
73
|
+
})
|
|
74
|
+
)
|
|
75
|
+
await waitNodesReadyForTesting(nodes)
|
|
76
|
+
|
|
77
|
+
const data = getDataEntries(closest[0])
|
|
78
|
+
expect(data).toHaveLength(1)
|
|
79
|
+
expectEqualData(data[0], DATA)
|
|
80
|
+
}, 180000)
|
|
81
|
+
|
|
82
|
+
it('Data replicates to the other nodes when storers are stopped', async () => {
|
|
83
|
+
await Promise.all(
|
|
84
|
+
nodes.map(async (node, i) => {
|
|
85
|
+
if (i !== ENTRY_POINT_INDEX) {
|
|
86
|
+
await node.joinDht([entryPointDescriptor])
|
|
87
|
+
}
|
|
88
|
+
})
|
|
89
|
+
)
|
|
90
|
+
await waitNodesReadyForTesting(nodes)
|
|
91
|
+
|
|
92
|
+
const randomIndex = Math.floor(Math.random() * nodes.length)
|
|
93
|
+
const storerDescriptors = await nodes[randomIndex].storeDataToDht(getDhtAddressFromRaw(DATA.key), DATA.data!)
|
|
94
|
+
const stoppedNodeIds: DhtAddress[] = []
|
|
95
|
+
await Promise.all(storerDescriptors.map(async (storerDescriptor) => {
|
|
96
|
+
const storer = nodes.find((n) => n.getNodeId() === getNodeIdFromPeerDescriptor(storerDescriptor))!
|
|
97
|
+
await storer.stop()
|
|
98
|
+
stoppedNodeIds.push(storer.getNodeId())
|
|
99
|
+
}))
|
|
100
|
+
|
|
101
|
+
const randomNonStoppedNode = sample(nodes.filter((n) => !stoppedNodeIds.includes(n.getNodeId())))!
|
|
102
|
+
const data = await randomNonStoppedNode.fetchDataFromDht(getDhtAddressFromRaw(DATA.key))
|
|
103
|
+
expect(data).toHaveLength(1)
|
|
104
|
+
expectEqualData(data[0], DATA)
|
|
105
|
+
}, 180000)
|
|
106
|
+
})
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
import { DhtNode, Events as DhtNodeEvents } from '../../src/dht/DhtNode'
|
|
2
|
-
import { Message,
|
|
2
|
+
import { Message, NodeType, PeerDescriptor, RouteMessageWrapper } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
3
3
|
import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
|
|
4
4
|
import { Logger, runAndWaitForEvents3, waitForCondition } from '@streamr/utils'
|
|
5
5
|
import { createMockConnectionDhtNode, createWrappedClosestPeersRequest } from '../utils/utils'
|
|
6
|
-
import { PeerID } from '../../src/helpers/PeerID'
|
|
7
6
|
import { Simulator } from '../../src/connection/simulator/Simulator'
|
|
8
7
|
import { v4 } from 'uuid'
|
|
9
8
|
import { Any } from '../../src/proto/google/protobuf/any'
|
|
10
9
|
import { RoutingMode } from '../../src/dht/routing/RoutingSession'
|
|
10
|
+
import { DhtAddress, createRandomDhtAddress, getRawFromDhtAddress } from '../../src/identifiers'
|
|
11
11
|
|
|
12
12
|
const logger = new Logger(module)
|
|
13
13
|
|
|
14
|
+
const NUM_NODES = 30
|
|
15
|
+
|
|
14
16
|
describe('Route Message With Mock Connections', () => {
|
|
17
|
+
|
|
15
18
|
let entryPoint: DhtNode
|
|
16
19
|
let sourceNode: DhtNode
|
|
17
20
|
let destinationNode: DhtNode
|
|
@@ -19,29 +22,21 @@ describe('Route Message With Mock Connections', () => {
|
|
|
19
22
|
let simulator: Simulator
|
|
20
23
|
let entryPointDescriptor: PeerDescriptor
|
|
21
24
|
|
|
22
|
-
const entryPointId = '0'
|
|
23
|
-
const sourceId = 'eeeeeeeee'
|
|
24
|
-
const destinationId = '000000000'
|
|
25
|
-
const NUM_NODES = 30
|
|
26
|
-
|
|
27
|
-
const receiveMatrix: Array<Array<number>> = []
|
|
28
|
-
|
|
29
25
|
beforeEach(async () => {
|
|
30
26
|
routerNodes = []
|
|
31
27
|
simulator = new Simulator()
|
|
32
|
-
entryPoint = await createMockConnectionDhtNode(
|
|
28
|
+
entryPoint = await createMockConnectionDhtNode(simulator, createRandomDhtAddress())
|
|
33
29
|
|
|
34
30
|
entryPointDescriptor = {
|
|
35
|
-
|
|
31
|
+
nodeId: getRawFromDhtAddress(entryPoint.getNodeId()),
|
|
36
32
|
type: NodeType.NODEJS
|
|
37
33
|
}
|
|
38
34
|
|
|
39
|
-
sourceNode = await createMockConnectionDhtNode(
|
|
40
|
-
destinationNode = await createMockConnectionDhtNode(
|
|
35
|
+
sourceNode = await createMockConnectionDhtNode(simulator, createRandomDhtAddress())
|
|
36
|
+
destinationNode = await createMockConnectionDhtNode(simulator, createRandomDhtAddress())
|
|
41
37
|
|
|
42
38
|
for (let i = 1; i < NUM_NODES; i++) {
|
|
43
|
-
const
|
|
44
|
-
const node = await createMockConnectionDhtNode(nodeId, simulator)
|
|
39
|
+
const node = await createMockConnectionDhtNode(simulator, createRandomDhtAddress())
|
|
45
40
|
routerNodes.push(node)
|
|
46
41
|
}
|
|
47
42
|
|
|
@@ -69,7 +64,6 @@ describe('Route Message With Mock Connections', () => {
|
|
|
69
64
|
const message: Message = {
|
|
70
65
|
serviceId: 'unknown',
|
|
71
66
|
messageId: v4(),
|
|
72
|
-
messageType: MessageType.RPC,
|
|
73
67
|
body: {
|
|
74
68
|
oneofKind: 'rpcMessage',
|
|
75
69
|
rpcMessage: rpcWrapper
|
|
@@ -81,29 +75,28 @@ describe('Route Message With Mock Connections', () => {
|
|
|
81
75
|
await runAndWaitForEvents3<DhtNodeEvents>([() => {
|
|
82
76
|
sourceNode.router!.doRouteMessage({
|
|
83
77
|
message,
|
|
84
|
-
|
|
78
|
+
target: destinationNode.getLocalPeerDescriptor().nodeId,
|
|
85
79
|
requestId: v4(),
|
|
86
80
|
sourcePeer: sourceNode.getLocalPeerDescriptor(),
|
|
87
81
|
reachableThrough: [],
|
|
88
|
-
routingPath: []
|
|
89
|
-
|
|
82
|
+
routingPath: [],
|
|
83
|
+
parallelRootNodeIds: []
|
|
90
84
|
})
|
|
91
85
|
}], [[destinationNode, 'message']], 20000)
|
|
92
86
|
}, 30000)
|
|
93
87
|
|
|
94
88
|
it('Receives multiple messages', async () => {
|
|
95
|
-
const
|
|
89
|
+
const messageCount = 20
|
|
96
90
|
let receivedMessages = 0
|
|
97
91
|
destinationNode.on('message', () => {
|
|
98
92
|
receivedMessages += 1
|
|
99
93
|
})
|
|
100
94
|
const rpcWrapper = createWrappedClosestPeersRequest(sourceNode.getLocalPeerDescriptor())
|
|
101
95
|
|
|
102
|
-
for (let i = 0; i <
|
|
96
|
+
for (let i = 0; i < messageCount; i++) {
|
|
103
97
|
const message: Message = {
|
|
104
98
|
serviceId: 'unknown',
|
|
105
99
|
messageId: v4(),
|
|
106
|
-
messageType: MessageType.RPC,
|
|
107
100
|
body: {
|
|
108
101
|
oneofKind: 'rpcMessage',
|
|
109
102
|
rpcMessage: rpcWrapper
|
|
@@ -113,53 +106,34 @@ describe('Route Message With Mock Connections', () => {
|
|
|
113
106
|
}
|
|
114
107
|
sourceNode.router!.doRouteMessage({
|
|
115
108
|
message,
|
|
116
|
-
|
|
109
|
+
target: destinationNode.getLocalPeerDescriptor().nodeId,
|
|
117
110
|
requestId: v4(),
|
|
118
111
|
sourcePeer: sourceNode.getLocalPeerDescriptor(),
|
|
119
112
|
reachableThrough: [],
|
|
120
|
-
routingPath: []
|
|
113
|
+
routingPath: [],
|
|
114
|
+
parallelRootNodeIds: []
|
|
121
115
|
})
|
|
122
116
|
}
|
|
123
|
-
await waitForCondition(() => receivedMessages ===
|
|
117
|
+
await waitForCondition(() => receivedMessages === messageCount)
|
|
124
118
|
})
|
|
125
119
|
|
|
126
120
|
it('From all to all', async () => {
|
|
127
|
-
|
|
128
|
-
for (const i in routerNodes) {
|
|
129
|
-
const arr: Array<number> = []
|
|
130
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
131
|
-
for (const j in routerNodes) {
|
|
132
|
-
arr.push(0)
|
|
133
|
-
}
|
|
134
|
-
receiveMatrix.push(arr)
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
const numsOfReceivedMessages: Record<string, number> = {}
|
|
121
|
+
const receivedMessageCounts: Record<DhtAddress, number> = {}
|
|
138
122
|
routerNodes.forEach((node) => {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
const target = receiveMatrix[parseInt(node.getNodeId().toString()) - 1]
|
|
144
|
-
target[parseInt(PeerID.fromValue(msg.sourceDescriptor!.kademliaId).toString()) - 1]++
|
|
145
|
-
} catch (e) {
|
|
146
|
-
console.error(e)
|
|
147
|
-
}
|
|
148
|
-
if (parseInt(node.getNodeId().toString()) > routerNodes.length || parseInt(node.getNodeId().toString()) === 0) {
|
|
149
|
-
console.error(node.getNodeId().toString())
|
|
150
|
-
}
|
|
123
|
+
const key = node.getNodeId()
|
|
124
|
+
receivedMessageCounts[key] = 0
|
|
125
|
+
node.on('message', () => {
|
|
126
|
+
receivedMessageCounts[key] = receivedMessageCounts[key] + 1
|
|
151
127
|
})
|
|
152
|
-
}
|
|
153
|
-
)
|
|
128
|
+
})
|
|
154
129
|
await Promise.all(
|
|
155
130
|
routerNodes.map(async (node) =>
|
|
156
131
|
Promise.all(routerNodes.map(async (receiver) => {
|
|
157
|
-
if (
|
|
132
|
+
if (node.getNodeId() !== receiver.getNodeId()) {
|
|
158
133
|
const rpcWrapper = createWrappedClosestPeersRequest(sourceNode.getLocalPeerDescriptor())
|
|
159
134
|
const message: Message = {
|
|
160
135
|
serviceId: 'nonexisting_service',
|
|
161
136
|
messageId: v4(),
|
|
162
|
-
messageType: MessageType.RPC,
|
|
163
137
|
body: {
|
|
164
138
|
oneofKind: 'rpcMessage',
|
|
165
139
|
rpcMessage: rpcWrapper
|
|
@@ -169,21 +143,21 @@ describe('Route Message With Mock Connections', () => {
|
|
|
169
143
|
}
|
|
170
144
|
node.router!.doRouteMessage({
|
|
171
145
|
message,
|
|
172
|
-
|
|
146
|
+
target: receiver.getLocalPeerDescriptor().nodeId,
|
|
173
147
|
sourcePeer: node.getLocalPeerDescriptor(),
|
|
174
148
|
requestId: v4(),
|
|
175
149
|
reachableThrough: [],
|
|
176
|
-
routingPath: []
|
|
150
|
+
routingPath: [],
|
|
151
|
+
parallelRootNodeIds: []
|
|
177
152
|
})
|
|
178
153
|
}
|
|
179
154
|
}))
|
|
180
155
|
)
|
|
181
156
|
)
|
|
182
|
-
await waitForCondition(() =>
|
|
183
|
-
, 30000)
|
|
157
|
+
await waitForCondition(() => receivedMessageCounts[routerNodes[0].getNodeId()] >= routerNodes.length - 1, 30000)
|
|
184
158
|
await Promise.all(
|
|
185
|
-
Object.keys(
|
|
186
|
-
waitForCondition(() =>
|
|
159
|
+
Object.keys(receivedMessageCounts).map(async (key) =>
|
|
160
|
+
waitForCondition(() => receivedMessageCounts[key as DhtAddress] >= routerNodes.length - 1, 30000)
|
|
187
161
|
)
|
|
188
162
|
)
|
|
189
163
|
|
|
@@ -194,22 +168,22 @@ describe('Route Message With Mock Connections', () => {
|
|
|
194
168
|
const closestPeersRequestMessage: Message = {
|
|
195
169
|
serviceId: 'unknown',
|
|
196
170
|
messageId: v4(),
|
|
197
|
-
messageType: MessageType.RPC,
|
|
198
171
|
body: {
|
|
199
172
|
oneofKind: 'rpcMessage',
|
|
200
173
|
rpcMessage: closestPeersRequest
|
|
201
174
|
},
|
|
202
|
-
sourceDescriptor: sourceNode.getLocalPeerDescriptor()
|
|
203
|
-
targetDescriptor: destinationNode.getLocalPeerDescriptor()
|
|
175
|
+
sourceDescriptor: sourceNode.getLocalPeerDescriptor(),
|
|
176
|
+
targetDescriptor: destinationNode.getLocalPeerDescriptor()
|
|
204
177
|
}
|
|
205
178
|
|
|
206
179
|
const routeMessageWrapper: RouteMessageWrapper = {
|
|
207
180
|
message: closestPeersRequestMessage,
|
|
208
|
-
|
|
181
|
+
target: destinationNode.getLocalPeerDescriptor().nodeId,
|
|
209
182
|
requestId: v4(),
|
|
210
183
|
sourcePeer: sourceNode.getLocalPeerDescriptor(),
|
|
211
184
|
reachableThrough: [entryPointDescriptor],
|
|
212
|
-
routingPath: []
|
|
185
|
+
routingPath: [],
|
|
186
|
+
parallelRootNodeIds: []
|
|
213
187
|
}
|
|
214
188
|
|
|
215
189
|
const rpcMessage: RpcMessage = {
|
|
@@ -224,22 +198,22 @@ describe('Route Message With Mock Connections', () => {
|
|
|
224
198
|
const requestMessage: Message = {
|
|
225
199
|
serviceId: 'layer0',
|
|
226
200
|
messageId: v4(),
|
|
227
|
-
messageType: MessageType.RPC,
|
|
228
201
|
body: {
|
|
229
202
|
oneofKind: 'rpcMessage',
|
|
230
203
|
rpcMessage
|
|
231
204
|
},
|
|
232
|
-
sourceDescriptor: sourceNode.getLocalPeerDescriptor()
|
|
233
|
-
targetDescriptor: entryPoint.getLocalPeerDescriptor()
|
|
205
|
+
sourceDescriptor: sourceNode.getLocalPeerDescriptor(),
|
|
206
|
+
targetDescriptor: entryPoint.getLocalPeerDescriptor()
|
|
234
207
|
}
|
|
235
208
|
|
|
236
209
|
const forwardedMessage: RouteMessageWrapper = {
|
|
237
210
|
message: requestMessage,
|
|
238
211
|
requestId: v4(),
|
|
239
212
|
sourcePeer: sourceNode.getLocalPeerDescriptor(),
|
|
240
|
-
|
|
213
|
+
target: entryPoint.getLocalPeerDescriptor().nodeId,
|
|
241
214
|
reachableThrough: [],
|
|
242
|
-
routingPath: []
|
|
215
|
+
routingPath: [],
|
|
216
|
+
parallelRootNodeIds: []
|
|
243
217
|
}
|
|
244
218
|
|
|
245
219
|
await runAndWaitForEvents3<DhtNodeEvents>([() => {
|
|
@@ -1,24 +1,20 @@
|
|
|
1
|
-
import { RpcCommunicator
|
|
1
|
+
import { RpcCommunicator } from '@streamr/proto-rpc'
|
|
2
2
|
import { RouterRpcRemote } from '../../src/dht/routing/RouterRpcRemote'
|
|
3
|
-
import { Message,
|
|
3
|
+
import { Message, RouteMessageAck, RouteMessageWrapper } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
4
4
|
import { RouterRpcClient } from '../../src/proto/packages/dht/protos/DhtRpc.client'
|
|
5
5
|
import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
|
|
6
|
-
import {
|
|
6
|
+
import { createMockPeerDescriptor, createWrappedClosestPeersRequest, mockRouterRpc } from '../utils/utils'
|
|
7
|
+
import { DhtCallContext } from '../../src/rpc-protocol/DhtCallContext'
|
|
8
|
+
|
|
9
|
+
const SERVICE_ID = 'test'
|
|
7
10
|
|
|
8
11
|
describe('RemoteRouter', () => {
|
|
9
12
|
|
|
10
13
|
let remoteRouter: RouterRpcRemote
|
|
11
|
-
let clientRpcCommunicator: RpcCommunicator
|
|
12
|
-
let serverRpcCommunicator: RpcCommunicator
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
kademliaId: generateId('client'),
|
|
16
|
-
type: NodeType.NODEJS
|
|
17
|
-
}
|
|
18
|
-
const serverPeerDescriptor: PeerDescriptor = {
|
|
19
|
-
kademliaId: generateId('server'),
|
|
20
|
-
type: NodeType.NODEJS
|
|
21
|
-
}
|
|
14
|
+
let clientRpcCommunicator: RpcCommunicator<DhtCallContext>
|
|
15
|
+
let serverRpcCommunicator: RpcCommunicator<DhtCallContext>
|
|
16
|
+
const clientPeerDescriptor = createMockPeerDescriptor()
|
|
17
|
+
const serverPeerDescriptor = createMockPeerDescriptor()
|
|
22
18
|
|
|
23
19
|
beforeEach(() => {
|
|
24
20
|
clientRpcCommunicator = new RpcCommunicator()
|
|
@@ -30,16 +26,14 @@ describe('RemoteRouter', () => {
|
|
|
30
26
|
serverRpcCommunicator.on('outgoingMessage', (message: RpcMessage) => {
|
|
31
27
|
clientRpcCommunicator.handleIncomingMessage(message)
|
|
32
28
|
})
|
|
33
|
-
|
|
34
|
-
remoteRouter = new RouterRpcRemote(clientPeerDescriptor, serverPeerDescriptor, serviceId, client)
|
|
29
|
+
remoteRouter = new RouterRpcRemote(clientPeerDescriptor, serverPeerDescriptor, clientRpcCommunicator, RouterRpcClient)
|
|
35
30
|
})
|
|
36
31
|
|
|
37
32
|
it('routeMessage happy path', async () => {
|
|
38
33
|
const rpcWrapper = createWrappedClosestPeersRequest(clientPeerDescriptor)
|
|
39
34
|
const routed: Message = {
|
|
40
|
-
serviceId,
|
|
35
|
+
serviceId: SERVICE_ID,
|
|
41
36
|
messageId: 'routed',
|
|
42
|
-
messageType: MessageType.RPC,
|
|
43
37
|
body: {
|
|
44
38
|
oneofKind: 'rpcMessage',
|
|
45
39
|
rpcMessage: rpcWrapper
|
|
@@ -49,9 +43,10 @@ describe('RemoteRouter', () => {
|
|
|
49
43
|
requestId: 'routed',
|
|
50
44
|
message: routed,
|
|
51
45
|
sourcePeer: clientPeerDescriptor,
|
|
52
|
-
|
|
46
|
+
target: serverPeerDescriptor.nodeId,
|
|
53
47
|
reachableThrough: [],
|
|
54
|
-
routingPath: []
|
|
48
|
+
routingPath: [],
|
|
49
|
+
parallelRootNodeIds: []
|
|
55
50
|
})
|
|
56
51
|
expect(routable).toEqual(true)
|
|
57
52
|
})
|
|
@@ -60,9 +55,8 @@ describe('RemoteRouter', () => {
|
|
|
60
55
|
serverRpcCommunicator.registerRpcMethod(RouteMessageWrapper, RouteMessageAck, 'routeMessage', mockRouterRpc.throwRouteMessageError)
|
|
61
56
|
const rpcWrapper = createWrappedClosestPeersRequest(clientPeerDescriptor)
|
|
62
57
|
const routed: Message = {
|
|
63
|
-
serviceId,
|
|
58
|
+
serviceId: SERVICE_ID,
|
|
64
59
|
messageId: 'routed',
|
|
65
|
-
messageType: MessageType.RPC,
|
|
66
60
|
body: {
|
|
67
61
|
oneofKind: 'rpcMessage',
|
|
68
62
|
rpcMessage: rpcWrapper
|
|
@@ -72,9 +66,10 @@ describe('RemoteRouter', () => {
|
|
|
72
66
|
requestId: 'routed',
|
|
73
67
|
message: routed,
|
|
74
68
|
sourcePeer: clientPeerDescriptor,
|
|
75
|
-
|
|
69
|
+
target: serverPeerDescriptor.nodeId,
|
|
76
70
|
reachableThrough: [],
|
|
77
|
-
routingPath: []
|
|
71
|
+
routingPath: [],
|
|
72
|
+
parallelRootNodeIds: []
|
|
78
73
|
})
|
|
79
74
|
expect(routable).toEqual(false)
|
|
80
75
|
})
|
|
@@ -2,35 +2,37 @@ import { LatencyType, Simulator } from '../../src/connection/simulator/Simulator
|
|
|
2
2
|
import { DhtNode } from '../../src/dht/DhtNode'
|
|
3
3
|
import { NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
4
4
|
import { createMockConnectionDhtNode } from '../utils/utils'
|
|
5
|
-
import { areEqualPeerDescriptors, getNodeIdFromPeerDescriptor } from '../../src/helpers/peerIdFromPeerDescriptor'
|
|
6
5
|
import { Logger } from '@streamr/utils'
|
|
6
|
+
import { getRandomRegion } from '../../src/connection/simulator/pings'
|
|
7
|
+
import { areEqualPeerDescriptors, createRandomDhtAddress, getNodeIdFromPeerDescriptor, getRawFromDhtAddress } from '../../src/identifiers'
|
|
7
8
|
|
|
8
9
|
const logger = new Logger(module)
|
|
9
10
|
|
|
11
|
+
const NUM_NODES = 80
|
|
12
|
+
const MAX_CONNECTIONS = 15
|
|
13
|
+
const K = 2
|
|
14
|
+
|
|
10
15
|
describe('Scaling down a Dht network', () => {
|
|
16
|
+
|
|
11
17
|
let entryPoint: DhtNode
|
|
12
18
|
let nodes: DhtNode[]
|
|
13
19
|
let entrypointDescriptor: PeerDescriptor
|
|
14
20
|
const simulator = new Simulator(LatencyType.REAL)
|
|
15
|
-
const NUM_NODES = 80
|
|
16
|
-
const MAX_CONNECTIONS = 15
|
|
17
|
-
const K = 2
|
|
18
21
|
|
|
19
22
|
beforeEach(async () => {
|
|
20
23
|
nodes = []
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
undefined, K, MAX_CONNECTIONS)
|
|
24
|
+
entryPoint = await createMockConnectionDhtNode(simulator,
|
|
25
|
+
createRandomDhtAddress(), K, MAX_CONNECTIONS)
|
|
24
26
|
nodes.push(entryPoint)
|
|
25
27
|
|
|
26
28
|
entrypointDescriptor = {
|
|
27
|
-
|
|
28
|
-
type: NodeType.NODEJS
|
|
29
|
+
nodeId: getRawFromDhtAddress(entryPoint.getNodeId()),
|
|
30
|
+
type: NodeType.NODEJS,
|
|
31
|
+
region: getRandomRegion()
|
|
29
32
|
}
|
|
30
33
|
|
|
31
34
|
for (let i = 1; i < NUM_NODES; i++) {
|
|
32
|
-
const
|
|
33
|
-
const node = await createMockConnectionDhtNode(nodeId, simulator, undefined, K, MAX_CONNECTIONS)
|
|
35
|
+
const node = await createMockConnectionDhtNode(simulator, undefined, K, MAX_CONNECTIONS)
|
|
34
36
|
nodes.push(node)
|
|
35
37
|
}
|
|
36
38
|
await Promise.all(nodes.map((node) => node.joinDht([entrypointDescriptor])))
|
|
@@ -52,7 +54,7 @@ describe('Scaling down a Dht network', () => {
|
|
|
52
54
|
const stoppingPeerDescriptor = nodes[nodeIndex].getLocalPeerDescriptor()
|
|
53
55
|
await nodes[nodeIndex].stop()
|
|
54
56
|
const nodeIsCleaned = nodes.every((node) =>
|
|
55
|
-
node.
|
|
57
|
+
node.getConnections().every((peer) => {
|
|
56
58
|
if (areEqualPeerDescriptors(peer, stoppingPeerDescriptor)) {
|
|
57
59
|
logger.error(getNodeIdFromPeerDescriptor(node.getLocalPeerDescriptor()) + ', '
|
|
58
60
|
+ getNodeIdFromPeerDescriptor(stoppingPeerDescriptor) + ' cleaning up failed')
|