aboutsummaryrefslogtreecommitdiff
path: root/spec/bandwidth-file-spec/implementation-details.md
blob: dbc02cccb4c6a456814bb50e1389d0e4333999c9 (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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
<a id="bandwidth-file-spec.txt-2.4"></a>

# Implementation details

<a id="bandwidth-file-spec.txt-2.4.1"></a>

## Writing bandwidth files atomically { #write-atomically }

To avoid inconsistent reads, implementations SHOULD write bandwidth files
atomically. If the file is transferred from another host, it SHOULD be
written to a temporary path, then renamed to the V3BandwidthsFile path.

sbws versions 0.7.0 and later write the bandwidth file to an archival
location, create a temporary symlink to that location, then atomically rename
the symlink
to the configured V3BandwidthsFile path.

Torflow does not write bandwidth files atomically.

<a id="bandwidth-file-spec.txt-2.4.2"></a>

## Additional KeyValue pair definitions { #key-value-pairs }

KeyValue pairs in RelayLines that current implementations generate.

<a id="bandwidth-file-spec.txt-2.4.2.1"></a>

### Simple Bandwidth Scanner { #sbws }

sbws RelayLines contain these keys:

"node_id" hexdigest

As above.

"bw" Bandwidth

As above.

"nick" nickname

\[Exactly once.\]

The relay nickname.

Torflow also has a "nick" KeyValue.

"rtt" Int

\[Zero or one time.\]

The Round Trip Time in milliseconds to obtain 1 byte of data.

This KeyValue was added in version 1.1.0 of this specification.
It became optional in version 1.3.0 or 1.4.0 of this specification.

"time" DateTime

\[Exactly once.\]

The date and time timestamp in ISO 8601 format and UTC time zone
when the last bandwidth was obtained.

This KeyValue was added in version 1.1.0 of this specification.
The Torflow equivalent is "measured_at".

"success" Int

\[Zero or one time.\]

The number of times that the bandwidth measurements for this relay were
successful.

This KeyValue was added in version 1.1.0 of this specification.

"error_circ" Int

\[Zero or one time.\]

The number of times that the bandwidth measurements for this relay
failed because of circuit failures.

This KeyValue was added in version 1.1.0 of this specification.
The Torflow equivalent is "circ_fail".

"error_stream" Int

\[Zero or one time.\]

The number of times that the bandwidth measurements for this relay
failed because of stream failures.

This KeyValue was added in version 1.1.0 of this specification.

"error_destination" Int

\[Zero or one time.\]

The number of times that the bandwidth measurements for this relay
failed because the destination Web server was not available.

This KeyValue was added in version 1.4.0 of this specification.

"error_second_relay" Int

\[Zero or one time.\]

The number of times that the bandwidth measurements for this relay
failed because sbws could not find a second relay for the test circuit.

This KeyValue was added in version 1.4.0 of this specification.

"error_misc" Int

\[Zero or one time.\]

The number of times that the bandwidth measurements for this relay
failed because of other reasons.

This KeyValue was added in version 1.1.0 of this specification.

"bw_mean" Int

\[Zero or one time.\]

The measured bandwidth mean for this relay in bytes per second.

This KeyValue was added in version 1.2.0 of this specification.

"bw_median" Int

\[Zero or one time.\]

The measured bandwidth median for this relay in bytes per second.

This KeyValue was added in version 1.2.0 of this specification.

"desc_bw_avg" Int

\[Zero or one time.\]

The descriptor average bandwidth for this relay in bytes per second.

This KeyValue was added in version 1.2.0 of this specification.

"desc_bw_obs_last" Int

\[Zero or one time.\]

The last descriptor observed bandwidth for this relay in bytes per
second.

This KeyValue was added in version 1.2.0 of this specification.

"desc_bw_obs_mean" Int

\[Zero or one time.\]

The descriptor observed bandwidth mean for this relay in bytes per
second.

This KeyValue was added in version 1.2.0 of this specification.

"desc_bw_bur" Int

\[Zero or one time.\]

The descriptor burst bandwidth for this relay in bytes per
second.

This KeyValue was added in version 1.2.0 of this specification.

"consensus_bandwidth" Int

\[Zero or one time.\]

The consensus bandwidth for this relay in bytes per second.

This KeyValue was added in version 1.2.0 of this specification.

"consensus_bandwidth_is_unmeasured" Bool

\[Zero or one time.\]

If the consensus bandwidth for this relay was not obtained from
three or more bandwidth authorities, this KeyValue is True or
False otherwise.

This KeyValue was added in version 1.2.0 of this specification.

"relay_in_recent_consensus_count" Int

\[Zero or one time.\]

The number of times this relay was found in a consensus in the
last data_period days. (Unless otherwise stated, data_period is
5 by default.)

This KeyValue was added in version 1.4.0 of this specification.

"relay_recent_priority_list_count" Int

\[Zero or one time.\]

The number of times this relay has been prioritized to be measured
in the last data_period days.

This KeyValue was added in version 1.4.0 of this specification.

"relay_recent_measurement_attempt_count" Int

\[Zero or one time.\]

The number of times this relay was tried to be measured in the
last data_period days.

This KeyValue was added in version 1.4.0 of this specification.

"relay_recent_measurement_failure_count" Int

\[Zero or one time.\]

The number of times this relay was tried to be measured in the
last data_period days, but it was not possible to obtain a
measurement.

This KeyValue was added in version 1.4.0 of this specification.

"relay_recent_measurements_excluded_error_count" Int

\[Zero or one time.\]

The number of recent relay measurement attempts that failed.
Measurements are recent if they are in the last data_period days
(5 by default).

(See the note in section 1.4, version 1.4.0, about excluded relays.)

This KeyValue was added in version 1.4.0 of this specification.

"relay_recent_measurements_excluded_near_count" Int

\[Zero or one time.\]

When all of a relay's recent successful measurements were performed in
a period of time that was too short (by default 1 day), the relay is
excluded. This KeyValue contains the number of recent successful
measurements for the relay that were ignored for this reason.

(See the note in section 1.4, version 1.4.0, about excluded relays.)

This KeyValue was added in version 1.4.0 of this specification.

"relay_recent_measurements_excluded_old_count" Int

\[Zero or one time.\]

The number of successful measurements for this relay that are too old
(more than data_period days, 5 by default).

Excludes measurements that are already counted in
relay_recent_measurements_excluded_near_count.

(See the note in section 1.4, version 1.4.0, about excluded relays.)

This KeyValue was added in version 1.4.0 of this specification.

"relay_recent_measurements_excluded_few_count" Int

\[Zero or one time.\]

The number of successful measurements for this relay that were ignored
because the relay did not have enough successful measurements (fewer
than 2, by default).

Excludes measurements that are already counted in
relay_recent_measurements_excluded_near_count or
relay_recent_measurements_excluded_old_count.

(See the note in section 1.4, version 1.4.0, about excluded relays.)

This KeyValue was added in version 1.4.0 of this specification.

"under_min_report" bool

\[Zero or one time.\]

If the value is 1, there are not enough eligible relays in the
bandwidth file, and Tor bandwidth authorities MAY NOT vote on this
relay. (Current Tor versions do not change their behaviour based on
the "under_min_report" key.)

If the value is 0 or the KeyValue is not present, there are enough
relays in the bandwidth file.

Because Tor versions released before April 2019 (see section 1.4. for
the full list of versions) ignore "vote=0", generator implementations
MUST NOT change the bandwidths for under_min_report relays. Using the
same bw value makes authorities that do not understand "vote=0"
or "under_min_report=1" produce votes that don't change relay weights
too much. It also avoids flapping when the reporting threshold is
reached.

This KeyValue was added in version 1.4.0 of this specification.

"unmeasured" bool

\[Zero or one time.\]

If the value is 1, this relay was not successfully measured and
Tor bandwidth authorities MAY NOT vote on this relay.
(Current Tor versions do not change their behaviour based on
the "unmeasured" key.)

If the value is 0 or the KeyValue is not present, this relay
was successfully measured.

Because Tor versions released before April 2019 (see section 1.4. for
the full list of versions) ignore "vote=0", generator implementations
MUST set "bw=1" for unmeasured relays. Using the minimum bw value
makes authorities that do not understand "vote=0" or "unmeasured=1"
produce votes that don't change relay weights too much.

This KeyValue was added in version 1.4.0 of this specification.

"vote" bool

\[Zero or one time.\]

If the value is 0, Tor directory authorities SHOULD ignore the relay's
entry in the bandwidth file. They SHOULD vote for the relay the same
way they would vote for a relay that is not present in the file.

This MAY be the case when this relay was not successfully measured but
it is included in the Bandwidth File, to diagnose why they were not
measured.

If the value is 1 or the KeyValue is not present, Tor directory
authorities MUST use the relay's bw value in any votes for that relay.

Implementations MUST also set "bw=1" for unmeasured relays.
But they MUST NOT change the bw for under_min_report relays.
(See the explanations under "unmeasured" and "under_min_report"
for more details.)

This KeyValue was added in version 1.4.0 of this specification.

"xoff_recv" Int

\[Zero or one time.\]

The number of times this relay received `XOFF_RECV` stream events while
being measured in the last data_period days.

This KeyValue was added in version 1.6.0 of this specification.

"xoff_sent" Int

\[Zero or one time.\]

The number of times this relay received `XOFF_SENT` stream events while
being measured in the last data_period days.

This KeyValue was added in version 1.6.0 of this specification.

"r_strm" Float

\[Zero or one time.\]

The stream ratio of this relay calculated as explained in B4.3.

This KeyValue was added in version 1.7.0 of this specification.

"r_strm_filt" Float

\[Zero or one time.\]

The filtered stream ratio of this relay calculated as explained in B4.3.

This KeyValue was added in version 1.7.0 of this specification.

<a id="bandwidth-file-spec.txt-2.4.2.2"></a>

### Torflow

Torflow RelayLines include node_id and bw, and other KeyValue pairs \[2\].

References:


1. <https://gitlab.torproject.org/tpo/network-health/torflow>
2. <https://gitlab.torproject.org/tpo/network-health/torflow/-/blob/main/NetworkScanners/BwAuthority/README.spec.txt?ref_type=heads#L332>
   The Torflow specification is outdated, and does not match the current
   implementation. See section A.1. for the format produced by Torflow.
3. [The Tor Directory Protocol](../dir-spec)
4. [How Tor Version Numbers Work In Tor](../version-spec.md)
5. <https://semver.org/>
```