[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [sbws/maint-1.1] fix: v3bwfile: !refactor, replace constants
commit 27e2112adfc114b6931ad87d54cf69b94c9a8e8e
Author: juga0 <juga@xxxxxxxxxx>
Date: Sun Feb 9 16:51:55 2020 +0000
fix: v3bwfile: !refactor, replace constants
- Add new KeyValues constants
- Remove HEADER_KEYS_V1X constant, only used once
- Replace HEADER_UNORDERED_KEYS with the new constants
Part of #30196.
---
sbws/lib/v3bwfile.py | 30 +++++++++++++++++++++++++-----
1 file changed, 25 insertions(+), 5 deletions(-)
diff --git a/sbws/lib/v3bwfile.py b/sbws/lib/v3bwfile.py
index a232093..b3a4775 100644
--- a/sbws/lib/v3bwfile.py
+++ b/sbws/lib/v3bwfile.py
@@ -34,16 +34,32 @@ KEYVALUE_SEP_V2 = ' '
# =================
# KeyValues that need to be in a specific order in the Bandwidth File.
HEADER_KEYS_V1_1_ORDERED = ['version']
-# List of the extra KeyValues accepted by the class
-HEADER_KEYS_V1X = [
+# KeyValues that are not initialized from the state file nor the measurements.
+# They can also be pass as an argument to `Header` to overwrite default values,
+# what is done in unit tests.
+# `latest bandwidth` is special cause it gets its value from timestamp, which
+# is not a KeyValue, but it's always pass as an agument.
+# It could be separaed in other list, but so far there is no need, cause:
+# 1. when it's pass to the Header to initialize it, it's just ignored.
+# 2. when the file is created, it's took into account.
+HEADER_KEYS_V1_1_SELF_INITIALIZED = [
"software",
"software_version",
"file_created",
+ "latest_bandwidth",
+]
+# KeyValues that are initialized from arguments.
+HEADER_KEYS_V1_1_TO_INIT = [
"earliest_bandwidth",
"generator_started",
+]
+
+# KeyValues added in the Bandwidth File v1.3.0
+HEADER_KEYS_V1_3 = [
"scanner_country",
"destinations_countries",
]
+
# number_eligible_relays is the number that ends in the bandwidth file
# ie, have not been excluded by one of the filters in 4. below
# They should be call recent_measurement_included_count to be congruent
@@ -112,9 +128,13 @@ HEADER_INIT_KEYS = \
HEADER_INT_KEYS = HEADER_KEYS_V1_2 + HEADER_KEYS_V1_4
# List of all unordered KeyValues currently being used to generate the file
-HEADER_UNORDERED_KEYS = HEADER_KEYS_V1X + HEADER_KEYS_V1_2 + \
- ['latest_bandwidth'] + \
- HEADER_KEYS_V1_4
+HEADER_UNORDERED_KEYS = (
+ HEADER_KEYS_V1_1_SELF_INITIALIZED
+ + HEADER_KEYS_V1_1_TO_INIT
+ + HEADER_KEYS_V1_3
+ + HEADER_KEYS_V1_2
+ + HEADER_KEYS_V1_4
+)
# List of all the KeyValues currently being used to generate the file
HEADER_ALL_KEYS = HEADER_KEYS_V1_1_ORDERED + HEADER_UNORDERED_KEYS
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits