Commit 8e4e5a3d authored by Matt Traudt's avatar Matt Traudt
Browse files

Finish GitHub #39: move result/wire versions to sbws/__init__.py

parent 003c0a2b
version = '0.1.0'
res_proto_ver = 1
wire_proto_ver = 1
......@@ -11,9 +11,7 @@ from datetime import date
from datetime import timedelta
from enum import Enum
from stem.descriptor.router_status_entry import RouterStatusEntryV3
RES_PROTO_VER = 1
from sbws import res_proto_ver
def group_results_by_relay(results, starting_dict=None):
......@@ -159,7 +157,7 @@ class Result:
@property
def version(self):
return RES_PROTO_VER
return res_proto_ver
def to_dict(self):
return {
......@@ -182,7 +180,7 @@ class Result:
NotImplementedError. If we can't parse the dict for some other reason,
return None. '''
assert 'version' in d
if d['version'] != RES_PROTO_VER:
if d['version'] != res_proto_ver:
return None
assert 'type' in d
if d['type'] == _ResultType.Success.value:
......
from ..util.sockio import read_line
import socket
from sbws import wire_proto_ver
MAGIC_BYTES = b'SBWS'
SUCCESS_BYTES = b'.'
PW_LEN = 64
WIRE_PROTO_VER = b'1'
def authenticate_client(sock, conf_section, log_fn=print):
......@@ -28,9 +28,9 @@ def authenticate_client(sock, conf_section, log_fn=print):
except socket.timeout as e:
log_fn(e)
return None
if line != str(WIRE_PROTO_VER, 'utf-8'):
if line != str(wire_proto_ver):
log_fn('Client gave protocol version {} but we support {}'.format(
line, str(WIRE_PROTO_VER, 'utf-8')))
line, wire_proto_ver))
return None
try:
......@@ -63,7 +63,7 @@ def authenticate_to_server(sock, pw, log_fn=print):
assert len(pw) == PW_LEN
try:
sock.send(MAGIC_BYTES)
sock.send(WIRE_PROTO_VER + b'\n')
sock.send(bytes('{}\n'.format(wire_proto_ver), 'utf-8'))
sock.send(bytes(pw, 'utf-8'))
msg = sock.recv(len(SUCCESS_BYTES))
except (socket.timeout, ConnectionResetError, BrokenPipeError) as e:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment