Skip to content

Commit

Permalink
Merge pull request #67 from Novage/feat/peersCountPerInfoHash
Browse files Browse the repository at this point in the history
added peersCountPerInfoHash in stats.json
  • Loading branch information
mrlika committed Feb 16, 2024
2 parents cc83788 + f550494 commit c0a5101
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
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

0 comments on commit c0a5101

Please sign in to comment.