@streamr/dht 0.0.1-tatum.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/.eslintignore +5 -0
- package/.eslintrc +3 -0
- package/README.md +38 -0
- package/dist/src/connection/Connection.d.ts +11 -0
- package/dist/src/connection/Connection.js +23 -0
- package/dist/src/connection/Connection.js.map +1 -0
- package/dist/src/connection/ConnectionLockHandler.d.ts +23 -0
- package/dist/src/connection/ConnectionLockHandler.js +94 -0
- package/dist/src/connection/ConnectionLockHandler.js.map +1 -0
- package/dist/src/connection/ConnectionManager.d.ts +94 -0
- package/dist/src/connection/ConnectionManager.js +554 -0
- package/dist/src/connection/ConnectionManager.js.map +1 -0
- package/dist/src/connection/ConnectivityChecker.d.ts +17 -0
- package/dist/src/connection/ConnectivityChecker.js +187 -0
- package/dist/src/connection/ConnectivityChecker.js.map +1 -0
- package/dist/src/connection/Handshaker.d.ts +19 -0
- package/dist/src/connection/Handshaker.js +77 -0
- package/dist/src/connection/Handshaker.js.map +1 -0
- package/dist/src/connection/IConnection.d.ts +38 -0
- package/dist/src/connection/IConnection.js +19 -0
- package/dist/src/connection/IConnection.js.map +1 -0
- package/dist/src/connection/IConnectionSource.d.ts +4 -0
- package/dist/src/connection/IConnectionSource.js +3 -0
- package/dist/src/connection/IConnectionSource.js.map +1 -0
- package/dist/src/connection/ManagedConnection.d.ts +60 -0
- package/dist/src/connection/ManagedConnection.js +352 -0
- package/dist/src/connection/ManagedConnection.js.map +1 -0
- package/dist/src/connection/ManagedWebRtcConnection.d.ts +7 -0
- package/dist/src/connection/ManagedWebRtcConnection.js +20 -0
- package/dist/src/connection/ManagedWebRtcConnection.js.map +1 -0
- package/dist/src/connection/RemoteConnectionLocker.d.ts +14 -0
- package/dist/src/connection/RemoteConnectionLocker.js +93 -0
- package/dist/src/connection/RemoteConnectionLocker.js.map +1 -0
- package/dist/src/connection/Simulator/Simulator.d.ts +42 -0
- package/dist/src/connection/Simulator/Simulator.js +325 -0
- package/dist/src/connection/Simulator/Simulator.js.map +1 -0
- package/dist/src/connection/Simulator/SimulatorConnection.d.ts +19 -0
- package/dist/src/connection/Simulator/SimulatorConnection.js +118 -0
- package/dist/src/connection/Simulator/SimulatorConnection.js.map +1 -0
- package/dist/src/connection/Simulator/SimulatorConnector.d.ts +17 -0
- package/dist/src/connection/Simulator/SimulatorConnector.js +72 -0
- package/dist/src/connection/Simulator/SimulatorConnector.js.map +1 -0
- package/dist/src/connection/Simulator/SimulatorTransport.d.ts +6 -0
- package/dist/src/connection/Simulator/SimulatorTransport.js +11 -0
- package/dist/src/connection/Simulator/SimulatorTransport.js.map +1 -0
- package/dist/src/connection/Simulator/pings.d.ts +21 -0
- package/dist/src/connection/Simulator/pings.js +61 -0
- package/dist/src/connection/Simulator/pings.js.map +1 -0
- package/dist/src/connection/WebRTC/IWebRtcConnection.d.ts +20 -0
- package/dist/src/connection/WebRTC/IWebRtcConnection.js +9 -0
- package/dist/src/connection/WebRTC/IWebRtcConnection.js.map +1 -0
- package/dist/src/connection/WebRTC/NodeWebRtcConnection.d.ts +47 -0
- package/dist/src/connection/WebRTC/NodeWebRtcConnection.js +233 -0
- package/dist/src/connection/WebRTC/NodeWebRtcConnection.js.map +1 -0
- package/dist/src/connection/WebRTC/RemoteWebrtcConnector.d.ts +12 -0
- package/dist/src/connection/WebRTC/RemoteWebrtcConnector.js +74 -0
- package/dist/src/connection/WebRTC/RemoteWebrtcConnector.js.map +1 -0
- package/dist/src/connection/WebRTC/WebRtcConnector.d.ts +47 -0
- package/dist/src/connection/WebRTC/WebRtcConnector.js +227 -0
- package/dist/src/connection/WebRTC/WebRtcConnector.js.map +1 -0
- package/dist/src/connection/WebRTC/iceServerAsString.d.ts +2 -0
- package/dist/src/connection/WebRTC/iceServerAsString.js +18 -0
- package/dist/src/connection/WebRTC/iceServerAsString.js.map +1 -0
- package/dist/src/connection/WebSocket/ClientWebSocket.d.ts +15 -0
- package/dist/src/connection/WebSocket/ClientWebSocket.js +113 -0
- package/dist/src/connection/WebSocket/ClientWebSocket.js.map +1 -0
- package/dist/src/connection/WebSocket/RemoteWebSocketConnector.d.ts +9 -0
- package/dist/src/connection/WebSocket/RemoteWebSocketConnector.js +63 -0
- package/dist/src/connection/WebSocket/RemoteWebSocketConnector.js.map +1 -0
- package/dist/src/connection/WebSocket/ServerWebSocket.d.ts +18 -0
- package/dist/src/connection/WebSocket/ServerWebSocket.js +103 -0
- package/dist/src/connection/WebSocket/ServerWebSocket.js.map +1 -0
- package/dist/src/connection/WebSocket/WebSocketConnector.d.ts +31 -0
- package/dist/src/connection/WebSocket/WebSocketConnector.js +202 -0
- package/dist/src/connection/WebSocket/WebSocketConnector.js.map +1 -0
- package/dist/src/connection/WebSocket/WebSocketServer.d.ts +9 -0
- package/dist/src/connection/WebSocket/WebSocketServer.js +101 -0
- package/dist/src/connection/WebSocket/WebSocketServer.js.map +1 -0
- package/dist/src/dht/DhtNode.d.ts +153 -0
- package/dist/src/dht/DhtNode.js +599 -0
- package/dist/src/dht/DhtNode.js.map +1 -0
- package/dist/src/dht/DhtPeer.d.ts +18 -0
- package/dist/src/dht/DhtPeer.js +74 -0
- package/dist/src/dht/DhtPeer.js.map +1 -0
- package/dist/src/dht/ExternalApi.d.ts +8 -0
- package/dist/src/dht/ExternalApi.js +26 -0
- package/dist/src/dht/ExternalApi.js.map +1 -0
- package/dist/src/dht/RemoteExternalApi.d.ts +6 -0
- package/dist/src/dht/RemoteExternalApi.js +26 -0
- package/dist/src/dht/RemoteExternalApi.js.map +1 -0
- package/dist/src/dht/contact/Contact.d.ts +22 -0
- package/dist/src/dht/contact/Contact.js +25 -0
- package/dist/src/dht/contact/Contact.js.map +1 -0
- package/dist/src/dht/contact/RandomContactList.d.ts +20 -0
- package/dist/src/dht/contact/RandomContactList.js +78 -0
- package/dist/src/dht/contact/RandomContactList.js.map +1 -0
- package/dist/src/dht/contact/Remote.d.ts +15 -0
- package/dist/src/dht/contact/Remote.js +24 -0
- package/dist/src/dht/contact/Remote.js.map +1 -0
- package/dist/src/dht/contact/SortedContactList.d.ts +35 -0
- package/dist/src/dht/contact/SortedContactList.js +156 -0
- package/dist/src/dht/contact/SortedContactList.js.map +1 -0
- package/dist/src/dht/discovery/DiscoverySession.d.ts +36 -0
- package/dist/src/dht/discovery/DiscoverySession.js +116 -0
- package/dist/src/dht/discovery/DiscoverySession.js.map +1 -0
- package/dist/src/dht/discovery/PeerDiscovery.d.ts +42 -0
- package/dist/src/dht/discovery/PeerDiscovery.js +157 -0
- package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -0
- package/dist/src/dht/find/RecursiveFindSession.d.ts +46 -0
- package/dist/src/dht/find/RecursiveFindSession.js +142 -0
- package/dist/src/dht/find/RecursiveFindSession.js.map +1 -0
- package/dist/src/dht/find/RecursiveFinder.d.ts +54 -0
- package/dist/src/dht/find/RecursiveFinder.js +180 -0
- package/dist/src/dht/find/RecursiveFinder.js.map +1 -0
- package/dist/src/dht/find/RemoteRecursiveFindSession.d.ts +6 -0
- package/dist/src/dht/find/RemoteRecursiveFindSession.js +25 -0
- package/dist/src/dht/find/RemoteRecursiveFindSession.js.map +1 -0
- package/dist/src/dht/routing/DuplicateDetector.d.ts +13 -0
- package/dist/src/dht/routing/DuplicateDetector.js +41 -0
- package/dist/src/dht/routing/DuplicateDetector.js.map +1 -0
- package/dist/src/dht/routing/RemoteRouter.d.ts +8 -0
- package/dist/src/dht/routing/RemoteRouter.js +106 -0
- package/dist/src/dht/routing/RemoteRouter.js.map +1 -0
- package/dist/src/dht/routing/Router.d.ts +60 -0
- package/dist/src/dht/routing/Router.js +207 -0
- package/dist/src/dht/routing/Router.js.map +1 -0
- package/dist/src/dht/routing/RoutingSession.d.ts +42 -0
- package/dist/src/dht/routing/RoutingSession.js +178 -0
- package/dist/src/dht/routing/RoutingSession.js.map +1 -0
- package/dist/src/dht/store/DataStore.d.ts +45 -0
- package/dist/src/dht/store/DataStore.js +244 -0
- package/dist/src/dht/store/DataStore.js.map +1 -0
- package/dist/src/dht/store/LocalDataStore.d.ts +19 -0
- package/dist/src/dht/store/LocalDataStore.js +104 -0
- package/dist/src/dht/store/LocalDataStore.js.map +1 -0
- package/dist/src/dht/store/RemoteStore.d.ts +8 -0
- package/dist/src/dht/store/RemoteStore.js +44 -0
- package/dist/src/dht/store/RemoteStore.js.map +1 -0
- package/dist/src/exports.d.ts +19 -0
- package/dist/src/exports.js +41 -0
- package/dist/src/exports.js.map +1 -0
- package/dist/src/helpers/AddressTools.d.ts +2 -0
- package/dist/src/helpers/AddressTools.js +31 -0
- package/dist/src/helpers/AddressTools.js.map +1 -0
- package/dist/src/helpers/PeerID.d.ts +25 -0
- package/dist/src/helpers/PeerID.js +84 -0
- package/dist/src/helpers/PeerID.js.map +1 -0
- package/dist/src/helpers/UUID.d.ts +7 -0
- package/dist/src/helpers/UUID.js +32 -0
- package/dist/src/helpers/UUID.js.map +1 -0
- package/dist/src/helpers/debugHelpers.d.ts +3 -0
- package/dist/src/helpers/debugHelpers.js +11 -0
- package/dist/src/helpers/debugHelpers.js.map +1 -0
- package/dist/src/helpers/errors.d.ts +72 -0
- package/dist/src/helpers/errors.js +95 -0
- package/dist/src/helpers/errors.js.map +1 -0
- package/dist/src/helpers/peerIdFromPeerDescriptor.d.ts +5 -0
- package/dist/src/helpers/peerIdFromPeerDescriptor.js +17 -0
- package/dist/src/helpers/peerIdFromPeerDescriptor.js.map +1 -0
- package/dist/src/helpers/protoClasses.d.ts +2 -0
- package/dist/src/helpers/protoClasses.js +35 -0
- package/dist/src/helpers/protoClasses.js.map +1 -0
- package/dist/src/helpers/protoToString.d.ts +2 -0
- package/dist/src/helpers/protoToString.js +20 -0
- package/dist/src/helpers/protoToString.js.map +1 -0
- package/dist/src/proto/google/protobuf/any.d.ts +173 -0
- package/dist/src/proto/google/protobuf/any.js +155 -0
- package/dist/src/proto/google/protobuf/any.js.map +1 -0
- package/dist/src/proto/google/protobuf/empty.d.ts +32 -0
- package/dist/src/proto/google/protobuf/empty.js +34 -0
- package/dist/src/proto/google/protobuf/empty.js.map +1 -0
- package/dist/src/proto/google/protobuf/timestamp.d.ts +149 -0
- package/dist/src/proto/google/protobuf/timestamp.js +136 -0
- package/dist/src/proto/google/protobuf/timestamp.js.map +1 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +320 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +245 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +1089 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +710 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +145 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.js +3 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.js.map +1 -0
- package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.d.ts +87 -0
- package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.js +66 -0
- package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.js.map +1 -0
- package/dist/src/proto/tests.d.ts +39 -0
- package/dist/src/proto/tests.js +34 -0
- package/dist/src/proto/tests.js.map +1 -0
- package/dist/src/rpc-protocol/DhtCallContext.d.ts +12 -0
- package/dist/src/rpc-protocol/DhtCallContext.js +8 -0
- package/dist/src/rpc-protocol/DhtCallContext.js.map +1 -0
- package/dist/src/rpc-protocol/DhtRpcOptions.d.ts +8 -0
- package/dist/src/rpc-protocol/DhtRpcOptions.js +3 -0
- package/dist/src/rpc-protocol/DhtRpcOptions.js.map +1 -0
- package/dist/src/transport/ITransport.d.ts +22 -0
- package/dist/src/transport/ITransport.js +3 -0
- package/dist/src/transport/ITransport.js.map +1 -0
- package/dist/src/transport/ListeningRpcCommunicator.d.ts +6 -0
- package/dist/src/transport/ListeningRpcCommunicator.js +14 -0
- package/dist/src/transport/ListeningRpcCommunicator.js.map +1 -0
- package/dist/src/transport/RoutingRpcCommunicator.d.ts +8 -0
- package/dist/src/transport/RoutingRpcCommunicator.js +52 -0
- package/dist/src/transport/RoutingRpcCommunicator.js.map +1 -0
- package/jest.config.js +2 -0
- package/karma.config.js +20 -0
- package/package.json +64 -0
- package/proto.sh +3 -0
- package/protos/DhtRpc.proto +330 -0
- package/protos/tests.proto +16 -0
- package/src/connection/Connection.ts +23 -0
- package/src/connection/ConnectionLockHandler.ts +105 -0
- package/src/connection/ConnectionManager.ts +676 -0
- package/src/connection/ConnectivityChecker.ts +173 -0
- package/src/connection/Handshaker.ts +92 -0
- package/src/connection/IConnection.ts +47 -0
- package/src/connection/IConnectionSource.ts +6 -0
- package/src/connection/ManagedConnection.ts +398 -0
- package/src/connection/ManagedWebRtcConnection.ts +27 -0
- package/src/connection/RemoteConnectionLocker.ts +88 -0
- package/src/connection/Simulator/Simulator.ts +399 -0
- package/src/connection/Simulator/SimulatorConnection.ts +137 -0
- package/src/connection/Simulator/SimulatorConnector.ts +104 -0
- package/src/connection/Simulator/SimulatorTransport.ts +9 -0
- package/src/connection/Simulator/pings.ts +42 -0
- package/src/connection/WebRTC/BrowserWebRtcConnection.ts +227 -0
- package/src/connection/WebRTC/IWebRtcConnection.ts +24 -0
- package/src/connection/WebRTC/NodeWebRtcConnection.ts +256 -0
- package/src/connection/WebRTC/RemoteWebrtcConnector.ts +93 -0
- package/src/connection/WebRTC/WebRtcConnector.ts +306 -0
- package/src/connection/WebRTC/iceServerAsString.ts +15 -0
- package/src/connection/WebSocket/ClientWebSocket.ts +118 -0
- package/src/connection/WebSocket/RemoteWebSocketConnector.ts +49 -0
- package/src/connection/WebSocket/ServerWebSocket.ts +119 -0
- package/src/connection/WebSocket/WebSocketConnector.ts +264 -0
- package/src/connection/WebSocket/WebSocketServer.ts +97 -0
- package/src/dht/DhtNode.ts +776 -0
- package/src/dht/DhtPeer.ts +96 -0
- package/src/dht/ExternalApi.ts +29 -0
- package/src/dht/RemoteExternalApi.ts +25 -0
- package/src/dht/contact/Contact.ts +36 -0
- package/src/dht/contact/RandomContactList.ts +92 -0
- package/src/dht/contact/Remote.ts +40 -0
- package/src/dht/contact/SortedContactList.ts +196 -0
- package/src/dht/discovery/DiscoverySession.ts +150 -0
- package/src/dht/discovery/PeerDiscovery.ts +162 -0
- package/src/dht/find/RecursiveFindSession.ts +178 -0
- package/src/dht/find/RecursiveFinder.ts +272 -0
- package/src/dht/find/RemoteRecursiveFindSession.ts +33 -0
- package/src/dht/routing/DuplicateDetector.ts +53 -0
- package/src/dht/routing/RemoteRouter.ts +115 -0
- package/src/dht/routing/Router.ts +266 -0
- package/src/dht/routing/RoutingSession.ts +222 -0
- package/src/dht/store/DataStore.ts +321 -0
- package/src/dht/store/LocalDataStore.ts +114 -0
- package/src/dht/store/RemoteStore.ts +58 -0
- package/src/exports.ts +19 -0
- package/src/helpers/AddressTools.ts +26 -0
- package/src/helpers/PeerID.ts +95 -0
- package/src/helpers/UUID.ts +30 -0
- package/src/helpers/debugHelpers.ts +9 -0
- package/src/helpers/errors.ts +49 -0
- package/src/helpers/peerIdFromPeerDescriptor.ts +14 -0
- package/src/helpers/protoClasses.ts +63 -0
- package/src/helpers/protoToString.ts +21 -0
- package/src/proto/google/protobuf/any.ts +319 -0
- package/src/proto/google/protobuf/empty.ts +84 -0
- package/src/proto/google/protobuf/timestamp.ts +281 -0
- package/src/proto/packages/dht/protos/DhtRpc.client.ts +373 -0
- package/src/proto/packages/dht/protos/DhtRpc.server.ts +148 -0
- package/src/proto/packages/dht/protos/DhtRpc.ts +1399 -0
- package/src/proto/packages/proto-rpc/protos/ProtoRpc.ts +108 -0
- package/src/proto/tests.ts +52 -0
- package/src/rpc-protocol/DhtCallContext.ts +15 -0
- package/src/rpc-protocol/DhtRpcOptions.ts +9 -0
- package/src/transport/ITransport.ts +31 -0
- package/src/transport/ListeningRpcCommunicator.ts +14 -0
- package/src/transport/RoutingRpcCommunicator.ts +59 -0
- package/src/types/glogal.d.ts +1 -0
- package/src/types/textencoding.d.ts +7 -0
- package/test/RandomGraphSimulation.ts +52 -0
- package/test/benchmark/KademliaCorrectness.test.ts +115 -0
- package/test/benchmark/RecursiveFind.test.ts +87 -0
- package/test/benchmark/any.test.ts +28 -0
- package/test/benchmark/kademlia-simulation/Contact.ts +32 -0
- package/test/benchmark/kademlia-simulation/KademliaSimulation.ts +94 -0
- package/test/benchmark/kademlia-simulation/SimulationNode.ts +125 -0
- package/test/data/generateGroundTruthData.ts +70 -0
- package/test/end-to-end/Layer0-Layer1.test.ts +87 -0
- package/test/end-to-end/Layer0.test.ts +60 -0
- package/test/end-to-end/Layer0MixedConnectionTypes.test.ts +94 -0
- package/test/end-to-end/Layer0WebRTC-Layer1.test.ts +134 -0
- package/test/end-to-end/Layer0WebRTC.test.ts +98 -0
- package/test/end-to-end/Layer1-Scale-WebRTC.test.ts +69 -0
- package/test/end-to-end/Layer1-Scale-WebSocket.test.ts +73 -0
- package/test/end-to-end/WebSocketConnectionRequest.test.ts +62 -0
- package/test/integration/ConnectionLocking.test.ts +166 -0
- package/test/integration/ConnectionManager.test.ts +291 -0
- package/test/integration/DhtNodeExternalAPI.test.ts +43 -0
- package/test/integration/DhtPeer.test.ts +73 -0
- package/test/integration/DhtRpc.test.ts +131 -0
- package/test/integration/DhtWithMockConnectionLatencies.test.ts +46 -0
- package/test/integration/DhtWithMockConnections.test.ts +46 -0
- package/test/integration/DhtWithRealConnectionLatencies.test.ts +47 -0
- package/test/integration/Layer1-scale.test.ts +200 -0
- package/test/integration/MigrateData.test.ts +203 -0
- package/test/integration/Mock-Layer1-Layer0.test.ts +106 -0
- package/test/integration/MultipleEntryPointJoining.test.ts +105 -0
- package/test/integration/RecursiveFind.test.ts +50 -0
- package/test/integration/RemoteRouter.test.ts +83 -0
- package/test/integration/RemoteStore.test.ts +66 -0
- package/test/integration/RouteMessage.test.ts +254 -0
- package/test/integration/RpcErrors.test.ts +153 -0
- package/test/integration/ScaleDownDht.test.ts +66 -0
- package/test/integration/SimultaneousConnections.test.ts +308 -0
- package/test/integration/Store.test.ts +72 -0
- package/test/integration/StoreAndDelete.test.ts +93 -0
- package/test/integration/StoreOnDhtWithTwoNodes.test.ts +71 -0
- package/test/integration/WebRtcConnectionManagement.test.ts +205 -0
- package/test/integration/WebRtcConnectorRpc.test.ts +145 -0
- package/test/integration/WebSocket.test.ts +64 -0
- package/test/integration/WebSocketConnectionManagement.test.ts +131 -0
- package/test/integration/WebSocketConnectorRpc.test.ts +86 -0
- package/test/kademlia-simulation/data/nodeids.json +13002 -0
- package/test/kademlia-simulation/data/orderedneighbors.json +1001 -0
- package/test/unit/AddressTools.test.ts +40 -0
- package/test/unit/DuplicateDetector.test.ts +29 -0
- package/test/unit/LocalDataStore.test.ts +107 -0
- package/test/unit/PeerID.test.ts +22 -0
- package/test/unit/ProtobufMessage.test.ts +21 -0
- package/test/unit/RandomContactList.test.ts +87 -0
- package/test/unit/RecursiveFinder.test.ts +112 -0
- package/test/unit/Router.test.ts +124 -0
- package/test/unit/SortedContactList.test.ts +127 -0
- package/test/unit/UUID.test.ts +49 -0
- package/test/unit/WebSocketServer.test.ts +42 -0
- package/test/utils/mock/RecursiveFinder.ts +19 -0
- package/test/utils/mock/Router.ts +53 -0
- package/test/utils/mock/Transport.ts +26 -0
- package/test/utils/utils.ts +311 -0
- package/tsconfig.browser.json +15 -0
- package/tsconfig.jest.json +19 -0
- package/tsconfig.json +3 -0
- package/tsconfig.node.json +18 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
2
|
+
import { DhtNode } from '../../src/dht/DhtNode'
|
|
3
|
+
import { PeerID } from '../../src/helpers/PeerID'
|
|
4
|
+
import { ConnectionType } from '../../src/connection/IConnection'
|
|
5
|
+
import { ConnectionManager } from '../../src/connection/ConnectionManager'
|
|
6
|
+
import EventEmitter from 'events'
|
|
7
|
+
import { waitForEvent } from '@streamr/utils'
|
|
8
|
+
|
|
9
|
+
describe('Layer0 with WebRTC connections', () => {
|
|
10
|
+
const epPeerDescriptor: PeerDescriptor = {
|
|
11
|
+
kademliaId: PeerID.fromString('entrypoint').value,
|
|
12
|
+
nodeName: 'entrypoint',
|
|
13
|
+
type: NodeType.NODEJS,
|
|
14
|
+
websocket: { ip: '127.0.0.1', port: 10029 }
|
|
15
|
+
}
|
|
16
|
+
let epDhtNode: DhtNode
|
|
17
|
+
let node1: DhtNode
|
|
18
|
+
let node2: DhtNode
|
|
19
|
+
let node3: DhtNode
|
|
20
|
+
let node4: DhtNode
|
|
21
|
+
|
|
22
|
+
beforeEach(async () => {
|
|
23
|
+
|
|
24
|
+
epDhtNode = new DhtNode({ peerDescriptor: epPeerDescriptor, nodeName: 'entrypoint', numberOfNodesPerKBucket: 8 })
|
|
25
|
+
await epDhtNode.start()
|
|
26
|
+
|
|
27
|
+
await epDhtNode.joinDht([epPeerDescriptor])
|
|
28
|
+
|
|
29
|
+
node1 = new DhtNode({ peerIdString: 'Peer0', nodeName: 'Peer0', entryPoints: [epPeerDescriptor] })
|
|
30
|
+
node2 = new DhtNode({ peerIdString: 'Peer1', nodeName: 'Peer1', entryPoints: [epPeerDescriptor] })
|
|
31
|
+
node3 = new DhtNode({ peerIdString: 'Peer2', nodeName: 'Peer2', entryPoints: [epPeerDescriptor] })
|
|
32
|
+
node4 = new DhtNode({ peerIdString: 'Peer3', nodeName: 'Peer3', entryPoints: [epPeerDescriptor] })
|
|
33
|
+
|
|
34
|
+
await Promise.all([
|
|
35
|
+
node1.start(),
|
|
36
|
+
node2.start(),
|
|
37
|
+
node3.start(),
|
|
38
|
+
node4.start()
|
|
39
|
+
])
|
|
40
|
+
|
|
41
|
+
await epDhtNode.joinDht([epPeerDescriptor])
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
afterEach(async () => {
|
|
45
|
+
await Promise.all([
|
|
46
|
+
node1.stop(),
|
|
47
|
+
node2.stop(),
|
|
48
|
+
node3.stop(),
|
|
49
|
+
node4.stop()
|
|
50
|
+
])
|
|
51
|
+
await epDhtNode.stop()
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
class Peer0Listener extends EventEmitter {
|
|
55
|
+
private nodeToListen: DhtNode
|
|
56
|
+
constructor(nodeToListen: DhtNode) {
|
|
57
|
+
super()
|
|
58
|
+
this.nodeToListen = nodeToListen
|
|
59
|
+
this.nodeToListen.on('connected', (peer: PeerDescriptor) => {
|
|
60
|
+
if (PeerID.fromValue(peer.kademliaId).equals(PeerID.fromString('Peer0'))) {
|
|
61
|
+
this.emit('peer0connected')
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
it('Happy path two peers', async () => {
|
|
68
|
+
|
|
69
|
+
await Promise.all([waitForEvent(new Peer0Listener(node2), 'peer0connected', 20000),
|
|
70
|
+
node2.joinDht([epPeerDescriptor]),
|
|
71
|
+
node1.joinDht([epPeerDescriptor])
|
|
72
|
+
])
|
|
73
|
+
|
|
74
|
+
expect((node1.getTransport() as ConnectionManager).hasConnection(node2.getPeerDescriptor())).toEqual(true)
|
|
75
|
+
expect((node2.getTransport() as ConnectionManager).hasConnection(node1.getPeerDescriptor())).toEqual(true)
|
|
76
|
+
expect((node1.getTransport() as ConnectionManager).getConnection(node2.getPeerDescriptor())!.connectionType)
|
|
77
|
+
.toEqual(ConnectionType.WEBRTC)
|
|
78
|
+
expect((node2.getTransport() as ConnectionManager).getConnection(node1.getPeerDescriptor())!.connectionType)
|
|
79
|
+
.toEqual(ConnectionType.WEBRTC)
|
|
80
|
+
|
|
81
|
+
}, 60000)
|
|
82
|
+
|
|
83
|
+
it('Happy path simultaneous joins', async () => {
|
|
84
|
+
await Promise.all([
|
|
85
|
+
node1.joinDht([epPeerDescriptor]),
|
|
86
|
+
node2.joinDht([epPeerDescriptor]),
|
|
87
|
+
node3.joinDht([epPeerDescriptor]),
|
|
88
|
+
node4.joinDht([epPeerDescriptor])
|
|
89
|
+
])
|
|
90
|
+
|
|
91
|
+
expect((node1.getTransport() as ConnectionManager).hasConnection(node2.getPeerDescriptor())).toEqual(true)
|
|
92
|
+
expect((node2.getTransport() as ConnectionManager).hasConnection(node1.getPeerDescriptor())).toEqual(true)
|
|
93
|
+
expect((node1.getTransport() as ConnectionManager).getConnection(node2.getPeerDescriptor())!.connectionType)
|
|
94
|
+
.toEqual(ConnectionType.WEBRTC)
|
|
95
|
+
expect((node2.getTransport() as ConnectionManager).getConnection(node1.getPeerDescriptor())!.connectionType)
|
|
96
|
+
.toEqual(ConnectionType.WEBRTC)
|
|
97
|
+
})
|
|
98
|
+
})
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { DhtNode } from '../../src/dht/DhtNode'
|
|
2
|
+
import { NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
3
|
+
import { PeerID } from '../../src/helpers/PeerID'
|
|
4
|
+
|
|
5
|
+
describe('Layer1 Scale', () => {
|
|
6
|
+
const epPeerDescriptor: PeerDescriptor = {
|
|
7
|
+
kademliaId: PeerID.fromString('0').value,
|
|
8
|
+
type: NodeType.NODEJS,
|
|
9
|
+
websocket: { ip: '127.0.0.1', port: 43228 },
|
|
10
|
+
nodeName: 'entrypoint'
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const STREAM_ID = 'stream'
|
|
14
|
+
|
|
15
|
+
const NUM_OF_NODES = 16
|
|
16
|
+
|
|
17
|
+
let layer0Nodes: DhtNode[]
|
|
18
|
+
|
|
19
|
+
let layer1Nodes: DhtNode[]
|
|
20
|
+
|
|
21
|
+
let epLayer0Node: DhtNode
|
|
22
|
+
let epLayer1Node: DhtNode
|
|
23
|
+
|
|
24
|
+
beforeEach(async () => {
|
|
25
|
+
epLayer0Node = new DhtNode({ peerDescriptor: epPeerDescriptor })
|
|
26
|
+
await epLayer0Node.start()
|
|
27
|
+
await epLayer0Node.joinDht([epPeerDescriptor])
|
|
28
|
+
|
|
29
|
+
epLayer1Node = new DhtNode({ transportLayer: epLayer0Node, peerDescriptor: epPeerDescriptor, serviceId: STREAM_ID })
|
|
30
|
+
await epLayer1Node.start()
|
|
31
|
+
await epLayer1Node.joinDht([epPeerDescriptor])
|
|
32
|
+
|
|
33
|
+
layer0Nodes = []
|
|
34
|
+
layer1Nodes = []
|
|
35
|
+
|
|
36
|
+
for (let i = 1; i < NUM_OF_NODES; i++) {
|
|
37
|
+
const node = new DhtNode({ peerIdString: `node-${i}`, nodeName: `${i}`, entryPoints: [epPeerDescriptor] })
|
|
38
|
+
await node.start()
|
|
39
|
+
layer0Nodes.push(node)
|
|
40
|
+
const layer1 = new DhtNode({
|
|
41
|
+
transportLayer: node,
|
|
42
|
+
entryPoints: [epPeerDescriptor],
|
|
43
|
+
peerDescriptor: node.getPeerDescriptor(),
|
|
44
|
+
serviceId: STREAM_ID,
|
|
45
|
+
rpcRequestTimeout: 5000
|
|
46
|
+
})
|
|
47
|
+
await layer1.start()
|
|
48
|
+
layer1Nodes.push(layer1)
|
|
49
|
+
}
|
|
50
|
+
await Promise.all(layer0Nodes.map((node) => node.joinDht([epPeerDescriptor])))
|
|
51
|
+
await Promise.all(layer1Nodes.map((node) => node.joinDht([epPeerDescriptor])))
|
|
52
|
+
}, 120000)
|
|
53
|
+
|
|
54
|
+
afterEach(async () => {
|
|
55
|
+
await Promise.all(layer1Nodes.map((node) => node.stop()))
|
|
56
|
+
await Promise.all(layer0Nodes.map((node) => node.stop()))
|
|
57
|
+
await epLayer0Node.stop()
|
|
58
|
+
await epLayer1Node.stop()
|
|
59
|
+
}, 15000)
|
|
60
|
+
|
|
61
|
+
it('bucket sizes', async () => {
|
|
62
|
+
layer0Nodes.forEach((node) => {
|
|
63
|
+
expect(node.getBucketSize()).toBeGreaterThanOrEqual(node.getK() - 1)
|
|
64
|
+
})
|
|
65
|
+
layer1Nodes.forEach((node) => {
|
|
66
|
+
expect(node.getBucketSize()).toBeGreaterThanOrEqual(node.getK() / 2)
|
|
67
|
+
})
|
|
68
|
+
})
|
|
69
|
+
})
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { DhtNode } from '../../src/dht/DhtNode'
|
|
2
|
+
import { NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
3
|
+
import { PeerID } from '../../src/helpers/PeerID'
|
|
4
|
+
|
|
5
|
+
describe('Layer1 Scale', () => {
|
|
6
|
+
const epPeerDescriptor: PeerDescriptor = {
|
|
7
|
+
kademliaId: PeerID.fromString('entrypoint').value,
|
|
8
|
+
type: NodeType.NODEJS,
|
|
9
|
+
websocket: { ip: '127.0.0.1', port: 43225 },
|
|
10
|
+
nodeName: 'entrypoint'
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const STREAM_ID = 'stream'
|
|
14
|
+
|
|
15
|
+
const NUM_OF_NODES = 16
|
|
16
|
+
|
|
17
|
+
let layer0Nodes: DhtNode[]
|
|
18
|
+
|
|
19
|
+
let layer1Nodes: DhtNode[]
|
|
20
|
+
|
|
21
|
+
let epLayer0Node: DhtNode
|
|
22
|
+
let epLayer1Node: DhtNode
|
|
23
|
+
|
|
24
|
+
beforeEach(async () => {
|
|
25
|
+
epLayer0Node = new DhtNode({ peerDescriptor: epPeerDescriptor, nodeName: 'entrypoint' })
|
|
26
|
+
await epLayer0Node.start()
|
|
27
|
+
await epLayer0Node.joinDht([epPeerDescriptor])
|
|
28
|
+
|
|
29
|
+
epLayer1Node = new DhtNode({ transportLayer: epLayer0Node, peerDescriptor: epPeerDescriptor, serviceId: STREAM_ID, nodeName: 'entrypoint' })
|
|
30
|
+
await epLayer1Node.start()
|
|
31
|
+
await epLayer1Node.joinDht([epPeerDescriptor])
|
|
32
|
+
|
|
33
|
+
layer0Nodes = []
|
|
34
|
+
layer1Nodes = []
|
|
35
|
+
|
|
36
|
+
for (let i = 0; i < NUM_OF_NODES; i++) {
|
|
37
|
+
const node = new DhtNode({ peerIdString: `node-${i}`, nodeName: `${i}`, webSocketPort: 62200 + i, entryPoints: [epPeerDescriptor] })
|
|
38
|
+
await node.start()
|
|
39
|
+
layer0Nodes.push(node)
|
|
40
|
+
const layer1 = new DhtNode({
|
|
41
|
+
nodeName: `${i}`,
|
|
42
|
+
transportLayer: node,
|
|
43
|
+
entryPoints: [epPeerDescriptor],
|
|
44
|
+
peerDescriptor: node.getPeerDescriptor(),
|
|
45
|
+
serviceId: STREAM_ID
|
|
46
|
+
})
|
|
47
|
+
await layer1.start()
|
|
48
|
+
layer1Nodes.push(layer1)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
await Promise.all(layer0Nodes.map((node) => node.joinDht([epPeerDescriptor])))
|
|
52
|
+
|
|
53
|
+
await Promise.all(layer1Nodes.map((node) => node.joinDht([epPeerDescriptor])))
|
|
54
|
+
|
|
55
|
+
}, 60000)
|
|
56
|
+
|
|
57
|
+
afterEach(async () => {
|
|
58
|
+
await Promise.all(layer1Nodes.map((node) => node.stop()))
|
|
59
|
+
await Promise.all(layer0Nodes.map((node) => node.stop()))
|
|
60
|
+
await epLayer0Node.stop()
|
|
61
|
+
await epLayer1Node.stop()
|
|
62
|
+
}, 15000)
|
|
63
|
+
|
|
64
|
+
// TODO: fix flaky test in NET-1021
|
|
65
|
+
it('bucket sizes', async () => {
|
|
66
|
+
layer0Nodes.forEach((node) => {
|
|
67
|
+
expect(node.getBucketSize()).toBeGreaterThanOrEqual(node.getK() - 1)
|
|
68
|
+
})
|
|
69
|
+
layer1Nodes.forEach((node ) => {
|
|
70
|
+
expect(node.getBucketSize()).toBeGreaterThanOrEqual(node.getK() / 2)
|
|
71
|
+
})
|
|
72
|
+
})
|
|
73
|
+
})
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
2
|
+
import { DhtNode } from '../../src/dht/DhtNode'
|
|
3
|
+
import { ConnectionManager } from '../../src/connection/ConnectionManager'
|
|
4
|
+
import { PeerID } from '../../src/helpers/PeerID'
|
|
5
|
+
import { waitForCondition } from '@streamr/utils'
|
|
6
|
+
import { isSamePeerDescriptor } from '../../src/helpers/peerIdFromPeerDescriptor'
|
|
7
|
+
|
|
8
|
+
describe('WebSocket IConnection Requests', () => {
|
|
9
|
+
const epPeerDescriptor: PeerDescriptor = {
|
|
10
|
+
kademliaId: PeerID.fromString('3').value,
|
|
11
|
+
type: NodeType.NODEJS,
|
|
12
|
+
websocket: { ip: '127.0.0.1', port: 10021 }
|
|
13
|
+
}
|
|
14
|
+
let epDhtNode: DhtNode
|
|
15
|
+
let node1: DhtNode
|
|
16
|
+
let node2: DhtNode
|
|
17
|
+
|
|
18
|
+
beforeEach(async () => {
|
|
19
|
+
|
|
20
|
+
epDhtNode = new DhtNode({ peerDescriptor: epPeerDescriptor })
|
|
21
|
+
await epDhtNode.start()
|
|
22
|
+
|
|
23
|
+
await epDhtNode.joinDht([epPeerDescriptor])
|
|
24
|
+
|
|
25
|
+
node1 = new DhtNode({ peerIdString: '2', nodeName: 'node1', webSocketPort: 10022, entryPoints: [epPeerDescriptor] })
|
|
26
|
+
node2 = new DhtNode({ peerIdString: '1', nodeName: 'node2', entryPoints: [epPeerDescriptor] })
|
|
27
|
+
await node1.start()
|
|
28
|
+
await node2.start()
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
afterEach(async () => {
|
|
32
|
+
await epDhtNode.stop()
|
|
33
|
+
await node1.stop()
|
|
34
|
+
await node2.stop()
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
it('Happy Path', async () => {
|
|
38
|
+
|
|
39
|
+
let connected1 = false
|
|
40
|
+
let connected2 = false
|
|
41
|
+
|
|
42
|
+
node1.on('connected', (peerDescriptor: PeerDescriptor) => {
|
|
43
|
+
if (isSamePeerDescriptor(peerDescriptor, node2.getPeerDescriptor())) {
|
|
44
|
+
connected1 = true
|
|
45
|
+
}
|
|
46
|
+
})
|
|
47
|
+
node2.on('connected', (peerDescriptor: PeerDescriptor) => {
|
|
48
|
+
if (isSamePeerDescriptor(peerDescriptor, node1.getPeerDescriptor())) {
|
|
49
|
+
connected2 = true
|
|
50
|
+
}
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
await node2.joinDht([epPeerDescriptor])
|
|
54
|
+
await node1.joinDht([epPeerDescriptor])
|
|
55
|
+
|
|
56
|
+
await waitForCondition(() => { return (connected1 && connected2) })
|
|
57
|
+
|
|
58
|
+
expect((node1.getTransport() as ConnectionManager).hasConnection(node2.getPeerDescriptor())).toEqual(true)
|
|
59
|
+
expect((node2.getTransport() as ConnectionManager).hasConnection(node1.getPeerDescriptor())).toEqual(true)
|
|
60
|
+
|
|
61
|
+
}, 10000)
|
|
62
|
+
})
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { Simulator } from '../../src/connection/Simulator/Simulator'
|
|
2
|
+
import { ConnectionManager } from '../../src/connection/ConnectionManager'
|
|
3
|
+
import { NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
4
|
+
import { waitForCondition } from '@streamr/utils'
|
|
5
|
+
import { PeerID } from '../../src/helpers/PeerID'
|
|
6
|
+
import { SimulatorTransport } from '../../src/exports'
|
|
7
|
+
|
|
8
|
+
describe('Connection Locking', () => {
|
|
9
|
+
|
|
10
|
+
const mockPeerDescriptor1: PeerDescriptor = {
|
|
11
|
+
kademliaId: PeerID.fromString('mock1').value,
|
|
12
|
+
nodeName: 'mock1',
|
|
13
|
+
type: NodeType.NODEJS
|
|
14
|
+
}
|
|
15
|
+
const mockPeerDescriptor2: PeerDescriptor = {
|
|
16
|
+
kademliaId: PeerID.fromString('mock2').value,
|
|
17
|
+
nodeName: 'mock2',
|
|
18
|
+
type: NodeType.NODEJS
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
let mockConnectorTransport1: ConnectionManager
|
|
22
|
+
let mockConnectorTransport2: ConnectionManager
|
|
23
|
+
|
|
24
|
+
let connectionManager1: ConnectionManager
|
|
25
|
+
let connectionManager2: ConnectionManager
|
|
26
|
+
|
|
27
|
+
let simulator: Simulator
|
|
28
|
+
|
|
29
|
+
beforeEach(async () => {
|
|
30
|
+
simulator = new Simulator()
|
|
31
|
+
mockConnectorTransport1 = new SimulatorTransport(mockPeerDescriptor1, simulator)
|
|
32
|
+
mockConnectorTransport2 = new SimulatorTransport(mockPeerDescriptor2, simulator)
|
|
33
|
+
|
|
34
|
+
connectionManager1 = new ConnectionManager({
|
|
35
|
+
transportLayer: mockConnectorTransport1
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
connectionManager2 = new ConnectionManager({
|
|
39
|
+
transportLayer: mockConnectorTransport2
|
|
40
|
+
})
|
|
41
|
+
await connectionManager1.start(() => mockPeerDescriptor1)
|
|
42
|
+
await connectionManager2.start(() => mockPeerDescriptor2)
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
afterEach(async () => {
|
|
46
|
+
await Promise.all([
|
|
47
|
+
mockConnectorTransport1.stop(),
|
|
48
|
+
mockConnectorTransport2.stop(),
|
|
49
|
+
connectionManager1.stop(),
|
|
50
|
+
connectionManager2.stop()
|
|
51
|
+
])
|
|
52
|
+
simulator.stop()
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
it('can lock connections', async () => {
|
|
56
|
+
await Promise.all([
|
|
57
|
+
waitForCondition(() => connectionManager2.hasRemoteLockedConnection(mockPeerDescriptor1)),
|
|
58
|
+
connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock')
|
|
59
|
+
])
|
|
60
|
+
expect(connectionManager1.hasConnection(mockPeerDescriptor2)).toEqual(true)
|
|
61
|
+
expect(connectionManager1.hasLocalLockedConnection(mockPeerDescriptor2)).toEqual(true)
|
|
62
|
+
expect(connectionManager2.hasRemoteLockedConnection(mockPeerDescriptor1)).toEqual(true)
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
it('Multiple services on the same peer', async () => {
|
|
66
|
+
await Promise.all([
|
|
67
|
+
waitForCondition(() => connectionManager2.hasRemoteLockedConnection(mockPeerDescriptor1)),
|
|
68
|
+
connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock1')
|
|
69
|
+
])
|
|
70
|
+
await Promise.all([
|
|
71
|
+
waitForCondition(() => connectionManager2.hasRemoteLockedConnection(mockPeerDescriptor1, 'testLock2')),
|
|
72
|
+
connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock2')
|
|
73
|
+
])
|
|
74
|
+
expect(connectionManager1.hasConnection(mockPeerDescriptor2)).toEqual(true)
|
|
75
|
+
expect(connectionManager1.hasLocalLockedConnection(mockPeerDescriptor2)).toEqual(true)
|
|
76
|
+
expect(connectionManager2.hasRemoteLockedConnection(mockPeerDescriptor1)).toEqual(true)
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
it('can unlock connections', async () => {
|
|
80
|
+
await Promise.all([
|
|
81
|
+
waitForCondition(() => connectionManager2.hasRemoteLockedConnection(mockPeerDescriptor1)),
|
|
82
|
+
connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock')
|
|
83
|
+
])
|
|
84
|
+
expect(connectionManager1.hasConnection(mockPeerDescriptor2))
|
|
85
|
+
expect(connectionManager2.hasLocalLockedConnection(mockPeerDescriptor2)).toEqual(false)
|
|
86
|
+
expect(connectionManager2.hasRemoteLockedConnection(mockPeerDescriptor1)).toEqual(true)
|
|
87
|
+
|
|
88
|
+
connectionManager1.unlockConnection(mockPeerDescriptor2, 'testLock')
|
|
89
|
+
expect(connectionManager1.hasLocalLockedConnection(mockPeerDescriptor2)).toEqual(false)
|
|
90
|
+
await waitForCondition(() => connectionManager2.hasRemoteLockedConnection(mockPeerDescriptor1) === false)
|
|
91
|
+
expect(connectionManager1.hasConnection(mockPeerDescriptor1)).toEqual(false)
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
it('unlocking multiple services', async () => {
|
|
95
|
+
await Promise.all([
|
|
96
|
+
waitForCondition(() => connectionManager2.hasRemoteLockedConnection(mockPeerDescriptor1)),
|
|
97
|
+
connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock1')
|
|
98
|
+
])
|
|
99
|
+
await Promise.all([
|
|
100
|
+
waitForCondition(() => connectionManager2.hasRemoteLockedConnection(mockPeerDescriptor1, 'testLock2')),
|
|
101
|
+
connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock2')
|
|
102
|
+
])
|
|
103
|
+
|
|
104
|
+
expect(connectionManager1.hasConnection(mockPeerDescriptor2))
|
|
105
|
+
expect(connectionManager2.hasLocalLockedConnection(mockPeerDescriptor1)).toEqual(false)
|
|
106
|
+
|
|
107
|
+
connectionManager1.unlockConnection(mockPeerDescriptor2, 'testLock1')
|
|
108
|
+
expect(connectionManager1.hasLocalLockedConnection(mockPeerDescriptor2)).toEqual(true)
|
|
109
|
+
|
|
110
|
+
connectionManager1.unlockConnection(mockPeerDescriptor2, 'testLock2')
|
|
111
|
+
expect(connectionManager1.hasLocalLockedConnection(mockPeerDescriptor2)).toEqual(false)
|
|
112
|
+
expect(connectionManager1.hasConnection(mockPeerDescriptor1)).toEqual(false)
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
it('maintains connection if both sides initially lock and then one end unlocks', async () => {
|
|
116
|
+
await Promise.all([
|
|
117
|
+
waitForCondition(() => connectionManager2.hasRemoteLockedConnection(mockPeerDescriptor1)),
|
|
118
|
+
waitForCondition(() => connectionManager1.hasRemoteLockedConnection(mockPeerDescriptor2)),
|
|
119
|
+
connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock1'),
|
|
120
|
+
connectionManager2.lockConnection(mockPeerDescriptor1, 'testLock1')
|
|
121
|
+
])
|
|
122
|
+
|
|
123
|
+
expect(connectionManager1.hasLocalLockedConnection(mockPeerDescriptor2))
|
|
124
|
+
expect(connectionManager2.hasLocalLockedConnection(mockPeerDescriptor1))
|
|
125
|
+
|
|
126
|
+
connectionManager1.unlockConnection(mockPeerDescriptor2, 'testLock1')
|
|
127
|
+
await waitForCondition(() =>
|
|
128
|
+
connectionManager1.hasRemoteLockedConnection(mockPeerDescriptor2, 'testLock1')
|
|
129
|
+
&& !connectionManager1.hasLocalLockedConnection(mockPeerDescriptor2, 'testLock1')
|
|
130
|
+
&& !connectionManager2.hasRemoteLockedConnection(mockPeerDescriptor1, 'testLock1')
|
|
131
|
+
&& connectionManager2.hasLocalLockedConnection(mockPeerDescriptor1, 'testLock1')
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
expect(connectionManager2.hasConnection(mockPeerDescriptor1)).toEqual(true)
|
|
135
|
+
expect(connectionManager1.hasConnection(mockPeerDescriptor2)).toEqual(true)
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
it('unlocks after graceful disconnect', async () => {
|
|
139
|
+
await Promise.all([
|
|
140
|
+
waitForCondition(() => connectionManager2.hasRemoteLockedConnection(mockPeerDescriptor1)),
|
|
141
|
+
waitForCondition(() => connectionManager1.hasRemoteLockedConnection(mockPeerDescriptor2)),
|
|
142
|
+
connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock1'),
|
|
143
|
+
connectionManager2.lockConnection(mockPeerDescriptor1, 'testLock1')
|
|
144
|
+
])
|
|
145
|
+
expect(connectionManager1.hasConnection(mockPeerDescriptor2))
|
|
146
|
+
expect(connectionManager2.hasLocalLockedConnection(mockPeerDescriptor1)).toEqual(true)
|
|
147
|
+
expect(connectionManager2.hasRemoteLockedConnection(mockPeerDescriptor1)).toEqual(true)
|
|
148
|
+
|
|
149
|
+
//@ts-expect-error private field
|
|
150
|
+
await connectionManager1.gracefullyDisconnectAsync(mockPeerDescriptor2)
|
|
151
|
+
|
|
152
|
+
await waitForCondition(() =>
|
|
153
|
+
!connectionManager1.hasRemoteLockedConnection(mockPeerDescriptor2, 'testLock1')
|
|
154
|
+
&& !connectionManager1.hasLocalLockedConnection(mockPeerDescriptor2, 'testLock1')
|
|
155
|
+
)
|
|
156
|
+
await waitForCondition(() =>
|
|
157
|
+
!connectionManager2.hasRemoteLockedConnection(mockPeerDescriptor1, 'testLock1')
|
|
158
|
+
&& !connectionManager2.hasLocalLockedConnection(mockPeerDescriptor1, 'testLock1')
|
|
159
|
+
)
|
|
160
|
+
await waitForCondition(() => !connectionManager2.hasConnection(mockPeerDescriptor1))
|
|
161
|
+
await waitForCondition(() => !connectionManager1.hasConnection(mockPeerDescriptor2))
|
|
162
|
+
|
|
163
|
+
expect(connectionManager1.hasConnection(mockPeerDescriptor2)).toEqual(false)
|
|
164
|
+
expect(connectionManager2.hasConnection(mockPeerDescriptor1)).toEqual(false)
|
|
165
|
+
}, 10000)
|
|
166
|
+
})
|