@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
package/.eslintignore
ADDED
package/.eslintrc
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# @streamr/dht (WIP)
|
|
2
|
+
|
|
3
|
+
An implementation of the Kademlia-based Streamr DHT used for the trackerless network.
|
|
4
|
+
|
|
5
|
+
## Generating Protobuf code
|
|
6
|
+
|
|
7
|
+
Auto-generated protobuf/gRPC code is compiled during the build process.
|
|
8
|
+
```bash
|
|
9
|
+
npm run build
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Alternatively
|
|
13
|
+
```bash
|
|
14
|
+
npm run prebuild
|
|
15
|
+
# Or
|
|
16
|
+
./proto.sh
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Running DHT simulations
|
|
20
|
+
|
|
21
|
+
Generate test data
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm run prepare-dht-simulation
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Run simulation
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm run run-dht-simulation
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
In order to change number of nodes, or other simulation settings,
|
|
34
|
+
|
|
35
|
+
* Edit the chages to the file 'test/simulation/data/generatedhtids.ts'.
|
|
36
|
+
* Then generate new test data by running 'npm run prepare-dht-simulation'
|
|
37
|
+
* Edit the same changes to file 'src/simulation/DhtSimulation.ts'
|
|
38
|
+
* Run the simulation with new settings using 'npm run run-dht-simulation '
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import EventEmitter from 'eventemitter3';
|
|
2
|
+
import { PeerDescriptor } from '../proto/packages/dht/protos/DhtRpc';
|
|
3
|
+
import { ConnectionID, ConnectionType, ConnectionEvents } from './IConnection';
|
|
4
|
+
export declare class Connection extends EventEmitter<ConnectionEvents> {
|
|
5
|
+
connectionId: ConnectionID;
|
|
6
|
+
connectionType: ConnectionType;
|
|
7
|
+
private peerDescriptor?;
|
|
8
|
+
constructor(connectionType: ConnectionType);
|
|
9
|
+
setPeerDescriptor(peerDescriptor: PeerDescriptor): void;
|
|
10
|
+
getPeerDescriptor(): PeerDescriptor | undefined;
|
|
11
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Connection = void 0;
|
|
7
|
+
const eventemitter3_1 = __importDefault(require("eventemitter3"));
|
|
8
|
+
const IConnection_1 = require("./IConnection");
|
|
9
|
+
class Connection extends eventemitter3_1.default {
|
|
10
|
+
constructor(connectionType) {
|
|
11
|
+
super();
|
|
12
|
+
this.connectionId = new IConnection_1.ConnectionID();
|
|
13
|
+
this.connectionType = connectionType;
|
|
14
|
+
}
|
|
15
|
+
setPeerDescriptor(peerDescriptor) {
|
|
16
|
+
this.peerDescriptor = peerDescriptor;
|
|
17
|
+
}
|
|
18
|
+
getPeerDescriptor() {
|
|
19
|
+
return this.peerDescriptor;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.Connection = Connection;
|
|
23
|
+
//# sourceMappingURL=Connection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Connection.js","sourceRoot":"","sources":["../../../src/connection/Connection.ts"],"names":[],"mappings":";;;;;;AAAA,kEAAwC;AAExC,+CAA8E;AAE9E,MAAa,UAAW,SAAQ,uBAA8B;IAK1D,YAAY,cAA8B;QACtC,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,YAAY,GAAG,IAAI,0BAAY,EAAE,CAAA;QACtC,IAAI,CAAC,cAAc,GAAG,cAAc,CAAA;IACxC,CAAC;IAED,iBAAiB,CAAC,cAA8B;QAC5C,IAAI,CAAC,cAAc,GAAG,cAAc,CAAA;IACxC,CAAC;IAED,iBAAiB;QACb,OAAO,IAAI,CAAC,cAAc,CAAA;IAC9B,CAAC;CACJ;AAlBD,gCAkBC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { PeerIDKey } from '../helpers/PeerID';
|
|
2
|
+
type ServiceName = string;
|
|
3
|
+
export declare class ConnectionLockHandler {
|
|
4
|
+
private localLocks;
|
|
5
|
+
private remoteLocks;
|
|
6
|
+
private weakLocks;
|
|
7
|
+
getNumberOfLocalLockedConnections(): number;
|
|
8
|
+
getNumberOfRemoteLockedConnections(): number;
|
|
9
|
+
getNumberOfWeakLockedConnections(): number;
|
|
10
|
+
isLocalLocked(id: PeerIDKey, serviceName?: ServiceName): boolean;
|
|
11
|
+
isRemoteLocked(id: PeerIDKey, serviceName?: ServiceName): boolean;
|
|
12
|
+
isWeakLocked(id: PeerIDKey): boolean;
|
|
13
|
+
isLocked(id: PeerIDKey): boolean;
|
|
14
|
+
addLocalLocked(id: PeerIDKey, serviceName: ServiceName): void;
|
|
15
|
+
addRemoteLocked(id: PeerIDKey, serviceName: ServiceName): void;
|
|
16
|
+
addWeakLocked(id: PeerIDKey): void;
|
|
17
|
+
removeLocalLocked(id: PeerIDKey, serviceName: ServiceName): void;
|
|
18
|
+
removeRemoteLocked(id: PeerIDKey, serviceName: ServiceName): void;
|
|
19
|
+
removeWeakLocked(id: PeerIDKey): void;
|
|
20
|
+
clearAllLocks(id: PeerIDKey): void;
|
|
21
|
+
clear(): void;
|
|
22
|
+
}
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Connection locks are independent of the existence of connections
|
|
3
|
+
// that is why this class is needed
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.ConnectionLockHandler = void 0;
|
|
6
|
+
class ConnectionLockHandler {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.localLocks = new Map();
|
|
9
|
+
this.remoteLocks = new Map();
|
|
10
|
+
this.weakLocks = new Set();
|
|
11
|
+
}
|
|
12
|
+
getNumberOfLocalLockedConnections() {
|
|
13
|
+
return this.localLocks.size;
|
|
14
|
+
}
|
|
15
|
+
getNumberOfRemoteLockedConnections() {
|
|
16
|
+
return this.remoteLocks.size;
|
|
17
|
+
}
|
|
18
|
+
getNumberOfWeakLockedConnections() {
|
|
19
|
+
return this.weakLocks.size;
|
|
20
|
+
}
|
|
21
|
+
isLocalLocked(id, serviceName) {
|
|
22
|
+
if (!serviceName) {
|
|
23
|
+
return this.localLocks.has(id);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
return this.localLocks.has(id) && this.localLocks.get(id).has(serviceName);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
isRemoteLocked(id, serviceName) {
|
|
30
|
+
if (!serviceName) {
|
|
31
|
+
return this.remoteLocks.has(id);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
if (this.remoteLocks.has(id) && this.remoteLocks.get(id).has(serviceName)) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
isWeakLocked(id) {
|
|
43
|
+
return this.weakLocks.has(id);
|
|
44
|
+
}
|
|
45
|
+
isLocked(id) {
|
|
46
|
+
return (this.isLocalLocked(id) || this.isRemoteLocked(id) || this.isWeakLocked(id));
|
|
47
|
+
}
|
|
48
|
+
addLocalLocked(id, serviceName) {
|
|
49
|
+
if (!this.localLocks.has(id)) {
|
|
50
|
+
this.localLocks.set(id, new Set());
|
|
51
|
+
}
|
|
52
|
+
this.localLocks.get(id).add(serviceName);
|
|
53
|
+
}
|
|
54
|
+
addRemoteLocked(id, serviceName) {
|
|
55
|
+
if (!this.remoteLocks.has(id)) {
|
|
56
|
+
this.remoteLocks.set(id, new Set());
|
|
57
|
+
}
|
|
58
|
+
this.remoteLocks.get(id).add(serviceName);
|
|
59
|
+
}
|
|
60
|
+
addWeakLocked(id) {
|
|
61
|
+
this.weakLocks.add(id);
|
|
62
|
+
}
|
|
63
|
+
removeLocalLocked(id, serviceName) {
|
|
64
|
+
if (this.localLocks.has(id)) {
|
|
65
|
+
this.localLocks.get(id)?.delete(serviceName);
|
|
66
|
+
if (this.localLocks.get(id)?.size === 0) {
|
|
67
|
+
this.localLocks.delete(id);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
removeRemoteLocked(id, serviceName) {
|
|
72
|
+
if (this.remoteLocks.has(id)) {
|
|
73
|
+
this.remoteLocks.get(id)?.delete(serviceName);
|
|
74
|
+
if (this.remoteLocks.get(id)?.size === 0) {
|
|
75
|
+
this.remoteLocks.delete(id);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
removeWeakLocked(id) {
|
|
80
|
+
this.weakLocks.delete(id);
|
|
81
|
+
}
|
|
82
|
+
clearAllLocks(id) {
|
|
83
|
+
this.localLocks.delete(id);
|
|
84
|
+
this.remoteLocks.delete(id);
|
|
85
|
+
this.weakLocks.delete(id);
|
|
86
|
+
}
|
|
87
|
+
clear() {
|
|
88
|
+
this.localLocks.clear();
|
|
89
|
+
this.remoteLocks.clear();
|
|
90
|
+
this.weakLocks.clear();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
exports.ConnectionLockHandler = ConnectionLockHandler;
|
|
94
|
+
//# sourceMappingURL=ConnectionLockHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConnectionLockHandler.js","sourceRoot":"","sources":["../../../src/connection/ConnectionLockHandler.ts"],"names":[],"mappings":";AAAA,mEAAmE;AACnE,mCAAmC;;;AAMnC,MAAa,qBAAqB;IAAlC;QAEY,eAAU,GAAqC,IAAI,GAAG,EAAE,CAAA;QACxD,gBAAW,GAAqC,IAAI,GAAG,EAAE,CAAA;QACzD,cAAS,GAAmB,IAAI,GAAG,EAAE,CAAA;IA6FjD,CAAC;IA3FU,iCAAiC;QACpC,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAA;IAC/B,CAAC;IAEM,kCAAkC;QACrC,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAA;IAChC,CAAC;IAEM,gCAAgC;QACnC,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAA;IAC9B,CAAC;IAEM,aAAa,CAAC,EAAa,EAAE,WAAyB;QACzD,IAAI,CAAC,WAAW,EAAE;YACd,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC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C,MAAM,CAAC,EAAE,CAAC,CAAA;QAC1B,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;QAC3B,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;IAC7B,CAAC;IAEM,KAAK;QACR,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAA;QACvB,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAA;QACxB,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAA;IAC1B,CAAC;CACJ;AAjGD,sDAiGC"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { EventEmitter } from 'eventemitter3';
|
|
2
|
+
import { ConnectivityResponse, Message, PeerDescriptor } from '../proto/packages/dht/protos/DhtRpc';
|
|
3
|
+
import { PeerIDKey } from '../helpers/PeerID';
|
|
4
|
+
import { ITransport, TransportEvents } from '../transport/ITransport';
|
|
5
|
+
import { IceServer } from './WebRTC/WebRtcConnector';
|
|
6
|
+
import { MetricsContext } from '@streamr/utils';
|
|
7
|
+
import { ManagedConnection } from './ManagedConnection';
|
|
8
|
+
import { Simulator } from './Simulator/Simulator';
|
|
9
|
+
export declare class ConnectionManagerConfig {
|
|
10
|
+
transportLayer?: ITransport;
|
|
11
|
+
webSocketHost?: string;
|
|
12
|
+
webSocketPort?: number;
|
|
13
|
+
entryPoints?: PeerDescriptor[];
|
|
14
|
+
nodeName?: string;
|
|
15
|
+
maxConnections: number;
|
|
16
|
+
iceServers?: IceServer[];
|
|
17
|
+
metricsContext?: MetricsContext;
|
|
18
|
+
webrtcAllowPrivateAddresses?: boolean;
|
|
19
|
+
webrtcDatachannelBufferThresholdLow?: number;
|
|
20
|
+
webrtcDatachannelBufferThresholdHigh?: number;
|
|
21
|
+
webrtcNewConnectionTimeout?: number;
|
|
22
|
+
simulator?: Simulator;
|
|
23
|
+
ownPeerDescriptor?: PeerDescriptor;
|
|
24
|
+
serviceIdPrefix?: string;
|
|
25
|
+
constructor(conf: Partial<ConnectionManagerConfig>);
|
|
26
|
+
}
|
|
27
|
+
export declare enum NatType {
|
|
28
|
+
OPEN_INTERNET = "open_internet",
|
|
29
|
+
UNKNOWN = "unknown"
|
|
30
|
+
}
|
|
31
|
+
type ServiceId = string;
|
|
32
|
+
export type PeerDescriptorGeneratorCallback = (connectivityResponse: ConnectivityResponse) => PeerDescriptor;
|
|
33
|
+
interface ConnectionManagerEvents {
|
|
34
|
+
newConnection: (connection: ManagedConnection) => void;
|
|
35
|
+
}
|
|
36
|
+
export interface ConnectionLocker {
|
|
37
|
+
lockConnection(targetDescriptor: PeerDescriptor, serviceId: ServiceId): void;
|
|
38
|
+
unlockConnection(targetDescriptor: PeerDescriptor, serviceId: ServiceId): void;
|
|
39
|
+
weakLockConnection(targetDescriptor: PeerDescriptor): void;
|
|
40
|
+
weakUnlockConnection(targetDescriptor: PeerDescriptor): void;
|
|
41
|
+
}
|
|
42
|
+
export type Events = TransportEvents & ConnectionManagerEvents;
|
|
43
|
+
export declare class ConnectionManager extends EventEmitter<Events> implements ITransport, ConnectionLocker {
|
|
44
|
+
static PROTOCOL_VERSION: string;
|
|
45
|
+
private config;
|
|
46
|
+
private readonly metricsContext;
|
|
47
|
+
private ownPeerDescriptor?;
|
|
48
|
+
private readonly messageDuplicateDetector;
|
|
49
|
+
private readonly metrics;
|
|
50
|
+
private locks;
|
|
51
|
+
private connections;
|
|
52
|
+
private webSocketConnector?;
|
|
53
|
+
private webrtcConnector?;
|
|
54
|
+
private simulatorConnector?;
|
|
55
|
+
private rpcCommunicator?;
|
|
56
|
+
private disconnectorIntervalRef?;
|
|
57
|
+
private serviceId;
|
|
58
|
+
private state;
|
|
59
|
+
constructor(conf: Partial<ConnectionManagerConfig>);
|
|
60
|
+
garbageCollectConnections(maxConnections: number, lastUsedLimit: number): void;
|
|
61
|
+
start(peerDescriptorGeneratorCallback?: PeerDescriptorGeneratorCallback): Promise<void>;
|
|
62
|
+
stop(): Promise<void>;
|
|
63
|
+
getConnectionTo(id: PeerIDKey): ManagedConnection;
|
|
64
|
+
getNumberOfLocalLockedConnections(): number;
|
|
65
|
+
getNumberOfRemoteLockedConnections(): number;
|
|
66
|
+
getNumberOfWeakLockedConnections(): number;
|
|
67
|
+
send(message: Message, doNotConnect?: boolean, doNotMindStopped?: boolean): Promise<void>;
|
|
68
|
+
private createConnection;
|
|
69
|
+
getConnection(peerDescriptor: PeerDescriptor): ManagedConnection | undefined;
|
|
70
|
+
getPeerDescriptor(): PeerDescriptor;
|
|
71
|
+
hasConnection(peerDescriptor: PeerDescriptor): boolean;
|
|
72
|
+
hasLocalLockedConnection(peerDescriptor: PeerDescriptor, _serviceId?: ServiceId): boolean;
|
|
73
|
+
hasRemoteLockedConnection(peerDescriptor: PeerDescriptor, _serviceId?: ServiceId): boolean;
|
|
74
|
+
canConnect(peerDescriptor: PeerDescriptor, _ip: string, _port: number): boolean;
|
|
75
|
+
handleMessage(message: Message): void;
|
|
76
|
+
private onData;
|
|
77
|
+
private onConnected;
|
|
78
|
+
private onDisconnected;
|
|
79
|
+
private incomingConnectionCallback;
|
|
80
|
+
private acceptIncomingConnection;
|
|
81
|
+
private closeConnection;
|
|
82
|
+
lockConnection(targetDescriptor: PeerDescriptor, serviceId: ServiceId): void;
|
|
83
|
+
unlockConnection(targetDescriptor: PeerDescriptor, serviceId: ServiceId): void;
|
|
84
|
+
weakLockConnection(targetDescriptor: PeerDescriptor): void;
|
|
85
|
+
weakUnlockConnection(targetDescriptor: PeerDescriptor): void;
|
|
86
|
+
private gracefullyDisconnectAsync;
|
|
87
|
+
private doGracefullyDisconnectAsync;
|
|
88
|
+
getAllConnectionPeerDescriptors(): PeerDescriptor[];
|
|
89
|
+
private lockRequest;
|
|
90
|
+
private unlockRequest;
|
|
91
|
+
private gracefulDisconnect;
|
|
92
|
+
private onConnectionCountChange;
|
|
93
|
+
}
|
|
94
|
+
export {};
|