@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,325 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.Simulator = exports.LatencyType = void 0;
|
|
30
|
+
/* eslint-disable @typescript-eslint/parameter-properties */
|
|
31
|
+
const eventemitter3_1 = __importDefault(require("eventemitter3"));
|
|
32
|
+
const utils_1 = require("@streamr/utils");
|
|
33
|
+
const pings_1 = require("./pings");
|
|
34
|
+
const peerIdFromPeerDescriptor_1 = require("../../helpers/peerIdFromPeerDescriptor");
|
|
35
|
+
const heap_1 = __importDefault(require("heap"));
|
|
36
|
+
const debugHelpers_1 = require("../../helpers/debugHelpers");
|
|
37
|
+
const sinon = __importStar(require("sinon"));
|
|
38
|
+
const logger = new utils_1.Logger(module);
|
|
39
|
+
var LatencyType;
|
|
40
|
+
(function (LatencyType) {
|
|
41
|
+
LatencyType["NONE"] = "NONE";
|
|
42
|
+
LatencyType["RANDOM"] = "RANDOM";
|
|
43
|
+
LatencyType["REAL"] = "REAL";
|
|
44
|
+
LatencyType["FIXED"] = "FIXED";
|
|
45
|
+
})(LatencyType || (exports.LatencyType = LatencyType = {}));
|
|
46
|
+
// One-way 'pipe' of messages
|
|
47
|
+
class Association {
|
|
48
|
+
constructor(sourceConnection, destinationConnection, connectedCallback) {
|
|
49
|
+
this.connectedCallback = connectedCallback;
|
|
50
|
+
this.lastOperationAt = 0;
|
|
51
|
+
this.closing = false;
|
|
52
|
+
this.sourceConnection = sourceConnection;
|
|
53
|
+
this.destinationConnection = destinationConnection;
|
|
54
|
+
}
|
|
55
|
+
setDestinationConnection(connection) {
|
|
56
|
+
this.destinationConnection = connection;
|
|
57
|
+
}
|
|
58
|
+
getLastOperationAt() {
|
|
59
|
+
return this.lastOperationAt;
|
|
60
|
+
}
|
|
61
|
+
setLastOperationAt(executionTime) {
|
|
62
|
+
this.lastOperationAt = executionTime;
|
|
63
|
+
}
|
|
64
|
+
setClosing() {
|
|
65
|
+
this.closing = true;
|
|
66
|
+
}
|
|
67
|
+
isClosing() {
|
|
68
|
+
return this.closing;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
class SimulatorOperation {
|
|
72
|
+
constructor(executionTime, association) {
|
|
73
|
+
this.executionTime = executionTime;
|
|
74
|
+
this.association = association;
|
|
75
|
+
this.objectId = 0;
|
|
76
|
+
this.objectId = SimulatorOperation.objectCounter;
|
|
77
|
+
SimulatorOperation.objectCounter++;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
SimulatorOperation.objectCounter = 0;
|
|
81
|
+
class ConnectOperation extends SimulatorOperation {
|
|
82
|
+
constructor(executionTime, association, sourceConnection, targetDescriptor) {
|
|
83
|
+
super(executionTime, association);
|
|
84
|
+
this.sourceConnection = sourceConnection;
|
|
85
|
+
this.targetDescriptor = targetDescriptor;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
class SendOperation extends SimulatorOperation {
|
|
89
|
+
constructor(executionTime, association, data) {
|
|
90
|
+
super(executionTime, association);
|
|
91
|
+
this.data = data;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
class CloseOperation extends SimulatorOperation {
|
|
95
|
+
}
|
|
96
|
+
class Simulator extends eventemitter3_1.default {
|
|
97
|
+
static useFakeTimers(on = true) {
|
|
98
|
+
if (on) {
|
|
99
|
+
if (!Simulator.clock) {
|
|
100
|
+
Simulator.clock = sinon.useFakeTimers();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
if (Simulator.clock) {
|
|
105
|
+
Simulator.clock.restore();
|
|
106
|
+
Simulator.clock = undefined;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
constructor(latencyType = LatencyType.NONE, fixedLatency) {
|
|
111
|
+
super();
|
|
112
|
+
this.stopped = false;
|
|
113
|
+
this.connectors = new Map();
|
|
114
|
+
this.associations = new Map();
|
|
115
|
+
this.loopCounter = 0;
|
|
116
|
+
this.operationCounter = 0;
|
|
117
|
+
this.MAX_LOOPS = 1000;
|
|
118
|
+
this.operationQueue = new heap_1.default((a, b) => {
|
|
119
|
+
if ((a.executionTime - b.executionTime) === 0) {
|
|
120
|
+
return (a.objectId - b.objectId);
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
return (a.executionTime - b.executionTime);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
this.latencyType = latencyType;
|
|
127
|
+
this.fixedLatency = fixedLatency;
|
|
128
|
+
if (this.latencyType === LatencyType.REAL) {
|
|
129
|
+
this.latencyTable = (0, pings_1.getRegionDelayMatrix)();
|
|
130
|
+
}
|
|
131
|
+
if (this.latencyType === LatencyType.FIXED && !this.fixedLatency) {
|
|
132
|
+
throw new Error('LatencyType.FIXED requires the desired latency to be given as second parameter');
|
|
133
|
+
}
|
|
134
|
+
this.generateExecutionTime = this.generateExecutionTime.bind(this);
|
|
135
|
+
this.getLatency = this.getLatency.bind(this);
|
|
136
|
+
this.executeCloseOperation = this.executeCloseOperation.bind(this);
|
|
137
|
+
this.executeConnectOperation = this.executeConnectOperation.bind(this);
|
|
138
|
+
this.executeSendOperation = this.executeSendOperation.bind(this);
|
|
139
|
+
this.executeQueuedOperations = this.executeQueuedOperations.bind(this);
|
|
140
|
+
this.accept = this.accept.bind(this);
|
|
141
|
+
this.send = this.send.bind(this);
|
|
142
|
+
this.close = this.close.bind(this);
|
|
143
|
+
this.scheduleNextTimeout = this.scheduleNextTimeout.bind(this);
|
|
144
|
+
this.scheduleOperation = this.scheduleOperation.bind(this);
|
|
145
|
+
}
|
|
146
|
+
generateExecutionTime(association, sourceRegion, targetRegion) {
|
|
147
|
+
let executionTime = Date.now() + this.getLatency(sourceRegion, targetRegion);
|
|
148
|
+
if (association.getLastOperationAt() > executionTime) {
|
|
149
|
+
executionTime = association.getLastOperationAt();
|
|
150
|
+
}
|
|
151
|
+
return executionTime;
|
|
152
|
+
}
|
|
153
|
+
getLatency(sourceRegion, targetRegion) {
|
|
154
|
+
let latency = 0;
|
|
155
|
+
if (this.latencyType === LatencyType.FIXED) {
|
|
156
|
+
latency = this.fixedLatency;
|
|
157
|
+
}
|
|
158
|
+
if (this.latencyType === LatencyType.REAL) {
|
|
159
|
+
if (sourceRegion === undefined || targetRegion === undefined || sourceRegion > 15 || targetRegion > 15) {
|
|
160
|
+
logger.error('invalid region index given to Simulator');
|
|
161
|
+
throw ('invalid region index given to Simulator');
|
|
162
|
+
}
|
|
163
|
+
latency = this.latencyTable[sourceRegion][targetRegion];
|
|
164
|
+
}
|
|
165
|
+
if (this.latencyType === LatencyType.RANDOM) {
|
|
166
|
+
latency = Math.random() * (250 - 5) + 5;
|
|
167
|
+
}
|
|
168
|
+
return latency;
|
|
169
|
+
}
|
|
170
|
+
accept(sourceConnection, targetConnection) {
|
|
171
|
+
const sourceAssociation = this.associations.get(sourceConnection.connectionId);
|
|
172
|
+
if (!sourceAssociation) {
|
|
173
|
+
logger.error('source association not found in accept()');
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
sourceAssociation.setDestinationConnection(targetConnection);
|
|
177
|
+
const targetAssociation = new Association(targetConnection, sourceConnection);
|
|
178
|
+
this.associations.set(targetConnection.connectionId, targetAssociation);
|
|
179
|
+
sourceAssociation.connectedCallback();
|
|
180
|
+
}
|
|
181
|
+
addConnector(connector) {
|
|
182
|
+
this.connectors.set((0, peerIdFromPeerDescriptor_1.keyFromPeerDescriptor)(connector.getPeerDescriptor()), connector);
|
|
183
|
+
}
|
|
184
|
+
executeConnectOperation(operation) {
|
|
185
|
+
const target = this.connectors.get((0, peerIdFromPeerDescriptor_1.keyFromPeerDescriptor)(operation.targetDescriptor));
|
|
186
|
+
if (!target) {
|
|
187
|
+
logger.error('Target connector not found when executing connect operation');
|
|
188
|
+
return operation.association.connectedCallback('Target connector not found');
|
|
189
|
+
}
|
|
190
|
+
target.handleIncomingConnection(operation.sourceConnection);
|
|
191
|
+
}
|
|
192
|
+
executeCloseOperation(operation) {
|
|
193
|
+
if (this.stopped) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
const target = operation.association.destinationConnection;
|
|
197
|
+
let counterAssociation;
|
|
198
|
+
if (target) {
|
|
199
|
+
counterAssociation = this.associations.get(target.connectionId);
|
|
200
|
+
}
|
|
201
|
+
if (!target || !counterAssociation) {
|
|
202
|
+
this.associations.delete(operation.association.sourceConnection.connectionId);
|
|
203
|
+
}
|
|
204
|
+
else if (!counterAssociation.isClosing()) {
|
|
205
|
+
target.handleIncomingDisconnection();
|
|
206
|
+
this.close(target);
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
// this is the 'ack' of the CloseOperation to the original closer
|
|
210
|
+
this.associations.delete(target.connectionId);
|
|
211
|
+
this.associations.delete(operation.association.sourceConnection.connectionId);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
executeSendOperation(operation) {
|
|
215
|
+
if (this.stopped) {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
const target = operation.association.destinationConnection;
|
|
219
|
+
target.handleIncomingData(operation.data);
|
|
220
|
+
}
|
|
221
|
+
executeQueuedOperations() {
|
|
222
|
+
const currentTime = Date.now();
|
|
223
|
+
while (this.operationQueue.size() > 0
|
|
224
|
+
&& this.operationQueue.peek().executionTime <= currentTime) {
|
|
225
|
+
const operation = this.operationQueue.pop();
|
|
226
|
+
this.operationCounter++;
|
|
227
|
+
if (operation instanceof ConnectOperation) {
|
|
228
|
+
this.executeConnectOperation(operation);
|
|
229
|
+
}
|
|
230
|
+
else if (operation instanceof CloseOperation) {
|
|
231
|
+
this.executeCloseOperation(operation);
|
|
232
|
+
}
|
|
233
|
+
else if (operation instanceof SendOperation) {
|
|
234
|
+
this.executeSendOperation(operation);
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
logger.error('Unknown SimulatorOperation');
|
|
238
|
+
}
|
|
239
|
+
this.loopCounter++;
|
|
240
|
+
if (this.loopCounter >= this.MAX_LOOPS) {
|
|
241
|
+
this.loopCounter = 0;
|
|
242
|
+
setTimeout(() => this.executeQueuedOperations(), 0);
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
this.scheduleNextTimeout();
|
|
247
|
+
}
|
|
248
|
+
getOperationCounter() {
|
|
249
|
+
return this.operationCounter;
|
|
250
|
+
}
|
|
251
|
+
scheduleNextTimeout() {
|
|
252
|
+
if (this.simulatorTimeout) {
|
|
253
|
+
clearTimeout(this.simulatorTimeout);
|
|
254
|
+
this.simulatorTimeout = undefined;
|
|
255
|
+
}
|
|
256
|
+
const currentTime = Date.now();
|
|
257
|
+
const firstOperation = this.operationQueue.peek();
|
|
258
|
+
if (!firstOperation) {
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
const firstOperationTime = firstOperation.executionTime;
|
|
262
|
+
const timeDifference = firstOperationTime - currentTime;
|
|
263
|
+
this.simulatorTimeout = setTimeout(this.executeQueuedOperations, timeDifference);
|
|
264
|
+
if (Simulator.clock) {
|
|
265
|
+
Simulator.clock.runAllAsync();
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
scheduleOperation(operation) {
|
|
269
|
+
this.operationQueue.push(operation);
|
|
270
|
+
this.scheduleNextTimeout();
|
|
271
|
+
}
|
|
272
|
+
connect(sourceConnection, targetDescriptor, connectedCallback) {
|
|
273
|
+
if (this.stopped) {
|
|
274
|
+
logger.error('connect() called on a stopped simulator ' + (new Error().stack));
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
debugHelpers_1.debugVars['simulatorHeapSize'] = this.operationQueue.size();
|
|
278
|
+
const association = new Association(sourceConnection, undefined, connectedCallback);
|
|
279
|
+
this.associations.set(sourceConnection.connectionId, association);
|
|
280
|
+
const executionTime = this.generateExecutionTime(association, sourceConnection.ownPeerDescriptor.region, targetDescriptor.region);
|
|
281
|
+
association.setLastOperationAt(executionTime);
|
|
282
|
+
const operation = new ConnectOperation(executionTime, association, sourceConnection, targetDescriptor);
|
|
283
|
+
this.scheduleOperation(operation);
|
|
284
|
+
}
|
|
285
|
+
close(sourceConnection) {
|
|
286
|
+
if (this.stopped) {
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
const association = this.associations.get(sourceConnection.connectionId);
|
|
290
|
+
if (!association) {
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
association.setClosing();
|
|
294
|
+
const executionTime = this.generateExecutionTime(association, sourceConnection.ownPeerDescriptor.region, sourceConnection.getPeerDescriptor()?.region);
|
|
295
|
+
association.setLastOperationAt(executionTime);
|
|
296
|
+
const operation = new CloseOperation(executionTime, association);
|
|
297
|
+
this.scheduleOperation(operation);
|
|
298
|
+
}
|
|
299
|
+
send(sourceConnection, data) {
|
|
300
|
+
if (this.stopped) {
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
const association = this.associations.get(sourceConnection.connectionId);
|
|
304
|
+
if (!association) {
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
if (association.isClosing()) {
|
|
308
|
+
logger.trace('Tried to call send() on a closing association');
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
const executionTime = this.generateExecutionTime(association, sourceConnection.ownPeerDescriptor.region, association.destinationConnection.ownPeerDescriptor.region);
|
|
312
|
+
association.setLastOperationAt(executionTime);
|
|
313
|
+
const operation = new SendOperation(executionTime, association, data);
|
|
314
|
+
this.scheduleOperation(operation);
|
|
315
|
+
}
|
|
316
|
+
stop() {
|
|
317
|
+
this.stopped = true;
|
|
318
|
+
logger.info(this.associations.size + ' associations in the beginning of stop()');
|
|
319
|
+
if (this.simulatorTimeout) {
|
|
320
|
+
clearTimeout(this.simulatorTimeout);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
exports.Simulator = Simulator;
|
|
325
|
+
//# sourceMappingURL=Simulator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Simulator.js","sourceRoot":"","sources":["../../../../src/connection/Simulator/Simulator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4DAA4D;AAC5D,kEAAwC;AAOxC,0CAAuC;AACvC,mCAA8C;AAC9C,qFAA8E;AAC9E,gDAAuB;AACvB,6DAAsD;AACtD,6CAA8B;AAE9B,MAAM,MAAM,GAAG,IAAI,cAAM,CAAC,MAAM,CAAC,CAAA;AAEjC,IAAY,WAAgF;AAA5F,WAAY,WAAW;IAAG,4BAAa,CAAA;IAAE,gCAAiB,CAAA;IAAE,4BAAa,CAAA;IAAE,8BAAe,CAAA;AAAC,CAAC,EAAhF,WAAW,2BAAX,WAAW,QAAqE;AAE5F,6BAA6B;AAE7B,MAAM,WAAW;IAMb,YAAY,gBAAqC,EAC7C,qBAA2C,EACpC,iBAA4C;QAA5C,sBAAiB,GAAjB,iBAAiB,CAA2B;QAL/C,oBAAe,GAAW,CAAC,CAAA;QAC3B,YAAO,GAAG,KAAK,CAAA;QAMnB,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAA;QACxC,IA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,IAAI,CAAC,gBAAqC,EAAE,IAAgB;QAE/D,IAAI,IAAI,CAAC,OAAO,EAAE;YACd,OAAM;SACT;QAED,MAAM,WAAW,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,gBAAgB,CAAC,YAAY,CAAC,CAAA;QACxE,IAAI,CAAC,WAAW,EAAE;YACd,OAAM;SACT;QAED,IAAI,WAAW,CAAC,SAAS,EAAE,EAAE;YACzB,MAAM,CAAC,KAAK,CAAC,+CAA+C,CAAC,CAAA;YAC7D,OAAM;SACT;QAED,MAAM,aAAa,GAAG,IAAI,CAAC,qBAAqB,CAAC,WAAW,EACxD,gBAAgB,CAAC,iBAAiB,CAAC,MAAM,EACzC,WAAW,CAAC,qBAAsB,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAA;QAEhE,WAAW,CAAC,kBAAkB,CAAC,aAAa,CAAC,CAAA;QAE7C,MAAM,SAAS,GAAG,IAAI,aAAa,CAAC,aAAa,EAAE,WAAW,EAAE,IAAI,CAAC,CAAA;QAErE,IAAI,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAA;IACrC,CAAC;IAEM,IAAI;QACP,IAAI,CAAC,OAAO,GAAG,IAAI,CAAA;QACnB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,GAAG,0CAA0C,CAAC,CAAA;QAEhF,IAAI,IAAI,CAAC,gBAAgB,EAAE;YACvB,YAAY,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAA;SACtC;IACL,CAAC;CACJ;AAjTD,8BAiTC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ConnectionType, IConnection } from '../IConnection';
|
|
2
|
+
import { Simulator } from './Simulator';
|
|
3
|
+
import { PeerDescriptor } from '../../proto/packages/dht/protos/DhtRpc';
|
|
4
|
+
import { Connection } from '../Connection';
|
|
5
|
+
import { DisconnectionType } from '../../transport/ITransport';
|
|
6
|
+
export declare class SimulatorConnection extends Connection implements IConnection {
|
|
7
|
+
private stopped;
|
|
8
|
+
ownPeerDescriptor: PeerDescriptor;
|
|
9
|
+
private targetPeerDescriptor;
|
|
10
|
+
private simulator;
|
|
11
|
+
constructor(ownPeerDescriptor: PeerDescriptor, targetPeerDescriptor: PeerDescriptor, connectionType: ConnectionType, simulator: Simulator);
|
|
12
|
+
send(data: Uint8Array): void;
|
|
13
|
+
close(disconnectionType: DisconnectionType): Promise<void>;
|
|
14
|
+
connect(): void;
|
|
15
|
+
handleIncomingData(data: Uint8Array): void;
|
|
16
|
+
handleIncomingDisconnection(): void;
|
|
17
|
+
destroy(): void;
|
|
18
|
+
private doDisconnect;
|
|
19
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SimulatorConnection = void 0;
|
|
4
|
+
const DhtRpc_1 = require("../../proto/packages/dht/protos/DhtRpc");
|
|
5
|
+
const Connection_1 = require("../Connection");
|
|
6
|
+
const utils_1 = require("@streamr/utils");
|
|
7
|
+
const protoToString_1 = require("../../helpers/protoToString");
|
|
8
|
+
const logger = new utils_1.Logger(module);
|
|
9
|
+
class SimulatorConnection extends Connection_1.Connection {
|
|
10
|
+
constructor(ownPeerDescriptor, targetPeerDescriptor, connectionType, simulator) {
|
|
11
|
+
super(connectionType);
|
|
12
|
+
this.stopped = false;
|
|
13
|
+
this.ownPeerDescriptor = ownPeerDescriptor;
|
|
14
|
+
this.setPeerDescriptor(targetPeerDescriptor);
|
|
15
|
+
this.targetPeerDescriptor = targetPeerDescriptor;
|
|
16
|
+
this.connectionType = connectionType;
|
|
17
|
+
this.simulator = simulator;
|
|
18
|
+
this.send = this.send.bind(this);
|
|
19
|
+
this.close = this.close.bind(this);
|
|
20
|
+
this.connect = this.connect.bind(this);
|
|
21
|
+
this.handleIncomingData = this.handleIncomingData.bind(this);
|
|
22
|
+
this.handleIncomingDisconnection = this.handleIncomingDisconnection.bind(this);
|
|
23
|
+
this.destroy = this.destroy.bind(this);
|
|
24
|
+
this.doDisconnect = this.doDisconnect.bind(this);
|
|
25
|
+
}
|
|
26
|
+
send(data) {
|
|
27
|
+
logger.trace('send()');
|
|
28
|
+
if (!this.stopped) {
|
|
29
|
+
this.simulator.send(this, data);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
logger.error(' ' + this.ownPeerDescriptor.nodeName + ', ' + (this.targetPeerDescriptor.nodeName) +
|
|
33
|
+
'tried to send() on a stopped connection');
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async close(disconnectionType) {
|
|
37
|
+
logger.trace(' ' + this.ownPeerDescriptor.nodeName + ', ' + (this.targetPeerDescriptor.nodeName) + ' close()');
|
|
38
|
+
if (!this.stopped) {
|
|
39
|
+
logger.trace(' ' + this.ownPeerDescriptor.nodeName + ', ' + (this.targetPeerDescriptor.nodeName) + ' close() not stopped');
|
|
40
|
+
this.stopped = true;
|
|
41
|
+
try {
|
|
42
|
+
logger.trace(' ' + this.ownPeerDescriptor.nodeName + ', ' + (this.targetPeerDescriptor.nodeName) +
|
|
43
|
+
' close() calling simulator.disconnect()');
|
|
44
|
+
this.simulator.close(this);
|
|
45
|
+
logger.trace(' ' + this.ownPeerDescriptor.nodeName + ', ' + (this.targetPeerDescriptor.nodeName) +
|
|
46
|
+
' close() simulator.disconnect returned');
|
|
47
|
+
}
|
|
48
|
+
catch (e) {
|
|
49
|
+
logger.trace(' ' + this.ownPeerDescriptor.nodeName + ', ' + (this.targetPeerDescriptor.nodeName) +
|
|
50
|
+
'close aborted' + e);
|
|
51
|
+
}
|
|
52
|
+
finally {
|
|
53
|
+
logger.trace(' ' + this.ownPeerDescriptor.nodeName + ', ' + (this.targetPeerDescriptor.nodeName) +
|
|
54
|
+
' calling this.doDisconnect');
|
|
55
|
+
this.doDisconnect(disconnectionType);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
logger.trace(' ' + this.ownPeerDescriptor.nodeName + ', ' + (this.targetPeerDescriptor.nodeName) +
|
|
60
|
+
' close() tried to close a stopped connection');
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
connect() {
|
|
64
|
+
if (!this.stopped) {
|
|
65
|
+
logger.trace('connect() called');
|
|
66
|
+
this.simulator.connect(this, this.targetPeerDescriptor, (error) => {
|
|
67
|
+
if (error) {
|
|
68
|
+
logger.trace(error);
|
|
69
|
+
this.doDisconnect('OTHER');
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
this.emit('connected');
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
logger.trace('tried to connect() a stopped connection');
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
handleIncomingData(data) {
|
|
81
|
+
if (!this.stopped) {
|
|
82
|
+
logger.trace('handleIncomingData()');
|
|
83
|
+
logger.trace((0, protoToString_1.protoToString)(DhtRpc_1.Message.fromBinary(data), DhtRpc_1.Message));
|
|
84
|
+
this.emit('data', data);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
logger.trace('tried to call handleIncomingData() a stopped connection');
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
handleIncomingDisconnection() {
|
|
91
|
+
if (!this.stopped) {
|
|
92
|
+
logger.trace(this.ownPeerDescriptor.nodeName + ' handleIncomingDisconnection()');
|
|
93
|
+
this.stopped = true;
|
|
94
|
+
this.doDisconnect('OTHER');
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
logger.trace('tried to call handleIncomingDisconnection() a stopped connection');
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
destroy() {
|
|
101
|
+
if (!this.stopped) {
|
|
102
|
+
logger.trace(this.ownPeerDescriptor.nodeName + ' destroy()');
|
|
103
|
+
this.removeAllListeners();
|
|
104
|
+
this.close('OTHER').catch((_e) => { });
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
logger.trace(this.ownPeerDescriptor.nodeName + ' tried to call destroy() a stopped connection');
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
doDisconnect(disconnectionType) {
|
|
111
|
+
logger.trace(this.ownPeerDescriptor.nodeName + ' doDisconnect()');
|
|
112
|
+
this.stopped = true;
|
|
113
|
+
logger.trace(' ' + this.ownPeerDescriptor.nodeName + ', ' + (this.targetPeerDescriptor.nodeName) + ' doDisconnect emitting');
|
|
114
|
+
this.emit('disconnected', disconnectionType);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
exports.SimulatorConnection = SimulatorConnection;
|
|
118
|
+
//# sourceMappingURL=SimulatorConnection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SimulatorConnection.js","sourceRoot":"","sources":["../../../../src/connection/Simulator/SimulatorConnection.ts"],"names":[],"mappings":";;;AAEA,mEAAgF;AAChF,8CAA0C;AAC1C,0CAAuC;AACvC,+DAA2D;AAG3D,MAAM,MAAM,GAAG,IAAI,cAAM,CAAC,MAAM,CAAC,CAAA;AAEjC,MAAa,mBAAoB,SAAQ,uBAAU;IAO/C,YACI,iBAAiC,EACjC,oBAAoC,EACpC,cAA8B,EAC9B,SAAoB;QAEpB,KAAK,CAAC,cAAc,CAAC,CAAA;QAXjB,YAAO,GAAG,KAAK,CAAA;QAanB,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAA;QAC1C,IAAI,CAAC,iBAAiB,CAAC,oBAAoB,CAAC,CAAA;QAC5C,IAAI,CAAC,oBAAoB,GAAG,oBAAoB,CAAA;QAChD,IAAI,CAAC,cAAc,GAAG,cAAc,CAAA;QACpC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;QAE1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAChC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAClC,IA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E,CAAA;YACzB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,EAAE,GAAG,CAAC,CAAC,CAAA;SACzC;aAAM;YACH,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,iBAAiB,CAAC,QAAQ,GAAG,+CAA+C,CAAC,CAAA;SAClG;IACL,CAAC;IAEO,YAAY,CAAC,iBAAoC;QACrD,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,iBAAiB,CAAC,QAAQ,GAAG,iBAAiB,CAAC,CAAA;QACjE,IAAI,CAAC,OAAO,GAAG,IAAI,CAAA;QAEnB,MAAM,CAAC,KAAK,CAAC,GAAG,GAAG,IAAI,CAAC,iBAAiB,CAAC,QAAQ,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,oBAAoB,CAAC,QAAS,CAAC,GAAG,wBAAwB,CAAC,CAAA;QAE7H,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,iBAAiB,CAAC,CAAA;IAEhD,CAAC;CACJ;AA9HD,kDA8HC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { PeerDescriptor } from '../../proto/packages/dht/protos/DhtRpc';
|
|
2
|
+
import { ManagedConnection } from '../ManagedConnection';
|
|
3
|
+
import { Simulator } from './Simulator';
|
|
4
|
+
import { SimulatorConnection } from './SimulatorConnection';
|
|
5
|
+
export declare class SimulatorConnector {
|
|
6
|
+
private connectingConnections;
|
|
7
|
+
private stopped;
|
|
8
|
+
private protocolVersion;
|
|
9
|
+
private ownPeerDescriptor;
|
|
10
|
+
private simulator;
|
|
11
|
+
private incomingConnectionCallback;
|
|
12
|
+
constructor(protocolVersion: string, ownPeerDescriptor: PeerDescriptor, simulator: Simulator, incomingConnectionCallback: (connection: ManagedConnection) => boolean);
|
|
13
|
+
connect(targetPeerDescriptor: PeerDescriptor): ManagedConnection;
|
|
14
|
+
getPeerDescriptor(): PeerDescriptor;
|
|
15
|
+
handleIncomingConnection(sourceConnection: SimulatorConnection): void;
|
|
16
|
+
stop(): Promise<void>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SimulatorConnector = void 0;
|
|
4
|
+
const IConnection_1 = require("../IConnection");
|
|
5
|
+
const utils_1 = require("@streamr/utils");
|
|
6
|
+
const ManagedConnection_1 = require("../ManagedConnection");
|
|
7
|
+
const SimulatorConnection_1 = require("./SimulatorConnection");
|
|
8
|
+
const peerIdFromPeerDescriptor_1 = require("../../helpers/peerIdFromPeerDescriptor");
|
|
9
|
+
const logger = new utils_1.Logger(module);
|
|
10
|
+
class SimulatorConnector {
|
|
11
|
+
constructor(protocolVersion, ownPeerDescriptor, simulator, incomingConnectionCallback) {
|
|
12
|
+
this.connectingConnections = new Map();
|
|
13
|
+
this.stopped = false;
|
|
14
|
+
this.protocolVersion = protocolVersion;
|
|
15
|
+
this.ownPeerDescriptor = ownPeerDescriptor;
|
|
16
|
+
this.simulator = simulator;
|
|
17
|
+
this.incomingConnectionCallback = incomingConnectionCallback;
|
|
18
|
+
}
|
|
19
|
+
connect(targetPeerDescriptor) {
|
|
20
|
+
logger.trace('connect() ' + this.ownPeerDescriptor.nodeName + ',' + targetPeerDescriptor.nodeName);
|
|
21
|
+
const peerKey = (0, peerIdFromPeerDescriptor_1.keyFromPeerDescriptor)(targetPeerDescriptor);
|
|
22
|
+
const existingConnection = this.connectingConnections.get(peerKey);
|
|
23
|
+
if (existingConnection) {
|
|
24
|
+
return existingConnection;
|
|
25
|
+
}
|
|
26
|
+
const connection = new SimulatorConnection_1.SimulatorConnection(this.ownPeerDescriptor, targetPeerDescriptor, IConnection_1.ConnectionType.SIMULATOR_CLIENT, this.simulator);
|
|
27
|
+
const managedConnection = new ManagedConnection_1.ManagedConnection(this.ownPeerDescriptor, this.protocolVersion, IConnection_1.ConnectionType.SIMULATOR_CLIENT, connection, undefined);
|
|
28
|
+
managedConnection.setPeerDescriptor(targetPeerDescriptor);
|
|
29
|
+
this.connectingConnections.set(peerKey, managedConnection);
|
|
30
|
+
connection.once('disconnected', () => {
|
|
31
|
+
this.connectingConnections.delete(peerKey);
|
|
32
|
+
});
|
|
33
|
+
connection.once('connected', () => {
|
|
34
|
+
this.connectingConnections.delete(peerKey);
|
|
35
|
+
});
|
|
36
|
+
connection.connect();
|
|
37
|
+
return managedConnection;
|
|
38
|
+
}
|
|
39
|
+
getPeerDescriptor() {
|
|
40
|
+
return this.ownPeerDescriptor;
|
|
41
|
+
}
|
|
42
|
+
handleIncomingConnection(sourceConnection) {
|
|
43
|
+
logger.trace(' ' + this.ownPeerDescriptor.nodeName + ', ' + sourceConnection.ownPeerDescriptor.nodeName +
|
|
44
|
+
' incoming connection, stopped: ' + this.stopped);
|
|
45
|
+
if (this.stopped) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const connection = new SimulatorConnection_1.SimulatorConnection(this.ownPeerDescriptor, sourceConnection.ownPeerDescriptor, IConnection_1.ConnectionType.SIMULATOR_SERVER, this.simulator);
|
|
49
|
+
const managedConnection = new ManagedConnection_1.ManagedConnection(this.ownPeerDescriptor, this.protocolVersion, IConnection_1.ConnectionType.SIMULATOR_SERVER, undefined, connection);
|
|
50
|
+
logger.trace('connected, objectId: ' + managedConnection.objectId);
|
|
51
|
+
managedConnection.once('handshakeRequest', (_peerDescriptor) => {
|
|
52
|
+
logger.trace(' ' + this.ownPeerDescriptor.nodeName + ', ' + sourceConnection.ownPeerDescriptor.nodeName + ' incoming handshake request');
|
|
53
|
+
logger.trace('incoming handshake request objectId: ' + managedConnection.objectId);
|
|
54
|
+
if (this.incomingConnectionCallback(managedConnection)) {
|
|
55
|
+
logger.trace(' ' + this.ownPeerDescriptor.nodeName + ', ' + sourceConnection.ownPeerDescriptor.nodeName + ' calling acceptHandshake');
|
|
56
|
+
managedConnection.acceptHandshake();
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
managedConnection.rejectHandshake('Duplicate connection');
|
|
60
|
+
managedConnection.destroy();
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
this.simulator.accept(sourceConnection, connection);
|
|
64
|
+
}
|
|
65
|
+
async stop() {
|
|
66
|
+
this.stopped = true;
|
|
67
|
+
const conns = Array.from(this.connectingConnections.values());
|
|
68
|
+
await Promise.allSettled(conns.map((conn) => conn.close('OTHER')));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.SimulatorConnector = SimulatorConnector;
|
|
72
|
+
//# sourceMappingURL=SimulatorConnector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SimulatorConnector.js","sourceRoot":"","sources":["../../../../src/connection/Simulator/SimulatorConnector.ts"],"names":[],"mappings":";;;AAAA,gDAA+C;AAK/C,0CAAuC;AACvC,4DAAwD;AAGxD,+DAA2D;AAC3D,qFAA8E;AAE9E,MAAM,MAAM,GAAG,IAAI,cAAM,CAAC,MAAM,CAAC,CAAA;AAEjC,MAAa,kBAAkB;IAS3B,YACI,eAAuB,EACvB,iBAAiC,EACjC,SAAoB,EACpB,0BAAsE;QAXlE,0BAAqB,GAAsC,IAAI,GAAG,EAAE,CAAA;QACpE,YAAO,GAAG,KAAK,CAAA;QAYnB,IAAI,CAAC,eAAe,GAAG,eAAe,CAAA;QACtC,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAA;QAC1C,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;QAC1B,IAAI,CAAC,0BAA0B,GAAG,0BAA0B,CAAA;IAChE,CAAC;IAEM,OAAO,CAAC,oBAAoC;QAC/C,MAAM,CAAC,KAAK,CAAC,YAAY,GAAG,IAAI,CAAC,iBAAiB,CAAC,QAAQ,GAAG,GAAG,GAAG,oBAAoB,CAAC,QAAQ,CAAC,CAAA;QAClG,MAAM,OAAO,GAAG,IAAA,gDAAqB,EAAC,oBAAoB,CAAC,CAAA;QAC3D,MAAM,kBAAkB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,OAAO,GAAG,IAAI,CAAA;QACnB,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,qBAAqB,CAAC,MAAM,EAAE,CAAC,CAAA;QAC7D,MAAM,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACxC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CACtB,CAAC,CAAA;IACN,CAAC;CACJ;AAzFD,gDAyFC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { PeerDescriptor } from '../../proto/packages/dht/protos/DhtRpc';
|
|
2
|
+
import { ConnectionManager } from '../ConnectionManager';
|
|
3
|
+
import { Simulator } from './Simulator';
|
|
4
|
+
export declare class SimulatorTransport extends ConnectionManager {
|
|
5
|
+
constructor(ownPeerDescriptor: PeerDescriptor, simulator: Simulator);
|
|
6
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SimulatorTransport = void 0;
|
|
4
|
+
const ConnectionManager_1 = require("../ConnectionManager");
|
|
5
|
+
class SimulatorTransport extends ConnectionManager_1.ConnectionManager {
|
|
6
|
+
constructor(ownPeerDescriptor, simulator) {
|
|
7
|
+
super({ ownPeerDescriptor: ownPeerDescriptor, simulator, serviceIdPrefix: 'simulator/', nodeName: ownPeerDescriptor.nodeName });
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.SimulatorTransport = SimulatorTransport;
|
|
11
|
+
//# sourceMappingURL=SimulatorTransport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SimulatorTransport.js","sourceRoot":"","sources":["../../../../src/connection/Simulator/SimulatorTransport.ts"],"names":[],"mappings":";;;AACA,4DAAwD;AAGxD,MAAa,kBAAmB,SAAQ,qCAAiB;IACrD,YAAY,iBAAiC,EAAE,SAAoB;QAC/D,KAAK,CAAC,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,SAAS,EAAE,eAAe,EAAE,YAAY,EAAE,QAAQ,EAAE,iBAAiB,CAAC,QAAQ,EAAE,CAAC,CAAA;IACnI,CAAC;CACJ;AAJD,gDAIC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare enum RegionIndex {
|
|
2
|
+
eu_central_1 = 0,
|
|
3
|
+
eu_west_1 = 1,
|
|
4
|
+
eu_west_2 = 2,
|
|
5
|
+
eu_west_3 = 3,
|
|
6
|
+
eu_north_1 = 4,
|
|
7
|
+
us_east_1 = 5,
|
|
8
|
+
us_east_2 = 6,
|
|
9
|
+
us_west_1 = 7,
|
|
10
|
+
us_west_2 = 8,
|
|
11
|
+
ca_central_1 = 9,
|
|
12
|
+
ap_south_1 = 10,
|
|
13
|
+
ap_northeast_2 = 11,
|
|
14
|
+
ap_southeast_1 = 12,
|
|
15
|
+
ap_southeast_2 = 13,
|
|
16
|
+
ap_northeast_1 = 14,
|
|
17
|
+
sa_east_1 = 15
|
|
18
|
+
}
|
|
19
|
+
export declare const regionPingMatrix: number[][];
|
|
20
|
+
export declare function getRegionDelayMatrix(): Array<Array<number>>;
|
|
21
|
+
export declare function getRandomRegion(): number;
|