Fix for #2589

Ylian Saint-Hilaire committed May 5, 2021 at 12:49 UTC f61ab701a593eed4d61b21401a9a4d0c2589c8e4
2 files changed +32 -1
meshrelay.js
+31
@@ -310,6 +310,22 @@ function CreateMeshRelayEx(parent, ws, req, domain, user, cookie) {
310 // Remove the timeout
311 if (relayinfo.timeout) { clearTimeout(relayinfo.timeout); delete relayinfo.timeout; }
312
313 + // Check the protocol in use
314 + req.query.p = parseInt(req.query.p);
315 + if (typeof req.query.p != 'number') { req.query.p = parseInt(obj.peer.req.query.p); if (typeof req.query.p != 'number') { req.query.p = 0; } }
316 + obj.peer.req.query.p = req.query.p;
317 +
318 + // Setup traffic accounting
319 + obj.ws._socket.bytesReadEx = 0;
320 + obj.ws._socket.bytesWrittenEx = 0;
321 + obj.ws._socket.p = req.query.p;
322 + obj.peer.ws._socket.bytesReadEx = 0;
323 + obj.peer.ws._socket.bytesWrittenEx = 0;
324 + obj.peer.ws._socket.p = req.query.p;
325 + if (parent.trafficStats.relayIn[req.query.p] == null) { parent.trafficStats.relayIn[req.query.p] = 0; }
326 + if (parent.trafficStats.relayOut[req.query.p] == null) { parent.trafficStats.relayOut[req.query.p] = 0; }
327 + if (parent.trafficStats.relayCount[req.query.p] == null) { parent.trafficStats.relayCount[req.query.p] = 1; } else { parent.trafficStats.relayCount[req.query.p]++; }
328 +
329 // Setup the agent PING/PONG timers unless requested not to
330 if ((obj.req.query.noping != 1) && (obj.peer.req != null) && (obj.peer.req.query != null) && (obj.peer.req.query.noping != 1)) {
331 if ((typeof parent.parent.args.agentping == 'number') && (obj.pingtimer == null)) { obj.pingtimer = setInterval(sendPing, parent.parent.args.agentping * 1000); }
@@ -516,6 +532,17 @@ function CreateMeshRelayEx(parent, ws, req, domain, user, cookie) {
532
533 // When data is received from the mesh relay web socket
534 ws.on('message', function (data) {
535 + // Perform traffic accounting
536 + parent.trafficStats.relayIn[this._socket.p] += (this._socket.bytesRead - this._socket.bytesReadEx);
537 + parent.trafficStats.relayOut[this._socket.p] += (this._socket.bytesWritten - this._socket.bytesWrittenEx);
538 +
539 + // Check the protocol in use
540 + req.query.p = parseInt(req.query.p);
541 + if (typeof req.query.p != 'number') { req.query.p = parseInt(obj.peer.req.query.p); if (typeof req.query.p != 'number') { req.query.p = 0; } }
542 + obj.peer.req.query.p = req.query.p;
543 +
544 +
545 +
546 if (this.peer != null) {
547 //if (typeof data == 'string') { console.log('Relay: ' + data); } else { console.log('Relay:' + data.length + ' byte(s)'); }
548 if (this.peer.slowRelay == null) {
@@ -584,6 +611,10 @@ function CreateMeshRelayEx(parent, ws, req, domain, user, cookie) {
611
612 // If the relay web socket is closed, close both sides.
613 ws.on('close', function (req) {
614 + // Perform traffic accounting
615 + parent.trafficStats.relayIn[this._socket.p] += (this._socket.bytesRead - this._socket.bytesReadEx);
616 + parent.trafficStats.relayOut[this._socket.p] += (this._socket.bytesWritten - this._socket.bytesWrittenEx);
617 +
618 if (obj.relaySessionCounted) { parent.relaySessionCount--; delete obj.relaySessionCounted; }
619 closeBothSides();
620 });
views/default.handlebars
+1 -1
@@ -6463,7 +6463,7 @@
6463 }
6464
6465 // SSH link
6466 - if ((features2 & 0x200) && (((connectivity & 1) != 0) || (node.mtype == 3)) && (node.agent) && ((meshrights & 8) != 0) && ((features & 0x40000000) == 0) && (node.agent.id != 14)) {
6466 + if ((features2 & 0x200) && (((connectivity & 1) != 0) || (node.mtype == 3)) && (node.agent) && ((meshrights & 8) != 0) && (node.agent.id != 14)) {
6467 x += '<a href=# id=sshLink onclick=p10ssh("' + node._id + '") title="' + "Launch web-based SSH session to this device" + '.">' + "Web-SSH" + '</a>&nbsp;';
6468 }
6469