Merge branch 'main' of https://git.mamahaha.work/dqy/mimajingsai
This commit is contained in:
commit
3076d501ec
@ -184,7 +184,7 @@ async def send_messages(
|
|||||||
):
|
):
|
||||||
global pk, sk
|
global pk, sk
|
||||||
id_list = []
|
id_list = []
|
||||||
print(node_ips)
|
|
||||||
# calculate id of nodes
|
# calculate id of nodes
|
||||||
for node_ip in node_ips:
|
for node_ip in node_ips:
|
||||||
node_ip = node_ip[0]
|
node_ip = node_ip[0]
|
||||||
@ -193,7 +193,6 @@ async def send_messages(
|
|||||||
for i in range(4):
|
for i in range(4):
|
||||||
id += int(ip_parts[i]) << (24 - (8 * i))
|
id += int(ip_parts[i]) << (24 - (8 * i))
|
||||||
id_list.append(id)
|
id_list.append(id)
|
||||||
|
|
||||||
# generate rk
|
# generate rk
|
||||||
rk_list = GenerateReKey(sk, pk_B, len(node_ips), shreshold, tuple(id_list)) # type: ignore
|
rk_list = GenerateReKey(sk, pk_B, len(node_ips), shreshold, tuple(id_list)) # type: ignore
|
||||||
|
|
||||||
@ -201,7 +200,7 @@ async def send_messages(
|
|||||||
|
|
||||||
for i in range(len(node_ips)):
|
for i in range(len(node_ips)):
|
||||||
url = "http://" + node_ips[i][0] + ":8001" + "/user_src?message"
|
url = "http://" + node_ips[i][0] + ":8001" + "/user_src?message"
|
||||||
|
print(url)
|
||||||
payload = {
|
payload = {
|
||||||
"source_ip": local_ip,
|
"source_ip": local_ip,
|
||||||
"dest_ip": dest_ip,
|
"dest_ip": dest_ip,
|
||||||
@ -209,6 +208,7 @@ async def send_messages(
|
|||||||
"rk": rk_list[i],
|
"rk": rk_list[i],
|
||||||
}
|
}
|
||||||
response = requests.post(url, json=payload)
|
response = requests.post(url, json=payload)
|
||||||
|
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
print(f"send to {node_ips[i]} successful")
|
print(f"send to {node_ips[i]} successful")
|
||||||
return 0
|
return 0
|
||||||
@ -329,6 +329,7 @@ async def recieve_request(i_m: IP_Message):
|
|||||||
# send message to nodes
|
# send message to nodes
|
||||||
await send_messages(tuple(node_ips), message, dest_ip, pk_B, threshold)
|
await send_messages(tuple(node_ips), message, dest_ip, pk_B, threshold)
|
||||||
response = {"threshold": threshold, "public_key": own_public_key}
|
response = {"threshold": threshold, "public_key": own_public_key}
|
||||||
|
print("###############RESPONSE = ", response)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
21
src/node.py
21
src/node.py
@ -6,6 +6,7 @@ import asyncio
|
|||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
from tpre import *
|
from tpre import *
|
||||||
import os
|
import os
|
||||||
|
from typing import Any, Tuple
|
||||||
|
|
||||||
|
|
||||||
@asynccontextmanager
|
@asynccontextmanager
|
||||||
@ -71,8 +72,15 @@ async def send_heartbeat_internal() -> None:
|
|||||||
await asyncio.sleep(timeout)
|
await asyncio.sleep(timeout)
|
||||||
|
|
||||||
|
|
||||||
|
class Req(BaseModel):
|
||||||
|
source_ip: str
|
||||||
|
dest_ip: str
|
||||||
|
capsule_ct: Tuple[capsule, bytes]
|
||||||
|
rk: Any
|
||||||
|
|
||||||
|
|
||||||
@app.post("/user_src") # 接收用户1发送的信息
|
@app.post("/user_src") # 接收用户1发送的信息
|
||||||
async def receive_user_src_message(message: Request):
|
async def receive_user_src_message(message: Req):
|
||||||
global client_ip_src, client_ip_des
|
global client_ip_src, client_ip_des
|
||||||
# kfrag , capsule_ct ,client_ip_src , client_ip_des = json_data[] # 看梁俊勇
|
# kfrag , capsule_ct ,client_ip_src , client_ip_des = json_data[] # 看梁俊勇
|
||||||
"""
|
"""
|
||||||
@ -83,12 +91,11 @@ async def receive_user_src_message(message: Request):
|
|||||||
"rk": rk_list[i],
|
"rk": rk_list[i],
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
print(type(message))
|
||||||
data = await message.json()
|
source_ip = message.source_ip
|
||||||
source_ip = data.get("source_ip")
|
dest_ip = message.dest_ip
|
||||||
dest_ip = data.get("dest_ip")
|
capsule_ct = message.capsule_ct
|
||||||
capsule_ct = data.get("capsule_ct")
|
rk = message.rk
|
||||||
rk = data.get("rk")
|
|
||||||
|
|
||||||
processed_message = ReEncrypt(rk, capsule_ct)
|
processed_message = ReEncrypt(rk, capsule_ct)
|
||||||
await send_user_des_message(source_ip, dest_ip, processed_message)
|
await send_user_des_message(source_ip, dest_ip, processed_message)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user