Skip to content

Commit

Permalink
[INF-180] Add SOCKS5 proxy for use with client (#3467)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
cheran-senthil authored Jul 15, 2022
1 parent df69fa6 commit e3bb6f5
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dev-tools/audius-compose
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
2 changes: 2 additions & 0 deletions dev-tools/startup/discovery-provider.sh
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
40 changes: 40 additions & 0 deletions dev-tools/startup/socks5-proxy-pac.py
Original file line number Diff line number Diff line change
@@ -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()
6 changes: 4 additions & 2 deletions discovery-provider/scripts/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}';"
Expand All @@ -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
Expand Down
17 changes: 16 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit e3bb6f5

Please sign in to comment.