test-network.sh 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. #! /bin/sh
  2. ECHO_N="/bin/echo -n"
  3. # Output is prefixed with the name of the script
  4. myname=$(basename "$0")
  5. until [ -z "$1" ]
  6. do
  7. case "$1" in
  8. --chutney-path)
  9. export CHUTNEY_PATH="$2"
  10. shift
  11. ;;
  12. --tor-path)
  13. # the path of a tor build directory
  14. # --tor-path overrides --tor and --tor-gencert
  15. export TOR_DIR="$2"
  16. shift
  17. ;;
  18. --tor)
  19. # the name or path of a tor binary
  20. export CHUTNEY_TOR="$2"
  21. shift
  22. ;;
  23. --tor-gencert)
  24. # the name or path of a tor-gencert binary
  25. export CHUTNEY_TOR_GENCERT="$2"
  26. shift
  27. ;;
  28. --flavor|--flavour|--network-flavor|--network-flavour)
  29. export NETWORK_FLAVOUR="$2"
  30. shift
  31. ;;
  32. # The amount of time chutney will wait before starting to verify
  33. # If negative, chutney exits straight after launching the network
  34. --start-time)
  35. export CHUTNEY_START_TIME="$2"
  36. shift
  37. ;;
  38. # The amount of time chutney will try to verify, before failing
  39. # If negative, chutney exits without verifying
  40. --delay|--sleep|--bootstrap-time|--time|--verify-time)
  41. # This isn't the best name for this variable, but we kept it the same
  42. # for backwards compatibility
  43. export CHUTNEY_BOOTSTRAP_TIME="$2"
  44. shift
  45. ;;
  46. # The amount of time chutney will wait after successfully verifying
  47. # If negative, chutney exits without stopping
  48. --stop-time)
  49. export CHUTNEY_STOP_TIME="$2"
  50. shift
  51. ;;
  52. # Environmental variables used by chutney verify performance tests
  53. # Send this many bytes per client connection (10 KBytes)
  54. --data|--data-bytes|--data-byte|--bytes|--byte)
  55. export CHUTNEY_DATA_BYTES="$2"
  56. shift
  57. ;;
  58. # Make this many connections per client (1)
  59. # Note: If you create 7 or more connections to a hidden service from
  60. # a single Tor 0.2.7 client, you'll likely get a verification failure due
  61. # to #15937. This is fixed in 0.2.8.
  62. --connections|--connection|--connection-count|--count)
  63. export CHUTNEY_CONNECTIONS="$2"
  64. shift
  65. ;;
  66. # Make each client connect to each HS (0)
  67. # 0 means a single client connects to each HS
  68. # 1 means every client connects to every HS
  69. --hs-multi-client|--hs-multi-clients|--hs-client|--hs-clients)
  70. export CHUTNEY_HS_MULTI_CLIENT="$2"
  71. shift
  72. ;;
  73. # The IPv4 address to bind to, defaults to 127.0.0.1
  74. --ipv4|--v4|-4|--ip)
  75. export CHUTNEY_LISTEN_ADDRESS="$2"
  76. shift
  77. ;;
  78. # The IPv6 address to bind to, default is not to bind to an IPv6 address
  79. --ipv6|--v6|-6)
  80. export CHUTNEY_LISTEN_ADDRESS_V6="$2"
  81. shift
  82. ;;
  83. --coverage)
  84. export USE_COVERAGE_BINARY=true
  85. ;;
  86. --dry-run)
  87. # process arguments, but don't call any other scripts
  88. export NETWORK_DRY_RUN=true
  89. ;;
  90. *)
  91. echo "$myname: Sorry, I don't know what to do with '$1'."
  92. # continue processing arguments during a dry run
  93. if [ "$NETWORK_DRY_RUN" != true ]; then
  94. exit 2
  95. fi
  96. ;;
  97. esac
  98. shift
  99. done
  100. # optional: $TOR_DIR is the tor build directory
  101. # it's used to find the location of tor binaries
  102. # if it's not set:
  103. # - set it ro $BUILDDIR, or
  104. # - if $PWD looks like a tor build directory, set it to $PWD, or
  105. # - unset $TOR_DIR, and let chutney fall back to finding tor binaries in $PATH
  106. if [ ! -d "$TOR_DIR" ]; then
  107. if [ -d "$BUILDDIR/src/or" -a -d "$BUILDDIR/src/tools" ]; then
  108. # Choose the build directory
  109. # But only if it looks like one
  110. echo "$myname: \$TOR_DIR not set, trying \$BUILDDIR"
  111. export TOR_DIR="$BUILDDIR"
  112. elif [ -d "$PWD/src/or" -a -d "$PWD/src/tools" ]; then
  113. # Guess the tor directory is the current directory
  114. # But only if it looks like one
  115. echo "$myname: \$TOR_DIR not set, trying \$PWD"
  116. export TOR_DIR="$PWD"
  117. elif [ -d "$PWD/../tor" -a -d "$PWD/../tor/src/or" -a \
  118. -d "$PWD/../tor/src/tools" ]; then
  119. # Guess the tor directory is next to the current directory
  120. # But only if it looks like one
  121. echo "$myname: \$TOR_DIR not set, trying \$PWD/../tor"
  122. export TOR_DIR="$PWD/../tor"
  123. else
  124. echo "$myname: no \$TOR_DIR, chutney will use \$PATH for tor binaries"
  125. unset TOR_DIR
  126. fi
  127. fi
  128. # mandatory: $CHUTNEY_PATH is the path to the chutney launch script
  129. # if it's not set:
  130. # - if $PWD looks like a chutney directory, set it to $PWD, or
  131. # - set it based on $TOR_DIR, expecting chutney to be next to tor, or
  132. # - fail and tell the user how to clone the chutney repository
  133. if [ ! -d "$CHUTNEY_PATH" -o ! -x "$CHUTNEY_PATH/chutney" -o \
  134. ! -f "$CHUTNEY_PATH/chutney" ]; then
  135. if [ -x "$PWD/chutney" -a -f "$PWD/chutney" ]; then
  136. echo "$myname: \$CHUTNEY_PATH not valid, trying \$PWD"
  137. export CHUTNEY_PATH="$PWD"
  138. elif [ -d "`dirname \"$0\"`/.." -a \
  139. -x "`dirname \"$0\"`/../chutney" -a \
  140. -f "`dirname \"$0\"`/../chutney" ]; then
  141. echo "$myname: \$CHUTNEY_PATH not valid, using this script's location"
  142. export CHUTNEY_PATH="`dirname \"$0\"`/.."
  143. elif [ -d "$TOR_DIR" -a -d "$TOR_DIR/../chutney" -a \
  144. -x "$TOR_DIR/../chutney/chutney" -a \
  145. -f "$TOR_DIR/../chutney/chutney" ]; then
  146. echo "$myname: \$CHUTNEY_PATH not valid, trying \$TOR_DIR/../chutney"
  147. export CHUTNEY_PATH="$TOR_DIR/../chutney"
  148. else
  149. # TODO: work out how to package and install chutney,
  150. # so users can find it in $PATH
  151. echo "$myname: missing 'chutney' in \$CHUTNEY_PATH ($CHUTNEY_PATH)"
  152. echo "$myname: Get chutney: git clone https://git.torproject.org/\
  153. chutney.git"
  154. echo "$myname: Set \$CHUTNEY_PATH to a non-standard location: export \
  155. CHUTNEY_PATH=\`pwd\`/chutney"
  156. unset CHUTNEY_PATH
  157. exit 1
  158. fi
  159. fi
  160. # For picking up the right tor binaries.
  161. # If $TOR_DIR isn't set, chutney looks for tor binaries by name or path
  162. # using $CHUTNEY_TOR and $CHUTNEY_TOR_GENCERT, and then falls back to
  163. # looking for tor and tor-gencert in $PATH
  164. if [ -d "$TOR_DIR" ]; then
  165. tor_name=tor
  166. tor_gencert_name=tor-gencert
  167. if [ "$USE_COVERAGE_BINARY" = true ]; then
  168. tor_name=tor-cov
  169. fi
  170. export CHUTNEY_TOR="${TOR_DIR}/src/or/${tor_name}"
  171. export CHUTNEY_TOR_GENCERT="${TOR_DIR}/src/tools/${tor_gencert_name}"
  172. fi
  173. # Set the variables for the chutney network flavour
  174. export NETWORK_FLAVOUR=${NETWORK_FLAVOUR:-"bridges+hs"}
  175. export CHUTNEY_NETWORK="networks/$NETWORK_FLAVOUR"
  176. # And finish up if we're doing a dry run
  177. if [ "$NETWORK_DRY_RUN" = true ]; then
  178. # we can't exit here, it breaks argument processing
  179. return
  180. fi
  181. cd "$CHUTNEY_PATH"
  182. ./tools/bootstrap-network.sh "$NETWORK_FLAVOUR" || exit 2
  183. # chutney starts verifying after 20 seconds, keeps on trying for 60 seconds,
  184. # and then stops immediately (by default)
  185. # Even the fastest chutney networks take 5-10 seconds for their first consensus
  186. # and then 10 seconds after that for relays to bootstrap and upload descriptors
  187. export CHUTNEY_START_TIME=${CHUTNEY_START_TIME:-20}
  188. export CHUTNEY_BOOTSTRAP_TIME=${CHUTNEY_BOOTSTRAP_TIME:-60}
  189. export CHUTNEY_STOP_TIME=${CHUTNEY_STOP_TIME:-0}
  190. if [ "$CHUTNEY_START_TIME" -ge 0 ]; then
  191. echo "Waiting ${CHUTNEY_START_TIME} seconds for a consensus containing relays to be generated..."
  192. sleep "$CHUTNEY_START_TIME"
  193. else
  194. echo "Chutney network launched and running. To stop the network, use:"
  195. echo "$PWD/chutney stop $PWD/$CHUTNEY_NETWORK"
  196. exit 0
  197. fi
  198. if [ "$CHUTNEY_BOOTSTRAP_TIME" -ge 0 ]; then
  199. # Chutney will try to verify for $CHUTNEY_BOOTSTRAP_TIME seconds
  200. ./chutney verify "$CHUTNEY_NETWORK"
  201. VERIFY_EXIT_STATUS="$?"
  202. else
  203. echo "Chutney network ready and running. To stop the network, use:"
  204. echo "$PWD/chutney stop $PWD/$CHUTNEY_NETWORK"
  205. exit 0
  206. fi
  207. if [ "$CHUTNEY_STOP_TIME" -ge 0 ]; then
  208. if [ "$CHUTNEY_STOP_TIME" -gt 0 ]; then
  209. echo "Waiting ${CHUTNEY_STOP_TIME} seconds before stopping the network..."
  210. fi
  211. sleep "$CHUTNEY_STOP_TIME"
  212. # work around a bug/feature in make -j2 (or more)
  213. # where make hangs if any child processes are still alive
  214. ./chutney stop "$CHUTNEY_NETWORK"
  215. exit "$VERIFY_EXIT_STATUS"
  216. else
  217. echo "Chutney network verified and running. To stop the network, use:"
  218. echo "$PWD/chutney stop $PWD/$CHUTNEY_NETWORK"
  219. exit 0
  220. fi