This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

tools.tornade: add isolated Tor wrapper tool

Creates isolated Tor instances with random ports for each invocation.
Supports SSH on macOS using ProxyCommand to bypass SIP limitations.
Optimized for fast startup with reduced circuit timeouts.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

author
lassulus
co-author
Claude
date (Jun 14, 2025, 11:22 PM CEST) commit f8f9ce8b parent c0144cd3
+94
+17
tools/tornade/flake-module.nix
··· 1 + { self, ... }: 2 + { 3 + perSystem = 4 + { pkgs, ... }: 5 + { 6 + packages.tornade = pkgs.writeShellApplication { 7 + name = "tornade"; 8 + runtimeInputs = with pkgs; [ 9 + tor 10 + torsocks 11 + coreutils 12 + procps 13 + ]; 14 + text = builtins.readFile ./tornade.sh; 15 + }; 16 + }; 17 + }
+77
tools/tornade/tornade.sh
··· 1 + #!/usr/bin/env bash 2 + set -euo pipefail 3 + 4 + # Create temporary directory for this tor instance 5 + TOR_DIR=$(mktemp -d -t tornade.XXXXXX) 6 + trap 'rm -rf "$TOR_DIR"' EXIT 7 + 8 + # Generate random ports 9 + SOCKS_PORT=$((9050 + RANDOM % 1000)) 10 + CONTROL_PORT=$((SOCKS_PORT + 1)) 11 + 12 + # Create tor configuration 13 + cat > "$TOR_DIR/torrc" <<EOF 14 + DataDirectory $TOR_DIR/data 15 + SocksPort 127.0.0.1:$SOCKS_PORT 16 + ControlPort 127.0.0.1:$CONTROL_PORT 17 + Log notice file $TOR_DIR/tor.log 18 + RunAsDaemon 0 19 + 20 + # Performance optimizations 21 + CircuitBuildTimeout 10 22 + LearnCircuitBuildTimeout 0 23 + NumEntryGuards 3 24 + KeepalivePeriod 60 25 + SocksTimeout 60 26 + 27 + # Don't wait for descriptor downloads 28 + UseMicroDescriptors 0 29 + EOF 30 + 31 + # Start tor in background 32 + echo "Starting isolated Tor instance on port $SOCKS_PORT..." >&2 33 + tor -f "$TOR_DIR/torrc" & 34 + TOR_PID=$! 35 + 36 + # Function to cleanup tor process 37 + cleanup() { 38 + if kill -0 "$TOR_PID" 2>/dev/null; then 39 + echo "Stopping Tor instance..." >&2 40 + kill "$TOR_PID" 2>/dev/null || true 41 + wait "$TOR_PID" 2>/dev/null || true 42 + fi 43 + rm -rf "$TOR_DIR" 44 + } 45 + trap cleanup EXIT INT TERM 46 + 47 + # Wait for tor to be ready 48 + echo "Waiting for Tor to establish circuits..." >&2 49 + # Check frequently at first, then slow down 50 + for i in {1..60}; do 51 + if grep -q "Bootstrapped 100%" "$TOR_DIR/tor.log" 2>/dev/null; then 52 + echo "Tor is ready!" >&2 53 + break 54 + fi 55 + # Check every 0.1s for first 2 seconds, then every 0.5s 56 + if [ "$i" -le 20 ]; then 57 + sleep 0.1 58 + else 59 + sleep 0.5 60 + fi 61 + done 62 + 63 + if ! grep -q "Bootstrapped 100%" "$TOR_DIR/tor.log" 2>/dev/null; then 64 + echo "Error: Tor failed to establish circuits" >&2 65 + exit 1 66 + fi 67 + 68 + # Check if we're trying to run SSH on macOS 69 + if [[ "$1" == "ssh" ]] && [[ "$(uname)" == "Darwin" ]]; then 70 + # On macOS, use ProxyCommand instead of torsocks due to SIP 71 + shift # remove 'ssh' from arguments 72 + exec ssh -o ProxyCommand="nc -x 127.0.0.1:$SOCKS_PORT %h %p" "$@" 73 + else 74 + # For other commands or non-macOS systems, use torsocks 75 + export TORSOCKS_TOR_PORT=$SOCKS_PORT 76 + exec torsocks "$@" 77 + fi