140-consensus-diffs.txt 5.2 KB

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