@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,157 @@
|
|
|
1
|
+
import {
|
|
2
|
+
RecursiveOperation,
|
|
3
|
+
Message,
|
|
4
|
+
RouteMessageAck,
|
|
5
|
+
RouteMessageError,
|
|
6
|
+
RouteMessageWrapper,
|
|
7
|
+
RecursiveOperationRequest
|
|
8
|
+
} from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
9
|
+
import {
|
|
10
|
+
createWrappedClosestPeersRequest,
|
|
11
|
+
createMockPeerDescriptor
|
|
12
|
+
} from '../utils/utils'
|
|
13
|
+
import { RecursiveOperationManager } from '../../src/dht/recursive-operation/RecursiveOperationManager'
|
|
14
|
+
import { LocalDataStore } from '../../src/dht/store/LocalDataStore'
|
|
15
|
+
import { v4 } from 'uuid'
|
|
16
|
+
import { MockRouter } from '../utils/mock/Router'
|
|
17
|
+
import { MockTransport } from '../utils/mock/Transport'
|
|
18
|
+
import { FakeRpcCommunicator } from '../utils/FakeRpcCommunicator'
|
|
19
|
+
import { Router } from '../../src/dht/routing/Router'
|
|
20
|
+
import { ITransport } from '../../src/transport/ITransport'
|
|
21
|
+
import { areEqualPeerDescriptors, createRandomDhtAddress } from '../../src/identifiers'
|
|
22
|
+
|
|
23
|
+
const createMockRouter = (error?: RouteMessageError): Partial<Router> => {
|
|
24
|
+
return {
|
|
25
|
+
doRouteMessage: (routedMessage: RouteMessageWrapper) => {
|
|
26
|
+
return {
|
|
27
|
+
requestId: routedMessage.requestId,
|
|
28
|
+
error
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
isMostLikelyDuplicate: () => false,
|
|
32
|
+
addToDuplicateDetector: () => {}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const createRequest = (): RecursiveOperationRequest => {
|
|
37
|
+
const request: RecursiveOperationRequest = {
|
|
38
|
+
operation: RecursiveOperation.FIND_CLOSEST_NODES,
|
|
39
|
+
sessionId: v4()
|
|
40
|
+
}
|
|
41
|
+
return request
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
describe('RecursiveOperationManager', () => {
|
|
45
|
+
|
|
46
|
+
const peerDescriptor1 = createMockPeerDescriptor()
|
|
47
|
+
const peerDescriptor2 = createMockPeerDescriptor()
|
|
48
|
+
const recursiveOperationRequest = createRequest()
|
|
49
|
+
const message: Message = {
|
|
50
|
+
serviceId: 'unknown',
|
|
51
|
+
messageId: v4(),
|
|
52
|
+
body: {
|
|
53
|
+
oneofKind: 'recursiveOperationRequest',
|
|
54
|
+
recursiveOperationRequest
|
|
55
|
+
},
|
|
56
|
+
sourceDescriptor: peerDescriptor1,
|
|
57
|
+
targetDescriptor: peerDescriptor2
|
|
58
|
+
}
|
|
59
|
+
const routedMessage: RouteMessageWrapper = {
|
|
60
|
+
message,
|
|
61
|
+
requestId: 'REQ',
|
|
62
|
+
routingPath: [],
|
|
63
|
+
reachableThrough: [],
|
|
64
|
+
sourcePeer: peerDescriptor1,
|
|
65
|
+
target: peerDescriptor2.nodeId,
|
|
66
|
+
parallelRootNodeIds: []
|
|
67
|
+
}
|
|
68
|
+
const rpcCommunicator = new FakeRpcCommunicator()
|
|
69
|
+
|
|
70
|
+
const createRecursiveOperationManager = (
|
|
71
|
+
router: Router = new MockRouter() as any,
|
|
72
|
+
transport: ITransport = new MockTransport()
|
|
73
|
+
): RecursiveOperationManager => {
|
|
74
|
+
return new RecursiveOperationManager({
|
|
75
|
+
localPeerDescriptor: peerDescriptor1,
|
|
76
|
+
router,
|
|
77
|
+
connections: new Map(),
|
|
78
|
+
serviceId: 'RecursiveOperationManager',
|
|
79
|
+
localDataStore: new LocalDataStore(30 * 100),
|
|
80
|
+
sessionTransport: transport,
|
|
81
|
+
addContact: () => {},
|
|
82
|
+
rpcCommunicator: rpcCommunicator as any
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
it('RecursiveOperationManager server', async () => {
|
|
87
|
+
const recursiveOperationManager = createRecursiveOperationManager()
|
|
88
|
+
const res = await rpcCommunicator.callRpcMethod('routeRequest', routedMessage) as RouteMessageAck
|
|
89
|
+
expect(res.error).toBeUndefined()
|
|
90
|
+
recursiveOperationManager.stop()
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
it('find closest nodes returns self if no peers', async () => {
|
|
94
|
+
const recursiveOperationManager = createRecursiveOperationManager()
|
|
95
|
+
const res = await recursiveOperationManager.execute(createRandomDhtAddress(), RecursiveOperation.FIND_CLOSEST_NODES)
|
|
96
|
+
expect(areEqualPeerDescriptors(res.closestNodes[0], peerDescriptor1)).toEqual(true)
|
|
97
|
+
recursiveOperationManager.stop()
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
it('RecursiveOperationManager server throws if payload is not RecursiveOperationRequest', async () => {
|
|
101
|
+
const manager = createRecursiveOperationManager(new MockRouter() as any)
|
|
102
|
+
const rpcWrapper = createWrappedClosestPeersRequest(peerDescriptor1)
|
|
103
|
+
const badMessage: Message = {
|
|
104
|
+
serviceId: 'unknown',
|
|
105
|
+
messageId: v4(),
|
|
106
|
+
body: {
|
|
107
|
+
oneofKind: 'rpcMessage',
|
|
108
|
+
rpcMessage: rpcWrapper
|
|
109
|
+
},
|
|
110
|
+
sourceDescriptor: peerDescriptor1,
|
|
111
|
+
targetDescriptor: peerDescriptor2
|
|
112
|
+
}
|
|
113
|
+
await expect(() => rpcCommunicator.callRpcMethod('routeRequest', {
|
|
114
|
+
message: badMessage,
|
|
115
|
+
requestId: 'REQ',
|
|
116
|
+
routingPath: [],
|
|
117
|
+
reachableThrough: [],
|
|
118
|
+
target: peerDescriptor1.nodeId,
|
|
119
|
+
sourcePeer: peerDescriptor2
|
|
120
|
+
})).rejects.toThrow()
|
|
121
|
+
manager.stop()
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
it('no targets', async () => {
|
|
125
|
+
const router = createMockRouter(RouteMessageError.NO_TARGETS)
|
|
126
|
+
const send = jest.fn()
|
|
127
|
+
const transport = {
|
|
128
|
+
send,
|
|
129
|
+
on: () => {},
|
|
130
|
+
off: () => {}
|
|
131
|
+
}
|
|
132
|
+
const recursiveOperationManager = createRecursiveOperationManager(router as any, transport as any)
|
|
133
|
+
const ack = await rpcCommunicator.callRpcMethod('routeRequest', routedMessage)
|
|
134
|
+
expect(ack).toEqual({
|
|
135
|
+
requestId: routedMessage.requestId,
|
|
136
|
+
error: RouteMessageError.NO_TARGETS
|
|
137
|
+
})
|
|
138
|
+
expect(send).toHaveBeenCalledTimes(1)
|
|
139
|
+
recursiveOperationManager.stop()
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
it('error', async () => {
|
|
143
|
+
const router = createMockRouter(RouteMessageError.DUPLICATE)
|
|
144
|
+
const send = jest.fn()
|
|
145
|
+
const transport = {
|
|
146
|
+
send
|
|
147
|
+
}
|
|
148
|
+
const recursiveOperationManager = createRecursiveOperationManager(router as any, transport as any)
|
|
149
|
+
const ack = await rpcCommunicator.callRpcMethod('routeRequest', routedMessage)
|
|
150
|
+
expect(ack).toEqual({
|
|
151
|
+
requestId: routedMessage.requestId,
|
|
152
|
+
error: RouteMessageError.DUPLICATE
|
|
153
|
+
})
|
|
154
|
+
expect(send).not.toHaveBeenCalled()
|
|
155
|
+
recursiveOperationManager.stop()
|
|
156
|
+
})
|
|
157
|
+
})
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { waitForCondition } from '@streamr/utils'
|
|
2
|
+
import { range } from 'lodash'
|
|
3
|
+
import { RecursiveOperationSession } from '../../src/dht/recursive-operation/RecursiveOperationSession'
|
|
4
|
+
import { RecursiveOperationSessionRpcRemote } from '../../src/dht/recursive-operation/RecursiveOperationSessionRpcRemote'
|
|
5
|
+
import { ServiceID } from '../../src/types/ServiceID'
|
|
6
|
+
import { createRandomDhtAddress } from '../../src/identifiers'
|
|
7
|
+
import { Message, PeerDescriptor, RecursiveOperation } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
8
|
+
import { RecursiveOperationSessionRpcClient } from '../../src/proto/packages/dht/protos/DhtRpc.client'
|
|
9
|
+
import { RoutingRpcCommunicator } from '../../src/transport/RoutingRpcCommunicator'
|
|
10
|
+
import { FakeEnvironment } from '../utils/FakeTransport'
|
|
11
|
+
import { createMockPeerDescriptor } from '../utils/utils'
|
|
12
|
+
|
|
13
|
+
describe('RecursiveOperationSession', () => {
|
|
14
|
+
|
|
15
|
+
let environment: FakeEnvironment
|
|
16
|
+
let localPeerDescriptor: PeerDescriptor
|
|
17
|
+
|
|
18
|
+
const createRpcRemote = (serviceId: ServiceID) => {
|
|
19
|
+
const mockPeerDescriptor = createMockPeerDescriptor()
|
|
20
|
+
const transport = environment.createTransport(mockPeerDescriptor)
|
|
21
|
+
const send = (msg: Message) => transport.send(msg)
|
|
22
|
+
return new RecursiveOperationSessionRpcRemote(
|
|
23
|
+
mockPeerDescriptor,
|
|
24
|
+
localPeerDescriptor,
|
|
25
|
+
new RoutingRpcCommunicator(serviceId, send),
|
|
26
|
+
RecursiveOperationSessionRpcClient
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
beforeEach(() => {
|
|
31
|
+
environment = new FakeEnvironment()
|
|
32
|
+
localPeerDescriptor = createMockPeerDescriptor()
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it('happy path', async () => {
|
|
36
|
+
const doRouteRequest = jest.fn()
|
|
37
|
+
const session = new RecursiveOperationSession({
|
|
38
|
+
transport: environment.createTransport(localPeerDescriptor),
|
|
39
|
+
targetId: createRandomDhtAddress(),
|
|
40
|
+
localPeerDescriptor,
|
|
41
|
+
waitedRoutingPathCompletions: 3,
|
|
42
|
+
operation: RecursiveOperation.FIND_CLOSEST_NODES,
|
|
43
|
+
doRouteRequest
|
|
44
|
+
})
|
|
45
|
+
const onCompleted = jest.fn()
|
|
46
|
+
session.on('completed', onCompleted)
|
|
47
|
+
|
|
48
|
+
session.start('')
|
|
49
|
+
expect(doRouteRequest).toHaveBeenCalled()
|
|
50
|
+
range(3).forEach(() => {
|
|
51
|
+
const remote = createRpcRemote(session.getId())
|
|
52
|
+
remote.sendResponse(
|
|
53
|
+
[createMockPeerDescriptor(), createMockPeerDescriptor()],
|
|
54
|
+
[createMockPeerDescriptor(), createMockPeerDescriptor()],
|
|
55
|
+
[],
|
|
56
|
+
true
|
|
57
|
+
)
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
// TODO now waits for the 4s timeout, could setup test so that it completes by receiving
|
|
61
|
+
// all data it wants
|
|
62
|
+
await waitForCondition(() => onCompleted.mock.calls.length > 0)
|
|
63
|
+
const result = session.getResults()
|
|
64
|
+
// TODO assert peer descriptors
|
|
65
|
+
expect(result.closestNodes).toHaveLength(6)
|
|
66
|
+
expect(result.dataEntries).toEqual([])
|
|
67
|
+
})
|
|
68
|
+
})
|
package/test/unit/Router.test.ts
CHANGED
|
@@ -1,28 +1,27 @@
|
|
|
1
1
|
import { v4 } from 'uuid'
|
|
2
2
|
import { DhtNodeRpcRemote } from '../../src/dht/DhtNodeRpcRemote'
|
|
3
3
|
import { Router } from '../../src/dht/routing/Router'
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
import {
|
|
5
|
+
Message,
|
|
6
|
+
PeerDescriptor,
|
|
7
|
+
RouteMessageAck,
|
|
8
|
+
RouteMessageError,
|
|
9
|
+
RouteMessageWrapper
|
|
10
|
+
} from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
11
|
+
import { createMockPeerDescriptor, createWrappedClosestPeersRequest } from '../utils/utils'
|
|
7
12
|
import { FakeRpcCommunicator } from '../utils/FakeRpcCommunicator'
|
|
13
|
+
import { DhtAddress, getNodeIdFromPeerDescriptor, createRandomDhtAddress } from '../../src/identifiers'
|
|
14
|
+
import { MockRpcCommunicator } from '../utils/mock/MockRpcCommunicator'
|
|
8
15
|
|
|
9
16
|
describe('Router', () => {
|
|
10
|
-
let router: Router
|
|
11
17
|
|
|
12
|
-
|
|
13
|
-
const peerDescriptor1
|
|
14
|
-
|
|
15
|
-
type: NodeType.NODEJS
|
|
16
|
-
}
|
|
17
|
-
const peerDescriptor2: PeerDescriptor = {
|
|
18
|
-
kademliaId: PeerID.fromString('destination').value,
|
|
19
|
-
type: NodeType.NODEJS
|
|
20
|
-
}
|
|
18
|
+
let router: Router
|
|
19
|
+
const peerDescriptor1 = createMockPeerDescriptor()
|
|
20
|
+
const peerDescriptor2 = createMockPeerDescriptor()
|
|
21
21
|
const rpcWrapper = createWrappedClosestPeersRequest(peerDescriptor1)
|
|
22
22
|
const message: Message = {
|
|
23
23
|
serviceId: 'unknown',
|
|
24
24
|
messageId: v4(),
|
|
25
|
-
messageType: MessageType.RPC,
|
|
26
25
|
body: {
|
|
27
26
|
oneofKind: 'rpcMessage',
|
|
28
27
|
rpcMessage: rpcWrapper
|
|
@@ -35,14 +34,15 @@ describe('Router', () => {
|
|
|
35
34
|
requestId: 'REQ',
|
|
36
35
|
routingPath: [],
|
|
37
36
|
reachableThrough: [],
|
|
38
|
-
|
|
39
|
-
sourcePeer: peerDescriptor2
|
|
37
|
+
target: peerDescriptor1.nodeId,
|
|
38
|
+
sourcePeer: peerDescriptor2,
|
|
39
|
+
parallelRootNodeIds: []
|
|
40
40
|
}
|
|
41
|
-
let connections: Map<
|
|
41
|
+
let connections: Map<DhtAddress, DhtNodeRpcRemote>
|
|
42
42
|
const rpcCommunicator = new FakeRpcCommunicator()
|
|
43
43
|
|
|
44
44
|
const createMockDhtNodeRpcRemote = (destination: PeerDescriptor): DhtNodeRpcRemote => {
|
|
45
|
-
return new DhtNodeRpcRemote(peerDescriptor1, destination,
|
|
45
|
+
return new DhtNodeRpcRemote(peerDescriptor1, destination, undefined as any, new MockRpcCommunicator())
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
beforeEach(() => {
|
|
@@ -51,8 +51,8 @@ describe('Router', () => {
|
|
|
51
51
|
localPeerDescriptor: peerDescriptor1,
|
|
52
52
|
rpcCommunicator: rpcCommunicator as any,
|
|
53
53
|
addContact: (_contact) => {},
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
connections,
|
|
55
|
+
handleMessage: () => {}
|
|
56
56
|
})
|
|
57
57
|
})
|
|
58
58
|
|
|
@@ -63,59 +63,76 @@ describe('Router', () => {
|
|
|
63
63
|
it('doRouteMessage without connections', async () => {
|
|
64
64
|
const ack = await rpcCommunicator.callRpcMethod('routeMessage', {
|
|
65
65
|
message,
|
|
66
|
-
|
|
66
|
+
target: peerDescriptor2.nodeId,
|
|
67
67
|
requestId: v4(),
|
|
68
68
|
sourcePeer: peerDescriptor1,
|
|
69
69
|
reachableThrough: [],
|
|
70
|
-
routingPath: []
|
|
70
|
+
routingPath: [],
|
|
71
|
+
parallelRootNodeIds: []
|
|
71
72
|
}) as RouteMessageAck
|
|
72
|
-
expect(ack.error).toEqual(
|
|
73
|
+
expect(ack.error).toEqual(RouteMessageError.NO_TARGETS)
|
|
73
74
|
})
|
|
74
75
|
|
|
75
76
|
it('doRouteMessage with connections', async () => {
|
|
76
|
-
connections.set(
|
|
77
|
+
connections.set(createRandomDhtAddress(), createMockDhtNodeRpcRemote(peerDescriptor2))
|
|
78
|
+
const ack = await rpcCommunicator.callRpcMethod('routeMessage', {
|
|
79
|
+
message,
|
|
80
|
+
target: peerDescriptor2.nodeId,
|
|
81
|
+
requestId: v4(),
|
|
82
|
+
sourcePeer: peerDescriptor1,
|
|
83
|
+
reachableThrough: [],
|
|
84
|
+
routingPath: [],
|
|
85
|
+
parallelRootNodeIds: []
|
|
86
|
+
}) as RouteMessageAck
|
|
87
|
+
expect(ack.error).toBeUndefined()
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
it('doRouteMessage with parallelRootNodeIds', async () => {
|
|
91
|
+
const nodeId = getNodeIdFromPeerDescriptor(peerDescriptor2)
|
|
92
|
+
connections.set(nodeId, createMockDhtNodeRpcRemote(peerDescriptor2))
|
|
77
93
|
const ack = await rpcCommunicator.callRpcMethod('routeMessage', {
|
|
78
94
|
message,
|
|
79
|
-
|
|
95
|
+
target: peerDescriptor2.nodeId,
|
|
80
96
|
requestId: v4(),
|
|
81
97
|
sourcePeer: peerDescriptor1,
|
|
82
98
|
reachableThrough: [],
|
|
83
|
-
routingPath: []
|
|
99
|
+
routingPath: [],
|
|
100
|
+
parallelRootNodeIds: [nodeId]
|
|
84
101
|
}) as RouteMessageAck
|
|
85
|
-
expect(ack.error).toEqual(
|
|
102
|
+
expect(ack.error).toEqual(RouteMessageError.NO_TARGETS)
|
|
86
103
|
})
|
|
87
104
|
|
|
88
105
|
it('route server is destination without connections', async () => {
|
|
89
106
|
const ack = await rpcCommunicator.callRpcMethod('routeMessage', routedMessage) as RouteMessageAck
|
|
90
|
-
expect(ack.error).
|
|
107
|
+
expect(ack.error).toBeUndefined()
|
|
91
108
|
})
|
|
92
109
|
|
|
93
110
|
it('route server with connections', async () => {
|
|
94
|
-
connections.set(
|
|
111
|
+
connections.set(createRandomDhtAddress(), createMockDhtNodeRpcRemote(peerDescriptor2))
|
|
95
112
|
const ack = await rpcCommunicator.callRpcMethod('routeMessage', routedMessage) as RouteMessageAck
|
|
96
|
-
expect(ack.error).
|
|
113
|
+
expect(ack.error).toBeUndefined()
|
|
97
114
|
})
|
|
98
115
|
|
|
99
116
|
it('route server on duplicate message', async () => {
|
|
100
117
|
router.addToDuplicateDetector(routedMessage.requestId)
|
|
101
118
|
const ack = await rpcCommunicator.callRpcMethod('routeMessage', routedMessage) as RouteMessageAck
|
|
102
|
-
expect(ack.error).toEqual(
|
|
119
|
+
expect(ack.error).toEqual(RouteMessageError.DUPLICATE)
|
|
103
120
|
})
|
|
104
121
|
|
|
105
122
|
it('forward server no connections', async () => {
|
|
106
123
|
const ack = await rpcCommunicator.callRpcMethod('forwardMessage', routedMessage) as RouteMessageAck
|
|
107
|
-
expect(ack.error).toEqual(
|
|
124
|
+
expect(ack.error).toEqual(RouteMessageError.NO_TARGETS)
|
|
108
125
|
})
|
|
109
126
|
|
|
110
127
|
it('forward server with connections', async () => {
|
|
111
|
-
connections.set(
|
|
128
|
+
connections.set(createRandomDhtAddress(), createMockDhtNodeRpcRemote(peerDescriptor2))
|
|
112
129
|
const ack = await rpcCommunicator.callRpcMethod('forwardMessage', routedMessage) as RouteMessageAck
|
|
113
|
-
expect(ack.error).
|
|
130
|
+
expect(ack.error).toBeUndefined()
|
|
114
131
|
})
|
|
115
132
|
|
|
116
133
|
it('forward server on duplicate message', async () => {
|
|
117
134
|
router.addToDuplicateDetector(routedMessage.requestId)
|
|
118
135
|
const ack = await rpcCommunicator.callRpcMethod('forwardMessage', routedMessage) as RouteMessageAck
|
|
119
|
-
expect(ack.error).toEqual(
|
|
136
|
+
expect(ack.error).toEqual(RouteMessageError.DUPLICATE)
|
|
120
137
|
})
|
|
121
138
|
})
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { v4 } from 'uuid'
|
|
2
|
+
import { RoutingMode, RoutingSession } from '../../src/dht/routing/RoutingSession'
|
|
3
|
+
import { Message, PeerDescriptor, RouteMessageWrapper } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
4
|
+
import { createMockPeerDescriptor, createWrappedClosestPeersRequest } from '../utils/utils'
|
|
5
|
+
import { DhtNodeRpcRemote } from '../../src/dht/DhtNodeRpcRemote'
|
|
6
|
+
import { RoutingRpcCommunicator } from '../../src/transport/RoutingRpcCommunicator'
|
|
7
|
+
import { DhtAddress, getNodeIdFromPeerDescriptor } from '../../src/identifiers'
|
|
8
|
+
import { MockRpcCommunicator } from '../utils/mock/MockRpcCommunicator'
|
|
9
|
+
import { RoutingTablesCache } from '../../src/dht/routing/RoutingTablesCache'
|
|
10
|
+
|
|
11
|
+
describe('RoutingSession', () => {
|
|
12
|
+
|
|
13
|
+
let session: RoutingSession
|
|
14
|
+
let connections: Map<DhtAddress, DhtNodeRpcRemote>
|
|
15
|
+
let rpcCommunicator: RoutingRpcCommunicator
|
|
16
|
+
let routingTablesCache: RoutingTablesCache
|
|
17
|
+
const mockPeerDescriptor1 = createMockPeerDescriptor()
|
|
18
|
+
const mockPeerDescriptor2 = createMockPeerDescriptor()
|
|
19
|
+
const rpcWrapper = createWrappedClosestPeersRequest(mockPeerDescriptor1)
|
|
20
|
+
const message: Message = {
|
|
21
|
+
serviceId: 'unknown',
|
|
22
|
+
messageId: v4(),
|
|
23
|
+
body: {
|
|
24
|
+
oneofKind: 'rpcMessage',
|
|
25
|
+
rpcMessage: rpcWrapper
|
|
26
|
+
},
|
|
27
|
+
sourceDescriptor: mockPeerDescriptor1,
|
|
28
|
+
targetDescriptor: mockPeerDescriptor2
|
|
29
|
+
}
|
|
30
|
+
const routedMessage: RouteMessageWrapper = {
|
|
31
|
+
message,
|
|
32
|
+
requestId: 'REQ',
|
|
33
|
+
routingPath: [],
|
|
34
|
+
reachableThrough: [],
|
|
35
|
+
target: mockPeerDescriptor1.nodeId,
|
|
36
|
+
sourcePeer: mockPeerDescriptor2,
|
|
37
|
+
parallelRootNodeIds: []
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const createMockDhtNodeRpcRemote = (destination: PeerDescriptor): DhtNodeRpcRemote => {
|
|
41
|
+
return new DhtNodeRpcRemote(mockPeerDescriptor1, destination, undefined as any, rpcCommunicator)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
beforeEach(() => {
|
|
45
|
+
rpcCommunicator = new MockRpcCommunicator()
|
|
46
|
+
connections = new Map()
|
|
47
|
+
routingTablesCache = new RoutingTablesCache()
|
|
48
|
+
session = new RoutingSession({
|
|
49
|
+
rpcCommunicator: rpcCommunicator,
|
|
50
|
+
localPeerDescriptor: mockPeerDescriptor1,
|
|
51
|
+
routedMessage,
|
|
52
|
+
connections,
|
|
53
|
+
parallelism: 2,
|
|
54
|
+
mode: RoutingMode.ROUTE,
|
|
55
|
+
excludedNodeIds: new Set(),
|
|
56
|
+
routingTablesCache
|
|
57
|
+
})
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
afterEach(() => {
|
|
61
|
+
rpcCommunicator.stop()
|
|
62
|
+
session.stop()
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
it('findMoreContacts', () => {
|
|
66
|
+
connections.set(getNodeIdFromPeerDescriptor(mockPeerDescriptor2), createMockDhtNodeRpcRemote(mockPeerDescriptor2))
|
|
67
|
+
const contacts = session.updateAndGetRoutablePeers()
|
|
68
|
+
expect(contacts.length).toBe(1)
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
it('findMoreContacts peer disconnects', () => {
|
|
72
|
+
connections.set(getNodeIdFromPeerDescriptor(mockPeerDescriptor2), createMockDhtNodeRpcRemote(mockPeerDescriptor2))
|
|
73
|
+
expect(session.updateAndGetRoutablePeers().length).toBe(1)
|
|
74
|
+
connections.delete(getNodeIdFromPeerDescriptor(mockPeerDescriptor2))
|
|
75
|
+
routingTablesCache.onNodeDisconnected(getNodeIdFromPeerDescriptor(mockPeerDescriptor2))
|
|
76
|
+
expect(session.updateAndGetRoutablePeers().length).toBe(0)
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
})
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { SortedContactList } from '../../src/dht/contact/SortedContactList'
|
|
2
|
-
import {
|
|
2
|
+
import { DhtAddress, DhtAddressRaw, createRandomDhtAddress, getDhtAddressFromRaw } from '../../src/identifiers'
|
|
3
3
|
|
|
4
|
-
const createItem = (
|
|
5
|
-
return {
|
|
4
|
+
const createItem = (nodeId: DhtAddressRaw): { getNodeId: () => DhtAddress } => {
|
|
5
|
+
return {
|
|
6
|
+
getNodeId: () => getDhtAddressFromRaw(nodeId)
|
|
7
|
+
}
|
|
6
8
|
}
|
|
7
9
|
|
|
8
10
|
describe('SortedContactList', () => {
|
|
11
|
+
|
|
9
12
|
const item0 = createItem(new Uint8Array([0, 0, 0, 0]))
|
|
10
13
|
const item1 = createItem(new Uint8Array([0, 0, 0, 1]))
|
|
11
14
|
const item2 = createItem(new Uint8Array([0, 0, 0, 2]))
|
|
@@ -13,19 +16,19 @@ describe('SortedContactList', () => {
|
|
|
13
16
|
const item4 = createItem(new Uint8Array([0, 0, 0, 4]))
|
|
14
17
|
|
|
15
18
|
it('compares Ids correctly', async () => {
|
|
16
|
-
const list = new SortedContactList(item0.
|
|
17
|
-
expect(list.compareIds(item0.
|
|
18
|
-
expect(list.compareIds(item1.
|
|
19
|
-
expect(list.compareIds(item0.
|
|
20
|
-
expect(list.compareIds(item0.
|
|
21
|
-
expect(list.compareIds(item1.
|
|
22
|
-
expect(list.compareIds(item2.
|
|
23
|
-
expect(list.compareIds(item2.
|
|
24
|
-
expect(list.compareIds(item1.
|
|
19
|
+
const list = new SortedContactList({ referenceId: item0.getNodeId(), maxSize: 10, allowToContainReferenceId: true, emitEvents: false })
|
|
20
|
+
expect(list.compareIds(item0.getNodeId(), item0.getNodeId())).toBe(0)
|
|
21
|
+
expect(list.compareIds(item1.getNodeId(), item1.getNodeId())).toBe(0)
|
|
22
|
+
expect(list.compareIds(item0.getNodeId(), item1.getNodeId())).toBe(-1)
|
|
23
|
+
expect(list.compareIds(item0.getNodeId(), item2.getNodeId())).toBe(-2)
|
|
24
|
+
expect(list.compareIds(item1.getNodeId(), item0.getNodeId())).toBe(1)
|
|
25
|
+
expect(list.compareIds(item2.getNodeId(), item0.getNodeId())).toBe(2)
|
|
26
|
+
expect(list.compareIds(item2.getNodeId(), item3.getNodeId())).toBe(-1)
|
|
27
|
+
expect(list.compareIds(item1.getNodeId(), item4.getNodeId())).toBe(-3)
|
|
25
28
|
})
|
|
26
|
-
|
|
29
|
+
|
|
27
30
|
it('orders itself correctly', async () => {
|
|
28
|
-
const list = new SortedContactList(item0.
|
|
31
|
+
const list = new SortedContactList({ referenceId: item0.getNodeId(), maxSize: 10, allowToContainReferenceId: true, emitEvents: false })
|
|
29
32
|
list.addContact(item3)
|
|
30
33
|
list.addContact(item2)
|
|
31
34
|
list.addContact(item1)
|
|
@@ -35,13 +38,13 @@ describe('SortedContactList', () => {
|
|
|
35
38
|
expect(contacts[1]).toEqual(item2)
|
|
36
39
|
expect(contacts[2]).toEqual(item3)
|
|
37
40
|
})
|
|
38
|
-
|
|
41
|
+
|
|
39
42
|
it('handles contacted nodes correctly', async () => {
|
|
40
|
-
const list = new SortedContactList(item0.
|
|
43
|
+
const list = new SortedContactList({ referenceId: item0.getNodeId(), maxSize: 10, allowToContainReferenceId: false, emitEvents: false })
|
|
41
44
|
list.addContact(item3)
|
|
42
45
|
list.addContact(item2)
|
|
43
46
|
list.addContact(item1)
|
|
44
|
-
list.setContacted(item2.
|
|
47
|
+
list.setContacted(item2.getNodeId())
|
|
45
48
|
const contacts = list.getUncontactedContacts(3)
|
|
46
49
|
expect(contacts.length).toEqual(2)
|
|
47
50
|
expect(contacts[0]).toEqual(item1)
|
|
@@ -49,7 +52,7 @@ describe('SortedContactList', () => {
|
|
|
49
52
|
})
|
|
50
53
|
|
|
51
54
|
it('cannot exceed maxSize', async () => {
|
|
52
|
-
const list = new SortedContactList(item0.
|
|
55
|
+
const list = new SortedContactList({ referenceId: item0.getNodeId(), maxSize: 3, allowToContainReferenceId: false, emitEvents: true })
|
|
53
56
|
const onContactRemoved = jest.fn()
|
|
54
57
|
list.on('contactRemoved', onContactRemoved)
|
|
55
58
|
list.addContact(item1)
|
|
@@ -57,30 +60,45 @@ describe('SortedContactList', () => {
|
|
|
57
60
|
list.addContact(item3)
|
|
58
61
|
list.addContact(item2)
|
|
59
62
|
expect(list.getSize()).toEqual(3)
|
|
63
|
+
expect(list.getAllContacts()).toEqual([item1, item2, item3])
|
|
64
|
+
expect(list.getContactIds()).toEqual([item1.getNodeId(), item2.getNodeId(), item3.getNodeId()])
|
|
60
65
|
expect(onContactRemoved).toBeCalledWith(item4, [item1, item2, item3])
|
|
61
|
-
expect(list.getContact(item4.
|
|
66
|
+
expect(list.getContact(item4.getNodeId())).toBeFalsy()
|
|
62
67
|
})
|
|
63
68
|
|
|
64
69
|
it('removing contacts', async () => {
|
|
65
|
-
const list = new SortedContactList(item0.
|
|
70
|
+
const list = new SortedContactList({ referenceId: item0.getNodeId(), maxSize: 8, allowToContainReferenceId: false, emitEvents: true })
|
|
66
71
|
const onContactRemoved = jest.fn()
|
|
67
72
|
list.on('contactRemoved', onContactRemoved)
|
|
73
|
+
list.removeContact(createRandomDhtAddress())
|
|
74
|
+
list.addContact(item3)
|
|
75
|
+
list.removeContact(item3.getNodeId())
|
|
68
76
|
list.addContact(item4)
|
|
69
77
|
list.addContact(item3)
|
|
70
78
|
list.addContact(item2)
|
|
71
79
|
list.addContact(item1)
|
|
72
|
-
list.removeContact(item2.
|
|
80
|
+
list.removeContact(item2.getNodeId())
|
|
73
81
|
expect(list.getSize()).toEqual(3)
|
|
74
|
-
expect(list.getContact(item2.
|
|
82
|
+
expect(list.getContact(item2.getNodeId())).toBeFalsy()
|
|
75
83
|
expect(list.getContactIds()).toEqual(list.getContactIds().sort(list.compareIds))
|
|
76
84
|
expect(list.getAllContacts()).toEqual([item1, item3, item4])
|
|
77
|
-
|
|
78
|
-
const ret = list.removeContact(PeerID.fromValue(Buffer.from([0, 0, 0, 6])))
|
|
85
|
+
const ret = list.removeContact(getDhtAddressFromRaw(Buffer.from([0, 0, 0, 6])))
|
|
79
86
|
expect(ret).toEqual(false)
|
|
87
|
+
list.removeContact(item3.getNodeId())
|
|
88
|
+
list.removeContact(createRandomDhtAddress())
|
|
89
|
+
expect(list.getAllContacts()).toEqual([item1, item4])
|
|
90
|
+
expect(onContactRemoved).toHaveBeenNthCalledWith(1, item3, [])
|
|
91
|
+
expect(onContactRemoved).toHaveBeenNthCalledWith(2, item2, [item1, item3, item4])
|
|
92
|
+
expect(onContactRemoved).toHaveBeenNthCalledWith(3, item3, [item1, item4])
|
|
80
93
|
})
|
|
81
94
|
|
|
82
|
-
it('get
|
|
83
|
-
const list = new SortedContactList(
|
|
95
|
+
it('get closest contacts', () => {
|
|
96
|
+
const list = new SortedContactList({
|
|
97
|
+
referenceId: item0.getNodeId(),
|
|
98
|
+
maxSize: 8,
|
|
99
|
+
allowToContainReferenceId: false,
|
|
100
|
+
emitEvents: false
|
|
101
|
+
})
|
|
84
102
|
list.addContact(item1)
|
|
85
103
|
list.addContact(item3)
|
|
86
104
|
list.addContact(item4)
|
|
@@ -90,14 +108,27 @@ describe('SortedContactList', () => {
|
|
|
90
108
|
})
|
|
91
109
|
|
|
92
110
|
it('get active contacts', () => {
|
|
93
|
-
const list = new SortedContactList(item0.
|
|
111
|
+
const list = new SortedContactList({ referenceId: item0.getNodeId(), maxSize: 8, allowToContainReferenceId: false, emitEvents: false })
|
|
94
112
|
list.addContact(item1)
|
|
95
113
|
list.addContact(item3)
|
|
96
114
|
list.addContact(item4)
|
|
97
115
|
list.addContact(item2)
|
|
98
|
-
list.setActive(item2.
|
|
99
|
-
list.setActive(item3.
|
|
100
|
-
list.setActive(item4.
|
|
116
|
+
list.setActive(item2.getNodeId())
|
|
117
|
+
list.setActive(item3.getNodeId())
|
|
118
|
+
list.setActive(item4.getNodeId())
|
|
101
119
|
expect(list.getActiveContacts()).toEqual([item2, item3, item4])
|
|
102
120
|
})
|
|
121
|
+
|
|
122
|
+
it('does not emit contactAdded if contact did not fit the structure', () => {
|
|
123
|
+
const list = new SortedContactList({ referenceId: item0.getNodeId(), maxSize: 2, allowToContainReferenceId: false, emitEvents: true })
|
|
124
|
+
const onContactAdded = jest.fn()
|
|
125
|
+
list.on('contactAdded', onContactAdded)
|
|
126
|
+
list.addContact(item1)
|
|
127
|
+
list.addContact(item2)
|
|
128
|
+
expect(onContactAdded).toBeCalledTimes(2)
|
|
129
|
+
list.addContact(item3)
|
|
130
|
+
expect(onContactAdded).toBeCalledTimes(2)
|
|
131
|
+
expect(list.getAllContacts().length).toEqual(2)
|
|
132
|
+
})
|
|
133
|
+
|
|
103
134
|
})
|