diff --git a/.gitea/workflows/ci.yaml b/.gitea/workflows/ci.yaml index a823d44..bcd41a8 100644 --- a/.gitea/workflows/ci.yaml +++ b/.gitea/workflows/ci.yaml @@ -16,13 +16,31 @@ jobs: - name: copy file via ssh password - uses: appleboy/scp-action@v0.1.4 + uses: cross-the-world/scp-pipeline@master with: - host: "110.41.155.96,110.41.130.197,110.41.21.35" - username: ${{ secrets.USERNAME }} - password: ${{ secrets.PASSWORD }} - source: "src/server.py,src/client.py,src/node.py" - target: "/root/mimajingsai/src/" + host: "110.41.155.96" + 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.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/ diff --git a/doc/README_app_en.md b/doc/README_app_en.md index 839dda2..dc3b4df 100644 --- a/doc/README_app_en.md +++ b/doc/README_app_en.md @@ -15,4 +15,6 @@ tpre3: docker run -it -p 8000:8000 -p 8001:8001 -p 8002:8002 -v ~/mimajingsai:/a 110.41.155.96 tpre1 110.41.130.197 tpre2 -110.41.21.35 tpre3 \ No newline at end of file +110.41.21.35 tpre3 + +python client_cli.py 110.41.21.35 aaa \ No newline at end of file diff --git a/src/client.py b/src/client.py index 965a21b..87afa04 100644 --- a/src/client.py +++ b/src/client.py @@ -114,19 +114,22 @@ async def receive_messages(message: C): return: status_code """ - + if not message.Tuple or not message.ip: raise HTTPException(status_code=400, detail="Invalid input data") C_capsule, C_ct = message.Tuple ip = message.ip - + # Serialization bin_C_capsule = pickle.dumps(C_capsule) # insert record into database with sqlite3.connect("client.db") as db: try: + print("bin:", bin_C_capsule) + print("ct:", C_ct) + print("ip:", ip) db.execute( """ INSERT INTO message @@ -134,7 +137,7 @@ async def receive_messages(message: C): VALUES (?, ?, ?) """, - (bin_C_capsule, C_ct, ip), + (bin_C_capsule, str(C_ct), ip), ) db.commit() await check_merge(C_ct, ip) @@ -149,6 +152,8 @@ async def receive_messages(message: C): async def check_merge(ct: int, ip: str): global sk, pk, node_response, message 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. cursor = db.execute( """ @@ -156,21 +161,23 @@ async def check_merge(ct: int, ip: str): FROM message WHERE ct = ? AND senderip = ? """, - (ct, ip), + (str(ct), ip), ) # [(capsule, ct), ...] cfrag_cts = cursor.fetchall() + print("ip", type(ip)) # get T cursor = db.execute( """ SELECT publickey, threshold FROM senderinfo - WHERE senderip = ? + WHERE ip = ? """, (ip), ) result = cursor.fetchall() + print("maybe error here?") pk_sender, T = result[0] # result[0] = (pk, threshold) if len(cfrag_cts) >= T: @@ -178,8 +185,8 @@ async def check_merge(ct: int, ip: str): temp_cfrag_cts = [] for i in cfrag_cts: 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) message = DecryptFrags(sk, pk, pk_sender, cfrags) # type: ignore node_response = True @@ -258,20 +265,6 @@ async def request_message(i_m: Request_Message): except: print("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: if response.status_code == 200: @@ -283,11 +276,11 @@ async def request_message(i_m: Request_Message): db.execute( """ INSERT INTO senderinfo - (public_key, threshold) + (ip, public_key, threshold) VALUES - (?, ?) + (?, ?, ?) """, - (public_key, threshold), + (str(dest_ip), public_key, threshold), ) except: print("Database error")