@streamr/dht 101.1.2 → 102.0.0-beta.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/.eslintignore +1 -1
- package/dist/{src/proto → generated}/google/protobuf/any.d.ts +11 -4
- package/dist/generated/google/protobuf/any.js.map +1 -0
- package/dist/{src/proto → generated}/google/protobuf/empty.d.ts +0 -1
- package/dist/generated/google/protobuf/empty.js.map +1 -0
- package/dist/{src/proto → generated}/google/protobuf/timestamp.d.ts +9 -3
- package/dist/generated/google/protobuf/timestamp.js.map +1 -0
- package/dist/{src/proto → generated}/packages/dht/protos/DhtRpc.client.d.ts +9 -0
- package/dist/{src/proto → generated}/packages/dht/protos/DhtRpc.client.js +7 -0
- package/dist/generated/packages/dht/protos/DhtRpc.client.js.map +1 -0
- package/dist/{src/proto → generated}/packages/dht/protos/DhtRpc.d.ts +16 -0
- package/dist/{src/proto → generated}/packages/dht/protos/DhtRpc.js +16 -2
- package/dist/generated/packages/dht/protos/DhtRpc.js.map +1 -0
- package/dist/{src/proto → generated}/packages/dht/protos/DhtRpc.server.d.ts +5 -0
- package/dist/generated/packages/dht/protos/DhtRpc.server.js.map +1 -0
- package/dist/generated/packages/proto-rpc/protos/ProtoRpc.js.map +1 -0
- package/dist/package.json +11 -11
- 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 +78 -24
- 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 +1 -1
- package/dist/src/connection/Handshaker.js +2 -2
- package/dist/src/connection/Handshaker.js.map +1 -1
- package/dist/src/connection/ManagedConnection.d.ts +7 -1
- package/dist/src/connection/ManagedConnection.js +24 -1
- 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 +2 -1
- package/dist/src/connection/connectivityChecker.js.map +1 -1
- package/dist/src/connection/connectivityRequestHandler.js +1 -1
- 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 +2 -2
- 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/webrtc/NodeWebrtcConnection.d.ts +2 -1
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js +13 -6
- 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 +9 -8
- 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/websocket/AbstractWebsocketClientConnection.d.ts +1 -0
- 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 -3
- 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/WebsocketServerConnector.d.ts +1 -1
- package/dist/src/connection/websocket/WebsocketServerConnector.js +7 -7
- package/dist/src/connection/websocket/WebsocketServerConnector.js.map +1 -1
- package/dist/src/dht/DhtNode.d.ts +4 -2
- package/dist/src/dht/DhtNode.js +17 -6
- package/dist/src/dht/DhtNode.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcLocal.d.ts +3 -3
- 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 +1 -1
- package/dist/src/dht/PeerManager.js +10 -10
- 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 +1 -1
- 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 -1
- 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 -1
- 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.js +1 -1
- package/dist/src/dht/discovery/RingDiscoverySession.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.d.ts +1 -1
- 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/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 +5 -6
- package/dist/src/dht/routing/RoutingSession.js.map +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 +2 -2
- package/dist/src/dht/store/LocalDataStore.js.map +1 -1
- package/dist/src/dht/store/StoreManager.d.ts +2 -2
- 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 +3 -3
- 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/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/protoClasses.js +1 -1
- package/dist/src/helpers/protoClasses.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/{src/proto → generated}/google/protobuf/any.ts +11 -4
- package/{src/proto → generated}/google/protobuf/empty.ts +0 -1
- package/{src/proto → generated}/google/protobuf/timestamp.ts +9 -3
- package/{src/proto → generated}/packages/dht/protos/DhtRpc.client.ts +12 -0
- package/{src/proto → generated}/packages/dht/protos/DhtRpc.server.ts +5 -0
- package/{src/proto → generated}/packages/dht/protos/DhtRpc.ts +23 -1
- package/package.json +11 -11
- package/proto.sh +2 -3
- package/protos/DhtRpc.proto +5 -0
- 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 +92 -26
- package/src/connection/ConnectionsView.ts +1 -1
- package/src/connection/ConnectorFacade.ts +1 -1
- package/src/connection/Handshaker.ts +3 -3
- package/src/connection/ManagedConnection.ts +28 -3
- package/src/connection/PendingConnection.ts +1 -1
- package/src/connection/connectivityChecker.ts +2 -1
- package/src/connection/connectivityRequestHandler.ts +1 -1
- package/src/connection/simulator/Simulator.ts +4 -4
- 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/webrtc/BrowserWebrtcConnection.ts +10 -1
- package/src/connection/webrtc/NodeWebrtcConnection.ts +15 -9
- package/src/connection/webrtc/WebrtcConnector.ts +10 -8
- 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 +8 -8
- package/src/dht/DhtNode.ts +21 -8
- package/src/dht/DhtNodeRpcLocal.ts +7 -7
- 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 +12 -12
- 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 +2 -2
- 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 +9 -9
- 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/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 +7 -8
- package/src/dht/routing/getPreviousPeer.ts +1 -1
- package/src/dht/store/LocalDataStore.ts +4 -4
- package/src/dht/store/StoreManager.ts +12 -12
- package/src/dht/store/StoreRpcLocal.ts +8 -8
- 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 +1 -1
- 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 +6 -6
- package/test/benchmark/KademliaCorrectness.test.ts +5 -5
- package/test/benchmark/RingCorrectness.test.ts +5 -5
- package/test/benchmark/SortedContactListBenchmark.test.ts +10 -10
- package/test/benchmark/hybrid-network-simulation/RingContactList.test.ts +1 -1
- 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 +1 -1
- package/test/end-to-end/memory-leak.test.ts +4 -4
- package/test/integration/ConnectionLocking.test.ts +16 -15
- package/test/integration/ConnectionManager.test.ts +62 -6
- package/test/integration/ConnectivityChecking.test.ts +2 -1
- package/test/integration/DhtJoinPeerDiscovery.test.ts +2 -2
- package/test/integration/DhtNode.test.ts +4 -4
- 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 +2 -1
- package/test/integration/Layer1-scale.test.ts +2 -2
- 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 +9 -9
- package/test/integration/RouterRpcRemote.test.ts +7 -7
- package/test/integration/SimultaneousConnections.test.ts +13 -12
- package/test/integration/Store.test.ts +9 -9
- package/test/integration/StoreAndDelete.test.ts +10 -10
- package/test/integration/StoreOnDhtWithThreeNodes.test.ts +9 -9
- package/test/integration/StoreOnDhtWithTwoNodes.test.ts +7 -7
- package/test/integration/StoreRpcRemote.test.ts +10 -10
- package/test/integration/WebrtcConnectionManagement.test.ts +4 -3
- package/test/integration/WebrtcConnectorRpc.test.ts +9 -9
- package/test/integration/Websocket.test.ts +0 -2
- package/test/integration/WebsocketClientConnectorRpc.test.ts +8 -8
- package/test/integration/WebsocketConnectionManagement.test.ts +8 -9
- package/test/integration/{rpc-connections-over-webrpc.test.ts → rpc-connections-over-webrtc.test.ts} +4 -3
- 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 +1 -1
- package/test/unit/ListeningRpcCommunicator.test.ts +52 -0
- package/test/unit/LocalDataStore.test.ts +21 -21
- package/test/unit/PeerManager.test.ts +13 -13
- 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 +4 -4
- package/test/unit/Router.test.ts +6 -6
- package/test/unit/RoutingSession.test.ts +6 -6
- package/test/unit/SortedContactList.test.ts +5 -5
- package/test/unit/StoreManager.test.ts +10 -10
- 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 +1 -1
- package/test/unit/createPeerDescriptor.test.ts +4 -4
- package/test/unit/getClosestNodes.test.ts +5 -5
- package/test/utils/FakeConnectorFacade.ts +1 -1
- package/test/utils/FakeTransport.ts +12 -9
- package/test/utils/customMatchers.ts +3 -3
- 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 -3
- package/test/utils/utils.ts +9 -9
- package/tsconfig.jest.json +2 -1
- package/tsconfig.node.json +1 -0
- package/dist/src/proto/google/protobuf/any.js.map +0 -1
- package/dist/src/proto/google/protobuf/empty.js.map +0 -1
- package/dist/src/proto/google/protobuf/timestamp.js.map +0 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +0 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +0 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.js.map +0 -1
- 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/src/proto/tests.ts +0 -52
- package/test/benchmark/any.test.ts +0 -28
- /package/dist/{src/proto → generated}/google/protobuf/any.js +0 -0
- /package/dist/{src/proto → generated}/google/protobuf/empty.js +0 -0
- /package/dist/{src/proto → generated}/google/protobuf/timestamp.js +0 -0
- /package/dist/{src/proto → generated}/packages/dht/protos/DhtRpc.server.js +0 -0
- /package/dist/{src/proto → generated}/packages/proto-rpc/protos/ProtoRpc.d.ts +0 -0
- /package/dist/{src/proto → generated}/packages/proto-rpc/protos/ProtoRpc.js +0 -0
- /package/{src/proto → generated}/packages/proto-rpc/protos/ProtoRpc.ts +0 -0
- /package/{src/types/glogal.d.ts → test/types/global.d.ts} +0 -0
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import {
|
|
2
2
|
WebsocketConnectionRequest
|
|
3
|
-
} from '
|
|
3
|
+
} from '../../../generated/packages/dht/protos/DhtRpc'
|
|
4
4
|
import { Logger } from '@streamr/utils'
|
|
5
5
|
import { RpcRemote } from '../../dht/contact/RpcRemote'
|
|
6
|
-
import { WebsocketClientConnectorRpcClient } from '
|
|
7
|
-
import {
|
|
6
|
+
import { WebsocketClientConnectorRpcClient } from '../../../generated/packages/dht/protos/DhtRpc.client'
|
|
7
|
+
import { toNodeId } from '../../identifiers'
|
|
8
8
|
|
|
9
9
|
const logger = new Logger(module)
|
|
10
10
|
|
|
11
11
|
export class WebsocketClientConnectorRpcRemote extends RpcRemote<WebsocketClientConnectorRpcClient> {
|
|
12
12
|
|
|
13
13
|
async requestConnection(): Promise<void> {
|
|
14
|
-
logger.trace(`Requesting WebSocket connection from ${
|
|
14
|
+
logger.trace(`Requesting WebSocket connection from ${toNodeId(this.getLocalPeerDescriptor())}`)
|
|
15
15
|
const request: WebsocketConnectionRequest = {}
|
|
16
16
|
const options = this.formDhtRpcOptions()
|
|
17
17
|
return this.getClient().requestConnection(request, options)
|
|
@@ -2,9 +2,9 @@ import { GeoIpLocator } from '@streamr/geoip-location'
|
|
|
2
2
|
import { ListeningRpcCommunicator } from '../../transport/ListeningRpcCommunicator'
|
|
3
3
|
import { Action, connectivityMethodToWebsocketUrl } from './WebsocketClientConnector'
|
|
4
4
|
import { WebsocketServer } from './WebsocketServer'
|
|
5
|
-
import { areEqualPeerDescriptors, DhtAddress,
|
|
5
|
+
import { areEqualPeerDescriptors, DhtAddress, toNodeId } from '../../identifiers'
|
|
6
6
|
import { AutoCertifierClientFacade } from './AutoCertifierClientFacade'
|
|
7
|
-
import { ConnectivityResponse, HandshakeError, PeerDescriptor } from '
|
|
7
|
+
import { ConnectivityResponse, HandshakeError, PeerDescriptor } from '../../../generated/packages/dht/protos/DhtRpc'
|
|
8
8
|
import { NatType, PortRange, TlsCertificate } from '../ConnectionManager'
|
|
9
9
|
import { ITransport } from '../../transport/ITransport'
|
|
10
10
|
import { ipv4ToNumber, Logger, wait } from '@streamr/utils'
|
|
@@ -17,7 +17,7 @@ import { shuffle } from 'lodash'
|
|
|
17
17
|
import { sendConnectivityRequest } from '../connectivityChecker'
|
|
18
18
|
import { acceptHandshake, Handshaker, rejectHandshake } from '../Handshaker'
|
|
19
19
|
import { WebsocketClientConnectorRpcRemote } from './WebsocketClientConnectorRpcRemote'
|
|
20
|
-
import { WebsocketClientConnectorRpcClient } from '
|
|
20
|
+
import { WebsocketClientConnectorRpcClient } from '../../../generated/packages/dht/protos/DhtRpc.client'
|
|
21
21
|
import { WebsocketServerStartError } from '../../helpers/errors'
|
|
22
22
|
import * as Err from '../../helpers/errors'
|
|
23
23
|
import { expectedConnectionType } from '../../helpers/Connectivity'
|
|
@@ -126,7 +126,7 @@ export class WebsocketServerConnector {
|
|
|
126
126
|
remoteVersion: string,
|
|
127
127
|
targetPeerDescriptor?: PeerDescriptor
|
|
128
128
|
) {
|
|
129
|
-
const nodeId =
|
|
129
|
+
const nodeId = toNodeId(sourcePeerDescriptor)
|
|
130
130
|
if (this.ongoingConnectRequests.has(nodeId)) {
|
|
131
131
|
const { pendingConnection, delFunc } = this.ongoingConnectRequests.get(nodeId)!
|
|
132
132
|
if (!isMaybeSupportedVersion(remoteVersion)) {
|
|
@@ -195,7 +195,7 @@ export class WebsocketServerConnector {
|
|
|
195
195
|
throw new Err.ConnectionFailed('ConnectivityChecker is destroyed')
|
|
196
196
|
}
|
|
197
197
|
} catch (err) {
|
|
198
|
-
const error = `Failed to connect to entrypoint with id ${
|
|
198
|
+
const error = `Failed to connect to entrypoint with id ${toNodeId(entryPoint)} `
|
|
199
199
|
+ `and URL ${connectivityMethodToWebsocketUrl(entryPoint.websocket!)}`
|
|
200
200
|
logger.error(error, { err })
|
|
201
201
|
shuffledEntrypoints.shift()
|
|
@@ -227,7 +227,7 @@ export class WebsocketServerConnector {
|
|
|
227
227
|
}
|
|
228
228
|
|
|
229
229
|
public connect(targetPeerDescriptor: PeerDescriptor): PendingConnection {
|
|
230
|
-
const nodeId =
|
|
230
|
+
const nodeId = toNodeId(targetPeerDescriptor)
|
|
231
231
|
if (this.ongoingConnectRequests.has(nodeId)) {
|
|
232
232
|
return this.ongoingConnectRequests.get(nodeId)!.pendingConnection
|
|
233
233
|
}
|
|
@@ -251,7 +251,7 @@ export class WebsocketServerConnector {
|
|
|
251
251
|
})
|
|
252
252
|
})
|
|
253
253
|
const pendingConnection = new PendingConnection(targetPeerDescriptor)
|
|
254
|
-
const nodeId =
|
|
254
|
+
const nodeId = toNodeId(targetPeerDescriptor)
|
|
255
255
|
// TODO: can this leak?
|
|
256
256
|
const delFunc = () => {
|
|
257
257
|
pendingConnection.off('connected', delFunc)
|
|
@@ -280,7 +280,7 @@ export class WebsocketServerConnector {
|
|
|
280
280
|
await Promise.allSettled(requests.map((ongoingConnectRequest) => ongoingConnectRequest.pendingConnection.close(true)))
|
|
281
281
|
|
|
282
282
|
await this.websocketServer?.stop()
|
|
283
|
-
|
|
283
|
+
this.geoIpLocator?.stop()
|
|
284
284
|
}
|
|
285
285
|
|
|
286
286
|
}
|
package/src/dht/DhtNode.ts
CHANGED
|
@@ -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'
|
|
@@ -104,6 +104,7 @@ export interface DhtNodeOptions {
|
|
|
104
104
|
autoCertifierUrl?: string
|
|
105
105
|
autoCertifierConfigFile?: string
|
|
106
106
|
geoIpDatabaseFolder?: string
|
|
107
|
+
allowIncomingPrivateConnections?: boolean
|
|
107
108
|
}
|
|
108
109
|
|
|
109
110
|
type StrictDhtNodeOptions = MarkRequired<DhtNodeOptions,
|
|
@@ -242,7 +243,8 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
242
243
|
const connectionManager = new ConnectionManager({
|
|
243
244
|
createConnectorFacade: () => new DefaultConnectorFacade(connectorFacadeOptions),
|
|
244
245
|
maxConnections: this.options.maxConnections,
|
|
245
|
-
metricsContext: this.options.metricsContext
|
|
246
|
+
metricsContext: this.options.metricsContext,
|
|
247
|
+
allowIncomingPrivateConnections: this.options.allowIncomingPrivateConnections ?? false
|
|
246
248
|
})
|
|
247
249
|
await connectionManager.start()
|
|
248
250
|
this.connectionsView = connectionManager
|
|
@@ -381,7 +383,7 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
381
383
|
this.transport!.on('disconnected', (peerDescriptor: PeerDescriptor, gracefulLeave: boolean) => {
|
|
382
384
|
const isControlLayerNode = (this.connectionLocker !== undefined)
|
|
383
385
|
if (isControlLayerNode) {
|
|
384
|
-
const nodeId =
|
|
386
|
+
const nodeId = toNodeId(peerDescriptor)
|
|
385
387
|
if (gracefulLeave) {
|
|
386
388
|
this.peerManager!.removeContact(nodeId)
|
|
387
389
|
} else {
|
|
@@ -500,7 +502,7 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
500
502
|
}
|
|
501
503
|
|
|
502
504
|
public getNodeId(): DhtAddress {
|
|
503
|
-
return
|
|
505
|
+
return toNodeId(this.localPeerDescriptor!)
|
|
504
506
|
}
|
|
505
507
|
|
|
506
508
|
public getNeighborCount(): number {
|
|
@@ -524,7 +526,7 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
524
526
|
|
|
525
527
|
private getConnectedEntryPoints(): PeerDescriptor[] {
|
|
526
528
|
return this.options.entryPoints !== undefined ? this.options.entryPoints.filter((entryPoint) =>
|
|
527
|
-
this.connectionsView!.hasConnection(
|
|
529
|
+
this.connectionsView!.hasConnection(toNodeId(entryPoint))
|
|
528
530
|
) : []
|
|
529
531
|
}
|
|
530
532
|
|
|
@@ -631,6 +633,17 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
631
633
|
return this.peerDiscovery!.isJoinCalled()
|
|
632
634
|
}
|
|
633
635
|
|
|
636
|
+
public getDiagnosticInfo(): Record<string, unknown> {
|
|
637
|
+
return {
|
|
638
|
+
localPeerDescriptor: this.localPeerDescriptor,
|
|
639
|
+
transport: this.transport!.getDiagnosticInfo(),
|
|
640
|
+
router: this.router!.getDiagnosticInfo(),
|
|
641
|
+
neighborCount: this.getNeighborCount(),
|
|
642
|
+
nearbyContactCount: Array.from(this.peerManager!.getNearbyContacts().getAllContactsInUndefinedOrder()).length,
|
|
643
|
+
randomContactCount: this.peerManager!.getRandomContacts().getSize()
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
|
|
634
647
|
public async stop(): Promise<void> {
|
|
635
648
|
if (this.abortController.signal.aborted || !this.started) {
|
|
636
649
|
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'
|
|
@@ -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'
|
|
@@ -77,7 +77,7 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
|
|
|
77
77
|
super()
|
|
78
78
|
this.options = options
|
|
79
79
|
this.neighbors = new KBucket<DhtNodeRpcRemote>({
|
|
80
|
-
localNodeId:
|
|
80
|
+
localNodeId: toDhtAddressRaw(this.options.localNodeId),
|
|
81
81
|
numberOfNodesPerKBucket: this.options.numberOfNodesPerKBucket,
|
|
82
82
|
numberOfNodesToPing: this.options.numberOfNodesPerKBucket
|
|
83
83
|
})
|
|
@@ -89,7 +89,7 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
|
|
|
89
89
|
this.emit('ringContactRemoved', contact.getPeerDescriptor())
|
|
90
90
|
})
|
|
91
91
|
this.neighbors.on('ping', (oldContacts: DhtNodeRpcRemote[], newContact: DhtNodeRpcRemote) => this.onKBucketPing(oldContacts, newContact))
|
|
92
|
-
this.neighbors.on('removed', (contact: DhtNodeRpcRemote) => this.onKBucketRemoved(
|
|
92
|
+
this.neighbors.on('removed', (contact: DhtNodeRpcRemote) => this.onKBucketRemoved(toNodeId(contact.getPeerDescriptor())))
|
|
93
93
|
this.neighbors.on('added', (contact: DhtNodeRpcRemote) => this.onKBucketAdded(contact))
|
|
94
94
|
this.neighbors.on('updated', () => {
|
|
95
95
|
// TODO: Update contact info to the connection manager and reconnect
|
|
@@ -130,7 +130,7 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
|
|
|
130
130
|
sortingList.addContacts(oldContacts)
|
|
131
131
|
const removableNodeId = sortingList.getFurthestContacts(1)[0].getNodeId()
|
|
132
132
|
this.options.connectionLocker?.weakUnlockConnection(removableNodeId, this.options.lockId)
|
|
133
|
-
this.neighbors.remove(
|
|
133
|
+
this.neighbors.remove(toDhtAddressRaw(removableNodeId))
|
|
134
134
|
this.neighbors.add(newContact)
|
|
135
135
|
}
|
|
136
136
|
|
|
@@ -151,7 +151,7 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
|
|
|
151
151
|
}
|
|
152
152
|
if (contact.getNodeId() !== this.options.localNodeId) {
|
|
153
153
|
const peerDescriptor = contact.getPeerDescriptor()
|
|
154
|
-
const nodeId =
|
|
154
|
+
const nodeId = toNodeId(peerDescriptor)
|
|
155
155
|
// Important to lock here, before the ping result is known
|
|
156
156
|
this.options.connectionLocker?.weakLockConnection(nodeId, this.options.lockId)
|
|
157
157
|
if (this.options.hasConnection(contact.getNodeId())) {
|
|
@@ -188,7 +188,7 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
|
|
|
188
188
|
|
|
189
189
|
private getNearbyActiveContactNotInNeighbors(): DhtNodeRpcRemote | undefined {
|
|
190
190
|
for (const contactId of this.nearbyContacts.getContactIds()) {
|
|
191
|
-
if (!this.neighbors.get(
|
|
191
|
+
if (!this.neighbors.get(toDhtAddressRaw(contactId)) && this.activeContacts.has(contactId)) {
|
|
192
192
|
return this.nearbyContacts.getContact(contactId)!
|
|
193
193
|
}
|
|
194
194
|
}
|
|
@@ -201,22 +201,22 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
|
|
|
201
201
|
}
|
|
202
202
|
logger.trace(`Removing contact ${nodeId}`)
|
|
203
203
|
this.ringContacts.removeContact(this.nearbyContacts.getContact(nodeId))
|
|
204
|
-
this.neighbors.remove(
|
|
204
|
+
this.neighbors.remove(toDhtAddressRaw(nodeId))
|
|
205
205
|
this.nearbyContacts.removeContact(nodeId)
|
|
206
206
|
this.activeContacts.delete(nodeId)
|
|
207
207
|
this.randomContacts.removeContact(nodeId)
|
|
208
208
|
}
|
|
209
209
|
|
|
210
210
|
removeNeighbor(nodeId: DhtAddress): void {
|
|
211
|
-
this.neighbors.remove(
|
|
211
|
+
this.neighbors.remove(toDhtAddressRaw(nodeId))
|
|
212
212
|
}
|
|
213
213
|
|
|
214
214
|
async pruneOfflineNodes(nodes: DhtNodeRpcRemote[]): Promise<void> {
|
|
215
215
|
logger.trace('Pruning offline nodes', { nodes: nodes.length })
|
|
216
216
|
const offlineNeighbors = await pingNodes(nodes, this.activeContacts)
|
|
217
217
|
offlineNeighbors.forEach((offlineNeighbor) => {
|
|
218
|
-
logger.trace('Removing offline node', { node:
|
|
219
|
-
this.removeContact(
|
|
218
|
+
logger.trace('Removing offline node', { node: toNodeId(offlineNeighbor) })
|
|
219
|
+
this.removeContact(toNodeId(offlineNeighbor))
|
|
220
220
|
})
|
|
221
221
|
}
|
|
222
222
|
|
|
@@ -278,7 +278,7 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
|
|
|
278
278
|
if (this.stopped) {
|
|
279
279
|
return
|
|
280
280
|
}
|
|
281
|
-
const nodeId =
|
|
281
|
+
const nodeId = toNodeId(peerDescriptor)
|
|
282
282
|
if (nodeId !== this.options.localNodeId) {
|
|
283
283
|
logger.trace(`Adding new contact ${nodeId}`)
|
|
284
284
|
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 }> =
|
|
@@ -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)
|