3 # function used by fetch-all* to download server descriptors and
6 # Copyright (c) 2005, 2006, 2007, 2008 Peter Palfrader
8 # Permission is hereby granted, free of charge, to any person obtaining a copy
9 # of this software and associated documentation files (the "Software"), to deal
10 # in the Software without restriction, including without limitation the rights
11 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 # copies of the Software, and to permit persons to whom the Software is
13 # furnished to do so, subject to the following conditions:
15 # The above copyright notice and this permission notice shall be included in
16 # all copies or substantial portions of the Software.
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 if [ "$objecttype" = "server-descriptor" ] ; then
41 pathpart
="server-descriptor"
42 elif [ "$objecttype" = "extra-info" ] ; then
46 echo "Called fetch_digest with illegal objecttype '$objecttype'" >&2
49 target
=$
( echo $digest |
sed -e 's#^\(.\)\(.\)#'"$pathpart"'/\1/\2/\1\2#' )
50 targetdir
=$
( dirname $target )
51 [ -d "$targetdir" ] || mkdir
-p "$targetdir"
52 if ! [ -e "$target" ]; then
53 for dirserver
in $DIRSERVERS; do
54 wget
-q -O "$target" http
://$dirserver/tor
/$urlpart/d
/"$digest" ||
rm -f "$target"
55 if [ -s "$target" ]; then
56 if egrep '^opt extra-info-digest ' "$target" > /dev
/null
; then
57 ei
=$
( egrep '^opt extra-info-digest ' "$target" |
awk '{print $3}' |
tr 'A-F' 'a-f' )
58 fetch_digest
"$ei" "extra-info"
59 elif egrep '^extra-info-digest ' "$target" > /dev
/null
; then
60 ei
=$
( egrep '^extra-info-digest ' "$target" |
awk '{print $2}' |
tr 'A-F' 'a-f' )
61 fetch_digest
"$ei" "extra-info"
69 #if ! [ -e "$target" ]; then
70 # echo "$objecttype $digest" >> failed
74 if [ -x /usr
/bin
/base64
] ; then
75 alias base64-decode
='/usr/bin/base64 -d'
78 perl
-MMIME::Base64
-e 'print decode_base64(<>)'