@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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// @generated by protobuf-ts 2.9.
|
|
1
|
+
// @generated by protobuf-ts 2.9.3 with parameter server_generic,generate_dependencies,long_type_number
|
|
2
2
|
// @generated from protobuf file "packages/proto-rpc/protos/ProtoRpc.proto" (package "protorpc", syntax proto3)
|
|
3
3
|
// tslint:disable
|
|
4
4
|
import { MessageType } from "@protobuf-ts/runtime";
|
|
@@ -6,9 +6,9 @@ export class DhtCallContext extends ProtoCallContext implements DhtRpcOptions {
|
|
|
6
6
|
// used by client
|
|
7
7
|
targetDescriptor?: PeerDescriptor
|
|
8
8
|
sourceDescriptor?: PeerDescriptor
|
|
9
|
-
notification?: boolean
|
|
10
9
|
clientId?: number
|
|
11
|
-
|
|
10
|
+
connect?: boolean
|
|
11
|
+
sendIfStopped?: boolean
|
|
12
12
|
//used in incoming calls
|
|
13
13
|
incomingSourceDescriptor?: PeerDescriptor
|
|
14
14
|
}
|
|
@@ -4,7 +4,16 @@ export interface TransportEvents {
|
|
|
4
4
|
disconnected: (peerDescriptor: PeerDescriptor, gracefulLeave: boolean) => void
|
|
5
5
|
message: (message: Message) => void
|
|
6
6
|
connected: (peerDescriptor: PeerDescriptor) => void
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface SendOptions {
|
|
10
|
+
connect: boolean
|
|
11
|
+
sendIfStopped: boolean
|
|
12
|
+
}
|
|
7
13
|
|
|
14
|
+
export const DEFAULT_SEND_OPTIONS = {
|
|
15
|
+
connect: true,
|
|
16
|
+
sendIfStopped: false
|
|
8
17
|
}
|
|
9
18
|
|
|
10
19
|
export interface ITransport {
|
|
@@ -21,8 +30,8 @@ export interface ITransport {
|
|
|
21
30
|
off<T extends keyof TransportEvents>(eventName: T, listener: (peerDescriptor: PeerDescriptor) => void): void
|
|
22
31
|
off<T extends keyof TransportEvents>(eventName: T, listener: (peerDescriptor: PeerDescriptor, gracefulLeave: boolean) => void): void
|
|
23
32
|
|
|
24
|
-
send(msg: Message,
|
|
33
|
+
send(msg: Message, opts?: SendOptions): Promise<void>
|
|
25
34
|
getLocalPeerDescriptor(): PeerDescriptor
|
|
26
|
-
|
|
35
|
+
getConnections(): PeerDescriptor[]
|
|
27
36
|
stop(): void | Promise<void>
|
|
28
37
|
}
|
|
@@ -9,7 +9,7 @@ export class ListeningRpcCommunicator extends RoutingRpcCommunicator {
|
|
|
9
9
|
private readonly listener: (msg: Message) => void
|
|
10
10
|
|
|
11
11
|
constructor(ownServiceId: ServiceID, transport: ITransport, config?: RpcCommunicatorConfig) {
|
|
12
|
-
super(ownServiceId, transport.send, config)
|
|
12
|
+
super(ownServiceId, (msg, opts) => transport.send(msg, opts), config)
|
|
13
13
|
this.listener = (msg: Message) => {
|
|
14
14
|
this.handleMessageFromPeer(msg)
|
|
15
15
|
}
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import { Message,
|
|
1
|
+
import { Message, PeerDescriptor } from '../proto/packages/dht/protos/DhtRpc'
|
|
2
2
|
import { v4 } from 'uuid'
|
|
3
3
|
import { RpcCommunicator, RpcCommunicatorConfig } from '@streamr/proto-rpc'
|
|
4
4
|
import { DhtCallContext } from '../rpc-protocol/DhtCallContext'
|
|
5
5
|
import { RpcMessage } from '../proto/packages/proto-rpc/protos/ProtoRpc'
|
|
6
6
|
import { ServiceID } from '../types/ServiceID'
|
|
7
|
+
import { DEFAULT_SEND_OPTIONS, SendOptions } from './ITransport'
|
|
7
8
|
|
|
8
|
-
export class RoutingRpcCommunicator extends RpcCommunicator {
|
|
9
|
+
export class RoutingRpcCommunicator extends RpcCommunicator<DhtCallContext> {
|
|
9
10
|
private ownServiceId: ServiceID
|
|
10
|
-
private sendFn: (msg: Message,
|
|
11
|
+
private sendFn: (msg: Message, opts: SendOptions) => Promise<void>
|
|
11
12
|
|
|
12
13
|
constructor(
|
|
13
14
|
ownServiceId: ServiceID,
|
|
14
|
-
sendFn: (msg: Message,
|
|
15
|
+
sendFn: (msg: Message, opts: SendOptions) => Promise<void>,
|
|
15
16
|
config?: RpcCommunicatorConfig
|
|
16
17
|
) {
|
|
17
18
|
super(config)
|
|
@@ -34,25 +35,31 @@ export class RoutingRpcCommunicator extends RpcCommunicator {
|
|
|
34
35
|
oneofKind: 'rpcMessage',
|
|
35
36
|
rpcMessage: msg
|
|
36
37
|
},
|
|
37
|
-
messageType: MessageType.RPC,
|
|
38
38
|
targetDescriptor
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
41
|
+
// TODO maybe sendOptions could be a separate block inside callContext
|
|
42
|
+
const sendOpts = (msg.header.response !== undefined)
|
|
43
|
+
? {
|
|
44
|
+
// typically we already have a connection, but if it has disconnected for some reason
|
|
45
|
+
// the receiver could have gone offline (or it is no longer a neighbor) and therefore there
|
|
46
|
+
// is no point in trying form a new connection
|
|
47
|
+
connect: false,
|
|
48
|
+
// TODO maybe this options could be removed?
|
|
49
|
+
sendIfStopped: true
|
|
50
|
+
} : {
|
|
51
|
+
connect: callContext?.connect ?? DEFAULT_SEND_OPTIONS.connect,
|
|
52
|
+
sendIfStopped: callContext?.sendIfStopped ?? DEFAULT_SEND_OPTIONS.sendIfStopped
|
|
53
|
+
}
|
|
54
|
+
return this.sendFn(message, sendOpts)
|
|
49
55
|
})
|
|
50
56
|
}
|
|
51
57
|
|
|
52
58
|
public handleMessageFromPeer(message: Message): void {
|
|
53
|
-
if (message.serviceId
|
|
59
|
+
if (message.serviceId === this.ownServiceId && message.body.oneofKind === 'rpcMessage') {
|
|
54
60
|
const context = new DhtCallContext()
|
|
55
61
|
context.incomingSourceDescriptor = message.sourceDescriptor
|
|
62
|
+
// TODO should we have some handling for this floating promise?
|
|
56
63
|
this.handleIncomingMessage(message.body.rpcMessage, context)
|
|
57
64
|
}
|
|
58
65
|
}
|
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
import KBucket from 'k-bucket'
|
|
4
4
|
import { range } from 'lodash'
|
|
5
|
+
import { DhtAddressRaw } from '../src/identifiers'
|
|
5
6
|
|
|
6
|
-
const compareIds = (id1:
|
|
7
|
+
const compareIds = (id1: DhtAddressRaw, id2: DhtAddressRaw) => {
|
|
7
8
|
const sorted = [id1, id2].sort()
|
|
8
9
|
return KBucket.distance(sorted[0], sorted[1])
|
|
9
10
|
}
|
|
10
11
|
|
|
11
|
-
const generateIDs = (count: number):
|
|
12
|
+
const generateIDs = (count: number): DhtAddressRaw[] => {
|
|
12
13
|
return range(count).map((i) => new Uint8Array([i, 1, 1]))
|
|
13
14
|
}
|
|
14
15
|
|
|
@@ -1,26 +1,21 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
2
|
import { LatencyType, Simulator } from '../../src/connection/simulator/Simulator'
|
|
3
3
|
import { DhtNode } from '../../src/dht/DhtNode'
|
|
4
|
-
import { NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
5
4
|
import { createMockConnectionDhtNode } from '../utils/utils'
|
|
6
5
|
import { execSync } from 'child_process'
|
|
7
6
|
import fs from 'fs'
|
|
8
|
-
import { PeerID } from '../../src/helpers/PeerID'
|
|
9
|
-
import { getNodeIdFromPeerDescriptor, peerIdFromPeerDescriptor } from '../../src/helpers/peerIdFromPeerDescriptor'
|
|
10
7
|
import { Logger, wait } from '@streamr/utils'
|
|
11
8
|
import { debugVars } from '../../src/helpers/debugHelpers'
|
|
9
|
+
import { getDhtAddressFromRaw, getNodeIdFromPeerDescriptor } from '../../src/identifiers'
|
|
12
10
|
|
|
13
11
|
const logger = new Logger(module)
|
|
14
12
|
|
|
15
13
|
describe('Find correctness', () => {
|
|
16
14
|
let entryPoint: DhtNode
|
|
17
15
|
let nodes: DhtNode[]
|
|
18
|
-
let entrypointDescriptor: PeerDescriptor
|
|
19
16
|
const simulator = new Simulator(LatencyType.NONE)
|
|
20
17
|
const NUM_NODES = 1000
|
|
21
18
|
|
|
22
|
-
const nodeIndicesById: Record<string, number> = {}
|
|
23
|
-
|
|
24
19
|
if (!fs.existsSync('test/data/nodeids.json')) {
|
|
25
20
|
console.log('ground truth data does not exist yet, generating..')
|
|
26
21
|
execSync('npm run prepare-kademlia-simulation')
|
|
@@ -31,20 +26,10 @@ describe('Find correctness', () => {
|
|
|
31
26
|
beforeEach(async () => {
|
|
32
27
|
|
|
33
28
|
nodes = []
|
|
34
|
-
|
|
35
|
-
entryPoint = await createMockConnectionDhtNode(entryPointId, simulator, Uint8Array.from(dhtIds[0].data), undefined)
|
|
36
|
-
nodes.push(entryPoint)
|
|
37
|
-
nodeIndicesById[entryPoint.getNodeId().toKey()] = 0
|
|
38
|
-
entrypointDescriptor = {
|
|
39
|
-
kademliaId: entryPoint.getNodeId().value,
|
|
40
|
-
type: NodeType.NODEJS
|
|
41
|
-
}
|
|
29
|
+
entryPoint = await createMockConnectionDhtNode(simulator, getDhtAddressFromRaw(Uint8Array.from(dhtIds[0].data)), undefined)
|
|
42
30
|
|
|
43
31
|
for (let i = 1; i < NUM_NODES; i++) {
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
const node = await createMockConnectionDhtNode(nodeId, simulator, Uint8Array.from(dhtIds[i].data), undefined)
|
|
47
|
-
nodeIndicesById[node.getNodeId().toKey()] = i
|
|
32
|
+
const node = await createMockConnectionDhtNode(simulator, getDhtAddressFromRaw(Uint8Array.from(dhtIds[i].data)), undefined)
|
|
48
33
|
nodes.push(node)
|
|
49
34
|
}
|
|
50
35
|
})
|
|
@@ -57,10 +42,10 @@ describe('Find correctness', () => {
|
|
|
57
42
|
})
|
|
58
43
|
|
|
59
44
|
it('Entrypoint can find a node from the network (exact match)', async () => {
|
|
60
|
-
await entryPoint.joinDht([
|
|
45
|
+
await entryPoint.joinDht([entryPoint.getLocalPeerDescriptor()])
|
|
61
46
|
|
|
62
47
|
await Promise.all(
|
|
63
|
-
nodes.map((node) => node.joinDht([
|
|
48
|
+
nodes.map((node) => node.joinDht([entryPoint.getLocalPeerDescriptor()]))
|
|
64
49
|
)
|
|
65
50
|
|
|
66
51
|
logger.info('waiting 120s')
|
|
@@ -71,17 +56,17 @@ describe('Find correctness', () => {
|
|
|
71
56
|
logger.info('waiting over')
|
|
72
57
|
|
|
73
58
|
nodes.forEach((node) => logger.info(getNodeIdFromPeerDescriptor(node.getLocalPeerDescriptor()) + ': connections:' +
|
|
74
|
-
node.
|
|
75
|
-
+ ', localLocked: ' + node.
|
|
76
|
-
+ ', remoteLocked: ' + node.
|
|
77
|
-
+ ', weakLocked: ' + node.
|
|
59
|
+
node.getConnectionCount() + ', kbucket: ' + node.getNeighborCount()
|
|
60
|
+
+ ', localLocked: ' + node.getLocalLockedConnectionCount()
|
|
61
|
+
+ ', remoteLocked: ' + node.getRemoteLockedConnectionCount()
|
|
62
|
+
+ ', weakLocked: ' + node.getWeakLockedConnectionCount()))
|
|
78
63
|
|
|
79
64
|
logger.info('starting find')
|
|
80
|
-
const
|
|
81
|
-
const
|
|
65
|
+
const targetId = Uint8Array.from(dhtIds[9].data)
|
|
66
|
+
const closestNodes = await nodes[159].findClosestNodesFromDht(getDhtAddressFromRaw(targetId))
|
|
82
67
|
logger.info('find over')
|
|
83
|
-
expect(
|
|
84
|
-
expect(
|
|
68
|
+
expect(closestNodes).toBeGreaterThanOrEqual(5)
|
|
69
|
+
expect(getDhtAddressFromRaw(targetId)).toEqual(getNodeIdFromPeerDescriptor(closestNodes[0]))
|
|
85
70
|
|
|
86
71
|
}, 180000)
|
|
87
72
|
})
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
2
|
import { Simulator } from '../../src/connection/simulator/Simulator'
|
|
3
3
|
import { DhtNode } from '../../src/dht/DhtNode'
|
|
4
|
-
import { PeerID } from '../../src/helpers/PeerID'
|
|
5
|
-
import { getNodeIdFromPeerDescriptor } from '../../src/helpers/peerIdFromPeerDescriptor'
|
|
6
|
-
import { NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
7
4
|
import { createMockConnectionDhtNode } from '../utils/utils'
|
|
8
5
|
import { execSync } from 'child_process'
|
|
9
6
|
import fs from 'fs'
|
|
7
|
+
import { DhtAddress, getDhtAddressFromRaw, getNodeIdFromPeerDescriptor } from '../../src/identifiers'
|
|
8
|
+
import { Logger } from '@streamr/utils'
|
|
9
|
+
|
|
10
|
+
const logger = new Logger(module)
|
|
10
11
|
|
|
11
12
|
describe('Kademlia correctness', () => {
|
|
12
13
|
let entryPoint: DhtNode
|
|
13
14
|
let nodes: DhtNode[]
|
|
14
|
-
let entrypointDescriptor: PeerDescriptor
|
|
15
15
|
const simulator = new Simulator()
|
|
16
|
-
const NUM_NODES =
|
|
16
|
+
const NUM_NODES = 200
|
|
17
17
|
|
|
18
|
-
const nodeIndicesById: Record<
|
|
18
|
+
const nodeIndicesById: Record<DhtAddress, number> = {}
|
|
19
19
|
|
|
20
20
|
if (!fs.existsSync('test/data/nodeids.json')) {
|
|
21
21
|
console.log('gound truth data does not exist yet, generating..')
|
|
@@ -27,22 +27,14 @@ describe('Kademlia correctness', () => {
|
|
|
27
27
|
= JSON.parse(fs.readFileSync('test/data/orderedneighbors.json').toString())
|
|
28
28
|
|
|
29
29
|
beforeEach(async () => {
|
|
30
|
-
|
|
31
30
|
nodes = []
|
|
32
|
-
|
|
33
|
-
entryPoint = await createMockConnectionDhtNode(entryPointId, simulator, Uint8Array.from(dhtIds[0].data), 8)
|
|
31
|
+
entryPoint = await createMockConnectionDhtNode(simulator, getDhtAddressFromRaw(Uint8Array.from(dhtIds[0].data)), 8)
|
|
34
32
|
nodes.push(entryPoint)
|
|
35
|
-
nodeIndicesById[entryPoint.getNodeId()
|
|
36
|
-
entrypointDescriptor = {
|
|
37
|
-
kademliaId: entryPoint.getNodeId().value,
|
|
38
|
-
type: NodeType.NODEJS
|
|
39
|
-
}
|
|
33
|
+
nodeIndicesById[entryPoint.getNodeId()] = 0
|
|
40
34
|
|
|
41
35
|
for (let i = 1; i < NUM_NODES; i++) {
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
const node = await createMockConnectionDhtNode(nodeId, simulator, Uint8Array.from(dhtIds[i].data))
|
|
45
|
-
nodeIndicesById[node.getNodeId().toKey()] = i
|
|
36
|
+
const node = await createMockConnectionDhtNode(simulator, getDhtAddressFromRaw(Uint8Array.from(dhtIds[i].data)))
|
|
37
|
+
nodeIndicesById[node.getNodeId()] = i
|
|
46
38
|
nodes.push(node)
|
|
47
39
|
}
|
|
48
40
|
})
|
|
@@ -50,16 +42,20 @@ describe('Kademlia correctness', () => {
|
|
|
50
42
|
afterEach(async () => {
|
|
51
43
|
await Promise.all([
|
|
52
44
|
entryPoint.stop(),
|
|
53
|
-
...nodes.map(
|
|
45
|
+
...nodes.map((node) => node.stop())
|
|
54
46
|
])
|
|
55
47
|
})
|
|
56
48
|
|
|
57
49
|
it('Can find correct neighbors', async () => {
|
|
58
|
-
await entryPoint.joinDht([
|
|
50
|
+
await entryPoint.joinDht([entryPoint.getLocalPeerDescriptor()])
|
|
59
51
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
52
|
+
for (let i = 1; i < NUM_NODES; i++) {
|
|
53
|
+
// time to join the network
|
|
54
|
+
const startTimestamp = Date.now()
|
|
55
|
+
await nodes[i].joinDht([entryPoint.getLocalPeerDescriptor()])
|
|
56
|
+
const endTimestamp = Date.now()
|
|
57
|
+
logger.info('Node ' + i + ' joined in ' + (endTimestamp - startTimestamp) + ' ms')
|
|
58
|
+
}
|
|
63
59
|
|
|
64
60
|
let minimumCorrectNeighbors = Number.MAX_SAFE_INTEGER
|
|
65
61
|
let sumCorrectNeighbors = 0
|
|
@@ -72,17 +68,17 @@ describe('Kademlia correctness', () => {
|
|
|
72
68
|
groundTruthString += groundTruth[i + ''][j].name + ','
|
|
73
69
|
}
|
|
74
70
|
|
|
75
|
-
const kademliaNeighbors = nodes[i].getClosestContacts().map((p) =>
|
|
71
|
+
const kademliaNeighbors = nodes[i].getClosestContacts(8).map((p) => getNodeIdFromPeerDescriptor(p))
|
|
76
72
|
|
|
77
73
|
let kadString = 'kademliaNeighbors: '
|
|
78
74
|
kademliaNeighbors.forEach((neighbor) => {
|
|
79
|
-
kadString += nodeIndicesById[neighbor
|
|
75
|
+
kadString += nodeIndicesById[neighbor] + ','
|
|
80
76
|
})
|
|
81
77
|
|
|
82
78
|
let correctNeighbors = 0
|
|
83
79
|
try {
|
|
84
80
|
for (let j = 0; j < groundTruth[i + ''].length; j++) {
|
|
85
|
-
if (groundTruth[i + ''][j].name != (nodeIndicesById[kademliaNeighbors[j]
|
|
81
|
+
if (groundTruth[i + ''][j].name != (nodeIndicesById[kademliaNeighbors[j]] + '')) {
|
|
86
82
|
break
|
|
87
83
|
}
|
|
88
84
|
correctNeighbors++
|
|
@@ -102,7 +98,7 @@ describe('Kademlia correctness', () => {
|
|
|
102
98
|
}
|
|
103
99
|
|
|
104
100
|
if (i > 0) {
|
|
105
|
-
sumKbucketSize += nodes[i].
|
|
101
|
+
sumKbucketSize += nodes[i].getNeighborCount()
|
|
106
102
|
sumCorrectNeighbors += correctNeighbors
|
|
107
103
|
}
|
|
108
104
|
}
|
|
@@ -114,5 +110,5 @@ describe('Kademlia correctness', () => {
|
|
|
114
110
|
console.log('Minimum correct neighbors: ' + minimumCorrectNeighbors)
|
|
115
111
|
console.log('Average correct neighbors: ' + avgCorrectNeighbors)
|
|
116
112
|
console.log('Average Kbucket size: ' + avgKbucketSize)
|
|
117
|
-
})
|
|
113
|
+
}, 120000)
|
|
118
114
|
})
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
import { Simulator } from '../../src/connection/simulator/Simulator'
|
|
3
|
+
import { DhtNode } from '../../src/dht/DhtNode'
|
|
4
|
+
import { createMockRingNode } from '../utils/utils'
|
|
5
|
+
import { execSync } from 'child_process'
|
|
6
|
+
import fs from 'fs'
|
|
7
|
+
import { DhtAddress, getDhtAddressFromRaw, getNodeIdFromPeerDescriptor } from '../../src/identifiers'
|
|
8
|
+
import { Logger } from '@streamr/utils'
|
|
9
|
+
import { getRingIdRawFromPeerDescriptor } from '../../src/dht/contact/ringIdentifiers'
|
|
10
|
+
|
|
11
|
+
const logger = new Logger(module)
|
|
12
|
+
|
|
13
|
+
describe('Ring correctness', () => {
|
|
14
|
+
let entryPoint: DhtNode
|
|
15
|
+
let nodes: DhtNode[]
|
|
16
|
+
const simulator = new Simulator()
|
|
17
|
+
|
|
18
|
+
const NUM_NODES = 900
|
|
19
|
+
const nodeIndicesById: Record<DhtAddress, number> = {}
|
|
20
|
+
|
|
21
|
+
const regions: Array<number> = []
|
|
22
|
+
for (let i = 0; i < (NUM_NODES + 1); i++) {
|
|
23
|
+
regions.push(i)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Shuffle the regions
|
|
27
|
+
for (let i = regions.length - 1; i > 0; i--) {
|
|
28
|
+
const j = Math.floor(Math.random() * (i + 1))
|
|
29
|
+
const temp = regions[i]
|
|
30
|
+
regions[i] = regions[j]
|
|
31
|
+
regions[j] = temp
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (!fs.existsSync('test/data/nodeids.json')) {
|
|
35
|
+
console.log('gound truth data does not exist yet, generating..')
|
|
36
|
+
execSync('npm run prepare-kademlia-simulation')
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const dhtIds: Array<{ type: string, data: Array<number> }> = JSON.parse(fs.readFileSync('test/data/nodeids.json').toString())
|
|
40
|
+
const groundTruth: Record<string, Array<{ name: string, distance: number, id: { type: string, data: Array<number> } }>>
|
|
41
|
+
= JSON.parse(fs.readFileSync('test/data/orderedneighbors.json').toString())
|
|
42
|
+
|
|
43
|
+
beforeEach(async () => {
|
|
44
|
+
jest.setTimeout(60000)
|
|
45
|
+
nodes = []
|
|
46
|
+
entryPoint = await createMockRingNode(simulator, getDhtAddressFromRaw(Uint8Array.from(dhtIds[0].data)), regions[0])
|
|
47
|
+
nodes.push(entryPoint)
|
|
48
|
+
nodeIndicesById[entryPoint.getNodeId()] = 0
|
|
49
|
+
|
|
50
|
+
for (let i = 1; i < NUM_NODES; i++) {
|
|
51
|
+
const node = await createMockRingNode(simulator, getDhtAddressFromRaw(Uint8Array.from(dhtIds[i].data)), regions[i + 1])
|
|
52
|
+
nodeIndicesById[node.getNodeId()] = i
|
|
53
|
+
nodes.push(node)
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
afterEach(async () => {
|
|
58
|
+
await Promise.all([
|
|
59
|
+
entryPoint.stop(),
|
|
60
|
+
...nodes.map((node) => node.stop())
|
|
61
|
+
])
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
it('Can find correct neighbors', async () => {
|
|
65
|
+
await entryPoint.joinDht([entryPoint.getLocalPeerDescriptor()])
|
|
66
|
+
|
|
67
|
+
//await Promise.all(
|
|
68
|
+
// nodes.map((node) => node.joinDht([entryPoint.getLocalPeerDescriptor()]))
|
|
69
|
+
//)
|
|
70
|
+
|
|
71
|
+
for (let i = 1; i < NUM_NODES; i++) {
|
|
72
|
+
// time to join the network
|
|
73
|
+
const startTimestamp = Date.now()
|
|
74
|
+
await nodes[i].joinDht([entryPoint.getLocalPeerDescriptor()])
|
|
75
|
+
const endTimestamp = Date.now()
|
|
76
|
+
logger.info('Node ' + i + ' joined in ' + (endTimestamp - startTimestamp) + ' ms')
|
|
77
|
+
const ringStartTimestamp = Date.now()
|
|
78
|
+
await nodes[i].joinRing()
|
|
79
|
+
const ringEndTimestamp = Date.now()
|
|
80
|
+
logger.info('Node ' + i + ' joined ring in ' + (ringEndTimestamp - ringStartTimestamp) + ' ms')
|
|
81
|
+
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/*
|
|
85
|
+
for (let i = 1; i < NUM_NODES; i++) {
|
|
86
|
+
// time to join the network
|
|
87
|
+
const ringStartTimestamp = Date.now()
|
|
88
|
+
await nodes[i].joinRing()
|
|
89
|
+
const ringEndTimestamp = Date.now()
|
|
90
|
+
logger.info('Node ' + i + ' joined ring in ' + (ringEndTimestamp - ringStartTimestamp) + ' ms')
|
|
91
|
+
}*/
|
|
92
|
+
|
|
93
|
+
for (let i = 1; i < NUM_NODES; i++) {
|
|
94
|
+
logger.info('Node ' + i + ', own region: ' + nodes[i].getLocalPeerDescriptor().region
|
|
95
|
+
+ '. Regions of closest ring peers, left: '
|
|
96
|
+
+ nodes[i].getClosestRingContactsTo(
|
|
97
|
+
getRingIdRawFromPeerDescriptor(nodes[i].getLocalPeerDescriptor()), 10).left.map((p) => p.region)
|
|
98
|
+
+ ', right: ' + nodes[i].getClosestRingContactsTo(getRingIdRawFromPeerDescriptor(
|
|
99
|
+
nodes[i].getLocalPeerDescriptor()), 10).right.map((p) => p.region)
|
|
100
|
+
)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
let minimumCorrectNeighbors = Number.MAX_SAFE_INTEGER
|
|
104
|
+
let sumCorrectNeighbors = 0
|
|
105
|
+
let sumKbucketSize = 1
|
|
106
|
+
|
|
107
|
+
for (let i = nodes.length - 1; i >= 0; i--) {
|
|
108
|
+
let groundTruthString = 'groundTruthNeighb: '
|
|
109
|
+
// eslint-disable-next-line @typescript-eslint/prefer-for-of
|
|
110
|
+
for (let j = 0; j < groundTruth[i + ''].length; j++) {
|
|
111
|
+
groundTruthString += groundTruth[i + ''][j].name + ','
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const kademliaNeighbors = nodes[i].getClosestContacts(8).map((p) => getNodeIdFromPeerDescriptor(p))
|
|
115
|
+
|
|
116
|
+
let kadString = 'kademliaNeighbors: '
|
|
117
|
+
kademliaNeighbors.forEach((neighbor) => {
|
|
118
|
+
kadString += nodeIndicesById[neighbor] + ','
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
let correctNeighbors = 0
|
|
122
|
+
try {
|
|
123
|
+
for (let j = 0; j < groundTruth[i + ''].length; j++) {
|
|
124
|
+
if (groundTruth[i + ''][j].name != (nodeIndicesById[kademliaNeighbors[j]] + '')) {
|
|
125
|
+
break
|
|
126
|
+
}
|
|
127
|
+
correctNeighbors++
|
|
128
|
+
}
|
|
129
|
+
} catch (e) {
|
|
130
|
+
console.error('Node ' + getNodeIdFromPeerDescriptor(nodes[i].getLocalPeerDescriptor()) + ' had only '
|
|
131
|
+
+ kademliaNeighbors.length + ' kademlia neighbors')
|
|
132
|
+
}
|
|
133
|
+
if (correctNeighbors === 0) {
|
|
134
|
+
console.log('No correct neighbors found for node ' + i)
|
|
135
|
+
console.log(groundTruthString)
|
|
136
|
+
console.log(kadString)
|
|
137
|
+
}
|
|
138
|
+
if (correctNeighbors < minimumCorrectNeighbors) {
|
|
139
|
+
console.log('NEW MIN', i, correctNeighbors)
|
|
140
|
+
minimumCorrectNeighbors = correctNeighbors
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (i > 0) {
|
|
144
|
+
sumKbucketSize += nodes[i].getNeighborCount()
|
|
145
|
+
sumCorrectNeighbors += correctNeighbors
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const avgKbucketSize = sumKbucketSize / (NUM_NODES - 1)
|
|
150
|
+
const avgCorrectNeighbors = sumCorrectNeighbors / (NUM_NODES - 1)
|
|
151
|
+
|
|
152
|
+
console.log('----------- Simulation results ------------------')
|
|
153
|
+
console.log('Minimum correct neighbors: ' + minimumCorrectNeighbors)
|
|
154
|
+
console.log('Average correct neighbors: ' + avgCorrectNeighbors)
|
|
155
|
+
console.log('Average Kbucket size: ' + avgKbucketSize)
|
|
156
|
+
}, 240000)
|
|
157
|
+
})
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
|
|
3
|
+
import KBucket from 'k-bucket'
|
|
4
|
+
import { SortedContactList } from '../../src/dht/contact/SortedContactList'
|
|
5
|
+
import { DhtAddress, DhtAddressRaw, createRandomDhtAddress, getRawFromDhtAddress } from '../../src/identifiers'
|
|
6
|
+
|
|
7
|
+
const NUM_ADDS = 1000
|
|
8
|
+
|
|
9
|
+
interface Item {
|
|
10
|
+
id: DhtAddressRaw
|
|
11
|
+
vectorClock: number
|
|
12
|
+
getNodeId: () => DhtAddress
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const createRandomItem = (index: number): Item => {
|
|
16
|
+
const nodeId = createRandomDhtAddress()
|
|
17
|
+
const nodeIdRaw = getRawFromDhtAddress(nodeId)
|
|
18
|
+
return {
|
|
19
|
+
getNodeId: () => nodeId,
|
|
20
|
+
id: nodeIdRaw,
|
|
21
|
+
vectorClock: index
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function shuffleArray<T>(array: T[]): T[] {
|
|
26
|
+
for (let i = array.length - 1; i > 0; i--) {
|
|
27
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
28
|
+
[array[i], array[j]] = [array[j], array[i]]
|
|
29
|
+
}
|
|
30
|
+
return array
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
describe('SortedContactListBenchmark', () => {
|
|
34
|
+
|
|
35
|
+
it('adds ' + NUM_ADDS + ' random nodeIds', async () => {
|
|
36
|
+
const randomIds = []
|
|
37
|
+
for (let i = 0; i < NUM_ADDS; i++) {
|
|
38
|
+
randomIds.push(createRandomItem(i))
|
|
39
|
+
}
|
|
40
|
+
const list = new SortedContactList({
|
|
41
|
+
referenceId: createRandomDhtAddress(),
|
|
42
|
+
allowToContainReferenceId: true,
|
|
43
|
+
emitEvents: true
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
console.time('SortedContactList.addContact() with emitEvents=true')
|
|
47
|
+
for (let i = 0; i < NUM_ADDS; i++) {
|
|
48
|
+
list.addContact(randomIds[i])
|
|
49
|
+
}
|
|
50
|
+
console.timeEnd('SortedContactList.addContact() with emitEvents=true')
|
|
51
|
+
|
|
52
|
+
const list2 = new SortedContactList({
|
|
53
|
+
referenceId: createRandomDhtAddress(),
|
|
54
|
+
allowToContainReferenceId: true,
|
|
55
|
+
emitEvents: false
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
console.time('SortedContactList.addContact() with emitEvents=false')
|
|
59
|
+
for (let i = 0; i < NUM_ADDS; i++) {
|
|
60
|
+
list2.addContact(randomIds[i])
|
|
61
|
+
}
|
|
62
|
+
console.timeEnd('SortedContactList.addContact() with emitEvents=false')
|
|
63
|
+
|
|
64
|
+
const kBucket = new KBucket<Item>({ localNodeId: getRawFromDhtAddress(createRandomDhtAddress()) })
|
|
65
|
+
console.time('KBucket.add()')
|
|
66
|
+
for (let i = 0; i < NUM_ADDS; i++) {
|
|
67
|
+
kBucket.add(randomIds[i])
|
|
68
|
+
}
|
|
69
|
+
console.timeEnd('KBucket.add()')
|
|
70
|
+
|
|
71
|
+
console.time('kBucket toArray()')
|
|
72
|
+
|
|
73
|
+
for (let i = 0; i < NUM_ADDS; i++) {
|
|
74
|
+
kBucket.toArray()
|
|
75
|
+
}
|
|
76
|
+
console.timeEnd('kBucket toArray()')
|
|
77
|
+
|
|
78
|
+
console.time('kBucket closest()')
|
|
79
|
+
for (let i = 0; i < NUM_ADDS; i++) {
|
|
80
|
+
kBucket.closest(getRawFromDhtAddress(createRandomDhtAddress()), 20)
|
|
81
|
+
}
|
|
82
|
+
console.timeEnd('kBucket closest()')
|
|
83
|
+
|
|
84
|
+
console.time('SortedContactList.getClosestContacts() with emitEvents=true')
|
|
85
|
+
for (let i = 0; i < NUM_ADDS; i++) {
|
|
86
|
+
const closest = new SortedContactList<Item>({
|
|
87
|
+
referenceId: createRandomDhtAddress(),
|
|
88
|
+
allowToContainReferenceId: true,
|
|
89
|
+
emitEvents: true
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
const arrayFromBucket = kBucket.toArray()
|
|
93
|
+
arrayFromBucket.forEach((contact) => closest.addContact(contact))
|
|
94
|
+
closest.getClosestContacts(20)
|
|
95
|
+
}
|
|
96
|
+
console.timeEnd('SortedContactList.getClosestContacts() with emitEvents=true')
|
|
97
|
+
|
|
98
|
+
console.time('SortedContactList.getClosestContacts() with emitEvents=false')
|
|
99
|
+
for (let i = 0; i < NUM_ADDS; i++) {
|
|
100
|
+
const closest = new SortedContactList<Item>({
|
|
101
|
+
referenceId: createRandomDhtAddress(),
|
|
102
|
+
allowToContainReferenceId: true,
|
|
103
|
+
emitEvents: false
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
const arrayFromBucket = kBucket.toArray()
|
|
107
|
+
arrayFromBucket.forEach((contact) => closest.addContact(contact))
|
|
108
|
+
closest.getClosestContacts(20)
|
|
109
|
+
}
|
|
110
|
+
console.timeEnd('SortedContactList.getClosestContacts() with emitEvents=false')
|
|
111
|
+
|
|
112
|
+
console.time('SortedContactList.getClosestContacts() with emitEvents=false and lodash')
|
|
113
|
+
for (let i = 0; i < NUM_ADDS; i++) {
|
|
114
|
+
const closest = new SortedContactList<Item>({
|
|
115
|
+
referenceId: createRandomDhtAddress(),
|
|
116
|
+
allowToContainReferenceId: true,
|
|
117
|
+
emitEvents: false
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
const arrayFromBucket = kBucket.toArray()
|
|
121
|
+
arrayFromBucket.forEach((contact) => closest.addContact(contact))
|
|
122
|
+
closest.getClosestContacts(20)
|
|
123
|
+
}
|
|
124
|
+
console.timeEnd('SortedContactList.getClosestContacts() with emitEvents=false and lodash')
|
|
125
|
+
|
|
126
|
+
console.time('SortedContactList.getClosestContacts() with emitEvents=false and addContacts()')
|
|
127
|
+
for (let i = 0; i < NUM_ADDS; i++) {
|
|
128
|
+
const closest = new SortedContactList<Item>({
|
|
129
|
+
referenceId: createRandomDhtAddress(),
|
|
130
|
+
allowToContainReferenceId: true,
|
|
131
|
+
emitEvents: false
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
const arrayFromBucket = kBucket.toArray()
|
|
135
|
+
closest.addContacts(arrayFromBucket)
|
|
136
|
+
closest.getClosestContacts(20)
|
|
137
|
+
}
|
|
138
|
+
console.timeEnd('SortedContactList.getClosestContacts() with emitEvents=false and addContacts()')
|
|
139
|
+
|
|
140
|
+
const shuffled = shuffleArray(kBucket.toArray())
|
|
141
|
+
console.time('kbucket add and closest')
|
|
142
|
+
for (let i = 0; i < NUM_ADDS; i++) {
|
|
143
|
+
const bucket2 = new KBucket<Item>({ localNodeId: getRawFromDhtAddress(createRandomDhtAddress()) })
|
|
144
|
+
|
|
145
|
+
shuffled.forEach((contact) => bucket2.add(contact))
|
|
146
|
+
bucket2.closest(getRawFromDhtAddress(createRandomDhtAddress()), 20)
|
|
147
|
+
}
|
|
148
|
+
console.timeEnd('kbucket add and closest')
|
|
149
|
+
|
|
150
|
+
})
|
|
151
|
+
})
|