diff --git a/DOCKER_VERSION b/DOCKER_VERSION index eab246c0..44e98ada 100644 --- a/DOCKER_VERSION +++ b/DOCKER_VERSION @@ -1 +1 @@ -7.3.2 +7.3.3 diff --git a/Dockerfile b/Dockerfile index ab6dda67..26257ce3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,6 +19,7 @@ RUN [ "make", "ws_install" ] FROM alpine as runtime RUN apk add --no-cache libstdc++ +RUN apk add --no-cache strace RUN addgroup -S app && adduser -S -G app app COPY --chown=app:app --from=build /usr/local/bin/ws /usr/local/bin/ws diff --git a/docker-compose.yml b/docker-compose.yml index 39268775..66d14b9a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,43 +1,59 @@ version: "3" services: - snake: - image: bsergean/ws:build - entrypoint: ws snake --port 8765 --host 0.0.0.0 --redis_hosts redis1 + # snake: + # image: bsergean/ws:build + # entrypoint: ws snake --port 8767 --host 0.0.0.0 --redis_hosts redis1 + # ports: + # - "8767:8767" + # networks: + # - ws-net + # depends_on: + # - redis1 + + # proxy: + # image: bsergean/ws:build + # entrypoint: strace ws proxy_server --remote_host 'wss://cobra.addsrv.com' --host 0.0.0.0 --port 8765 -v + # ports: + # - "8765:8765" + # networks: + # - ws-net + + pyproxy: + image: bsergean/ws_proxy:build + entrypoint: /usr/bin/ws_proxy.py --remote_url 'wss://cobra.addsrv.com' --host 0.0.0.0 --port 8765 ports: - "8765:8765" networks: - ws-net - depends_on: - - redis1 - ws: - security_opt: - - seccomp:unconfined - cap_add: - - SYS_PTRACE - stdin_open: true - tty: true - image: bsergean/ws:build - entrypoint: bash - networks: - - ws-net - depends_on: - - redis1 - - redis1: - image: redis:alpine - networks: - - ws-net - - statsd: - image: jaconel/statsd - ports: - - "8125:8125" - environment: - - STATSD_DUMP_MSG=true - - GRAPHITE_HOST=127.0.0.1 - networks: - - ws-net + # ws: + # security_opt: + # - seccomp:unconfined + # cap_add: + # - SYS_PTRACE + # stdin_open: true + # tty: true + # image: bsergean/ws:build + # entrypoint: sh + # networks: + # - ws-net + # depends_on: + # - redis1 + # + # redis1: + # image: redis:alpine + # networks: + # - ws-net + # + # statsd: + # image: jaconel/statsd + # ports: + # - "8125:8125" + # environment: + # - STATSD_DUMP_MSG=true + # - GRAPHITE_HOST=127.0.0.1 + # networks: + # - ws-net networks: ws-net: diff --git a/ixwebsocket/IXWebSocketVersion.h b/ixwebsocket/IXWebSocketVersion.h index 9e8f6893..2de2ede4 100644 --- a/ixwebsocket/IXWebSocketVersion.h +++ b/ixwebsocket/IXWebSocketVersion.h @@ -6,4 +6,4 @@ #pragma once -#define IX_WEBSOCKET_VERSION "7.3.1" +#define IX_WEBSOCKET_VERSION "7.3.3" diff --git a/makefile b/makefile index 1fd6f47d..ca3493eb 100644 --- a/makefile +++ b/makefile @@ -57,6 +57,7 @@ docker: docker_push: docker tag ${IMG} ${LATEST} docker push ${LATEST} + docker push ${IMG} run: docker run --cap-add sys_ptrace --entrypoint=sh -it bsergean/ws:build diff --git a/test/compatibility/python/websockets/DOCKER_VERSION b/test/compatibility/python/websockets/DOCKER_VERSION new file mode 100644 index 00000000..8acdd82b --- /dev/null +++ b/test/compatibility/python/websockets/DOCKER_VERSION @@ -0,0 +1 @@ +0.0.1 diff --git a/test/compatibility/python/websockets/Dockerfile b/test/compatibility/python/websockets/Dockerfile new file mode 100644 index 00000000..016e3f23 --- /dev/null +++ b/test/compatibility/python/websockets/Dockerfile @@ -0,0 +1,8 @@ +FROM python:3.8.0-alpine3.10 + +RUN pip install websockets +COPY ws_proxy.py /usr/bin +RUN chmod +x /usr/bin/ws_proxy.py + +EXPOSE 8765 +CMD ["python", "/usr/bin/ws_proxy.py"] diff --git a/test/compatibility/python/websockets/makefile b/test/compatibility/python/websockets/makefile new file mode 100644 index 00000000..018430ad --- /dev/null +++ b/test/compatibility/python/websockets/makefile @@ -0,0 +1,20 @@ +.PHONY: docker + +NAME := bsergean/ws_proxy +TAG := $(shell cat DOCKER_VERSION) +IMG := ${NAME}:${TAG} +LATEST := ${NAME}:latest +BUILD := ${NAME}:build + +docker_test: + docker build -t ${BUILD} . + +docker: + git clean -dfx + docker build -t ${IMG} . + docker tag ${IMG} ${BUILD} + +docker_push: + docker tag ${IMG} ${LATEST} + docker push ${LATEST} + docker push ${IMG} diff --git a/test/compatibility/python/websockets/ws_proxy.py b/test/compatibility/python/websockets/ws_proxy.py new file mode 100644 index 00000000..6956f46f --- /dev/null +++ b/test/compatibility/python/websockets/ws_proxy.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python3 + +# WS server example + +import argparse +import asyncio +import websockets + + +async def hello(websocket, path): + + url = REMOTE_URL + path + async with websockets.connect(url) as ws: + taskA = asyncio.create_task(clientToServer(ws, websocket)) + taskB = asyncio.create_task(serverToClient(ws, websocket)) + + await taskA + await taskB + + +async def clientToServer(ws, websocket): + async for message in ws: + await websocket.send(message) + + +async def serverToClient(ws, websocket): + async for message in websocket: + await ws.send(message) + + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description='websocket proxy.') + parser.add_argument('--host', help='Host to bind to.', default='localhost') + parser.add_argument('--port', help='Port to bind to.', default=8765) + parser.add_argument('--remote_url', help='Remote websocket url', default='ws://localhost:8767') + args = parser.parse_args() + + REMOTE_URL = args.remote_url + + start_server = websockets.serve(hello, args.host, args.port) + + asyncio.get_event_loop().run_until_complete(start_server) + asyncio.get_event_loop().run_forever() diff --git a/ws/ws_proxy_server.cpp b/ws/ws_proxy_server.cpp index f0ccd712..c576affb 100644 --- a/ws/ws_proxy_server.cpp +++ b/ws/ws_proxy_server.cpp @@ -65,14 +65,13 @@ namespace ix if (msg->type == ix::WebSocketMessageType::Open) { std::cerr << "New connection" << std::endl; - std::cerr << "id: " << state->getId() << std::endl; + std::cerr << "server id: " << state->getId() << std::endl; std::cerr << "Uri: " << msg->openInfo.uri << std::endl; std::cerr << "Headers:" << std::endl; for (auto it : msg->openInfo.headers) { std::cerr << it.first << ": " << it.second << std::endl; } - state->setConnected(); } else if (msg->type == ix::WebSocketMessageType::Close) { @@ -80,6 +79,7 @@ namespace ix << " code " << msg->closeInfo.code << " reason " << msg->closeInfo.reason << std::endl; webSocket->close(msg->closeInfo.code, msg->closeInfo.reason); + state->setTerminated(); } else if (msg->type == ix::WebSocketMessageType::Error) { @@ -108,7 +108,7 @@ namespace ix if (msg->type == ix::WebSocketMessageType::Open) { std::cerr << "New connection" << std::endl; - std::cerr << "id: " << state->getId() << std::endl; + std::cerr << "client id: " << state->getId() << std::endl; std::cerr << "Uri: " << msg->openInfo.uri << std::endl; std::cerr << "Headers:" << std::endl; for (auto it : msg->openInfo.headers) @@ -124,10 +124,12 @@ namespace ix // we should sleep here for a bit until we've established the // connection with the remote server - while (!state->isConnected()) + while (state->webSocket().getReadyState() != ReadyState::Open) { + std::cerr << "waiting for server connection establishment" << std::endl; std::this_thread::sleep_for(std::chrono::milliseconds(10)); } + std::cerr << "server connection established" << std::endl; } else if (msg->type == ix::WebSocketMessageType::Close) {