http&bouncer: connection configured save mode

Signed-off-by: Yonle <yonle@lecturify.net>
This commit is contained in:
Yonle 2024-02-25 00:23:09 +07:00
parent 7293893ab4
commit 84b0421f4c
3 changed files with 7 additions and 3 deletions

View File

@ -38,6 +38,7 @@ module.exports = (ws, req, onClose) => {
ws.acceptKinds = query.accept?.split(",").map(_ => parseInt(_));
ws.forcedLimit = parseInt(query.limit);
ws.accurateMode = parseInt(query.accurate);
ws.saveMode = parseInt(query.save);
if (authorized_keys?.length) {
authKey = Date.now() + Math.random().toString(36);
@ -268,7 +269,7 @@ function newConn(addr, client, reconn_t = 0) {
if (client.events.get(data[1]).size >= limit) {
// Once reached to <filter.limit>, send EOSE to client.
client.send(JSON.stringify(["EOSE", data[1]]));
if (!client.accurateMode && pause_on_limit) {
if (!client.accurateMode && (client.saveMode || pause_on_limit)) {
client.pause_subs.add(data[1]);
} else {
client.pendingEOSE.delete(data[1]);

View File

@ -49,7 +49,7 @@ module.exports = {
// Could save client's bandwidth. Disable this if you need to get more events.
//
// You may also need to adjust <max_eose_score>.
pause_on_limit: false,
pause_on_limit: true,
// Maximum of received EOSE from relays to send EOSE to client.
// Normally, waiting EOSE from 3 relays should be enough. Leaving it with 0 equals wait for every established relays.

View File

@ -79,9 +79,12 @@ server.on('request', (req, res) => {
res.write(`\n\n- To make connection that override client's REQ limit, Connect:`);
res.write(`\n ${serverAddr}?limit=50 or ${serverAddr}?accurate=1&limit=50`);
res.write(`\n (Will override REQ limit from client to 50 if exceeds)`);
res.write(`\n\n- To connect with accurate bouncing mode, Connect:`);
res.write(`\n\n- To connect with accurate bouncing mode${config.pause_on_limit ? "" : " (Default)"}, Connect:`);
res.write(`\n ${serverAddr}?accurate=1`);
res.write(`\n (Will consume lot of bandwidths)`);
res.write(`\n\n- To connect with save mode${config.pause_on_limit ? " (Default)" : ""}, Connect:`);
res.write(`\n ${serverAddr}?save=1`);
res.write(`\n (Saves bandwidth usage)`);
res.end(`\n\n---\nPowered by Bostr (${version}) - Open source Nostr bouncer\nhttps://github.com/Yonle/bostr`);
} else if (req.url.includes("favicon") && favicon) {
res.writeHead(200, { "Content-Type": "image/" + config.favicon?.split(".").pop() });