@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
|
@@ -0,0 +1,288 @@
|
|
|
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.PeerManager = exports.getDistance = void 0;
|
|
7
|
+
const utils_1 = require("@streamr/utils");
|
|
8
|
+
const k_bucket_1 = __importDefault(require("k-bucket"));
|
|
9
|
+
const RandomContactList_1 = require("./contact/RandomContactList");
|
|
10
|
+
const SortedContactList_1 = require("./contact/SortedContactList");
|
|
11
|
+
const eventemitter3_1 = __importDefault(require("eventemitter3"));
|
|
12
|
+
const identifiers_1 = require("../identifiers");
|
|
13
|
+
const RingContactList_1 = require("./contact/RingContactList");
|
|
14
|
+
const ringIdentifiers_1 = require("./contact/ringIdentifiers");
|
|
15
|
+
const logger = new utils_1.Logger(module);
|
|
16
|
+
const getDistance = (nodeIdOrDataKeyRaw1, nodeIdOrDataKeyRaw2) => {
|
|
17
|
+
return k_bucket_1.default.distance(nodeIdOrDataKeyRaw1, nodeIdOrDataKeyRaw2);
|
|
18
|
+
};
|
|
19
|
+
exports.getDistance = getDistance;
|
|
20
|
+
class PeerManager extends eventemitter3_1.default {
|
|
21
|
+
// Glossary:
|
|
22
|
+
// * 'neighbors' are the nodes that are our neighbors according to
|
|
23
|
+
// the protocol of the layer we are in
|
|
24
|
+
// * 'connections' are the nodes that are connected to this node on Layer0
|
|
25
|
+
// * 'contacts' are all non-unresponsive nodes that we know about
|
|
26
|
+
// The kademlia k-bucket
|
|
27
|
+
bucket;
|
|
28
|
+
// Nodes that are connected to this node on Layer0
|
|
29
|
+
connections = new Map();
|
|
30
|
+
// All nodes that we know about
|
|
31
|
+
contacts;
|
|
32
|
+
randomPeers;
|
|
33
|
+
ringContacts;
|
|
34
|
+
stopped = false;
|
|
35
|
+
config;
|
|
36
|
+
constructor(config) {
|
|
37
|
+
super();
|
|
38
|
+
this.config = config;
|
|
39
|
+
this.bucket = new k_bucket_1.default({
|
|
40
|
+
localNodeId: (0, identifiers_1.getRawFromDhtAddress)(this.config.localNodeId),
|
|
41
|
+
numberOfNodesPerKBucket: this.config.numberOfNodesPerKBucket,
|
|
42
|
+
numberOfNodesToPing: this.config.numberOfNodesPerKBucket
|
|
43
|
+
});
|
|
44
|
+
this.ringContacts = new RingContactList_1.RingContactList((0, ringIdentifiers_1.getRingIdRawFromPeerDescriptor)(this.config.localPeerDescriptor), true);
|
|
45
|
+
this.ringContacts.on('ringContactAdded', (peerDescriptor, closestPeers) => {
|
|
46
|
+
this.emit('ringContactAdded', peerDescriptor, closestPeers);
|
|
47
|
+
});
|
|
48
|
+
this.ringContacts.on('ringContactRemoved', (peerDescriptor, closestPeers) => {
|
|
49
|
+
this.emit('ringContactRemoved', peerDescriptor, closestPeers);
|
|
50
|
+
});
|
|
51
|
+
this.bucket.on('ping', (oldContacts, newContact) => this.onKBucketPing(oldContacts, newContact));
|
|
52
|
+
this.bucket.on('removed', (contact) => this.onKBucketRemoved((0, identifiers_1.getNodeIdFromPeerDescriptor)(contact.getPeerDescriptor())));
|
|
53
|
+
this.bucket.on('added', (contact) => this.onKBucketAdded(contact));
|
|
54
|
+
this.bucket.on('updated', () => {
|
|
55
|
+
// TODO: Update contact info to the connection manager and reconnect
|
|
56
|
+
});
|
|
57
|
+
this.contacts = new SortedContactList_1.SortedContactList({
|
|
58
|
+
referenceId: this.config.localNodeId,
|
|
59
|
+
maxSize: this.config.maxContactListSize,
|
|
60
|
+
allowToContainReferenceId: false,
|
|
61
|
+
emitEvents: true
|
|
62
|
+
});
|
|
63
|
+
this.contacts.on('contactRemoved', (removedContact, activeContacts) => {
|
|
64
|
+
if (this.stopped) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
this.emit('contactRemoved', removedContact.getPeerDescriptor(), activeContacts.map((c) => c.getPeerDescriptor()));
|
|
68
|
+
this.randomPeers.addContact(this.config.createDhtNodeRpcRemote(removedContact.getPeerDescriptor()));
|
|
69
|
+
});
|
|
70
|
+
this.contacts.on('contactAdded', (contactAdded, activeContacts) => this.emit('contactAdded', contactAdded.getPeerDescriptor(), activeContacts.map((c) => c.getPeerDescriptor())));
|
|
71
|
+
this.randomPeers = new RandomContactList_1.RandomContactList(this.config.localNodeId, this.config.maxContactListSize);
|
|
72
|
+
this.randomPeers.on('contactRemoved', (removedContact, activeContacts) => this.emit('randomContactRemoved', removedContact.getPeerDescriptor(), activeContacts.map((c) => c.getPeerDescriptor())));
|
|
73
|
+
this.randomPeers.on('contactAdded', (contactAdded, activeContacts) => this.emit('randomContactAdded', contactAdded.getPeerDescriptor(), activeContacts.map((c) => c.getPeerDescriptor())));
|
|
74
|
+
}
|
|
75
|
+
onKBucketPing(oldContacts, newContact) {
|
|
76
|
+
if (this.stopped) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const sortingList = new SortedContactList_1.SortedContactList({
|
|
80
|
+
referenceId: this.config.localNodeId,
|
|
81
|
+
maxSize: 100, // TODO use config option or named constant?
|
|
82
|
+
allowToContainReferenceId: false,
|
|
83
|
+
emitEvents: false
|
|
84
|
+
});
|
|
85
|
+
sortingList.addContacts(oldContacts);
|
|
86
|
+
const sortedContacts = sortingList.getAllContacts();
|
|
87
|
+
const removableNodeId = sortedContacts[sortedContacts.length - 1].getNodeId();
|
|
88
|
+
this.config.connectionManager?.weakUnlockConnection(removableNodeId, this.config.lockId);
|
|
89
|
+
this.bucket.remove((0, identifiers_1.getRawFromDhtAddress)(removableNodeId));
|
|
90
|
+
this.bucket.add(newContact);
|
|
91
|
+
}
|
|
92
|
+
onKBucketRemoved(nodeId) {
|
|
93
|
+
if (this.stopped) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
this.config.connectionManager?.weakUnlockConnection(nodeId, this.config.lockId);
|
|
97
|
+
logger.trace(`Removed contact ${nodeId}`);
|
|
98
|
+
if (this.bucket.count() === 0) {
|
|
99
|
+
this.emit('kBucketEmpty');
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
onKBucketAdded(contact) {
|
|
103
|
+
if (this.stopped) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
if (contact.getNodeId() !== this.config.localNodeId) {
|
|
107
|
+
const peerDescriptor = contact.getPeerDescriptor();
|
|
108
|
+
const nodeId = (0, identifiers_1.getNodeIdFromPeerDescriptor)(peerDescriptor);
|
|
109
|
+
// Important to lock here, before the ping result is known
|
|
110
|
+
this.config.connectionManager?.weakLockConnection(nodeId, this.config.lockId);
|
|
111
|
+
if (this.connections.has(contact.getNodeId())) {
|
|
112
|
+
logger.trace(`Added new contact ${nodeId}`);
|
|
113
|
+
}
|
|
114
|
+
else { // open connection by pinging
|
|
115
|
+
logger.trace('starting ping ' + nodeId);
|
|
116
|
+
contact.ping().then((result) => {
|
|
117
|
+
if (result) {
|
|
118
|
+
logger.trace(`Added new contact ${nodeId}`);
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
logger.trace('ping failed ' + nodeId);
|
|
122
|
+
this.config.connectionManager?.weakUnlockConnection(nodeId, this.config.lockId);
|
|
123
|
+
this.removeContact(nodeId);
|
|
124
|
+
this.addClosestContactToBucket();
|
|
125
|
+
}
|
|
126
|
+
return;
|
|
127
|
+
}).catch((_e) => {
|
|
128
|
+
this.config.connectionManager?.weakUnlockConnection(nodeId, this.config.lockId);
|
|
129
|
+
this.removeContact(nodeId);
|
|
130
|
+
this.addClosestContactToBucket();
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
addClosestContactToBucket() {
|
|
136
|
+
if (this.stopped) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const closest = this.getClosestActiveContactNotInBucket();
|
|
140
|
+
if (closest) {
|
|
141
|
+
this.addContact([closest.getPeerDescriptor()]);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
getClosestActiveContactNotInBucket() {
|
|
145
|
+
for (const contactId of this.contacts.getContactIds()) {
|
|
146
|
+
if (!this.bucket.get((0, identifiers_1.getRawFromDhtAddress)(contactId)) && this.contacts.isActive(contactId)) {
|
|
147
|
+
return this.contacts.getContact(contactId).contact;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return undefined;
|
|
151
|
+
}
|
|
152
|
+
onContactConnected(peerDescriptor) {
|
|
153
|
+
const nodeId = (0, identifiers_1.getNodeIdFromPeerDescriptor)(peerDescriptor);
|
|
154
|
+
if (nodeId === this.config.localNodeId) {
|
|
155
|
+
logger.error('handleConnected() to self');
|
|
156
|
+
}
|
|
157
|
+
const rpcRemote = this.config.createDhtNodeRpcRemote(peerDescriptor);
|
|
158
|
+
if (!this.connections.has(nodeId)) {
|
|
159
|
+
this.connections.set(nodeId, rpcRemote);
|
|
160
|
+
logger.trace('connectionschange add ' + this.connections.size);
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
logger.trace('new connection not set to connections, there is already a connection with the peer ID');
|
|
164
|
+
}
|
|
165
|
+
logger.trace('connected: ' + nodeId + ' ' + this.connections.size);
|
|
166
|
+
}
|
|
167
|
+
onContactDisconnected(nodeId, gracefulLeave) {
|
|
168
|
+
logger.trace('disconnected: ' + nodeId);
|
|
169
|
+
this.connections.delete(nodeId);
|
|
170
|
+
if (this.config.isLayer0) {
|
|
171
|
+
this.bucket.remove((0, identifiers_1.getRawFromDhtAddress)(nodeId));
|
|
172
|
+
if (gracefulLeave === true) {
|
|
173
|
+
logger.trace(nodeId + ' ' + 'onTransportDisconnected with gracefulLeave ' + gracefulLeave);
|
|
174
|
+
this.removeContact(nodeId);
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
logger.trace(nodeId + ' ' + 'onTransportDisconnected with gracefulLeave ' + gracefulLeave);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
removeContact(nodeId) {
|
|
182
|
+
if (this.stopped) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
logger.trace(`Removing contact ${nodeId}`);
|
|
186
|
+
this.ringContacts.removeContact(this.contacts.getContact(nodeId)?.contact);
|
|
187
|
+
this.bucket.remove((0, identifiers_1.getRawFromDhtAddress)(nodeId));
|
|
188
|
+
this.contacts.removeContact(nodeId);
|
|
189
|
+
this.randomPeers.removeContact(nodeId);
|
|
190
|
+
}
|
|
191
|
+
stop() {
|
|
192
|
+
this.stopped = true;
|
|
193
|
+
this.bucket.toArray().forEach((rpcRemote) => {
|
|
194
|
+
rpcRemote.leaveNotice();
|
|
195
|
+
this.bucket.remove(rpcRemote.id);
|
|
196
|
+
});
|
|
197
|
+
this.bucket.removeAllListeners();
|
|
198
|
+
this.ringContacts.getAllContacts().forEach((rpcRemote) => {
|
|
199
|
+
rpcRemote.leaveNotice();
|
|
200
|
+
this.ringContacts.removeContact(rpcRemote);
|
|
201
|
+
});
|
|
202
|
+
this.contacts.stop();
|
|
203
|
+
this.randomPeers.stop();
|
|
204
|
+
this.connections.clear();
|
|
205
|
+
}
|
|
206
|
+
getClosestNeighborsTo(referenceId, limit, excludedNodeIds) {
|
|
207
|
+
const closest = new SortedContactList_1.SortedContactList({
|
|
208
|
+
referenceId,
|
|
209
|
+
allowToContainReferenceId: true,
|
|
210
|
+
emitEvents: false,
|
|
211
|
+
excludedNodeIds
|
|
212
|
+
});
|
|
213
|
+
this.bucket.toArray().forEach((contact) => closest.addContact(contact));
|
|
214
|
+
return closest.getClosestContacts(limit);
|
|
215
|
+
}
|
|
216
|
+
// TODO reduce copy-paste?
|
|
217
|
+
getClosestContactsTo(referenceId, limit, excludedNodeIds) {
|
|
218
|
+
const closest = new SortedContactList_1.SortedContactList({
|
|
219
|
+
referenceId,
|
|
220
|
+
allowToContainReferenceId: true,
|
|
221
|
+
emitEvents: false,
|
|
222
|
+
excludedNodeIds
|
|
223
|
+
});
|
|
224
|
+
this.contacts.getAllContacts().map((contact) => closest.addContact(contact));
|
|
225
|
+
// TODO should set the excludeSet and limit to SortedContactList constructor and remove these line
|
|
226
|
+
return closest.getClosestContacts(limit);
|
|
227
|
+
}
|
|
228
|
+
getClosestRingContactsTo(ringIdRaw, limit, excludedIds) {
|
|
229
|
+
const closest = new RingContactList_1.RingContactList(ringIdRaw, false, excludedIds);
|
|
230
|
+
this.contacts.getAllContacts().map((contact) => closest.addContact(contact));
|
|
231
|
+
this.ringContacts.getAllContacts().map((contact) => closest.addContact(contact));
|
|
232
|
+
return closest.getClosestContacts(limit ?? 8);
|
|
233
|
+
}
|
|
234
|
+
getContactCount(excludedNodeIds) {
|
|
235
|
+
return this.contacts.getAllContacts().filter((contact) => {
|
|
236
|
+
if (!excludedNodeIds) {
|
|
237
|
+
return true;
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
return !excludedNodeIds.has(contact.getNodeId());
|
|
241
|
+
}
|
|
242
|
+
}).length;
|
|
243
|
+
}
|
|
244
|
+
getConnectionCount() {
|
|
245
|
+
return this.connections.size;
|
|
246
|
+
}
|
|
247
|
+
getNeighborCount() {
|
|
248
|
+
return this.bucket.count();
|
|
249
|
+
}
|
|
250
|
+
getNeighbors() {
|
|
251
|
+
return this.bucket.toArray().map((rpcRemote) => rpcRemote.getPeerDescriptor());
|
|
252
|
+
}
|
|
253
|
+
setContactActive(nodeId) {
|
|
254
|
+
this.contacts.setActive(nodeId);
|
|
255
|
+
}
|
|
256
|
+
addContact(peerDescriptors, setActive) {
|
|
257
|
+
if (this.stopped) {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
peerDescriptors.forEach((contact) => {
|
|
261
|
+
const nodeId = (0, identifiers_1.getNodeIdFromPeerDescriptor)(contact);
|
|
262
|
+
if (nodeId !== this.config.localNodeId) {
|
|
263
|
+
logger.trace(`Adding new contact ${nodeId}`);
|
|
264
|
+
const remote = this.config.createDhtNodeRpcRemote(contact);
|
|
265
|
+
const isInBucket = (this.bucket.get(contact.nodeId) !== null);
|
|
266
|
+
const isInContacts = (this.contacts.getContact(nodeId) !== undefined);
|
|
267
|
+
const isInRingContacts = this.ringContacts.getContact(contact) !== undefined;
|
|
268
|
+
if (isInBucket || isInContacts) {
|
|
269
|
+
this.randomPeers.addContact(remote);
|
|
270
|
+
}
|
|
271
|
+
if (!isInBucket) {
|
|
272
|
+
this.bucket.add(remote);
|
|
273
|
+
}
|
|
274
|
+
if (!isInContacts) {
|
|
275
|
+
this.contacts.addContact(remote);
|
|
276
|
+
}
|
|
277
|
+
if (setActive) {
|
|
278
|
+
this.contacts.setActive(nodeId);
|
|
279
|
+
}
|
|
280
|
+
if (!isInRingContacts) {
|
|
281
|
+
this.ringContacts.addContact(remote);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
exports.PeerManager = PeerManager;
|
|
288
|
+
//# sourceMappingURL=PeerManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PeerManager.js","sourceRoot":"","sources":["../../../src/dht/PeerManager.ts"],"names":[],"mappings":";;;;;;AAAA,0CAEuB;AACvB,wDAA8B;AAK9B,mEAA+D;AAC/D,mEAA+D;AAE/D,kEAAwC;AACxC,gDAA6G;AAC7G,+DAAyE;AACzE,+DAAqF;AAGrF,MAAM,MAAM,GAAG,IAAI,cAAM,CAAC,MAAM,CAAC,CAAA;AAwB1B,MAAM,WAAW,GAAG,CAAC,mBAAkC,EAAE,mBAAkC,EAAU,EAAE;IAC1G,OAAO,kBAAO,CAAC,QAAQ,CAAC,mBAAmB,EAAE,mBAAmB,CAAC,CAAA;AACrE,CAAC,CAAA;AAFY,QAAA,WAAW,eAEvB;AAED,MAAa,WAAY,SAAQ,uBAA+B;IAE5D,aAAa;IACb,mEAAmE;IACnE,wCAAwC;IACxC,0EAA0E;IAC1E,iEAAiE;IAEjE,wBAAwB;IAChB,MAAM,CAA2B;IACzC,kDAAkD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,CAAA;gBACpC,CAAC;gBACD,IAAI,SAAS,EAAE,CAAC;oBACZ,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;gBACnC,CAAC;gBACD,IAAI,CAAC,gBAAgB,EAAE,CAAC;oBACpB,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,MAAM,CAAC,CAAA;gBACxC,CAAC;YACL,CAAC;QACL,CAAC,CAAC,CAAA;IACN,CAAC;CACJ;AArSD,kCAqSC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { PeerID } from '../../helpers/PeerID';
|
|
2
1
|
import { PeerDescriptor } from '../../proto/packages/dht/protos/DhtRpc';
|
|
2
|
+
import { DhtAddress } from '../../identifiers';
|
|
3
3
|
export declare class Contact {
|
|
4
4
|
private peerDescriptor;
|
|
5
5
|
constructor(peerDescriptor: PeerDescriptor);
|
|
6
6
|
getPeerDescriptor(): PeerDescriptor;
|
|
7
|
-
|
|
7
|
+
getNodeId(): DhtAddress;
|
|
8
8
|
}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Contact = void 0;
|
|
4
|
-
const
|
|
4
|
+
const identifiers_1 = require("../../identifiers");
|
|
5
5
|
class Contact {
|
|
6
|
+
peerDescriptor;
|
|
6
7
|
constructor(peerDescriptor) {
|
|
7
8
|
this.peerDescriptor = peerDescriptor;
|
|
8
9
|
}
|
|
9
10
|
getPeerDescriptor() {
|
|
10
11
|
return this.peerDescriptor;
|
|
11
12
|
}
|
|
12
|
-
|
|
13
|
-
return (0,
|
|
13
|
+
getNodeId() {
|
|
14
|
+
return (0, identifiers_1.getNodeIdFromPeerDescriptor)(this.peerDescriptor);
|
|
14
15
|
}
|
|
15
16
|
}
|
|
16
17
|
exports.Contact = Contact;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Contact.js","sourceRoot":"","sources":["../../../../src/dht/contact/Contact.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"Contact.js","sourceRoot":"","sources":["../../../../src/dht/contact/Contact.ts"],"names":[],"mappings":";;;AACA,mDAA2E;AAE3E,MAAa,OAAO;IAER,cAAc,CAAgB;IAEtC,YAAY,cAA8B;QACtC,IAAI,CAAC,cAAc,GAAG,cAAc,CAAA;IACxC,CAAC;IAEM,iBAAiB;QACpB,OAAO,IAAI,CAAC,cAAc,CAAA;IAC9B,CAAC;IAEM,SAAS;QACZ,OAAO,IAAA,yCAA2B,EAAC,IAAI,CAAC,cAAc,CAAC,CAAA;IAC3D,CAAC;CACJ;AAfD,0BAeC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { PeerID, PeerIDKey } from '../../helpers/PeerID';
|
|
2
1
|
import EventEmitter from 'eventemitter3';
|
|
2
|
+
import { DhtAddress } from '../../identifiers';
|
|
3
3
|
export declare class ContactState<C> {
|
|
4
4
|
contacted: boolean;
|
|
5
5
|
active: boolean;
|
|
@@ -8,18 +8,18 @@ export declare class ContactState<C> {
|
|
|
8
8
|
}
|
|
9
9
|
export interface Events<C> {
|
|
10
10
|
contactRemoved: (removedContact: C, closestContacts: C[]) => void;
|
|
11
|
-
|
|
11
|
+
contactAdded: (contactAdded: C, closestContacts: C[]) => void;
|
|
12
12
|
}
|
|
13
13
|
export declare class ContactList<C extends {
|
|
14
|
-
|
|
14
|
+
getNodeId: () => DhtAddress;
|
|
15
15
|
}> extends EventEmitter<Events<C>> {
|
|
16
|
-
protected contactsById: Map<
|
|
17
|
-
protected contactIds:
|
|
18
|
-
protected
|
|
16
|
+
protected contactsById: Map<DhtAddress, ContactState<C>>;
|
|
17
|
+
protected contactIds: DhtAddress[];
|
|
18
|
+
protected localNodeId: DhtAddress;
|
|
19
19
|
protected maxSize: number;
|
|
20
20
|
protected defaultContactQueryLimit: number;
|
|
21
|
-
constructor(
|
|
22
|
-
getContact(id:
|
|
21
|
+
constructor(localNodeId: DhtAddress, maxSize: number, defaultContactQueryLimit?: number);
|
|
22
|
+
getContact(id: DhtAddress): ContactState<C> | undefined;
|
|
23
23
|
getSize(): number;
|
|
24
24
|
clear(): void;
|
|
25
25
|
stop(): void;
|
|
@@ -6,24 +6,29 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.ContactList = exports.ContactState = void 0;
|
|
7
7
|
const eventemitter3_1 = __importDefault(require("eventemitter3"));
|
|
8
8
|
class ContactState {
|
|
9
|
+
contacted = false;
|
|
10
|
+
active = false;
|
|
11
|
+
contact;
|
|
9
12
|
constructor(contact) {
|
|
10
|
-
this.contacted = false;
|
|
11
|
-
this.active = false;
|
|
12
13
|
this.contact = contact;
|
|
13
14
|
}
|
|
14
15
|
}
|
|
15
16
|
exports.ContactState = ContactState;
|
|
16
17
|
class ContactList extends eventemitter3_1.default {
|
|
17
|
-
|
|
18
|
+
contactsById = new Map();
|
|
19
|
+
// TODO move this to SortedContactList
|
|
20
|
+
contactIds = [];
|
|
21
|
+
localNodeId;
|
|
22
|
+
maxSize;
|
|
23
|
+
defaultContactQueryLimit;
|
|
24
|
+
constructor(localNodeId, maxSize, defaultContactQueryLimit = 20) {
|
|
18
25
|
super();
|
|
19
|
-
this.
|
|
20
|
-
this.contactIds = [];
|
|
21
|
-
this.ownId = ownId;
|
|
26
|
+
this.localNodeId = localNodeId;
|
|
22
27
|
this.maxSize = maxSize;
|
|
23
28
|
this.defaultContactQueryLimit = defaultContactQueryLimit;
|
|
24
29
|
}
|
|
25
30
|
getContact(id) {
|
|
26
|
-
return this.contactsById.get(id
|
|
31
|
+
return this.contactsById.get(id);
|
|
27
32
|
}
|
|
28
33
|
getSize() {
|
|
29
34
|
return this.contactIds.length;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContactList.js","sourceRoot":"","sources":["../../../../src/dht/contact/ContactList.ts"],"names":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"ContactList.js","sourceRoot":"","sources":["../../../../src/dht/contact/ContactList.ts"],"names":[],"mappings":";;;;;;AAAA,kEAAwC;AAGxC,MAAa,YAAY;IACd,SAAS,GAAG,KAAK,CAAA;IACjB,MAAM,GAAG,KAAK,CAAA;IACd,OAAO,CAAG;IAEjB,YAAY,OAAU;QAClB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IAC1B,CAAC;CACJ;AARD,oCAQC;AAOD,MAAa,WAAuD,SAAQ,uBAAuB;IAErF,YAAY,GAAqC,IAAI,GAAG,EAAE,CAAA;IACpE,sCAAsC;IAC5B,UAAU,GAAiB,EAAE,CAAA;IAC7B,WAAW,CAAY;IACvB,OAAO,CAAQ;IACf,wBAAwB,CAAA;IAElC,YACI,WAAuB,EACvB,OAAe,EACf,wBAAwB,GAAG,EAAE;QAE7B,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;QAC9B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,wBAAwB,GAAG,wBAAwB,CAAA;IAC5D,CAAC;IAEM,UAAU,CAAC,EAAc;QAC5B,OAAO,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;IACpC,CAAC;IAEM,OAAO;QACV,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAA;IACjC,CAAC;IAEM,KAAK;QACR,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,CAAA;QACzB,IAAI,CAAC,UAAU,GAAG,EAAE,CAAA;IACxB,CAAC;IAEM,IAAI;QACP,IAAI,CAAC,kBAAkB,EAAE,CAAA;QACzB,IAAI,CAAC,KAAK,EAAE,CAAA;IAChB,CAAC;CACJ;AArCD,kCAqCC"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DhtAddress } from '../../identifiers';
|
|
2
2
|
import { ContactList } from './ContactList';
|
|
3
3
|
export declare class RandomContactList<C extends {
|
|
4
|
-
|
|
4
|
+
getNodeId: () => DhtAddress;
|
|
5
5
|
}> extends ContactList<C> {
|
|
6
6
|
private randomness;
|
|
7
|
-
constructor(
|
|
7
|
+
constructor(localNodeId: DhtAddress, maxSize: number, randomness?: number, defaultContactQueryLimit?: number);
|
|
8
8
|
addContact(contact: C): void;
|
|
9
|
-
removeContact(id:
|
|
9
|
+
removeContact(id: DhtAddress): boolean;
|
|
10
10
|
getContacts(limit?: number): C[];
|
|
11
11
|
}
|
|
@@ -3,33 +3,34 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.RandomContactList = void 0;
|
|
4
4
|
const ContactList_1 = require("./ContactList");
|
|
5
5
|
class RandomContactList extends ContactList_1.ContactList {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
randomness;
|
|
7
|
+
constructor(localNodeId, maxSize, randomness = 0.20, defaultContactQueryLimit) {
|
|
8
|
+
super(localNodeId, maxSize, defaultContactQueryLimit);
|
|
8
9
|
this.randomness = randomness;
|
|
9
10
|
}
|
|
10
11
|
addContact(contact) {
|
|
11
|
-
if (this.
|
|
12
|
+
if (this.localNodeId === contact.getNodeId()) {
|
|
12
13
|
return;
|
|
13
14
|
}
|
|
14
|
-
if (!this.contactsById.has(contact.
|
|
15
|
+
if (!this.contactsById.has(contact.getNodeId())) {
|
|
15
16
|
const roll = Math.random();
|
|
16
17
|
if (roll < this.randomness) {
|
|
17
18
|
if (this.getSize() === this.maxSize && this.getSize() > 0) {
|
|
18
19
|
const toRemove = this.contactIds[0];
|
|
19
20
|
this.removeContact(toRemove);
|
|
20
21
|
}
|
|
21
|
-
this.contactIds.push(contact.
|
|
22
|
-
this.contactsById.set(contact.
|
|
23
|
-
this.emit('
|
|
22
|
+
this.contactIds.push(contact.getNodeId());
|
|
23
|
+
this.contactsById.set(contact.getNodeId(), new ContactList_1.ContactState(contact));
|
|
24
|
+
this.emit('contactAdded', contact, this.getContacts());
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
27
|
}
|
|
27
28
|
removeContact(id) {
|
|
28
|
-
if (this.contactsById.has(id
|
|
29
|
-
const removed = this.contactsById.get(id
|
|
30
|
-
const index = this.contactIds.findIndex((
|
|
29
|
+
if (this.contactsById.has(id)) {
|
|
30
|
+
const removed = this.contactsById.get(id).contact;
|
|
31
|
+
const index = this.contactIds.findIndex((nodeId) => (nodeId === id));
|
|
31
32
|
this.contactIds.splice(index, 1);
|
|
32
|
-
this.contactsById.delete(id
|
|
33
|
+
this.contactsById.delete(id);
|
|
33
34
|
this.emit('contactRemoved', removed, this.getContacts());
|
|
34
35
|
return true;
|
|
35
36
|
}
|
|
@@ -38,7 +39,7 @@ class RandomContactList extends ContactList_1.ContactList {
|
|
|
38
39
|
getContacts(limit = this.defaultContactQueryLimit) {
|
|
39
40
|
const ret = [];
|
|
40
41
|
this.contactIds.forEach((contactId) => {
|
|
41
|
-
const contact = this.contactsById.get(contactId
|
|
42
|
+
const contact = this.contactsById.get(contactId);
|
|
42
43
|
if (contact) {
|
|
43
44
|
ret.push(contact.contact);
|
|
44
45
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RandomContactList.js","sourceRoot":"","sources":["../../../../src/dht/contact/RandomContactList.ts"],"names":[],"mappings":";;;AACA,+CAAyD;AAEzD,MAAa,
|
|
1
|
+
{"version":3,"file":"RandomContactList.js","sourceRoot":"","sources":["../../../../src/dht/contact/RandomContactList.ts"],"names":[],"mappings":";;;AACA,+CAAyD;AAEzD,MAAa,iBAA6D,SAAQ,yBAAc;IAEpF,UAAU,CAAQ;IAE1B,YACI,WAAuB,EACvB,OAAe,EACf,UAAU,GAAG,IAAI,EACjB,wBAAiC;QAEjC,KAAK,CAAC,WAAW,EAAE,OAAO,EAAE,wBAAwB,CAAC,CAAA;QACrD,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;IAChC,CAAC;IAED,UAAU,CAAC,OAAU;QACjB,IAAI,IAAI,CAAC,WAAW,KAAK,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC;YA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AC,CAAA;YAC5B,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,OAAO,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC,CAAA;YACxD,OAAO,IAAI,CAAA;QACf,CAAC;QACD,OAAO,KAAK,CAAA;IAChB,CAAC;IAEM,WAAW,CAAC,KAAK,GAAG,IAAI,CAAC,wBAAwB;QACpD,MAAM,GAAG,GAAQ,EAAE,CAAA;QACnB,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE;YAClC,MAAM,OAAO,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;YAChD,IAAI,OAAO,EAAE,CAAC;gBACV,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;YAC7B,CAAC;QACL,CAAC,CAAC,CAAA;QACF,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAA;IAC9B,CAAC;CACJ;AA1DD,8CA0DC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { PeerDescriptor } from '../../proto/packages/dht/protos/DhtRpc';
|
|
2
|
+
import { RingIdRaw } from './ringIdentifiers';
|
|
3
|
+
import { DhtAddress } from '../../identifiers';
|
|
4
|
+
import EventEmitter from 'eventemitter3';
|
|
5
|
+
export interface RingContacts {
|
|
6
|
+
left: PeerDescriptor[];
|
|
7
|
+
right: PeerDescriptor[];
|
|
8
|
+
}
|
|
9
|
+
export interface RingContactListEvents {
|
|
10
|
+
ringContactAdded: (peerDescriptor: PeerDescriptor, closestPeers: RingContacts) => void;
|
|
11
|
+
ringContactRemoved: (peerDescriptor: PeerDescriptor, closestPeers: RingContacts) => void;
|
|
12
|
+
}
|
|
13
|
+
export declare class RingContactList<C extends {
|
|
14
|
+
getPeerDescriptor(): PeerDescriptor;
|
|
15
|
+
}> extends EventEmitter<RingContactListEvents> {
|
|
16
|
+
private readonly numNeighborsPerSide;
|
|
17
|
+
private readonly referenceId;
|
|
18
|
+
private readonly excludedIds;
|
|
19
|
+
private readonly leftNeighbors;
|
|
20
|
+
private readonly rightNeighbors;
|
|
21
|
+
private readonly emitEvents;
|
|
22
|
+
constructor(rawReferenceId: RingIdRaw, emitEvents: boolean, excludedIds?: Set<DhtAddress>);
|
|
23
|
+
addContact(contact: C): void;
|
|
24
|
+
removeContact(contact?: C): void;
|
|
25
|
+
getContact(peerDescriptor: PeerDescriptor): C | undefined;
|
|
26
|
+
getClosestContacts(limitPerSide?: number): {
|
|
27
|
+
left: C[];
|
|
28
|
+
right: C[];
|
|
29
|
+
};
|
|
30
|
+
getAllContacts(): C[];
|
|
31
|
+
}
|