mirror of
https://github.com/Yonle/bostr.git
synced 2025-09-27 13:26:30 +02:00
introduce max EOSE score in config
Signed-off-by: Yonle <yonle@lecturify.net>
This commit is contained in:
@@ -3,13 +3,16 @@ const { validateEvent, nip19 } = require("nostr-tools");
|
|||||||
const auth = require("./auth.js");
|
const auth = require("./auth.js");
|
||||||
const nip42 = require("./nip42.js");
|
const nip42 = require("./nip42.js");
|
||||||
|
|
||||||
let { relays, tmp_store, log_about_relays, authorized_keys, private_keys, reconnect_time, wait_eose, pause_on_limit, eose_timeout } = require("./config");
|
let { relays, tmp_store, log_about_relays, authorized_keys, private_keys, reconnect_time, wait_eose, pause_on_limit, eose_timeout, max_eose_score } = require("./config");
|
||||||
|
|
||||||
const socks = new Set();
|
const socks = new Set();
|
||||||
const csess = new Map();
|
const csess = new Map();
|
||||||
|
|
||||||
authorized_keys = authorized_keys?.map(i => i.startsWith("npub") ? nip19.decode(i).data : i);
|
authorized_keys = authorized_keys?.map(i => i.startsWith("npub") ? nip19.decode(i).data : i);
|
||||||
|
|
||||||
|
// CL MaxEoseScore: Set <max_eose_score> as 0 if configured relays is under of the expected number from <max_eose_score>
|
||||||
|
if (relays.length < max_eose_score) max_eose_score = 0;
|
||||||
|
|
||||||
// CL - User socket
|
// CL - User socket
|
||||||
module.exports = (ws, req) => {
|
module.exports = (ws, req) => {
|
||||||
let authKey = null;
|
let authKey = null;
|
||||||
@@ -226,7 +229,8 @@ function newConn(addr, id) {
|
|||||||
case "EOSE":
|
case "EOSE":
|
||||||
if (!client.pendingEOSE.has(data[1])) return;
|
if (!client.pendingEOSE.has(data[1])) return;
|
||||||
client.pendingEOSE.set(data[1], client.pendingEOSE.get(data[1]) + 1);
|
client.pendingEOSE.set(data[1], client.pendingEOSE.get(data[1]) + 1);
|
||||||
if (wait_eose && (client.pendingEOSE.get(data[1]) < Array.from(socks).filter(sock => sock.id === id).length)) return;
|
if (process.env.LOG_ABOUT_RELAYS || log_about_relays) console.log(process.pid, "---", `[${id}]`, `got EOSE from ${ws.url} for ${data[1]}. There are ${client.pendingEOSE.get(data[1])} EOSE received out of ${Array.from(socks).filter(sock => sock.id === id).length} connected relays.`);
|
||||||
|
if (wait_eose && (client.pendingEOSE.get(data[1]) < (max_eose_score || Array.from(socks).filter(sock => sock.id === id).length))) return;
|
||||||
client.pendingEOSE.delete(data[1]);
|
client.pendingEOSE.delete(data[1]);
|
||||||
cancel_EOSETimeout(data[1]);
|
cancel_EOSETimeout(data[1]);
|
||||||
if (client.pause_subs.has(data[1])) return client.pause_subs.delete(data[1]);
|
if (client.pause_subs.has(data[1])) return client.pause_subs.delete(data[1]);
|
||||||
|
@@ -21,8 +21,8 @@ module.exports = {
|
|||||||
//
|
//
|
||||||
// Depending on your configured relays,
|
// Depending on your configured relays,
|
||||||
// It may could cause loading problems in client due to slow EOSE from bouncer.
|
// It may could cause loading problems in client due to slow EOSE from bouncer.
|
||||||
// You could try fix this by changing <eose_timeout> value.
|
// You could try fix this by changing <eose_timeout> or <max_eose_score> value.
|
||||||
wait_eose: false,
|
wait_eose: true,
|
||||||
|
|
||||||
// Pause an subscription from receiving further events after reached to <filter.limit>
|
// Pause an subscription from receiving further events after reached to <filter.limit>
|
||||||
// Could save client's bandwdith.
|
// Could save client's bandwdith.
|
||||||
@@ -33,6 +33,12 @@ module.exports = {
|
|||||||
// EOSE timeout in miliseconds
|
// EOSE timeout in miliseconds
|
||||||
eose_timeout: 2300,
|
eose_timeout: 2300,
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
// NOTE: Please adjust this max score correctly with your configured relays.
|
||||||
|
// If you only setted up 3 relays, Set the <max_eose_score> as 0.
|
||||||
|
max_eose_score: 3,
|
||||||
|
|
||||||
// A whitelist of users public keys who could use this bouncer.
|
// A whitelist of users public keys who could use this bouncer.
|
||||||
// Leaving this empty will allows everyone to use this bouncer.
|
// Leaving this empty will allows everyone to use this bouncer.
|
||||||
// NOTE: - Require NIP-42 compatible nostr client
|
// NOTE: - Require NIP-42 compatible nostr client
|
||||||
|
Reference in New Issue
Block a user