This commit is contained in:
sangge 2023-10-23 22:21:16 +08:00
commit e304771743
2 changed files with 7 additions and 6 deletions

View File

@ -213,7 +213,7 @@ class IP_Message(BaseModel):
dest_ip: str
message_name: str
source_ip: str
pk: int
pk: Tuple[int, int]
class Request_Message(BaseModel):
@ -305,7 +305,7 @@ async def recieve_request(i_m: IP_Message):
message = b"hello world" + random.randbytes(8)
# 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}
return response

View File

@ -29,6 +29,7 @@ def init():
asyncio.create_task(receive_heartbeat_internal())
def clean_env():
clear_database()
# 关闭游标和连接
cursor.close()
conn.close()
@ -93,7 +94,7 @@ async def receive_heartbeat(ip: str):
async def receive_heartbeat_internal():
while 1:
timeout = 70
timeout = 7
# 删除超时的节点
# cursor.execute("DELETE FROM nodes WHERE last_heartbeat < ?", (time.time() - timeout,))
# conn.commit()
@ -120,12 +121,12 @@ async def send_nodes_list(count: int) -> list:
return nodes_list
@app.get("/server/clear_database")
async def clear_database() -> None:
# @app.get("/server/clear_database")
def clear_database() -> None:
cursor.execute("DELETE FROM nodes")
conn.commit()
if __name__ == "__main__":
import uvicorn # pylint: disable=e0401
uvicorn.run("server:app", host="0.0.0.0", port=8000, reload=True)
uvicorn.run("server:app", host="0.0.0.0", port=8000, reload=True)