main #22

Merged
ccyj merged 68 commits from sangge/tpre-python:main into main 2023-10-26 14:45:47 +08:00
3 changed files with 44 additions and 31 deletions
Showing only changes of commit 9fb1d4bf14 - Show all commits

View File

@ -16,13 +16,31 @@ jobs:
- name: copy file via ssh password - name: copy file via ssh password
uses: appleboy/scp-action@v0.1.4 uses: cross-the-world/scp-pipeline@master
with: with:
host: "110.41.155.96,110.41.130.197,110.41.21.35" host: "110.41.155.96"
username: ${{ secrets.USERNAME }} user: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }} pass: ${{ secrets.PASSWORD }}
source: "src/server.py,src/client.py,src/node.py" local: "src/*"
target: "/root/mimajingsai/src/" remote: /root/mimajingsai/src/
- name: copy file via ssh password
uses: cross-the-world/scp-pipeline@master
with:
host: "110.41.130.197"
user: ${{ secrets.USERNAME }}
pass: ${{ secrets.PASSWORD }}
local: "src/*"
remote: /root/mimajingsai/src/
- name: copy file via ssh password
uses: cross-the-world/scp-pipeline@master
with:
host: "110.41.21.35"
user: ${{ secrets.USERNAME }}
pass: ${{ secrets.PASSWORD }}
local: "src/*"
remote: /root/mimajingsai/src/

View File

@ -16,3 +16,5 @@ tpre3: docker run -it -p 8000:8000 -p 8001:8001 -p 8002:8002 -v ~/mimajingsai:/a
110.41.155.96 tpre1 110.41.155.96 tpre1
110.41.130.197 tpre2 110.41.130.197 tpre2
110.41.21.35 tpre3 110.41.21.35 tpre3
python client_cli.py 110.41.21.35 aaa

View File

@ -127,6 +127,9 @@ async def receive_messages(message: C):
# insert record into database # insert record into database
with sqlite3.connect("client.db") as db: with sqlite3.connect("client.db") as db:
try: try:
print("bin:", bin_C_capsule)
print("ct:", C_ct)
print("ip:", ip)
db.execute( db.execute(
""" """
INSERT INTO message INSERT INTO message
@ -134,7 +137,7 @@ async def receive_messages(message: C):
VALUES VALUES
(?, ?, ?) (?, ?, ?)
""", """,
(bin_C_capsule, C_ct, ip), (bin_C_capsule, str(C_ct), ip),
) )
db.commit() db.commit()
await check_merge(C_ct, ip) await check_merge(C_ct, ip)
@ -149,6 +152,8 @@ async def receive_messages(message: C):
async def check_merge(ct: int, ip: str): async def check_merge(ct: int, ip: str):
global sk, pk, node_response, message global sk, pk, node_response, message
with sqlite3.connect("client.db") as db: with sqlite3.connect("client.db") as db:
print("str(ct):", str(ct))
print("ip:", ip)
# Check if the combination of ct_column and ip_column appears more than once. # Check if the combination of ct_column and ip_column appears more than once.
cursor = db.execute( cursor = db.execute(
""" """
@ -156,21 +161,23 @@ async def check_merge(ct: int, ip: str):
FROM message FROM message
WHERE ct = ? AND senderip = ? WHERE ct = ? AND senderip = ?
""", """,
(ct, ip), (str(ct), ip),
) )
# [(capsule, ct), ...] # [(capsule, ct), ...]
cfrag_cts = cursor.fetchall() cfrag_cts = cursor.fetchall()
print("ip", type(ip))
# get T # get T
cursor = db.execute( cursor = db.execute(
""" """
SELECT publickey, threshold SELECT publickey, threshold
FROM senderinfo FROM senderinfo
WHERE senderip = ? WHERE ip = ?
""", """,
(ip), (ip),
) )
result = cursor.fetchall() result = cursor.fetchall()
print("maybe error here?")
pk_sender, T = result[0] # result[0] = (pk, threshold) pk_sender, T = result[0] # result[0] = (pk, threshold)
if len(cfrag_cts) >= T: if len(cfrag_cts) >= T:
@ -178,7 +185,7 @@ async def check_merge(ct: int, ip: str):
temp_cfrag_cts = [] temp_cfrag_cts = []
for i in cfrag_cts: for i in cfrag_cts:
capsule = pickle.loads(i[0]) capsule = pickle.loads(i[0])
temp_cfrag_cts.append((capsule, i[1])) temp_cfrag_cts.append((capsule, int(i[1])))
cfrags = mergecfrag(temp_cfrag_cts) cfrags = mergecfrag(temp_cfrag_cts)
message = DecryptFrags(sk, pk, pk_sender, cfrags) # type: ignore message = DecryptFrags(sk, pk, pk_sender, cfrags) # type: ignore
@ -258,20 +265,6 @@ async def request_message(i_m: Request_Message):
except: except:
print("can't post") print("can't post")
return {"message": "can't post"} return {"message": "can't post"}
if response.status_code == 200:
data = response.json()
public_key = int(data["public_key"])
threshold = int(data["threshold"])
with sqlite3.connect("client.db") as db:
db.execute(
"""
INSERT INTO senderinfo
(public_key, threshold)
VALUES
(?, ?)
""",
(public_key, threshold),
)
try: try:
if response.status_code == 200: if response.status_code == 200:
@ -283,11 +276,11 @@ async def request_message(i_m: Request_Message):
db.execute( db.execute(
""" """
INSERT INTO senderinfo INSERT INTO senderinfo
(public_key, threshold) (ip, public_key, threshold)
VALUES VALUES
(?, ?) (?, ?, ?)
""", """,
(public_key, threshold), (str(dest_ip), public_key, threshold),
) )
except: except:
print("Database error") print("Database error")