From badeaa8ac368574c39b32a53f01aa59c61e8b698 Mon Sep 17 00:00:00 2001 From: ading2210 Date: Tue, 16 Jan 2024 00:25:29 -0500 Subject: [PATCH] use wisp server instead of wsproxy --- .gitmodules | 5 +++- README.md | 6 ++--- server/main.py | 55 ----------------------------------------- server/requirements.txt | 1 - server/run.sh | 1 + server/wisp_server | 1 + 6 files changed, 9 insertions(+), 60 deletions(-) delete mode 100644 server/main.py delete mode 100644 server/requirements.txt create mode 160000 server/wisp_server diff --git a/.gitmodules b/.gitmodules index ae9314b..46e8a75 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "client/wisp_client"] path = client/wisp_client - url = https://github.com/mercuryWorkshop/wisp-client-js + url = https://github.com/MercuryWorkshop/wisp-client-js +[submodule "server/wisp_server"] + path = server/wisp_server + url = https://github.com/MercuryWorkshop/wisp-server-python diff --git a/README.md b/README.md index 031a1cb..db1997d 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ This is an experimental port of [libcurl](https://curl.se/libcurl/) to WebAssemb ## Building: You can build this project by running the following commands: ``` -git clone https://github.com/ading2210/libcurl.js +git clone https://github.com/ading2210/libcurl.js --recursive cd libcurl.js/client ./build.sh ``` @@ -48,11 +48,11 @@ libcurl.set_websocket("ws://localhost:6001/"); ``` ## Proxy Server: -The proxy server consists of a [SOCKS5 proxy server](https://github.com/Amaindex/asyncio-socks-server) behind a [websocket TCP proxy](https://github.com/novnc/websockify). +The proxy server consists of a standard [Wisp](https://github.com/MercuryWorkshop/wisp-protocol) server, allowing multiple TCP connections to share the same websocket. To host the proxy server, run the following commands: ``` -git clone https://github.com/ading2210/libcurl.js +git clone https://github.com/ading2210/libcurl.js --recursive cd libcurl.js/server ./run.sh ``` diff --git a/server/main.py b/server/main.py deleted file mode 100644 index 68d84be..0000000 --- a/server/main.py +++ /dev/null @@ -1,55 +0,0 @@ -import asyncio -from websockets.server import serve -from websockets.exceptions import ConnectionClosed - -buffer_size = 1024*1024 - -class Connection: - def __init__(self, ws, path): - self.ws = ws - self.path = path - - async def setup_connection(self): - addr_str = self.path.split("/")[-1] - self.tcp_host, self.tcp_port = addr_str.split(":") - self.tcp_port = int(self.tcp_port) - - self.tcp_reader, self.tcp_writer = await asyncio.open_connection(host=self.tcp_host, port=self.tcp_port, limit=buffer_size) - - async def handle_ws(self): - while True: - try: - data = await self.ws.recv() - except ConnectionClosed: - break - self.tcp_writer.write(data) - await self.tcp_writer.drain() - print("sent data to tcp") - - self.tcp_writer.close() - - async def handle_tcp(self): - while True: - data = await self.tcp_reader.read(buffer_size) - if len(data) == 0: - break #socket closed - await self.ws.send(data) - print("sent data to ws") - - await self.ws.close() - -async def connection_handler(websocket, path): - print("incoming connection from "+path) - connection = Connection(websocket, path) - await connection.setup_connection() - ws_handler = asyncio.create_task(connection.handle_ws()) - tcp_handler = asyncio.create_task(connection.handle_tcp()) - - await asyncio.gather(ws_handler, tcp_handler) - -async def main(): - async with serve(connection_handler, "127.0.0.1", 6001, subprotocols=["binary"]): - await asyncio.Future() - -if __name__ == "__main__": - asyncio.run(main()) diff --git a/server/requirements.txt b/server/requirements.txt deleted file mode 100644 index 7a38911..0000000 --- a/server/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -websockets \ No newline at end of file diff --git a/server/run.sh b/server/run.sh index ca6acd2..4f3cfeb 100755 --- a/server/run.sh +++ b/server/run.sh @@ -4,6 +4,7 @@ set -e +cd wisp_server if [ ! -d ".venv" ]; then python3 -m venv .venv fi diff --git a/server/wisp_server b/server/wisp_server new file mode 160000 index 0000000..8747346 --- /dev/null +++ b/server/wisp_server @@ -0,0 +1 @@ +Subproject commit 874734623e4dfc4652b34a1bc61e1e35ca86dee8