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

more_registry update

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