Add KEEPALIVE_OPTIONS_REQUEST message support to mpserver

This commit is contained in:
Ganeshr93 2022-01-06 01:44:04 -06:00
parent ce93843a51
commit 64ce36405d

View File

@ -30,6 +30,7 @@ module.exports.CreateMpsServer = function (parent, db, args, certificates) {
const net = require('net');
const tls = require('tls');
const MAX_IDLE = 90000; // 90 seconds max idle time, higher than the typical KEEP-ALIVE periode of 60 seconds
const KEEPALIVE_INTERVAL = 30; // 30 seconds is typical keepalive interval for AMT CIRA connection
// This MPS server is also a tiny HTTPS server. HTTP responses are here.
obj.httpResponses = {
@ -563,6 +564,13 @@ module.exports.CreateMpsServer = function (parent, db, args, certificates) {
parent.debug('mpscmd', '--> KEEPALIVE_REPLY');
return 5;
}
case APFProtocol.KEEPALIVE_OPTIONS_REPLY: {
if (len < 9) return 0;
const keepaliveInterval = common.ReadInt(data, 1);
const timeout = common.ReadInt(data, 5);
parent.debug('mpscmd', '--> KEEPALIVE_OPTIONS_REPLY', keepaliveInterval, timeout);
return 9;
}
case APFProtocol.PROTOCOLVERSION: {
if (len < 93) return 0;
protocolVersionCount++;
@ -888,6 +896,9 @@ module.exports.CreateMpsServer = function (parent, db, args, certificates) {
parent.debug('mpscmd', '--> GLOBAL_REQUEST', request, addr + ':' + port);
if (socket.tag.boundPorts.indexOf(port) == -1) { socket.tag.boundPorts.push(port); }
SendTcpForwardSuccessReply(socket, port);
//5900 port is the last TCP port on which connections for forwarding are to be cancelled. Ports order: 16993, 16992, 664, 623, 16995, 16994, 5900
//Request keepalive interval time
if (port === 5900) { SendKeepaliveOptionsRequest(socket, KEEPALIVE_INTERVAL, 0); }
return 14 + requestLen + addrLen;
}
@ -1173,6 +1184,11 @@ module.exports.CreateMpsServer = function (parent, db, args, certificates) {
Write(socket, String.fromCharCode(APFProtocol.KEEPALIVE_REPLY) + common.IntToStr(cookie));
}
function SendKeepaliveOptionsRequest(socket, keepaliveTime, timeout) {
parent.debug('mpscmd', '<-- KEEPALIVE_OPTIONS_REQUEST', keepaliveTime, timeout);
Write(socket, String.fromCharCode(APFProtocol.KEEPALIVE_OPTIONS_REQUEST) + common.IntToStr(keepaliveTime) + common.IntToStr(timeout));
}
function SendChannelOpenFailure(socket, senderChannel, reasonCode) {
parent.debug('mpscmd', '<-- CHANNEL_OPEN_FAILURE', senderChannel, reasonCode);
Write(socket, String.fromCharCode(APFProtocol.CHANNEL_OPEN_FAILURE) + common.IntToStr(senderChannel) + common.IntToStr(reasonCode) + common.IntToStr(0) + common.IntToStr(0));