Tor is decentralised in the sense that thousands of volunteers run the relays. It is not decentralised in how clients find those relays. That job belongs to a small, hard-coded set of directory authorities, currently around nine machines run by people the Tor Project trusts, and every Tor client in the world believes what a majority of them sign.

That's a deliberate trade-off. A fully peer-to-peer directory sounds nicer but is much easier to poison: an attacker who controls many peers can show different clients different views of the network and partition them. A small, known group that publishes one signed document for everyone avoids that. The cost is that those authorities are a single point of attack and coordination, and everyone involved knows it.

What the authorities actually do

Every relay uploads a signed server descriptor to each authority when it starts and periodically after that. The descriptor lists its identity keys, its onion key for the ntor handshake, its IP addresses and ports, its exit policy, its declared family, contact info, platform version and self-reported bandwidth.

Each authority then does its own checking. It connects to the relay's ORPort to see whether it's reachable. It tracks uptime over time. It checks the version against a list of recommended ones. Based on what it sees, it forms an opinion on every relay, including which flags it deserves:

FlagRoughly means
RunningThe authority reached it recently
ValidRunning an acceptable version and not rejected
FastBandwidth above a low threshold
StableLong mean time between failures
GuardFast, stable, around long enough to be an entry guard
ExitExit policy allows common web ports to most addresses
BadExitKnown to misbehave as an exit; don't exit through it
HSDirCan store onion service descriptors
V2DirServes directory information to clients
MiddleOnlyRestricted to the middle position
StaleDescHasn't uploaded a new descriptor in a while

Some flags (BadExit, MiddleOnly, outright rejection) come from manual decisions by authority operators, usually acting on reports from the bad-relays team. The rest are computed.

The hourly vote

Once an hour each authority publishes a vote: a document listing every relay it knows about, with the flags it thinks they should have and other measurements. A few minutes later the authorities fetch each other's votes and each one runs the same deterministic algorithm over the full set. Because the inputs and the algorithm are identical, they all arrive at the same consensus document byte for byte. Then they sign it and exchange signatures. If more than half have signed, the consensus is published to the network, normally right on the hour.

The rules for combining votes are mostly majority-based. A relay is listed if more than half the voting authorities list it. A flag is set if more than half of the authorities that vote on that flag give it. The rules are versioned as "consensus methods" so that authorities running different tor versions can still agree: they pick the highest method a supermajority supports.

Each consensus has three timestamps. valid-after is when it takes effect. fresh-until is an hour later, when clients should start looking for a newer one. valid-until is a couple of hours after that. Clients will tolerate a somewhat stale consensus if the authorities fail to produce a new one, which happens occasionally when enough authorities are down or under attack. The network keeps working on the last good document for a while, so a missed hour or two isn't a crisis.

Bandwidth: the part relays can't lie about (much)

If clients chose relays by self-reported bandwidth, a malicious operator could just claim to be enormous and attract a big share of circuits. So some authorities also act as bandwidth authorities. They run a scanner (these days sbws, the Simple Bandwidth Scanner) that builds two-hop circuits through each relay and times downloads through it. The results feed into the authority's vote, and the consensus takes the median of the measured values. Clients then weight their path selection by those measured numbers, not by what relays claim. The bandwidth authority glossary entry has a shorter version of this.

The consensus also includes "bandwidth weights", a set of position-specific multipliers that decide how often guard-capable or exit-capable relays should be used in other positions. When exit capacity is scarce, exits are mostly kept out of middle positions.

Keys and trust

Each authority has a long-term identity key that the operator keeps offline. That key signs a certificate for a medium-term signing key, which lives on the server and signs votes and consensuses. If the server is compromised, the operator can revoke the signing key without changing the identity that is compiled into every Tor client. The authority list itself, with addresses and identity fingerprints, is part of the tor source code, which is why adding or retiring an authority means a new tor release and years of overlap.

The authorities also produce a shared random value every day through a commit-and-reveal protocol. Onion services use it to decide which relays hold their descriptors, so nobody can predict the positions far in advance and park relays there. If you've read about HSDirs, that's where the randomness comes from.

Getting the consensus to clients

Several million clients fetching an hourly document from nine servers wouldn't work. Instead, relays with the V2Dir flag act as directory caches. Clients ship with a list of fallback directory mirrors for bootstrapping, then fetch from their guard after that. They also download the compact microdescriptor flavour of the consensus rather than the full one, and since 0.3.1 they can fetch diffs against the copy they already hold, which cut directory bandwidth substantially.

Every consensus ever published is archived by the Tor Project on CollecTor, which is also what makes the graphs on Tor Metrics possible. If you want to see the real thing, look in your tor data directory for cached-microdesc-consensus. Each relay is a block starting with an r line, then s for flags, w for bandwidth weight and m for the microdescriptor digest. It's dull to read and fascinating once you realise every Tor client on earth has the same file.

A related caveat: authorities can only judge what they can measure. They don't know who actually operates a relay, and they can't see if a group of relays is secretly coordinated. That's the gap Sybil attacks aim at.

#directory-authorities #consensus #tor-network #relays