forked from sangge/tpre-python
Merge branch 'sangge-main'
This commit is contained in:
commit
a6588cde0e
@ -1,3 +1,4 @@
|
|||||||
gmssl-python
|
gmssl-python
|
||||||
fastapi
|
fastapi
|
||||||
uvicorn
|
uvicorn
|
||||||
|
requests
|
@ -212,7 +212,7 @@ class IP_Message(BaseModel):
|
|||||||
dest_ip: str
|
dest_ip: str
|
||||||
message_name: str
|
message_name: str
|
||||||
source_ip: str
|
source_ip: str
|
||||||
pk: int
|
pk: Tuple[int, int]
|
||||||
|
|
||||||
|
|
||||||
class Request_Message(BaseModel):
|
class Request_Message(BaseModel):
|
||||||
@ -301,7 +301,7 @@ async def recieve_request(i_m: IP_Message):
|
|||||||
if source_ip != i_m.dest_ip:
|
if source_ip != i_m.dest_ip:
|
||||||
return HTTPException(status_code=400, detail="Wrong ip")
|
return HTTPException(status_code=400, detail="Wrong ip")
|
||||||
dest_ip = i_m.source_ip
|
dest_ip = i_m.source_ip
|
||||||
threshold = random.randrange(1, 6)
|
threshold = random.randrange(1, 2)
|
||||||
own_public_key = pk
|
own_public_key = pk
|
||||||
pk_B = i_m.pk
|
pk_B = i_m.pk
|
||||||
|
|
||||||
@ -320,7 +320,7 @@ async def recieve_request(i_m: IP_Message):
|
|||||||
message = b"hello world" + random.randbytes(8)
|
message = b"hello world" + random.randbytes(8)
|
||||||
|
|
||||||
# send message to nodes
|
# send message to nodes
|
||||||
await send_messages(node_ips, message, dest_ip, pk_B, threshold) # type: ignore
|
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}
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
@ -35,6 +35,7 @@ def init():
|
|||||||
|
|
||||||
|
|
||||||
def clean_env():
|
def clean_env():
|
||||||
|
clear_database()
|
||||||
# 关闭游标和连接
|
# 关闭游标和连接
|
||||||
cursor.close()
|
cursor.close()
|
||||||
conn.close()
|
conn.close()
|
||||||
@ -99,7 +100,7 @@ async def delete_node(ip: str) -> None:
|
|||||||
|
|
||||||
|
|
||||||
# 接收节点心跳包
|
# 接收节点心跳包
|
||||||
@app.post("/server/heartbeat")
|
@app.get("/server/heartbeat")
|
||||||
async def receive_heartbeat(ip: str):
|
async def receive_heartbeat(ip: str):
|
||||||
cursor.execute(
|
cursor.execute(
|
||||||
"UPDATE nodes SET last_heartbeat = ? WHERE ip = ?", (time.time(), ip)
|
"UPDATE nodes SET last_heartbeat = ? WHERE ip = ?", (time.time(), ip)
|
||||||
@ -109,7 +110,7 @@ async def receive_heartbeat(ip: str):
|
|||||||
|
|
||||||
async def receive_heartbeat_internal():
|
async def receive_heartbeat_internal():
|
||||||
while 1:
|
while 1:
|
||||||
timeout = 70
|
timeout = 7
|
||||||
# 删除超时的节点
|
# 删除超时的节点
|
||||||
# cursor.execute("DELETE FROM nodes WHERE last_heartbeat < ?", (time.time() - timeout,))
|
# cursor.execute("DELETE FROM nodes WHERE last_heartbeat < ?", (time.time() - timeout,))
|
||||||
# conn.commit()
|
# conn.commit()
|
||||||
@ -137,8 +138,8 @@ async def send_nodes_list(count: int) -> list:
|
|||||||
return nodes_list
|
return nodes_list
|
||||||
|
|
||||||
|
|
||||||
@app.get("/server/clear_database")
|
# @app.get("/server/clear_database")
|
||||||
async def clear_database() -> None:
|
def clear_database() -> None:
|
||||||
cursor.execute("DELETE FROM nodes")
|
cursor.execute("DELETE FROM nodes")
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user