@streamr/dht 100.0.0-pretestnet.6 → 100.0.0-rc.1
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 +19 -10
- 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 +1 -2
- package/dist/src/connection/webrtc/WebrtcConnector.js +36 -32
- package/dist/src/connection/webrtc/WebrtcConnector.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.d.ts +4 -2
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js +28 -22
- 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 +17 -14
- 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 +24 -12
- 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 +25 -27
- package/src/connection/webrtc/WebrtcConnector.ts +31 -36
- package/src/connection/webrtc/WebrtcConnectorRpcLocal.ts +31 -25
- 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
|
@@ -1,36 +1,28 @@
|
|
|
1
1
|
import { ProtoRpcClient, RpcCommunicator, toProtoRpcClient } from '@streamr/proto-rpc'
|
|
2
2
|
import { WebsocketConnectorRpcClient } from '../../src/proto/packages/dht/protos/DhtRpc.client'
|
|
3
|
-
import {
|
|
3
|
+
import { createMockPeerDescriptor } from '../utils/utils'
|
|
4
4
|
import {
|
|
5
|
-
|
|
6
|
-
PeerDescriptor,
|
|
7
|
-
WebsocketConnectionRequest,
|
|
8
|
-
WebsocketConnectionResponse
|
|
5
|
+
WebsocketConnectionRequest
|
|
9
6
|
} from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
10
7
|
import { mockWebsocketConnectorRpc } from '../utils/utils'
|
|
11
8
|
import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
|
|
9
|
+
import { Empty } from '../../src/proto/google/protobuf/empty'
|
|
10
|
+
import { DhtCallContext } from '../../src/rpc-protocol/DhtCallContext'
|
|
12
11
|
|
|
13
12
|
describe('WebsocketConnectorRpc', () => {
|
|
14
|
-
|
|
15
|
-
let
|
|
13
|
+
|
|
14
|
+
let rpcCommunicator1: RpcCommunicator<DhtCallContext>
|
|
15
|
+
let rpcCommunicator2: RpcCommunicator<DhtCallContext>
|
|
16
16
|
let client1: ProtoRpcClient<WebsocketConnectorRpcClient>
|
|
17
17
|
let client2: ProtoRpcClient<WebsocketConnectorRpcClient>
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
kademliaId: generateId('peer1'),
|
|
21
|
-
type: NodeType.NODEJS
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const peerDescriptor2: PeerDescriptor = {
|
|
25
|
-
kademliaId: generateId('peer2'),
|
|
26
|
-
type: NodeType.NODEJS
|
|
27
|
-
}
|
|
18
|
+
const peerDescriptor1 = createMockPeerDescriptor()
|
|
19
|
+
const peerDescriptor2 = createMockPeerDescriptor()
|
|
28
20
|
|
|
29
21
|
beforeEach(() => {
|
|
30
22
|
rpcCommunicator1 = new RpcCommunicator()
|
|
31
23
|
rpcCommunicator1.registerRpcMethod(
|
|
32
24
|
WebsocketConnectionRequest,
|
|
33
|
-
|
|
25
|
+
Empty,
|
|
34
26
|
'requestConnection',
|
|
35
27
|
mockWebsocketConnectorRpc.requestConnection
|
|
36
28
|
)
|
|
@@ -38,7 +30,7 @@ describe('WebsocketConnectorRpc', () => {
|
|
|
38
30
|
rpcCommunicator2 = new RpcCommunicator()
|
|
39
31
|
rpcCommunicator2.registerRpcMethod(
|
|
40
32
|
WebsocketConnectionRequest,
|
|
41
|
-
|
|
33
|
+
Empty,
|
|
42
34
|
'requestConnection',
|
|
43
35
|
mockWebsocketConnectorRpc.requestConnection
|
|
44
36
|
)
|
|
@@ -67,16 +59,14 @@ describe('WebsocketConnectorRpc', () => {
|
|
|
67
59
|
},
|
|
68
60
|
{ targetDescriptor: peerDescriptor2 },
|
|
69
61
|
)
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
62
|
+
await response1
|
|
63
|
+
|
|
73
64
|
const response2 = client2.requestConnection({
|
|
74
65
|
ip: '127.0.0.1',
|
|
75
66
|
port: 9111
|
|
76
67
|
},
|
|
77
68
|
{ targetDescriptor: peerDescriptor1 },
|
|
78
69
|
)
|
|
79
|
-
|
|
80
|
-
expect(res2.accepted).toEqual(true)
|
|
70
|
+
await response2
|
|
81
71
|
})
|
|
82
72
|
})
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ConnectionManager } from '../../src/connection/ConnectionManager'
|
|
2
2
|
import { LatencyType, Simulator } from '../../src/connection/simulator/Simulator'
|
|
3
|
-
import { PeerID } from '../../src/helpers/PeerID'
|
|
4
3
|
import { ITransport } from '../../src/transport/ITransport'
|
|
5
4
|
import { v4 } from 'uuid'
|
|
6
5
|
import { SimulatorTransport } from '../../src/connection/simulator/SimulatorTransport'
|
|
@@ -8,9 +7,12 @@ import { DhtRpcOptions } from '../../src/rpc-protocol/DhtRpcOptions'
|
|
|
8
7
|
import { ListeningRpcCommunicator } from '../../src/transport/ListeningRpcCommunicator'
|
|
9
8
|
import { ProtoRpcClient, toProtoRpcClient } from '@streamr/proto-rpc'
|
|
10
9
|
import { DhtNodeRpcClient } from '../../src/proto/packages/dht/protos/DhtRpc.client'
|
|
11
|
-
import {
|
|
10
|
+
import { PeerDescriptor, PingRequest, PingResponse } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
12
11
|
import { DefaultConnectorFacade } from '../../src/connection/ConnectorFacade'
|
|
13
12
|
import { MetricsContext } from '@streamr/utils'
|
|
13
|
+
import { createMockPeerDescriptor } from '../utils/utils'
|
|
14
|
+
|
|
15
|
+
const SERVICE_ID = 'test'
|
|
14
16
|
|
|
15
17
|
const createConnectionManager = (localPeerDescriptor: PeerDescriptor, transport: ITransport) => {
|
|
16
18
|
return new ConnectionManager({
|
|
@@ -22,47 +24,32 @@ const createConnectionManager = (localPeerDescriptor: PeerDescriptor, transport:
|
|
|
22
24
|
})
|
|
23
25
|
}
|
|
24
26
|
|
|
25
|
-
describe('RPC
|
|
27
|
+
describe('RPC connections over WebRTC', () => {
|
|
26
28
|
|
|
27
29
|
let manager1: ConnectionManager
|
|
28
30
|
let manager2: ConnectionManager
|
|
29
|
-
|
|
30
31
|
let rpcCommunicator1: ListeningRpcCommunicator
|
|
31
32
|
let rpcCommunicator2: ListeningRpcCommunicator
|
|
32
|
-
|
|
33
33
|
let client1: ProtoRpcClient<DhtNodeRpcClient>
|
|
34
|
-
//let client2: ProtoRpcClient<DhtNodeRpcClient>
|
|
35
|
-
|
|
36
34
|
let simulator: Simulator
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
kademliaId: PeerID.fromString('peer1').value,
|
|
40
|
-
type: NodeType.NODEJS,
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const peerDescriptor2: PeerDescriptor = {
|
|
44
|
-
kademliaId: PeerID.fromString('peer2').value,
|
|
45
|
-
type: NodeType.NODEJS,
|
|
46
|
-
}
|
|
47
|
-
|
|
35
|
+
const peerDescriptor1 = createMockPeerDescriptor()
|
|
36
|
+
const peerDescriptor2 = createMockPeerDescriptor()
|
|
48
37
|
let connectorTransport1: SimulatorTransport
|
|
49
38
|
let connectorTransport2: SimulatorTransport
|
|
50
39
|
|
|
51
|
-
const serviceId = 'test'
|
|
52
|
-
|
|
53
40
|
beforeEach(async () => {
|
|
54
41
|
|
|
55
42
|
simulator = new Simulator(LatencyType.FIXED, 50)
|
|
56
43
|
connectorTransport1 = new SimulatorTransport(peerDescriptor1, simulator)
|
|
57
44
|
await connectorTransport1.start()
|
|
58
45
|
manager1 = createConnectionManager(peerDescriptor1, connectorTransport1)
|
|
59
|
-
rpcCommunicator1 = new ListeningRpcCommunicator(
|
|
46
|
+
rpcCommunicator1 = new ListeningRpcCommunicator(SERVICE_ID, manager1)
|
|
60
47
|
client1 = toProtoRpcClient(new DhtNodeRpcClient(rpcCommunicator1.getRpcClientTransport()))
|
|
61
48
|
|
|
62
49
|
connectorTransport2 = new SimulatorTransport(peerDescriptor2, simulator)
|
|
63
50
|
await connectorTransport2.start()
|
|
64
51
|
manager2 = createConnectionManager(peerDescriptor2, connectorTransport2)
|
|
65
|
-
rpcCommunicator2 = new ListeningRpcCommunicator(
|
|
52
|
+
rpcCommunicator2 = new ListeningRpcCommunicator(SERVICE_ID, manager2)
|
|
66
53
|
//client2 = toProtoRpcClient(new DhtNodeRpcClient(rpcCommunicator2.getRpcClientTransport()))
|
|
67
54
|
|
|
68
55
|
await manager1.start()
|
|
@@ -71,10 +58,10 @@ describe('RPC errors', () => {
|
|
|
71
58
|
})
|
|
72
59
|
|
|
73
60
|
afterEach(async () => {
|
|
74
|
-
await connectorTransport1.stop()
|
|
75
|
-
await connectorTransport2.stop()
|
|
76
61
|
await manager1.stop()
|
|
77
62
|
await manager2.stop()
|
|
63
|
+
await connectorTransport1.stop()
|
|
64
|
+
await connectorTransport2.stop()
|
|
78
65
|
simulator.stop()
|
|
79
66
|
})
|
|
80
67
|
|
|
@@ -117,6 +104,9 @@ describe('RPC errors', () => {
|
|
|
117
104
|
}, 60000)
|
|
118
105
|
|
|
119
106
|
/*
|
|
107
|
+
|
|
108
|
+
TODO enable these tests (NET-1177)
|
|
109
|
+
|
|
120
110
|
it.only('Throws a client-side exception if WebRTC connection fails', async () => {
|
|
121
111
|
|
|
122
112
|
const request: PingRequest = {
|
|
@@ -143,14 +133,13 @@ describe('RPC errors', () => {
|
|
|
143
133
|
|
|
144
134
|
const msg: Message = {
|
|
145
135
|
serviceId,
|
|
146
|
-
messageType: MessageType.RPC,
|
|
147
136
|
messageId: '1',
|
|
148
137
|
body: RpcMessage.toBinary(rpcMessage)
|
|
149
138
|
}
|
|
150
139
|
|
|
151
140
|
const disconnectedPromise1 = new Promise<void>((resolve, _reject) => {
|
|
152
141
|
manager1.on('disconnected', () => {
|
|
153
|
-
//expect(message.
|
|
142
|
+
//expect(message.body.oneofKind).toBe('rpcMessage')
|
|
154
143
|
resolve()
|
|
155
144
|
})
|
|
156
145
|
})
|
|
@@ -37,4 +37,8 @@ describe('isPrivateIPv4', () => {
|
|
|
37
37
|
it('return false for a public address', () => {
|
|
38
38
|
expect(isPrivateIPv4('203.0.113.181')).toBe(false)
|
|
39
39
|
})
|
|
40
|
+
|
|
41
|
+
it('return true for localhost IP address', () => {
|
|
42
|
+
expect(isPrivateIPv4('127.0.0.1')).toBe(true)
|
|
43
|
+
})
|
|
40
44
|
})
|
|
@@ -1,38 +1,30 @@
|
|
|
1
1
|
import { NodeType } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
2
2
|
import { expectedConnectionType } from '../../src/helpers/Connectivity'
|
|
3
3
|
import { ConnectionType } from '../../src/connection/IConnection'
|
|
4
|
+
import { createMockPeerDescriptor } from '../utils/utils'
|
|
4
5
|
|
|
5
6
|
describe('Connectivity helpers', () => {
|
|
6
7
|
|
|
7
|
-
const tlsServerPeerDescriptor = {
|
|
8
|
-
kademliaId: new Uint8Array(1),
|
|
9
|
-
type: NodeType.NODEJS,
|
|
8
|
+
const tlsServerPeerDescriptor = createMockPeerDescriptor({
|
|
10
9
|
websocket: {
|
|
11
10
|
host: 'mock',
|
|
12
11
|
port: 1234,
|
|
13
12
|
tls: true
|
|
14
13
|
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const noTlsServerPeerDescriptor = {
|
|
18
|
-
kademliaId: new Uint8Array(1),
|
|
19
|
-
type: NodeType.NODEJS,
|
|
14
|
+
})
|
|
15
|
+
const noTlsServerPeerDescriptor = createMockPeerDescriptor({
|
|
20
16
|
websocket: {
|
|
21
17
|
host: 'mock',
|
|
22
18
|
port: 1234,
|
|
23
19
|
tls: false
|
|
24
20
|
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const browserPeerDescriptor = {
|
|
28
|
-
kademliaId: new Uint8Array(2),
|
|
21
|
+
})
|
|
22
|
+
const browserPeerDescriptor = createMockPeerDescriptor({
|
|
29
23
|
type: NodeType.BROWSER
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const noServerPeerDescriptor = {
|
|
33
|
-
kademliaId: new Uint8Array(3),
|
|
24
|
+
})
|
|
25
|
+
const noServerPeerDescriptor = createMockPeerDescriptor({
|
|
34
26
|
type: NodeType.NODEJS
|
|
35
|
-
}
|
|
27
|
+
})
|
|
36
28
|
|
|
37
29
|
it('two server peers', () => {
|
|
38
30
|
expect(expectedConnectionType(tlsServerPeerDescriptor, tlsServerPeerDescriptor)).toBe(ConnectionType.WEBSOCKET_CLIENT)
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { DuplicateDetector } from '../../src/dht/routing/DuplicateDetector'
|
|
2
2
|
|
|
3
|
+
const MAX_VALUE_COUNT = 10
|
|
4
|
+
|
|
3
5
|
describe('Duplicate Detector', () => {
|
|
6
|
+
|
|
4
7
|
let detector: DuplicateDetector
|
|
5
|
-
|
|
8
|
+
|
|
6
9
|
beforeEach(async () => {
|
|
7
|
-
detector = new DuplicateDetector(
|
|
10
|
+
detector = new DuplicateDetector(MAX_VALUE_COUNT)
|
|
8
11
|
})
|
|
9
12
|
|
|
10
13
|
it('detects duplicates', async () => {
|
|
@@ -13,11 +16,11 @@ describe('Duplicate Detector', () => {
|
|
|
13
16
|
expect(detector.isMostLikelyDuplicate('test')).toEqual(true)
|
|
14
17
|
})
|
|
15
18
|
|
|
16
|
-
it('
|
|
17
|
-
for (let i = 0; i <
|
|
19
|
+
it('removes from tail when full', () => {
|
|
20
|
+
for (let i = 0; i < MAX_VALUE_COUNT; i++) {
|
|
18
21
|
detector.add(`test${i}`)
|
|
19
22
|
}
|
|
20
|
-
for (let i = 0; i <
|
|
23
|
+
for (let i = 0; i < MAX_VALUE_COUNT; i++) {
|
|
21
24
|
expect(detector.isMostLikelyDuplicate(`test${i}`)).toEqual(true)
|
|
22
25
|
}
|
|
23
26
|
detector.add('test10')
|
|
@@ -1,29 +1,15 @@
|
|
|
1
|
-
import { Any } from '../../src/proto/google/protobuf/any'
|
|
2
|
-
import { NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
3
|
-
import {
|
|
4
|
-
areEqualPeerDescriptors,
|
|
5
|
-
keyFromPeerDescriptor,
|
|
6
|
-
peerIdFromPeerDescriptor
|
|
7
|
-
} from '../../src/helpers/peerIdFromPeerDescriptor'
|
|
8
|
-
import { LocalDataStore } from '../../src/dht/store/LocalDataStore'
|
|
9
1
|
import { wait } from '@streamr/utils'
|
|
10
|
-
import {
|
|
2
|
+
import { LocalDataStore } from '../../src/dht/store/LocalDataStore'
|
|
3
|
+
import { createMockPeerDescriptor } from '../utils/utils'
|
|
4
|
+
import { createMockDataEntry } from '../utils/mock/mockDataEntry'
|
|
5
|
+
import { createRandomDhtAddress, getDhtAddressFromRaw, getNodeIdFromPeerDescriptor } from '../../src/identifiers'
|
|
11
6
|
|
|
12
7
|
describe('LocalDataStore', () => {
|
|
8
|
+
|
|
13
9
|
let localDataStore: LocalDataStore
|
|
14
|
-
const storer1: PeerDescriptor = {
|
|
15
|
-
kademliaId: new Uint8Array([1, 2, 3]),
|
|
16
|
-
type: NodeType.NODEJS
|
|
17
|
-
}
|
|
18
|
-
const storer2: PeerDescriptor = {
|
|
19
|
-
kademliaId: new Uint8Array([3, 2, 1]),
|
|
20
|
-
type: NodeType.NODEJS
|
|
21
|
-
}
|
|
22
|
-
const data1 = Any.pack(storer1, PeerDescriptor)
|
|
23
|
-
const data2 = Any.pack(storer2, PeerDescriptor)
|
|
24
10
|
|
|
25
11
|
beforeEach(() => {
|
|
26
|
-
localDataStore = new LocalDataStore()
|
|
12
|
+
localDataStore = new LocalDataStore(30 * 1000)
|
|
27
13
|
})
|
|
28
14
|
|
|
29
15
|
afterEach(() => {
|
|
@@ -31,75 +17,92 @@ describe('LocalDataStore', () => {
|
|
|
31
17
|
})
|
|
32
18
|
|
|
33
19
|
it('can store', () => {
|
|
34
|
-
const
|
|
35
|
-
localDataStore.storeEntry(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
fetchedData.forEach((entry) => {
|
|
39
|
-
const fetchedDescriptor = Any.unpack(entry.data!, PeerDescriptor)
|
|
40
|
-
expect(areEqualPeerDescriptors(fetchedDescriptor, storer1)).toBeTrue()
|
|
41
|
-
})
|
|
20
|
+
const storedEntry = createMockDataEntry()
|
|
21
|
+
localDataStore.storeEntry(storedEntry)
|
|
22
|
+
const fetchedEntries = Array.from(localDataStore.values(getDhtAddressFromRaw(storedEntry.key)))
|
|
23
|
+
expect(fetchedEntries).toIncludeSameMembers([storedEntry])
|
|
42
24
|
})
|
|
43
25
|
|
|
44
26
|
it('multiple storers behind one key', () => {
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
})
|
|
27
|
+
const creator1 = createRandomDhtAddress()
|
|
28
|
+
const creator2 = createRandomDhtAddress()
|
|
29
|
+
const key = createRandomDhtAddress()
|
|
30
|
+
const storedEntry1 = createMockDataEntry({ key, creator: creator1 })
|
|
31
|
+
const storedEntry2 = createMockDataEntry({ key, creator: creator2 })
|
|
32
|
+
localDataStore.storeEntry(storedEntry1)
|
|
33
|
+
localDataStore.storeEntry(storedEntry2)
|
|
34
|
+
const fetchedEntries = Array.from(localDataStore.values(key))
|
|
35
|
+
expect(fetchedEntries).toIncludeSameMembers([storedEntry1, storedEntry2])
|
|
55
36
|
})
|
|
56
37
|
|
|
57
38
|
it('can remove data entries', () => {
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
localDataStore.
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
})
|
|
39
|
+
const creator1 = createRandomDhtAddress()
|
|
40
|
+
const creator2 = createRandomDhtAddress()
|
|
41
|
+
const key = createRandomDhtAddress()
|
|
42
|
+
const storedEntry1 = createMockDataEntry({ key, creator: creator1 })
|
|
43
|
+
const storedEntry2 = createMockDataEntry({ key, creator: creator2 })
|
|
44
|
+
localDataStore.storeEntry(storedEntry1)
|
|
45
|
+
localDataStore.storeEntry(storedEntry2)
|
|
46
|
+
localDataStore.deleteEntry(key, creator1)
|
|
47
|
+
const fetchedEntries = Array.from(localDataStore.values(key))
|
|
48
|
+
expect(fetchedEntries).toIncludeSameMembers([storedEntry2])
|
|
69
49
|
})
|
|
70
50
|
|
|
71
51
|
it('can remove all data entries', () => {
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
localDataStore.
|
|
78
|
-
localDataStore.
|
|
79
|
-
|
|
80
|
-
|
|
52
|
+
const creator1 = createRandomDhtAddress()
|
|
53
|
+
const creator2 = createRandomDhtAddress()
|
|
54
|
+
const key = createRandomDhtAddress()
|
|
55
|
+
const storedEntry1 = createMockDataEntry({ key, creator: creator1 })
|
|
56
|
+
const storedEntry2 = createMockDataEntry({ key, creator: creator2 })
|
|
57
|
+
localDataStore.storeEntry(storedEntry1)
|
|
58
|
+
localDataStore.storeEntry(storedEntry2)
|
|
59
|
+
localDataStore.deleteEntry(key, creator1)
|
|
60
|
+
localDataStore.deleteEntry(key, creator2)
|
|
61
|
+
expect(Array.from(localDataStore.values(key))).toHaveLength(0)
|
|
81
62
|
})
|
|
82
63
|
|
|
83
64
|
it('data is deleted after TTL', async () => {
|
|
84
|
-
const
|
|
85
|
-
localDataStore.storeEntry(
|
|
86
|
-
|
|
87
|
-
const intitialStore = localDataStore.getEntry(dataKey)
|
|
88
|
-
expect(intitialStore.size).toBe(1)
|
|
65
|
+
const storedEntry = createMockDataEntry({ ttl: 1000 })
|
|
66
|
+
localDataStore.storeEntry(storedEntry)
|
|
67
|
+
expect(Array.from(localDataStore.values(getDhtAddressFromRaw(storedEntry.key)))).toHaveLength(1)
|
|
89
68
|
await wait(1100)
|
|
90
|
-
|
|
91
|
-
expect(fetchedData.size).toBe(0)
|
|
69
|
+
expect(Array.from(localDataStore.values(getDhtAddressFromRaw(storedEntry.key)))).toHaveLength(0)
|
|
92
70
|
})
|
|
93
71
|
|
|
94
|
-
|
|
95
|
-
const dataKey = peerIdFromPeerDescriptor(storer1)
|
|
96
|
-
localDataStore.storeEntry({ storer: storer1, kademliaId: dataKey.value, data: data1,
|
|
97
|
-
ttl: 10000, stale: false, deleted: false, storerTime: Timestamp.now() })
|
|
98
|
-
const notDeletedData = localDataStore.getEntry(dataKey)
|
|
99
|
-
expect(notDeletedData.get(keyFromPeerDescriptor(storer1))!.deleted).toBeFalse()
|
|
100
|
-
localDataStore.markAsDeleted(dataKey.value, peerIdFromPeerDescriptor(storer1))
|
|
101
|
-
const deletedData = localDataStore.getEntry(dataKey)
|
|
102
|
-
expect(deletedData.get(keyFromPeerDescriptor(storer1))!.deleted).toBeTrue()
|
|
103
|
-
})
|
|
72
|
+
describe('mark data as deleted', () => {
|
|
104
73
|
|
|
74
|
+
it('happy path', () => {
|
|
75
|
+
const creator1 = createRandomDhtAddress()
|
|
76
|
+
const storedEntry = createMockDataEntry({ creator: creator1 })
|
|
77
|
+
localDataStore.storeEntry(storedEntry)
|
|
78
|
+
const notDeletedData = Array.from(localDataStore.values(getDhtAddressFromRaw(storedEntry.key)))
|
|
79
|
+
expect(notDeletedData[0].deleted).toBeFalse()
|
|
80
|
+
const returnValue = localDataStore.markAsDeleted(
|
|
81
|
+
getDhtAddressFromRaw(storedEntry.key),
|
|
82
|
+
creator1
|
|
83
|
+
)
|
|
84
|
+
expect(returnValue).toBe(true)
|
|
85
|
+
const deletedData = Array.from(localDataStore.values(getDhtAddressFromRaw(storedEntry.key)))
|
|
86
|
+
expect(deletedData[0].deleted).toBeTrue()
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
it('data not stored', () => {
|
|
90
|
+
const key = createRandomDhtAddress()
|
|
91
|
+
const returnValue = localDataStore.markAsDeleted(
|
|
92
|
+
key,
|
|
93
|
+
getNodeIdFromPeerDescriptor(createMockPeerDescriptor())
|
|
94
|
+
)
|
|
95
|
+
expect(returnValue).toBe(false)
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
it('data not stored by the given creator', () => {
|
|
99
|
+
const storedEntry = createMockDataEntry()
|
|
100
|
+
localDataStore.storeEntry(storedEntry)
|
|
101
|
+
const returnValue = localDataStore.markAsDeleted(
|
|
102
|
+
getDhtAddressFromRaw(storedEntry.key),
|
|
103
|
+
getNodeIdFromPeerDescriptor(createMockPeerDescriptor())
|
|
104
|
+
)
|
|
105
|
+
expect(returnValue).toBe(false)
|
|
106
|
+
})
|
|
107
|
+
})
|
|
105
108
|
})
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { PeerManager, getDistance } from '../../src/dht/PeerManager'
|
|
2
|
+
import { DhtAddress, createRandomDhtAddress, getNodeIdFromPeerDescriptor, getRawFromDhtAddress } from '../../src/identifiers'
|
|
3
|
+
import { NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
4
|
+
import { range, sampleSize, sortBy, without } from 'lodash'
|
|
5
|
+
import { DhtNodeRpcRemote } from '../../src/dht/DhtNodeRpcRemote'
|
|
6
|
+
import { MockRpcCommunicator } from '../utils/mock/MockRpcCommunicator'
|
|
7
|
+
import { createMockPeerDescriptor } from '../utils/utils'
|
|
8
|
+
|
|
9
|
+
describe('PeerManager', () => {
|
|
10
|
+
|
|
11
|
+
it('getClosestContactsTo', () => {
|
|
12
|
+
const nodeIds = range(10).map(() => createRandomDhtAddress())
|
|
13
|
+
const peerDescriptor = createMockPeerDescriptor()
|
|
14
|
+
const manager = new PeerManager({
|
|
15
|
+
localNodeId: getNodeIdFromPeerDescriptor(peerDescriptor),
|
|
16
|
+
localPeerDescriptor: peerDescriptor,
|
|
17
|
+
createDhtNodeRpcRemote: (peerDescriptor: PeerDescriptor) => {
|
|
18
|
+
return new DhtNodeRpcRemote(undefined as any, peerDescriptor, undefined as any, new MockRpcCommunicator())
|
|
19
|
+
}
|
|
20
|
+
} as any)
|
|
21
|
+
manager.addContact(nodeIds.map((n) => ({ nodeId: getRawFromDhtAddress(n), type: NodeType.NODEJS })))
|
|
22
|
+
|
|
23
|
+
const referenceId = createRandomDhtAddress()
|
|
24
|
+
const excluded = new Set<DhtAddress>(sampleSize(nodeIds, 2))
|
|
25
|
+
const actual = manager.getClosestContactsTo(referenceId, 5, excluded)
|
|
26
|
+
|
|
27
|
+
const expected = sortBy(
|
|
28
|
+
without(nodeIds, ...Array.from(excluded.values())),
|
|
29
|
+
(n: DhtAddress) => getDistance(getRawFromDhtAddress(n), getRawFromDhtAddress(referenceId))
|
|
30
|
+
).slice(0, 5)
|
|
31
|
+
expect(actual.map((n) => n.getNodeId())).toEqual(expected)
|
|
32
|
+
})
|
|
33
|
+
})
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { RandomContactList } from '../../src/dht/contact/RandomContactList'
|
|
2
|
-
import {
|
|
2
|
+
import { DhtAddress, DhtAddressRaw, 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('RandomContactList', () => {
|
|
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,7 +16,7 @@ describe('RandomContactList', () => {
|
|
|
13
16
|
const item4 = createItem(new Uint8Array([0, 0, 0, 4]))
|
|
14
17
|
|
|
15
18
|
it('adds contacts correctly', () => {
|
|
16
|
-
const list = new RandomContactList(item0.
|
|
19
|
+
const list = new RandomContactList(item0.getNodeId(), 5, 1)
|
|
17
20
|
list.addContact(item1)
|
|
18
21
|
list.addContact(item2)
|
|
19
22
|
list.addContact(item3)
|
|
@@ -27,15 +30,15 @@ describe('RandomContactList', () => {
|
|
|
27
30
|
})
|
|
28
31
|
|
|
29
32
|
it('removes contacts correctly', () => {
|
|
30
|
-
const list = new RandomContactList(item0.
|
|
33
|
+
const list = new RandomContactList(item0.getNodeId(), 5, 1)
|
|
31
34
|
list.addContact(item1)
|
|
32
35
|
list.addContact(item2)
|
|
33
36
|
list.addContact(item3)
|
|
34
37
|
list.addContact(item4)
|
|
35
|
-
list.removeContact(item2.
|
|
36
|
-
expect(list.getContact(item1.
|
|
37
|
-
expect(list.getContact(item3.
|
|
38
|
-
expect(list.getContact(item4.
|
|
38
|
+
list.removeContact(item2.getNodeId())
|
|
39
|
+
expect(list.getContact(item1.getNodeId())).toBeTruthy()
|
|
40
|
+
expect(list.getContact(item3.getNodeId())).toBeTruthy()
|
|
41
|
+
expect(list.getContact(item4.getNodeId())).toBeTruthy()
|
|
39
42
|
expect(list.getContacts()).toEqual(
|
|
40
43
|
[item1, item3, item4]
|
|
41
44
|
)
|