140-consensus-diffs.txt 5.2 KB

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