Improved web relay sharing (#4413)

This commit is contained in:
Ylian Saint-Hilaire 2022-08-25 21:10:09 -07:00
parent 5d7fabfc21
commit 4fe394226c
3 changed files with 15 additions and 4 deletions

View File

@ -92,8 +92,13 @@ module.exports.CreateWebRelaySession = function (parent, db, req, args, domain,
obj.webCookies = {};
// Setup an expire time if needed
if (expire != null) { var timeout = (expire - Date.now()); if (timeout < 10) { timeout = 10; } obj.expireTimer = setTimeout(close, timeout); }
if (expire != null) {
var timeout = (expire - Date.now());
if (timeout < 10) { timeout = 10; }
parent.parent.debug('webrelay', 'timeout set to ' + Math.floor(timeout / 1000) + ' second(s).');
obj.expireTimer = setTimeout(function () { parent.parent.debug('webrelay', 'timeout'); close(); }, timeout);
}
// Events
obj.closed = false;
obj.onclose = null;
@ -131,6 +136,8 @@ module.exports.CreateWebRelaySession = function (parent, db, req, args, domain,
// Handle request
function handleNextRequest() {
if (obj.closed == true) return;
// if there are not pending requests, do nothing
if (pendingRequests.length == 0) return;
@ -148,13 +155,14 @@ module.exports.CreateWebRelaySession = function (parent, db, req, args, domain,
return;
}
}
if (count > 0) return;
launchNewTunnel();
}
function launchNewTunnel() {
// Launch a new tunnel
if (obj.closed == true) return;
parent.parent.debug('webrelay', 'launchNewTunnel');
const tunnel = module.exports.CreateWebRelay(obj, db, args, domain);
tunnel.onclose = function (tunnelId, processedCount) {
@ -188,6 +196,7 @@ module.exports.CreateWebRelaySession = function (parent, db, req, args, domain,
}
}
tunnel.onNextRequest = function () {
if (tunnels == null) return;
parent.parent.debug('webrelay', 'tunnel-onNextRequest');
handleNextRequest();
}

View File

@ -224,6 +224,7 @@ module.exports.CreateWebRelayServer = function (parent, db, args, certificates,
if (req.session.userid) { delete req.session.userid; } // Clear the web relay userid
if (req.session.z != webSessionId) { req.session.z = webSessionId; } // Set the web relay guest session
expire = urlCookie.expire;
if ((expire != null) && (expire <= Date.now())) { parent.debug('webrelay', 'expired link'); res.sendStatus(404); return; }
}
// No session identifier was setup, exit now
@ -246,7 +247,7 @@ module.exports.CreateWebRelayServer = function (parent, db, args, certificates,
if (xrelaySession != null) { xrelaySession.close(); delete relaySessions[webSessionId]; }
// Create a web relay session
const relaySession = require('./apprelays.js').CreateWebRelaySession(obj, db, req, args, domain, userid, nodeid, addr, port, appid, xrelaySession, expire);
const relaySession = require('./apprelays.js').CreateWebRelaySession(obj, db, req, args, domain, userid, nodeid, addr, port, appid, webSessionId, expire);
relaySession.onclose = function (sessionId) {
// Remove the relay session
delete relaySessions[sessionId];

View File

@ -6610,6 +6610,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF
if (req.session.userid) { delete req.session.userid; } // Clear the web relay userid
if (req.session.z != webSessionId) { req.session.z = webSessionId; } // Set the web relay guest session
expire = urlCookie.expire;
if ((expire != null) && (expire <= Date.now())) { parent.debug('webrelay', 'expired link'); res.sendStatus(404); return; }
}
// No session identifier was setup, exit now