@streamr/dht 100.0.0-pretestnet.4 → 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/protos/DhtRpc.proto
CHANGED
|
@@ -10,6 +10,7 @@ import "packages/proto-rpc/protos/ProtoRpc.proto";
|
|
|
10
10
|
|
|
11
11
|
service DhtNodeRpc {
|
|
12
12
|
rpc getClosestPeers (ClosestPeersRequest) returns (ClosestPeersResponse);
|
|
13
|
+
rpc getClosestRingPeers (ClosestRingPeersRequest) returns (ClosestRingPeersResponse);
|
|
13
14
|
rpc ping (PingRequest) returns (PingResponse);
|
|
14
15
|
rpc leaveNotice (LeaveNotice) returns (google.protobuf.Empty);
|
|
15
16
|
}
|
|
@@ -19,22 +20,21 @@ service RouterRpc {
|
|
|
19
20
|
rpc forwardMessage (RouteMessageWrapper) returns (RouteMessageAck);
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
service
|
|
23
|
-
rpc
|
|
23
|
+
service RecursiveOperationRpc {
|
|
24
|
+
rpc routeRequest (RouteMessageWrapper) returns (RouteMessageAck);
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
service StoreRpc {
|
|
27
28
|
rpc storeData (StoreDataRequest) returns (StoreDataResponse);
|
|
28
|
-
rpc
|
|
29
|
-
rpc deleteData (DeleteDataRequest) returns (DeleteDataResponse);
|
|
29
|
+
rpc replicateData (ReplicateDataRequest) returns (google.protobuf.Empty);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
service
|
|
33
|
-
rpc
|
|
32
|
+
service RecursiveOperationSessionRpc {
|
|
33
|
+
rpc sendResponse(RecursiveOperationResponse) returns (google.protobuf.Empty);
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
service WebsocketConnectorRpc {
|
|
37
|
-
rpc requestConnection (WebsocketConnectionRequest) returns (
|
|
37
|
+
rpc requestConnection (WebsocketConnectionRequest) returns (google.protobuf.Empty);
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
service WebrtcConnectorRpc {
|
|
@@ -47,25 +47,25 @@ service WebrtcConnectorRpc {
|
|
|
47
47
|
service ConnectionLockRpc {
|
|
48
48
|
rpc lockRequest (LockRequest) returns (LockResponse);
|
|
49
49
|
rpc unlockRequest (UnlockRequest) returns (google.protobuf.Empty);
|
|
50
|
-
rpc gracefulDisconnect (DisconnectNotice) returns (
|
|
50
|
+
rpc gracefulDisconnect (DisconnectNotice) returns (google.protobuf.Empty);
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
service ExternalApiRpc {
|
|
54
|
-
rpc
|
|
54
|
+
rpc externalFetchData (ExternalFetchDataRequest) returns (ExternalFetchDataResponse);
|
|
55
55
|
rpc externalStoreData (ExternalStoreDataRequest) returns (ExternalStoreDataResponse);
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
// Used inside RpcMessage
|
|
59
59
|
|
|
60
60
|
message StoreDataRequest {
|
|
61
|
-
bytes
|
|
61
|
+
bytes key = 1;
|
|
62
62
|
google.protobuf.Any data = 2;
|
|
63
|
-
|
|
64
|
-
google.protobuf.Timestamp
|
|
63
|
+
bytes creator = 3;
|
|
64
|
+
google.protobuf.Timestamp createdAt = 4;
|
|
65
|
+
uint32 ttl = 5;
|
|
65
66
|
}
|
|
66
67
|
|
|
67
68
|
message StoreDataResponse {
|
|
68
|
-
string error = 1;
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
message ExternalStoreDataRequest {
|
|
@@ -77,35 +77,23 @@ message ExternalStoreDataResponse {
|
|
|
77
77
|
repeated PeerDescriptor storers = 1;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
message
|
|
81
|
-
DataEntry
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
message MigrateDataResponse {
|
|
85
|
-
string error = 1;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
message DeleteDataRequest {
|
|
89
|
-
bytes kademliaId = 1;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
message DeleteDataResponse {
|
|
93
|
-
bool deleted = 1;
|
|
80
|
+
message ReplicateDataRequest {
|
|
81
|
+
DataEntry entry = 1;
|
|
94
82
|
}
|
|
95
83
|
|
|
96
84
|
message DataEntry {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
google.protobuf.Timestamp
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
bool
|
|
104
|
-
|
|
85
|
+
bytes key = 1;
|
|
86
|
+
google.protobuf.Any data = 2;
|
|
87
|
+
bytes creator = 3;
|
|
88
|
+
google.protobuf.Timestamp createdAt = 4;
|
|
89
|
+
google.protobuf.Timestamp storedAt = 5;
|
|
90
|
+
uint32 ttl = 6; // milliseconds
|
|
91
|
+
bool stale = 7;
|
|
92
|
+
bool deleted = 8;
|
|
105
93
|
}
|
|
106
94
|
|
|
107
95
|
message ClosestPeersRequest {
|
|
108
|
-
bytes
|
|
96
|
+
bytes nodeId = 1;
|
|
109
97
|
string requestId = 2;
|
|
110
98
|
}
|
|
111
99
|
|
|
@@ -114,15 +102,32 @@ message ClosestPeersResponse {
|
|
|
114
102
|
string requestId = 2;
|
|
115
103
|
}
|
|
116
104
|
|
|
117
|
-
message
|
|
105
|
+
message ClosestRingPeersRequest {
|
|
106
|
+
bytes ringId = 1;
|
|
107
|
+
string requestId = 2;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
message ClosestRingPeersResponse {
|
|
111
|
+
repeated PeerDescriptor leftPeers = 1;
|
|
112
|
+
repeated PeerDescriptor rightPeers = 2;
|
|
113
|
+
string requestId = 3;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
message RecursiveOperationRequest {
|
|
118
117
|
string sessionId = 1;
|
|
119
|
-
|
|
118
|
+
RecursiveOperation operation = 2;
|
|
120
119
|
}
|
|
121
120
|
|
|
122
|
-
|
|
121
|
+
enum RecursiveOperation {
|
|
122
|
+
FIND_CLOSEST_NODES = 0;
|
|
123
|
+
FETCH_DATA = 1;
|
|
124
|
+
DELETE_DATA = 2;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
message RecursiveOperationResponse {
|
|
123
128
|
repeated PeerDescriptor closestConnectedPeers = 1;
|
|
124
129
|
repeated DataEntry dataEntries = 2;
|
|
125
|
-
|
|
130
|
+
bool noCloserNodesFound = 3;
|
|
126
131
|
repeated PeerDescriptor routingPath = 4;
|
|
127
132
|
}
|
|
128
133
|
|
|
@@ -135,16 +140,19 @@ message PingResponse {
|
|
|
135
140
|
}
|
|
136
141
|
|
|
137
142
|
message LeaveNotice {
|
|
138
|
-
string serviceId = 1;
|
|
139
143
|
}
|
|
140
144
|
|
|
141
145
|
message PeerDescriptor {
|
|
142
|
-
bytes
|
|
146
|
+
bytes nodeId = 1;
|
|
143
147
|
NodeType type = 2;
|
|
144
148
|
ConnectivityMethod udp = 3;
|
|
145
149
|
ConnectivityMethod tcp = 4;
|
|
146
150
|
ConnectivityMethod websocket = 5;
|
|
147
151
|
optional uint32 region = 6;
|
|
152
|
+
optional uint32 ipAddress = 7;
|
|
153
|
+
optional bytes publicKey = 8;
|
|
154
|
+
// signature of fields 2-8
|
|
155
|
+
optional bytes signature = 9;
|
|
148
156
|
}
|
|
149
157
|
|
|
150
158
|
message ConnectivityMethod {
|
|
@@ -156,7 +164,6 @@ message ConnectivityMethod {
|
|
|
156
164
|
enum NodeType {
|
|
157
165
|
NODEJS = 0;
|
|
158
166
|
BROWSER = 1;
|
|
159
|
-
VIRTUAL = 3;
|
|
160
167
|
}
|
|
161
168
|
|
|
162
169
|
enum RpcResponseError {
|
|
@@ -167,20 +174,27 @@ enum RpcResponseError {
|
|
|
167
174
|
}
|
|
168
175
|
|
|
169
176
|
message RouteMessageWrapper {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
177
|
+
string requestId = 1;
|
|
178
|
+
PeerDescriptor sourcePeer = 2;
|
|
179
|
+
bytes target = 3;
|
|
173
180
|
Message message = 4;
|
|
174
181
|
repeated PeerDescriptor reachableThrough = 5;
|
|
175
182
|
repeated PeerDescriptor routingPath = 6;
|
|
183
|
+
repeated string parallelRootNodeIds = 7;
|
|
176
184
|
}
|
|
177
185
|
|
|
178
186
|
message RouteMessageAck {
|
|
179
187
|
string requestId = 1;
|
|
180
|
-
|
|
188
|
+
optional RouteMessageError error = 2;
|
|
181
189
|
}
|
|
182
190
|
|
|
183
|
-
|
|
191
|
+
enum RouteMessageError {
|
|
192
|
+
NO_TARGETS = 0;
|
|
193
|
+
DUPLICATE = 1;
|
|
194
|
+
// TODO: can this be removed? If DhtNode is already stopped the server side requests
|
|
195
|
+
// should not be processed
|
|
196
|
+
STOPPED = 2;
|
|
197
|
+
}
|
|
184
198
|
|
|
185
199
|
message ConnectivityRequest {
|
|
186
200
|
uint32 port = 1;
|
|
@@ -193,47 +207,42 @@ message ConnectivityResponse {
|
|
|
193
207
|
string host = 1;
|
|
194
208
|
string natType = 2;
|
|
195
209
|
ConnectivityMethod websocket = 3;
|
|
210
|
+
uint32 ipAddress = 4;
|
|
211
|
+
string version = 5;
|
|
196
212
|
}
|
|
197
213
|
|
|
198
214
|
message HandshakeRequest {
|
|
199
215
|
PeerDescriptor sourcePeerDescriptor = 1;
|
|
200
216
|
optional PeerDescriptor targetPeerDescriptor = 2;
|
|
217
|
+
string version = 3;
|
|
201
218
|
}
|
|
202
219
|
|
|
203
220
|
message HandshakeResponse {
|
|
204
221
|
PeerDescriptor sourcePeerDescriptor = 1;
|
|
205
222
|
optional HandshakeError error = 2;
|
|
223
|
+
string version = 3;
|
|
206
224
|
}
|
|
207
225
|
|
|
208
226
|
enum HandshakeError {
|
|
209
227
|
DUPLICATE_CONNECTION = 0;
|
|
210
228
|
INVALID_TARGET_PEER_DESCRIPTOR = 1;
|
|
229
|
+
UNSUPPORTED_VERSION = 2;
|
|
211
230
|
}
|
|
212
231
|
|
|
213
232
|
// Wraps all messages
|
|
214
233
|
|
|
215
|
-
enum MessageType {
|
|
216
|
-
RPC = 0;
|
|
217
|
-
CONNECTIVITY_REQUEST = 1;
|
|
218
|
-
CONNECTIVITY_RESPONSE = 2;
|
|
219
|
-
HANDSHAKE_REQUEST = 3;
|
|
220
|
-
HANDSHAKE_RESPONSE = 4;
|
|
221
|
-
FIND_REQUEST = 5;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
234
|
message Message {
|
|
225
235
|
string messageId = 1;
|
|
226
|
-
|
|
227
|
-
PeerDescriptor
|
|
228
|
-
|
|
229
|
-
string serviceId = 5; // id of the RPC service
|
|
236
|
+
PeerDescriptor sourceDescriptor = 2;
|
|
237
|
+
PeerDescriptor targetDescriptor = 3;
|
|
238
|
+
string serviceId = 4; // id of the RPC service
|
|
230
239
|
oneof body {
|
|
240
|
+
protorpc.RpcMessage rpcMessage = 5;
|
|
231
241
|
ConnectivityRequest connectivityRequest = 6;
|
|
232
242
|
ConnectivityResponse connectivityResponse = 7;
|
|
233
243
|
HandshakeRequest handshakeRequest = 8;
|
|
234
244
|
HandshakeResponse handshakeResponse = 9;
|
|
235
|
-
|
|
236
|
-
FindRequest findRequest = 11;
|
|
245
|
+
RecursiveOperationRequest recursiveOperationRequest = 10;
|
|
237
246
|
};
|
|
238
247
|
}
|
|
239
248
|
|
|
@@ -243,10 +252,6 @@ message Message {
|
|
|
243
252
|
message WebsocketConnectionRequest {
|
|
244
253
|
}
|
|
245
254
|
|
|
246
|
-
message WebsocketConnectionResponse {
|
|
247
|
-
bool accepted = 1;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
255
|
// WebRTC
|
|
251
256
|
message WebrtcConnectionRequest {
|
|
252
257
|
}
|
|
@@ -277,7 +282,6 @@ message UnlockRequest {
|
|
|
277
282
|
|
|
278
283
|
message LockResponse {
|
|
279
284
|
bool accepted = 1;
|
|
280
|
-
optional bool reason = 2;
|
|
281
285
|
}
|
|
282
286
|
|
|
283
287
|
enum DisconnectMode {
|
|
@@ -289,14 +293,10 @@ message DisconnectNotice {
|
|
|
289
293
|
DisconnectMode disconnectMode = 1;
|
|
290
294
|
}
|
|
291
295
|
|
|
292
|
-
message
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
message ExternalFindDataRequest {
|
|
296
|
-
bytes kademliaId = 1;
|
|
296
|
+
message ExternalFetchDataRequest {
|
|
297
|
+
bytes key = 1;
|
|
297
298
|
}
|
|
298
299
|
|
|
299
|
-
message
|
|
300
|
-
repeated DataEntry
|
|
301
|
-
optional string error = 2;
|
|
300
|
+
message ExternalFetchDataResponse {
|
|
301
|
+
repeated DataEntry entries = 1;
|
|
302
302
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import EventEmitter from 'eventemitter3'
|
|
2
2
|
import { PeerDescriptor } from '../proto/packages/dht/protos/DhtRpc'
|
|
3
3
|
import { ConnectionID, ConnectionType, ConnectionEvents } from './IConnection'
|
|
4
|
+
import { v4 as uuid } from 'uuid'
|
|
4
5
|
|
|
5
6
|
export class Connection extends EventEmitter<ConnectionEvents> {
|
|
6
7
|
public connectionId: ConnectionID
|
|
@@ -9,7 +10,7 @@ export class Connection extends EventEmitter<ConnectionEvents> {
|
|
|
9
10
|
|
|
10
11
|
constructor(connectionType: ConnectionType) {
|
|
11
12
|
super()
|
|
12
|
-
this.connectionId =
|
|
13
|
+
this.connectionId = createRandomConnectionId()
|
|
13
14
|
this.connectionType = connectionType
|
|
14
15
|
}
|
|
15
16
|
|
|
@@ -21,3 +22,7 @@ export class Connection extends EventEmitter<ConnectionEvents> {
|
|
|
21
22
|
return this.peerDescriptor
|
|
22
23
|
}
|
|
23
24
|
}
|
|
25
|
+
|
|
26
|
+
export const createRandomConnectionId = (): ConnectionID => {
|
|
27
|
+
return uuid() as ConnectionID
|
|
28
|
+
}
|
|
@@ -1,40 +1,40 @@
|
|
|
1
1
|
// Connection locks are independent of the existence of connections
|
|
2
2
|
// that is why this class is needed
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { DhtAddress } from '../identifiers'
|
|
5
5
|
|
|
6
6
|
export type LockID = string
|
|
7
7
|
|
|
8
8
|
export class ConnectionLockHandler {
|
|
9
9
|
|
|
10
|
-
private localLocks: Map<
|
|
11
|
-
private remoteLocks: Map<
|
|
10
|
+
private localLocks: Map<DhtAddress, Set<LockID>> = new Map()
|
|
11
|
+
private remoteLocks: Map<DhtAddress, Set<LockID>> = new Map()
|
|
12
12
|
// TODO: remove weakLocks use localLocks instead. When opening weakLocks from the ConnectioManager,
|
|
13
13
|
// simply do not send lock requests.
|
|
14
|
-
private weakLocks: Set<
|
|
14
|
+
private weakLocks: Map<DhtAddress, Set<LockID>> = new Map()
|
|
15
15
|
|
|
16
|
-
public
|
|
16
|
+
public getLocalLockedConnectionCount(): number {
|
|
17
17
|
return this.localLocks.size
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
public
|
|
20
|
+
public getRemoteLockedConnectionCount(): number {
|
|
21
21
|
return this.remoteLocks.size
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
public
|
|
24
|
+
public getWeakLockedConnectionCount(): number {
|
|
25
25
|
return this.weakLocks.size
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
public isLocalLocked(id:
|
|
29
|
-
if (
|
|
28
|
+
public isLocalLocked(id: DhtAddress, lockId?: LockID): boolean {
|
|
29
|
+
if (lockId === undefined) {
|
|
30
30
|
return this.localLocks.has(id)
|
|
31
31
|
} else {
|
|
32
32
|
return this.localLocks.has(id) && this.localLocks.get(id)!.has(lockId)
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
public isRemoteLocked(id:
|
|
37
|
-
if (
|
|
36
|
+
public isRemoteLocked(id: DhtAddress, lockId?: LockID): boolean {
|
|
37
|
+
if (lockId === undefined) {
|
|
38
38
|
return this.remoteLocks.has(id)
|
|
39
39
|
} else {
|
|
40
40
|
if (this.remoteLocks.has(id) && this.remoteLocks.get(id)!.has(lockId)) {
|
|
@@ -45,33 +45,36 @@ export class ConnectionLockHandler {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
private isWeakLocked(id:
|
|
48
|
+
private isWeakLocked(id: DhtAddress): boolean {
|
|
49
49
|
return this.weakLocks.has(id)
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
public isLocked(id:
|
|
52
|
+
public isLocked(id: DhtAddress): boolean {
|
|
53
53
|
return (this.isLocalLocked(id) || this.isRemoteLocked(id) || this.isWeakLocked(id))
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
public addLocalLocked(id:
|
|
56
|
+
public addLocalLocked(id: DhtAddress, lockId: LockID): void {
|
|
57
57
|
if (!this.localLocks.has(id)) {
|
|
58
58
|
this.localLocks.set(id, new Set())
|
|
59
59
|
}
|
|
60
60
|
this.localLocks.get(id)!.add(lockId)
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
public addRemoteLocked(id:
|
|
63
|
+
public addRemoteLocked(id: DhtAddress, lockId: LockID): void {
|
|
64
64
|
if (!this.remoteLocks.has(id)) {
|
|
65
65
|
this.remoteLocks.set(id, new Set())
|
|
66
66
|
}
|
|
67
67
|
this.remoteLocks.get(id)!.add(lockId)
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
public addWeakLocked(id:
|
|
71
|
-
this.weakLocks.
|
|
70
|
+
public addWeakLocked(id: DhtAddress, lockId: LockID): void {
|
|
71
|
+
if (!this.weakLocks.has(id)) {
|
|
72
|
+
this.weakLocks.set(id, new Set())
|
|
73
|
+
}
|
|
74
|
+
this.weakLocks.get(id)!.add(lockId)
|
|
72
75
|
}
|
|
73
76
|
|
|
74
|
-
public removeLocalLocked(id:
|
|
77
|
+
public removeLocalLocked(id: DhtAddress, lockId: LockID): void {
|
|
75
78
|
if (this.localLocks.has(id)) {
|
|
76
79
|
this.localLocks.get(id)?.delete(lockId)
|
|
77
80
|
if (this.localLocks.get(id)?.size === 0) {
|
|
@@ -80,7 +83,7 @@ export class ConnectionLockHandler {
|
|
|
80
83
|
}
|
|
81
84
|
}
|
|
82
85
|
|
|
83
|
-
public removeRemoteLocked(id:
|
|
86
|
+
public removeRemoteLocked(id: DhtAddress, lockId: LockID): void {
|
|
84
87
|
if (this.remoteLocks.has(id)) {
|
|
85
88
|
this.remoteLocks.get(id)?.delete(lockId)
|
|
86
89
|
if (this.remoteLocks.get(id)?.size === 0) {
|
|
@@ -89,11 +92,16 @@ export class ConnectionLockHandler {
|
|
|
89
92
|
}
|
|
90
93
|
}
|
|
91
94
|
|
|
92
|
-
public removeWeakLocked(id:
|
|
93
|
-
this.weakLocks.
|
|
95
|
+
public removeWeakLocked(id: DhtAddress, lockId: LockID): void {
|
|
96
|
+
if (this.weakLocks.has(id)) {
|
|
97
|
+
this.weakLocks.get(id)?.delete(lockId)
|
|
98
|
+
if (this.weakLocks.get(id)?.size === 0) {
|
|
99
|
+
this.weakLocks.delete(id)
|
|
100
|
+
}
|
|
101
|
+
}
|
|
94
102
|
}
|
|
95
103
|
|
|
96
|
-
public clearAllLocks(id:
|
|
104
|
+
public clearAllLocks(id: DhtAddress): void {
|
|
97
105
|
this.localLocks.delete(id)
|
|
98
106
|
this.remoteLocks.delete(id)
|
|
99
107
|
this.weakLocks.delete(id)
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
2
2
|
import { Logger } from '@streamr/utils'
|
|
3
|
-
import {
|
|
4
|
-
areEqualPeerDescriptors,
|
|
5
|
-
keyFromPeerDescriptor,
|
|
6
|
-
peerIdFromPeerDescriptor
|
|
7
|
-
} from '../helpers/peerIdFromPeerDescriptor'
|
|
8
3
|
import { Empty } from '../proto/google/protobuf/empty'
|
|
9
4
|
import {
|
|
10
5
|
DisconnectMode,
|
|
@@ -16,13 +11,13 @@ import {
|
|
|
16
11
|
} from '../proto/packages/dht/protos/DhtRpc'
|
|
17
12
|
import { IConnectionLockRpc } from '../proto/packages/dht/protos/DhtRpc.server'
|
|
18
13
|
import { DhtCallContext } from '../rpc-protocol/DhtCallContext'
|
|
19
|
-
import { PeerIDKey } from '../helpers/PeerID'
|
|
20
14
|
import { getNodeIdOrUnknownFromPeerDescriptor } from './ConnectionManager'
|
|
21
15
|
import { LockID } from './ConnectionLockHandler'
|
|
16
|
+
import { DhtAddress, areEqualPeerDescriptors, getNodeIdFromPeerDescriptor } from '../identifiers'
|
|
22
17
|
|
|
23
18
|
interface ConnectionLockRpcLocalConfig {
|
|
24
|
-
addRemoteLocked: (id:
|
|
25
|
-
removeRemoteLocked: (id:
|
|
19
|
+
addRemoteLocked: (id: DhtAddress, lockId: LockID) => void
|
|
20
|
+
removeRemoteLocked: (id: DhtAddress, lockId: LockID) => void
|
|
26
21
|
closeConnection: (peerDescriptor: PeerDescriptor, gracefulLeave: boolean, reason?: string) => void
|
|
27
22
|
getLocalPeerDescriptor: () => PeerDescriptor
|
|
28
23
|
}
|
|
@@ -39,14 +34,14 @@ export class ConnectionLockRpcLocal implements IConnectionLockRpc {
|
|
|
39
34
|
|
|
40
35
|
async lockRequest(lockRequest: LockRequest, context: ServerCallContext): Promise<LockResponse> {
|
|
41
36
|
const senderPeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
|
|
42
|
-
const remotePeerId = peerIdFromPeerDescriptor(senderPeerDescriptor)
|
|
43
37
|
if (areEqualPeerDescriptors(senderPeerDescriptor, this.config.getLocalPeerDescriptor())) {
|
|
44
38
|
const response: LockResponse = {
|
|
45
39
|
accepted: false
|
|
46
40
|
}
|
|
47
41
|
return response
|
|
48
42
|
}
|
|
49
|
-
|
|
43
|
+
const remoteNodeId = getNodeIdFromPeerDescriptor(senderPeerDescriptor)
|
|
44
|
+
this.config.addRemoteLocked(remoteNodeId, lockRequest.lockId)
|
|
50
45
|
const response: LockResponse = {
|
|
51
46
|
accepted: true
|
|
52
47
|
}
|
|
@@ -55,8 +50,8 @@ export class ConnectionLockRpcLocal implements IConnectionLockRpc {
|
|
|
55
50
|
|
|
56
51
|
async unlockRequest(unlockRequest: UnlockRequest, context: ServerCallContext): Promise<Empty> {
|
|
57
52
|
const senderPeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
|
|
58
|
-
const
|
|
59
|
-
this.config.removeRemoteLocked(
|
|
53
|
+
const nodeId = getNodeIdFromPeerDescriptor(senderPeerDescriptor)
|
|
54
|
+
this.config.removeRemoteLocked(nodeId, unlockRequest.lockId)
|
|
60
55
|
return {}
|
|
61
56
|
}
|
|
62
57
|
|
|
@@ -1,23 +1,13 @@
|
|
|
1
1
|
import { Logger } from '@streamr/utils'
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import * as Err from '../helpers/errors'
|
|
6
|
-
import { getNodeIdFromPeerDescriptor } from '../helpers/peerIdFromPeerDescriptor'
|
|
7
|
-
import { Remote } from '../dht/contact/Remote'
|
|
2
|
+
import { RpcRemote } from '../dht/contact/RpcRemote'
|
|
3
|
+
import { DisconnectMode, DisconnectNotice, LockRequest, UnlockRequest } from '../proto/packages/dht/protos/DhtRpc'
|
|
4
|
+
import { ConnectionLockRpcClient } from '../proto/packages/dht/protos/DhtRpc.client'
|
|
8
5
|
import { LockID } from './ConnectionLockHandler'
|
|
6
|
+
import { getNodeIdFromPeerDescriptor } from '../identifiers'
|
|
9
7
|
|
|
10
8
|
const logger = new Logger(module)
|
|
11
9
|
|
|
12
|
-
export class ConnectionLockRpcRemote extends
|
|
13
|
-
|
|
14
|
-
constructor(
|
|
15
|
-
localPeerDescriptor: PeerDescriptor,
|
|
16
|
-
targetPeerDescriptor: PeerDescriptor,
|
|
17
|
-
client: ProtoRpcClient<IConnectionLockRpcClient>
|
|
18
|
-
) {
|
|
19
|
-
super(localPeerDescriptor, targetPeerDescriptor, 'DUMMY', client)
|
|
20
|
-
}
|
|
10
|
+
export class ConnectionLockRpcRemote extends RpcRemote<ConnectionLockRpcClient> {
|
|
21
11
|
|
|
22
12
|
public async lockRequest(lockId: LockID): Promise<boolean> {
|
|
23
13
|
logger.trace(`Requesting locked connection to ${getNodeIdFromPeerDescriptor(this.getPeerDescriptor())}`)
|
|
@@ -29,7 +19,7 @@ export class ConnectionLockRpcRemote extends Remote<IConnectionLockRpcClient> {
|
|
|
29
19
|
const res = await this.getClient().lockRequest(request, options)
|
|
30
20
|
return res.accepted
|
|
31
21
|
} catch (err) {
|
|
32
|
-
logger.debug(
|
|
22
|
+
logger.debug('Connection lock rejected', { error: err })
|
|
33
23
|
return false
|
|
34
24
|
}
|
|
35
25
|
}
|
|
@@ -53,9 +43,9 @@ export class ConnectionLockRpcRemote extends Remote<IConnectionLockRpcClient> {
|
|
|
53
43
|
disconnectMode
|
|
54
44
|
}
|
|
55
45
|
const options = this.formDhtRpcOptions({
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
timeout: 2000
|
|
46
|
+
connect: false,
|
|
47
|
+
sendIfStopped: true,
|
|
48
|
+
timeout: 2000 // TODO use config option or named constant?
|
|
59
49
|
})
|
|
60
50
|
await this.getClient().gracefulDisconnect(request, options)
|
|
61
51
|
}
|