@streamr/dht 0.0.1-tatum.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +5 -0
- package/.eslintrc +3 -0
- package/README.md +38 -0
- package/dist/src/connection/Connection.d.ts +11 -0
- package/dist/src/connection/Connection.js +23 -0
- package/dist/src/connection/Connection.js.map +1 -0
- package/dist/src/connection/ConnectionLockHandler.d.ts +23 -0
- package/dist/src/connection/ConnectionLockHandler.js +94 -0
- package/dist/src/connection/ConnectionLockHandler.js.map +1 -0
- package/dist/src/connection/ConnectionManager.d.ts +94 -0
- package/dist/src/connection/ConnectionManager.js +554 -0
- package/dist/src/connection/ConnectionManager.js.map +1 -0
- package/dist/src/connection/ConnectivityChecker.d.ts +17 -0
- package/dist/src/connection/ConnectivityChecker.js +187 -0
- package/dist/src/connection/ConnectivityChecker.js.map +1 -0
- package/dist/src/connection/Handshaker.d.ts +19 -0
- package/dist/src/connection/Handshaker.js +77 -0
- package/dist/src/connection/Handshaker.js.map +1 -0
- package/dist/src/connection/IConnection.d.ts +38 -0
- package/dist/src/connection/IConnection.js +19 -0
- package/dist/src/connection/IConnection.js.map +1 -0
- package/dist/src/connection/IConnectionSource.d.ts +4 -0
- package/dist/src/connection/IConnectionSource.js +3 -0
- package/dist/src/connection/IConnectionSource.js.map +1 -0
- package/dist/src/connection/ManagedConnection.d.ts +60 -0
- package/dist/src/connection/ManagedConnection.js +352 -0
- package/dist/src/connection/ManagedConnection.js.map +1 -0
- package/dist/src/connection/ManagedWebRtcConnection.d.ts +7 -0
- package/dist/src/connection/ManagedWebRtcConnection.js +20 -0
- package/dist/src/connection/ManagedWebRtcConnection.js.map +1 -0
- package/dist/src/connection/RemoteConnectionLocker.d.ts +14 -0
- package/dist/src/connection/RemoteConnectionLocker.js +93 -0
- package/dist/src/connection/RemoteConnectionLocker.js.map +1 -0
- package/dist/src/connection/Simulator/Simulator.d.ts +42 -0
- package/dist/src/connection/Simulator/Simulator.js +325 -0
- package/dist/src/connection/Simulator/Simulator.js.map +1 -0
- package/dist/src/connection/Simulator/SimulatorConnection.d.ts +19 -0
- package/dist/src/connection/Simulator/SimulatorConnection.js +118 -0
- package/dist/src/connection/Simulator/SimulatorConnection.js.map +1 -0
- package/dist/src/connection/Simulator/SimulatorConnector.d.ts +17 -0
- package/dist/src/connection/Simulator/SimulatorConnector.js +72 -0
- package/dist/src/connection/Simulator/SimulatorConnector.js.map +1 -0
- package/dist/src/connection/Simulator/SimulatorTransport.d.ts +6 -0
- package/dist/src/connection/Simulator/SimulatorTransport.js +11 -0
- package/dist/src/connection/Simulator/SimulatorTransport.js.map +1 -0
- package/dist/src/connection/Simulator/pings.d.ts +21 -0
- package/dist/src/connection/Simulator/pings.js +61 -0
- package/dist/src/connection/Simulator/pings.js.map +1 -0
- package/dist/src/connection/WebRTC/IWebRtcConnection.d.ts +20 -0
- package/dist/src/connection/WebRTC/IWebRtcConnection.js +9 -0
- package/dist/src/connection/WebRTC/IWebRtcConnection.js.map +1 -0
- package/dist/src/connection/WebRTC/NodeWebRtcConnection.d.ts +47 -0
- package/dist/src/connection/WebRTC/NodeWebRtcConnection.js +233 -0
- package/dist/src/connection/WebRTC/NodeWebRtcConnection.js.map +1 -0
- package/dist/src/connection/WebRTC/RemoteWebrtcConnector.d.ts +12 -0
- package/dist/src/connection/WebRTC/RemoteWebrtcConnector.js +74 -0
- package/dist/src/connection/WebRTC/RemoteWebrtcConnector.js.map +1 -0
- package/dist/src/connection/WebRTC/WebRtcConnector.d.ts +47 -0
- package/dist/src/connection/WebRTC/WebRtcConnector.js +227 -0
- package/dist/src/connection/WebRTC/WebRtcConnector.js.map +1 -0
- package/dist/src/connection/WebRTC/iceServerAsString.d.ts +2 -0
- package/dist/src/connection/WebRTC/iceServerAsString.js +18 -0
- package/dist/src/connection/WebRTC/iceServerAsString.js.map +1 -0
- package/dist/src/connection/WebSocket/ClientWebSocket.d.ts +15 -0
- package/dist/src/connection/WebSocket/ClientWebSocket.js +113 -0
- package/dist/src/connection/WebSocket/ClientWebSocket.js.map +1 -0
- package/dist/src/connection/WebSocket/RemoteWebSocketConnector.d.ts +9 -0
- package/dist/src/connection/WebSocket/RemoteWebSocketConnector.js +63 -0
- package/dist/src/connection/WebSocket/RemoteWebSocketConnector.js.map +1 -0
- package/dist/src/connection/WebSocket/ServerWebSocket.d.ts +18 -0
- package/dist/src/connection/WebSocket/ServerWebSocket.js +103 -0
- package/dist/src/connection/WebSocket/ServerWebSocket.js.map +1 -0
- package/dist/src/connection/WebSocket/WebSocketConnector.d.ts +31 -0
- package/dist/src/connection/WebSocket/WebSocketConnector.js +202 -0
- package/dist/src/connection/WebSocket/WebSocketConnector.js.map +1 -0
- package/dist/src/connection/WebSocket/WebSocketServer.d.ts +9 -0
- package/dist/src/connection/WebSocket/WebSocketServer.js +101 -0
- package/dist/src/connection/WebSocket/WebSocketServer.js.map +1 -0
- package/dist/src/dht/DhtNode.d.ts +153 -0
- package/dist/src/dht/DhtNode.js +599 -0
- package/dist/src/dht/DhtNode.js.map +1 -0
- package/dist/src/dht/DhtPeer.d.ts +18 -0
- package/dist/src/dht/DhtPeer.js +74 -0
- package/dist/src/dht/DhtPeer.js.map +1 -0
- package/dist/src/dht/ExternalApi.d.ts +8 -0
- package/dist/src/dht/ExternalApi.js +26 -0
- package/dist/src/dht/ExternalApi.js.map +1 -0
- package/dist/src/dht/RemoteExternalApi.d.ts +6 -0
- package/dist/src/dht/RemoteExternalApi.js +26 -0
- package/dist/src/dht/RemoteExternalApi.js.map +1 -0
- package/dist/src/dht/contact/Contact.d.ts +22 -0
- package/dist/src/dht/contact/Contact.js +25 -0
- package/dist/src/dht/contact/Contact.js.map +1 -0
- package/dist/src/dht/contact/RandomContactList.d.ts +20 -0
- package/dist/src/dht/contact/RandomContactList.js +78 -0
- package/dist/src/dht/contact/RandomContactList.js.map +1 -0
- package/dist/src/dht/contact/Remote.d.ts +15 -0
- package/dist/src/dht/contact/Remote.js +24 -0
- package/dist/src/dht/contact/Remote.js.map +1 -0
- package/dist/src/dht/contact/SortedContactList.d.ts +35 -0
- package/dist/src/dht/contact/SortedContactList.js +156 -0
- package/dist/src/dht/contact/SortedContactList.js.map +1 -0
- package/dist/src/dht/discovery/DiscoverySession.d.ts +36 -0
- package/dist/src/dht/discovery/DiscoverySession.js +116 -0
- package/dist/src/dht/discovery/DiscoverySession.js.map +1 -0
- package/dist/src/dht/discovery/PeerDiscovery.d.ts +42 -0
- package/dist/src/dht/discovery/PeerDiscovery.js +157 -0
- package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -0
- package/dist/src/dht/find/RecursiveFindSession.d.ts +46 -0
- package/dist/src/dht/find/RecursiveFindSession.js +142 -0
- package/dist/src/dht/find/RecursiveFindSession.js.map +1 -0
- package/dist/src/dht/find/RecursiveFinder.d.ts +54 -0
- package/dist/src/dht/find/RecursiveFinder.js +180 -0
- package/dist/src/dht/find/RecursiveFinder.js.map +1 -0
- package/dist/src/dht/find/RemoteRecursiveFindSession.d.ts +6 -0
- package/dist/src/dht/find/RemoteRecursiveFindSession.js +25 -0
- package/dist/src/dht/find/RemoteRecursiveFindSession.js.map +1 -0
- package/dist/src/dht/routing/DuplicateDetector.d.ts +13 -0
- package/dist/src/dht/routing/DuplicateDetector.js +41 -0
- package/dist/src/dht/routing/DuplicateDetector.js.map +1 -0
- package/dist/src/dht/routing/RemoteRouter.d.ts +8 -0
- package/dist/src/dht/routing/RemoteRouter.js +106 -0
- package/dist/src/dht/routing/RemoteRouter.js.map +1 -0
- package/dist/src/dht/routing/Router.d.ts +60 -0
- package/dist/src/dht/routing/Router.js +207 -0
- package/dist/src/dht/routing/Router.js.map +1 -0
- package/dist/src/dht/routing/RoutingSession.d.ts +42 -0
- package/dist/src/dht/routing/RoutingSession.js +178 -0
- package/dist/src/dht/routing/RoutingSession.js.map +1 -0
- package/dist/src/dht/store/DataStore.d.ts +45 -0
- package/dist/src/dht/store/DataStore.js +244 -0
- package/dist/src/dht/store/DataStore.js.map +1 -0
- package/dist/src/dht/store/LocalDataStore.d.ts +19 -0
- package/dist/src/dht/store/LocalDataStore.js +104 -0
- package/dist/src/dht/store/LocalDataStore.js.map +1 -0
- package/dist/src/dht/store/RemoteStore.d.ts +8 -0
- package/dist/src/dht/store/RemoteStore.js +44 -0
- package/dist/src/dht/store/RemoteStore.js.map +1 -0
- package/dist/src/exports.d.ts +19 -0
- package/dist/src/exports.js +41 -0
- package/dist/src/exports.js.map +1 -0
- package/dist/src/helpers/AddressTools.d.ts +2 -0
- package/dist/src/helpers/AddressTools.js +31 -0
- package/dist/src/helpers/AddressTools.js.map +1 -0
- package/dist/src/helpers/PeerID.d.ts +25 -0
- package/dist/src/helpers/PeerID.js +84 -0
- package/dist/src/helpers/PeerID.js.map +1 -0
- package/dist/src/helpers/UUID.d.ts +7 -0
- package/dist/src/helpers/UUID.js +32 -0
- package/dist/src/helpers/UUID.js.map +1 -0
- package/dist/src/helpers/debugHelpers.d.ts +3 -0
- package/dist/src/helpers/debugHelpers.js +11 -0
- package/dist/src/helpers/debugHelpers.js.map +1 -0
- package/dist/src/helpers/errors.d.ts +72 -0
- package/dist/src/helpers/errors.js +95 -0
- package/dist/src/helpers/errors.js.map +1 -0
- package/dist/src/helpers/peerIdFromPeerDescriptor.d.ts +5 -0
- package/dist/src/helpers/peerIdFromPeerDescriptor.js +17 -0
- package/dist/src/helpers/peerIdFromPeerDescriptor.js.map +1 -0
- package/dist/src/helpers/protoClasses.d.ts +2 -0
- package/dist/src/helpers/protoClasses.js +35 -0
- package/dist/src/helpers/protoClasses.js.map +1 -0
- package/dist/src/helpers/protoToString.d.ts +2 -0
- package/dist/src/helpers/protoToString.js +20 -0
- package/dist/src/helpers/protoToString.js.map +1 -0
- package/dist/src/proto/google/protobuf/any.d.ts +173 -0
- package/dist/src/proto/google/protobuf/any.js +155 -0
- package/dist/src/proto/google/protobuf/any.js.map +1 -0
- package/dist/src/proto/google/protobuf/empty.d.ts +32 -0
- package/dist/src/proto/google/protobuf/empty.js +34 -0
- package/dist/src/proto/google/protobuf/empty.js.map +1 -0
- package/dist/src/proto/google/protobuf/timestamp.d.ts +149 -0
- package/dist/src/proto/google/protobuf/timestamp.js +136 -0
- package/dist/src/proto/google/protobuf/timestamp.js.map +1 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +320 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +245 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +1089 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +710 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +145 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.js +3 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.js.map +1 -0
- package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.d.ts +87 -0
- package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.js +66 -0
- package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.js.map +1 -0
- package/dist/src/proto/tests.d.ts +39 -0
- package/dist/src/proto/tests.js +34 -0
- package/dist/src/proto/tests.js.map +1 -0
- package/dist/src/rpc-protocol/DhtCallContext.d.ts +12 -0
- package/dist/src/rpc-protocol/DhtCallContext.js +8 -0
- package/dist/src/rpc-protocol/DhtCallContext.js.map +1 -0
- package/dist/src/rpc-protocol/DhtRpcOptions.d.ts +8 -0
- package/dist/src/rpc-protocol/DhtRpcOptions.js +3 -0
- package/dist/src/rpc-protocol/DhtRpcOptions.js.map +1 -0
- package/dist/src/transport/ITransport.d.ts +22 -0
- package/dist/src/transport/ITransport.js +3 -0
- package/dist/src/transport/ITransport.js.map +1 -0
- package/dist/src/transport/ListeningRpcCommunicator.d.ts +6 -0
- package/dist/src/transport/ListeningRpcCommunicator.js +14 -0
- package/dist/src/transport/ListeningRpcCommunicator.js.map +1 -0
- package/dist/src/transport/RoutingRpcCommunicator.d.ts +8 -0
- package/dist/src/transport/RoutingRpcCommunicator.js +52 -0
- package/dist/src/transport/RoutingRpcCommunicator.js.map +1 -0
- package/jest.config.js +2 -0
- package/karma.config.js +20 -0
- package/package.json +64 -0
- package/proto.sh +3 -0
- package/protos/DhtRpc.proto +330 -0
- package/protos/tests.proto +16 -0
- package/src/connection/Connection.ts +23 -0
- package/src/connection/ConnectionLockHandler.ts +105 -0
- package/src/connection/ConnectionManager.ts +676 -0
- package/src/connection/ConnectivityChecker.ts +173 -0
- package/src/connection/Handshaker.ts +92 -0
- package/src/connection/IConnection.ts +47 -0
- package/src/connection/IConnectionSource.ts +6 -0
- package/src/connection/ManagedConnection.ts +398 -0
- package/src/connection/ManagedWebRtcConnection.ts +27 -0
- package/src/connection/RemoteConnectionLocker.ts +88 -0
- package/src/connection/Simulator/Simulator.ts +399 -0
- package/src/connection/Simulator/SimulatorConnection.ts +137 -0
- package/src/connection/Simulator/SimulatorConnector.ts +104 -0
- package/src/connection/Simulator/SimulatorTransport.ts +9 -0
- package/src/connection/Simulator/pings.ts +42 -0
- package/src/connection/WebRTC/BrowserWebRtcConnection.ts +227 -0
- package/src/connection/WebRTC/IWebRtcConnection.ts +24 -0
- package/src/connection/WebRTC/NodeWebRtcConnection.ts +256 -0
- package/src/connection/WebRTC/RemoteWebrtcConnector.ts +93 -0
- package/src/connection/WebRTC/WebRtcConnector.ts +306 -0
- package/src/connection/WebRTC/iceServerAsString.ts +15 -0
- package/src/connection/WebSocket/ClientWebSocket.ts +118 -0
- package/src/connection/WebSocket/RemoteWebSocketConnector.ts +49 -0
- package/src/connection/WebSocket/ServerWebSocket.ts +119 -0
- package/src/connection/WebSocket/WebSocketConnector.ts +264 -0
- package/src/connection/WebSocket/WebSocketServer.ts +97 -0
- package/src/dht/DhtNode.ts +776 -0
- package/src/dht/DhtPeer.ts +96 -0
- package/src/dht/ExternalApi.ts +29 -0
- package/src/dht/RemoteExternalApi.ts +25 -0
- package/src/dht/contact/Contact.ts +36 -0
- package/src/dht/contact/RandomContactList.ts +92 -0
- package/src/dht/contact/Remote.ts +40 -0
- package/src/dht/contact/SortedContactList.ts +196 -0
- package/src/dht/discovery/DiscoverySession.ts +150 -0
- package/src/dht/discovery/PeerDiscovery.ts +162 -0
- package/src/dht/find/RecursiveFindSession.ts +178 -0
- package/src/dht/find/RecursiveFinder.ts +272 -0
- package/src/dht/find/RemoteRecursiveFindSession.ts +33 -0
- package/src/dht/routing/DuplicateDetector.ts +53 -0
- package/src/dht/routing/RemoteRouter.ts +115 -0
- package/src/dht/routing/Router.ts +266 -0
- package/src/dht/routing/RoutingSession.ts +222 -0
- package/src/dht/store/DataStore.ts +321 -0
- package/src/dht/store/LocalDataStore.ts +114 -0
- package/src/dht/store/RemoteStore.ts +58 -0
- package/src/exports.ts +19 -0
- package/src/helpers/AddressTools.ts +26 -0
- package/src/helpers/PeerID.ts +95 -0
- package/src/helpers/UUID.ts +30 -0
- package/src/helpers/debugHelpers.ts +9 -0
- package/src/helpers/errors.ts +49 -0
- package/src/helpers/peerIdFromPeerDescriptor.ts +14 -0
- package/src/helpers/protoClasses.ts +63 -0
- package/src/helpers/protoToString.ts +21 -0
- package/src/proto/google/protobuf/any.ts +319 -0
- package/src/proto/google/protobuf/empty.ts +84 -0
- package/src/proto/google/protobuf/timestamp.ts +281 -0
- package/src/proto/packages/dht/protos/DhtRpc.client.ts +373 -0
- package/src/proto/packages/dht/protos/DhtRpc.server.ts +148 -0
- package/src/proto/packages/dht/protos/DhtRpc.ts +1399 -0
- package/src/proto/packages/proto-rpc/protos/ProtoRpc.ts +108 -0
- package/src/proto/tests.ts +52 -0
- package/src/rpc-protocol/DhtCallContext.ts +15 -0
- package/src/rpc-protocol/DhtRpcOptions.ts +9 -0
- package/src/transport/ITransport.ts +31 -0
- package/src/transport/ListeningRpcCommunicator.ts +14 -0
- package/src/transport/RoutingRpcCommunicator.ts +59 -0
- package/src/types/glogal.d.ts +1 -0
- package/src/types/textencoding.d.ts +7 -0
- package/test/RandomGraphSimulation.ts +52 -0
- package/test/benchmark/KademliaCorrectness.test.ts +115 -0
- package/test/benchmark/RecursiveFind.test.ts +87 -0
- package/test/benchmark/any.test.ts +28 -0
- package/test/benchmark/kademlia-simulation/Contact.ts +32 -0
- package/test/benchmark/kademlia-simulation/KademliaSimulation.ts +94 -0
- package/test/benchmark/kademlia-simulation/SimulationNode.ts +125 -0
- package/test/data/generateGroundTruthData.ts +70 -0
- package/test/end-to-end/Layer0-Layer1.test.ts +87 -0
- package/test/end-to-end/Layer0.test.ts +60 -0
- package/test/end-to-end/Layer0MixedConnectionTypes.test.ts +94 -0
- package/test/end-to-end/Layer0WebRTC-Layer1.test.ts +134 -0
- package/test/end-to-end/Layer0WebRTC.test.ts +98 -0
- package/test/end-to-end/Layer1-Scale-WebRTC.test.ts +69 -0
- package/test/end-to-end/Layer1-Scale-WebSocket.test.ts +73 -0
- package/test/end-to-end/WebSocketConnectionRequest.test.ts +62 -0
- package/test/integration/ConnectionLocking.test.ts +166 -0
- package/test/integration/ConnectionManager.test.ts +291 -0
- package/test/integration/DhtNodeExternalAPI.test.ts +43 -0
- package/test/integration/DhtPeer.test.ts +73 -0
- package/test/integration/DhtRpc.test.ts +131 -0
- package/test/integration/DhtWithMockConnectionLatencies.test.ts +46 -0
- package/test/integration/DhtWithMockConnections.test.ts +46 -0
- package/test/integration/DhtWithRealConnectionLatencies.test.ts +47 -0
- package/test/integration/Layer1-scale.test.ts +200 -0
- package/test/integration/MigrateData.test.ts +203 -0
- package/test/integration/Mock-Layer1-Layer0.test.ts +106 -0
- package/test/integration/MultipleEntryPointJoining.test.ts +105 -0
- package/test/integration/RecursiveFind.test.ts +50 -0
- package/test/integration/RemoteRouter.test.ts +83 -0
- package/test/integration/RemoteStore.test.ts +66 -0
- package/test/integration/RouteMessage.test.ts +254 -0
- package/test/integration/RpcErrors.test.ts +153 -0
- package/test/integration/ScaleDownDht.test.ts +66 -0
- package/test/integration/SimultaneousConnections.test.ts +308 -0
- package/test/integration/Store.test.ts +72 -0
- package/test/integration/StoreAndDelete.test.ts +93 -0
- package/test/integration/StoreOnDhtWithTwoNodes.test.ts +71 -0
- package/test/integration/WebRtcConnectionManagement.test.ts +205 -0
- package/test/integration/WebRtcConnectorRpc.test.ts +145 -0
- package/test/integration/WebSocket.test.ts +64 -0
- package/test/integration/WebSocketConnectionManagement.test.ts +131 -0
- package/test/integration/WebSocketConnectorRpc.test.ts +86 -0
- package/test/kademlia-simulation/data/nodeids.json +13002 -0
- package/test/kademlia-simulation/data/orderedneighbors.json +1001 -0
- package/test/unit/AddressTools.test.ts +40 -0
- package/test/unit/DuplicateDetector.test.ts +29 -0
- package/test/unit/LocalDataStore.test.ts +107 -0
- package/test/unit/PeerID.test.ts +22 -0
- package/test/unit/ProtobufMessage.test.ts +21 -0
- package/test/unit/RandomContactList.test.ts +87 -0
- package/test/unit/RecursiveFinder.test.ts +112 -0
- package/test/unit/Router.test.ts +124 -0
- package/test/unit/SortedContactList.test.ts +127 -0
- package/test/unit/UUID.test.ts +49 -0
- package/test/unit/WebSocketServer.test.ts +42 -0
- package/test/utils/mock/RecursiveFinder.ts +19 -0
- package/test/utils/mock/Router.ts +53 -0
- package/test/utils/mock/Transport.ts +26 -0
- package/test/utils/utils.ts +311 -0
- package/tsconfig.browser.json +15 -0
- package/tsconfig.jest.json +19 -0
- package/tsconfig.json +3 -0
- package/tsconfig.node.json +18 -0
|
@@ -0,0 +1,554 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.ConnectionManager = exports.NatType = exports.ConnectionManagerConfig = void 0;
|
|
27
|
+
const eventemitter3_1 = require("eventemitter3");
|
|
28
|
+
const DhtRpc_1 = require("../proto/packages/dht/protos/DhtRpc");
|
|
29
|
+
const WebSocketConnector_1 = require("./WebSocket/WebSocketConnector");
|
|
30
|
+
const protoToString_1 = require("../helpers/protoToString");
|
|
31
|
+
const WebRtcConnector_1 = require("./WebRTC/WebRtcConnector");
|
|
32
|
+
const utils_1 = require("@streamr/utils");
|
|
33
|
+
const Err = __importStar(require("../helpers/errors"));
|
|
34
|
+
const NodeWebRtcConnection_1 = require("./WebRTC/NodeWebRtcConnection");
|
|
35
|
+
const RoutingRpcCommunicator_1 = require("../transport/RoutingRpcCommunicator");
|
|
36
|
+
const proto_rpc_1 = require("@streamr/proto-rpc");
|
|
37
|
+
const DhtRpc_client_1 = require("../proto/packages/dht/protos/DhtRpc.client");
|
|
38
|
+
const RemoteConnectionLocker_1 = require("./RemoteConnectionLocker");
|
|
39
|
+
const SimulatorConnector_1 = require("./Simulator/SimulatorConnector");
|
|
40
|
+
const ConnectionLockHandler_1 = require("./ConnectionLockHandler");
|
|
41
|
+
const DuplicateDetector_1 = require("../dht/routing/DuplicateDetector");
|
|
42
|
+
const SortedContactList_1 = require("../dht/contact/SortedContactList");
|
|
43
|
+
const Contact_1 = require("../dht/contact/Contact");
|
|
44
|
+
const peerIdFromPeerDescriptor_1 = require("../helpers/peerIdFromPeerDescriptor");
|
|
45
|
+
class ConnectionManagerConfig {
|
|
46
|
+
constructor(conf) {
|
|
47
|
+
this.maxConnections = 80;
|
|
48
|
+
// assign given non-undefined config vars over defaults
|
|
49
|
+
let k;
|
|
50
|
+
for (k in conf) {
|
|
51
|
+
if (conf[k] === undefined) {
|
|
52
|
+
delete conf[k];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
Object.assign(this, conf);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.ConnectionManagerConfig = ConnectionManagerConfig;
|
|
59
|
+
var NatType;
|
|
60
|
+
(function (NatType) {
|
|
61
|
+
NatType["OPEN_INTERNET"] = "open_internet";
|
|
62
|
+
NatType["UNKNOWN"] = "unknown";
|
|
63
|
+
})(NatType || (exports.NatType = NatType = {}));
|
|
64
|
+
const logger = new utils_1.Logger(module);
|
|
65
|
+
var ConnectionManagerState;
|
|
66
|
+
(function (ConnectionManagerState) {
|
|
67
|
+
ConnectionManagerState["IDLE"] = "idle";
|
|
68
|
+
ConnectionManagerState["RUNNING"] = "running";
|
|
69
|
+
ConnectionManagerState["STOPPING"] = "stopping";
|
|
70
|
+
ConnectionManagerState["STOPPED"] = "stopped";
|
|
71
|
+
})(ConnectionManagerState || (ConnectionManagerState = {}));
|
|
72
|
+
class ConnectionManager extends eventemitter3_1.EventEmitter {
|
|
73
|
+
constructor(conf) {
|
|
74
|
+
super();
|
|
75
|
+
this.messageDuplicateDetector = new DuplicateDetector_1.DuplicateDetector(100000, 100);
|
|
76
|
+
this.locks = new ConnectionLockHandler_1.ConnectionLockHandler();
|
|
77
|
+
this.connections = new Map();
|
|
78
|
+
this.state = ConnectionManagerState.IDLE;
|
|
79
|
+
this.onConnected = (connection) => {
|
|
80
|
+
const peerDescriptor = connection.getPeerDescriptor();
|
|
81
|
+
this.emit('connected', peerDescriptor);
|
|
82
|
+
logger.trace(' ' + this.ownPeerDescriptor?.nodeName + ', ' + peerDescriptor.nodeName + ' onConnected() ' + connection.connectionType);
|
|
83
|
+
this.onConnectionCountChange();
|
|
84
|
+
};
|
|
85
|
+
this.onDisconnected = (connection, disconnectionType) => {
|
|
86
|
+
logger.trace(' ' + this.config.nodeName + ', ' + connection.getPeerDescriptor()?.nodeName +
|
|
87
|
+
' onDisconnected() ' + disconnectionType);
|
|
88
|
+
const hexKey = (0, peerIdFromPeerDescriptor_1.keyFromPeerDescriptor)(connection.getPeerDescriptor());
|
|
89
|
+
const storedConnection = this.connections.get(hexKey);
|
|
90
|
+
if (storedConnection && storedConnection.connectionId.equals(connection.connectionId)) {
|
|
91
|
+
this.locks.clearAllLocks(hexKey);
|
|
92
|
+
this.connections.delete(hexKey);
|
|
93
|
+
logger.trace(' ' + this.config.nodeName + ', ' + connection.getPeerDescriptor()?.nodeName +
|
|
94
|
+
' deleted connection in onDisconnected() ' + disconnectionType);
|
|
95
|
+
this.emit('disconnected', connection.getPeerDescriptor(), disconnectionType);
|
|
96
|
+
this.onConnectionCountChange();
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
logger.trace(' ' + this.config.nodeName + ', ' + connection.getPeerDescriptor()?.nodeName +
|
|
100
|
+
' onDisconnected() did nothing, no such connection in connectionManager');
|
|
101
|
+
if (storedConnection) {
|
|
102
|
+
logger.trace(this.config.nodeName + ', ' + connection.getPeerDescriptor()?.nodeName +
|
|
103
|
+
' connectionIds do not match ' + storedConnection.connectionId + ' ' + connection.connectionId);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
this.config = new ConnectionManagerConfig(conf);
|
|
108
|
+
this.onData = this.onData.bind(this);
|
|
109
|
+
this.incomingConnectionCallback = this.incomingConnectionCallback.bind(this);
|
|
110
|
+
this.metricsContext = this.config.metricsContext || new utils_1.MetricsContext();
|
|
111
|
+
this.metrics = {
|
|
112
|
+
sendMessagesPerSecond: new utils_1.RateMetric(),
|
|
113
|
+
sendBytesPerSecond: new utils_1.RateMetric(),
|
|
114
|
+
receiveMessagesPerSecond: new utils_1.RateMetric(),
|
|
115
|
+
receiveBytesPerSecond: new utils_1.RateMetric(),
|
|
116
|
+
connectionAverageCount: new utils_1.LevelMetric(0),
|
|
117
|
+
connectionTotalFailureCount: new utils_1.CountMetric()
|
|
118
|
+
};
|
|
119
|
+
this.metricsContext.addMetrics('node', this.metrics);
|
|
120
|
+
if (this.config.simulator) {
|
|
121
|
+
logger.trace(`Creating SimulatorConnector`);
|
|
122
|
+
this.simulatorConnector = new SimulatorConnector_1.SimulatorConnector(ConnectionManager.PROTOCOL_VERSION, this.config.ownPeerDescriptor, this.config.simulator, this.incomingConnectionCallback);
|
|
123
|
+
this.config.simulator.addConnector(this.simulatorConnector);
|
|
124
|
+
this.ownPeerDescriptor = this.config.ownPeerDescriptor;
|
|
125
|
+
this.state = ConnectionManagerState.RUNNING;
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
logger.trace(`Creating WebSocketConnector`);
|
|
129
|
+
this.webSocketConnector = new WebSocketConnector_1.WebSocketConnector(ConnectionManager.PROTOCOL_VERSION, this.config.transportLayer, this.canConnect.bind(this), this.incomingConnectionCallback, this.config.webSocketPort, this.config.webSocketHost, this.config.entryPoints);
|
|
130
|
+
logger.trace(`Creating WebRTCConnector`);
|
|
131
|
+
this.webrtcConnector = new WebRtcConnector_1.WebRtcConnector({
|
|
132
|
+
rpcTransport: this.config.transportLayer,
|
|
133
|
+
protocolVersion: ConnectionManager.PROTOCOL_VERSION,
|
|
134
|
+
iceServers: this.config.iceServers,
|
|
135
|
+
allowPrivateAddresses: this.config.webrtcAllowPrivateAddresses,
|
|
136
|
+
bufferThresholdLow: this.config.webrtcDatachannelBufferThresholdLow,
|
|
137
|
+
bufferThresholdHigh: this.config.webrtcDatachannelBufferThresholdHigh,
|
|
138
|
+
connectionTimeout: this.config.webrtcNewConnectionTimeout
|
|
139
|
+
}, this.incomingConnectionCallback);
|
|
140
|
+
}
|
|
141
|
+
this.serviceId = (this.config.serviceIdPrefix ? this.config.serviceIdPrefix : '') + 'ConnectionManager';
|
|
142
|
+
this.send = this.send.bind(this);
|
|
143
|
+
this.rpcCommunicator = new RoutingRpcCommunicator_1.RoutingRpcCommunicator(this.serviceId, this.send, {
|
|
144
|
+
rpcRequestTimeout: 10000
|
|
145
|
+
});
|
|
146
|
+
this.rpcCommunicator.registerRpcMethod(DhtRpc_1.LockRequest, DhtRpc_1.LockResponse, 'lockRequest', (req, context) => this.lockRequest(req, context));
|
|
147
|
+
this.rpcCommunicator.registerRpcNotification(DhtRpc_1.UnlockRequest, 'unlockRequest', (req, context) => this.unlockRequest(req, context));
|
|
148
|
+
this.rpcCommunicator.registerRpcMethod(DhtRpc_1.DisconnectNotice, DhtRpc_1.DisconnectNoticeResponse, 'gracefulDisconnect', (req, context) => this.gracefulDisconnect(req, context));
|
|
149
|
+
}
|
|
150
|
+
garbageCollectConnections(maxConnections, lastUsedLimit) {
|
|
151
|
+
if (this.connections.size <= maxConnections) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
const disconnectionCandidates = new SortedContactList_1.SortedContactList((0, peerIdFromPeerDescriptor_1.peerIdFromPeerDescriptor)(this.ownPeerDescriptor), 100000);
|
|
155
|
+
this.connections.forEach((connection) => {
|
|
156
|
+
if (!this.locks.isLocked(connection.peerIdKey) && Date.now() - connection.getLastUsed() > lastUsedLimit) {
|
|
157
|
+
logger.trace('disconnecting in timeout interval: ' + this.config.nodeName + ', '
|
|
158
|
+
+ connection.getPeerDescriptor()?.nodeName + ' ');
|
|
159
|
+
disconnectionCandidates.addContact(new Contact_1.Contact(connection.getPeerDescriptor()));
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
const sortedCandidates = disconnectionCandidates.getAllContacts();
|
|
163
|
+
const targetNum = this.connections.size - maxConnections;
|
|
164
|
+
for (let i = 0; i < sortedCandidates.length && i < targetNum; i++) {
|
|
165
|
+
logger.trace(this.config.nodeName + ' garbageCollecting '
|
|
166
|
+
+ sortedCandidates[sortedCandidates.length - 1 - i].getPeerDescriptor().nodeName);
|
|
167
|
+
this.gracefullyDisconnectAsync(sortedCandidates[sortedCandidates.length - 1 - i].getPeerDescriptor(), DhtRpc_1.DisconnectMode.NORMAL).catch((_e) => { });
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
async start(peerDescriptorGeneratorCallback) {
|
|
171
|
+
if (this.state === ConnectionManagerState.RUNNING || this.state === ConnectionManagerState.STOPPED) {
|
|
172
|
+
throw new Err.CouldNotStart(`Cannot start already ${this.state} module`);
|
|
173
|
+
}
|
|
174
|
+
this.state = ConnectionManagerState.RUNNING;
|
|
175
|
+
logger.trace(`Starting ConnectionManager...`);
|
|
176
|
+
// Garbage collection of connections
|
|
177
|
+
this.disconnectorIntervalRef = setInterval(() => {
|
|
178
|
+
logger.trace('disconnectorInterval');
|
|
179
|
+
const LAST_USED_LIMIT = 20000;
|
|
180
|
+
this.garbageCollectConnections(this.config.maxConnections, LAST_USED_LIMIT);
|
|
181
|
+
}, 5000);
|
|
182
|
+
if (!this.config.simulator) {
|
|
183
|
+
await this.webSocketConnector.start();
|
|
184
|
+
const connectivityResponse = await this.webSocketConnector.checkConnectivity();
|
|
185
|
+
const ownPeerDescriptor = peerDescriptorGeneratorCallback(connectivityResponse);
|
|
186
|
+
this.ownPeerDescriptor = ownPeerDescriptor;
|
|
187
|
+
this.webSocketConnector.setOwnPeerDescriptor(ownPeerDescriptor);
|
|
188
|
+
this.webrtcConnector.setOwnPeerDescriptor(ownPeerDescriptor);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
async stop() {
|
|
192
|
+
if (this.state === ConnectionManagerState.STOPPED || this.state === ConnectionManagerState.STOPPING) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
this.state = ConnectionManagerState.STOPPING;
|
|
196
|
+
logger.trace(`Stopping ConnectionManager`);
|
|
197
|
+
if (this.disconnectorIntervalRef) {
|
|
198
|
+
clearInterval(this.disconnectorIntervalRef);
|
|
199
|
+
}
|
|
200
|
+
if (!this.config.simulator) {
|
|
201
|
+
await this.webSocketConnector.stop();
|
|
202
|
+
this.webSocketConnector = undefined;
|
|
203
|
+
await this.webrtcConnector.stop();
|
|
204
|
+
this.webrtcConnector = undefined;
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
await this.simulatorConnector.stop();
|
|
208
|
+
this.simulatorConnector = undefined;
|
|
209
|
+
}
|
|
210
|
+
await Promise.all(Array.from(this.connections.values()).map((peer) => {
|
|
211
|
+
return new Promise((resolve, _reject) => {
|
|
212
|
+
if (peer.isHandshakeCompleted()) {
|
|
213
|
+
this.gracefullyDisconnectAsync(peer.getPeerDescriptor(), DhtRpc_1.DisconnectMode.LEAVING)
|
|
214
|
+
.then(() => { resolve(); })
|
|
215
|
+
.catch((e) => {
|
|
216
|
+
logger.error(e);
|
|
217
|
+
resolve();
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
logger.trace('handshake of connection not completed, force-closing');
|
|
222
|
+
(0, utils_1.waitForEvent3)(peer, 'disconnected', 2000)
|
|
223
|
+
.then(() => {
|
|
224
|
+
logger.trace('resolving after receiving disconnected event from non-handshaked connection');
|
|
225
|
+
resolve();
|
|
226
|
+
})
|
|
227
|
+
.catch((e) => {
|
|
228
|
+
logger.trace('force-closing non-handshaked connection timed out ' + e);
|
|
229
|
+
resolve();
|
|
230
|
+
});
|
|
231
|
+
peer.close('OTHER');
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
}));
|
|
235
|
+
this.state = ConnectionManagerState.STOPPED;
|
|
236
|
+
this.rpcCommunicator.stop();
|
|
237
|
+
this.config.transportLayer = undefined;
|
|
238
|
+
this.messageDuplicateDetector.clear();
|
|
239
|
+
this.locks.clear();
|
|
240
|
+
this.removeAllListeners();
|
|
241
|
+
if (!this.config.simulator) {
|
|
242
|
+
NodeWebRtcConnection_1.WEB_RTC_CLEANUP.cleanUp();
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
getConnectionTo(id) {
|
|
246
|
+
return this.connections.get(id);
|
|
247
|
+
}
|
|
248
|
+
getNumberOfLocalLockedConnections() {
|
|
249
|
+
return this.locks.getNumberOfLocalLockedConnections();
|
|
250
|
+
}
|
|
251
|
+
getNumberOfRemoteLockedConnections() {
|
|
252
|
+
return this.locks.getNumberOfRemoteLockedConnections();
|
|
253
|
+
}
|
|
254
|
+
getNumberOfWeakLockedConnections() {
|
|
255
|
+
return this.locks.getNumberOfWeakLockedConnections();
|
|
256
|
+
}
|
|
257
|
+
async send(message, doNotConnect = false, doNotMindStopped = false) {
|
|
258
|
+
if (this.state === ConnectionManagerState.STOPPED && !doNotMindStopped) {
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
const peerDescriptor = message.targetDescriptor;
|
|
262
|
+
if ((0, peerIdFromPeerDescriptor_1.isSamePeerDescriptor)(peerDescriptor, this.ownPeerDescriptor)) {
|
|
263
|
+
throw new Err.CannotConnectToSelf('Cannot send to self');
|
|
264
|
+
}
|
|
265
|
+
logger.trace(`Sending message to: ${peerDescriptor.kademliaId.toString()}`);
|
|
266
|
+
message = {
|
|
267
|
+
...message,
|
|
268
|
+
targetDescriptor: message.targetDescriptor || peerDescriptor,
|
|
269
|
+
sourceDescriptor: message.sourceDescriptor || this.ownPeerDescriptor,
|
|
270
|
+
};
|
|
271
|
+
const hexId = (0, peerIdFromPeerDescriptor_1.keyFromPeerDescriptor)(peerDescriptor);
|
|
272
|
+
let connection = this.connections.get(hexId);
|
|
273
|
+
if (!connection && !doNotConnect) {
|
|
274
|
+
connection = this.createConnection(peerDescriptor);
|
|
275
|
+
this.incomingConnectionCallback(connection);
|
|
276
|
+
}
|
|
277
|
+
else if (!connection) {
|
|
278
|
+
throw new Err.SendFailed('No connection to target, doNotConnect flag is true');
|
|
279
|
+
}
|
|
280
|
+
const binary = DhtRpc_1.Message.toBinary(message);
|
|
281
|
+
this.metrics.sendBytesPerSecond.record(binary.byteLength);
|
|
282
|
+
this.metrics.sendMessagesPerSecond.record(1);
|
|
283
|
+
return connection.send(binary, doNotConnect);
|
|
284
|
+
}
|
|
285
|
+
createConnection(peerDescriptor) {
|
|
286
|
+
if (this.simulatorConnector) {
|
|
287
|
+
return this.simulatorConnector.connect(peerDescriptor);
|
|
288
|
+
}
|
|
289
|
+
else if (peerDescriptor.websocket || this.ownPeerDescriptor.websocket) {
|
|
290
|
+
return this.webSocketConnector.connect(peerDescriptor);
|
|
291
|
+
}
|
|
292
|
+
return this.webrtcConnector.connect(peerDescriptor);
|
|
293
|
+
}
|
|
294
|
+
getConnection(peerDescriptor) {
|
|
295
|
+
const hexId = (0, peerIdFromPeerDescriptor_1.keyFromPeerDescriptor)(peerDescriptor);
|
|
296
|
+
return this.connections.get(hexId);
|
|
297
|
+
}
|
|
298
|
+
getPeerDescriptor() {
|
|
299
|
+
return this.ownPeerDescriptor;
|
|
300
|
+
}
|
|
301
|
+
hasConnection(peerDescriptor) {
|
|
302
|
+
const hexId = (0, peerIdFromPeerDescriptor_1.keyFromPeerDescriptor)(peerDescriptor);
|
|
303
|
+
return this.connections.has(hexId);
|
|
304
|
+
}
|
|
305
|
+
hasLocalLockedConnection(peerDescriptor, _serviceId) {
|
|
306
|
+
const hexId = (0, peerIdFromPeerDescriptor_1.keyFromPeerDescriptor)(peerDescriptor);
|
|
307
|
+
return this.locks.isLocalLocked(hexId);
|
|
308
|
+
}
|
|
309
|
+
hasRemoteLockedConnection(peerDescriptor, _serviceId) {
|
|
310
|
+
const hexId = (0, peerIdFromPeerDescriptor_1.keyFromPeerDescriptor)(peerDescriptor);
|
|
311
|
+
return this.locks.isRemoteLocked(hexId);
|
|
312
|
+
}
|
|
313
|
+
canConnect(peerDescriptor, _ip, _port) {
|
|
314
|
+
// Perhaps the connection's state should be checked here
|
|
315
|
+
return !this.hasConnection(peerDescriptor); // TODO: Add port range check
|
|
316
|
+
}
|
|
317
|
+
handleMessage(message) {
|
|
318
|
+
logger.trace('Received message of type ' + message.messageType);
|
|
319
|
+
if (message.messageType !== DhtRpc_1.MessageType.RPC) {
|
|
320
|
+
logger.trace('Filtered out non-RPC message of type ' + message.messageType);
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
if (this.messageDuplicateDetector.isMostLikelyDuplicate(message.messageId)) {
|
|
324
|
+
logger.trace('handleMessage filtered duplicate ' + this.config.nodeName + ', '
|
|
325
|
+
+ message.sourceDescriptor?.nodeName + ' ' + message.serviceId + ' ' + message.messageId);
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
this.messageDuplicateDetector.add(message.messageId, message.sourceDescriptor.nodeName, message);
|
|
329
|
+
if (message.serviceId === this.serviceId) {
|
|
330
|
+
this.rpcCommunicator?.handleMessageFromPeer(message);
|
|
331
|
+
}
|
|
332
|
+
else {
|
|
333
|
+
logger.trace('emit "message" ' + this.config.nodeName + ', ' + message.sourceDescriptor?.nodeName
|
|
334
|
+
+ ' ' + message.serviceId + ' ' + message.messageId);
|
|
335
|
+
this.emit('message', message);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
onData(data, peerDescriptor) {
|
|
339
|
+
if (this.state === ConnectionManagerState.STOPPED) {
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
this.metrics.receiveBytesPerSecond.record(data.byteLength);
|
|
343
|
+
this.metrics.receiveMessagesPerSecond.record(1);
|
|
344
|
+
let message;
|
|
345
|
+
try {
|
|
346
|
+
message = DhtRpc_1.Message.fromBinary(data);
|
|
347
|
+
logger.trace(`${this.config.nodeName} received protojson: ${(0, protoToString_1.protoToString)(message, DhtRpc_1.Message)}`);
|
|
348
|
+
}
|
|
349
|
+
catch (e) {
|
|
350
|
+
logger.debug(`Parsing incoming data into Message failed: ${e}`);
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
message.sourceDescriptor = peerDescriptor;
|
|
354
|
+
try {
|
|
355
|
+
this.handleMessage(message);
|
|
356
|
+
}
|
|
357
|
+
catch (e) {
|
|
358
|
+
logger.debug(`Handling incoming data failed: ${e}`);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
incomingConnectionCallback(connection) {
|
|
362
|
+
if (this.state === ConnectionManagerState.STOPPED) {
|
|
363
|
+
return false;
|
|
364
|
+
}
|
|
365
|
+
logger.trace('incomingConnectionCallback() objectId ' + connection.objectId);
|
|
366
|
+
connection.offeredAsIncoming = true;
|
|
367
|
+
if (!this.acceptIncomingConnection(connection)) {
|
|
368
|
+
return false;
|
|
369
|
+
}
|
|
370
|
+
connection.on('managedData', this.onData);
|
|
371
|
+
connection.on('disconnected', (disconnectionType, _code, _reason) => {
|
|
372
|
+
this.onDisconnected(connection, disconnectionType);
|
|
373
|
+
});
|
|
374
|
+
this.emit('newConnection', connection);
|
|
375
|
+
if (connection.isHandshakeCompleted()) {
|
|
376
|
+
this.onConnected(connection);
|
|
377
|
+
}
|
|
378
|
+
else {
|
|
379
|
+
connection.once('handshakeCompleted', (_peerDescriptor) => {
|
|
380
|
+
this.onConnected(connection);
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
return true;
|
|
384
|
+
}
|
|
385
|
+
acceptIncomingConnection(newConnection) {
|
|
386
|
+
logger.trace(' ' + this.config.nodeName + ', ' + newConnection.getPeerDescriptor()?.nodeName + ' acceptIncomingConnection()');
|
|
387
|
+
const newPeerID = (0, peerIdFromPeerDescriptor_1.peerIdFromPeerDescriptor)(newConnection.getPeerDescriptor());
|
|
388
|
+
const hexKey = (0, peerIdFromPeerDescriptor_1.keyFromPeerDescriptor)(newConnection.getPeerDescriptor());
|
|
389
|
+
if (this.connections.has(hexKey)) {
|
|
390
|
+
if (newPeerID.hasSmallerHashThan((0, peerIdFromPeerDescriptor_1.peerIdFromPeerDescriptor)(this.ownPeerDescriptor))) {
|
|
391
|
+
logger.trace(' ' + this.config.nodeName + ', ' + newConnection.getPeerDescriptor()?.nodeName +
|
|
392
|
+
' acceptIncomingConnection() replace current connection');
|
|
393
|
+
// replace the current connection
|
|
394
|
+
const oldConnection = this.connections.get(newPeerID.toKey());
|
|
395
|
+
logger.trace('replaced: ' + this.config.nodeName + ', ' + newConnection.getPeerDescriptor()?.nodeName + ' ');
|
|
396
|
+
const buffer = oldConnection.stealOutputBuffer();
|
|
397
|
+
for (const data of buffer) {
|
|
398
|
+
newConnection.sendNoWait(data);
|
|
399
|
+
}
|
|
400
|
+
oldConnection.reportBufferSentByOtherConnection();
|
|
401
|
+
oldConnection.replacedByOtherConnection = true;
|
|
402
|
+
}
|
|
403
|
+
else {
|
|
404
|
+
newConnection.rejectedAsIncoming = true;
|
|
405
|
+
return false;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
logger.trace(' ' + this.ownPeerDescriptor?.nodeName + ', ' + newConnection.getPeerDescriptor()?.nodeName +
|
|
409
|
+
' added to connections at acceptIncomingConnection');
|
|
410
|
+
this.connections.set(hexKey, newConnection);
|
|
411
|
+
return true;
|
|
412
|
+
}
|
|
413
|
+
async closeConnection(peerDescriptor, disconnectionType, reason) {
|
|
414
|
+
logger.trace(' ' + this.ownPeerDescriptor?.nodeName + ', ' + peerDescriptor.nodeName + ' ' + 'closeConnection()');
|
|
415
|
+
const id = (0, peerIdFromPeerDescriptor_1.keyFromPeerDescriptor)(peerDescriptor);
|
|
416
|
+
this.locks.clearAllLocks(id);
|
|
417
|
+
if (this.connections.has(id)) {
|
|
418
|
+
logger.trace(' ' + this.ownPeerDescriptor?.nodeName + ', ' + peerDescriptor.nodeName + ' ' +
|
|
419
|
+
'closeConnection() this.connections had the id');
|
|
420
|
+
logger.trace(`Closeconnection called to Peer ${id}${reason ? `: ${reason}` : ''}`);
|
|
421
|
+
const connectionToClose = this.connections.get(id);
|
|
422
|
+
logger.trace('disconnecting: ' + this.config.nodeName + ', ' + connectionToClose.getPeerDescriptor()?.nodeName);
|
|
423
|
+
logger.trace(' ' + this.ownPeerDescriptor?.nodeName + ', ' + peerDescriptor.nodeName + ' ' +
|
|
424
|
+
'closeConnection() calling connection.close()');
|
|
425
|
+
await connectionToClose.close(disconnectionType);
|
|
426
|
+
logger.trace(' ' + this.ownPeerDescriptor?.nodeName + ', ' + peerDescriptor.nodeName + ' ' +
|
|
427
|
+
'closeConnection() connection.close() called');
|
|
428
|
+
}
|
|
429
|
+
else {
|
|
430
|
+
logger.trace(' ' + this.ownPeerDescriptor?.nodeName + ', ' + peerDescriptor.nodeName + ' ' +
|
|
431
|
+
'closeConnection() this.connections did not have the id');
|
|
432
|
+
this.emit('disconnected', peerDescriptor, 'OTHER');
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
lockConnection(targetDescriptor, serviceId) {
|
|
436
|
+
if (this.state === ConnectionManagerState.STOPPED || (0, peerIdFromPeerDescriptor_1.isSamePeerDescriptor)(targetDescriptor, this.ownPeerDescriptor)) {
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
const hexKey = (0, peerIdFromPeerDescriptor_1.keyFromPeerDescriptor)(targetDescriptor);
|
|
440
|
+
const remoteConnectionLocker = new RemoteConnectionLocker_1.RemoteConnectionLocker(this.ownPeerDescriptor, targetDescriptor, ConnectionManager.PROTOCOL_VERSION, (0, proto_rpc_1.toProtoRpcClient)(new DhtRpc_client_1.ConnectionLockerClient(this.rpcCommunicator.getRpcClientTransport())));
|
|
441
|
+
this.locks.addLocalLocked(hexKey, serviceId);
|
|
442
|
+
remoteConnectionLocker.lockRequest(serviceId)
|
|
443
|
+
.then((_accepted) => logger.trace('LockRequest successful'))
|
|
444
|
+
.catch((err) => { logger.debug(err); });
|
|
445
|
+
}
|
|
446
|
+
unlockConnection(targetDescriptor, serviceId) {
|
|
447
|
+
if (this.state === ConnectionManagerState.STOPPED || (0, peerIdFromPeerDescriptor_1.isSamePeerDescriptor)(targetDescriptor, this.ownPeerDescriptor)) {
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
const hexKey = (0, peerIdFromPeerDescriptor_1.keyFromPeerDescriptor)(targetDescriptor);
|
|
451
|
+
this.locks.removeLocalLocked(hexKey, serviceId);
|
|
452
|
+
const remoteConnectionLocker = new RemoteConnectionLocker_1.RemoteConnectionLocker(this.ownPeerDescriptor, targetDescriptor, ConnectionManager.PROTOCOL_VERSION, (0, proto_rpc_1.toProtoRpcClient)(new DhtRpc_client_1.ConnectionLockerClient(this.rpcCommunicator.getRpcClientTransport())));
|
|
453
|
+
if (this.connections.has(hexKey)) {
|
|
454
|
+
remoteConnectionLocker.unlockRequest(serviceId);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
weakLockConnection(targetDescriptor) {
|
|
458
|
+
if (this.state === ConnectionManagerState.STOPPED || (0, peerIdFromPeerDescriptor_1.isSamePeerDescriptor)(targetDescriptor, this.ownPeerDescriptor)) {
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
const hexKey = (0, peerIdFromPeerDescriptor_1.keyFromPeerDescriptor)(targetDescriptor);
|
|
462
|
+
this.locks.addWeakLocked(hexKey);
|
|
463
|
+
}
|
|
464
|
+
weakUnlockConnection(targetDescriptor) {
|
|
465
|
+
if (this.state === ConnectionManagerState.STOPPED || (0, peerIdFromPeerDescriptor_1.isSamePeerDescriptor)(targetDescriptor, this.ownPeerDescriptor)) {
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
const hexKey = (0, peerIdFromPeerDescriptor_1.keyFromPeerDescriptor)(targetDescriptor);
|
|
469
|
+
this.locks.removeWeakLocked(hexKey);
|
|
470
|
+
}
|
|
471
|
+
async gracefullyDisconnectAsync(targetDescriptor, disconnectMode) {
|
|
472
|
+
const connection = this.connections.get((0, peerIdFromPeerDescriptor_1.peerIdFromPeerDescriptor)(targetDescriptor).toKey());
|
|
473
|
+
if (!connection) {
|
|
474
|
+
logger.debug('gracefullyDisconnectedAsync() tried on a non-existing connection');
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
const promise = new Promise((resolve, _reject) => {
|
|
478
|
+
// eslint-disable-next-line promise/catch-or-return
|
|
479
|
+
(0, utils_1.waitForEvent3)(connection, 'disconnected', 2000).then(() => {
|
|
480
|
+
logger.trace('disconnected event received in gracefullyDisconnectAsync()');
|
|
481
|
+
return;
|
|
482
|
+
})
|
|
483
|
+
.catch((e) => {
|
|
484
|
+
logger.trace('force-closing connection after timeout ' + e);
|
|
485
|
+
connection.close('OTHER');
|
|
486
|
+
})
|
|
487
|
+
.finally(() => {
|
|
488
|
+
logger.trace('resolving after receiving disconnected event');
|
|
489
|
+
resolve();
|
|
490
|
+
});
|
|
491
|
+
});
|
|
492
|
+
this.doGracefullyDisconnectAsync(targetDescriptor, disconnectMode)
|
|
493
|
+
.then(() => { return; })
|
|
494
|
+
.catch((e) => {
|
|
495
|
+
logger.error(e);
|
|
496
|
+
});
|
|
497
|
+
await promise;
|
|
498
|
+
}
|
|
499
|
+
async doGracefullyDisconnectAsync(targetDescriptor, disconnectMode) {
|
|
500
|
+
logger.trace(' ' + this.ownPeerDescriptor?.nodeName + ', ' + targetDescriptor.nodeName + ' gracefullyDisconnectAsync()');
|
|
501
|
+
const remoteConnectionLocker = new RemoteConnectionLocker_1.RemoteConnectionLocker(this.ownPeerDescriptor, targetDescriptor, ConnectionManager.PROTOCOL_VERSION, (0, proto_rpc_1.toProtoRpcClient)(new DhtRpc_client_1.ConnectionLockerClient(this.rpcCommunicator.getRpcClientTransport())));
|
|
502
|
+
try {
|
|
503
|
+
await remoteConnectionLocker.gracefulDisconnect(disconnectMode);
|
|
504
|
+
}
|
|
505
|
+
catch (ex) {
|
|
506
|
+
logger.debug(' ' + this.ownPeerDescriptor?.nodeName + ', ' + targetDescriptor.nodeName +
|
|
507
|
+
' remoteConnectionLocker.gracefulDisconnect() failed' + ex);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
getAllConnectionPeerDescriptors() {
|
|
511
|
+
return Array.from(this.connections.values())
|
|
512
|
+
.filter((managedConnection) => managedConnection.isHandshakeCompleted())
|
|
513
|
+
.map((managedConnection) => managedConnection.getPeerDescriptor());
|
|
514
|
+
}
|
|
515
|
+
// IConnectionLocker server implementation
|
|
516
|
+
async lockRequest(lockRequest, _context) {
|
|
517
|
+
const remotePeerId = (0, peerIdFromPeerDescriptor_1.peerIdFromPeerDescriptor)(lockRequest.peerDescriptor);
|
|
518
|
+
if ((0, peerIdFromPeerDescriptor_1.isSamePeerDescriptor)(lockRequest.peerDescriptor, this.ownPeerDescriptor)) {
|
|
519
|
+
const response = {
|
|
520
|
+
accepted: false
|
|
521
|
+
};
|
|
522
|
+
return response;
|
|
523
|
+
}
|
|
524
|
+
this.locks.addRemoteLocked(remotePeerId.toKey(), lockRequest.serviceId);
|
|
525
|
+
const response = {
|
|
526
|
+
accepted: true
|
|
527
|
+
};
|
|
528
|
+
return response;
|
|
529
|
+
}
|
|
530
|
+
// IConnectionLocker server implementation
|
|
531
|
+
async unlockRequest(unlockRequest, _context) {
|
|
532
|
+
const hexKey = (0, peerIdFromPeerDescriptor_1.keyFromPeerDescriptor)(unlockRequest.peerDescriptor);
|
|
533
|
+
this.locks.removeRemoteLocked(hexKey, unlockRequest.serviceId);
|
|
534
|
+
return {};
|
|
535
|
+
}
|
|
536
|
+
// IConnectionLocker server implementation
|
|
537
|
+
async gracefulDisconnect(disconnectNotice, _context) {
|
|
538
|
+
logger.trace(' ' + this.config.nodeName + ', ' + disconnectNotice.peerDescriptor?.nodeName
|
|
539
|
+
+ ' received gracefulDisconnect notice');
|
|
540
|
+
if (disconnectNotice.disconnecMode === DhtRpc_1.DisconnectMode.LEAVING) {
|
|
541
|
+
this.closeConnection(disconnectNotice.peerDescriptor, 'INCOMING_GRACEFUL_LEAVE', 'graceful leave notified');
|
|
542
|
+
}
|
|
543
|
+
else {
|
|
544
|
+
this.closeConnection(disconnectNotice.peerDescriptor, 'INCOMING_GRACEFUL_DISCONNECT', 'graceful disconnect notified');
|
|
545
|
+
}
|
|
546
|
+
return {};
|
|
547
|
+
}
|
|
548
|
+
onConnectionCountChange() {
|
|
549
|
+
this.metrics.connectionAverageCount.record(this.connections.size);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
exports.ConnectionManager = ConnectionManager;
|
|
553
|
+
ConnectionManager.PROTOCOL_VERSION = '1.0';
|
|
554
|
+
//# sourceMappingURL=ConnectionManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConnectionManager.js","sourceRoot":"","sources":["../../../src/connection/ConnectionManager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA4C;AAC5C,gEAW4C;AAC5C,uEAAmE;AAEnE,4DAAwD;AAExD,8DAAqE;AACrE,0CAAuI;AACvI,uDAAwC;AACxC,wEAA+D;AAE/D,gFAA4E;AAC5E,kDAAqD;AACrD,8EAAmF;AACnF,qEAAiE;AAIjE,uEAAmE;AACnE,mEAA+D;AAC/D,wEAAoE;AACpE,wEAAoE;AACpE,oDAAgD;AAChD,kFAI4C;AAE5C,MAAa,uBAAuB;IAmBhC,YAAY,IAAsC;QAblD,mBAAc,GAAW,EAAE,CAAA;QAcvB,uDAAuD;QACvD,IAAI,CAAoB,CAAA;QACxB,KAAK,CAAC,IAAI,IAAI,EAAE;YACZ,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,SAAS,EAAE;gBACvB,OAAO,IAAI,CAAC,CAAC,CAAC,CAAA;aACjB;SACJ;QACD,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;IAC7B,CAAC;CACJ;AA7BD,0DA6BC;AAED,IAAY,OAGX;AAHD,WAAY,OAAO;IACf,0CAA+B,CAAA;IAC/B,8BAAmB,CAAA;AACvB,CAAC,EAHW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AAA;IACb,CAAC;IAEO,uBAAuB;QAC3B,IAAI,CAAC,OAAO,CAAC,sBAAsB,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;IACrE,CAAC;;AAnjBL,8CAojBC;AAnjBiB,kCAAgB,GAAG,KAAK,AAAR,CAAQ"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ConnectivityResponse, PeerDescriptor } from '../proto/packages/dht/protos/DhtRpc';
|
|
2
|
+
import { ServerWebSocket } from './WebSocket/ServerWebSocket';
|
|
3
|
+
export declare enum ConnectionMode {
|
|
4
|
+
REQUEST = "connectivityRequest",
|
|
5
|
+
PROBE = "connectivityProbe"
|
|
6
|
+
}
|
|
7
|
+
export declare class ConnectivityChecker {
|
|
8
|
+
private static readonly CONNECTIVITY_CHECKER_SERVICE_ID;
|
|
9
|
+
private static readonly CONNECTIVITY_CHECKER_TIMEOUT;
|
|
10
|
+
private stopped;
|
|
11
|
+
private webSocketPort?;
|
|
12
|
+
constructor(webSocketPort?: number);
|
|
13
|
+
sendConnectivityRequest(entryPoint: PeerDescriptor): Promise<ConnectivityResponse>;
|
|
14
|
+
listenToIncomingConnectivityRequests(connectionToListenTo: ServerWebSocket): void;
|
|
15
|
+
private handleIncomingConnectivityRequest;
|
|
16
|
+
private connectAsync;
|
|
17
|
+
}
|