@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
|
@@ -3,10 +3,11 @@ import { ConnectionManager } from '../../src/connection/ConnectionManager'
|
|
|
3
3
|
import { DefaultConnectorFacade } from '../../src/connection/ConnectorFacade'
|
|
4
4
|
import { LatencyType, Simulator } from '../../src/connection/simulator/Simulator'
|
|
5
5
|
import { SimulatorTransport } from '../../src/connection/simulator/SimulatorTransport'
|
|
6
|
-
import { ITransport } from '../../src/
|
|
7
|
-
import {
|
|
8
|
-
import { NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
6
|
+
import { ITransport } from '../../src/transport/ITransport'
|
|
7
|
+
import { PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
9
8
|
import { getRandomRegion } from '../../dist/src/connection/simulator/pings'
|
|
9
|
+
import { createMockPeerDescriptor } from '../utils/utils'
|
|
10
|
+
import { getNodeIdFromPeerDescriptor } from '../../src/identifiers'
|
|
10
11
|
|
|
11
12
|
const createConnectionManager = (localPeerDescriptor: PeerDescriptor, transport: ITransport) => {
|
|
12
13
|
return new ConnectionManager({
|
|
@@ -20,23 +21,16 @@ const createConnectionManager = (localPeerDescriptor: PeerDescriptor, transport:
|
|
|
20
21
|
|
|
21
22
|
describe('Connection Locking', () => {
|
|
22
23
|
|
|
23
|
-
const mockPeerDescriptor1
|
|
24
|
-
kademliaId: PeerID.fromString('mock1').value,
|
|
25
|
-
type: NodeType.NODEJS,
|
|
24
|
+
const mockPeerDescriptor1 = createMockPeerDescriptor({
|
|
26
25
|
region: getRandomRegion()
|
|
27
|
-
}
|
|
28
|
-
const mockPeerDescriptor2
|
|
29
|
-
kademliaId: PeerID.fromString('mock2').value,
|
|
30
|
-
type: NodeType.NODEJS,
|
|
26
|
+
})
|
|
27
|
+
const mockPeerDescriptor2 = createMockPeerDescriptor({
|
|
31
28
|
region: getRandomRegion()
|
|
32
|
-
}
|
|
33
|
-
|
|
29
|
+
})
|
|
34
30
|
let mockConnectorTransport1: ConnectionManager
|
|
35
31
|
let mockConnectorTransport2: ConnectionManager
|
|
36
|
-
|
|
37
32
|
let connectionManager1: ConnectionManager
|
|
38
33
|
let connectionManager2: ConnectionManager
|
|
39
|
-
|
|
40
34
|
let simulator: Simulator
|
|
41
35
|
|
|
42
36
|
beforeEach(async () => {
|
|
@@ -62,114 +56,126 @@ describe('Connection Locking', () => {
|
|
|
62
56
|
})
|
|
63
57
|
|
|
64
58
|
it('can lock connections', async () => {
|
|
59
|
+
const nodeId1 = getNodeIdFromPeerDescriptor(mockPeerDescriptor1)
|
|
60
|
+
const nodeId2 = getNodeIdFromPeerDescriptor(mockPeerDescriptor2)
|
|
65
61
|
await Promise.all([
|
|
66
|
-
waitForCondition(() => connectionManager2.hasRemoteLockedConnection(
|
|
62
|
+
waitForCondition(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
|
|
67
63
|
connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock')
|
|
68
64
|
])
|
|
69
|
-
expect(connectionManager1.hasConnection(
|
|
70
|
-
expect(connectionManager1.hasLocalLockedConnection(
|
|
71
|
-
expect(connectionManager2.hasRemoteLockedConnection(
|
|
65
|
+
expect(connectionManager1.hasConnection(nodeId2)).toEqual(true)
|
|
66
|
+
expect(connectionManager1.hasLocalLockedConnection(nodeId2)).toEqual(true)
|
|
67
|
+
expect(connectionManager2.hasRemoteLockedConnection(nodeId1)).toEqual(true)
|
|
72
68
|
})
|
|
73
69
|
|
|
74
70
|
it('Multiple services on the same peer', async () => {
|
|
71
|
+
const nodeId1 = getNodeIdFromPeerDescriptor(mockPeerDescriptor1)
|
|
72
|
+
const nodeId2 = getNodeIdFromPeerDescriptor(mockPeerDescriptor2)
|
|
75
73
|
await Promise.all([
|
|
76
|
-
waitForCondition(() => connectionManager2.hasRemoteLockedConnection(
|
|
74
|
+
waitForCondition(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
|
|
77
75
|
connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock1')
|
|
78
76
|
])
|
|
79
77
|
await Promise.all([
|
|
80
|
-
waitForCondition(() => connectionManager2.hasRemoteLockedConnection(
|
|
78
|
+
waitForCondition(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
|
|
81
79
|
connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock2')
|
|
82
80
|
])
|
|
83
|
-
expect(connectionManager1.hasConnection(
|
|
84
|
-
expect(connectionManager1.hasLocalLockedConnection(
|
|
85
|
-
expect(connectionManager2.hasRemoteLockedConnection(
|
|
81
|
+
expect(connectionManager1.hasConnection(nodeId2)).toEqual(true)
|
|
82
|
+
expect(connectionManager1.hasLocalLockedConnection(nodeId2)).toEqual(true)
|
|
83
|
+
expect(connectionManager2.hasRemoteLockedConnection(nodeId1)).toEqual(true)
|
|
86
84
|
})
|
|
87
85
|
|
|
88
86
|
it('can unlock connections', async () => {
|
|
87
|
+
const nodeId1 = getNodeIdFromPeerDescriptor(mockPeerDescriptor1)
|
|
88
|
+
const nodeId2 = getNodeIdFromPeerDescriptor(mockPeerDescriptor2)
|
|
89
89
|
await Promise.all([
|
|
90
|
-
waitForCondition(() => connectionManager2.hasRemoteLockedConnection(
|
|
90
|
+
waitForCondition(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
|
|
91
91
|
connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock')
|
|
92
92
|
])
|
|
93
|
-
expect(connectionManager1.hasConnection(
|
|
94
|
-
expect(connectionManager2.hasLocalLockedConnection(
|
|
95
|
-
expect(connectionManager2.hasRemoteLockedConnection(
|
|
93
|
+
expect(connectionManager1.hasConnection(nodeId2))
|
|
94
|
+
expect(connectionManager2.hasLocalLockedConnection(nodeId2)).toEqual(false)
|
|
95
|
+
expect(connectionManager2.hasRemoteLockedConnection(nodeId1)).toEqual(true)
|
|
96
96
|
|
|
97
97
|
connectionManager1.unlockConnection(mockPeerDescriptor2, 'testLock')
|
|
98
|
-
expect(connectionManager1.hasLocalLockedConnection(
|
|
99
|
-
await waitForCondition(() => connectionManager2.hasRemoteLockedConnection(
|
|
100
|
-
expect(connectionManager1.hasConnection(
|
|
98
|
+
expect(connectionManager1.hasLocalLockedConnection(nodeId2)).toEqual(false)
|
|
99
|
+
await waitForCondition(() => connectionManager2.hasRemoteLockedConnection(nodeId1) === false)
|
|
100
|
+
expect(connectionManager1.hasConnection(nodeId1)).toEqual(false)
|
|
101
101
|
})
|
|
102
102
|
|
|
103
103
|
it('unlocking multiple services', async () => {
|
|
104
|
+
const nodeId1 = getNodeIdFromPeerDescriptor(mockPeerDescriptor1)
|
|
105
|
+
const nodeId2 = getNodeIdFromPeerDescriptor(mockPeerDescriptor2)
|
|
104
106
|
await Promise.all([
|
|
105
|
-
waitForCondition(() => connectionManager2.hasRemoteLockedConnection(
|
|
107
|
+
waitForCondition(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
|
|
106
108
|
connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock1')
|
|
107
109
|
])
|
|
108
110
|
await Promise.all([
|
|
109
|
-
waitForCondition(() => connectionManager2.hasRemoteLockedConnection(
|
|
111
|
+
waitForCondition(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
|
|
110
112
|
connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock2')
|
|
111
113
|
])
|
|
112
114
|
|
|
113
|
-
expect(connectionManager1.hasConnection(
|
|
114
|
-
expect(connectionManager2.hasLocalLockedConnection(
|
|
115
|
+
expect(connectionManager1.hasConnection(nodeId2))
|
|
116
|
+
expect(connectionManager2.hasLocalLockedConnection(nodeId1)).toEqual(false)
|
|
115
117
|
|
|
116
118
|
connectionManager1.unlockConnection(mockPeerDescriptor2, 'testLock1')
|
|
117
|
-
expect(connectionManager1.hasLocalLockedConnection(
|
|
119
|
+
expect(connectionManager1.hasLocalLockedConnection(nodeId2)).toEqual(true)
|
|
118
120
|
|
|
119
121
|
connectionManager1.unlockConnection(mockPeerDescriptor2, 'testLock2')
|
|
120
|
-
expect(connectionManager1.hasLocalLockedConnection(
|
|
121
|
-
expect(connectionManager1.hasConnection(
|
|
122
|
+
expect(connectionManager1.hasLocalLockedConnection(nodeId2)).toEqual(false)
|
|
123
|
+
expect(connectionManager1.hasConnection(nodeId1)).toEqual(false)
|
|
122
124
|
})
|
|
123
125
|
|
|
124
126
|
it('maintains connection if both sides initially lock and then one end unlocks', async () => {
|
|
127
|
+
const nodeId1 = getNodeIdFromPeerDescriptor(mockPeerDescriptor1)
|
|
128
|
+
const nodeId2 = getNodeIdFromPeerDescriptor(mockPeerDescriptor2)
|
|
125
129
|
await Promise.all([
|
|
126
|
-
waitForCondition(() => connectionManager2.hasRemoteLockedConnection(
|
|
127
|
-
waitForCondition(() => connectionManager1.hasRemoteLockedConnection(
|
|
130
|
+
waitForCondition(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
|
|
131
|
+
waitForCondition(() => connectionManager1.hasRemoteLockedConnection(nodeId2)),
|
|
128
132
|
connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock1'),
|
|
129
133
|
connectionManager2.lockConnection(mockPeerDescriptor1, 'testLock1')
|
|
130
134
|
])
|
|
131
135
|
|
|
132
|
-
expect(connectionManager1.hasLocalLockedConnection(
|
|
133
|
-
expect(connectionManager2.hasLocalLockedConnection(
|
|
136
|
+
expect(connectionManager1.hasLocalLockedConnection(nodeId2))
|
|
137
|
+
expect(connectionManager2.hasLocalLockedConnection(nodeId1))
|
|
134
138
|
|
|
135
139
|
connectionManager1.unlockConnection(mockPeerDescriptor2, 'testLock1')
|
|
136
140
|
await waitForCondition(() =>
|
|
137
|
-
connectionManager1.hasRemoteLockedConnection(
|
|
138
|
-
&& !connectionManager1.hasLocalLockedConnection(
|
|
139
|
-
&& !connectionManager2.hasRemoteLockedConnection(
|
|
140
|
-
&& connectionManager2.hasLocalLockedConnection(
|
|
141
|
+
connectionManager1.hasRemoteLockedConnection(nodeId2)
|
|
142
|
+
&& !connectionManager1.hasLocalLockedConnection(nodeId2)
|
|
143
|
+
&& !connectionManager2.hasRemoteLockedConnection(nodeId1)
|
|
144
|
+
&& connectionManager2.hasLocalLockedConnection(nodeId1)
|
|
141
145
|
)
|
|
142
146
|
|
|
143
|
-
expect(connectionManager2.hasConnection(
|
|
144
|
-
expect(connectionManager1.hasConnection(
|
|
147
|
+
expect(connectionManager2.hasConnection(nodeId1)).toEqual(true)
|
|
148
|
+
expect(connectionManager1.hasConnection(nodeId2)).toEqual(true)
|
|
145
149
|
})
|
|
146
150
|
|
|
147
151
|
it('unlocks after graceful disconnect', async () => {
|
|
152
|
+
const nodeId1 = getNodeIdFromPeerDescriptor(mockPeerDescriptor1)
|
|
153
|
+
const nodeId2 = getNodeIdFromPeerDescriptor(mockPeerDescriptor2)
|
|
148
154
|
await Promise.all([
|
|
149
|
-
waitForCondition(() => connectionManager2.hasRemoteLockedConnection(
|
|
150
|
-
waitForCondition(() => connectionManager1.hasRemoteLockedConnection(
|
|
155
|
+
waitForCondition(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
|
|
156
|
+
waitForCondition(() => connectionManager1.hasRemoteLockedConnection(nodeId2)),
|
|
151
157
|
connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock1'),
|
|
152
158
|
connectionManager2.lockConnection(mockPeerDescriptor1, 'testLock1')
|
|
153
159
|
])
|
|
154
|
-
expect(connectionManager1.hasConnection(
|
|
155
|
-
expect(connectionManager2.hasLocalLockedConnection(
|
|
156
|
-
expect(connectionManager2.hasRemoteLockedConnection(
|
|
160
|
+
expect(connectionManager1.hasConnection(nodeId2))
|
|
161
|
+
expect(connectionManager2.hasLocalLockedConnection(nodeId1)).toEqual(true)
|
|
162
|
+
expect(connectionManager2.hasRemoteLockedConnection(nodeId1)).toEqual(true)
|
|
157
163
|
|
|
158
164
|
//@ts-expect-error private field
|
|
159
165
|
await connectionManager1.gracefullyDisconnectAsync(mockPeerDescriptor2)
|
|
160
166
|
|
|
161
167
|
await waitForCondition(() =>
|
|
162
|
-
!connectionManager1.hasRemoteLockedConnection(
|
|
163
|
-
&& !connectionManager1.hasLocalLockedConnection(
|
|
168
|
+
!connectionManager1.hasRemoteLockedConnection(nodeId2)
|
|
169
|
+
&& !connectionManager1.hasLocalLockedConnection(nodeId2)
|
|
164
170
|
)
|
|
165
171
|
await waitForCondition(() =>
|
|
166
|
-
!connectionManager2.hasRemoteLockedConnection(
|
|
167
|
-
&& !connectionManager2.hasLocalLockedConnection(
|
|
172
|
+
!connectionManager2.hasRemoteLockedConnection(nodeId1)
|
|
173
|
+
&& !connectionManager2.hasLocalLockedConnection(nodeId1)
|
|
168
174
|
)
|
|
169
|
-
await waitForCondition(() => !connectionManager2.hasConnection(
|
|
170
|
-
await waitForCondition(() => !connectionManager1.hasConnection(
|
|
175
|
+
await waitForCondition(() => !connectionManager2.hasConnection(nodeId1))
|
|
176
|
+
await waitForCondition(() => !connectionManager1.hasConnection(nodeId2))
|
|
171
177
|
|
|
172
|
-
expect(connectionManager1.hasConnection(
|
|
173
|
-
expect(connectionManager2.hasConnection(
|
|
178
|
+
expect(connectionManager1.hasConnection(nodeId2)).toEqual(false)
|
|
179
|
+
expect(connectionManager2.hasConnection(nodeId1)).toEqual(false)
|
|
174
180
|
}, 10000)
|
|
175
181
|
})
|
|
@@ -1,45 +1,32 @@
|
|
|
1
|
+
import { Logger, MetricsContext, waitForEvent3 } from '@streamr/utils'
|
|
2
|
+
import { MarkOptional } from 'ts-essentials'
|
|
1
3
|
import { ConnectionManager } from '../../src/connection/ConnectionManager'
|
|
2
|
-
import {
|
|
3
|
-
import { PeerID } from '../../src/helpers/PeerID'
|
|
4
|
+
import { DefaultConnectorFacade, DefaultConnectorFacadeConfig } from '../../src/connection/ConnectorFacade'
|
|
4
5
|
import { Simulator } from '../../src/connection/simulator/Simulator'
|
|
5
|
-
import {
|
|
6
|
+
import { SimulatorTransport } from '../../src/connection/simulator/SimulatorTransport'
|
|
7
|
+
import { createPeerDescriptor } from '../../src/helpers/createPeerDescriptor'
|
|
8
|
+
import { createRandomDhtAddress, getRawFromDhtAddress } from '../../src/identifiers'
|
|
9
|
+
import { ConnectivityResponse, Message, NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
6
10
|
import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
|
|
7
|
-
import { Logger, MetricsContext, waitForEvent3 } from '@streamr/utils'
|
|
8
|
-
import { SimulatorTransport } from '../../src/exports'
|
|
9
|
-
import { DefaultConnectorFacade, DefaultConnectorFacadeConfig } from '../../src/connection/ConnectorFacade'
|
|
10
|
-
import { MarkOptional } from 'ts-essentials'
|
|
11
|
-
import { createRandomKademliaId } from '../../src/helpers/kademliaId'
|
|
12
11
|
import { TransportEvents } from '../../src/transport/ITransport'
|
|
12
|
+
import { createMockPeerDescriptor } from '../utils/utils'
|
|
13
|
+
import { getRandomRegion } from '../../src/connection/simulator/pings'
|
|
14
|
+
|
|
15
|
+
const SERVICE_ID = 'demo'
|
|
13
16
|
|
|
14
17
|
const logger = new Logger(module)
|
|
15
18
|
|
|
16
19
|
// TODO: refactor this test file to use beforeEach and AfterEach for proper teardown
|
|
17
20
|
describe('ConnectionManager', () => {
|
|
18
|
-
const serviceId = 'demo'
|
|
19
21
|
|
|
20
|
-
const mockPeerDescriptor1
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const mockPeerDescriptor2: PeerDescriptor = {
|
|
25
|
-
kademliaId: PeerID.fromString('tester2').value,
|
|
26
|
-
type: NodeType.NODEJS
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const mockPeerDescriptor3: PeerDescriptor = {
|
|
30
|
-
kademliaId: PeerID.fromString('tester3').value,
|
|
31
|
-
type: NodeType.NODEJS
|
|
32
|
-
}
|
|
33
|
-
const mockPeerDescriptor4: PeerDescriptor = {
|
|
34
|
-
kademliaId: PeerID.fromString('tester4').value,
|
|
35
|
-
type: NodeType.NODEJS
|
|
36
|
-
}
|
|
22
|
+
const mockPeerDescriptor1 = createMockPeerDescriptor()
|
|
23
|
+
const mockPeerDescriptor2 = createMockPeerDescriptor()
|
|
24
|
+
const mockPeerDescriptor3 = createMockPeerDescriptor()
|
|
25
|
+
const mockPeerDescriptor4 = createMockPeerDescriptor()
|
|
37
26
|
const simulator = new Simulator()
|
|
38
|
-
|
|
39
27
|
const mockTransport = new SimulatorTransport(mockPeerDescriptor1, simulator)
|
|
40
28
|
const mockConnectorTransport1 = new SimulatorTransport(mockPeerDescriptor1, simulator)
|
|
41
29
|
const mockConnectorTransport2 = new SimulatorTransport(mockPeerDescriptor2, simulator)
|
|
42
|
-
|
|
43
30
|
let createLocalPeerDescriptor: jest.Mock<PeerDescriptor, [ConnectivityResponse]>
|
|
44
31
|
|
|
45
32
|
const createConnectionManager = (opts: MarkOptional<DefaultConnectorFacadeConfig, 'createLocalPeerDescriptor'>) => {
|
|
@@ -54,7 +41,7 @@ describe('ConnectionManager', () => {
|
|
|
54
41
|
}
|
|
55
42
|
|
|
56
43
|
beforeEach(() => {
|
|
57
|
-
createLocalPeerDescriptor = jest.fn().mockImplementation((response) => createPeerDescriptor(response))
|
|
44
|
+
createLocalPeerDescriptor = jest.fn().mockImplementation((response) => createPeerDescriptor(response, getRandomRegion()))
|
|
58
45
|
})
|
|
59
46
|
|
|
60
47
|
beforeAll(async () => {
|
|
@@ -85,12 +72,13 @@ describe('ConnectionManager', () => {
|
|
|
85
72
|
|
|
86
73
|
it('Throws an async exception if fails to connect to entrypoints', async () => {
|
|
87
74
|
|
|
75
|
+
const entryPoint = createMockPeerDescriptor({
|
|
76
|
+
websocket: { host: '127.0.0.1', port: 12345, tls: false }
|
|
77
|
+
})
|
|
88
78
|
const connectionManager = createConnectionManager({
|
|
89
79
|
transport: mockTransport,
|
|
90
80
|
websocketPortRange: { min: 9992, max: 9992 },
|
|
91
|
-
entryPoints: [
|
|
92
|
-
{ kademliaId: Uint8Array.from([1, 2, 3]), type: NodeType.NODEJS, websocket: { host: '127.0.0.1', port: 12345, tls: false } }
|
|
93
|
-
]
|
|
81
|
+
entryPoints: [entryPoint]
|
|
94
82
|
})
|
|
95
83
|
|
|
96
84
|
await expect(connectionManager.start()).rejects.toThrow('Failed to connect to the entrypoints')
|
|
@@ -108,12 +96,13 @@ describe('ConnectionManager', () => {
|
|
|
108
96
|
await connectionManager1.start()
|
|
109
97
|
expect(createLocalPeerDescriptor.mock.calls[0][0].host).toEqual('127.0.0.1')
|
|
110
98
|
|
|
99
|
+
const entryPoint = createMockPeerDescriptor({
|
|
100
|
+
websocket: { host: '127.0.0.1', port: 9993, tls: false }
|
|
101
|
+
})
|
|
111
102
|
const connectionManager2 = createConnectionManager({
|
|
112
103
|
transport: mockConnectorTransport2,
|
|
113
104
|
websocketPortRange: { min: 9994, max: 9994 },
|
|
114
|
-
entryPoints: [
|
|
115
|
-
{ kademliaId: Uint8Array.from([1, 2, 3]), type: NodeType.NODEJS, websocket: { host: '127.0.0.1', port: 9993, tls: false } }
|
|
116
|
-
]
|
|
105
|
+
entryPoints: [entryPoint]
|
|
117
106
|
})
|
|
118
107
|
|
|
119
108
|
await connectionManager2.start()
|
|
@@ -145,8 +134,7 @@ describe('ConnectionManager', () => {
|
|
|
145
134
|
expect(createLocalPeerDescriptor.mock.calls[1][0].host).toEqual('127.0.0.1')
|
|
146
135
|
|
|
147
136
|
const msg: Message = {
|
|
148
|
-
serviceId,
|
|
149
|
-
messageType: MessageType.RPC,
|
|
137
|
+
serviceId: SERVICE_ID,
|
|
150
138
|
messageId: '1',
|
|
151
139
|
body: {
|
|
152
140
|
oneofKind: 'rpcMessage',
|
|
@@ -156,7 +144,7 @@ describe('ConnectionManager', () => {
|
|
|
156
144
|
|
|
157
145
|
const promise = new Promise<void>((resolve, _reject) => {
|
|
158
146
|
connectionManager2.on('message', async (message: Message) => {
|
|
159
|
-
expect(message.
|
|
147
|
+
expect(message.body.oneofKind).toBe('rpcMessage')
|
|
160
148
|
resolve()
|
|
161
149
|
})
|
|
162
150
|
})
|
|
@@ -204,8 +192,7 @@ describe('ConnectionManager', () => {
|
|
|
204
192
|
await connectionManager2.start()
|
|
205
193
|
|
|
206
194
|
const msg: Message = {
|
|
207
|
-
serviceId,
|
|
208
|
-
messageType: MessageType.RPC,
|
|
195
|
+
serviceId: SERVICE_ID,
|
|
209
196
|
messageId: '1',
|
|
210
197
|
body: {
|
|
211
198
|
oneofKind: 'rpcMessage',
|
|
@@ -229,7 +216,7 @@ describe('ConnectionManager', () => {
|
|
|
229
216
|
|
|
230
217
|
const promise = new Promise<void>((resolve, _reject) => {
|
|
231
218
|
connectionManager2.on('message', async (message: Message) => {
|
|
232
|
-
expect(message.
|
|
219
|
+
expect(message.body.oneofKind).toBe('rpcMessage')
|
|
233
220
|
resolve()
|
|
234
221
|
})
|
|
235
222
|
})
|
|
@@ -255,8 +242,7 @@ describe('ConnectionManager', () => {
|
|
|
255
242
|
await connectionManager4.start()
|
|
256
243
|
|
|
257
244
|
const msg: Message = {
|
|
258
|
-
serviceId,
|
|
259
|
-
messageType: MessageType.RPC,
|
|
245
|
+
serviceId: SERVICE_ID,
|
|
260
246
|
messageId: '1',
|
|
261
247
|
body: {
|
|
262
248
|
oneofKind: 'rpcMessage',
|
|
@@ -266,7 +252,7 @@ describe('ConnectionManager', () => {
|
|
|
266
252
|
|
|
267
253
|
const dataPromise = new Promise<void>((resolve, _reject) => {
|
|
268
254
|
connectionManager4.on('message', async (message: Message) => {
|
|
269
|
-
expect(message.
|
|
255
|
+
expect(message.body.oneofKind).toBe('rpcMessage')
|
|
270
256
|
resolve()
|
|
271
257
|
})
|
|
272
258
|
})
|
|
@@ -304,9 +290,10 @@ describe('ConnectionManager', () => {
|
|
|
304
290
|
await Promise.all([disconnectedPromise1, disconnectedPromise2])
|
|
305
291
|
await connectionManager3.stop()
|
|
306
292
|
await connectionManager4.stop()
|
|
293
|
+
simulator2.stop()
|
|
307
294
|
})
|
|
308
295
|
|
|
309
|
-
it('Cannot send to own WebsocketServer if
|
|
296
|
+
it('Cannot send to own WebsocketServer if nodeIds do not match', async () => {
|
|
310
297
|
const connectionManager1 = createConnectionManager({
|
|
311
298
|
transport: mockTransport,
|
|
312
299
|
websocketHost: '127.0.0.1',
|
|
@@ -317,10 +304,9 @@ describe('ConnectionManager', () => {
|
|
|
317
304
|
expect(createLocalPeerDescriptor.mock.calls[0][0].host).toEqual('127.0.0.1')
|
|
318
305
|
|
|
319
306
|
const peerDescriptor = connectionManager1.getLocalPeerDescriptor()
|
|
320
|
-
peerDescriptor.
|
|
307
|
+
peerDescriptor.nodeId = new Uint8Array([12, 12, 12, 12])
|
|
321
308
|
const msg: Message = {
|
|
322
|
-
serviceId,
|
|
323
|
-
messageType: MessageType.RPC,
|
|
309
|
+
serviceId: SERVICE_ID,
|
|
324
310
|
messageId: '1',
|
|
325
311
|
targetDescriptor: peerDescriptor,
|
|
326
312
|
body: {
|
|
@@ -335,27 +321,22 @@ describe('ConnectionManager', () => {
|
|
|
335
321
|
await connectionManager1.stop()
|
|
336
322
|
})
|
|
337
323
|
|
|
338
|
-
it('Cannot send to a WebSocketServer if
|
|
324
|
+
it('Cannot send to a WebSocketServer if nodeIds do not match', async () => {
|
|
339
325
|
|
|
340
|
-
const peerDescriptor1 = {
|
|
341
|
-
kademliaId: createRandomKademliaId(),
|
|
342
|
-
type: NodeType.NODEJS,
|
|
326
|
+
const peerDescriptor1 = createMockPeerDescriptor({
|
|
343
327
|
websocket: {
|
|
344
328
|
host: '127.0.0.1',
|
|
345
329
|
port: 10002,
|
|
346
330
|
tls: false
|
|
347
331
|
}
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
const peerDescriptor2 = {
|
|
351
|
-
kademliaId: createRandomKademliaId(),
|
|
352
|
-
type: NodeType.NODEJS,
|
|
332
|
+
})
|
|
333
|
+
const peerDescriptor2 = createMockPeerDescriptor({
|
|
353
334
|
websocket: {
|
|
354
335
|
host: '127.0.0.1',
|
|
355
336
|
port: 10003,
|
|
356
337
|
tls: false
|
|
357
338
|
}
|
|
358
|
-
}
|
|
339
|
+
})
|
|
359
340
|
const connectionManager1 = createConnectionManager({
|
|
360
341
|
transport: mockTransport,
|
|
361
342
|
websocketHost: '127.0.0.1',
|
|
@@ -375,12 +356,11 @@ describe('ConnectionManager', () => {
|
|
|
375
356
|
await connectionManager2.start()
|
|
376
357
|
|
|
377
358
|
const msg: Message = {
|
|
378
|
-
serviceId,
|
|
379
|
-
messageType: MessageType.RPC,
|
|
359
|
+
serviceId: SERVICE_ID,
|
|
380
360
|
messageId: '1',
|
|
381
361
|
targetDescriptor: {
|
|
382
|
-
// This is not the correct
|
|
383
|
-
|
|
362
|
+
// This is not the correct nodeId of peerDescriptor2
|
|
363
|
+
nodeId: getRawFromDhtAddress(createRandomDhtAddress()),
|
|
384
364
|
type: NodeType.NODEJS,
|
|
385
365
|
websocket: peerDescriptor2.websocket
|
|
386
366
|
},
|
|
@@ -404,7 +384,7 @@ describe('ConnectionManager', () => {
|
|
|
404
384
|
const connectionManager1 = createConnectionManager({
|
|
405
385
|
transport: mockTransport,
|
|
406
386
|
websocketHost: '127.0.0.1',
|
|
407
|
-
autoCertifierUrl: 'https://
|
|
387
|
+
autoCertifierUrl: 'https://127.0.0.1:12333',
|
|
408
388
|
websocketServerEnableTls: true,
|
|
409
389
|
websocketPortRange: { min: 10004, max: 10004 }
|
|
410
390
|
})
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { MetricsContext } from '@streamr/utils'
|
|
2
|
+
import { ConnectionManager } from '../../src/connection/ConnectionManager'
|
|
3
|
+
import { DefaultConnectorFacade } from '../../src/connection/ConnectorFacade'
|
|
4
|
+
import { MockTransport } from '../utils/mock/Transport'
|
|
5
|
+
import { createMockPeerDescriptor } from '../utils/utils'
|
|
6
|
+
import { sendConnectivityRequest } from '../../src/connection/connectivityChecker'
|
|
7
|
+
import { LOCAL_PROTOCOL_VERSION } from '../../src/helpers/version'
|
|
8
|
+
|
|
9
|
+
describe('ConnectivityChecking', () => {
|
|
10
|
+
|
|
11
|
+
let server: ConnectionManager
|
|
12
|
+
const PORT = 15000
|
|
13
|
+
const HOST = '127.0.0.1'
|
|
14
|
+
|
|
15
|
+
beforeEach(async () => {
|
|
16
|
+
server = new ConnectionManager({
|
|
17
|
+
createConnectorFacade: () => new DefaultConnectorFacade({
|
|
18
|
+
createLocalPeerDescriptor: () => {
|
|
19
|
+
return {
|
|
20
|
+
...createMockPeerDescriptor(),
|
|
21
|
+
websocket: {
|
|
22
|
+
host: HOST,
|
|
23
|
+
port: PORT,
|
|
24
|
+
tls: false
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
websocketHost: HOST,
|
|
29
|
+
websocketPortRange: { min: PORT, max: PORT },
|
|
30
|
+
websocketServerEnableTls: false,
|
|
31
|
+
transport: new MockTransport()
|
|
32
|
+
}),
|
|
33
|
+
metricsContext: new MetricsContext()
|
|
34
|
+
})
|
|
35
|
+
await server.start()
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
afterEach(async () => {
|
|
39
|
+
await server.stop()
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
it('connectivityCheck with compatible version', async () => {
|
|
43
|
+
const request = {
|
|
44
|
+
host: HOST,
|
|
45
|
+
port: PORT,
|
|
46
|
+
tls: false,
|
|
47
|
+
selfSigned: false
|
|
48
|
+
}
|
|
49
|
+
const response = await sendConnectivityRequest(request, server.getLocalPeerDescriptor())
|
|
50
|
+
expect(response.version).toEqual(LOCAL_PROTOCOL_VERSION)
|
|
51
|
+
})
|
|
52
|
+
})
|
|
@@ -1,34 +1,30 @@
|
|
|
1
1
|
import { LatencyType, Simulator } from '../../src/connection/simulator/Simulator'
|
|
2
2
|
import { getRandomRegion } from '../../src/connection/simulator/pings'
|
|
3
3
|
import { DhtNode } from '../../src/dht/DhtNode'
|
|
4
|
-
import {
|
|
5
|
-
import { createMockConnectionDhtNode } from '../utils/utils'
|
|
4
|
+
import { getDhtAddressFromRaw } from '../../src/identifiers'
|
|
5
|
+
import { createMockConnectionDhtNode, createMockPeerDescriptor } from '../utils/utils'
|
|
6
6
|
|
|
7
7
|
const NUM_OF_NODES_PER_KBUCKET = 8
|
|
8
8
|
|
|
9
9
|
const runTest = async (latencyType: LatencyType) => {
|
|
10
10
|
const simulator = new Simulator(latencyType)
|
|
11
|
-
const
|
|
12
|
-
const entryPoint = await createMockConnectionDhtNode(entryPointId, simulator, undefined, NUM_OF_NODES_PER_KBUCKET)
|
|
13
|
-
const entrypointDescriptor = {
|
|
14
|
-
kademliaId: entryPoint.getNodeId().value,
|
|
15
|
-
type: NodeType.NODEJS,
|
|
11
|
+
const entrypointDescriptor = createMockPeerDescriptor({
|
|
16
12
|
region: getRandomRegion()
|
|
17
|
-
}
|
|
13
|
+
})
|
|
14
|
+
const entryPoint = await createMockConnectionDhtNode(simulator, getDhtAddressFromRaw(entrypointDescriptor.nodeId), NUM_OF_NODES_PER_KBUCKET)
|
|
18
15
|
const nodes: DhtNode[] = []
|
|
19
16
|
for (let i = 1; i < 100; i++) {
|
|
20
|
-
const
|
|
21
|
-
const node = await createMockConnectionDhtNode(nodeId, simulator, undefined, NUM_OF_NODES_PER_KBUCKET)
|
|
17
|
+
const node = await createMockConnectionDhtNode(simulator, undefined, NUM_OF_NODES_PER_KBUCKET)
|
|
22
18
|
nodes.push(node)
|
|
23
19
|
}
|
|
24
20
|
|
|
25
21
|
await entryPoint.joinDht([entrypointDescriptor])
|
|
26
22
|
await Promise.all(nodes.map((node) => node.joinDht([entrypointDescriptor])))
|
|
27
23
|
nodes.forEach((node) => {
|
|
28
|
-
expect(node.
|
|
24
|
+
expect(node.getNeighborCount()).toBeGreaterThanOrEqual(NUM_OF_NODES_PER_KBUCKET / 2)
|
|
29
25
|
expect(node.getClosestContacts().length).toBeGreaterThanOrEqual(NUM_OF_NODES_PER_KBUCKET / 2)
|
|
30
26
|
})
|
|
31
|
-
expect(entryPoint.
|
|
27
|
+
expect(entryPoint.getNeighborCount()).toBeGreaterThanOrEqual(NUM_OF_NODES_PER_KBUCKET / 2)
|
|
32
28
|
|
|
33
29
|
await Promise.all([
|
|
34
30
|
entryPoint.stop(),
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { DhtNode } from '../../src/dht/DhtNode'
|
|
2
1
|
import { LatencyType, Simulator } from '../../src/connection/simulator/Simulator'
|
|
2
|
+
import { DhtNode } from '../../src/dht/DhtNode'
|
|
3
|
+
import { createRandomDhtAddress, getDhtAddressFromRaw, getNodeIdFromPeerDescriptor } from '../../src/identifiers'
|
|
4
|
+
import { createMockDataEntry, expectEqualData } from '../utils/mock/mockDataEntry'
|
|
3
5
|
import { createMockConnectionDhtNode } from '../utils/utils'
|
|
4
|
-
import { Any } from '../../src/proto/google/protobuf/any'
|
|
5
|
-
import { PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
6
|
-
import { PeerID } from '../../src/helpers/PeerID'
|
|
7
6
|
|
|
8
7
|
describe('DhtNodeExternalApi', () => {
|
|
9
8
|
|
|
@@ -13,8 +12,8 @@ describe('DhtNodeExternalApi', () => {
|
|
|
13
12
|
|
|
14
13
|
beforeEach(async () => {
|
|
15
14
|
simulator = new Simulator(LatencyType.NONE)
|
|
16
|
-
dhtNode1 = await createMockConnectionDhtNode(
|
|
17
|
-
remote = await createMockConnectionDhtNode(
|
|
15
|
+
dhtNode1 = await createMockConnectionDhtNode(simulator)
|
|
16
|
+
remote = await createMockConnectionDhtNode(simulator)
|
|
18
17
|
await dhtNode1.joinDht([dhtNode1.getLocalPeerDescriptor()])
|
|
19
18
|
})
|
|
20
19
|
|
|
@@ -26,27 +25,24 @@ describe('DhtNodeExternalApi', () => {
|
|
|
26
25
|
simulator.stop()
|
|
27
26
|
})
|
|
28
27
|
|
|
29
|
-
it('
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
await
|
|
33
|
-
|
|
34
|
-
const foundData = await remote.findDataViaPeer(key, dhtNode1.getLocalPeerDescriptor())
|
|
35
|
-
expect(Any.unpack(foundData[0].data!, PeerDescriptor)).toEqual(dhtNode1.getLocalPeerDescriptor())
|
|
28
|
+
it('fetch data happy path', async () => {
|
|
29
|
+
const entry = createMockDataEntry()
|
|
30
|
+
await dhtNode1.storeDataToDht(getDhtAddressFromRaw(entry.key), entry.data!)
|
|
31
|
+
const foundData = await remote.fetchDataFromDhtViaPeer(getDhtAddressFromRaw(entry.key), dhtNode1.getLocalPeerDescriptor())
|
|
32
|
+
expectEqualData(foundData[0], entry)
|
|
36
33
|
})
|
|
37
34
|
|
|
38
|
-
it('
|
|
39
|
-
const foundData = await remote.
|
|
35
|
+
it('fetch data returns empty array if no data found', async () => {
|
|
36
|
+
const foundData = await remote.fetchDataFromDhtViaPeer(createRandomDhtAddress(), dhtNode1.getLocalPeerDescriptor())
|
|
40
37
|
expect(foundData).toEqual([])
|
|
41
38
|
})
|
|
42
39
|
|
|
43
40
|
it('external store data happy path', async () => {
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
expect(Any.unpack(foundData[0].data!, PeerDescriptor)).toEqual(dhtNode1.getLocalPeerDescriptor())
|
|
41
|
+
const entry = createMockDataEntry()
|
|
42
|
+
await remote.storeDataToDhtViaPeer(getDhtAddressFromRaw(entry.key), entry.data!, dhtNode1.getLocalPeerDescriptor())
|
|
43
|
+
const foundData = await remote.fetchDataFromDhtViaPeer(getDhtAddressFromRaw(entry.key), dhtNode1.getLocalPeerDescriptor())
|
|
44
|
+
expectEqualData(foundData[0], entry)
|
|
45
|
+
expect(getDhtAddressFromRaw(foundData[0].creator)).toEqual(getNodeIdFromPeerDescriptor(remote.getLocalPeerDescriptor()))
|
|
50
46
|
})
|
|
51
47
|
|
|
52
48
|
})
|