Merge pull request 'main' (#16) from dqy/mimajingsai:main into main

Reviewed-on: sangge/mimajingsai#16
This commit is contained in:
sangge 2023-10-23 14:10:12 +08:00
commit 063d13a405
2 changed files with 7 additions and 12 deletions

View File

@ -2,11 +2,9 @@ from fastapi import FastAPI
from fastapi.encoders import jsonable_encoder
from fastapi.responses import JSONResponse
from contextlib import asynccontextmanager
from typing import Tuple, Callable
import sqlite3
import asyncio
import time
import random
@asynccontextmanager
async def lifespan(app: FastAPI):
@ -28,7 +26,7 @@ cursor.execute('''CREATE TABLE IF NOT EXISTS nodes (
)''')
def init():
task = asyncio.create_task(receive_heartbeat_internal())
asyncio.create_task(receive_heartbeat_internal())
def clean_env():
# 关闭游标和连接
@ -93,16 +91,13 @@ async def receive_heartbeat(ip: str):
cursor.execute("UPDATE nodes SET last_heartbeat = ? WHERE ip = ?", (time.time(), ip))
return {"status": "received"}
async def receive_heartbeat_internal() -> int:
async def receive_heartbeat_internal():
while 1:
print('successful delete1')
timeout = 10
timeout = 70
# 删除超时的节点
cursor.execute("DELETE FROM nodes WHERE last_heartbeat < ?", (time.time() - timeout,))
conn.commit()
print('successful delete')
await asyncio.sleep(timeout)
return 1
@app.get("/server/send_nodes_list")
async def send_nodes_list(count: int) -> JSONResponse:

View File

@ -272,7 +272,7 @@ def f(x: int, f_modulus: list, T: int) -> int:
return res
def GenerateReKey(sk_A: int, pk_B: point, N: int, T: int) -> list:
def GenerateReKey(sk_A: int, pk_B: point, N: int, T: int, id_tuple: Tuple[int,...]) -> list:
"""
param:
skA, pkB, N(节点总数), T(阈值)
@ -288,7 +288,7 @@ def GenerateReKey(sk_A: int, pk_B: point, N: int, T: int) -> list:
# d是Bob的密钥对与临时密钥对的非交互式Diffie-Hellman密钥交换的结果
d = hash3((X_A, pk_B, multiply(pk_B, x_A)))
# 计算多项式系数, 确定代理节点的ID(一个点)
# 计算多项式系数
f_modulus = []
# 计算f0
# f0 = (sk_A * inv(d, G.P)) % G.P
@ -305,10 +305,10 @@ def GenerateReKey(sk_A: int, pk_B: point, N: int, T: int) -> list:
for i in range(N):
y = random.randint(0, sm2p256v1.N - 1)
Y = multiply(g, y)
s_x = hash5(i, D) # id需要设置
s_x = hash5(id_tuple[i], D) # id需要设置
r_k = f(s_x, f_modulus, T)
U1 = multiply(U, r_k)
kFrag = (i, r_k, X_A, U1)
kFrag = (id_tuple[i], r_k, X_A, U1)
KF.append(kFrag)
return KF