@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,138 @@
|
|
|
1
|
+
import { wait, waitForCondition } from '@streamr/utils'
|
|
2
|
+
import { range, sortBy } from 'lodash'
|
|
3
|
+
import { getDistance } from '../../src/dht/PeerManager'
|
|
4
|
+
import { StoreManager } from '../../src/dht/store/StoreManager'
|
|
5
|
+
import {
|
|
6
|
+
DhtAddress,
|
|
7
|
+
createRandomDhtAddress,
|
|
8
|
+
getDhtAddressFromRaw,
|
|
9
|
+
getRawFromDhtAddress,
|
|
10
|
+
} from '../../src/identifiers'
|
|
11
|
+
import { NodeType, ReplicateDataRequest } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
12
|
+
|
|
13
|
+
const DATA_ENTRY = {
|
|
14
|
+
key: getRawFromDhtAddress(createRandomDhtAddress()),
|
|
15
|
+
creator: getRawFromDhtAddress(createRandomDhtAddress())
|
|
16
|
+
}
|
|
17
|
+
const NODES_CLOSEST_TO_DATA = sortBy(
|
|
18
|
+
range(5).map(() => createRandomDhtAddress()),
|
|
19
|
+
(id: DhtAddress) => getDistance(getRawFromDhtAddress(id), DATA_ENTRY.key)
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
describe('StoreManager', () => {
|
|
23
|
+
|
|
24
|
+
describe('new contact', () => {
|
|
25
|
+
|
|
26
|
+
const createStoreManager = (
|
|
27
|
+
localNodeId: DhtAddress,
|
|
28
|
+
closestNeighbors: DhtAddress[],
|
|
29
|
+
replicateData: (request: ReplicateDataRequest) => unknown,
|
|
30
|
+
setAllEntriesAsStale: (key: DhtAddress) => unknown
|
|
31
|
+
): StoreManager => {
|
|
32
|
+
const getClosestNeighborsTo = () => {
|
|
33
|
+
return closestNeighbors.map((nodeId) => ({ nodeId: getRawFromDhtAddress(nodeId), type: NodeType.NODEJS }))
|
|
34
|
+
}
|
|
35
|
+
return new StoreManager({
|
|
36
|
+
rpcCommunicator: {
|
|
37
|
+
registerRpcMethod: () => {},
|
|
38
|
+
registerRpcNotification: () => {}
|
|
39
|
+
} as any,
|
|
40
|
+
recursiveOperationManager: undefined as any,
|
|
41
|
+
localPeerDescriptor: { nodeId: getRawFromDhtAddress(localNodeId), type: NodeType.NODEJS },
|
|
42
|
+
localDataStore: {
|
|
43
|
+
keys: () => [getDhtAddressFromRaw(DATA_ENTRY.key)],
|
|
44
|
+
values: () => [DATA_ENTRY],
|
|
45
|
+
setAllEntriesAsStale
|
|
46
|
+
} as any,
|
|
47
|
+
serviceId: undefined as any,
|
|
48
|
+
highestTtl: undefined as any,
|
|
49
|
+
redundancyFactor: 3,
|
|
50
|
+
getClosestNeighborsTo,
|
|
51
|
+
createRpcRemote: () => ({ replicateData } as any)
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
describe('this node is primary storer', () => {
|
|
56
|
+
|
|
57
|
+
it('new node is within redundancy factor', async () => {
|
|
58
|
+
const replicateData = jest.fn<undefined, [ReplicateDataRequest]>()
|
|
59
|
+
const setAllEntriesAsStale = jest.fn<undefined, [DhtAddress]>()
|
|
60
|
+
const manager = createStoreManager(
|
|
61
|
+
NODES_CLOSEST_TO_DATA[0],
|
|
62
|
+
[NODES_CLOSEST_TO_DATA[1], NODES_CLOSEST_TO_DATA[3], NODES_CLOSEST_TO_DATA[4]],
|
|
63
|
+
replicateData,
|
|
64
|
+
setAllEntriesAsStale
|
|
65
|
+
)
|
|
66
|
+
manager.onContactAdded({ nodeId: getRawFromDhtAddress(NODES_CLOSEST_TO_DATA[2]), type: NodeType.NODEJS })
|
|
67
|
+
await waitForCondition(() => replicateData.mock.calls.length === 1)
|
|
68
|
+
expect(replicateData).toHaveBeenCalledWith({
|
|
69
|
+
entry: DATA_ENTRY
|
|
70
|
+
})
|
|
71
|
+
expect(setAllEntriesAsStale).not.toHaveBeenCalled()
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
it('new node is not within redundancy factor', async () => {
|
|
75
|
+
const replicateData = jest.fn<undefined, [ReplicateDataRequest]>()
|
|
76
|
+
const setAllEntriesAsStale = jest.fn<undefined, [DhtAddress]>()
|
|
77
|
+
const manager = createStoreManager(
|
|
78
|
+
NODES_CLOSEST_TO_DATA[0],
|
|
79
|
+
[NODES_CLOSEST_TO_DATA[1], NODES_CLOSEST_TO_DATA[2], NODES_CLOSEST_TO_DATA[3]],
|
|
80
|
+
replicateData,
|
|
81
|
+
setAllEntriesAsStale
|
|
82
|
+
)
|
|
83
|
+
manager.onContactAdded({ nodeId: getRawFromDhtAddress(NODES_CLOSEST_TO_DATA[4]), type: NodeType.NODEJS })
|
|
84
|
+
await wait(50)
|
|
85
|
+
expect(replicateData).not.toHaveBeenCalled()
|
|
86
|
+
expect(setAllEntriesAsStale).not.toHaveBeenCalled()
|
|
87
|
+
})
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
describe('this node is not primary storer', () => {
|
|
91
|
+
|
|
92
|
+
it('this node is within redundancy factor', async () => {
|
|
93
|
+
const replicateData = jest.fn<undefined, [ReplicateDataRequest]>()
|
|
94
|
+
const setAllEntriesAsStale = jest.fn<undefined, [DhtAddress]>()
|
|
95
|
+
const manager = createStoreManager(
|
|
96
|
+
NODES_CLOSEST_TO_DATA[1],
|
|
97
|
+
[NODES_CLOSEST_TO_DATA[0], NODES_CLOSEST_TO_DATA[2], NODES_CLOSEST_TO_DATA[3]],
|
|
98
|
+
replicateData,
|
|
99
|
+
setAllEntriesAsStale
|
|
100
|
+
)
|
|
101
|
+
manager.onContactAdded({ nodeId: getRawFromDhtAddress(NODES_CLOSEST_TO_DATA[4]), type: NodeType.NODEJS })
|
|
102
|
+
await wait(50)
|
|
103
|
+
expect(replicateData).not.toHaveBeenCalled()
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
it('this node is not within redundancy factor', async () => {
|
|
107
|
+
const replicateData = jest.fn<undefined, [ReplicateDataRequest]>()
|
|
108
|
+
const setAllEntriesAsStale = jest.fn<undefined, [DhtAddress]>()
|
|
109
|
+
const manager = createStoreManager(
|
|
110
|
+
NODES_CLOSEST_TO_DATA[3],
|
|
111
|
+
[NODES_CLOSEST_TO_DATA[0], NODES_CLOSEST_TO_DATA[1], NODES_CLOSEST_TO_DATA[2]],
|
|
112
|
+
replicateData,
|
|
113
|
+
setAllEntriesAsStale
|
|
114
|
+
)
|
|
115
|
+
manager.onContactAdded({ nodeId: getRawFromDhtAddress(NODES_CLOSEST_TO_DATA[4]), type: NodeType.NODEJS })
|
|
116
|
+
await wait(50)
|
|
117
|
+
expect(replicateData).not.toHaveBeenCalled()
|
|
118
|
+
expect(setAllEntriesAsStale).toHaveBeenCalledTimes(1)
|
|
119
|
+
expect(setAllEntriesAsStale).toHaveBeenCalledWith(getDhtAddressFromRaw(DATA_ENTRY.key))
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
it('this node has less than redundancyFactor neighbors', async () => {
|
|
123
|
+
const replicateData = jest.fn<undefined, [ReplicateDataRequest]>()
|
|
124
|
+
const setAllEntriesAsStale = jest.fn<undefined, [DhtAddress]>()
|
|
125
|
+
const manager = createStoreManager(
|
|
126
|
+
NODES_CLOSEST_TO_DATA[3],
|
|
127
|
+
[NODES_CLOSEST_TO_DATA[0], NODES_CLOSEST_TO_DATA[1]],
|
|
128
|
+
replicateData,
|
|
129
|
+
setAllEntriesAsStale
|
|
130
|
+
)
|
|
131
|
+
manager.onContactAdded({ nodeId: getRawFromDhtAddress(NODES_CLOSEST_TO_DATA[4]), type: NodeType.NODEJS })
|
|
132
|
+
await wait(50)
|
|
133
|
+
expect(replicateData).not.toHaveBeenCalled()
|
|
134
|
+
expect(setAllEntriesAsStale).toHaveBeenCalledTimes(0)
|
|
135
|
+
})
|
|
136
|
+
})
|
|
137
|
+
})
|
|
138
|
+
})
|
|
@@ -1,16 +1,8 @@
|
|
|
1
1
|
/* eslint-disable max-len */
|
|
2
2
|
import { WebsocketConnector } from '../../src/connection/websocket/WebsocketConnector'
|
|
3
|
-
import {
|
|
4
|
-
import crypto from 'crypto'
|
|
3
|
+
import { NodeType } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
5
4
|
import { MockTransport } from '../utils/mock/Transport'
|
|
6
|
-
|
|
7
|
-
const createMockPeerDescriptor = (nodeType: NodeType, websocket?: ConnectivityMethod): PeerDescriptor => {
|
|
8
|
-
return {
|
|
9
|
-
kademliaId: crypto.randomBytes(10),
|
|
10
|
-
type: nodeType,
|
|
11
|
-
websocket
|
|
12
|
-
}
|
|
13
|
-
}
|
|
5
|
+
import { createMockPeerDescriptor } from '../utils/utils'
|
|
14
6
|
|
|
15
7
|
describe('WebsocketConnector', () => {
|
|
16
8
|
|
|
@@ -22,43 +14,43 @@ describe('WebsocketConnector', () => {
|
|
|
22
14
|
} as any)
|
|
23
15
|
|
|
24
16
|
it('node without server', () => {
|
|
25
|
-
connector.setLocalPeerDescriptor(createMockPeerDescriptor(NodeType.NODEJS))
|
|
26
|
-
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor(NodeType.NODEJS, { host: '2.2.2.2', port: 22, tls: false }))).toBe(true)
|
|
27
|
-
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor(NodeType.NODEJS, { host: '2.2.2.2', port: 22, tls: true }))).toBe(true)
|
|
28
|
-
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor(NodeType.NODEJS))).toBe(false)
|
|
29
|
-
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor(NodeType.BROWSER))).toBe(false)
|
|
17
|
+
connector.setLocalPeerDescriptor(createMockPeerDescriptor({ type: NodeType.NODEJS }))
|
|
18
|
+
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor({ type: NodeType.NODEJS, websocket: { host: '2.2.2.2', port: 22, tls: false } }))).toBe(true)
|
|
19
|
+
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor({ type: NodeType.NODEJS, websocket: { host: '2.2.2.2', port: 22, tls: true } }))).toBe(true)
|
|
20
|
+
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor({ type: NodeType.NODEJS }))).toBe(false)
|
|
21
|
+
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor({ type: NodeType.BROWSER }))).toBe(false)
|
|
30
22
|
})
|
|
31
23
|
|
|
32
24
|
it('node with TLS server', () => {
|
|
33
|
-
connector.setLocalPeerDescriptor(createMockPeerDescriptor(NodeType.NODEJS, { host: '1.1.1.1', port: 11, tls: true }))
|
|
34
|
-
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor(NodeType.NODEJS, { host: '2.2.2.2', port: 22, tls: false }))).toBe(true)
|
|
35
|
-
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor(NodeType.NODEJS, { host: '2.2.2.2', port: 22, tls: true }))).toBe(true)
|
|
36
|
-
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor(NodeType.NODEJS))).toBe(true)
|
|
37
|
-
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor(NodeType.BROWSER))).toBe(true)
|
|
25
|
+
connector.setLocalPeerDescriptor(createMockPeerDescriptor({ type: NodeType.NODEJS, websocket: { host: '1.1.1.1', port: 11, tls: true } }))
|
|
26
|
+
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor({ type: NodeType.NODEJS, websocket: { host: '2.2.2.2', port: 22, tls: false } }))).toBe(true)
|
|
27
|
+
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor({ type: NodeType.NODEJS, websocket: { host: '2.2.2.2', port: 22, tls: true } }))).toBe(true)
|
|
28
|
+
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor({ type: NodeType.NODEJS }))).toBe(true)
|
|
29
|
+
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor({ type: NodeType.BROWSER }))).toBe(true)
|
|
38
30
|
})
|
|
39
31
|
|
|
40
32
|
it('node with non-TLS server', () => {
|
|
41
|
-
connector.setLocalPeerDescriptor(createMockPeerDescriptor(NodeType.NODEJS, { host: '1.1.1.1', port: 11, tls: false }))
|
|
42
|
-
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor(NodeType.NODEJS, { host: '2.2.2.2', port: 22, tls: false }))).toBe(true)
|
|
43
|
-
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor(NodeType.NODEJS, { host: '2.2.2.2', port: 22, tls: true }))).toBe(true)
|
|
44
|
-
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor(NodeType.NODEJS))).toBe(true)
|
|
45
|
-
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor(NodeType.BROWSER))).toBe(false)
|
|
33
|
+
connector.setLocalPeerDescriptor(createMockPeerDescriptor({ type: NodeType.NODEJS, websocket: { host: '1.1.1.1', port: 11, tls: false } }))
|
|
34
|
+
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor({ type: NodeType.NODEJS, websocket: { host: '2.2.2.2', port: 22, tls: false } }))).toBe(true)
|
|
35
|
+
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor({ type: NodeType.NODEJS, websocket: { host: '2.2.2.2', port: 22, tls: true } }))).toBe(true)
|
|
36
|
+
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor({ type: NodeType.NODEJS }))).toBe(true)
|
|
37
|
+
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor({ type: NodeType.BROWSER }))).toBe(false)
|
|
46
38
|
})
|
|
47
39
|
|
|
48
40
|
it('node with non-TLS server in local network', () => {
|
|
49
|
-
connector.setLocalPeerDescriptor(createMockPeerDescriptor(NodeType.NODEJS, { host: '192.168.11.11', port: 11, tls: false }))
|
|
50
|
-
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor(NodeType.NODEJS, { host: '2.2.2.2', port: 22, tls: false }))).toBe(true)
|
|
51
|
-
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor(NodeType.NODEJS, { host: '2.2.2.2', port: 22, tls: true }))).toBe(true)
|
|
52
|
-
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor(NodeType.NODEJS))).toBe(true)
|
|
53
|
-
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor(NodeType.BROWSER))).toBe(true)
|
|
41
|
+
connector.setLocalPeerDescriptor(createMockPeerDescriptor({ type: NodeType.NODEJS, websocket: { host: '192.168.11.11', port: 11, tls: false } }))
|
|
42
|
+
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor({ type: NodeType.NODEJS, websocket: { host: '2.2.2.2', port: 22, tls: false } }))).toBe(true)
|
|
43
|
+
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor({ type: NodeType.NODEJS, websocket: { host: '2.2.2.2', port: 22, tls: true } }))).toBe(true)
|
|
44
|
+
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor({ type: NodeType.NODEJS }))).toBe(true)
|
|
45
|
+
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor({ type: NodeType.BROWSER }))).toBe(true)
|
|
54
46
|
})
|
|
55
47
|
|
|
56
48
|
it('browser', () => {
|
|
57
|
-
connector.setLocalPeerDescriptor(createMockPeerDescriptor(NodeType.BROWSER))
|
|
58
|
-
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor(NodeType.NODEJS, { host: '2.2.2.2', port: 22, tls: false }))).toBe(false)
|
|
59
|
-
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor(NodeType.NODEJS, { host: '2.2.2.2', port: 22, tls: true }))).toBe(true)
|
|
60
|
-
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor(NodeType.NODEJS))).toBe(false)
|
|
61
|
-
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor(NodeType.BROWSER))).toBe(false)
|
|
49
|
+
connector.setLocalPeerDescriptor(createMockPeerDescriptor({ type: NodeType.BROWSER }))
|
|
50
|
+
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor({ type: NodeType.NODEJS, websocket: { host: '2.2.2.2', port: 22, tls: false } }))).toBe(false)
|
|
51
|
+
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor({ type: NodeType.NODEJS, websocket: { host: '2.2.2.2', port: 22, tls: true } }))).toBe(true)
|
|
52
|
+
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor({ type: NodeType.NODEJS }))).toBe(false)
|
|
53
|
+
expect(connector.isPossibleToFormConnection(createMockPeerDescriptor({ type: NodeType.BROWSER }))).toBe(false)
|
|
62
54
|
})
|
|
63
55
|
})
|
|
64
56
|
})
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { ipv4ToNumber, waitForCondition } from '@streamr/utils'
|
|
2
|
+
import { EventEmitter } from 'eventemitter3'
|
|
3
|
+
import { once } from 'events'
|
|
4
|
+
import { Server as HttpServer, createServer as createHttpServer } from 'http'
|
|
5
|
+
import { server as WsServer } from 'websocket'
|
|
6
|
+
import { CONNECTIVITY_CHECKER_SERVICE_ID } from '../../src/connection/connectivityChecker'
|
|
7
|
+
import { attachConnectivityRequestHandler } from '../../src/connection/connectivityRequestHandler'
|
|
8
|
+
import { Message } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
9
|
+
import { LOCAL_PROTOCOL_VERSION } from '../../src/helpers/version'
|
|
10
|
+
|
|
11
|
+
const HOST = '127.0.0.1'
|
|
12
|
+
const PORT = 15001
|
|
13
|
+
|
|
14
|
+
describe('connectivityRequestHandler', () => {
|
|
15
|
+
|
|
16
|
+
let httpServer: HttpServer
|
|
17
|
+
let wsServer: WsServer
|
|
18
|
+
let connection: any
|
|
19
|
+
|
|
20
|
+
beforeEach(async () => {
|
|
21
|
+
httpServer = createHttpServer()
|
|
22
|
+
wsServer = new WsServer({
|
|
23
|
+
httpServer,
|
|
24
|
+
autoAcceptConnections: true
|
|
25
|
+
})
|
|
26
|
+
httpServer.listen(PORT)
|
|
27
|
+
await once(httpServer, 'listening')
|
|
28
|
+
connection = new EventEmitter()
|
|
29
|
+
connection.send = jest.fn()
|
|
30
|
+
connection.remoteIpAddress = HOST
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
afterEach(async () => {
|
|
34
|
+
wsServer.shutDown()
|
|
35
|
+
httpServer.close()
|
|
36
|
+
await once(httpServer, 'close')
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
it('happy path', async () => {
|
|
40
|
+
attachConnectivityRequestHandler(connection)
|
|
41
|
+
const request: Message = {
|
|
42
|
+
serviceId: CONNECTIVITY_CHECKER_SERVICE_ID,
|
|
43
|
+
messageId: 'mock-message-id',
|
|
44
|
+
body: {
|
|
45
|
+
oneofKind: 'connectivityRequest',
|
|
46
|
+
connectivityRequest: { port: PORT, host: HOST, tls: false, selfSigned: false }
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
connection.emit('data', Message.toBinary(request))
|
|
50
|
+
|
|
51
|
+
await waitForCondition(() => connection.send.mock.calls.length > 0)
|
|
52
|
+
|
|
53
|
+
const receivedMessage = Message.fromBinary(connection.send.mock.calls[0][0])
|
|
54
|
+
expect(receivedMessage).toEqual({
|
|
55
|
+
body: {
|
|
56
|
+
connectivityResponse: {
|
|
57
|
+
host: HOST,
|
|
58
|
+
natType: 'open_internet',
|
|
59
|
+
websocket: {
|
|
60
|
+
host: HOST,
|
|
61
|
+
port: PORT,
|
|
62
|
+
tls: false
|
|
63
|
+
},
|
|
64
|
+
ipAddress: ipv4ToNumber(HOST),
|
|
65
|
+
version: LOCAL_PROTOCOL_VERSION
|
|
66
|
+
},
|
|
67
|
+
oneofKind: 'connectivityResponse'
|
|
68
|
+
},
|
|
69
|
+
messageId: expect.any(String),
|
|
70
|
+
serviceId: 'system/connectivity-checker'
|
|
71
|
+
})
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
it('disabled connectivity probing', async () => {
|
|
75
|
+
attachConnectivityRequestHandler(connection)
|
|
76
|
+
const request: Message = {
|
|
77
|
+
serviceId: CONNECTIVITY_CHECKER_SERVICE_ID,
|
|
78
|
+
messageId: 'mock-message-id',
|
|
79
|
+
body: {
|
|
80
|
+
oneofKind: 'connectivityRequest',
|
|
81
|
+
connectivityRequest: { port: 0, host: HOST, tls: false, selfSigned: false }
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
connection.emit('data', Message.toBinary(request))
|
|
85
|
+
|
|
86
|
+
await waitForCondition(() => connection.send.mock.calls.length > 0)
|
|
87
|
+
|
|
88
|
+
const receivedMessage = Message.fromBinary(connection.send.mock.calls[0][0])
|
|
89
|
+
expect(receivedMessage).toEqual({
|
|
90
|
+
body: {
|
|
91
|
+
connectivityResponse: {
|
|
92
|
+
host: HOST,
|
|
93
|
+
natType: 'unknown',
|
|
94
|
+
ipAddress: ipv4ToNumber(HOST),
|
|
95
|
+
version: LOCAL_PROTOCOL_VERSION
|
|
96
|
+
},
|
|
97
|
+
oneofKind: 'connectivityResponse'
|
|
98
|
+
},
|
|
99
|
+
messageId: expect.any(String),
|
|
100
|
+
serviceId: 'system/connectivity-checker'
|
|
101
|
+
})
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
})
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { ipv4ToNumber } from '@streamr/utils'
|
|
2
|
+
import { createPeerDescriptor } from '../../src/helpers/createPeerDescriptor'
|
|
3
|
+
import { isBrowserEnvironment } from '../../src/helpers/browser/isBrowserEnvironment'
|
|
4
|
+
import { NodeType } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
5
|
+
import { createRandomDhtAddress, getRawFromDhtAddress } from '../../src/identifiers'
|
|
6
|
+
import { getRandomRegion } from '../../dist/src/connection/simulator/pings'
|
|
7
|
+
|
|
8
|
+
const IP_ADDRESS = '1.2.3.4'
|
|
9
|
+
|
|
10
|
+
describe('createPeerDescriptor', () => {
|
|
11
|
+
|
|
12
|
+
const region = getRandomRegion()
|
|
13
|
+
|
|
14
|
+
it('without websocket', () => {
|
|
15
|
+
const connectivityResponse = {
|
|
16
|
+
ipAddress: ipv4ToNumber(IP_ADDRESS)
|
|
17
|
+
} as any
|
|
18
|
+
const peerDescriptor = createPeerDescriptor(connectivityResponse, region)
|
|
19
|
+
expect(peerDescriptor).toEqual({
|
|
20
|
+
nodeId: expect.any(Uint8Array),
|
|
21
|
+
type: isBrowserEnvironment() ? NodeType.BROWSER : NodeType.NODEJS,
|
|
22
|
+
ipAddress: ipv4ToNumber(IP_ADDRESS),
|
|
23
|
+
publicKey: expect.any(Uint8Array),
|
|
24
|
+
signature: expect.any(Uint8Array),
|
|
25
|
+
region
|
|
26
|
+
})
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it('with websocket', () => {
|
|
30
|
+
const connectivityResponse = {
|
|
31
|
+
ipAddress: ipv4ToNumber(IP_ADDRESS),
|
|
32
|
+
websocket: {
|
|
33
|
+
host: 'bar.com',
|
|
34
|
+
port: 123,
|
|
35
|
+
tls: true
|
|
36
|
+
}
|
|
37
|
+
} as any
|
|
38
|
+
const peerDescriptor = createPeerDescriptor(connectivityResponse, region)
|
|
39
|
+
expect(peerDescriptor).toEqual({
|
|
40
|
+
nodeId: expect.any(Uint8Array),
|
|
41
|
+
type: isBrowserEnvironment() ? NodeType.BROWSER : NodeType.NODEJS,
|
|
42
|
+
ipAddress: ipv4ToNumber(IP_ADDRESS),
|
|
43
|
+
publicKey: expect.any(Uint8Array),
|
|
44
|
+
signature: expect.any(Uint8Array),
|
|
45
|
+
websocket: {
|
|
46
|
+
host: 'bar.com',
|
|
47
|
+
port: 123,
|
|
48
|
+
tls: true
|
|
49
|
+
},
|
|
50
|
+
region
|
|
51
|
+
})
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it('explicit nodeId', () => {
|
|
55
|
+
const nodeId = createRandomDhtAddress()
|
|
56
|
+
const connectivityResponse = {
|
|
57
|
+
ipAddress: ipv4ToNumber(IP_ADDRESS)
|
|
58
|
+
} as any
|
|
59
|
+
const peerDescriptor = createPeerDescriptor(connectivityResponse, region, nodeId)
|
|
60
|
+
expect(peerDescriptor).toEqual({
|
|
61
|
+
nodeId: getRawFromDhtAddress(nodeId),
|
|
62
|
+
type: isBrowserEnvironment() ? NodeType.BROWSER : NodeType.NODEJS,
|
|
63
|
+
ipAddress: ipv4ToNumber(IP_ADDRESS),
|
|
64
|
+
publicKey: expect.any(Uint8Array),
|
|
65
|
+
signature: expect.any(Uint8Array),
|
|
66
|
+
region
|
|
67
|
+
})
|
|
68
|
+
})
|
|
69
|
+
})
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { cloneDeep } from 'lodash'
|
|
2
|
+
import { createMockPeerDescriptor } from '../utils/utils'
|
|
3
|
+
|
|
4
|
+
describe('custom matchers', () => {
|
|
5
|
+
|
|
6
|
+
it('happy path', () => {
|
|
7
|
+
const peerDescriptor = createMockPeerDescriptor({
|
|
8
|
+
websocket: { port: 1, host: 'x', tls: true }
|
|
9
|
+
})
|
|
10
|
+
expect(peerDescriptor).toEqualPeerDescriptor(cloneDeep(peerDescriptor))
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
it('no match', () => {
|
|
14
|
+
expect(createMockPeerDescriptor()).not.toEqualPeerDescriptor(createMockPeerDescriptor())
|
|
15
|
+
})
|
|
16
|
+
})
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { isMaybeSupportedVersion } from '../../src/helpers/version'
|
|
2
|
+
|
|
3
|
+
describe('version', () => {
|
|
4
|
+
|
|
5
|
+
it('supported', () => {
|
|
6
|
+
expect(isMaybeSupportedVersion('1.0')).toBe(true)
|
|
7
|
+
expect(isMaybeSupportedVersion('1.1')).toBe(true)
|
|
8
|
+
expect(isMaybeSupportedVersion('2.0')).toBe(true)
|
|
9
|
+
expect(isMaybeSupportedVersion('3.5')).toBe(true)
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
it('not supported', () => {
|
|
13
|
+
expect(isMaybeSupportedVersion('')).toBe(false)
|
|
14
|
+
expect(isMaybeSupportedVersion('100.0.0-testnet-three.3')).toBe(false)
|
|
15
|
+
expect(isMaybeSupportedVersion('0.0')).toBe(false)
|
|
16
|
+
expect(isMaybeSupportedVersion('0.1')).toBe(false)
|
|
17
|
+
})
|
|
18
|
+
})
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { EventEmitter } from 'eventemitter3'
|
|
2
|
+
import { ITransport, TransportEvents } from '../../src/transport/ITransport'
|
|
3
|
+
import { Message, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
4
|
+
|
|
5
|
+
class FakeTransport extends EventEmitter<TransportEvents> implements ITransport {
|
|
6
|
+
|
|
7
|
+
private onSend: (msg: Message) => void
|
|
8
|
+
private readonly localPeerDescriptor: PeerDescriptor
|
|
9
|
+
|
|
10
|
+
constructor(peerDescriptor: PeerDescriptor, onSend: (msg: Message) => void) {
|
|
11
|
+
super()
|
|
12
|
+
this.onSend = onSend
|
|
13
|
+
this.localPeerDescriptor = peerDescriptor
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async send(msg: Message): Promise<void> {
|
|
17
|
+
msg.sourceDescriptor = this.localPeerDescriptor
|
|
18
|
+
this.onSend(msg)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// eslint-disable-next-line class-methods-use-this
|
|
22
|
+
getLocalPeerDescriptor(): PeerDescriptor {
|
|
23
|
+
throw new Error('not implemented')
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// eslint-disable-next-line class-methods-use-this
|
|
27
|
+
getConnections(): PeerDescriptor[] {
|
|
28
|
+
throw new Error('not implemented')
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// eslint-disable-next-line class-methods-use-this
|
|
32
|
+
stop(): void | Promise<void> {
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export class FakeEnvironment {
|
|
37
|
+
|
|
38
|
+
private transports: FakeTransport[] = []
|
|
39
|
+
|
|
40
|
+
createTransport(peerDescriptor: PeerDescriptor): ITransport {
|
|
41
|
+
const transport = new FakeTransport(peerDescriptor, (msg) => {
|
|
42
|
+
this.transports.forEach((t) => t.emit('message', msg))
|
|
43
|
+
})
|
|
44
|
+
this.transports.push(transport)
|
|
45
|
+
return transport
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { areEqualBinaries } from '@streamr/utils'
|
|
2
|
+
import { printExpected, printReceived } from 'jest-matcher-utils'
|
|
3
|
+
import { isEqual } from 'lodash'
|
|
4
|
+
import { ConnectivityMethod, NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
5
|
+
import { getDhtAddressFromRaw } from '../../src/identifiers'
|
|
6
|
+
|
|
7
|
+
// we could ES2015 module syntax (https://jestjs.io/docs/expect#expectextendmatchers),
|
|
8
|
+
// but the IDE doesn't find custom matchers if we do that
|
|
9
|
+
declare global {
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
11
|
+
namespace jest {
|
|
12
|
+
interface Matchers<R> {
|
|
13
|
+
toEqualPeerDescriptor(expected: PeerDescriptor): R
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const formErrorMessage = (description: string, expected: string | number | undefined, actual: string | number | undefined): string => {
|
|
19
|
+
return `${description}\nExpected: ${printExpected(expected)}\nReceived: ${printReceived(actual)}`
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const toEqualPeerDescriptor = (
|
|
23
|
+
actual: PeerDescriptor,
|
|
24
|
+
expected: PeerDescriptor
|
|
25
|
+
): jest.CustomMatcherResult => {
|
|
26
|
+
const messages: string[] = []
|
|
27
|
+
if (!areEqualBinaries(expected.nodeId, actual.nodeId)) {
|
|
28
|
+
messages.push(formErrorMessage('nodeId', getDhtAddressFromRaw(expected.nodeId), getDhtAddressFromRaw(actual.nodeId)))
|
|
29
|
+
}
|
|
30
|
+
if (!isEqual(expected.type, actual.type)) {
|
|
31
|
+
const typeNames = { [NodeType.NODEJS]: 'NODEJS', [NodeType.BROWSER]: 'BROWSER' }
|
|
32
|
+
messages.push(formErrorMessage('type', typeNames[expected.type], typeNames[actual.type]))
|
|
33
|
+
}
|
|
34
|
+
expectEqualConnectivityMethod('udp', expected.udp, actual.udp, messages)
|
|
35
|
+
expectEqualConnectivityMethod('tpc', expected.tcp, actual.tcp, messages)
|
|
36
|
+
expectEqualConnectivityMethod('websocket', expected.websocket, actual.websocket, messages)
|
|
37
|
+
if (expected.region !== actual.region) {
|
|
38
|
+
messages.push(formErrorMessage('region', expected?.region, actual?.region))
|
|
39
|
+
}
|
|
40
|
+
if (messages.length > 0) {
|
|
41
|
+
return {
|
|
42
|
+
pass: false,
|
|
43
|
+
message: () => messages.join('\n\n')
|
|
44
|
+
}
|
|
45
|
+
} else {
|
|
46
|
+
return {
|
|
47
|
+
pass: true,
|
|
48
|
+
message: () => `Expected not to throw ${printReceived('StreamrClientError')}`
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const expectEqualConnectivityMethod = (
|
|
54
|
+
description: string,
|
|
55
|
+
method1: ConnectivityMethod | undefined,
|
|
56
|
+
method2: ConnectivityMethod | undefined,
|
|
57
|
+
messages: string[]
|
|
58
|
+
) => {
|
|
59
|
+
const toOutput = (method?: ConnectivityMethod) => {
|
|
60
|
+
return (method !== undefined)
|
|
61
|
+
? `{port: ${method.port}, host: '${method.host}', tls: ${method.tls}}`
|
|
62
|
+
: undefined
|
|
63
|
+
}
|
|
64
|
+
if (!isEqual(method1, method2)) {
|
|
65
|
+
messages.push(formErrorMessage(description, toOutput(method1), toOutput(method2)))
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
expect.extend({
|
|
70
|
+
toEqualPeerDescriptor
|
|
71
|
+
})
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Methods } from '@streamr/test-utils'
|
|
2
|
+
import { Router } from '../../../src/dht/routing/Router'
|
|
2
3
|
import { RouteMessageAck } from '../../../src/proto/packages/dht/protos/DhtRpc'
|
|
3
4
|
|
|
4
|
-
export class MockRouter implements
|
|
5
|
+
export class MockRouter implements Methods<Router> {
|
|
5
6
|
|
|
6
7
|
// eslint-disable-next-line class-methods-use-this
|
|
7
8
|
addRoutingSession(): void {
|
|
@@ -30,7 +31,7 @@ export class MockRouter implements IRouter {
|
|
|
30
31
|
|
|
31
32
|
// eslint-disable-next-line class-methods-use-this
|
|
32
33
|
send(): Promise<void> {
|
|
33
|
-
throw Error('Not implemented')
|
|
34
|
+
throw new Error('Not implemented')
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
// eslint-disable-next-line class-methods-use-this
|
|
@@ -48,4 +49,13 @@ export class MockRouter implements IRouter {
|
|
|
48
49
|
return RouteMessageAck.create()
|
|
49
50
|
}
|
|
50
51
|
|
|
52
|
+
// eslint-disable-next-line class-methods-use-this
|
|
53
|
+
onNodeConnected(): void {}
|
|
54
|
+
|
|
55
|
+
// eslint-disable-next-line class-methods-use-this
|
|
56
|
+
onNodeDisconnected(): void {}
|
|
57
|
+
|
|
58
|
+
// eslint-disable-next-line class-methods-use-this
|
|
59
|
+
resetCache(): void {}
|
|
60
|
+
|
|
51
61
|
}
|
|
@@ -15,7 +15,7 @@ export class MockTransport extends EventEmitter<TransportEvents> implements ITra
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
// eslint-disable-next-line class-methods-use-this
|
|
18
|
-
|
|
18
|
+
getConnections(): PeerDescriptor[] {
|
|
19
19
|
return []
|
|
20
20
|
}
|
|
21
21
|
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { MessageType as MessageType$, ScalarType } from '@protobuf-ts/runtime'
|
|
2
|
+
import { randomString } from '@streamr/utils'
|
|
3
|
+
import { Timestamp } from '../../../src/proto/google/protobuf/timestamp'
|
|
4
|
+
import { Any } from '../../../src/proto/google/protobuf/any'
|
|
5
|
+
import { DataEntry } from '../../../src/proto/packages/dht/protos/DhtRpc'
|
|
6
|
+
import { DhtAddress, createRandomDhtAddress, getRawFromDhtAddress } from '../../../src/identifiers'
|
|
7
|
+
import { omit } from 'lodash'
|
|
8
|
+
|
|
9
|
+
const MockData = new class extends MessageType$<{ foo: string }> {
|
|
10
|
+
constructor() {
|
|
11
|
+
super('MockData', [
|
|
12
|
+
{ no: 1, name: 'foo', kind: 'scalar', opt: false, T: ScalarType.STRING }
|
|
13
|
+
])
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const createMockDataEntry = (
|
|
18
|
+
entry: Partial<Omit<DataEntry, 'key' | 'creator'> & { key: DhtAddress, creator: DhtAddress }> = {}
|
|
19
|
+
): DataEntry => {
|
|
20
|
+
return {
|
|
21
|
+
key: getRawFromDhtAddress(entry.key ?? createRandomDhtAddress()),
|
|
22
|
+
data: Any.pack({ foo: randomString(5) }, MockData),
|
|
23
|
+
creator: getRawFromDhtAddress(entry.creator ?? createRandomDhtAddress()),
|
|
24
|
+
ttl: 10000,
|
|
25
|
+
stale: false,
|
|
26
|
+
deleted: false,
|
|
27
|
+
createdAt: Timestamp.now(),
|
|
28
|
+
...omit(entry, 'key', 'creator')
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const unpackData = (entry: DataEntry): { foo: string } => {
|
|
33
|
+
return Any.unpack(entry.data!, MockData)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const expectEqualData = (entry1: DataEntry, entry2: DataEntry): void => {
|
|
37
|
+
expect(unpackData(entry1).foo).toBe(unpackData(entry2).foo)
|
|
38
|
+
}
|