path-spec.txt 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. $Id$
  2. Tor Path Specification
  3. Roger Dingledine
  4. Nick Mathewson
  5. Note: This is an attempt to specify Tor as currently implemented. Future
  6. versions of Tor will implement improved algorithms.
  7. This document tries to cover how Tor chooses to build circuits and assign
  8. streams to circuits. Other implementations MAY take other approaches, but
  9. implementors should be aware of the anonymity and load-balancing implications
  10. of their choices.
  11. THIS SPEC ISN'T DONE OR CORRECT. I'm just copying in relevant info so
  12. far. The starred points are things we should cover, but not an exhaustive
  13. list. -NM
  14. 1. General operation
  15. * We build some circuits preemptively, and some on-demand.
  16. * We attach greedily, and expire after time.
  17. 2. Building circuits
  18. * Preemptive building
  19. * On-demand building
  20. * Choosing the path first, building second.
  21. * Choosing the length of the circuit.
  22. * Choosing entries, midpoints, exits.
  23. * What to do when an extend fails
  24. * Keeping track of 'expected' ports
  25. * Backing off from circuit building when a long time has passed
  26. *
  27. 3. Attaching streams to circuits
  28. 4. Rendezvous circuits
  29. 5. Guard nodes
  30. (From some emails by arma)
  31. Hi folks,
  32. I've gotten the codebase to the point that I'm going to start trying
  33. to make helper nodes work well. With luck they will be on by default in
  34. the final 0.1.1.x release.
  35. For background on helper nodes, read
  36. http://wiki.noreply.org/noreply/TheOnionRouter/TorFAQ#RestrictedEntry
  37. First order of business: the phrase "helper node" sucks. We always have
  38. to define it after we say it to somebody. Nick likes the phrase "contact
  39. node", because they are your point-of-contact into the network. That is
  40. better than phrases like "bridge node". The phrase "fixed entry node"
  41. doesn't seem to work with non-math people, because they wonder what was
  42. broken about it. I'm sort of partial to the phrase "entry node" or maybe
  43. "restricted entry node". In any case, if you have ideas on names, please
  44. mail me off-list and I'll collate them.
  45. Right now the code exists to pick helper nodes, store our choices to
  46. disk, and use them for our entry nodes. But there are three topics
  47. to tackle before I'm comfortable turning them on by default. First,
  48. how to handle churn: since Tor nodes are not always up, and sometimes
  49. disappear forever, we need a plan for replacing missing helpers in a
  50. safe way. Second, we need a way to distinguish "the network is down"
  51. from "all my helpers are down", also in a safe way. Lastly, we need to
  52. examine the situation where a client picks three crummy helper nodes
  53. and is forever doomed to a lousy Tor experience. Here's my plan:
  54. How to handle churn.
  55. - Keep track of whether you have ever actually established a
  56. connection to each helper. Any helper node in your list that you've
  57. never used is ok to drop immediately. Also, we don't save that
  58. one to disk.
  59. - If all our helpers are down, we need more helper nodes: add a new
  60. one to the *end*of our list. Only remove dead ones when they have
  61. been gone for a very long time (months).
  62. - Pick from the first n (by default 3) helper nodes in your list
  63. that are up (according to the network-statuses) and reachable
  64. (according to your local firewall config).
  65. - This means that order matters when writing/reading them to disk.
  66. How to deal with network down.
  67. - While all helpers are down/unreachable and there are no established
  68. or on-the-way testing circuits, launch a testing circuit. (Do this
  69. periodically in the same way we try to establish normal circuits
  70. when things are working normally.)
  71. (Testing circuits are a special type of circuit, that streams won't
  72. attach to by accident.)
  73. - When a testing circuit succeeds, mark all helpers up and hold
  74. the testing circuit open.
  75. - If a connection to a helper succeeds, close all testing circuits.
  76. Else mark that helper down and try another.
  77. - If the last helper is marked down and we already have a testing
  78. circuit established, then add the first hop of that testing circuit
  79. to the end of our helper node list, close that testing circuit,
  80. and go back to square one. (Actually, rather than closing the
  81. testing circuit, can we get away with converting it to a normal
  82. circuit and beginning to use it immediately?)
  83. How to pick non-sucky helpers.
  84. - When we're picking a new helper nodes, don't use ones which aren't
  85. reachable according to our local ReachableAddresses configuration.
  86. (There's an attack here: if I pick my helper nodes in a very
  87. restrictive environment, say "ReachableAddresses 18.0.0.0/255.0.0.0:*",
  88. then somebody watching me use the network from another location will
  89. guess where I first joined the network. But let's ignore it for now.)
  90. - Right now we choose new helpers just like we'd choose any entry
  91. node: they must be "stable" (claim >1day uptime) and "fast" (advertise
  92. >10kB capacity). In 0.1.1.11-alpha, clients let dirservers define
  93. "stable" and "fast" however they like, and they just believe them.
  94. So the next step is to make them a function of the current network:
  95. e.g. line up all the 'up' nodes in order and declare the top
  96. three-quarter to be stable, fast, etc, as long as they meet some
  97. minimum too.
  98. - If that's not sufficient (it won't be), dirservers should introduce
  99. a new status flag: in additional to "stable" and "fast", we should
  100. also describe certain nodes as "entry", meaning they are suitable
  101. to be chosen as a helper. The first difference would be that we'd
  102. demand the top half rather than the top three-quarters. Another
  103. requirement would be to look at "mean time between returning" to
  104. ensure that these nodes spend most of their time available. (Up for
  105. two days straight, once a month, is not good enough.)
  106. - Lastly, we need a function, given our current set of helpers and a
  107. directory of the rest of the network, that decides when our helper
  108. set has become "too crummy" and we need to add more. For example,
  109. this could be based on currently advertised capacity of each of
  110. our helpers, and it would also be based on the user's preferences
  111. of speed vs. security.
  112. ***
  113. Lasse wrote:
  114. > I am a bit concerned with performance if we are to have e.g. two out of
  115. > three helper nodes down or unreachable. How often should Tor check if
  116. > they are back up and running?
  117. Right now Tor believes a threshold of directory servers when deciding
  118. whether each server is up. When Tor observes a server to be down
  119. (connection failed or building the first hop of the circuit failed),
  120. it marks it as down and doesn't try it again, until it gets a new
  121. network-status from somebody, at which point it takes a new concensus
  122. and marks the appropriate servers as up.
  123. According to sec 5.1 of dir-spec.txt, the client will try to fetch a new
  124. network-status at least every 30 minutes, and more often in certain cases.
  125. With the proposed scheme, we'll also mark all our helpers as up shortly
  126. after the last one is marked down.
  127. > When should there be
  128. > added an extra node to the helper node list? This is kind of an
  129. > important threshold?
  130. I agree, this is an important question. I don't have a good answer yet. Is
  131. it terrible, anonymity-wise, to add a new helper every time only one of
  132. your helpers is up? Notice that I say add rather than replace -- so you'd
  133. only use this fourth helper when one of your main three helpers is down,
  134. and if three of your four are down, you'd add a fifth, but only use it
  135. when two of the first four are down, etc.
  136. In fact, this may be smarter than just picking a random node for your
  137. testing circuit, because if your network goes up and down a lot, then
  138. eventually you have a chance of using any entry node in the network for
  139. your testing circuit.
  140. We have a design choice here. Do we only try to use helpers for the
  141. connections that will have streams on them (revealing our communication
  142. partners), or do we also want to restrict the overall set of nodes that
  143. we'll connect to, to discourage people from enumerating all Tor clients?
  144. I'm increasingly of the belief that we want to hide our presence too,
  145. based on the fact that Steven and George and others keep coming up with
  146. attacks that start with "Assuming we know the set of users".
  147. If so, then here's a revised "How to deal with network down" section:
  148. 1) When a helper is marked down or the helper list shrinks, and as
  149. a result the total number of helpers that are either (up and
  150. reachable) or (reachable but never connected to) is <= 1, then pick
  151. a new helper and add it to the end of the list.
  152. [We count nodes that have never been connected to, since otherwise
  153. we might keep on adding new nodes before trying any of them. By
  154. "reachable" I mean "is allowed by ReachableAddresses".]
  155. 2) When you fail to connect to a helper that has never been connected
  156. to, you remove him from the list right then (and the above rule
  157. might kick in).
  158. 3) When you succeed at connecting to a helper that you've never
  159. connected to before, mark all reachable helpers earlier in the list
  160. as up, and close that circuit.
  161. [We close the circuit, since if the other helpers are now up, we
  162. prefer to use them for circuits that will reveal communication
  163. partners.]
  164. This certainly seems simpler. Are there holes that I'm missing?
  165. > If running from a laptop you will meet different firewall settings, so
  166. > how should Helper Nodes settings keep up with moving from an open
  167. > ReachableAddresses to a FascistFirewall setting after the helper nodes
  168. > have been selected?
  169. I added the word "reachable" to three places in the above list, and I
  170. believe that totally solves this question.
  171. And as a bonus, it leads to an answer to Nick's attack ("If I pick
  172. my helper nodes all on 18.0.0.0:*, then I move, you'll know where I
  173. bootstrapped") -- the answer is to pick your original three helper nodes
  174. without regard for reachability. Then the above algorithm will add some
  175. more that are reachable for you, and if you move somewhere, it's more
  176. likely (though not certain) that some of the originals will become useful.
  177. Is that smart or just complex?
  178. > What happens if(when?) performance of the third node is bad?
  179. My above solution solves this a little bit, in that we always try to
  180. have two nodes available. But what if they are both up but bad? I'm not
  181. sure. As my previous mail said, we need some function, given our list
  182. of helpers and the network directory, that will tell us when we're in a
  183. bad situation. I can imagine some simple versions of this function --
  184. for example, when both our working helpers are in the bottom half of
  185. the nodes, ranked by capacity.
  186. But the hard part: what's the remedy when we decide there's something
  187. to fix? Do we add a third, and now we have two crummy ones and a new
  188. one? Or do we drop one or both of the bad ones?
  189. Perhaps we believe the latest claim from the network-status concensus,
  190. and we count a helper the dirservers believe is crummy as "not worth
  191. trying" (equivalent to "not reachable under our current ReachableAddresses
  192. config") -- and then the above algorithm would end up adding good ones,
  193. but we'd go back to the originals if they resume being acceptable? That's
  194. an appealing design. I wonder if it will cause the typical Tor user to
  195. have a helper node list that comprises most of the network, though. I'm
  196. ok with this.
  197. > Another point you might want to keep in mind, is the possibility to
  198. > reuse the code in order to add a second layer helper node (meaning node
  199. > number two) to "protect" the first layer (node number one) helper nodes.
  200. > These nodes should be tied to each of the first layer nodes. E.g. there
  201. > is one helper node list, as described in your mail, for each of the
  202. > first layer nodes, following their create/destroy.
  203. True. Does that require us to add a fourth hop to our path length,
  204. since the first hop is from a limited set, the second hop is from a
  205. limited set, and the third hop might also be constrained because, say,
  206. we're asking for an unusual exit port?
  207. > Another of the things might worth adding to the to do list is
  208. > localization of server (helper) nodes. Making it possible to pick
  209. > countries/regions where you do (not) want your helper nodes located. (As
  210. > in "HelperNodesLocated us,!eu" etc.) I know this requires the use of
  211. > external data and may not be worth it, but it _could_ be integrated at
  212. > the directory servers only -- adding a list of node IP's and e.g. a
  213. > country/region code to the directory and thus reduce the overhead. (?)
  214. > Maybe extending the Family-term?
  215. I think we are heading towards doing path selection based on geography,
  216. but I don't have a good sense yet of how that will actually turn out --
  217. that is, with what mechanism Tor clients will learn the information they
  218. need. But this seems to be something that is orthogonal to the rest of
  219. this discussion, so I look forward to having somebody else solve it for
  220. us, and fitting it in when it's ready. :)
  221. > And I would like to keep an option to pick the first X helper nodes
  222. > myself and then let Tor extend this list if these nodes are down (like
  223. > EntryNodes in current code). Even if this opens up for some new types of
  224. > "relationship" attacks.
  225. Good idea. Here's how I'd like to name these:
  226. The "EntryNodes" config option is a list of seed helper nodes. When we
  227. read EntryNodes, any node listed in entrynodes but not in the current
  228. helper node list gets *pre*pended to the helper node list.
  229. The "NumEntryNodes" config option (currently called NumHelperNodes)
  230. specifies the number of up, reachable, good-enough helper nodes that
  231. will make up the pool of possible choices for first hop, counted from
  232. the front of the helper node list until we have enough.
  233. The "UseEntryNodes" config option (currently called UseHelperNodes)
  234. tells us to turn on all this helper node behavior. If you set EntryNodes,
  235. then this option is implied.
  236. The "StrictEntryNodes" config option, provided for backward compatibility
  237. and for debugging, means a) we replace the helper node list with the
  238. current EntryNodes list, and b) whenever we would do an operation that
  239. alters the helper node list, we don't. (Yes, this means that if all the
  240. helper nodes are down, we lose until we mark them up again. But this is
  241. how it behaves now.)
  242. > I am sure my next point has been asked before, but what about testing
  243. > the current speed of the connections when looking for new helper nodes,
  244. > not only testing the connectivity? I know this might contribute to a lot
  245. > of overhead in the network, but if this only occur e.g. when using
  246. > helper nodes as a Hidden Service it might not have that large an impact,
  247. > but could help availability for the services?
  248. If we're just going to be testing them when we're first picking them,
  249. then it seems we can do the same thing by letting the directory servers
  250. test them. This has the added benefit that all the (behaving) clients
  251. use the same data, so they don't end up partitioned by a node that
  252. (for example) performs selectively for his victims.
  253. Another idea would be to periodically keep track of what speeds you get
  254. through your helpers, and make decisions from this. The reason we haven't
  255. done this yet is because there are a lot of variables -- perhaps the
  256. web site is slow, perhaps some other node in the path is slow, perhaps
  257. your local network is slow briefly, perhaps you got unlucky, etc. I
  258. believe that over time (assuming the user has roughly the same browsing
  259. habits) all of these would average out and you'd get a usable answer,
  260. but I don't have a good sense of how long it would take to converge,
  261. so I don't know whether this would be worthwhile.
  262. > BTW. I feel confortable with all the terms helper/entry/contact nodes,
  263. > but I think you (the developers) should just pick one and stay with it
  264. > to avoid confusion.
  265. I think I'm going to try to co-opt the term 'Entry' node for this
  266. purpose. We're going to have to keep referring to helper nodes for the
  267. research community for a while though, so they realize that Tor does
  268. more than just let users ask for certain entry nodes.