Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash -e
- # Non-Fast&Stable relays are ignored
- # BadExit flag disables Exit flag
- # Valid, Running flags are ignored (all relays have them)
- # Named, Unnamed, HSDir, V2Dir, Authority flags are ignored
- insum() {
- local sum=0 x=
- while read x; do
- sum=$((sum + x))
- done
- echo ${sum}
- }
- cat cached-consensus \
- | sed -rn 's/^r ([^ ]+ ){5}([^ ]+).*/\2/p; /^s /s:(s? |$):/:gp; s/^w Bandwidth=(.*)/\1^/p' \
- | tr '\n^' ' \n' | sed 's/^ //' | sort -nrk3 \
- | grep '/Fast.*/Stable' \
- | sed -r 's:/(BadExit(/Exit)?|Fast|Stable|Named|Unnamed|Running|Valid|HSDir|V2Dir|Authority)::g' \
- > nodes
- guards=`awk '/\/Guard/ {print $3}' nodes | insum`
- exits=`awk '/\/Exit/ {print $3}' nodes | insum`
- total=`awk '{print $3}' nodes | insum`
- echo "Guards: ${guards}, Exits: ${exits}, Total: ${total}"
- rm -f nodes-sniff
- snsum=0
- ord=0
- cat nodes | while read ip flags bw; do
- if [ ${flags} = /Exit/Guard/ ]; then
- snsum=$((snsum + bw))
- gper=$(((snsum * 100 + 50) / guards))
- eper=$(((snsum * 100 + 50) / exits))
- # mark same-Class-C subnets, don't aggregate with non-Exit+Guard
- # (so lower bound, but doesn't seem to matter much)
- if grep -qs "^${ip%.*}\." nodes-sniff; then
- ip=" ${ip}"
- else
- ord=$((ord + 1))
- fi
- echo -e "${ip}\t\t\t${gper} ${eper}\t\t${ord} $((gper * eper))" >> nodes-sniff
- fi
- done
- cat nodes-sniff \
- | awk '{print $4,$5}' \
- | tac | sort -nuk1 \
- | sed 's/[0-9][0-9]$/.&%/' \
- > nodes-sniff-summary
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement