@streamr/dht 100.0.0-pretestnet.6 → 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
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
import { MetricsContext, waitForCondition } from '@streamr/utils'
|
|
2
2
|
import { ConnectionManager } from '../../src/connection/ConnectionManager'
|
|
3
3
|
import { DefaultConnectorFacade, DefaultConnectorFacadeConfig } from '../../src/connection/ConnectorFacade'
|
|
4
|
-
import { Simulator } from '../../src/connection/simulator/Simulator'
|
|
4
|
+
import { LatencyType, Simulator } from '../../src/connection/simulator/Simulator'
|
|
5
5
|
import { SimulatorTransport } from '../../src/connection/simulator/SimulatorTransport'
|
|
6
|
-
import {
|
|
7
|
-
import { Message, MessageType, NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
6
|
+
import { Message, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
8
7
|
import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
|
|
8
|
+
import { createMockPeerDescriptor } from '../utils/utils'
|
|
9
|
+
import { getRandomRegion } from '../../src/connection/simulator/pings'
|
|
10
|
+
import { MockTransport } from '../utils/mock/Transport'
|
|
11
|
+
import { getNodeIdFromPeerDescriptor } from '../../src/identifiers'
|
|
12
|
+
|
|
13
|
+
const BASE_MESSAGE: Message = {
|
|
14
|
+
serviceId: 'serviceId',
|
|
15
|
+
messageId: '1',
|
|
16
|
+
body: {
|
|
17
|
+
oneofKind: 'rpcMessage',
|
|
18
|
+
rpcMessage: RpcMessage.create()
|
|
19
|
+
}
|
|
20
|
+
}
|
|
9
21
|
|
|
10
22
|
const createConnectionManager = (localPeerDescriptor: PeerDescriptor, opts: Omit<DefaultConnectorFacadeConfig, 'createLocalPeerDescriptor'>) => {
|
|
11
23
|
return new ConnectionManager({
|
|
@@ -20,111 +32,92 @@ const createConnectionManager = (localPeerDescriptor: PeerDescriptor, opts: Omit
|
|
|
20
32
|
describe('SimultaneousConnections', () => {
|
|
21
33
|
|
|
22
34
|
let simulator: Simulator
|
|
23
|
-
let
|
|
24
|
-
let
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
kademliaId: PeerID.fromString('mock1').value,
|
|
28
|
-
type: NodeType.NODEJS
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const peerDescriptor2 = {
|
|
32
|
-
kademliaId: PeerID.fromString('mock2').value,
|
|
33
|
-
type: NodeType.NODEJS
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const baseMsg: Message = {
|
|
37
|
-
serviceId: 'serviceId',
|
|
38
|
-
messageType: MessageType.RPC,
|
|
39
|
-
messageId: '1',
|
|
40
|
-
body: {
|
|
41
|
-
oneofKind: 'rpcMessage',
|
|
42
|
-
rpcMessage: RpcMessage.create()
|
|
43
|
-
}
|
|
44
|
-
}
|
|
35
|
+
let simTransport1: SimulatorTransport
|
|
36
|
+
let simTransport2: SimulatorTransport
|
|
37
|
+
const peerDescriptor1 = createMockPeerDescriptor({ region: getRandomRegion() })
|
|
38
|
+
const peerDescriptor2 = createMockPeerDescriptor({ region: getRandomRegion() })
|
|
45
39
|
|
|
46
40
|
beforeEach(async () => {
|
|
47
|
-
simulator = new Simulator()
|
|
48
|
-
|
|
49
|
-
await
|
|
50
|
-
|
|
51
|
-
await
|
|
41
|
+
simulator = new Simulator(LatencyType.REAL)
|
|
42
|
+
simTransport1 = new SimulatorTransport(peerDescriptor1, simulator)
|
|
43
|
+
await simTransport1.start()
|
|
44
|
+
simTransport2 = new SimulatorTransport(peerDescriptor2, simulator)
|
|
45
|
+
await simTransport2.start()
|
|
52
46
|
})
|
|
53
47
|
|
|
54
48
|
afterEach(async () => {
|
|
55
|
-
await
|
|
56
|
-
await
|
|
49
|
+
await simTransport1.stop()
|
|
50
|
+
await simTransport2.stop()
|
|
57
51
|
})
|
|
58
52
|
|
|
59
53
|
it('simultanous simulated connection', async () => {
|
|
60
54
|
const msg1: Message = {
|
|
61
|
-
...
|
|
55
|
+
...BASE_MESSAGE,
|
|
62
56
|
targetDescriptor: peerDescriptor2
|
|
63
57
|
}
|
|
64
58
|
const msg2: Message = {
|
|
65
|
-
...
|
|
59
|
+
...BASE_MESSAGE,
|
|
66
60
|
targetDescriptor: peerDescriptor1
|
|
67
61
|
}
|
|
68
62
|
|
|
69
63
|
const promise1 = new Promise<void>((resolve, _reject) => {
|
|
70
|
-
|
|
71
|
-
expect(message.
|
|
64
|
+
simTransport1.on('message', async (message: Message) => {
|
|
65
|
+
expect(message.body.oneofKind).toBe('rpcMessage')
|
|
72
66
|
resolve()
|
|
73
67
|
})
|
|
74
68
|
})
|
|
75
69
|
const promise2 = new Promise<void>((resolve, _reject) => {
|
|
76
|
-
|
|
77
|
-
expect(message.
|
|
70
|
+
simTransport2.on('message', async (message: Message) => {
|
|
71
|
+
expect(message.body.oneofKind).toBe('rpcMessage')
|
|
78
72
|
resolve()
|
|
79
73
|
})
|
|
80
74
|
})
|
|
81
75
|
await Promise.all([
|
|
82
76
|
promise1,
|
|
83
77
|
promise2,
|
|
84
|
-
|
|
85
|
-
|
|
78
|
+
simTransport1.send(msg1),
|
|
79
|
+
simTransport2.send(msg2)
|
|
86
80
|
])
|
|
87
|
-
await waitForCondition(() =>
|
|
88
|
-
await waitForCondition(() =>
|
|
81
|
+
await waitForCondition(() => simTransport2.hasConnection(getNodeIdFromPeerDescriptor(peerDescriptor1)))
|
|
82
|
+
await waitForCondition(() => simTransport1.hasConnection(getNodeIdFromPeerDescriptor(peerDescriptor2)))
|
|
89
83
|
})
|
|
90
84
|
|
|
91
85
|
describe('Websocket 2 servers', () => {
|
|
92
86
|
|
|
93
87
|
let connectionManager1: ConnectionManager
|
|
94
88
|
let connectionManager2: ConnectionManager
|
|
95
|
-
|
|
96
|
-
const
|
|
97
|
-
kademliaId: PeerID.fromString('mock1').value,
|
|
98
|
-
type: NodeType.NODEJS,
|
|
89
|
+
|
|
90
|
+
const wsPeerDescriptor1 = createMockPeerDescriptor({
|
|
99
91
|
websocket: {
|
|
100
92
|
host: '127.0.0.1',
|
|
101
93
|
port: 43432,
|
|
102
94
|
tls: false
|
|
103
|
-
}
|
|
104
|
-
|
|
95
|
+
},
|
|
96
|
+
region: getRandomRegion()
|
|
97
|
+
})
|
|
105
98
|
|
|
106
|
-
const
|
|
107
|
-
kademliaId: PeerID.fromString('mock2').value,
|
|
108
|
-
type: NodeType.NODEJS,
|
|
99
|
+
const wsPeerDescriptor2 = createMockPeerDescriptor({
|
|
109
100
|
websocket: {
|
|
110
101
|
host: '127.0.0.1',
|
|
111
102
|
port: 43433,
|
|
112
103
|
tls: false
|
|
113
|
-
}
|
|
114
|
-
|
|
104
|
+
},
|
|
105
|
+
region: getRandomRegion()
|
|
106
|
+
})
|
|
115
107
|
|
|
116
108
|
beforeEach(async () => {
|
|
109
|
+
|
|
117
110
|
const websocketPortRange = { min: 43432, max: 43433 }
|
|
118
|
-
connectionManager1 = createConnectionManager(
|
|
119
|
-
transport:
|
|
111
|
+
connectionManager1 = createConnectionManager(wsPeerDescriptor1, {
|
|
112
|
+
transport: new MockTransport(),
|
|
120
113
|
websocketPortRange,
|
|
121
|
-
entryPoints: [
|
|
114
|
+
entryPoints: [wsPeerDescriptor1],
|
|
122
115
|
websocketServerEnableTls: false
|
|
123
116
|
})
|
|
124
|
-
connectionManager2 = createConnectionManager(
|
|
125
|
-
transport:
|
|
117
|
+
connectionManager2 = createConnectionManager(wsPeerDescriptor2, {
|
|
118
|
+
transport: new MockTransport(),
|
|
126
119
|
websocketPortRange,
|
|
127
|
-
entryPoints: [
|
|
120
|
+
entryPoints: [wsPeerDescriptor1],
|
|
128
121
|
websocketServerEnableTls: false
|
|
129
122
|
})
|
|
130
123
|
await connectionManager1.start()
|
|
@@ -138,23 +131,23 @@ describe('SimultaneousConnections', () => {
|
|
|
138
131
|
|
|
139
132
|
it('Simultaneous Connections', async () => {
|
|
140
133
|
const msg1: Message = {
|
|
141
|
-
...
|
|
142
|
-
targetDescriptor:
|
|
134
|
+
...BASE_MESSAGE,
|
|
135
|
+
targetDescriptor: wsPeerDescriptor2
|
|
143
136
|
}
|
|
144
137
|
const msg2: Message = {
|
|
145
|
-
...
|
|
146
|
-
targetDescriptor:
|
|
138
|
+
...BASE_MESSAGE,
|
|
139
|
+
targetDescriptor: wsPeerDescriptor1
|
|
147
140
|
}
|
|
148
141
|
|
|
149
142
|
const promise1 = new Promise<void>((resolve, _reject) => {
|
|
150
143
|
connectionManager1.on('message', async (message: Message) => {
|
|
151
|
-
expect(message.
|
|
144
|
+
expect(message.body.oneofKind).toBe('rpcMessage')
|
|
152
145
|
resolve()
|
|
153
146
|
})
|
|
154
147
|
})
|
|
155
148
|
const promise2 = new Promise<void>((resolve, _reject) => {
|
|
156
149
|
connectionManager2.on('message', async (message: Message) => {
|
|
157
|
-
expect(message.
|
|
150
|
+
expect(message.body.oneofKind).toBe('rpcMessage')
|
|
158
151
|
resolve()
|
|
159
152
|
})
|
|
160
153
|
})
|
|
@@ -166,40 +159,44 @@ describe('SimultaneousConnections', () => {
|
|
|
166
159
|
connectionManager2.send(msg2)
|
|
167
160
|
])
|
|
168
161
|
|
|
169
|
-
await waitForCondition(() => connectionManager1.hasConnection(
|
|
170
|
-
await waitForCondition(() => connectionManager2.hasConnection(
|
|
162
|
+
await waitForCondition(() => connectionManager1.hasConnection(getNodeIdFromPeerDescriptor(wsPeerDescriptor2)))
|
|
163
|
+
await waitForCondition(() => connectionManager2.hasConnection(getNodeIdFromPeerDescriptor(wsPeerDescriptor1)))
|
|
171
164
|
})
|
|
172
165
|
})
|
|
173
166
|
|
|
174
167
|
describe('Websocket 1 server (ConnectionRequests)', () => {
|
|
175
|
-
|
|
168
|
+
|
|
169
|
+
let simTransport1: SimulatorTransport
|
|
170
|
+
let simTransport2: SimulatorTransport
|
|
176
171
|
let connectionManager1: ConnectionManager
|
|
177
172
|
let connectionManager2: ConnectionManager
|
|
178
173
|
|
|
179
|
-
const
|
|
180
|
-
kademliaId: PeerID.fromString('mock1').value,
|
|
181
|
-
type: NodeType.NODEJS,
|
|
174
|
+
const wsPeerDescriptor1 = createMockPeerDescriptor({
|
|
182
175
|
websocket: {
|
|
183
176
|
host: '127.0.0.1',
|
|
184
177
|
port: 43432,
|
|
185
178
|
tls: false
|
|
186
|
-
}
|
|
187
|
-
|
|
179
|
+
},
|
|
180
|
+
region: getRandomRegion()
|
|
181
|
+
})
|
|
188
182
|
|
|
189
|
-
const
|
|
190
|
-
kademliaId: PeerID.fromString('mock2').value,
|
|
191
|
-
type: NodeType.NODEJS
|
|
192
|
-
}
|
|
183
|
+
const wsPeerDescriptor2 = createMockPeerDescriptor({ region: getRandomRegion() })
|
|
193
184
|
|
|
194
185
|
beforeEach(async () => {
|
|
195
|
-
|
|
196
|
-
|
|
186
|
+
simulator = new Simulator(LatencyType.REAL)
|
|
187
|
+
simTransport1 = new SimulatorTransport(wsPeerDescriptor1, simulator)
|
|
188
|
+
await simTransport1.start()
|
|
189
|
+
simTransport2 = new SimulatorTransport(wsPeerDescriptor2, simulator)
|
|
190
|
+
await simTransport2.start()
|
|
191
|
+
|
|
192
|
+
connectionManager1 = createConnectionManager(wsPeerDescriptor1, {
|
|
193
|
+
transport: simTransport1,
|
|
197
194
|
websocketPortRange: { min: 43432, max: 43432 },
|
|
198
|
-
entryPoints: [
|
|
195
|
+
entryPoints: [wsPeerDescriptor1],
|
|
199
196
|
websocketServerEnableTls: false
|
|
200
197
|
})
|
|
201
|
-
connectionManager2 = createConnectionManager(
|
|
202
|
-
transport:
|
|
198
|
+
connectionManager2 = createConnectionManager(wsPeerDescriptor2, {
|
|
199
|
+
transport: simTransport2
|
|
203
200
|
})
|
|
204
201
|
await connectionManager1.start()
|
|
205
202
|
await connectionManager2.start()
|
|
@@ -208,27 +205,29 @@ describe('SimultaneousConnections', () => {
|
|
|
208
205
|
afterEach(async () => {
|
|
209
206
|
await connectionManager1.stop()
|
|
210
207
|
await connectionManager2.stop()
|
|
208
|
+
await simTransport1.stop()
|
|
209
|
+
await simTransport2.stop()
|
|
211
210
|
})
|
|
212
211
|
|
|
213
212
|
it('Simultaneous Connections', async () => {
|
|
214
213
|
const msg1: Message = {
|
|
215
|
-
...
|
|
216
|
-
targetDescriptor:
|
|
214
|
+
...BASE_MESSAGE,
|
|
215
|
+
targetDescriptor: wsPeerDescriptor2
|
|
217
216
|
}
|
|
218
217
|
const msg2: Message = {
|
|
219
|
-
...
|
|
220
|
-
targetDescriptor:
|
|
218
|
+
...BASE_MESSAGE,
|
|
219
|
+
targetDescriptor: wsPeerDescriptor1
|
|
221
220
|
}
|
|
222
221
|
|
|
223
222
|
const promise1 = new Promise<void>((resolve, _reject) => {
|
|
224
223
|
connectionManager1.on('message', async (message: Message) => {
|
|
225
|
-
expect(message.
|
|
224
|
+
expect(message.body.oneofKind).toBe('rpcMessage')
|
|
226
225
|
resolve()
|
|
227
226
|
})
|
|
228
227
|
})
|
|
229
228
|
const promise2 = new Promise<void>((resolve, _reject) => {
|
|
230
229
|
connectionManager2.on('message', async (message: Message) => {
|
|
231
|
-
expect(message.
|
|
230
|
+
expect(message.body.oneofKind).toBe('rpcMessage')
|
|
232
231
|
resolve()
|
|
233
232
|
})
|
|
234
233
|
})
|
|
@@ -240,32 +239,32 @@ describe('SimultaneousConnections', () => {
|
|
|
240
239
|
connectionManager2.send(msg2)
|
|
241
240
|
])
|
|
242
241
|
|
|
243
|
-
await waitForCondition(() => connectionManager1.hasConnection(
|
|
244
|
-
await waitForCondition(() => connectionManager2.hasConnection(
|
|
242
|
+
await waitForCondition(() => connectionManager1.hasConnection(getNodeIdFromPeerDescriptor(wsPeerDescriptor2)))
|
|
243
|
+
await waitForCondition(() => connectionManager2.hasConnection(getNodeIdFromPeerDescriptor(wsPeerDescriptor1)))
|
|
245
244
|
})
|
|
246
245
|
})
|
|
247
246
|
|
|
248
247
|
describe('WebRTC', () => {
|
|
249
248
|
|
|
249
|
+
let simTransport1: SimulatorTransport
|
|
250
|
+
let simTransport2: SimulatorTransport
|
|
250
251
|
let connectionManager1: ConnectionManager
|
|
251
252
|
let connectionManager2: ConnectionManager
|
|
252
253
|
|
|
253
|
-
const
|
|
254
|
-
|
|
255
|
-
type: NodeType.NODEJS
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
const wrtcPeer2: PeerDescriptor = {
|
|
259
|
-
kademliaId: PeerID.fromString('mock2').value,
|
|
260
|
-
type: NodeType.NODEJS
|
|
261
|
-
}
|
|
254
|
+
const wrtcPeerDescriptor1 = createMockPeerDescriptor({ region: getRandomRegion() })
|
|
255
|
+
const wrtcPeerDescriptor2 = createMockPeerDescriptor({ region: getRandomRegion() })
|
|
262
256
|
|
|
263
257
|
beforeEach(async () => {
|
|
264
|
-
|
|
265
|
-
|
|
258
|
+
simulator = new Simulator(LatencyType.REAL)
|
|
259
|
+
simTransport1 = new SimulatorTransport(wrtcPeerDescriptor1, simulator)
|
|
260
|
+
await simTransport1.start()
|
|
261
|
+
simTransport2 = new SimulatorTransport(wrtcPeerDescriptor2, simulator)
|
|
262
|
+
await simTransport2.start()
|
|
263
|
+
connectionManager1 = createConnectionManager(wrtcPeerDescriptor1, {
|
|
264
|
+
transport: simTransport1,
|
|
266
265
|
})
|
|
267
|
-
connectionManager2 = createConnectionManager(
|
|
268
|
-
transport:
|
|
266
|
+
connectionManager2 = createConnectionManager(wrtcPeerDescriptor2, {
|
|
267
|
+
transport: simTransport2,
|
|
269
268
|
})
|
|
270
269
|
await connectionManager1.start()
|
|
271
270
|
await connectionManager2.start()
|
|
@@ -274,27 +273,29 @@ describe('SimultaneousConnections', () => {
|
|
|
274
273
|
afterEach(async () => {
|
|
275
274
|
await connectionManager1.stop()
|
|
276
275
|
await connectionManager2.stop()
|
|
276
|
+
await simTransport1.stop()
|
|
277
|
+
await simTransport2.stop()
|
|
277
278
|
})
|
|
278
279
|
|
|
279
280
|
it('Simultaneous Connections', async () => {
|
|
280
281
|
const msg1: Message = {
|
|
281
|
-
...
|
|
282
|
-
targetDescriptor:
|
|
282
|
+
...BASE_MESSAGE,
|
|
283
|
+
targetDescriptor: wrtcPeerDescriptor2
|
|
283
284
|
}
|
|
284
285
|
const msg2: Message = {
|
|
285
|
-
...
|
|
286
|
-
targetDescriptor:
|
|
286
|
+
...BASE_MESSAGE,
|
|
287
|
+
targetDescriptor: wrtcPeerDescriptor1
|
|
287
288
|
}
|
|
288
289
|
|
|
289
290
|
const promise1 = new Promise<void>((resolve, _reject) => {
|
|
290
291
|
connectionManager1.on('message', async (message: Message) => {
|
|
291
|
-
expect(message.
|
|
292
|
+
expect(message.body.oneofKind).toBe('rpcMessage')
|
|
292
293
|
resolve()
|
|
293
294
|
})
|
|
294
295
|
})
|
|
295
296
|
const promise2 = new Promise<void>((resolve, _reject) => {
|
|
296
297
|
connectionManager2.on('message', async (message: Message) => {
|
|
297
|
-
expect(message.
|
|
298
|
+
expect(message.body.oneofKind).toBe('rpcMessage')
|
|
298
299
|
resolve()
|
|
299
300
|
})
|
|
300
301
|
})
|
|
@@ -306,8 +307,8 @@ describe('SimultaneousConnections', () => {
|
|
|
306
307
|
connectionManager2.send(msg2)
|
|
307
308
|
])
|
|
308
309
|
|
|
309
|
-
await waitForCondition(() => connectionManager1.hasConnection(
|
|
310
|
-
await waitForCondition(() => connectionManager2.hasConnection(
|
|
310
|
+
await waitForCondition(() => connectionManager1.hasConnection(getNodeIdFromPeerDescriptor(wrtcPeerDescriptor2)))
|
|
311
|
+
await waitForCondition(() => connectionManager2.hasConnection(getNodeIdFromPeerDescriptor(wrtcPeerDescriptor1)))
|
|
311
312
|
})
|
|
312
313
|
})
|
|
313
314
|
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { LatencyType, Simulator } from '../../src/connection/simulator/Simulator'
|
|
2
2
|
import { DhtNode } from '../../src/dht/DhtNode'
|
|
3
|
+
import { getDhtAddressFromRaw, getNodeIdFromPeerDescriptor } from '../../src/identifiers'
|
|
3
4
|
import { PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
import { createMockDataEntry, expectEqualData } from '../utils/mock/mockDataEntry'
|
|
6
|
+
import { createMockConnectionDhtNode, createMockPeerDescriptor, waitConnectionManagersReadyForTesting } from '../utils/utils'
|
|
7
|
+
|
|
8
|
+
const NUM_NODES = 100
|
|
9
|
+
const MAX_CONNECTIONS = 20
|
|
10
|
+
const K = 4
|
|
8
11
|
|
|
9
12
|
describe('Storing data in DHT', () => {
|
|
13
|
+
|
|
10
14
|
let entryPoint: DhtNode
|
|
11
15
|
let nodes: DhtNode[]
|
|
12
16
|
let entrypointDescriptor: PeerDescriptor
|
|
13
17
|
const simulator = new Simulator(LatencyType.REAL)
|
|
14
|
-
const NUM_NODES = 100
|
|
15
|
-
const MAX_CONNECTIONS = 20
|
|
16
|
-
const K = 4
|
|
17
|
-
const nodeIndicesById: Record<string, number> = {}
|
|
18
18
|
|
|
19
19
|
const getRandomNode = () => {
|
|
20
20
|
return nodes[Math.floor(Math.random() * nodes.length)]
|
|
@@ -22,18 +22,14 @@ describe('Storing data in DHT', () => {
|
|
|
22
22
|
|
|
23
23
|
beforeEach(async () => {
|
|
24
24
|
nodes = []
|
|
25
|
-
|
|
26
|
-
entryPoint = await createMockConnectionDhtNode(entryPointId, simulator,
|
|
25
|
+
entryPoint = await createMockConnectionDhtNode(simulator,
|
|
27
26
|
undefined, K, MAX_CONNECTIONS)
|
|
28
27
|
nodes.push(entryPoint)
|
|
29
|
-
nodeIndicesById[entryPoint.getNodeId().toKey()] = 0
|
|
30
28
|
entrypointDescriptor = entryPoint.getLocalPeerDescriptor()
|
|
31
29
|
nodes.push(entryPoint)
|
|
32
30
|
for (let i = 1; i < NUM_NODES; i++) {
|
|
33
|
-
const
|
|
34
|
-
const node = await createMockConnectionDhtNode(nodeId, simulator,
|
|
31
|
+
const node = await createMockConnectionDhtNode(simulator,
|
|
35
32
|
undefined, K, MAX_CONNECTIONS, 60000)
|
|
36
|
-
nodeIndicesById[node.getNodeId().toKey()] = i
|
|
37
33
|
nodes.push(node)
|
|
38
34
|
}
|
|
39
35
|
await Promise.all(nodes.map((node) => node.joinDht([entrypointDescriptor])))
|
|
@@ -42,28 +38,48 @@ describe('Storing data in DHT', () => {
|
|
|
42
38
|
|
|
43
39
|
afterEach(async () => {
|
|
44
40
|
await Promise.all(nodes.map((node) => node.stop()))
|
|
45
|
-
})
|
|
41
|
+
}, 15000)
|
|
46
42
|
|
|
47
43
|
it('Storing data works', async () => {
|
|
48
44
|
const storingNodeIndex = 34
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
|
|
45
|
+
const entry = createMockDataEntry()
|
|
46
|
+
const successfulStorers = await nodes[storingNodeIndex].storeDataToDht(
|
|
47
|
+
getDhtAddressFromRaw(entry.key),
|
|
48
|
+
entry.data!
|
|
49
|
+
)
|
|
52
50
|
expect(successfulStorers.length).toBeGreaterThan(4)
|
|
53
|
-
},
|
|
51
|
+
}, 30000)
|
|
54
52
|
|
|
55
53
|
it('Storing and getting data works', async () => {
|
|
56
54
|
const storingNode = getRandomNode()
|
|
57
|
-
const
|
|
58
|
-
const
|
|
59
|
-
|
|
55
|
+
const entry = createMockDataEntry()
|
|
56
|
+
const successfulStorers = await storingNode.storeDataToDht(
|
|
57
|
+
getDhtAddressFromRaw(entry.key),
|
|
58
|
+
entry.data!
|
|
59
|
+
)
|
|
60
60
|
expect(successfulStorers.length).toBeGreaterThan(4)
|
|
61
|
+
const fetchingNode = getRandomNode()
|
|
62
|
+
const results = await fetchingNode.fetchDataFromDht(getDhtAddressFromRaw(entry.key))
|
|
63
|
+
results.forEach((result) => {
|
|
64
|
+
expectEqualData(result, entry)
|
|
65
|
+
})
|
|
66
|
+
}, 30000)
|
|
61
67
|
|
|
68
|
+
it('storing with explicit creator', async () => {
|
|
69
|
+
const storingNode = getRandomNode()
|
|
70
|
+
const entry = createMockDataEntry()
|
|
71
|
+
const requestor = createMockPeerDescriptor()
|
|
72
|
+
const successfulStorers = await storingNode.storeDataToDht(
|
|
73
|
+
getDhtAddressFromRaw(entry.key),
|
|
74
|
+
entry.data!,
|
|
75
|
+
getDhtAddressFromRaw(requestor.nodeId)
|
|
76
|
+
)
|
|
77
|
+
expect(successfulStorers.length).toBeGreaterThan(4)
|
|
62
78
|
const fetchingNode = getRandomNode()
|
|
63
|
-
const results = await fetchingNode.
|
|
64
|
-
results.forEach((
|
|
65
|
-
|
|
66
|
-
expect(
|
|
79
|
+
const results = await fetchingNode.fetchDataFromDht(getDhtAddressFromRaw(entry.key))
|
|
80
|
+
results.forEach((result) => {
|
|
81
|
+
expectEqualData(result, entry)
|
|
82
|
+
expect(getDhtAddressFromRaw(result.creator)).toEqual(getNodeIdFromPeerDescriptor(requestor))
|
|
67
83
|
})
|
|
68
|
-
},
|
|
84
|
+
}, 30000)
|
|
69
85
|
})
|
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
import { LatencyType, Simulator } from '../../src/connection/simulator/Simulator'
|
|
2
2
|
import { DhtNode } from '../../src/dht/DhtNode'
|
|
3
|
-
import { PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
4
3
|
import { createMockConnectionDhtNode, waitConnectionManagersReadyForTesting } from '../utils/utils'
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
4
|
+
import { createMockDataEntry, expectEqualData } from '../utils/mock/mockDataEntry'
|
|
5
|
+
import { createRandomDhtAddress } from '../../src/identifiers'
|
|
6
|
+
import { getDhtAddressFromRaw } from '../../src/identifiers'
|
|
7
|
+
import { wait } from '@streamr/utils'
|
|
8
|
+
|
|
9
|
+
const NUM_NODES = 5
|
|
10
|
+
const MAX_CONNECTIONS = 5
|
|
11
|
+
const K = 4
|
|
8
12
|
|
|
9
13
|
describe('Storing data in DHT', () => {
|
|
10
|
-
|
|
14
|
+
|
|
11
15
|
let nodes: DhtNode[]
|
|
12
|
-
let entrypointDescriptor: PeerDescriptor
|
|
13
16
|
const simulator = new Simulator(LatencyType.REAL)
|
|
14
|
-
const NUM_NODES = 5
|
|
15
|
-
const MAX_CONNECTIONS = 5
|
|
16
|
-
const K = 4
|
|
17
|
-
const nodeIndicesById: Record<string, number> = {}
|
|
18
17
|
|
|
19
18
|
const getRandomNode = () => {
|
|
20
19
|
return nodes[Math.floor(Math.random() * nodes.length)]
|
|
@@ -22,21 +21,15 @@ describe('Storing data in DHT', () => {
|
|
|
22
21
|
|
|
23
22
|
beforeEach(async () => {
|
|
24
23
|
nodes = []
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
undefined, K, MAX_CONNECTIONS)
|
|
28
|
-
nodes.push(entryPoint)
|
|
29
|
-
nodeIndicesById[entryPoint.getNodeId().toKey()] = 0
|
|
30
|
-
entrypointDescriptor = entryPoint.getLocalPeerDescriptor()
|
|
24
|
+
const entryPoint = await createMockConnectionDhtNode(simulator,
|
|
25
|
+
createRandomDhtAddress(), K, MAX_CONNECTIONS)
|
|
31
26
|
nodes.push(entryPoint)
|
|
32
27
|
for (let i = 1; i < NUM_NODES; i++) {
|
|
33
|
-
const
|
|
34
|
-
const node = await createMockConnectionDhtNode(nodeId, simulator,
|
|
28
|
+
const node = await createMockConnectionDhtNode(simulator,
|
|
35
29
|
undefined, K, MAX_CONNECTIONS, 60000)
|
|
36
|
-
nodeIndicesById[node.getNodeId().toKey()] = i
|
|
37
30
|
nodes.push(node)
|
|
38
31
|
}
|
|
39
|
-
await Promise.all(nodes.map((node) => node.joinDht([
|
|
32
|
+
await Promise.all(nodes.map((node) => node.joinDht([entryPoint.getLocalPeerDescriptor()])))
|
|
40
33
|
await waitConnectionManagersReadyForTesting(nodes.map((node) => node.connectionManager!), MAX_CONNECTIONS)
|
|
41
34
|
}, 90000)
|
|
42
35
|
|
|
@@ -46,45 +39,40 @@ describe('Storing data in DHT', () => {
|
|
|
46
39
|
|
|
47
40
|
it('Data can be deleted', async () => {
|
|
48
41
|
const storingNode = getRandomNode()
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
const successfulStorers = await storingNode.storeDataToDht(dataKey.value, data)
|
|
42
|
+
const entry = createMockDataEntry()
|
|
43
|
+
const successfulStorers = await storingNode.storeDataToDht(getDhtAddressFromRaw(entry.key), entry.data!)
|
|
52
44
|
expect(successfulStorers.length).toBeGreaterThan(4)
|
|
53
|
-
await storingNode.deleteDataFromDht(
|
|
54
|
-
|
|
45
|
+
await storingNode.deleteDataFromDht(getDhtAddressFromRaw(entry.key), true)
|
|
46
|
+
// Wait for the delete operation to propagate
|
|
47
|
+
await wait(500)
|
|
55
48
|
const fetchingNode = getRandomNode()
|
|
56
|
-
const results = await fetchingNode.
|
|
57
|
-
results.forEach((
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
expect(areEqualPeerDescriptors(fetchedDescriptor, entrypointDescriptor)).toBeTrue()
|
|
49
|
+
const results = await fetchingNode.fetchDataFromDht(getDhtAddressFromRaw(entry.key))
|
|
50
|
+
results.forEach((result) => {
|
|
51
|
+
expect(result.deleted).toBeTrue()
|
|
52
|
+
expectEqualData(result, entry)
|
|
61
53
|
})
|
|
62
54
|
}, 90000)
|
|
63
55
|
|
|
64
56
|
it('Data can be deleted and re-stored', async () => {
|
|
65
57
|
const storingNode = getRandomNode()
|
|
66
|
-
const
|
|
67
|
-
const
|
|
68
|
-
const successfulStorers1 = await storingNode.storeDataToDht(dataKey.value, data)
|
|
58
|
+
const entry = createMockDataEntry()
|
|
59
|
+
const successfulStorers1 = await storingNode.storeDataToDht(getDhtAddressFromRaw(entry.key), entry.data!)
|
|
69
60
|
expect(successfulStorers1.length).toBeGreaterThan(4)
|
|
70
|
-
await storingNode.deleteDataFromDht(
|
|
71
|
-
|
|
61
|
+
await storingNode.deleteDataFromDht(getDhtAddressFromRaw(entry.key), true)
|
|
62
|
+
// Wait for the delete operation to propagate
|
|
63
|
+
await wait(500)
|
|
72
64
|
const fetchingNode = getRandomNode()
|
|
73
|
-
const results1 = await fetchingNode.
|
|
74
|
-
results1.forEach((
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
expect(areEqualPeerDescriptors(fetchedDescriptor, entrypointDescriptor)).toBeTrue()
|
|
65
|
+
const results1 = await fetchingNode.fetchDataFromDht(getDhtAddressFromRaw(entry.key))
|
|
66
|
+
results1.forEach((result) => {
|
|
67
|
+
expect(result.deleted).toBeTrue()
|
|
68
|
+
expectEqualData(result, entry)
|
|
78
69
|
})
|
|
79
|
-
|
|
80
|
-
const successfulStorers2 = await storingNode.storeDataToDht(dataKey.value, data)
|
|
70
|
+
const successfulStorers2 = await storingNode.storeDataToDht(getDhtAddressFromRaw(entry.key), entry.data!)
|
|
81
71
|
expect(successfulStorers2.length).toBeGreaterThan(4)
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
expect(entry.deleted).toBeFalse()
|
|
87
|
-
expect(areEqualPeerDescriptors(fetchedDescriptor, entrypointDescriptor)).toBeTrue()
|
|
72
|
+
const results2 = await fetchingNode.fetchDataFromDht(getDhtAddressFromRaw(entry.key))
|
|
73
|
+
results2.forEach((result) => {
|
|
74
|
+
expect(result.deleted).toBeFalse()
|
|
75
|
+
expectEqualData(result, entry)
|
|
88
76
|
})
|
|
89
77
|
}, 90000)
|
|
90
78
|
})
|