mirror of
https://github.com/Yonle/bostr.git
synced 2025-03-19 14:21:54 +01:00
bouncer: try use Set() for connectedRelays counting instead.
This commit is contained in:
parent
20aab1a79c
commit
2bf91f8603
10
bouncer.js
10
bouncer.js
@ -34,13 +34,13 @@ module.exports = (ws, req, onClose) => {
|
||||
ws.subalias = new Map();
|
||||
ws.fakesubalias = new Map();
|
||||
ws.mergedFilters = new Map();
|
||||
ws.connectedRelays = new Set();
|
||||
ws.pubkey = null;
|
||||
ws.rejectKinds = query.reject?.split(",").map(_ => parseInt(_));
|
||||
ws.acceptKinds = query.accept?.split(",").map(_ => parseInt(_));
|
||||
ws.forcedLimit = parseInt(query.limit);
|
||||
ws.accurateMode = parseInt(query.accurate);
|
||||
ws.saveMode = parseInt(query.save);
|
||||
ws.connectedRelays = 0;
|
||||
|
||||
if (authorized_keys?.length) {
|
||||
authKey = Date.now() + Math.random().toString(36);
|
||||
@ -229,7 +229,7 @@ function newConn(addr, client, reconn_t = 0) {
|
||||
relay.on('open', _ => {
|
||||
if (client.readyState !== 1) return relay.terminate();
|
||||
reconn_t = 0;
|
||||
client.connectedRelays++;
|
||||
client.connectedRelays.add(relay);
|
||||
if (log_about_relays) console.log(process.pid, "---", client.ip, `${relay.url} is connected`);
|
||||
|
||||
for (const i of client.my_events) {
|
||||
@ -292,9 +292,9 @@ function newConn(addr, client, reconn_t = 0) {
|
||||
data[1] = client.subalias.get(data[1]);
|
||||
if (!client.pendingEOSE.has(data[1])) return;
|
||||
client.pendingEOSE.set(data[1], client.pendingEOSE.get(data[1]) + 1);
|
||||
if (log_about_relays) console.log(process.pid, "---", client.ip, `got EOSE from ${relay.url} for ${data[1]}. There are ${client.pendingEOSE.get(data[1])} EOSE received out of ${client.connectedRelays} connected relays.`);
|
||||
if (log_about_relays) console.log(process.pid, "---", client.ip, `got EOSE from ${relay.url} for ${data[1]}. There are ${client.pendingEOSE.get(data[1])} EOSE received out of ${client.connectedRelays.size} connected relays.`);
|
||||
|
||||
if (wait_eose && ((client.pendingEOSE.get(data[1]) < max_eose_score) || (client.pendingEOSE.get(data[1]) < client.connectedRelays))) return;
|
||||
if (wait_eose && ((client.pendingEOSE.get(data[1]) < max_eose_score) || (client.pendingEOSE.get(data[1]) < client.connectedRelays.size))) return;
|
||||
client.pendingEOSE.delete(data[1]);
|
||||
|
||||
if (client.pause_subs.has(data[1])) {
|
||||
@ -330,7 +330,7 @@ function newConn(addr, client, reconn_t = 0) {
|
||||
relay.on('close', _ => {
|
||||
if (client.readyState !== 1) return;
|
||||
client.relays.delete(relay); // Remove this socket session from <client.relays> list
|
||||
client.connectedRelays--;
|
||||
client.connectedRelays.delete(relay);
|
||||
if (log_about_relays) console.log(process.pid, "-!-", client.ip, "Disconnected from", relay.url);
|
||||
reconn_t += reconnect_time || 5000
|
||||
const reconnectTimeout = setTimeout(_ => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user