http&bouncer: connection configured accurateMode

Signed-off-by: Yonle <yonle@lecturify.net>
This commit is contained in:
Yonle 2024-02-24 12:23:55 +07:00
parent aa2084d6b9
commit 7293893ab4
2 changed files with 9 additions and 7 deletions

View File

@ -37,6 +37,7 @@ module.exports = (ws, req, onClose) => {
ws.rejectKinds = query.reject?.split(",").map(_ => parseInt(_));
ws.acceptKinds = query.accept?.split(",").map(_ => parseInt(_));
ws.forcedLimit = parseInt(query.limit);
ws.accurateMode = parseInt(query.accurate);
if (authorized_keys?.length) {
authKey = Date.now() + Math.random().toString(36);
@ -254,22 +255,20 @@ function newConn(addr, client, reconn_t = 0) {
if (NotInSearchQuery) return;
if (client.events.get(data[1]).has(data[2]?.id)) return; // No need to transmit once it has been transmitted before.
if (!client.pause_subs.has(data[1])) {
client.events.get(data[1]).add(data[2]?.id);
client.send(JSON.stringify(data));
}
client.events.get(data[1]).add(data[2]?.id);
client.send(JSON.stringify(data));
// Now count for REQ limit requested by client.
// If it's at the limit, Send EOSE to client and delete pendingEOSE of subID
// Skip if EOSE has been omitted
if (!client.pendingEOSE.has(data[1]) || client.pause_subs.has(data[1])) return;
if (!client.pendingEOSE.has(data[1])) return;
const limit = getFilterLimit(filter);
if (limit === Infinity) return;
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 (pause_on_limit) {
if (!client.accurateMode && pause_on_limit) {
client.pause_subs.add(data[1]);
} else {
client.pendingEOSE.delete(data[1]);

View File

@ -77,8 +77,11 @@ server.on('request', (req, res) => {
res.write(`\n ${serverAddr}?reject=3,6,7`);
res.write(`\n (Will not send events with kind 3, 6, and 7)`);
res.write(`\n\n- To make connection that override client's REQ limit, Connect:`);
res.write(`\n ${serverAddr}?limit=50`);
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 ${serverAddr}?accurate=1`);
res.write(`\n (Will consume lot of bandwidths)`);
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() });