@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
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
|
|
3
|
+
import { wait } from '@streamr/utils'
|
|
4
|
+
import { WebsocketServer } from '../../src/connection/websocket/WebsocketServer'
|
|
5
|
+
import { ClientWebsocket } from '../../src/connection/websocket/ClientWebsocket'
|
|
6
|
+
|
|
7
|
+
// This 'test' is meant to be run manually using the following command:
|
|
8
|
+
// node --inspect ../../../../node_modules/.bin/jest WebsocketServerMemoryLeak.test.ts
|
|
9
|
+
// while wathing for memory leaks in Chrome DevTools
|
|
10
|
+
|
|
11
|
+
describe('WebsocketServermemoryLeak', () => {
|
|
12
|
+
|
|
13
|
+
it('Accepts and detroys connections', async () => {
|
|
14
|
+
const server = new WebsocketServer({
|
|
15
|
+
portRange: { min: 19792, max: 19792 },
|
|
16
|
+
enableTls: false
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
server.on('connected', (connection) => {
|
|
20
|
+
console.log('ServerWebsocket connected')
|
|
21
|
+
connection.destroy()
|
|
22
|
+
console.log('ServerWebsocket destroyed')
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
const port = await server.start()
|
|
26
|
+
expect(port).toEqual(19792)
|
|
27
|
+
|
|
28
|
+
for (let i = 0; i < 10000; i++) {
|
|
29
|
+
const clientWebsocket: ClientWebsocket = new ClientWebsocket()
|
|
30
|
+
clientWebsocket.on('connected', () => {
|
|
31
|
+
console.log('clientWebsocket connected ' + i)
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
clientWebsocket.connect(`ws://127.0.0.1:${port}`)
|
|
35
|
+
i++
|
|
36
|
+
await wait(3000)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
await server.stop()
|
|
40
|
+
}, 120000000)
|
|
41
|
+
})
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { ConnectivityResponse, PeerDescriptor } from '../../../src/proto/packages/dht/protos/DhtRpc'
|
|
2
|
+
import { createPeerDescriptor } from '../../../src/helpers/createPeerDescriptor'
|
|
3
|
+
import { NatType } from '../../../src/connection/ConnectionManager'
|
|
4
|
+
import { ipv4ToNumber, Logger } from '@streamr/utils'
|
|
5
|
+
import { RingContactList } from '../../../src/dht/contact/RingContactList'
|
|
6
|
+
import { getRingIdRawFromPeerDescriptor } from '../../../src/dht/contact/ringIdentifiers'
|
|
7
|
+
import { getRandomRegion } from '../../../src/connection/simulator/pings'
|
|
8
|
+
|
|
9
|
+
const logger = new Logger(module)
|
|
10
|
+
|
|
11
|
+
function ipv4ToString(ip: number): string {
|
|
12
|
+
return [
|
|
13
|
+
(ip >>> 24) & 0xFF,
|
|
14
|
+
(ip >>> 16) & 0xFF,
|
|
15
|
+
(ip >>> 8) & 0xFF,
|
|
16
|
+
ip & 0xFF
|
|
17
|
+
].join('.')
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
class MockNode {
|
|
21
|
+
private readonly peerDescriptor: PeerDescriptor
|
|
22
|
+
|
|
23
|
+
constructor(_region: number, ipAddress: string) {
|
|
24
|
+
|
|
25
|
+
const connectivityResponse: ConnectivityResponse = {
|
|
26
|
+
host: 'localhost',
|
|
27
|
+
natType: NatType.UNKNOWN,
|
|
28
|
+
ipAddress: ipv4ToNumber(ipAddress),
|
|
29
|
+
version: '0.0.0'
|
|
30
|
+
|
|
31
|
+
}
|
|
32
|
+
this.peerDescriptor = createPeerDescriptor(connectivityResponse, getRandomRegion())
|
|
33
|
+
logger.info(ipv4ToString(this.peerDescriptor.ipAddress!))
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public getPeerDescriptor(): PeerDescriptor {
|
|
37
|
+
return this.peerDescriptor
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// populate with mock ip addresses
|
|
42
|
+
const mockData: Array< [number, string] > = [
|
|
43
|
+
[0, '5.2.4.2'],
|
|
44
|
+
[0, '6.23.2.4'],
|
|
45
|
+
[0, '7.2.4.2'],
|
|
46
|
+
[0, '8.23.2.4'],
|
|
47
|
+
[0, '9.3.2.4'],
|
|
48
|
+
[0, '10.3.2.4'],
|
|
49
|
+
[0, '24.23.2.4'],
|
|
50
|
+
[0, '31.23.2.4'],
|
|
51
|
+
[0, '33.2.4.2'],
|
|
52
|
+
[0, '35.3.2.4'],
|
|
53
|
+
[0, '37.23.2.4'],
|
|
54
|
+
[0, '39.2.4.2'],
|
|
55
|
+
[0, '42.3.2.4'],
|
|
56
|
+
[0, '46.2.4.2'],
|
|
57
|
+
[0, '48.3.2.4'],
|
|
58
|
+
[0, '50.23.2.4']
|
|
59
|
+
]
|
|
60
|
+
|
|
61
|
+
const mockNodes: MockNode[] = mockData.map(([region, ipAddress]) => new MockNode(region, ipAddress))
|
|
62
|
+
const referenceNode = mockNodes[5]
|
|
63
|
+
const ringContactList: RingContactList<MockNode> = new RingContactList<MockNode>(
|
|
64
|
+
getRingIdRawFromPeerDescriptor(referenceNode.getPeerDescriptor()),
|
|
65
|
+
false
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
mockNodes.forEach((node) => ringContactList.addContact(node))
|
|
69
|
+
|
|
70
|
+
ringContactList.getClosestContacts().left.forEach((node) => logger.info(ipv4ToString(node.getPeerDescriptor().ipAddress!)))
|
|
71
|
+
logger.info('reference node: ' + ipv4ToString(referenceNode.getPeerDescriptor().ipAddress!))
|
|
72
|
+
ringContactList.getClosestContacts().right.forEach((node) => logger.info(ipv4ToString(node.getPeerDescriptor().ipAddress!)))
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import { PeerID } from '../../../src/helpers/PeerID'
|
|
2
1
|
import type { SimulationNode } from './SimulationNode'
|
|
3
2
|
import { NodeType, PeerDescriptor } from '../../../src/proto/packages/dht/protos/DhtRpc'
|
|
3
|
+
import { DhtAddress, DhtAddressRaw, getRawFromDhtAddress } from '../../../src/identifiers'
|
|
4
4
|
|
|
5
5
|
export class Contact {
|
|
6
6
|
private static counter = 0
|
|
7
7
|
|
|
8
|
-
public
|
|
9
|
-
public id:
|
|
8
|
+
public ownId: DhtAddress
|
|
9
|
+
public id: DhtAddressRaw
|
|
10
10
|
public vectorClock = 0
|
|
11
11
|
public dhtNode: SimulationNode | undefined
|
|
12
12
|
|
|
13
|
-
constructor(ownId:
|
|
14
|
-
this.
|
|
13
|
+
constructor(ownId: DhtAddress, dhtNode?: SimulationNode) {
|
|
14
|
+
this.ownId = ownId
|
|
15
15
|
this.vectorClock = Contact.counter++
|
|
16
16
|
this.dhtNode = dhtNode
|
|
17
|
-
this.id = ownId
|
|
17
|
+
this.id = getRawFromDhtAddress(ownId)
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
getPeerDescriptor(): PeerDescriptor {
|
|
21
21
|
const peerDescriptor: PeerDescriptor = {
|
|
22
|
-
|
|
22
|
+
nodeId: getRawFromDhtAddress(this.ownId),
|
|
23
23
|
type: NodeType.NODEJS
|
|
24
24
|
}
|
|
25
25
|
return peerDescriptor
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
return this.
|
|
28
|
+
getNodeId(): DhtAddress {
|
|
29
|
+
return this.ownId
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { SimulationNode } from './SimulationNode'
|
|
4
4
|
import fs from 'fs'
|
|
5
|
-
import {
|
|
5
|
+
import { getDhtAddressFromRaw } from '../../../src/identifiers'
|
|
6
6
|
|
|
7
7
|
export class KademliaSimulation {
|
|
8
8
|
|
|
@@ -17,7 +17,7 @@ export class KademliaSimulation {
|
|
|
17
17
|
|
|
18
18
|
constructor() {
|
|
19
19
|
if (!fs.existsSync('test/data/nodeids.json')) {
|
|
20
|
-
throw ('Cannot find test/data/nodeids.json, please run "npm run prepare-kademlia-simulation first"')
|
|
20
|
+
throw new Error('Cannot find test/data/nodeids.json, please run "npm run prepare-kademlia-simulation first"')
|
|
21
21
|
}
|
|
22
22
|
this.dhtIds = JSON.parse(fs.readFileSync('test/data/nodeids.json').toString())
|
|
23
23
|
this.groundTruth = JSON.parse(fs.readFileSync('test/data/orderedneighbors.json').toString())
|
|
@@ -25,7 +25,7 @@ export class KademliaSimulation {
|
|
|
25
25
|
|
|
26
26
|
public run(): void {
|
|
27
27
|
for (let i = 0; i < KademliaSimulation.NUM_NODES; i++) {
|
|
28
|
-
const node = new SimulationNode(
|
|
28
|
+
const node = new SimulationNode(getDhtAddressFromRaw(Buffer.from(this.dhtIds[i].data.slice(0, KademliaSimulation.ID_LENGTH))))
|
|
29
29
|
this.nodeNamesById[JSON.stringify(node.getContact().id)] = i
|
|
30
30
|
this.nodes.push(node)
|
|
31
31
|
node.joinDht(this.nodes[0])
|
|
@@ -42,17 +42,17 @@ export class KademliaSimulation {
|
|
|
42
42
|
|
|
43
43
|
for (let i = this.nodes.length - 1; i >= 0; i--) {
|
|
44
44
|
|
|
45
|
-
const
|
|
45
|
+
const outgoingRpcCallCount = this.nodes[i].getOutgoingRpcCallCount()
|
|
46
46
|
console.log('-----------')
|
|
47
47
|
console.log('Node: ' + i)
|
|
48
48
|
console.log('Kbucket size: ' + this.nodes[i].getKBucketSize())
|
|
49
|
-
console.log('Num incoming RPC calls: ' + this.nodes[i].
|
|
50
|
-
console.log('Num outgoing RPC calls: ' +
|
|
49
|
+
console.log('Num incoming RPC calls: ' + this.nodes[i].getIncomingRpcCallCount())
|
|
50
|
+
console.log('Num outgoing RPC calls: ' + outgoingRpcCallCount)
|
|
51
51
|
|
|
52
|
-
sumOutgoingRpcCalls +=
|
|
52
|
+
sumOutgoingRpcCalls += outgoingRpcCallCount
|
|
53
53
|
|
|
54
|
-
if (maxOutgoingRpcCalls <
|
|
55
|
-
maxOutgoingRpcCalls =
|
|
54
|
+
if (maxOutgoingRpcCalls < outgoingRpcCallCount) {
|
|
55
|
+
maxOutgoingRpcCalls = outgoingRpcCallCount
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
const kademliaNeighbors = this.nodes[i].getNeightborList().getContactIds()
|
|
@@ -79,13 +79,13 @@ export class KademliaSimulation {
|
|
|
79
79
|
|
|
80
80
|
const avgCorrectNeighbors = sumCorrectNeighbors / (KademliaSimulation.NUM_NODES - 1)
|
|
81
81
|
const avgKbucketSize = sumKbucketSize / (KademliaSimulation.NUM_NODES - 1)
|
|
82
|
-
const
|
|
82
|
+
const avgOutgoingRpcCallCount = sumOutgoingRpcCalls / (KademliaSimulation.NUM_NODES - 1)
|
|
83
83
|
|
|
84
84
|
console.log('----------- Simulation results ------------------')
|
|
85
85
|
console.log('Minimum correct neighbors: ' + minimumCorrectNeighbors)
|
|
86
86
|
console.log('Average correct neighbors: ' + avgCorrectNeighbors)
|
|
87
87
|
console.log('Average Kbucket size: ' + avgKbucketSize)
|
|
88
|
-
console.log('Average number of outgoing RPC calls: ' +
|
|
88
|
+
console.log('Average number of outgoing RPC calls: ' + avgOutgoingRpcCallCount)
|
|
89
89
|
console.log('MAX number of outgoing RPC calls: ' + maxOutgoingRpcCalls)
|
|
90
90
|
}
|
|
91
91
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import KBucket from 'k-bucket'
|
|
2
2
|
import { Contact } from './Contact'
|
|
3
3
|
import { SortedContactList } from '../../../src/dht/contact/SortedContactList'
|
|
4
|
-
import {
|
|
4
|
+
import { DhtAddress, getRawFromDhtAddress } from '../../../src/identifiers'
|
|
5
5
|
|
|
6
6
|
export class SimulationNode {
|
|
7
7
|
|
|
@@ -12,21 +12,26 @@ export class SimulationNode {
|
|
|
12
12
|
private bucket: KBucket<Contact>
|
|
13
13
|
private ownContact: Contact
|
|
14
14
|
|
|
15
|
-
private
|
|
16
|
-
private
|
|
15
|
+
private incomingRpcCallCount = 0
|
|
16
|
+
private outgoingRpcCallCount = 0
|
|
17
17
|
|
|
18
18
|
private neighborList: SortedContactList<Contact>
|
|
19
|
-
private ownId:
|
|
19
|
+
private ownId: DhtAddress
|
|
20
20
|
|
|
21
|
-
constructor(ownId:
|
|
21
|
+
constructor(ownId: DhtAddress) {
|
|
22
22
|
this.ownId = ownId
|
|
23
23
|
this.ownContact = new Contact(this.ownId, this)
|
|
24
24
|
this.bucket = new KBucket({
|
|
25
|
-
localNodeId: this.ownId
|
|
25
|
+
localNodeId: getRawFromDhtAddress(this.ownId),
|
|
26
26
|
numberOfNodesPerKBucket: this.numberOfNodesPerKBucket
|
|
27
27
|
})
|
|
28
28
|
|
|
29
|
-
this.neighborList = new SortedContactList(
|
|
29
|
+
this.neighborList = new SortedContactList({
|
|
30
|
+
referenceId: this.ownId,
|
|
31
|
+
maxSize: 1000,
|
|
32
|
+
allowToContainReferenceId: false,
|
|
33
|
+
emitEvents: false
|
|
34
|
+
})
|
|
30
35
|
}
|
|
31
36
|
|
|
32
37
|
// For simulation use
|
|
@@ -42,34 +47,33 @@ export class SimulationNode {
|
|
|
42
47
|
return this.bucket.count()
|
|
43
48
|
}
|
|
44
49
|
|
|
45
|
-
public
|
|
46
|
-
return this.
|
|
50
|
+
public getIncomingRpcCallCount(): number {
|
|
51
|
+
return this.incomingRpcCallCount
|
|
47
52
|
}
|
|
48
53
|
|
|
49
|
-
public
|
|
50
|
-
return this.
|
|
54
|
+
public getOutgoingRpcCallCount(): number {
|
|
55
|
+
return this.outgoingRpcCallCount
|
|
51
56
|
}
|
|
52
57
|
|
|
53
58
|
// RPC call
|
|
54
59
|
|
|
55
|
-
public getClosestNodesTo(id:
|
|
56
|
-
this.
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
if (!this.bucket.get(
|
|
60
|
-
const contact = new Contact(
|
|
60
|
+
public getClosestNodesTo(id: DhtAddress, caller: SimulationNode): Contact[] {
|
|
61
|
+
this.incomingRpcCallCount++
|
|
62
|
+
const idValue = getRawFromDhtAddress(id)
|
|
63
|
+
const ret = this.bucket.closest(idValue)
|
|
64
|
+
if (!this.bucket.get(idValue)) {
|
|
65
|
+
const contact = new Contact(id, caller)
|
|
61
66
|
this.bucket.add(contact)
|
|
62
67
|
this.neighborList.addContact(contact)
|
|
63
68
|
}
|
|
64
|
-
|
|
65
69
|
return ret
|
|
66
70
|
}
|
|
67
71
|
|
|
68
72
|
private findMoreContacts(contactList: Contact[], shortlist: SortedContactList<Contact>) {
|
|
69
73
|
contactList.forEach((contact) => {
|
|
70
|
-
shortlist.setContacted(contact.
|
|
71
|
-
shortlist.setActive(contact.
|
|
72
|
-
this.
|
|
74
|
+
shortlist.setContacted(contact.getNodeId())
|
|
75
|
+
shortlist.setActive(contact.getNodeId())
|
|
76
|
+
this.outgoingRpcCallCount++
|
|
73
77
|
const returnedContacts = contact.dhtNode!.getClosestNodesTo(this.ownId, this)
|
|
74
78
|
shortlist.addContacts(returnedContacts)
|
|
75
79
|
returnedContacts.forEach((returnedContact: Contact) => {
|
|
@@ -81,12 +85,12 @@ export class SimulationNode {
|
|
|
81
85
|
}
|
|
82
86
|
|
|
83
87
|
public joinDht(entryPoint: SimulationNode): void {
|
|
84
|
-
if (entryPoint.getContact().
|
|
88
|
+
if (entryPoint.getContact().getNodeId() === this.ownId) {
|
|
85
89
|
return
|
|
86
90
|
}
|
|
87
91
|
|
|
88
92
|
this.bucket.add(entryPoint.getContact())
|
|
89
|
-
const closest = this.bucket.closest(this.ownId
|
|
93
|
+
const closest = this.bucket.closest(getRawFromDhtAddress(this.ownId), this.ALPHA)
|
|
90
94
|
|
|
91
95
|
this.neighborList.addContacts(closest)
|
|
92
96
|
|
|
@@ -100,7 +104,7 @@ export class SimulationNode {
|
|
|
100
104
|
|
|
101
105
|
this.findMoreContacts(uncontacted, this.neighborList)
|
|
102
106
|
|
|
103
|
-
if (oldClosestContactId
|
|
107
|
+
if (oldClosestContactId === this.neighborList.getClosestContactId()) {
|
|
104
108
|
uncontacted = this.neighborList.getUncontactedContacts(this.K)
|
|
105
109
|
if (uncontacted.length === 0) {
|
|
106
110
|
return
|
|
@@ -111,7 +115,7 @@ export class SimulationNode {
|
|
|
111
115
|
this.findMoreContacts(uncontacted, this.neighborList)
|
|
112
116
|
|
|
113
117
|
if (this.neighborList.getActiveContacts().length >= this.K ||
|
|
114
|
-
oldClosestContactId
|
|
118
|
+
(oldClosestContactId === this.neighborList.getClosestContactId())) {
|
|
115
119
|
return
|
|
116
120
|
}
|
|
117
121
|
uncontacted = this.neighborList.getUncontactedContacts(this.ALPHA)
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import fs from 'fs'
|
|
2
2
|
import crypto from 'crypto'
|
|
3
3
|
import KBucket from 'k-bucket'
|
|
4
|
+
import { DhtAddressRaw } from '../../src/identifiers'
|
|
4
5
|
|
|
5
|
-
const ID_LENGTH =
|
|
6
|
-
const NUM_NODES =
|
|
6
|
+
const ID_LENGTH = 20
|
|
7
|
+
const NUM_NODES = 900
|
|
7
8
|
const NUM_NEAREST = 10
|
|
8
9
|
|
|
9
|
-
const generateId = function():
|
|
10
|
+
const generateId = function(): DhtAddressRaw {
|
|
10
11
|
return crypto.randomBytes(ID_LENGTH)
|
|
11
12
|
}
|
|
12
13
|
|
|
13
|
-
const findNNearestNeighbors = function(ownIndex: number, ownId:
|
|
14
|
+
const findNNearestNeighbors = function(ownIndex: number, ownId: DhtAddressRaw, nodes: Array<DhtAddressRaw>, n: number): Array<number> {
|
|
14
15
|
const retIndex: Array<number> = []
|
|
15
16
|
|
|
16
17
|
for (let i = 0; i < n; i++) {
|
|
@@ -37,7 +38,7 @@ const neighborWriter = fs.createWriteStream('orderedneighbors.json', {})
|
|
|
37
38
|
|
|
38
39
|
neighborWriter.write('{\n')
|
|
39
40
|
|
|
40
|
-
const nodes: Array<
|
|
41
|
+
const nodes: Array<DhtAddressRaw> = []
|
|
41
42
|
|
|
42
43
|
// generate nodeIds
|
|
43
44
|
|
|
@@ -53,7 +54,7 @@ for (let i = 0; i < NUM_NODES; i++) {
|
|
|
53
54
|
|
|
54
55
|
const neighborIds = findNNearestNeighbors(i, nodes[i], nodes, NUM_NEAREST)
|
|
55
56
|
|
|
56
|
-
const neighborNames: Array<{ name: number, distance: number, id:
|
|
57
|
+
const neighborNames: Array<{ name: number, distance: number, id: DhtAddressRaw }> = []
|
|
57
58
|
// eslint-disable-next-line @typescript-eslint/prefer-for-of
|
|
58
59
|
for (let j = 0; j < neighborIds.length; j++) {
|
|
59
60
|
neighborNames.push({ name: neighborIds[j], distance: KBucket.distance(nodes[i], nodes[neighborIds[j]]), id: nodes[neighborIds[j]] })
|
|
@@ -1,28 +1,24 @@
|
|
|
1
|
-
import { NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
2
1
|
import { DhtNode } from '../../src/dht/DhtNode'
|
|
3
|
-
import { areEqualPeerDescriptors } from '../../src/
|
|
2
|
+
import { areEqualPeerDescriptors } from '../../src/identifiers'
|
|
3
|
+
import { createMockPeerDescriptor } from '../utils/utils'
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
type: NodeType.NODEJS,
|
|
9
|
-
websocket: { host: '127.0.0.1', port: 10016, tls: false }
|
|
10
|
-
}
|
|
5
|
+
const STREAM_ID1 = 'stream1'
|
|
6
|
+
const STREAM_ID2 = 'stream2'
|
|
7
|
+
const WEBSOCKET_PORT_RANGE = { min: 10017, max: 10018 }
|
|
11
8
|
|
|
12
|
-
|
|
13
|
-
const STREAM_ID2 = 'stream2'
|
|
9
|
+
describe('Layer0-Layer1', () => {
|
|
14
10
|
|
|
11
|
+
const epPeerDescriptor = createMockPeerDescriptor({
|
|
12
|
+
websocket: { host: '127.0.0.1', port: 10016, tls: false }
|
|
13
|
+
})
|
|
15
14
|
let epDhtNode: DhtNode
|
|
16
15
|
let node1: DhtNode
|
|
17
16
|
let node2: DhtNode
|
|
18
|
-
|
|
19
17
|
let stream1Node1: DhtNode
|
|
20
18
|
let stream1Node2: DhtNode
|
|
21
19
|
let stream2Node1: DhtNode
|
|
22
20
|
let stream2Node2: DhtNode
|
|
23
21
|
|
|
24
|
-
const websocketPortRange = { min: 10017, max: 10018 }
|
|
25
|
-
|
|
26
22
|
beforeEach(async () => {
|
|
27
23
|
|
|
28
24
|
epDhtNode = new DhtNode({ peerDescriptor: epPeerDescriptor, websocketServerEnableTls: false })
|
|
@@ -30,12 +26,12 @@ describe('Layer0-Layer1', () => {
|
|
|
30
26
|
await epDhtNode.joinDht([epPeerDescriptor])
|
|
31
27
|
|
|
32
28
|
node1 = new DhtNode({
|
|
33
|
-
websocketPortRange,
|
|
29
|
+
websocketPortRange: WEBSOCKET_PORT_RANGE,
|
|
34
30
|
entryPoints: [epPeerDescriptor],
|
|
35
31
|
websocketServerEnableTls: false
|
|
36
32
|
})
|
|
37
33
|
node2 = new DhtNode({
|
|
38
|
-
websocketPortRange,
|
|
34
|
+
websocketPortRange: WEBSOCKET_PORT_RANGE,
|
|
39
35
|
entryPoints: [epPeerDescriptor],
|
|
40
36
|
websocketServerEnableTls: false
|
|
41
37
|
})
|
|
@@ -1,46 +1,43 @@
|
|
|
1
|
-
import { PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
2
1
|
import { DhtNode } from '../../src/dht/DhtNode'
|
|
3
2
|
|
|
3
|
+
const WEBSOCKET_PORT_RANGE = { min: 10012, max: 10015 }
|
|
4
|
+
|
|
4
5
|
describe('Layer0', () => {
|
|
5
6
|
|
|
6
|
-
let epPeerDescriptor: PeerDescriptor
|
|
7
|
-
|
|
8
7
|
let epDhtNode: DhtNode
|
|
9
8
|
let node1: DhtNode
|
|
10
9
|
let node2: DhtNode
|
|
11
10
|
let node3: DhtNode
|
|
12
11
|
let node4: DhtNode
|
|
13
12
|
|
|
14
|
-
const websocketPortRange = { min: 10012, max: 10015 }
|
|
15
13
|
beforeEach(async () => {
|
|
16
14
|
|
|
17
15
|
epDhtNode = new DhtNode({ websocketHost: '127.0.0.1', websocketPortRange: { min: 10011, max: 10011 }, websocketServerEnableTls: false })
|
|
18
16
|
await epDhtNode.start()
|
|
19
|
-
|
|
20
|
-
await epDhtNode.joinDht([epPeerDescriptor])
|
|
17
|
+
await epDhtNode.joinDht([epDhtNode.getLocalPeerDescriptor()])
|
|
21
18
|
|
|
22
19
|
node1 = new DhtNode({
|
|
23
|
-
websocketPortRange,
|
|
20
|
+
websocketPortRange: WEBSOCKET_PORT_RANGE,
|
|
24
21
|
websocketHost: '127.0.0.1',
|
|
25
|
-
entryPoints: [
|
|
22
|
+
entryPoints: [epDhtNode.getLocalPeerDescriptor()],
|
|
26
23
|
websocketServerEnableTls: false
|
|
27
24
|
})
|
|
28
25
|
node2 = new DhtNode({
|
|
29
|
-
websocketPortRange,
|
|
26
|
+
websocketPortRange: WEBSOCKET_PORT_RANGE,
|
|
30
27
|
websocketHost: '127.0.0.1',
|
|
31
|
-
entryPoints: [
|
|
28
|
+
entryPoints: [epDhtNode.getLocalPeerDescriptor()],
|
|
32
29
|
websocketServerEnableTls: false
|
|
33
30
|
})
|
|
34
31
|
node3 = new DhtNode({
|
|
35
|
-
websocketPortRange,
|
|
32
|
+
websocketPortRange: WEBSOCKET_PORT_RANGE,
|
|
36
33
|
websocketHost: '127.0.0.1',
|
|
37
|
-
entryPoints: [
|
|
34
|
+
entryPoints: [epDhtNode.getLocalPeerDescriptor()],
|
|
38
35
|
websocketServerEnableTls: false
|
|
39
36
|
})
|
|
40
37
|
node4 = new DhtNode({
|
|
41
|
-
websocketPortRange,
|
|
38
|
+
websocketPortRange: WEBSOCKET_PORT_RANGE,
|
|
42
39
|
websocketHost: '127.0.0.1',
|
|
43
|
-
entryPoints: [
|
|
40
|
+
entryPoints: [epDhtNode.getLocalPeerDescriptor()],
|
|
44
41
|
websocketServerEnableTls: false
|
|
45
42
|
})
|
|
46
43
|
|
|
@@ -65,15 +62,15 @@ describe('Layer0', () => {
|
|
|
65
62
|
|
|
66
63
|
it('Happy path', async () => {
|
|
67
64
|
await Promise.all([
|
|
68
|
-
node1.joinDht([
|
|
69
|
-
node2.joinDht([
|
|
70
|
-
node3.joinDht([
|
|
71
|
-
node4.joinDht([
|
|
65
|
+
node1.joinDht([epDhtNode.getLocalPeerDescriptor()]),
|
|
66
|
+
node2.joinDht([epDhtNode.getLocalPeerDescriptor()]),
|
|
67
|
+
node3.joinDht([epDhtNode.getLocalPeerDescriptor()]),
|
|
68
|
+
node4.joinDht([epDhtNode.getLocalPeerDescriptor()])
|
|
72
69
|
])
|
|
73
70
|
|
|
74
|
-
expect(node1.
|
|
75
|
-
expect(node2.
|
|
76
|
-
expect(node3.
|
|
77
|
-
expect(node4.
|
|
71
|
+
expect(node1.getNeighborCount()).toBeGreaterThanOrEqual(2)
|
|
72
|
+
expect(node2.getNeighborCount()).toBeGreaterThanOrEqual(2)
|
|
73
|
+
expect(node3.getNeighborCount()).toBeGreaterThanOrEqual(2)
|
|
74
|
+
expect(node4.getNeighborCount()).toBeGreaterThanOrEqual(2)
|
|
78
75
|
}, 10000)
|
|
79
76
|
})
|
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import { NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
2
1
|
import { DhtNode } from '../../src/dht/DhtNode'
|
|
3
2
|
import { waitForEvent3 } from '@streamr/utils'
|
|
4
3
|
import { ConnectionManager } from '../../src/connection/ConnectionManager'
|
|
5
4
|
import { TransportEvents } from '../../src/transport/ITransport'
|
|
5
|
+
import { createMockPeerDescriptor } from '../utils/utils'
|
|
6
|
+
|
|
7
|
+
const WEBSOCKET_PORT_RANGE = { min: 11222, max: 11223 }
|
|
6
8
|
|
|
7
9
|
describe('Layer0MixedConnectionTypes', () => {
|
|
8
10
|
|
|
9
|
-
const epPeerDescriptor
|
|
10
|
-
kademliaId: Uint8Array.from([1, 2, 3]),
|
|
11
|
-
type: NodeType.NODEJS,
|
|
11
|
+
const epPeerDescriptor = createMockPeerDescriptor({
|
|
12
12
|
websocket: { host: '127.0.0.1', port: 11221, tls: false }
|
|
13
|
-
}
|
|
14
|
-
|
|
13
|
+
})
|
|
15
14
|
let epDhtNode: DhtNode
|
|
16
15
|
let node1: DhtNode
|
|
17
16
|
let node2: DhtNode
|
|
@@ -19,7 +18,6 @@ describe('Layer0MixedConnectionTypes', () => {
|
|
|
19
18
|
let node4: DhtNode
|
|
20
19
|
let node5: DhtNode
|
|
21
20
|
|
|
22
|
-
const websocketPortRange = { min: 11222, max: 11223 }
|
|
23
21
|
beforeEach(async () => {
|
|
24
22
|
|
|
25
23
|
epDhtNode = new DhtNode({
|
|
@@ -31,12 +29,12 @@ describe('Layer0MixedConnectionTypes', () => {
|
|
|
31
29
|
|
|
32
30
|
await epDhtNode.joinDht([epPeerDescriptor])
|
|
33
31
|
node1 = new DhtNode({
|
|
34
|
-
websocketPortRange,
|
|
32
|
+
websocketPortRange: WEBSOCKET_PORT_RANGE,
|
|
35
33
|
entryPoints: [epPeerDescriptor],
|
|
36
34
|
websocketServerEnableTls: false
|
|
37
35
|
})
|
|
38
36
|
node2 = new DhtNode({
|
|
39
|
-
websocketPortRange,
|
|
37
|
+
websocketPortRange: WEBSOCKET_PORT_RANGE,
|
|
40
38
|
entryPoints: [epPeerDescriptor],
|
|
41
39
|
websocketServerEnableTls: false
|
|
42
40
|
})
|
|
@@ -89,13 +87,13 @@ describe('Layer0MixedConnectionTypes', () => {
|
|
|
89
87
|
node5.joinDht([epPeerDescriptor])
|
|
90
88
|
])
|
|
91
89
|
|
|
92
|
-
expect(node1.
|
|
93
|
-
expect(node2.
|
|
94
|
-
expect(node3.
|
|
95
|
-
expect(node4.
|
|
96
|
-
expect(node5.
|
|
90
|
+
expect(node1.getNeighborCount()).toBeGreaterThanOrEqual(2)
|
|
91
|
+
expect(node2.getNeighborCount()).toBeGreaterThanOrEqual(2)
|
|
92
|
+
expect(node3.getNeighborCount()).toBeGreaterThanOrEqual(2)
|
|
93
|
+
expect(node4.getNeighborCount()).toBeGreaterThanOrEqual(2)
|
|
94
|
+
expect(node5.getNeighborCount()).toBeGreaterThanOrEqual(1)
|
|
97
95
|
|
|
98
|
-
},
|
|
96
|
+
}, 20000)
|
|
99
97
|
|
|
100
98
|
it('Simultaneous joins', async () => {
|
|
101
99
|
await Promise.all([
|
|
@@ -105,10 +103,10 @@ describe('Layer0MixedConnectionTypes', () => {
|
|
|
105
103
|
node4.joinDht([epPeerDescriptor]),
|
|
106
104
|
node5.joinDht([epPeerDescriptor])
|
|
107
105
|
])
|
|
108
|
-
expect(node1.
|
|
109
|
-
expect(node2.
|
|
110
|
-
expect(node3.
|
|
111
|
-
expect(node4.
|
|
112
|
-
expect(node5.
|
|
113
|
-
},
|
|
106
|
+
expect(node1.getNeighborCount()).toBeGreaterThanOrEqual(2)
|
|
107
|
+
expect(node2.getNeighborCount()).toBeGreaterThanOrEqual(2)
|
|
108
|
+
expect(node3.getNeighborCount()).toBeGreaterThanOrEqual(2)
|
|
109
|
+
expect(node4.getNeighborCount()).toBeGreaterThanOrEqual(2)
|
|
110
|
+
expect(node5.getNeighborCount()).toBeGreaterThanOrEqual(2)
|
|
111
|
+
}, 40000)
|
|
114
112
|
})
|