From 454f1c9d6daa44b3fc94ff09828e7eee0fd1f18a Mon Sep 17 00:00:00 2001 From: Bram Kelchtermans Date: Wed, 4 Nov 2026 11:43:04 +0100 Subject: [PATCH] max conns? --- Dockers/xtream-proxy/src/config.js | 9 +++++++-- Dockers/xtream-proxy/src/upstream-pool.js | 21 +++++++++++++++++++-- Dockers/xtream-proxy/src/upstream.js | 3 ++- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/Dockers/xtream-proxy/src/config.js b/Dockers/xtream-proxy/src/config.js index 54fc516..6e4b392 100644 --- a/Dockers/xtream-proxy/src/config.js +++ b/Dockers/xtream-proxy/src/config.js @@ -77,7 +77,7 @@ function readConfigEntries() { } for (const url of validUrls) { - entries.push({ url, username, password }); + entries.push({ url, username, password, entryId: index }); } }); return entries; @@ -102,7 +102,12 @@ function reloadConfig() { seen.add(upstream.key); const existing = previous.get(upstream.key); - next.push(existing || upstream); + if (existing) { + existing.entryId = upstream.entryId; + next.push(existing); + } else { + next.push(upstream); + } } const removed = upstreams.filter((u) => !seen.has(u.key)).length; diff --git a/Dockers/xtream-proxy/src/upstream-pool.js b/Dockers/xtream-proxy/src/upstream-pool.js index 2efc181..2a3f33f 100644 --- a/Dockers/xtream-proxy/src/upstream-pool.js +++ b/Dockers/xtream-proxy/src/upstream-pool.js @@ -26,13 +26,30 @@ function isBusy(upstream) { } function totalConnectionCapacity() { - let total = 0; + const perEntry = new Map(); for (const upstream of getUpstreams()) { + const entryId = upstream.entryId ?? upstream.key; const maxCons = upstream.state.maxCons; - total += maxCons !== null && maxCons > 0 ? maxCons : 1; + + if (!perEntry.has(entryId)) { + perEntry.set(entryId, maxCons); + continue; + } + + const current = perEntry.get(entryId); + if (maxCons !== null && maxCons > 0) { + perEntry.set( + entryId, + current !== null && current > 0 ? Math.max(current, maxCons) : maxCons + ); + } } + let total = 0; + for (const maxCons of perEntry.values()) { + total += maxCons !== null && maxCons > 0 ? maxCons : 1; + } return total; } diff --git a/Dockers/xtream-proxy/src/upstream.js b/Dockers/xtream-proxy/src/upstream.js index 6d47cfd..6233787 100644 --- a/Dockers/xtream-proxy/src/upstream.js +++ b/Dockers/xtream-proxy/src/upstream.js @@ -19,7 +19,7 @@ function baseState() { } class Upstream { - constructor({ url, username, password }) { + constructor({ url, username, password, entryId }) { const parsed = new URL(url); parsed.hash = ''; parsed.search = ''; @@ -27,6 +27,7 @@ class Upstream { this.basePath = parsed.pathname.replace(/\/+$/, ''); this.username = username; this.password = password; + this.entryId = entryId; this.key = `${parsed.origin}${this.basePath}|${username}|${password}`; this.state = { ...baseState(), inFlight: 0 }; }