@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,227 @@
|
|
|
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.WebRtcConnector = void 0;
|
|
27
|
+
const DhtRpc_1 = require("../../proto/packages/dht/protos/DhtRpc");
|
|
28
|
+
const ListeningRpcCommunicator_1 = require("../../transport/ListeningRpcCommunicator");
|
|
29
|
+
const NodeWebRtcConnection_1 = require("./NodeWebRtcConnection");
|
|
30
|
+
const RemoteWebrtcConnector_1 = require("./RemoteWebrtcConnector");
|
|
31
|
+
const DhtRpc_client_1 = require("../../proto/packages/dht/protos/DhtRpc.client");
|
|
32
|
+
const ManagedWebRtcConnection_1 = require("../ManagedWebRtcConnection");
|
|
33
|
+
const utils_1 = require("@streamr/utils");
|
|
34
|
+
const Err = __importStar(require("../../helpers/errors"));
|
|
35
|
+
const proto_rpc_1 = require("@streamr/proto-rpc");
|
|
36
|
+
const peerIdFromPeerDescriptor_1 = require("../../helpers/peerIdFromPeerDescriptor");
|
|
37
|
+
const AddressTools_1 = require("../../helpers/AddressTools");
|
|
38
|
+
const logger = new utils_1.Logger(module);
|
|
39
|
+
class WebRtcConnector {
|
|
40
|
+
constructor(config, incomingConnectionCallback) {
|
|
41
|
+
this.ongoingConnectAttempts = new Map();
|
|
42
|
+
this.stopped = false;
|
|
43
|
+
this.config = config;
|
|
44
|
+
this.iceServers = config.iceServers || [];
|
|
45
|
+
this.allowPrivateAddresses = config.allowPrivateAddresses || true;
|
|
46
|
+
this.incomingConnectionCallback = incomingConnectionCallback;
|
|
47
|
+
this.rpcCommunicator = new ListeningRpcCommunicator_1.ListeningRpcCommunicator(WebRtcConnector.WEBRTC_CONNECTOR_SERVICE_ID, config.rpcTransport, {
|
|
48
|
+
rpcRequestTimeout: 15000
|
|
49
|
+
});
|
|
50
|
+
this.rpcCommunicator.registerRpcNotification(DhtRpc_1.RtcOffer, 'rtcOffer', (req, context) => this.rtcOffer(req, context));
|
|
51
|
+
this.rpcCommunicator.registerRpcNotification(DhtRpc_1.RtcAnswer, 'rtcAnswer', (req, context) => this.rtcAnswer(req, context));
|
|
52
|
+
this.rpcCommunicator.registerRpcNotification(DhtRpc_1.IceCandidate, 'iceCandidate', (req, context) => this.iceCandidate(req, context));
|
|
53
|
+
this.rpcCommunicator.registerRpcNotification(DhtRpc_1.WebRtcConnectionRequest, 'requestConnection', (req, context) => this.requestConnection(req, context));
|
|
54
|
+
}
|
|
55
|
+
connect(targetPeerDescriptor) {
|
|
56
|
+
if ((0, peerIdFromPeerDescriptor_1.isSamePeerDescriptor)(targetPeerDescriptor, this.ownPeerDescriptor)) {
|
|
57
|
+
throw new Err.CannotConnectToSelf('Cannot open WebRTC Connection to self');
|
|
58
|
+
}
|
|
59
|
+
logger.trace(`Opening WebRTC connection to ${targetPeerDescriptor.kademliaId.toString()}`);
|
|
60
|
+
const peerKey = (0, peerIdFromPeerDescriptor_1.keyFromPeerDescriptor)(targetPeerDescriptor);
|
|
61
|
+
const existingConnection = this.ongoingConnectAttempts.get(peerKey);
|
|
62
|
+
if (existingConnection) {
|
|
63
|
+
return existingConnection;
|
|
64
|
+
}
|
|
65
|
+
const connection = new NodeWebRtcConnection_1.NodeWebRtcConnection({
|
|
66
|
+
remotePeerDescriptor: targetPeerDescriptor,
|
|
67
|
+
iceServers: this.iceServers,
|
|
68
|
+
bufferThresholdLow: this.config.bufferThresholdLow,
|
|
69
|
+
bufferThresholdHigh: this.config.bufferThresholdHigh,
|
|
70
|
+
connectingTimeout: this.config.connectionTimeout
|
|
71
|
+
});
|
|
72
|
+
const offering = this.isOffering(targetPeerDescriptor);
|
|
73
|
+
let managedConnection;
|
|
74
|
+
if (offering) {
|
|
75
|
+
managedConnection = new ManagedWebRtcConnection_1.ManagedWebRtcConnection(this.ownPeerDescriptor, this.config.protocolVersion, connection);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
managedConnection = new ManagedWebRtcConnection_1.ManagedWebRtcConnection(this.ownPeerDescriptor, this.config.protocolVersion, undefined, connection);
|
|
79
|
+
}
|
|
80
|
+
managedConnection.setPeerDescriptor(targetPeerDescriptor);
|
|
81
|
+
this.ongoingConnectAttempts.set((0, peerIdFromPeerDescriptor_1.keyFromPeerDescriptor)(targetPeerDescriptor), managedConnection);
|
|
82
|
+
const delFunc = () => {
|
|
83
|
+
if (this.ongoingConnectAttempts.has(peerKey)) {
|
|
84
|
+
this.ongoingConnectAttempts.delete(peerKey);
|
|
85
|
+
}
|
|
86
|
+
connection.off('disconnected', delFunc);
|
|
87
|
+
managedConnection.off('handshakeCompleted', delFunc);
|
|
88
|
+
};
|
|
89
|
+
connection.on('disconnected', delFunc);
|
|
90
|
+
managedConnection.on('handshakeCompleted', delFunc);
|
|
91
|
+
const remoteConnector = new RemoteWebrtcConnector_1.RemoteWebrtcConnector(targetPeerDescriptor, (0, proto_rpc_1.toProtoRpcClient)(new DhtRpc_client_1.WebRtcConnectorServiceClient(this.rpcCommunicator.getRpcClientTransport())));
|
|
92
|
+
connection.on('localCandidate', (candidate, mid) => {
|
|
93
|
+
remoteConnector.sendIceCandidate(this.ownPeerDescriptor, candidate, mid, connection.connectionId.toString());
|
|
94
|
+
});
|
|
95
|
+
if (offering) {
|
|
96
|
+
connection.once('localDescription', (description, _type) => {
|
|
97
|
+
remoteConnector.sendRtcOffer(this.ownPeerDescriptor, description, connection.connectionId.toString());
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
connection.once('localDescription', (description, _type) => {
|
|
102
|
+
remoteConnector.sendRtcAnswer(this.ownPeerDescriptor, description, connection.connectionId.toString());
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
connection.start(offering);
|
|
106
|
+
if (!offering) {
|
|
107
|
+
remoteConnector.requestConnection(this.ownPeerDescriptor, connection.connectionId.toString());
|
|
108
|
+
}
|
|
109
|
+
return managedConnection;
|
|
110
|
+
}
|
|
111
|
+
setOwnPeerDescriptor(peerDescriptor) {
|
|
112
|
+
this.ownPeerDescriptor = peerDescriptor;
|
|
113
|
+
}
|
|
114
|
+
isIceCandidateAllowed(candidate) {
|
|
115
|
+
if (!this.allowPrivateAddresses) {
|
|
116
|
+
const address = (0, AddressTools_1.getAddressFromIceCandidate)(candidate);
|
|
117
|
+
if (address && (0, AddressTools_1.isPrivateIPv4)(address)) {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
onRtcOffer(remotePeer, targetPeer, description, connectionId) {
|
|
124
|
+
if (this.stopped || !(0, peerIdFromPeerDescriptor_1.isSamePeerDescriptor)(targetPeer, this.ownPeerDescriptor)) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const peerKey = (0, peerIdFromPeerDescriptor_1.keyFromPeerDescriptor)(remotePeer);
|
|
128
|
+
let managedConnection = this.ongoingConnectAttempts.get(peerKey);
|
|
129
|
+
let connection = managedConnection?.getWebRtcConnection();
|
|
130
|
+
if (!managedConnection) {
|
|
131
|
+
connection = new NodeWebRtcConnection_1.NodeWebRtcConnection({ remotePeerDescriptor: remotePeer });
|
|
132
|
+
managedConnection = new ManagedWebRtcConnection_1.ManagedWebRtcConnection(this.ownPeerDescriptor, this.config.protocolVersion, undefined, connection);
|
|
133
|
+
managedConnection.setPeerDescriptor(remotePeer);
|
|
134
|
+
this.ongoingConnectAttempts.set(peerKey, managedConnection);
|
|
135
|
+
this.incomingConnectionCallback(managedConnection);
|
|
136
|
+
const remoteConnector = new RemoteWebrtcConnector_1.RemoteWebrtcConnector(remotePeer, (0, proto_rpc_1.toProtoRpcClient)(new DhtRpc_client_1.WebRtcConnectorServiceClient(this.rpcCommunicator.getRpcClientTransport())));
|
|
137
|
+
connection.on('localCandidate', (candidate, mid) => {
|
|
138
|
+
remoteConnector.sendIceCandidate(this.ownPeerDescriptor, candidate, mid, connection.connectionId.toString());
|
|
139
|
+
});
|
|
140
|
+
connection.once('localDescription', (description, _type) => {
|
|
141
|
+
remoteConnector.sendRtcAnswer(this.ownPeerDescriptor, description, connection.connectionId.toString());
|
|
142
|
+
});
|
|
143
|
+
connection.start(false);
|
|
144
|
+
}
|
|
145
|
+
// Always use offerers connectionId
|
|
146
|
+
connection.setConnectionId(connectionId);
|
|
147
|
+
connection.setRemoteDescription(description, 'offer');
|
|
148
|
+
managedConnection.on('handshakeRequest', () => {
|
|
149
|
+
if (this.ongoingConnectAttempts.has(peerKey)) {
|
|
150
|
+
this.ongoingConnectAttempts.delete(peerKey);
|
|
151
|
+
}
|
|
152
|
+
managedConnection.acceptHandshake();
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
onRtcAnswer(remotePeerDescriptor, targetPeerDescriptor, description, connectionId) {
|
|
156
|
+
if (this.stopped || !(0, peerIdFromPeerDescriptor_1.isSamePeerDescriptor)(targetPeerDescriptor, this.ownPeerDescriptor)) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
const peerKey = (0, peerIdFromPeerDescriptor_1.keyFromPeerDescriptor)(remotePeerDescriptor);
|
|
160
|
+
const connection = this.ongoingConnectAttempts.get(peerKey)?.getWebRtcConnection();
|
|
161
|
+
if (!connection) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
else if (connection.connectionId.toString() !== connectionId) {
|
|
165
|
+
logger.trace(`Ignoring RTC answer due to connectionId mismatch`);
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
connection.setRemoteDescription(description, 'answer');
|
|
169
|
+
}
|
|
170
|
+
onConnectionRequest(targetPeerDescriptor) {
|
|
171
|
+
if (this.stopped || this.ongoingConnectAttempts.has((0, peerIdFromPeerDescriptor_1.keyFromPeerDescriptor)(targetPeerDescriptor))) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
const managedConnection = this.connect(targetPeerDescriptor);
|
|
175
|
+
managedConnection.setPeerDescriptor(targetPeerDescriptor);
|
|
176
|
+
this.incomingConnectionCallback(managedConnection);
|
|
177
|
+
}
|
|
178
|
+
onRemoteCandidate(remotePeerDescriptor, targetPeerDescriptor, candidate, mid, connectionId) {
|
|
179
|
+
if (this.stopped || !(0, peerIdFromPeerDescriptor_1.isSamePeerDescriptor)(targetPeerDescriptor, this.ownPeerDescriptor)) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
const peerKey = (0, peerIdFromPeerDescriptor_1.keyFromPeerDescriptor)(remotePeerDescriptor);
|
|
183
|
+
const connection = this.ongoingConnectAttempts.get(peerKey)?.getWebRtcConnection();
|
|
184
|
+
if (!connection) {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
else if (connection.connectionId.toString() !== connectionId) {
|
|
188
|
+
logger.trace(`Ignoring remote candidate due to connectionId mismatch`);
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
else if (this.isIceCandidateAllowed(candidate)) {
|
|
192
|
+
connection.addRemoteCandidate(candidate, mid);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
async stop() {
|
|
196
|
+
logger.trace('stop()');
|
|
197
|
+
this.stopped = true;
|
|
198
|
+
const attempts = Array.from(this.ongoingConnectAttempts.values());
|
|
199
|
+
await Promise.allSettled(attempts.map((conn) => conn.close('OTHER')));
|
|
200
|
+
this.rpcCommunicator.stop();
|
|
201
|
+
}
|
|
202
|
+
isOffering(targetPeerDescriptor) {
|
|
203
|
+
const myId = (0, peerIdFromPeerDescriptor_1.peerIdFromPeerDescriptor)(this.ownPeerDescriptor);
|
|
204
|
+
const theirId = (0, peerIdFromPeerDescriptor_1.peerIdFromPeerDescriptor)(targetPeerDescriptor);
|
|
205
|
+
return myId.hasSmallerHashThan(theirId);
|
|
206
|
+
}
|
|
207
|
+
// IWebRTCConnector implementation
|
|
208
|
+
async requestConnection(request, _context) {
|
|
209
|
+
this.onConnectionRequest(request.requester);
|
|
210
|
+
return {};
|
|
211
|
+
}
|
|
212
|
+
async rtcOffer(request, _context) {
|
|
213
|
+
this.onRtcOffer(request.requester, request.target, request.description, request.connectionId);
|
|
214
|
+
return {};
|
|
215
|
+
}
|
|
216
|
+
async rtcAnswer(request, _context) {
|
|
217
|
+
this.onRtcAnswer(request.requester, request.target, request.description, request.connectionId);
|
|
218
|
+
return {};
|
|
219
|
+
}
|
|
220
|
+
async iceCandidate(request, _context) {
|
|
221
|
+
this.onRemoteCandidate(request.requester, request.target, request.candidate, request.mid, request.connectionId);
|
|
222
|
+
return {};
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
exports.WebRtcConnector = WebRtcConnector;
|
|
226
|
+
WebRtcConnector.WEBRTC_CONNECTOR_SERVICE_ID = 'system/webrtc_connector';
|
|
227
|
+
//# sourceMappingURL=WebRtcConnector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WebRtcConnector.js","sourceRoot":"","sources":["../../../../src/connection/WebRTC/WebRtcConnector.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mEAK+C;AAG/C,uFAAmF;AACnF,iEAA6D;AAC7D,mEAA+D;AAC/D,iFAA4F;AAE5F,wEAAoE;AACpE,0CAAuC;AACvC,0DAA2C;AAI3C,kDAAqD;AACrD,qFAI+C;AAC/C,6DA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C,iBAAkB,CAAC,CAAA;QAC9D,MAAM,OAAO,GAAG,IAAA,mDAAwB,EAAC,oBAAoB,CAAC,CAAA;QAC9D,OAAO,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAA;IAC3C,CAAC;IAED,kCAAkC;IAClC,KAAK,CAAC,iBAAiB,CAAC,OAAgC,EAAE,QAA2B;QACjF,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAAC,SAAU,CAAC,CAAA;QAC5C,OAAO,EAAE,CAAA;IACb,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,OAAiB,EAAE,QAA2B;QACzD,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,SAAU,EAAE,OAAO,CAAC,MAAO,EAAE,OAAO,CAAC,WAAW,EAAE,OAAO,CAAC,YAAY,CAAC,CAAA;QAC/F,OAAO,EAAE,CAAA;IACb,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,OAAkB,EAAE,QAA2B;QAC3D,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,SAAU,EAAE,OAAO,CAAC,MAAO,EAAE,OAAO,CAAC,WAAW,EAAE,OAAO,CAAC,YAAY,CAAC,CAAA;QAChG,OAAO,EAAE,CAAA;IACb,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,OAAqB,EAAE,QAA2B;QACjE,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,SAAU,EAAE,OAAO,CAAC,MAAO,EAAE,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,YAAY,CAAC,CAAA;QACjH,OAAO,EAAE,CAAA;IACb,CAAC;;AAjQL,0CAkQC;AAjQ2B,2CAA2B,GAAG,yBAAyB,AAA5B,CAA4B"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.iceServerAsString = void 0;
|
|
4
|
+
function iceServerAsString({ url, port, username, password, tcp }) {
|
|
5
|
+
const [protocol, hostname] = url.split(':');
|
|
6
|
+
if (hostname === undefined) {
|
|
7
|
+
throw new Error(`invalid stun/turn format: ${url}`);
|
|
8
|
+
}
|
|
9
|
+
if (username === undefined && password === undefined) {
|
|
10
|
+
return `${protocol}:${hostname}:${port}`;
|
|
11
|
+
}
|
|
12
|
+
if (username !== undefined && password !== undefined) {
|
|
13
|
+
return `${protocol}:${username}:${password}@${hostname}:${port}${tcp ? '?transport=tcp' : ''}`;
|
|
14
|
+
}
|
|
15
|
+
throw new Error(`username (${username}) and password (${password}) must be supplied together`);
|
|
16
|
+
}
|
|
17
|
+
exports.iceServerAsString = iceServerAsString;
|
|
18
|
+
//# sourceMappingURL=iceServerAsString.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iceServerAsString.js","sourceRoot":"","sources":["../../../../src/connection/WebRTC/iceServerAsString.ts"],"names":[],"mappings":";;;AAEA,SAAgB,iBAAiB,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,EAAa;IAC/E,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAC3C,IAAI,QAAQ,KAAK,SAAS,EAAE;QACxB,MAAM,IAAI,KAAK,CAAC,6BAA6B,GAAG,EAAE,CAAC,CAAA;KACtD;IACD,IAAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,KAAK,SAAS,EAAE;QAClD,OAAO,GAAG,QAAQ,IAAI,QAAQ,IAAI,IAAI,EAAE,CAAA;KAC3C;IACD,IAAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,KAAK,SAAS,EAAE;QAClD,OAAO,GAAG,QAAQ,IAAI,QAAQ,IAAI,QAAQ,IAAI,QAAQ,IAAI,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,EAAE,CAAA;KACjG;IACD,MAAM,IAAI,KAAK,CAAC,aAAa,QAAQ,mBAAmB,QAAQ,6BAA6B,CAAC,CAAA;AAClG,CAAC;AAZD,8CAYC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { IConnection, ConnectionID, ConnectionType, ConnectionEvents } from '../IConnection';
|
|
2
|
+
import EventEmitter from 'eventemitter3';
|
|
3
|
+
export declare class ClientWebSocket extends EventEmitter<ConnectionEvents> implements IConnection {
|
|
4
|
+
readonly connectionId: ConnectionID;
|
|
5
|
+
private socket?;
|
|
6
|
+
connectionType: ConnectionType;
|
|
7
|
+
private stopped;
|
|
8
|
+
constructor();
|
|
9
|
+
connect(address: string): void;
|
|
10
|
+
private doDisconnect;
|
|
11
|
+
send(data: Uint8Array): void;
|
|
12
|
+
close(): Promise<void>;
|
|
13
|
+
private stopListening;
|
|
14
|
+
destroy(): void;
|
|
15
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
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.ClientWebSocket = void 0;
|
|
7
|
+
const IConnection_1 = require("../IConnection");
|
|
8
|
+
const websocket_1 = require("websocket");
|
|
9
|
+
const eventemitter3_1 = __importDefault(require("eventemitter3"));
|
|
10
|
+
const utils_1 = require("@streamr/utils");
|
|
11
|
+
const logger = new utils_1.Logger(module);
|
|
12
|
+
const BINARY_TYPE = 'arraybuffer';
|
|
13
|
+
class ClientWebSocket extends eventemitter3_1.default {
|
|
14
|
+
constructor() {
|
|
15
|
+
super();
|
|
16
|
+
this.connectionType = IConnection_1.ConnectionType.WEBSOCKET_CLIENT;
|
|
17
|
+
this.stopped = false;
|
|
18
|
+
this.connectionId = new IConnection_1.ConnectionID();
|
|
19
|
+
}
|
|
20
|
+
connect(address) {
|
|
21
|
+
if (!this.stopped) {
|
|
22
|
+
this.socket = new websocket_1.w3cwebsocket(address);
|
|
23
|
+
this.socket.binaryType = BINARY_TYPE;
|
|
24
|
+
this.socket.onerror = (error) => {
|
|
25
|
+
if (!this.stopped) {
|
|
26
|
+
logger.trace('WebSocket Client error: ' + error);
|
|
27
|
+
this.emit('error', error.name);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
this.socket.onopen = () => {
|
|
31
|
+
if (!this.stopped) {
|
|
32
|
+
logger.trace('WebSocket Client Connected');
|
|
33
|
+
if (this.socket && this.socket.readyState === this.socket.OPEN) {
|
|
34
|
+
this.emit('connected');
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
this.socket.onclose = (event) => {
|
|
39
|
+
if (!this.stopped) {
|
|
40
|
+
logger.trace('Websocket Closed');
|
|
41
|
+
this.doDisconnect('OTHER', event.code, event.reason);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
this.socket.onmessage = (message) => {
|
|
45
|
+
if (!this.stopped) {
|
|
46
|
+
if (typeof message.data === 'string') {
|
|
47
|
+
logger.debug('Received string: \'' + message.data + '\'');
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
this.emit('data', new Uint8Array(message.data));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
logger.debug('Tried to connect() a stopped connection');
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
doDisconnect(disconnectionType, code, reason) {
|
|
60
|
+
this.stopped = true;
|
|
61
|
+
this.stopListening();
|
|
62
|
+
this.socket = undefined;
|
|
63
|
+
this.emit('disconnected', disconnectionType, code, reason);
|
|
64
|
+
this.removeAllListeners();
|
|
65
|
+
}
|
|
66
|
+
send(data) {
|
|
67
|
+
if (!this.stopped) {
|
|
68
|
+
if (this.socket && this.socket.readyState === this.socket.OPEN) {
|
|
69
|
+
logger.trace(`Sending data with size ${data.byteLength}`);
|
|
70
|
+
this.socket?.send(data.buffer);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
logger.warn('Tried to send data on a non-open connection');
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
logger.debug('Tried to send() on stopped connection');
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
async close() {
|
|
81
|
+
if (!this.stopped) {
|
|
82
|
+
logger.trace(`Closing socket for connection ${this.connectionId.toString()}`);
|
|
83
|
+
this.socket?.close();
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
logger.debug('Tried to close() a stopped connection');
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
stopListening() {
|
|
90
|
+
if (this.socket) {
|
|
91
|
+
this.socket.onopen = undefined;
|
|
92
|
+
this.socket.onclose = undefined;
|
|
93
|
+
this.socket.onerror = undefined;
|
|
94
|
+
this.socket.onmessage = undefined;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
destroy() {
|
|
98
|
+
if (!this.stopped) {
|
|
99
|
+
this.removeAllListeners();
|
|
100
|
+
if (this.socket) {
|
|
101
|
+
this.stopListening();
|
|
102
|
+
this.socket.close();
|
|
103
|
+
this.socket = undefined;
|
|
104
|
+
}
|
|
105
|
+
this.stopped = true;
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
logger.debug('Tried to destroy() a stopped connection');
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
exports.ClientWebSocket = ClientWebSocket;
|
|
113
|
+
//# sourceMappingURL=ClientWebSocket.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ClientWebSocket.js","sourceRoot":"","sources":["../../../../src/connection/WebSocket/ClientWebSocket.ts"],"names":[],"mappings":";;;;;;AAAA,gDAA4F;AAC5F,yCAAiF;AACjF,kEAAwC;AACxC,0CAAuC;AAGvC,MAAM,MAAM,GAAG,IAAI,cAAM,CAAC,MAAM,C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} from '../../proto/packages/dht/protos/DhtRpc.client';
|
|
3
|
+
import { ProtoRpcClient } from '@streamr/proto-rpc';
|
|
4
|
+
export declare class RemoteWebSocketConnector {
|
|
5
|
+
private peerDescriptor;
|
|
6
|
+
private client;
|
|
7
|
+
constructor(peerDescriptor: PeerDescriptor, client: ProtoRpcClient<IWebSocketConnectorServiceClient>);
|
|
8
|
+
requestConnection(sourceDescriptor: PeerDescriptor, ip: string, port: number): Promise<boolean>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
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.RemoteWebSocketConnector = void 0;
|
|
27
|
+
const utils_1 = require("@streamr/utils");
|
|
28
|
+
const Err = __importStar(require("../../helpers/errors"));
|
|
29
|
+
const logger = new utils_1.Logger(module);
|
|
30
|
+
class RemoteWebSocketConnector {
|
|
31
|
+
constructor(peerDescriptor, client) {
|
|
32
|
+
this.peerDescriptor = peerDescriptor;
|
|
33
|
+
this.client = client;
|
|
34
|
+
}
|
|
35
|
+
async requestConnection(sourceDescriptor, ip, port) {
|
|
36
|
+
logger.trace(`Requesting WebSocket connection from ${this.peerDescriptor.kademliaId.toString()}`);
|
|
37
|
+
const request = {
|
|
38
|
+
target: this.peerDescriptor,
|
|
39
|
+
requester: sourceDescriptor,
|
|
40
|
+
ip,
|
|
41
|
+
port
|
|
42
|
+
};
|
|
43
|
+
const options = {
|
|
44
|
+
sourceDescriptor: sourceDescriptor,
|
|
45
|
+
targetDescriptor: this.peerDescriptor
|
|
46
|
+
};
|
|
47
|
+
try {
|
|
48
|
+
const res = await this.client.requestConnection(request, options);
|
|
49
|
+
if (res.reason) {
|
|
50
|
+
logger.debug('WebSocketConnectionRequest Rejected', {
|
|
51
|
+
stack: new Err.WebSocketConnectionRequestRejected(res.reason).stack
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
return res.accepted;
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
logger.debug(new Err.WebSocketConnectionRequestRejected('WebSocketConnectionRequest rejected', err).stack);
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.RemoteWebSocketConnector = RemoteWebSocketConnector;
|
|
63
|
+
//# sourceMappingURL=RemoteWebSocketConnector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RemoteWebSocketConnector.js","sourceRoot":"","sources":["../../../../src/connection/WebSocket/RemoteWebSocketConnector.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,0CAAuC;AACvC,0DAA2C;AAG3C,M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ter3';
|
|
3
|
+
import { IConnection, ConnectionID, ConnectionEvents, ConnectionType } from '../IConnection';
|
|
4
|
+
import { connection as WsConnection } from 'websocket';
|
|
5
|
+
import { Url } from 'url';
|
|
6
|
+
export declare class ServerWebSocket extends EventEmitter<ConnectionEvents> implements IConnection {
|
|
7
|
+
readonly connectionId: ConnectionID;
|
|
8
|
+
readonly connectionType = ConnectionType.WEBSOCKET_SERVER;
|
|
9
|
+
readonly resourceURL: Url;
|
|
10
|
+
private socket?;
|
|
11
|
+
private stopped;
|
|
12
|
+
constructor(socket: WsConnection, resourceURL: Url);
|
|
13
|
+
private doDisconnect;
|
|
14
|
+
send(data: Uint8Array): void;
|
|
15
|
+
close(): Promise<void>;
|
|
16
|
+
destroy(): void;
|
|
17
|
+
getRemoteAddress(): string;
|
|
18
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
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.ServerWebSocket = void 0;
|
|
7
|
+
const eventemitter3_1 = __importDefault(require("eventemitter3"));
|
|
8
|
+
const IConnection_1 = require("../IConnection");
|
|
9
|
+
const utils_1 = require("@streamr/utils");
|
|
10
|
+
const logger = new utils_1.Logger(module);
|
|
11
|
+
var MessageType;
|
|
12
|
+
(function (MessageType) {
|
|
13
|
+
MessageType["UTF8"] = "utf8";
|
|
14
|
+
MessageType["BINARY"] = "binary";
|
|
15
|
+
})(MessageType || (MessageType = {}));
|
|
16
|
+
class ServerWebSocket extends eventemitter3_1.default {
|
|
17
|
+
constructor(socket, resourceURL) {
|
|
18
|
+
super();
|
|
19
|
+
this.connectionType = IConnection_1.ConnectionType.WEBSOCKET_SERVER;
|
|
20
|
+
this.stopped = false;
|
|
21
|
+
this.resourceURL = resourceURL;
|
|
22
|
+
this.connectionId = new IConnection_1.ConnectionID();
|
|
23
|
+
socket.on('message', (message) => {
|
|
24
|
+
if (!this.stopped) {
|
|
25
|
+
logger.trace('ServerWebSocket::onMessage');
|
|
26
|
+
if (message.type === MessageType.UTF8) {
|
|
27
|
+
logger.debug('Received string Message: ' + message.utf8Data);
|
|
28
|
+
}
|
|
29
|
+
else if (message.type === MessageType.BINARY) {
|
|
30
|
+
logger.trace('Received Binary Message of ' + message.binaryData.length + ' bytes');
|
|
31
|
+
this.emit('data', new Uint8Array(message.binaryData.buffer, message.binaryData.byteOffset, message.binaryData.byteLength / Uint8Array.BYTES_PER_ELEMENT));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
socket.on('close', (reasonCode, description) => {
|
|
36
|
+
if (!this.stopped) {
|
|
37
|
+
logger.trace(' Peer ' + socket.remoteAddress + ' disconnected.');
|
|
38
|
+
this.doDisconnect('OTHER', reasonCode, description);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
socket.on('error', (error) => {
|
|
42
|
+
if (!this.stopped) {
|
|
43
|
+
this.emit('error', error.name);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
this.socket = socket;
|
|
47
|
+
}
|
|
48
|
+
doDisconnect(disconnectionType, reasonCode, description) {
|
|
49
|
+
this.stopped = true;
|
|
50
|
+
this.socket?.removeAllListeners();
|
|
51
|
+
this.socket = undefined;
|
|
52
|
+
this.emit('disconnected', disconnectionType, reasonCode, description);
|
|
53
|
+
this.removeAllListeners();
|
|
54
|
+
}
|
|
55
|
+
send(data) {
|
|
56
|
+
// If in an Karma / Electron test, use the NodeJS implementation
|
|
57
|
+
// of Buffer instead of the browser polyfill
|
|
58
|
+
if (!this.stopped && this.socket) {
|
|
59
|
+
if (typeof NodeJsBuffer !== 'undefined') {
|
|
60
|
+
this.socket.sendBytes(NodeJsBuffer.from(data));
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
this.socket.sendBytes(Buffer.from(data));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
logger.error('Tried to call send() on a stopped socket');
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
async close() {
|
|
71
|
+
if (!this.stopped) {
|
|
72
|
+
this.socket?.close();
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
logger.error('Tried to close a stopped connection');
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
destroy() {
|
|
79
|
+
if (!this.stopped) {
|
|
80
|
+
this.removeAllListeners();
|
|
81
|
+
if (this.socket) {
|
|
82
|
+
this.socket.removeAllListeners();
|
|
83
|
+
this.socket.close();
|
|
84
|
+
this.socket = undefined;
|
|
85
|
+
}
|
|
86
|
+
this.stopped = true;
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
logger.error('Tried to destroy() a stopped connection');
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
getRemoteAddress() {
|
|
93
|
+
if (!this.stopped && this.socket) {
|
|
94
|
+
return this.socket.remoteAddress;
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
logger.error('Tried to get the remoteAddress of a stopped connection');
|
|
98
|
+
return '';
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
exports.ServerWebSocket = ServerWebSocket;
|
|
103
|
+
//# sourceMappingURL=ServerWebSocket.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ServerWebSocket.js","sourceRoot":"","sources":["../../../../src/connection/WebSocket/ServerWebSocket.ts"],"names":[],"mappings":";;;;;;AAAA,kEAAwC;AACxC,gDAA4F;AAE5F,0CAAuC;AAIvC,MAAM,MAAM,GAAG,IAAI,cAAM,CAAC,MAAM,CAAC,CAAA;AAQjC,IAAK,WAGJ;AAHD,WAAK,WAAW;IACZ,4BAAa,CAAA;IACb,gCAAiB,CAAA;AACrB,CAAC,EAHI,WAAW,KAAX,WAAW,QAGf;AAED,MAAa,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AC,KAAK,CAAC,qCAAqC,CAAC,CAAA;SACtD;IACL,CAAC;IAEM,OAAO;QACV,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;YACf,IAAI,CAAC,kBAAkB,EAAE,CAAA;YACzB,IAAI,IAAI,CAAC,MAAM,EAAE;gBACb,IAAI,CAAC,MAAM,CAAC,kBAAkB,EAAE,CAAA;gBAChC,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAA;gBACnB,IAAI,CAAC,MAAM,GAAG,SAAS,CAAA;aAC1B;YACD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAA;SACtB;aAAM;YACH,MAAM,CAAC,KAAK,CAAC,yCAAyC,CAAC,CAAA;SAC1D;IACL,CAAC;IAEM,gBAAgB;QACnB,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,MAAM,EAAE;YAC9B,OAAO,IAAI,CAAC,MAAM,CAAC,aAAa,CAAA;SACnC;aAAM;YACH,MAAM,CAAC,KAAK,CAAC,wDAAwD,CAAC,CAAA;YACtE,OAAO,EAAE,CAAA;SACZ;IACL,CAAC;CACJ;AAlGD,0CAkGC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ITransport } from '../../transport/ITransport';
|
|
2
|
+
import { ConnectivityResponse, PeerDescriptor, WebSocketConnectionRequest, WebSocketConnectionResponse } from '../../proto/packages/dht/protos/DhtRpc';
|
|
3
|
+
import { IWebSocketConnectorService } from '../../proto/packages/dht/protos/DhtRpc.server';
|
|
4
|
+
import { ServerCallContext } from '@protobuf-ts/runtime-rpc';
|
|
5
|
+
import { ManagedConnection } from '../ManagedConnection';
|
|
6
|
+
export declare class WebSocketConnector implements IWebSocketConnectorService {
|
|
7
|
+
private static readonly WEBSOCKET_CONNECTOR_SERVICE_ID;
|
|
8
|
+
private readonly rpcCommunicator;
|
|
9
|
+
private readonly canConnectFunction;
|
|
10
|
+
private readonly webSocketServer?;
|
|
11
|
+
private readonly connectivityChecker;
|
|
12
|
+
private readonly ongoingConnectRequests;
|
|
13
|
+
private incomingConnectionCallback;
|
|
14
|
+
private webSocketPort?;
|
|
15
|
+
private webSocketHost?;
|
|
16
|
+
private entrypoints?;
|
|
17
|
+
private readonly protocolVersion;
|
|
18
|
+
private ownPeerDescriptor?;
|
|
19
|
+
private connectingConnections;
|
|
20
|
+
private stopped;
|
|
21
|
+
constructor(protocolVersion: string, rpcTransport: ITransport, fnCanConnect: (peerDescriptor: PeerDescriptor, _ip: string, port: number) => boolean, incomingConnectionCallback: (connection: ManagedConnection) => boolean, webSocketPort?: number, webSocketHost?: string, entrypoints?: PeerDescriptor[]);
|
|
22
|
+
private attachHandshaker;
|
|
23
|
+
start(): Promise<void>;
|
|
24
|
+
checkConnectivity(reattempt?: number): Promise<ConnectivityResponse>;
|
|
25
|
+
connect(targetPeerDescriptor: PeerDescriptor): ManagedConnection;
|
|
26
|
+
requestConnectionFromPeer(ownPeerDescriptor: PeerDescriptor, targetPeerDescriptor: PeerDescriptor): ManagedConnection;
|
|
27
|
+
private onServerSocketHandshakeRequest;
|
|
28
|
+
setOwnPeerDescriptor(ownPeerDescriptor: PeerDescriptor): void;
|
|
29
|
+
stop(): Promise<void>;
|
|
30
|
+
requestConnection(request: WebSocketConnectionRequest, _context: ServerCallContext): Promise<WebSocketConnectionResponse>;
|
|
31
|
+
}
|