[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [sbws/master] Check bw line size
commit c3f7b0482d902601eb02b3e3dee7e683e0e949d0
Author: juga0 <juga@xxxxxxxxxx>
Date: Sat May 26 19:23:44 2018 +0000
Check bw line size
also, convert types to int when generating line from str
---
sbws/globals.py | 1 +
sbws/lib/v3bwfile.py | 14 ++++++++++++--
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/sbws/globals.py b/sbws/globals.py
index 602075a..a6621ab 100644
--- a/sbws/globals.py
+++ b/sbws/globals.py
@@ -25,6 +25,7 @@ TORRC_STARTING_POINT = {
}
SCALE_CONSTANT = 7500
+BW_LINE_SIZE = 510
def is_initted(d):
diff --git a/sbws/lib/v3bwfile.py b/sbws/lib/v3bwfile.py
index cb4a6af..2d7196a 100644
--- a/sbws/lib/v3bwfile.py
+++ b/sbws/lib/v3bwfile.py
@@ -6,7 +6,7 @@ import logging
from statistics import median
from sbws import __version__
-from sbws.globals import SPEC_VERSION
+from sbws.globals import SPEC_VERSION, BW_LINE_SIZE
from sbws.lib.resultdump import ResultSuccess, _ResultType
from sbws.util.filelock import FileLock
from sbws.util.timestamp import now_isodt_str, unixts_to_isodt_str
@@ -32,7 +32,9 @@ LINE_TERMINATOR = TERMINATOR + LINE_SEP
BW_KEYVALUE_SEP_V110 = ' '
BW_EXTRA_ARG_KEYVALUES = ['master_key_ed25519', 'nick', 'rtts', 'last_time',
'success', 'error_stream', 'error_circ',
- 'error_misc', 'error_auth']
+ 'error_misc']
+BW_KEYVALUES_INT = ['bw', 'rtts', 'success', 'error_auth', 'error_stream',
+ 'error_circ', 'error_misc']
BW_KEYVALUES = ['node_id', 'bw'] + BW_EXTRA_ARG_KEYVALUES
@@ -278,6 +280,11 @@ class V3BWLine(object):
"""Return Bandwidth Line string following spec v1.1.0."""
bw_line_str = BW_KEYVALUE_SEP_V110.join(
self.bw_keyvalue_v110str_ls) + LINE_SEP
+ if len(bw_line_str) > BW_LINE_SIZE:
+ # if this is the case, probably there are too many KeyValues,
+ # or the limit needs to be changed in Tor
+ log.warn("The bandwidth line %s is longer than %s",
+ len(bw_line_str), BW_LINE_SIZE)
return bw_line_str
def __str__(self):
@@ -289,6 +296,9 @@ class V3BWLine(object):
kwargs = dict([kv.split(KEYVALUE_SEP_V110)
for kv in line.split(BW_KEYVALUE_SEP_V110)
if kv.split(KEYVALUE_SEP_V110)[0] in BW_KEYVALUES])
+ for k, v in kwargs.items():
+ if k in BW_KEYVALUES_INT:
+ kwargs[k] = int(v)
bw_line = cls(**kwargs)
return bw_line
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits