Added AgentPing/Pong feature in relay.

Ylian Saint-Hilaire committed Apr 16, 2020 at 15:38 UTC 50e0bad1cbd035d12ba36b2cccdde776fc16a1c9
3 files changed +21 -2
meshrelay.js
+19 -1
@@ -115,7 +115,17 @@ module.exports.CreateMeshRelay = function (parent, ws, req, domain, user, cookie
115 }
116 return false;
117 };
118 -
118 +
119 + // Send a PING/PONG message
120 + function sendPing() {
121 + try { obj.ws.send('{"ctrlChannel":"102938","type":"ping"}'); } catch (ex) { }
122 + try { if (obj.peer != null) { obj.peer.ws.send('{"ctrlChannel":"102938","type":"ping"}'); } } catch (ex) { }
123 + }
124 + function sendPong() {
125 + try { obj.ws.send('{"ctrlChannel":"102938","type":"pong"}'); } catch (ex) { }
126 + try { if (obj.peer != null) { obj.peer.ws.send('{"ctrlChannel":"102938","type":"pong"}'); } } catch (ex) { }
127 + }
128 +
129 function performRelay() {
130 if (obj.id == null) { try { obj.close(); } catch (e) { } return null; } // Attempt to connect without id, drop this.
131 ws._socket.setKeepAlive(true, 240000); // Set TCP keep alive
@@ -195,6 +205,10 @@ module.exports.CreateMeshRelay = function (parent, ws, req, domain, user, cookie
205 // Remove the timeout
206 if (relayinfo.timeout) { clearTimeout(relayinfo.timeout); delete relayinfo.timeout; }
207
208 + // Setup the agent PING/PONG timers
209 + if ((typeof parent.parent.args.agentping == 'number') && (obj.pingtimer == null)) { obj.pingtimer = setInterval(sendPing, parent.parent.args.agentping * 1000); }
210 + else if ((typeof parent.parent.args.agentpong == 'number') && (obj.pongtimer == null)) { obj.pongtimer = setInterval(sendPong, parent.parent.args.agentpong * 1000); }
211 +
212 // Setup session recording
213 var sessionUser = obj.user;
214 if (sessionUser == null) { sessionUser = obj.peer.user; }
@@ -355,6 +369,8 @@ module.exports.CreateMeshRelay = function (parent, ws, req, domain, user, cookie
369 delete peer.id;
370 delete peer.ws;
371 delete peer.peer;
372 + if (peer.pingtimer != null) { clearInterval(peer.pingtimer); delete peer.pingtimer; }
373 + if (peer.pongtimer != null) { clearInterval(peer.pongtimer); delete peer.pongtimer; }
374 } else {
375 parent.parent.debug('relay', 'Relay disconnect: ' + obj.id + ' (' + cleanRemoteAddr(obj.req.ip) + ')');
376 }
@@ -380,6 +396,8 @@ module.exports.CreateMeshRelay = function (parent, ws, req, domain, user, cookie
396 delete obj.id;
397 delete obj.ws;
398 delete obj.peer;
399 + if (obj.pingtimer != null) { clearInterval(obj.pingtimer); delete obj.pingtimer; }
400 + if (obj.pongtimer != null) { clearInterval(obj.pongtimer); delete obj.pongtimer; }
401 }
402
403 // Record a new entry in a recording log
package.json
+1 -1
@@ -1,6 +1,6 @@
1 {
2 "name": "meshcentral",
3 - "version": "0.5.1-y",
3 + "version": "0.5.1-z",
4 "keywords": [
5 "Remote Management",
6 "Intel AMT",
views/default.handlebars
+1
@@ -11204,6 +11204,7 @@
11204 type: 'line',
11205 data: { labels: [], datasets: [{ label: '', backgroundColor: 'rgba(255, 99, 132, .5)', borderColor: 'rgb(255, 99, 132)', data: [], fill: true }] },
11206 options: {
11207 + animation: false,
11208 responsive: true,
11209 maintainAspectRatio: false,
11210 elements: { line: { cubicInterpolationMode: 'monotone' } },