@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
package/karma.config.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-require-imports */
|
|
2
|
+
const path = require('path')
|
|
3
|
+
const { createKarmaConfig, createWebpackConfig } = require('@streamr/browser-test-runner')
|
|
4
|
+
|
|
5
|
+
const TEST_PATHS = [
|
|
6
|
+
'test/unit/**/*.ts',
|
|
7
|
+
'./test/integration/**/!(DhtWith*|MigrateData*).ts/',
|
|
8
|
+
'test/end-to-end/**/*.ts'
|
|
9
|
+
]
|
|
10
|
+
|
|
11
|
+
const NodeWebRtcConnection = path.resolve(__dirname, 'src/connection/WebRTC/NodeWebRtcConnection.ts')
|
|
12
|
+
const BrowserWebRtcConnection = path.resolve(__dirname, 'src/connection/WebRTC/BrowserWebRtcConnection.ts')
|
|
13
|
+
|
|
14
|
+
module.exports = createKarmaConfig(TEST_PATHS, createWebpackConfig({
|
|
15
|
+
entry: './src/exports.ts',
|
|
16
|
+
libraryName: 'dht',
|
|
17
|
+
alias: {
|
|
18
|
+
[NodeWebRtcConnection]: BrowserWebRtcConnection
|
|
19
|
+
}
|
|
20
|
+
}))
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@streamr/dht",
|
|
3
|
+
"version": "0.0.1-tatum.0",
|
|
4
|
+
"description": "Streamr Network DHT",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/streamr-dev/network.git",
|
|
8
|
+
"directory": "packages/dht"
|
|
9
|
+
},
|
|
10
|
+
"main": "dist/src/exports.js",
|
|
11
|
+
"types": "dist/src/exports.d.ts",
|
|
12
|
+
"license": "STREAMR NETWORK OPEN SOURCE LICENSE",
|
|
13
|
+
"author": "Streamr Network AG <contact@streamr.network>",
|
|
14
|
+
"scripts": {
|
|
15
|
+
"generate-protoc-code": "./proto.sh",
|
|
16
|
+
"build": "tsc -b tsconfig.node.json",
|
|
17
|
+
"build-browser": "webpack --mode=development --progress",
|
|
18
|
+
"check": "tsc -p ./tsconfig.jest.json --noEmit",
|
|
19
|
+
"clean": "jest --clearCache || true; rm -rf dist *.tsbuildinfo node_modules/.cache || true",
|
|
20
|
+
"eslint": "eslint --cache --cache-location=node_modules/.cache/.eslintcache/ '*/**/*.{js,ts}'",
|
|
21
|
+
"prepublishOnly": "npm run clean && NODE_ENV=production tsc -b tsconfig.node.json",
|
|
22
|
+
"test": "jest test/unit test/integration test/end-to-end",
|
|
23
|
+
"test-browser": "karma start karma.config.js",
|
|
24
|
+
"test-unit": "jest test/unit",
|
|
25
|
+
"test-integration": "jest test/integration",
|
|
26
|
+
"test-end-to-end": "jest test/end-to-end",
|
|
27
|
+
"benchmark": "jest test/benchmark",
|
|
28
|
+
"prepare-kademlia-simulation": "cd test/data && node --max-old-space-size=8096 -- ../../../../node_modules/.bin/ts-node -P ../../tsconfig.node.json generateGroundTruthData.ts",
|
|
29
|
+
"run-kademlia-simulation": "ts-node --project tsconfig.node.json $NODE_DEBUG_OPTION --files test/benchmark/kademlia-simulation/KademliaSimulation.ts"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@protobuf-ts/runtime": "^2.8.2",
|
|
33
|
+
"@protobuf-ts/runtime-rpc": "^2.8.2",
|
|
34
|
+
"@streamr/proto-rpc": "0.0.1-tatum.0",
|
|
35
|
+
"@streamr/utils": "0.0.1-tatum.0",
|
|
36
|
+
"eventemitter3": "^5.0.0",
|
|
37
|
+
"heap": "^0.2.6",
|
|
38
|
+
"ipaddr.js": "^2.0.1",
|
|
39
|
+
"k-bucket": "^5.1.0",
|
|
40
|
+
"lodash": "^4.17.21",
|
|
41
|
+
"node-datachannel": "^0.4.3",
|
|
42
|
+
"sinon": "15.1.2",
|
|
43
|
+
"uuid": "^9.0.0",
|
|
44
|
+
"websocket": "^1.0.34"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@streamr/browser-test-runner": "^0.0.1",
|
|
48
|
+
"@streamr/test-utils": "0.0.1-tatum.0",
|
|
49
|
+
"@types/express": "^4.17.13",
|
|
50
|
+
"@types/heap": "^0.2.28",
|
|
51
|
+
"@types/k-bucket": "^5.0.1",
|
|
52
|
+
"@types/lodash": "^4.14.197",
|
|
53
|
+
"@types/sinon": "^10.0.15",
|
|
54
|
+
"@types/uuid": "^9.0.2",
|
|
55
|
+
"@types/websocket": "^1.0.3",
|
|
56
|
+
"express": "^4.17.1",
|
|
57
|
+
"patch-package": "^8.0.0",
|
|
58
|
+
"ts-node": "^10.9.1"
|
|
59
|
+
},
|
|
60
|
+
"optionalDependencies": {
|
|
61
|
+
"bufferutil": "^4.0.5",
|
|
62
|
+
"utf-8-validate": "^6.0.3"
|
|
63
|
+
}
|
|
64
|
+
}
|
package/proto.sh
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
mkdir -p ./src/proto
|
|
2
|
+
# npx protoc --ts_out ./src/proto --ts_opt server_generic,generate_dependencies --proto_path ../.. packages/trackerless-network/protos/NetworkRpc.proto
|
|
3
|
+
npx protoc --ts_out ./src/proto --ts_opt server_generic,generate_dependencies,long_type_number --proto_path ../.. packages/dht/protos/DhtRpc.proto
|
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
syntax = "proto3";
|
|
2
|
+
option optimize_for = CODE_SIZE;
|
|
3
|
+
|
|
4
|
+
package dht;
|
|
5
|
+
|
|
6
|
+
import "google/protobuf/empty.proto";
|
|
7
|
+
import "google/protobuf/any.proto";
|
|
8
|
+
import "google/protobuf/timestamp.proto";
|
|
9
|
+
import "packages/proto-rpc/protos/ProtoRpc.proto";
|
|
10
|
+
|
|
11
|
+
service DhtRpcService {
|
|
12
|
+
rpc getClosestPeers (ClosestPeersRequest) returns (ClosestPeersResponse);
|
|
13
|
+
rpc ping (PingRequest) returns (PingResponse);
|
|
14
|
+
rpc leaveNotice (LeaveNotice) returns (google.protobuf.Empty);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
service RoutingService {
|
|
18
|
+
rpc routeMessage (RouteMessageWrapper) returns (RouteMessageAck);
|
|
19
|
+
rpc forwardMessage (RouteMessageWrapper) returns (RouteMessageAck);
|
|
20
|
+
rpc findRecursively (RouteMessageWrapper) returns (RouteMessageAck);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
service StoreService {
|
|
24
|
+
rpc storeData (StoreDataRequest) returns (StoreDataResponse);
|
|
25
|
+
rpc migrateData (MigrateDataRequest) returns (MigrateDataResponse);
|
|
26
|
+
rpc deleteData (DeleteDataRequest) returns (DeleteDataResponse);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
service RecursiveFindSessionService {
|
|
30
|
+
rpc reportRecursiveFindResult(RecursiveFindReport) returns (google.protobuf.Empty);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
service WebSocketConnectorService {
|
|
34
|
+
rpc requestConnection (WebSocketConnectionRequest) returns (WebSocketConnectionResponse);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
service WebRtcConnectorService {
|
|
38
|
+
rpc requestConnection (WebRtcConnectionRequest) returns (google.protobuf.Empty);
|
|
39
|
+
rpc rtcOffer (RtcOffer) returns (google.protobuf.Empty);
|
|
40
|
+
rpc rtcAnswer (RtcAnswer) returns (google.protobuf.Empty);
|
|
41
|
+
rpc iceCandidate (IceCandidate) returns (google.protobuf.Empty);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
service ConnectionLocker {
|
|
45
|
+
rpc lockRequest (LockRequest) returns (LockResponse);
|
|
46
|
+
rpc unlockRequest (UnlockRequest) returns (google.protobuf.Empty);
|
|
47
|
+
rpc gracefulDisconnect (DisconnectNotice) returns (DisconnectNoticeResponse);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
service ExternalApiService {
|
|
51
|
+
rpc findData (FindDataRequest) returns (FindDataResponse);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Used inside RpcMessage
|
|
55
|
+
|
|
56
|
+
message StoreDataRequest {
|
|
57
|
+
bytes kademliaId = 1;
|
|
58
|
+
google.protobuf.Any data = 2;
|
|
59
|
+
uint32 ttl = 3;
|
|
60
|
+
google.protobuf.Timestamp storerTime = 4;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
message StoreDataResponse {
|
|
64
|
+
string error = 1;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
message MigrateDataRequest {
|
|
68
|
+
DataEntry dataEntry = 1;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
message MigrateDataResponse {
|
|
72
|
+
string error = 1;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
message DeleteDataRequest {
|
|
76
|
+
bytes kademliaId = 1;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
message DeleteDataResponse {
|
|
80
|
+
bool deleted = 1;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
message DataEntry {
|
|
84
|
+
PeerDescriptor storer = 1;
|
|
85
|
+
bytes kademliaId = 2;
|
|
86
|
+
google.protobuf.Any data = 3;
|
|
87
|
+
google.protobuf.Timestamp storedAt = 4;
|
|
88
|
+
uint32 ttl = 5; // milliseconds
|
|
89
|
+
bool stale = 6;
|
|
90
|
+
bool deleted = 7;
|
|
91
|
+
google.protobuf.Timestamp storerTime = 8;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
message ClosestPeersRequest {
|
|
95
|
+
bytes kademliaId = 1;
|
|
96
|
+
string requestId = 2;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
message ClosestPeersResponse {
|
|
100
|
+
repeated PeerDescriptor peers = 1;
|
|
101
|
+
string requestId = 2;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
enum FindMode {
|
|
105
|
+
NODE = 0;
|
|
106
|
+
DATA = 1;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
message RecursiveFindRequest {
|
|
110
|
+
string recursiveFindSessionId = 1;
|
|
111
|
+
FindMode findMode = 2;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
message RecursiveFindReport {
|
|
115
|
+
repeated PeerDescriptor nodes = 1;
|
|
116
|
+
repeated DataEntry dataEntries = 2;
|
|
117
|
+
optional bool noCloserNodesFound = 3;
|
|
118
|
+
repeated PeerDescriptor routingPath = 4;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
message PingRequest {
|
|
122
|
+
string requestId = 1;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
message PingResponse {
|
|
126
|
+
string requestId = 1;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
message LeaveNotice {
|
|
130
|
+
string serviceId = 1;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
message PeerDescriptor {
|
|
134
|
+
bytes kademliaId = 1;
|
|
135
|
+
NodeType type = 2;
|
|
136
|
+
ConnectivityMethod udp = 3;
|
|
137
|
+
ConnectivityMethod tcp = 4;
|
|
138
|
+
ConnectivityMethod websocket = 5;
|
|
139
|
+
optional bool openInternet = 6;
|
|
140
|
+
optional uint32 region = 7;
|
|
141
|
+
optional string nodeName = 8;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
message ConnectivityMethod {
|
|
145
|
+
uint32 port = 2;
|
|
146
|
+
string ip = 3;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
enum NodeType {
|
|
150
|
+
NODEJS = 0;
|
|
151
|
+
BROWSER = 1;
|
|
152
|
+
VIRTUAL = 3;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
message ConnectivityReportRequest {
|
|
156
|
+
uint32 port = 1;
|
|
157
|
+
string requestId = 2;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
message ConnectivityReportResponse {
|
|
161
|
+
string open_internet = 1;
|
|
162
|
+
string ip = 2;
|
|
163
|
+
string natType = 3;
|
|
164
|
+
string requestId = 4;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
enum RpcResponseError {
|
|
168
|
+
SERVER_TIMOUT = 0;
|
|
169
|
+
CLIENT_TIMEOUT = 1;
|
|
170
|
+
SERVER_ERROR = 2;
|
|
171
|
+
UNKNOWN_RPC_METHOD = 3;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
message RouteMessageWrapper {
|
|
175
|
+
PeerDescriptor sourcePeer = 1;
|
|
176
|
+
string requestId = 2;
|
|
177
|
+
PeerDescriptor destinationPeer = 3;
|
|
178
|
+
PeerDescriptor previousPeer = 4;
|
|
179
|
+
Message message = 5;
|
|
180
|
+
repeated PeerDescriptor reachableThrough = 6;
|
|
181
|
+
repeated PeerDescriptor routingPath = 7;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
message RouteMessageAck {
|
|
185
|
+
PeerDescriptor sourcePeer = 1;
|
|
186
|
+
string requestId = 2;
|
|
187
|
+
PeerDescriptor destinationPeer = 3;
|
|
188
|
+
string error = 4;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Correspond to the MessageType Enum
|
|
192
|
+
|
|
193
|
+
message ConnectivityRequest {
|
|
194
|
+
uint32 port = 1;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
message ConnectivityResponse {
|
|
198
|
+
bool open_internet = 1;
|
|
199
|
+
string ip = 2;
|
|
200
|
+
string natType = 3;
|
|
201
|
+
ConnectivityMethod websocket = 4;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
message HandshakeRequest {
|
|
205
|
+
bytes sourceId = 1;
|
|
206
|
+
string protocolVersion = 2;
|
|
207
|
+
PeerDescriptor peerDescriptor = 3;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
message HandshakeResponse {
|
|
211
|
+
bytes sourceId = 1;
|
|
212
|
+
string protocolVersion = 2;
|
|
213
|
+
PeerDescriptor peerDescriptor = 3;
|
|
214
|
+
optional string responseError = 4;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// Wraps all messages
|
|
218
|
+
|
|
219
|
+
enum MessageType {
|
|
220
|
+
CONNECTIVITY_REQUEST = 0;
|
|
221
|
+
CONNECTIVITY_RESPONSE = 1;
|
|
222
|
+
HANDSHAKE_REQUEST = 2;
|
|
223
|
+
HANDSHAKE_RESPONSE = 3;
|
|
224
|
+
RPC = 4;
|
|
225
|
+
RECURSIVE_FIND_REQUEST = 5;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
message Message {
|
|
229
|
+
string messageId = 1;
|
|
230
|
+
MessageType messageType = 2;
|
|
231
|
+
PeerDescriptor sourceDescriptor = 3;
|
|
232
|
+
PeerDescriptor targetDescriptor = 4;
|
|
233
|
+
string serviceId = 5; // id of the RPC service
|
|
234
|
+
oneof body {
|
|
235
|
+
ConnectivityRequest connectivityRequest = 6;
|
|
236
|
+
ConnectivityResponse connectivityResponse = 7;
|
|
237
|
+
HandshakeRequest handshakeRequest = 8;
|
|
238
|
+
HandshakeResponse handshakeResponse = 9;
|
|
239
|
+
protorpc.RpcMessage rpcMessage = 10;
|
|
240
|
+
RecursiveFindRequest RecursiveFindRequest = 11;
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// Connector Messages
|
|
245
|
+
|
|
246
|
+
// WebSocket
|
|
247
|
+
message WebSocketConnectionRequest {
|
|
248
|
+
PeerDescriptor requester = 1;
|
|
249
|
+
PeerDescriptor target = 2;
|
|
250
|
+
string ip = 3;
|
|
251
|
+
uint32 port = 4;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
message WebSocketConnectionResponse {
|
|
255
|
+
PeerDescriptor requester = 1;
|
|
256
|
+
PeerDescriptor target = 2;
|
|
257
|
+
bool accepted = 3;
|
|
258
|
+
optional string reason = 4;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// WebRTC
|
|
262
|
+
message WebRtcConnectionRequest {
|
|
263
|
+
PeerDescriptor requester = 1;
|
|
264
|
+
PeerDescriptor target = 2;
|
|
265
|
+
string connectionId = 3;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
message RtcOffer {
|
|
269
|
+
PeerDescriptor requester = 1;
|
|
270
|
+
PeerDescriptor target = 2;
|
|
271
|
+
string description = 3;
|
|
272
|
+
string connectionId = 4;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
message RtcAnswer {
|
|
276
|
+
PeerDescriptor requester = 1;
|
|
277
|
+
PeerDescriptor target = 2;
|
|
278
|
+
string description = 3;
|
|
279
|
+
string connectionId = 4;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
message IceCandidate {
|
|
283
|
+
string candidate = 1;
|
|
284
|
+
string mid = 2;
|
|
285
|
+
string connectionId = 3;
|
|
286
|
+
PeerDescriptor requester = 4;
|
|
287
|
+
PeerDescriptor target = 5;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
message LockRequest {
|
|
291
|
+
string protocolVersion = 1;
|
|
292
|
+
PeerDescriptor peerDescriptor = 2;
|
|
293
|
+
string serviceId = 3;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
message UnlockRequest {
|
|
297
|
+
string protocolVersion = 1;
|
|
298
|
+
PeerDescriptor peerDescriptor = 2;
|
|
299
|
+
string serviceId = 3;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
message LockResponse {
|
|
303
|
+
bool accepted = 1;
|
|
304
|
+
optional bool reason = 2;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
enum DisconnectMode {
|
|
308
|
+
NORMAL = 0;
|
|
309
|
+
LEAVING = 1;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
message DisconnectNotice {
|
|
313
|
+
string protocolVersion = 1;
|
|
314
|
+
PeerDescriptor peerDescriptor = 2;
|
|
315
|
+
DisconnectMode disconnecMode = 3;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
message DisconnectNoticeResponse {
|
|
319
|
+
string protocolVersion = 1;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
message FindDataRequest {
|
|
323
|
+
bytes kademliaId = 1;
|
|
324
|
+
PeerDescriptor requestor = 2;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
message FindDataResponse {
|
|
328
|
+
repeated DataEntry dataEntries = 1;
|
|
329
|
+
optional string error = 2;
|
|
330
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
|
|
2
|
+
syntax = "proto3";
|
|
3
|
+
option optimize_for = CODE_SIZE;
|
|
4
|
+
|
|
5
|
+
package tests;
|
|
6
|
+
|
|
7
|
+
import "google/protobuf/any.proto";
|
|
8
|
+
|
|
9
|
+
message TestMessage {
|
|
10
|
+
string messageId = 1;
|
|
11
|
+
google.protobuf.Any body = 2;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
message SomeMessage {
|
|
15
|
+
string juttu = 1;
|
|
16
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import EventEmitter from 'eventemitter3'
|
|
2
|
+
import { PeerDescriptor } from '../proto/packages/dht/protos/DhtRpc'
|
|
3
|
+
import { ConnectionID, ConnectionType, ConnectionEvents } from './IConnection'
|
|
4
|
+
|
|
5
|
+
export class Connection extends EventEmitter<ConnectionEvents> {
|
|
6
|
+
public connectionId: ConnectionID
|
|
7
|
+
public connectionType: ConnectionType
|
|
8
|
+
private peerDescriptor?: PeerDescriptor
|
|
9
|
+
|
|
10
|
+
constructor(connectionType: ConnectionType) {
|
|
11
|
+
super()
|
|
12
|
+
this.connectionId = new ConnectionID()
|
|
13
|
+
this.connectionType = connectionType
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
setPeerDescriptor(peerDescriptor: PeerDescriptor): void {
|
|
17
|
+
this.peerDescriptor = peerDescriptor
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
getPeerDescriptor(): PeerDescriptor | undefined {
|
|
21
|
+
return this.peerDescriptor
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// Connection locks are independent of the existence of connections
|
|
2
|
+
// that is why this class is needed
|
|
3
|
+
|
|
4
|
+
import { PeerIDKey } from '../helpers/PeerID'
|
|
5
|
+
|
|
6
|
+
type ServiceName = string
|
|
7
|
+
|
|
8
|
+
export class ConnectionLockHandler {
|
|
9
|
+
|
|
10
|
+
private localLocks: Map<PeerIDKey, Set<ServiceName>> = new Map()
|
|
11
|
+
private remoteLocks: Map<PeerIDKey, Set<ServiceName>> = new Map()
|
|
12
|
+
private weakLocks: Set<PeerIDKey> = new Set()
|
|
13
|
+
|
|
14
|
+
public getNumberOfLocalLockedConnections(): number {
|
|
15
|
+
return this.localLocks.size
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public getNumberOfRemoteLockedConnections(): number {
|
|
19
|
+
return this.remoteLocks.size
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public getNumberOfWeakLockedConnections(): number {
|
|
23
|
+
return this.weakLocks.size
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public isLocalLocked(id: PeerIDKey, serviceName?: ServiceName): boolean {
|
|
27
|
+
if (!serviceName) {
|
|
28
|
+
return this.localLocks.has(id)
|
|
29
|
+
} else {
|
|
30
|
+
return this.localLocks.has(id) && this.localLocks.get(id)!.has(serviceName)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public isRemoteLocked(id: PeerIDKey, serviceName?: ServiceName): boolean {
|
|
35
|
+
if (!serviceName) {
|
|
36
|
+
return this.remoteLocks.has(id)
|
|
37
|
+
} else {
|
|
38
|
+
if (this.remoteLocks.has(id) && this.remoteLocks.get(id)!.has(serviceName)) {
|
|
39
|
+
return true
|
|
40
|
+
} else {
|
|
41
|
+
return false
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public isWeakLocked(id: PeerIDKey): boolean {
|
|
47
|
+
return this.weakLocks.has(id)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public isLocked(id: PeerIDKey): boolean {
|
|
51
|
+
return (this.isLocalLocked(id) || this.isRemoteLocked(id) || this.isWeakLocked(id))
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public addLocalLocked(id: PeerIDKey, serviceName: ServiceName): void {
|
|
55
|
+
if (!this.localLocks.has(id)) {
|
|
56
|
+
this.localLocks.set(id, new Set())
|
|
57
|
+
}
|
|
58
|
+
this.localLocks.get(id)!.add(serviceName)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
public addRemoteLocked(id: PeerIDKey, serviceName: ServiceName): void {
|
|
62
|
+
if (!this.remoteLocks.has(id)) {
|
|
63
|
+
this.remoteLocks.set(id, new Set())
|
|
64
|
+
}
|
|
65
|
+
this.remoteLocks.get(id)!.add(serviceName)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public addWeakLocked(id: PeerIDKey): void {
|
|
69
|
+
this.weakLocks.add(id)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public removeLocalLocked(id: PeerIDKey, serviceName: ServiceName): void {
|
|
73
|
+
if (this.localLocks.has(id)) {
|
|
74
|
+
this.localLocks.get(id)?.delete(serviceName)
|
|
75
|
+
if (this.localLocks.get(id)?.size === 0) {
|
|
76
|
+
this.localLocks.delete(id)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
public removeRemoteLocked(id: PeerIDKey, serviceName: ServiceName): void {
|
|
82
|
+
if (this.remoteLocks.has(id)) {
|
|
83
|
+
this.remoteLocks.get(id)?.delete(serviceName)
|
|
84
|
+
if (this.remoteLocks.get(id)?.size === 0) {
|
|
85
|
+
this.remoteLocks.delete(id)
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
public removeWeakLocked(id: PeerIDKey): void {
|
|
91
|
+
this.weakLocks.delete(id)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
public clearAllLocks(id: PeerIDKey): void {
|
|
95
|
+
this.localLocks.delete(id)
|
|
96
|
+
this.remoteLocks.delete(id)
|
|
97
|
+
this.weakLocks.delete(id)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
public clear(): void {
|
|
101
|
+
this.localLocks.clear()
|
|
102
|
+
this.remoteLocks.clear()
|
|
103
|
+
this.weakLocks.clear()
|
|
104
|
+
}
|
|
105
|
+
}
|