From f396eaa034dc71e96d73c564701a453fa2c389cf Mon Sep 17 00:00:00 2001 From: sg Date: Sat, 13 May 2023 21:35:51 +0300 Subject: [PATCH 1/4] Update 'README.md' --- README.md | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/README.md b/README.md index 73be878..c4be050 100644 --- a/README.md +++ b/README.md @@ -5,22 +5,4 @@ A relay server is used to help with data transfer. **transphase** - the relay server \ **transmat** - tool to copy files/directories \ -**transplace** - HTTP proxy/exit point - -### How to copy files using ```transmat``` -Transphase relay server should be running and accessible by the parties. -On the sending party: -``` -transmat --send -``` -This will prepare the sender and output the command to run on the receiving party, eg: -``` -transmat --receive --password Space-Time-Continuum -``` - -The sending party will wait for the receiving party to connect to the relay server, and then it will start the transfer. \ -With the exception of some service messages, all the data is encrypted. \ -Encryption and decryption is done only client-side, and the relay server has no useful knowledge of the data it relays. \ -Fernet module (AES128-CBC + HMAC-SHA256) is used to encrypt and authenticate the data. - -See also ```transmat --help``` \ No newline at end of file +**transplace** - HTTP proxy/exit point \ No newline at end of file From be7a22a25f22735867e95b50d0a6461a4c935eeb Mon Sep 17 00:00:00 2001 From: SG Date: Sat, 13 May 2023 20:36:27 +0200 Subject: [PATCH 2/4] Added Readme.md --- transmat/Readme.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 transmat/Readme.md diff --git a/transmat/Readme.md b/transmat/Readme.md new file mode 100644 index 0000000..b5a014e --- /dev/null +++ b/transmat/Readme.md @@ -0,0 +1,17 @@ +### How to copy files using ```transmat``` +Transphase relay server should be running and accessible by the parties. +On the sending party: +``` +transmat --send +``` +This will prepare the sender and output the command to run on the receiving party, eg: +``` +transmat --receive --password Space-Time-Continuum +``` + +The sending party will wait for the receiving party to connect to the relay server, and then it will start the transfer. \ +With the exception of some service messages, all the data is encrypted. \ +Encryption and decryption is done only client-side, and the relay server has no useful knowledge of the data it relays. \ +Fernet module (AES128-CBC + HMAC-SHA256) is used to encrypt and authenticate the data. + +See also ```transmat --help``` \ No newline at end of file From db65f2700f2a63db6264cc53946adf1f9a783ffb Mon Sep 17 00:00:00 2001 From: SG Date: Sun, 14 May 2023 20:40:48 +0200 Subject: [PATCH 3/4] initial reqrite using Quart --- transphase/quartphase.py | 33 +++++++++++++++++++++++++++++++++ transphase/requirements.txt | 6 +----- 2 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 transphase/quartphase.py diff --git a/transphase/quartphase.py b/transphase/quartphase.py new file mode 100644 index 0000000..8d42555 --- /dev/null +++ b/transphase/quartphase.py @@ -0,0 +1,33 @@ +import json +import asyncio +from quart import Quart, websocket + +peer_list = {} + +app = Quart(__name__) + +@app.route("/") +async def retmain(): + return f"Ready to relay\n" + +@app.websocket("/ws") +async def handle_websockets(): + peer_group_id = None + while True: + try: + message = await websocket.receive() + msg = json.loads(message) + if "peer_group_id" in msg: + peer_group_id = msg["peer_group_id"] + if peer_group_id not in peer_list: + peer_list[peer_group_id] = set() + peer_list[peer_group_id].add(websocket._get_current_object()) + for peer in peer_list[peer_group_id]: + if peer != websocket._get_current_object(): + await peer.send(message) + except asyncio.exceptions.CancelledError: + peer_list[peer_group_id].remove(websocket._get_current_object()) + if len(peer_list[peer_group_id]) < 1: + peer_list.pop(peer_group_id) + +app.run() \ No newline at end of file diff --git a/transphase/requirements.txt b/transphase/requirements.txt index 3584239..4b455bc 100644 --- a/transphase/requirements.txt +++ b/transphase/requirements.txt @@ -1,6 +1,2 @@ -asyncio==3.4.3 -cffi==1.15.1 cryptography==40.0.2 -pycparser==2.21 -pyjson==1.3.0 -websockets==11.0.2 \ No newline at end of file +quart \ No newline at end of file From e21c91cbc4854252e5dce358795732dbf3296b3d Mon Sep 17 00:00:00 2001 From: SG Date: Sun, 14 May 2023 21:33:54 +0200 Subject: [PATCH 4/4] Rename files --- transphase/quartphase.py | 33 -------------------- transphase/transphase.py | 65 +++++++++++++--------------------------- 2 files changed, 20 insertions(+), 78 deletions(-) delete mode 100644 transphase/quartphase.py mode change 100755 => 100644 transphase/transphase.py diff --git a/transphase/quartphase.py b/transphase/quartphase.py deleted file mode 100644 index 8d42555..0000000 --- a/transphase/quartphase.py +++ /dev/null @@ -1,33 +0,0 @@ -import json -import asyncio -from quart import Quart, websocket - -peer_list = {} - -app = Quart(__name__) - -@app.route("/") -async def retmain(): - return f"Ready to relay\n" - -@app.websocket("/ws") -async def handle_websockets(): - peer_group_id = None - while True: - try: - message = await websocket.receive() - msg = json.loads(message) - if "peer_group_id" in msg: - peer_group_id = msg["peer_group_id"] - if peer_group_id not in peer_list: - peer_list[peer_group_id] = set() - peer_list[peer_group_id].add(websocket._get_current_object()) - for peer in peer_list[peer_group_id]: - if peer != websocket._get_current_object(): - await peer.send(message) - except asyncio.exceptions.CancelledError: - peer_list[peer_group_id].remove(websocket._get_current_object()) - if len(peer_list[peer_group_id]) < 1: - peer_list.pop(peer_group_id) - -app.run() \ No newline at end of file diff --git a/transphase/transphase.py b/transphase/transphase.py old mode 100755 new mode 100644 index 4586da4..8d42555 --- a/transphase/transphase.py +++ b/transphase/transphase.py @@ -1,58 +1,33 @@ -#!/usr/bin/env python -import asyncio -import websockets -import logging import json - - -logging.basicConfig( - format="%(asctime)s %(message)s", - level=logging.INFO, -) +import asyncio +from quart import Quart, websocket peer_list = {} -class LoggerAdapter(logging.LoggerAdapter): - """Add connection ID and client IP address to websockets logs.""" - def process(self, msg, kwargs): - try: - websocket = kwargs["extra"]["websocket"] - except KeyError: - return msg, kwargs - rip = websocket.remote_address[0] - try: - xff = websocket.request_headers.get("X-Forwarded-For") - except: - xff = "None" - return f"{websocket.id} {rip} {xff}", kwargs +app = Quart(__name__) -async def handler(websocket): +@app.route("/") +async def retmain(): + return f"Ready to relay\n" + +@app.websocket("/ws") +async def handle_websockets(): peer_group_id = None - try: - while not websocket.closed: - message = await websocket.recv() + while True: + try: + message = await websocket.receive() msg = json.loads(message) if "peer_group_id" in msg: peer_group_id = msg["peer_group_id"] if peer_group_id not in peer_list: - peer_list[peer_group_id] = set() # Create new set for all peers in peer_group_id - peer_list[peer_group_id].add(websocket) # Add peer's socket to peer_group + peer_list[peer_group_id] = set() + peer_list[peer_group_id].add(websocket._get_current_object()) for peer in peer_list[peer_group_id]: - if peer != websocket: + if peer != websocket._get_current_object(): await peer.send(message) - except websockets.exceptions.ConnectionClosed as e: - pass - finally: - peer_list[peer_group_id].remove(websocket) - if len(peer_list[peer_group_id]) < 1: - peer_list.pop(peer_group_id) + except asyncio.exceptions.CancelledError: + peer_list[peer_group_id].remove(websocket._get_current_object()) + if len(peer_list[peer_group_id]) < 1: + peer_list.pop(peer_group_id) -async def main(): - async with websockets.serve( - handler, "", 8001, ping_timeout=30, - logger=LoggerAdapter(logging.getLogger("websockets.server"), None), - ): - await asyncio.Future() # run forever - -if __name__ == "__main__": - asyncio.run(main()) \ No newline at end of file +app.run() \ No newline at end of file