140-consensus-diffs.txt 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. Filename: 140-consensus-diffs.txt
  2. Title: Provide diffs between consensuses
  3. Author: Peter Palfrader
  4. Created: 13-Jun-2008
  5. Status: Accepted
  6. Target: 0.2.2.x
  7. 1. Overview.
  8. Tor clients and servers need a list of which relays are on the
  9. network. This list, the consensus, is created by authorities
  10. hourly and clients fetch a copy of it, with some delay, hourly.
  11. This proposal suggests that clients download diffs of consensuses
  12. once they have a consensus instead of hourly downloading a full
  13. consensus.
  14. 2. Numbers
  15. After implementing proposal 138 which removes nodes that are not
  16. running from the list a consensus document is about 92 kilobytes
  17. in size after compression.
  18. The diff between two consecutive consensus, in ed format, is on
  19. average 13 kilobytes compressed.
  20. 3. Proposal
  21. 3.1 Clients
  22. If a client has a consensus that is recent enough it SHOULD
  23. try to download a diff to get the latest consensus rather than
  24. fetching a full one.
  25. [XXX: what is recent enough?
  26. time delta in hours / size of compressed diff
  27. 0 20
  28. 1 9650
  29. 2 17011
  30. 3 23150
  31. 4 29813
  32. 5 36079
  33. 6 39455
  34. 7 43903
  35. 8 48907
  36. 9 54549
  37. 10 60057
  38. 11 67810
  39. 12 71171
  40. 13 73863
  41. 14 76048
  42. 15 80031
  43. 16 84686
  44. 17 89862
  45. 18 94760
  46. 19 94868
  47. 20 94223
  48. 21 93921
  49. 22 92144
  50. 23 90228
  51. [ size of gzip compressed "diff -e" between the consensus on
  52. 2008-06-01-00:00:00 and the following consensuses that day.
  53. Consensuses have been modified to exclude down routers per
  54. proposal 138. ]
  55. Data suggests that for the first few hours diffs are very useful,
  56. saving about 60% for the first three hours, 30% for the first 10,
  57. and almost nothing once we are past 16 hours.
  58. ]
  59. 3.2 Servers
  60. Directory authorities and servers need to keep up to X [XXX: depends
  61. on how long clients try to download diffs per above] old consensus
  62. documents so they can build diffs. They should offer a diff to the
  63. most recent consensus at the URL
  64. http://tor.noreply.org/tor/status-vote/current/consensus/diff/<HASH>/<FPRLIST>
  65. where hash is the full digest of the consensus the client currently
  66. has, and FPRLIST is a list of (abbreviated) fingerprints of
  67. authorities the client trusts.
  68. Servers will only return a consensus if more than half of the requested
  69. authorities have signed the document, otherwise a 404 error will be sent
  70. back. The fingerprints can be shortened to a length of any multiple of
  71. two, using only the leftmost part of the encoded fingerprint. Tor uses
  72. 3 bytes (6 hex characters) of the fingerprint. (This is just like the
  73. conditional consensus downloads that Tor supports starting with
  74. 0.1.2.1-alpha.)
  75. If a server cannot offer a diff from the consensus identified by the
  76. hash but has a current consensus it MUST return the full consensus.
  77. [XXX: what should we do when the client already has the latest
  78. consensus? I can think of the following options:
  79. - send back 3xx not modified
  80. - send back 200 ok and an empty diff
  81. - send back 404 nothing newer here.
  82. I currently lean towards the empty diff.]
  83. 4. Diff Format
  84. Diffs start with the token "network-status-diff-version" followed by a
  85. space and the version number, currently "1".
  86. If a document does not start with network-status-diff it is assumed
  87. to be a full consensus download and would therefore currently start
  88. with "network-status-version 3".
  89. Following the network-status-diff header line is a diff, or patch, in
  90. limited ed format. We choose this format because it is easy to create
  91. and process with standard tools (patch, diff -e, ed). This will help
  92. us in developing and testing this proposal and it should make future
  93. debugging easier.
  94. [ If at one point in the future we decide that the space benefits from
  95. a custom diff format outweighs these benefits we can always
  96. introduce a new diff format and offer it at for instance
  97. ../diff2/... ]
  98. We support the following ed commands, each on a line by itself:
  99. - "<n1>d" Delete line n1
  100. - "<n1>,<n2>d" Delete lines n1 through n2, including
  101. - "<n1>c" Replace line n1 with the following block
  102. - "<n1>,<n2>c" Replace lines n1 through n2, including, with the
  103. following block.
  104. - "<n1>a" Append the following block after line n1.
  105. - "a" Append the following block after the current line.
  106. - "s/.//" Remove the first character in the current line.
  107. Note that line numbers always apply to the file after all previous
  108. commands have already been applied.
  109. The "current line" is either the first line of the file, if this is
  110. the first command, the last line of a block we added in an append or
  111. change command, or the line immediate following a set of lines we just
  112. deleted (or the last line of the file if there are no lines after
  113. that).
  114. The replace and append command take blocks. These blocks are simply
  115. appended to the diff after the line with the command. A line with
  116. just a period (".") ends the block (and is not part of the lines
  117. to add). Note that it is impossible to insert a line with just
  118. a single dot. Recommended procedure is to insert a line with
  119. two dots, then remove the first character of that line using s/.//.