[tor-commits] [sbws/master] Unify ed25519 master key terms

pastly at torproject.org pastly at torproject.org
Thu Jun 14 13:29:51 UTC 2018


commit f33706ce183f6d5370c7755beca8831f1cd512c5
Author: juga0 <juga at riseup.net>
Date:   Mon Jun 11 10:43:17 2018 +0000

    Unify ed25519 master key terms
    
    to make it less confussing.
    Note that stem call it ed25519_master_key instead of
    master_key_ed25519, but dir-spec.txt uses master-key-ed25519, which
    is the term chosen here.
---
 sbws/lib/relaylist.py                   |  4 +++-
 sbws/lib/resultdump.py                  | 22 +++++++++++-----------
 sbws/lib/v3bwfile.py                    |  4 ++--
 tests/integration/lib/test_relaylist.py |  3 ++-
 tests/unit/core/test_generate.py        | 12 ++++++------
 tests/unit/lib/data/results.txt         |  4 ++--
 tests/unit/lib/test_results.py          | 10 +++++-----
 tests/unit/lib/test_v3bwfile.py         |  4 ++--
 8 files changed, 33 insertions(+), 30 deletions(-)

diff --git a/sbws/lib/relaylist.py b/sbws/lib/relaylist.py
index 5d584ea..4f7055c 100644
--- a/sbws/lib/relaylist.py
+++ b/sbws/lib/relaylist.py
@@ -78,12 +78,14 @@ class Relay:
         return self._from_ns('address')
 
     @property
-    def ed25519_master_key(self):
+    def master_key_ed25519(self):
         """Obtain ed25519 master key of the relay in server descriptors.
 
         :returns: str, the ed25519 master key base 64 encoded without
         trailing '='s.
         """
+        # Even if this key is called master-key-ed25519 in dir-spec.txt,
+        # it seems that stem parses it as ed25519_master_key
         return self._from_desc('ed25519_master_key').rstrip('=')
 
 
diff --git a/sbws/lib/resultdump.py b/sbws/lib/resultdump.py
index 4401412..32fd1cd 100644
--- a/sbws/lib/resultdump.py
+++ b/sbws/lib/resultdump.py
@@ -150,15 +150,15 @@ class Result:
     class Relay:
         ''' Implements just enough of a stem RouterStatusEntryV3 for this
         Result class to be happy '''
-        def __init__(self, fingerprint, nickname, address, ed25519_master_key):
+        def __init__(self, fingerprint, nickname, address, master_key_ed25519):
             self.fingerprint = fingerprint
             self.nickname = nickname
             self.address = address
-            self.ed25519_master_key = ed25519_master_key
+            self.master_key_ed25519 = master_key_ed25519
 
     def __init__(self, relay, circ, dest_url, scanner_nick, t=None):
         self._relay = Result.Relay(relay.fingerprint, relay.nickname,
-                                   relay.address, relay.ed25519_master_key)
+                                   relay.address, relay.master_key_ed25519)
         self._circ = circ
         self._dest_url = dest_url
         self._scanner = scanner_nick
@@ -181,8 +181,8 @@ class Result:
         return self._relay.address
 
     @property
-    def ed25519_master_key(self):
-        return self._relay.ed25519_master_key
+    def master_key_ed25519(self):
+        return self._relay.master_key_ed25519
 
     @property
     def circ(self):
@@ -209,7 +209,7 @@ class Result:
             'fingerprint': self.fingerprint,
             'nickname': self.nickname,
             'address': self.address,
-            'ed25519_master_key': self.ed25519_master_key,
+            'master_key_ed25519': self.master_key_ed25519,
             'circ': self.circ,
             'dest_url': self.dest_url,
             'time': self.time,
@@ -283,7 +283,7 @@ class ResultError(Result):
         return ResultError(
             Result.Relay(
                 d['fingerprint'], d['nickname'], d['address'],
-                d['ed25519_master_key']),
+                d['master_key_ed25519']),
             d['circ'], d['dest_url'], d['scanner'],
             msg=d['msg'], t=d['time'])
 
@@ -324,7 +324,7 @@ class ResultErrorCircuit(ResultError):
         return ResultErrorCircuit(
             Result.Relay(
                 d['fingerprint'], d['nickname'], d['address'],
-                d['ed25519_master_key']),
+                d['master_key_ed25519']),
             d['circ'], d['dest_url'], d['scanner'],
             msg=d['msg'], t=d['time'])
 
@@ -347,7 +347,7 @@ class ResultErrorStream(ResultError):
         return ResultErrorStream(
             Result.Relay(
                 d['fingerprint'], d['nickname'], d['address'],
-                d['ed25519_master_key']),
+                d['master_key_ed25519']),
             d['circ'], d['dest_url'], d['scanner'],
             msg=d['msg'], t=d['time'])
 
@@ -383,7 +383,7 @@ class ResultErrorAuth(ResultError):
         return ResultErrorAuth(
             Result.Relay(
                 d['fingerprint'], d['nickname'], d['address'],
-                d['ed25519_master_key']),
+                d['master_key_ed25519']),
             d['circ'], d['dest_url'], d['scanner'],
             msg=d['msg'], t=d['time'])
 
@@ -417,7 +417,7 @@ class ResultSuccess(Result):
             d['rtts'], d['downloads'],
             Result.Relay(
                 d['fingerprint'], d['nickname'], d['address'],
-                d['ed25519_master_key']),
+                d['master_key_ed25519']),
             d['circ'], d['dest_url'], d['scanner'],
             t=d['time'])
 
diff --git a/sbws/lib/v3bwfile.py b/sbws/lib/v3bwfile.py
index 9a2dfdd..4091912 100644
--- a/sbws/lib/v3bwfile.py
+++ b/sbws/lib/v3bwfile.py
@@ -336,8 +336,8 @@ class V3BWLine(object):
         bw = cls.bw_from_results(success_results)
         kwargs = dict()
         kwargs['nick'] = results[0].nickname
-        if getattr(results[0], 'ed25519_master_key'):
-            kwargs['master_key_ed25519'] = results[0].ed25519_master_key
+        if getattr(results[0], 'master_key_ed25519'):
+            kwargs['master_key_ed25519'] = results[0].master_key_ed25519
         kwargs['rtt'] = cls.rtt_from_results(success_results)
         kwargs['time'] = cls.last_time_from_results(results)
         kwargs.update(cls.result_types_from_results(results))
diff --git a/tests/integration/lib/test_relaylist.py b/tests/integration/lib/test_relaylist.py
index 8f16ef8..a3fbbf0 100644
--- a/tests/integration/lib/test_relaylist.py
+++ b/tests/integration/lib/test_relaylist.py
@@ -10,8 +10,9 @@ def test_relay_properties(persistent_launch_tor):
     assert relay.fingerprint == 'AA45C13025C037F056E734169891878ED0880231'
     assert 'Authority' in relay.flags
     assert not relay.exit_policy or not relay.exit_policy.is_exiting_allowed()
+    print(relay)
     assert relay.average_bandwidth == 1073741824
     assert relay.bandwidth == 0
     assert relay.address == '127.10.0.1'
-    assert relay.ed25519_master_key == \
+    assert relay.master_key_ed25519 == \
         'wLglSEw9/DHfpNrlrqjVRSnGLVWfnm0vYxkryH4aT6Q'
diff --git a/tests/unit/core/test_generate.py b/tests/unit/core/test_generate.py
index fae4fe0..ad1fff2 100644
--- a/tests/unit/core/test_generate.py
+++ b/tests/unit/core/test_generate.py
@@ -118,7 +118,7 @@ def test_generate_single_success_noscale(dotsbws_success_result, caplog,
     rtt = median([round(r * 1000) for r in result.rtts])
     bw_line = V3BWLine(result.fingerprint, bw, nick=result.nickname, rtt=rtt,
                        time=unixts_to_isodt_str(round(result.time)),
-                       master_key_ed25519=result.ed25519_master_key,
+                       master_key_ed25519=result.master_key_ed25519,
                        success=1, error_circ=0, error_misc=0,
                        error_stream=0)
     assert stdout_lines[NUM_LINES_HEADER_V110] + '\n' == str(bw_line)
@@ -151,7 +151,7 @@ def test_generate_single_success_scale(dotsbws_success_result, parser,
     rtt = median([round(r * 1000) for r in result.rtts])
     bw_line = V3BWLine(result.fingerprint, bw, nick=result.nickname, rtt=rtt,
                        time=unixts_to_isodt_str(round(result.time)),
-                       master_key_ed25519=result.ed25519_master_key,
+                       master_key_ed25519=result.master_key_ed25519,
                        success=1, error_circ=0, error_misc=0,
                        error_stream=0)
     assert stdout_lines[NUM_LINES_HEADER_V110] + '\n' == str(bw_line)
@@ -185,7 +185,7 @@ def test_generate_single_relay_success_noscale(
     speed = round(median(speeds))
     rtt = round(median([round(r * 1000) for r in result.rtts]))
     bw_line = V3BWLine(result.fingerprint, speed, nick=result.nickname,
-                       rtt=rtt, master_key_ed25519=result.ed25519_master_key,
+                       rtt=rtt, master_key_ed25519=result.master_key_ed25519,
                        time=unixts_to_isodt_str(round(result.time)),
                        success=2, error_circ=0, error_misc=0,
                        error_stream=0)
@@ -219,7 +219,7 @@ def test_generate_single_relay_success_scale(
     rtt = round(median([round(r * 1000) for r in result.rtts]))
     bw_line = V3BWLine(result.fingerprint, speed, nick=result.nickname,
                        rtt=rtt,
-                       master_key_ed25519=result.ed25519_master_key,
+                       master_key_ed25519=result.master_key_ed25519,
                        time=unixts_to_isodt_str(round(result.time)),
                        success=2, error_circ=0, error_misc=0,
                        error_stream=0)
@@ -253,7 +253,7 @@ def test_generate_two_relays_success_noscale(
     r1_time = unixts_to_isodt_str(round(max([r.time for r in r1_results])))
     r1_name = r1_results[0].nickname
     r1_fingerprint = r1_results[0].fingerprint
-    r1_ed25519 = r1_results[0].ed25519_master_key
+    r1_ed25519 = r1_results[0].master_key_ed25519
     r1_speeds = [dl['amount'] / dl['duration'] / 1024
                  for r in r1_results for dl in r.downloads]
     r1_speed = round(median(r1_speeds))
@@ -269,7 +269,7 @@ def test_generate_two_relays_success_noscale(
     r2_time = unixts_to_isodt_str(round(max([r.time for r in r2_results])))
     r2_name = r2_results[0].nickname
     r2_fingerprint = r2_results[0].fingerprint
-    r2_ed25519 = r2_results[0].ed25519_master_key
+    r2_ed25519 = r2_results[0].master_key_ed25519
     r2_speeds = [dl['amount'] / dl['duration'] / 1024
                  for r in r2_results for dl in r.downloads]
     r2_speed = round(median(r2_speeds))
diff --git a/tests/unit/lib/data/results.txt b/tests/unit/lib/data/results.txt
index ecf0b68..d2005f6 100644
--- a/tests/unit/lib/data/results.txt
+++ b/tests/unit/lib/data/results.txt
@@ -1,2 +1,2 @@
-{"version": 3, "time": 1523887747, "circ": ["AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"], "type": "success", "rtts": [0.4596822261810303, 0.44872617721557617, 0.4563450813293457, 0.44872212409973145, 0.4561030864715576, 0.4765200614929199, 0.4495084285736084, 0.45711588859558105, 0.45520496368408203, 0.4635589122772217], "fingerprint": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "scanner": "IDidntEditTheSBWSConfig", "downloads": [{"amount": 590009, "duration": 6.1014368534088135}, {"amount": 590009, "duration": 8.391342878341675}, {"amount": 321663, "duration": 7.064587831497192}, {"amount": 321663, "duration": 8.266003131866455}, {"amount": 321663, "duration": 5.779450178146362}], "dest_url": "http://y.z", "nickname": "A", "address": "111.111.111.111", "ed25519_master_key": "g+Shk00y9Md0hg1S6ptnuc/wWKbADBgdjT0Kg+TSF3s"}
-{"version": 3, "time": 1523974147, "circ": ["AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"], "type": "error-stream", "msg": "Something bad happened while measuring bandwidth", "fingerprint": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "scanner": "IDidntEditTheSBWSConfig", "dest_url": "http://y.z", "nickname": "A", "address": "111.111.111.111", "ed25519_master_key": "g+Shk00y9Md0hg1S6ptnuc/wWKbADBgdjT0Kg+TSF3s"}
+{"version": 3, "time": 1523887747, "circ": ["AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"], "type": "success", "rtts": [0.4596822261810303, 0.44872617721557617, 0.4563450813293457, 0.44872212409973145, 0.4561030864715576, 0.4765200614929199, 0.4495084285736084, 0.45711588859558105, 0.45520496368408203, 0.4635589122772217], "fingerprint": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "scanner": "IDidntEditTheSBWSConfig", "downloads": [{"amount": 590009, "duration": 6.1014368534088135}, {"amount": 590009, "duration": 8.391342878341675}, {"amount": 321663, "duration": 7.064587831497192}, {"amount": 321663, "duration": 8.266003131866455}, {"amount": 321663, "duration": 5.779450178146362}], "dest_url": "http://y.z", "nickname": "A", "address": "111.111.111.111", "master_key_ed25519": "g+Shk00y9Md0hg1S6ptnuc/wWKbADBgdjT0Kg+TSF3s"}
+{"version": 3, "time": 1523974147, "circ": ["AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"], "type": "error-stream", "msg": "Something bad happened while measuring bandwidth", "fingerprint": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "scanner": "IDidntEditTheSBWSConfig", "dest_url": "http://y.z", "nickname": "A", "address": "111.111.111.111", "master_key_ed25519": "g+Shk00y9Md0hg1S6ptnuc/wWKbADBgdjT0Kg+TSF3s"}
diff --git a/tests/unit/lib/test_results.py b/tests/unit/lib/test_results.py
index 010d505..3d4770e 100644
--- a/tests/unit/lib/test_results.py
+++ b/tests/unit/lib/test_results.py
@@ -112,7 +112,7 @@ def test_ResultSuccess_from_dict(time_mock):
         'nickname': nick, 'address': relay_ip, 'circ': circ,
         'dest_url': dest_url, 'scanner': scanner_nick,
         'version': RESULT_VERSION, 'type': _ResultType.Success, 'time': t,
-        'ed25519_master_key': ed25519,
+        'master_key_ed25519': ed25519,
     }
     r2 = Result.from_dict(d)
     assert isinstance(r1, ResultSuccess)
@@ -169,7 +169,7 @@ def test_ResultError_from_dict(time_mock):
         'nickname': nick, 'address': relay_ip, 'circ': circ,
         'dest_url': dest_url, 'scanner': scanner_nick,
         'version': RESULT_VERSION, 'type': _ResultType.Error, 'time': t,
-        'ed25519_master_key': ed25519,
+        'master_key_ed25519': ed25519,
     }
     r2 = Result.from_dict(d)
     assert isinstance(r1, ResultError)
@@ -227,7 +227,7 @@ def test_ResultErrorCircuit_from_dict(time_mock):
         'nickname': nick, 'address': relay_ip, 'circ': circ,
         'dest_url': dest_url, 'scanner': scanner_nick,
         'version': RESULT_VERSION, 'type': _ResultType.ErrorCircuit, 'time': t,
-        'ed25519_master_key': ed25519,
+        'master_key_ed25519': ed25519,
     }
     r2 = Result.from_dict(d)
     assert isinstance(r1, ResultErrorCircuit)
@@ -285,7 +285,7 @@ def test_ResultErrorStream_from_dict(time_mock):
         'nickname': nick, 'address': relay_ip, 'circ': circ,
         'dest_url': dest_url, 'scanner': scanner_nick,
         'version': RESULT_VERSION, 'type': _ResultType.ErrorStream, 'time': t,
-        'ed25519_master_key': ed25519,
+        'master_key_ed25519': ed25519,
     }
     r2 = Result.from_dict(d)
     assert isinstance(r1, ResultErrorStream)
@@ -343,7 +343,7 @@ def test_ResultErrorAuth_from_dict(time_mock):
         'nickname': nick, 'address': relay_ip, 'circ': circ,
         'dest_url': dest_url, 'scanner': scanner_nick,
         'version': RESULT_VERSION, 'type': _ResultType.ErrorAuth, 'time': t,
-        'ed25519_master_key': ed25519,
+        'master_key_ed25519': ed25519,
     }
     r2 = Result.from_dict(d)
     assert isinstance(r1, ResultErrorAuth)
diff --git a/tests/unit/lib/test_v3bwfile.py b/tests/unit/lib/test_v3bwfile.py
index b61c303..750ab63 100644
--- a/tests/unit/lib/test_v3bwfile.py
+++ b/tests/unit/lib/test_v3bwfile.py
@@ -54,7 +54,7 @@ RESULT_ERROR_STREAM_DICT = {
     "type": "error-stream",
     "msg": "Something bad happened while measuring bandwidth",
     "nickname": "A",
-    "ed25519_master_key": "g+Shk00y9Md0hg1S6ptnuc/wWKbADBgdjT0Kg+TSF3s"
+    "master_key_ed25519": "g+Shk00y9Md0hg1S6ptnuc/wWKbADBgdjT0Kg+TSF3s"
 }
 
 RESULT_SUCCESS_DICT = {
@@ -78,7 +78,7 @@ RESULT_SUCCESS_DICT = {
         {"amount": 321663, "duration": 8.266003131866455},
         {"amount": 321663, "duration": 5.779450178146362}],
     "nickname": "A",
-    "ed25519_master_key": "g+Shk00y9Md0hg1S6ptnuc/wWKbADBgdjT0Kg+TSF3s"
+    "master_key_ed25519": "g+Shk00y9Md0hg1S6ptnuc/wWKbADBgdjT0Kg+TSF3s"
 }
 RESULT_SUCCESS_STR = str(RESULT_SUCCESS_DICT)
 RESULT_ERROR_STREAM_STR = str(RESULT_ERROR_STREAM_DICT)





More information about the tor-commits mailing list