@streamr/dht 100.0.0-pretestnet.6 → 100.0.0-testnet-one.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/connection/ConnectionLockHandler.js +2 -2
- package/dist/src/connection/ConnectionLockHandler.js.map +1 -1
- package/dist/src/connection/ConnectionLockRpcRemote.d.ts +2 -2
- package/dist/src/connection/ConnectionLockRpcRemote.js +2 -2
- package/dist/src/connection/ConnectionLockRpcRemote.js.map +1 -1
- package/dist/src/connection/ConnectionManager.js +4 -1
- package/dist/src/connection/ConnectionManager.js.map +1 -1
- package/dist/src/connection/ConnectorFacade.js.map +1 -1
- package/dist/src/connection/ManagedConnection.js +1 -0
- package/dist/src/connection/ManagedConnection.js.map +1 -1
- package/dist/src/connection/connectivityChecker.d.ts +9 -0
- package/dist/src/connection/connectivityChecker.js +121 -0
- package/dist/src/connection/connectivityChecker.js.map +1 -0
- package/dist/src/connection/connectivityRequestHandler.d.ts +2 -0
- package/dist/src/connection/connectivityRequestHandler.js +79 -0
- package/dist/src/connection/connectivityRequestHandler.js.map +1 -0
- package/dist/src/connection/simulator/Simulator.js +3 -2
- package/dist/src/connection/simulator/Simulator.js.map +1 -1
- package/dist/src/connection/simulator/SimulatorConnection.js +1 -1
- package/dist/src/connection/simulator/SimulatorConnection.js.map +1 -1
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js +1 -1
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnector.js +1 -1
- package/dist/src/connection/webrtc/WebrtcConnector.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.d.ts +2 -2
- package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.js +2 -2
- 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/ClientWebsocket.js +1 -0
- package/dist/src/connection/websocket/ClientWebsocket.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnector.d.ts +0 -1
- package/dist/src/connection/websocket/WebsocketConnector.js +41 -7
- package/dist/src/connection/websocket/WebsocketConnector.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.d.ts +2 -2
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.js +2 -2
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.js.map +1 -1
- package/dist/src/dht/DhtNode.d.ts +9 -19
- package/dist/src/dht/DhtNode.js +76 -216
- package/dist/src/dht/DhtNode.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcLocal.js +3 -3
- package/dist/src/dht/DhtNodeRpcLocal.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcRemote.d.ts +3 -3
- package/dist/src/dht/DhtNodeRpcRemote.js +4 -4
- package/dist/src/dht/DhtNodeRpcRemote.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcLocal.d.ts +4 -4
- package/dist/src/dht/ExternalApiRpcLocal.js +5 -12
- package/dist/src/dht/ExternalApiRpcLocal.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcRemote.d.ts +3 -3
- package/dist/src/dht/ExternalApiRpcRemote.js +5 -5
- package/dist/src/dht/ExternalApiRpcRemote.js.map +1 -1
- package/dist/src/dht/PeerManager.d.ts +48 -0
- package/dist/src/dht/PeerManager.js +208 -0
- package/dist/src/dht/PeerManager.js.map +1 -0
- package/dist/src/dht/contact/ContactList.d.ts +1 -1
- package/dist/src/dht/contact/ContactList.js +1 -0
- package/dist/src/dht/contact/ContactList.js.map +1 -1
- package/dist/src/dht/contact/{Remote.d.ts → RpcRemote.d.ts} +3 -3
- package/dist/src/dht/contact/{Remote.js → RpcRemote.js} +8 -8
- package/dist/src/dht/contact/RpcRemote.js.map +1 -0
- package/dist/src/dht/discovery/DiscoverySession.d.ts +2 -9
- package/dist/src/dht/discovery/DiscoverySession.js +12 -26
- package/dist/src/dht/discovery/DiscoverySession.js.map +1 -1
- package/dist/src/dht/discovery/PeerDiscovery.d.ts +2 -9
- package/dist/src/dht/discovery/PeerDiscovery.js +13 -15
- package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -1
- package/dist/src/dht/find/FindRpcLocal.js +2 -1
- package/dist/src/dht/find/FindRpcLocal.js.map +1 -1
- package/dist/src/dht/find/FindSession.d.ts +6 -6
- package/dist/src/dht/find/FindSession.js +13 -13
- package/dist/src/dht/find/FindSession.js.map +1 -1
- package/dist/src/dht/find/FindSessionRpcLocal.d.ts +1 -1
- package/dist/src/dht/find/FindSessionRpcRemote.d.ts +2 -2
- package/dist/src/dht/find/FindSessionRpcRemote.js +2 -2
- package/dist/src/dht/find/FindSessionRpcRemote.js.map +1 -1
- package/dist/src/dht/find/Finder.d.ts +4 -4
- package/dist/src/dht/find/Finder.js +50 -42
- package/dist/src/dht/find/Finder.js.map +1 -1
- package/dist/src/dht/routing/FindRpcRemote.d.ts +2 -2
- package/dist/src/dht/routing/FindRpcRemote.js +7 -5
- package/dist/src/dht/routing/FindRpcRemote.js.map +1 -1
- package/dist/src/dht/routing/Router.d.ts +2 -6
- package/dist/src/dht/routing/Router.js +21 -18
- package/dist/src/dht/routing/Router.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcLocal.d.ts +2 -2
- package/dist/src/dht/routing/RouterRpcLocal.js +4 -3
- 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 +13 -8
- package/dist/src/dht/routing/RouterRpcRemote.js.map +1 -1
- package/dist/src/dht/routing/RoutingSession.d.ts +1 -1
- package/dist/src/dht/routing/RoutingSession.js +16 -11
- package/dist/src/dht/routing/RoutingSession.js.map +1 -1
- package/dist/src/dht/routing/getPreviousPeer.js.map +1 -1
- package/dist/src/dht/store/LocalDataStore.d.ts +3 -3
- package/dist/src/dht/store/LocalDataStore.js +18 -17
- package/dist/src/dht/store/LocalDataStore.js.map +1 -1
- package/dist/src/dht/store/StoreRpcLocal.d.ts +10 -9
- package/dist/src/dht/store/StoreRpcLocal.js +91 -99
- package/dist/src/dht/store/StoreRpcLocal.js.map +1 -1
- package/dist/src/dht/store/StoreRpcRemote.d.ts +4 -5
- package/dist/src/dht/store/StoreRpcRemote.js +6 -15
- package/dist/src/dht/store/StoreRpcRemote.js.map +1 -1
- package/dist/src/exports.d.ts +1 -1
- package/dist/src/exports.js +4 -4
- package/dist/src/exports.js.map +1 -1
- package/dist/src/helpers/PeerID.js +2 -2
- package/dist/src/helpers/PeerID.js.map +1 -1
- package/dist/src/helpers/UUID.js +1 -1
- package/dist/src/helpers/UUID.js.map +1 -1
- package/dist/src/helpers/nodeId.d.ts +1 -0
- package/dist/src/helpers/{kademliaId.js → nodeId.js} +4 -4
- package/dist/src/helpers/nodeId.js.map +1 -0
- package/dist/src/helpers/peerIdFromPeerDescriptor.js +3 -3
- package/dist/src/helpers/peerIdFromPeerDescriptor.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +5 -16
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +2 -9
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +80 -95
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +67 -66
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +3 -10
- package/dist/src/transport/RoutingRpcCommunicator.js +2 -0
- package/dist/src/transport/RoutingRpcCommunicator.js.map +1 -1
- package/karma.config.js +2 -2
- package/package.json +5 -5
- package/protos/DhtRpc.proto +36 -36
- package/src/connection/ConnectionLockHandler.ts +2 -2
- package/src/connection/ConnectionLockRpcRemote.ts +2 -2
- package/src/connection/ConnectionManager.ts +4 -1
- package/src/connection/ConnectorFacade.ts +5 -4
- package/src/connection/ManagedConnection.ts +1 -0
- package/src/connection/connectivityChecker.ts +101 -0
- package/src/connection/connectivityRequestHandler.ts +79 -0
- package/src/connection/simulator/Simulator.ts +3 -2
- package/src/connection/simulator/SimulatorConnection.ts +1 -1
- package/src/connection/webrtc/BrowserWebrtcConnection.ts +10 -10
- package/src/connection/webrtc/NodeWebrtcConnection.ts +1 -1
- package/src/connection/webrtc/WebrtcConnector.ts +1 -1
- package/src/connection/webrtc/WebrtcConnectorRpcLocal.ts +1 -1
- package/src/connection/webrtc/WebrtcConnectorRpcRemote.ts +2 -2
- package/src/connection/webrtc/iceServerAsString.ts +1 -1
- package/src/connection/websocket/ClientWebsocket.ts +1 -0
- package/src/connection/websocket/WebsocketConnector.ts +22 -12
- package/src/connection/websocket/WebsocketConnectorRpcRemote.ts +2 -2
- package/src/dht/DhtNode.ts +102 -269
- package/src/dht/DhtNodeRpcLocal.ts +3 -3
- package/src/dht/DhtNodeRpcRemote.ts +4 -4
- package/src/dht/ExternalApiRpcLocal.ts +8 -13
- package/src/dht/ExternalApiRpcRemote.ts +5 -5
- package/src/dht/PeerManager.ts +256 -0
- package/src/dht/contact/ContactList.ts +3 -2
- package/src/dht/contact/{Remote.ts → RpcRemote.ts} +7 -6
- package/src/dht/discovery/DiscoverySession.ts +15 -40
- package/src/dht/discovery/PeerDiscovery.ts +18 -23
- package/src/dht/find/FindRpcLocal.ts +2 -2
- package/src/dht/find/FindSession.ts +20 -20
- package/src/dht/find/FindSessionRpcLocal.ts +1 -1
- package/src/dht/find/FindSessionRpcRemote.ts +2 -2
- package/src/dht/find/Finder.ts +79 -58
- package/src/dht/routing/FindRpcRemote.ts +7 -5
- package/src/dht/routing/Router.ts +22 -21
- package/src/dht/routing/RouterRpcLocal.ts +5 -5
- package/src/dht/routing/RouterRpcRemote.ts +13 -10
- package/src/dht/routing/RoutingSession.ts +15 -10
- package/src/dht/routing/getPreviousPeer.ts +1 -1
- package/src/dht/store/LocalDataStore.ts +18 -17
- package/src/dht/store/StoreRpcLocal.ts +101 -108
- package/src/dht/store/StoreRpcRemote.ts +7 -23
- package/src/exports.ts +1 -1
- package/src/helpers/PeerID.ts +2 -2
- package/src/helpers/UUID.ts +1 -1
- package/src/helpers/{kademliaId.ts → nodeId.ts} +1 -1
- package/src/helpers/peerIdFromPeerDescriptor.ts +3 -3
- package/src/proto/packages/dht/protos/DhtRpc.client.ts +6 -20
- package/src/proto/packages/dht/protos/DhtRpc.server.ts +3 -10
- package/src/proto/packages/dht/protos/DhtRpc.ts +103 -135
- package/src/transport/RoutingRpcCommunicator.ts +2 -0
- package/test/benchmark/Find.test.ts +4 -4
- package/test/benchmark/KademliaCorrectness.test.ts +2 -2
- package/test/benchmark/kademlia-simulation/Contact.ts +1 -1
- package/test/benchmark/kademlia-simulation/KademliaSimulation.ts +1 -1
- package/test/end-to-end/Layer0-Layer1.test.ts +1 -1
- package/test/end-to-end/Layer0MixedConnectionTypes.test.ts +1 -1
- package/test/end-to-end/Layer0Webrtc-Layer1.test.ts +2 -2
- package/test/end-to-end/Layer0Webrtc.test.ts +2 -2
- package/test/end-to-end/Layer1-Scale-WebSocket.test.ts +1 -1
- package/test/end-to-end/Layer1-Scale-Webrtc.test.ts +1 -1
- package/test/end-to-end/WebsocketConnectionRequest.test.ts +1 -1
- package/test/end-to-end/memory-leak.test.ts +8 -12
- package/test/integration/ConnectionLocking.test.ts +2 -2
- package/test/integration/ConnectionManager.test.ts +14 -14
- package/test/integration/DhtJoinPeerDiscovery.test.ts +1 -1
- package/test/integration/DhtNodeExternalAPI.test.ts +10 -7
- package/test/integration/DhtNodeRpcRemote.test.ts +4 -4
- package/test/integration/DhtRpc.test.ts +6 -6
- package/test/integration/Find.test.ts +3 -3
- package/test/integration/Layer1-scale.test.ts +2 -2
- package/test/integration/Mock-Layer1-Layer0.test.ts +1 -1
- package/test/integration/{MigrateData.test.ts → ReplicateData.test.ts} +9 -9
- package/test/integration/RouteMessage.test.ts +2 -2
- package/test/integration/RouterRpcRemote.test.ts +2 -2
- package/test/integration/RpcErrors.test.ts +2 -2
- package/test/integration/ScaleDownDht.test.ts +4 -2
- package/test/integration/SimultaneousConnections.test.ts +8 -8
- package/test/integration/Store.test.ts +33 -13
- package/test/integration/StoreAndDelete.test.ts +19 -17
- package/test/integration/StoreOnDhtWithTwoNodes.test.ts +20 -20
- package/test/integration/StoreRpcRemote.test.ts +3 -3
- package/test/integration/WebrtcConnectionManagement.test.ts +2 -2
- package/test/integration/WebrtcConnectorRpc.test.ts +1 -1
- package/test/integration/WebsocketConnectionManagement.test.ts +2 -2
- package/test/integration/WebsocketConnectorRpc.test.ts +2 -2
- package/test/unit/ConnectivityHelpers.test.ts +4 -4
- package/test/unit/Finder.test.ts +69 -23
- package/test/unit/LocalDataStore.test.ts +60 -43
- package/test/unit/RandomContactList.test.ts +2 -2
- package/test/unit/Router.test.ts +19 -11
- package/test/unit/RoutingSession.test.ts +76 -0
- package/test/unit/SortedContactList.test.ts +2 -2
- package/test/unit/WebsocketConnector.test.ts +1 -1
- package/test/unit/connectivityRequestHandler.test.ts +71 -0
- package/test/utils/mock/Router.ts +1 -1
- package/test/utils/utils.ts +24 -22
- 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/dht/contact/Remote.js.map +0 -1
- package/dist/src/helpers/kademliaId.d.ts +0 -1
- package/dist/src/helpers/kademliaId.js.map +0 -1
- package/src/connection/ConnectivityChecker.ts +0 -199
|
@@ -85,7 +85,7 @@ export class SimulatorConnection extends Connection implements IConnection {
|
|
|
85
85
|
logger.trace('connect() called')
|
|
86
86
|
|
|
87
87
|
this.simulator.connect(this, this.targetPeerDescriptor, (error?: string) => {
|
|
88
|
-
if (error) {
|
|
88
|
+
if (error !== undefined) {
|
|
89
89
|
logger.trace(error)
|
|
90
90
|
this.doDisconnect(false)
|
|
91
91
|
} else {
|
|
@@ -51,7 +51,7 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IWebrt
|
|
|
51
51
|
this.peerConnection = new RTCPeerConnection({ iceServers: urls })
|
|
52
52
|
|
|
53
53
|
this.peerConnection.onicecandidate = (event) => {
|
|
54
|
-
if (event.candidate && event.candidate.sdpMid) {
|
|
54
|
+
if ((event.candidate !== null) && (event.candidate.sdpMid !== null)) {
|
|
55
55
|
this.emit('localCandidate', event.candidate.candidate, event.candidate.sdpMid)
|
|
56
56
|
}
|
|
57
57
|
}
|
|
@@ -63,14 +63,14 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IWebrt
|
|
|
63
63
|
if (isOffering) {
|
|
64
64
|
this.peerConnection.onnegotiationneeded = async () => {
|
|
65
65
|
try {
|
|
66
|
-
if (this.peerConnection) {
|
|
66
|
+
if (this.peerConnection !== undefined) {
|
|
67
67
|
this.makingOffer = true
|
|
68
68
|
try {
|
|
69
69
|
await this.peerConnection.setLocalDescription()
|
|
70
70
|
} catch (err) {
|
|
71
71
|
logger.warn('error', { err })
|
|
72
72
|
}
|
|
73
|
-
if (this.peerConnection.localDescription) {
|
|
73
|
+
if (this.peerConnection.localDescription !== null) {
|
|
74
74
|
this.emit('localDescription', this.peerConnection.localDescription?.sdp, this.peerConnection.localDescription?.type)
|
|
75
75
|
}
|
|
76
76
|
}
|
|
@@ -93,7 +93,7 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IWebrt
|
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
public async setRemoteDescription(description: string, type: string): Promise<void> {
|
|
96
|
-
const offerCollision = (type.toLowerCase() === RtcDescription.OFFER) && (this.makingOffer ||
|
|
96
|
+
const offerCollision = (type.toLowerCase() === RtcDescription.OFFER) && (this.makingOffer || (this.peerConnection === undefined) ||
|
|
97
97
|
this.peerConnection.signalingState != 'stable')
|
|
98
98
|
|
|
99
99
|
const ignoreOffer = this.isOffering && offerCollision
|
|
@@ -106,13 +106,13 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IWebrt
|
|
|
106
106
|
logger.warn('error', { err })
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
if (type.toLowerCase() === RtcDescription.OFFER && this.peerConnection) {
|
|
109
|
+
if ((type.toLowerCase() === RtcDescription.OFFER) && (this.peerConnection !== undefined)) {
|
|
110
110
|
try {
|
|
111
111
|
await this.peerConnection.setLocalDescription()
|
|
112
112
|
} catch (err) {
|
|
113
113
|
logger.warn('error', { err })
|
|
114
114
|
}
|
|
115
|
-
if (this.peerConnection.localDescription) {
|
|
115
|
+
if (this.peerConnection.localDescription !== null) {
|
|
116
116
|
this.emit('localDescription', this.peerConnection.localDescription.sdp, this.peerConnection.localDescription.type)
|
|
117
117
|
}
|
|
118
118
|
}
|
|
@@ -148,7 +148,7 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IWebrt
|
|
|
148
148
|
|
|
149
149
|
this.removeAllListeners()
|
|
150
150
|
|
|
151
|
-
if (this.dataChannel) {
|
|
151
|
+
if (this.dataChannel !== undefined) {
|
|
152
152
|
try {
|
|
153
153
|
this.dataChannel.close()
|
|
154
154
|
} catch (e) {
|
|
@@ -158,7 +158,7 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IWebrt
|
|
|
158
158
|
|
|
159
159
|
this.dataChannel = undefined
|
|
160
160
|
|
|
161
|
-
if (this.peerConnection) {
|
|
161
|
+
if (this.peerConnection !== undefined) {
|
|
162
162
|
try {
|
|
163
163
|
this.peerConnection.close()
|
|
164
164
|
} catch (e) {
|
|
@@ -209,7 +209,7 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IWebrt
|
|
|
209
209
|
}
|
|
210
210
|
|
|
211
211
|
private stopListening() {
|
|
212
|
-
if (this.dataChannel) {
|
|
212
|
+
if (this.dataChannel !== undefined) {
|
|
213
213
|
this.dataChannel.onopen = null
|
|
214
214
|
this.dataChannel.onclose = null
|
|
215
215
|
this.dataChannel.onerror = null
|
|
@@ -217,7 +217,7 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IWebrt
|
|
|
217
217
|
this.dataChannel.onmessage = null
|
|
218
218
|
}
|
|
219
219
|
|
|
220
|
-
if (this.peerConnection) {
|
|
220
|
+
if (this.peerConnection !== undefined) {
|
|
221
221
|
this.peerConnection.onicecandidate = null
|
|
222
222
|
this.peerConnection.onicegatheringstatechange = null
|
|
223
223
|
this.peerConnection.onnegotiationneeded = null
|
|
@@ -161,7 +161,7 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IConne
|
|
|
161
161
|
if (!this.closed) {
|
|
162
162
|
logger.trace(
|
|
163
163
|
`Closing Node WebRTC Connection to ${getNodeIdFromPeerDescriptor(this.remotePeerDescriptor)}`
|
|
164
|
-
+ `${reason ? `, reason: ${reason}` : ''}`
|
|
164
|
+
+ `${(reason !== undefined) ? `, reason: ${reason}` : ''}`
|
|
165
165
|
)
|
|
166
166
|
|
|
167
167
|
this.closed = true
|
|
@@ -178,7 +178,7 @@ export class WebrtcConnector {
|
|
|
178
178
|
)
|
|
179
179
|
|
|
180
180
|
connection.on('localCandidate', (candidate: string, mid: string) => {
|
|
181
|
-
if (this.config.externalIp) {
|
|
181
|
+
if (this.config.externalIp !== undefined) {
|
|
182
182
|
candidate = replaceInternalIpWithExternalIp(candidate, this.config.externalIp)
|
|
183
183
|
logger.debug(`onLocalCandidate injected external ip ${candidate} ${mid}`)
|
|
184
184
|
}
|
|
@@ -123,7 +123,7 @@ export class WebrtcConnectorRpcLocal implements IWebrtcConnectorRpc {
|
|
|
123
123
|
private isIceCandidateAllowed(candidate: string): boolean {
|
|
124
124
|
if (!this.config.allowPrivateAddresses) {
|
|
125
125
|
const address = getAddressFromIceCandidate(candidate)
|
|
126
|
-
if (address && isPrivateIPv4(address)) {
|
|
126
|
+
if ((address !== undefined) && isPrivateIPv4(address)) {
|
|
127
127
|
return false
|
|
128
128
|
}
|
|
129
129
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RpcRemote } from '../../dht/contact/RpcRemote'
|
|
2
2
|
import {
|
|
3
3
|
IceCandidate,
|
|
4
4
|
PeerDescriptor,
|
|
@@ -12,7 +12,7 @@ import { Logger } from '@streamr/utils'
|
|
|
12
12
|
|
|
13
13
|
const logger = new Logger(module)
|
|
14
14
|
|
|
15
|
-
export class WebrtcConnectorRpcRemote extends
|
|
15
|
+
export class WebrtcConnectorRpcRemote extends RpcRemote<IWebrtcConnectorRpcClient> {
|
|
16
16
|
|
|
17
17
|
constructor(
|
|
18
18
|
localPeerDescriptor: PeerDescriptor,
|
|
@@ -9,7 +9,7 @@ export function iceServerAsString({ url, port, username, password, tcp }: IceSer
|
|
|
9
9
|
return `${protocol}:${hostname}:${port}`
|
|
10
10
|
}
|
|
11
11
|
if (username !== undefined && password !== undefined) {
|
|
12
|
-
return `${protocol}:${username}:${password}@${hostname}:${port}${tcp ? '?transport=tcp' : ''}`
|
|
12
|
+
return `${protocol}:${username}:${password}@${hostname}:${port}${(tcp !== undefined) ? '?transport=tcp' : ''}`
|
|
13
13
|
}
|
|
14
14
|
throw new Error(`username (${username}) and password (${password}) must be supplied together`)
|
|
15
15
|
}
|
|
@@ -23,6 +23,7 @@ export class ClientWebsocket extends EventEmitter<ConnectionEvents> implements I
|
|
|
23
23
|
this.connectionId = new ConnectionID()
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
// TODO explicit default value for "selfSigned" or make it required
|
|
26
27
|
public connect(address: string, selfSigned?: boolean): void {
|
|
27
28
|
if (!this.destroyed) {
|
|
28
29
|
this.socket = new Websocket(address, undefined, undefined, undefined, { rejectUnauthorized: !selfSigned })
|
|
@@ -16,7 +16,7 @@ import { WebsocketConnectorRpcClient } from '../../proto/packages/dht/protos/Dht
|
|
|
16
16
|
import { Logger, binaryToHex, wait } from '@streamr/utils'
|
|
17
17
|
import { ManagedConnection } from '../ManagedConnection'
|
|
18
18
|
import { WebsocketServer } from './WebsocketServer'
|
|
19
|
-
import {
|
|
19
|
+
import { sendConnectivityRequest } from '../connectivityChecker'
|
|
20
20
|
import { NatType, PortRange, TlsCertificate } from '../ConnectionManager'
|
|
21
21
|
import { PeerIDKey } from '../../helpers/PeerID'
|
|
22
22
|
import { ServerWebsocket } from './ServerWebsocket'
|
|
@@ -29,6 +29,9 @@ import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
|
29
29
|
import { expectedConnectionType } from '../../helpers/Connectivity'
|
|
30
30
|
import { WebsocketServerStartError } from '../../helpers/errors'
|
|
31
31
|
import { AutoCertifierClientFacade } from './AutoCertifierClientFacade'
|
|
32
|
+
import { attachConnectivityRequestHandler } from '../connectivityRequestHandler'
|
|
33
|
+
import * as Err from '../../helpers/errors'
|
|
34
|
+
|
|
32
35
|
const logger = new Logger(module)
|
|
33
36
|
|
|
34
37
|
export type Action = 'connectivityRequest' | 'connectivityProbe'
|
|
@@ -59,7 +62,6 @@ export class WebsocketConnector {
|
|
|
59
62
|
private static readonly WEBSOCKET_CONNECTOR_SERVICE_ID = 'system/websocket-connector'
|
|
60
63
|
private readonly rpcCommunicator: ListeningRpcCommunicator
|
|
61
64
|
private readonly websocketServer?: WebsocketServer
|
|
62
|
-
private connectivityChecker?: ConnectivityChecker
|
|
63
65
|
private readonly ongoingConnectRequests: Map<PeerIDKey, ManagedConnection> = new Map()
|
|
64
66
|
private onNewConnection: (connection: ManagedConnection) => boolean
|
|
65
67
|
private host?: string
|
|
@@ -77,7 +79,7 @@ export class WebsocketConnector {
|
|
|
77
79
|
|
|
78
80
|
constructor(config: WebsocketConnectorConfig) {
|
|
79
81
|
this.websocketServer = config.portRange ? new WebsocketServer({
|
|
80
|
-
portRange: config.portRange
|
|
82
|
+
portRange: config.portRange,
|
|
81
83
|
tlsCertificate: config.tlsCertificate,
|
|
82
84
|
maxMessageSize: config.maxMessageSize,
|
|
83
85
|
enableTls: config.serverEnableTls
|
|
@@ -134,13 +136,12 @@ export class WebsocketConnector {
|
|
|
134
136
|
updateCertificate: (certificate: string, privateKey: string) => this.websocketServer!.updateCertificate(certificate, privateKey)
|
|
135
137
|
})
|
|
136
138
|
logger.trace(`AutoCertifying subdomain...`)
|
|
137
|
-
await this.autoCertifierClient
|
|
139
|
+
await this.autoCertifierClient.start()
|
|
138
140
|
}
|
|
139
141
|
|
|
140
142
|
private setHost(hostName: string): void {
|
|
141
143
|
logger.trace(`Setting host name to ${hostName}`)
|
|
142
144
|
this.host = hostName
|
|
143
|
-
this.connectivityChecker!.setHost(hostName)
|
|
144
145
|
}
|
|
145
146
|
|
|
146
147
|
public async start(): Promise<void> {
|
|
@@ -151,7 +152,7 @@ export class WebsocketConnector {
|
|
|
151
152
|
const action = query?.action as (Action | undefined)
|
|
152
153
|
logger.trace('WebSocket client connected', { action, remoteAddress: serverSocket.getRemoteAddress() })
|
|
153
154
|
if (action === 'connectivityRequest') {
|
|
154
|
-
|
|
155
|
+
attachConnectivityRequestHandler(serverSocket)
|
|
155
156
|
} else if (action === 'connectivityProbe') {
|
|
156
157
|
// no-op
|
|
157
158
|
} else {
|
|
@@ -160,7 +161,6 @@ export class WebsocketConnector {
|
|
|
160
161
|
})
|
|
161
162
|
const port = await this.websocketServer.start()
|
|
162
163
|
this.selectedPort = port
|
|
163
|
-
this.connectivityChecker = new ConnectivityChecker(this.selectedPort, this.serverEnableTls, this.host)
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
166
|
|
|
@@ -189,12 +189,22 @@ export class WebsocketConnector {
|
|
|
189
189
|
return preconfiguredConnectivityResponse
|
|
190
190
|
} else {
|
|
191
191
|
// Do real connectivity checking
|
|
192
|
-
|
|
192
|
+
const connectivityRequest = {
|
|
193
|
+
port: this.selectedPort!,
|
|
194
|
+
host: this.host,
|
|
195
|
+
tls: this.serverEnableTls,
|
|
196
|
+
selfSigned
|
|
197
|
+
}
|
|
198
|
+
if (!this.abortController.signal.aborted) {
|
|
199
|
+
return await sendConnectivityRequest(connectivityRequest, entryPoint)
|
|
200
|
+
} else {
|
|
201
|
+
throw new Err.ConnectionFailed('ConnectivityChecker is destroyed')
|
|
202
|
+
}
|
|
193
203
|
}
|
|
194
204
|
}
|
|
195
205
|
} catch (err) {
|
|
196
206
|
if (reattempt < ENTRY_POINT_CONNECTION_ATTEMPTS) {
|
|
197
|
-
const error = `Failed to connect to entrypoint with id ${binaryToHex(entryPoint.
|
|
207
|
+
const error = `Failed to connect to entrypoint with id ${binaryToHex(entryPoint.nodeId)} `
|
|
198
208
|
+ `and URL ${connectivityMethodToWebsocketUrl(entryPoint.websocket!)}`
|
|
199
209
|
logger.error(error, { error: err })
|
|
200
210
|
await wait(2000)
|
|
@@ -257,6 +267,7 @@ export class WebsocketConnector {
|
|
|
257
267
|
targetPeerDescriptor,
|
|
258
268
|
toProtoRpcClient(new WebsocketConnectorRpcClient(this.rpcCommunicator.getRpcClientTransport()))
|
|
259
269
|
)
|
|
270
|
+
// TODO should we have some handling for this floating promise?
|
|
260
271
|
remoteConnector.requestConnection(localPeerDescriptor.websocket!.host, localPeerDescriptor.websocket!.port)
|
|
261
272
|
})
|
|
262
273
|
const managedConnection = new ManagedConnection(
|
|
@@ -265,7 +276,7 @@ export class WebsocketConnector {
|
|
|
265
276
|
undefined,
|
|
266
277
|
undefined,
|
|
267
278
|
targetPeerDescriptor
|
|
268
|
-
)
|
|
279
|
+
)
|
|
269
280
|
managedConnection.on('disconnected', () => this.ongoingConnectRequests.delete(keyFromPeerDescriptor(targetPeerDescriptor)))
|
|
270
281
|
managedConnection.setRemotePeerDescriptor(targetPeerDescriptor)
|
|
271
282
|
this.ongoingConnectRequests.set(keyFromPeerDescriptor(targetPeerDescriptor), managedConnection)
|
|
@@ -273,7 +284,7 @@ export class WebsocketConnector {
|
|
|
273
284
|
}
|
|
274
285
|
|
|
275
286
|
private onServerSocketHandshakeRequest(
|
|
276
|
-
sourcePeerDescriptor: PeerDescriptor,
|
|
287
|
+
sourcePeerDescriptor: PeerDescriptor,
|
|
277
288
|
serverWebsocket: IConnection,
|
|
278
289
|
targetPeerDescriptor?: PeerDescriptor
|
|
279
290
|
) {
|
|
@@ -322,7 +333,6 @@ export class WebsocketConnector {
|
|
|
322
333
|
|
|
323
334
|
const attempts = Array.from(this.connectingConnections.values())
|
|
324
335
|
await Promise.allSettled(attempts.map((conn) => conn.close(false)))
|
|
325
|
-
this.connectivityChecker?.destroy()
|
|
326
336
|
await this.websocketServer?.stop()
|
|
327
337
|
}
|
|
328
338
|
}
|
|
@@ -7,11 +7,11 @@ import { Logger } from '@streamr/utils'
|
|
|
7
7
|
import * as Err from '../../helpers/errors'
|
|
8
8
|
import { ProtoRpcClient } from '@streamr/proto-rpc'
|
|
9
9
|
import { getNodeIdFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
|
|
10
|
-
import {
|
|
10
|
+
import { RpcRemote } from '../../dht/contact/RpcRemote'
|
|
11
11
|
|
|
12
12
|
const logger = new Logger(module)
|
|
13
13
|
|
|
14
|
-
export class WebsocketConnectorRpcRemote extends
|
|
14
|
+
export class WebsocketConnectorRpcRemote extends RpcRemote<IWebsocketConnectorRpcClient> {
|
|
15
15
|
|
|
16
16
|
constructor(
|
|
17
17
|
localPeerDescriptor: PeerDescriptor,
|