torrc_format.txt 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. This document specifies the current format and semantics of the torrc
  2. file, as of July 2015. Note that we make no guarantee about the
  3. stability of this format. If you write something designed for strict
  4. compatibility with this document, please expect us to break it sooner or
  5. later.
  6. Yes, some of this is quite stupid. My goal here is to explain what it
  7. does, not what it should do.
  8. - Nick
  9. 1. File Syntax
  10. # A file is interpreted as every Entry in the file, in order.
  11. TorrcFile = Line*
  12. Line = BlankLine | Entry
  13. BlankLine = WS* OptComment LF
  14. | WS* LF
  15. OptComment =
  16. | Comment
  17. Comment = '#' NonLF*
  18. # Each Entry is interpreted as an optional "Magic" flag, a key, and a
  19. # value.
  20. Entry = SP* OptMagic Key (SP+ | '\\' NL SP*)+ Val LF
  21. | SP* OptMagic Key (SP* | '\\' NL SP*)* LF
  22. OptMagic =
  23. | "+"
  24. | "/"
  25. # Keys are always specified verbatim. They are case insensitive. It
  26. # is an error to specify a key that Tor does not recognize.
  27. Key = KC*
  28. # Sadly, every kind of value is decoded differently...
  29. Val = QuotedVal | ContinuedVal | PlainVal
  30. # The text of a PlainVal is the text of its PVBody portion,
  31. # plus the optional trailing backslash.
  32. PlainVal = PVBody* ('\\')? SP* OptComment
  33. # Note that a PVBody is copied verbatim. Slashes are included
  34. # verbatim. No changes are made. Note that a body may be empty.
  35. PVBody = (VC | '\\' NonLF ) *
  36. # The text of a ContinuedVal is the text of each of its PVBody
  37. # sub-elements, in order, concatenated.
  38. ContinuedVal = CVal1 CVal2* CVal3
  39. CVal1 = PVBody '\\' LF
  40. CVal2 = PVBody ( '\\' LF | Comment LF )
  41. CVal3 = PVBody
  42. # The text of a QuotedVal is decoded as if it were a C string.
  43. QuotedVal = DQ QVBody DQ SP* Comment
  44. QVBody = QC
  45. | '\\' ( 'n' | 'r' | 't' | '\\' | '\'' | DQ | 'x' XD XD | OD OD? OD? )
  46. XD = any hexadecimal digit
  47. OD = any octal digit
  48. NonLF = Any character but '\n'
  49. LF = '\n' | EOF
  50. WS = ' ' | '\t' | '\r'
  51. SP = ' ' | '\t'
  52. DQ = '\"'
  53. KC = Any character except an isspace() character or '#'
  54. VC = Any character except '\\', '\n', or '#'
  55. QC = Any character except '\n', '\\', or '\"'
  56. 2. Mid-level Semantics
  57. There are four configuration "domains", from lowest to highest priority:
  58. * Built-in defaults
  59. * The "torrc_defaults" file, if any
  60. * The "torrc" file, if any
  61. * Arguments provided on the command line, if any.
  62. Normally, values from high-priority domains override low-priority
  63. domains, but see 'magic' below.
  64. Configuration keys fall into three categories: singletons, lists, and
  65. groups.
  66. A singleton key may appear at most once in any domain. Its
  67. corresponding value is equal to its value in the highest-priority
  68. domain in which it occurs.
  69. A list key may appear any number of times in a domain. By default,
  70. its corresponding value is equal to all of the values specified for
  71. it in the highest-priority domain in which it appears. (See 'magic'
  72. below).
  73. A group key may appear any number of times in a domain. It is
  74. associated with a number of other keys in the same group. The
  75. relative positions of entries with the keys in a single group
  76. matters, but entries with keys not in the group may be freely
  77. interspersed. By default, the group has a value equal to all keys
  78. and values it contains, from the highest-priority domain in which any
  79. of its keys occurs.
  80. Magic:
  81. If the '/' flag is specified for an entry, it sets the value for
  82. that entry to an empty list. (This will cause a higher-priority
  83. domain to clear a list from a lower-priority domain, without
  84. actually adding any entries.)
  85. If the '+' flag is specified for the first entry in a list or a
  86. group that appears in a given domain, that list or group is
  87. appended to the list or group from the next-lowest-priority
  88. domain, rather than replacing it.
  89. 3. High-level semantics
  90. There are further constraints on the values that each entry can take.
  91. These constraints are out-of-scope for this document.
  92. 4. Examples
  93. (Indentation is removed in this section, to avoid confusion.)
  94. 4.1. Syntax examples
  95. # Here is a simple configuration entry. The key is "Foo"; the value is
  96. # "Bar"
  97. Foo Bar
  98. # A configuration entry can have spaces in its value, as below. Here the
  99. # key is "Foo" and the value is "Bar Baz"
  100. Foo Bar Baz
  101. # This configuration entry has space at the end of the line, but those
  102. # spaces don't count, so the key and value are still "Foo" and "Bar Baz"
  103. Foo Bar Baz
  104. # There can be an escaped newline between the value and the key. This
  105. # is another way to say key="Hello", value="World"
  106. Hello\
  107. World
  108. # In regular entries of this kind, you can have a comment at the end of
  109. # the line, either with a space before it or not. Each of these is a
  110. # different spelling of key="Hello", value="World"
  111. Hello World #today
  112. Hello World#tomorrow
  113. # One way to encode a complex entry is as a C string. This is the same
  114. # as key="Hello", value="World!"
  115. Hello "World!"
  116. # The string can contain the usual set of C escapes. This entry has
  117. # key="Hello", and value="\"World\"\nand\nuniverse"
  118. Hello "\"World\"\nand\nuniverse"
  119. # And now we get to the more-or-less awful part.
  120. #
  121. # Multi-line entries ending with a backslash on each line aren't so
  122. # bad. The backslash is removed, and everything else is included
  123. # verbatim. So this entry has key="Hello" and value="Worldandfriends"
  124. Hello\
  125. World\
  126. and\
  127. friends
  128. # Backslashes in the middle of a line are included as-is. The key of
  129. # this one is "Too" and the value is "Many\\Backsl\ashes here" (with
  130. # backslashes in that last string as-is)
  131. Too \
  132. Many\\\
  133. Backsl\ashes \\
  134. here
  135. # And here's the really yucky part. If a comment appears in a multi-line
  136. # entry, the entry is still able to continue on the next line, as in the
  137. # following, where the key is "This" and the value is
  138. # "entry and some are silly"
  139. This entry \
  140. # has comments \
  141. and some \
  142. are # generally \
  143. silly
  144. # But you can also write that without the backslashes at the end of the
  145. # comment lines. That is to say, this entry is exactly the same as the
  146. # one above!
  147. This entry \
  148. # has comments
  149. and some \
  150. are # generally
  151. silly