mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2024-12-22 13:21:31 +03:00
Fixed to relay metadata and RTT calculation.
This commit is contained in:
parent
03ea86d643
commit
a793685e1f
@ -20,7 +20,6 @@ module.exports.CreateMeshRelay = function (parent, ws, req, domain, user, cookie
|
||||
obj.user = user;
|
||||
obj.ruserid = null;
|
||||
obj.req = req; // Used in multi-server.js
|
||||
obj.metadata = {};
|
||||
|
||||
// Check relay authentication
|
||||
if ((user == null) && (obj.req.query != null) && (obj.req.query.rauth != null)) {
|
||||
@ -269,7 +268,7 @@ module.exports.CreateMeshRelay = function (parent, ws, req, domain, user, cookie
|
||||
} else {
|
||||
// Wait for other relay connection
|
||||
ws._socket.pause(); // Hold traffic until the other connection
|
||||
parent.wsrelays[obj.id] = { peer1: obj, state: 1, metadata: obj.metadata, timeout: setTimeout(function () { closeBothSides(); }, 30000) };
|
||||
parent.wsrelays[obj.id] = { peer1: obj, state: 1, timeout: setTimeout(function () { closeBothSides(); }, 30000) };
|
||||
parent.parent.debug('relay', 'Relay holding: ' + obj.id + ' (' + cleanRemoteAddr(obj.req.ip) + ') ' + (obj.authenticated ? 'Authenticated' : ''));
|
||||
|
||||
// Check if a peer server has this connection
|
||||
@ -421,8 +420,7 @@ module.exports.CreateMeshRelay = function (parent, ws, req, domain, user, cookie
|
||||
|
||||
// Check if this user has permission to manage this computer
|
||||
if ((parent.GetNodeRights(user, node.meshid, node._id) & MESHRIGHT_REMOTECONTROL) == 0) { console.log('ERR: Access denied (1)'); try { obj.close(); } catch (e) { } return; }
|
||||
obj.metadata.peer2 = { name: node.name };
|
||||
obj.metadata.authUser = user;
|
||||
|
||||
// Send connection request to agent
|
||||
const rcookie = parent.parent.encodeCookie({ ruserid: user._id }, parent.parent.loginCookieEncryptionKey);
|
||||
if (obj.id == undefined) { obj.id = ('' + Math.random()).substring(2); } // If there is no connection id, generate one.
|
||||
@ -440,8 +438,7 @@ module.exports.CreateMeshRelay = function (parent, ws, req, domain, user, cookie
|
||||
|
||||
// Check if this user has permission to manage this computer
|
||||
if ((parent.GetNodeRights(user, node.meshid, node._id) & MESHRIGHT_REMOTECONTROL) == 0) { console.log('ERR: Access denied (2)'); try { obj.close(); } catch (e) { } return; }
|
||||
obj.metadata.peer2 = { name: node.name };
|
||||
obj.metadata.authUser = user;
|
||||
|
||||
// Send connection request to agent
|
||||
if (obj.id == null) { obj.id = ('' + Math.random()).substring(2); } // If there is no connection id, generate one.
|
||||
const rcookie = parent.parent.encodeCookie({ ruserid: user._id }, parent.parent.loginCookieEncryptionKey);
|
||||
|
13
meshuser.js
13
meshuser.js
@ -1041,10 +1041,15 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
|
||||
}
|
||||
case 'relays': {
|
||||
for (var i in parent.wsrelays) {
|
||||
r += 'id: ' + i + ', state: ' + parent.wsrelays[i].state;
|
||||
if (parent.wsrelays[i].peer1 != null) { r += ', peer1: ' + cleanRemoteAddr(parent.wsrelays[i].peer1.req.ip); }
|
||||
if (parent.wsrelays[i].peer2 != null) { r += ', peer2: ' + cleanRemoteAddr(parent.wsrelays[i].peer2.req.ip); }
|
||||
if (parent.wsrelays[i].metadata != null) { r += ', ' + parent.wsrelays[i].metadata.authUser._id + ' connected to ' + parent.wsrelays[i].metadata.peer2.name; }
|
||||
r += 'id: ' + i + ', ' + ((parent.wsrelays[i].state == 2)?'connected':'pending');
|
||||
if (parent.wsrelays[i].peer1 != null) {
|
||||
r += ', ' + cleanRemoteAddr(parent.wsrelays[i].peer1.req.ip);
|
||||
if (parent.wsrelays[i].peer1.user) { r += ' (User:' + parent.wsrelays[i].peer1.user.name + ')' }
|
||||
}
|
||||
if (parent.wsrelays[i].peer2 != null) {
|
||||
r += ' to ' + cleanRemoteAddr(parent.wsrelays[i].peer2.req.ip);
|
||||
if (parent.wsrelays[i].peer2.user) { r += ' (User:' + parent.wsrelays[i].peer2.user.name + ')' }
|
||||
}
|
||||
r += '\r\n';
|
||||
}
|
||||
if (r == '') { r = 'No relays.'; }
|
||||
|
@ -28,7 +28,7 @@ var CreateAgentRedirect = function (meshserver, module, serverPublicNamePort, au
|
||||
obj.webrtc = null;
|
||||
obj.debugmode = 0;
|
||||
obj.serverIsRecording = false;
|
||||
obj.latency = { timer: null, lastSend: 0, current: 0, send: false, callbacks: [] };
|
||||
obj.latency = { lastSend: null, current: -1, callback: null };
|
||||
if (domainUrl == null) { domainUrl = '/'; }
|
||||
|
||||
// Console Message
|
||||
@ -74,9 +74,9 @@ var CreateAgentRedirect = function (meshserver, module, serverPublicNamePort, au
|
||||
if (controlMsg.type == 'console') {
|
||||
obj.consoleMessage = controlMsg.msg;
|
||||
if (obj.onConsoleMessageChange) { obj.onConsoleMessageChange(obj, obj.consoleMessage); }
|
||||
} else if (controlMsg.type = 'latency') {
|
||||
} else if ((controlMsg.type = 'latency') && (typeof controlMsg.time == 'number')) {
|
||||
obj.latency.current = (new Date().getTime()) - controlMsg.time;
|
||||
obj.latency.onUpdate();
|
||||
if (obj.latency.callbacks != null) { obj.latency.callback(obj.latency.current); }
|
||||
} else if (obj.webrtc != null) {
|
||||
if (controlMsg.type == 'answer') {
|
||||
obj.webrtc.setRemoteDescription(new RTCSessionDescription(controlMsg), function () { /*console.log('WebRTC remote ok');*/ }, obj.xxCloseWebRTC);
|
||||
@ -95,24 +95,14 @@ var CreateAgentRedirect = function (meshserver, module, serverPublicNamePort, au
|
||||
|
||||
function performWebRtcSwitch() {
|
||||
if ((obj.webSwitchOk == true) && (obj.webRtcActive == true)) {
|
||||
obj.latency.current = -1;
|
||||
obj.sendCtrlMsg('{"ctrlChannel":"102938","type":"webrtc0"}'); // Indicate to the meshagent that it can start traffic switchover
|
||||
obj.sendCtrlMsg('{"ctrlChannel":"102938","type":"webrtc1"}'); // Indicate to the meshagent that data traffic will no longer be sent over websocket.
|
||||
// TODO: Hold/Stop sending data over websocket
|
||||
if (obj.onStateChanged != null) { obj.onStateChanged(obj, obj.State); }
|
||||
}
|
||||
}
|
||||
|
||||
obj.latencyTimer = function() {
|
||||
obj.latency.send = true;
|
||||
}
|
||||
|
||||
obj.latency.onUpdate = function(func) {
|
||||
if (func != null) { obj.latency.callbacks.push(func); return; }
|
||||
if (obj.latency.callbacks.length > 0) {
|
||||
for (var x in obj.latency.callbacks) obj.latency.callbacks[x](obj.latency.current);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
obj.xxOnMessage = function (e) {
|
||||
//console.log('Recv', e.data, e.data.byteLength, obj.State);
|
||||
if (obj.State < 3) {
|
||||
@ -153,6 +143,7 @@ var CreateAgentRedirect = function (meshserver, module, serverPublicNamePort, au
|
||||
}, obj.xxCloseWebRTC, { mandatory: { OfferToReceiveAudio: false, OfferToReceiveVideo: false } });
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -164,11 +155,6 @@ var CreateAgentRedirect = function (meshserver, module, serverPublicNamePort, au
|
||||
}
|
||||
|
||||
if (typeof e.data == 'object') {
|
||||
if (obj.latency.timer == null) {
|
||||
obj.latency.timer = setInterval(obj.latencyTimer, 3000);
|
||||
}
|
||||
if (obj.latency.send) { obj.latency.send = false; obj.sendCtrlMsg('{"ctrlChannel":"102938","type":"latency","time":'+ new Date().getTime() +'}'); }
|
||||
|
||||
if (fileReaderInuse == true) { fileReaderAcc.push(e.data); return; }
|
||||
if (fileReader.readAsBinaryString && (obj.m.ProcessBinaryData == null)) {
|
||||
// Chrome & Firefox (Draft)
|
||||
@ -188,6 +174,12 @@ var CreateAgentRedirect = function (meshserver, module, serverPublicNamePort, au
|
||||
// If we get a string object, it maybe the WebRTC confirm. Ignore it.
|
||||
obj.xxOnSocketData(e.data);
|
||||
}
|
||||
|
||||
// Request RTT mesure, don't use this if WebRTC is active
|
||||
if (obj.webRtcActive != true) {
|
||||
var ticks = new Date().getTime();
|
||||
if ((obj.latency.lastSend == null) || ((ticks - obj.latency.lastSend) > 5000)) { obj.latency.lastSend = ticks; obj.sendCtrlMsg('{"ctrlChannel":"102938","type":"latency","time":' + ticks + '}'); }
|
||||
}
|
||||
};
|
||||
|
||||
// Setup the file reader
|
||||
@ -268,8 +260,7 @@ var CreateAgentRedirect = function (meshserver, module, serverPublicNamePort, au
|
||||
|
||||
obj.Stop = function (x) {
|
||||
if (obj.debugmode == 1) { console.log('stop', x); }
|
||||
obj.latency.current = 0;
|
||||
obj.latency.onUpdate();
|
||||
|
||||
// Clean up WebRTC
|
||||
obj.xxCloseWebRTC();
|
||||
|
||||
|
@ -515,7 +515,6 @@
|
||||
<span id=connectbutton1hspan> <input type=button id=connectbutton1h value="HW Connect" title="Connect using Intel AMT hardware KVM" onclick=connectDesktop(event,2) onkeypress="return false" onkeydown="return false" disabled="disabled" /></span>
|
||||
<span id=disconnectbutton1span> <input type=button id=disconnectbutton1 value="Disconnect" onclick=connectDesktop(event,0) onkeypress="return false" onkeydown="return false" /></span>
|
||||
<span id="deskstatus">Disconnected</span>
|
||||
<span id="connectLatency">(Ping: <span id="connectLatencyTime">0</span>ms)</span>
|
||||
</div>
|
||||
</div>
|
||||
<div id=deskarea2 style="">
|
||||
@ -554,6 +553,7 @@
|
||||
</div>
|
||||
<div id=deskarea4 class="areaFoot">
|
||||
<div class="toright2">
|
||||
<span id="DeskLatency" title="Desktop Session Latency"></span>
|
||||
<span id="DeskTimer" title="Session time"></span>
|
||||
<select id=termdisplays style="display:none" onchange=deskSetDisplay(event) onkeypress="return false" onkeydown="return false"></select>
|
||||
<input id=DeskToolsButton type=button value=Tools title="Toggle tools view" onkeypress="return false" onkeydown="return false" onclick="toggleDeskTools()" />
|
||||
@ -5861,7 +5861,7 @@
|
||||
desktop.m.onDisplayinfo = deskDisplayInfo;
|
||||
desktop.m.onScreenSizeChange = deskAdjust;
|
||||
desktop.Start(desktopNode._id);
|
||||
desktop.latency.onUpdate(function(ms) { QH('connectLatencyTime', ms); });
|
||||
desktop.latency.callback = function(ms) { console.log('latency', ms); updateSessionTime(); };
|
||||
desktop.contype = 1;
|
||||
} else if (contype == 3) {
|
||||
// Ask for user sessions
|
||||
@ -5941,10 +5941,11 @@
|
||||
|
||||
function updateSessionTime() {
|
||||
// Desktop
|
||||
var seconds = 0;
|
||||
var latencyStr = '', seconds = 0;
|
||||
if (desktop && desktop.startTime) {
|
||||
if (desktop.latency && (desktop.latency.current >= 0)) { latencyStr = format('{0} ms, ', desktop.latency.current); }
|
||||
seconds = Math.floor((new Date() - desktop.startTime) / 1000);
|
||||
QH('DeskTimer', zeroPad(Math.floor(seconds / 3600), 2) + ':' + zeroPad((Math.floor(seconds / 60) % 60), 2) + ':' + zeroPad((seconds % 60), 2));
|
||||
QH('DeskTimer', latencyStr + zeroPad(Math.floor(seconds / 3600), 2) + ':' + zeroPad((Math.floor(seconds / 60) % 60), 2) + ':' + zeroPad((seconds % 60), 2));
|
||||
} else {
|
||||
QH('DeskTimer', '');
|
||||
}
|
||||
@ -5952,8 +5953,9 @@
|
||||
// Terminal
|
||||
seconds = 0;
|
||||
if (terminal && terminal.startTime) {
|
||||
if (terminal.latency && (terminal.latency.current >= 0)) { latencyStr = format('{0} ms, ', terminal.latency.current); }
|
||||
seconds = Math.floor((new Date() - terminal.startTime) / 1000);
|
||||
QH('TermTimer', zeroPad(Math.floor(seconds / 3600), 2) + ':' + zeroPad((Math.floor(seconds / 60) % 60), 2) + ':' + zeroPad((seconds % 60), 2));
|
||||
QH('TermTimer', latencyStr + zeroPad(Math.floor(seconds / 3600), 2) + ':' + zeroPad((Math.floor(seconds / 60) % 60), 2) + ':' + zeroPad((seconds % 60), 2));
|
||||
} else {
|
||||
QH('TermTimer', '');
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user