@streamr/dht 100.2.5-beta.1 → 101.0.0-beta.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 +8 -8
- package/dist/src/connection/ConnectionLockRpcLocal.d.ts +3 -3
- package/dist/src/connection/ConnectionLockRpcLocal.js +8 -8
- package/dist/src/connection/ConnectionLockRpcLocal.js.map +1 -1
- package/dist/src/connection/ConnectionLockRpcRemote.js +1 -1
- package/dist/src/connection/ConnectionLockRpcRemote.js.map +1 -1
- package/dist/src/connection/ConnectionManager.d.ts +4 -6
- package/dist/src/connection/ConnectionManager.js +128 -103
- package/dist/src/connection/ConnectionManager.js.map +1 -1
- package/dist/src/connection/ConnectorFacade.d.ts +15 -14
- package/dist/src/connection/ConnectorFacade.js +70 -52
- package/dist/src/connection/ConnectorFacade.js.map +1 -1
- package/dist/src/connection/Handshaker.d.ts +9 -2
- package/dist/src/connection/Handshaker.js +117 -27
- package/dist/src/connection/Handshaker.js.map +1 -1
- package/dist/src/connection/ManagedConnection.d.ts +13 -38
- package/dist/src/connection/ManagedConnection.js +31 -252
- package/dist/src/connection/ManagedConnection.js.map +1 -1
- package/dist/src/connection/OutputBuffer.d.ts +9 -0
- package/dist/src/connection/OutputBuffer.js +26 -0
- package/dist/src/connection/OutputBuffer.js.map +1 -0
- package/dist/src/connection/PendingConnection.d.ts +19 -0
- package/dist/src/connection/PendingConnection.js +59 -0
- package/dist/src/connection/PendingConnection.js.map +1 -0
- package/dist/src/connection/connectivityChecker.js +3 -3
- package/dist/src/connection/connectivityChecker.js.map +1 -1
- package/dist/src/connection/connectivityRequestHandler.js +2 -2
- package/dist/src/connection/connectivityRequestHandler.js.map +1 -1
- package/dist/src/connection/simulator/Simulator.d.ts +1 -3
- package/dist/src/connection/simulator/Simulator.js +1 -4
- package/dist/src/connection/simulator/Simulator.js.map +1 -1
- package/dist/src/connection/simulator/SimulatorConnection.js +1 -2
- package/dist/src/connection/simulator/SimulatorConnection.js.map +1 -1
- package/dist/src/connection/simulator/SimulatorConnector.d.ts +3 -3
- package/dist/src/connection/simulator/SimulatorConnector.js +28 -21
- package/dist/src/connection/simulator/SimulatorConnector.js.map +1 -1
- package/dist/src/connection/webrtc/NodeWebrtcConnection.d.ts +1 -6
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js +3 -20
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnector.d.ts +11 -6
- package/dist/src/connection/webrtc/WebrtcConnector.js +57 -42
- package/dist/src/connection/webrtc/WebrtcConnector.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.d.ts +8 -10
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js +21 -44
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js.map +1 -1
- package/dist/src/connection/websocket/AbstractWebsocketClientConnection.js +8 -2
- package/dist/src/connection/websocket/AbstractWebsocketClientConnection.js.map +1 -1
- package/dist/src/connection/websocket/AutoCertifierClientFacade.d.ts +3 -3
- package/dist/src/connection/websocket/AutoCertifierClientFacade.js +8 -8
- package/dist/src/connection/websocket/AutoCertifierClientFacade.js.map +1 -1
- package/dist/src/connection/websocket/NodeWebsocketClientConnection.js +1 -1
- package/dist/src/connection/websocket/NodeWebsocketClientConnection.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketClientConnector.d.ts +26 -0
- package/dist/src/connection/websocket/WebsocketClientConnector.js +86 -0
- package/dist/src/connection/websocket/WebsocketClientConnector.js.map +1 -0
- package/dist/src/connection/websocket/WebsocketClientConnectorRpcLocal.d.ts +19 -0
- package/dist/src/connection/websocket/WebsocketClientConnectorRpcLocal.js +23 -0
- package/dist/src/connection/websocket/WebsocketClientConnectorRpcLocal.js.map +1 -0
- package/dist/src/connection/websocket/WebsocketClientConnectorRpcRemote.d.ts +5 -0
- package/dist/src/connection/websocket/{WebsocketConnectorRpcRemote.js → WebsocketClientConnectorRpcRemote.js} +4 -4
- package/dist/src/connection/websocket/WebsocketClientConnectorRpcRemote.js.map +1 -0
- package/dist/src/connection/websocket/WebsocketServer.d.ts +8 -5
- package/dist/src/connection/websocket/WebsocketServer.js +11 -11
- package/dist/src/connection/websocket/WebsocketServer.js.map +1 -1
- package/dist/src/connection/websocket/{WebsocketConnector.d.ts → WebsocketServerConnector.d.ts} +16 -21
- package/dist/src/connection/websocket/{WebsocketConnector.js → WebsocketServerConnector.js} +112 -160
- package/dist/src/connection/websocket/WebsocketServerConnector.js.map +1 -0
- package/dist/src/dht/DhtNode.d.ts +4 -4
- package/dist/src/dht/DhtNode.js +85 -84
- package/dist/src/dht/DhtNode.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcLocal.d.ts +3 -3
- package/dist/src/dht/DhtNodeRpcLocal.js +9 -9
- package/dist/src/dht/DhtNodeRpcLocal.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcLocal.d.ts +3 -3
- package/dist/src/dht/ExternalApiRpcLocal.js +5 -5
- package/dist/src/dht/ExternalApiRpcLocal.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcRemote.js +2 -2
- package/dist/src/dht/ExternalApiRpcRemote.js.map +1 -1
- package/dist/src/dht/PeerManager.d.ts +4 -4
- package/dist/src/dht/PeerManager.js +22 -22
- package/dist/src/dht/PeerManager.js.map +1 -1
- package/dist/src/dht/contact/SortedContactList.d.ts +3 -3
- package/dist/src/dht/contact/SortedContactList.js +9 -9
- package/dist/src/dht/contact/SortedContactList.js.map +1 -1
- package/dist/src/dht/discovery/DiscoverySession.d.ts +3 -3
- package/dist/src/dht/discovery/DiscoverySession.js +21 -21
- package/dist/src/dht/discovery/DiscoverySession.js.map +1 -1
- package/dist/src/dht/discovery/PeerDiscovery.d.ts +3 -3
- package/dist/src/dht/discovery/PeerDiscovery.js +46 -44
- package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -1
- package/dist/src/dht/discovery/RingDiscoverySession.d.ts +3 -3
- package/dist/src/dht/discovery/RingDiscoverySession.js +19 -19
- package/dist/src/dht/discovery/RingDiscoverySession.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.d.ts +3 -3
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.js +33 -33
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.d.ts +3 -3
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.js +8 -8
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.d.ts +4 -4
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.js +24 -24
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.d.ts +4 -4
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js +5 -5
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js.map +1 -1
- package/dist/src/dht/routing/Router.d.ts +3 -3
- package/dist/src/dht/routing/Router.js +20 -20
- package/dist/src/dht/routing/Router.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcLocal.d.ts +3 -3
- package/dist/src/dht/routing/RouterRpcLocal.js +16 -16
- package/dist/src/dht/routing/RouterRpcLocal.js.map +1 -1
- package/dist/src/dht/routing/RoutingSession.d.ts +3 -3
- package/dist/src/dht/routing/RoutingSession.js +24 -24
- package/dist/src/dht/routing/RoutingSession.js.map +1 -1
- package/dist/src/dht/store/StoreManager.d.ts +3 -3
- package/dist/src/dht/store/StoreManager.js +25 -25
- package/dist/src/dht/store/StoreManager.js.map +1 -1
- package/dist/src/dht/store/StoreRpcLocal.d.ts +3 -3
- package/dist/src/dht/store/StoreRpcLocal.js +12 -12
- package/dist/src/dht/store/StoreRpcLocal.js.map +1 -1
- package/dist/src/exports.d.ts +3 -0
- package/dist/src/exports.js +5 -1
- package/dist/src/exports.js.map +1 -1
- package/dist/src/proto/google/protobuf/any.d.ts +5 -8
- package/dist/src/proto/google/protobuf/any.js.map +1 -1
- package/dist/src/proto/google/protobuf/empty.d.ts +1 -0
- package/dist/src/proto/google/protobuf/empty.js.map +1 -1
- package/dist/src/proto/google/protobuf/timestamp.d.ts +1 -10
- package/dist/src/proto/google/protobuf/timestamp.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +4 -4
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +8 -8
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +3 -3
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +4 -4
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +2 -2
- package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.js +1 -1
- package/dist/src/transport/ListeningRpcCommunicator.d.ts +2 -2
- package/dist/src/transport/ListeningRpcCommunicator.js +2 -2
- package/dist/src/transport/ListeningRpcCommunicator.js.map +1 -1
- package/dist/src/transport/RoutingRpcCommunicator.d.ts +2 -2
- package/dist/src/transport/RoutingRpcCommunicator.js +2 -2
- package/dist/src/transport/RoutingRpcCommunicator.js.map +1 -1
- package/package.json +8 -8
- package/protos/DhtRpc.proto +1 -1
- package/src/connection/ConnectionLockRpcLocal.ts +9 -9
- package/src/connection/ConnectionLockRpcRemote.ts +1 -1
- package/src/connection/ConnectionManager.ts +153 -111
- package/src/connection/ConnectorFacade.ts +84 -61
- package/src/connection/Handshaker.ts +131 -27
- package/src/connection/ManagedConnection.ts +41 -304
- package/src/connection/OutputBuffer.ts +28 -0
- package/src/connection/PendingConnection.ts +68 -0
- package/src/connection/connectivityChecker.ts +2 -2
- package/src/connection/connectivityRequestHandler.ts +1 -1
- package/src/connection/simulator/Simulator.ts +1 -5
- package/src/connection/simulator/SimulatorConnection.ts +1 -2
- package/src/connection/simulator/SimulatorConnector.ts +34 -33
- package/src/connection/webrtc/BrowserWebrtcConnection.ts +0 -6
- package/src/connection/webrtc/NodeWebrtcConnection.ts +3 -24
- package/src/connection/webrtc/WebrtcConnector.ts +73 -62
- package/src/connection/webrtc/WebrtcConnectorRpcLocal.ts +26 -56
- package/src/connection/websocket/AbstractWebsocketClientConnection.ts +8 -2
- package/src/connection/websocket/AutoCertifierClientFacade.ts +11 -11
- package/src/connection/websocket/NodeWebsocketClientConnection.ts +1 -1
- package/src/connection/websocket/WebsocketClientConnector.ts +119 -0
- package/src/connection/websocket/WebsocketClientConnectorRpcLocal.ts +39 -0
- package/src/connection/websocket/{WebsocketConnectorRpcRemote.ts → WebsocketClientConnectorRpcRemote.ts} +2 -2
- package/src/connection/websocket/WebsocketServer.ts +18 -14
- package/src/connection/websocket/{WebsocketConnector.ts → WebsocketServerConnector.ts} +128 -205
- package/src/dht/DhtNode.ts +90 -89
- package/src/dht/DhtNodeRpcLocal.ts +11 -11
- package/src/dht/ExternalApiRpcLocal.ts +6 -6
- package/src/dht/ExternalApiRpcRemote.ts +2 -2
- package/src/dht/PeerManager.ts +24 -24
- package/src/dht/contact/SortedContactList.ts +10 -10
- package/src/dht/discovery/DiscoverySession.ts +24 -24
- package/src/dht/discovery/PeerDiscovery.ts +47 -45
- package/src/dht/discovery/RingDiscoverySession.ts +23 -23
- package/src/dht/recursive-operation/RecursiveOperationManager.ts +36 -36
- package/src/dht/recursive-operation/RecursiveOperationRpcLocal.ts +9 -9
- package/src/dht/recursive-operation/RecursiveOperationSession.ts +25 -25
- package/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.ts +7 -7
- package/src/dht/routing/Router.ts +21 -21
- package/src/dht/routing/RouterRpcLocal.ts +17 -17
- package/src/dht/routing/RoutingSession.ts +26 -26
- package/src/dht/store/StoreManager.ts +27 -27
- package/src/dht/store/StoreRpcLocal.ts +13 -13
- package/src/exports.ts +3 -0
- package/src/proto/google/protobuf/any.ts +6 -9
- package/src/proto/google/protobuf/empty.ts +2 -1
- package/src/proto/google/protobuf/timestamp.ts +2 -11
- package/src/proto/packages/dht/protos/DhtRpc.client.ts +9 -9
- package/src/proto/packages/dht/protos/DhtRpc.server.ts +3 -3
- package/src/proto/packages/dht/protos/DhtRpc.ts +4 -4
- package/src/proto/packages/proto-rpc/protos/ProtoRpc.ts +1 -1
- package/src/transport/ListeningRpcCommunicator.ts +3 -3
- package/src/transport/RoutingRpcCommunicator.ts +3 -3
- package/test/end-to-end/Layer0Webrtc.test.ts +0 -10
- package/test/integration/ConnectionManager.test.ts +3 -2
- package/test/integration/GeoIpConnectivityChecking.test.ts +1 -1
- package/test/integration/SimultaneousConnections.test.ts +2 -2
- package/test/integration/WebrtcConnectionManagement.test.ts +2 -10
- package/test/integration/{WebsocketConnectorRpc.test.ts → WebsocketClientConnectorRpc.test.ts} +9 -9
- package/test/integration/WebsocketConnectionManagement.test.ts +11 -29
- package/test/unit/ConnectionManager.test.ts +64 -0
- package/test/unit/DiscoverySession.test.ts +1 -1
- package/test/unit/Handshaker.test.ts +169 -0
- package/test/unit/ManagedConnection.test.ts +58 -0
- package/test/unit/PendingConnection.test.ts +57 -0
- package/test/unit/WebrtcConnector.test.ts +56 -0
- package/test/unit/{WebsocketConnector.test.ts → WebsocketClientConnector.test.ts} +56 -11
- package/test/unit/WebsocketServerConnector.test.ts +102 -0
- package/test/utils/FakeConnectorFacade.ts +41 -0
- package/test/utils/mock/MockConnection.ts +26 -0
- package/test/utils/utils.ts +2 -2
- package/dist/src/connection/IConnectionSource.d.ts +0 -4
- package/dist/src/connection/IConnectionSource.js +0 -3
- package/dist/src/connection/IConnectionSource.js.map +0 -1
- package/dist/src/connection/webrtc/ManagedWebrtcConnection.d.ts +0 -7
- package/dist/src/connection/webrtc/ManagedWebrtcConnection.js +0 -20
- package/dist/src/connection/webrtc/ManagedWebrtcConnection.js.map +0 -1
- package/dist/src/connection/websocket/WebsocketConnector.js.map +0 -1
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.d.ts +0 -19
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.js +0 -23
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.js.map +0 -1
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.d.ts +0 -5
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.js.map +0 -1
- package/src/connection/IConnectionSource.ts +0 -6
- package/src/connection/webrtc/ManagedWebrtcConnection.ts +0 -27
- package/src/connection/websocket/WebsocketConnectorRpcLocal.ts +0 -39
|
@@ -13,12 +13,6 @@ enum DisconnectedRtcPeerConnectionStateEnum {
|
|
|
13
13
|
|
|
14
14
|
const logger = new Logger(module)
|
|
15
15
|
|
|
16
|
-
export const WEBRTC_CLEANUP = new class {
|
|
17
|
-
// eslint-disable-next-line class-methods-use-this
|
|
18
|
-
cleanUp(): void {
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
16
|
type Events = WebrtcConnectionEvents & ConnectionEvents
|
|
23
17
|
|
|
24
18
|
interface Params {
|
|
@@ -2,7 +2,7 @@ import { IWebrtcConnection, WebrtcConnectionEvents } from './IWebrtcConnection'
|
|
|
2
2
|
import { ConnectionType, IConnection, ConnectionID, ConnectionEvents } from '../IConnection'
|
|
3
3
|
import { PeerDescriptor } from '../../proto/packages/dht/protos/DhtRpc'
|
|
4
4
|
import EventEmitter from 'eventemitter3'
|
|
5
|
-
import { DataChannel, DescriptionType, PeerConnection,
|
|
5
|
+
import { DataChannel, DescriptionType, PeerConnection, initLogger } from 'node-datachannel'
|
|
6
6
|
import { Logger } from '@streamr/utils'
|
|
7
7
|
import { IllegalRtcPeerConnectionState } from '../../helpers/errors'
|
|
8
8
|
import { iceServerAsString } from './iceServerAsString'
|
|
@@ -13,18 +13,10 @@ import { createRandomConnectionId } from '../Connection'
|
|
|
13
13
|
|
|
14
14
|
const logger = new Logger(module)
|
|
15
15
|
|
|
16
|
-
export const WEBRTC_CLEANUP = new class {
|
|
17
|
-
// eslint-disable-next-line class-methods-use-this
|
|
18
|
-
cleanUp(): void {
|
|
19
|
-
cleanup()
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
16
|
export interface Params {
|
|
24
17
|
remotePeerDescriptor: PeerDescriptor
|
|
25
18
|
bufferThresholdHigh?: number
|
|
26
19
|
bufferThresholdLow?: number
|
|
27
|
-
connectingTimeout?: number
|
|
28
20
|
maxMessageSize?: number
|
|
29
21
|
iceServers?: IceServer[] // TODO make this parameter required (empty array is a good fallback which can be set by the caller if needed)
|
|
30
22
|
portRange?: PortRange
|
|
@@ -55,16 +47,15 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IConne
|
|
|
55
47
|
private dataChannel?: DataChannel
|
|
56
48
|
private lastState: RtcPeerConnectionState = 'connecting'
|
|
57
49
|
private remoteDescriptionSet = false
|
|
58
|
-
private connectingTimeoutRef?: NodeJS.Timeout
|
|
59
50
|
public readonly connectionType: ConnectionType = ConnectionType.WEBRTC
|
|
60
51
|
private readonly iceServers: IceServer[]
|
|
61
52
|
private readonly _bufferThresholdHigh: number // TODO: buffer handling must be implemented before production use (NET-938)
|
|
62
53
|
private readonly bufferThresholdLow: number
|
|
63
|
-
private readonly connectingTimeout: number
|
|
64
54
|
private readonly remotePeerDescriptor: PeerDescriptor
|
|
65
55
|
private readonly portRange?: PortRange
|
|
66
56
|
private readonly maxMessageSize?: number
|
|
67
57
|
private closed = false
|
|
58
|
+
private offering?: boolean
|
|
68
59
|
|
|
69
60
|
constructor(params: Params) {
|
|
70
61
|
super()
|
|
@@ -73,7 +64,6 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IConne
|
|
|
73
64
|
// eslint-disable-next-line no-underscore-dangle
|
|
74
65
|
this._bufferThresholdHigh = params.bufferThresholdHigh ?? 2 ** 17
|
|
75
66
|
this.bufferThresholdLow = params.bufferThresholdLow ?? 2 ** 15
|
|
76
|
-
this.connectingTimeout = params.connectingTimeout ?? 20000
|
|
77
67
|
this.remotePeerDescriptor = params.remotePeerDescriptor
|
|
78
68
|
this.maxMessageSize = params.maxMessageSize ?? 1048576
|
|
79
69
|
this.portRange = params.portRange
|
|
@@ -81,6 +71,7 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IConne
|
|
|
81
71
|
|
|
82
72
|
public start(isOffering: boolean): void {
|
|
83
73
|
const nodeId = getNodeIdFromPeerDescriptor(this.remotePeerDescriptor)
|
|
74
|
+
this.offering = isOffering
|
|
84
75
|
logger.trace(`Starting new connection for peer ${nodeId}`, { isOffering })
|
|
85
76
|
this.connection = new PeerConnection(nodeId, {
|
|
86
77
|
iceServers: this.iceServers.map(iceServerAsString),
|
|
@@ -89,11 +80,6 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IConne
|
|
|
89
80
|
portRangeEnd: this.portRange?.max,
|
|
90
81
|
})
|
|
91
82
|
|
|
92
|
-
this.connectingTimeoutRef = setTimeout(() => {
|
|
93
|
-
logger.trace('connectingTimeout, this.closed === ' + this.closed)
|
|
94
|
-
this.doClose(false)
|
|
95
|
-
}, this.connectingTimeout)
|
|
96
|
-
|
|
97
83
|
this.connection.onStateChange((state: string) => this.onStateChange(state))
|
|
98
84
|
this.connection.onGatheringStateChange(() => {})
|
|
99
85
|
|
|
@@ -169,10 +155,6 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IConne
|
|
|
169
155
|
|
|
170
156
|
this.emit('disconnected', gracefulLeave, undefined, reason)
|
|
171
157
|
this.removeAllListeners()
|
|
172
|
-
|
|
173
|
-
if (this.connectingTimeoutRef) {
|
|
174
|
-
clearTimeout(this.connectingTimeoutRef)
|
|
175
|
-
}
|
|
176
158
|
|
|
177
159
|
if (this.dataChannel) {
|
|
178
160
|
try {
|
|
@@ -226,9 +208,6 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IConne
|
|
|
226
208
|
}
|
|
227
209
|
|
|
228
210
|
private onDataChannelOpen(): void {
|
|
229
|
-
if (this.connectingTimeoutRef) {
|
|
230
|
-
clearTimeout(this.connectingTimeoutRef)
|
|
231
|
-
}
|
|
232
211
|
logger.trace(`DataChannel opened for peer ${getNodeIdFromPeerDescriptor(this.remotePeerDescriptor)}`)
|
|
233
212
|
this.emit('connected')
|
|
234
213
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
HandshakeError,
|
|
2
3
|
IceCandidate,
|
|
3
4
|
PeerDescriptor,
|
|
4
5
|
RtcAnswer,
|
|
@@ -9,15 +10,16 @@ import { ListeningRpcCommunicator } from '../../transport/ListeningRpcCommunicat
|
|
|
9
10
|
import { NodeWebrtcConnection } from './NodeWebrtcConnection'
|
|
10
11
|
import { WebrtcConnectorRpcRemote } from './WebrtcConnectorRpcRemote'
|
|
11
12
|
import { WebrtcConnectorRpcClient } from '../../proto/packages/dht/protos/DhtRpc.client'
|
|
12
|
-
import { ManagedWebrtcConnection } from './ManagedWebrtcConnection'
|
|
13
13
|
import { Logger } from '@streamr/utils'
|
|
14
14
|
import * as Err from '../../helpers/errors'
|
|
15
|
-
import { ManagedConnection } from '../ManagedConnection'
|
|
16
15
|
import { PortRange } from '../ConnectionManager'
|
|
17
16
|
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
18
17
|
import { WebrtcConnectorRpcLocal } from './WebrtcConnectorRpcLocal'
|
|
19
18
|
import { DhtAddress, areEqualPeerDescriptors, getNodeIdFromPeerDescriptor } from '../../identifiers'
|
|
20
19
|
import { getOfferer } from '../../helpers/offering'
|
|
20
|
+
import { acceptHandshake, createIncomingHandshaker, createOutgoingHandshaker, rejectHandshake } from '../Handshaker'
|
|
21
|
+
import { isMaybeSupportedVersion } from '../../helpers/version'
|
|
22
|
+
import { PendingConnection } from '../PendingConnection'
|
|
21
23
|
|
|
22
24
|
const logger = new Logger(module)
|
|
23
25
|
|
|
@@ -30,14 +32,14 @@ export const replaceInternalIpWithExternalIp = (candidate: string, ip: string):
|
|
|
30
32
|
return parsed.join(' ')
|
|
31
33
|
}
|
|
32
34
|
|
|
33
|
-
export interface
|
|
35
|
+
export interface WebrtcConnectorOptions {
|
|
36
|
+
onNewConnection: (connection: PendingConnection) => boolean
|
|
34
37
|
transport: ITransport
|
|
35
38
|
iceServers?: IceServer[]
|
|
36
39
|
allowPrivateAddresses?: boolean
|
|
37
40
|
bufferThresholdLow?: number
|
|
38
41
|
bufferThresholdHigh?: number
|
|
39
42
|
maxMessageSize?: number
|
|
40
|
-
connectionTimeout?: number
|
|
41
43
|
externalIp?: string
|
|
42
44
|
portRange?: PortRange
|
|
43
45
|
}
|
|
@@ -50,38 +52,37 @@ export interface IceServer {
|
|
|
50
52
|
tcp?: boolean
|
|
51
53
|
}
|
|
52
54
|
|
|
55
|
+
export interface ConnectingConnection {
|
|
56
|
+
managedConnection: PendingConnection
|
|
57
|
+
connection: NodeWebrtcConnection
|
|
58
|
+
}
|
|
59
|
+
|
|
53
60
|
export class WebrtcConnector {
|
|
54
61
|
|
|
55
62
|
private static readonly WEBRTC_CONNECTOR_SERVICE_ID = 'system/webrtc-connector'
|
|
56
63
|
private readonly rpcCommunicator: ListeningRpcCommunicator
|
|
57
|
-
private readonly ongoingConnectAttempts: Map<DhtAddress,
|
|
64
|
+
private readonly ongoingConnectAttempts: Map<DhtAddress, ConnectingConnection> = new Map()
|
|
58
65
|
private localPeerDescriptor?: PeerDescriptor
|
|
59
66
|
private stopped = false
|
|
60
|
-
private
|
|
61
|
-
|
|
62
|
-
constructor(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
this.config = config
|
|
67
|
-
this.rpcCommunicator = new ListeningRpcCommunicator(WebrtcConnector.WEBRTC_CONNECTOR_SERVICE_ID, config.transport, {
|
|
68
|
-
rpcRequestTimeout: 15000 // TODO use config option or named constant?
|
|
67
|
+
private options: WebrtcConnectorOptions
|
|
68
|
+
|
|
69
|
+
constructor(options: WebrtcConnectorOptions) {
|
|
70
|
+
this.options = options
|
|
71
|
+
this.rpcCommunicator = new ListeningRpcCommunicator(WebrtcConnector.WEBRTC_CONNECTOR_SERVICE_ID, options.transport, {
|
|
72
|
+
rpcRequestTimeout: 15000 // TODO use options option or named constant?
|
|
69
73
|
})
|
|
70
|
-
this.registerLocalRpcMethods(
|
|
74
|
+
this.registerLocalRpcMethods(options)
|
|
71
75
|
}
|
|
72
76
|
|
|
73
|
-
private registerLocalRpcMethods(
|
|
74
|
-
config: WebrtcConnectorConfig,
|
|
75
|
-
onNewConnection: (connection: ManagedConnection) => boolean
|
|
76
|
-
) {
|
|
77
|
+
private registerLocalRpcMethods(options: WebrtcConnectorOptions) {
|
|
77
78
|
const localRpc = new WebrtcConnectorRpcLocal({
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
onNewConnection,
|
|
79
|
+
connect: (targetPeerDescriptor: PeerDescriptor, doNotRequestConnection: boolean) =>
|
|
80
|
+
this.connect(targetPeerDescriptor, doNotRequestConnection),
|
|
81
|
+
onNewConnection: (connection: PendingConnection) => this.options.onNewConnection(connection),
|
|
81
82
|
ongoingConnectAttempts: this.ongoingConnectAttempts,
|
|
82
83
|
rpcCommunicator: this.rpcCommunicator,
|
|
83
84
|
getLocalPeerDescriptor: () => this.localPeerDescriptor!,
|
|
84
|
-
allowPrivateAddresses:
|
|
85
|
+
allowPrivateAddresses: options.allowPrivateAddresses ?? true
|
|
85
86
|
})
|
|
86
87
|
this.rpcCommunicator.registerRpcNotification(WebrtcConnectionRequest, 'requestConnection',
|
|
87
88
|
async (_req: WebrtcConnectionRequest, context: ServerCallContext) => {
|
|
@@ -121,7 +122,7 @@ export class WebrtcConnector {
|
|
|
121
122
|
)
|
|
122
123
|
}
|
|
123
124
|
|
|
124
|
-
connect(targetPeerDescriptor: PeerDescriptor):
|
|
125
|
+
connect(targetPeerDescriptor: PeerDescriptor, doNotRequestConnection: boolean): PendingConnection {
|
|
125
126
|
if (areEqualPeerDescriptors(targetPeerDescriptor, this.localPeerDescriptor!)) {
|
|
126
127
|
throw new Err.CannotConnectToSelf('Cannot open WebRTC Connection to self')
|
|
127
128
|
}
|
|
@@ -131,7 +132,7 @@ export class WebrtcConnector {
|
|
|
131
132
|
const nodeId = getNodeIdFromPeerDescriptor(targetPeerDescriptor)
|
|
132
133
|
const existingConnection = this.ongoingConnectAttempts.get(nodeId)
|
|
133
134
|
if (existingConnection) {
|
|
134
|
-
return existingConnection
|
|
135
|
+
return existingConnection.managedConnection
|
|
135
136
|
}
|
|
136
137
|
|
|
137
138
|
const connection = this.createConnection(targetPeerDescriptor)
|
|
@@ -139,68 +140,75 @@ export class WebrtcConnector {
|
|
|
139
140
|
const localNodeId = getNodeIdFromPeerDescriptor(this.localPeerDescriptor!)
|
|
140
141
|
const targetNodeId = getNodeIdFromPeerDescriptor(targetPeerDescriptor)
|
|
141
142
|
const offering = (getOfferer(localNodeId, targetNodeId) === 'local')
|
|
142
|
-
let
|
|
143
|
-
|
|
144
|
-
if (offering) {
|
|
145
|
-
managedConnection = new ManagedWebrtcConnection(this.localPeerDescriptor!, connection)
|
|
146
|
-
} else {
|
|
147
|
-
managedConnection = new ManagedWebrtcConnection(this.localPeerDescriptor!, undefined, connection)
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
managedConnection.setRemotePeerDescriptor(targetPeerDescriptor)
|
|
151
|
-
|
|
152
|
-
this.ongoingConnectAttempts.set(targetNodeId, managedConnection)
|
|
153
|
-
|
|
154
|
-
const delFunc = () => {
|
|
155
|
-
this.ongoingConnectAttempts.delete(nodeId)
|
|
156
|
-
connection.off('disconnected', delFunc)
|
|
157
|
-
managedConnection.off('handshakeCompleted', delFunc)
|
|
158
|
-
}
|
|
159
|
-
connection.on('disconnected', delFunc)
|
|
160
|
-
managedConnection.on('handshakeCompleted', delFunc)
|
|
161
|
-
|
|
143
|
+
let pendingConnection: PendingConnection
|
|
162
144
|
const remoteConnector = new WebrtcConnectorRpcRemote(
|
|
163
145
|
this.localPeerDescriptor!,
|
|
164
146
|
targetPeerDescriptor,
|
|
165
147
|
this.rpcCommunicator,
|
|
166
148
|
WebrtcConnectorRpcClient
|
|
167
149
|
)
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
remoteConnector.sendIceCandidate(candidate, mid, connection.connectionId)
|
|
175
|
-
})
|
|
176
|
-
|
|
150
|
+
const delFunc = () => {
|
|
151
|
+
this.ongoingConnectAttempts.delete(nodeId)
|
|
152
|
+
connection.off('disconnected', delFunc)
|
|
153
|
+
pendingConnection.off('disconnected', delFunc)
|
|
154
|
+
pendingConnection.off('connected', delFunc)
|
|
155
|
+
}
|
|
177
156
|
if (offering) {
|
|
157
|
+
pendingConnection = new PendingConnection(targetPeerDescriptor)
|
|
158
|
+
createOutgoingHandshaker(this.localPeerDescriptor!, pendingConnection, connection, targetPeerDescriptor)
|
|
178
159
|
connection.once('localDescription', (description: string) => {
|
|
160
|
+
logger.trace('Sending offer to remote peer')
|
|
179
161
|
remoteConnector.sendRtcOffer(description, connection.connectionId)
|
|
180
162
|
})
|
|
181
163
|
} else {
|
|
164
|
+
pendingConnection = new PendingConnection(targetPeerDescriptor)
|
|
165
|
+
const handshaker = createIncomingHandshaker(this.localPeerDescriptor!, pendingConnection, connection)
|
|
182
166
|
connection.once('localDescription', (description: string) => {
|
|
183
167
|
remoteConnector.sendRtcAnswer(description, connection.connectionId)
|
|
184
168
|
})
|
|
169
|
+
handshaker.on('handshakeRequest', (_sourceDescriptor: PeerDescriptor, remoteVersion: string) => {
|
|
170
|
+
if (!isMaybeSupportedVersion(remoteVersion)) {
|
|
171
|
+
rejectHandshake(pendingConnection!, connection, handshaker, HandshakeError.UNSUPPORTED_VERSION)
|
|
172
|
+
} else {
|
|
173
|
+
acceptHandshake(handshaker, pendingConnection, connection)
|
|
174
|
+
}
|
|
175
|
+
delFunc()
|
|
176
|
+
})
|
|
185
177
|
}
|
|
186
178
|
|
|
179
|
+
this.ongoingConnectAttempts.set(targetNodeId, {
|
|
180
|
+
managedConnection: pendingConnection,
|
|
181
|
+
connection
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
connection.on('disconnected', delFunc)
|
|
185
|
+
pendingConnection.on('disconnected', delFunc)
|
|
186
|
+
pendingConnection.on('connected', delFunc)
|
|
187
|
+
|
|
188
|
+
connection.on('localCandidate', (candidate: string, mid: string) => {
|
|
189
|
+
if (this.options.externalIp !== undefined) {
|
|
190
|
+
candidate = replaceInternalIpWithExternalIp(candidate, this.options.externalIp)
|
|
191
|
+
logger.debug(`onLocalCandidate injected external ip ${candidate} ${mid}`)
|
|
192
|
+
}
|
|
193
|
+
remoteConnector.sendIceCandidate(candidate, mid, connection.connectionId)
|
|
194
|
+
})
|
|
195
|
+
|
|
187
196
|
connection.start(offering)
|
|
188
197
|
|
|
189
|
-
if (!offering) {
|
|
198
|
+
if (!doNotRequestConnection && !offering) {
|
|
190
199
|
remoteConnector.requestConnection()
|
|
191
200
|
}
|
|
192
201
|
|
|
193
|
-
return
|
|
202
|
+
return pendingConnection
|
|
194
203
|
}
|
|
195
204
|
|
|
196
205
|
private createConnection(targetPeerDescriptor: PeerDescriptor): NodeWebrtcConnection {
|
|
197
206
|
return new NodeWebrtcConnection({
|
|
198
207
|
remotePeerDescriptor: targetPeerDescriptor,
|
|
199
|
-
iceServers: this.
|
|
200
|
-
bufferThresholdLow: this.
|
|
201
|
-
bufferThresholdHigh: this.
|
|
202
|
-
|
|
203
|
-
portRange: this.config.portRange
|
|
208
|
+
iceServers: this.options.iceServers,
|
|
209
|
+
bufferThresholdLow: this.options.bufferThresholdLow,
|
|
210
|
+
bufferThresholdHigh: this.options.bufferThresholdHigh,
|
|
211
|
+
portRange: this.options.portRange
|
|
204
212
|
// TODO should we pass maxMessageSize?
|
|
205
213
|
})
|
|
206
214
|
}
|
|
@@ -214,7 +222,10 @@ export class WebrtcConnector {
|
|
|
214
222
|
this.stopped = true
|
|
215
223
|
|
|
216
224
|
const attempts = Array.from(this.ongoingConnectAttempts.values())
|
|
217
|
-
await Promise.allSettled(attempts.map((conn) =>
|
|
225
|
+
await Promise.allSettled(attempts.map(async (conn) => {
|
|
226
|
+
conn.connection.destroy()
|
|
227
|
+
await conn.managedConnection.close(false)
|
|
228
|
+
}))
|
|
218
229
|
|
|
219
230
|
this.rpcCommunicator.destroy()
|
|
220
231
|
}
|
|
@@ -3,32 +3,27 @@ import { Logger } from '@streamr/utils'
|
|
|
3
3
|
import { getAddressFromIceCandidate, isPrivateIPv4 } from '../../helpers/AddressTools'
|
|
4
4
|
import { Empty } from '../../proto/google/protobuf/empty'
|
|
5
5
|
import {
|
|
6
|
-
HandshakeError,
|
|
7
6
|
IceCandidate,
|
|
8
7
|
PeerDescriptor,
|
|
9
8
|
RtcAnswer,
|
|
10
9
|
RtcOffer
|
|
11
10
|
} from '../../proto/packages/dht/protos/DhtRpc'
|
|
12
|
-
import { WebrtcConnectorRpcClient } from '../../proto/packages/dht/protos/DhtRpc.client'
|
|
13
11
|
import { IWebrtcConnectorRpc } from '../../proto/packages/dht/protos/DhtRpc.server'
|
|
14
12
|
import { DhtCallContext } from '../../rpc-protocol/DhtCallContext'
|
|
15
13
|
import { ListeningRpcCommunicator } from '../../transport/ListeningRpcCommunicator'
|
|
16
|
-
import { ManagedConnection } from '../ManagedConnection'
|
|
17
|
-
import { ManagedWebrtcConnection } from './ManagedWebrtcConnection'
|
|
18
14
|
import { NodeWebrtcConnection } from './NodeWebrtcConnection'
|
|
19
|
-
import { WebrtcConnectorRpcRemote } from './WebrtcConnectorRpcRemote'
|
|
20
15
|
import { DhtAddress, getNodeIdFromPeerDescriptor } from '../../identifiers'
|
|
21
|
-
import { isMaybeSupportedVersion } from '../../helpers/version'
|
|
22
16
|
import { ConnectionID } from '../IConnection'
|
|
17
|
+
import { ConnectingConnection } from './WebrtcConnector'
|
|
18
|
+
import { PendingConnection } from '../PendingConnection'
|
|
23
19
|
|
|
24
20
|
const logger = new Logger(module)
|
|
25
21
|
|
|
26
|
-
interface
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
onNewConnection: (connection: ManagedConnection) => boolean
|
|
22
|
+
interface WebrtcConnectorRpcLocalOptions {
|
|
23
|
+
connect: (targetPeerDescriptor: PeerDescriptor, doNotRequestConnection: boolean) => PendingConnection
|
|
24
|
+
onNewConnection: (connection: PendingConnection) => boolean
|
|
30
25
|
// TODO pass accessor methods instead of passing a mutable entity
|
|
31
|
-
ongoingConnectAttempts: Map<DhtAddress,
|
|
26
|
+
ongoingConnectAttempts: Map<DhtAddress, ConnectingConnection>
|
|
32
27
|
rpcCommunicator: ListeningRpcCommunicator
|
|
33
28
|
getLocalPeerDescriptor: () => PeerDescriptor
|
|
34
29
|
allowPrivateAddresses: boolean
|
|
@@ -36,71 +31,46 @@ interface WebrtcConnectorRpcLocalConfig {
|
|
|
36
31
|
|
|
37
32
|
export class WebrtcConnectorRpcLocal implements IWebrtcConnectorRpc {
|
|
38
33
|
|
|
39
|
-
private readonly
|
|
34
|
+
private readonly options: WebrtcConnectorRpcLocalOptions
|
|
40
35
|
|
|
41
|
-
constructor(
|
|
42
|
-
this.
|
|
36
|
+
constructor(options: WebrtcConnectorRpcLocalOptions) {
|
|
37
|
+
this.options = options
|
|
43
38
|
}
|
|
44
39
|
|
|
45
40
|
async requestConnection(context: ServerCallContext): Promise<Empty> {
|
|
46
41
|
const targetPeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
|
|
47
|
-
if (this.
|
|
42
|
+
if (this.options.ongoingConnectAttempts.has(getNodeIdFromPeerDescriptor(targetPeerDescriptor))) {
|
|
48
43
|
return {}
|
|
49
44
|
}
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
this.config.onNewConnection(managedConnection)
|
|
45
|
+
const pendingConnection = this.options.connect(targetPeerDescriptor, false)
|
|
46
|
+
this.options.onNewConnection(pendingConnection)
|
|
53
47
|
return {}
|
|
54
48
|
}
|
|
55
49
|
|
|
56
50
|
async rtcOffer(request: RtcOffer, context: ServerCallContext): Promise<Empty> {
|
|
57
|
-
const
|
|
58
|
-
const nodeId = getNodeIdFromPeerDescriptor(
|
|
59
|
-
let
|
|
60
|
-
let
|
|
51
|
+
const remotePeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
|
|
52
|
+
const nodeId = getNodeIdFromPeerDescriptor(remotePeerDescriptor)
|
|
53
|
+
let connection: NodeWebrtcConnection
|
|
54
|
+
let pendingConnection: PendingConnection
|
|
61
55
|
|
|
62
|
-
if (!
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
this.
|
|
68
|
-
|
|
69
|
-
this.config.getLocalPeerDescriptor(),
|
|
70
|
-
remotePeer,
|
|
71
|
-
this.config.rpcCommunicator,
|
|
72
|
-
WebrtcConnectorRpcClient
|
|
73
|
-
)
|
|
74
|
-
connection.on('localCandidate', (candidate: string, mid: string) => {
|
|
75
|
-
remoteConnector.sendIceCandidate(candidate, mid, connection!.connectionId)
|
|
76
|
-
})
|
|
77
|
-
connection.once('localDescription', (description: string) => {
|
|
78
|
-
remoteConnector.sendRtcAnswer(description, connection!.connectionId)
|
|
79
|
-
})
|
|
80
|
-
connection.start(false)
|
|
56
|
+
if (!this.options.ongoingConnectAttempts.has(nodeId)) {
|
|
57
|
+
pendingConnection = this.options.connect(remotePeerDescriptor, true)
|
|
58
|
+
connection = this.options.ongoingConnectAttempts.get(nodeId)!.connection
|
|
59
|
+
this.options.onNewConnection(pendingConnection)
|
|
60
|
+
} else {
|
|
61
|
+
pendingConnection = this.options.ongoingConnectAttempts.get(nodeId)!.managedConnection
|
|
62
|
+
connection = this.options.ongoingConnectAttempts.get(nodeId)!.connection
|
|
81
63
|
}
|
|
82
|
-
|
|
83
64
|
// Always use offerers connectionId
|
|
84
65
|
connection!.setConnectionId(request.connectionId as ConnectionID)
|
|
85
66
|
connection!.setRemoteDescription(request.description, 'offer')
|
|
86
|
-
|
|
87
|
-
managedConnection.on('handshakeRequest', (_sourceDescriptor: PeerDescriptor, remoteVersion: string) => {
|
|
88
|
-
if (this.config.ongoingConnectAttempts.has(nodeId)) {
|
|
89
|
-
this.config.ongoingConnectAttempts.delete(nodeId)
|
|
90
|
-
}
|
|
91
|
-
if (!isMaybeSupportedVersion(remoteVersion)) {
|
|
92
|
-
managedConnection.rejectHandshake(HandshakeError.UNSUPPORTED_VERSION)
|
|
93
|
-
} else {
|
|
94
|
-
managedConnection.acceptHandshake()
|
|
95
|
-
}
|
|
96
|
-
})
|
|
97
67
|
return {}
|
|
98
68
|
}
|
|
99
69
|
|
|
100
70
|
async rtcAnswer(request: RtcAnswer, context: ServerCallContext): Promise<Empty> {
|
|
101
71
|
const remotePeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
|
|
102
72
|
const nodeId = getNodeIdFromPeerDescriptor(remotePeerDescriptor)
|
|
103
|
-
const connection = this.
|
|
73
|
+
const connection = this.options.ongoingConnectAttempts.get(nodeId)?.connection
|
|
104
74
|
if (!connection) {
|
|
105
75
|
return {}
|
|
106
76
|
} else if (connection.connectionId !== request.connectionId) {
|
|
@@ -114,7 +84,7 @@ export class WebrtcConnectorRpcLocal implements IWebrtcConnectorRpc {
|
|
|
114
84
|
async iceCandidate(request: IceCandidate, context: ServerCallContext): Promise<Empty> {
|
|
115
85
|
const remotePeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
|
|
116
86
|
const nodeId = getNodeIdFromPeerDescriptor(remotePeerDescriptor)
|
|
117
|
-
const connection = this.
|
|
87
|
+
const connection = this.options.ongoingConnectAttempts.get(nodeId)?.connection
|
|
118
88
|
if (!connection) {
|
|
119
89
|
return {}
|
|
120
90
|
} else if (connection.connectionId !== request.connectionId) {
|
|
@@ -127,7 +97,7 @@ export class WebrtcConnectorRpcLocal implements IWebrtcConnectorRpc {
|
|
|
127
97
|
}
|
|
128
98
|
|
|
129
99
|
private isIceCandidateAllowed(candidate: string): boolean {
|
|
130
|
-
if (!this.
|
|
100
|
+
if (!this.options.allowPrivateAddresses) {
|
|
131
101
|
const address = getAddressFromIceCandidate(candidate)
|
|
132
102
|
if ((address !== undefined) && isPrivateIPv4(address)) {
|
|
133
103
|
return false
|
|
@@ -44,7 +44,13 @@ export abstract class AbstractWebsocketClientConnection extends EventEmitter<Con
|
|
|
44
44
|
logger.trace(`Sending data with size ${data.byteLength}`)
|
|
45
45
|
this.socket?.send(data)
|
|
46
46
|
} else {
|
|
47
|
-
|
|
47
|
+
// Could this throw for faster feedback on RPC calls?
|
|
48
|
+
// Currently this log line is seen if a connection is closing but the disconnected event has not been emitted yet.
|
|
49
|
+
logger.debug('Tried to send data on a non-open connection', {
|
|
50
|
+
id: this.connectionId,
|
|
51
|
+
readyState: this.socket!.readyState,
|
|
52
|
+
destroyed: this.destroyed
|
|
53
|
+
})
|
|
48
54
|
}
|
|
49
55
|
} else {
|
|
50
56
|
logger.debug('Tried to send() on stopped connection')
|
|
@@ -58,7 +64,7 @@ export abstract class AbstractWebsocketClientConnection extends EventEmitter<Con
|
|
|
58
64
|
logger.trace(`Closing socket for connection ${this.connectionId}`)
|
|
59
65
|
this.socket?.close(gracefulLeave ? CUSTOM_GOING_AWAY : undefined)
|
|
60
66
|
} else {
|
|
61
|
-
logger.debug('Tried to close() a stopped connection')
|
|
67
|
+
logger.debug('Tried to close() a stopped connection', { id: this.connectionId })
|
|
62
68
|
}
|
|
63
69
|
}
|
|
64
70
|
|
|
@@ -37,7 +37,7 @@ export interface IAutoCertifierClient {
|
|
|
37
37
|
on(eventName: string, cb: (subdomain: CertifiedSubdomain) => void): void
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
interface
|
|
40
|
+
interface AutoCertifierClientFacadeOptions {
|
|
41
41
|
url: string
|
|
42
42
|
configFile: string
|
|
43
43
|
transport: ITransport
|
|
@@ -55,24 +55,24 @@ export class AutoCertifierClientFacade {
|
|
|
55
55
|
|
|
56
56
|
private autoCertifierClient: IAutoCertifierClient
|
|
57
57
|
private readonly rpcCommunicator: ListeningRpcCommunicator
|
|
58
|
-
private readonly
|
|
58
|
+
private readonly options: AutoCertifierClientFacadeOptions
|
|
59
59
|
|
|
60
|
-
constructor(
|
|
61
|
-
this.
|
|
62
|
-
this.rpcCommunicator = new ListeningRpcCommunicator(AUTO_CERTIFIER_SERVICE_ID,
|
|
63
|
-
this.autoCertifierClient =
|
|
60
|
+
constructor(options: AutoCertifierClientFacadeOptions) {
|
|
61
|
+
this.options = options
|
|
62
|
+
this.rpcCommunicator = new ListeningRpcCommunicator(AUTO_CERTIFIER_SERVICE_ID, options.transport)
|
|
63
|
+
this.autoCertifierClient = options.createClientFactory ? options.createClientFactory()
|
|
64
64
|
: defaultAutoCertifierClientFactory(
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
options.configFile,
|
|
66
|
+
options.url,
|
|
67
67
|
this.rpcCommunicator,
|
|
68
|
-
|
|
68
|
+
options.wsServerPort
|
|
69
69
|
)
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
async start(): Promise<void> {
|
|
73
73
|
this.autoCertifierClient.on('updatedCertificate', (subdomain: CertifiedSubdomain) => {
|
|
74
|
-
this.
|
|
75
|
-
this.
|
|
74
|
+
this.options.setHost(subdomain.fqdn)
|
|
75
|
+
this.options.updateCertificate(subdomain.certificate, subdomain.privateKey)
|
|
76
76
|
logger.trace(`Updated certificate`)
|
|
77
77
|
})
|
|
78
78
|
await Promise.all([
|
|
@@ -28,7 +28,7 @@ export class WebsocketClientConnection extends AbstractWebsocketClientConnection
|
|
|
28
28
|
}
|
|
29
29
|
})
|
|
30
30
|
} else {
|
|
31
|
-
logger.debug('Tried to connect() a stopped connection')
|
|
31
|
+
logger.debug('Tried to connect() a stopped connection', { id: this.connectionId })
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
|