7 Note: This is an attempt to specify Tor as currently implemented. Future
8 versions of Tor will implement improved algorithms.
10 This document tries to cover how Tor chooses to build circuits and assign
11 streams to circuits. Other implementations MAY take other approaches, but
12 implementors should be aware of the anonymity and load-balancing implications
15 THIS SPEC ISN'T DONE YET.
17 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL
18 NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and
19 "OPTIONAL" in this document are to be interpreted as described in
26 1.2. A relay's bandwidth
29 2.1.0. We don't build circuits until we have enough directory info
30 2.1.1. Clients build circuits preemptively
31 2.1.2. Clients build circuits on demand
32 2.1.3. Relays build circuits for testing reachability and bandwidth
33 2.1.4. Hidden-service circuits
34 2.1.5. Rate limiting of failed circuits
35 2.1.6. When to tear down circuits
36 2.2. Path selection and constraints
37 2.2.1. Choosing an exit
38 2.2.2. User configuration
39 2.3. Cannibalizing circuits
40 2.4. Learning when to give up ("timeout") on circuit construction
41 2.4.1 Distribution choice and parameter estimation
42 2.4.2. How much data to record
43 2.4.3. How to record timeouts
44 2.4.4. Detecting Changing Network Conditions
45 2.4.5. Consensus parameters governing behavior
46 2.4.6. Consensus parameters governing behavior
48 3. Attaching streams to circuits
49 4. Hidden-service related circuits
51 5.1. How consensus bandwidth weights factor into entry guard selection
52 6. Server descriptor purposes
53 7. Detecting route manipulation by Guard nodes (Path Bias)
54 7.1. Measuring path construction success rates
55 7.2. Measuring path usage success rates
56 7.3. Scaling success counts
58 7.5. Known barriers to enforcement
60 X.1. Do we actually do this?
61 X.2. A thing we could do to deal with reachability.
62 X.3. Some stuff that worries me about entry guards. 2006 Jun, Nickm.
66 Tor begins building circuits as soon as it has enough directory
67 information to do so (see section 5 of dir-spec.txt). Some circuits are
68 built preemptively because we expect to need them later (for user
69 traffic), and some are built because of immediate need (for user traffic
70 that no current circuit can handle, for testing the network or our
71 reachability, and so on).
73 [Newer versions of Tor (0.2.6.2-alpha and later):
74 If the consensus contains Exits (the typical case), Tor will build both
75 exit and internal circuits. When bootstrap completes, Tor will be ready
76 to handle an application requesting an exit circuit to services like the
79 If the consensus does not contain Exits, Tor will only build internal
80 circuits. In this case, earlier statuses will have included "internal"
81 as indicated above. When bootstrap completes, Tor will be ready to handle
82 an application requesting an internal circuit to hidden services at
85 If a future consensus contains Exits, exit circuits may become available.]
87 When a client application creates a new stream (by opening a SOCKS
88 connection or launching a resolve request), we attach it to an appropriate
89 open circuit if one exists, or wait if an appropriate circuit is
90 in-progress. We launch a new circuit only
91 if no current circuit can handle the request. We rotate circuits over
92 time to avoid some profiling attacks.
94 To build a circuit, we choose all the nodes we want to use, and then
95 construct the circuit. Sometimes, when we want a circuit that ends at a
96 given hop, and we have an appropriate unused circuit, we "cannibalize" the
97 existing circuit and extend it to the new terminus.
99 These processes are described in more detail below.
101 This document describes Tor's automatic path selection logic only; path
102 selection can be overridden by a controller (with the EXTENDCIRCUIT and
103 ATTACHSTREAM commands). Paths constructed through these means may
104 violate some constraints given below.
108 A "path" is an ordered sequence of nodes, not yet built as a circuit.
110 A "clean" circuit is one that has not yet been used for any traffic.
112 A "fast" or "stable" or "valid" node is one that has the 'Fast' or
113 'Stable' or 'Valid' flag
114 set respectively, based on our current directory information. A "fast"
115 or "stable" circuit is one consisting only of "fast" or "stable" nodes.
117 In an "exit" circuit, the final node is chosen based on waiting stream
118 requests if any, and in any case it avoids nodes with exit policy of
119 "reject *:*". An "internal" circuit, on the other hand, is one where
120 the final node is chosen just like a middle node (ignoring its exit
123 A "request" is a client-side stream or DNS resolve that needs to be
126 A "pending" circuit is one that we have started to build, but which has
129 A circuit or path "supports" a request if it is okay to use the
130 circuit/path to fulfill the request, according to the rules given below.
131 A circuit or path "might support" a request if some aspect of the request
132 is unknown (usually its target IP), but we believe the path probably
133 supports the request according to the rules given below.
135 1.2. A relay's bandwidth
137 Old versions of Tor did not report bandwidths in network status
138 documents, so clients had to learn them from the routers' advertised
141 For versions of Tor prior to 0.2.1.17-rc, everywhere below where we
142 refer to a relay's "bandwidth", we mean its clipped advertised
143 bandwidth, computed by taking the smaller of the 'rate' and
144 'observed' arguments to the "bandwidth" element in the relay's
145 descriptor. If a router's advertised bandwidth is greater than
146 MAX_BELIEVABLE_BANDWIDTH (currently 10 MB/s), we clipped to that
149 For more recent versions of Tor, we take the bandwidth value declared
150 in the consensus, and fall back to the clipped advertised bandwidth
151 only if the consensus does not have bandwidths listed.
157 2.1.0. We don't build circuits until we have enough directory info
159 There's a class of possible attacks where our directory servers
160 only give us information about the relays that they would like us
161 to use. To prevent this attack, we don't build multi-hop
162 circuits for real traffic (like those in 2.1.1, 2.1.2, 2.1.4
163 below) until we have enough directory information to be
164 reasonably confident this attack isn't being done to us.
166 Here, "enough" directory information is defined as:
168 * Having a consensus that's been valid at some point in the
169 last REASONABLY_LIVE_TIME interval (24 hours).
171 * Having enough descriptors that we could build at least some
172 fraction F of all bandwidth-weighted paths, without taking
173 ExitNodes/EntryNodes/etc into account.
175 (F is set by the PathsNeededToBuildCircuits option,
176 defaulting to the 'min_paths_for_circs_pct' consensus
177 parameter, with a final default value of 60%.)
179 * Having enough descriptors that we could build at least some
180 fraction F of all bandwidth-weighted paths, _while_ taking
181 ExitNodes/EntryNodes/etc into account.
185 * Having a descriptor for every one of the first
186 NUM_USABLE_PRIMARY_GUARDS guards among our primary guards. (see
189 We define the "fraction of bandwidth-weighted paths" as the product of
190 these three fractions.
192 * The fraction of descriptors that we have for nodes with the Guard
193 flag, weighted by their bandwidth for the guard position.
194 * The fraction of descriptors that we have for all nodes,
195 weighted by their bandwidth for the middle position.
196 * The fraction of descriptors that we have for nodes with the Exit
197 flag, weighted by their bandwidth for the exit position.
199 If the consensus has zero weighted bandwidth for a given kind of
200 relay (Guard, Middle, or Exit), Tor instead uses the fraction of relays
201 for which it has the descriptor (not weighted by bandwidth at all).
203 If the consensus lists zero exit-flagged relays, Tor instead uses the
204 fraction of middle relays.
207 2.1.1. Clients build circuits preemptively
209 When running as a client, Tor tries to maintain at least a certain
210 number of clean circuits, so that new streams can be handled
211 quickly. To increase the likelihood of success, Tor tries to
212 predict what circuits will be useful by choosing from among nodes
213 that support the ports we have used in the recent past (by default
214 one hour). Specifically, on startup Tor tries to maintain one clean
215 fast exit circuit that allows connections to port 80, and at least
216 two fast clean stable internal circuits in case we get a resolve
217 request or hidden service request (at least three if we _run_ a
220 After that, Tor will adapt the circuits that it preemptively builds
221 based on the requests it sees from the user: it tries to have two fast
222 clean exit circuits available for every port seen within the past hour
223 (each circuit can be adequate for many predicted ports -- it doesn't
224 need two separate circuits for each port), and it tries to have the
225 above internal circuits available if we've seen resolves or hidden
226 service activity within the past hour. If there are 12 or more clean
227 circuits open, it doesn't open more even if it has more predictions.
229 Only stable circuits can "cover" a port that is listed in the
230 LongLivedPorts config option. Similarly, hidden service requests
231 to ports listed in LongLivedPorts make us create stable internal
234 Note that if there are no requests from the user for an hour, Tor
235 will predict no use and build no preemptive circuits.
237 The Tor client SHOULD NOT store its list of predicted requests to a
240 2.1.2. Clients build circuits on demand
242 Additionally, when a client request exists that no circuit (built or
243 pending) might support, we create a new circuit to support the request.
244 For exit connections, we pick an exit node that will handle the
245 most pending requests (choosing arbitrarily among ties), launch a
246 circuit to end there, and repeat until every unattached request
247 might be supported by a pending or built circuit. For internal
248 circuits, we pick an arbitrary acceptable path, repeating as needed.
250 Clients consider a circuit to become "dirty" as soon as a stream is
251 attached to it, or some other request is performed over the circuit.
252 If a circuit has been "dirty" for at least MaxCircuitDirtiness seconds,
253 new circuits may not be attached to it.
255 In some cases we can reuse an already established circuit if it's
256 clean; see Section 2.3 (cannibalizing circuits) for details.
258 2.1.3. Relays build circuits for testing reachability and bandwidth
260 Tor relays test reachability of their ORPort once they have
261 successfully built a circuit (on startup and whenever their IP address
262 changes). They build an ordinary fast internal circuit with themselves
263 as the last hop. As soon as any testing circuit succeeds, the Tor
264 relay decides it's reachable and is willing to publish a descriptor.
266 We launch multiple testing circuits (one at a time), until we
267 have NUM_PARALLEL_TESTING_CIRC (4) such circuits open. Then we
268 do a "bandwidth test" by sending a certain number of relay drop
269 cells down each circuit: BandwidthRate * 10 / CELL_NETWORK_SIZE
270 total cells divided across the four circuits, but never more than
271 CIRCWINDOW_START (1000) cells total. This exercises both outgoing and
272 incoming bandwidth, and helps to jumpstart the observed bandwidth
275 Tor relays also test reachability of their DirPort once they have
276 established a circuit, but they use an ordinary exit circuit for
279 2.1.4. Hidden-service circuits
283 2.1.5. Rate limiting of failed circuits
285 If we fail to build a circuit N times in a X second period (see Section
286 2.3 for how this works), we stop building circuits until the X seconds
290 2.1.6. When to tear down circuits
292 Clients should tear down circuits (in general) only when those circuits
293 have no streams on them. Additionally, clients should tear-down
294 stream-less circuits only under one of the following conditions:
296 - The circuit has never had a stream attached, and it was created too
297 long in the past (based on CircuitsAvailableTimeout or
298 cbtlearntimeout, depending on timeout estimate status).
300 - The circuit is dirty (has had a stream attached), and it has been
301 dirty for at least MaxCircuitDirtiness.
303 2.2. Path selection and constraints
305 We choose the path for each new circuit before we build it. We choose the
306 exit node first, followed by the other nodes in the circuit, front to
307 back. (In other words, for a 3-hop circuit, we first pick hop 3,
308 then hop 1, then hop 2.) All paths we generate obey the following
311 - We do not choose the same router twice for the same path.
312 - We do not choose any router in the same family as another in the same
313 path. (Two routers are in the same family if each one lists the other
314 in the "family" entries of its descriptor.)
315 - We do not choose more than one router in a given /16 subnet
316 (unless EnforceDistinctSubnets is 0).
317 - We don't choose any non-running or non-valid router unless we have
318 been configured to do so. By default, we are configured to allow
319 non-valid routers in "middle" and "rendezvous" positions.
320 - If we're using Guard nodes, the first node must be a Guard (see 5
322 - XXXX Choosing the length
324 For "fast" circuits, we only choose nodes with the Fast flag. For
325 non-"fast" circuits, all nodes are eligible.
327 For all circuits, we weight node selection according to router bandwidth.
329 We also weight the bandwidth of Exit and Guard flagged nodes depending on
330 the fraction of total bandwidth that they make up and depending upon the
331 position they are being selected for.
333 These weights are published in the consensus, and are computed as described
334 in Section "Computing Bandwidth Weights" of dir-spec.txt. They are:
336 Wgg - Weight for Guard-flagged nodes in the guard position
337 Wgm - Weight for non-flagged nodes in the guard Position
338 Wgd - Weight for Guard+Exit-flagged nodes in the guard Position
340 Wmg - Weight for Guard-flagged nodes in the middle Position
341 Wmm - Weight for non-flagged nodes in the middle Position
342 Wme - Weight for Exit-flagged nodes in the middle Position
343 Wmd - Weight for Guard+Exit flagged nodes in the middle Position
345 Weg - Weight for Guard flagged nodes in the exit Position
346 Wem - Weight for non-flagged nodes in the exit Position
347 Wee - Weight for Exit-flagged nodes in the exit Position
348 Wed - Weight for Guard+Exit-flagged nodes in the exit Position
350 Wgb - Weight for BEGIN_DIR-supporting Guard-flagged nodes
351 Wmb - Weight for BEGIN_DIR-supporting non-flagged nodes
352 Web - Weight for BEGIN_DIR-supporting Exit-flagged nodes
353 Wdb - Weight for BEGIN_DIR-supporting Guard+Exit-flagged nodes
355 Wbg - Weight for Guard+Exit-flagged nodes for BEGIN_DIR requests
356 Wbm - Weight for Guard+Exit-flagged nodes for BEGIN_DIR requests
357 Wbe - Weight for Guard+Exit-flagged nodes for BEGIN_DIR requests
358 Wbd - Weight for Guard+Exit-flagged nodes for BEGIN_DIR requests
360 If any of those weights is malformed or not present in a consensus,
361 clients proceed with the regular path selection algorithm setting
362 the weights to the default value of 10000.
364 Additionally, we may be building circuits with one or more requests in
365 mind. Each kind of request puts certain constraints on paths:
367 - All service-side introduction circuits and all rendezvous paths
369 - All connection requests for connections that we think will need to
370 stay open a long time require Stable circuits. Currently, Tor decides
371 this by examining the request's target port, and comparing it to a
372 list of "long-lived" ports. (Default: 21, 22, 706, 1863, 5050,
373 5190, 5222, 5223, 6667, 6697, 8300.)
374 - DNS resolves require an exit node whose exit policy is not equivalent
376 - Reverse DNS resolves require a version of Tor with advertised eventdns
377 support (available in Tor 0.1.2.1-alpha-dev and later).
378 - All connection requests require an exit node whose exit policy
379 supports their target address and port (if known), or which "might
380 support it" (if the address isn't known). See 2.2.1.
381 - Rules for Fast? XXXXX
383 2.2.1. Choosing an exit
385 If we know what IP address we want to connect to or resolve, we can
386 trivially tell whether a given router will support it by simulating
387 its declared exit policy.
389 Because we often connect to addresses of the form hostname:port, we do not
390 always know the target IP address when we select an exit node. In these
391 cases, we need to pick an exit node that "might support" connections to a
392 given address port with an unknown address. An exit node "might support"
393 such a connection if any clause that accepts any connections to that port
394 precedes all clauses (if any) that reject all connections to that port.
396 Unless requested to do so by the user, we never choose an exit node
397 flagged as "BadExit" by more than half of the authorities who advertise
398 themselves as listing bad exits.
400 2.2.2. User configuration
402 Users can alter the default behavior for path selection with configuration
405 - If "ExitNodes" is provided, then every request requires an exit node on
406 the ExitNodes list. (If a request is supported by no nodes on that list,
407 and StrictExitNodes is false, then Tor treats that request as if
408 ExitNodes were not provided.)
410 - "EntryNodes" and "StrictEntryNodes" behave analogously.
412 - If a user tries to connect to or resolve a hostname of the form
413 <target>.<servername>.exit, the request is rewritten to a request for
414 <target>, and the request is only supported by the exit whose nickname
415 or fingerprint is <servername>.
417 - When set, "HSLayer2Nodes" and "HSLayer3Nodes" relax Tor's path
418 restrictions to allow nodes in the same /16 and node family to reappear
419 in the path. They also allow the guard node to be chosen as the RP, IP,
420 and HSDIR, and as the hop before those positions.
422 2.3. Cannibalizing circuits
424 If we need a circuit and have a clean one already established, in
425 some cases we can adapt the clean circuit for our new
426 purpose. Specifically,
428 For hidden service interactions, we can "cannibalize" a clean internal
429 circuit if one is available, so we don't need to build those circuits
430 from scratch on demand.
432 We can also cannibalize clean circuits when the client asks to exit
433 at a given node -- either via the ".exit" notation or because the
434 destination is running at the same location as an exit node.
436 2.4. Learning when to give up ("timeout") on circuit construction
438 Since version 0.2.2.8-alpha, Tor clients attempt to learn when to give
439 up on circuits based on network conditions.
441 2.4.1. Distribution choice
443 Based on studies of build times, we found that the distribution of
444 circuit build times appears to be a Frechet distribution (and a multi-modal
445 Frechet distribution, if more than one guard or bridge is used). However,
446 estimators and quantile functions of the Frechet distribution are difficult
447 to work with and slow to converge. So instead, since we are only interested
448 in the accuracy of the tail, clients approximate the tail of the multi-modal
449 distribution with a single Pareto curve.
451 2.4.2. How much data to record
453 From our observations, the minimum number of circuit build times for a
454 reasonable fit appears to be on the order of 100. However, to keep a
455 good fit over the long term, clients store 1000 most recent circuit build
456 times in a circular array.
458 These build times only include the times required to build three-hop
459 circuits, and the times required to build the first three hops of circuits
460 with more than three hops. Circuits of fewer than three hops are not
461 recorded, and hops past the third are not recorded.
463 The Tor client should build test circuits at a rate of one every 'cbttestfreq'
464 (10 seconds) until 'cbtmincircs' (100 circuits) are built, with a maximum of
465 'cbtmaxopencircs' (default: 10) circuits open at once. This allows a fresh
466 Tor to have a CircuitBuildTimeout estimated within 30 minutes after install
467 or network change (see section 2.4.5 below).
469 Timeouts are stored on disk in a histogram of 10ms bin width, the same
470 width used to calculate the Xm value above. The timeouts recorded in the
471 histogram must be shuffled after being read from disk, to preserve a
472 proper expiration of old values after restart.
474 Thus, some build time resolution is lost during restart. Implementations may
475 choose a different persistence mechanism than this histogram, but be aware
476 that build time binning is still needed for parameter estimation.
478 2.4.3. Parameter estimation
480 Once 'cbtmincircs' build times are recorded, Tor clients update the
481 distribution parameters and recompute the timeout every circuit completion
482 (though see section 2.4.5 for when to pause and reset timeout due to
483 too many circuits timing out).
485 Tor clients calculate the parameters for a Pareto distribution fitting the
486 data using the maximum likelihood estimator. For derivation, see:
487 https://en.wikipedia.org/wiki/Pareto_distribution#Estimation_of_parameters
489 Because build times are not a true Pareto distribution, we alter how Xm is
490 computed. In a max likelihood estimator, the mode of the distribution is
493 Instead of using the mode of discrete build times directly, Tor clients
494 compute the Xm parameter using the weighted average of the midpoints
495 of the 'cbtnummodes' (10) most frequently occurring 10ms histogram bins.
496 Ties are broken in favor of earlier bins (that is, in favor of bins
497 corresponding to shorter build times).
499 (The use of 10 modes was found to minimize error from the selected
500 cbtquantile, with 10ms bins for quantiles 60-80, compared to many other
503 To avoid ln(1.0+epsilon) precision issues, use log laws to rewrite the
504 estimator for 'alpha' as the sum of logs followed by subtraction, rather
505 than multiplication and division:
507 alpha = n/(Sum_n{ln(MAX(Xm, x_i))} - n*ln(Xm))
509 In this, n is the total number of build times that have completed, x_i is
510 the ith recorded build time, and Xm is the modes of x_i as above.
512 All times below Xm are counted as having the Xm value via the MAX(),
513 because in Pareto estimators, Xm is supposed to be the lowest value.
514 However, since clients use mode averaging to estimate Xm, there can be
515 values below our Xm. Effectively, the Pareto estimator then treats that
516 everything smaller than Xm happened at Xm. One can also see that if
517 clients did not do this, alpha could underflow to become negative, which
518 results in an exponential curve, not a Pareto probability distribution.
520 The timeout itself is calculated by using the Pareto Quantile function (the
521 inverted CDF) to give us the value on the CDF such that 80% of the mass
522 of the distribution is below the timeout value (parameter 'cbtquantile').
524 The Pareto Quantile Function (inverse CDF) is:
526 F(q) = Xm/((1.0-q)^(1.0/alpha))
528 Thus, clients obtain the circuit build timeout for 3-hop circuits by
531 timeout_ms = F(0.8) # 'cbtquantile' == 0.8
533 With this, we expect that the Tor client will accept the fastest 80% of the
534 total number of paths on the network.
536 Clients obtain the circuit close time to completely abandon circuits as:
538 close_ms = F(0.99) # 'cbtclosequantile' == 0.99
540 To avoid waiting an unreasonably long period of time for circuits that
541 simply have relays that are down, Tor clients cap timeout_ms at the max
542 build time actually observed so far, and cap close_ms at twice this max,
543 but at least 60 seconds:
545 timeout_ms = MIN(timeout_ms, max_observed_timeout)
546 close_ms = MAX(MIN(close_ms, 2*max_observed_timeout), 'cbtinitialtimeout')
548 2.4.3. Calculating timeouts thresholds for circuits of different lengths
550 The timeout_ms and close_ms estimates above are good only for 3-hop
551 circuits, since only 3-hop circuits are recorded in the list of build
554 To calculate the appropriate timeouts and close timeouts for circuits of
555 other lengths, the client multiples the timeout_ms and close_ms values
556 by a scaling factor determined by the number of communication hops
557 needed to build their circuits:
559 timeout_ms[hops=n] = timeout_ms * Actions(N) / Actions(3)
561 close_ms[hops=n] = close_ms * Actions(N) / Actions(3)
563 where Actions(N) = N * (N + 1) / 2.
565 To calculate timeouts for operations other than circuit building,
566 the client should add X to Actions(N) for every round-trip communication
567 required with the Xth hop.
569 2.4.4. How to record timeouts
571 Pareto estimators begin to lose their accuracy if the tail is omitted.
572 Hence, Tor clients actually calculate two timeouts: a usage timeout, and a
575 Circuits that pass the usage timeout are marked as measurement circuits,
576 and are allowed to continue to build until the close timeout corresponding
577 to the point 'cbtclosequantile' (default 99) on the Pareto curve, or 60
578 seconds, whichever is greater.
580 The actual completion times for these measurement circuits should be
583 Implementations should completely abandon a circuit and ignore the circuit
584 if the total build time exceeds the close threshold. Such closed circuits
585 should be ignored, as this typically means one of the relays in the path is
588 2.4.5. Detecting Changing Network Conditions
590 Tor clients attempt to detect both network connectivity loss and drastic
591 changes in the timeout characteristics.
593 To detect changing network conditions, clients keep a history of
594 the timeout or non-timeout status of the past 'cbtrecentcount' circuits
595 (20 circuits) that successfully completed at least one hop. If more than
596 90% of these circuits timeout, the client discards all buildtimes history,
597 resets the timeout to 'cbtinitialtimeout' (60 seconds), and then begins
598 recomputing the timeout.
600 If the timeout was already at least `cbtinitialtimeout`,
601 the client doubles the timeout.
603 The records here (of how many circuits succeeded or failed among the most
604 recent 'cbrrecentcount') are not stored as persistent state. On reload,
605 we start with a new, empty state.
607 2.4.6. Consensus parameters governing behavior
609 Clients that implement circuit build timeout learning should obey the
610 following consensus parameters that govern behavior, in order to allow
611 us to handle bugs or other emergent behaviors due to client circuit
612 construction. If these parameters are not present in the consensus,
613 the listed default values should be used instead.
619 Effect: If 1, all CircuitBuildTime learning code should be
620 disabled and history should be discarded. For use in
621 emergency situations only.
627 Effect: This value governs how many modes to use in the weighted
628 average calculation of Pareto parameter Xm. Selecting Xm as the
629 average of multiple modes improves accuracy of the Pareto tail
630 for quantile cutoffs from 60-80% (see cbtquantile).
636 Effect: This is the number of circuit build outcomes (success vs
637 timeout) to keep track of for the following option.
643 Effect: When this many timeouts happen in the last 'cbtrecentcount'
644 circuit attempts, the client should discard all of its
645 history and begin learning a fresh timeout value.
647 Note that if this parameter's value is greater than the value
648 of 'cbtrecentcount', then the history will never be
649 discarded because of this feature.
655 Effect: This is the minimum number of circuits to build before
658 Note that if this parameter's value is higher than 1000 (the
659 number of time observations that a client keeps in its
660 circular buffer), circuit build timeout calculation is
661 effectively disabled, and the default timeouts are used
668 Effect: This is the position on the quantile curve to use to set the
669 timeout value. It is a percent (10-99).
673 Min: Value of cbtquantile parameter
675 Effect: This is the position on the quantile curve to use to set the
676 timeout value to use to actually close circuits. It is a
682 Max: 2147483647 (INT32_MAX)
683 Effect: Describes how often in seconds to build a test circuit to
684 gather timeout values. Only applies if less than 'cbtmincircs'
690 Max: 2147483647 (INT32_MAX)
691 Effect: This is the minimum allowed timeout value in milliseconds.
695 Min: Value of cbtmintimeout
696 Max: 2147483647 (INT32_MAX)
697 Effect: This is the timeout value to use before we have enough data
698 to compute a timeout, in milliseconds. If we do not have
699 enough data to compute a timeout estimate (see cbtmincircs),
700 then we use this interval both for the close timeout and the
707 Effect: This is how long idle circuits will be kept open while cbt is
708 learning a new timeout value.
714 Effect: This is the maximum number of circuits that can be open at
715 at the same time during the circuit build time learning phase.
717 2.5. Handling failure
719 If an attempt to extend a circuit fails (either because the first create
720 failed or a subsequent extend failed) then the circuit is torn down and is
721 no longer pending. (XXXX really?) Requests that might have been
722 supported by the pending circuit thus become unsupported, and a new
723 circuit needs to be constructed.
725 If a stream "begin" attempt fails with an EXITPOLICY error, we
726 decide that the exit node's exit policy is not correctly advertised,
727 so we treat the exit node as if it were a non-exit until we retrieve
728 a fresh descriptor for it.
730 Excessive amounts of either type of failure can indicate an
731 attack on anonymity. See section 7 for how excessive failure is handled.
733 3. Attaching streams to circuits
735 When a circuit that might support a request is built, Tor tries to attach
736 the request's stream to the circuit and sends a BEGIN, BEGIN_DIR,
738 cell as appropriate. If the request completes unsuccessfully, Tor
739 considers the reason given in the CLOSE relay cell. [XXX yes, and?]
742 After a request has remained unattached for SocksTimeout (2 minutes
743 by default), Tor abandons the attempt and signals an error to the
744 client as appropriate (e.g., by closing the SOCKS connection).
746 XXX Timeouts and when Tor auto-retries.
748 * What stream-end-reasons are appropriate for retrying.
750 If no reply to BEGIN/RESOLVE, then the stream will timeout and fail.
752 4. Hidden-service related circuits
754 XXX Tracking expected hidden service use (client-side and hidserv-side)
758 We use Guard nodes (also called "helper nodes" in the research
759 literature) to prevent certain profiling attacks. For an overview of
760 our Guard selection algorithm -- which has grown rather complex -- see
763 5.1. How consensus bandwidth weights factor into entry guard selection
765 When weighting a list of routers for choosing an entry guard, the following
766 consensus parameters (from the "bandwidth-weights" line) apply:
768 Wgg - Weight for Guard-flagged nodes in the guard position
769 Wgm - Weight for non-flagged nodes in the guard Position
770 Wgd - Weight for Guard+Exit-flagged nodes in the guard Position
771 Wgb - Weight for BEGIN_DIR-supporting Guard-flagged nodes
772 Wmb - Weight for BEGIN_DIR-supporting non-flagged nodes
773 Web - Weight for BEGIN_DIR-supporting Exit-flagged nodes
774 Wdb - Weight for BEGIN_DIR-supporting Guard+Exit-flagged nodes
776 Please see "bandwidth-weights" in ยง3.4.1 of dir-spec.txt for more in depth
777 descriptions of these parameters.
779 If a router has been marked as both an entry guard and an exit, then we
780 prefer to use it more, with our preference for doing so (roughly) linearly
781 increasing w.r.t. the router's non-guard bandwidth and bandwidth weight
782 (calculated without taking the guard flag into account). From proposal
786 | Let Wpf denote the weight from the 'bandwidth-weights' line a
787 | client would apply to N for position p if it had the guard
788 | flag, Wpn the weight if it did not have the guard flag, and B the
789 | measured bandwidth of N in the consensus. Then instead of choosing
790 | N for position p proportionally to Wpf*B or Wpn*B, clients should
791 | choose N proportionally to F*Wpf*B + (1-F)*Wpn*B.
793 where F is the weight as calculated using the above parameters.
795 6. Server descriptor purposes
797 There are currently three "purposes" supported for server descriptors:
798 general, controller, and bridge. Most descriptors are of type general
799 -- these are the ones listed in the consensus, and the ones fetched
800 and used in normal cases.
802 Controller-purpose descriptors are those delivered by the controller
803 and labelled as such: they will be kept around (and expire like
804 normal descriptors), and they can be used by the controller in its
805 CIRCUITEXTEND commands. Otherwise they are ignored by Tor when it
808 Bridge-purpose descriptors are for routers that are used as bridges. See
809 doc/design-paper/blocking.pdf for more design explanation, or proposal
810 125 for specific details. Currently bridge descriptors are used in place
811 of normal entry guards, for Tor clients that have UseBridges enabled.
813 7. Detecting route manipulation by Guard nodes (Path Bias)
815 The Path Bias defense is designed to defend against a type of route
816 capture where malicious Guard nodes deliberately fail or choke circuits
817 that extend to non-colluding Exit nodes to maximize their network
818 utilization in favor of carrying only compromised traffic.
820 In the extreme, the attack allows an adversary that carries c/n
821 of the network capacity to deanonymize c/n of the network
822 connections, breaking the O((c/n)^2) property of Tor's original
823 threat model. It also allows targeted attacks aimed at monitoring
824 the activity of specific users, bridges, or Guard nodes.
826 There are two points where path selection can be manipulated:
827 during construction, and during usage. Circuit construction
828 can be manipulated by inducing circuit failures during circuit
829 extend steps, which causes the Tor client to transparently retry
830 the circuit construction with a new path. Circuit usage can be
831 manipulated by abusing the stream retry features of Tor (for
832 example by withholding stream attempt responses from the client
833 until the stream timeout has expired), at which point the tor client
834 will also transparently retry the stream on a new path.
836 The defense as deployed therefore makes two independent sets of
837 measurements of successful path use: one during circuit construction,
838 and one during circuit usage.
840 The intended behavior is for clients to ultimately disable the use
841 of Guards responsible for excessive circuit failure of either type
842 (see section 7.4); however known issues with the Tor network currently
843 restrict the defense to being informational only at this stage (see
846 7.1. Measuring path construction success rates
848 Clients maintain two counts for each of their guards: a count of the
849 number of times a circuit was extended to at least two hops through that
850 guard, and a count of the number of circuits that successfully complete
851 through that guard. The ratio of these two numbers is used to determine
852 a circuit success rate for that Guard.
854 Circuit build timeouts are counted as construction failures if the
855 circuit fails to complete before the 95% "right-censored" timeout
856 interval, not the 80% timeout condition (see section 2.4).
858 If a circuit closes prematurely after construction but before being
859 requested to close by the client, this is counted as a failure.
861 7.2. Measuring path usage success rates
863 Clients maintain two usage counts for each of their guards: a count
864 of the number of usage attempts, and a count of the number of
867 A usage attempt means any attempt to attach a stream to a circuit.
869 Usage success status is temporarily recorded by state flags on circuits.
870 Guard usage success counts are not incremented until circuit close. A
871 circuit is marked as successfully used if we receive a properly
872 recognized RELAY cell on that circuit that was expected for the current
875 If subsequent stream attachments fail or time out, the successfully used
876 state of the circuit is cleared, causing it once again to be regarded
877 as a usage attempt only.
879 Upon close by the client, all circuits that are still marked as usage
880 attempts are probed using a RELAY_BEGIN cell constructed with a
881 destination of the form 0.a.b.c:25, where a.b.c is a 24 bit random
882 nonce. If we get a RELAY_COMMAND_END in response matching our nonce,
883 the circuit is counted as successfully used.
885 If any unrecognized RELAY cells arrive after the probe has been sent,
886 the circuit is counted as a usage failure.
888 If the stream failure reason codes DESTROY, TORPROTOCOL, or INTERNAL
889 are received in response to any stream attempt, such circuits are not
890 probed and are declared usage failures.
892 Prematurely closed circuits are not probed, and are counted as usage
895 7.3. Scaling success counts
897 To provide a moving average of recent Guard activity while
898 still preserving the ability to verify correctness, we periodically
899 "scale" the success counts by multiplying them by a scale factor
902 Scaling is performed when either usage or construction attempt counts
903 exceed a parametrized value.
905 To avoid error due to scaling during circuit construction and use,
906 currently open circuits are subtracted from the usage counts before
907 scaling, and added back after scaling.
911 The following consensus parameters tune various aspects of the
917 Effect: This is the minimum number of circuits that must complete
918 at least 2 hops before we begin evaluating construction rates.
925 Effect: If the circuit success rate falls below this percentage,
926 we emit a notice log message.
932 Effect: If the circuit success rate falls below this percentage,
933 we emit a warn log message.
939 Effect: If the circuit success rate falls below this percentage,
940 we emit a more alarmist warning log message. If
941 pb_dropguard is set to 1, we also disable the use of the
948 Effect: If the circuit success rate falls below pb_extremepct,
949 when pb_dropguard is set to 1, we disable use of that
955 Effect: After this many circuits have completed at least two hops,
956 Tor performs the scaling described in Section 7.3.
958 pb_multfactor and pb_scalefactor
962 Effect: The double-precision result obtained from
963 pb_multfactor/pb_scalefactor is multiplied by our current
964 counts to scale them.
969 Effect: This is the minimum number of circuits that we must attempt to
970 use before we begin evaluating construction rates.
975 Effect: If the circuit usage success rate falls below this percentage,
976 we emit a notice log message.
981 Effect: If the circuit usage success rate falls below this percentage,
982 we emit a warning log message. We also disable the use of the
983 guard if pb_dropguards is set.
988 Effect: After we have attempted to use this many circuits,
989 Tor performs the scaling described in Section 7.3.
991 7.5. Known barriers to enforcement
993 Due to intermittent CPU overload at relays, the normal rate of
994 successful circuit completion is highly variable. The Guard-dropping
995 version of the defense is unlikely to be deployed until the ntor
996 circuit handshake is enabled, or the nature of CPU overload induced
997 failure is better understood.
1003 X.1. Do we actually do this?
1005 How to deal with network down.
1006 - While all helpers are down/unreachable and there are no established
1007 or on-the-way testing circuits, launch a testing circuit. (Do this
1008 periodically in the same way we try to establish normal circuits
1009 when things are working normally.)
1010 (Testing circuits are a special type of circuit, that streams won't
1011 attach to by accident.)
1012 - When a testing circuit succeeds, mark all helpers up and hold
1013 the testing circuit open.
1014 - If a connection to a helper succeeds, close all testing circuits.
1015 Else mark that helper down and try another.
1016 - If the last helper is marked down and we already have a testing
1017 circuit established, then add the first hop of that testing circuit
1018 to the end of our helper node list, close that testing circuit,
1019 and go back to square one. (Actually, rather than closing the
1020 testing circuit, can we get away with converting it to a normal
1021 circuit and beginning to use it immediately?)
1023 [Do we actually do any of the above? If so, let's spec it. If not, let's
1026 X.2. A thing we could do to deal with reachability.
1028 And as a bonus, it leads to an answer to Nick's attack ("If I pick
1029 my helper nodes all on 18.0.0.0:*, then I move, you'll know where I
1030 bootstrapped") -- the answer is to pick your original three helper nodes
1031 without regard for reachability. Then the above algorithm will add some
1032 more that are reachable for you, and if you move somewhere, it's more
1033 likely (though not certain) that some of the originals will become useful.
1034 Is that smart or just complex?
1036 X.3. Some stuff that worries me about entry guards. 2006 Jun, Nickm.
1038 It is unlikely for two users to have the same set of entry guards.
1039 Observing a user is sufficient to learn its entry guards. So, as we move
1040 around, entry guards make us linkable. If we want to change guards when
1041 our location (IP? subnet?) changes, we have two bad options. We could
1043 - Drop the old guards. But if we go back to our old location,
1044 we'll not use our old guards. For a laptop that sometimes gets used
1045 from work and sometimes from home, this is pretty fatal.
1046 - Remember the old guards as associated with the old location, and use
1047 them again if we ever go back to the old location. This would be
1048 nasty, since it would force us to record where we've been.
1050 [Do we do any of this now? If not, this should move into 099-misc or