From 810e21d7d31b1394da7e10fd0c21a499d1577bae Mon Sep 17 00:00:00 2001 From: Aaron Fiore Date: Wed, 4 Feb 2026 15:29:41 -0800 Subject: [PATCH 1/8] client: plugins: tor: refactor check for running `dfi` instance --- client/plugins/docker/tor.bash | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/client/plugins/docker/tor.bash b/client/plugins/docker/tor.bash index b2c4645..71339e3 100755 --- a/client/plugins/docker/tor.bash +++ b/client/plugins/docker/tor.bash @@ -44,10 +44,9 @@ function tor::start() # NOTE: proxychains.conf's [ProxyList] won't allow hostnames (or Docker network container name). # So, to avoid conflicting IP address spaces, docker-finance will not hardcode address space. - # Ergo, a already-running container will be needed (sorry, lib_docker::run()) - if ! docker container inspect -f '{{.State.Running}}' "$global_container" &>/dev/null; then - lib_utils::die_fatal "docker-finance not running! Bring \`up\` container and try again." - fi + # Ergo, an already-running container will be needed (sorry, lib_docker::run()) + lib_docker::exec "" \ + || lib_utils::die_fatal "docker-finance not running! Bring \`up\` a \`dfi\` instance and try again." local -r _torrc="/etc/tor/torrc" From 56ba75e7909012e42474eb493577f4112b8c3d01 Mon Sep 17 00:00:00 2001 From: Aaron Fiore Date: Wed, 4 Feb 2026 15:34:31 -0800 Subject: [PATCH 2/8] client: plugins: tor: fix inspection for running tor container --- client/plugins/docker/tor.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/plugins/docker/tor.bash b/client/plugins/docker/tor.bash index 71339e3..643c1a7 100755 --- a/client/plugins/docker/tor.bash +++ b/client/plugins/docker/tor.bash @@ -50,7 +50,7 @@ function tor::start() local -r _torrc="/etc/tor/torrc" - if docker container inspect -f '{{.State.Running}}' "$tor_container" &>/dev/null; then + if [[ $(docker container inspect -f '{{.State.Running}}' "$tor_container" 2>/dev/null) == "true" ]]; then lib_utils::print_error "${tor_container}: instance already running (consider \`restart\`)" return 1 else From 890c063130a3f72cf8d0ddcc4d860b720b274764 Mon Sep 17 00:00:00 2001 From: Aaron Fiore Date: Wed, 4 Feb 2026 15:34:59 -0800 Subject: [PATCH 3/8] client: plugins: tor: pull `alpine:latest` when `start`ing --- client/plugins/docker/tor.bash | 1 + 1 file changed, 1 insertion(+) diff --git a/client/plugins/docker/tor.bash b/client/plugins/docker/tor.bash index 643c1a7..97796e5 100755 --- a/client/plugins/docker/tor.bash +++ b/client/plugins/docker/tor.bash @@ -54,6 +54,7 @@ function tor::start() lib_utils::print_error "${tor_container}: instance already running (consider \`restart\`)" return 1 else + docker pull alpine:latest || lib_utils::die_fatal docker run -it --rm --detach \ --network "$global_network" \ --name="${tor_container}" \ From 19c2d477f655de073cfb54c570fca7372565e3e1 Mon Sep 17 00:00:00 2001 From: Aaron Fiore Date: Wed, 4 Feb 2026 15:36:08 -0800 Subject: [PATCH 4/8] client: plugins: tor: print info instead of warnings (when info) --- client/plugins/docker/tor.bash | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/plugins/docker/tor.bash b/client/plugins/docker/tor.bash index 97796e5..21ae1a6 100755 --- a/client/plugins/docker/tor.bash +++ b/client/plugins/docker/tor.bash @@ -71,7 +71,7 @@ function tor::start() lib_utils::print_info "${tor_container}: container IP '${_ip}'" # Need to wait for a working installation - lib_utils::print_warning "${tor_container}: waiting for Tor installation" + lib_utils::print_info "${tor_container}: waiting for Tor installation" while ! docker exec "$tor_container" /bin/sh -c 'apk info -e tor' 1>/dev/null; do sleep 1s done && lib_utils::print_info "${tor_container}: Tor installation ready" @@ -100,7 +100,7 @@ function tor::start() # Test Tor connection local -r _sleep="30s" - lib_utils::print_warning "${global_container}: testing connection (bootstrapping ~${_sleep})" + lib_utils::print_info "${global_container}: testing connection (bootstrapping ~${_sleep})" sleep "$_sleep" # Give time to bootstrap # TODO: run timer to verify response (and fail if N times if no response) docker exec "$global_container" \ @@ -116,7 +116,7 @@ function tor::stop() lib_utils::print_error "${tor_container}: container not running" return 1 fi - lib_utils::print_warning "${tor_container}: stopping container" + lib_utils::print_info "${tor_container}: stopping container" docker container stop "$tor_container" &>/dev/null \ && lib_utils::print_info "${tor_container}: container stopped" } From e0c66e74d67ad1c930695437e746f1d2785fc682 Mon Sep 17 00:00:00 2001 From: Aaron Fiore Date: Wed, 4 Feb 2026 15:41:09 -0800 Subject: [PATCH 5/8] client: plugins: tor: don't use interactive shell when updating proxychains --- client/plugins/docker/tor.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/plugins/docker/tor.bash b/client/plugins/docker/tor.bash index 21ae1a6..f81139e 100755 --- a/client/plugins/docker/tor.bash +++ b/client/plugins/docker/tor.bash @@ -87,11 +87,11 @@ function tor::start() lib_utils::print_info "${tor_container}: restarting Tor with updated ${_torrc}" docker exec "$tor_container" /bin/sh -c "pkill -HUP tor" || lib_utils::die_fatal - # Set docker-finance's proxychains to point to Tor instance + # Set `dfi`'s proxychains instance to point to Tor instance local -r _proxychains="/etc/proxychains.conf" lib_utils::print_info "${global_container}: updating $_proxychains" docker exec --user root "$global_container" \ - /bin/bash -i -c " + /bin/bash -c " sed -i \ -e 's:^#quiet_mode:quiet_mode:' \ -e 's:^# localnet 127.0.0.0/255.0.0.0:localnet 127.0.0.0/255.0.0.0:' \ From f302908b824d036e2a4930df0c0174d31927b191 Mon Sep 17 00:00:00 2001 From: Aaron Fiore Date: Wed, 4 Feb 2026 15:43:15 -0800 Subject: [PATCH 6/8] client: plugins: tor: implement retries when bootstrapping --- client/plugins/docker/tor.bash | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/client/plugins/docker/tor.bash b/client/plugins/docker/tor.bash index f81139e..a0138fc 100755 --- a/client/plugins/docker/tor.bash +++ b/client/plugins/docker/tor.bash @@ -102,12 +102,25 @@ function tor::start() local -r _sleep="30s" lib_utils::print_info "${global_container}: testing connection (bootstrapping ~${_sleep})" sleep "$_sleep" # Give time to bootstrap - # TODO: run timer to verify response (and fail if N times if no response) - docker exec "$global_container" \ - /bin/bash -i -c " - proxychains curl -s https://check.torproject.org 2>/dev/null \ - | grep -B3 'Your IP address appears to be' \ - | sed -e 's/^ //g' -e '\$ s/[^\\.0-9]//g' -e '/^\$/d' -e '2,3d'" || lib_utils::die_fatal + + local _tries=1 + while [ $_tries -ne 3 ]; do + lib_docker::exec "proxychains curl -s https://check.torproject.org 2>/dev/null \ + | grep -B3 'Your IP address appears to be' \ + | sed -e 's/^ //g' -e '\$ s/[^\\.0-9]//g' -e '/^\$/d' -e '2,3d' \ + | grep -A2 --color=never Congratulations || exit 1 2>/dev/null" 2>/dev/null + if [ $? -ne 0 ]; then + lib_utils::print_warning "Could not bootstrap, trying again (${_tries}/3)" + docker exec "$tor_container" /bin/sh -c "pkill -HUP tor" || lib_utils::die_fatal + sleep "$_sleep" + ((_tries++)) + else + break + fi + done + if [ $_tries -eq 3 ]; then + lib_utils::die_fatal "Could not successfully bootstrap! \`restart\` this instance" + fi } function tor::stop() From aebe9c66e36a02fe1f645a86282b9ef6007e7bc5 Mon Sep 17 00:00:00 2001 From: Aaron Fiore Date: Wed, 4 Feb 2026 15:43:58 -0800 Subject: [PATCH 7/8] client: plugins: tor: add timeout when `stop`ing tor container --- client/plugins/docker/tor.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/plugins/docker/tor.bash b/client/plugins/docker/tor.bash index a0138fc..d272ecf 100755 --- a/client/plugins/docker/tor.bash +++ b/client/plugins/docker/tor.bash @@ -130,7 +130,7 @@ function tor::stop() return 1 fi lib_utils::print_info "${tor_container}: stopping container" - docker container stop "$tor_container" &>/dev/null \ + docker container stop -t 3 "$tor_container" &>/dev/null \ && lib_utils::print_info "${tor_container}: container stopped" } From 0871934f3c5cac396b1a014cf243654a840fc923 Mon Sep 17 00:00:00 2001 From: Aaron Fiore Date: Wed, 4 Feb 2026 15:45:09 -0800 Subject: [PATCH 8/8] repo: gitea: workflows: dfi: plugins: tor: refactor Reflects updates to plugin impl. --- .gitea/workflows/dfi.bash | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/.gitea/workflows/dfi.bash b/.gitea/workflows/dfi.bash index ecb8a0e..1ec90b6 100755 --- a/.gitea/workflows/dfi.bash +++ b/.gitea/workflows/dfi.bash @@ -219,24 +219,10 @@ function client::finance::plugins::__tor() [ -z "$_plugins" ] && exit 1 client::finance::up - local -r _congrats="| grep Congratulations" - - # start - local _tries=0 - while [ $_tries -lt 3 ]; do - "${ci_shell[@]}" "$_plugins repo/tor.bash start" $_congrats - [ $? -eq 0 ] && break || ((_tries++)) + local -r _tor=("start" "restart" "stop") + for _arg in "${_tor[@]}"; do + "${ci_shell[@]}" "$_plugins repo/tor.bash $_arg" done - - # restart - local _tries=0 - while [ $_tries -lt 3 ]; do - "${ci_shell[@]}" "$_plugins repo/tor.bash restart" $_congrats - [ $? -eq 0 ] && break || ((_tries++)) - done - - # stop - "${ci_shell[@]}" "$_plugins repo/tor.bash stop" client::finance::down }