Commit 45b09b5a authored by zhifan huang's avatar zhifan huang

more_registry update

parent 8527bff8
......@@ -517,7 +517,7 @@ class RegistryServer(object):
v and x509.encrypt(cert, v).encode('base64')
return zlib.compress(json.dumps(config))
def _queryAddress(self, peer):
def _queryAddress(self, peer) -> bytes:
self.sendto(peer, 1)
s = self.sock,
timeout = 3
......@@ -563,7 +563,7 @@ class RegistryServer(object):
msg = ';'.join(','.join(a.split(',')[:3])
for a in msg.split(';'))
cert = self.getCert(cn)
msg = "%s %s" % (peer, msg)
msg = b"%s %s" % (peer, msg)
logging.info("Sending bootstrap peer: %s", msg)
return x509.encrypt(cert, msg)
......
......@@ -362,12 +362,11 @@ class TestRegistryServer(unittest.TestCase):
cn = new_prefix()
pkey, _ = insert_cert(self.server.db, self.server.cert, cn)
self.server.sessions[cn] = [(0,7)]
query.return_value = expect_msg = "address"
query.return_value = expect_msg = b"address"
self.server.ctl.neighbours = neigh = {}
# peers while looke like [0, 1, 2, 3, 4], have 5 peer
for i in 1,2,3,4:
neigh[i] = (i, {format(i,"016b"):i})
neigh[i] = (i, {format(i,"016b").encode():i})
msg = self.server.getBootstrapPeer(cn)
......@@ -489,7 +488,8 @@ class TestRegistryServer(unittest.TestCase):
(None, None),
("0000000000000000", "v0"),
("0000000000000001", "v1"),
("0000000000000001", "v1")
("0000000000000001", "v1"),
("0000000000000000", "v0")
]
recv.side_effect = recv_case
select_side_effect.i = len(recv_case) + 1
......
......@@ -27,7 +27,8 @@ def openssl(*args, **kwargs):
stderr=subprocess.PIPE,
**kwargs)
def encrypt(cert, data):
# use communicate so set data and return as bytes
def encrypt(cert, data:bytes) -> bytes:
r, w = os.pipe()
# https://peps.python.org/pep-0446/ Make newly created file descriptors non-inheritable
# so need pass fd by subprocess
......
Markdown is supported
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