aboutsummaryrefslogtreecommitdiff
path: root/doc/torrc_format.txt
blob: 7a4a92a663eaa6350989bb9c4b5752b265389c3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
This document specifies the current format and semantics of the torrc
file, as of July 2015.  Note that we make no guarantee about the
stability of this format.  If you write something designed for strict
compatibility with this document, please expect us to break it sooner or
later.

Yes, some of this is quite stupid.  My goal here is to explain what it
does, not what it should do.

  - Nick



1. File Syntax

   ; The syntax here is defined an Augmented Backus-Naur form, as
   ; specified in RFC5234.

   ; A file is interpreted as every Entry in the file, in order.
   TorrcFile = *Line [ UnterminatedLine ]

   Line = BlankLine LF / Entry LF
   UnterminatedLine = BlankLine / Entry

   BlankLine =  *WSP OptComment LF
   BlankLine =/ *WSP LF

   OptComment = [ Comment ]

   Comment = "#" *NonLF

   ; Each Entry is interpreted as an optional "Magic" flag, a key, and a
   ; value.
   Entry =  *WSP [ Magic ] Key 1*(1*WSP / "\" NL *WSP) Val LF
   Entry =/ *WSP [ Magic ] Key  *( *WSP / "\" NL *WSP) LF

   Magic = "+" / "/"

   ; Keys are always specified verbatim.  They are case insensitive.  It
   ; is an error to specify a key that Tor does not recognize.
   Key = 1*KC

   ; Sadly, every kind of value is decoded differently...
   Val = QuotedVal / ContinuedVal / PlainVal

   ; The text of a PlainVal is the text of its PVBody portion,
   ; plus the optional trailing backslash.
   PlainVal = PVBody [ "\" ] *WSP OptComment

   ; Note that a PVBody is copied verbatim.  Slashes are included
   ; verbatim.  No changes are made.  Note that a body may be empty.
   PVBody = * (VC / "\" NonLF )

   ; The text of a ContinuedVal is the text of each of its PVBody
   ; sub-elements, in order, concatenated.
   ContinuedVal = CVal1 *CVal2 CVal3

   CVal1 = PVBody "\" LF
   CVal2 = PVBody ( "\" LF / Comment LF )
   CVal3 = PVBody

   ; The text of a QuotedVal is decoded as if it were a C string.
   QuotedVal = DQ QVBody DQ *WSP Comment

   QVBody =  QC
   QVBody =/ "\" ( "n" / "r" / "t" / "\" / "'" / DQUOTE )
   QVBOdy =/ "\" ( "x" 2HEXDIG / 1*3OCTDIG )

   ; Anything besides NUL and LF
   NonLF = %x01-%x09 / %x0b - %xff

   ; Note that on windows, we open our configuration files in "text" mode,
   ; which causes CRLF pairs to be interpreted as LF.  So, on windows:
   ;         LF = [ %x0d ] %x0a
   ; but everywhere else,
   LF = %0x0a

   OCTDIG = '0' - '7'

   KC = Any character except an isspace() character or '#' or NUL
   VC = Any character except '\\', '\n', '#', or NUL
   QC = Any character except '\n', '\\', '\"', or NUL

2. Mid-level Semantics


   There are four configuration "domains", from lowest to highest priority:

      * Built-in defaults
      * The "torrc_defaults" file, if any
      * The "torrc" file, if any
      * Arguments provided on the command line, if any.

   Normally, values from high-priority domains override low-priority
   domains, but see 'magic' below.

   Configuration keys fall into three categories: singletons, lists, and
   groups.

   A singleton key may appear at most once in any domain.  Its
   corresponding value is equal to its value in the highest-priority
   domain in which it occurs.

   A list key may appear any number of times in a domain.  By default,
   its corresponding value is equal to all of the values specified for
   it in the highest-priority domain in which it appears. (See 'magic'
   below).

   A group key may appear any number of times in a domain.  It is
   associated with a number of other keys in the same group.  The
   relative positions of entries with the keys in a single group
   matters, but entries with keys not in the group may be freely
   interspersed.  By default, the group has a value equal to all keys
   and values it contains, from the highest-priority domain in which any
   of its keys occurs.

   Magic:

      If the '/' flag is specified for an entry, it sets the value for
      that entry to an empty list.  (This will cause a higher-priority
      domain to clear a list from a lower-priority domain, without
      actually adding any entries.)

      If the '+' flag is specified for the first entry in a list or a
      group that appears in a given domain, that list or group is
      appended to the list or group from the next-lowest-priority
      domain, rather than replacing it.

3. High-level semantics

   There are further constraints on the values that each entry can take.
   These constraints are out-of-scope for this document.

4. Examples

   (Indentation is removed in this section, to avoid confusion.)

4.1. Syntax examples

# Here is a simple configuration entry.  The key is "Foo"; the value is
# "Bar"

Foo Bar

# A configuration entry can have spaces in its value, as below. Here the
# key is "Foo" and the value is "Bar    Baz"
Foo    Bar    Baz

# This configuration entry has space at the end of the line, but those
# spaces don't count, so the key and value are still "Foo" and "Bar    Baz"
Foo    Bar    Baz    

# There can be an escaped newline between the value and the key.  This
# is another way to say  key="Hello", value="World"
Hello\
World

# In regular entries of this kind, you can have a comment at the end of
# the line, either with a space before it or not.  Each of these is a
# different spelling of key="Hello", value="World"

Hello World   #today
Hello World#tomorrow

# One way to encode a complex entry is as a C string.  This is the same
# as key="Hello", value="World!"
Hello "World!"

# The string can contain the usual set of C escapes.  This entry has
# key="Hello", and value="\"World\"\nand\nuniverse"
Hello "\"World\"\nand\nuniverse"

# And now we get to the more-or-less awful part.
#
# Multi-line entries ending with a backslash on each line aren't so
# bad.  The backslash is removed, and everything else is included
# verbatim. So this entry has key="Hello" and value="Worldandfriends"
Hello\
World\
and\
friends

# Backslashes in the middle of a line are included as-is.  The key of
# this one is "Too" and the value is "Many\\Backsl\ashes \here" (with
# backslashes in that last string as-is)
Too \
Many\\\
Backsl\ashes \\
here

# And here's the really yucky part. If a comment appears in a multi-line
# entry, the entry is still able to continue on the next line, as in the
# following, where the key is "This" and the value is
# "entry        and some        are  silly"
This entry      \
 # has comments \
 and some       \
 are # generally \
 silly

# But you can also write that without the backslashes at the end of the
# comment lines.  That is to say, this entry is exactly the same as the
# one above!
This entry      \
 # has comments
 and some       \
 are # generally
 silly