@streamr/dht 100.0.0-pretestnet.6 → 100.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +90 -8
- package/dist/package.json +70 -0
- package/dist/src/connection/Connection.d.ts +1 -0
- package/dist/src/connection/Connection.js +10 -3
- package/dist/src/connection/Connection.js.map +1 -1
- package/dist/src/connection/ConnectionLockHandler.d.ts +14 -14
- package/dist/src/connection/ConnectionLockHandler.js +22 -16
- package/dist/src/connection/ConnectionLockHandler.js.map +1 -1
- package/dist/src/connection/ConnectionLockRpcLocal.d.ts +3 -3
- package/dist/src/connection/ConnectionLockRpcLocal.js +7 -6
- package/dist/src/connection/ConnectionLockRpcLocal.js.map +1 -1
- package/dist/src/connection/ConnectionLockRpcRemote.d.ts +4 -6
- package/dist/src/connection/ConnectionLockRpcRemote.js +10 -37
- package/dist/src/connection/ConnectionLockRpcRemote.js.map +1 -1
- package/dist/src/connection/ConnectionManager.d.ts +19 -20
- package/dist/src/connection/ConnectionManager.js +132 -117
- package/dist/src/connection/ConnectionManager.js.map +1 -1
- package/dist/src/connection/ConnectorFacade.d.ts +3 -2
- package/dist/src/connection/ConnectorFacade.js +10 -3
- package/dist/src/connection/ConnectorFacade.js.map +1 -1
- package/dist/src/connection/Handshaker.d.ts +3 -1
- package/dist/src/connection/Handshaker.js +19 -10
- package/dist/src/connection/Handshaker.js.map +1 -1
- package/dist/src/connection/IConnection.d.ts +2 -7
- package/dist/src/connection/IConnection.js +1 -8
- package/dist/src/connection/IConnection.js.map +1 -1
- package/dist/src/connection/ManagedConnection.d.ts +5 -7
- package/dist/src/connection/ManagedConnection.js +42 -26
- package/dist/src/connection/ManagedConnection.js.map +1 -1
- package/dist/src/connection/ManagedWebrtcConnection.js.map +1 -1
- package/dist/src/connection/connectivityChecker.d.ts +9 -0
- package/dist/src/connection/connectivityChecker.js +130 -0
- package/dist/src/connection/connectivityChecker.js.map +1 -0
- package/dist/src/connection/connectivityRequestHandler.d.ts +3 -0
- package/dist/src/connection/connectivityRequestHandler.js +101 -0
- package/dist/src/connection/connectivityRequestHandler.js.map +1 -0
- package/dist/src/connection/simulator/Simulator.d.ts +0 -3
- package/dist/src/connection/simulator/Simulator.js +34 -69
- package/dist/src/connection/simulator/Simulator.js.map +1 -1
- package/dist/src/connection/simulator/SimulatorConnection.js +27 -25
- package/dist/src/connection/simulator/SimulatorConnection.js.map +1 -1
- package/dist/src/connection/simulator/SimulatorConnector.js +16 -12
- package/dist/src/connection/simulator/SimulatorConnector.js.map +1 -1
- package/dist/src/connection/simulator/pings.js.map +1 -1
- package/dist/src/connection/webrtc/NodeWebrtcConnection.d.ts +2 -3
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js +40 -27
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnector.d.ts +1 -2
- package/dist/src/connection/webrtc/WebrtcConnector.js +36 -32
- package/dist/src/connection/webrtc/WebrtcConnector.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.d.ts +4 -2
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js +28 -22
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.d.ts +3 -6
- package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.js +2 -5
- package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.js.map +1 -1
- package/dist/src/connection/webrtc/iceServerAsString.js +1 -1
- package/dist/src/connection/webrtc/iceServerAsString.js.map +1 -1
- package/dist/src/connection/websocket/AutoCertifierClientFacade.d.ts +1 -2
- package/dist/src/connection/websocket/AutoCertifierClientFacade.js +6 -4
- package/dist/src/connection/websocket/AutoCertifierClientFacade.js.map +1 -1
- package/dist/src/connection/websocket/ClientWebsocket.d.ts +1 -0
- package/dist/src/connection/websocket/ClientWebsocket.js +14 -7
- package/dist/src/connection/websocket/ClientWebsocket.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnector.d.ts +3 -9
- package/dist/src/connection/websocket/WebsocketConnector.js +142 -74
- package/dist/src/connection/websocket/WebsocketConnector.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.d.ts +5 -3
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.js +9 -12
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.d.ts +4 -7
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.js +7 -44
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketServer.d.ts +1 -4
- package/dist/src/connection/websocket/WebsocketServer.js +49 -40
- package/dist/src/connection/websocket/WebsocketServer.js.map +1 -1
- package/dist/src/connection/websocket/{ServerWebsocket.d.ts → WebsocketServerConnection.d.ts} +8 -4
- package/dist/src/connection/websocket/WebsocketServerConnection.js +97 -0
- package/dist/src/connection/websocket/WebsocketServerConnection.js.map +1 -0
- package/dist/src/dht/DhtNode.d.ts +45 -49
- package/dist/src/dht/DhtNode.js +229 -317
- package/dist/src/dht/DhtNode.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcLocal.d.ts +10 -9
- package/dist/src/dht/DhtNodeRpcLocal.js +19 -11
- package/dist/src/dht/DhtNodeRpcLocal.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcRemote.d.ts +15 -10
- package/dist/src/dht/DhtNodeRpcRemote.js +38 -21
- package/dist/src/dht/DhtNodeRpcRemote.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcLocal.d.ts +7 -6
- package/dist/src/dht/ExternalApiRpcLocal.js +9 -13
- package/dist/src/dht/ExternalApiRpcLocal.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcRemote.d.ts +6 -5
- package/dist/src/dht/ExternalApiRpcRemote.js +10 -7
- package/dist/src/dht/ExternalApiRpcRemote.js.map +1 -1
- package/dist/src/dht/PeerManager.d.ts +61 -0
- package/dist/src/dht/PeerManager.js +288 -0
- package/dist/src/dht/PeerManager.js.map +1 -0
- package/dist/src/dht/contact/Contact.d.ts +2 -2
- package/dist/src/dht/contact/Contact.js +4 -3
- package/dist/src/dht/contact/Contact.js.map +1 -1
- package/dist/src/dht/contact/ContactList.d.ts +8 -8
- package/dist/src/dht/contact/ContactList.js +12 -7
- package/dist/src/dht/contact/ContactList.js.map +1 -1
- package/dist/src/dht/contact/RandomContactList.d.ts +4 -4
- package/dist/src/dht/contact/RandomContactList.js +13 -12
- package/dist/src/dht/contact/RandomContactList.js.map +1 -1
- package/dist/src/dht/contact/RingContactList.d.ts +31 -0
- package/dist/src/dht/contact/RingContactList.js +133 -0
- package/dist/src/dht/contact/RingContactList.js.map +1 -0
- package/dist/src/dht/contact/{Remote.d.ts → RpcRemote.d.ts} +8 -7
- package/dist/src/dht/contact/{Remote.js → RpcRemote.js} +16 -13
- package/dist/src/dht/contact/RpcRemote.js.map +1 -0
- package/dist/src/dht/contact/SortedContactList.d.ts +29 -15
- package/dist/src/dht/contact/SortedContactList.js +79 -42
- package/dist/src/dht/contact/SortedContactList.js.map +1 -1
- package/dist/src/dht/contact/ringIdentifiers.d.ts +16 -0
- package/dist/src/dht/contact/ringIdentifiers.js +54 -0
- package/dist/src/dht/contact/ringIdentifiers.js.map +1 -0
- package/dist/src/dht/discovery/DiscoverySession.d.ts +8 -18
- package/dist/src/dht/discovery/DiscoverySession.js +32 -48
- package/dist/src/dht/discovery/DiscoverySession.js.map +1 -1
- package/dist/src/dht/discovery/PeerDiscovery.d.ts +16 -12
- package/dist/src/dht/discovery/PeerDiscovery.js +82 -39
- package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -1
- package/dist/src/dht/discovery/RingDiscoverySession.d.ts +29 -0
- package/dist/src/dht/discovery/RingDiscoverySession.js +123 -0
- package/dist/src/dht/discovery/RingDiscoverySession.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.d.ts +36 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.js +166 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.d.ts +14 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.js +26 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.d.ts +6 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js +44 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.d.ts +44 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.js +187 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.d.ts +14 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js +20 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.d.ts +6 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.js +21 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.js.map +1 -0
- package/dist/src/dht/routing/DuplicateDetector.d.ts +2 -4
- package/dist/src/dht/routing/DuplicateDetector.js +10 -15
- package/dist/src/dht/routing/DuplicateDetector.js.map +1 -1
- package/dist/src/dht/routing/Router.d.ts +11 -27
- package/dist/src/dht/routing/Router.js +92 -58
- package/dist/src/dht/routing/Router.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcLocal.d.ts +3 -4
- package/dist/src/dht/routing/RouterRpcLocal.js +17 -16
- package/dist/src/dht/routing/RouterRpcLocal.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcRemote.d.ts +3 -3
- package/dist/src/dht/routing/RouterRpcRemote.js +29 -20
- package/dist/src/dht/routing/RouterRpcRemote.js.map +1 -1
- package/dist/src/dht/routing/RoutingSession.d.ts +29 -21
- package/dist/src/dht/routing/RoutingSession.js +93 -68
- package/dist/src/dht/routing/RoutingSession.js.map +1 -1
- package/dist/src/dht/routing/RoutingTablesCache.d.ts +24 -0
- package/dist/src/dht/routing/RoutingTablesCache.js +46 -0
- package/dist/src/dht/routing/RoutingTablesCache.js.map +1 -0
- package/dist/src/dht/routing/getPreviousPeer.js.map +1 -1
- package/dist/src/dht/store/LocalDataStore.d.ts +9 -14
- package/dist/src/dht/store/LocalDataStore.js +46 -72
- package/dist/src/dht/store/LocalDataStore.js.map +1 -1
- package/dist/src/dht/store/StoreManager.d.ts +33 -0
- package/dist/src/dht/store/StoreManager.js +182 -0
- package/dist/src/dht/store/StoreManager.js.map +1 -0
- package/dist/src/dht/store/StoreRpcLocal.d.ts +11 -41
- package/dist/src/dht/store/StoreRpcLocal.js +27 -234
- package/dist/src/dht/store/StoreRpcLocal.js.map +1 -1
- package/dist/src/dht/store/StoreRpcRemote.d.ts +6 -7
- package/dist/src/dht/store/StoreRpcRemote.js +10 -20
- package/dist/src/dht/store/StoreRpcRemote.js.map +1 -1
- package/dist/src/exports.d.ts +5 -3
- package/dist/src/exports.js +10 -8
- package/dist/src/exports.js.map +1 -1
- package/dist/src/helpers/AddressTools.js +2 -0
- package/dist/src/helpers/AddressTools.js.map +1 -1
- package/dist/src/helpers/Connectivity.js.map +1 -1
- package/dist/src/helpers/MapWithTtl.d.ts +14 -0
- package/dist/src/helpers/MapWithTtl.js +60 -0
- package/dist/src/helpers/MapWithTtl.js.map +1 -0
- package/dist/src/helpers/createPeerDescriptor.d.ts +3 -0
- package/dist/src/helpers/createPeerDescriptor.js +57 -0
- package/dist/src/helpers/createPeerDescriptor.js.map +1 -0
- package/dist/src/helpers/createPeerDescriptorSignaturePayload.d.ts +2 -0
- package/dist/src/helpers/createPeerDescriptorSignaturePayload.js +30 -0
- package/dist/src/helpers/createPeerDescriptorSignaturePayload.js.map +1 -0
- package/dist/src/helpers/debugHelpers.js.map +1 -1
- package/dist/src/helpers/errors.js +2 -0
- package/dist/src/helpers/errors.js.map +1 -1
- package/dist/src/helpers/offering.d.ts +4 -0
- package/dist/src/helpers/offering.js +18 -0
- package/dist/src/helpers/offering.js.map +1 -0
- package/dist/src/helpers/protoClasses.js +2 -3
- package/dist/src/helpers/protoClasses.js.map +1 -1
- package/dist/src/helpers/protoToString.js.map +1 -1
- package/dist/src/helpers/version.d.ts +6 -0
- package/dist/src/helpers/version.js +38 -0
- package/dist/src/helpers/version.js.map +1 -0
- package/dist/src/identifiers.d.ts +10 -0
- package/dist/src/identifiers.js +31 -0
- package/dist/src/identifiers.js.map +1 -0
- package/dist/src/proto/google/protobuf/any.js +8 -8
- package/dist/src/proto/google/protobuf/any.js.map +1 -1
- package/dist/src/proto/google/protobuf/empty.js +2 -4
- package/dist/src/proto/google/protobuf/empty.js.map +1 -1
- package/dist/src/proto/google/protobuf/timestamp.js +10 -10
- package/dist/src/proto/google/protobuf/timestamp.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +46 -49
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +63 -54
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +226 -232
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +146 -168
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +26 -29
- package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.js +1 -1
- package/dist/src/rpc-protocol/DhtCallContext.d.ts +2 -2
- package/dist/src/rpc-protocol/DhtCallContext.js +8 -0
- package/dist/src/rpc-protocol/DhtCallContext.js.map +1 -1
- package/dist/src/rpc-protocol/DhtRpcOptions.d.ts +2 -1
- package/dist/src/transport/ITransport.d.ts +10 -2
- package/dist/src/transport/ITransport.js +5 -0
- package/dist/src/transport/ITransport.js.map +1 -1
- package/dist/src/transport/ListeningRpcCommunicator.js +3 -1
- package/dist/src/transport/ListeningRpcCommunicator.js.map +1 -1
- package/dist/src/transport/RoutingRpcCommunicator.d.ts +4 -2
- package/dist/src/transport/RoutingRpcCommunicator.js +19 -12
- package/dist/src/transport/RoutingRpcCommunicator.js.map +1 -1
- package/jest.config.js +4 -1
- package/karma-setup.js +2 -0
- package/karma.config.js +13 -9
- package/package.json +17 -14
- package/protos/DhtRpc.proto +76 -76
- package/src/connection/Connection.ts +6 -1
- package/src/connection/ConnectionLockHandler.ts +30 -22
- package/src/connection/ConnectionLockRpcLocal.ts +7 -12
- package/src/connection/ConnectionLockRpcRemote.ts +9 -19
- package/src/connection/ConnectionManager.ts +132 -138
- package/src/connection/ConnectorFacade.ts +10 -9
- package/src/connection/Handshaker.ts +24 -12
- package/src/connection/IConnection.ts +2 -8
- package/src/connection/ManagedConnection.ts +34 -35
- package/src/connection/connectivityChecker.ts +109 -0
- package/src/connection/connectivityRequestHandler.ts +103 -0
- package/src/connection/simulator/Simulator.ts +6 -37
- package/src/connection/simulator/SimulatorConnection.ts +23 -25
- package/src/connection/simulator/SimulatorConnector.ts +11 -11
- package/src/connection/webrtc/BrowserWebrtcConnection.ts +17 -25
- package/src/connection/webrtc/NodeWebrtcConnection.ts +25 -27
- package/src/connection/webrtc/WebrtcConnector.ts +31 -36
- package/src/connection/webrtc/WebrtcConnectorRpcLocal.ts +31 -25
- package/src/connection/webrtc/WebrtcConnectorRpcRemote.ts +4 -14
- package/src/connection/webrtc/iceServerAsString.ts +1 -1
- package/src/connection/websocket/AutoCertifierClientFacade.ts +4 -6
- package/src/connection/websocket/ClientWebsocket.ts +10 -4
- package/src/connection/websocket/WebsocketConnector.ts +120 -97
- package/src/connection/websocket/WebsocketConnectorRpcLocal.ts +13 -15
- package/src/connection/websocket/WebsocketConnectorRpcRemote.ts +7 -27
- package/src/connection/websocket/WebsocketServer.ts +50 -53
- package/src/connection/websocket/WebsocketServerConnection.ts +104 -0
- package/src/dht/DhtNode.ts +289 -410
- package/src/dht/DhtNodeRpcLocal.ts +25 -17
- package/src/dht/DhtNodeRpcRemote.ts +43 -27
- package/src/dht/ExternalApiRpcLocal.ts +30 -17
- package/src/dht/ExternalApiRpcRemote.ts +14 -11
- package/src/dht/PeerManager.ts +339 -0
- package/src/dht/contact/Contact.ts +4 -4
- package/src/dht/contact/ContactList.ts +11 -10
- package/src/dht/contact/RandomContactList.ts +15 -15
- package/src/dht/contact/RingContactList.ts +151 -0
- package/src/dht/contact/{Remote.ts → RpcRemote.ts} +16 -19
- package/src/dht/contact/SortedContactList.ts +120 -72
- package/src/dht/contact/ringIdentifiers.ts +62 -0
- package/src/dht/discovery/DiscoverySession.ts +36 -61
- package/src/dht/discovery/PeerDiscovery.ts +98 -43
- package/src/dht/discovery/RingDiscoverySession.ts +160 -0
- package/src/dht/recursive-operation/RecursiveOperationManager.ts +246 -0
- package/src/dht/recursive-operation/RecursiveOperationRpcLocal.ts +34 -0
- package/src/dht/recursive-operation/RecursiveOperationRpcRemote.ts +43 -0
- package/src/dht/recursive-operation/RecursiveOperationSession.ts +232 -0
- package/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.ts +35 -0
- package/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.ts +30 -0
- package/src/dht/routing/DuplicateDetector.ts +9 -21
- package/src/dht/routing/Router.ts +95 -92
- package/src/dht/routing/RouterRpcLocal.ts +16 -18
- package/src/dht/routing/RouterRpcRemote.ts +26 -24
- package/src/dht/routing/RoutingSession.ts +119 -98
- package/src/dht/routing/RoutingTablesCache.ts +58 -0
- package/src/dht/routing/getPreviousPeer.ts +1 -1
- package/src/dht/store/LocalDataStore.ts +47 -77
- package/src/dht/store/StoreManager.ts +209 -0
- package/src/dht/store/StoreRpcLocal.ts +39 -308
- package/src/dht/store/StoreRpcRemote.ts +13 -31
- package/src/exports.ts +13 -3
- package/src/helpers/AddressTools.ts +2 -0
- package/src/helpers/MapWithTtl.ts +71 -0
- package/src/helpers/createPeerDescriptor.ts +57 -0
- package/src/helpers/createPeerDescriptorSignaturePayload.ts +28 -0
- package/src/helpers/offering.ts +15 -0
- package/src/helpers/protoClasses.ts +4 -6
- package/src/helpers/version.ts +32 -0
- package/src/identifiers.ts +29 -0
- package/src/proto/google/protobuf/any.ts +4 -4
- package/src/proto/google/protobuf/empty.ts +2 -4
- package/src/proto/google/protobuf/timestamp.ts +4 -4
- package/src/proto/packages/dht/protos/DhtRpc.client.ts +65 -68
- package/src/proto/packages/dht/protos/DhtRpc.server.ts +27 -30
- package/src/proto/packages/dht/protos/DhtRpc.ts +297 -313
- package/src/proto/packages/proto-rpc/protos/ProtoRpc.ts +1 -1
- package/src/rpc-protocol/DhtCallContext.ts +2 -2
- package/src/rpc-protocol/DhtRpcOptions.ts +2 -1
- package/src/transport/ITransport.ts +11 -2
- package/src/transport/ListeningRpcCommunicator.ts +1 -1
- package/src/transport/RoutingRpcCommunicator.ts +21 -14
- package/test/RandomGraphSimulation.ts +3 -2
- package/test/benchmark/Find.test.ts +13 -28
- package/test/benchmark/KademliaCorrectness.test.ts +24 -28
- package/test/benchmark/RingCorrectness.test.ts +157 -0
- package/test/benchmark/SortedContactListBenchmark.test.ts +151 -0
- package/test/benchmark/WebsocketServerMemoryLeak.test.ts +41 -0
- package/test/benchmark/hybrid-network-simulation/RingContactList.test.ts +72 -0
- package/test/benchmark/kademlia-simulation/Contact.ts +9 -9
- package/test/benchmark/kademlia-simulation/KademliaSimulation.ts +11 -11
- package/test/benchmark/kademlia-simulation/SimulationNode.ts +29 -25
- package/test/data/generateGroundTruthData.ts +7 -6
- package/test/end-to-end/Layer0-Layer1.test.ts +11 -15
- package/test/end-to-end/Layer0.test.ts +19 -22
- package/test/end-to-end/Layer0MixedConnectionTypes.test.ts +19 -21
- package/test/end-to-end/Layer0Webrtc-Layer1.test.ts +26 -28
- package/test/end-to-end/Layer0Webrtc.test.ts +19 -19
- package/test/end-to-end/Layer1-Scale-WebSocket.test.ts +10 -18
- package/test/end-to-end/Layer1-Scale-Webrtc.test.ts +8 -15
- package/test/end-to-end/RecoveryFromFailedAutoCertification.test.ts +2 -2
- package/test/end-to-end/WebsocketConnectionRequest.test.ts +8 -9
- package/test/end-to-end/memory-leak.test.ts +19 -24
- package/test/integration/ConnectionLocking.test.ts +66 -60
- package/test/integration/ConnectionManager.test.ts +43 -63
- package/test/integration/ConnectivityChecking.test.ts +52 -0
- package/test/integration/DhtJoinPeerDiscovery.test.ts +8 -12
- package/test/integration/DhtNodeExternalAPI.test.ts +17 -21
- package/test/integration/DhtNodeRpcRemote.test.ts +19 -26
- package/test/integration/DhtRpc.test.ts +20 -24
- package/test/integration/Find.test.ts +10 -12
- package/test/integration/Layer1-scale.test.ts +25 -37
- package/test/integration/Mock-Layer1-Layer0.test.ts +39 -59
- package/test/integration/MultipleEntryPointJoining.test.ts +14 -14
- package/test/integration/ReplicateData.test.ts +106 -0
- package/test/integration/RouteMessage.test.ts +42 -68
- package/test/integration/RouterRpcRemote.test.ts +19 -24
- package/test/integration/ScaleDownDht.test.ts +14 -12
- package/test/integration/SimultaneousConnections.test.ts +112 -111
- package/test/integration/Store.test.ts +43 -27
- package/test/integration/StoreAndDelete.test.ts +36 -48
- package/test/integration/StoreOnDhtWithThreeNodes.test.ts +59 -0
- package/test/integration/StoreOnDhtWithTwoNodes.test.ts +17 -37
- package/test/integration/StoreRpcRemote.test.ts +20 -32
- package/test/integration/WebrtcConnectionManagement.test.ts +39 -25
- package/test/integration/WebrtcConnectorRpc.test.ts +6 -11
- package/test/integration/WebsocketConnectionManagement.test.ts +87 -22
- package/test/integration/WebsocketConnectorRpc.test.ts +14 -24
- package/test/integration/{RpcErrors.test.ts → rpc-connections-over-webrpc.test.ts} +15 -26
- package/test/unit/AddressTools.test.ts +4 -0
- package/test/unit/ConnectivityHelpers.test.ts +9 -17
- package/test/unit/DuplicateDetector.test.ts +8 -5
- package/test/unit/LocalDataStore.test.ts +78 -75
- package/test/unit/PeerManager.test.ts +33 -0
- package/test/unit/RandomContactList.test.ts +12 -9
- package/test/unit/RecursiveOperationManager.test.ts +157 -0
- package/test/unit/RecursiveOperationSession.test.ts +68 -0
- package/test/unit/Router.test.ts +52 -35
- package/test/unit/RoutingSession.test.ts +79 -0
- package/test/unit/SortedContactList.test.ts +61 -30
- package/test/unit/StoreManager.test.ts +138 -0
- package/test/unit/WebsocketConnector.test.ts +27 -35
- package/test/unit/connectivityRequestHandler.test.ts +104 -0
- package/test/unit/createPeerDescriptor.test.ts +69 -0
- package/test/unit/customMatchers.test.ts +16 -0
- package/test/unit/version.test.ts +18 -0
- package/test/utils/FakeTransport.ts +47 -0
- package/test/utils/customMatchers.ts +71 -0
- package/test/utils/mock/MockRpcCommunicator.ts +7 -0
- package/test/utils/mock/Router.ts +13 -3
- package/test/utils/mock/Transport.ts +1 -1
- package/test/utils/mock/mockDataEntry.ts +38 -0
- package/test/utils/utils.ts +104 -107
- package/tsconfig.browser.json +2 -1
- package/tsconfig.jest.json +4 -2
- package/tsconfig.node.json +4 -2
- package/dist/src/connection/ConnectivityChecker.d.ts +0 -17
- package/dist/src/connection/ConnectivityChecker.js +0 -208
- package/dist/src/connection/ConnectivityChecker.js.map +0 -1
- package/dist/src/connection/websocket/ServerWebsocket.js +0 -100
- package/dist/src/connection/websocket/ServerWebsocket.js.map +0 -1
- package/dist/src/dht/contact/Remote.js.map +0 -1
- package/dist/src/dht/find/FindRpcLocal.d.ts +0 -14
- package/dist/src/dht/find/FindRpcLocal.js +0 -25
- package/dist/src/dht/find/FindRpcLocal.js.map +0 -1
- package/dist/src/dht/find/FindSession.d.ts +0 -44
- package/dist/src/dht/find/FindSession.js +0 -145
- package/dist/src/dht/find/FindSession.js.map +0 -1
- package/dist/src/dht/find/FindSessionRpcLocal.d.ts +0 -12
- package/dist/src/dht/find/FindSessionRpcLocal.js +0 -17
- package/dist/src/dht/find/FindSessionRpcLocal.js.map +0 -1
- package/dist/src/dht/find/FindSessionRpcRemote.d.ts +0 -6
- package/dist/src/dht/find/FindSessionRpcRemote.js +0 -21
- package/dist/src/dht/find/FindSessionRpcRemote.js.map +0 -1
- package/dist/src/dht/find/Finder.d.ts +0 -49
- package/dist/src/dht/find/Finder.js +0 -184
- package/dist/src/dht/find/Finder.js.map +0 -1
- package/dist/src/dht/routing/FindRpcRemote.d.ts +0 -6
- package/dist/src/dht/routing/FindRpcRemote.js +0 -41
- package/dist/src/dht/routing/FindRpcRemote.js.map +0 -1
- package/dist/src/helpers/PeerID.d.ts +0 -24
- package/dist/src/helpers/PeerID.js +0 -78
- package/dist/src/helpers/PeerID.js.map +0 -1
- package/dist/src/helpers/UUID.d.ts +0 -8
- package/dist/src/helpers/UUID.js +0 -36
- package/dist/src/helpers/UUID.js.map +0 -1
- package/dist/src/helpers/kademliaId.d.ts +0 -1
- package/dist/src/helpers/kademliaId.js +0 -14
- package/dist/src/helpers/kademliaId.js.map +0 -1
- package/dist/src/helpers/peerIdFromPeerDescriptor.d.ts +0 -6
- package/dist/src/helpers/peerIdFromPeerDescriptor.js +0 -23
- package/dist/src/helpers/peerIdFromPeerDescriptor.js.map +0 -1
- package/src/connection/ConnectivityChecker.ts +0 -199
- package/src/connection/websocket/ServerWebsocket.ts +0 -114
- package/src/dht/find/FindRpcLocal.ts +0 -35
- package/src/dht/find/FindSession.ts +0 -178
- package/src/dht/find/FindSessionRpcLocal.ts +0 -25
- package/src/dht/find/FindSessionRpcRemote.ts +0 -30
- package/src/dht/find/Finder.ts +0 -275
- package/src/dht/routing/FindRpcRemote.ts +0 -40
- package/src/helpers/PeerID.ts +0 -88
- package/src/helpers/UUID.ts +0 -35
- package/src/helpers/kademliaId.ts +0 -8
- package/src/helpers/peerIdFromPeerDescriptor.ts +0 -20
- package/test/integration/MigrateData.test.ts +0 -204
- package/test/unit/Finder.test.ts +0 -110
- package/test/unit/PeerID.test.ts +0 -22
- package/test/unit/UUID.test.ts +0 -55
|
@@ -4,7 +4,7 @@ import { Message, PeerDescriptor } from '../../proto/packages/dht/protos/DhtRpc'
|
|
|
4
4
|
import { Connection } from '../Connection'
|
|
5
5
|
import { Logger } from '@streamr/utils'
|
|
6
6
|
import { protoToString } from '../../helpers/protoToString'
|
|
7
|
-
import { getNodeIdFromPeerDescriptor } from '../../
|
|
7
|
+
import { getNodeIdFromPeerDescriptor } from '../../identifiers'
|
|
8
8
|
|
|
9
9
|
const logger = new Logger(module)
|
|
10
10
|
|
|
@@ -45,38 +45,34 @@ export class SimulatorConnection extends Connection implements IConnection {
|
|
|
45
45
|
this.simulator.send(this, data)
|
|
46
46
|
|
|
47
47
|
} else {
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
const localNodeId = getNodeIdFromPeerDescriptor(this.localPeerDescriptor)
|
|
49
|
+
const targetNodeId = getNodeIdFromPeerDescriptor(this.targetPeerDescriptor)
|
|
50
|
+
logger.error(localNodeId + ', ' + targetNodeId + 'tried to send() on a stopped connection')
|
|
50
51
|
}
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
public async close(gracefulLeave: boolean): Promise<void> {
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
const localNodeId = getNodeIdFromPeerDescriptor(this.localPeerDescriptor)
|
|
56
|
+
const targetNodeId = getNodeIdFromPeerDescriptor(this.targetPeerDescriptor)
|
|
56
57
|
|
|
58
|
+
logger.trace(localNodeId + ', ' + targetNodeId + ' close()')
|
|
57
59
|
if (!this.stopped) {
|
|
58
|
-
logger.trace(
|
|
59
|
-
+ getNodeIdFromPeerDescriptor(this.targetPeerDescriptor) + ' close() not stopped')
|
|
60
|
+
logger.trace(localNodeId + ', ' + targetNodeId + ' close() not stopped')
|
|
60
61
|
this.stopped = true
|
|
61
62
|
|
|
62
63
|
try {
|
|
63
|
-
logger.trace(
|
|
64
|
-
' close() calling simulator.disconnect()')
|
|
64
|
+
logger.trace(localNodeId + ', ' + targetNodeId + ' close() calling simulator.disconnect()')
|
|
65
65
|
this.simulator.close(this)
|
|
66
|
-
logger.trace(
|
|
67
|
-
' close() simulator.disconnect returned')
|
|
66
|
+
logger.trace(localNodeId + ', ' + targetNodeId + ' close() simulator.disconnect returned')
|
|
68
67
|
} catch (e) {
|
|
69
|
-
logger.trace(
|
|
70
|
-
'close aborted' + e)
|
|
68
|
+
logger.trace(localNodeId + ', ' + targetNodeId + 'close aborted' + e)
|
|
71
69
|
} finally {
|
|
72
|
-
logger.trace(
|
|
73
|
-
' calling this.doDisconnect')
|
|
70
|
+
logger.trace(localNodeId + ', ' + targetNodeId + ' calling this.doDisconnect')
|
|
74
71
|
this.doDisconnect(gracefulLeave)
|
|
75
72
|
}
|
|
76
73
|
|
|
77
74
|
} else {
|
|
78
|
-
logger.trace(
|
|
79
|
-
' close() tried to close a stopped connection')
|
|
75
|
+
logger.trace(localNodeId + ', ' + targetNodeId + ' close() tried to close a stopped connection')
|
|
80
76
|
}
|
|
81
77
|
}
|
|
82
78
|
|
|
@@ -85,7 +81,7 @@ export class SimulatorConnection extends Connection implements IConnection {
|
|
|
85
81
|
logger.trace('connect() called')
|
|
86
82
|
|
|
87
83
|
this.simulator.connect(this, this.targetPeerDescriptor, (error?: string) => {
|
|
88
|
-
if (error) {
|
|
84
|
+
if (error !== undefined) {
|
|
89
85
|
logger.trace(error)
|
|
90
86
|
this.doDisconnect(false)
|
|
91
87
|
} else {
|
|
@@ -109,7 +105,8 @@ export class SimulatorConnection extends Connection implements IConnection {
|
|
|
109
105
|
|
|
110
106
|
public handleIncomingDisconnection(): void {
|
|
111
107
|
if (!this.stopped) {
|
|
112
|
-
|
|
108
|
+
const localNodeId = getNodeIdFromPeerDescriptor(this.localPeerDescriptor)
|
|
109
|
+
logger.trace(localNodeId + ' handleIncomingDisconnection()')
|
|
113
110
|
this.stopped = true
|
|
114
111
|
this.doDisconnect(false)
|
|
115
112
|
} else {
|
|
@@ -118,23 +115,24 @@ export class SimulatorConnection extends Connection implements IConnection {
|
|
|
118
115
|
}
|
|
119
116
|
|
|
120
117
|
public destroy(): void {
|
|
118
|
+
const localNodeId = getNodeIdFromPeerDescriptor(this.localPeerDescriptor)
|
|
121
119
|
if (!this.stopped) {
|
|
122
|
-
logger.trace(
|
|
120
|
+
logger.trace(localNodeId + ' destroy()')
|
|
123
121
|
this.removeAllListeners()
|
|
124
122
|
this.close(false).catch((_e) => { })
|
|
125
123
|
} else {
|
|
126
|
-
logger.trace(
|
|
124
|
+
logger.trace(localNodeId + ' tried to call destroy() a stopped connection')
|
|
127
125
|
}
|
|
128
126
|
}
|
|
129
127
|
|
|
130
128
|
private doDisconnect(gracefulLeave: boolean) {
|
|
131
|
-
|
|
129
|
+
const localNodeId = getNodeIdFromPeerDescriptor(this.localPeerDescriptor)
|
|
130
|
+
const targetNodeId = getNodeIdFromPeerDescriptor(this.targetPeerDescriptor)
|
|
131
|
+
logger.trace(localNodeId + ' doDisconnect()')
|
|
132
132
|
this.stopped = true
|
|
133
133
|
|
|
134
|
-
logger.trace(
|
|
135
|
-
+ getNodeIdFromPeerDescriptor(this.targetPeerDescriptor) + ' doDisconnect emitting')
|
|
134
|
+
logger.trace(localNodeId + ', ' + targetNodeId + ' doDisconnect emitting')
|
|
136
135
|
|
|
137
136
|
this.emit('disconnected', gracefulLeave)
|
|
138
|
-
|
|
139
137
|
}
|
|
140
138
|
}
|
|
@@ -6,16 +6,15 @@ import {
|
|
|
6
6
|
} from '../../proto/packages/dht/protos/DhtRpc'
|
|
7
7
|
import { Logger } from '@streamr/utils'
|
|
8
8
|
import { ManagedConnection } from '../ManagedConnection'
|
|
9
|
-
import { PeerIDKey } from '../../helpers/PeerID'
|
|
10
9
|
import { Simulator } from './Simulator'
|
|
11
10
|
import { SimulatorConnection } from './SimulatorConnection'
|
|
12
|
-
import {
|
|
11
|
+
import { DhtAddress, getNodeIdFromPeerDescriptor } from '../../identifiers'
|
|
13
12
|
|
|
14
13
|
const logger = new Logger(module)
|
|
15
14
|
|
|
16
15
|
export class SimulatorConnector {
|
|
17
16
|
|
|
18
|
-
private connectingConnections: Map<
|
|
17
|
+
private connectingConnections: Map<DhtAddress, ManagedConnection> = new Map()
|
|
19
18
|
private stopped = false
|
|
20
19
|
private localPeerDescriptor: PeerDescriptor
|
|
21
20
|
private simulator: Simulator
|
|
@@ -33,8 +32,8 @@ export class SimulatorConnector {
|
|
|
33
32
|
|
|
34
33
|
public connect(targetPeerDescriptor: PeerDescriptor): ManagedConnection {
|
|
35
34
|
logger.trace('connect() ' + getNodeIdFromPeerDescriptor(targetPeerDescriptor))
|
|
36
|
-
const
|
|
37
|
-
const existingConnection = this.connectingConnections.get(
|
|
35
|
+
const nodeId = getNodeIdFromPeerDescriptor(targetPeerDescriptor)
|
|
36
|
+
const existingConnection = this.connectingConnections.get(nodeId)
|
|
38
37
|
if (existingConnection) {
|
|
39
38
|
return existingConnection
|
|
40
39
|
}
|
|
@@ -44,12 +43,12 @@ export class SimulatorConnector {
|
|
|
44
43
|
const managedConnection = new ManagedConnection(this.localPeerDescriptor, ConnectionType.SIMULATOR_CLIENT, connection, undefined)
|
|
45
44
|
managedConnection.setRemotePeerDescriptor(targetPeerDescriptor)
|
|
46
45
|
|
|
47
|
-
this.connectingConnections.set(
|
|
46
|
+
this.connectingConnections.set(nodeId, managedConnection)
|
|
48
47
|
connection.once('disconnected', () => {
|
|
49
|
-
this.connectingConnections.delete(
|
|
48
|
+
this.connectingConnections.delete(nodeId)
|
|
50
49
|
})
|
|
51
50
|
connection.once('connected', () => {
|
|
52
|
-
this.connectingConnections.delete(
|
|
51
|
+
this.connectingConnections.delete(nodeId)
|
|
53
52
|
})
|
|
54
53
|
|
|
55
54
|
connection.connect()
|
|
@@ -62,7 +61,8 @@ export class SimulatorConnector {
|
|
|
62
61
|
}
|
|
63
62
|
|
|
64
63
|
public handleIncomingConnection(sourceConnection: SimulatorConnection): void {
|
|
65
|
-
|
|
64
|
+
const localNodeId = getNodeIdFromPeerDescriptor(sourceConnection.localPeerDescriptor)
|
|
65
|
+
logger.trace(localNodeId + ' incoming connection, stopped: ' + this.stopped)
|
|
66
66
|
if (this.stopped) {
|
|
67
67
|
return
|
|
68
68
|
}
|
|
@@ -74,10 +74,10 @@ export class SimulatorConnector {
|
|
|
74
74
|
logger.trace('connected')
|
|
75
75
|
|
|
76
76
|
managedConnection.once('handshakeRequest', () => {
|
|
77
|
-
logger.trace(
|
|
77
|
+
logger.trace(localNodeId + ' incoming handshake request')
|
|
78
78
|
|
|
79
79
|
if (this.onNewConnection(managedConnection)) {
|
|
80
|
-
logger.trace(
|
|
80
|
+
logger.trace(localNodeId + ' calling acceptHandshake')
|
|
81
81
|
managedConnection.acceptHandshake()
|
|
82
82
|
} else {
|
|
83
83
|
managedConnection.rejectHandshake(HandshakeError.DUPLICATE_CONNECTION)
|
|
@@ -3,6 +3,7 @@ import { WebrtcConnectionEvents, IWebrtcConnection, RtcDescription } from './IWe
|
|
|
3
3
|
import { IConnection, ConnectionID, ConnectionEvents, ConnectionType } from '../IConnection'
|
|
4
4
|
import { Logger } from '@streamr/utils'
|
|
5
5
|
import { IceServer } from './WebrtcConnector'
|
|
6
|
+
import { createRandomConnectionId } from '../Connection'
|
|
6
7
|
|
|
7
8
|
const logger = new Logger(module)
|
|
8
9
|
|
|
@@ -22,12 +23,9 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IWebrt
|
|
|
22
23
|
|
|
23
24
|
public connectionId: ConnectionID
|
|
24
25
|
public readonly connectionType: ConnectionType = ConnectionType.WEBRTC
|
|
25
|
-
|
|
26
26
|
// We need to keep track of connection state ourselves because
|
|
27
27
|
// RTCPeerConnection.connectionState is not supported on Firefox
|
|
28
|
-
|
|
29
28
|
private lastState: RTCPeerConnectionState = 'connecting'
|
|
30
|
-
|
|
31
29
|
private readonly iceServers: IceServer[]
|
|
32
30
|
private peerConnection?: RTCPeerConnection
|
|
33
31
|
private dataChannel?: RTCDataChannel
|
|
@@ -37,7 +35,7 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IWebrt
|
|
|
37
35
|
|
|
38
36
|
constructor(params: Params) {
|
|
39
37
|
super()
|
|
40
|
-
this.connectionId =
|
|
38
|
+
this.connectionId = createRandomConnectionId()
|
|
41
39
|
this.iceServers = params.iceServers ?? []
|
|
42
40
|
}
|
|
43
41
|
|
|
@@ -51,7 +49,7 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IWebrt
|
|
|
51
49
|
this.peerConnection = new RTCPeerConnection({ iceServers: urls })
|
|
52
50
|
|
|
53
51
|
this.peerConnection.onicecandidate = (event) => {
|
|
54
|
-
if (event.candidate && event.candidate.sdpMid) {
|
|
52
|
+
if ((event.candidate !== null) && (event.candidate.sdpMid !== null)) {
|
|
55
53
|
this.emit('localCandidate', event.candidate.candidate, event.candidate.sdpMid)
|
|
56
54
|
}
|
|
57
55
|
}
|
|
@@ -63,14 +61,14 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IWebrt
|
|
|
63
61
|
if (isOffering) {
|
|
64
62
|
this.peerConnection.onnegotiationneeded = async () => {
|
|
65
63
|
try {
|
|
66
|
-
if (this.peerConnection) {
|
|
64
|
+
if (this.peerConnection !== undefined) {
|
|
67
65
|
this.makingOffer = true
|
|
68
66
|
try {
|
|
69
67
|
await this.peerConnection.setLocalDescription()
|
|
70
68
|
} catch (err) {
|
|
71
69
|
logger.warn('error', { err })
|
|
72
70
|
}
|
|
73
|
-
if (this.peerConnection.localDescription) {
|
|
71
|
+
if (this.peerConnection.localDescription !== null) {
|
|
74
72
|
this.emit('localDescription', this.peerConnection.localDescription?.sdp, this.peerConnection.localDescription?.type)
|
|
75
73
|
}
|
|
76
74
|
}
|
|
@@ -86,14 +84,12 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IWebrt
|
|
|
86
84
|
} else {
|
|
87
85
|
this.peerConnection.ondatachannel = (event) => {
|
|
88
86
|
this.setupDataChannel(event.channel)
|
|
89
|
-
logger.trace('connection.onDataChannel')
|
|
90
|
-
this.openDataChannel(event.channel)
|
|
91
87
|
}
|
|
92
88
|
}
|
|
93
89
|
}
|
|
94
90
|
|
|
95
91
|
public async setRemoteDescription(description: string, type: string): Promise<void> {
|
|
96
|
-
const offerCollision = (type.toLowerCase() === RtcDescription.OFFER) && (this.makingOffer ||
|
|
92
|
+
const offerCollision = (type.toLowerCase() === RtcDescription.OFFER) && (this.makingOffer || (this.peerConnection === undefined) ||
|
|
97
93
|
this.peerConnection.signalingState != 'stable')
|
|
98
94
|
|
|
99
95
|
const ignoreOffer = this.isOffering && offerCollision
|
|
@@ -106,13 +102,13 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IWebrt
|
|
|
106
102
|
logger.warn('error', { err })
|
|
107
103
|
}
|
|
108
104
|
|
|
109
|
-
if (type.toLowerCase() === RtcDescription.OFFER && this.peerConnection) {
|
|
105
|
+
if ((type.toLowerCase() === RtcDescription.OFFER) && (this.peerConnection !== undefined)) {
|
|
110
106
|
try {
|
|
111
107
|
await this.peerConnection.setLocalDescription()
|
|
112
108
|
} catch (err) {
|
|
113
109
|
logger.warn('error', { err })
|
|
114
110
|
}
|
|
115
|
-
if (this.peerConnection.localDescription) {
|
|
111
|
+
if (this.peerConnection.localDescription !== null) {
|
|
116
112
|
this.emit('localDescription', this.peerConnection.localDescription.sdp, this.peerConnection.localDescription.type)
|
|
117
113
|
}
|
|
118
114
|
}
|
|
@@ -148,7 +144,7 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IWebrt
|
|
|
148
144
|
|
|
149
145
|
this.removeAllListeners()
|
|
150
146
|
|
|
151
|
-
if (this.dataChannel) {
|
|
147
|
+
if (this.dataChannel !== undefined) {
|
|
152
148
|
try {
|
|
153
149
|
this.dataChannel.close()
|
|
154
150
|
} catch (e) {
|
|
@@ -158,7 +154,7 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IWebrt
|
|
|
158
154
|
|
|
159
155
|
this.dataChannel = undefined
|
|
160
156
|
|
|
161
|
-
if (this.peerConnection) {
|
|
157
|
+
if (this.peerConnection !== undefined) {
|
|
162
158
|
try {
|
|
163
159
|
this.peerConnection.close()
|
|
164
160
|
} catch (e) {
|
|
@@ -184,9 +180,10 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IWebrt
|
|
|
184
180
|
}
|
|
185
181
|
|
|
186
182
|
private setupDataChannel(dataChannel: RTCDataChannel): void {
|
|
183
|
+
this.dataChannel = dataChannel
|
|
187
184
|
dataChannel.onopen = () => {
|
|
188
185
|
logger.trace('dc.onOpen')
|
|
189
|
-
this.
|
|
186
|
+
this.onDataChannelOpen()
|
|
190
187
|
}
|
|
191
188
|
|
|
192
189
|
dataChannel.onclose = () => {
|
|
@@ -198,10 +195,6 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IWebrt
|
|
|
198
195
|
logger.warn(`dc.onError: ${err}`)
|
|
199
196
|
}
|
|
200
197
|
|
|
201
|
-
dataChannel.onbufferedamountlow = () => {
|
|
202
|
-
//this.emitLowBackpressure()
|
|
203
|
-
}
|
|
204
|
-
|
|
205
198
|
dataChannel.onmessage = (msg) => {
|
|
206
199
|
logger.trace('dc.onmessage')
|
|
207
200
|
this.emit('data', new Uint8Array(msg.data))
|
|
@@ -209,7 +202,7 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IWebrt
|
|
|
209
202
|
}
|
|
210
203
|
|
|
211
204
|
private stopListening() {
|
|
212
|
-
if (this.dataChannel) {
|
|
205
|
+
if (this.dataChannel !== undefined) {
|
|
213
206
|
this.dataChannel.onopen = null
|
|
214
207
|
this.dataChannel.onclose = null
|
|
215
208
|
this.dataChannel.onerror = null
|
|
@@ -217,7 +210,7 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IWebrt
|
|
|
217
210
|
this.dataChannel.onmessage = null
|
|
218
211
|
}
|
|
219
212
|
|
|
220
|
-
if (this.peerConnection) {
|
|
213
|
+
if (this.peerConnection !== undefined) {
|
|
221
214
|
this.peerConnection.onicecandidate = null
|
|
222
215
|
this.peerConnection.onicegatheringstatechange = null
|
|
223
216
|
this.peerConnection.onnegotiationneeded = null
|
|
@@ -225,13 +218,12 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IWebrt
|
|
|
225
218
|
}
|
|
226
219
|
}
|
|
227
220
|
|
|
228
|
-
private
|
|
229
|
-
this.dataChannel = dataChannel
|
|
221
|
+
private onDataChannelOpen(): void {
|
|
230
222
|
this.lastState = 'connected'
|
|
231
223
|
this.emit('connected')
|
|
232
224
|
}
|
|
233
225
|
|
|
234
|
-
public setConnectionId(
|
|
235
|
-
this.connectionId =
|
|
226
|
+
public setConnectionId(connectionId: ConnectionID): void {
|
|
227
|
+
this.connectionId = connectionId
|
|
236
228
|
}
|
|
237
229
|
}
|
|
@@ -5,10 +5,11 @@ import EventEmitter from 'eventemitter3'
|
|
|
5
5
|
import nodeDatachannel, { DataChannel, DescriptionType, PeerConnection } from 'node-datachannel'
|
|
6
6
|
import { Logger } from '@streamr/utils'
|
|
7
7
|
import { IllegalRtcPeerConnectionState } from '../../helpers/errors'
|
|
8
|
-
import { getNodeIdFromPeerDescriptor, keyFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
|
|
9
8
|
import { iceServerAsString } from './iceServerAsString'
|
|
10
9
|
import { IceServer } from './WebrtcConnector'
|
|
11
10
|
import { PortRange } from '../ConnectionManager'
|
|
11
|
+
import { getNodeIdFromPeerDescriptor } from '../../identifiers'
|
|
12
|
+
import { createRandomConnectionId } from '../Connection'
|
|
12
13
|
|
|
13
14
|
const logger = new Logger(module)
|
|
14
15
|
|
|
@@ -25,7 +26,7 @@ export interface Params {
|
|
|
25
26
|
bufferThresholdLow?: number
|
|
26
27
|
connectingTimeout?: number
|
|
27
28
|
maxMessageSize?: number
|
|
28
|
-
iceServers?: IceServer[]
|
|
29
|
+
iceServers?: IceServer[] // TODO make this parameter required (empty array is a good fallback which can be set by the caller if needed)
|
|
29
30
|
portRange?: PortRange
|
|
30
31
|
}
|
|
31
32
|
|
|
@@ -55,7 +56,6 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IConne
|
|
|
55
56
|
private lastState: RtcPeerConnectionState = 'connecting'
|
|
56
57
|
private remoteDescriptionSet = false
|
|
57
58
|
private connectingTimeoutRef?: NodeJS.Timeout
|
|
58
|
-
|
|
59
59
|
public readonly connectionType: ConnectionType = ConnectionType.WEBRTC
|
|
60
60
|
private readonly iceServers: IceServer[]
|
|
61
61
|
private readonly _bufferThresholdHigh: number // TODO: buffer handling must be implemented before production use (NET-938)
|
|
@@ -68,7 +68,7 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IConne
|
|
|
68
68
|
|
|
69
69
|
constructor(params: Params) {
|
|
70
70
|
super()
|
|
71
|
-
this.connectionId =
|
|
71
|
+
this.connectionId = createRandomConnectionId()
|
|
72
72
|
this.iceServers = params.iceServers ?? []
|
|
73
73
|
// eslint-disable-next-line no-underscore-dangle
|
|
74
74
|
this._bufferThresholdHigh = params.bufferThresholdHigh ?? 2 ** 17
|
|
@@ -80,9 +80,9 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IConne
|
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
public start(isOffering: boolean): void {
|
|
83
|
-
const
|
|
84
|
-
logger.trace(`Starting new connection for peer ${
|
|
85
|
-
this.connection = new PeerConnection(
|
|
83
|
+
const nodeId = getNodeIdFromPeerDescriptor(this.remotePeerDescriptor)
|
|
84
|
+
logger.trace(`Starting new connection for peer ${nodeId}`, { isOffering })
|
|
85
|
+
this.connection = new PeerConnection(nodeId, {
|
|
86
86
|
iceServers: this.iceServers.map(iceServerAsString),
|
|
87
87
|
maxMessageSize: this.maxMessageSize,
|
|
88
88
|
portRangeBegin: this.portRange?.min,
|
|
@@ -107,18 +107,19 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IConne
|
|
|
107
107
|
const dataChannel = this.connection.createDataChannel('streamrDataChannel')
|
|
108
108
|
this.setupDataChannel(dataChannel)
|
|
109
109
|
} else {
|
|
110
|
-
this.connection.onDataChannel((dataChannel) => this.
|
|
110
|
+
this.connection.onDataChannel((dataChannel) => this.setupDataChannel(dataChannel))
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
public async setRemoteDescription(description: string, type: string): Promise<void> {
|
|
115
115
|
if (this.connection) {
|
|
116
|
+
const remoteNodeId = getNodeIdFromPeerDescriptor(this.remotePeerDescriptor)
|
|
116
117
|
try {
|
|
117
|
-
logger.trace(`Setting remote descriptor for peer: ${
|
|
118
|
+
logger.trace(`Setting remote descriptor for peer: ${remoteNodeId}`)
|
|
118
119
|
this.connection.setRemoteDescription(description, type as DescriptionType)
|
|
119
120
|
this.remoteDescriptionSet = true
|
|
120
121
|
} catch (err) {
|
|
121
|
-
logger.debug(`Failed to set remote descriptor for peer ${
|
|
122
|
+
logger.debug(`Failed to set remote descriptor for peer ${remoteNodeId}`)
|
|
122
123
|
}
|
|
123
124
|
} else {
|
|
124
125
|
this.doClose(false, `Tried to set description for non-existent connection`)
|
|
@@ -128,11 +129,12 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IConne
|
|
|
128
129
|
public addRemoteCandidate(candidate: string, mid: string): void {
|
|
129
130
|
if (this.connection) {
|
|
130
131
|
if (this.remoteDescriptionSet) {
|
|
132
|
+
const remoteNodeId = getNodeIdFromPeerDescriptor(this.remotePeerDescriptor)
|
|
131
133
|
try {
|
|
132
|
-
logger.trace(`Setting remote candidate for peer: ${
|
|
134
|
+
logger.trace(`Setting remote candidate for peer: ${remoteNodeId}`)
|
|
133
135
|
this.connection.addRemoteCandidate(candidate, mid)
|
|
134
136
|
} catch (err) {
|
|
135
|
-
logger.debug(`Failed to set remote candidate for peer ${
|
|
137
|
+
logger.debug(`Failed to set remote candidate for peer ${remoteNodeId}`)
|
|
136
138
|
}
|
|
137
139
|
} else {
|
|
138
140
|
// TODO: should queue candidates until remote description is set?
|
|
@@ -148,7 +150,8 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IConne
|
|
|
148
150
|
try {
|
|
149
151
|
this.dataChannel!.sendMessageBinary(data as Buffer)
|
|
150
152
|
} catch (err) {
|
|
151
|
-
|
|
153
|
+
const remoteNodeId = getNodeIdFromPeerDescriptor(this.remotePeerDescriptor)
|
|
154
|
+
logger.debug('Failed to send binary message to ' + remoteNodeId + err)
|
|
152
155
|
}
|
|
153
156
|
}
|
|
154
157
|
}
|
|
@@ -159,10 +162,8 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IConne
|
|
|
159
162
|
|
|
160
163
|
private doClose(gracefulLeave: boolean, reason?: string): void {
|
|
161
164
|
if (!this.closed) {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
+ `${reason ? `, reason: ${reason}` : ''}`
|
|
165
|
-
)
|
|
165
|
+
const remoteNodeId = getNodeIdFromPeerDescriptor(this.remotePeerDescriptor)
|
|
166
|
+
logger.trace(`Closing Node WebRTC Connection to ${remoteNodeId}` + `${(reason !== undefined) ? `, reason: ${reason}` : ''}`)
|
|
166
167
|
|
|
167
168
|
this.closed = true
|
|
168
169
|
|
|
@@ -189,6 +190,8 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IConne
|
|
|
189
190
|
logger.trace('conn.close() errored: %s', e)
|
|
190
191
|
}
|
|
191
192
|
}
|
|
193
|
+
this.connection = undefined
|
|
194
|
+
this.dataChannel = undefined
|
|
192
195
|
}
|
|
193
196
|
}
|
|
194
197
|
|
|
@@ -197,16 +200,12 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IConne
|
|
|
197
200
|
this.doClose(false)
|
|
198
201
|
}
|
|
199
202
|
|
|
200
|
-
private onDataChannel(dataChannel: DataChannel): void {
|
|
201
|
-
this.openDataChannel(dataChannel)
|
|
202
|
-
this.setupDataChannel(dataChannel)
|
|
203
|
-
}
|
|
204
|
-
|
|
205
203
|
private setupDataChannel(dataChannel: DataChannel): void {
|
|
204
|
+
this.dataChannel = dataChannel
|
|
206
205
|
dataChannel.setBufferedAmountLowThreshold(this.bufferThresholdLow)
|
|
207
206
|
dataChannel.onOpen(() => {
|
|
208
207
|
logger.trace(`dc.onOpened`)
|
|
209
|
-
this.
|
|
208
|
+
this.onDataChannelOpen()
|
|
210
209
|
})
|
|
211
210
|
|
|
212
211
|
dataChannel.onClosed(() => {
|
|
@@ -226,11 +225,10 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IConne
|
|
|
226
225
|
})
|
|
227
226
|
}
|
|
228
227
|
|
|
229
|
-
private
|
|
228
|
+
private onDataChannelOpen(): void {
|
|
230
229
|
if (this.connectingTimeoutRef) {
|
|
231
230
|
clearTimeout(this.connectingTimeoutRef)
|
|
232
231
|
}
|
|
233
|
-
this.dataChannel = dataChannel
|
|
234
232
|
logger.trace(`DataChannel opened for peer ${getNodeIdFromPeerDescriptor(this.remotePeerDescriptor)}`)
|
|
235
233
|
this.emit('connected')
|
|
236
234
|
}
|
|
@@ -256,7 +254,7 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IConne
|
|
|
256
254
|
return !this.closed && this.lastState === 'connected' && !!this.dataChannel
|
|
257
255
|
}
|
|
258
256
|
|
|
259
|
-
public setConnectionId(
|
|
260
|
-
this.connectionId =
|
|
257
|
+
public setConnectionId(connectionId: ConnectionID): void {
|
|
258
|
+
this.connectionId = connectionId
|
|
261
259
|
}
|
|
262
260
|
}
|
|
@@ -9,21 +9,15 @@ import { ListeningRpcCommunicator } from '../../transport/ListeningRpcCommunicat
|
|
|
9
9
|
import { NodeWebrtcConnection } from './NodeWebrtcConnection'
|
|
10
10
|
import { WebrtcConnectorRpcRemote } from './WebrtcConnectorRpcRemote'
|
|
11
11
|
import { WebrtcConnectorRpcClient } from '../../proto/packages/dht/protos/DhtRpc.client'
|
|
12
|
-
import { PeerIDKey } from '../../helpers/PeerID'
|
|
13
12
|
import { ManagedWebrtcConnection } from '../ManagedWebrtcConnection'
|
|
14
13
|
import { Logger } from '@streamr/utils'
|
|
15
14
|
import * as Err from '../../helpers/errors'
|
|
16
15
|
import { ManagedConnection } from '../ManagedConnection'
|
|
17
|
-
import { toProtoRpcClient } from '@streamr/proto-rpc'
|
|
18
|
-
import {
|
|
19
|
-
areEqualPeerDescriptors,
|
|
20
|
-
getNodeIdFromPeerDescriptor,
|
|
21
|
-
keyFromPeerDescriptor,
|
|
22
|
-
peerIdFromPeerDescriptor
|
|
23
|
-
} from '../../helpers/peerIdFromPeerDescriptor'
|
|
24
16
|
import { PortRange } from '../ConnectionManager'
|
|
25
17
|
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
26
18
|
import { WebrtcConnectorRpcLocal } from './WebrtcConnectorRpcLocal'
|
|
19
|
+
import { DhtAddress, areEqualPeerDescriptors, getNodeIdFromPeerDescriptor } from '../../identifiers'
|
|
20
|
+
import { getOfferer } from '../../helpers/offering'
|
|
27
21
|
|
|
28
22
|
const logger = new Logger(module)
|
|
29
23
|
|
|
@@ -60,10 +54,9 @@ export class WebrtcConnector {
|
|
|
60
54
|
|
|
61
55
|
private static readonly WEBRTC_CONNECTOR_SERVICE_ID = 'system/webrtc-connector'
|
|
62
56
|
private readonly rpcCommunicator: ListeningRpcCommunicator
|
|
63
|
-
private readonly ongoingConnectAttempts: Map<
|
|
57
|
+
private readonly ongoingConnectAttempts: Map<DhtAddress, ManagedWebrtcConnection> = new Map()
|
|
64
58
|
private localPeerDescriptor?: PeerDescriptor
|
|
65
59
|
private stopped = false
|
|
66
|
-
private iceServers: IceServer[]
|
|
67
60
|
private config: WebrtcConnectorConfig
|
|
68
61
|
|
|
69
62
|
constructor(
|
|
@@ -71,9 +64,8 @@ export class WebrtcConnector {
|
|
|
71
64
|
onNewConnection: (connection: ManagedConnection) => boolean
|
|
72
65
|
) {
|
|
73
66
|
this.config = config
|
|
74
|
-
this.iceServers = config.iceServers ?? []
|
|
75
67
|
this.rpcCommunicator = new ListeningRpcCommunicator(WebrtcConnector.WEBRTC_CONNECTOR_SERVICE_ID, config.transport, {
|
|
76
|
-
rpcRequestTimeout: 15000
|
|
68
|
+
rpcRequestTimeout: 15000 // TODO use config option or named constant?
|
|
77
69
|
})
|
|
78
70
|
this.registerLocalRpcMethods(config, onNewConnection)
|
|
79
71
|
}
|
|
@@ -83,6 +75,7 @@ export class WebrtcConnector {
|
|
|
83
75
|
onNewConnection: (connection: ManagedConnection) => boolean
|
|
84
76
|
) {
|
|
85
77
|
const localRpc = new WebrtcConnectorRpcLocal({
|
|
78
|
+
createConnection: (targetPeerDescriptor: PeerDescriptor) => this.createConnection(targetPeerDescriptor),
|
|
86
79
|
connect: (targetPeerDescriptor: PeerDescriptor) => this.connect(targetPeerDescriptor),
|
|
87
80
|
onNewConnection,
|
|
88
81
|
ongoingConnectAttempts: this.ongoingConnectAttempts,
|
|
@@ -135,22 +128,17 @@ export class WebrtcConnector {
|
|
|
135
128
|
|
|
136
129
|
logger.trace(`Opening WebRTC connection to ${getNodeIdFromPeerDescriptor(targetPeerDescriptor)}`)
|
|
137
130
|
|
|
138
|
-
const
|
|
139
|
-
const existingConnection = this.ongoingConnectAttempts.get(
|
|
131
|
+
const nodeId = getNodeIdFromPeerDescriptor(targetPeerDescriptor)
|
|
132
|
+
const existingConnection = this.ongoingConnectAttempts.get(nodeId)
|
|
140
133
|
if (existingConnection) {
|
|
141
134
|
return existingConnection
|
|
142
135
|
}
|
|
143
136
|
|
|
144
|
-
const connection =
|
|
145
|
-
remotePeerDescriptor: targetPeerDescriptor,
|
|
146
|
-
iceServers: this.iceServers,
|
|
147
|
-
bufferThresholdLow: this.config.bufferThresholdLow,
|
|
148
|
-
bufferThresholdHigh: this.config.bufferThresholdHigh,
|
|
149
|
-
connectingTimeout: this.config.connectionTimeout,
|
|
150
|
-
portRange: this.config.portRange
|
|
151
|
-
})
|
|
137
|
+
const connection = this.createConnection(targetPeerDescriptor)
|
|
152
138
|
|
|
153
|
-
const
|
|
139
|
+
const localNodeId = getNodeIdFromPeerDescriptor(this.localPeerDescriptor!)
|
|
140
|
+
const targetNodeId = getNodeIdFromPeerDescriptor(targetPeerDescriptor)
|
|
141
|
+
const offering = (getOfferer(localNodeId, targetNodeId) === 'local')
|
|
154
142
|
let managedConnection: ManagedWebrtcConnection
|
|
155
143
|
|
|
156
144
|
if (offering) {
|
|
@@ -161,10 +149,10 @@ export class WebrtcConnector {
|
|
|
161
149
|
|
|
162
150
|
managedConnection.setRemotePeerDescriptor(targetPeerDescriptor)
|
|
163
151
|
|
|
164
|
-
this.ongoingConnectAttempts.set(
|
|
152
|
+
this.ongoingConnectAttempts.set(targetNodeId, managedConnection)
|
|
165
153
|
|
|
166
154
|
const delFunc = () => {
|
|
167
|
-
this.ongoingConnectAttempts.delete(
|
|
155
|
+
this.ongoingConnectAttempts.delete(nodeId)
|
|
168
156
|
connection.off('disconnected', delFunc)
|
|
169
157
|
managedConnection.off('handshakeCompleted', delFunc)
|
|
170
158
|
}
|
|
@@ -174,24 +162,25 @@ export class WebrtcConnector {
|
|
|
174
162
|
const remoteConnector = new WebrtcConnectorRpcRemote(
|
|
175
163
|
this.localPeerDescriptor!,
|
|
176
164
|
targetPeerDescriptor,
|
|
177
|
-
|
|
165
|
+
this.rpcCommunicator,
|
|
166
|
+
WebrtcConnectorRpcClient
|
|
178
167
|
)
|
|
179
168
|
|
|
180
169
|
connection.on('localCandidate', (candidate: string, mid: string) => {
|
|
181
|
-
if (this.config.externalIp) {
|
|
170
|
+
if (this.config.externalIp !== undefined) {
|
|
182
171
|
candidate = replaceInternalIpWithExternalIp(candidate, this.config.externalIp)
|
|
183
172
|
logger.debug(`onLocalCandidate injected external ip ${candidate} ${mid}`)
|
|
184
173
|
}
|
|
185
|
-
remoteConnector.sendIceCandidate(candidate, mid, connection.connectionId
|
|
174
|
+
remoteConnector.sendIceCandidate(candidate, mid, connection.connectionId)
|
|
186
175
|
})
|
|
187
176
|
|
|
188
177
|
if (offering) {
|
|
189
178
|
connection.once('localDescription', (description: string) => {
|
|
190
|
-
remoteConnector.sendRtcOffer(description, connection.connectionId
|
|
179
|
+
remoteConnector.sendRtcOffer(description, connection.connectionId)
|
|
191
180
|
})
|
|
192
181
|
} else {
|
|
193
182
|
connection.once('localDescription', (description: string) => {
|
|
194
|
-
remoteConnector.sendRtcAnswer(description, connection.connectionId
|
|
183
|
+
remoteConnector.sendRtcAnswer(description, connection.connectionId)
|
|
195
184
|
})
|
|
196
185
|
}
|
|
197
186
|
|
|
@@ -204,6 +193,18 @@ export class WebrtcConnector {
|
|
|
204
193
|
return managedConnection
|
|
205
194
|
}
|
|
206
195
|
|
|
196
|
+
private createConnection(targetPeerDescriptor: PeerDescriptor): NodeWebrtcConnection {
|
|
197
|
+
return new NodeWebrtcConnection({
|
|
198
|
+
remotePeerDescriptor: targetPeerDescriptor,
|
|
199
|
+
iceServers: this.config.iceServers,
|
|
200
|
+
bufferThresholdLow: this.config.bufferThresholdLow,
|
|
201
|
+
bufferThresholdHigh: this.config.bufferThresholdHigh,
|
|
202
|
+
connectingTimeout: this.config.connectionTimeout,
|
|
203
|
+
portRange: this.config.portRange
|
|
204
|
+
// TODO should we pass maxMessageSize?
|
|
205
|
+
})
|
|
206
|
+
}
|
|
207
|
+
|
|
207
208
|
setLocalPeerDescriptor(peerDescriptor: PeerDescriptor): void {
|
|
208
209
|
this.localPeerDescriptor = peerDescriptor
|
|
209
210
|
}
|
|
@@ -217,10 +218,4 @@ export class WebrtcConnector {
|
|
|
217
218
|
|
|
218
219
|
this.rpcCommunicator.destroy()
|
|
219
220
|
}
|
|
220
|
-
|
|
221
|
-
public isOffering(targetPeerDescriptor: PeerDescriptor): boolean {
|
|
222
|
-
const myId = peerIdFromPeerDescriptor(this.localPeerDescriptor!)
|
|
223
|
-
const theirId = peerIdFromPeerDescriptor(targetPeerDescriptor)
|
|
224
|
-
return myId.hasSmallerHashThan(theirId)
|
|
225
|
-
}
|
|
226
221
|
}
|