From e3bb6f52f0dd61899df33bf86e1a2a9a30867add Mon Sep 17 00:00:00 2001 From: Cheran Date: Fri, 15 Jul 2022 12:22:48 -0400 Subject: [PATCH] [INF-180] Add SOCKS5 proxy for use with client (#3467) * Add socks5 proxy for use with client * Fix colon * Remove hot reload of libs * Disable rsyslog * Fix docker ps * Add back sleep * Extend proxy * Hardcode proxy version --- dev-tools/audius-compose | 2 +- dev-tools/startup/discovery-provider.sh | 2 ++ dev-tools/startup/socks5-proxy-pac.py | 40 +++++++++++++++++++++++++ discovery-provider/scripts/start.sh | 6 ++-- docker-compose.yml | 17 ++++++++++- 5 files changed, 63 insertions(+), 4 deletions(-) create mode 100644 dev-tools/startup/socks5-proxy-pac.py diff --git a/dev-tools/audius-compose b/dev-tools/audius-compose index 6a3cbf95725..1262ee13008 100755 --- a/dev-tools/audius-compose +++ b/dev-tools/audius-compose @@ -203,7 +203,7 @@ def ps(protocol_dir): if service["Publishers"]: for publisher in service["Publishers"]: if publisher["PublishedPort"]: - ports[publisher["TargetPort"]] = publisher["PublishedPort"] + ports[publisher["PublishedPort"]] = publisher["TargetPort"] if service["Service"] == "creator-node": name = f"{service['Service']}-{replica}" diff --git a/dev-tools/startup/discovery-provider.sh b/dev-tools/startup/discovery-provider.sh index bb557480e3b..5138d955e43 100644 --- a/dev-tools/startup/discovery-provider.sh +++ b/dev-tools/startup/discovery-provider.sh @@ -1,5 +1,7 @@ #!/usr/bin/env sh +export audius_enable_rsyslog=false + export audius_discprov_url="http://$(hostname -i):5000" export audius_delegate_owner_wallet=$(printenv "DP${replica}_DELEGATE_OWNER_ADDRESS") diff --git a/dev-tools/startup/socks5-proxy-pac.py b/dev-tools/startup/socks5-proxy-pac.py new file mode 100644 index 00000000000..cab5b340874 --- /dev/null +++ b/dev-tools/startup/socks5-proxy-pac.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python + +import socket +import http +import http.server + +IP_ADDRESS = socket.gethostbyname(socket.gethostname()) +TLD = socket.getfqdn().split(".")[-1] + +PAC_TEMPLATE = """ +function FindProxyForURL(url, host) {{ + if (isInNet(host, "{ip}", "255.255.0.0") || host.endsWith("{tld}") || !host.includes(".")) {{ + return "SOCKS5 {proxy_host}:1080" + }} + + return "DIRECT"; +}} +""" + + +class Handler(http.server.BaseHTTPRequestHandler): + def do_GET(self): + self.send_response(http.HTTPStatus.OK) + self.send_header("Content-type", "application/x-ns-proxy-autoconfig") + self.end_headers() + + pac = PAC_TEMPLATE.format( + ip=IP_ADDRESS, tld=TLD, proxy_host=self.headers["Host"].split(":")[0] + ) + + self.wfile.write(pac.encode()) + + +def main(): + httpd = http.server.HTTPServer(("", 80), Handler) + httpd.serve_forever() + + +if __name__ == "__main__": + main() diff --git a/discovery-provider/scripts/start.sh b/discovery-provider/scripts/start.sh index d2abf151be3..9ad56fdcc60 100755 --- a/discovery-provider/scripts/start.sh +++ b/discovery-provider/scripts/start.sh @@ -81,10 +81,10 @@ if [ -z "$audius_db_url" ]; then sudo -u postgres pg_ctl init -D /db echo "host all all 0.0.0.0/0 md5" >>/db/pg_hba.conf echo "listen_addresses = '*'" >>/db/postgresql.conf - sudo -u postgres pg_ctl start -D /db -o "-c shared_buffers=512MB" -o "-c shared_preload_libraries=pg_stat_statements" + sudo -u postgres pg_ctl start -D /db -o "-c shared_preload_libraries=pg_stat_statements" sudo -u postgres createdb audius_discovery else - sudo -u postgres pg_ctl start -D /db -o "-c shared_buffers=512MB" -o "-c shared_preload_libraries=pg_stat_statements" + sudo -u postgres pg_ctl start -D /db -o "-c shared_preload_libraries=pg_stat_statements" fi sudo -u postgres psql -c "ALTER USER postgres PASSWORD '${postgres_password:-postgres}';" @@ -108,6 +108,8 @@ if [ "$audius_db_run_migrations" != false ]; then export PYTHONPATH='.' alembic upgrade head echo "Finished running migrations" + + sleep 20 fi # start es-indexer diff --git a/docker-compose.yml b/docker-compose.yml index 80af900078a..60ebd66cbca 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -145,7 +145,7 @@ services: build-audius-libs: build: libs - command: sh -c "cp scripts/AudiusClaimDistributor.json scripts/Wormhole.json eth-contracts/ABIs/ && npm run dev" + command: sh -c "cp scripts/AudiusClaimDistributor.json scripts/Wormhole.json eth-contracts/ABIs/" volumes: - audius-libs:/usr/src/app - poa-contracts-abis:/usr/src/app/data-contracts/ABIs @@ -348,6 +348,21 @@ services: deploy: mode: global + # SOCKS5 proxy for use with client + + socks5-proxy: + image: serjs/go-socks5-proxy:v0.0.3 + ports: + - "1080:1080" + + socks5-proxy-pac: + image: python:3.10.5 + command: sh -c "head -n-1 /etc/hosts > /etc/hosts && python /tmp/dev-tools/startup/socks5-proxy-pac.py" + ports: + - "8080:80" + volumes: + - ./dev-tools:/tmp/dev-tools + volumes: poa-contracts-abis: eth-contracts-abis: