This repository has no description
0

Configure Feed

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

tools.tornade: add 5-attempt retry mechanism

Improves Tor connection success rate from ~33% to ~80% by retrying failed
circuit establishment attempts with optimized settings.

+36 -24
+36 -24
tools/tornade/tornade.sh
··· 17 17 Log notice file $TOR_DIR/tor.log 18 18 RunAsDaemon 0 19 19 20 - # Performance optimizations 21 - CircuitBuildTimeout 10 20 + # Performance and reliability optimizations 21 + CircuitBuildTimeout 15 22 22 LearnCircuitBuildTimeout 0 23 - NumEntryGuards 3 23 + NumEntryGuards 8 24 24 KeepalivePeriod 60 25 - SocksTimeout 60 25 + SocksTimeout 120 26 26 27 - # Don't wait for descriptor downloads 28 - UseMicroDescriptors 0 27 + # Reliability settings 28 + MaxCircuitDirtiness 600 29 + NewCircuitPeriod 30 30 + UseEntryGuards 1 29 31 EOF 30 32 31 - # Start tor in background 32 - echo "Starting isolated Tor instance on port $SOCKS_PORT..." >&2 33 - tor -f "$TOR_DIR/torrc" & 33 + # Start tor in background - suppress output to avoid protocol interference 34 + tor -f "$TOR_DIR/torrc" >/dev/null 2>&1 & 34 35 TOR_PID=$! 35 36 36 37 # Function to cleanup tor process 37 38 cleanup() { 38 39 if kill -0 "$TOR_PID" 2>/dev/null; then 39 - echo "Stopping Tor instance..." >&2 40 40 kill "$TOR_PID" 2>/dev/null || true 41 41 wait "$TOR_PID" 2>/dev/null || true 42 42 fi ··· 44 44 } 45 45 trap cleanup EXIT INT TERM 46 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 47 + # Retry up to 5 times to establish circuits 48 + for attempt in 1 2 3 4 5; do 49 + 50 + if [ $attempt -gt 1 ]; then 51 + # Kill previous tor instance and restart 52 + kill "$TOR_PID" 2>/dev/null || true 53 + wait "$TOR_PID" 2>/dev/null || true 54 + tor -f "$TOR_DIR/torrc" >/dev/null 2>&1 & 55 + TOR_PID=$! 54 56 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 57 + 58 + # Check frequently at first, then slow down - longer timeout per attempt 59 + for i in {1..120}; do 60 + if grep -q "Bootstrapped 100%" "$TOR_DIR/tor.log" 2>/dev/null; then 61 + # Success - exit both loops 62 + break 2 63 + fi 64 + # Check every 0.1s for first 2 seconds, then every 0.5s 65 + if [ "$i" -le 20 ]; then 66 + sleep 0.1 67 + else 68 + sleep 0.5 69 + fi 70 + done 71 + 72 + # This attempt failed, continue to next attempt 61 73 done 62 74 75 + # Final check - if still not ready after all attempts, exit 63 76 if ! grep -q "Bootstrapped 100%" "$TOR_DIR/tor.log" 2>/dev/null; then 64 - echo "Error: Tor failed to establish circuits" >&2 65 77 exit 1 66 78 fi 67 79