From 50e0bad1cbd035d12ba36b2cccdde776fc16a1c9 Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Thu, 16 Apr 2020 15:38:15 -0700 Subject: [PATCH] Added AgentPing/Pong feature in relay. --- meshrelay.js | 20 +++++++++++++++++++- package.json | 2 +- views/default.handlebars | 1 + 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/meshrelay.js b/meshrelay.js index 332c7b44..d54d24c7 100644 --- a/meshrelay.js +++ b/meshrelay.js @@ -115,7 +115,17 @@ module.exports.CreateMeshRelay = function (parent, ws, req, domain, user, cookie } return false; }; - + + // Send a PING/PONG message + function sendPing() { + try { obj.ws.send('{"ctrlChannel":"102938","type":"ping"}'); } catch (ex) { } + try { if (obj.peer != null) { obj.peer.ws.send('{"ctrlChannel":"102938","type":"ping"}'); } } catch (ex) { } + } + function sendPong() { + try { obj.ws.send('{"ctrlChannel":"102938","type":"pong"}'); } catch (ex) { } + try { if (obj.peer != null) { obj.peer.ws.send('{"ctrlChannel":"102938","type":"pong"}'); } } catch (ex) { } + } + function performRelay() { if (obj.id == null) { try { obj.close(); } catch (e) { } return null; } // Attempt to connect without id, drop this. ws._socket.setKeepAlive(true, 240000); // Set TCP keep alive @@ -195,6 +205,10 @@ module.exports.CreateMeshRelay = function (parent, ws, req, domain, user, cookie // Remove the timeout if (relayinfo.timeout) { clearTimeout(relayinfo.timeout); delete relayinfo.timeout; } + // Setup the agent PING/PONG timers + if ((typeof parent.parent.args.agentping == 'number') && (obj.pingtimer == null)) { obj.pingtimer = setInterval(sendPing, parent.parent.args.agentping * 1000); } + else if ((typeof parent.parent.args.agentpong == 'number') && (obj.pongtimer == null)) { obj.pongtimer = setInterval(sendPong, parent.parent.args.agentpong * 1000); } + // Setup session recording var sessionUser = obj.user; if (sessionUser == null) { sessionUser = obj.peer.user; } @@ -355,6 +369,8 @@ module.exports.CreateMeshRelay = function (parent, ws, req, domain, user, cookie delete peer.id; delete peer.ws; delete peer.peer; + if (peer.pingtimer != null) { clearInterval(peer.pingtimer); delete peer.pingtimer; } + if (peer.pongtimer != null) { clearInterval(peer.pongtimer); delete peer.pongtimer; } } else { parent.parent.debug('relay', 'Relay disconnect: ' + obj.id + ' (' + cleanRemoteAddr(obj.req.ip) + ')'); } @@ -380,6 +396,8 @@ module.exports.CreateMeshRelay = function (parent, ws, req, domain, user, cookie delete obj.id; delete obj.ws; delete obj.peer; + if (obj.pingtimer != null) { clearInterval(obj.pingtimer); delete obj.pingtimer; } + if (obj.pongtimer != null) { clearInterval(obj.pongtimer); delete obj.pongtimer; } } // Record a new entry in a recording log diff --git a/package.json b/package.json index db02b110..376d1a57 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "meshcentral", - "version": "0.5.1-y", + "version": "0.5.1-z", "keywords": [ "Remote Management", "Intel AMT", diff --git a/views/default.handlebars b/views/default.handlebars index af3866d0..8008c8ab 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -11204,6 +11204,7 @@ type: 'line', data: { labels: [], datasets: [{ label: '', backgroundColor: 'rgba(255, 99, 132, .5)', borderColor: 'rgb(255, 99, 132)', data: [], fill: true }] }, options: { + animation: false, responsive: true, maintainAspectRatio: false, elements: { line: { cubicInterpolationMode: 'monotone' } },