@streamr/dht 100.0.0-testnet-one.4 → 100.0.0-testnet-two.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/dist/package.json +66 -0
- package/dist/src/connection/ConnectionLockHandler.d.ts +11 -11
- package/dist/src/connection/ConnectionLockHandler.js.map +1 -1
- package/dist/src/connection/ConnectionLockRpcLocal.d.ts +3 -3
- package/dist/src/connection/ConnectionLockRpcLocal.js +4 -4
- package/dist/src/connection/ConnectionLockRpcLocal.js.map +1 -1
- package/dist/src/connection/ConnectionLockRpcRemote.d.ts +3 -5
- package/dist/src/connection/ConnectionLockRpcRemote.js +4 -7
- package/dist/src/connection/ConnectionLockRpcRemote.js.map +1 -1
- package/dist/src/connection/ConnectionManager.d.ts +4 -6
- package/dist/src/connection/ConnectionManager.js +48 -46
- package/dist/src/connection/ConnectionManager.js.map +1 -1
- package/dist/src/connection/ConnectorFacade.d.ts +2 -2
- package/dist/src/connection/ConnectorFacade.js +2 -1
- package/dist/src/connection/ConnectorFacade.js.map +1 -1
- package/dist/src/connection/Handshaker.d.ts +1 -1
- package/dist/src/connection/Handshaker.js +14 -5
- package/dist/src/connection/Handshaker.js.map +1 -1
- package/dist/src/connection/ManagedConnection.d.ts +4 -7
- package/dist/src/connection/ManagedConnection.js +9 -13
- package/dist/src/connection/ManagedConnection.js.map +1 -1
- package/dist/src/connection/connectivityChecker.js +1 -0
- package/dist/src/connection/connectivityChecker.js.map +1 -1
- package/dist/src/connection/simulator/Simulator.d.ts +0 -3
- package/dist/src/connection/simulator/Simulator.js +3 -51
- package/dist/src/connection/simulator/Simulator.js.map +1 -1
- package/dist/src/connection/simulator/SimulatorConnector.js +5 -5
- package/dist/src/connection/simulator/SimulatorConnector.js.map +1 -1
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js +2 -2
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnector.d.ts +0 -1
- package/dist/src/connection/webrtc/WebrtcConnector.js +7 -9
- package/dist/src/connection/webrtc/WebrtcConnector.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.d.ts +2 -2
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js +21 -14
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.d.ts +2 -5
- package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.js +1 -4
- package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.js.map +1 -1
- package/dist/src/connection/websocket/AutoCertifierClientFacade.d.ts +1 -2
- package/dist/src/connection/websocket/AutoCertifierClientFacade.js +3 -4
- package/dist/src/connection/websocket/AutoCertifierClientFacade.js.map +1 -1
- package/dist/src/connection/websocket/ClientWebsocket.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnector.d.ts +2 -7
- package/dist/src/connection/websocket/WebsocketConnector.js +48 -44
- package/dist/src/connection/websocket/WebsocketConnector.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.d.ts +3 -2
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.js +8 -10
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.d.ts +3 -6
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.js +0 -3
- 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 +11 -12
- package/dist/src/connection/websocket/WebsocketServer.js.map +1 -1
- package/dist/src/dht/DhtNode.d.ts +10 -13
- package/dist/src/dht/DhtNode.js +41 -54
- package/dist/src/dht/DhtNode.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcLocal.d.ts +2 -3
- package/dist/src/dht/DhtNodeRpcLocal.js +1 -1
- package/dist/src/dht/DhtNodeRpcLocal.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcRemote.d.ts +7 -7
- package/dist/src/dht/DhtNodeRpcRemote.js +9 -11
- package/dist/src/dht/DhtNodeRpcRemote.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcLocal.d.ts +5 -4
- package/dist/src/dht/ExternalApiRpcLocal.js +3 -2
- package/dist/src/dht/ExternalApiRpcLocal.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcRemote.d.ts +2 -2
- package/dist/src/dht/ExternalApiRpcRemote.js +2 -0
- package/dist/src/dht/ExternalApiRpcRemote.js.map +1 -1
- package/dist/src/dht/PeerManager.d.ts +13 -14
- package/dist/src/dht/PeerManager.js +45 -60
- package/dist/src/dht/PeerManager.js.map +1 -1
- package/dist/src/dht/contact/Contact.d.ts +2 -2
- package/dist/src/dht/contact/Contact.js +2 -2
- package/dist/src/dht/contact/Contact.js.map +1 -1
- package/dist/src/dht/contact/ContactList.d.ts +7 -7
- package/dist/src/dht/contact/ContactList.js +3 -3
- 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 +12 -11
- package/dist/src/dht/contact/RandomContactList.js.map +1 -1
- package/dist/src/dht/contact/RpcRemote.d.ts +7 -4
- package/dist/src/dht/contact/RpcRemote.js +5 -2
- package/dist/src/dht/contact/RpcRemote.js.map +1 -1
- package/dist/src/dht/contact/SortedContactList.d.ts +13 -13
- package/dist/src/dht/contact/SortedContactList.js +33 -29
- package/dist/src/dht/contact/SortedContactList.js.map +1 -1
- package/dist/src/dht/discovery/DiscoverySession.d.ts +2 -4
- package/dist/src/dht/discovery/DiscoverySession.js +19 -23
- package/dist/src/dht/discovery/DiscoverySession.js.map +1 -1
- package/dist/src/dht/discovery/PeerDiscovery.d.ts +2 -5
- package/dist/src/dht/discovery/PeerDiscovery.js +12 -20
- package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.d.ts +36 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.js +165 -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/{find/FindRpcLocal.js → recursive-operation/RecursiveOperationRpcLocal.js} +7 -7
- 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/{routing/FindRpcRemote.js → recursive-operation/RecursiveOperationRpcRemote.js} +11 -11
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.d.ts +42 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.js +182 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.d.ts +12 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js +17 -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/Router.d.ts +4 -19
- package/dist/src/dht/routing/Router.js +41 -33
- package/dist/src/dht/routing/Router.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcLocal.js +6 -5
- package/dist/src/dht/routing/RouterRpcLocal.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcRemote.d.ts +2 -2
- package/dist/src/dht/routing/RouterRpcRemote.js +7 -7
- package/dist/src/dht/routing/RouterRpcRemote.js.map +1 -1
- package/dist/src/dht/routing/RoutingSession.d.ts +20 -16
- package/dist/src/dht/routing/RoutingSession.js +37 -45
- package/dist/src/dht/routing/RoutingSession.js.map +1 -1
- package/dist/src/dht/store/LocalDataStore.d.ts +11 -13
- package/dist/src/dht/store/LocalDataStore.js +36 -56
- 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 +186 -0
- package/dist/src/dht/store/StoreManager.js.map +1 -0
- package/dist/src/dht/store/StoreRpcLocal.d.ts +8 -40
- package/dist/src/dht/store/StoreRpcLocal.js +13 -229
- package/dist/src/dht/store/StoreRpcLocal.js.map +1 -1
- package/dist/src/dht/store/StoreRpcRemote.d.ts +5 -5
- package/dist/src/dht/store/StoreRpcRemote.js +4 -5
- package/dist/src/dht/store/StoreRpcRemote.js.map +1 -1
- package/dist/src/exports.d.ts +2 -0
- package/dist/src/exports.js.map +1 -1
- package/dist/src/helpers/MapWithTtl.d.ts +14 -0
- package/dist/src/helpers/MapWithTtl.js +59 -0
- package/dist/src/helpers/MapWithTtl.js.map +1 -0
- package/dist/src/helpers/PeerID.d.ts +2 -0
- package/dist/src/helpers/PeerID.js +4 -0
- package/dist/src/helpers/PeerID.js.map +1 -1
- package/dist/src/helpers/nodeId.d.ts +5 -0
- package/dist/src/helpers/nodeId.js +18 -1
- package/dist/src/helpers/nodeId.js.map +1 -1
- package/dist/src/helpers/peerIdFromPeerDescriptor.d.ts +2 -1
- package/dist/src/helpers/peerIdFromPeerDescriptor.js +2 -1
- package/dist/src/helpers/peerIdFromPeerDescriptor.js.map +1 -1
- package/dist/src/helpers/protoClasses.js +2 -3
- package/dist/src/helpers/protoClasses.js.map +1 -1
- package/dist/src/helpers/versionCompatibility.d.ts +2 -0
- package/dist/src/helpers/versionCompatibility.js +18 -0
- package/dist/src/helpers/versionCompatibility.js.map +1 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +21 -22
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +18 -18
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +49 -65
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +43 -58
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +11 -12
- package/dist/src/rpc-protocol/DhtCallContext.d.ts +2 -1
- 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 +9 -1
- package/dist/src/transport/ITransport.js +5 -0
- package/dist/src/transport/ITransport.js.map +1 -1
- package/dist/src/transport/ListeningRpcCommunicator.js +1 -1
- package/dist/src/transport/ListeningRpcCommunicator.js.map +1 -1
- package/dist/src/transport/RoutingRpcCommunicator.d.ts +2 -1
- package/dist/src/transport/RoutingRpcCommunicator.js +16 -11
- 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 +11 -7
- package/package.json +6 -7
- package/protos/DhtRpc.proto +20 -24
- package/src/connection/ConnectionLockHandler.ts +15 -15
- package/src/connection/ConnectionLockRpcLocal.ts +8 -9
- package/src/connection/ConnectionLockRpcRemote.ts +7 -16
- package/src/connection/ConnectionManager.ts +58 -55
- package/src/connection/ConnectorFacade.ts +3 -0
- package/src/connection/Handshaker.ts +21 -6
- package/src/connection/ManagedConnection.ts +20 -34
- package/src/connection/connectivityChecker.ts +1 -0
- package/src/connection/simulator/Simulator.ts +5 -36
- package/src/connection/simulator/SimulatorConnector.ts +8 -8
- package/src/connection/webrtc/BrowserWebrtcConnection.ts +0 -3
- package/src/connection/webrtc/NodeWebrtcConnection.ts +3 -4
- package/src/connection/webrtc/WebrtcConnector.ts +11 -13
- package/src/connection/webrtc/WebrtcConnectorRpcLocal.ts +25 -18
- package/src/connection/webrtc/WebrtcConnectorRpcRemote.ts +3 -13
- package/src/connection/websocket/AutoCertifierClientFacade.ts +4 -6
- package/src/connection/websocket/ClientWebsocket.ts +1 -0
- package/src/connection/websocket/WebsocketConnector.ts +57 -61
- package/src/connection/websocket/WebsocketConnectorRpcLocal.ts +11 -13
- package/src/connection/websocket/WebsocketConnectorRpcRemote.ts +4 -15
- package/src/connection/websocket/WebsocketServer.ts +14 -17
- package/src/dht/DhtNode.ts +69 -71
- package/src/dht/DhtNodeRpcLocal.ts +1 -3
- package/src/dht/DhtNodeRpcRemote.ts +14 -18
- package/src/dht/ExternalApiRpcLocal.ts +16 -6
- package/src/dht/ExternalApiRpcRemote.ts +5 -3
- package/src/dht/PeerManager.ts +73 -90
- package/src/dht/contact/Contact.ts +5 -4
- package/src/dht/contact/ContactList.ts +9 -9
- package/src/dht/contact/RandomContactList.ts +14 -14
- package/src/dht/contact/RpcRemote.ts +10 -7
- package/src/dht/contact/SortedContactList.ts +48 -45
- package/src/dht/discovery/DiscoverySession.ts +25 -27
- package/src/dht/discovery/PeerDiscovery.ts +16 -37
- package/src/dht/recursive-operation/RecursiveOperationManager.ts +240 -0
- package/src/dht/{find/FindRpcLocal.ts → recursive-operation/RecursiveOperationRpcLocal.ts} +9 -9
- package/src/dht/{routing/FindRpcRemote.ts → recursive-operation/RecursiveOperationRpcRemote.ts} +10 -10
- package/src/dht/recursive-operation/RecursiveOperationSession.ts +224 -0
- package/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.ts +25 -0
- package/src/dht/{find/FindSessionRpcRemote.ts → recursive-operation/RecursiveOperationSessionRpcRemote.ts} +8 -8
- package/src/dht/routing/Router.ts +45 -64
- package/src/dht/routing/RouterRpcLocal.ts +7 -6
- package/src/dht/routing/RouterRpcRemote.ts +9 -10
- package/src/dht/routing/RoutingSession.ts +59 -68
- package/src/dht/store/LocalDataStore.ts +47 -66
- package/src/dht/store/StoreManager.ts +217 -0
- package/src/dht/store/StoreRpcLocal.ts +26 -302
- package/src/dht/store/StoreRpcRemote.ts +9 -11
- package/src/exports.ts +2 -0
- package/src/helpers/MapWithTtl.ts +71 -0
- package/src/helpers/PeerID.ts +5 -0
- package/src/helpers/nodeId.ts +20 -0
- package/src/helpers/peerIdFromPeerDescriptor.ts +5 -3
- package/src/helpers/protoClasses.ts +4 -6
- package/src/helpers/versionCompatibility.ts +13 -0
- package/src/proto/packages/dht/protos/DhtRpc.client.ts +31 -32
- package/src/proto/packages/dht/protos/DhtRpc.server.ts +11 -12
- package/src/proto/packages/dht/protos/DhtRpc.ts +67 -90
- package/src/rpc-protocol/DhtCallContext.ts +2 -1
- package/src/rpc-protocol/DhtRpcOptions.ts +2 -1
- package/src/transport/ITransport.ts +10 -1
- package/src/transport/ListeningRpcCommunicator.ts +1 -1
- package/src/transport/RoutingRpcCommunicator.ts +18 -12
- package/test/benchmark/Find.test.ts +8 -21
- package/test/benchmark/KademliaCorrectness.test.ts +11 -20
- package/test/benchmark/SortedContactListBenchmark.test.ts +9 -9
- package/test/benchmark/kademlia-simulation/Contact.ts +9 -8
- package/test/benchmark/kademlia-simulation/KademliaSimulation.ts +2 -2
- package/test/benchmark/kademlia-simulation/SimulationNode.ts +17 -17
- package/test/end-to-end/Layer0-Layer1.test.ts +10 -14
- package/test/end-to-end/Layer0.test.ts +15 -18
- package/test/end-to-end/Layer0MixedConnectionTypes.test.ts +7 -9
- package/test/end-to-end/Layer0Webrtc-Layer1.test.ts +4 -10
- package/test/end-to-end/Layer0Webrtc.test.ts +5 -6
- package/test/end-to-end/Layer1-Scale-WebSocket.test.ts +8 -16
- package/test/end-to-end/Layer1-Scale-Webrtc.test.ts +6 -13
- package/test/end-to-end/WebsocketConnectionRequest.test.ts +5 -6
- package/test/end-to-end/memory-leak.test.ts +6 -8
- package/test/integration/ConnectionLocking.test.ts +6 -13
- package/test/integration/ConnectionManager.test.ts +26 -43
- package/test/integration/DhtJoinPeerDiscovery.test.ts +5 -10
- package/test/integration/DhtNodeExternalAPI.test.ts +16 -22
- package/test/integration/DhtNodeRpcRemote.test.ts +13 -22
- package/test/integration/DhtRpc.test.ts +13 -18
- package/test/integration/Find.test.ts +10 -10
- package/test/integration/Layer1-scale.test.ts +17 -28
- package/test/integration/Mock-Layer1-Layer0.test.ts +25 -43
- package/test/integration/MultipleEntryPointJoining.test.ts +7 -7
- package/test/integration/ReplicateData.test.ts +28 -30
- package/test/integration/RouteMessage.test.ts +30 -27
- package/test/integration/RouterRpcRemote.test.ts +12 -18
- package/test/integration/RpcErrors.test.ts +8 -21
- package/test/integration/ScaleDownDht.test.ts +11 -10
- package/test/integration/SimultaneousConnections.test.ts +43 -67
- package/test/integration/Store.test.ts +23 -36
- package/test/integration/StoreAndDelete.test.ts +30 -50
- package/test/integration/StoreOnDhtWithTwoNodes.test.ts +16 -37
- package/test/integration/StoreRpcRemote.test.ts +20 -30
- package/test/integration/WebrtcConnectionManagement.test.ts +3 -13
- package/test/integration/WebrtcConnectorRpc.test.ts +3 -9
- package/test/integration/WebsocketConnectionManagement.test.ts +7 -10
- package/test/integration/WebsocketConnectorRpc.test.ts +8 -17
- package/test/unit/ConnectivityHelpers.test.ts +9 -17
- package/test/unit/DuplicateDetector.test.ts +7 -4
- package/test/unit/LocalDataStore.test.ts +66 -77
- package/test/unit/PeerManager.test.ts +31 -0
- package/test/unit/RandomContactList.test.ts +13 -8
- package/test/unit/{Finder.test.ts → RecursiveOperationManager.test.ts} +38 -43
- package/test/unit/RecursiveOperationSession.test.ts +68 -0
- package/test/unit/Router.test.ts +15 -22
- package/test/unit/RoutingSession.test.ts +23 -25
- package/test/unit/SortedContactList.test.ts +41 -26
- package/test/unit/StoreManager.test.ts +132 -0
- package/test/unit/WebsocketConnector.test.ts +27 -35
- package/test/unit/customMatchers.test.ts +16 -0
- package/test/unit/versionCompatibility.test.ts +16 -0
- package/test/utils/FakeTransport.ts +44 -0
- package/test/utils/customMatchers.ts +70 -0
- package/test/utils/mock/MockRpcCommunicator.ts +7 -0
- package/test/utils/mock/Router.ts +3 -2
- package/test/utils/mock/mockDataEntry.ts +36 -0
- package/test/utils/utils.ts +49 -87
- package/tsconfig.browser.json +2 -1
- package/tsconfig.jest.json +2 -1
- package/tsconfig.node.json +2 -1
- package/dist/src/dht/find/FindRpcLocal.d.ts +0 -14
- 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 -150
- 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 -197
- 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.map +0 -1
- package/src/dht/find/FindSession.ts +0 -183
- package/src/dht/find/FindSessionRpcLocal.ts +0 -25
- package/src/dht/find/Finder.ts +0 -295
|
@@ -9,8 +9,7 @@ import {
|
|
|
9
9
|
ConnectivityResponse,
|
|
10
10
|
HandshakeError,
|
|
11
11
|
PeerDescriptor,
|
|
12
|
-
WebsocketConnectionRequest
|
|
13
|
-
WebsocketConnectionResponse
|
|
12
|
+
WebsocketConnectionRequest
|
|
14
13
|
} from '../../proto/packages/dht/protos/DhtRpc'
|
|
15
14
|
import { WebsocketConnectorRpcClient } from '../../proto/packages/dht/protos/DhtRpc.client'
|
|
16
15
|
import { Logger, binaryToHex, wait } from '@streamr/utils'
|
|
@@ -18,11 +17,9 @@ import { ManagedConnection } from '../ManagedConnection'
|
|
|
18
17
|
import { WebsocketServer } from './WebsocketServer'
|
|
19
18
|
import { sendConnectivityRequest } from '../connectivityChecker'
|
|
20
19
|
import { NatType, PortRange, TlsCertificate } from '../ConnectionManager'
|
|
21
|
-
import { PeerIDKey } from '../../helpers/PeerID'
|
|
22
20
|
import { ServerWebsocket } from './ServerWebsocket'
|
|
23
|
-
import { toProtoRpcClient } from '@streamr/proto-rpc'
|
|
24
21
|
import { Handshaker } from '../Handshaker'
|
|
25
|
-
import { areEqualPeerDescriptors,
|
|
22
|
+
import { areEqualPeerDescriptors, getNodeIdFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
|
|
26
23
|
import { ParsedUrlQuery } from 'querystring'
|
|
27
24
|
import { range, sample } from 'lodash'
|
|
28
25
|
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
@@ -31,6 +28,10 @@ import { WebsocketServerStartError } from '../../helpers/errors'
|
|
|
31
28
|
import { AutoCertifierClientFacade } from './AutoCertifierClientFacade'
|
|
32
29
|
import { attachConnectivityRequestHandler } from '../connectivityRequestHandler'
|
|
33
30
|
import * as Err from '../../helpers/errors'
|
|
31
|
+
import { Empty } from '../../proto/google/protobuf/empty'
|
|
32
|
+
import { NodeID } from '../../helpers/nodeId'
|
|
33
|
+
import { version } from '../../../package.json'
|
|
34
|
+
import { isCompatibleVersion } from '../../helpers/versionCompatibility'
|
|
34
35
|
|
|
35
36
|
const logger = new Logger(module)
|
|
36
37
|
|
|
@@ -45,6 +46,7 @@ const ENTRY_POINT_CONNECTION_ATTEMPTS = 5
|
|
|
45
46
|
export interface WebsocketConnectorConfig {
|
|
46
47
|
transport: ITransport
|
|
47
48
|
onNewConnection: (connection: ManagedConnection) => boolean
|
|
49
|
+
hasConnection: (peerDescriptor: PeerDescriptor) => boolean
|
|
48
50
|
portRange?: PortRange
|
|
49
51
|
maxMessageSize?: number
|
|
50
52
|
host?: string
|
|
@@ -61,38 +63,26 @@ export class WebsocketConnector {
|
|
|
61
63
|
private static readonly WEBSOCKET_CONNECTOR_SERVICE_ID = 'system/websocket-connector'
|
|
62
64
|
private readonly rpcCommunicator: ListeningRpcCommunicator
|
|
63
65
|
private readonly websocketServer?: WebsocketServer
|
|
64
|
-
private readonly ongoingConnectRequests: Map<
|
|
65
|
-
private onNewConnection: (connection: ManagedConnection) => boolean
|
|
66
|
+
private readonly ongoingConnectRequests: Map<NodeID, ManagedConnection> = new Map()
|
|
66
67
|
private host?: string
|
|
67
|
-
private readonly entrypoints?: PeerDescriptor[]
|
|
68
|
-
private readonly tlsCertificate?: TlsCertificate
|
|
69
|
-
private readonly autoCertifierTransport: ITransport
|
|
70
|
-
private readonly autoCertifierUrl: string
|
|
71
|
-
private readonly autoCertifierConfigFile: string
|
|
72
|
-
private readonly serverEnableTls: boolean
|
|
73
68
|
private autoCertifierClient?: AutoCertifierClientFacade
|
|
74
69
|
private selectedPort?: number
|
|
75
70
|
private localPeerDescriptor?: PeerDescriptor
|
|
76
|
-
private connectingConnections: Map<
|
|
71
|
+
private connectingConnections: Map<NodeID, ManagedConnection> = new Map()
|
|
77
72
|
private abortController = new AbortController()
|
|
73
|
+
private readonly config: WebsocketConnectorConfig
|
|
78
74
|
|
|
79
75
|
constructor(config: WebsocketConnectorConfig) {
|
|
76
|
+
this.config = config
|
|
80
77
|
this.websocketServer = config.portRange ? new WebsocketServer({
|
|
81
78
|
portRange: config.portRange,
|
|
82
79
|
tlsCertificate: config.tlsCertificate,
|
|
83
80
|
maxMessageSize: config.maxMessageSize,
|
|
84
81
|
enableTls: config.serverEnableTls
|
|
85
82
|
}) : undefined
|
|
86
|
-
this.onNewConnection = config.onNewConnection
|
|
87
83
|
this.host = config.host
|
|
88
|
-
this.entrypoints = config.entrypoints
|
|
89
|
-
this.tlsCertificate = config.tlsCertificate
|
|
90
|
-
this.autoCertifierTransport = config.autoCertifierTransport
|
|
91
|
-
this.autoCertifierUrl = config.autoCertifierUrl
|
|
92
|
-
this.autoCertifierConfigFile = config.autoCertifierConfigFile
|
|
93
|
-
this.serverEnableTls = config.serverEnableTls
|
|
94
84
|
this.rpcCommunicator = new ListeningRpcCommunicator(WebsocketConnector.WEBSOCKET_CONNECTOR_SERVICE_ID, config.transport, {
|
|
95
|
-
rpcRequestTimeout: 15000
|
|
85
|
+
rpcRequestTimeout: 15000 // TODO use config option or named constant?
|
|
96
86
|
})
|
|
97
87
|
this.registerLocalRpcMethods(config)
|
|
98
88
|
}
|
|
@@ -101,10 +91,11 @@ export class WebsocketConnector {
|
|
|
101
91
|
const rpcLocal = new WebsocketConnectorRpcLocal({
|
|
102
92
|
connect: (targetPeerDescriptor: PeerDescriptor) => this.connect(targetPeerDescriptor),
|
|
103
93
|
hasConnection: (targetPeerDescriptor: PeerDescriptor): boolean => {
|
|
104
|
-
const
|
|
105
|
-
if (this.connectingConnections.has(
|
|
106
|
-
|| this.connectingConnections.has(
|
|
107
|
-
|| this.ongoingConnectRequests.has(
|
|
94
|
+
const nodeId = getNodeIdFromPeerDescriptor(targetPeerDescriptor)
|
|
95
|
+
if (this.connectingConnections.has(nodeId)
|
|
96
|
+
|| this.connectingConnections.has(nodeId)
|
|
97
|
+
|| this.ongoingConnectRequests.has(nodeId)
|
|
98
|
+
|| config.hasConnection(targetPeerDescriptor)
|
|
108
99
|
) {
|
|
109
100
|
return true
|
|
110
101
|
} else {
|
|
@@ -114,15 +105,14 @@ export class WebsocketConnector {
|
|
|
114
105
|
onNewConnection: (connection: ManagedConnection) => config.onNewConnection(connection),
|
|
115
106
|
abortSignal: this.abortController.signal
|
|
116
107
|
})
|
|
117
|
-
this.rpcCommunicator.
|
|
108
|
+
this.rpcCommunicator.registerRpcNotification(
|
|
118
109
|
WebsocketConnectionRequest,
|
|
119
|
-
WebsocketConnectionResponse,
|
|
120
110
|
'requestConnection',
|
|
121
|
-
async (req: WebsocketConnectionRequest, context: ServerCallContext): Promise<
|
|
111
|
+
async (req: WebsocketConnectionRequest, context: ServerCallContext): Promise<Empty> => {
|
|
122
112
|
if (!this.abortController.signal.aborted) {
|
|
123
113
|
return rpcLocal.requestConnection(req, context)
|
|
124
114
|
} else {
|
|
125
|
-
return {
|
|
115
|
+
return {}
|
|
126
116
|
}
|
|
127
117
|
}
|
|
128
118
|
)
|
|
@@ -130,16 +120,16 @@ export class WebsocketConnector {
|
|
|
130
120
|
|
|
131
121
|
private attachHandshaker(connection: IConnection) {
|
|
132
122
|
const handshaker = new Handshaker(this.localPeerDescriptor!, connection)
|
|
133
|
-
handshaker.once('handshakeRequest', (localPeerDescriptor: PeerDescriptor, remotePeerDescriptor?: PeerDescriptor) => {
|
|
134
|
-
this.onServerSocketHandshakeRequest(localPeerDescriptor, connection, remotePeerDescriptor)
|
|
123
|
+
handshaker.once('handshakeRequest', (localPeerDescriptor: PeerDescriptor, sourceVersion: string, remotePeerDescriptor?: PeerDescriptor) => {
|
|
124
|
+
this.onServerSocketHandshakeRequest(localPeerDescriptor, connection, sourceVersion, remotePeerDescriptor)
|
|
135
125
|
})
|
|
136
126
|
}
|
|
137
127
|
|
|
138
128
|
public async autoCertify(): Promise<void> {
|
|
139
129
|
this.autoCertifierClient = new AutoCertifierClientFacade({
|
|
140
|
-
configFile: this.autoCertifierConfigFile,
|
|
141
|
-
transport: this.autoCertifierTransport,
|
|
142
|
-
url: this.autoCertifierUrl,
|
|
130
|
+
configFile: this.config.autoCertifierConfigFile,
|
|
131
|
+
transport: this.config.autoCertifierTransport,
|
|
132
|
+
url: this.config.autoCertifierUrl,
|
|
143
133
|
wsServerPort: this.selectedPort!,
|
|
144
134
|
setHost: (hostName: string) => this.setHost(hostName),
|
|
145
135
|
updateCertificate: (certificate: string, privateKey: string) => this.websocketServer!.updateCertificate(certificate, privateKey)
|
|
@@ -183,17 +173,17 @@ export class WebsocketConnector {
|
|
|
183
173
|
return noServerConnectivityResponse
|
|
184
174
|
}
|
|
185
175
|
for (const reattempt of range(ENTRY_POINT_CONNECTION_ATTEMPTS)) {
|
|
186
|
-
const entryPoint = sample(this.entrypoints)!
|
|
176
|
+
const entryPoint = sample(this.config.entrypoints)!
|
|
187
177
|
try {
|
|
188
178
|
if (!this.websocketServer) {
|
|
189
179
|
return noServerConnectivityResponse
|
|
190
180
|
} else {
|
|
191
|
-
if (!this.entrypoints || this.entrypoints.length === 0) {
|
|
181
|
+
if (!this.config.entrypoints || this.config.entrypoints.length === 0) {
|
|
192
182
|
// return connectivity info given in config
|
|
193
183
|
const preconfiguredConnectivityResponse: ConnectivityResponse = {
|
|
194
184
|
host: this.host!,
|
|
195
185
|
natType: NatType.OPEN_INTERNET,
|
|
196
|
-
websocket: { host: this.host!, port: this.selectedPort!, tls: this.tlsCertificate !== undefined }
|
|
186
|
+
websocket: { host: this.host!, port: this.selectedPort!, tls: this.config.tlsCertificate !== undefined }
|
|
197
187
|
}
|
|
198
188
|
return preconfiguredConnectivityResponse
|
|
199
189
|
} else {
|
|
@@ -201,7 +191,7 @@ export class WebsocketConnector {
|
|
|
201
191
|
const connectivityRequest = {
|
|
202
192
|
port: this.selectedPort!,
|
|
203
193
|
host: this.host,
|
|
204
|
-
tls: this.serverEnableTls,
|
|
194
|
+
tls: this.config.serverEnableTls,
|
|
205
195
|
selfSigned
|
|
206
196
|
}
|
|
207
197
|
if (!this.abortController.signal.aborted) {
|
|
@@ -229,8 +219,8 @@ export class WebsocketConnector {
|
|
|
229
219
|
}
|
|
230
220
|
|
|
231
221
|
public connect(targetPeerDescriptor: PeerDescriptor): ManagedConnection {
|
|
232
|
-
const
|
|
233
|
-
const existingConnection = this.connectingConnections.get(
|
|
222
|
+
const nodeId = getNodeIdFromPeerDescriptor(targetPeerDescriptor)
|
|
223
|
+
const existingConnection = this.connectingConnections.get(nodeId)
|
|
234
224
|
if (existingConnection) {
|
|
235
225
|
return existingConnection
|
|
236
226
|
}
|
|
@@ -251,11 +241,11 @@ export class WebsocketConnector {
|
|
|
251
241
|
)
|
|
252
242
|
managedConnection.setRemotePeerDescriptor(targetPeerDescriptor)
|
|
253
243
|
|
|
254
|
-
this.connectingConnections.set(
|
|
244
|
+
this.connectingConnections.set(getNodeIdFromPeerDescriptor(targetPeerDescriptor), managedConnection)
|
|
255
245
|
|
|
256
246
|
const delFunc = () => {
|
|
257
|
-
if (this.connectingConnections.has(
|
|
258
|
-
this.connectingConnections.delete(
|
|
247
|
+
if (this.connectingConnections.has(nodeId)) {
|
|
248
|
+
this.connectingConnections.delete(nodeId)
|
|
259
249
|
}
|
|
260
250
|
socket.off('disconnected', delFunc)
|
|
261
251
|
managedConnection.off('handshakeCompleted', delFunc)
|
|
@@ -274,13 +264,15 @@ export class WebsocketConnector {
|
|
|
274
264
|
const remoteConnector = new WebsocketConnectorRpcRemote(
|
|
275
265
|
localPeerDescriptor,
|
|
276
266
|
targetPeerDescriptor,
|
|
277
|
-
|
|
267
|
+
'DUMMY',
|
|
268
|
+
this.rpcCommunicator,
|
|
269
|
+
WebsocketConnectorRpcClient
|
|
278
270
|
)
|
|
279
|
-
remoteConnector.requestConnection().then((
|
|
280
|
-
logger.trace('Sent WebsocketConnectionRequest
|
|
271
|
+
remoteConnector.requestConnection().then(() => {
|
|
272
|
+
logger.trace('Sent WebsocketConnectionRequest notification to peer', { targetPeerDescriptor })
|
|
281
273
|
return
|
|
282
274
|
}, (err) => {
|
|
283
|
-
logger.debug('Failed to send WebsocketConnectionRequest
|
|
275
|
+
logger.debug('Failed to send WebsocketConnectionRequest notification to peer ', {
|
|
284
276
|
error: err, targetPeerDescriptor
|
|
285
277
|
})
|
|
286
278
|
})
|
|
@@ -292,24 +284,28 @@ export class WebsocketConnector {
|
|
|
292
284
|
undefined,
|
|
293
285
|
targetPeerDescriptor
|
|
294
286
|
)
|
|
295
|
-
managedConnection.on('disconnected', () => this.ongoingConnectRequests.delete(
|
|
287
|
+
managedConnection.on('disconnected', () => this.ongoingConnectRequests.delete(getNodeIdFromPeerDescriptor(targetPeerDescriptor)))
|
|
296
288
|
managedConnection.setRemotePeerDescriptor(targetPeerDescriptor)
|
|
297
|
-
this.ongoingConnectRequests.set(
|
|
289
|
+
this.ongoingConnectRequests.set(getNodeIdFromPeerDescriptor(targetPeerDescriptor), managedConnection)
|
|
298
290
|
return managedConnection
|
|
299
291
|
}
|
|
300
292
|
|
|
301
293
|
private onServerSocketHandshakeRequest(
|
|
302
294
|
sourcePeerDescriptor: PeerDescriptor,
|
|
303
295
|
serverWebsocket: IConnection,
|
|
296
|
+
sourceVersion: string,
|
|
304
297
|
targetPeerDescriptor?: PeerDescriptor
|
|
305
298
|
) {
|
|
306
|
-
const
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
299
|
+
const nodeId = getNodeIdFromPeerDescriptor(sourcePeerDescriptor)
|
|
300
|
+
if (this.ongoingConnectRequests.has(nodeId)) {
|
|
301
|
+
const ongoingConnectRequest = this.ongoingConnectRequests.get(nodeId)!
|
|
302
|
+
if (!isCompatibleVersion(sourceVersion, version)) {
|
|
303
|
+
ongoingConnectRequest.rejectHandshake(HandshakeError.UNSUPPORTED_VERSION)
|
|
304
|
+
} else {
|
|
305
|
+
ongoingConnectRequest.attachImplementation(serverWebsocket)
|
|
306
|
+
ongoingConnectRequest.acceptHandshake()
|
|
307
|
+
}
|
|
308
|
+
this.ongoingConnectRequests.delete(nodeId)
|
|
313
309
|
} else {
|
|
314
310
|
const managedConnection = new ManagedConnection(
|
|
315
311
|
this.localPeerDescriptor!,
|
|
@@ -318,12 +314,12 @@ export class WebsocketConnector {
|
|
|
318
314
|
serverWebsocket,
|
|
319
315
|
targetPeerDescriptor
|
|
320
316
|
)
|
|
321
|
-
|
|
322
317
|
managedConnection.setRemotePeerDescriptor(sourcePeerDescriptor)
|
|
323
|
-
|
|
324
|
-
|
|
318
|
+
if (!isCompatibleVersion(sourceVersion, version)) {
|
|
319
|
+
managedConnection.rejectHandshake(HandshakeError.UNSUPPORTED_VERSION)
|
|
320
|
+
} else if (targetPeerDescriptor && !areEqualPeerDescriptors(this.localPeerDescriptor!, targetPeerDescriptor)) {
|
|
325
321
|
managedConnection.rejectHandshake(HandshakeError.INVALID_TARGET_PEER_DESCRIPTOR)
|
|
326
|
-
} else if (this.onNewConnection(managedConnection)) {
|
|
322
|
+
} else if (this.config.onNewConnection(managedConnection)) {
|
|
327
323
|
managedConnection.acceptHandshake()
|
|
328
324
|
} else {
|
|
329
325
|
managedConnection.rejectHandshake(HandshakeError.DUPLICATE_CONNECTION)
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
2
2
|
import {
|
|
3
3
|
PeerDescriptor,
|
|
4
|
-
WebsocketConnectionRequest
|
|
5
|
-
WebsocketConnectionResponse
|
|
4
|
+
WebsocketConnectionRequest
|
|
6
5
|
} from '../../proto/packages/dht/protos/DhtRpc'
|
|
7
6
|
import { IWebsocketConnectorRpc } from '../../proto/packages/dht/protos/DhtRpc.server'
|
|
8
7
|
import { DhtCallContext } from '../../rpc-protocol/DhtCallContext'
|
|
9
8
|
import { ManagedConnection } from '../ManagedConnection'
|
|
9
|
+
import { Empty } from '../../proto/google/protobuf/empty'
|
|
10
10
|
|
|
11
11
|
interface WebsocketConnectorRpcLocalConfig {
|
|
12
12
|
connect: (targetPeerDescriptor: PeerDescriptor) => ManagedConnection
|
|
@@ -23,17 +23,15 @@ export class WebsocketConnectorRpcLocal implements IWebsocketConnectorRpc {
|
|
|
23
23
|
this.config = config
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
public async requestConnection(_request: WebsocketConnectionRequest, context: ServerCallContext): Promise<
|
|
26
|
+
public async requestConnection(_request: WebsocketConnectionRequest, context: ServerCallContext): Promise<Empty> {
|
|
27
|
+
if (this.config.abortSignal.aborted) {
|
|
28
|
+
return {}
|
|
29
|
+
}
|
|
27
30
|
const senderPeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const connection = this.config.connect(senderPeerDescriptor)
|
|
34
|
-
this.config.onNewConnection(connection)
|
|
35
|
-
}
|
|
36
|
-
})
|
|
37
|
-
return { accepted: true }
|
|
31
|
+
if (!this.config.hasConnection(senderPeerDescriptor)) {
|
|
32
|
+
const connection = this.config.connect(senderPeerDescriptor)
|
|
33
|
+
this.config.onNewConnection(connection)
|
|
34
|
+
}
|
|
35
|
+
return {}
|
|
38
36
|
}
|
|
39
37
|
}
|
|
@@ -1,27 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
WebsocketConnectionRequest,
|
|
4
|
-
WebsocketConnectionResponse
|
|
2
|
+
WebsocketConnectionRequest
|
|
5
3
|
} from '../../proto/packages/dht/protos/DhtRpc'
|
|
6
|
-
import { IWebsocketConnectorRpcClient } from '../../proto/packages/dht/protos/DhtRpc.client'
|
|
7
4
|
import { Logger } from '@streamr/utils'
|
|
8
|
-
import { ProtoRpcClient } from '@streamr/proto-rpc'
|
|
9
5
|
import { getNodeIdFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
|
|
10
6
|
import { RpcRemote } from '../../dht/contact/RpcRemote'
|
|
7
|
+
import { WebsocketConnectorRpcClient } from '../../proto/packages/dht/protos/DhtRpc.client'
|
|
11
8
|
|
|
12
9
|
const logger = new Logger(module)
|
|
13
10
|
|
|
14
|
-
export class WebsocketConnectorRpcRemote extends RpcRemote<
|
|
11
|
+
export class WebsocketConnectorRpcRemote extends RpcRemote<WebsocketConnectorRpcClient> {
|
|
15
12
|
|
|
16
|
-
|
|
17
|
-
localPeerDescriptor: PeerDescriptor,
|
|
18
|
-
remotePeerDescriptor: PeerDescriptor,
|
|
19
|
-
client: ProtoRpcClient<IWebsocketConnectorRpcClient>
|
|
20
|
-
) {
|
|
21
|
-
super(localPeerDescriptor, remotePeerDescriptor, 'DUMMY', client)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
async requestConnection(): Promise<WebsocketConnectionResponse> {
|
|
13
|
+
async requestConnection(): Promise<void> {
|
|
25
14
|
logger.trace(`Requesting WebSocket connection from ${getNodeIdFromPeerDescriptor(this.getLocalPeerDescriptor())}`)
|
|
26
15
|
const request: WebsocketConnectionRequest = {}
|
|
27
16
|
const options = this.formDhtRpcOptions()
|
|
@@ -33,24 +33,18 @@ export class WebsocketServer extends EventEmitter<ConnectionSourceEvents> {
|
|
|
33
33
|
private httpServer?: HttpServer | HttpsServer
|
|
34
34
|
private wsServer?: WsServer
|
|
35
35
|
private readonly abortController = new AbortController()
|
|
36
|
-
private readonly
|
|
37
|
-
private readonly tlsCertificate?: TlsCertificate
|
|
38
|
-
private readonly enableTls: boolean
|
|
39
|
-
private readonly maxMessageSize: number
|
|
36
|
+
private readonly config: WebsocketServerConfig
|
|
40
37
|
|
|
41
38
|
constructor(config: WebsocketServerConfig) {
|
|
42
39
|
super()
|
|
43
|
-
this.
|
|
44
|
-
this.enableTls = config.enableTls
|
|
45
|
-
this.tlsCertificate = config.tlsCertificate
|
|
46
|
-
this.maxMessageSize = config.maxMessageSize ?? 1048576
|
|
40
|
+
this.config = config
|
|
47
41
|
}
|
|
48
42
|
|
|
49
43
|
public async start(): Promise<number> {
|
|
50
|
-
const ports = range(this.portRange.min, this.portRange.max + 1)
|
|
44
|
+
const ports = range(this.config.portRange.min, this.config.portRange.max + 1)
|
|
51
45
|
for (const port of ports) {
|
|
52
46
|
try {
|
|
53
|
-
await asAbortable(this.startServer(port, this.enableTls), this.abortController.signal)
|
|
47
|
+
await asAbortable(this.startServer(port, this.config.enableTls), this.abortController.signal)
|
|
54
48
|
return port
|
|
55
49
|
} catch (err) {
|
|
56
50
|
if (err.originalError?.code === 'EADDRINUSE') {
|
|
@@ -60,7 +54,9 @@ export class WebsocketServer extends EventEmitter<ConnectionSourceEvents> {
|
|
|
60
54
|
}
|
|
61
55
|
}
|
|
62
56
|
}
|
|
63
|
-
throw new WebsocketServerStartError(
|
|
57
|
+
throw new WebsocketServerStartError(
|
|
58
|
+
`Failed to start WebSocket server on any port in range: ${this.config.portRange.min}-${this.config.portRange.min}`
|
|
59
|
+
)
|
|
64
60
|
}
|
|
65
61
|
|
|
66
62
|
// If tlsCertificate has been given the tls boolean is ignored
|
|
@@ -72,14 +68,15 @@ export class WebsocketServer extends EventEmitter<ConnectionSourceEvents> {
|
|
|
72
68
|
response.end()
|
|
73
69
|
}
|
|
74
70
|
return new Promise((resolve, reject) => {
|
|
75
|
-
if (this.tlsCertificate) {
|
|
71
|
+
if (this.config.tlsCertificate) {
|
|
76
72
|
this.httpServer = createHttpsServer({
|
|
77
|
-
key: fs.readFileSync(this.tlsCertificate.privateKeyFileName),
|
|
78
|
-
cert: fs.readFileSync(this.tlsCertificate.certFileName)
|
|
73
|
+
key: fs.readFileSync(this.config.tlsCertificate.privateKeyFileName),
|
|
74
|
+
cert: fs.readFileSync(this.config.tlsCertificate.certFileName)
|
|
79
75
|
}, requestListener)
|
|
80
76
|
} else if (!tls) {
|
|
81
77
|
this.httpServer = createHttpServer(requestListener)
|
|
82
78
|
} else {
|
|
79
|
+
// TODO use config option or named constant?
|
|
83
80
|
const certificate = createSelfSignedCertificate('streamr-self-signed-' + new UUID().toString(), 1000)
|
|
84
81
|
this.httpServer = createHttpsServer({
|
|
85
82
|
key: certificate.serverKey,
|
|
@@ -159,19 +156,19 @@ export class WebsocketServer extends EventEmitter<ConnectionSourceEvents> {
|
|
|
159
156
|
}
|
|
160
157
|
|
|
161
158
|
private createWsServer(httpServer: HttpServer | HttpsServer): WsServer {
|
|
159
|
+
const maxReceivedMessageSize = this.config.maxMessageSize ?? 1048576
|
|
162
160
|
// Use the real nodejs WebSocket server in Electron tests
|
|
163
|
-
|
|
164
161
|
if (typeof NodeJsWsServer !== 'undefined') {
|
|
165
162
|
return new NodeJsWsServer({
|
|
166
163
|
httpServer,
|
|
167
164
|
autoAcceptConnections: false,
|
|
168
|
-
maxReceivedMessageSize
|
|
165
|
+
maxReceivedMessageSize
|
|
169
166
|
})
|
|
170
167
|
} else {
|
|
171
168
|
return this.wsServer = new WsServer({
|
|
172
169
|
httpServer,
|
|
173
170
|
autoAcceptConnections: false,
|
|
174
|
-
maxReceivedMessageSize
|
|
171
|
+
maxReceivedMessageSize
|
|
175
172
|
})
|
|
176
173
|
}
|
|
177
174
|
}
|