test: test

This commit is contained in:
dqy
2023-10-24 21:43:34 +08:00
parent 0e3ecd475a
commit 3f5fbbcc91
2 changed files with 21 additions and 12 deletions

View File

@@ -184,23 +184,23 @@ async def send_messages(
):
global pk, sk
id_list = []
print(node_ips)
# calculate id of nodes
for node_ip in node_ips:
node_ip = node_ip[0]
ip_parts = node_ip.split(".")
id = 0
for i in range(4):
id += int(ip_parts[i]) << (24 - (8 * i))
id_list.append(id)
# generate rk
rk_list = GenerateReKey(sk, pk_B, len(node_ips), shreshold, tuple(id_list)) # type: ignore
capsule_ct = Encrypt(pk, message) # type: ignore
for i in range(len(node_ips)):
url = "http://" + node_ips[i] + ":8001" + "/user_src?message"
url = "http://" + node_ips[i][0] + ":8001" + "/user_src?message"
print(url)
payload = {
"source_ip": local_ip,
"dest_ip": dest_ip,
@@ -208,6 +208,7 @@ async def send_messages(
"rk": rk_list[i],
}
response = requests.post(url, json=payload)
if response.status_code == 200:
print(f"send to {node_ips[i]} successful")
return 0
@@ -327,6 +328,7 @@ async def recieve_request(i_m: IP_Message):
# send message to nodes
await send_messages(tuple(node_ips), message, dest_ip, pk_B, threshold)
response = {"threshold": threshold, "public_key": own_public_key}
print("###############RESPONSE = ", response)
return response