@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
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { createMockConnectionDhtNode } from '../utils/utils'
|
|
2
|
+
import { DhtNode } from '../../src/dht/DhtNode'
|
|
3
|
+
import { Simulator } from '../../src/connection/simulator/Simulator'
|
|
4
|
+
import { createMockDataEntry, expectEqualData } from '../utils/mock/mockDataEntry'
|
|
5
|
+
import { getDhtAddressFromRaw } from '../../src/identifiers'
|
|
6
|
+
|
|
7
|
+
describe('Storing data in DHT with two peers', () => {
|
|
8
|
+
|
|
9
|
+
let entryPoint: DhtNode
|
|
10
|
+
let node1: DhtNode
|
|
11
|
+
let node2: DhtNode
|
|
12
|
+
let simulator: Simulator | undefined
|
|
13
|
+
|
|
14
|
+
beforeEach(async () => {
|
|
15
|
+
simulator = new Simulator()
|
|
16
|
+
entryPoint = await createMockConnectionDhtNode(simulator)
|
|
17
|
+
node1 = await createMockConnectionDhtNode(simulator)
|
|
18
|
+
node2 = await createMockConnectionDhtNode(simulator)
|
|
19
|
+
|
|
20
|
+
await entryPoint.start()
|
|
21
|
+
await node1.start()
|
|
22
|
+
await node2.start()
|
|
23
|
+
|
|
24
|
+
await entryPoint.joinDht([entryPoint.getLocalPeerDescriptor()])
|
|
25
|
+
node1.joinDht([entryPoint.getLocalPeerDescriptor()]).catch(() => {})
|
|
26
|
+
node2.joinDht([entryPoint.getLocalPeerDescriptor()]).catch(() => {})
|
|
27
|
+
await Promise.all([
|
|
28
|
+
node1.waitForNetworkConnectivity(),
|
|
29
|
+
node2.waitForNetworkConnectivity()
|
|
30
|
+
])
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
afterEach(async () => {
|
|
34
|
+
await entryPoint.stop()
|
|
35
|
+
await node1.stop()
|
|
36
|
+
await node2.stop()
|
|
37
|
+
simulator?.stop()
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
it('Node can store on three peer DHT', async () => {
|
|
41
|
+
const storedData1 = createMockDataEntry()
|
|
42
|
+
const storedData2 = createMockDataEntry()
|
|
43
|
+
// Here we effectively test that fetching "null" data doesn't take too long. A test timeout here indicates an issue.
|
|
44
|
+
await node1.fetchDataFromDht(getDhtAddressFromRaw(storedData1.key))
|
|
45
|
+
await node2.fetchDataFromDht(getDhtAddressFromRaw(storedData1.key))
|
|
46
|
+
|
|
47
|
+
await node1.storeDataToDht(getDhtAddressFromRaw(storedData1.key), storedData1.data!)
|
|
48
|
+
await node2.storeDataToDht(getDhtAddressFromRaw(storedData1.key), storedData1.data!)
|
|
49
|
+
await entryPoint.storeDataToDht(getDhtAddressFromRaw(storedData2.key), storedData2.data!)
|
|
50
|
+
const foundData1 = await node1.fetchDataFromDht(getDhtAddressFromRaw(storedData1.key))
|
|
51
|
+
const foundData2 = await node2.fetchDataFromDht(getDhtAddressFromRaw(storedData1.key))
|
|
52
|
+
const foundData3 = await entryPoint.fetchDataFromDht(getDhtAddressFromRaw(storedData2.key))
|
|
53
|
+
expectEqualData(foundData1[0], storedData1)
|
|
54
|
+
expectEqualData(foundData1[1], storedData1)
|
|
55
|
+
expectEqualData(foundData2[0], storedData1)
|
|
56
|
+
expectEqualData(foundData2[1], storedData1)
|
|
57
|
+
expectEqualData(foundData3[0], storedData2)
|
|
58
|
+
}, 30000)
|
|
59
|
+
})
|
|
@@ -1,31 +1,20 @@
|
|
|
1
1
|
import { createMockConnectionDhtNode } from '../utils/utils'
|
|
2
2
|
import { DhtNode } from '../../src/dht/DhtNode'
|
|
3
3
|
import { Simulator } from '../../src/connection/simulator/Simulator'
|
|
4
|
-
import { PeerID } from '../../src/helpers/PeerID'
|
|
5
|
-
import { Any } from '../../src/proto/google/protobuf/any'
|
|
6
|
-
import { PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
7
|
-
import { areEqualPeerDescriptors } from '../../src/helpers/peerIdFromPeerDescriptor'
|
|
8
4
|
import { waitForCondition } from '@streamr/utils'
|
|
5
|
+
import { createMockDataEntry, expectEqualData } from '../utils/mock/mockDataEntry'
|
|
6
|
+
import { getDhtAddressFromRaw } from '../../src/identifiers'
|
|
9
7
|
|
|
10
8
|
describe('Storing data in DHT with two peers', () => {
|
|
11
9
|
|
|
12
10
|
let entryPoint: DhtNode
|
|
13
11
|
let otherNode: DhtNode
|
|
14
|
-
|
|
15
12
|
let simulator: Simulator | undefined
|
|
16
13
|
|
|
17
14
|
beforeEach(async () => {
|
|
18
15
|
simulator = new Simulator()
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
entryPoint = await createMockConnectionDhtNode(
|
|
22
|
-
entryPointId,
|
|
23
|
-
simulator,
|
|
24
|
-
)
|
|
25
|
-
otherNode = await createMockConnectionDhtNode(
|
|
26
|
-
otherNodeId,
|
|
27
|
-
simulator
|
|
28
|
-
)
|
|
16
|
+
entryPoint = await createMockConnectionDhtNode(simulator)
|
|
17
|
+
otherNode = await createMockConnectionDhtNode(simulator)
|
|
29
18
|
|
|
30
19
|
await entryPoint.start()
|
|
31
20
|
await otherNode.start()
|
|
@@ -41,31 +30,22 @@ describe('Storing data in DHT with two peers', () => {
|
|
|
41
30
|
})
|
|
42
31
|
|
|
43
32
|
it('Node can store on two peer DHT', async () => {
|
|
44
|
-
const
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
expect(successfulStorers2[0].kademliaId).toStrictEqual(otherNode.getLocalPeerDescriptor().kademliaId)
|
|
53
|
-
|
|
54
|
-
const foundData1 = await otherNode.getDataFromDht(dataKey1.value)
|
|
55
|
-
const foundData2 = await entryPoint.getDataFromDht(dataKey2.value)
|
|
56
|
-
expect(areEqualPeerDescriptors(otherNode.getLocalPeerDescriptor(), Any.unpack(foundData1[0]!.data!, PeerDescriptor))).toBeTrue()
|
|
57
|
-
expect(areEqualPeerDescriptors(entryPoint.getLocalPeerDescriptor(), Any.unpack(foundData2[0]!.data!, PeerDescriptor))).toBeTrue()
|
|
33
|
+
const storedData1 = createMockDataEntry()
|
|
34
|
+
const storedData2 = createMockDataEntry()
|
|
35
|
+
await otherNode.storeDataToDht(getDhtAddressFromRaw(storedData1.key), storedData1.data!)
|
|
36
|
+
await entryPoint.storeDataToDht(getDhtAddressFromRaw(storedData2.key), storedData2.data!)
|
|
37
|
+
const foundData1 = await otherNode.fetchDataFromDht(getDhtAddressFromRaw(storedData1.key))
|
|
38
|
+
const foundData2 = await entryPoint.fetchDataFromDht(getDhtAddressFromRaw(storedData2.key))
|
|
39
|
+
expectEqualData(foundData1[0], storedData1)
|
|
40
|
+
expectEqualData(foundData2[0], storedData2)
|
|
58
41
|
})
|
|
59
42
|
|
|
60
43
|
it('Can store on one peer DHT', async () => {
|
|
61
44
|
await otherNode.stop()
|
|
62
|
-
await waitForCondition(() => entryPoint.
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const foundData = await entryPoint.getDataFromDht(dataKey.value)
|
|
69
|
-
expect(areEqualPeerDescriptors(entryPoint.getLocalPeerDescriptor(), Any.unpack(foundData[0]!.data!, PeerDescriptor))).toBeTrue()
|
|
45
|
+
await waitForCondition(() => entryPoint.getNeighborCount() === 0)
|
|
46
|
+
const storedData = createMockDataEntry()
|
|
47
|
+
await entryPoint.storeDataToDht(getDhtAddressFromRaw(storedData.key), storedData.data!)
|
|
48
|
+
const foundData = await entryPoint.fetchDataFromDht(getDhtAddressFromRaw(storedData.key))
|
|
49
|
+
expectEqualData(foundData[0], storedData)
|
|
70
50
|
}, 60000)
|
|
71
51
|
})
|
|
@@ -1,34 +1,28 @@
|
|
|
1
|
-
import { RpcCommunicator
|
|
1
|
+
import { RpcCommunicator } from '@streamr/proto-rpc'
|
|
2
2
|
import {
|
|
3
|
-
NodeType,
|
|
4
|
-
PeerDescriptor,
|
|
5
3
|
StoreDataRequest,
|
|
6
4
|
StoreDataResponse
|
|
7
5
|
} from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
8
|
-
import {
|
|
6
|
+
import { createMockPeerDescriptor, mockStoreRpc } from '../utils/utils'
|
|
9
7
|
import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
|
|
10
8
|
import { StoreRpcClient } from '../../src/proto/packages/dht/protos/DhtRpc.client'
|
|
11
9
|
import { StoreRpcRemote } from '../../src/dht/store/StoreRpcRemote'
|
|
12
|
-
import {
|
|
10
|
+
import { createMockDataEntry } from '../utils/mock/mockDataEntry'
|
|
11
|
+
import { DhtCallContext } from '../../src/rpc-protocol/DhtCallContext'
|
|
12
|
+
import { createRandomDhtAddress, getNodeIdFromPeerDescriptor, getRawFromDhtAddress } from '../../src/identifiers'
|
|
13
13
|
|
|
14
14
|
describe('StoreRpcRemote', () => {
|
|
15
15
|
|
|
16
16
|
let rpcRemote: StoreRpcRemote
|
|
17
|
-
let clientRpcCommunicator: RpcCommunicator
|
|
18
|
-
let serverRpcCommunicator: RpcCommunicator
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
type: NodeType.NODEJS
|
|
23
|
-
}
|
|
24
|
-
const serverPeerDescriptor: PeerDescriptor = {
|
|
25
|
-
kademliaId: generateId('server'),
|
|
26
|
-
type: NodeType.NODEJS
|
|
27
|
-
}
|
|
28
|
-
const data = Any.pack(clientPeerDescriptor, PeerDescriptor)
|
|
17
|
+
let clientRpcCommunicator: RpcCommunicator<DhtCallContext>
|
|
18
|
+
let serverRpcCommunicator: RpcCommunicator<DhtCallContext>
|
|
19
|
+
const clientPeerDescriptor = createMockPeerDescriptor()
|
|
20
|
+
const serverPeerDescriptor = createMockPeerDescriptor()
|
|
21
|
+
const data = createMockDataEntry()
|
|
29
22
|
const request: StoreDataRequest = {
|
|
30
|
-
|
|
31
|
-
data,
|
|
23
|
+
key: data.key,
|
|
24
|
+
data: data.data,
|
|
25
|
+
creator: getRawFromDhtAddress(createRandomDhtAddress()),
|
|
32
26
|
ttl: 10
|
|
33
27
|
}
|
|
34
28
|
|
|
@@ -42,25 +36,19 @@ describe('StoreRpcRemote', () => {
|
|
|
42
36
|
serverRpcCommunicator.on('outgoingMessage', (message: RpcMessage) => {
|
|
43
37
|
clientRpcCommunicator.handleIncomingMessage(message)
|
|
44
38
|
})
|
|
45
|
-
|
|
46
|
-
rpcRemote = new StoreRpcRemote(clientPeerDescriptor, serverPeerDescriptor, serviceId, client)
|
|
39
|
+
rpcRemote = new StoreRpcRemote(clientPeerDescriptor, serverPeerDescriptor, clientRpcCommunicator, StoreRpcClient)
|
|
47
40
|
})
|
|
48
41
|
|
|
49
42
|
it('storeData happy path', async () => {
|
|
50
|
-
|
|
51
|
-
expect(response.error).toBeEmpty()
|
|
43
|
+
await expect(rpcRemote.storeData(request)).toResolve()
|
|
52
44
|
})
|
|
53
45
|
|
|
54
46
|
it('storeData rejects', async () => {
|
|
55
47
|
serverRpcCommunicator.registerRpcMethod(StoreDataRequest, StoreDataResponse, 'storeData', mockStoreRpc.throwStoreDataError)
|
|
56
|
-
await expect(rpcRemote.storeData(request))
|
|
57
|
-
|
|
48
|
+
await expect(rpcRemote.storeData(request)).rejects.toThrowError(
|
|
49
|
+
'Could not store data to'
|
|
50
|
+
+ ` ${getNodeIdFromPeerDescriptor(serverPeerDescriptor)} from ${getNodeIdFromPeerDescriptor(clientPeerDescriptor)}`
|
|
51
|
+
+ ' Error: Mock'
|
|
52
|
+
)
|
|
58
53
|
})
|
|
59
|
-
|
|
60
|
-
it('storeData response error', async () => {
|
|
61
|
-
serverRpcCommunicator.registerRpcMethod(StoreDataRequest, StoreDataResponse, 'storeData', mockStoreRpc.storeDataErrorString)
|
|
62
|
-
const response = await rpcRemote.storeData(request)
|
|
63
|
-
expect(response.error).toEqual('Mock')
|
|
64
|
-
})
|
|
65
|
-
|
|
66
54
|
})
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { ConnectionManager } from '../../src/connection/ConnectionManager'
|
|
2
2
|
import { LatencyType, Simulator } from '../../src/connection/simulator/Simulator'
|
|
3
|
-
import { Message,
|
|
3
|
+
import { Message, NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
4
4
|
import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
|
|
5
|
-
import { PeerID } from '../../src/helpers/PeerID'
|
|
6
5
|
import { ConnectionType } from '../../src/connection/IConnection'
|
|
7
6
|
import { ITransport } from '../../src/transport/ITransport'
|
|
8
7
|
import * as Err from '../../src/helpers/errors'
|
|
9
8
|
import { SimulatorTransport } from '../../src/connection/simulator/SimulatorTransport'
|
|
10
9
|
import { DefaultConnectorFacade } from '../../src/connection/ConnectorFacade'
|
|
11
10
|
import { MetricsContext } from '@streamr/utils'
|
|
11
|
+
import { createMockPeerDescriptor } from '../utils/utils'
|
|
12
|
+
import { getNodeIdFromPeerDescriptor } from '../../src/identifiers'
|
|
12
13
|
|
|
13
14
|
const createConnectionManager = (localPeerDescriptor: PeerDescriptor, transport: ITransport) => {
|
|
14
15
|
return new ConnectionManager({
|
|
@@ -24,19 +25,9 @@ describe('WebRTC Connection Management', () => {
|
|
|
24
25
|
|
|
25
26
|
let manager1: ConnectionManager
|
|
26
27
|
let manager2: ConnectionManager
|
|
27
|
-
|
|
28
28
|
let simulator: Simulator
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
kademliaId: PeerID.fromString('peer1').value,
|
|
32
|
-
type: NodeType.NODEJS,
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const peerDescriptor2: PeerDescriptor = {
|
|
36
|
-
kademliaId: PeerID.fromString('peer2').value,
|
|
37
|
-
type: NodeType.NODEJS,
|
|
38
|
-
}
|
|
39
|
-
|
|
29
|
+
const peerDescriptor1 = createMockPeerDescriptor()
|
|
30
|
+
const peerDescriptor2 = createMockPeerDescriptor()
|
|
40
31
|
let connectorTransport1: SimulatorTransport
|
|
41
32
|
let connectorTransport2: SimulatorTransport
|
|
42
33
|
|
|
@@ -72,14 +63,13 @@ describe('WebRTC Connection Management', () => {
|
|
|
72
63
|
oneofKind: 'rpcMessage',
|
|
73
64
|
rpcMessage: RpcMessage.create()
|
|
74
65
|
},
|
|
75
|
-
messageType: MessageType.RPC,
|
|
76
66
|
messageId: 'mockerer'
|
|
77
67
|
}
|
|
78
68
|
|
|
79
69
|
manager2.on('message', (message: Message) => {
|
|
80
70
|
expect(message.messageId).toEqual('mockerer')
|
|
81
|
-
expect(manager1.getConnection(peerDescriptor2)!.connectionType).toEqual(ConnectionType.WEBRTC)
|
|
82
|
-
expect(manager2.getConnection(peerDescriptor1)!.connectionType).toEqual(ConnectionType.WEBRTC)
|
|
71
|
+
expect(manager1.getConnection(getNodeIdFromPeerDescriptor(peerDescriptor2))!.connectionType).toEqual(ConnectionType.WEBRTC)
|
|
72
|
+
expect(manager2.getConnection(getNodeIdFromPeerDescriptor(peerDescriptor1))!.connectionType).toEqual(ConnectionType.WEBRTC)
|
|
83
73
|
|
|
84
74
|
done()
|
|
85
75
|
})
|
|
@@ -96,13 +86,12 @@ describe('WebRTC Connection Management', () => {
|
|
|
96
86
|
oneofKind: 'rpcMessage',
|
|
97
87
|
rpcMessage: RpcMessage.create()
|
|
98
88
|
},
|
|
99
|
-
messageType: MessageType.RPC,
|
|
100
89
|
messageId: 'mockerer'
|
|
101
90
|
}
|
|
102
91
|
manager1.on('message', (message: Message) => {
|
|
103
92
|
expect(message.messageId).toEqual('mockerer')
|
|
104
|
-
expect(manager1.getConnection(peerDescriptor2)!.connectionType).toEqual(ConnectionType.WEBRTC)
|
|
105
|
-
expect(manager2.getConnection(peerDescriptor1)!.connectionType).toEqual(ConnectionType.WEBRTC)
|
|
93
|
+
expect(manager1.getConnection(getNodeIdFromPeerDescriptor(peerDescriptor2))!.connectionType).toEqual(ConnectionType.WEBRTC)
|
|
94
|
+
expect(manager2.getConnection(getNodeIdFromPeerDescriptor(peerDescriptor1))!.connectionType).toEqual(ConnectionType.WEBRTC)
|
|
106
95
|
|
|
107
96
|
done()
|
|
108
97
|
})
|
|
@@ -117,7 +106,6 @@ describe('WebRTC Connection Management', () => {
|
|
|
117
106
|
oneofKind: 'rpcMessage',
|
|
118
107
|
rpcMessage: RpcMessage.create()
|
|
119
108
|
},
|
|
120
|
-
messageType: MessageType.RPC,
|
|
121
109
|
messageId: 'mockerer'
|
|
122
110
|
}
|
|
123
111
|
dummyMessage.targetDescriptor = peerDescriptor1
|
|
@@ -129,7 +117,6 @@ describe('WebRTC Connection Management', () => {
|
|
|
129
117
|
it('Connects and disconnects webrtc connections', async () => {
|
|
130
118
|
const msg: Message = {
|
|
131
119
|
serviceId,
|
|
132
|
-
messageType: MessageType.RPC,
|
|
133
120
|
messageId: '1',
|
|
134
121
|
body: {
|
|
135
122
|
oneofKind: 'rpcMessage',
|
|
@@ -139,14 +126,14 @@ describe('WebRTC Connection Management', () => {
|
|
|
139
126
|
|
|
140
127
|
const dataPromise = new Promise<void>((resolve, _reject) => {
|
|
141
128
|
manager2.on('message', async (message: Message) => {
|
|
142
|
-
expect(message.
|
|
129
|
+
expect(message.body.oneofKind).toBe('rpcMessage')
|
|
143
130
|
resolve()
|
|
144
131
|
})
|
|
145
132
|
})
|
|
146
133
|
|
|
147
134
|
const connectedPromise1 = new Promise<void>((resolve, _reject) => {
|
|
148
135
|
manager1.on('connected', () => {
|
|
149
|
-
//expect(message.
|
|
136
|
+
//expect(message.body.oneofKind).toBe('rpcMessage')
|
|
150
137
|
resolve()
|
|
151
138
|
})
|
|
152
139
|
})
|
|
@@ -184,7 +171,6 @@ describe('WebRTC Connection Management', () => {
|
|
|
184
171
|
it('Disconnects webrtcconnection while being connected', async () => {
|
|
185
172
|
const msg: Message = {
|
|
186
173
|
serviceId,
|
|
187
|
-
messageType: MessageType.RPC,
|
|
188
174
|
messageId: '1',
|
|
189
175
|
body: {
|
|
190
176
|
oneofKind: 'rpcMessage',
|
|
@@ -209,4 +195,32 @@ describe('WebRTC Connection Management', () => {
|
|
|
209
195
|
await disconnectedPromise1
|
|
210
196
|
|
|
211
197
|
}, 20000)
|
|
198
|
+
|
|
199
|
+
it('failed connections are cleaned up', async () => {
|
|
200
|
+
const msg: Message = {
|
|
201
|
+
serviceId,
|
|
202
|
+
messageId: '1',
|
|
203
|
+
body: {
|
|
204
|
+
oneofKind: 'rpcMessage',
|
|
205
|
+
rpcMessage: RpcMessage.create()
|
|
206
|
+
},
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const disconnectedPromise1 = new Promise<void>((resolve, _reject) => {
|
|
210
|
+
manager1.on('disconnected', () => {
|
|
211
|
+
resolve()
|
|
212
|
+
})
|
|
213
|
+
})
|
|
214
|
+
|
|
215
|
+
msg.targetDescriptor = {
|
|
216
|
+
nodeId: new Uint8Array([0, 0, 0, 0, 0]),
|
|
217
|
+
type: NodeType.NODEJS,
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
await Promise.allSettled([
|
|
221
|
+
manager1.send(msg),
|
|
222
|
+
disconnectedPromise1
|
|
223
|
+
])
|
|
224
|
+
expect(manager1.getConnection(getNodeIdFromPeerDescriptor(msg.targetDescriptor))).toBeUndefined()
|
|
225
|
+
}, 20000)
|
|
212
226
|
})
|
|
@@ -2,32 +2,27 @@ import { ProtoRpcClient, RpcCommunicator, toProtoRpcClient } from '@streamr/prot
|
|
|
2
2
|
import { WebrtcConnectorRpcClient } from '../../src/proto/packages/dht/protos/DhtRpc.client'
|
|
3
3
|
import {
|
|
4
4
|
IceCandidate,
|
|
5
|
-
NodeType,
|
|
6
|
-
PeerDescriptor,
|
|
7
5
|
RtcAnswer,
|
|
8
6
|
RtcOffer,
|
|
9
7
|
WebrtcConnectionRequest
|
|
10
8
|
} from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
11
9
|
import { Empty } from '../../src/proto/google/protobuf/empty'
|
|
12
|
-
import {
|
|
10
|
+
import { createMockPeerDescriptor } from '../utils/utils'
|
|
13
11
|
import { IWebrtcConnectorRpc } from '../../src/proto/packages/dht/protos/DhtRpc.server'
|
|
14
12
|
import { waitForCondition } from '@streamr/utils'
|
|
15
13
|
import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
|
|
14
|
+
import { DhtCallContext } from '../../src/rpc-protocol/DhtCallContext'
|
|
16
15
|
|
|
17
16
|
describe('WebRTC rpc messages', () => {
|
|
18
|
-
let rpcCommunicator1: RpcCommunicator
|
|
19
|
-
let rpcCommunicator2: RpcCommunicator
|
|
20
|
-
let client: ProtoRpcClient<WebrtcConnectorRpcClient>
|
|
21
17
|
|
|
18
|
+
let rpcCommunicator1: RpcCommunicator<DhtCallContext>
|
|
19
|
+
let rpcCommunicator2: RpcCommunicator<DhtCallContext>
|
|
20
|
+
let client: ProtoRpcClient<WebrtcConnectorRpcClient>
|
|
22
21
|
let requestConnectionCounter: number
|
|
23
22
|
let rtcOfferCounter: number
|
|
24
23
|
let rtcAnswerCounter: number
|
|
25
24
|
let iceCandidateCounter: number
|
|
26
|
-
|
|
27
|
-
const targetDescriptor: PeerDescriptor = {
|
|
28
|
-
kademliaId: generateId('peer'),
|
|
29
|
-
type: NodeType.NODEJS
|
|
30
|
-
}
|
|
25
|
+
const targetDescriptor = createMockPeerDescriptor()
|
|
31
26
|
|
|
32
27
|
beforeEach(() => {
|
|
33
28
|
requestConnectionCounter = 0
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
/* eslint-disable promise/no-nesting */
|
|
2
2
|
|
|
3
|
-
import { MetricsContext, waitForCondition } from '@streamr/utils'
|
|
3
|
+
import { MetricsContext, waitForCondition, waitForEvent3 } from '@streamr/utils'
|
|
4
4
|
import { ConnectionManager } from '../../src/connection/ConnectionManager'
|
|
5
5
|
import { DefaultConnectorFacade, DefaultConnectorFacadeConfig } from '../../src/connection/ConnectorFacade'
|
|
6
6
|
import { ConnectionType } from '../../src/connection/IConnection'
|
|
7
7
|
import { Simulator } from '../../src/connection/simulator/Simulator'
|
|
8
|
-
import { SimulatorTransport } from '../../src/
|
|
9
|
-
import { PeerID } from '../../src/helpers/PeerID'
|
|
8
|
+
import { SimulatorTransport } from '../../src/connection/simulator/SimulatorTransport'
|
|
10
9
|
import * as Err from '../../src/helpers/errors'
|
|
11
|
-
import { Message,
|
|
10
|
+
import { Message, NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
12
11
|
import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
|
|
12
|
+
import { TransportEvents } from '../../src/transport/ITransport'
|
|
13
|
+
import { getNodeIdFromPeerDescriptor } from '../../src/identifiers'
|
|
14
|
+
|
|
15
|
+
const SERVICE_ID = 'test'
|
|
13
16
|
|
|
14
17
|
const createConfig = (localPeerDescriptor: PeerDescriptor, opts: Omit<DefaultConnectorFacadeConfig, 'createLocalPeerDescriptor'>) => {
|
|
15
18
|
return {
|
|
@@ -23,14 +26,12 @@ const createConfig = (localPeerDescriptor: PeerDescriptor, opts: Omit<DefaultCon
|
|
|
23
26
|
|
|
24
27
|
describe('Websocket Connection Management', () => {
|
|
25
28
|
|
|
26
|
-
const serviceId = 'test'
|
|
27
29
|
let wsServerManager: ConnectionManager
|
|
28
30
|
let noWsServerManager: ConnectionManager
|
|
29
|
-
|
|
31
|
+
let biggerNoWsServerManager: ConnectionManager
|
|
30
32
|
const simulator = new Simulator()
|
|
31
|
-
|
|
32
33
|
const wsServerConnectorPeerDescriptor: PeerDescriptor = {
|
|
33
|
-
|
|
34
|
+
nodeId: new Uint8Array([2]),
|
|
34
35
|
type: NodeType.NODEJS,
|
|
35
36
|
websocket: {
|
|
36
37
|
host: '127.0.0.1',
|
|
@@ -38,14 +39,18 @@ describe('Websocket Connection Management', () => {
|
|
|
38
39
|
tls: false
|
|
39
40
|
}
|
|
40
41
|
}
|
|
41
|
-
|
|
42
42
|
const noWsServerConnectorPeerDescriptor: PeerDescriptor = {
|
|
43
|
-
|
|
43
|
+
nodeId: new Uint8Array([1]),
|
|
44
|
+
type: NodeType.NODEJS,
|
|
45
|
+
}
|
|
46
|
+
const biggerNoWsServerConnectorPeerDescriptor: PeerDescriptor = {
|
|
47
|
+
nodeId: new Uint8Array([3]),
|
|
44
48
|
type: NodeType.NODEJS,
|
|
45
49
|
}
|
|
46
50
|
|
|
47
51
|
let connectorTransport1: SimulatorTransport
|
|
48
52
|
let connectorTransport2: SimulatorTransport
|
|
53
|
+
let connectorTransport3: SimulatorTransport
|
|
49
54
|
|
|
50
55
|
beforeEach(async () => {
|
|
51
56
|
|
|
@@ -53,6 +58,8 @@ describe('Websocket Connection Management', () => {
|
|
|
53
58
|
await connectorTransport1.start()
|
|
54
59
|
connectorTransport2 = new SimulatorTransport(noWsServerConnectorPeerDescriptor, simulator)
|
|
55
60
|
await connectorTransport2.start()
|
|
61
|
+
connectorTransport3 = new SimulatorTransport(biggerNoWsServerConnectorPeerDescriptor, simulator)
|
|
62
|
+
await connectorTransport3.start()
|
|
56
63
|
|
|
57
64
|
const config1 = createConfig(wsServerConnectorPeerDescriptor, {
|
|
58
65
|
transport: connectorTransport1,
|
|
@@ -62,36 +69,46 @@ describe('Websocket Connection Management', () => {
|
|
|
62
69
|
const config2 = createConfig(noWsServerConnectorPeerDescriptor, {
|
|
63
70
|
transport: connectorTransport2
|
|
64
71
|
})
|
|
72
|
+
const config3 = createConfig(biggerNoWsServerConnectorPeerDescriptor, {
|
|
73
|
+
transport: connectorTransport3
|
|
74
|
+
})
|
|
65
75
|
|
|
66
76
|
wsServerManager = new ConnectionManager(config1)
|
|
67
77
|
noWsServerManager = new ConnectionManager(config2)
|
|
78
|
+
biggerNoWsServerManager = new ConnectionManager(config3)
|
|
68
79
|
|
|
69
80
|
await wsServerManager.start()
|
|
70
81
|
await noWsServerManager.start()
|
|
82
|
+
await biggerNoWsServerManager.start()
|
|
71
83
|
})
|
|
72
84
|
|
|
73
85
|
afterEach(async () => {
|
|
74
86
|
await wsServerManager.stop()
|
|
75
87
|
await noWsServerManager.stop()
|
|
88
|
+
await biggerNoWsServerManager.stop()
|
|
76
89
|
await connectorTransport1.stop()
|
|
77
90
|
await connectorTransport2.stop()
|
|
91
|
+
await connectorTransport3.stop()
|
|
78
92
|
})
|
|
79
93
|
|
|
80
|
-
it('Can open connections to serverless peer', (done) => {
|
|
94
|
+
it('Can open connections to serverless peer with smaller nodeId', (done) => {
|
|
81
95
|
const dummyMessage: Message = {
|
|
82
|
-
serviceId,
|
|
96
|
+
serviceId: SERVICE_ID,
|
|
83
97
|
body: {
|
|
84
98
|
oneofKind: 'rpcMessage',
|
|
85
99
|
rpcMessage: RpcMessage.create()
|
|
86
100
|
},
|
|
87
|
-
messageType: MessageType.RPC,
|
|
88
101
|
messageId: 'mockerer',
|
|
89
102
|
targetDescriptor: noWsServerConnectorPeerDescriptor
|
|
90
103
|
}
|
|
91
104
|
noWsServerManager.on('message', (message: Message) => {
|
|
92
105
|
expect(message.messageId).toEqual('mockerer')
|
|
93
|
-
expect(wsServerManager.getConnection(noWsServerConnectorPeerDescriptor)!.connectionType).toEqual(
|
|
94
|
-
|
|
106
|
+
expect(wsServerManager.getConnection(getNodeIdFromPeerDescriptor(noWsServerConnectorPeerDescriptor))!.connectionType).toEqual(
|
|
107
|
+
ConnectionType.WEBSOCKET_SERVER
|
|
108
|
+
)
|
|
109
|
+
expect(noWsServerManager.getConnection(getNodeIdFromPeerDescriptor(wsServerConnectorPeerDescriptor))!.connectionType).toEqual(
|
|
110
|
+
ConnectionType.WEBSOCKET_CLIENT
|
|
111
|
+
)
|
|
95
112
|
|
|
96
113
|
done()
|
|
97
114
|
})
|
|
@@ -99,37 +116,85 @@ describe('Websocket Connection Management', () => {
|
|
|
99
116
|
wsServerManager.send(dummyMessage)
|
|
100
117
|
})
|
|
101
118
|
|
|
119
|
+
it('Can open connections to serverless peer with bigger nodeId', (done) => {
|
|
120
|
+
const dummyMessage: Message = {
|
|
121
|
+
serviceId: SERVICE_ID,
|
|
122
|
+
body: {
|
|
123
|
+
oneofKind: 'rpcMessage',
|
|
124
|
+
rpcMessage: RpcMessage.create()
|
|
125
|
+
},
|
|
126
|
+
messageId: 'mockerer',
|
|
127
|
+
targetDescriptor: biggerNoWsServerConnectorPeerDescriptor
|
|
128
|
+
}
|
|
129
|
+
biggerNoWsServerManager.on('message', (message: Message) => {
|
|
130
|
+
expect(message.messageId).toEqual('mockerer')
|
|
131
|
+
expect(wsServerManager.getConnection(getNodeIdFromPeerDescriptor(biggerNoWsServerConnectorPeerDescriptor))!.connectionType).toEqual(
|
|
132
|
+
ConnectionType.WEBSOCKET_SERVER
|
|
133
|
+
)
|
|
134
|
+
expect(biggerNoWsServerManager.getConnection(getNodeIdFromPeerDescriptor(wsServerConnectorPeerDescriptor))!.connectionType).toEqual(
|
|
135
|
+
ConnectionType.WEBSOCKET_CLIENT
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
done()
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
wsServerManager.send(dummyMessage)
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
it('Failed connection requests are cleaned up', async () => {
|
|
145
|
+
const dummyMessage: Message = {
|
|
146
|
+
serviceId: SERVICE_ID,
|
|
147
|
+
body: {
|
|
148
|
+
oneofKind: 'rpcMessage',
|
|
149
|
+
rpcMessage: RpcMessage.create()
|
|
150
|
+
},
|
|
151
|
+
messageId: 'mockerer',
|
|
152
|
+
targetDescriptor: {
|
|
153
|
+
nodeId: new Uint8Array([1, 2, 4]),
|
|
154
|
+
type: NodeType.NODEJS
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
await Promise.allSettled([
|
|
159
|
+
waitForEvent3<TransportEvents>(wsServerManager, 'disconnected', 15000),
|
|
160
|
+
wsServerManager.send(dummyMessage)
|
|
161
|
+
])
|
|
162
|
+
expect(wsServerManager.getConnection(getNodeIdFromPeerDescriptor(dummyMessage.targetDescriptor!))).toBeUndefined()
|
|
163
|
+
}, 20000)
|
|
164
|
+
|
|
102
165
|
it('Can open connections to peer with server', async () => {
|
|
103
166
|
const dummyMessage: Message = {
|
|
104
|
-
serviceId,
|
|
167
|
+
serviceId: SERVICE_ID,
|
|
105
168
|
body: {
|
|
106
169
|
oneofKind: 'rpcMessage',
|
|
107
170
|
rpcMessage: RpcMessage.create()
|
|
108
171
|
},
|
|
109
|
-
messageType: MessageType.RPC,
|
|
110
172
|
messageId: 'mockerer',
|
|
111
173
|
targetDescriptor: wsServerConnectorPeerDescriptor
|
|
112
174
|
}
|
|
113
175
|
await noWsServerManager.send(dummyMessage)
|
|
114
176
|
await waitForCondition(
|
|
115
177
|
() => {
|
|
116
|
-
|
|
117
|
-
|
|
178
|
+
const nodeId = getNodeIdFromPeerDescriptor(noWsServerConnectorPeerDescriptor)
|
|
179
|
+
return (!!wsServerManager.getConnection(nodeId)
|
|
180
|
+
&& wsServerManager.getConnection(nodeId)!.connectionType === ConnectionType.WEBSOCKET_SERVER)
|
|
118
181
|
}
|
|
119
182
|
)
|
|
120
183
|
await waitForCondition(
|
|
121
|
-
() =>
|
|
184
|
+
() => {
|
|
185
|
+
const connection = noWsServerManager.getConnection(getNodeIdFromPeerDescriptor(wsServerConnectorPeerDescriptor))!
|
|
186
|
+
return connection.connectionType === ConnectionType.WEBSOCKET_CLIENT
|
|
187
|
+
}
|
|
122
188
|
)
|
|
123
189
|
})
|
|
124
190
|
|
|
125
191
|
it('Connecting to self throws', async () => {
|
|
126
192
|
const dummyMessage: Message = {
|
|
127
|
-
serviceId,
|
|
193
|
+
serviceId: SERVICE_ID,
|
|
128
194
|
body: {
|
|
129
195
|
oneofKind: 'rpcMessage',
|
|
130
196
|
rpcMessage: RpcMessage.create()
|
|
131
197
|
},
|
|
132
|
-
messageType: MessageType.RPC,
|
|
133
198
|
messageId: 'mockerer',
|
|
134
199
|
targetDescriptor: noWsServerConnectorPeerDescriptor
|
|
135
200
|
}
|