@streamr/dht 100.0.0-pretestnet.6 → 100.0.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +90 -8
- package/dist/package.json +70 -0
- package/dist/src/connection/Connection.d.ts +1 -0
- package/dist/src/connection/Connection.js +10 -3
- package/dist/src/connection/Connection.js.map +1 -1
- package/dist/src/connection/ConnectionLockHandler.d.ts +14 -14
- package/dist/src/connection/ConnectionLockHandler.js +22 -16
- package/dist/src/connection/ConnectionLockHandler.js.map +1 -1
- package/dist/src/connection/ConnectionLockRpcLocal.d.ts +3 -3
- package/dist/src/connection/ConnectionLockRpcLocal.js +7 -6
- package/dist/src/connection/ConnectionLockRpcLocal.js.map +1 -1
- package/dist/src/connection/ConnectionLockRpcRemote.d.ts +4 -6
- package/dist/src/connection/ConnectionLockRpcRemote.js +10 -37
- package/dist/src/connection/ConnectionLockRpcRemote.js.map +1 -1
- package/dist/src/connection/ConnectionManager.d.ts +19 -20
- package/dist/src/connection/ConnectionManager.js +132 -117
- package/dist/src/connection/ConnectionManager.js.map +1 -1
- package/dist/src/connection/ConnectorFacade.d.ts +3 -2
- package/dist/src/connection/ConnectorFacade.js +10 -3
- package/dist/src/connection/ConnectorFacade.js.map +1 -1
- package/dist/src/connection/Handshaker.d.ts +3 -1
- package/dist/src/connection/Handshaker.js +18 -9
- package/dist/src/connection/Handshaker.js.map +1 -1
- package/dist/src/connection/IConnection.d.ts +2 -7
- package/dist/src/connection/IConnection.js +1 -8
- package/dist/src/connection/IConnection.js.map +1 -1
- package/dist/src/connection/ManagedConnection.d.ts +5 -7
- package/dist/src/connection/ManagedConnection.js +42 -26
- package/dist/src/connection/ManagedConnection.js.map +1 -1
- package/dist/src/connection/ManagedWebrtcConnection.js.map +1 -1
- package/dist/src/connection/connectivityChecker.d.ts +9 -0
- package/dist/src/connection/connectivityChecker.js +130 -0
- package/dist/src/connection/connectivityChecker.js.map +1 -0
- package/dist/src/connection/connectivityRequestHandler.d.ts +3 -0
- package/dist/src/connection/connectivityRequestHandler.js +101 -0
- package/dist/src/connection/connectivityRequestHandler.js.map +1 -0
- package/dist/src/connection/simulator/Simulator.d.ts +0 -3
- package/dist/src/connection/simulator/Simulator.js +34 -69
- package/dist/src/connection/simulator/Simulator.js.map +1 -1
- package/dist/src/connection/simulator/SimulatorConnection.js +27 -25
- package/dist/src/connection/simulator/SimulatorConnection.js.map +1 -1
- package/dist/src/connection/simulator/SimulatorConnector.js +16 -12
- package/dist/src/connection/simulator/SimulatorConnector.js.map +1 -1
- package/dist/src/connection/simulator/pings.js.map +1 -1
- package/dist/src/connection/webrtc/NodeWebrtcConnection.d.ts +2 -3
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js +40 -27
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnector.d.ts +0 -2
- package/dist/src/connection/webrtc/WebrtcConnector.js +24 -25
- package/dist/src/connection/webrtc/WebrtcConnector.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.d.ts +2 -2
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js +27 -20
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.d.ts +3 -6
- package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.js +2 -5
- package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.js.map +1 -1
- package/dist/src/connection/webrtc/iceServerAsString.js +1 -1
- package/dist/src/connection/webrtc/iceServerAsString.js.map +1 -1
- package/dist/src/connection/websocket/AutoCertifierClientFacade.d.ts +1 -2
- package/dist/src/connection/websocket/AutoCertifierClientFacade.js +6 -4
- package/dist/src/connection/websocket/AutoCertifierClientFacade.js.map +1 -1
- package/dist/src/connection/websocket/ClientWebsocket.d.ts +1 -0
- package/dist/src/connection/websocket/ClientWebsocket.js +14 -7
- package/dist/src/connection/websocket/ClientWebsocket.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnector.d.ts +3 -9
- package/dist/src/connection/websocket/WebsocketConnector.js +142 -74
- package/dist/src/connection/websocket/WebsocketConnector.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.d.ts +5 -3
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.js +9 -12
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.d.ts +4 -7
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.js +7 -44
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketServer.d.ts +1 -4
- package/dist/src/connection/websocket/WebsocketServer.js +49 -40
- package/dist/src/connection/websocket/WebsocketServer.js.map +1 -1
- package/dist/src/connection/websocket/{ServerWebsocket.d.ts → WebsocketServerConnection.d.ts} +8 -4
- package/dist/src/connection/websocket/WebsocketServerConnection.js +97 -0
- package/dist/src/connection/websocket/WebsocketServerConnection.js.map +1 -0
- package/dist/src/dht/DhtNode.d.ts +45 -49
- package/dist/src/dht/DhtNode.js +229 -317
- package/dist/src/dht/DhtNode.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcLocal.d.ts +10 -9
- package/dist/src/dht/DhtNodeRpcLocal.js +19 -11
- package/dist/src/dht/DhtNodeRpcLocal.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcRemote.d.ts +15 -10
- package/dist/src/dht/DhtNodeRpcRemote.js +38 -21
- package/dist/src/dht/DhtNodeRpcRemote.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcLocal.d.ts +7 -6
- package/dist/src/dht/ExternalApiRpcLocal.js +9 -13
- package/dist/src/dht/ExternalApiRpcLocal.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcRemote.d.ts +6 -5
- package/dist/src/dht/ExternalApiRpcRemote.js +10 -7
- package/dist/src/dht/ExternalApiRpcRemote.js.map +1 -1
- package/dist/src/dht/PeerManager.d.ts +61 -0
- package/dist/src/dht/PeerManager.js +288 -0
- package/dist/src/dht/PeerManager.js.map +1 -0
- package/dist/src/dht/contact/Contact.d.ts +2 -2
- package/dist/src/dht/contact/Contact.js +4 -3
- package/dist/src/dht/contact/Contact.js.map +1 -1
- package/dist/src/dht/contact/ContactList.d.ts +8 -8
- package/dist/src/dht/contact/ContactList.js +12 -7
- package/dist/src/dht/contact/ContactList.js.map +1 -1
- package/dist/src/dht/contact/RandomContactList.d.ts +4 -4
- package/dist/src/dht/contact/RandomContactList.js +13 -12
- package/dist/src/dht/contact/RandomContactList.js.map +1 -1
- package/dist/src/dht/contact/RingContactList.d.ts +31 -0
- package/dist/src/dht/contact/RingContactList.js +133 -0
- package/dist/src/dht/contact/RingContactList.js.map +1 -0
- package/dist/src/dht/contact/{Remote.d.ts → RpcRemote.d.ts} +8 -7
- package/dist/src/dht/contact/{Remote.js → RpcRemote.js} +16 -13
- package/dist/src/dht/contact/RpcRemote.js.map +1 -0
- package/dist/src/dht/contact/SortedContactList.d.ts +29 -15
- package/dist/src/dht/contact/SortedContactList.js +79 -42
- package/dist/src/dht/contact/SortedContactList.js.map +1 -1
- package/dist/src/dht/contact/ringIdentifiers.d.ts +16 -0
- package/dist/src/dht/contact/ringIdentifiers.js +54 -0
- package/dist/src/dht/contact/ringIdentifiers.js.map +1 -0
- package/dist/src/dht/discovery/DiscoverySession.d.ts +8 -18
- package/dist/src/dht/discovery/DiscoverySession.js +32 -48
- package/dist/src/dht/discovery/DiscoverySession.js.map +1 -1
- package/dist/src/dht/discovery/PeerDiscovery.d.ts +16 -12
- package/dist/src/dht/discovery/PeerDiscovery.js +82 -39
- package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -1
- package/dist/src/dht/discovery/RingDiscoverySession.d.ts +29 -0
- package/dist/src/dht/discovery/RingDiscoverySession.js +123 -0
- package/dist/src/dht/discovery/RingDiscoverySession.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.d.ts +36 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.js +166 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.d.ts +14 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.js +26 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.d.ts +6 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js +44 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.d.ts +44 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.js +187 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.d.ts +14 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js +20 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.d.ts +6 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.js +21 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.js.map +1 -0
- package/dist/src/dht/routing/DuplicateDetector.d.ts +2 -4
- package/dist/src/dht/routing/DuplicateDetector.js +10 -15
- package/dist/src/dht/routing/DuplicateDetector.js.map +1 -1
- package/dist/src/dht/routing/Router.d.ts +11 -27
- package/dist/src/dht/routing/Router.js +92 -58
- package/dist/src/dht/routing/Router.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcLocal.d.ts +3 -4
- package/dist/src/dht/routing/RouterRpcLocal.js +17 -16
- package/dist/src/dht/routing/RouterRpcLocal.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcRemote.d.ts +3 -3
- package/dist/src/dht/routing/RouterRpcRemote.js +29 -20
- package/dist/src/dht/routing/RouterRpcRemote.js.map +1 -1
- package/dist/src/dht/routing/RoutingSession.d.ts +29 -21
- package/dist/src/dht/routing/RoutingSession.js +93 -68
- package/dist/src/dht/routing/RoutingSession.js.map +1 -1
- package/dist/src/dht/routing/RoutingTablesCache.d.ts +24 -0
- package/dist/src/dht/routing/RoutingTablesCache.js +46 -0
- package/dist/src/dht/routing/RoutingTablesCache.js.map +1 -0
- package/dist/src/dht/routing/getPreviousPeer.js.map +1 -1
- package/dist/src/dht/store/LocalDataStore.d.ts +9 -14
- package/dist/src/dht/store/LocalDataStore.js +46 -72
- package/dist/src/dht/store/LocalDataStore.js.map +1 -1
- package/dist/src/dht/store/StoreManager.d.ts +33 -0
- package/dist/src/dht/store/StoreManager.js +182 -0
- package/dist/src/dht/store/StoreManager.js.map +1 -0
- package/dist/src/dht/store/StoreRpcLocal.d.ts +11 -41
- package/dist/src/dht/store/StoreRpcLocal.js +27 -234
- package/dist/src/dht/store/StoreRpcLocal.js.map +1 -1
- package/dist/src/dht/store/StoreRpcRemote.d.ts +6 -7
- package/dist/src/dht/store/StoreRpcRemote.js +10 -20
- package/dist/src/dht/store/StoreRpcRemote.js.map +1 -1
- package/dist/src/exports.d.ts +5 -3
- package/dist/src/exports.js +10 -8
- package/dist/src/exports.js.map +1 -1
- package/dist/src/helpers/AddressTools.js +2 -0
- package/dist/src/helpers/AddressTools.js.map +1 -1
- package/dist/src/helpers/Connectivity.js.map +1 -1
- package/dist/src/helpers/MapWithTtl.d.ts +14 -0
- package/dist/src/helpers/MapWithTtl.js +60 -0
- package/dist/src/helpers/MapWithTtl.js.map +1 -0
- package/dist/src/helpers/createPeerDescriptor.d.ts +3 -0
- package/dist/src/helpers/createPeerDescriptor.js +57 -0
- package/dist/src/helpers/createPeerDescriptor.js.map +1 -0
- package/dist/src/helpers/createPeerDescriptorSignaturePayload.d.ts +2 -0
- package/dist/src/helpers/createPeerDescriptorSignaturePayload.js +30 -0
- package/dist/src/helpers/createPeerDescriptorSignaturePayload.js.map +1 -0
- package/dist/src/helpers/debugHelpers.js.map +1 -1
- package/dist/src/helpers/errors.js +2 -0
- package/dist/src/helpers/errors.js.map +1 -1
- package/dist/src/helpers/offering.d.ts +4 -0
- package/dist/src/helpers/offering.js +18 -0
- package/dist/src/helpers/offering.js.map +1 -0
- package/dist/src/helpers/protoClasses.js +2 -3
- package/dist/src/helpers/protoClasses.js.map +1 -1
- package/dist/src/helpers/protoToString.js.map +1 -1
- package/dist/src/helpers/version.d.ts +6 -0
- package/dist/src/helpers/version.js +38 -0
- package/dist/src/helpers/version.js.map +1 -0
- package/dist/src/identifiers.d.ts +10 -0
- package/dist/src/identifiers.js +31 -0
- package/dist/src/identifiers.js.map +1 -0
- package/dist/src/proto/google/protobuf/any.js +8 -8
- package/dist/src/proto/google/protobuf/any.js.map +1 -1
- package/dist/src/proto/google/protobuf/empty.js +2 -4
- package/dist/src/proto/google/protobuf/empty.js.map +1 -1
- package/dist/src/proto/google/protobuf/timestamp.js +10 -10
- package/dist/src/proto/google/protobuf/timestamp.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +46 -49
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +63 -54
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +226 -232
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +146 -168
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +26 -29
- package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.js +1 -1
- package/dist/src/rpc-protocol/DhtCallContext.d.ts +2 -2
- package/dist/src/rpc-protocol/DhtCallContext.js +8 -0
- package/dist/src/rpc-protocol/DhtCallContext.js.map +1 -1
- package/dist/src/rpc-protocol/DhtRpcOptions.d.ts +2 -1
- package/dist/src/transport/ITransport.d.ts +10 -2
- package/dist/src/transport/ITransport.js +5 -0
- package/dist/src/transport/ITransport.js.map +1 -1
- package/dist/src/transport/ListeningRpcCommunicator.js +3 -1
- package/dist/src/transport/ListeningRpcCommunicator.js.map +1 -1
- package/dist/src/transport/RoutingRpcCommunicator.d.ts +4 -2
- package/dist/src/transport/RoutingRpcCommunicator.js +19 -12
- package/dist/src/transport/RoutingRpcCommunicator.js.map +1 -1
- package/jest.config.js +4 -1
- package/karma-setup.js +2 -0
- package/karma.config.js +13 -9
- package/package.json +16 -13
- package/protos/DhtRpc.proto +76 -76
- package/src/connection/Connection.ts +6 -1
- package/src/connection/ConnectionLockHandler.ts +30 -22
- package/src/connection/ConnectionLockRpcLocal.ts +7 -12
- package/src/connection/ConnectionLockRpcRemote.ts +9 -19
- package/src/connection/ConnectionManager.ts +132 -138
- package/src/connection/ConnectorFacade.ts +10 -9
- package/src/connection/Handshaker.ts +23 -11
- package/src/connection/IConnection.ts +2 -8
- package/src/connection/ManagedConnection.ts +34 -35
- package/src/connection/connectivityChecker.ts +109 -0
- package/src/connection/connectivityRequestHandler.ts +103 -0
- package/src/connection/simulator/Simulator.ts +6 -37
- package/src/connection/simulator/SimulatorConnection.ts +23 -25
- package/src/connection/simulator/SimulatorConnector.ts +11 -11
- package/src/connection/webrtc/BrowserWebrtcConnection.ts +17 -25
- package/src/connection/webrtc/NodeWebrtcConnection.ts +24 -26
- package/src/connection/webrtc/WebrtcConnector.ts +18 -29
- package/src/connection/webrtc/WebrtcConnectorRpcLocal.ts +29 -24
- package/src/connection/webrtc/WebrtcConnectorRpcRemote.ts +4 -14
- package/src/connection/webrtc/iceServerAsString.ts +1 -1
- package/src/connection/websocket/AutoCertifierClientFacade.ts +4 -6
- package/src/connection/websocket/ClientWebsocket.ts +10 -4
- package/src/connection/websocket/WebsocketConnector.ts +120 -97
- package/src/connection/websocket/WebsocketConnectorRpcLocal.ts +13 -15
- package/src/connection/websocket/WebsocketConnectorRpcRemote.ts +7 -27
- package/src/connection/websocket/WebsocketServer.ts +50 -53
- package/src/connection/websocket/WebsocketServerConnection.ts +104 -0
- package/src/dht/DhtNode.ts +289 -410
- package/src/dht/DhtNodeRpcLocal.ts +25 -17
- package/src/dht/DhtNodeRpcRemote.ts +43 -27
- package/src/dht/ExternalApiRpcLocal.ts +30 -17
- package/src/dht/ExternalApiRpcRemote.ts +14 -11
- package/src/dht/PeerManager.ts +339 -0
- package/src/dht/contact/Contact.ts +4 -4
- package/src/dht/contact/ContactList.ts +11 -10
- package/src/dht/contact/RandomContactList.ts +15 -15
- package/src/dht/contact/RingContactList.ts +151 -0
- package/src/dht/contact/{Remote.ts → RpcRemote.ts} +16 -19
- package/src/dht/contact/SortedContactList.ts +120 -72
- package/src/dht/contact/ringIdentifiers.ts +62 -0
- package/src/dht/discovery/DiscoverySession.ts +36 -61
- package/src/dht/discovery/PeerDiscovery.ts +98 -43
- package/src/dht/discovery/RingDiscoverySession.ts +160 -0
- package/src/dht/recursive-operation/RecursiveOperationManager.ts +246 -0
- package/src/dht/recursive-operation/RecursiveOperationRpcLocal.ts +34 -0
- package/src/dht/recursive-operation/RecursiveOperationRpcRemote.ts +43 -0
- package/src/dht/recursive-operation/RecursiveOperationSession.ts +232 -0
- package/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.ts +35 -0
- package/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.ts +30 -0
- package/src/dht/routing/DuplicateDetector.ts +9 -21
- package/src/dht/routing/Router.ts +95 -92
- package/src/dht/routing/RouterRpcLocal.ts +16 -18
- package/src/dht/routing/RouterRpcRemote.ts +26 -24
- package/src/dht/routing/RoutingSession.ts +119 -98
- package/src/dht/routing/RoutingTablesCache.ts +58 -0
- package/src/dht/routing/getPreviousPeer.ts +1 -1
- package/src/dht/store/LocalDataStore.ts +47 -77
- package/src/dht/store/StoreManager.ts +209 -0
- package/src/dht/store/StoreRpcLocal.ts +39 -308
- package/src/dht/store/StoreRpcRemote.ts +13 -31
- package/src/exports.ts +13 -3
- package/src/helpers/AddressTools.ts +2 -0
- package/src/helpers/MapWithTtl.ts +71 -0
- package/src/helpers/createPeerDescriptor.ts +57 -0
- package/src/helpers/createPeerDescriptorSignaturePayload.ts +28 -0
- package/src/helpers/offering.ts +15 -0
- package/src/helpers/protoClasses.ts +4 -6
- package/src/helpers/version.ts +32 -0
- package/src/identifiers.ts +29 -0
- package/src/proto/google/protobuf/any.ts +4 -4
- package/src/proto/google/protobuf/empty.ts +2 -4
- package/src/proto/google/protobuf/timestamp.ts +4 -4
- package/src/proto/packages/dht/protos/DhtRpc.client.ts +65 -68
- package/src/proto/packages/dht/protos/DhtRpc.server.ts +27 -30
- package/src/proto/packages/dht/protos/DhtRpc.ts +297 -313
- package/src/proto/packages/proto-rpc/protos/ProtoRpc.ts +1 -1
- package/src/rpc-protocol/DhtCallContext.ts +2 -2
- package/src/rpc-protocol/DhtRpcOptions.ts +2 -1
- package/src/transport/ITransport.ts +11 -2
- package/src/transport/ListeningRpcCommunicator.ts +1 -1
- package/src/transport/RoutingRpcCommunicator.ts +21 -14
- package/test/RandomGraphSimulation.ts +3 -2
- package/test/benchmark/Find.test.ts +13 -28
- package/test/benchmark/KademliaCorrectness.test.ts +24 -28
- package/test/benchmark/RingCorrectness.test.ts +157 -0
- package/test/benchmark/SortedContactListBenchmark.test.ts +151 -0
- package/test/benchmark/WebsocketServerMemoryLeak.test.ts +41 -0
- package/test/benchmark/hybrid-network-simulation/RingContactList.test.ts +72 -0
- package/test/benchmark/kademlia-simulation/Contact.ts +9 -9
- package/test/benchmark/kademlia-simulation/KademliaSimulation.ts +11 -11
- package/test/benchmark/kademlia-simulation/SimulationNode.ts +29 -25
- package/test/data/generateGroundTruthData.ts +7 -6
- package/test/end-to-end/Layer0-Layer1.test.ts +11 -15
- package/test/end-to-end/Layer0.test.ts +19 -22
- package/test/end-to-end/Layer0MixedConnectionTypes.test.ts +19 -21
- package/test/end-to-end/Layer0Webrtc-Layer1.test.ts +26 -28
- package/test/end-to-end/Layer0Webrtc.test.ts +19 -19
- package/test/end-to-end/Layer1-Scale-WebSocket.test.ts +10 -18
- package/test/end-to-end/Layer1-Scale-Webrtc.test.ts +8 -15
- package/test/end-to-end/RecoveryFromFailedAutoCertification.test.ts +2 -2
- package/test/end-to-end/WebsocketConnectionRequest.test.ts +8 -9
- package/test/end-to-end/memory-leak.test.ts +19 -24
- package/test/integration/ConnectionLocking.test.ts +66 -60
- package/test/integration/ConnectionManager.test.ts +43 -63
- package/test/integration/ConnectivityChecking.test.ts +52 -0
- package/test/integration/DhtJoinPeerDiscovery.test.ts +8 -12
- package/test/integration/DhtNodeExternalAPI.test.ts +17 -21
- package/test/integration/DhtNodeRpcRemote.test.ts +19 -26
- package/test/integration/DhtRpc.test.ts +20 -24
- package/test/integration/Find.test.ts +10 -12
- package/test/integration/Layer1-scale.test.ts +25 -37
- package/test/integration/Mock-Layer1-Layer0.test.ts +39 -59
- package/test/integration/MultipleEntryPointJoining.test.ts +14 -14
- package/test/integration/ReplicateData.test.ts +106 -0
- package/test/integration/RouteMessage.test.ts +42 -68
- package/test/integration/RouterRpcRemote.test.ts +19 -24
- package/test/integration/ScaleDownDht.test.ts +14 -12
- package/test/integration/SimultaneousConnections.test.ts +112 -111
- package/test/integration/Store.test.ts +43 -27
- package/test/integration/StoreAndDelete.test.ts +36 -48
- package/test/integration/StoreOnDhtWithThreeNodes.test.ts +59 -0
- package/test/integration/StoreOnDhtWithTwoNodes.test.ts +17 -37
- package/test/integration/StoreRpcRemote.test.ts +20 -32
- package/test/integration/WebrtcConnectionManagement.test.ts +39 -25
- package/test/integration/WebrtcConnectorRpc.test.ts +6 -11
- package/test/integration/WebsocketConnectionManagement.test.ts +87 -22
- package/test/integration/WebsocketConnectorRpc.test.ts +14 -24
- package/test/integration/{RpcErrors.test.ts → rpc-connections-over-webrpc.test.ts} +15 -26
- package/test/unit/AddressTools.test.ts +4 -0
- package/test/unit/ConnectivityHelpers.test.ts +9 -17
- package/test/unit/DuplicateDetector.test.ts +8 -5
- package/test/unit/LocalDataStore.test.ts +78 -75
- package/test/unit/PeerManager.test.ts +33 -0
- package/test/unit/RandomContactList.test.ts +12 -9
- package/test/unit/RecursiveOperationManager.test.ts +157 -0
- package/test/unit/RecursiveOperationSession.test.ts +68 -0
- package/test/unit/Router.test.ts +52 -35
- package/test/unit/RoutingSession.test.ts +79 -0
- package/test/unit/SortedContactList.test.ts +61 -30
- package/test/unit/StoreManager.test.ts +138 -0
- package/test/unit/WebsocketConnector.test.ts +27 -35
- package/test/unit/connectivityRequestHandler.test.ts +104 -0
- package/test/unit/createPeerDescriptor.test.ts +69 -0
- package/test/unit/customMatchers.test.ts +16 -0
- package/test/unit/version.test.ts +18 -0
- package/test/utils/FakeTransport.ts +47 -0
- package/test/utils/customMatchers.ts +71 -0
- package/test/utils/mock/MockRpcCommunicator.ts +7 -0
- package/test/utils/mock/Router.ts +13 -3
- package/test/utils/mock/Transport.ts +1 -1
- package/test/utils/mock/mockDataEntry.ts +38 -0
- package/test/utils/utils.ts +104 -107
- package/tsconfig.browser.json +2 -1
- package/tsconfig.jest.json +4 -2
- package/tsconfig.node.json +4 -2
- package/dist/src/connection/ConnectivityChecker.d.ts +0 -17
- package/dist/src/connection/ConnectivityChecker.js +0 -208
- package/dist/src/connection/ConnectivityChecker.js.map +0 -1
- package/dist/src/connection/websocket/ServerWebsocket.js +0 -100
- package/dist/src/connection/websocket/ServerWebsocket.js.map +0 -1
- package/dist/src/dht/contact/Remote.js.map +0 -1
- package/dist/src/dht/find/FindRpcLocal.d.ts +0 -14
- package/dist/src/dht/find/FindRpcLocal.js +0 -25
- package/dist/src/dht/find/FindRpcLocal.js.map +0 -1
- package/dist/src/dht/find/FindSession.d.ts +0 -44
- package/dist/src/dht/find/FindSession.js +0 -145
- package/dist/src/dht/find/FindSession.js.map +0 -1
- package/dist/src/dht/find/FindSessionRpcLocal.d.ts +0 -12
- package/dist/src/dht/find/FindSessionRpcLocal.js +0 -17
- package/dist/src/dht/find/FindSessionRpcLocal.js.map +0 -1
- package/dist/src/dht/find/FindSessionRpcRemote.d.ts +0 -6
- package/dist/src/dht/find/FindSessionRpcRemote.js +0 -21
- package/dist/src/dht/find/FindSessionRpcRemote.js.map +0 -1
- package/dist/src/dht/find/Finder.d.ts +0 -49
- package/dist/src/dht/find/Finder.js +0 -184
- package/dist/src/dht/find/Finder.js.map +0 -1
- package/dist/src/dht/routing/FindRpcRemote.d.ts +0 -6
- package/dist/src/dht/routing/FindRpcRemote.js +0 -41
- package/dist/src/dht/routing/FindRpcRemote.js.map +0 -1
- package/dist/src/helpers/PeerID.d.ts +0 -24
- package/dist/src/helpers/PeerID.js +0 -78
- package/dist/src/helpers/PeerID.js.map +0 -1
- package/dist/src/helpers/UUID.d.ts +0 -8
- package/dist/src/helpers/UUID.js +0 -36
- package/dist/src/helpers/UUID.js.map +0 -1
- package/dist/src/helpers/kademliaId.d.ts +0 -1
- package/dist/src/helpers/kademliaId.js +0 -14
- package/dist/src/helpers/kademliaId.js.map +0 -1
- package/dist/src/helpers/peerIdFromPeerDescriptor.d.ts +0 -6
- package/dist/src/helpers/peerIdFromPeerDescriptor.js +0 -23
- package/dist/src/helpers/peerIdFromPeerDescriptor.js.map +0 -1
- package/src/connection/ConnectivityChecker.ts +0 -199
- package/src/connection/websocket/ServerWebsocket.ts +0 -114
- package/src/dht/find/FindRpcLocal.ts +0 -35
- package/src/dht/find/FindSession.ts +0 -178
- package/src/dht/find/FindSessionRpcLocal.ts +0 -25
- package/src/dht/find/FindSessionRpcRemote.ts +0 -30
- package/src/dht/find/Finder.ts +0 -275
- package/src/dht/routing/FindRpcRemote.ts +0 -40
- package/src/helpers/PeerID.ts +0 -88
- package/src/helpers/UUID.ts +0 -35
- package/src/helpers/kademliaId.ts +0 -8
- package/src/helpers/peerIdFromPeerDescriptor.ts +0 -20
- package/test/integration/MigrateData.test.ts +0 -204
- package/test/unit/Finder.test.ts +0 -110
- package/test/unit/PeerID.test.ts +0 -22
- package/test/unit/UUID.test.ts +0 -55
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connectivityChecker.js","sourceRoot":"","sources":["../../../src/connection/connectivityChecker.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAAsF;AACtF,+BAAyB;AACzB,uDAAwC;AACxC,gEAG4C;AAE5C,iEAA6D;AAC7D,uEAAiF;AACjF,gDAA4D;AAE5D,MAAM,MAAM,GAAG,IAAI,cAAM,CAAC,MAAM,CAAC,CAAA;AAEjC,4CAA4C;AACrC,MAAM,YAAY,GAAG,KAAK,EAAE,EAAE,GAAG,EAAE,UAAU,EAAE,SAAS,GAAG,IAAI,EACV,EACpC,EAAE;IACtB,MAAM,MAAM,GAAG,IAAI,iCAAe,EAAE,CAAA;IACpC,IAAI,MAAoD,CAAA;IACxD,IAAI,CAAC;QACD,MAAM,GAAG,MAAM,IAAA,yBAAiB,EAAmB;YAC/C,GAAG,EAAE,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,UAAU,CAAC,CAAA,CAAC,CAAC;SAAC,EAC9C,MAAM,EAAE,CAAC,WAAW,EAAE,OAAO,CAAC,EAC9B,SAAS,CAAC,CAAA;IACd,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACT,MAAM,IAAI,GAAG,CAAC,gBAAgB,CAAC,gCAAgC,CAAC,CAAA;IACpE,CAAC;IACD,IAAI,MAAM,CAAC,UAAU,KAAK,OAAO,EAAE,CAAC;QAChC,MAAM,IAAI,GAAG,CAAC,gBAAgB,CAAC,qCAAqC,CAAC,CAAA;IACzE,CAAC;IACD,OAAO,MAAM,CAAA;AACjB,CAAC,CAAA;AAjBY,QAAA,YAAY,gBAiBxB;AAEY,QAAA,+BAA+B,GAAG,6BAA6B,CAAA;AAC5E,MAAM,4BAA4B,GAAG,IAAI,CAAA;AAElC,MAAM,uBAAuB,GAAG,KAAK,EACxC,OAA4B,EAC5B,UAA0B,EACG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AAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;QAChF,OAAO,MAAM,UAAU,CAAA;IAC3B,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACT,MAAM,CAAC,KAAK,CAAC,oCAAoC,CAAC,CAAA;QAClD,MAAM,CAAC,CAAA;IACX,CAAC;AACL,CAAC,CAAA;AAvEY,QAAA,uBAAuB,2BAuEnC"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.attachConnectivityRequestHandler = exports.DISABLE_CONNECTIVITY_PROBE = void 0;
|
|
4
|
+
const utils_1 = require("@streamr/utils");
|
|
5
|
+
const uuid_1 = require("uuid");
|
|
6
|
+
const DhtRpc_1 = require("../proto/packages/dht/protos/DhtRpc");
|
|
7
|
+
const ConnectionManager_1 = require("./ConnectionManager");
|
|
8
|
+
const connectivityChecker_1 = require("./connectivityChecker");
|
|
9
|
+
const WebsocketConnector_1 = require("./websocket/WebsocketConnector");
|
|
10
|
+
const version_1 = require("../helpers/version");
|
|
11
|
+
exports.DISABLE_CONNECTIVITY_PROBE = 0;
|
|
12
|
+
const logger = new utils_1.Logger(module);
|
|
13
|
+
const attachConnectivityRequestHandler = (connectionToListenTo) => {
|
|
14
|
+
connectionToListenTo.on('data', async (data) => {
|
|
15
|
+
logger.trace('server received data');
|
|
16
|
+
try {
|
|
17
|
+
const message = DhtRpc_1.Message.fromBinary(data);
|
|
18
|
+
if (message.body.oneofKind === 'connectivityRequest') {
|
|
19
|
+
logger.trace('ConnectivityRequest received: ' + JSON.stringify(DhtRpc_1.Message.toJson(message)));
|
|
20
|
+
try {
|
|
21
|
+
await handleIncomingConnectivityRequest(connectionToListenTo, message.body.connectivityRequest);
|
|
22
|
+
logger.trace('handleIncomingConnectivityRequest ok');
|
|
23
|
+
}
|
|
24
|
+
catch (e) {
|
|
25
|
+
logger.error('handleIncomingConnectivityRequest', { error: e });
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
logger.trace(`Could not parse message: ${err}`);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
exports.attachConnectivityRequestHandler = attachConnectivityRequestHandler;
|
|
35
|
+
const handleIncomingConnectivityRequest = async (connection, connectivityRequest) => {
|
|
36
|
+
const host = connectivityRequest.host ?? connection.remoteIpAddress;
|
|
37
|
+
const ipAddress = connection.remoteIpAddress;
|
|
38
|
+
let connectivityResponse;
|
|
39
|
+
if (connectivityRequest.port !== exports.DISABLE_CONNECTIVITY_PROBE) {
|
|
40
|
+
connectivityResponse = await connectivityProbe(connectivityRequest, ipAddress, host);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
logger.trace('ConnectivityRequest port is 0, replying without connectivityProbe');
|
|
44
|
+
connectivityResponse = {
|
|
45
|
+
host,
|
|
46
|
+
natType: ConnectionManager_1.NatType.UNKNOWN,
|
|
47
|
+
ipAddress: (0, utils_1.ipv4ToNumber)(ipAddress),
|
|
48
|
+
version: version_1.LOCAL_PROTOCOL_VERSION
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
const msg = {
|
|
52
|
+
serviceId: connectivityChecker_1.CONNECTIVITY_CHECKER_SERVICE_ID,
|
|
53
|
+
messageId: (0, uuid_1.v4)(),
|
|
54
|
+
body: {
|
|
55
|
+
oneofKind: 'connectivityResponse',
|
|
56
|
+
connectivityResponse
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
connection.send(DhtRpc_1.Message.toBinary(msg));
|
|
60
|
+
logger.trace('ConnectivityResponse sent: ' + JSON.stringify(DhtRpc_1.Message.toJson(msg)));
|
|
61
|
+
};
|
|
62
|
+
const connectivityProbe = async (connectivityRequest, ipAddress, host) => {
|
|
63
|
+
let outgoingConnection;
|
|
64
|
+
let connectivityResponseMessage;
|
|
65
|
+
try {
|
|
66
|
+
const wsServerInfo = {
|
|
67
|
+
host,
|
|
68
|
+
port: connectivityRequest.port,
|
|
69
|
+
tls: connectivityRequest.tls
|
|
70
|
+
};
|
|
71
|
+
const url = (0, WebsocketConnector_1.connectivityMethodToWebsocketUrl)(wsServerInfo, 'connectivityProbe');
|
|
72
|
+
logger.trace(`Attempting Connectivity Check to ${url}`);
|
|
73
|
+
outgoingConnection = await (0, connectivityChecker_1.connectAsync)({
|
|
74
|
+
url,
|
|
75
|
+
selfSigned: connectivityRequest.selfSigned
|
|
76
|
+
});
|
|
77
|
+
logger.trace('Connectivity test produced positive result, communicating reply to the requester ' + host + ':' + connectivityRequest.port);
|
|
78
|
+
connectivityResponseMessage = {
|
|
79
|
+
host,
|
|
80
|
+
natType: ConnectionManager_1.NatType.OPEN_INTERNET,
|
|
81
|
+
websocket: { host, port: connectivityRequest.port, tls: connectivityRequest.tls },
|
|
82
|
+
ipAddress: (0, utils_1.ipv4ToNumber)(ipAddress),
|
|
83
|
+
version: version_1.LOCAL_PROTOCOL_VERSION
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
logger.debug('error', { err });
|
|
88
|
+
connectivityResponseMessage = {
|
|
89
|
+
host,
|
|
90
|
+
natType: ConnectionManager_1.NatType.UNKNOWN,
|
|
91
|
+
ipAddress: (0, utils_1.ipv4ToNumber)(ipAddress),
|
|
92
|
+
version: version_1.LOCAL_PROTOCOL_VERSION
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
if (outgoingConnection) {
|
|
96
|
+
// TODO should we have some handling for this floating promise?
|
|
97
|
+
outgoingConnection.close(false);
|
|
98
|
+
}
|
|
99
|
+
return connectivityResponseMessage;
|
|
100
|
+
};
|
|
101
|
+
//# sourceMappingURL=connectivityRequestHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connectivityRequestHandler.js","sourceRoot":"","sources":["../../../src/connection/connectivityRequestHandler.ts"],"names":[],"mappings":";;;AAA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AA,qDAAgC,EAAC,YAAY,EAAE,mBAAmB,CAAC,CAAA;QAC/E,MAAM,CAAC,KAAK,CAAC,oCAAoC,GAAG,EAAE,CAAC,CAAA;QACvD,kBAAkB,GAAG,MAAM,IAAA,kCAAY,EAAC;YACpC,GAAG;YACH,UAAU,EAAE,mBAAmB,CAAC,UAAU;SAC7C,CAAC,CAAA;QACF,MAAM,CAAC,KAAK,CAAC,mFAAmF,GAAG,IAAI,GAAG,GAAG,GAAG,mBAAmB,CAAC,IAAI,CAAC,CAAA;QACzI,2BAA2B,GAAG;YAC1B,IAAI;YACJ,OAAO,EAAE,2BAAO,CAAC,aAAa;YAC9B,SAAS,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,mBAAmB,CAAC,IAAI,EAAE,GAAG,EAAE,mBAAmB,CAAC,GAAG,EAAE;YACjF,SAAS,EAAE,IAAA,oBAAY,EAAC,SAAS,CAAC;YAClC,OAAO,EAAE,gCAAsB;SAClC,CAAA;IACL,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACX,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,GAAG,EAAE,CAAC,CAAA;QAC9B,2BAA2B,GAAG;YAC1B,IAAI;YACJ,OAAO,EAAE,2BAAO,CAAC,OAAO;YACxB,SAAS,EAAE,IAAA,oBAAY,EAAC,SAAS,CAAC;YAClC,OAAO,EAAE,gCAAsB;SAClC,CAAA;IACL,CAAC;IACD,IAAI,kBAAkB,EAAE,CAAC;QACrB,+DAA+D;QAC/D,kBAAkB,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;IACnC,CAAC;IACD,OAAO,2BAA2B,CAAA;AACtC,CAAC,CAAA"}
|
|
@@ -3,7 +3,6 @@ import { PeerDescriptor } from '../../proto/packages/dht/protos/DhtRpc';
|
|
|
3
3
|
import { ConnectionSourceEvents } from '../IConnectionSource';
|
|
4
4
|
import { SimulatorConnector } from './SimulatorConnector';
|
|
5
5
|
import { SimulatorConnection } from './SimulatorConnection';
|
|
6
|
-
export declare function isRunningInElectron(): boolean;
|
|
7
6
|
export declare enum LatencyType {
|
|
8
7
|
NONE = "NONE",
|
|
9
8
|
RANDOM = "RANDOM",
|
|
@@ -21,8 +20,6 @@ export declare class Simulator extends EventEmitter<ConnectionSourceEvents> {
|
|
|
21
20
|
private MAX_LOOPS;
|
|
22
21
|
private operationQueue;
|
|
23
22
|
private simulatorTimeout?;
|
|
24
|
-
private static clock;
|
|
25
|
-
static useFakeTimers(on?: boolean): void;
|
|
26
23
|
constructor(latencyType?: LatencyType, fixedLatency?: number);
|
|
27
24
|
private generateExecutionTime;
|
|
28
25
|
private getLatency;
|
|
@@ -1,45 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
4
|
};
|
|
28
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.Simulator = exports.LatencyType =
|
|
6
|
+
exports.Simulator = exports.LatencyType = void 0;
|
|
30
7
|
/* eslint-disable @typescript-eslint/parameter-properties */
|
|
31
8
|
const eventemitter3_1 = __importDefault(require("eventemitter3"));
|
|
32
9
|
const utils_1 = require("@streamr/utils");
|
|
33
10
|
const pings_1 = require("./pings");
|
|
34
|
-
const peerIdFromPeerDescriptor_1 = require("../../helpers/peerIdFromPeerDescriptor");
|
|
35
11
|
const heap_1 = __importDefault(require("heap"));
|
|
36
12
|
const debugHelpers_1 = require("../../helpers/debugHelpers");
|
|
37
|
-
const
|
|
38
|
-
function isRunningInElectron() {
|
|
39
|
-
// eslint-disable-next-line no-underscore-dangle
|
|
40
|
-
return typeof _streamr_electron_test !== 'undefined';
|
|
41
|
-
}
|
|
42
|
-
exports.isRunningInElectron = isRunningInElectron;
|
|
13
|
+
const identifiers_1 = require("../../identifiers");
|
|
43
14
|
const logger = new utils_1.Logger(module);
|
|
44
15
|
var LatencyType;
|
|
45
16
|
(function (LatencyType) {
|
|
@@ -50,10 +21,13 @@ var LatencyType;
|
|
|
50
21
|
})(LatencyType || (exports.LatencyType = LatencyType = {}));
|
|
51
22
|
// One-way 'pipe' of messages
|
|
52
23
|
class Association {
|
|
24
|
+
connectedCallback;
|
|
25
|
+
sourceConnection;
|
|
26
|
+
destinationConnection;
|
|
27
|
+
lastOperationAt = 0;
|
|
28
|
+
closing = false;
|
|
53
29
|
constructor(sourceConnection, destinationConnection, connectedCallback) {
|
|
54
30
|
this.connectedCallback = connectedCallback;
|
|
55
|
-
this.lastOperationAt = 0;
|
|
56
|
-
this.closing = false;
|
|
57
31
|
this.sourceConnection = sourceConnection;
|
|
58
32
|
this.destinationConnection = destinationConnection;
|
|
59
33
|
}
|
|
@@ -74,16 +48,20 @@ class Association {
|
|
|
74
48
|
}
|
|
75
49
|
}
|
|
76
50
|
class SimulatorOperation {
|
|
51
|
+
executionTime;
|
|
52
|
+
association;
|
|
53
|
+
static objectCounter = 0;
|
|
54
|
+
objectId = 0;
|
|
77
55
|
constructor(executionTime, association) {
|
|
78
56
|
this.executionTime = executionTime;
|
|
79
57
|
this.association = association;
|
|
80
|
-
this.objectId = 0;
|
|
81
58
|
this.objectId = SimulatorOperation.objectCounter;
|
|
82
59
|
SimulatorOperation.objectCounter++;
|
|
83
60
|
}
|
|
84
61
|
}
|
|
85
|
-
SimulatorOperation.objectCounter = 0;
|
|
86
62
|
class ConnectOperation extends SimulatorOperation {
|
|
63
|
+
sourceConnection;
|
|
64
|
+
targetDescriptor;
|
|
87
65
|
constructor(executionTime, association, sourceConnection, targetDescriptor) {
|
|
88
66
|
super(executionTime, association);
|
|
89
67
|
this.sourceConnection = sourceConnection;
|
|
@@ -91,6 +69,7 @@ class ConnectOperation extends SimulatorOperation {
|
|
|
91
69
|
}
|
|
92
70
|
}
|
|
93
71
|
class SendOperation extends SimulatorOperation {
|
|
72
|
+
data;
|
|
94
73
|
constructor(executionTime, association, data) {
|
|
95
74
|
super(executionTime, association);
|
|
96
75
|
this.data = data;
|
|
@@ -99,42 +78,31 @@ class SendOperation extends SimulatorOperation {
|
|
|
99
78
|
class CloseOperation extends SimulatorOperation {
|
|
100
79
|
}
|
|
101
80
|
class Simulator extends eventemitter3_1.default {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
114
|
-
}
|
|
81
|
+
stopped = false;
|
|
82
|
+
connectors = new Map();
|
|
83
|
+
latencyTable;
|
|
84
|
+
associations = new Map();
|
|
85
|
+
latencyType;
|
|
86
|
+
fixedLatency;
|
|
87
|
+
loopCounter = 0;
|
|
88
|
+
MAX_LOOPS = 1000;
|
|
89
|
+
operationQueue = new heap_1.default((a, b) => {
|
|
90
|
+
if ((a.executionTime - b.executionTime) === 0) {
|
|
91
|
+
return (a.objectId - b.objectId);
|
|
115
92
|
}
|
|
116
|
-
|
|
93
|
+
else {
|
|
94
|
+
return (a.executionTime - b.executionTime);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
simulatorTimeout;
|
|
117
98
|
constructor(latencyType = LatencyType.NONE, fixedLatency) {
|
|
118
99
|
super();
|
|
119
|
-
this.stopped = false;
|
|
120
|
-
this.connectors = new Map();
|
|
121
|
-
this.associations = new Map();
|
|
122
|
-
this.loopCounter = 0;
|
|
123
|
-
this.MAX_LOOPS = 1000;
|
|
124
|
-
this.operationQueue = new heap_1.default((a, b) => {
|
|
125
|
-
if ((a.executionTime - b.executionTime) === 0) {
|
|
126
|
-
return (a.objectId - b.objectId);
|
|
127
|
-
}
|
|
128
|
-
else {
|
|
129
|
-
return (a.executionTime - b.executionTime);
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
100
|
this.latencyType = latencyType;
|
|
133
101
|
this.fixedLatency = fixedLatency;
|
|
134
102
|
if (this.latencyType === LatencyType.REAL) {
|
|
135
103
|
this.latencyTable = (0, pings_1.getRegionDelayMatrix)();
|
|
136
104
|
}
|
|
137
|
-
if (this.latencyType === LatencyType.FIXED &&
|
|
105
|
+
if ((this.latencyType === LatencyType.FIXED) && (this.fixedLatency === undefined)) {
|
|
138
106
|
throw new Error('LatencyType.FIXED requires the desired latency to be given as second parameter');
|
|
139
107
|
}
|
|
140
108
|
this.generateExecutionTime = this.generateExecutionTime.bind(this);
|
|
@@ -164,7 +132,7 @@ class Simulator extends eventemitter3_1.default {
|
|
|
164
132
|
if (this.latencyType === LatencyType.REAL) {
|
|
165
133
|
if (sourceRegion === undefined || targetRegion === undefined || sourceRegion > 15 || targetRegion > 15) {
|
|
166
134
|
logger.error('invalid region index given to Simulator');
|
|
167
|
-
throw ('invalid region index given to Simulator');
|
|
135
|
+
throw new Error('invalid region index given to Simulator');
|
|
168
136
|
}
|
|
169
137
|
latency = this.latencyTable[sourceRegion][targetRegion];
|
|
170
138
|
}
|
|
@@ -185,10 +153,10 @@ class Simulator extends eventemitter3_1.default {
|
|
|
185
153
|
sourceAssociation.connectedCallback();
|
|
186
154
|
}
|
|
187
155
|
addConnector(connector) {
|
|
188
|
-
this.connectors.set((0,
|
|
156
|
+
this.connectors.set((0, identifiers_1.getNodeIdFromPeerDescriptor)(connector.getPeerDescriptor()), connector);
|
|
189
157
|
}
|
|
190
158
|
executeConnectOperation(operation) {
|
|
191
|
-
const target = this.connectors.get((0,
|
|
159
|
+
const target = this.connectors.get((0, identifiers_1.getNodeIdFromPeerDescriptor)(operation.targetDescriptor));
|
|
192
160
|
if (!target) {
|
|
193
161
|
logger.error('Target connector not found when executing connect operation');
|
|
194
162
|
return operation.association.connectedCallback('Target connector not found');
|
|
@@ -263,9 +231,6 @@ class Simulator extends eventemitter3_1.default {
|
|
|
263
231
|
const firstOperationTime = firstOperation.executionTime;
|
|
264
232
|
const timeDifference = firstOperationTime - currentTime;
|
|
265
233
|
this.simulatorTimeout = setTimeout(this.executeQueuedOperations, timeDifference);
|
|
266
|
-
if (Simulator.clock) {
|
|
267
|
-
Simulator.clock.runAllAsync();
|
|
268
|
-
}
|
|
269
234
|
}
|
|
270
235
|
scheduleOperation(operation) {
|
|
271
236
|
this.operationQueue.push(operation);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Simulator.js","sourceRoot":"","sources":["../../../../src/connection/simulator/Simulator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Simulator.js","sourceRoot":"","sources":["../../../../src/connection/simulator/Simulator.ts"],"names":[],"mappings":";;;;;;AAAA,4DAA4D;AAC5D,kEAAwC;AAMxC,0CAAuC;AACvC,mCAA8C;AAC9C,gDAAuB;AACvB,6DAAsD;AACtD,mDAA2E;AA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,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,GAAG,0CAA0C,CAAC,CAAA;QAEhF,IAAI,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACxB,YAAY,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAA;QACvC,CAAC;IACL,CAAC;CACJ;AAxRD,8BAwRC"}
|
|
@@ -5,12 +5,15 @@ const DhtRpc_1 = require("../../proto/packages/dht/protos/DhtRpc");
|
|
|
5
5
|
const Connection_1 = require("../Connection");
|
|
6
6
|
const utils_1 = require("@streamr/utils");
|
|
7
7
|
const protoToString_1 = require("../../helpers/protoToString");
|
|
8
|
-
const
|
|
8
|
+
const identifiers_1 = require("../../identifiers");
|
|
9
9
|
const logger = new utils_1.Logger(module);
|
|
10
10
|
class SimulatorConnection extends Connection_1.Connection {
|
|
11
|
+
stopped = false;
|
|
12
|
+
localPeerDescriptor;
|
|
13
|
+
targetPeerDescriptor;
|
|
14
|
+
simulator;
|
|
11
15
|
constructor(localPeerDescriptor, targetPeerDescriptor, connectionType, simulator) {
|
|
12
16
|
super(connectionType);
|
|
13
|
-
this.stopped = false;
|
|
14
17
|
this.localPeerDescriptor = localPeerDescriptor;
|
|
15
18
|
this.setPeerDescriptor(targetPeerDescriptor);
|
|
16
19
|
this.targetPeerDescriptor = targetPeerDescriptor;
|
|
@@ -30,44 +33,40 @@ class SimulatorConnection extends Connection_1.Connection {
|
|
|
30
33
|
this.simulator.send(this, data);
|
|
31
34
|
}
|
|
32
35
|
else {
|
|
33
|
-
|
|
34
|
-
|
|
36
|
+
const localNodeId = (0, identifiers_1.getNodeIdFromPeerDescriptor)(this.localPeerDescriptor);
|
|
37
|
+
const targetNodeId = (0, identifiers_1.getNodeIdFromPeerDescriptor)(this.targetPeerDescriptor);
|
|
38
|
+
logger.error(localNodeId + ', ' + targetNodeId + 'tried to send() on a stopped connection');
|
|
35
39
|
}
|
|
36
40
|
}
|
|
37
41
|
async close(gracefulLeave) {
|
|
38
|
-
|
|
39
|
-
|
|
42
|
+
const localNodeId = (0, identifiers_1.getNodeIdFromPeerDescriptor)(this.localPeerDescriptor);
|
|
43
|
+
const targetNodeId = (0, identifiers_1.getNodeIdFromPeerDescriptor)(this.targetPeerDescriptor);
|
|
44
|
+
logger.trace(localNodeId + ', ' + targetNodeId + ' close()');
|
|
40
45
|
if (!this.stopped) {
|
|
41
|
-
logger.trace(
|
|
42
|
-
+ (0, peerIdFromPeerDescriptor_1.getNodeIdFromPeerDescriptor)(this.targetPeerDescriptor) + ' close() not stopped');
|
|
46
|
+
logger.trace(localNodeId + ', ' + targetNodeId + ' close() not stopped');
|
|
43
47
|
this.stopped = true;
|
|
44
48
|
try {
|
|
45
|
-
logger.trace(
|
|
46
|
-
' close() calling simulator.disconnect()');
|
|
49
|
+
logger.trace(localNodeId + ', ' + targetNodeId + ' close() calling simulator.disconnect()');
|
|
47
50
|
this.simulator.close(this);
|
|
48
|
-
logger.trace(
|
|
49
|
-
' close() simulator.disconnect returned');
|
|
51
|
+
logger.trace(localNodeId + ', ' + targetNodeId + ' close() simulator.disconnect returned');
|
|
50
52
|
}
|
|
51
53
|
catch (e) {
|
|
52
|
-
logger.trace(
|
|
53
|
-
'close aborted' + e);
|
|
54
|
+
logger.trace(localNodeId + ', ' + targetNodeId + 'close aborted' + e);
|
|
54
55
|
}
|
|
55
56
|
finally {
|
|
56
|
-
logger.trace(
|
|
57
|
-
' calling this.doDisconnect');
|
|
57
|
+
logger.trace(localNodeId + ', ' + targetNodeId + ' calling this.doDisconnect');
|
|
58
58
|
this.doDisconnect(gracefulLeave);
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
else {
|
|
62
|
-
logger.trace(
|
|
63
|
-
' close() tried to close a stopped connection');
|
|
62
|
+
logger.trace(localNodeId + ', ' + targetNodeId + ' close() tried to close a stopped connection');
|
|
64
63
|
}
|
|
65
64
|
}
|
|
66
65
|
connect() {
|
|
67
66
|
if (!this.stopped) {
|
|
68
67
|
logger.trace('connect() called');
|
|
69
68
|
this.simulator.connect(this, this.targetPeerDescriptor, (error) => {
|
|
70
|
-
if (error) {
|
|
69
|
+
if (error !== undefined) {
|
|
71
70
|
logger.trace(error);
|
|
72
71
|
this.doDisconnect(false);
|
|
73
72
|
}
|
|
@@ -92,7 +91,8 @@ class SimulatorConnection extends Connection_1.Connection {
|
|
|
92
91
|
}
|
|
93
92
|
handleIncomingDisconnection() {
|
|
94
93
|
if (!this.stopped) {
|
|
95
|
-
|
|
94
|
+
const localNodeId = (0, identifiers_1.getNodeIdFromPeerDescriptor)(this.localPeerDescriptor);
|
|
95
|
+
logger.trace(localNodeId + ' handleIncomingDisconnection()');
|
|
96
96
|
this.stopped = true;
|
|
97
97
|
this.doDisconnect(false);
|
|
98
98
|
}
|
|
@@ -101,20 +101,22 @@ class SimulatorConnection extends Connection_1.Connection {
|
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
destroy() {
|
|
104
|
+
const localNodeId = (0, identifiers_1.getNodeIdFromPeerDescriptor)(this.localPeerDescriptor);
|
|
104
105
|
if (!this.stopped) {
|
|
105
|
-
logger.trace(
|
|
106
|
+
logger.trace(localNodeId + ' destroy()');
|
|
106
107
|
this.removeAllListeners();
|
|
107
108
|
this.close(false).catch((_e) => { });
|
|
108
109
|
}
|
|
109
110
|
else {
|
|
110
|
-
logger.trace(
|
|
111
|
+
logger.trace(localNodeId + ' tried to call destroy() a stopped connection');
|
|
111
112
|
}
|
|
112
113
|
}
|
|
113
114
|
doDisconnect(gracefulLeave) {
|
|
114
|
-
|
|
115
|
+
const localNodeId = (0, identifiers_1.getNodeIdFromPeerDescriptor)(this.localPeerDescriptor);
|
|
116
|
+
const targetNodeId = (0, identifiers_1.getNodeIdFromPeerDescriptor)(this.targetPeerDescriptor);
|
|
117
|
+
logger.trace(localNodeId + ' doDisconnect()');
|
|
115
118
|
this.stopped = true;
|
|
116
|
-
logger.trace(
|
|
117
|
-
+ (0, peerIdFromPeerDescriptor_1.getNodeIdFromPeerDescriptor)(this.targetPeerDescriptor) + ' doDisconnect emitting');
|
|
119
|
+
logger.trace(localNodeId + ', ' + targetNodeId + ' doDisconnect emitting');
|
|
118
120
|
this.emit('disconnected', gracefulLeave);
|
|
119
121
|
}
|
|
120
122
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SimulatorConnection.js","sourceRoot":"","sources":["../../../../src/connection/simulator/SimulatorConnection.ts"],"names":[],"mappings":";;;AAEA,mEAAgF;AAChF,8CAA0C;AAC1C,0CAAuC;AACvC,+DAA2D;AAC3D,
|
|
1
|
+
{"version":3,"file":"SimulatorConnection.js","sourceRoot":"","sources":["../../../../src/connection/simulator/SimulatorConnection.ts"],"names":[],"mappings":";;;AAEA,mEAAgF;AAChF,8CAA0C;AAC1C,0CAAuC;AACvC,+DAA2D;AAC3D,mDAA+D;AAE/D,MAAM,MAAM,GAAG,IAAI,cAAM,CAAC,MAAM,CAAC,CAAA;AAEjC,MAAa,mBAAoB,SAAQ,uBAAU;IAEvC,OAAO,GAAG,KAAK,CAAA;IAChB,mBAAmB,CAAgB;IAClC,oBAAoB,CAAgB;IACpC,SAAS,CAAW;IAE5B,YACI,mBAAmC,EACnC,oBAAoC,EACpC,cAA8B,EAC9B,SAAoB;QAEpB,KAAK,CAAC,cAAc,CAAC,CAAA;QAErB,IAAI,CAAC,mBAAmB,GAAG,mBAAmB,CAAA;QAC9C,IAAI,CAAC,iBAAiB,CAAC,oBAAoB,CAAC,CAAA;QAC5C,IAAI,CAAC,oBAAoB,GAAG,oBAAoB,CAAA;QAChD,IAAI,CAAC,cAAc,GAAG,cAAc,CAAA;QACpC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;QAE1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAChC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAClC,IAAI,CAAC,OAAO,GAAG,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AAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,EAAE,GAAG,CAAC,CAAC,CAAA;QACxC,CAAC;aAAM,CAAC;YACJ,MAAM,CAAC,KAAK,CAAC,WAAW,GAAG,+CAA+C,CAAC,CAAA;QAC/E,CAAC;IACL,CAAC;IAEO,YAAY,CAAC,aAAsB;QACvC,MAAM,WAAW,GAAG,IAAA,yCAA2B,EAAC,IAAI,CAAC,mBAAmB,CAAC,CAAA;QACzE,MAAM,YAAY,GAAG,IAAA,yCAA2B,EAAC,IAAI,CAAC,oBAAoB,CAAC,CAAA;QAC3E,MAAM,CAAC,KAAK,CAAC,WAAW,GAAG,iBAAiB,CAAC,CAAA;QAC7C,IAAI,CAAC,OAAO,GAAG,IAAI,CAAA;QAEnB,MAAM,CAAC,KAAK,CAAC,WAAW,GAAG,IAAI,GAAG,YAAY,GAAG,wBAAwB,CAAC,CAAA;QAE1E,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,aAAa,CAAC,CAAA;IAC5C,CAAC;CACJ;AA/HD,kDA+HC"}
|
|
@@ -6,32 +6,35 @@ const DhtRpc_1 = require("../../proto/packages/dht/protos/DhtRpc");
|
|
|
6
6
|
const utils_1 = require("@streamr/utils");
|
|
7
7
|
const ManagedConnection_1 = require("../ManagedConnection");
|
|
8
8
|
const SimulatorConnection_1 = require("./SimulatorConnection");
|
|
9
|
-
const
|
|
9
|
+
const identifiers_1 = require("../../identifiers");
|
|
10
10
|
const logger = new utils_1.Logger(module);
|
|
11
11
|
class SimulatorConnector {
|
|
12
|
+
connectingConnections = new Map();
|
|
13
|
+
stopped = false;
|
|
14
|
+
localPeerDescriptor;
|
|
15
|
+
simulator;
|
|
16
|
+
onNewConnection;
|
|
12
17
|
constructor(localPeerDescriptor, simulator, onNewConnection) {
|
|
13
|
-
this.connectingConnections = new Map();
|
|
14
|
-
this.stopped = false;
|
|
15
18
|
this.localPeerDescriptor = localPeerDescriptor;
|
|
16
19
|
this.simulator = simulator;
|
|
17
20
|
this.onNewConnection = onNewConnection;
|
|
18
21
|
}
|
|
19
22
|
connect(targetPeerDescriptor) {
|
|
20
|
-
logger.trace('connect() ' + (0,
|
|
21
|
-
const
|
|
22
|
-
const existingConnection = this.connectingConnections.get(
|
|
23
|
+
logger.trace('connect() ' + (0, identifiers_1.getNodeIdFromPeerDescriptor)(targetPeerDescriptor));
|
|
24
|
+
const nodeId = (0, identifiers_1.getNodeIdFromPeerDescriptor)(targetPeerDescriptor);
|
|
25
|
+
const existingConnection = this.connectingConnections.get(nodeId);
|
|
23
26
|
if (existingConnection) {
|
|
24
27
|
return existingConnection;
|
|
25
28
|
}
|
|
26
29
|
const connection = new SimulatorConnection_1.SimulatorConnection(this.localPeerDescriptor, targetPeerDescriptor, IConnection_1.ConnectionType.SIMULATOR_CLIENT, this.simulator);
|
|
27
30
|
const managedConnection = new ManagedConnection_1.ManagedConnection(this.localPeerDescriptor, IConnection_1.ConnectionType.SIMULATOR_CLIENT, connection, undefined);
|
|
28
31
|
managedConnection.setRemotePeerDescriptor(targetPeerDescriptor);
|
|
29
|
-
this.connectingConnections.set(
|
|
32
|
+
this.connectingConnections.set(nodeId, managedConnection);
|
|
30
33
|
connection.once('disconnected', () => {
|
|
31
|
-
this.connectingConnections.delete(
|
|
34
|
+
this.connectingConnections.delete(nodeId);
|
|
32
35
|
});
|
|
33
36
|
connection.once('connected', () => {
|
|
34
|
-
this.connectingConnections.delete(
|
|
37
|
+
this.connectingConnections.delete(nodeId);
|
|
35
38
|
});
|
|
36
39
|
connection.connect();
|
|
37
40
|
return managedConnection;
|
|
@@ -40,7 +43,8 @@ class SimulatorConnector {
|
|
|
40
43
|
return this.localPeerDescriptor;
|
|
41
44
|
}
|
|
42
45
|
handleIncomingConnection(sourceConnection) {
|
|
43
|
-
|
|
46
|
+
const localNodeId = (0, identifiers_1.getNodeIdFromPeerDescriptor)(sourceConnection.localPeerDescriptor);
|
|
47
|
+
logger.trace(localNodeId + ' incoming connection, stopped: ' + this.stopped);
|
|
44
48
|
if (this.stopped) {
|
|
45
49
|
return;
|
|
46
50
|
}
|
|
@@ -48,9 +52,9 @@ class SimulatorConnector {
|
|
|
48
52
|
const managedConnection = new ManagedConnection_1.ManagedConnection(this.localPeerDescriptor, IConnection_1.ConnectionType.SIMULATOR_SERVER, undefined, connection);
|
|
49
53
|
logger.trace('connected');
|
|
50
54
|
managedConnection.once('handshakeRequest', () => {
|
|
51
|
-
logger.trace(
|
|
55
|
+
logger.trace(localNodeId + ' incoming handshake request');
|
|
52
56
|
if (this.onNewConnection(managedConnection)) {
|
|
53
|
-
logger.trace(
|
|
57
|
+
logger.trace(localNodeId + ' calling acceptHandshake');
|
|
54
58
|
managedConnection.acceptHandshake();
|
|
55
59
|
}
|
|
56
60
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SimulatorConnector.js","sourceRoot":"","sources":["../../../../src/connection/simulator/SimulatorConnector.ts"],"names":[],"mappings":";;;AAAA,gDAA+C;AAE/C,mEAG+C;AAC/C,0CAAuC;AACvC,4DAAwD;
|
|
1
|
+
{"version":3,"file":"SimulatorConnector.js","sourceRoot":"","sources":["../../../../src/connection/simulator/SimulatorConnector.ts"],"names":[],"mappings":";;;AAAA,gDAA+C;AAE/C,mEAG+C;AAC/C,0CAAuC;AACvC,4DAAwD;AAExD,+DAA2D;AAC3D,mDAA2E;AAE3E,MAAM,MAAM,GAAG,IAAI,cAAM,CAAC,MAAM,CAAC,CAAA;AAEjC,MAAa,kBAAkB;IAEnB,qBAAqB,GAAuC,IAAI,GAAG,EAAE,CAAA;IACrE,OAAO,GAAG,KAAK,CAAA;IACf,mBAAmB,CAAgB;IACnC,SAAS,CAAW;IACpB,eAAe,CAA4C;IAEnE,YACI,mBAAmC,EACnC,SAAoB,EACpB,eAA2D;QAE3D,IAAI,CAAC,mBAAmB,GAAG,mBAAmB,CAAA;QAC9C,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;QAC1B,IAAI,CAAC,eAAe,GAA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