@streamr/dht 100.0.0-pretestnet.6 → 100.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +90 -8
- package/dist/package.json +70 -0
- package/dist/src/connection/Connection.d.ts +1 -0
- package/dist/src/connection/Connection.js +10 -3
- package/dist/src/connection/Connection.js.map +1 -1
- package/dist/src/connection/ConnectionLockHandler.d.ts +14 -14
- package/dist/src/connection/ConnectionLockHandler.js +22 -16
- package/dist/src/connection/ConnectionLockHandler.js.map +1 -1
- package/dist/src/connection/ConnectionLockRpcLocal.d.ts +3 -3
- package/dist/src/connection/ConnectionLockRpcLocal.js +7 -6
- package/dist/src/connection/ConnectionLockRpcLocal.js.map +1 -1
- package/dist/src/connection/ConnectionLockRpcRemote.d.ts +4 -6
- package/dist/src/connection/ConnectionLockRpcRemote.js +10 -37
- package/dist/src/connection/ConnectionLockRpcRemote.js.map +1 -1
- package/dist/src/connection/ConnectionManager.d.ts +19 -20
- package/dist/src/connection/ConnectionManager.js +132 -117
- package/dist/src/connection/ConnectionManager.js.map +1 -1
- package/dist/src/connection/ConnectorFacade.d.ts +3 -2
- package/dist/src/connection/ConnectorFacade.js +10 -3
- package/dist/src/connection/ConnectorFacade.js.map +1 -1
- package/dist/src/connection/Handshaker.d.ts +3 -1
- package/dist/src/connection/Handshaker.js +19 -10
- package/dist/src/connection/Handshaker.js.map +1 -1
- package/dist/src/connection/IConnection.d.ts +2 -7
- package/dist/src/connection/IConnection.js +1 -8
- package/dist/src/connection/IConnection.js.map +1 -1
- package/dist/src/connection/ManagedConnection.d.ts +5 -7
- package/dist/src/connection/ManagedConnection.js +42 -26
- package/dist/src/connection/ManagedConnection.js.map +1 -1
- package/dist/src/connection/ManagedWebrtcConnection.js.map +1 -1
- package/dist/src/connection/connectivityChecker.d.ts +9 -0
- package/dist/src/connection/connectivityChecker.js +130 -0
- package/dist/src/connection/connectivityChecker.js.map +1 -0
- package/dist/src/connection/connectivityRequestHandler.d.ts +3 -0
- package/dist/src/connection/connectivityRequestHandler.js +101 -0
- package/dist/src/connection/connectivityRequestHandler.js.map +1 -0
- package/dist/src/connection/simulator/Simulator.d.ts +0 -3
- package/dist/src/connection/simulator/Simulator.js +34 -69
- package/dist/src/connection/simulator/Simulator.js.map +1 -1
- package/dist/src/connection/simulator/SimulatorConnection.js +27 -25
- package/dist/src/connection/simulator/SimulatorConnection.js.map +1 -1
- package/dist/src/connection/simulator/SimulatorConnector.js +16 -12
- package/dist/src/connection/simulator/SimulatorConnector.js.map +1 -1
- package/dist/src/connection/simulator/pings.js.map +1 -1
- package/dist/src/connection/webrtc/NodeWebrtcConnection.d.ts +2 -3
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js +40 -27
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnector.d.ts +1 -2
- package/dist/src/connection/webrtc/WebrtcConnector.js +36 -32
- package/dist/src/connection/webrtc/WebrtcConnector.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.d.ts +4 -2
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js +28 -22
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.d.ts +3 -6
- package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.js +2 -5
- package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.js.map +1 -1
- package/dist/src/connection/webrtc/iceServerAsString.js +1 -1
- package/dist/src/connection/webrtc/iceServerAsString.js.map +1 -1
- package/dist/src/connection/websocket/AutoCertifierClientFacade.d.ts +1 -2
- package/dist/src/connection/websocket/AutoCertifierClientFacade.js +6 -4
- package/dist/src/connection/websocket/AutoCertifierClientFacade.js.map +1 -1
- package/dist/src/connection/websocket/ClientWebsocket.d.ts +1 -0
- package/dist/src/connection/websocket/ClientWebsocket.js +14 -7
- package/dist/src/connection/websocket/ClientWebsocket.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnector.d.ts +3 -9
- package/dist/src/connection/websocket/WebsocketConnector.js +142 -74
- package/dist/src/connection/websocket/WebsocketConnector.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.d.ts +5 -3
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.js +9 -12
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.d.ts +4 -7
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.js +7 -44
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketServer.d.ts +1 -4
- package/dist/src/connection/websocket/WebsocketServer.js +49 -40
- package/dist/src/connection/websocket/WebsocketServer.js.map +1 -1
- package/dist/src/connection/websocket/{ServerWebsocket.d.ts → WebsocketServerConnection.d.ts} +8 -4
- package/dist/src/connection/websocket/WebsocketServerConnection.js +97 -0
- package/dist/src/connection/websocket/WebsocketServerConnection.js.map +1 -0
- package/dist/src/dht/DhtNode.d.ts +45 -49
- package/dist/src/dht/DhtNode.js +229 -317
- package/dist/src/dht/DhtNode.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcLocal.d.ts +10 -9
- package/dist/src/dht/DhtNodeRpcLocal.js +19 -11
- package/dist/src/dht/DhtNodeRpcLocal.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcRemote.d.ts +15 -10
- package/dist/src/dht/DhtNodeRpcRemote.js +38 -21
- package/dist/src/dht/DhtNodeRpcRemote.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcLocal.d.ts +7 -6
- package/dist/src/dht/ExternalApiRpcLocal.js +9 -13
- package/dist/src/dht/ExternalApiRpcLocal.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcRemote.d.ts +6 -5
- package/dist/src/dht/ExternalApiRpcRemote.js +10 -7
- package/dist/src/dht/ExternalApiRpcRemote.js.map +1 -1
- package/dist/src/dht/PeerManager.d.ts +61 -0
- package/dist/src/dht/PeerManager.js +288 -0
- package/dist/src/dht/PeerManager.js.map +1 -0
- package/dist/src/dht/contact/Contact.d.ts +2 -2
- package/dist/src/dht/contact/Contact.js +4 -3
- package/dist/src/dht/contact/Contact.js.map +1 -1
- package/dist/src/dht/contact/ContactList.d.ts +8 -8
- package/dist/src/dht/contact/ContactList.js +12 -7
- package/dist/src/dht/contact/ContactList.js.map +1 -1
- package/dist/src/dht/contact/RandomContactList.d.ts +4 -4
- package/dist/src/dht/contact/RandomContactList.js +13 -12
- package/dist/src/dht/contact/RandomContactList.js.map +1 -1
- package/dist/src/dht/contact/RingContactList.d.ts +31 -0
- package/dist/src/dht/contact/RingContactList.js +133 -0
- package/dist/src/dht/contact/RingContactList.js.map +1 -0
- package/dist/src/dht/contact/{Remote.d.ts → RpcRemote.d.ts} +8 -7
- package/dist/src/dht/contact/{Remote.js → RpcRemote.js} +16 -13
- package/dist/src/dht/contact/RpcRemote.js.map +1 -0
- package/dist/src/dht/contact/SortedContactList.d.ts +29 -15
- package/dist/src/dht/contact/SortedContactList.js +79 -42
- package/dist/src/dht/contact/SortedContactList.js.map +1 -1
- package/dist/src/dht/contact/ringIdentifiers.d.ts +16 -0
- package/dist/src/dht/contact/ringIdentifiers.js +54 -0
- package/dist/src/dht/contact/ringIdentifiers.js.map +1 -0
- package/dist/src/dht/discovery/DiscoverySession.d.ts +8 -18
- package/dist/src/dht/discovery/DiscoverySession.js +32 -48
- package/dist/src/dht/discovery/DiscoverySession.js.map +1 -1
- package/dist/src/dht/discovery/PeerDiscovery.d.ts +16 -12
- package/dist/src/dht/discovery/PeerDiscovery.js +82 -39
- package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -1
- package/dist/src/dht/discovery/RingDiscoverySession.d.ts +29 -0
- package/dist/src/dht/discovery/RingDiscoverySession.js +123 -0
- package/dist/src/dht/discovery/RingDiscoverySession.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.d.ts +36 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.js +166 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.d.ts +14 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.js +26 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.d.ts +6 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js +44 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.d.ts +44 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.js +187 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.d.ts +14 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js +20 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.d.ts +6 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.js +21 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.js.map +1 -0
- package/dist/src/dht/routing/DuplicateDetector.d.ts +2 -4
- package/dist/src/dht/routing/DuplicateDetector.js +10 -15
- package/dist/src/dht/routing/DuplicateDetector.js.map +1 -1
- package/dist/src/dht/routing/Router.d.ts +11 -27
- package/dist/src/dht/routing/Router.js +92 -58
- package/dist/src/dht/routing/Router.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcLocal.d.ts +3 -4
- package/dist/src/dht/routing/RouterRpcLocal.js +17 -16
- package/dist/src/dht/routing/RouterRpcLocal.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcRemote.d.ts +3 -3
- package/dist/src/dht/routing/RouterRpcRemote.js +29 -20
- package/dist/src/dht/routing/RouterRpcRemote.js.map +1 -1
- package/dist/src/dht/routing/RoutingSession.d.ts +29 -21
- package/dist/src/dht/routing/RoutingSession.js +93 -68
- package/dist/src/dht/routing/RoutingSession.js.map +1 -1
- package/dist/src/dht/routing/RoutingTablesCache.d.ts +24 -0
- package/dist/src/dht/routing/RoutingTablesCache.js +46 -0
- package/dist/src/dht/routing/RoutingTablesCache.js.map +1 -0
- package/dist/src/dht/routing/getPreviousPeer.js.map +1 -1
- package/dist/src/dht/store/LocalDataStore.d.ts +9 -14
- package/dist/src/dht/store/LocalDataStore.js +46 -72
- package/dist/src/dht/store/LocalDataStore.js.map +1 -1
- package/dist/src/dht/store/StoreManager.d.ts +33 -0
- package/dist/src/dht/store/StoreManager.js +182 -0
- package/dist/src/dht/store/StoreManager.js.map +1 -0
- package/dist/src/dht/store/StoreRpcLocal.d.ts +11 -41
- package/dist/src/dht/store/StoreRpcLocal.js +27 -234
- package/dist/src/dht/store/StoreRpcLocal.js.map +1 -1
- package/dist/src/dht/store/StoreRpcRemote.d.ts +6 -7
- package/dist/src/dht/store/StoreRpcRemote.js +10 -20
- package/dist/src/dht/store/StoreRpcRemote.js.map +1 -1
- package/dist/src/exports.d.ts +5 -3
- package/dist/src/exports.js +10 -8
- package/dist/src/exports.js.map +1 -1
- package/dist/src/helpers/AddressTools.js +2 -0
- package/dist/src/helpers/AddressTools.js.map +1 -1
- package/dist/src/helpers/Connectivity.js.map +1 -1
- package/dist/src/helpers/MapWithTtl.d.ts +14 -0
- package/dist/src/helpers/MapWithTtl.js +60 -0
- package/dist/src/helpers/MapWithTtl.js.map +1 -0
- package/dist/src/helpers/createPeerDescriptor.d.ts +3 -0
- package/dist/src/helpers/createPeerDescriptor.js +57 -0
- package/dist/src/helpers/createPeerDescriptor.js.map +1 -0
- package/dist/src/helpers/createPeerDescriptorSignaturePayload.d.ts +2 -0
- package/dist/src/helpers/createPeerDescriptorSignaturePayload.js +30 -0
- package/dist/src/helpers/createPeerDescriptorSignaturePayload.js.map +1 -0
- package/dist/src/helpers/debugHelpers.js.map +1 -1
- package/dist/src/helpers/errors.js +2 -0
- package/dist/src/helpers/errors.js.map +1 -1
- package/dist/src/helpers/offering.d.ts +4 -0
- package/dist/src/helpers/offering.js +18 -0
- package/dist/src/helpers/offering.js.map +1 -0
- package/dist/src/helpers/protoClasses.js +2 -3
- package/dist/src/helpers/protoClasses.js.map +1 -1
- package/dist/src/helpers/protoToString.js.map +1 -1
- package/dist/src/helpers/version.d.ts +6 -0
- package/dist/src/helpers/version.js +38 -0
- package/dist/src/helpers/version.js.map +1 -0
- package/dist/src/identifiers.d.ts +10 -0
- package/dist/src/identifiers.js +31 -0
- package/dist/src/identifiers.js.map +1 -0
- package/dist/src/proto/google/protobuf/any.js +8 -8
- package/dist/src/proto/google/protobuf/any.js.map +1 -1
- package/dist/src/proto/google/protobuf/empty.js +2 -4
- package/dist/src/proto/google/protobuf/empty.js.map +1 -1
- package/dist/src/proto/google/protobuf/timestamp.js +10 -10
- package/dist/src/proto/google/protobuf/timestamp.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +46 -49
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +63 -54
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +226 -232
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +146 -168
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +26 -29
- package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.js +1 -1
- package/dist/src/rpc-protocol/DhtCallContext.d.ts +2 -2
- package/dist/src/rpc-protocol/DhtCallContext.js +8 -0
- package/dist/src/rpc-protocol/DhtCallContext.js.map +1 -1
- package/dist/src/rpc-protocol/DhtRpcOptions.d.ts +2 -1
- package/dist/src/transport/ITransport.d.ts +10 -2
- package/dist/src/transport/ITransport.js +5 -0
- package/dist/src/transport/ITransport.js.map +1 -1
- package/dist/src/transport/ListeningRpcCommunicator.js +3 -1
- package/dist/src/transport/ListeningRpcCommunicator.js.map +1 -1
- package/dist/src/transport/RoutingRpcCommunicator.d.ts +4 -2
- package/dist/src/transport/RoutingRpcCommunicator.js +19 -12
- package/dist/src/transport/RoutingRpcCommunicator.js.map +1 -1
- package/jest.config.js +4 -1
- package/karma-setup.js +2 -0
- package/karma.config.js +13 -9
- package/package.json +17 -14
- package/protos/DhtRpc.proto +76 -76
- package/src/connection/Connection.ts +6 -1
- package/src/connection/ConnectionLockHandler.ts +30 -22
- package/src/connection/ConnectionLockRpcLocal.ts +7 -12
- package/src/connection/ConnectionLockRpcRemote.ts +9 -19
- package/src/connection/ConnectionManager.ts +132 -138
- package/src/connection/ConnectorFacade.ts +10 -9
- package/src/connection/Handshaker.ts +24 -12
- package/src/connection/IConnection.ts +2 -8
- package/src/connection/ManagedConnection.ts +34 -35
- package/src/connection/connectivityChecker.ts +109 -0
- package/src/connection/connectivityRequestHandler.ts +103 -0
- package/src/connection/simulator/Simulator.ts +6 -37
- package/src/connection/simulator/SimulatorConnection.ts +23 -25
- package/src/connection/simulator/SimulatorConnector.ts +11 -11
- package/src/connection/webrtc/BrowserWebrtcConnection.ts +17 -25
- package/src/connection/webrtc/NodeWebrtcConnection.ts +25 -27
- package/src/connection/webrtc/WebrtcConnector.ts +31 -36
- package/src/connection/webrtc/WebrtcConnectorRpcLocal.ts +31 -25
- package/src/connection/webrtc/WebrtcConnectorRpcRemote.ts +4 -14
- package/src/connection/webrtc/iceServerAsString.ts +1 -1
- package/src/connection/websocket/AutoCertifierClientFacade.ts +4 -6
- package/src/connection/websocket/ClientWebsocket.ts +10 -4
- package/src/connection/websocket/WebsocketConnector.ts +120 -97
- package/src/connection/websocket/WebsocketConnectorRpcLocal.ts +13 -15
- package/src/connection/websocket/WebsocketConnectorRpcRemote.ts +7 -27
- package/src/connection/websocket/WebsocketServer.ts +50 -53
- package/src/connection/websocket/WebsocketServerConnection.ts +104 -0
- package/src/dht/DhtNode.ts +289 -410
- package/src/dht/DhtNodeRpcLocal.ts +25 -17
- package/src/dht/DhtNodeRpcRemote.ts +43 -27
- package/src/dht/ExternalApiRpcLocal.ts +30 -17
- package/src/dht/ExternalApiRpcRemote.ts +14 -11
- package/src/dht/PeerManager.ts +339 -0
- package/src/dht/contact/Contact.ts +4 -4
- package/src/dht/contact/ContactList.ts +11 -10
- package/src/dht/contact/RandomContactList.ts +15 -15
- package/src/dht/contact/RingContactList.ts +151 -0
- package/src/dht/contact/{Remote.ts → RpcRemote.ts} +16 -19
- package/src/dht/contact/SortedContactList.ts +120 -72
- package/src/dht/contact/ringIdentifiers.ts +62 -0
- package/src/dht/discovery/DiscoverySession.ts +36 -61
- package/src/dht/discovery/PeerDiscovery.ts +98 -43
- package/src/dht/discovery/RingDiscoverySession.ts +160 -0
- package/src/dht/recursive-operation/RecursiveOperationManager.ts +246 -0
- package/src/dht/recursive-operation/RecursiveOperationRpcLocal.ts +34 -0
- package/src/dht/recursive-operation/RecursiveOperationRpcRemote.ts +43 -0
- package/src/dht/recursive-operation/RecursiveOperationSession.ts +232 -0
- package/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.ts +35 -0
- package/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.ts +30 -0
- package/src/dht/routing/DuplicateDetector.ts +9 -21
- package/src/dht/routing/Router.ts +95 -92
- package/src/dht/routing/RouterRpcLocal.ts +16 -18
- package/src/dht/routing/RouterRpcRemote.ts +26 -24
- package/src/dht/routing/RoutingSession.ts +119 -98
- package/src/dht/routing/RoutingTablesCache.ts +58 -0
- package/src/dht/routing/getPreviousPeer.ts +1 -1
- package/src/dht/store/LocalDataStore.ts +47 -77
- package/src/dht/store/StoreManager.ts +209 -0
- package/src/dht/store/StoreRpcLocal.ts +39 -308
- package/src/dht/store/StoreRpcRemote.ts +13 -31
- package/src/exports.ts +13 -3
- package/src/helpers/AddressTools.ts +2 -0
- package/src/helpers/MapWithTtl.ts +71 -0
- package/src/helpers/createPeerDescriptor.ts +57 -0
- package/src/helpers/createPeerDescriptorSignaturePayload.ts +28 -0
- package/src/helpers/offering.ts +15 -0
- package/src/helpers/protoClasses.ts +4 -6
- package/src/helpers/version.ts +32 -0
- package/src/identifiers.ts +29 -0
- package/src/proto/google/protobuf/any.ts +4 -4
- package/src/proto/google/protobuf/empty.ts +2 -4
- package/src/proto/google/protobuf/timestamp.ts +4 -4
- package/src/proto/packages/dht/protos/DhtRpc.client.ts +65 -68
- package/src/proto/packages/dht/protos/DhtRpc.server.ts +27 -30
- package/src/proto/packages/dht/protos/DhtRpc.ts +297 -313
- package/src/proto/packages/proto-rpc/protos/ProtoRpc.ts +1 -1
- package/src/rpc-protocol/DhtCallContext.ts +2 -2
- package/src/rpc-protocol/DhtRpcOptions.ts +2 -1
- package/src/transport/ITransport.ts +11 -2
- package/src/transport/ListeningRpcCommunicator.ts +1 -1
- package/src/transport/RoutingRpcCommunicator.ts +21 -14
- package/test/RandomGraphSimulation.ts +3 -2
- package/test/benchmark/Find.test.ts +13 -28
- package/test/benchmark/KademliaCorrectness.test.ts +24 -28
- package/test/benchmark/RingCorrectness.test.ts +157 -0
- package/test/benchmark/SortedContactListBenchmark.test.ts +151 -0
- package/test/benchmark/WebsocketServerMemoryLeak.test.ts +41 -0
- package/test/benchmark/hybrid-network-simulation/RingContactList.test.ts +72 -0
- package/test/benchmark/kademlia-simulation/Contact.ts +9 -9
- package/test/benchmark/kademlia-simulation/KademliaSimulation.ts +11 -11
- package/test/benchmark/kademlia-simulation/SimulationNode.ts +29 -25
- package/test/data/generateGroundTruthData.ts +7 -6
- package/test/end-to-end/Layer0-Layer1.test.ts +11 -15
- package/test/end-to-end/Layer0.test.ts +19 -22
- package/test/end-to-end/Layer0MixedConnectionTypes.test.ts +19 -21
- package/test/end-to-end/Layer0Webrtc-Layer1.test.ts +26 -28
- package/test/end-to-end/Layer0Webrtc.test.ts +19 -19
- package/test/end-to-end/Layer1-Scale-WebSocket.test.ts +10 -18
- package/test/end-to-end/Layer1-Scale-Webrtc.test.ts +8 -15
- package/test/end-to-end/RecoveryFromFailedAutoCertification.test.ts +2 -2
- package/test/end-to-end/WebsocketConnectionRequest.test.ts +8 -9
- package/test/end-to-end/memory-leak.test.ts +19 -24
- package/test/integration/ConnectionLocking.test.ts +66 -60
- package/test/integration/ConnectionManager.test.ts +43 -63
- package/test/integration/ConnectivityChecking.test.ts +52 -0
- package/test/integration/DhtJoinPeerDiscovery.test.ts +8 -12
- package/test/integration/DhtNodeExternalAPI.test.ts +17 -21
- package/test/integration/DhtNodeRpcRemote.test.ts +19 -26
- package/test/integration/DhtRpc.test.ts +20 -24
- package/test/integration/Find.test.ts +10 -12
- package/test/integration/Layer1-scale.test.ts +25 -37
- package/test/integration/Mock-Layer1-Layer0.test.ts +39 -59
- package/test/integration/MultipleEntryPointJoining.test.ts +14 -14
- package/test/integration/ReplicateData.test.ts +106 -0
- package/test/integration/RouteMessage.test.ts +42 -68
- package/test/integration/RouterRpcRemote.test.ts +19 -24
- package/test/integration/ScaleDownDht.test.ts +14 -12
- package/test/integration/SimultaneousConnections.test.ts +112 -111
- package/test/integration/Store.test.ts +43 -27
- package/test/integration/StoreAndDelete.test.ts +36 -48
- package/test/integration/StoreOnDhtWithThreeNodes.test.ts +59 -0
- package/test/integration/StoreOnDhtWithTwoNodes.test.ts +17 -37
- package/test/integration/StoreRpcRemote.test.ts +20 -32
- package/test/integration/WebrtcConnectionManagement.test.ts +39 -25
- package/test/integration/WebrtcConnectorRpc.test.ts +6 -11
- package/test/integration/WebsocketConnectionManagement.test.ts +87 -22
- package/test/integration/WebsocketConnectorRpc.test.ts +14 -24
- package/test/integration/{RpcErrors.test.ts → rpc-connections-over-webrpc.test.ts} +15 -26
- package/test/unit/AddressTools.test.ts +4 -0
- package/test/unit/ConnectivityHelpers.test.ts +9 -17
- package/test/unit/DuplicateDetector.test.ts +8 -5
- package/test/unit/LocalDataStore.test.ts +78 -75
- package/test/unit/PeerManager.test.ts +33 -0
- package/test/unit/RandomContactList.test.ts +12 -9
- package/test/unit/RecursiveOperationManager.test.ts +157 -0
- package/test/unit/RecursiveOperationSession.test.ts +68 -0
- package/test/unit/Router.test.ts +52 -35
- package/test/unit/RoutingSession.test.ts +79 -0
- package/test/unit/SortedContactList.test.ts +61 -30
- package/test/unit/StoreManager.test.ts +138 -0
- package/test/unit/WebsocketConnector.test.ts +27 -35
- package/test/unit/connectivityRequestHandler.test.ts +104 -0
- package/test/unit/createPeerDescriptor.test.ts +69 -0
- package/test/unit/customMatchers.test.ts +16 -0
- package/test/unit/version.test.ts +18 -0
- package/test/utils/FakeTransport.ts +47 -0
- package/test/utils/customMatchers.ts +71 -0
- package/test/utils/mock/MockRpcCommunicator.ts +7 -0
- package/test/utils/mock/Router.ts +13 -3
- package/test/utils/mock/Transport.ts +1 -1
- package/test/utils/mock/mockDataEntry.ts +38 -0
- package/test/utils/utils.ts +104 -107
- package/tsconfig.browser.json +2 -1
- package/tsconfig.jest.json +4 -2
- package/tsconfig.node.json +4 -2
- package/dist/src/connection/ConnectivityChecker.d.ts +0 -17
- package/dist/src/connection/ConnectivityChecker.js +0 -208
- package/dist/src/connection/ConnectivityChecker.js.map +0 -1
- package/dist/src/connection/websocket/ServerWebsocket.js +0 -100
- package/dist/src/connection/websocket/ServerWebsocket.js.map +0 -1
- package/dist/src/dht/contact/Remote.js.map +0 -1
- package/dist/src/dht/find/FindRpcLocal.d.ts +0 -14
- package/dist/src/dht/find/FindRpcLocal.js +0 -25
- package/dist/src/dht/find/FindRpcLocal.js.map +0 -1
- package/dist/src/dht/find/FindSession.d.ts +0 -44
- package/dist/src/dht/find/FindSession.js +0 -145
- package/dist/src/dht/find/FindSession.js.map +0 -1
- package/dist/src/dht/find/FindSessionRpcLocal.d.ts +0 -12
- package/dist/src/dht/find/FindSessionRpcLocal.js +0 -17
- package/dist/src/dht/find/FindSessionRpcLocal.js.map +0 -1
- package/dist/src/dht/find/FindSessionRpcRemote.d.ts +0 -6
- package/dist/src/dht/find/FindSessionRpcRemote.js +0 -21
- package/dist/src/dht/find/FindSessionRpcRemote.js.map +0 -1
- package/dist/src/dht/find/Finder.d.ts +0 -49
- package/dist/src/dht/find/Finder.js +0 -184
- package/dist/src/dht/find/Finder.js.map +0 -1
- package/dist/src/dht/routing/FindRpcRemote.d.ts +0 -6
- package/dist/src/dht/routing/FindRpcRemote.js +0 -41
- package/dist/src/dht/routing/FindRpcRemote.js.map +0 -1
- package/dist/src/helpers/PeerID.d.ts +0 -24
- package/dist/src/helpers/PeerID.js +0 -78
- package/dist/src/helpers/PeerID.js.map +0 -1
- package/dist/src/helpers/UUID.d.ts +0 -8
- package/dist/src/helpers/UUID.js +0 -36
- package/dist/src/helpers/UUID.js.map +0 -1
- package/dist/src/helpers/kademliaId.d.ts +0 -1
- package/dist/src/helpers/kademliaId.js +0 -14
- package/dist/src/helpers/kademliaId.js.map +0 -1
- package/dist/src/helpers/peerIdFromPeerDescriptor.d.ts +0 -6
- package/dist/src/helpers/peerIdFromPeerDescriptor.js +0 -23
- package/dist/src/helpers/peerIdFromPeerDescriptor.js.map +0 -1
- package/src/connection/ConnectivityChecker.ts +0 -199
- package/src/connection/websocket/ServerWebsocket.ts +0 -114
- package/src/dht/find/FindRpcLocal.ts +0 -35
- package/src/dht/find/FindSession.ts +0 -178
- package/src/dht/find/FindSessionRpcLocal.ts +0 -25
- package/src/dht/find/FindSessionRpcRemote.ts +0 -30
- package/src/dht/find/Finder.ts +0 -275
- package/src/dht/routing/FindRpcRemote.ts +0 -40
- package/src/helpers/PeerID.ts +0 -88
- package/src/helpers/UUID.ts +0 -35
- package/src/helpers/kademliaId.ts +0 -8
- package/src/helpers/peerIdFromPeerDescriptor.ts +0 -20
- package/test/integration/MigrateData.test.ts +0 -204
- package/test/unit/Finder.test.ts +0 -110
- package/test/unit/PeerID.test.ts +0 -22
- package/test/unit/UUID.test.ts +0 -55
|
@@ -1,254 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.StoreRpcLocal = void 0;
|
|
4
|
-
const DhtRpc_1 = require("../../proto/packages/dht/protos/DhtRpc");
|
|
5
|
-
const PeerID_1 = require("../../helpers/PeerID");
|
|
6
|
-
const proto_rpc_1 = require("@streamr/proto-rpc");
|
|
7
|
-
const DhtRpc_client_1 = require("../../proto/packages/dht/protos/DhtRpc.client");
|
|
8
|
-
const peerIdFromPeerDescriptor_1 = require("../../helpers/peerIdFromPeerDescriptor");
|
|
9
4
|
const utils_1 = require("@streamr/utils");
|
|
10
|
-
const StoreRpcRemote_1 = require("./StoreRpcRemote");
|
|
11
5
|
const timestamp_1 = require("../../proto/google/protobuf/timestamp");
|
|
12
|
-
const
|
|
13
|
-
const Contact_1 = require("../contact/Contact");
|
|
6
|
+
const identifiers_1 = require("../../identifiers");
|
|
14
7
|
const logger = new utils_1.Logger(module);
|
|
15
8
|
class StoreRpcLocal {
|
|
9
|
+
config;
|
|
16
10
|
constructor(config) {
|
|
17
|
-
this.
|
|
18
|
-
this.finder = config.finder;
|
|
19
|
-
this.localPeerDescriptor = config.localPeerDescriptor;
|
|
20
|
-
this.localDataStore = config.localDataStore;
|
|
21
|
-
this.serviceId = config.serviceId;
|
|
22
|
-
this.maxTtl = config.maxTtl;
|
|
23
|
-
this.highestTtl = config.highestTtl;
|
|
24
|
-
this.redundancyFactor = config.redundancyFactor;
|
|
25
|
-
this.dhtNodeEmitter = config.dhtNodeEmitter;
|
|
26
|
-
this.rpcRequestTimeout = config.rpcRequestTimeout;
|
|
27
|
-
this.getNodesClosestToIdFromBucket = config.getNodesClosestToIdFromBucket;
|
|
28
|
-
this.rpcCommunicator.registerRpcMethod(DhtRpc_1.StoreDataRequest, DhtRpc_1.StoreDataResponse, 'storeData', (request, context) => this.storeData(request, context));
|
|
29
|
-
this.rpcCommunicator.registerRpcMethod(DhtRpc_1.MigrateDataRequest, DhtRpc_1.MigrateDataResponse, 'migrateData', (request, context) => this.migrateData(request, context));
|
|
30
|
-
this.rpcCommunicator.registerRpcMethod(DhtRpc_1.DeleteDataRequest, DhtRpc_1.DeleteDataResponse, 'deleteData', (request, context) => this.deleteData(request, context));
|
|
31
|
-
this.dhtNodeEmitter.on('newContact', (peerDescriptor) => {
|
|
32
|
-
this.localDataStore.getStore().forEach((dataMap, _dataKey) => {
|
|
33
|
-
dataMap.forEach((dataEntry) => {
|
|
34
|
-
if (this.shouldMigrateDataToNewNode(dataEntry.dataEntry, peerDescriptor)) {
|
|
35
|
-
this.migrateDataToContact(dataEntry.dataEntry, peerDescriptor);
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
shouldMigrateDataToNewNode(dataEntry, newNode) {
|
|
42
|
-
const dataId = PeerID_1.PeerID.fromValue(dataEntry.kademliaId);
|
|
43
|
-
const newNodeId = PeerID_1.PeerID.fromValue(newNode.kademliaId);
|
|
44
|
-
const localPeerId = PeerID_1.PeerID.fromValue(this.localPeerDescriptor.kademliaId);
|
|
45
|
-
const closestToData = this.getNodesClosestToIdFromBucket(dataEntry.kademliaId, 10);
|
|
46
|
-
const sortedList = new SortedContactList_1.SortedContactList(dataId, 20, undefined, true);
|
|
47
|
-
sortedList.addContact(new Contact_1.Contact(this.localPeerDescriptor));
|
|
48
|
-
closestToData.forEach((con) => {
|
|
49
|
-
if (!newNodeId.equals(PeerID_1.PeerID.fromValue(con.getPeerDescriptor().kademliaId))) {
|
|
50
|
-
sortedList.addContact(new Contact_1.Contact(con.getPeerDescriptor()));
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
if (!sortedList.getAllContacts()[0].getPeerId().equals(localPeerId)) {
|
|
54
|
-
// If we are not the closes node to the data, do not migrate
|
|
55
|
-
return false;
|
|
56
|
-
}
|
|
57
|
-
const newPeerId = PeerID_1.PeerID.fromValue(newNode.kademliaId);
|
|
58
|
-
sortedList.addContact(new Contact_1.Contact(newNode));
|
|
59
|
-
const sorted = sortedList.getAllContacts();
|
|
60
|
-
let index = 0;
|
|
61
|
-
for (index = 0; index < sorted.length; index++) {
|
|
62
|
-
if (sorted[index].getPeerId().equals(newPeerId)) {
|
|
63
|
-
break;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
// if new node is within the storageRedundancyFactor closest nodes to the data
|
|
67
|
-
// do migrate data to it
|
|
68
|
-
if (index < this.redundancyFactor) {
|
|
69
|
-
this.localDataStore.setStale(dataId, dataEntry.storer, false);
|
|
70
|
-
return true;
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
this.localDataStore.setStale(dataId, dataEntry.storer, true);
|
|
74
|
-
return false;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
async migrateDataToContact(dataEntry, contact, doNotConnect = false) {
|
|
78
|
-
const rpcRemote = new StoreRpcRemote_1.StoreRpcRemote(this.localPeerDescriptor, contact, this.serviceId, (0, proto_rpc_1.toProtoRpcClient)(new DhtRpc_client_1.StoreRpcClient(this.rpcCommunicator.getRpcClientTransport())), this.rpcRequestTimeout);
|
|
79
|
-
try {
|
|
80
|
-
const response = await rpcRemote.migrateData({ dataEntry }, doNotConnect);
|
|
81
|
-
if (response.error) {
|
|
82
|
-
logger.trace('migrateData() returned error: ' + response.error);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
catch (e) {
|
|
86
|
-
logger.trace('migrateData() threw an exception ' + e);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
async storeDataToDht(key, data) {
|
|
90
|
-
logger.debug(`Storing data to DHT ${this.serviceId}`);
|
|
91
|
-
const result = await this.finder.startFind(key);
|
|
92
|
-
const closestNodes = result.closestNodes;
|
|
93
|
-
const successfulNodes = [];
|
|
94
|
-
const ttl = this.highestTtl; // ToDo: make TTL decrease according to some nice curve
|
|
95
|
-
const storerTime = timestamp_1.Timestamp.now();
|
|
96
|
-
for (let i = 0; i < closestNodes.length && successfulNodes.length < this.redundancyFactor; i++) {
|
|
97
|
-
if ((0, peerIdFromPeerDescriptor_1.areEqualPeerDescriptors)(this.localPeerDescriptor, closestNodes[i])) {
|
|
98
|
-
this.localDataStore.storeEntry({
|
|
99
|
-
kademliaId: key,
|
|
100
|
-
storer: this.localPeerDescriptor,
|
|
101
|
-
ttl,
|
|
102
|
-
storedAt: timestamp_1.Timestamp.now(),
|
|
103
|
-
data,
|
|
104
|
-
stale: false,
|
|
105
|
-
deleted: false,
|
|
106
|
-
storerTime
|
|
107
|
-
});
|
|
108
|
-
successfulNodes.push(closestNodes[i]);
|
|
109
|
-
continue;
|
|
110
|
-
}
|
|
111
|
-
const rpcRemote = new StoreRpcRemote_1.StoreRpcRemote(this.localPeerDescriptor, closestNodes[i], this.serviceId, (0, proto_rpc_1.toProtoRpcClient)(new DhtRpc_client_1.StoreRpcClient(this.rpcCommunicator.getRpcClientTransport())), this.rpcRequestTimeout);
|
|
112
|
-
try {
|
|
113
|
-
const response = await rpcRemote.storeData({ kademliaId: key, data, ttl, storerTime });
|
|
114
|
-
if (!response.error) {
|
|
115
|
-
successfulNodes.push(closestNodes[i]);
|
|
116
|
-
logger.trace('remote.storeData() returned success');
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
logger.trace('remote.storeData() returned error: ' + response.error);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
catch (e) {
|
|
123
|
-
logger.trace('remote.storeData() threw an exception ' + e);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
return successfulNodes;
|
|
127
|
-
}
|
|
128
|
-
selfIsOneOfClosestPeers(dataId) {
|
|
129
|
-
const localPeerId = PeerID_1.PeerID.fromValue(this.localPeerDescriptor.kademliaId);
|
|
130
|
-
const closestPeers = this.getNodesClosestToIdFromBucket(dataId, this.redundancyFactor);
|
|
131
|
-
const sortedList = new SortedContactList_1.SortedContactList(localPeerId, this.redundancyFactor, undefined, true);
|
|
132
|
-
sortedList.addContact(new Contact_1.Contact(this.localPeerDescriptor));
|
|
133
|
-
closestPeers.forEach((con) => sortedList.addContact(new Contact_1.Contact(con.getPeerDescriptor())));
|
|
134
|
-
return sortedList.getClosestContacts().some((node) => node.getPeerId().equals(localPeerId));
|
|
135
|
-
}
|
|
136
|
-
async deleteDataFromDht(key) {
|
|
137
|
-
logger.debug(`Deleting data from DHT ${this.serviceId}`);
|
|
138
|
-
const result = await this.finder.startFind(key);
|
|
139
|
-
const closestNodes = result.closestNodes;
|
|
140
|
-
const successfulNodes = [];
|
|
141
|
-
for (let i = 0; i < closestNodes.length && successfulNodes.length < this.redundancyFactor; i++) {
|
|
142
|
-
if ((0, peerIdFromPeerDescriptor_1.areEqualPeerDescriptors)(this.localPeerDescriptor, closestNodes[i])) {
|
|
143
|
-
this.localDataStore.markAsDeleted(key, (0, peerIdFromPeerDescriptor_1.peerIdFromPeerDescriptor)(this.localPeerDescriptor));
|
|
144
|
-
successfulNodes.push(closestNodes[i]);
|
|
145
|
-
continue;
|
|
146
|
-
}
|
|
147
|
-
const rpcRemote = new StoreRpcRemote_1.StoreRpcRemote(this.localPeerDescriptor, closestNodes[i], this.serviceId, (0, proto_rpc_1.toProtoRpcClient)(new DhtRpc_client_1.StoreRpcClient(this.rpcCommunicator.getRpcClientTransport())), this.rpcRequestTimeout);
|
|
148
|
-
try {
|
|
149
|
-
const response = await rpcRemote.deleteData({ kademliaId: key });
|
|
150
|
-
if (response.deleted) {
|
|
151
|
-
logger.trace('remote.deleteData() returned success');
|
|
152
|
-
}
|
|
153
|
-
else {
|
|
154
|
-
logger.trace('could not delete data from ' + (0, peerIdFromPeerDescriptor_1.getNodeIdFromPeerDescriptor)(closestNodes[i]));
|
|
155
|
-
}
|
|
156
|
-
successfulNodes.push(closestNodes[i]);
|
|
157
|
-
}
|
|
158
|
-
catch (e) {
|
|
159
|
-
logger.trace('remote.deleteData() threw an exception ' + e);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
11
|
+
this.config = config;
|
|
162
12
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
const
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
13
|
+
async storeData(request) {
|
|
14
|
+
logger.trace('storeData()');
|
|
15
|
+
const key = (0, identifiers_1.getDhtAddressFromRaw)(request.key);
|
|
16
|
+
const selfIsOneOfClosestPeers = this.config.selfIsWithinRedundancyFactor(key);
|
|
17
|
+
this.config.localDataStore.storeEntry({
|
|
18
|
+
key: request.key,
|
|
19
|
+
data: request.data,
|
|
20
|
+
creator: request.creator,
|
|
21
|
+
createdAt: request.createdAt,
|
|
172
22
|
storedAt: timestamp_1.Timestamp.now(),
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
stale: !this.selfIsOneOfClosestPeers(kademliaId),
|
|
23
|
+
ttl: request.ttl,
|
|
24
|
+
stale: !selfIsOneOfClosestPeers,
|
|
176
25
|
deleted: false
|
|
177
26
|
});
|
|
178
|
-
if (!
|
|
179
|
-
this.localDataStore.setAllEntriesAsStale(
|
|
27
|
+
if (!selfIsOneOfClosestPeers) {
|
|
28
|
+
this.config.localDataStore.setAllEntriesAsStale(key);
|
|
180
29
|
}
|
|
181
|
-
|
|
182
|
-
return DhtRpc_1.StoreDataResponse.create();
|
|
30
|
+
return {};
|
|
183
31
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
const
|
|
187
|
-
const
|
|
188
|
-
const deleted = this.localDataStore.markAsDeleted(kademliaId, (0, peerIdFromPeerDescriptor_1.peerIdFromPeerDescriptor)(incomingSourceDescriptor));
|
|
189
|
-
return DhtRpc_1.DeleteDataResponse.create({ deleted });
|
|
190
|
-
}
|
|
191
|
-
// RPC service implementation
|
|
192
|
-
async migrateData(request, context) {
|
|
193
|
-
logger.trace('server-side migrateData()');
|
|
194
|
-
const dataEntry = request.dataEntry;
|
|
195
|
-
const wasStored = this.localDataStore.storeEntry(dataEntry);
|
|
32
|
+
async replicateData(request, context) {
|
|
33
|
+
logger.trace('server-side replicateData()');
|
|
34
|
+
const dataEntry = request.entry;
|
|
35
|
+
const wasStored = this.config.localDataStore.storeEntry(dataEntry);
|
|
196
36
|
if (wasStored) {
|
|
197
|
-
this.
|
|
198
|
-
}
|
|
199
|
-
if (!this.selfIsOneOfClosestPeers(dataEntry.kademliaId)) {
|
|
200
|
-
this.localDataStore.setAllEntriesAsStale(PeerID_1.PeerID.fromValue(dataEntry.kademliaId));
|
|
201
|
-
}
|
|
202
|
-
logger.trace('server-side migrateData() at end');
|
|
203
|
-
return DhtRpc_1.MigrateDataResponse.create();
|
|
204
|
-
}
|
|
205
|
-
migrateDataToNeighborsIfNeeded(incomingPeer, dataEntry) {
|
|
206
|
-
// sort own contact list according to data id
|
|
207
|
-
const localPeerId = PeerID_1.PeerID.fromValue(this.localPeerDescriptor.kademliaId);
|
|
208
|
-
const dataId = PeerID_1.PeerID.fromValue(dataEntry.kademliaId);
|
|
209
|
-
const incomingPeerId = PeerID_1.PeerID.fromValue(incomingPeer.kademliaId);
|
|
210
|
-
const closestToData = this.getNodesClosestToIdFromBucket(dataEntry.kademliaId, 10);
|
|
211
|
-
const sortedList = new SortedContactList_1.SortedContactList(dataId, this.redundancyFactor, undefined, true);
|
|
212
|
-
sortedList.addContact(new Contact_1.Contact(this.localPeerDescriptor));
|
|
213
|
-
closestToData.forEach((con) => {
|
|
214
|
-
sortedList.addContact(new Contact_1.Contact(con.getPeerDescriptor()));
|
|
215
|
-
});
|
|
216
|
-
if (!sortedList.getAllContacts()[0].getPeerId().equals(localPeerId)) {
|
|
217
|
-
// If we are not the closest node to the data, migrate only to the
|
|
218
|
-
// closest one to the data
|
|
219
|
-
const contact = sortedList.getAllContacts()[0];
|
|
220
|
-
const contactPeerId = PeerID_1.PeerID.fromValue(contact.getPeerDescriptor().kademliaId);
|
|
221
|
-
if (!incomingPeerId.equals(contactPeerId) && !localPeerId.equals(contactPeerId)) {
|
|
222
|
-
setImmediate(async () => {
|
|
223
|
-
try {
|
|
224
|
-
await this.migrateDataToContact(dataEntry, contact.getPeerDescriptor());
|
|
225
|
-
logger.trace('migrateDataToContact() returned when migrating to only the closest contact');
|
|
226
|
-
}
|
|
227
|
-
catch (e) {
|
|
228
|
-
logger.error('migrating data to only the closest contact failed ' + e);
|
|
229
|
-
}
|
|
230
|
-
});
|
|
231
|
-
}
|
|
37
|
+
this.config.replicateDataToNeighbors(context.incomingSourceDescriptor, request.entry);
|
|
232
38
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
const contactPeerId = PeerID_1.PeerID.fromValue(contact.getPeerDescriptor().kademliaId);
|
|
237
|
-
if (!incomingPeerId.equals(contactPeerId) && !localPeerId.equals(contactPeerId)) {
|
|
238
|
-
if (!incomingPeerId.equals(contactPeerId) && !localPeerId.equals(contactPeerId)) {
|
|
239
|
-
setImmediate(async () => {
|
|
240
|
-
try {
|
|
241
|
-
await this.migrateDataToContact(dataEntry, contact.getPeerDescriptor());
|
|
242
|
-
logger.trace('migrateDataToContact() returned');
|
|
243
|
-
}
|
|
244
|
-
catch (e) {
|
|
245
|
-
logger.error('migrating data to one of the closest contacts failed ' + e);
|
|
246
|
-
}
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
});
|
|
39
|
+
const key = (0, identifiers_1.getDhtAddressFromRaw)(dataEntry.key);
|
|
40
|
+
if (!this.config.selfIsWithinRedundancyFactor(key)) {
|
|
41
|
+
this.config.localDataStore.setAllEntriesAsStale(key);
|
|
251
42
|
}
|
|
43
|
+
logger.trace('server-side replicateData() at end');
|
|
44
|
+
return {};
|
|
252
45
|
}
|
|
253
46
|
}
|
|
254
47
|
exports.StoreRpcLocal = StoreRpcLocal;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StoreRpcLocal.js","sourceRoot":"","sources":["../../../../src/dht/store/StoreR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CAAC,CAAA;QACF,IAAI,CAAC,uBAAuB,EAAE,CAAC;YAC3B,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,oBAAoB,CAAC,GAAG,CAAC,CAAA;QACxD,CAAC;QACD,OAAO,EAAE,CAAA;IACb,CAAC;IAEM,KAAK,CAAC,aAAa,CAAC,OAA6B,EAAE,OAA0B;QAChF,MAAM,CAAC,KAAK,CAAC,6BAA6B,CAAC,CAAA;QAC3C,MAAM,SAAS,GAAG,OAAO,CAAC,KAAM,CAAA;QAChC,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,UAAU,CAAC,SAAS,CAAC,CAAA;QAClE,IAAI,SAAS,EAAE,CAAC;YACZ,IAAI,CAAC,MAAM,CAAC,wBAAwB,CAAE,OAA0B,CAAC,wBAAyB,EAAE,OAAO,CAAC,KAAM,CAAC,CAAA;QAC/G,CAAC;QACD,MAAM,GAAG,GAAG,IAAA,kCAAoB,EAAC,SAAS,CAAC,GAAG,CAAC,CAAA;QAC/C,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,4BAA4B,CAAC,GAAG,CAAC,EAAE,CAAC;YACjD,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,oBAAoB,CAAC,GAAG,CAAC,CAAA;QACxD,CAAC;QACD,MAAM,CAAC,KAAK,CAAC,oCAAoC,CAAC,CAAA;QAClD,OAAO,EAAE,CAAA;IACb,CAAC;CACJ;AA1CD,sCA0CC"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
export declare class StoreRpcRemote extends
|
|
5
|
-
storeData(request: StoreDataRequest): Promise<
|
|
6
|
-
|
|
7
|
-
migrateData(request: MigrateDataRequest, doNotConnect?: boolean): Promise<MigrateDataResponse>;
|
|
1
|
+
import { ReplicateDataRequest, StoreDataRequest } from '../../proto/packages/dht/protos/DhtRpc';
|
|
2
|
+
import { StoreRpcClient } from '../../proto/packages/dht/protos/DhtRpc.client';
|
|
3
|
+
import { RpcRemote } from '../contact/RpcRemote';
|
|
4
|
+
export declare class StoreRpcRemote extends RpcRemote<StoreRpcClient> {
|
|
5
|
+
storeData(request: StoreDataRequest): Promise<void>;
|
|
6
|
+
replicateData(request: ReplicateDataRequest): Promise<void>;
|
|
8
7
|
}
|
|
@@ -1,35 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.StoreRpcRemote = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
class StoreRpcRemote extends
|
|
4
|
+
const identifiers_1 = require("../../identifiers");
|
|
5
|
+
const RpcRemote_1 = require("../contact/RpcRemote");
|
|
6
|
+
class StoreRpcRemote extends RpcRemote_1.RpcRemote {
|
|
7
7
|
async storeData(request) {
|
|
8
8
|
const options = this.formDhtRpcOptions();
|
|
9
9
|
try {
|
|
10
|
-
|
|
10
|
+
await this.getClient().storeData(request, options);
|
|
11
11
|
}
|
|
12
12
|
catch (err) {
|
|
13
|
-
const to = (0,
|
|
14
|
-
const from = (0,
|
|
15
|
-
throw Error(`Could not store data to ${to} from ${from} ${err}`);
|
|
13
|
+
const to = (0, identifiers_1.getNodeIdFromPeerDescriptor)(this.getPeerDescriptor());
|
|
14
|
+
const from = (0, identifiers_1.getNodeIdFromPeerDescriptor)(this.getLocalPeerDescriptor());
|
|
15
|
+
throw new Error(`Could not store data to ${to} from ${from} ${err}`);
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
-
async
|
|
19
|
-
const options = this.formDhtRpcOptions();
|
|
20
|
-
try {
|
|
21
|
-
return await this.getClient().deleteData(request, options);
|
|
22
|
-
}
|
|
23
|
-
catch (err) {
|
|
24
|
-
throw Error(`Could not call delete data to ${(0, peerIdFromPeerDescriptor_1.getNodeIdFromPeerDescriptor)(this.getPeerDescriptor())} ${err}`);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
async migrateData(request, doNotConnect = false) {
|
|
18
|
+
async replicateData(request) {
|
|
28
19
|
const options = this.formDhtRpcOptions({
|
|
29
|
-
timeout:
|
|
30
|
-
doNotConnect
|
|
20
|
+
timeout: RpcRemote_1.EXISTING_CONNECTION_TIMEOUT
|
|
31
21
|
});
|
|
32
|
-
return this.getClient().
|
|
22
|
+
return this.getClient().replicateData(request, options);
|
|
33
23
|
}
|
|
34
24
|
}
|
|
35
25
|
exports.StoreRpcRemote = StoreRpcRemote;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StoreRpcRemote.js","sourceRoot":"","sources":["../../../../src/dht/store/StoreRpcRemote.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"StoreRpcRemote.js","sourceRoot":"","sources":["../../../../src/dht/store/StoreRpcRemote.ts"],"names":[],"mappings":";;;AAAA,mDAA+D;AAM/D,oDAA6E;AAE7E,MAAa,cAAe,SAAQ,qBAAyB;IAEzD,KAAK,CAAC,SAAS,CAAC,OAAyB;QACrC,MAAM,OAAO,GAAG,IAAI,CAAC,iBAAiB,EAAE,CAAA;QACxC,IAAI,CAAC;YACD,MAAM,IAAI,CAAC,SAAS,EAAE,CAAC,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QACtD,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,MAAM,EAAE,GAAG,IAAA,yCAA2B,EAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC,CAAA;YAChE,MAAM,IAAI,GAAG,IAAA,yCAA2B,EAAC,IAAI,CAAC,sBAAsB,EAAE,CAAC,CAAA;YACvE,MAAM,IAAI,KAAK,CAAC,2BAA2B,EAAE,SAAS,IAAI,IAAI,GAAG,EAAE,CAAC,CAAA;QACxE,CAAC;IACL,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,OAA6B;QAC7C,MAAM,OAAO,GAAG,IAAI,CAAC,iBAAiB,CAAC;YACnC,OAAO,EAAE,uCAA2B;SACvC,CAAC,CAAA;QACF,OAAO,IAAI,CAAC,SAAS,EAAE,CAAC,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;IAC3D,CAAC;CAEJ;AApBD,wCAoBC"}
|
package/dist/src/exports.d.ts
CHANGED
|
@@ -7,13 +7,15 @@ export { getRandomRegion, getRegionDelayMatrix } from './connection/simulator/pi
|
|
|
7
7
|
export { PeerDescriptor, Message, NodeType, DataEntry } from './proto/packages/dht/protos/DhtRpc';
|
|
8
8
|
export { ITransport } from './transport/ITransport';
|
|
9
9
|
export { ConnectionManager, ConnectionLocker, PortRange, TlsCertificate } from './connection/ConnectionManager';
|
|
10
|
+
export { LockID } from './connection/ConnectionLockHandler';
|
|
10
11
|
export { DefaultConnectorFacade } from './connection/ConnectorFacade';
|
|
11
12
|
export { DhtRpcOptions } from './rpc-protocol/DhtRpcOptions';
|
|
12
|
-
export {
|
|
13
|
-
export { areEqualPeerDescriptors } from './helpers/peerIdFromPeerDescriptor';
|
|
13
|
+
export { RpcRemote, EXISTING_CONNECTION_TIMEOUT } from './dht/contact/RpcRemote';
|
|
14
14
|
export { IceServer } from './connection/webrtc/WebrtcConnector';
|
|
15
15
|
export { DhtCallContext } from './rpc-protocol/DhtCallContext';
|
|
16
16
|
export { ClientWebsocket } from './connection/websocket/ClientWebsocket';
|
|
17
17
|
export { ManagedConnection } from './connection/ManagedConnection';
|
|
18
18
|
export { ConnectionType } from './connection/IConnection';
|
|
19
|
-
export {
|
|
19
|
+
export { ServiceID } from './types/ServiceID';
|
|
20
|
+
export { RingContacts } from './dht/contact/RingContactList';
|
|
21
|
+
export { DhtAddress, DhtAddressRaw, getDhtAddressFromRaw, getRawFromDhtAddress, createRandomDhtAddress, areEqualPeerDescriptors, getNodeIdFromPeerDescriptor } from './identifiers';
|
package/dist/src/exports.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getNodeIdFromPeerDescriptor = exports.areEqualPeerDescriptors = exports.createRandomDhtAddress = exports.getRawFromDhtAddress = exports.getDhtAddressFromRaw = exports.ConnectionType = exports.ManagedConnection = exports.ClientWebsocket = exports.DhtCallContext = exports.EXISTING_CONNECTION_TIMEOUT = exports.RpcRemote = exports.DefaultConnectorFacade = exports.ConnectionManager = exports.DataEntry = exports.NodeType = exports.Message = exports.PeerDescriptor = exports.getRegionDelayMatrix = exports.getRandomRegion = exports.SimulatorTransport = exports.LatencyType = exports.Simulator = exports.RoutingRpcCommunicator = exports.ListeningRpcCommunicator = exports.DhtNode = void 0;
|
|
4
4
|
var DhtNode_1 = require("./dht/DhtNode");
|
|
5
5
|
Object.defineProperty(exports, "DhtNode", { enumerable: true, get: function () { return DhtNode_1.DhtNode; } });
|
|
6
6
|
var ListeningRpcCommunicator_1 = require("./transport/ListeningRpcCommunicator");
|
|
@@ -24,11 +24,9 @@ var ConnectionManager_1 = require("./connection/ConnectionManager");
|
|
|
24
24
|
Object.defineProperty(exports, "ConnectionManager", { enumerable: true, get: function () { return ConnectionManager_1.ConnectionManager; } });
|
|
25
25
|
var ConnectorFacade_1 = require("./connection/ConnectorFacade");
|
|
26
26
|
Object.defineProperty(exports, "DefaultConnectorFacade", { enumerable: true, get: function () { return ConnectorFacade_1.DefaultConnectorFacade; } });
|
|
27
|
-
var
|
|
28
|
-
Object.defineProperty(exports, "
|
|
29
|
-
Object.defineProperty(exports, "EXISTING_CONNECTION_TIMEOUT", { enumerable: true, get: function () { return
|
|
30
|
-
var peerIdFromPeerDescriptor_1 = require("./helpers/peerIdFromPeerDescriptor");
|
|
31
|
-
Object.defineProperty(exports, "areEqualPeerDescriptors", { enumerable: true, get: function () { return peerIdFromPeerDescriptor_1.areEqualPeerDescriptors; } });
|
|
27
|
+
var RpcRemote_1 = require("./dht/contact/RpcRemote");
|
|
28
|
+
Object.defineProperty(exports, "RpcRemote", { enumerable: true, get: function () { return RpcRemote_1.RpcRemote; } });
|
|
29
|
+
Object.defineProperty(exports, "EXISTING_CONNECTION_TIMEOUT", { enumerable: true, get: function () { return RpcRemote_1.EXISTING_CONNECTION_TIMEOUT; } });
|
|
32
30
|
var DhtCallContext_1 = require("./rpc-protocol/DhtCallContext");
|
|
33
31
|
Object.defineProperty(exports, "DhtCallContext", { enumerable: true, get: function () { return DhtCallContext_1.DhtCallContext; } });
|
|
34
32
|
var ClientWebsocket_1 = require("./connection/websocket/ClientWebsocket");
|
|
@@ -37,6 +35,10 @@ var ManagedConnection_1 = require("./connection/ManagedConnection");
|
|
|
37
35
|
Object.defineProperty(exports, "ManagedConnection", { enumerable: true, get: function () { return ManagedConnection_1.ManagedConnection; } });
|
|
38
36
|
var IConnection_1 = require("./connection/IConnection");
|
|
39
37
|
Object.defineProperty(exports, "ConnectionType", { enumerable: true, get: function () { return IConnection_1.ConnectionType; } });
|
|
40
|
-
var
|
|
41
|
-
Object.defineProperty(exports, "
|
|
38
|
+
var identifiers_1 = require("./identifiers");
|
|
39
|
+
Object.defineProperty(exports, "getDhtAddressFromRaw", { enumerable: true, get: function () { return identifiers_1.getDhtAddressFromRaw; } });
|
|
40
|
+
Object.defineProperty(exports, "getRawFromDhtAddress", { enumerable: true, get: function () { return identifiers_1.getRawFromDhtAddress; } });
|
|
41
|
+
Object.defineProperty(exports, "createRandomDhtAddress", { enumerable: true, get: function () { return identifiers_1.createRandomDhtAddress; } });
|
|
42
|
+
Object.defineProperty(exports, "areEqualPeerDescriptors", { enumerable: true, get: function () { return identifiers_1.areEqualPeerDescriptors; } });
|
|
43
|
+
Object.defineProperty(exports, "getNodeIdFromPeerDescriptor", { enumerable: true, get: function () { return identifiers_1.getNodeIdFromPeerDescriptor; } });
|
|
42
44
|
//# sourceMappingURL=exports.js.map
|
package/dist/src/exports.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exports.js","sourceRoot":"","sources":["../../src/exports.ts"],"names":[],"mappings":";;;AAAA,yCAAsE;AA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,OAAA;AAC1B,wDAAyD;AAAhD,6GAAA,cAAc,OAAA;AAGvB,6CAQsB;AALlB,mHAAA,oBAAoB,OAAA;AACpB,mHAAA,oBAAoB,OAAA;AACpB,qHAAA,sBAAsB,OAAA;AACtB,sHAAA,uBAAuB,OAAA;AACvB,0HAAA,2BAA2B,OAAA"}
|
|
@@ -6,10 +6,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.getAddressFromIceCandidate = exports.isPrivateIPv4 = void 0;
|
|
7
7
|
const ipaddr_js_1 = __importDefault(require("ipaddr.js"));
|
|
8
8
|
// IPv4 private address ranges as specified by RFC 1918
|
|
9
|
+
// and private loopback addresses
|
|
9
10
|
const IPv4PrivateRanges = [
|
|
10
11
|
'10.0.0.0/8',
|
|
11
12
|
'172.16.0.0/12',
|
|
12
13
|
'192.168.0.0/16',
|
|
14
|
+
'127.0.0.0/8'
|
|
13
15
|
].map((a) => ipaddr_js_1.default.parseCIDR(a));
|
|
14
16
|
function isPrivateIPv4(address) {
|
|
15
17
|
if (ipaddr_js_1.default.IPv4.isValid(address)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AddressTools.js","sourceRoot":"","sources":["../../../src/helpers/AddressTools.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA8B;AAE9B,uDAAuD;AACvD,MAAM,iBAAiB,GAAG;IACtB,YAAY;IACZ,eAAe;IACf,gBAAgB;
|
|
1
|
+
{"version":3,"file":"AddressTools.js","sourceRoot":"","sources":["../../../src/helpers/AddressTools.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA8B;AAE9B,uDAAuD;AACvD,iCAAiC;AACjC,MAAM,iBAAiB,GAAG;IACtB,YAAY;IACZ,eAAe;IACf,gBAAgB;IAChB,aAAa;CAChB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,mBAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAA;AAEjC,SAAgB,aAAa,CAAC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|
1
|
+
export declare class MapWithTtl<K, V> {
|
|
2
|
+
private readonly delegate;
|
|
3
|
+
private readonly getTtl;
|
|
4
|
+
constructor(getTtl: (value: V) => number);
|
|
5
|
+
set(key: K, value: V): void;
|
|
6
|
+
get(key: K): V | undefined;
|
|
7
|
+
has(key: K): boolean;
|
|
8
|
+
delete(key: K): void;
|
|
9
|
+
clear(): void;
|
|
10
|
+
size(): number;
|
|
11
|
+
values(): IterableIterator<V>;
|
|
12
|
+
forEach(cb: (value: V, key: K) => void): void;
|
|
13
|
+
private createTimeout;
|
|
14
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MapWithTtl = void 0;
|
|
4
|
+
class MapWithTtl {
|
|
5
|
+
delegate = new Map();
|
|
6
|
+
getTtl;
|
|
7
|
+
constructor(getTtl) {
|
|
8
|
+
this.getTtl = getTtl;
|
|
9
|
+
}
|
|
10
|
+
set(key, value) {
|
|
11
|
+
const existing = this.delegate.get(key);
|
|
12
|
+
if (existing !== undefined) {
|
|
13
|
+
clearTimeout(existing.timeout);
|
|
14
|
+
}
|
|
15
|
+
this.delegate.set(key, {
|
|
16
|
+
value,
|
|
17
|
+
timeout: this.createTimeout(key, value)
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
get(key) {
|
|
21
|
+
const wrapper = this.delegate.get(key);
|
|
22
|
+
return wrapper?.value;
|
|
23
|
+
}
|
|
24
|
+
has(key) {
|
|
25
|
+
return this.delegate.has(key);
|
|
26
|
+
}
|
|
27
|
+
delete(key) {
|
|
28
|
+
const existing = this.delegate.get(key);
|
|
29
|
+
if (existing !== undefined) {
|
|
30
|
+
clearTimeout(existing.timeout);
|
|
31
|
+
this.delegate.delete(key);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
clear() {
|
|
35
|
+
this.delegate.forEach((value) => {
|
|
36
|
+
clearTimeout(value.timeout);
|
|
37
|
+
});
|
|
38
|
+
this.delegate.clear();
|
|
39
|
+
}
|
|
40
|
+
size() {
|
|
41
|
+
return this.delegate.size;
|
|
42
|
+
}
|
|
43
|
+
*values() {
|
|
44
|
+
for (const v of this.delegate.values()) {
|
|
45
|
+
yield v.value;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
forEach(cb) {
|
|
49
|
+
this.delegate.forEach((valueWrapper, key) => {
|
|
50
|
+
cb(valueWrapper.value, key);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
createTimeout(key, value) {
|
|
54
|
+
return setTimeout(() => {
|
|
55
|
+
this.delete(key);
|
|
56
|
+
}, this.getTtl(value));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.MapWithTtl = MapWithTtl;
|
|
60
|
+
//# sourceMappingURL=MapWithTtl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MapWithTtl.js","sourceRoot":"","sources":["../../../src/helpers/MapWithTtl.ts"],"names":[],"mappings":";;;AAKA,MAAa,UAAU;IAEF,QAAQ,GAA4B,IAAI,GAAG,EAAE,CAAA;IAC7C,MAAM,CAAsB;IAE7C,YAAY,MAA4B;QACpC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACxB,CAAC;IAED,GAAG,CAAC,GAAM,EAAE,KAAQ;QAChB,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QACvC,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;YACzB,YAAY,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAA;QAClC,CAAC;QACD,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE;YACnB,KAAK;YACL,OAAO,EAAE,IAAI,CAAC,aAAa,CAAC,GAAG,EAAE,KAAK,CAAC;SAC1C,CAAC,CAAA;IACN,CAAC;IAED,GAAG,CAAC,GAAM;QACN,MAAM,OAAO,GAAG,IA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,CAAC,CAAA;QACpB,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;IAC1B,CAAC;CACJ;AAjED,gCAiEC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { DhtAddress } from '../identifiers';
|
|
2
|
+
import { ConnectivityResponse, PeerDescriptor } from '../proto/packages/dht/protos/DhtRpc';
|
|
3
|
+
export declare const createPeerDescriptor: (connectivityResponse: ConnectivityResponse, region: number, nodeId?: DhtAddress) => PeerDescriptor;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createPeerDescriptor = void 0;
|
|
7
|
+
const utils_1 = require("@streamr/utils");
|
|
8
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
9
|
+
const isBrowserEnvironment_1 = require("../helpers/browser/isBrowserEnvironment");
|
|
10
|
+
const createPeerDescriptorSignaturePayload_1 = require("../helpers/createPeerDescriptorSignaturePayload");
|
|
11
|
+
const identifiers_1 = require("../identifiers");
|
|
12
|
+
const DhtRpc_1 = require("../proto/packages/dht/protos/DhtRpc");
|
|
13
|
+
const calculateNodeIdRaw = (ipAddress, privateKey) => {
|
|
14
|
+
// nodeId is calculated as
|
|
15
|
+
// concatenate(
|
|
16
|
+
// get104leastSignificatBits(hash(ipAddress)),
|
|
17
|
+
// get56leastSignificatBits(sign(ipAddress))
|
|
18
|
+
// )
|
|
19
|
+
const ipAsBuffer = Buffer.alloc(4);
|
|
20
|
+
ipAsBuffer.writeUInt32BE(ipAddress);
|
|
21
|
+
const ipHash = (0, utils_1.hash)(ipAsBuffer);
|
|
22
|
+
const signature = (0, utils_1.createSignature)(ipAsBuffer, privateKey);
|
|
23
|
+
const nodeIdRaw = Buffer.concat([
|
|
24
|
+
ipHash.subarray(ipHash.length - 13, ipHash.length),
|
|
25
|
+
signature.subarray(signature.length - 7, signature.length)
|
|
26
|
+
]);
|
|
27
|
+
return nodeIdRaw;
|
|
28
|
+
};
|
|
29
|
+
const createPeerDescriptor = (connectivityResponse, region, nodeId) => {
|
|
30
|
+
const privateKey = crypto_1.default.randomBytes(32);
|
|
31
|
+
const publicKey = crypto_1.default.randomBytes(20); // TODO calculate publicKey from privateKey
|
|
32
|
+
let nodeIdRaw;
|
|
33
|
+
if (nodeId !== undefined) {
|
|
34
|
+
nodeIdRaw = (0, identifiers_1.getRawFromDhtAddress)(nodeId);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
nodeIdRaw = calculateNodeIdRaw(connectivityResponse.ipAddress, privateKey);
|
|
38
|
+
}
|
|
39
|
+
const ret = {
|
|
40
|
+
nodeId: nodeIdRaw,
|
|
41
|
+
type: (0, isBrowserEnvironment_1.isBrowserEnvironment)() ? DhtRpc_1.NodeType.BROWSER : DhtRpc_1.NodeType.NODEJS,
|
|
42
|
+
ipAddress: connectivityResponse.ipAddress,
|
|
43
|
+
region,
|
|
44
|
+
publicKey
|
|
45
|
+
};
|
|
46
|
+
if (connectivityResponse.websocket) {
|
|
47
|
+
ret.websocket = {
|
|
48
|
+
host: connectivityResponse.websocket.host,
|
|
49
|
+
port: connectivityResponse.websocket.port,
|
|
50
|
+
tls: connectivityResponse.websocket.tls
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
ret.signature = (0, utils_1.createSignature)((0, createPeerDescriptorSignaturePayload_1.createPeerDescriptorSignaturePayload)(ret), privateKey);
|
|
54
|
+
return ret;
|
|
55
|
+
};
|
|
56
|
+
exports.createPeerDescriptor = createPeerDescriptor;
|
|
57
|
+
//# sourceMappingURL=createPeerDescriptor.js.map
|