import type { FastifyRequest, FastifyReply } from "fastify"; import type { KnownPDSStorage } from "./knownPDSStorage"; import type { ActiveLabelsStorage } from "./activeLabelsStorage"; import { CacheableMemory } from "cacheable"; export class InfoServer { private knownPDSStorage: KnownPDSStorage; private activeLabelsStorage: ActiveLabelsStorage; private maxPDSDedicatedLabels: number; private statsCache = new CacheableMemory({ ttl: '10s' }); constructor(knownPDSStorage: KnownPDSStorage, activeLabelsStorage: ActiveLabelsStorage, maxPDSDedicatedLabels: number) { this.knownPDSStorage = knownPDSStorage; this.activeLabelsStorage = activeLabelsStorage; this.maxPDSDedicatedLabels = maxPDSDedicatedLabels; } private readonly cacheKey = "stats"; private async computeStats(): Promise { const v = [ await this.knownPDSStorage.countKnownPDSs(), await this.knownPDSStorage.countPDSCrawlingFailures(), await this.activeLabelsStorage.countActiveLabelSubjects(), ]; this.statsCache.set(this.cacheKey, v); return v; } async indexPage(req: FastifyRequest, resp: FastifyReply) { let [totalPDS, failures, activeLabels] = ( this.statsCache.get(this.cacheKey) ?? await this.computeStats() ) as number[]; resp.type("text/html").send(` Independent PDS Labeler

pds.labeler.tny.im

This community ran Bluesky labeler identifies accounts that are hosted on a PDS not operated by Bluesky PBC, and which is, therefore, considered "independent." Some PDS meet this criteria but are not considered, for technical or logistical reasons.

This labeler provides dedicated labels for the ${this.maxPDSDedicatedLabels} biggest independent PDS that it is aware of, by number of accounts.

Subscribe to the labeler on Bluesky to use it.

This labeler works by enumerating accounts (repositories) within each PDS that it finds. It finds new PDS by consuming some events from the Bluesky firehose, and fetching the DID documents of the respective accounts, in order to identify or confirm their current PDS host. Additionally, known PDS are rescanned periodically in order to find and label new accounts.

The source code for the labeler is available on Tangled under a dual MIT and Apache-2.0 licensing scheme.

This labeler is aware of ${activeLabels} accounts hosted on a total of ${totalPDS} independent PDS. It is failing to crawl ${failures} of these PDS, most of which correspond to nonexistent, offline or otherwise malfunctioning or misidentified PDS.

`); } }