@streamr/dht 100.0.0-pretestnet.6 → 100.0.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +90 -8
- package/dist/package.json +70 -0
- package/dist/src/connection/Connection.d.ts +1 -0
- package/dist/src/connection/Connection.js +10 -3
- package/dist/src/connection/Connection.js.map +1 -1
- package/dist/src/connection/ConnectionLockHandler.d.ts +14 -14
- package/dist/src/connection/ConnectionLockHandler.js +22 -16
- package/dist/src/connection/ConnectionLockHandler.js.map +1 -1
- package/dist/src/connection/ConnectionLockRpcLocal.d.ts +3 -3
- package/dist/src/connection/ConnectionLockRpcLocal.js +7 -6
- package/dist/src/connection/ConnectionLockRpcLocal.js.map +1 -1
- package/dist/src/connection/ConnectionLockRpcRemote.d.ts +4 -6
- package/dist/src/connection/ConnectionLockRpcRemote.js +10 -37
- package/dist/src/connection/ConnectionLockRpcRemote.js.map +1 -1
- package/dist/src/connection/ConnectionManager.d.ts +19 -20
- package/dist/src/connection/ConnectionManager.js +132 -117
- package/dist/src/connection/ConnectionManager.js.map +1 -1
- package/dist/src/connection/ConnectorFacade.d.ts +3 -2
- package/dist/src/connection/ConnectorFacade.js +10 -3
- package/dist/src/connection/ConnectorFacade.js.map +1 -1
- package/dist/src/connection/Handshaker.d.ts +3 -1
- package/dist/src/connection/Handshaker.js +18 -9
- package/dist/src/connection/Handshaker.js.map +1 -1
- package/dist/src/connection/IConnection.d.ts +2 -7
- package/dist/src/connection/IConnection.js +1 -8
- package/dist/src/connection/IConnection.js.map +1 -1
- package/dist/src/connection/ManagedConnection.d.ts +5 -7
- package/dist/src/connection/ManagedConnection.js +42 -26
- package/dist/src/connection/ManagedConnection.js.map +1 -1
- package/dist/src/connection/ManagedWebrtcConnection.js.map +1 -1
- package/dist/src/connection/connectivityChecker.d.ts +9 -0
- package/dist/src/connection/connectivityChecker.js +130 -0
- package/dist/src/connection/connectivityChecker.js.map +1 -0
- package/dist/src/connection/connectivityRequestHandler.d.ts +3 -0
- package/dist/src/connection/connectivityRequestHandler.js +101 -0
- package/dist/src/connection/connectivityRequestHandler.js.map +1 -0
- package/dist/src/connection/simulator/Simulator.d.ts +0 -3
- package/dist/src/connection/simulator/Simulator.js +34 -69
- package/dist/src/connection/simulator/Simulator.js.map +1 -1
- package/dist/src/connection/simulator/SimulatorConnection.js +27 -25
- package/dist/src/connection/simulator/SimulatorConnection.js.map +1 -1
- package/dist/src/connection/simulator/SimulatorConnector.js +16 -12
- package/dist/src/connection/simulator/SimulatorConnector.js.map +1 -1
- package/dist/src/connection/simulator/pings.js.map +1 -1
- package/dist/src/connection/webrtc/NodeWebrtcConnection.d.ts +2 -3
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js +40 -27
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnector.d.ts +0 -2
- package/dist/src/connection/webrtc/WebrtcConnector.js +24 -25
- package/dist/src/connection/webrtc/WebrtcConnector.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.d.ts +2 -2
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js +27 -20
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.d.ts +3 -6
- package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.js +2 -5
- package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.js.map +1 -1
- package/dist/src/connection/webrtc/iceServerAsString.js +1 -1
- package/dist/src/connection/webrtc/iceServerAsString.js.map +1 -1
- package/dist/src/connection/websocket/AutoCertifierClientFacade.d.ts +1 -2
- package/dist/src/connection/websocket/AutoCertifierClientFacade.js +6 -4
- package/dist/src/connection/websocket/AutoCertifierClientFacade.js.map +1 -1
- package/dist/src/connection/websocket/ClientWebsocket.d.ts +1 -0
- package/dist/src/connection/websocket/ClientWebsocket.js +14 -7
- package/dist/src/connection/websocket/ClientWebsocket.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnector.d.ts +3 -9
- package/dist/src/connection/websocket/WebsocketConnector.js +142 -74
- package/dist/src/connection/websocket/WebsocketConnector.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.d.ts +5 -3
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.js +9 -12
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.d.ts +4 -7
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.js +7 -44
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketServer.d.ts +1 -4
- package/dist/src/connection/websocket/WebsocketServer.js +49 -40
- package/dist/src/connection/websocket/WebsocketServer.js.map +1 -1
- package/dist/src/connection/websocket/{ServerWebsocket.d.ts → WebsocketServerConnection.d.ts} +8 -4
- package/dist/src/connection/websocket/WebsocketServerConnection.js +97 -0
- package/dist/src/connection/websocket/WebsocketServerConnection.js.map +1 -0
- package/dist/src/dht/DhtNode.d.ts +45 -49
- package/dist/src/dht/DhtNode.js +229 -317
- package/dist/src/dht/DhtNode.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcLocal.d.ts +10 -9
- package/dist/src/dht/DhtNodeRpcLocal.js +19 -11
- package/dist/src/dht/DhtNodeRpcLocal.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcRemote.d.ts +15 -10
- package/dist/src/dht/DhtNodeRpcRemote.js +38 -21
- package/dist/src/dht/DhtNodeRpcRemote.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcLocal.d.ts +7 -6
- package/dist/src/dht/ExternalApiRpcLocal.js +9 -13
- package/dist/src/dht/ExternalApiRpcLocal.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcRemote.d.ts +6 -5
- package/dist/src/dht/ExternalApiRpcRemote.js +10 -7
- package/dist/src/dht/ExternalApiRpcRemote.js.map +1 -1
- package/dist/src/dht/PeerManager.d.ts +61 -0
- package/dist/src/dht/PeerManager.js +288 -0
- package/dist/src/dht/PeerManager.js.map +1 -0
- package/dist/src/dht/contact/Contact.d.ts +2 -2
- package/dist/src/dht/contact/Contact.js +4 -3
- package/dist/src/dht/contact/Contact.js.map +1 -1
- package/dist/src/dht/contact/ContactList.d.ts +8 -8
- package/dist/src/dht/contact/ContactList.js +12 -7
- package/dist/src/dht/contact/ContactList.js.map +1 -1
- package/dist/src/dht/contact/RandomContactList.d.ts +4 -4
- package/dist/src/dht/contact/RandomContactList.js +13 -12
- package/dist/src/dht/contact/RandomContactList.js.map +1 -1
- package/dist/src/dht/contact/RingContactList.d.ts +31 -0
- package/dist/src/dht/contact/RingContactList.js +133 -0
- package/dist/src/dht/contact/RingContactList.js.map +1 -0
- package/dist/src/dht/contact/{Remote.d.ts → RpcRemote.d.ts} +8 -7
- package/dist/src/dht/contact/{Remote.js → RpcRemote.js} +16 -13
- package/dist/src/dht/contact/RpcRemote.js.map +1 -0
- package/dist/src/dht/contact/SortedContactList.d.ts +29 -15
- package/dist/src/dht/contact/SortedContactList.js +79 -42
- package/dist/src/dht/contact/SortedContactList.js.map +1 -1
- package/dist/src/dht/contact/ringIdentifiers.d.ts +16 -0
- package/dist/src/dht/contact/ringIdentifiers.js +54 -0
- package/dist/src/dht/contact/ringIdentifiers.js.map +1 -0
- package/dist/src/dht/discovery/DiscoverySession.d.ts +8 -18
- package/dist/src/dht/discovery/DiscoverySession.js +32 -48
- package/dist/src/dht/discovery/DiscoverySession.js.map +1 -1
- package/dist/src/dht/discovery/PeerDiscovery.d.ts +16 -12
- package/dist/src/dht/discovery/PeerDiscovery.js +82 -39
- package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -1
- package/dist/src/dht/discovery/RingDiscoverySession.d.ts +29 -0
- package/dist/src/dht/discovery/RingDiscoverySession.js +123 -0
- package/dist/src/dht/discovery/RingDiscoverySession.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.d.ts +36 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.js +166 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.d.ts +14 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.js +26 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.d.ts +6 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js +44 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.d.ts +44 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.js +187 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.d.ts +14 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js +20 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.d.ts +6 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.js +21 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.js.map +1 -0
- package/dist/src/dht/routing/DuplicateDetector.d.ts +2 -4
- package/dist/src/dht/routing/DuplicateDetector.js +10 -15
- package/dist/src/dht/routing/DuplicateDetector.js.map +1 -1
- package/dist/src/dht/routing/Router.d.ts +11 -27
- package/dist/src/dht/routing/Router.js +92 -58
- package/dist/src/dht/routing/Router.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcLocal.d.ts +3 -4
- package/dist/src/dht/routing/RouterRpcLocal.js +17 -16
- package/dist/src/dht/routing/RouterRpcLocal.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcRemote.d.ts +3 -3
- package/dist/src/dht/routing/RouterRpcRemote.js +29 -20
- package/dist/src/dht/routing/RouterRpcRemote.js.map +1 -1
- package/dist/src/dht/routing/RoutingSession.d.ts +29 -21
- package/dist/src/dht/routing/RoutingSession.js +93 -68
- package/dist/src/dht/routing/RoutingSession.js.map +1 -1
- package/dist/src/dht/routing/RoutingTablesCache.d.ts +24 -0
- package/dist/src/dht/routing/RoutingTablesCache.js +46 -0
- package/dist/src/dht/routing/RoutingTablesCache.js.map +1 -0
- package/dist/src/dht/routing/getPreviousPeer.js.map +1 -1
- package/dist/src/dht/store/LocalDataStore.d.ts +9 -14
- package/dist/src/dht/store/LocalDataStore.js +46 -72
- package/dist/src/dht/store/LocalDataStore.js.map +1 -1
- package/dist/src/dht/store/StoreManager.d.ts +33 -0
- package/dist/src/dht/store/StoreManager.js +182 -0
- package/dist/src/dht/store/StoreManager.js.map +1 -0
- package/dist/src/dht/store/StoreRpcLocal.d.ts +11 -41
- package/dist/src/dht/store/StoreRpcLocal.js +27 -234
- package/dist/src/dht/store/StoreRpcLocal.js.map +1 -1
- package/dist/src/dht/store/StoreRpcRemote.d.ts +6 -7
- package/dist/src/dht/store/StoreRpcRemote.js +10 -20
- package/dist/src/dht/store/StoreRpcRemote.js.map +1 -1
- package/dist/src/exports.d.ts +5 -3
- package/dist/src/exports.js +10 -8
- package/dist/src/exports.js.map +1 -1
- package/dist/src/helpers/AddressTools.js +2 -0
- package/dist/src/helpers/AddressTools.js.map +1 -1
- package/dist/src/helpers/Connectivity.js.map +1 -1
- package/dist/src/helpers/MapWithTtl.d.ts +14 -0
- package/dist/src/helpers/MapWithTtl.js +60 -0
- package/dist/src/helpers/MapWithTtl.js.map +1 -0
- package/dist/src/helpers/createPeerDescriptor.d.ts +3 -0
- package/dist/src/helpers/createPeerDescriptor.js +57 -0
- package/dist/src/helpers/createPeerDescriptor.js.map +1 -0
- package/dist/src/helpers/createPeerDescriptorSignaturePayload.d.ts +2 -0
- package/dist/src/helpers/createPeerDescriptorSignaturePayload.js +30 -0
- package/dist/src/helpers/createPeerDescriptorSignaturePayload.js.map +1 -0
- package/dist/src/helpers/debugHelpers.js.map +1 -1
- package/dist/src/helpers/errors.js +2 -0
- package/dist/src/helpers/errors.js.map +1 -1
- package/dist/src/helpers/offering.d.ts +4 -0
- package/dist/src/helpers/offering.js +18 -0
- package/dist/src/helpers/offering.js.map +1 -0
- package/dist/src/helpers/protoClasses.js +2 -3
- package/dist/src/helpers/protoClasses.js.map +1 -1
- package/dist/src/helpers/protoToString.js.map +1 -1
- package/dist/src/helpers/version.d.ts +6 -0
- package/dist/src/helpers/version.js +38 -0
- package/dist/src/helpers/version.js.map +1 -0
- package/dist/src/identifiers.d.ts +10 -0
- package/dist/src/identifiers.js +31 -0
- package/dist/src/identifiers.js.map +1 -0
- package/dist/src/proto/google/protobuf/any.js +8 -8
- package/dist/src/proto/google/protobuf/any.js.map +1 -1
- package/dist/src/proto/google/protobuf/empty.js +2 -4
- package/dist/src/proto/google/protobuf/empty.js.map +1 -1
- package/dist/src/proto/google/protobuf/timestamp.js +10 -10
- package/dist/src/proto/google/protobuf/timestamp.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +46 -49
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +63 -54
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +226 -232
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +146 -168
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +26 -29
- package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.js +1 -1
- package/dist/src/rpc-protocol/DhtCallContext.d.ts +2 -2
- package/dist/src/rpc-protocol/DhtCallContext.js +8 -0
- package/dist/src/rpc-protocol/DhtCallContext.js.map +1 -1
- package/dist/src/rpc-protocol/DhtRpcOptions.d.ts +2 -1
- package/dist/src/transport/ITransport.d.ts +10 -2
- package/dist/src/transport/ITransport.js +5 -0
- package/dist/src/transport/ITransport.js.map +1 -1
- package/dist/src/transport/ListeningRpcCommunicator.js +3 -1
- package/dist/src/transport/ListeningRpcCommunicator.js.map +1 -1
- package/dist/src/transport/RoutingRpcCommunicator.d.ts +4 -2
- package/dist/src/transport/RoutingRpcCommunicator.js +19 -12
- package/dist/src/transport/RoutingRpcCommunicator.js.map +1 -1
- package/jest.config.js +4 -1
- package/karma-setup.js +2 -0
- package/karma.config.js +13 -9
- package/package.json +16 -13
- package/protos/DhtRpc.proto +76 -76
- package/src/connection/Connection.ts +6 -1
- package/src/connection/ConnectionLockHandler.ts +30 -22
- package/src/connection/ConnectionLockRpcLocal.ts +7 -12
- package/src/connection/ConnectionLockRpcRemote.ts +9 -19
- package/src/connection/ConnectionManager.ts +132 -138
- package/src/connection/ConnectorFacade.ts +10 -9
- package/src/connection/Handshaker.ts +23 -11
- package/src/connection/IConnection.ts +2 -8
- package/src/connection/ManagedConnection.ts +34 -35
- package/src/connection/connectivityChecker.ts +109 -0
- package/src/connection/connectivityRequestHandler.ts +103 -0
- package/src/connection/simulator/Simulator.ts +6 -37
- package/src/connection/simulator/SimulatorConnection.ts +23 -25
- package/src/connection/simulator/SimulatorConnector.ts +11 -11
- package/src/connection/webrtc/BrowserWebrtcConnection.ts +17 -25
- package/src/connection/webrtc/NodeWebrtcConnection.ts +24 -26
- package/src/connection/webrtc/WebrtcConnector.ts +18 -29
- package/src/connection/webrtc/WebrtcConnectorRpcLocal.ts +29 -24
- package/src/connection/webrtc/WebrtcConnectorRpcRemote.ts +4 -14
- package/src/connection/webrtc/iceServerAsString.ts +1 -1
- package/src/connection/websocket/AutoCertifierClientFacade.ts +4 -6
- package/src/connection/websocket/ClientWebsocket.ts +10 -4
- package/src/connection/websocket/WebsocketConnector.ts +120 -97
- package/src/connection/websocket/WebsocketConnectorRpcLocal.ts +13 -15
- package/src/connection/websocket/WebsocketConnectorRpcRemote.ts +7 -27
- package/src/connection/websocket/WebsocketServer.ts +50 -53
- package/src/connection/websocket/WebsocketServerConnection.ts +104 -0
- package/src/dht/DhtNode.ts +289 -410
- package/src/dht/DhtNodeRpcLocal.ts +25 -17
- package/src/dht/DhtNodeRpcRemote.ts +43 -27
- package/src/dht/ExternalApiRpcLocal.ts +30 -17
- package/src/dht/ExternalApiRpcRemote.ts +14 -11
- package/src/dht/PeerManager.ts +339 -0
- package/src/dht/contact/Contact.ts +4 -4
- package/src/dht/contact/ContactList.ts +11 -10
- package/src/dht/contact/RandomContactList.ts +15 -15
- package/src/dht/contact/RingContactList.ts +151 -0
- package/src/dht/contact/{Remote.ts → RpcRemote.ts} +16 -19
- package/src/dht/contact/SortedContactList.ts +120 -72
- package/src/dht/contact/ringIdentifiers.ts +62 -0
- package/src/dht/discovery/DiscoverySession.ts +36 -61
- package/src/dht/discovery/PeerDiscovery.ts +98 -43
- package/src/dht/discovery/RingDiscoverySession.ts +160 -0
- package/src/dht/recursive-operation/RecursiveOperationManager.ts +246 -0
- package/src/dht/recursive-operation/RecursiveOperationRpcLocal.ts +34 -0
- package/src/dht/recursive-operation/RecursiveOperationRpcRemote.ts +43 -0
- package/src/dht/recursive-operation/RecursiveOperationSession.ts +232 -0
- package/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.ts +35 -0
- package/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.ts +30 -0
- package/src/dht/routing/DuplicateDetector.ts +9 -21
- package/src/dht/routing/Router.ts +95 -92
- package/src/dht/routing/RouterRpcLocal.ts +16 -18
- package/src/dht/routing/RouterRpcRemote.ts +26 -24
- package/src/dht/routing/RoutingSession.ts +119 -98
- package/src/dht/routing/RoutingTablesCache.ts +58 -0
- package/src/dht/routing/getPreviousPeer.ts +1 -1
- package/src/dht/store/LocalDataStore.ts +47 -77
- package/src/dht/store/StoreManager.ts +209 -0
- package/src/dht/store/StoreRpcLocal.ts +39 -308
- package/src/dht/store/StoreRpcRemote.ts +13 -31
- package/src/exports.ts +13 -3
- package/src/helpers/AddressTools.ts +2 -0
- package/src/helpers/MapWithTtl.ts +71 -0
- package/src/helpers/createPeerDescriptor.ts +57 -0
- package/src/helpers/createPeerDescriptorSignaturePayload.ts +28 -0
- package/src/helpers/offering.ts +15 -0
- package/src/helpers/protoClasses.ts +4 -6
- package/src/helpers/version.ts +32 -0
- package/src/identifiers.ts +29 -0
- package/src/proto/google/protobuf/any.ts +4 -4
- package/src/proto/google/protobuf/empty.ts +2 -4
- package/src/proto/google/protobuf/timestamp.ts +4 -4
- package/src/proto/packages/dht/protos/DhtRpc.client.ts +65 -68
- package/src/proto/packages/dht/protos/DhtRpc.server.ts +27 -30
- package/src/proto/packages/dht/protos/DhtRpc.ts +297 -313
- package/src/proto/packages/proto-rpc/protos/ProtoRpc.ts +1 -1
- package/src/rpc-protocol/DhtCallContext.ts +2 -2
- package/src/rpc-protocol/DhtRpcOptions.ts +2 -1
- package/src/transport/ITransport.ts +11 -2
- package/src/transport/ListeningRpcCommunicator.ts +1 -1
- package/src/transport/RoutingRpcCommunicator.ts +21 -14
- package/test/RandomGraphSimulation.ts +3 -2
- package/test/benchmark/Find.test.ts +13 -28
- package/test/benchmark/KademliaCorrectness.test.ts +24 -28
- package/test/benchmark/RingCorrectness.test.ts +157 -0
- package/test/benchmark/SortedContactListBenchmark.test.ts +151 -0
- package/test/benchmark/WebsocketServerMemoryLeak.test.ts +41 -0
- package/test/benchmark/hybrid-network-simulation/RingContactList.test.ts +72 -0
- package/test/benchmark/kademlia-simulation/Contact.ts +9 -9
- package/test/benchmark/kademlia-simulation/KademliaSimulation.ts +11 -11
- package/test/benchmark/kademlia-simulation/SimulationNode.ts +29 -25
- package/test/data/generateGroundTruthData.ts +7 -6
- package/test/end-to-end/Layer0-Layer1.test.ts +11 -15
- package/test/end-to-end/Layer0.test.ts +19 -22
- package/test/end-to-end/Layer0MixedConnectionTypes.test.ts +19 -21
- package/test/end-to-end/Layer0Webrtc-Layer1.test.ts +26 -28
- package/test/end-to-end/Layer0Webrtc.test.ts +19 -19
- package/test/end-to-end/Layer1-Scale-WebSocket.test.ts +10 -18
- package/test/end-to-end/Layer1-Scale-Webrtc.test.ts +8 -15
- package/test/end-to-end/RecoveryFromFailedAutoCertification.test.ts +2 -2
- package/test/end-to-end/WebsocketConnectionRequest.test.ts +8 -9
- package/test/end-to-end/memory-leak.test.ts +19 -24
- package/test/integration/ConnectionLocking.test.ts +66 -60
- package/test/integration/ConnectionManager.test.ts +43 -63
- package/test/integration/ConnectivityChecking.test.ts +52 -0
- package/test/integration/DhtJoinPeerDiscovery.test.ts +8 -12
- package/test/integration/DhtNodeExternalAPI.test.ts +17 -21
- package/test/integration/DhtNodeRpcRemote.test.ts +19 -26
- package/test/integration/DhtRpc.test.ts +20 -24
- package/test/integration/Find.test.ts +10 -12
- package/test/integration/Layer1-scale.test.ts +25 -37
- package/test/integration/Mock-Layer1-Layer0.test.ts +39 -59
- package/test/integration/MultipleEntryPointJoining.test.ts +14 -14
- package/test/integration/ReplicateData.test.ts +106 -0
- package/test/integration/RouteMessage.test.ts +42 -68
- package/test/integration/RouterRpcRemote.test.ts +19 -24
- package/test/integration/ScaleDownDht.test.ts +14 -12
- package/test/integration/SimultaneousConnections.test.ts +112 -111
- package/test/integration/Store.test.ts +43 -27
- package/test/integration/StoreAndDelete.test.ts +36 -48
- package/test/integration/StoreOnDhtWithThreeNodes.test.ts +59 -0
- package/test/integration/StoreOnDhtWithTwoNodes.test.ts +17 -37
- package/test/integration/StoreRpcRemote.test.ts +20 -32
- package/test/integration/WebrtcConnectionManagement.test.ts +39 -25
- package/test/integration/WebrtcConnectorRpc.test.ts +6 -11
- package/test/integration/WebsocketConnectionManagement.test.ts +87 -22
- package/test/integration/WebsocketConnectorRpc.test.ts +14 -24
- package/test/integration/{RpcErrors.test.ts → rpc-connections-over-webrpc.test.ts} +15 -26
- package/test/unit/AddressTools.test.ts +4 -0
- package/test/unit/ConnectivityHelpers.test.ts +9 -17
- package/test/unit/DuplicateDetector.test.ts +8 -5
- package/test/unit/LocalDataStore.test.ts +78 -75
- package/test/unit/PeerManager.test.ts +33 -0
- package/test/unit/RandomContactList.test.ts +12 -9
- package/test/unit/RecursiveOperationManager.test.ts +157 -0
- package/test/unit/RecursiveOperationSession.test.ts +68 -0
- package/test/unit/Router.test.ts +52 -35
- package/test/unit/RoutingSession.test.ts +79 -0
- package/test/unit/SortedContactList.test.ts +61 -30
- package/test/unit/StoreManager.test.ts +138 -0
- package/test/unit/WebsocketConnector.test.ts +27 -35
- package/test/unit/connectivityRequestHandler.test.ts +104 -0
- package/test/unit/createPeerDescriptor.test.ts +69 -0
- package/test/unit/customMatchers.test.ts +16 -0
- package/test/unit/version.test.ts +18 -0
- package/test/utils/FakeTransport.ts +47 -0
- package/test/utils/customMatchers.ts +71 -0
- package/test/utils/mock/MockRpcCommunicator.ts +7 -0
- package/test/utils/mock/Router.ts +13 -3
- package/test/utils/mock/Transport.ts +1 -1
- package/test/utils/mock/mockDataEntry.ts +38 -0
- package/test/utils/utils.ts +104 -107
- package/tsconfig.browser.json +2 -1
- package/tsconfig.jest.json +4 -2
- package/tsconfig.node.json +4 -2
- package/dist/src/connection/ConnectivityChecker.d.ts +0 -17
- package/dist/src/connection/ConnectivityChecker.js +0 -208
- package/dist/src/connection/ConnectivityChecker.js.map +0 -1
- package/dist/src/connection/websocket/ServerWebsocket.js +0 -100
- package/dist/src/connection/websocket/ServerWebsocket.js.map +0 -1
- package/dist/src/dht/contact/Remote.js.map +0 -1
- package/dist/src/dht/find/FindRpcLocal.d.ts +0 -14
- package/dist/src/dht/find/FindRpcLocal.js +0 -25
- package/dist/src/dht/find/FindRpcLocal.js.map +0 -1
- package/dist/src/dht/find/FindSession.d.ts +0 -44
- package/dist/src/dht/find/FindSession.js +0 -145
- package/dist/src/dht/find/FindSession.js.map +0 -1
- package/dist/src/dht/find/FindSessionRpcLocal.d.ts +0 -12
- package/dist/src/dht/find/FindSessionRpcLocal.js +0 -17
- package/dist/src/dht/find/FindSessionRpcLocal.js.map +0 -1
- package/dist/src/dht/find/FindSessionRpcRemote.d.ts +0 -6
- package/dist/src/dht/find/FindSessionRpcRemote.js +0 -21
- package/dist/src/dht/find/FindSessionRpcRemote.js.map +0 -1
- package/dist/src/dht/find/Finder.d.ts +0 -49
- package/dist/src/dht/find/Finder.js +0 -184
- package/dist/src/dht/find/Finder.js.map +0 -1
- package/dist/src/dht/routing/FindRpcRemote.d.ts +0 -6
- package/dist/src/dht/routing/FindRpcRemote.js +0 -41
- package/dist/src/dht/routing/FindRpcRemote.js.map +0 -1
- package/dist/src/helpers/PeerID.d.ts +0 -24
- package/dist/src/helpers/PeerID.js +0 -78
- package/dist/src/helpers/PeerID.js.map +0 -1
- package/dist/src/helpers/UUID.d.ts +0 -8
- package/dist/src/helpers/UUID.js +0 -36
- package/dist/src/helpers/UUID.js.map +0 -1
- package/dist/src/helpers/kademliaId.d.ts +0 -1
- package/dist/src/helpers/kademliaId.js +0 -14
- package/dist/src/helpers/kademliaId.js.map +0 -1
- package/dist/src/helpers/peerIdFromPeerDescriptor.d.ts +0 -6
- package/dist/src/helpers/peerIdFromPeerDescriptor.js +0 -23
- package/dist/src/helpers/peerIdFromPeerDescriptor.js.map +0 -1
- package/src/connection/ConnectivityChecker.ts +0 -199
- package/src/connection/websocket/ServerWebsocket.ts +0 -114
- package/src/dht/find/FindRpcLocal.ts +0 -35
- package/src/dht/find/FindSession.ts +0 -178
- package/src/dht/find/FindSessionRpcLocal.ts +0 -25
- package/src/dht/find/FindSessionRpcRemote.ts +0 -30
- package/src/dht/find/Finder.ts +0 -275
- package/src/dht/routing/FindRpcRemote.ts +0 -40
- package/src/helpers/PeerID.ts +0 -88
- package/src/helpers/UUID.ts +0 -35
- package/src/helpers/kademliaId.ts +0 -8
- package/src/helpers/peerIdFromPeerDescriptor.ts +0 -20
- package/test/integration/MigrateData.test.ts +0 -204
- package/test/unit/Finder.test.ts +0 -110
- package/test/unit/PeerID.test.ts +0 -22
- package/test/unit/UUID.test.ts +0 -55
package/README.md
CHANGED
|
@@ -1,17 +1,99 @@
|
|
|
1
|
-
# @streamr/dht
|
|
1
|
+
# @streamr/dht
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A connectionful Kademlia based P2P distributed hash table (DHT). Implements an in-memory key-value data store where multiple creators of data store values behind a single key. The library is entirely browser compatible.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
All communication between peers utilizes [protobuf](https://protobuf.dev/), transported with the help of the custom `@streamr/proto-rpc` library.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
Connections in the DHT are established using WebSocket or WebRTC connections. The nodes will decide internally based on peers' connectivity information which connection types to use.
|
|
8
|
+
|
|
9
|
+
The DHT also provides an interface for sending messages from peer to peer with the `DhtNode#send` function. The sent message is routed over the network to the target node.
|
|
10
|
+
|
|
11
|
+
## Running a node
|
|
12
|
+
|
|
13
|
+
Running a bare DhtNode in the Streamr Network is heavily discouraged as it requires advanced configuration. However, if you do wish to run a node here are some recommended configurations.
|
|
14
|
+
|
|
15
|
+
(the following values are examples. For working production or test values check the @streamr/sdk default network configuration)
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
const DhtNode = new DhtNode({
|
|
19
|
+
// Add a list of known entry points to the network
|
|
20
|
+
entryPoints: [{
|
|
21
|
+
kademliaId: new Uint8Array([1, 2, 3])
|
|
22
|
+
}],
|
|
23
|
+
// a list of STUN and TURN servers. Critically important when opening webrtc conenctions behind NATs.
|
|
24
|
+
iceServers: [{
|
|
25
|
+
url: "stun.l.google.com",
|
|
26
|
+
port: 19302
|
|
27
|
+
}],
|
|
28
|
+
// A range of ports that the node will attempt to start a WebSocket server in. If you wish to use an exact port give equal values to min and max. If left unspecified the node will start without a server.
|
|
29
|
+
websocketPortRange: {
|
|
30
|
+
min: 30000,
|
|
31
|
+
max: 30500
|
|
32
|
+
},
|
|
33
|
+
...
|
|
34
|
+
})
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## WebSocket Server TLS configuration
|
|
38
|
+
|
|
39
|
+
Setting up TLS is important if you wish to allow nodes running in the browser to connect to your node over websocket. If left unconfigured webrtc connections will be used in such cases.
|
|
40
|
+
|
|
41
|
+
There two ways to configure TLS for a DhtNode's WS server.
|
|
42
|
+
|
|
43
|
+
### Auto-certification
|
|
44
|
+
|
|
45
|
+
When starting a node configure it to automatically fetch TLS certificates for a randomly generated domain name as such:
|
|
46
|
+
|
|
47
|
+
```js
|
|
48
|
+
const DhtNode = new DhtNode({
|
|
49
|
+
...
|
|
50
|
+
websocketServerEnableTls: true,
|
|
51
|
+
autoCertifierUrl: 'http://example-autocertifier-url:30000/',
|
|
52
|
+
autoCertifierConfigFile: '~/.streamr/certificate.json'
|
|
53
|
+
...
|
|
54
|
+
})
|
|
10
55
|
```
|
|
11
56
|
|
|
12
|
-
|
|
57
|
+
### Custom TLS configuration
|
|
58
|
+
|
|
59
|
+
If you have your own domain name and/or TLS certificates you can configure the node to use them as follows:
|
|
60
|
+
|
|
61
|
+
```js
|
|
62
|
+
const DhtNode = new DhtNode({
|
|
63
|
+
tlsCertificate: {
|
|
64
|
+
certFileName: 'path/to/file'
|
|
65
|
+
privateKeyFileName: 'path/to/file'
|
|
66
|
+
},
|
|
67
|
+
websocketHost: 'custom-domain.com' // If using a custom domain name give it here to ensure that connectivity checking is correctly pointed to the server
|
|
68
|
+
})
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Setting up a custom DHT network
|
|
72
|
+
|
|
73
|
+
To setup a custom DHT network outside the Streamr Networks Mumbai or Polygon environments, you simply need to set up one or multiple entry point DhtNodes to the network and point all newly joining DhtNodes to them. It is also a good idea to configure the entry points to know each other. This makes it possible to restart them without causing network partitioning.
|
|
74
|
+
|
|
75
|
+
## Development
|
|
76
|
+
|
|
77
|
+
### local testing and develpment setup
|
|
78
|
+
|
|
79
|
+
When running a node for testing or develpment a few configurations are important.
|
|
80
|
+
|
|
81
|
+
```js
|
|
82
|
+
const DhtNode = new DhtNode({
|
|
83
|
+
entryPoints: [], // Point this to your local dev entry point!
|
|
84
|
+
iceServers: [], // Keep empty to ensure webrtc connections are local
|
|
85
|
+
webrtcAllowPrivateAddresses: true, // Make sure that the value is true in local develpment
|
|
86
|
+
websocketServerEnableTls: false, // Keep as false to ensure that auto-certification is not attempted
|
|
87
|
+
websocketHost: '127.0.0.1', // Use 127.0.0.1 instead of localhost during develpment!
|
|
88
|
+
})
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Generating Protobuf code
|
|
92
|
+
|
|
93
|
+
After making changes to the protobuf definitions you should regenerate the protobuf code with the following command.
|
|
94
|
+
|
|
13
95
|
```bash
|
|
14
|
-
npm run
|
|
96
|
+
npm run generate-protoc-code
|
|
15
97
|
# Or
|
|
16
98
|
./proto.sh
|
|
17
99
|
```
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@streamr/dht",
|
|
3
|
+
"version": "100.0.0-rc.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
|
+
"test": "npm run test-unit && npm run test-integration && npm run test-end-to-end",
|
|
22
|
+
"test-browser": "karma start karma.config.js",
|
|
23
|
+
"test-unit": "jest test/unit",
|
|
24
|
+
"test-integration": "jest --bail test/integration",
|
|
25
|
+
"test-end-to-end": "jest --bail test/end-to-end",
|
|
26
|
+
"benchmark": "jest test/benchmark",
|
|
27
|
+
"prepare-kademlia-simulation": "cd test/data && node --max-old-space-size=8096 -- ../../../../node_modules/.bin/ts-node -P ../../tsconfig.node.json generateGroundTruthData.ts",
|
|
28
|
+
"run-kademlia-simulation": "ts-node --project tsconfig.node.json $NODE_DEBUG_OPTION --files test/benchmark/kademlia-simulation/KademliaSimulation.ts"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@js-sdsl/ordered-map": "^4.4.2",
|
|
32
|
+
"@protobuf-ts/runtime": "^2.8.2",
|
|
33
|
+
"@protobuf-ts/runtime-rpc": "^2.8.2",
|
|
34
|
+
"@streamr/autocertifier-client": "100.0.0-rc.0",
|
|
35
|
+
"@streamr/cdn-location": "100.0.0-rc.0",
|
|
36
|
+
"@streamr/proto-rpc": "100.0.0-rc.0",
|
|
37
|
+
"@streamr/utils": "100.0.0-rc.0",
|
|
38
|
+
"eventemitter3": "^5.0.0",
|
|
39
|
+
"heap": "^0.2.6",
|
|
40
|
+
"ipaddr.js": "^2.0.1",
|
|
41
|
+
"k-bucket": "^5.1.0",
|
|
42
|
+
"lodash": "^4.17.21",
|
|
43
|
+
"lru-cache": "10.2.0",
|
|
44
|
+
"node-datachannel": "^0.4.3",
|
|
45
|
+
"querystring": "0.2.1",
|
|
46
|
+
"uuid": "^9.0.1",
|
|
47
|
+
"websocket": "^1.0.34",
|
|
48
|
+
"ws": "^8.16.0"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@streamr/browser-test-runner": "^0.0.1",
|
|
52
|
+
"@streamr/test-utils": "100.0.0-rc.0",
|
|
53
|
+
"@types/express": "^4.17.21",
|
|
54
|
+
"@types/heap": "^0.2.34",
|
|
55
|
+
"@types/k-bucket": "^5.0.1",
|
|
56
|
+
"@types/lodash": "^4.14.202",
|
|
57
|
+
"@types/uuid": "^9.0.8",
|
|
58
|
+
"@types/websocket": "^1.0.10",
|
|
59
|
+
"@types/ws": "^8.5.10",
|
|
60
|
+
"express": "^4.17.1",
|
|
61
|
+
"jest-leak-detector": "^27.3.1",
|
|
62
|
+
"patch-package": "^8.0.0",
|
|
63
|
+
"ts-essentials": "^9.4.1",
|
|
64
|
+
"ts-node": "^10.9.2"
|
|
65
|
+
},
|
|
66
|
+
"optionalDependencies": {
|
|
67
|
+
"bufferutil": "^4.0.8",
|
|
68
|
+
"utf-8-validate": "^6.0.3"
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -3,13 +3,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Connection = void 0;
|
|
6
|
+
exports.createRandomConnectionId = exports.Connection = void 0;
|
|
7
7
|
const eventemitter3_1 = __importDefault(require("eventemitter3"));
|
|
8
|
-
const
|
|
8
|
+
const uuid_1 = require("uuid");
|
|
9
9
|
class Connection extends eventemitter3_1.default {
|
|
10
|
+
connectionId;
|
|
11
|
+
connectionType;
|
|
12
|
+
peerDescriptor;
|
|
10
13
|
constructor(connectionType) {
|
|
11
14
|
super();
|
|
12
|
-
this.connectionId =
|
|
15
|
+
this.connectionId = (0, exports.createRandomConnectionId)();
|
|
13
16
|
this.connectionType = connectionType;
|
|
14
17
|
}
|
|
15
18
|
setPeerDescriptor(peerDescriptor) {
|
|
@@ -20,4 +23,8 @@ class Connection extends eventemitter3_1.default {
|
|
|
20
23
|
}
|
|
21
24
|
}
|
|
22
25
|
exports.Connection = Connection;
|
|
26
|
+
const createRandomConnectionId = () => {
|
|
27
|
+
return (0, uuid_1.v4)();
|
|
28
|
+
};
|
|
29
|
+
exports.createRandomConnectionId = createRandomConnectionId;
|
|
23
30
|
//# sourceMappingURL=Connection.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Connection.js","sourceRoot":"","sources":["../../../src/connection/Connection.ts"],"names":[],"mappings":";;;;;;AAAA,kEAAwC;
|
|
1
|
+
{"version":3,"file":"Connection.js","sourceRoot":"","sources":["../../../src/connection/Connection.ts"],"names":[],"mappings":";;;;;;AAAA,kEAAwC;AAGxC,+BAAiC;AAEjC,MAAa,UAAW,SAAQ,uBAA8B;IACnD,YAAY,CAAc;IAC1B,cAAc,CAAgB;IAC7B,cAAc,CAAiB;IAEvC,YAAY,cAA8B;QACtC,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,YAAY,GAAG,IAAA,gCAAwB,GAAE,CAAA;QAC9C,IAAI,CAAC,cAAc,GAAG,cAAc,CAAA;IACxC,CAAC;IAED,iBAAiB,CAAC,cAA8B;QAC5C,IAAI,CAAC,cAAc,GAAG,cAAc,CAAA;IACxC,CAAC;IAED,iBAAiB;QACb,OAAO,IAAI,CAAC,cAAc,CAAA;IAC9B,CAAC;CACJ;AAlBD,gCAkBC;AAEM,MAAM,wBAAwB,GAAG,GAAiB,EAAE;IACvD,OAAO,IAAA,SAAI,GAAkB,CAAA;AACjC,CAAC,CAAA;AAFY,QAAA,wBAAwB,4BAEpC"}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DhtAddress } from '../identifiers';
|
|
2
2
|
export type LockID = string;
|
|
3
3
|
export declare class ConnectionLockHandler {
|
|
4
4
|
private localLocks;
|
|
5
5
|
private remoteLocks;
|
|
6
6
|
private weakLocks;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
isLocalLocked(id:
|
|
11
|
-
isRemoteLocked(id:
|
|
7
|
+
getLocalLockedConnectionCount(): number;
|
|
8
|
+
getRemoteLockedConnectionCount(): number;
|
|
9
|
+
getWeakLockedConnectionCount(): number;
|
|
10
|
+
isLocalLocked(id: DhtAddress, lockId?: LockID): boolean;
|
|
11
|
+
isRemoteLocked(id: DhtAddress, lockId?: LockID): boolean;
|
|
12
12
|
private isWeakLocked;
|
|
13
|
-
isLocked(id:
|
|
14
|
-
addLocalLocked(id:
|
|
15
|
-
addRemoteLocked(id:
|
|
16
|
-
addWeakLocked(id:
|
|
17
|
-
removeLocalLocked(id:
|
|
18
|
-
removeRemoteLocked(id:
|
|
19
|
-
removeWeakLocked(id:
|
|
20
|
-
clearAllLocks(id:
|
|
13
|
+
isLocked(id: DhtAddress): boolean;
|
|
14
|
+
addLocalLocked(id: DhtAddress, lockId: LockID): void;
|
|
15
|
+
addRemoteLocked(id: DhtAddress, lockId: LockID): void;
|
|
16
|
+
addWeakLocked(id: DhtAddress, lockId: LockID): void;
|
|
17
|
+
removeLocalLocked(id: DhtAddress, lockId: LockID): void;
|
|
18
|
+
removeRemoteLocked(id: DhtAddress, lockId: LockID): void;
|
|
19
|
+
removeWeakLocked(id: DhtAddress, lockId: LockID): void;
|
|
20
|
+
clearAllLocks(id: DhtAddress): void;
|
|
21
21
|
clear(): void;
|
|
22
22
|
}
|
|
@@ -4,24 +4,22 @@
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.ConnectionLockHandler = void 0;
|
|
6
6
|
class ConnectionLockHandler {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
getNumberOfLocalLockedConnections() {
|
|
7
|
+
localLocks = new Map();
|
|
8
|
+
remoteLocks = new Map();
|
|
9
|
+
// TODO: remove weakLocks use localLocks instead. When opening weakLocks from the ConnectioManager,
|
|
10
|
+
// simply do not send lock requests.
|
|
11
|
+
weakLocks = new Map();
|
|
12
|
+
getLocalLockedConnectionCount() {
|
|
15
13
|
return this.localLocks.size;
|
|
16
14
|
}
|
|
17
|
-
|
|
15
|
+
getRemoteLockedConnectionCount() {
|
|
18
16
|
return this.remoteLocks.size;
|
|
19
17
|
}
|
|
20
|
-
|
|
18
|
+
getWeakLockedConnectionCount() {
|
|
21
19
|
return this.weakLocks.size;
|
|
22
20
|
}
|
|
23
21
|
isLocalLocked(id, lockId) {
|
|
24
|
-
if (
|
|
22
|
+
if (lockId === undefined) {
|
|
25
23
|
return this.localLocks.has(id);
|
|
26
24
|
}
|
|
27
25
|
else {
|
|
@@ -29,7 +27,7 @@ class ConnectionLockHandler {
|
|
|
29
27
|
}
|
|
30
28
|
}
|
|
31
29
|
isRemoteLocked(id, lockId) {
|
|
32
|
-
if (
|
|
30
|
+
if (lockId === undefined) {
|
|
33
31
|
return this.remoteLocks.has(id);
|
|
34
32
|
}
|
|
35
33
|
else {
|
|
@@ -59,8 +57,11 @@ class ConnectionLockHandler {
|
|
|
59
57
|
}
|
|
60
58
|
this.remoteLocks.get(id).add(lockId);
|
|
61
59
|
}
|
|
62
|
-
addWeakLocked(id) {
|
|
63
|
-
this.weakLocks.
|
|
60
|
+
addWeakLocked(id, lockId) {
|
|
61
|
+
if (!this.weakLocks.has(id)) {
|
|
62
|
+
this.weakLocks.set(id, new Set());
|
|
63
|
+
}
|
|
64
|
+
this.weakLocks.get(id).add(lockId);
|
|
64
65
|
}
|
|
65
66
|
removeLocalLocked(id, lockId) {
|
|
66
67
|
if (this.localLocks.has(id)) {
|
|
@@ -78,8 +79,13 @@ class ConnectionLockHandler {
|
|
|
78
79
|
}
|
|
79
80
|
}
|
|
80
81
|
}
|
|
81
|
-
removeWeakLocked(id) {
|
|
82
|
-
this.weakLocks.
|
|
82
|
+
removeWeakLocked(id, lockId) {
|
|
83
|
+
if (this.weakLocks.has(id)) {
|
|
84
|
+
this.weakLocks.get(id)?.delete(lockId);
|
|
85
|
+
if (this.weakLocks.get(id)?.size === 0) {
|
|
86
|
+
this.weakLocks.delete(id);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
83
89
|
}
|
|
84
90
|
clearAllLocks(id) {
|
|
85
91
|
this.localLocks.delete(id);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConnectionLockHandler.js","sourceRoot":"","sources":["../../../src/connection/ConnectionLockHandler.ts"],"names":[],"mappings":";AAAA,mEAAmE;AACnE,mCAAmC;;;AAMnC,MAAa,qBAAqB;
|
|
1
|
+
{"version":3,"file":"ConnectionLockHandler.js","sourceRoot":"","sources":["../../../src/connection/ConnectionLockHandler.ts"],"names":[],"mappings":"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"}
|
|
@@ -2,11 +2,11 @@ import { ServerCallContext } from '@protobuf-ts/runtime-rpc';
|
|
|
2
2
|
import { Empty } from '../proto/google/protobuf/empty';
|
|
3
3
|
import { DisconnectNotice, LockRequest, LockResponse, PeerDescriptor, UnlockRequest } from '../proto/packages/dht/protos/DhtRpc';
|
|
4
4
|
import { IConnectionLockRpc } from '../proto/packages/dht/protos/DhtRpc.server';
|
|
5
|
-
import { PeerIDKey } from '../helpers/PeerID';
|
|
6
5
|
import { LockID } from './ConnectionLockHandler';
|
|
6
|
+
import { DhtAddress } from '../identifiers';
|
|
7
7
|
interface ConnectionLockRpcLocalConfig {
|
|
8
|
-
addRemoteLocked: (id:
|
|
9
|
-
removeRemoteLocked: (id:
|
|
8
|
+
addRemoteLocked: (id: DhtAddress, lockId: LockID) => void;
|
|
9
|
+
removeRemoteLocked: (id: DhtAddress, lockId: LockID) => void;
|
|
10
10
|
closeConnection: (peerDescriptor: PeerDescriptor, gracefulLeave: boolean, reason?: string) => void;
|
|
11
11
|
getLocalPeerDescriptor: () => PeerDescriptor;
|
|
12
12
|
}
|
|
@@ -2,24 +2,25 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ConnectionLockRpcLocal = void 0;
|
|
4
4
|
const utils_1 = require("@streamr/utils");
|
|
5
|
-
const peerIdFromPeerDescriptor_1 = require("../helpers/peerIdFromPeerDescriptor");
|
|
6
5
|
const DhtRpc_1 = require("../proto/packages/dht/protos/DhtRpc");
|
|
7
6
|
const ConnectionManager_1 = require("./ConnectionManager");
|
|
7
|
+
const identifiers_1 = require("../identifiers");
|
|
8
8
|
const logger = new utils_1.Logger(module);
|
|
9
9
|
class ConnectionLockRpcLocal {
|
|
10
|
+
config;
|
|
10
11
|
constructor(config) {
|
|
11
12
|
this.config = config;
|
|
12
13
|
}
|
|
13
14
|
async lockRequest(lockRequest, context) {
|
|
14
15
|
const senderPeerDescriptor = context.incomingSourceDescriptor;
|
|
15
|
-
|
|
16
|
-
if ((0, peerIdFromPeerDescriptor_1.areEqualPeerDescriptors)(senderPeerDescriptor, this.config.getLocalPeerDescriptor())) {
|
|
16
|
+
if ((0, identifiers_1.areEqualPeerDescriptors)(senderPeerDescriptor, this.config.getLocalPeerDescriptor())) {
|
|
17
17
|
const response = {
|
|
18
18
|
accepted: false
|
|
19
19
|
};
|
|
20
20
|
return response;
|
|
21
21
|
}
|
|
22
|
-
|
|
22
|
+
const remoteNodeId = (0, identifiers_1.getNodeIdFromPeerDescriptor)(senderPeerDescriptor);
|
|
23
|
+
this.config.addRemoteLocked(remoteNodeId, lockRequest.lockId);
|
|
23
24
|
const response = {
|
|
24
25
|
accepted: true
|
|
25
26
|
};
|
|
@@ -27,8 +28,8 @@ class ConnectionLockRpcLocal {
|
|
|
27
28
|
}
|
|
28
29
|
async unlockRequest(unlockRequest, context) {
|
|
29
30
|
const senderPeerDescriptor = context.incomingSourceDescriptor;
|
|
30
|
-
const
|
|
31
|
-
this.config.removeRemoteLocked(
|
|
31
|
+
const nodeId = (0, identifiers_1.getNodeIdFromPeerDescriptor)(senderPeerDescriptor);
|
|
32
|
+
this.config.removeRemoteLocked(nodeId, unlockRequest.lockId);
|
|
32
33
|
return {};
|
|
33
34
|
}
|
|
34
35
|
async gracefulDisconnect(disconnectNotice, context) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConnectionLockRpcLocal.js","sourceRoot":"","sources":["../../../src/connection/ConnectionLockRpcLocal.ts"],"names":[],"mappings":";;;AACA,0CAAuC;
|
|
1
|
+
{"version":3,"file":"ConnectionLockRpcLocal.js","sourceRoot":"","sources":["../../../src/connection/ConnectionLockRpcLocal.ts"],"names":[],"mappings":";;;AACA,0CAAuC;AAEvC,gEAO4C;AAG5C,2DAA0E;AAE1E,gDAAiG;AASjG,MAAM,MAAM,GAAG,IAAI,cAAM,CAAC,MAAM,CAAC,CAAA;AAEjC,MAAa,sBAAsB;IAEd,MAAM,CAA8B;IAErD,YAAY,MAAoC;QAC5C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACxB,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,WAAwB,EAAE,OAA0B;QAClE,MAAM,oBAAoB,GAAI,OAA0B,CAAC,wBAAyB,CAAA;QAClF,IAAI,IAAA,qCAAuB,EAAC,oBAAoB,EAAE,IAAI,CAAC,MAAM,CAAC,sBAAsB,EAAE,CAAC,EAAE,CAAC;YACtF,MAAM,QAAQ,GAAiB;gBAC3B,QAAQ,EAAE,KAAK;aAClB,CAAA;YACD,OAAO,QAAQ,CAAA;QACnB,CAAC;QACD,MAAM,YAAY,GAAG,IAAA,yCAA2B,EAAC,oBAAoB,CAAC,CAAA;QACtE,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,YAAY,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;QAC7D,MAAM,QAAQ,GAAiB;YAC3B,QAAQ,EAAE,IAAI;SACjB,CAAA;QACD,OAAO,QAAQ,CAAA;IACnB,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,aAA4B,EAAE,OAA0B;QACxE,MAAM,oBAAoB,GAAI,OAA0B,CAAC,wBAAyB,CAAA;QAClF,MAAM,MAAM,GAAG,IAAA,yCAA2B,EAAC,oBAAoB,CAAC,CAAA;QAChE,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,CAAA;QAC5D,OAAO,EAAE,CAAA;IACb,CAAC;IAED,KAAK,CAAC,kBAAkB,CAAC,gBAAkC,EAAE,OAA0B;QACnF,MAAM,oBAAoB,GAAI,OAA0B,CAAC,wBAAyB,CAAA;QAClF,MAAM,CAAC,KAAK,CAAC,IAAA,wDAAoC,EAAC,oBAAoB,CAAC,GAAG,qCAAqC,CAAC,CAAA;QAEhH,IAAI,gBAAgB,CAAC,cAAc,KAAK,uBAAc,CAAC,OAAO,EAAE,CAAC;YAC7D,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,oBAAoB,EAAE,IAAI,EAAE,yBAAyB,CAAC,CAAA;QACtF,CAAC;aAAM,CAAC;YACJ,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,oBAAoB,EAAE,KAAK,EAAE,8BAA8B,CAAC,CAAA;QAC5F,CAAC;QACD,OAAO,EAAE,CAAA;IACb,CAAC;CACJ;AA1CD,wDA0CC"}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { Remote } from '../dht/contact/Remote';
|
|
1
|
+
import { RpcRemote } from '../dht/contact/RpcRemote';
|
|
2
|
+
import { DisconnectMode } from '../proto/packages/dht/protos/DhtRpc';
|
|
3
|
+
import { ConnectionLockRpcClient } from '../proto/packages/dht/protos/DhtRpc.client';
|
|
5
4
|
import { LockID } from './ConnectionLockHandler';
|
|
6
|
-
export declare class ConnectionLockRpcRemote extends
|
|
7
|
-
constructor(localPeerDescriptor: PeerDescriptor, targetPeerDescriptor: PeerDescriptor, client: ProtoRpcClient<IConnectionLockRpcClient>);
|
|
5
|
+
export declare class ConnectionLockRpcRemote extends RpcRemote<ConnectionLockRpcClient> {
|
|
8
6
|
lockRequest(lockId: LockID): Promise<boolean>;
|
|
9
7
|
unlockRequest(lockId: LockID): void;
|
|
10
8
|
gracefulDisconnect(disconnectMode: DisconnectMode): Promise<void>;
|
|
@@ -1,40 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
3
|
exports.ConnectionLockRpcRemote = void 0;
|
|
27
4
|
const utils_1 = require("@streamr/utils");
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
const Remote_1 = require("../dht/contact/Remote");
|
|
5
|
+
const RpcRemote_1 = require("../dht/contact/RpcRemote");
|
|
6
|
+
const identifiers_1 = require("../identifiers");
|
|
31
7
|
const logger = new utils_1.Logger(module);
|
|
32
|
-
class ConnectionLockRpcRemote extends
|
|
33
|
-
constructor(localPeerDescriptor, targetPeerDescriptor, client) {
|
|
34
|
-
super(localPeerDescriptor, targetPeerDescriptor, 'DUMMY', client);
|
|
35
|
-
}
|
|
8
|
+
class ConnectionLockRpcRemote extends RpcRemote_1.RpcRemote {
|
|
36
9
|
async lockRequest(lockId) {
|
|
37
|
-
logger.trace(`Requesting locked connection to ${(0,
|
|
10
|
+
logger.trace(`Requesting locked connection to ${(0, identifiers_1.getNodeIdFromPeerDescriptor)(this.getPeerDescriptor())}`);
|
|
38
11
|
const request = {
|
|
39
12
|
lockId
|
|
40
13
|
};
|
|
@@ -44,12 +17,12 @@ class ConnectionLockRpcRemote extends Remote_1.Remote {
|
|
|
44
17
|
return res.accepted;
|
|
45
18
|
}
|
|
46
19
|
catch (err) {
|
|
47
|
-
logger.debug(
|
|
20
|
+
logger.debug('Connection lock rejected', { error: err });
|
|
48
21
|
return false;
|
|
49
22
|
}
|
|
50
23
|
}
|
|
51
24
|
unlockRequest(lockId) {
|
|
52
|
-
logger.trace(`Requesting connection to be unlocked from ${(0,
|
|
25
|
+
logger.trace(`Requesting connection to be unlocked from ${(0, identifiers_1.getNodeIdFromPeerDescriptor)(this.getPeerDescriptor())}`);
|
|
53
26
|
const request = {
|
|
54
27
|
lockId
|
|
55
28
|
};
|
|
@@ -61,14 +34,14 @@ class ConnectionLockRpcRemote extends Remote_1.Remote {
|
|
|
61
34
|
});
|
|
62
35
|
}
|
|
63
36
|
async gracefulDisconnect(disconnectMode) {
|
|
64
|
-
logger.trace(`Notifying a graceful disconnect to ${(0,
|
|
37
|
+
logger.trace(`Notifying a graceful disconnect to ${(0, identifiers_1.getNodeIdFromPeerDescriptor)(this.getPeerDescriptor())}`);
|
|
65
38
|
const request = {
|
|
66
39
|
disconnectMode
|
|
67
40
|
};
|
|
68
41
|
const options = this.formDhtRpcOptions({
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
timeout: 2000
|
|
42
|
+
connect: false,
|
|
43
|
+
sendIfStopped: true,
|
|
44
|
+
timeout: 2000 // TODO use config option or named constant?
|
|
72
45
|
});
|
|
73
46
|
await this.getClient().gracefulDisconnect(request, options);
|
|
74
47
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConnectionLockRpcRemote.js","sourceRoot":"","sources":["../../../src/connection/ConnectionLockRpcRemote.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ConnectionLockRpcRemote.js","sourceRoot":"","sources":["../../../src/connection/ConnectionLockRpcRemote.ts"],"names":[],"mappings":";;;AAAA,0CAAuC;AACvC,wDAAoD;AAIpD,gDAA4D;AAE5D,MAAM,MAAM,GAAG,IAAI,cAAM,CAAC,MAAM,CAAC,CAAA;AAEjC,MAAa,uBAAwB,SAAQ,qBAAkC;IAEpE,KAAK,CAAC,WAAW,CAAC,MAAc;QACnC,MAAM,CAAC,KAAK,CAAC,mCAAmC,IAAA,yCAA2B,EAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC,EAAE,CAAC,CAAA;QACxG,MAAM,OAAO,GAAgB;YACzB,MAAM;SACT,CAAA;QACD,MAAM,OAAO,GAAG,IAAI,CAAC,iBAAiB,EAAE,CAAA;QACxC,IAAI,CAAC;YACD,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,SAAS,EAAE,CAAC,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;YAChE,OAAO,GAAG,CAAC,QAAQ,CAAA;QACvB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,MAAM,CAAC,KAAK,CAAC,0BAA0B,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAA;YACxD,OAAO,KAAK,CAAA;QAChB,CAAC;IACL,CAAC;IAEM,aAAa,CAAC,MAAc;QAC/B,MAAM,CAAC,KAAK,CAAC,6CAA6C,IAAA,yCAA2B,EAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC,EAAE,CAAC,CAAA;QAClH,MAAM,OAAO,GAAkB;YAC3B,MAAM;SACT,CAAA;QACD,MAAM,OAAO,GAAG,IAAI,CAAC,iBAAiB,CAAC;YACnC,YAAY,EAAE,IAAI;SACrB,CAAC,CAAA;QACF,IAAI,CAAC,SAAS,EAAE,CAAC,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,EAAE;YAC1D,MAAM,CAAC,KAAK,CAAC,8BAA8B,CAAC,CAAA;QAChD,CAAC,CAAC,CAAA;IACN,CAAC;IAEM,KAAK,CAAC,kBAAkB,CAAC,cAA8B;QAC1D,MAAM,CAAC,KAAK,CAAC,sCAAsC,IAAA,yCAA2B,EAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC,EAAE,CAAC,CAAA;QAC3G,MAAM,OAAO,GAAqB;YAC9B,cAAc;SACjB,CAAA;QACD,MAAM,OAAO,GAAG,IAAI,CAAC,iBAAiB,CAAC;YACnC,OAAO,EAAE,KAAK;YACd,aAAa,EAAE,IAAI;YACnB,OAAO,EAAE,IAAI,CAAE,4CAA4C;SAC9D,CAAC,CAAA;QACF,MAAM,IAAI,CAAC,SAAS,EAAE,CAAC,kBAAkB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;IAC/D,CAAC;CACJ;AA1CD,0DA0CC"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { MetricsContext } from '@streamr/utils';
|
|
2
2
|
import { EventEmitter } from 'eventemitter3';
|
|
3
3
|
import { Message, PeerDescriptor } from '../proto/packages/dht/protos/DhtRpc';
|
|
4
|
-
import { ITransport, TransportEvents } from '../transport/ITransport';
|
|
4
|
+
import { ITransport, SendOptions, TransportEvents } from '../transport/ITransport';
|
|
5
5
|
import { LockID } from './ConnectionLockHandler';
|
|
6
6
|
import { ConnectorFacade } from './ConnectorFacade';
|
|
7
7
|
import { ManagedConnection } from './ManagedConnection';
|
|
8
|
+
import { DhtAddress } from '../identifiers';
|
|
8
9
|
export interface ConnectionManagerConfig {
|
|
9
10
|
maxConnections?: number;
|
|
10
11
|
metricsContext: MetricsContext;
|
|
@@ -14,12 +15,11 @@ export declare enum NatType {
|
|
|
14
15
|
OPEN_INTERNET = "open_internet",
|
|
15
16
|
UNKNOWN = "unknown"
|
|
16
17
|
}
|
|
17
|
-
type ServiceId = string;
|
|
18
18
|
export interface ConnectionLocker {
|
|
19
|
-
lockConnection(targetDescriptor: PeerDescriptor,
|
|
20
|
-
unlockConnection(targetDescriptor: PeerDescriptor,
|
|
21
|
-
weakLockConnection(
|
|
22
|
-
weakUnlockConnection(
|
|
19
|
+
lockConnection(targetDescriptor: PeerDescriptor, lockId: LockID): void;
|
|
20
|
+
unlockConnection(targetDescriptor: PeerDescriptor, lockId: LockID): void;
|
|
21
|
+
weakLockConnection(nodeId: DhtAddress, lockId: LockID): void;
|
|
22
|
+
weakUnlockConnection(nodeId: DhtAddress, lockId: LockID): void;
|
|
23
23
|
}
|
|
24
24
|
export interface PortRange {
|
|
25
25
|
min: number;
|
|
@@ -45,19 +45,19 @@ export declare class ConnectionManager extends EventEmitter<TransportEvents> imp
|
|
|
45
45
|
garbageCollectConnections(maxConnections: number, lastUsedLimit: number): void;
|
|
46
46
|
start(): Promise<void>;
|
|
47
47
|
stop(): Promise<void>;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
send(message: Message,
|
|
48
|
+
getLocalLockedConnectionCount(): number;
|
|
49
|
+
getRemoteLockedConnectionCount(): number;
|
|
50
|
+
getWeakLockedConnectionCount(): number;
|
|
51
|
+
send(message: Message, opts?: SendOptions): Promise<void>;
|
|
52
52
|
private isConnectionToSelf;
|
|
53
53
|
private isOwnWebsocketServer;
|
|
54
|
-
getConnection(
|
|
54
|
+
getConnection(nodeId: DhtAddress): ManagedConnection | undefined;
|
|
55
55
|
getLocalPeerDescriptor(): PeerDescriptor;
|
|
56
|
-
hasConnection(
|
|
57
|
-
hasLocalLockedConnection(
|
|
58
|
-
hasRemoteLockedConnection(
|
|
59
|
-
private
|
|
60
|
-
|
|
56
|
+
hasConnection(nodeId: DhtAddress): boolean;
|
|
57
|
+
hasLocalLockedConnection(nodeId: DhtAddress): boolean;
|
|
58
|
+
hasRemoteLockedConnection(nodeId: DhtAddress): boolean;
|
|
59
|
+
private handleMessage;
|
|
60
|
+
handleIncomingMessage(message: Message): boolean;
|
|
61
61
|
private onData;
|
|
62
62
|
private onConnected;
|
|
63
63
|
private onDisconnected;
|
|
@@ -66,11 +66,10 @@ export declare class ConnectionManager extends EventEmitter<TransportEvents> imp
|
|
|
66
66
|
private closeConnection;
|
|
67
67
|
lockConnection(targetDescriptor: PeerDescriptor, lockId: LockID): void;
|
|
68
68
|
unlockConnection(targetDescriptor: PeerDescriptor, lockId: LockID): void;
|
|
69
|
-
weakLockConnection(
|
|
70
|
-
weakUnlockConnection(
|
|
69
|
+
weakLockConnection(nodeId: DhtAddress, lockId: LockID): void;
|
|
70
|
+
weakUnlockConnection(nodeId: DhtAddress, lockId: LockID): void;
|
|
71
71
|
private gracefullyDisconnectAsync;
|
|
72
72
|
private doGracefullyDisconnectAsync;
|
|
73
|
-
|
|
73
|
+
getConnections(): PeerDescriptor[];
|
|
74
74
|
private onConnectionCountChange;
|
|
75
75
|
}
|
|
76
|
-
export {};
|