@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,49 @@
|
|
|
1
|
+
import { UUID } from '../../src/helpers/UUID'
|
|
2
|
+
import { v4 } from 'uuid'
|
|
3
|
+
|
|
4
|
+
describe('UUID', () => {
|
|
5
|
+
|
|
6
|
+
it('generates unique IDs without constructor parameters', () => {
|
|
7
|
+
const ids: UUID[] = []
|
|
8
|
+
for (let i = 0; i < 100; i++) {
|
|
9
|
+
ids.push(new UUID())
|
|
10
|
+
}
|
|
11
|
+
for (let x = 0; x < ids.length; x++) {
|
|
12
|
+
const compare1 = ids[x]
|
|
13
|
+
for (let y = 0; y < ids.length; y++) {
|
|
14
|
+
if (x !== y) {
|
|
15
|
+
const compare2 = ids[y]
|
|
16
|
+
expect(compare1.toString() === compare2.toString()).toEqual(false)
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
it('Uses passed string uuid parameter as id', () => {
|
|
23
|
+
const stringId = v4()
|
|
24
|
+
const uuid = new UUID(stringId)
|
|
25
|
+
expect(uuid.toString() === stringId).toEqual(true)
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it('Throws if incorrect string is given as uuid string parameter', () => {
|
|
29
|
+
expect(()=> {new UUID('äå%')}).toThrow(TypeError)
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
it('Uses passed UUID as id', () => {
|
|
33
|
+
const uuid1 = new UUID()
|
|
34
|
+
const uuid2 = new UUID(uuid1)
|
|
35
|
+
expect(uuid1.toString() === uuid2.toString()).toEqual(true)
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
it('Uses passed UintArray uuid as id', () => {
|
|
39
|
+
const uuid1 = new UUID()
|
|
40
|
+
const uuid2 = new UUID(uuid1.value)
|
|
41
|
+
expect(uuid1.toString() === uuid2.toString()).toEqual(true)
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
it('Get value returns correct value', () => {
|
|
45
|
+
const uuid1 = new UUID()
|
|
46
|
+
const uuid2 = new UUID(uuid1.value)
|
|
47
|
+
expect(Buffer.compare(uuid1.value, uuid2.value) === 0)
|
|
48
|
+
})
|
|
49
|
+
})
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/* eslint-disable promise/no-nesting */
|
|
2
|
+
|
|
3
|
+
import { WebSocketServer } from '../../src/connection/WebSocket/WebSocketServer'
|
|
4
|
+
|
|
5
|
+
describe('WebSocketServer', () => {
|
|
6
|
+
|
|
7
|
+
it('starts and stops with host "127.0.0.1"', async () => {
|
|
8
|
+
const server = new WebSocketServer()
|
|
9
|
+
await server.start(19792, '127.0.0.1')
|
|
10
|
+
await server.stop()
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
it('starts and stops if no host given', async () => {
|
|
14
|
+
const server = new WebSocketServer()
|
|
15
|
+
await server.start(19792)
|
|
16
|
+
await server.stop()
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
it('throws if too big a port number is given', async () => {
|
|
20
|
+
const server1 = new WebSocketServer()
|
|
21
|
+
await server1.start(19792)
|
|
22
|
+
|
|
23
|
+
const server2 = new WebSocketServer()
|
|
24
|
+
|
|
25
|
+
await expect(server2.start(19792))
|
|
26
|
+
.rejects
|
|
27
|
+
.toThrow()
|
|
28
|
+
|
|
29
|
+
await server1.stop()
|
|
30
|
+
await server2.stop()
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it('throws if port is already in use', async () => {
|
|
34
|
+
const server = new WebSocketServer()
|
|
35
|
+
|
|
36
|
+
await expect(server.start(197923233))
|
|
37
|
+
.rejects
|
|
38
|
+
.toThrow()
|
|
39
|
+
|
|
40
|
+
await server.stop()
|
|
41
|
+
})
|
|
42
|
+
})
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { RecursiveFindResult, IRecursiveFinder } from '../../../src/dht/find/RecursiveFinder'
|
|
2
|
+
import { RouteMessageAck, RouteMessageWrapper } from '../../../src/proto/packages/dht/protos/DhtRpc'
|
|
3
|
+
|
|
4
|
+
export class MockRecursiveFinder implements IRecursiveFinder {
|
|
5
|
+
|
|
6
|
+
// eslint-disable-next-line class-methods-use-this
|
|
7
|
+
async startRecursiveFind(): Promise<RecursiveFindResult> {
|
|
8
|
+
return {
|
|
9
|
+
closestNodes: [],
|
|
10
|
+
dataEntries: []
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// eslint-disable-next-line class-methods-use-this
|
|
15
|
+
async findRecursively(_routedMessage: RouteMessageWrapper): Promise<RouteMessageAck> {
|
|
16
|
+
return RouteMessageAck.create()
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { IRouter } from '../../../src/dht/routing/Router'
|
|
2
|
+
import { RoutingSession, RoutingMode } from '../../../src/dht/routing/RoutingSession'
|
|
3
|
+
import { PeerDescriptor, Message, RouteMessageAck, RouteMessageWrapper } from '../../../src/proto/packages/dht/protos/DhtRpc'
|
|
4
|
+
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
5
|
+
|
|
6
|
+
export class MockRouter implements IRouter {
|
|
7
|
+
|
|
8
|
+
// eslint-disable-next-line class-methods-use-this
|
|
9
|
+
addRoutingSession(_session: RoutingSession): void {
|
|
10
|
+
return
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// eslint-disable-next-line class-methods-use-this
|
|
14
|
+
removeRoutingSession(_sessionId: string): void {
|
|
15
|
+
return
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// eslint-disable-next-line class-methods-use-this
|
|
19
|
+
addToDuplicateDetector(_messageId: string, _senderId: string, _message?: Message): void {
|
|
20
|
+
return
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// eslint-disable-next-line class-methods-use-this
|
|
24
|
+
checkDuplicate(_messageId: string): boolean {
|
|
25
|
+
return false
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// eslint-disable-next-line class-methods-use-this
|
|
29
|
+
doRouteMessage(_routedMessage: RouteMessageWrapper, _mode: RoutingMode): RouteMessageAck {
|
|
30
|
+
return RouteMessageAck.create()
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// eslint-disable-next-line class-methods-use-this
|
|
34
|
+
send(_msg: Message, _reachableThrough: PeerDescriptor[]): Promise<void> {
|
|
35
|
+
throw Error('Not implemented')
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// eslint-disable-next-line class-methods-use-this
|
|
39
|
+
stop(): void {
|
|
40
|
+
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// eslint-disable-next-line class-methods-use-this
|
|
44
|
+
async routeMessage(_routedMessage: RouteMessageWrapper, _context: ServerCallContext): Promise<RouteMessageAck> {
|
|
45
|
+
return RouteMessageAck.create()
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// eslint-disable-next-line class-methods-use-this
|
|
49
|
+
async forwardMessage(_forwardMessage: RouteMessageWrapper, _context: ServerCallContext): Promise<RouteMessageAck> {
|
|
50
|
+
return RouteMessageAck.create()
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ITransport, TransportEvents } from '../../../src/transport/ITransport'
|
|
2
|
+
import { EventEmitter } from 'eventemitter3'
|
|
3
|
+
import { Message, PeerDescriptor } from '../../../src/proto/packages/dht/protos/DhtRpc'
|
|
4
|
+
|
|
5
|
+
export class MockTransport extends EventEmitter<TransportEvents> implements ITransport {
|
|
6
|
+
|
|
7
|
+
// eslint-disable-next-line class-methods-use-this
|
|
8
|
+
async send(_msg: Message, _doNotConnect?: boolean): Promise<void> {
|
|
9
|
+
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// eslint-disable-next-line class-methods-use-this
|
|
13
|
+
getPeerDescriptor(): PeerDescriptor {
|
|
14
|
+
return PeerDescriptor.create()
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// eslint-disable-next-line class-methods-use-this
|
|
18
|
+
getAllConnectionPeerDescriptors(): PeerDescriptor[] {
|
|
19
|
+
return []
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// eslint-disable-next-line class-methods-use-this
|
|
23
|
+
stop(): void {
|
|
24
|
+
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
import { DhtNode } from '../../src/dht/DhtNode'
|
|
2
|
+
import {
|
|
3
|
+
ClosestPeersRequest,
|
|
4
|
+
ClosestPeersResponse,
|
|
5
|
+
LeaveNotice,
|
|
6
|
+
MigrateDataRequest,
|
|
7
|
+
MigrateDataResponse,
|
|
8
|
+
NodeType,
|
|
9
|
+
PeerDescriptor,
|
|
10
|
+
PingRequest,
|
|
11
|
+
PingResponse,
|
|
12
|
+
RouteMessageAck,
|
|
13
|
+
RouteMessageWrapper,
|
|
14
|
+
StoreDataRequest,
|
|
15
|
+
StoreDataResponse,
|
|
16
|
+
WebSocketConnectionRequest,
|
|
17
|
+
WebSocketConnectionResponse,
|
|
18
|
+
RecursiveFindRequest,
|
|
19
|
+
FindMode,
|
|
20
|
+
DeleteDataRequest,
|
|
21
|
+
DeleteDataResponse
|
|
22
|
+
} from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
23
|
+
import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
|
|
24
|
+
import { PeerID } from '../../src/helpers/PeerID'
|
|
25
|
+
import {
|
|
26
|
+
IDhtRpcService,
|
|
27
|
+
IRoutingService,
|
|
28
|
+
IStoreService,
|
|
29
|
+
IWebSocketConnectorService
|
|
30
|
+
} from '../../src/proto/packages/dht/protos/DhtRpc.server'
|
|
31
|
+
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
32
|
+
import { Simulator } from '../../src/connection/Simulator/Simulator'
|
|
33
|
+
import { ConnectionManager } from '../../src/connection/ConnectionManager'
|
|
34
|
+
import { v4 } from 'uuid'
|
|
35
|
+
import { getRandomRegion } from '../../src/connection/Simulator/pings'
|
|
36
|
+
import { Empty } from '../../src/proto/google/protobuf/empty'
|
|
37
|
+
import { Any } from '../../src/proto/google/protobuf/any'
|
|
38
|
+
import { waitForCondition } from '@streamr/utils'
|
|
39
|
+
import { RoutingRpcCommunicator } from '../../src/transport/RoutingRpcCommunicator'
|
|
40
|
+
|
|
41
|
+
export const generateId = (stringId: string): Uint8Array => {
|
|
42
|
+
return PeerID.fromString(stringId).value
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export const createMockConnectionDhtNode = async (stringId: string,
|
|
46
|
+
simulator: Simulator,
|
|
47
|
+
binaryId?: Uint8Array,
|
|
48
|
+
K?: number,
|
|
49
|
+
nodeName?: string,
|
|
50
|
+
maxConnections = 80,
|
|
51
|
+
dhtJoinTimeout = 45000
|
|
52
|
+
): Promise<DhtNode> => {
|
|
53
|
+
|
|
54
|
+
let id: PeerID
|
|
55
|
+
if (binaryId) {
|
|
56
|
+
id = PeerID.fromValue(binaryId)
|
|
57
|
+
} else {
|
|
58
|
+
id = PeerID.fromString(stringId)
|
|
59
|
+
}
|
|
60
|
+
const peerDescriptor: PeerDescriptor = {
|
|
61
|
+
kademliaId: id.value,
|
|
62
|
+
type: NodeType.NODEJS,
|
|
63
|
+
region: getRandomRegion(),
|
|
64
|
+
nodeName: nodeName ? nodeName : stringId
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const mockConnectionManager = new ConnectionManager({
|
|
68
|
+
ownPeerDescriptor: peerDescriptor,
|
|
69
|
+
simulator: simulator,
|
|
70
|
+
nodeName: nodeName ? nodeName : stringId
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
const node = new DhtNode({
|
|
74
|
+
peerDescriptor: peerDescriptor,
|
|
75
|
+
transportLayer: mockConnectionManager,
|
|
76
|
+
nodeName: nodeName,
|
|
77
|
+
numberOfNodesPerKBucket: K ? K : 8,
|
|
78
|
+
maxConnections: maxConnections,
|
|
79
|
+
dhtJoinTimeout
|
|
80
|
+
})
|
|
81
|
+
await node.start()
|
|
82
|
+
|
|
83
|
+
return node
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export const createMockConnectionLayer1Node = async (stringId: string, layer0Node: DhtNode, serviceId?: string): Promise<DhtNode> => {
|
|
87
|
+
const id = PeerID.fromString(stringId)
|
|
88
|
+
const descriptor: PeerDescriptor = {
|
|
89
|
+
kademliaId: id.value,
|
|
90
|
+
type: 0,
|
|
91
|
+
nodeName: stringId
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const node = new DhtNode({
|
|
95
|
+
peerDescriptor: descriptor, transportLayer: layer0Node,
|
|
96
|
+
serviceId: serviceId ? serviceId : 'layer1', numberOfNodesPerKBucket: 8, nodeName: stringId
|
|
97
|
+
})
|
|
98
|
+
await node.start()
|
|
99
|
+
return node
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export const createWrappedClosestPeersRequest = (
|
|
103
|
+
sourceDescriptor: PeerDescriptor,
|
|
104
|
+
_udestinationDescriptor: PeerDescriptor
|
|
105
|
+
): RpcMessage => {
|
|
106
|
+
|
|
107
|
+
const routedMessage: ClosestPeersRequest = {
|
|
108
|
+
kademliaId: sourceDescriptor.kademliaId,
|
|
109
|
+
requestId: v4()
|
|
110
|
+
}
|
|
111
|
+
const rpcWrapper: RpcMessage = {
|
|
112
|
+
body: Any.pack(routedMessage, ClosestPeersRequest),
|
|
113
|
+
header: {
|
|
114
|
+
method: 'closestPeersRequest',
|
|
115
|
+
request: 'request'
|
|
116
|
+
},
|
|
117
|
+
requestId: v4()
|
|
118
|
+
}
|
|
119
|
+
return rpcWrapper
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export const createRecursiveFindRequest = (
|
|
123
|
+
findMode: FindMode
|
|
124
|
+
): RecursiveFindRequest => {
|
|
125
|
+
const request: RecursiveFindRequest = {
|
|
126
|
+
findMode,
|
|
127
|
+
recursiveFindSessionId: v4()
|
|
128
|
+
}
|
|
129
|
+
return request
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
interface IDhtRpcWithError extends IDhtRpcService {
|
|
133
|
+
throwPingError: (request: PingRequest, _context: ServerCallContext) => Promise<PingResponse>
|
|
134
|
+
respondPingWithTimeout: (request: PingRequest, _context: ServerCallContext) => Promise<PingResponse>
|
|
135
|
+
throwGetClosestPeersError: (request: ClosestPeersRequest, _context: ServerCallContext) => Promise<ClosestPeersResponse>
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export const MockDhtRpc: IDhtRpcWithError = {
|
|
139
|
+
async getClosestPeers(_request: ClosestPeersRequest, _context: ServerCallContext): Promise<ClosestPeersResponse> {
|
|
140
|
+
const neighbors = getMockPeers()
|
|
141
|
+
const response: ClosestPeersResponse = {
|
|
142
|
+
peers: neighbors,
|
|
143
|
+
requestId: 'why am i still here'
|
|
144
|
+
}
|
|
145
|
+
return response
|
|
146
|
+
},
|
|
147
|
+
async ping(request: PingRequest, _context: ServerCallContext): Promise<PingResponse> {
|
|
148
|
+
const response: PingResponse = {
|
|
149
|
+
requestId: request.requestId
|
|
150
|
+
}
|
|
151
|
+
return response
|
|
152
|
+
},
|
|
153
|
+
async leaveNotice(_request: LeaveNotice, _context: ServerCallContext): Promise<Empty> {
|
|
154
|
+
return {}
|
|
155
|
+
},
|
|
156
|
+
async throwPingError(_urequest: PingRequest, _context: ServerCallContext): Promise<PingResponse> {
|
|
157
|
+
throw new Error()
|
|
158
|
+
},
|
|
159
|
+
respondPingWithTimeout(request: PingRequest, _context: ServerCallContext): Promise<PingResponse> {
|
|
160
|
+
return new Promise((resolve, _reject) => {
|
|
161
|
+
const response: PingResponse = {
|
|
162
|
+
requestId: request.requestId
|
|
163
|
+
}
|
|
164
|
+
setTimeout(() => resolve(response), 2000)
|
|
165
|
+
})
|
|
166
|
+
},
|
|
167
|
+
async throwGetClosestPeersError(_urequest: ClosestPeersRequest, _context: ServerCallContext): Promise<ClosestPeersResponse> {
|
|
168
|
+
throw new Error('Closest peers error')
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
interface IRouterServiceWithError extends IRoutingService {
|
|
173
|
+
throwRouteMessageError: (request: RouteMessageWrapper, _context: ServerCallContext) => Promise<RouteMessageAck>
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export const MockRoutingService: IRouterServiceWithError = {
|
|
177
|
+
async routeMessage(routed: RouteMessageWrapper, _context: ServerCallContext): Promise<RouteMessageAck> {
|
|
178
|
+
const response: RouteMessageAck = {
|
|
179
|
+
requestId: routed.requestId,
|
|
180
|
+
destinationPeer: routed.sourcePeer,
|
|
181
|
+
sourcePeer: routed.destinationPeer,
|
|
182
|
+
error: ''
|
|
183
|
+
}
|
|
184
|
+
return response
|
|
185
|
+
},
|
|
186
|
+
async findRecursively(routed: RouteMessageWrapper, _context: ServerCallContext): Promise<RouteMessageAck> {
|
|
187
|
+
const response: RouteMessageAck = {
|
|
188
|
+
requestId: routed.requestId,
|
|
189
|
+
destinationPeer: routed.sourcePeer,
|
|
190
|
+
sourcePeer: routed.destinationPeer,
|
|
191
|
+
error: ''
|
|
192
|
+
}
|
|
193
|
+
return response
|
|
194
|
+
},
|
|
195
|
+
async forwardMessage(routed: RouteMessageWrapper, _context: ServerCallContext): Promise<RouteMessageAck> {
|
|
196
|
+
const response: RouteMessageAck = {
|
|
197
|
+
requestId: routed.requestId,
|
|
198
|
+
destinationPeer: routed.sourcePeer,
|
|
199
|
+
sourcePeer: routed.destinationPeer,
|
|
200
|
+
error: ''
|
|
201
|
+
}
|
|
202
|
+
return response
|
|
203
|
+
},
|
|
204
|
+
async throwRouteMessageError(_urequest: RouteMessageWrapper, _context: ServerCallContext): Promise<RouteMessageAck> {
|
|
205
|
+
throw new Error()
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
interface IStoreServiceWithError extends IStoreService {
|
|
210
|
+
throwStoreDataError: (request: StoreDataRequest, _context: ServerCallContext) => Promise<StoreDataResponse>
|
|
211
|
+
storeDataErrorString: (request: StoreDataRequest, _context: ServerCallContext) => Promise<StoreDataResponse>
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export const MockStoreService: IStoreServiceWithError = {
|
|
215
|
+
async storeData(_request: StoreDataRequest, _context: ServerCallContext): Promise<StoreDataResponse> {
|
|
216
|
+
return {
|
|
217
|
+
error: ''
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
async throwStoreDataError(_request: StoreDataRequest, _context: ServerCallContext): Promise<StoreDataResponse> {
|
|
221
|
+
throw new Error('Mock')
|
|
222
|
+
},
|
|
223
|
+
async storeDataErrorString(_request: StoreDataRequest, _context: ServerCallContext): Promise<StoreDataResponse> {
|
|
224
|
+
return {
|
|
225
|
+
error: 'Mock'
|
|
226
|
+
}
|
|
227
|
+
},
|
|
228
|
+
async migrateData(_request: MigrateDataRequest, _context: ServerCallContext): Promise<MigrateDataResponse> {
|
|
229
|
+
return MigrateDataResponse.create()
|
|
230
|
+
},
|
|
231
|
+
async deleteData(_request: DeleteDataRequest, _context: ServerCallContext): Promise<DeleteDataResponse> {
|
|
232
|
+
return DeleteDataResponse.create()
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export const MockWebSocketConnectorRpc: IWebSocketConnectorService = {
|
|
237
|
+
async requestConnection(request: WebSocketConnectionRequest, _context: ServerCallContext): Promise<WebSocketConnectionResponse> {
|
|
238
|
+
const responseConnection: WebSocketConnectionResponse = {
|
|
239
|
+
target: request.target,
|
|
240
|
+
requester: request.requester,
|
|
241
|
+
accepted: true
|
|
242
|
+
}
|
|
243
|
+
return responseConnection
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export const getMockPeers = (): PeerDescriptor[] => {
|
|
248
|
+
const n1: PeerDescriptor = {
|
|
249
|
+
kademliaId: generateId('Neighbor1'),
|
|
250
|
+
type: NodeType.NODEJS,
|
|
251
|
+
}
|
|
252
|
+
const n2: PeerDescriptor = {
|
|
253
|
+
kademliaId: generateId('Neighbor2'),
|
|
254
|
+
type: NodeType.NODEJS,
|
|
255
|
+
}
|
|
256
|
+
const n3: PeerDescriptor = {
|
|
257
|
+
kademliaId: generateId('Neighbor3'),
|
|
258
|
+
type: NodeType.NODEJS,
|
|
259
|
+
}
|
|
260
|
+
const n4: PeerDescriptor = {
|
|
261
|
+
kademliaId: generateId('Neighbor1'),
|
|
262
|
+
type: NodeType.BROWSER,
|
|
263
|
+
}
|
|
264
|
+
return [
|
|
265
|
+
n1, n2, n3, n4
|
|
266
|
+
]
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export const waitConnectionManagersReadyForTesting = async (connectionManagers: ConnectionManager[], limit: number): Promise<void> => {
|
|
270
|
+
connectionManagers.forEach((connectionManager) => garbageCollectConnections(connectionManager, limit))
|
|
271
|
+
try {
|
|
272
|
+
await Promise.all(connectionManagers.map((connectionManager) => waitReadyForTesting(connectionManager, limit)))
|
|
273
|
+
} catch (_err) {
|
|
274
|
+
// did not successfully meet condition but network should be in a stable non-star state
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export const waitNodesReadyForTesting = async (nodes: DhtNode[], limit: number = 10000): Promise<void> => {
|
|
279
|
+
return waitConnectionManagersReadyForTesting(
|
|
280
|
+
nodes.map((node) => {
|
|
281
|
+
return (node.getTransport() as ConnectionManager)
|
|
282
|
+
}), limit)
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
function garbageCollectConnections(connectionManager: ConnectionManager, limit: number): void {
|
|
286
|
+
const LAST_USED_LIMIT = 100
|
|
287
|
+
connectionManager.garbageCollectConnections(limit, LAST_USED_LIMIT)
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
async function waitReadyForTesting(connectionManager: ConnectionManager, limit: number): Promise<void> {
|
|
291
|
+
const LAST_USED_LIMIT = 100
|
|
292
|
+
connectionManager.garbageCollectConnections(limit, LAST_USED_LIMIT)
|
|
293
|
+
try {
|
|
294
|
+
await waitForCondition(() => {
|
|
295
|
+
return (connectionManager.getNumberOfLocalLockedConnections() === 0 &&
|
|
296
|
+
connectionManager.getNumberOfRemoteLockedConnections() === 0 &&
|
|
297
|
+
connectionManager.getAllConnectionPeerDescriptors().length <= limit)
|
|
298
|
+
}, 20000)
|
|
299
|
+
} catch (err) {
|
|
300
|
+
if (connectionManager.getNumberOfLocalLockedConnections() > 0
|
|
301
|
+
&& connectionManager.getNumberOfRemoteLockedConnections() > 0) {
|
|
302
|
+
throw Error('Connections are still locked')
|
|
303
|
+
} else if (connectionManager.getAllConnectionPeerDescriptors().length > limit) {
|
|
304
|
+
throw Error(`ConnectionManager has more than ${limit}`)
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
export function createMockRoutingRpcCommunicator(): RoutingRpcCommunicator {
|
|
310
|
+
return new RoutingRpcCommunicator('router', async (_msg, _doNotConnect) => {})
|
|
311
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.browser.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "dist",
|
|
5
|
+
"rootDirs": ["src", "test"],
|
|
6
|
+
"noImplicitOverride": false
|
|
7
|
+
},
|
|
8
|
+
"include": [
|
|
9
|
+
"src/**/*",
|
|
10
|
+
"test/**/*"
|
|
11
|
+
],
|
|
12
|
+
"exclude": [
|
|
13
|
+
"src/connection/WebRTC/NodeWebRtcConnection.ts"
|
|
14
|
+
]
|
|
15
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.jest.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "dist",
|
|
5
|
+
"noImplicitOverride": false
|
|
6
|
+
},
|
|
7
|
+
"include": [
|
|
8
|
+
"src/**/*",
|
|
9
|
+
"test/**/*"
|
|
10
|
+
],
|
|
11
|
+
"exclude": [
|
|
12
|
+
"src/connection/WebRTC/BrowserWebRtcConnection.ts"
|
|
13
|
+
],
|
|
14
|
+
"references": [
|
|
15
|
+
{ "path": "../utils/tsconfig.node.json" },
|
|
16
|
+
{ "path": "../test-utils/tsconfig.node.json" },
|
|
17
|
+
{ "path": "../proto-rpc/tsconfig.node.json" }
|
|
18
|
+
]
|
|
19
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.node.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "dist",
|
|
5
|
+
"noImplicitOverride": false
|
|
6
|
+
},
|
|
7
|
+
"include": [
|
|
8
|
+
"src/**/*"
|
|
9
|
+
],
|
|
10
|
+
"exclude": [
|
|
11
|
+
"src/connection/WebRTC/BrowserWebRtcConnection.ts"
|
|
12
|
+
],
|
|
13
|
+
"references": [
|
|
14
|
+
{ "path": "../utils/tsconfig.node.json" },
|
|
15
|
+
{ "path": "../test-utils/tsconfig.node.json" },
|
|
16
|
+
{ "path": "../proto-rpc/tsconfig.node.json" }
|
|
17
|
+
]
|
|
18
|
+
}
|