@streamr/dht 101.1.2 → 102.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/package.json +17 -18
- package/dist/src/connection/Connection.d.ts +1 -1
- package/dist/src/connection/ConnectionLockRpcLocal.d.ts +5 -3
- package/dist/src/connection/ConnectionLockRpcLocal.js +9 -3
- package/dist/src/connection/ConnectionLockRpcLocal.js.map +1 -1
- package/dist/src/connection/ConnectionLockRpcRemote.d.ts +3 -2
- package/dist/src/connection/ConnectionLockRpcRemote.js +14 -3
- package/dist/src/connection/ConnectionLockRpcRemote.js.map +1 -1
- package/dist/src/connection/ConnectionLockStates.d.ts +5 -0
- package/dist/src/connection/ConnectionLockStates.js +14 -0
- package/dist/src/connection/ConnectionLockStates.js.map +1 -1
- package/dist/src/connection/ConnectionManager.d.ts +8 -1
- package/dist/src/connection/ConnectionManager.js +96 -32
- package/dist/src/connection/ConnectionManager.js.map +1 -1
- package/dist/src/connection/ConnectionsView.d.ts +1 -1
- package/dist/src/connection/ConnectorFacade.d.ts +1 -1
- package/dist/src/connection/Handshaker.d.ts +2 -2
- package/dist/src/connection/Handshaker.js +11 -7
- package/dist/src/connection/Handshaker.js.map +1 -1
- package/dist/src/connection/ManagedConnection.d.ts +7 -1
- package/dist/src/connection/ManagedConnection.js +41 -8
- package/dist/src/connection/ManagedConnection.js.map +1 -1
- package/dist/src/connection/PendingConnection.d.ts +1 -1
- package/dist/src/connection/connectivityChecker.d.ts +1 -1
- package/dist/src/connection/connectivityChecker.js +22 -11
- package/dist/src/connection/connectivityChecker.js.map +1 -1
- package/dist/src/connection/connectivityRequestHandler.js +4 -4
- package/dist/src/connection/connectivityRequestHandler.js.map +1 -1
- package/dist/src/connection/simulator/Simulator.d.ts +1 -1
- package/dist/src/connection/simulator/Simulator.js +5 -4
- package/dist/src/connection/simulator/Simulator.js.map +1 -1
- package/dist/src/connection/simulator/SimulatorConnection.d.ts +1 -1
- package/dist/src/connection/simulator/SimulatorConnection.js +9 -9
- package/dist/src/connection/simulator/SimulatorConnection.js.map +1 -1
- package/dist/src/connection/simulator/SimulatorConnector.d.ts +1 -1
- package/dist/src/connection/simulator/SimulatorConnector.js +4 -4
- package/dist/src/connection/simulator/SimulatorConnector.js.map +1 -1
- package/dist/src/connection/simulator/SimulatorTransport.d.ts +1 -1
- package/dist/src/connection/simulator/SimulatorTransport.js +2 -1
- package/dist/src/connection/simulator/SimulatorTransport.js.map +1 -1
- package/dist/src/connection/simulator/pings.d.ts +1 -1
- package/dist/src/connection/simulator/pings.js +3 -3
- package/dist/src/connection/simulator/pings.js.map +1 -1
- package/dist/src/connection/webrtc/NodeWebrtcConnection.d.ts +2 -1
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js +13 -8
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnector.d.ts +2 -1
- package/dist/src/connection/webrtc/WebrtcConnector.js +28 -17
- package/dist/src/connection/webrtc/WebrtcConnector.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.d.ts +3 -3
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js +4 -4
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.d.ts +1 -1
- package/dist/src/connection/webrtc/iceServerAsString.js +1 -2
- package/dist/src/connection/webrtc/iceServerAsString.js.map +1 -1
- package/dist/src/connection/websocket/AbstractWebsocketClientConnection.d.ts +0 -1
- package/dist/src/connection/websocket/WebsocketClientConnector.d.ts +1 -1
- package/dist/src/connection/websocket/WebsocketClientConnector.js +3 -3
- package/dist/src/connection/websocket/WebsocketClientConnector.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketClientConnectorRpcLocal.d.ts +3 -4
- package/dist/src/connection/websocket/WebsocketClientConnectorRpcLocal.js +1 -1
- package/dist/src/connection/websocket/WebsocketClientConnectorRpcLocal.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketClientConnectorRpcRemote.d.ts +1 -1
- package/dist/src/connection/websocket/WebsocketClientConnectorRpcRemote.js +1 -1
- package/dist/src/connection/websocket/WebsocketClientConnectorRpcRemote.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketServerConnection.d.ts +0 -1
- package/dist/src/connection/websocket/WebsocketServerConnector.d.ts +1 -1
- package/dist/src/connection/websocket/WebsocketServerConnector.js +34 -24
- package/dist/src/connection/websocket/WebsocketServerConnector.js.map +1 -1
- package/dist/src/dht/DhtNode.d.ts +5 -2
- package/dist/src/dht/DhtNode.js +20 -8
- package/dist/src/dht/DhtNode.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcLocal.d.ts +4 -4
- package/dist/src/dht/DhtNodeRpcLocal.js +3 -3
- package/dist/src/dht/DhtNodeRpcLocal.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcRemote.d.ts +2 -2
- package/dist/src/dht/DhtNodeRpcRemote.js +3 -3
- package/dist/src/dht/DhtNodeRpcRemote.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcLocal.d.ts +3 -3
- package/dist/src/dht/ExternalApiRpcLocal.js +3 -3
- package/dist/src/dht/ExternalApiRpcLocal.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcRemote.d.ts +3 -3
- package/dist/src/dht/ExternalApiRpcRemote.js +2 -2
- package/dist/src/dht/ExternalApiRpcRemote.js.map +1 -1
- package/dist/src/dht/PeerManager.d.ts +3 -2
- package/dist/src/dht/PeerManager.js +12 -11
- package/dist/src/dht/PeerManager.js.map +1 -1
- package/dist/src/dht/contact/Contact.d.ts +1 -1
- package/dist/src/dht/contact/Contact.js +1 -1
- package/dist/src/dht/contact/Contact.js.map +1 -1
- package/dist/src/dht/contact/RingContactList.d.ts +1 -1
- package/dist/src/dht/contact/RingContactList.js +1 -1
- package/dist/src/dht/contact/RingContactList.js.map +1 -1
- package/dist/src/dht/contact/RpcRemote.d.ts +1 -1
- package/dist/src/dht/contact/SortedContactList.js +2 -2
- package/dist/src/dht/contact/SortedContactList.js.map +1 -1
- package/dist/src/dht/contact/ringIdentifiers.d.ts +1 -1
- package/dist/src/dht/discovery/DiscoverySession.d.ts +1 -2
- package/dist/src/dht/discovery/DiscoverySession.js +3 -3
- package/dist/src/dht/discovery/DiscoverySession.js.map +1 -1
- package/dist/src/dht/discovery/PeerDiscovery.d.ts +1 -2
- package/dist/src/dht/discovery/PeerDiscovery.js +7 -7
- package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -1
- package/dist/src/dht/discovery/RingDiscoverySession.d.ts +0 -1
- package/dist/src/dht/discovery/RingDiscoverySession.js +1 -1
- package/dist/src/dht/discovery/RingDiscoverySession.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.d.ts +3 -3
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.js +8 -8
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.d.ts +2 -2
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.js +2 -2
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.d.ts +2 -2
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js +3 -3
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.d.ts +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.js +7 -7
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.d.ts +3 -3
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.d.ts +2 -2
- package/dist/src/dht/routing/DuplicateDetector.js.map +1 -1
- package/dist/src/dht/routing/Router.d.ts +4 -1
- package/dist/src/dht/routing/Router.js +17 -9
- package/dist/src/dht/routing/Router.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcLocal.d.ts +2 -2
- package/dist/src/dht/routing/RouterRpcLocal.js +5 -5
- package/dist/src/dht/routing/RouterRpcLocal.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcRemote.d.ts +2 -2
- package/dist/src/dht/routing/RouterRpcRemote.js +7 -7
- package/dist/src/dht/routing/RouterRpcRemote.js.map +1 -1
- package/dist/src/dht/routing/RoutingSession.d.ts +1 -1
- package/dist/src/dht/routing/RoutingSession.js +7 -8
- package/dist/src/dht/routing/RoutingSession.js.map +1 -1
- package/dist/src/dht/routing/RoutingTablesCache.d.ts +1 -1
- package/dist/src/dht/routing/getPreviousPeer.d.ts +1 -1
- package/dist/src/dht/store/LocalDataStore.d.ts +1 -1
- package/dist/src/dht/store/LocalDataStore.js +3 -3
- package/dist/src/dht/store/LocalDataStore.js.map +1 -1
- package/dist/src/dht/store/StoreManager.d.ts +3 -3
- package/dist/src/dht/store/StoreManager.js +8 -8
- package/dist/src/dht/store/StoreManager.js.map +1 -1
- package/dist/src/dht/store/StoreRpcLocal.d.ts +4 -4
- package/dist/src/dht/store/StoreRpcLocal.js +4 -4
- package/dist/src/dht/store/StoreRpcLocal.js.map +1 -1
- package/dist/src/dht/store/StoreRpcRemote.d.ts +3 -3
- package/dist/src/dht/store/StoreRpcRemote.js +7 -4
- package/dist/src/dht/store/StoreRpcRemote.js.map +1 -1
- package/dist/src/exports.d.ts +2 -2
- package/dist/src/exports.js +6 -6
- package/dist/src/exports.js.map +1 -1
- package/dist/src/helpers/AddressTools.js +2 -3
- package/dist/src/helpers/AddressTools.js.map +1 -1
- package/dist/src/helpers/Connectivity.d.ts +1 -1
- package/dist/src/helpers/Connectivity.js +1 -1
- package/dist/src/helpers/Connectivity.js.map +1 -1
- package/dist/src/helpers/createPeerDescriptor.d.ts +1 -1
- package/dist/src/helpers/createPeerDescriptor.js +2 -2
- package/dist/src/helpers/createPeerDescriptor.js.map +1 -1
- package/dist/src/helpers/createPeerDescriptorSignaturePayload.d.ts +1 -1
- package/dist/src/helpers/createPeerDescriptorSignaturePayload.js +1 -1
- package/dist/src/helpers/createPeerDescriptorSignaturePayload.js.map +1 -1
- package/dist/src/helpers/debugHelpers.js +2 -2
- package/dist/src/helpers/debugHelpers.js.map +1 -1
- package/dist/src/helpers/protoClasses.d.ts +1 -1
- package/dist/src/helpers/protoClasses.js +1 -1
- package/dist/src/helpers/protoClasses.js.map +1 -1
- package/dist/src/helpers/protoToString.js +1 -2
- package/dist/src/helpers/protoToString.js.map +1 -1
- package/dist/src/helpers/version.d.ts +1 -1
- package/dist/src/helpers/version.js +4 -4
- package/dist/src/helpers/version.js.map +1 -1
- package/dist/src/identifiers.d.ts +5 -5
- package/dist/src/identifiers.js +11 -11
- package/dist/src/identifiers.js.map +1 -1
- package/dist/src/rpc-protocol/DhtCallContext.d.ts +1 -1
- package/dist/src/rpc-protocol/DhtRpcOptions.d.ts +1 -1
- package/dist/src/transport/ITransport.d.ts +2 -1
- package/dist/src/transport/ListeningRpcCommunicator.d.ts +2 -1
- package/dist/src/transport/ListeningRpcCommunicator.js +13 -4
- package/dist/src/transport/ListeningRpcCommunicator.js.map +1 -1
- package/dist/src/transport/RoutingRpcCommunicator.d.ts +1 -1
- package/eslint.config.mjs +12 -0
- package/jest.config.ts +12 -0
- package/package.json +17 -18
- package/proto.sh +2 -3
- package/protos/DhtRpc.proto +11 -4
- package/src/connection/Connection.ts +1 -1
- package/src/connection/ConnectionLockRpcLocal.ts +16 -7
- package/src/connection/ConnectionLockRpcRemote.ts +18 -6
- package/src/connection/ConnectionLockStates.ts +18 -0
- package/src/connection/ConnectionManager.ts +93 -27
- package/src/connection/ConnectionsView.ts +1 -1
- package/src/connection/ConnectorFacade.ts +1 -1
- package/src/connection/Handshaker.ts +18 -14
- package/src/connection/ManagedConnection.ts +28 -3
- package/src/connection/PendingConnection.ts +1 -1
- package/src/connection/connectivityChecker.ts +6 -5
- package/src/connection/connectivityRequestHandler.ts +4 -4
- package/src/connection/simulator/Simulator.ts +8 -7
- package/src/connection/simulator/SimulatorConnection.ts +10 -10
- package/src/connection/simulator/SimulatorConnector.ts +5 -5
- package/src/connection/simulator/SimulatorTransport.ts +3 -2
- package/src/connection/simulator/pings.ts +1 -1
- package/src/connection/webrtc/BrowserWebrtcConnection.ts +10 -1
- package/src/connection/webrtc/NodeWebrtcConnection.ts +15 -11
- package/src/connection/webrtc/WebrtcConnector.ts +13 -11
- package/src/connection/webrtc/WebrtcConnectorRpcLocal.ts +8 -8
- package/src/connection/webrtc/WebrtcConnectorRpcRemote.ts +2 -2
- package/src/connection/websocket/WebsocketClientConnector.ts +5 -5
- package/src/connection/websocket/WebsocketClientConnectorRpcLocal.ts +5 -5
- package/src/connection/websocket/WebsocketClientConnectorRpcRemote.ts +4 -4
- package/src/connection/websocket/WebsocketServerConnector.ts +24 -20
- package/src/dht/DhtNode.ts +29 -11
- package/src/dht/DhtNodeRpcLocal.ts +8 -8
- package/src/dht/DhtNodeRpcRemote.ts +5 -5
- package/src/dht/ExternalApiRpcLocal.ts +8 -8
- package/src/dht/ExternalApiRpcRemote.ts +6 -6
- package/src/dht/PeerManager.ts +16 -14
- package/src/dht/contact/Contact.ts +3 -3
- package/src/dht/contact/RingContactList.ts +3 -3
- package/src/dht/contact/RpcRemote.ts +1 -1
- package/src/dht/contact/SortedContactList.ts +3 -3
- package/src/dht/contact/ringIdentifiers.ts +1 -1
- package/src/dht/discovery/DiscoverySession.ts +5 -5
- package/src/dht/discovery/PeerDiscovery.ts +12 -12
- package/src/dht/discovery/RingDiscoverySession.ts +3 -3
- package/src/dht/recursive-operation/RecursiveOperationManager.ts +10 -10
- package/src/dht/recursive-operation/RecursiveOperationRpcLocal.ts +4 -4
- package/src/dht/recursive-operation/RecursiveOperationRpcRemote.ts +6 -6
- package/src/dht/recursive-operation/RecursiveOperationSession.ts +8 -8
- package/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.ts +5 -5
- package/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.ts +2 -2
- package/src/dht/routing/DuplicateDetector.ts +1 -1
- package/src/dht/routing/Router.ts +19 -10
- package/src/dht/routing/RouterRpcLocal.ts +7 -7
- package/src/dht/routing/RouterRpcRemote.ts +9 -9
- package/src/dht/routing/RoutingSession.ts +9 -10
- package/src/dht/routing/RoutingTablesCache.ts +1 -1
- package/src/dht/routing/getPreviousPeer.ts +1 -1
- package/src/dht/store/LocalDataStore.ts +5 -5
- package/src/dht/store/StoreManager.ts +13 -13
- package/src/dht/store/StoreRpcLocal.ts +9 -9
- package/src/dht/store/StoreRpcRemote.ts +10 -7
- package/src/exports.ts +5 -5
- package/src/helpers/Connectivity.ts +1 -1
- package/src/helpers/createPeerDescriptor.ts +3 -3
- package/src/helpers/createPeerDescriptorSignaturePayload.ts +1 -1
- package/src/helpers/protoClasses.ts +2 -2
- package/src/helpers/version.ts +2 -2
- package/src/identifiers.ts +7 -7
- package/src/rpc-protocol/DhtCallContext.ts +1 -1
- package/src/rpc-protocol/DhtRpcOptions.ts +1 -1
- package/src/transport/ITransport.ts +2 -1
- package/src/transport/ListeningRpcCommunicator.ts +14 -6
- package/src/transport/RoutingRpcCommunicator.ts +2 -2
- package/test/benchmark/Find.test.ts +9 -9
- package/test/benchmark/KademliaCorrectness.test.ts +7 -7
- package/test/benchmark/RingCorrectness.test.ts +8 -8
- package/test/benchmark/SortedContactListBenchmark.test.ts +10 -10
- package/test/benchmark/hybrid-network-simulation/RingContactList.test.ts +3 -3
- package/test/end-to-end/Layer0Webrtc-Layer1.test.ts +6 -6
- package/test/end-to-end/Layer0Webrtc.test.ts +6 -6
- package/test/end-to-end/RecoveryFromFailedAutoCertification.test.ts +1 -1
- package/test/end-to-end/WebsocketConnectionRequest.test.ts +3 -3
- package/test/end-to-end/memory-leak.test.ts +6 -6
- package/test/integration/ConnectionLocking.test.ts +48 -37
- package/test/integration/ConnectionManager.test.ts +62 -6
- package/test/integration/ConnectivityChecking.test.ts +3 -2
- package/test/integration/DhtJoinPeerDiscovery.test.ts +2 -2
- package/test/integration/DhtNode.test.ts +6 -6
- package/test/integration/DhtNodeExternalAPI.test.ts +7 -7
- package/test/integration/DhtNodeRpcRemote.test.ts +9 -9
- package/test/integration/DhtRpc.test.ts +12 -13
- package/test/integration/Find.test.ts +5 -5
- package/test/integration/GeoIpConnectivityChecking.test.ts +8 -7
- package/test/integration/Layer1-scale.test.ts +3 -3
- package/test/integration/Mock-Layer1-Layer0.test.ts +6 -6
- package/test/integration/MultipleEntryPointJoining.test.ts +1 -1
- package/test/integration/ReplicateData.test.ts +10 -11
- package/test/integration/RouteMessage.test.ts +13 -13
- package/test/integration/RouterRpcRemote.test.ts +7 -7
- package/test/integration/SimultaneousConnections.test.ts +14 -13
- package/test/integration/Store.test.ts +9 -9
- package/test/integration/StoreAndDelete.test.ts +10 -10
- package/test/integration/StoreOnDhtWithThreeNodes.test.ts +10 -10
- package/test/integration/StoreOnDhtWithTwoNodes.test.ts +10 -10
- package/test/integration/StoreRpcRemote.test.ts +11 -11
- package/test/integration/WebrtcConnectionManagement.test.ts +4 -31
- package/test/integration/WebrtcConnectorRpc.test.ts +14 -14
- package/test/integration/Websocket.test.ts +0 -2
- package/test/integration/WebsocketClientConnectorRpc.test.ts +8 -8
- package/test/integration/WebsocketConnectionManagement.test.ts +11 -12
- package/test/integration/{rpc-connections-over-webrpc.test.ts → rpc-connections-over-webrtc.test.ts} +12 -46
- package/test/unit/AutoCertifierClientFacade.test.ts +6 -6
- package/test/unit/ConnectionManager.test.ts +4 -3
- package/test/unit/ConnectivityHelpers.test.ts +1 -1
- package/test/unit/DiscoverySession.test.ts +6 -6
- package/test/unit/Handshaker.test.ts +2 -2
- package/test/unit/ListeningRpcCommunicator.test.ts +52 -0
- package/test/unit/LocalDataStore.test.ts +21 -21
- package/test/unit/PeerManager.test.ts +15 -15
- package/test/unit/PendingConnection.test.ts +1 -1
- package/test/unit/ProtobufMessage.test.ts +1 -1
- package/test/unit/RandomContactList.test.ts +2 -2
- package/test/unit/RecursiveOperationManager.test.ts +3 -3
- package/test/unit/RecursiveOperationSession.test.ts +6 -6
- package/test/unit/Router.test.ts +6 -6
- package/test/unit/RoutingSession.test.ts +13 -6
- package/test/unit/SortedContactList.test.ts +8 -8
- package/test/unit/StoreManager.test.ts +12 -12
- package/test/unit/StoreRpcLocal.test.ts +9 -9
- package/test/unit/WebrtcConnection.test.ts +29 -0
- package/test/unit/WebsocketClientConnector.test.ts +1 -1
- package/test/unit/WebsocketServerConnector.test.ts +1 -1
- package/test/unit/connectivityRequestHandler.test.ts +6 -6
- package/test/unit/createPeerDescriptor.test.ts +4 -4
- package/test/unit/customMatchers.test.ts +18 -0
- package/test/unit/getClosestNodes.test.ts +5 -5
- package/test/unit/version.test.ts +9 -9
- package/test/utils/FakeConnectorFacade.ts +1 -1
- package/test/utils/FakeTransport.ts +12 -9
- package/test/utils/customMatchers.ts +9 -9
- package/test/utils/mock/MockConnectionsView.ts +1 -1
- package/test/utils/mock/MockRouter.ts +5 -1
- package/test/utils/mock/MockTransport.ts +6 -1
- package/test/utils/mock/mockDataEntry.ts +6 -6
- package/test/utils/topology.ts +3 -4
- package/test/utils/utils.ts +11 -11
- package/tsconfig.jest.json +2 -1
- package/tsconfig.node.json +1 -0
- package/.eslintignore +0 -5
- package/.eslintrc +0 -3
- package/dist/src/proto/google/protobuf/any.d.ts +0 -173
- package/dist/src/proto/google/protobuf/any.js +0 -155
- package/dist/src/proto/google/protobuf/any.js.map +0 -1
- package/dist/src/proto/google/protobuf/empty.d.ts +0 -32
- package/dist/src/proto/google/protobuf/empty.js +0 -32
- package/dist/src/proto/google/protobuf/empty.js.map +0 -1
- package/dist/src/proto/google/protobuf/timestamp.d.ts +0 -149
- package/dist/src/proto/google/protobuf/timestamp.js +0 -136
- package/dist/src/proto/google/protobuf/timestamp.js.map +0 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +0 -352
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +0 -278
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +0 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +0 -975
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +0 -661
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +0 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +0 -157
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.js +0 -3
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.js.map +0 -1
- package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.d.ts +0 -87
- package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.js +0 -66
- package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.js.map +0 -1
- package/dist/src/proto/tests.d.ts +0 -39
- package/dist/src/proto/tests.js +0 -34
- package/dist/src/proto/tests.js.map +0 -1
- package/jest.config.js +0 -5
- package/src/proto/google/protobuf/any.ts +0 -319
- package/src/proto/google/protobuf/empty.ts +0 -82
- package/src/proto/google/protobuf/timestamp.ts +0 -281
- package/src/proto/packages/dht/protos/DhtRpc.client.ts +0 -407
- package/src/proto/packages/dht/protos/DhtRpc.server.ts +0 -160
- package/src/proto/packages/dht/protos/DhtRpc.ts +0 -1244
- package/src/proto/packages/proto-rpc/protos/ProtoRpc.ts +0 -108
- package/src/proto/tests.ts +0 -52
- package/test/benchmark/any.test.ts +0 -28
- /package/{src/types/glogal.d.ts → test/types/global.d.ts} +0 -0
package/src/dht/DhtNode.ts
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
MetricsContext,
|
|
5
5
|
merge,
|
|
6
6
|
scheduleAtInterval,
|
|
7
|
-
|
|
7
|
+
until
|
|
8
8
|
} from '@streamr/utils'
|
|
9
9
|
import { EventEmitter } from 'eventemitter3'
|
|
10
10
|
import { sample } from 'lodash'
|
|
@@ -15,8 +15,8 @@ import { DefaultConnectorFacade, DefaultConnectorFacadeOptions } from '../connec
|
|
|
15
15
|
import { IceServer } from '../connection/webrtc/WebrtcConnector'
|
|
16
16
|
import { isBrowserEnvironment } from '../helpers/browser/isBrowserEnvironment'
|
|
17
17
|
import { createPeerDescriptor } from '../helpers/createPeerDescriptor'
|
|
18
|
-
import { DhtAddress, KADEMLIA_ID_LENGTH_IN_BYTES,
|
|
19
|
-
import { Any } from '
|
|
18
|
+
import { DhtAddress, KADEMLIA_ID_LENGTH_IN_BYTES, toNodeId } from '../identifiers'
|
|
19
|
+
import { Any } from '../../generated/google/protobuf/any'
|
|
20
20
|
import {
|
|
21
21
|
ClosestPeersRequest,
|
|
22
22
|
ClosestPeersResponse,
|
|
@@ -34,8 +34,8 @@ import {
|
|
|
34
34
|
PingRequest,
|
|
35
35
|
PingResponse,
|
|
36
36
|
RecursiveOperation
|
|
37
|
-
} from '
|
|
38
|
-
import { ExternalApiRpcClient, StoreRpcClient } from '
|
|
37
|
+
} from '../../generated/packages/dht/protos/DhtRpc'
|
|
38
|
+
import { ExternalApiRpcClient, StoreRpcClient } from '../../generated/packages/dht/protos/DhtRpc.client'
|
|
39
39
|
import { ITransport, TransportEvents } from '../transport/ITransport'
|
|
40
40
|
import { RoutingRpcCommunicator } from '../transport/RoutingRpcCommunicator'
|
|
41
41
|
import { ServiceID } from '../types/ServiceID'
|
|
@@ -79,6 +79,10 @@ export interface DhtNodeOptions {
|
|
|
79
79
|
storageRedundancyFactor?: number
|
|
80
80
|
periodicallyPingNeighbors?: boolean
|
|
81
81
|
periodicallyPingRingContacts?: boolean
|
|
82
|
+
// Limit for how many new neighbors to ping. If number of neighbors is higher than the limit new neighbors
|
|
83
|
+
// are not pinged when they are added. This is to prevent flooding the network with pings when joining.
|
|
84
|
+
// Enable periodicallyPingNeighbors to eventually ping all neighbors.
|
|
85
|
+
neighborPingLimit?: number
|
|
82
86
|
|
|
83
87
|
transport?: ITransport
|
|
84
88
|
connectionsView?: ConnectionsView
|
|
@@ -104,6 +108,7 @@ export interface DhtNodeOptions {
|
|
|
104
108
|
autoCertifierUrl?: string
|
|
105
109
|
autoCertifierConfigFile?: string
|
|
106
110
|
geoIpDatabaseFolder?: string
|
|
111
|
+
allowIncomingPrivateConnections?: boolean
|
|
107
112
|
}
|
|
108
113
|
|
|
109
114
|
type StrictDhtNodeOptions = MarkRequired<DhtNodeOptions,
|
|
@@ -242,7 +247,8 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
242
247
|
const connectionManager = new ConnectionManager({
|
|
243
248
|
createConnectorFacade: () => new DefaultConnectorFacade(connectorFacadeOptions),
|
|
244
249
|
maxConnections: this.options.maxConnections,
|
|
245
|
-
metricsContext: this.options.metricsContext
|
|
250
|
+
metricsContext: this.options.metricsContext,
|
|
251
|
+
allowIncomingPrivateConnections: this.options.allowIncomingPrivateConnections ?? false
|
|
246
252
|
})
|
|
247
253
|
await connectionManager.start()
|
|
248
254
|
this.connectionsView = connectionManager
|
|
@@ -338,7 +344,8 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
338
344
|
connectionLocker: this.connectionLocker,
|
|
339
345
|
lockId: this.options.serviceId,
|
|
340
346
|
createDhtNodeRpcRemote: (peerDescriptor: PeerDescriptor) => this.createDhtNodeRpcRemote(peerDescriptor),
|
|
341
|
-
hasConnection: (nodeId: DhtAddress) => this.connectionsView!.hasConnection(nodeId)
|
|
347
|
+
hasConnection: (nodeId: DhtAddress) => this.connectionsView!.hasConnection(nodeId),
|
|
348
|
+
neighborPingLimit: this.options.neighborPingLimit
|
|
342
349
|
})
|
|
343
350
|
this.peerManager.on('nearbyContactRemoved', (peerDescriptor: PeerDescriptor) => {
|
|
344
351
|
this.emit('nearbyContactRemoved', peerDescriptor)
|
|
@@ -381,7 +388,7 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
381
388
|
this.transport!.on('disconnected', (peerDescriptor: PeerDescriptor, gracefulLeave: boolean) => {
|
|
382
389
|
const isControlLayerNode = (this.connectionLocker !== undefined)
|
|
383
390
|
if (isControlLayerNode) {
|
|
384
|
-
const nodeId =
|
|
391
|
+
const nodeId = toNodeId(peerDescriptor)
|
|
385
392
|
if (gracefulLeave) {
|
|
386
393
|
this.peerManager!.removeContact(nodeId)
|
|
387
394
|
} else {
|
|
@@ -500,7 +507,7 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
500
507
|
}
|
|
501
508
|
|
|
502
509
|
public getNodeId(): DhtAddress {
|
|
503
|
-
return
|
|
510
|
+
return toNodeId(this.localPeerDescriptor!)
|
|
504
511
|
}
|
|
505
512
|
|
|
506
513
|
public getNeighborCount(): number {
|
|
@@ -524,7 +531,7 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
524
531
|
|
|
525
532
|
private getConnectedEntryPoints(): PeerDescriptor[] {
|
|
526
533
|
return this.options.entryPoints !== undefined ? this.options.entryPoints.filter((entryPoint) =>
|
|
527
|
-
this.connectionsView!.hasConnection(
|
|
534
|
+
this.connectionsView!.hasConnection(toNodeId(entryPoint))
|
|
528
535
|
) : []
|
|
529
536
|
}
|
|
530
537
|
|
|
@@ -619,7 +626,7 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
619
626
|
}
|
|
620
627
|
|
|
621
628
|
public async waitForNetworkConnectivity(): Promise<void> {
|
|
622
|
-
await
|
|
629
|
+
await until(
|
|
623
630
|
() => this.connectionsView!.getConnectionCount() > 0,
|
|
624
631
|
this.options.networkConnectivityTimeout,
|
|
625
632
|
100,
|
|
@@ -631,6 +638,17 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
631
638
|
return this.peerDiscovery!.isJoinCalled()
|
|
632
639
|
}
|
|
633
640
|
|
|
641
|
+
public getDiagnosticInfo(): Record<string, unknown> {
|
|
642
|
+
return {
|
|
643
|
+
localPeerDescriptor: this.localPeerDescriptor,
|
|
644
|
+
transport: this.transport!.getDiagnosticInfo(),
|
|
645
|
+
router: this.router!.getDiagnosticInfo(),
|
|
646
|
+
neighborCount: this.getNeighborCount(),
|
|
647
|
+
nearbyContactCount: Array.from(this.peerManager!.getNearbyContacts().getAllContactsInUndefinedOrder()).length,
|
|
648
|
+
randomContactCount: this.peerManager!.getRandomContacts().getSize()
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
|
|
634
652
|
public async stop(): Promise<void> {
|
|
635
653
|
if (this.abortController.signal.aborted || !this.started) {
|
|
636
654
|
return
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
2
2
|
import { Logger } from '@streamr/utils'
|
|
3
|
-
import { DhtAddress,
|
|
4
|
-
import { Empty } from '
|
|
3
|
+
import { DhtAddress, toDhtAddress, toNodeId } from '../identifiers'
|
|
4
|
+
import { Empty } from '../../generated/google/protobuf/empty'
|
|
5
5
|
import {
|
|
6
6
|
ClosestPeersRequest,
|
|
7
7
|
ClosestPeersResponse,
|
|
@@ -10,8 +10,8 @@ import {
|
|
|
10
10
|
PeerDescriptor,
|
|
11
11
|
PingRequest,
|
|
12
12
|
PingResponse
|
|
13
|
-
} from '
|
|
14
|
-
import { IDhtNodeRpc } from '
|
|
13
|
+
} from '../../generated/packages/dht/protos/DhtRpc'
|
|
14
|
+
import { IDhtNodeRpc } from '../../generated/packages/dht/protos/DhtRpc.server'
|
|
15
15
|
import { DhtCallContext } from '../rpc-protocol/DhtCallContext'
|
|
16
16
|
import { RingContacts } from './contact/RingContactList'
|
|
17
17
|
import { getClosestNodes } from './contact/getClosestNodes'
|
|
@@ -19,7 +19,7 @@ import { RingIdRaw } from './contact/ringIdentifiers'
|
|
|
19
19
|
|
|
20
20
|
interface DhtNodeRpcLocalOptions {
|
|
21
21
|
peerDiscoveryQueryBatchSize: number
|
|
22
|
-
getNeighbors: () =>
|
|
22
|
+
getNeighbors: () => readonly PeerDescriptor[]
|
|
23
23
|
getClosestRingContactsTo: (id: RingIdRaw, limit: number) => RingContacts
|
|
24
24
|
addContact: (contact: PeerDescriptor) => void
|
|
25
25
|
removeContact: (nodeId: DhtAddress) => void
|
|
@@ -39,7 +39,7 @@ export class DhtNodeRpcLocal implements IDhtNodeRpc {
|
|
|
39
39
|
async getClosestPeers(request: ClosestPeersRequest, context: ServerCallContext): Promise<ClosestPeersResponse> {
|
|
40
40
|
this.options.addContact((context as DhtCallContext).incomingSourceDescriptor!)
|
|
41
41
|
const peers = getClosestNodes(
|
|
42
|
-
|
|
42
|
+
toDhtAddress(request.nodeId),
|
|
43
43
|
this.options.getNeighbors(),
|
|
44
44
|
{ maxCount: this.options.peerDiscoveryQueryBatchSize }
|
|
45
45
|
)
|
|
@@ -63,7 +63,7 @@ export class DhtNodeRpcLocal implements IDhtNodeRpc {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
async ping(request: PingRequest, context: ServerCallContext): Promise<PingResponse> {
|
|
66
|
-
logger.trace('received ping request: ' +
|
|
66
|
+
logger.trace('received ping request: ' + toNodeId((context as DhtCallContext).incomingSourceDescriptor!))
|
|
67
67
|
setImmediate(() => {
|
|
68
68
|
this.options.addContact((context as DhtCallContext).incomingSourceDescriptor!)
|
|
69
69
|
})
|
|
@@ -76,7 +76,7 @@ export class DhtNodeRpcLocal implements IDhtNodeRpc {
|
|
|
76
76
|
async leaveNotice(context: ServerCallContext): Promise<Empty> {
|
|
77
77
|
// TODO check signature??
|
|
78
78
|
const sender = (context as DhtCallContext).incomingSourceDescriptor!
|
|
79
|
-
const senderNodeId =
|
|
79
|
+
const senderNodeId = toNodeId(sender)
|
|
80
80
|
logger.trace('received leave notice: ' + senderNodeId)
|
|
81
81
|
this.options.removeContact(senderNodeId)
|
|
82
82
|
return {}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { RpcCommunicator } from '@streamr/proto-rpc'
|
|
2
2
|
import { Logger } from '@streamr/utils'
|
|
3
3
|
import { v4 } from 'uuid'
|
|
4
|
-
import { DhtAddress, DhtAddressRaw,
|
|
4
|
+
import { DhtAddress, DhtAddressRaw, toNodeId, toDhtAddressRaw } from '../identifiers'
|
|
5
5
|
import {
|
|
6
6
|
ClosestPeersRequest,
|
|
7
7
|
ClosestRingPeersRequest,
|
|
8
8
|
PeerDescriptor,
|
|
9
9
|
PingRequest
|
|
10
|
-
} from '
|
|
11
|
-
import { DhtNodeRpcClient } from '
|
|
10
|
+
} from '../../generated/packages/dht/protos/DhtRpc'
|
|
11
|
+
import { DhtNodeRpcClient } from '../../generated/packages/dht/protos/DhtRpc.client'
|
|
12
12
|
import { ServiceID } from '../types/ServiceID'
|
|
13
13
|
import { RpcRemote } from './contact/RpcRemote'
|
|
14
14
|
import { DhtCallContext } from '../rpc-protocol/DhtCallContext'
|
|
@@ -46,7 +46,7 @@ export class DhtNodeRpcRemote extends RpcRemote<DhtNodeRpcClient> implements KBu
|
|
|
46
46
|
async getClosestPeers(nodeId: DhtAddress): Promise<PeerDescriptor[]> {
|
|
47
47
|
logger.trace(`Requesting getClosestPeers on ${this.serviceId} from ${this.getNodeId()}`)
|
|
48
48
|
const request: ClosestPeersRequest = {
|
|
49
|
-
nodeId:
|
|
49
|
+
nodeId: toDhtAddressRaw(nodeId),
|
|
50
50
|
requestId: v4()
|
|
51
51
|
}
|
|
52
52
|
try {
|
|
@@ -102,6 +102,6 @@ export class DhtNodeRpcRemote extends RpcRemote<DhtNodeRpcClient> implements KBu
|
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
getNodeId(): DhtAddress {
|
|
105
|
-
return
|
|
105
|
+
return toNodeId(this.getPeerDescriptor())
|
|
106
106
|
}
|
|
107
107
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IExternalApiRpc } from '
|
|
1
|
+
import { IExternalApiRpc } from '../../generated/packages/dht/protos/DhtRpc.server'
|
|
2
2
|
import {
|
|
3
3
|
ExternalFetchDataRequest,
|
|
4
4
|
ExternalFetchDataResponse,
|
|
@@ -6,12 +6,12 @@ import {
|
|
|
6
6
|
ExternalStoreDataResponse,
|
|
7
7
|
RecursiveOperation,
|
|
8
8
|
PeerDescriptor
|
|
9
|
-
} from '
|
|
9
|
+
} from '../../generated/packages/dht/protos/DhtRpc'
|
|
10
10
|
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
11
11
|
import { DhtCallContext } from '../rpc-protocol/DhtCallContext'
|
|
12
12
|
import { RecursiveOperationResult } from './recursive-operation/RecursiveOperationManager'
|
|
13
|
-
import { Any } from '
|
|
14
|
-
import { DhtAddress,
|
|
13
|
+
import { Any } from '../../generated/google/protobuf/any'
|
|
14
|
+
import { DhtAddress, toNodeId, toDhtAddress } from '../identifiers'
|
|
15
15
|
|
|
16
16
|
interface ExternalApiRpcLocalOptions {
|
|
17
17
|
executeRecursiveOperation: (
|
|
@@ -37,9 +37,9 @@ export class ExternalApiRpcLocal implements IExternalApiRpc {
|
|
|
37
37
|
async externalFetchData(request: ExternalFetchDataRequest, context: ServerCallContext): Promise<ExternalFetchDataResponse> {
|
|
38
38
|
const senderPeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
|
|
39
39
|
const result = await this.options.executeRecursiveOperation(
|
|
40
|
-
|
|
40
|
+
toDhtAddress(request.key),
|
|
41
41
|
RecursiveOperation.FETCH_DATA,
|
|
42
|
-
|
|
42
|
+
toNodeId(senderPeerDescriptor)
|
|
43
43
|
)
|
|
44
44
|
return ExternalFetchDataResponse.create({ entries: result.dataEntries ?? [] })
|
|
45
45
|
}
|
|
@@ -47,9 +47,9 @@ export class ExternalApiRpcLocal implements IExternalApiRpc {
|
|
|
47
47
|
async externalStoreData(request: ExternalStoreDataRequest, context: ServerCallContext): Promise<ExternalStoreDataResponse> {
|
|
48
48
|
const senderPeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
|
|
49
49
|
const result = await this.options.storeDataToDht(
|
|
50
|
-
|
|
50
|
+
toDhtAddress(request.key),
|
|
51
51
|
request.data!,
|
|
52
|
-
|
|
52
|
+
toNodeId(senderPeerDescriptor)
|
|
53
53
|
)
|
|
54
54
|
return ExternalStoreDataResponse.create({
|
|
55
55
|
storers: result
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { DhtAddress,
|
|
2
|
-
import { Any } from '
|
|
3
|
-
import { DataEntry, ExternalFetchDataRequest, ExternalStoreDataRequest, PeerDescriptor } from '
|
|
4
|
-
import { ExternalApiRpcClient } from '
|
|
1
|
+
import { DhtAddress, toDhtAddressRaw } from '../identifiers'
|
|
2
|
+
import { Any } from '../../generated/google/protobuf/any'
|
|
3
|
+
import { DataEntry, ExternalFetchDataRequest, ExternalStoreDataRequest, PeerDescriptor } from '../../generated/packages/dht/protos/DhtRpc'
|
|
4
|
+
import { ExternalApiRpcClient } from '../../generated/packages/dht/protos/DhtRpc.client'
|
|
5
5
|
import { RpcRemote } from './contact/RpcRemote'
|
|
6
6
|
|
|
7
7
|
export class ExternalApiRpcRemote extends RpcRemote<ExternalApiRpcClient> {
|
|
8
8
|
|
|
9
9
|
async externalFetchData(key: DhtAddress): Promise<DataEntry[]> {
|
|
10
10
|
const request: ExternalFetchDataRequest = {
|
|
11
|
-
key:
|
|
11
|
+
key: toDhtAddressRaw(key)
|
|
12
12
|
}
|
|
13
13
|
const options = this.formDhtRpcOptions({
|
|
14
14
|
// TODO use options option or named constant?
|
|
@@ -24,7 +24,7 @@ export class ExternalApiRpcRemote extends RpcRemote<ExternalApiRpcClient> {
|
|
|
24
24
|
|
|
25
25
|
async storeData(key: DhtAddress, data: Any): Promise<PeerDescriptor[]> {
|
|
26
26
|
const request: ExternalStoreDataRequest = {
|
|
27
|
-
key:
|
|
27
|
+
key: toDhtAddressRaw(key),
|
|
28
28
|
data
|
|
29
29
|
}
|
|
30
30
|
const options = this.formDhtRpcOptions({
|
package/src/dht/PeerManager.ts
CHANGED
|
@@ -5,10 +5,10 @@ import EventEmitter from 'eventemitter3'
|
|
|
5
5
|
import KBucket from 'k-bucket'
|
|
6
6
|
import { LockID } from '../connection/ConnectionLockStates'
|
|
7
7
|
import { ConnectionLocker } from '../connection/ConnectionManager'
|
|
8
|
-
import { DhtAddress, DhtAddressRaw,
|
|
8
|
+
import { DhtAddress, DhtAddressRaw, toNodeId, toDhtAddressRaw } from '../identifiers'
|
|
9
9
|
import {
|
|
10
10
|
PeerDescriptor
|
|
11
|
-
} from '
|
|
11
|
+
} from '../../generated/packages/dht/protos/DhtRpc'
|
|
12
12
|
import { DhtNodeRpcRemote } from './DhtNodeRpcRemote'
|
|
13
13
|
import { RandomContactList } from './contact/RandomContactList'
|
|
14
14
|
import { RingContactList } from './contact/RingContactList'
|
|
@@ -23,6 +23,7 @@ interface PeerManagerOptions {
|
|
|
23
23
|
localNodeId: DhtAddress
|
|
24
24
|
localPeerDescriptor: PeerDescriptor
|
|
25
25
|
connectionLocker?: ConnectionLocker
|
|
26
|
+
neighborPingLimit?: number
|
|
26
27
|
lockId: LockID
|
|
27
28
|
createDhtNodeRpcRemote: (peerDescriptor: PeerDescriptor) => DhtNodeRpcRemote
|
|
28
29
|
hasConnection: (nodeId: DhtAddress) => boolean
|
|
@@ -77,7 +78,7 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
|
|
|
77
78
|
super()
|
|
78
79
|
this.options = options
|
|
79
80
|
this.neighbors = new KBucket<DhtNodeRpcRemote>({
|
|
80
|
-
localNodeId:
|
|
81
|
+
localNodeId: toDhtAddressRaw(this.options.localNodeId),
|
|
81
82
|
numberOfNodesPerKBucket: this.options.numberOfNodesPerKBucket,
|
|
82
83
|
numberOfNodesToPing: this.options.numberOfNodesPerKBucket
|
|
83
84
|
})
|
|
@@ -89,7 +90,7 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
|
|
|
89
90
|
this.emit('ringContactRemoved', contact.getPeerDescriptor())
|
|
90
91
|
})
|
|
91
92
|
this.neighbors.on('ping', (oldContacts: DhtNodeRpcRemote[], newContact: DhtNodeRpcRemote) => this.onKBucketPing(oldContacts, newContact))
|
|
92
|
-
this.neighbors.on('removed', (contact: DhtNodeRpcRemote) => this.onKBucketRemoved(
|
|
93
|
+
this.neighbors.on('removed', (contact: DhtNodeRpcRemote) => this.onKBucketRemoved(toNodeId(contact.getPeerDescriptor())))
|
|
93
94
|
this.neighbors.on('added', (contact: DhtNodeRpcRemote) => this.onKBucketAdded(contact))
|
|
94
95
|
this.neighbors.on('updated', () => {
|
|
95
96
|
// TODO: Update contact info to the connection manager and reconnect
|
|
@@ -130,7 +131,7 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
|
|
|
130
131
|
sortingList.addContacts(oldContacts)
|
|
131
132
|
const removableNodeId = sortingList.getFurthestContacts(1)[0].getNodeId()
|
|
132
133
|
this.options.connectionLocker?.weakUnlockConnection(removableNodeId, this.options.lockId)
|
|
133
|
-
this.neighbors.remove(
|
|
134
|
+
this.neighbors.remove(toDhtAddressRaw(removableNodeId))
|
|
134
135
|
this.neighbors.add(newContact)
|
|
135
136
|
}
|
|
136
137
|
|
|
@@ -151,10 +152,11 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
|
|
|
151
152
|
}
|
|
152
153
|
if (contact.getNodeId() !== this.options.localNodeId) {
|
|
153
154
|
const peerDescriptor = contact.getPeerDescriptor()
|
|
154
|
-
const nodeId =
|
|
155
|
+
const nodeId = toNodeId(peerDescriptor)
|
|
155
156
|
// Important to lock here, before the ping result is known
|
|
156
157
|
this.options.connectionLocker?.weakLockConnection(nodeId, this.options.lockId)
|
|
157
|
-
if (this.options.hasConnection(contact.getNodeId())
|
|
158
|
+
if (this.options.hasConnection(contact.getNodeId())
|
|
159
|
+
|| (this.options.neighborPingLimit !== undefined && this.neighbors.count() > this.options.neighborPingLimit)) {
|
|
158
160
|
logger.trace(`Added new contact ${nodeId}`)
|
|
159
161
|
} else { // open connection by pinging
|
|
160
162
|
logger.trace('starting ping ' + nodeId)
|
|
@@ -188,7 +190,7 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
|
|
|
188
190
|
|
|
189
191
|
private getNearbyActiveContactNotInNeighbors(): DhtNodeRpcRemote | undefined {
|
|
190
192
|
for (const contactId of this.nearbyContacts.getContactIds()) {
|
|
191
|
-
if (!this.neighbors.get(
|
|
193
|
+
if (!this.neighbors.get(toDhtAddressRaw(contactId)) && this.activeContacts.has(contactId)) {
|
|
192
194
|
return this.nearbyContacts.getContact(contactId)!
|
|
193
195
|
}
|
|
194
196
|
}
|
|
@@ -201,22 +203,22 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
|
|
|
201
203
|
}
|
|
202
204
|
logger.trace(`Removing contact ${nodeId}`)
|
|
203
205
|
this.ringContacts.removeContact(this.nearbyContacts.getContact(nodeId))
|
|
204
|
-
this.neighbors.remove(
|
|
206
|
+
this.neighbors.remove(toDhtAddressRaw(nodeId))
|
|
205
207
|
this.nearbyContacts.removeContact(nodeId)
|
|
206
208
|
this.activeContacts.delete(nodeId)
|
|
207
209
|
this.randomContacts.removeContact(nodeId)
|
|
208
210
|
}
|
|
209
211
|
|
|
210
212
|
removeNeighbor(nodeId: DhtAddress): void {
|
|
211
|
-
this.neighbors.remove(
|
|
213
|
+
this.neighbors.remove(toDhtAddressRaw(nodeId))
|
|
212
214
|
}
|
|
213
215
|
|
|
214
216
|
async pruneOfflineNodes(nodes: DhtNodeRpcRemote[]): Promise<void> {
|
|
215
217
|
logger.trace('Pruning offline nodes', { nodes: nodes.length })
|
|
216
218
|
const offlineNeighbors = await pingNodes(nodes, this.activeContacts)
|
|
217
219
|
offlineNeighbors.forEach((offlineNeighbor) => {
|
|
218
|
-
logger.trace('Removing offline node', { node:
|
|
219
|
-
this.removeContact(
|
|
220
|
+
logger.trace('Removing offline node', { node: toNodeId(offlineNeighbor) })
|
|
221
|
+
this.removeContact(toNodeId(offlineNeighbor))
|
|
220
222
|
})
|
|
221
223
|
}
|
|
222
224
|
|
|
@@ -266,7 +268,7 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
|
|
|
266
268
|
return this.neighbors.count()
|
|
267
269
|
}
|
|
268
270
|
|
|
269
|
-
getNeighbors():
|
|
271
|
+
getNeighbors(): readonly DhtNodeRpcRemote[] {
|
|
270
272
|
return this.neighbors.toArray()
|
|
271
273
|
}
|
|
272
274
|
|
|
@@ -278,7 +280,7 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
|
|
|
278
280
|
if (this.stopped) {
|
|
279
281
|
return
|
|
280
282
|
}
|
|
281
|
-
const nodeId =
|
|
283
|
+
const nodeId = toNodeId(peerDescriptor)
|
|
282
284
|
if (nodeId !== this.options.localNodeId) {
|
|
283
285
|
logger.trace(`Adding new contact ${nodeId}`)
|
|
284
286
|
const remote = this.options.createDhtNodeRpcRemote(peerDescriptor)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { PeerDescriptor } from '
|
|
2
|
-
import { DhtAddress,
|
|
1
|
+
import { PeerDescriptor } from '../../../generated/packages/dht/protos/DhtRpc'
|
|
2
|
+
import { DhtAddress, toNodeId } from '../../identifiers'
|
|
3
3
|
|
|
4
4
|
export class Contact {
|
|
5
5
|
|
|
@@ -14,6 +14,6 @@ export class Contact {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
public getNodeId(): DhtAddress {
|
|
17
|
-
return
|
|
17
|
+
return toNodeId(this.peerDescriptor)
|
|
18
18
|
}
|
|
19
19
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { PeerDescriptor } from '
|
|
1
|
+
import { PeerDescriptor } from '../../../generated/packages/dht/protos/DhtRpc'
|
|
2
2
|
import { OrderedMap } from '@js-sdsl/ordered-map'
|
|
3
3
|
import { RingDistance, RingId, RingIdRaw, getLeftDistance, getRightDistance, getRingIdFromPeerDescriptor, getRingIdFromRaw } from './ringIdentifiers'
|
|
4
|
-
import { DhtAddress,
|
|
4
|
+
import { DhtAddress, toNodeId } from '../../identifiers'
|
|
5
5
|
import EventEmitter from 'eventemitter3'
|
|
6
6
|
import { Events } from './ContactList'
|
|
7
7
|
|
|
@@ -28,7 +28,7 @@ export class RingContactList<C extends { getPeerDescriptor(): PeerDescriptor }>
|
|
|
28
28
|
|
|
29
29
|
addContact(contact: C): void {
|
|
30
30
|
const id = getRingIdFromPeerDescriptor(contact.getPeerDescriptor())
|
|
31
|
-
if (id === this.referenceId || this.excludedIds.has(
|
|
31
|
+
if (id === this.referenceId || this.excludedIds.has(toNodeId(contact.getPeerDescriptor()))) {
|
|
32
32
|
return
|
|
33
33
|
}
|
|
34
34
|
let elementAdded = false
|
|
@@ -2,7 +2,7 @@ import type { ServiceInfo } from '@protobuf-ts/runtime-rpc'
|
|
|
2
2
|
import { ClassType, ClientTransport, ProtoRpcClient, RpcCommunicator, toProtoRpcClient } from '@streamr/proto-rpc'
|
|
3
3
|
import { ConnectionType } from '../../connection/IConnection'
|
|
4
4
|
import { expectedConnectionType } from '../../helpers/Connectivity'
|
|
5
|
-
import { PeerDescriptor } from '
|
|
5
|
+
import { PeerDescriptor } from '../../../generated/packages/dht/protos/DhtRpc'
|
|
6
6
|
import { DhtRpcOptions } from '../../rpc-protocol/DhtRpcOptions'
|
|
7
7
|
import { DhtCallContext } from '../../rpc-protocol/DhtCallContext'
|
|
8
8
|
|
|
@@ -2,7 +2,7 @@ import { Events } from './ContactList'
|
|
|
2
2
|
import { sortedIndexBy } from 'lodash'
|
|
3
3
|
import EventEmitter from 'eventemitter3'
|
|
4
4
|
import { getDistance } from '../PeerManager'
|
|
5
|
-
import { DhtAddress,
|
|
5
|
+
import { DhtAddress, toDhtAddressRaw } from '../../identifiers'
|
|
6
6
|
|
|
7
7
|
// add other getters in the future if needed
|
|
8
8
|
export type ReadonlySortedContactList<C extends { getNodeId: () => DhtAddress }> =
|
|
@@ -42,7 +42,7 @@ export class SortedContactList<C extends { getNodeId: () => DhtAddress }> extend
|
|
|
42
42
|
|
|
43
43
|
public addContact(contact: C): void {
|
|
44
44
|
const contactId = contact.getNodeId()
|
|
45
|
-
if (this.options.excludedNodeIds
|
|
45
|
+
if (this.options.excludedNodeIds?.has(contactId)) {
|
|
46
46
|
return
|
|
47
47
|
}
|
|
48
48
|
if ((!this.options.allowToContainReferenceId && (this.options.referenceId === contactId)) ||
|
|
@@ -120,7 +120,7 @@ export class SortedContactList<C extends { getNodeId: () => DhtAddress }> extend
|
|
|
120
120
|
// TODO inline this method?
|
|
121
121
|
private distanceToReferenceId(id: DhtAddress): number {
|
|
122
122
|
// TODO maybe this class should store the referenceId also as DhtAddressRaw so that we don't need to convert it here?
|
|
123
|
-
return getDistance(
|
|
123
|
+
return getDistance(toDhtAddressRaw(this.options.referenceId), toDhtAddressRaw(id))
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
public removeContact(id: DhtAddress): boolean {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PeerDescriptor } from '
|
|
1
|
+
import { PeerDescriptor } from '../../../generated/packages/dht/protos/DhtRpc'
|
|
2
2
|
|
|
3
3
|
// Notice: you cannot convert RingId to RingIdRaw, because
|
|
4
4
|
// RingId is only an approximation of the actual value.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Gate, Logger, withTimeout } from '@streamr/utils'
|
|
2
2
|
import { v4 } from 'uuid'
|
|
3
|
-
import { DhtAddress,
|
|
4
|
-
import { PeerDescriptor } from '
|
|
3
|
+
import { DhtAddress, toNodeId, toDhtAddressRaw } from '../../identifiers'
|
|
4
|
+
import { PeerDescriptor } from '../../../generated/packages/dht/protos/DhtRpc'
|
|
5
5
|
import { DhtNodeRpcRemote } from '../DhtNodeRpcRemote'
|
|
6
6
|
import { PeerManager, getDistance } from '../PeerManager'
|
|
7
7
|
import { getClosestNodes } from '../contact/getClosestNodes'
|
|
@@ -44,7 +44,7 @@ export class DiscoverySession {
|
|
|
44
44
|
if (this.options.abortSignal.aborted || this.doneGate.isOpen()) {
|
|
45
45
|
return []
|
|
46
46
|
}
|
|
47
|
-
const nodeId =
|
|
47
|
+
const nodeId = toNodeId(peerDescriptor)
|
|
48
48
|
logger.trace(`Getting closest neighbors from remote: ${nodeId}`)
|
|
49
49
|
this.options.contactedPeers.add(nodeId)
|
|
50
50
|
const remote = this.options.createDhtNodeRpcRemote(peerDescriptor)
|
|
@@ -58,7 +58,7 @@ export class DiscoverySession {
|
|
|
58
58
|
return
|
|
59
59
|
}
|
|
60
60
|
this.ongoingRequests.delete(nodeId)
|
|
61
|
-
const targetId =
|
|
61
|
+
const targetId = toDhtAddressRaw(this.options.targetId)
|
|
62
62
|
const oldClosestNeighbor = this.getClosestNeighbor()
|
|
63
63
|
const oldClosestDistance = getDistance(targetId, oldClosestNeighbor.nodeId)
|
|
64
64
|
this.addContacts(contacts)
|
|
@@ -105,7 +105,7 @@ export class DiscoverySession {
|
|
|
105
105
|
if (this.ongoingRequests.size >= this.options.parallelism) {
|
|
106
106
|
break
|
|
107
107
|
}
|
|
108
|
-
const nodeId =
|
|
108
|
+
const nodeId = toNodeId(node)
|
|
109
109
|
this.ongoingRequests.add(nodeId)
|
|
110
110
|
// eslint-disable-next-line promise/catch-or-return
|
|
111
111
|
this.fetchClosestNeighborsFromRemote(node)
|
|
@@ -3,12 +3,12 @@ import { ConnectionLocker } from '../../connection/ConnectionManager'
|
|
|
3
3
|
import {
|
|
4
4
|
DhtAddress,
|
|
5
5
|
areEqualPeerDescriptors,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
randomDhtAddress,
|
|
7
|
+
toDhtAddress,
|
|
8
|
+
toNodeId,
|
|
9
|
+
toDhtAddressRaw
|
|
10
10
|
} from '../../identifiers'
|
|
11
|
-
import { PeerDescriptor } from '
|
|
11
|
+
import { PeerDescriptor } from '../../../generated/packages/dht/protos/DhtRpc'
|
|
12
12
|
import { ServiceID } from '../../types/ServiceID'
|
|
13
13
|
import { DhtNodeRpcRemote } from '../DhtNodeRpcRemote'
|
|
14
14
|
import { PeerManager } from '../PeerManager'
|
|
@@ -31,9 +31,9 @@ interface PeerDiscoveryOptions {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
export const createDistantDhtAddress = (address: DhtAddress): DhtAddress => {
|
|
34
|
-
const raw =
|
|
34
|
+
const raw = toDhtAddressRaw(address)
|
|
35
35
|
const flipped = raw.map((val) => ~val)
|
|
36
|
-
return
|
|
36
|
+
return toDhtAddress(flipped)
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
const logger = new Logger(module)
|
|
@@ -82,14 +82,14 @@ export class PeerDiscovery {
|
|
|
82
82
|
logger.debug(
|
|
83
83
|
`Joining ${this.options.serviceId === CONTROL_LAYER_NODE_SERVICE_ID
|
|
84
84
|
? 'The Streamr Network' : `Control Layer for ${this.options.serviceId}`}`
|
|
85
|
-
+ ` via entrypoint ${
|
|
85
|
+
+ ` via entrypoint ${toNodeId(entryPointDescriptor)}`
|
|
86
86
|
)
|
|
87
87
|
if (areEqualPeerDescriptors(entryPointDescriptor, this.options.localPeerDescriptor)) {
|
|
88
88
|
return
|
|
89
89
|
}
|
|
90
90
|
this.options.connectionLocker?.lockConnection(entryPointDescriptor, `${this.options.serviceId}::joinDht`)
|
|
91
91
|
this.options.peerManager.addContact(entryPointDescriptor)
|
|
92
|
-
const targetId =
|
|
92
|
+
const targetId = toNodeId(this.options.localPeerDescriptor)
|
|
93
93
|
const sessions = [this.createSession(targetId, contactedPeers)]
|
|
94
94
|
if (additionalDistantJoin.enabled) {
|
|
95
95
|
sessions.push(this.createSession(createDistantDhtAddress(targetId), additionalDistantJoin.contactedPeers))
|
|
@@ -205,9 +205,9 @@ export class PeerDiscovery {
|
|
|
205
205
|
if (this.isStopped()) {
|
|
206
206
|
return
|
|
207
207
|
}
|
|
208
|
-
const localNodeId =
|
|
208
|
+
const localNodeId = toNodeId(this.options.localPeerDescriptor)
|
|
209
209
|
const nodes = this.getClosestNeighbors(localNodeId, this.options.parallelism)
|
|
210
|
-
const randomNodes = this.getClosestNeighbors(
|
|
210
|
+
const randomNodes = this.getClosestNeighbors(randomDhtAddress(), 1)
|
|
211
211
|
await Promise.allSettled([
|
|
212
212
|
...nodes.map(async (node: PeerDescriptor) => {
|
|
213
213
|
const remote = this.options.createDhtNodeRpcRemote(node)
|
|
@@ -218,7 +218,7 @@ export class PeerDiscovery {
|
|
|
218
218
|
}),
|
|
219
219
|
...randomNodes.map(async (node: PeerDescriptor) => {
|
|
220
220
|
const remote = this.options.createDhtNodeRpcRemote(node)
|
|
221
|
-
const contacts = await remote.getClosestPeers(
|
|
221
|
+
const contacts = await remote.getClosestPeers(randomDhtAddress())
|
|
222
222
|
for (const contact of contacts) {
|
|
223
223
|
this.options.peerManager.addContact(contact)
|
|
224
224
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Gate, Logger, withTimeout } from '@streamr/utils'
|
|
2
2
|
import { v4 } from 'uuid'
|
|
3
|
-
import { DhtAddress,
|
|
4
|
-
import { PeerDescriptor } from '
|
|
3
|
+
import { DhtAddress, toNodeId } from '../../identifiers'
|
|
4
|
+
import { PeerDescriptor } from '../../../generated/packages/dht/protos/DhtRpc'
|
|
5
5
|
import { DhtNodeRpcRemote } from '../DhtNodeRpcRemote'
|
|
6
6
|
import { PeerManager } from '../PeerManager'
|
|
7
7
|
import { RingContacts } from '../contact/RingContactList'
|
|
@@ -47,7 +47,7 @@ export class RingDiscoverySession {
|
|
|
47
47
|
if (this.options.abortSignal.aborted || this.doneGate.isOpen()) {
|
|
48
48
|
return { left: [], right: [] }
|
|
49
49
|
}
|
|
50
|
-
logger.trace(`Getting closest ring peers from contact: ${
|
|
50
|
+
logger.trace(`Getting closest ring peers from contact: ${toNodeId(contact.getPeerDescriptor())}`)
|
|
51
51
|
this.numContactedPeers++
|
|
52
52
|
this.options.contactedPeers.add(contact.getNodeId())
|
|
53
53
|
const returnedContacts = await contact.getClosestRingPeers(this.options.targetId)
|