Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added peersCountPerInfoHash in stats.json #67

Merged
merged 2 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
sourceType: "module",
},
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
],
Expand All @@ -16,5 +17,6 @@ module.exports = {
"@typescript-eslint/prefer-nullish-coalescing": "error",
"spaced-comment": ["warn", "always", { markers: ["/"] }],
curly: ["warn", "multi-line", "consistent"],
"object-shorthand": ["error", "always"],
},
};
2 changes: 1 addition & 1 deletion lib/fast-tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ export class FastTracker implements Tracker {
}
}

peer.sendMessage({ action: "scrape", files: files }, peer);
peer.sendMessage({ action: "scrape", files }, peer);
}
}

Expand Down
22 changes: 14 additions & 8 deletions lib/run-uws-tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ function validateSettings(jsonSettings: UnknownObject): Settings | undefined {
}

return {
servers: servers,
servers,
tracker: jsonSettings.tracker,
websocketsAccess: jsonSettings.websocketsAccess,
};
Expand All @@ -188,11 +188,11 @@ async function runServers(tracker: Tracker, settings: Settings): Promise<void> {

const serverPromises = settings.servers.map(async (serverSettings) => {
const server = buildServer({
tracker: tracker,
serverSettings: serverSettings,
tracker,
serverSettings,
websocketsAccess: settings.websocketsAccess,
indexHtml: indexHtml,
servers: servers,
indexHtml,
servers,
});
servers.push(server);
await server.run();
Expand Down Expand Up @@ -236,10 +236,15 @@ function buildServer({
.get("/stats.json", (response: HttpResponse, request: HttpRequest) => {
debugRequest(server, request);

const { swarms } = tracker;
const swarms = tracker.swarms;
const peersCountPerInfoHash: Record<string, number> = {};

let peersCount = 0;
for (const swarm of swarms.values()) {
for (const [infoHash, swarm] of swarms) {
peersCount += swarm.peers.length;

const infoHashHex = Buffer.from(infoHash, "binary").toString("hex");
peersCountPerInfoHash[infoHashHex] = peersCount;
}

const serversStats = new Array<{
Expand All @@ -257,9 +262,10 @@ function buildServer({
response.writeHeader("Content-Type", "application/json").end(
JSON.stringify({
torrentsCount: swarms.size,
peersCount: peersCount,
peersCount,
servers: serversStats,
memory: process.memoryUsage(),
peersCountPerInfoHash,
}),
);
})
Expand Down
Loading