This commit is contained in:
2023-10-23 17:02:04 +08:00
3 changed files with 19 additions and 17 deletions

View File

@@ -314,22 +314,25 @@ def get_own_ip() -> str:
# get node list from central server
def get_node_list(count: int, server_addr: str):
url = "http://" + server_addr + "/server/send_nodes_list"
payload = {"count": count}
response = requests.post(url, json=payload)
url = "http://" + server_addr + "/server/send_nodes_list?count=" + str(count)
# payload = {"count": count}
# response = requests.post(url, json=payload)
response = requests.get(url)
# Checking the response
if response.status_code == 200:
print("Success get node list")
node_ip = response.text
node_ip = eval(node_ip)
print(node_ip)
# insert node ip to database
with sqlite3.connect("client.db") as db:
db.executemany(
"""
INSERT INTO node
nodeip
VALUE (?)
(nodeip)
VALUES (?)
""",
node_ip,
[(ip,) for ip in node_ip],
)
db.commit()
print("Success add node ip")
@@ -347,4 +350,4 @@ local_ip = get_own_ip()
if __name__ == "__main__":
import uvicorn # pylint: disable=e0401
uvicorn.run("client:app", host="0.0.0.0", port=8003, reload="True")
uvicorn.run("client:app", host="0.0.0.0", port=8003, reload=True)