fix: fix int to byte
This commit is contained in:
parent
879b32a007
commit
329bf9805d
17
src/node.py
17
src/node.py
@ -32,7 +32,7 @@ processed_message = () # 重加密后的数据
|
|||||||
|
|
||||||
# 向中心服务器发送自己的IP地址,并获取自己的id
|
# 向中心服务器发送自己的IP地址,并获取自己的id
|
||||||
def send_ip():
|
def send_ip():
|
||||||
url = server_address + "/get_node?ip=" + ip
|
url = server_address + "/get_node?ip=" + ip # type: ignore
|
||||||
# ip = get_local_ip() # type: ignore
|
# ip = get_local_ip() # type: ignore
|
||||||
global id
|
global id
|
||||||
id = requests.get(url, timeout=3)
|
id = requests.get(url, timeout=3)
|
||||||
@ -54,7 +54,6 @@ def get_local_ip():
|
|||||||
raise ValueError("Unable to get IP")
|
raise ValueError("Unable to get IP")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def init():
|
def init():
|
||||||
get_local_ip()
|
get_local_ip()
|
||||||
send_ip()
|
send_ip()
|
||||||
@ -72,7 +71,7 @@ def clear():
|
|||||||
async def send_heartbeat_internal() -> None:
|
async def send_heartbeat_internal() -> None:
|
||||||
timeout = 30
|
timeout = 30
|
||||||
global ip
|
global ip
|
||||||
url = server_address + "/heartbeat?ip=" + ip
|
url = server_address + "/heartbeat?ip=" + ip # type: ignore
|
||||||
while True:
|
while True:
|
||||||
# print('successful send my_heart')
|
# print('successful send my_heart')
|
||||||
try:
|
try:
|
||||||
@ -112,14 +111,10 @@ async def user_src(message: Req):
|
|||||||
dest_ip = message.dest_ip
|
dest_ip = message.dest_ip
|
||||||
capsule = message.capsule
|
capsule = message.capsule
|
||||||
ct = message.ct
|
ct = message.ct
|
||||||
# here has a problem. If ct longer than 32 bytes,
|
|
||||||
# here will raise an error then exit.
|
byte_length = (ct.bit_length() + 7) // 8
|
||||||
# So node will goes down.
|
capsule_ct = (capsule, ct.to_bytes(byte_length))
|
||||||
# def int_to_bytes(ct):
|
|
||||||
# byte_length = (ct.bit_length() + 7) // 8
|
|
||||||
# return ct.to_bytes(byte_length, byteorder='big')
|
|
||||||
# capsule_ct = (capsule, int_to_bytes(ct))
|
|
||||||
capsule_ct = (capsule, ct.to_bytes(32))
|
|
||||||
rk = message.rk
|
rk = message.rk
|
||||||
print(f"Computed capsule_ct: {capsule_ct}")
|
print(f"Computed capsule_ct: {capsule_ct}")
|
||||||
a, b = ReEncrypt(rk, capsule_ct)
|
a, b = ReEncrypt(rk, capsule_ct)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user