Commit af1ad3b8 authored by Ivan Vilata-i-Balaguer's avatar Ivan Vilata-i-Balaguer
Browse files

Merge branch 'docker-pack-utils' into master.

This adds a new `utils` directory with test tools under Ouinet's main
directory in the Docker image.
parents 091e069e 16b4f915
......@@ -31,7 +31,7 @@ FROM base as builder
# This version is a recommendation and this file has been tested to work for it,
# but you may attempt to build other versions by overriding this argument.
# Also see `OUINET_DOCKER_VERSION` below.
ARG OUINET_VERSION=v0.8.0
ARG OUINET_VERSION=v0.8.1
RUN git clone --recursive -b "$OUINET_VERSION" https://github.com/equalitie/ouinet.git
WORKDIR /opt/ouinet
# The C.UTF-8 locale (which is always available in Debian)
......@@ -43,7 +43,7 @@ RUN cp -r /usr/local/src/ouinet/repos/ repo-templates/
ARG OUINET_DEBUG=no
RUN \
if [ $OUINET_DEBUG != yes ]; then \
strip injector client src/ouiservice/obfs4proxy/obfs4proxy \
strip injector client src/ouiservice/obfs4proxy/obfs4proxy test/bt-* test/oui-* \
&& find . -name '*.so' -exec strip '{}' + \
&& find . -wholename '*/libexec/*' -executable -type f -exec strip '{}' + ; \
fi
......@@ -104,6 +104,11 @@ RUN ldconfig
COPY --from=builder /opt/ouinet/injector /opt/ouinet/client ./
COPY --from=builder /opt/ouinet/src/ouiservice/obfs4proxy/obfs4proxy ./
COPY --from=builder /opt/ouinet/repo-templates/ repo-templates/
RUN mkdir utils
COPY --from=builder \
/opt/ouinet/test/bt-* /opt/ouinet/test/oui-* \
/usr/local/src/ouinet/scripts/ping-swarm
utils/
# This ensures that we use the desired Docker-specific files.
RUN echo "$OUINET_DOCKER_VERSION"
COPY --from=builder /usr/local/src/ouinet/scripts/ouinet-wrapper.sh ouinet
......
#!/bin/sh
# Ping the given Ouinet swarms using BEP5.
#
# Usage: ping-swarm [injectors|bridges|URI]...
#
# Where URI can be an exact URI like "https://example.com/foo/"
# or a group like "example.com/foo" (not equivalent).
#
# Default is to ping both injectors and bridges.
#
# Environment variables:
#
# - OUI_PROTO: Ouinet protocol version number
# - OUI_INJPK: Base32-encoded injector public key (lowercase, no padding)
#
# This must be executed where Ouinet's test utilities are.
set -e
# Uncomment if libraries sit along binaries.
#export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH
# Uncomment and edit for fixed default values.
#OUI_PROTO=5
#OUI_INJPK="abcdefghijklmnopqrstuvwxyz234567abcdefghijklmnopqrst"
v="$OUI_PROTO"
pk="$OUI_INJPK"
if [ ! "$v" -o ! "$pk" ]; then
echo "Please set OUI_PROTO and OUI_INJPK." > /dev/stderr
exit 1
fi
if [ $# -lt 1 ]; then
exec $0 injectors bridges
fi
ping_peer() { # (endpoint) => (did_reply)
# Sample DHT message from
# <https://www.bittorrent.org/beps/bep_0005.html#ping>.
local ping='d1:ad2:id20:abcdefghij0123456789e1:q4:ping1:t2:aa1:y1:qe'
local host="${1%:*}" port="${1##*:}"
echo -n "$ping" | timeout 2 nc -uW1 "$host" "$port" > /dev/null
}
ping_peers() { # () / endpoint* => () / peers replies
local ep peers=0 replies=0 replying
while read ep; do
peers=$((peers + 1))
if ping_peer $ep; then
replying="$replying $ep"
replies=$((replies + 1))
fi
done
echo "Replying peers:$replying" > /dev/stderr
echo $peers $replies
}
select_peers() { # () / bt-pep5_output => () endpoint*
grep -E '^[][\.\:0-9A-Fa-f]+:[0-9]+' | tr -d [] | sed 's/, */\n/g'
}
bep5_query() { # (infohash) => () bt-pep5_output
./bt-bep5 0.0.0.0 get_peers $1 2>&1
}
for group in "$@"; do
# swarm = "ed25519:<base32up_encode(pubkey)>/v<VERSION>/<GROUP>"
case "$group" in
injectors|bridges)
swarm="ed25519:$pk/v$v/$group"
;;
*)
swarm="ed25519:$pk/v$v/uri/$group"
esac
# infohash = sha1(swarm)
infohash="$(echo -n "$swarm" | sha1sum | cut -d' ' -f1)"
echo "Group : $group"
echo "Swarm : $swarm"
echo "Infohash: $infohash"
bep5_query "$infohash" | tee /dev/stderr \
| select_peers | ping_peers \
| ( read peers replies
echo "Swarm group=\"$group\": peers=$peers replies=$replies" )
echo
done
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment