mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-01 02:12:26 +00:00
Merge pull request #2041 from PR0M3TH3AN/codex/update-torrentclient.probepeers-for-webseed-wires
Handle web seed peers in torrent probes
This commit is contained in:
1 file changed
+56
-11
+56
-11
@@ -345,16 +345,53 @@ export class TorrentClient {
|
||||
return;
|
||||
}
|
||||
|
||||
const settleHealthy = () => {
|
||||
const peers = Math.max(1, Math.floor(normalizeNumber(torrent?.numPeers, 1)));
|
||||
finalize({ healthy: true, peers, reason: "peer" });
|
||||
let webSeedCount = 0;
|
||||
|
||||
const getWebSeedCount = () => {
|
||||
if (torrent?.wires?.length) {
|
||||
const wireCount = torrent.wires.filter(
|
||||
(wire) => wire?.type === "webSeed"
|
||||
).length;
|
||||
return Math.max(webSeedCount, wireCount);
|
||||
}
|
||||
return webSeedCount;
|
||||
};
|
||||
|
||||
torrent.once("wire", settleHealthy);
|
||||
const getPeerCounts = () => {
|
||||
const regularPeers = Math.max(
|
||||
0,
|
||||
Math.floor(normalizeNumber(torrent?.numPeers, 0))
|
||||
);
|
||||
const webSeeds = getWebSeedCount();
|
||||
return {
|
||||
regularPeers,
|
||||
webSeeds,
|
||||
totalPeers: regularPeers + webSeeds,
|
||||
};
|
||||
};
|
||||
|
||||
const settleHealthy = (counts = getPeerCounts()) => {
|
||||
const peers = Math.max(1, counts.totalPeers);
|
||||
const webseedOnly = counts.regularPeers === 0 && counts.webSeeds > 0;
|
||||
finalize({
|
||||
healthy: true,
|
||||
peers,
|
||||
reason: webseedOnly ? "webseed" : "peer",
|
||||
webseedOnly,
|
||||
});
|
||||
};
|
||||
|
||||
torrent.on("wire", (wire) => {
|
||||
if (wire?.type === "webSeed") {
|
||||
webSeedCount += 1;
|
||||
}
|
||||
settleHealthy();
|
||||
});
|
||||
|
||||
torrent.once("error", (err) => {
|
||||
const peers = Math.max(0, Math.floor(normalizeNumber(torrent?.numPeers, 0)));
|
||||
const webseedOnly = peers === 0 && hasWebSeed;
|
||||
const counts = getPeerCounts();
|
||||
const webseedOnly = counts.regularPeers === 0 && counts.webSeeds > 0;
|
||||
const peers = Math.max(0, counts.totalPeers);
|
||||
finalize({
|
||||
healthy: webseedOnly,
|
||||
reason: webseedOnly ? "webseed" : "error",
|
||||
@@ -366,8 +403,9 @@ export class TorrentClient {
|
||||
|
||||
if (safeTimeout > 0) {
|
||||
timeoutId = setTimeout(() => {
|
||||
const peers = Math.max(0, Math.floor(normalizeNumber(torrent?.numPeers, 0)));
|
||||
const webseedOnly = peers === 0 && hasWebSeed;
|
||||
const counts = getPeerCounts();
|
||||
const webseedOnly = counts.regularPeers === 0 && counts.webSeeds > 0;
|
||||
const peers = Math.max(0, counts.totalPeers);
|
||||
finalize({
|
||||
healthy: webseedOnly,
|
||||
peers,
|
||||
@@ -386,9 +424,16 @@ export class TorrentClient {
|
||||
if (!torrent || settled) {
|
||||
return;
|
||||
}
|
||||
const peers = Math.max(0, Math.floor(normalizeNumber(torrent.numPeers, 0)));
|
||||
if (peers > 0) {
|
||||
finalize({ healthy: true, peers, reason: "peer" });
|
||||
const counts = getPeerCounts();
|
||||
if (counts.totalPeers > 0) {
|
||||
const webseedOnly =
|
||||
counts.regularPeers === 0 && counts.webSeeds > 0;
|
||||
finalize({
|
||||
healthy: true,
|
||||
peers: counts.totalPeers,
|
||||
reason: webseedOnly ? "webseed" : "peer",
|
||||
webseedOnly,
|
||||
});
|
||||
}
|
||||
}, pollInterval);
|
||||
}, pollInterval);
|
||||
|
||||
Reference in new issue
Block a user