@streamr/dht 100.0.0-pretestnet.6 → 100.0.0-rc.1
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 +19 -10
- 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 +1 -2
- package/dist/src/connection/webrtc/WebrtcConnector.js +36 -32
- package/dist/src/connection/webrtc/WebrtcConnector.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.d.ts +4 -2
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js +28 -22
- 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 +17 -14
- 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 +24 -12
- 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 +25 -27
- package/src/connection/webrtc/WebrtcConnector.ts +31 -36
- package/src/connection/webrtc/WebrtcConnectorRpcLocal.ts +31 -25
- 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/src/dht/find/Finder.ts
DELETED
|
@@ -1,275 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DataEntry,
|
|
3
|
-
Message,
|
|
4
|
-
MessageType,
|
|
5
|
-
NodeType,
|
|
6
|
-
PeerDescriptor,
|
|
7
|
-
FindRequest,
|
|
8
|
-
RouteMessageAck,
|
|
9
|
-
RouteMessageWrapper
|
|
10
|
-
} from '../../proto/packages/dht/protos/DhtRpc'
|
|
11
|
-
import { PeerID, PeerIDKey } from '../../helpers/PeerID'
|
|
12
|
-
import { RoutingErrors, IRouter } from '../routing/Router'
|
|
13
|
-
import { RoutingMode } from '../routing/RoutingSession'
|
|
14
|
-
import { areEqualPeerDescriptors, peerIdFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
|
|
15
|
-
import { Logger, runAndWaitForEvents3 } from '@streamr/utils'
|
|
16
|
-
import { RoutingRpcCommunicator } from '../../transport/RoutingRpcCommunicator'
|
|
17
|
-
import { FindSessionRpcRemote } from './FindSessionRpcRemote'
|
|
18
|
-
import { v4 } from 'uuid'
|
|
19
|
-
import { FindSession, FindSessionEvents } from './FindSession'
|
|
20
|
-
import { DhtNodeRpcRemote } from '../DhtNodeRpcRemote'
|
|
21
|
-
import { ITransport } from '../../transport/ITransport'
|
|
22
|
-
import { LocalDataStore } from '../store/LocalDataStore'
|
|
23
|
-
import { ListeningRpcCommunicator } from '../../transport/ListeningRpcCommunicator'
|
|
24
|
-
import { FindSessionRpcClient } from '../../proto/packages/dht/protos/DhtRpc.client'
|
|
25
|
-
import { toProtoRpcClient } from '@streamr/proto-rpc'
|
|
26
|
-
import { SortedContactList } from '../contact/SortedContactList'
|
|
27
|
-
import { getPreviousPeer } from '../routing/getPreviousPeer'
|
|
28
|
-
import { createRouteMessageAck } from '../routing/RouterRpcLocal'
|
|
29
|
-
import { ServiceID } from '../../types/ServiceID'
|
|
30
|
-
import { FindRpcLocal } from './FindRpcLocal'
|
|
31
|
-
|
|
32
|
-
interface FinderConfig {
|
|
33
|
-
rpcCommunicator: RoutingRpcCommunicator
|
|
34
|
-
sessionTransport: ITransport
|
|
35
|
-
connections: Map<PeerIDKey, DhtNodeRpcRemote>
|
|
36
|
-
router: IRouter
|
|
37
|
-
localPeerDescriptor: PeerDescriptor
|
|
38
|
-
serviceId: ServiceID
|
|
39
|
-
localDataStore: LocalDataStore
|
|
40
|
-
addContact: (contact: PeerDescriptor, setActive?: boolean) => void
|
|
41
|
-
isPeerCloserToIdThanSelf: (peer1: PeerDescriptor, compareToId: PeerID) => boolean
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export interface IFinder {
|
|
45
|
-
startFind(idToFind: Uint8Array, fetchData?: boolean): Promise<FindResult>
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export interface FindResult { closestNodes: Array<PeerDescriptor>, dataEntries?: Array<DataEntry> }
|
|
49
|
-
|
|
50
|
-
const logger = new Logger(module)
|
|
51
|
-
|
|
52
|
-
export class Finder implements IFinder {
|
|
53
|
-
|
|
54
|
-
private readonly rpcCommunicator: RoutingRpcCommunicator
|
|
55
|
-
private readonly sessionTransport: ITransport
|
|
56
|
-
private readonly connections: Map<PeerIDKey, DhtNodeRpcRemote>
|
|
57
|
-
private readonly router: IRouter
|
|
58
|
-
private readonly localPeerDescriptor: PeerDescriptor
|
|
59
|
-
private readonly serviceId: ServiceID
|
|
60
|
-
private readonly localDataStore: LocalDataStore
|
|
61
|
-
private readonly isPeerCloserToIdThanSelf: (peer1: PeerDescriptor, compareToId: PeerID) => boolean
|
|
62
|
-
private ongoingSessions: Map<string, FindSession> = new Map()
|
|
63
|
-
private stopped = false
|
|
64
|
-
|
|
65
|
-
constructor(config: FinderConfig) {
|
|
66
|
-
this.rpcCommunicator = config.rpcCommunicator
|
|
67
|
-
this.sessionTransport = config.sessionTransport
|
|
68
|
-
this.connections = config.connections
|
|
69
|
-
this.router = config.router
|
|
70
|
-
this.localPeerDescriptor = config.localPeerDescriptor
|
|
71
|
-
this.serviceId = config.serviceId
|
|
72
|
-
this.localDataStore = config.localDataStore
|
|
73
|
-
this.isPeerCloserToIdThanSelf = config.isPeerCloserToIdThanSelf
|
|
74
|
-
this.registerLocalRpcMethods(config)
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
private registerLocalRpcMethods(config: FinderConfig) {
|
|
78
|
-
const rpcLocal = new FindRpcLocal({
|
|
79
|
-
doRouteFindRequest: (routedMessage: RouteMessageWrapper) => this.doRouteFindRequest(routedMessage),
|
|
80
|
-
addContact: (contact: PeerDescriptor, setActive?: boolean) => config.addContact(contact, setActive),
|
|
81
|
-
isMostLikelyDuplicate: (requestId: string) => this.router.isMostLikelyDuplicate(requestId),
|
|
82
|
-
addToDuplicateDetector: (requestId: string) => this.router.addToDuplicateDetector(requestId)
|
|
83
|
-
})
|
|
84
|
-
this.rpcCommunicator.registerRpcMethod(
|
|
85
|
-
RouteMessageWrapper,
|
|
86
|
-
RouteMessageAck,
|
|
87
|
-
'routeFindRequest',
|
|
88
|
-
async (routedMessage: RouteMessageWrapper) => {
|
|
89
|
-
if (this.stopped) {
|
|
90
|
-
return createRouteMessageAck(routedMessage, 'routeFindRequest() service is not running')
|
|
91
|
-
} else {
|
|
92
|
-
return rpcLocal.routeFindRequest(routedMessage)
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
)
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
public async startFind(
|
|
99
|
-
idToFind: Uint8Array,
|
|
100
|
-
fetchData: boolean = false,
|
|
101
|
-
excludedPeer?: PeerDescriptor
|
|
102
|
-
): Promise<FindResult> {
|
|
103
|
-
if (this.stopped) {
|
|
104
|
-
return { closestNodes: [] }
|
|
105
|
-
}
|
|
106
|
-
const sessionId = v4()
|
|
107
|
-
const session = new FindSession({
|
|
108
|
-
serviceId: sessionId,
|
|
109
|
-
transport: this.sessionTransport,
|
|
110
|
-
kademliaIdToFind: idToFind,
|
|
111
|
-
localPeerId: peerIdFromPeerDescriptor(this.localPeerDescriptor),
|
|
112
|
-
waitedRoutingPathCompletions: this.connections.size > 1 ? 2 : 1,
|
|
113
|
-
fetchData
|
|
114
|
-
})
|
|
115
|
-
if (this.connections.size === 0) {
|
|
116
|
-
const data = this.localDataStore.getEntry(PeerID.fromValue(idToFind))
|
|
117
|
-
session.doSendFindResponse(
|
|
118
|
-
[this.localPeerDescriptor],
|
|
119
|
-
[this.localPeerDescriptor],
|
|
120
|
-
data ? Array.from(data.values()) : [],
|
|
121
|
-
true
|
|
122
|
-
)
|
|
123
|
-
return session.getResults()
|
|
124
|
-
}
|
|
125
|
-
const routeMessage = this.wrapFindRequest(idToFind, sessionId, fetchData)
|
|
126
|
-
this.ongoingSessions.set(sessionId, session)
|
|
127
|
-
try {
|
|
128
|
-
await runAndWaitForEvents3<FindSessionEvents>(
|
|
129
|
-
[() => this.doRouteFindRequest(routeMessage, excludedPeer)],
|
|
130
|
-
[[session, 'findCompleted']],
|
|
131
|
-
15000
|
|
132
|
-
)
|
|
133
|
-
} catch (err) {
|
|
134
|
-
logger.debug(`doRouteFindRequest failed with error ${err}`)
|
|
135
|
-
}
|
|
136
|
-
this.findAndReportLocalData(idToFind, fetchData, [], this.localPeerDescriptor, sessionId)
|
|
137
|
-
this.ongoingSessions.delete(sessionId)
|
|
138
|
-
session.stop()
|
|
139
|
-
return session.getResults()
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
private wrapFindRequest(idToFind: Uint8Array, sessionId: string, fetchData: boolean): RouteMessageWrapper {
|
|
143
|
-
const targetDescriptor: PeerDescriptor = {
|
|
144
|
-
kademliaId: idToFind,
|
|
145
|
-
type: NodeType.VIRTUAL
|
|
146
|
-
}
|
|
147
|
-
const request: FindRequest = {
|
|
148
|
-
sessionId,
|
|
149
|
-
fetchData
|
|
150
|
-
}
|
|
151
|
-
const msg: Message = {
|
|
152
|
-
messageType: MessageType.FIND_REQUEST,
|
|
153
|
-
messageId: v4(),
|
|
154
|
-
serviceId: this.serviceId,
|
|
155
|
-
body: {
|
|
156
|
-
oneofKind: 'findRequest',
|
|
157
|
-
findRequest: request
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
const routeMessage: RouteMessageWrapper = {
|
|
161
|
-
message: msg,
|
|
162
|
-
requestId: v4(),
|
|
163
|
-
destinationPeer: targetDescriptor,
|
|
164
|
-
sourcePeer: this.localPeerDescriptor,
|
|
165
|
-
reachableThrough: [],
|
|
166
|
-
routingPath: []
|
|
167
|
-
}
|
|
168
|
-
return routeMessage
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
private findAndReportLocalData(
|
|
172
|
-
idToFind: Uint8Array,
|
|
173
|
-
fetchData: boolean,
|
|
174
|
-
routingPath: PeerDescriptor[],
|
|
175
|
-
sourcePeer: PeerDescriptor,
|
|
176
|
-
sessionId: string
|
|
177
|
-
): boolean {
|
|
178
|
-
if (fetchData) {
|
|
179
|
-
const data = this.localDataStore.getEntry(PeerID.fromValue(idToFind))
|
|
180
|
-
if (data.size > 0) {
|
|
181
|
-
this.sendFindResponse(routingPath, sourcePeer, sessionId, [], data, true)
|
|
182
|
-
return true
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
return false
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
private findLocalData(idToFind: Uint8Array, fetchData: boolean): Map<PeerIDKey, DataEntry> | undefined {
|
|
189
|
-
if (fetchData) {
|
|
190
|
-
return this.localDataStore.getEntry(PeerID.fromValue(idToFind))
|
|
191
|
-
}
|
|
192
|
-
return undefined
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
private sendFindResponse(
|
|
196
|
-
routingPath: PeerDescriptor[],
|
|
197
|
-
targetPeerDescriptor: PeerDescriptor,
|
|
198
|
-
serviceId: ServiceID,
|
|
199
|
-
closestNodes: PeerDescriptor[],
|
|
200
|
-
data: Map<PeerIDKey, DataEntry> | undefined,
|
|
201
|
-
noCloserNodesFound: boolean = false
|
|
202
|
-
): void {
|
|
203
|
-
const dataEntries = data ? Array.from(data.values(), DataEntry.create.bind(DataEntry)) : []
|
|
204
|
-
const isOwnNode = areEqualPeerDescriptors(this.localPeerDescriptor, targetPeerDescriptor)
|
|
205
|
-
if (isOwnNode && this.ongoingSessions.has(serviceId)) {
|
|
206
|
-
this.ongoingSessions.get(serviceId)!
|
|
207
|
-
.doSendFindResponse(routingPath, closestNodes, dataEntries, noCloserNodesFound)
|
|
208
|
-
} else {
|
|
209
|
-
const remoteCommunicator = new ListeningRpcCommunicator(serviceId, this.sessionTransport, { rpcRequestTimeout: 15000 })
|
|
210
|
-
const rpcRemote = new FindSessionRpcRemote(
|
|
211
|
-
this.localPeerDescriptor,
|
|
212
|
-
targetPeerDescriptor,
|
|
213
|
-
serviceId,
|
|
214
|
-
toProtoRpcClient(new FindSessionRpcClient(remoteCommunicator.getRpcClientTransport())),
|
|
215
|
-
10000
|
|
216
|
-
)
|
|
217
|
-
rpcRemote.sendFindResponse(routingPath, closestNodes, dataEntries, noCloserNodesFound)
|
|
218
|
-
remoteCommunicator.destroy()
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
private doRouteFindRequest(routedMessage: RouteMessageWrapper, excludedPeer?: PeerDescriptor): RouteMessageAck {
|
|
223
|
-
if (this.stopped) {
|
|
224
|
-
return createRouteMessageAck(routedMessage, 'DhtNode Stopped')
|
|
225
|
-
}
|
|
226
|
-
const idToFind = peerIdFromPeerDescriptor(routedMessage.destinationPeer!)
|
|
227
|
-
const msg = routedMessage.message
|
|
228
|
-
const findRequest = msg?.body.oneofKind === 'findRequest' ? msg.body.findRequest : undefined
|
|
229
|
-
const closestPeersToDestination = this.getClosestConnections(routedMessage.destinationPeer!.kademliaId, 5)
|
|
230
|
-
const data = this.findLocalData(idToFind.value, findRequest!.fetchData)
|
|
231
|
-
if (areEqualPeerDescriptors(this.localPeerDescriptor, routedMessage.destinationPeer!)) {
|
|
232
|
-
this.sendFindResponse(routedMessage.routingPath, routedMessage.sourcePeer!, findRequest!.sessionId,
|
|
233
|
-
closestPeersToDestination, data, true)
|
|
234
|
-
return createRouteMessageAck(routedMessage)
|
|
235
|
-
}
|
|
236
|
-
const ack = this.router.doRouteMessage(routedMessage, RoutingMode.FIND, excludedPeer)
|
|
237
|
-
if (ack.error === RoutingErrors.NO_CANDIDATES_FOUND) {
|
|
238
|
-
logger.trace(`routeFindRequest Node found no candidates`)
|
|
239
|
-
this.sendFindResponse(routedMessage.routingPath, routedMessage.sourcePeer!, findRequest!.sessionId,
|
|
240
|
-
closestPeersToDestination, data, true)
|
|
241
|
-
} else if (ack.error) {
|
|
242
|
-
return ack
|
|
243
|
-
} else {
|
|
244
|
-
const noCloserContactsFound = (
|
|
245
|
-
closestPeersToDestination.length > 0
|
|
246
|
-
&& getPreviousPeer(routedMessage)
|
|
247
|
-
&& !this.isPeerCloserToIdThanSelf(closestPeersToDestination[0], idToFind)
|
|
248
|
-
)
|
|
249
|
-
this.sendFindResponse(routedMessage.routingPath, routedMessage.sourcePeer!, findRequest!.sessionId,
|
|
250
|
-
closestPeersToDestination, data, noCloserContactsFound)
|
|
251
|
-
}
|
|
252
|
-
return ack
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
private getClosestConnections(kademliaId: Uint8Array, limit: number): PeerDescriptor[] {
|
|
256
|
-
const connectedPeers = Array.from(this.connections.values())
|
|
257
|
-
const closestPeers = new SortedContactList<DhtNodeRpcRemote>(
|
|
258
|
-
PeerID.fromValue(kademliaId),
|
|
259
|
-
limit,
|
|
260
|
-
undefined,
|
|
261
|
-
true,
|
|
262
|
-
undefined
|
|
263
|
-
)
|
|
264
|
-
closestPeers.addContacts(connectedPeers)
|
|
265
|
-
return closestPeers.getClosestContacts(limit).map((peer) => peer.getPeerDescriptor())
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
public stop(): void {
|
|
269
|
-
this.stopped = true
|
|
270
|
-
this.ongoingSessions.forEach((session, _id) => {
|
|
271
|
-
session.stop()
|
|
272
|
-
})
|
|
273
|
-
this.ongoingSessions.clear()
|
|
274
|
-
}
|
|
275
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { RouteMessageWrapper } from '../../proto/packages/dht/protos/DhtRpc'
|
|
2
|
-
import { v4 } from 'uuid'
|
|
3
|
-
import { getNodeIdFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
|
|
4
|
-
import { Remote } from '../contact/Remote'
|
|
5
|
-
import { Logger } from '@streamr/utils'
|
|
6
|
-
import { IFindRpcClient } from '../../proto/packages/dht/protos/DhtRpc.client'
|
|
7
|
-
import { getPreviousPeer } from './getPreviousPeer'
|
|
8
|
-
|
|
9
|
-
const logger = new Logger(module)
|
|
10
|
-
|
|
11
|
-
export class FindRpcRemote extends Remote<IFindRpcClient> {
|
|
12
|
-
|
|
13
|
-
async routeFindRequest(params: RouteMessageWrapper): Promise<boolean> {
|
|
14
|
-
const message: RouteMessageWrapper = {
|
|
15
|
-
destinationPeer: params.destinationPeer,
|
|
16
|
-
sourcePeer: params.sourcePeer,
|
|
17
|
-
message: params.message,
|
|
18
|
-
requestId: params.requestId ?? v4(),
|
|
19
|
-
reachableThrough: params.reachableThrough ?? [],
|
|
20
|
-
routingPath: params.routingPath
|
|
21
|
-
}
|
|
22
|
-
const options = this.formDhtRpcOptions()
|
|
23
|
-
try {
|
|
24
|
-
const ack = await this.getClient().routeFindRequest(message, options)
|
|
25
|
-
if (ack.error.length > 0) {
|
|
26
|
-
logger.debug('Next hop responded with error ' + ack.error)
|
|
27
|
-
return false
|
|
28
|
-
}
|
|
29
|
-
} catch (err) {
|
|
30
|
-
const previousPeer = getPreviousPeer(params)
|
|
31
|
-
const fromNode = previousPeer
|
|
32
|
-
? getNodeIdFromPeerDescriptor(previousPeer)
|
|
33
|
-
: getNodeIdFromPeerDescriptor(params.sourcePeer!)
|
|
34
|
-
// eslint-disable-next-line max-len
|
|
35
|
-
logger.debug(`Failed to send routeFindRequest message from ${fromNode} to ${getNodeIdFromPeerDescriptor(this.getPeerDescriptor())} with: ${err}`)
|
|
36
|
-
return false
|
|
37
|
-
}
|
|
38
|
-
return true
|
|
39
|
-
}
|
|
40
|
-
}
|
package/src/helpers/PeerID.ts
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { BrandedString } from '@streamr/utils'
|
|
2
|
-
import { UUID } from './UUID'
|
|
3
|
-
import { IllegalArguments } from './errors'
|
|
4
|
-
import crypto from 'crypto'
|
|
5
|
-
|
|
6
|
-
export type PeerIDKey = BrandedString<'PeerIDKey'>
|
|
7
|
-
|
|
8
|
-
export class PeerID {
|
|
9
|
-
// avoid creating a new instance for every operation
|
|
10
|
-
private static readonly textEncoder = new TextEncoder()
|
|
11
|
-
private static readonly textDecoder = new TextDecoder()
|
|
12
|
-
|
|
13
|
-
private readonly data!: Uint8Array
|
|
14
|
-
private readonly key: PeerIDKey // precompute often-used form of data
|
|
15
|
-
|
|
16
|
-
protected constructor({ ip, value, stringValue }: { ip?: string, value?: Uint8Array, stringValue?: string } = {}) {
|
|
17
|
-
if (ip) {
|
|
18
|
-
this.data = new Uint8Array(20)
|
|
19
|
-
const ipNum = this.ip2Int(ip)
|
|
20
|
-
const view = new DataView(this.data.buffer)
|
|
21
|
-
view.setInt32(0, ipNum)
|
|
22
|
-
|
|
23
|
-
this.data.set((new UUID()).value, 4)
|
|
24
|
-
} else if (value) {
|
|
25
|
-
this.data = new Uint8Array(value.slice(0))
|
|
26
|
-
} else if (stringValue) {
|
|
27
|
-
const ab = PeerID.textEncoder.encode(stringValue) //toUTF8Array(stringValue)
|
|
28
|
-
this.data = ab
|
|
29
|
-
} else {
|
|
30
|
-
throw new IllegalArguments('Constructor of PeerID must be given either ip, value or stringValue')
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
this.key = Buffer.from(this.data).toString('hex') as PeerIDKey
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
static fromIp(ip: string): PeerID {
|
|
37
|
-
return new PeerID({ ip })
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
static fromValue(value: Uint8Array): PeerID {
|
|
41
|
-
return new PeerID({ value })
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
static fromKey(value: PeerIDKey): PeerID {
|
|
45
|
-
return new PeerID({ value: Buffer.from(value, 'hex') })
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
static fromString(stringValue: string): PeerID {
|
|
49
|
-
return new PeerID({ stringValue })
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// TODO convert to static method?
|
|
53
|
-
// eslint-disable-next-line class-methods-use-this
|
|
54
|
-
private ip2Int(ip: string): number {
|
|
55
|
-
return ip.split('.').map((octet, index, array) => {
|
|
56
|
-
return parseInt(octet) * Math.pow(256, (array.length - index - 1))
|
|
57
|
-
}).reduce((prev, curr) => {
|
|
58
|
-
return prev + curr
|
|
59
|
-
})
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
equals(other: PeerID): boolean {
|
|
63
|
-
return (Buffer.compare(this.data, other.value) === 0)
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
toString(): string {
|
|
67
|
-
return PeerID.textDecoder.decode(this.data) //utf8ArrayToString(this.data)
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
toKey(): PeerIDKey {
|
|
71
|
-
return this.key
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
get value(): Uint8Array {
|
|
75
|
-
return this.data
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
hasSmallerHashThan(other: PeerID): boolean {
|
|
79
|
-
const myId = this.toKey()
|
|
80
|
-
const theirId = other.toKey()
|
|
81
|
-
return PeerID.offeringHash(myId + ',' + theirId) < PeerID.offeringHash(theirId + ',' + myId)
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
private static offeringHash(idPair: string): number {
|
|
85
|
-
const buffer = crypto.createHash('md5').update(idPair).digest()
|
|
86
|
-
return buffer.readInt32LE(0)
|
|
87
|
-
}
|
|
88
|
-
}
|
package/src/helpers/UUID.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { v4, parse, stringify } from 'uuid'
|
|
2
|
-
import { binaryToHex } from '@streamr/utils'
|
|
3
|
-
|
|
4
|
-
export class UUID {
|
|
5
|
-
private buf: Uint8Array
|
|
6
|
-
|
|
7
|
-
constructor(other?: (UUID | Uint8Array | string)) {
|
|
8
|
-
if (!other) {
|
|
9
|
-
this.buf = new Uint8Array(16)
|
|
10
|
-
v4(null, this.buf)
|
|
11
|
-
} else if (other.constructor === UUID) {
|
|
12
|
-
this.buf = other.buf
|
|
13
|
-
} else if (typeof other === 'string') {
|
|
14
|
-
this.buf = new Uint8Array(parse(other))
|
|
15
|
-
} else {
|
|
16
|
-
this.buf = other as Uint8Array
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
toString(): string {
|
|
21
|
-
return stringify(this.buf)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
toHex(): string {
|
|
25
|
-
return binaryToHex(this.buf)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
equals(other: UUID): boolean {
|
|
29
|
-
return (Buffer.compare(this.buf, other.value) === 0)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
get value(): Uint8Array {
|
|
33
|
-
return this.buf
|
|
34
|
-
}
|
|
35
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { binaryToHex } from '@streamr/utils'
|
|
2
|
-
import { PeerDescriptor } from '../proto/packages/dht/protos/DhtRpc'
|
|
3
|
-
import { PeerID, PeerIDKey } from './PeerID'
|
|
4
|
-
|
|
5
|
-
export const peerIdFromPeerDescriptor = (peerDescriptor: PeerDescriptor): PeerID => {
|
|
6
|
-
return PeerID.fromValue(peerDescriptor.kademliaId)
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
// TODO could move getNodeIdFromPeerDescriptor (and NodeID) from trackerless-network
|
|
10
|
-
export const getNodeIdFromPeerDescriptor = (peerDescriptor: PeerDescriptor): string => {
|
|
11
|
-
return binaryToHex(peerDescriptor.kademliaId)
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export const keyFromPeerDescriptor = (peerDescriptor: PeerDescriptor): PeerIDKey => {
|
|
15
|
-
return PeerID.fromValue(peerDescriptor.kademliaId).toKey()
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const areEqualPeerDescriptors = (peerDescriptor1: PeerDescriptor, peerDescriptor2: PeerDescriptor): boolean => {
|
|
19
|
-
return peerIdFromPeerDescriptor(peerDescriptor1).equals(peerIdFromPeerDescriptor(peerDescriptor2))
|
|
20
|
-
}
|
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
2
|
-
import { LatencyType, Simulator } from '../../src/connection/simulator/Simulator'
|
|
3
|
-
import { DhtNode } from '../../src/dht/DhtNode'
|
|
4
|
-
import { NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
5
|
-
import { createMockConnectionDhtNode, waitNodesReadyForTesting } from '../utils/utils'
|
|
6
|
-
import { execSync } from 'child_process'
|
|
7
|
-
import fs from 'fs'
|
|
8
|
-
import { Logger } from '@streamr/utils'
|
|
9
|
-
import { PeerID } from '../../src/helpers/PeerID'
|
|
10
|
-
import { getNodeIdFromPeerDescriptor, keyFromPeerDescriptor, peerIdFromPeerDescriptor } from '../../src/helpers/peerIdFromPeerDescriptor'
|
|
11
|
-
import { Any } from '../../src/proto/google/protobuf/any'
|
|
12
|
-
import { SortedContactList } from '../../src/dht/contact/SortedContactList'
|
|
13
|
-
import { Contact } from '../../src/dht/contact/Contact'
|
|
14
|
-
|
|
15
|
-
const logger = new Logger(module)
|
|
16
|
-
|
|
17
|
-
jest.setTimeout(60000)
|
|
18
|
-
|
|
19
|
-
describe('Migrating data from node to node in DHT', () => {
|
|
20
|
-
let entryPoint: DhtNode
|
|
21
|
-
let nodes: DhtNode[]
|
|
22
|
-
let entrypointDescriptor: PeerDescriptor
|
|
23
|
-
const simulator = new Simulator(LatencyType.FIXED, 20)
|
|
24
|
-
const NUM_NODES = 100
|
|
25
|
-
const MAX_CONNECTIONS = 80
|
|
26
|
-
const K = 8
|
|
27
|
-
|
|
28
|
-
const nodesById: Map<string, DhtNode> = new Map()
|
|
29
|
-
|
|
30
|
-
if (!fs.existsSync('test/data/nodeids.json')) {
|
|
31
|
-
console.log('ground truth data does not exist yet, generating..')
|
|
32
|
-
execSync('npm run prepare-kademlia-simulation')
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const dhtIds: Array<{ type: string, data: Array<number> }> = JSON.parse(fs.readFileSync('test/data/nodeids.json').toString())
|
|
36
|
-
/*
|
|
37
|
-
const getRandomNode = () => {
|
|
38
|
-
return nodes[Math.floor(Math.random() * nodes.length)]
|
|
39
|
-
}
|
|
40
|
-
*/
|
|
41
|
-
beforeEach(async () => {
|
|
42
|
-
nodes = []
|
|
43
|
-
const entryPointId = '0'
|
|
44
|
-
entryPoint = await createMockConnectionDhtNode(entryPointId, simulator,
|
|
45
|
-
Uint8Array.from(dhtIds[0].data), K, MAX_CONNECTIONS)
|
|
46
|
-
nodes.push(entryPoint)
|
|
47
|
-
nodesById.set(entryPoint.getNodeId().toKey(), entryPoint)
|
|
48
|
-
|
|
49
|
-
entrypointDescriptor = {
|
|
50
|
-
kademliaId: entryPoint.getNodeId().value,
|
|
51
|
-
type: NodeType.NODEJS
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
nodes.push(entryPoint)
|
|
55
|
-
|
|
56
|
-
for (let i = 1; i < NUM_NODES; i++) {
|
|
57
|
-
const nodeId = `${i}`
|
|
58
|
-
|
|
59
|
-
const node = await createMockConnectionDhtNode(nodeId, simulator,
|
|
60
|
-
Uint8Array.from(dhtIds[i].data), K, MAX_CONNECTIONS)
|
|
61
|
-
nodesById.set(node.getNodeId().toKey(), node)
|
|
62
|
-
nodes.push(node)
|
|
63
|
-
}
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
afterEach(async () => {
|
|
67
|
-
await Promise.all([
|
|
68
|
-
...nodes.map(async (node) => await node.stop())
|
|
69
|
-
])
|
|
70
|
-
logger.info('nodes stopped')
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
afterAll(async () => {
|
|
74
|
-
simulator.stop()
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
it('Data migrates to the closest node no matter where it is stored', async () => {
|
|
78
|
-
const dataKey = PeerID.fromString('3232323e12r31r3')
|
|
79
|
-
const data = Any.pack(entrypointDescriptor, PeerDescriptor)
|
|
80
|
-
|
|
81
|
-
// calculate offline which node is closest to the data
|
|
82
|
-
|
|
83
|
-
const sortedList = new SortedContactList<Contact>(dataKey, 10000)
|
|
84
|
-
|
|
85
|
-
nodes.forEach((node) => {
|
|
86
|
-
sortedList.addContact(new Contact(node.getLocalPeerDescriptor())
|
|
87
|
-
)
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
const closest = sortedList.getAllContacts()
|
|
91
|
-
|
|
92
|
-
logger.info('Nodes sorted according to distance to data are: ')
|
|
93
|
-
closest.forEach((contact) => {
|
|
94
|
-
logger.info(getNodeIdFromPeerDescriptor(contact.getPeerDescriptor()))
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
logger.info('node 0 joining to the DHT')
|
|
98
|
-
|
|
99
|
-
await nodes[0].joinDht([entrypointDescriptor])
|
|
100
|
-
|
|
101
|
-
logger.info('storing data to node 0')
|
|
102
|
-
const successfulStorers = await nodes[0].storeDataToDht(dataKey.value, data)
|
|
103
|
-
expect(successfulStorers.length).toBe(1)
|
|
104
|
-
logger.info('data successfully stored to node 0')
|
|
105
|
-
|
|
106
|
-
logger.info('Nodes sorted according to distance to data with storing nodes marked are: ')
|
|
107
|
-
|
|
108
|
-
closest.forEach((contact) => {
|
|
109
|
-
const node = nodesById.get(PeerID.fromValue(contact.getPeerDescriptor().kademliaId).toKey())!
|
|
110
|
-
let hasDataMarker = ''
|
|
111
|
-
|
|
112
|
-
// @ts-expect-error private field
|
|
113
|
-
if (node.localDataStore.getEntry(dataKey)) {
|
|
114
|
-
hasDataMarker = '<-'
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// eslint-disable-next-line max-len
|
|
118
|
-
logger.info(peerIdFromPeerDescriptor(contact.getPeerDescriptor()) + ' ' + getNodeIdFromPeerDescriptor(node.getLocalPeerDescriptor()) + hasDataMarker)
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
logger.info(NUM_NODES + ' nodes joining layer0 DHT')
|
|
122
|
-
await Promise.all(
|
|
123
|
-
nodes.map((node) => {
|
|
124
|
-
if (keyFromPeerDescriptor(node.getLocalPeerDescriptor()) != '0') {
|
|
125
|
-
node.joinDht([entrypointDescriptor])
|
|
126
|
-
}
|
|
127
|
-
})
|
|
128
|
-
)
|
|
129
|
-
|
|
130
|
-
logger.info('completed ' + NUM_NODES + ' nodes joining layer0 DHT')
|
|
131
|
-
|
|
132
|
-
await waitNodesReadyForTesting(nodes)
|
|
133
|
-
|
|
134
|
-
logger.info('After join of 99 nodes: nodes sorted according to distance to data with storing nodes marked are: ')
|
|
135
|
-
|
|
136
|
-
closest.forEach((contact) => {
|
|
137
|
-
const node = nodesById.get(PeerID.fromValue(contact.getPeerDescriptor().kademliaId).toKey())!
|
|
138
|
-
let hasDataMarker = ''
|
|
139
|
-
|
|
140
|
-
// @ts-expect-error private field
|
|
141
|
-
|
|
142
|
-
if (node.localDataStore.getEntry(dataKey)) {
|
|
143
|
-
hasDataMarker = '<-'
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
logger.info(getNodeIdFromPeerDescriptor(node.getLocalPeerDescriptor()) + hasDataMarker)
|
|
147
|
-
})
|
|
148
|
-
|
|
149
|
-
const closestNode = nodesById.get(PeerID.fromValue(closest[0].getPeerDescriptor().kademliaId).toKey())!
|
|
150
|
-
|
|
151
|
-
// @ts-expect-error private field
|
|
152
|
-
expect(closestNode.localDataStore.getEntry(dataKey)).toBeTruthy()
|
|
153
|
-
}, 180000)
|
|
154
|
-
|
|
155
|
-
it('Data migrates to the last remaining node if all other nodes leave gracefully', async () => {
|
|
156
|
-
const dataKey = PeerID.fromString('3232323e12r31r3')
|
|
157
|
-
const data = Any.pack(entrypointDescriptor, PeerDescriptor)
|
|
158
|
-
|
|
159
|
-
logger.info(NUM_NODES + ' nodes joining layer0 DHT')
|
|
160
|
-
await Promise.all(
|
|
161
|
-
nodes.map((node) => {
|
|
162
|
-
node.joinDht([entrypointDescriptor])
|
|
163
|
-
})
|
|
164
|
-
)
|
|
165
|
-
|
|
166
|
-
logger.info('completed ' + NUM_NODES + ' nodes joining layer0 DHT')
|
|
167
|
-
|
|
168
|
-
await waitNodesReadyForTesting(nodes)
|
|
169
|
-
|
|
170
|
-
const randomIndex = Math.floor(Math.random() * nodes.length)
|
|
171
|
-
logger.info('storing data to a random node: ' + randomIndex)
|
|
172
|
-
|
|
173
|
-
const successfulStorers = await nodes[randomIndex].storeDataToDht(dataKey.value, data)
|
|
174
|
-
|
|
175
|
-
logger.info('data successfully stored to ' + successfulStorers + ' nodes')
|
|
176
|
-
|
|
177
|
-
const randomIndices = []
|
|
178
|
-
for (let i = 0; i < nodes.length; i++) {
|
|
179
|
-
randomIndices.push(i)
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
console.error(randomIndices)
|
|
183
|
-
while (randomIndices.length > 1) {
|
|
184
|
-
const index = Math.floor(Math.random() * randomIndices.length)
|
|
185
|
-
const nodeIndex = randomIndices[index]
|
|
186
|
-
randomIndices.splice(index, 1)
|
|
187
|
-
|
|
188
|
-
logger.info('Stopping node ' + nodeIndex + ' ' +
|
|
189
|
-
// @ts-expect-error private field
|
|
190
|
-
(nodes[nodeIndex].localDataStore.getEntry(dataKey) ? ', has data' : ' does not have data'))
|
|
191
|
-
|
|
192
|
-
await nodes[nodeIndex].stop()
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
logger.info('after random graceful leaving, node ' + randomIndices[0] + ' is left')
|
|
196
|
-
|
|
197
|
-
// @ts-expect-error private field
|
|
198
|
-
logger.info('data of ' + randomIndices[0] + ' was ' + nodes[randomIndices[0]].localDataStore.getEntry(dataKey))
|
|
199
|
-
|
|
200
|
-
// @ts-expect-error private field
|
|
201
|
-
expect(nodes[randomIndices[0]].localDataStore.getEntry(dataKey)).toBeTruthy()
|
|
202
|
-
|
|
203
|
-
}, 180000)
|
|
204
|
-
})
|