Created
March 16, 2019 04:27
-
-
Save Stebalien/dd0b0f09cdbc766aeb7a3caac19280bc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
REPO="$(mktemp -d)" | |
IPFS_PATH="$REPO" | |
cleanup() { | |
rm -rf "$REPO" | |
wait | |
} | |
trap "cleanup" INT EXIT | |
ipfs init >/dev/null | |
ipfs daemon --routing=dhtclient >&2 & | |
IPFS_PID="$!" | |
while ! ( [[ -e "$IPFS_PATH/api" ]] && ipfs id >/dev/null >&1 ); do | |
kill -0 "$IPFS_PID" 2>&1 >/dev/null || exit 1 | |
sleep 1 | |
done | |
echo "Bootstrapping..." >&2 | |
ipfs --timeout=10s dht findprovs "$(ipfs id --format='<id>')" >/dev/null 2>&1 | |
FILE="$(echo "Gateway Latency Test: $(date)" | ipfs add -q)" | |
echo "Added file: $FILE" >&2 | |
echo "Providing..." >&2 | |
ipfs --timeout=20s dht provide "$FILE" >/dev/null 2>&1 | |
echo "Retrieving..." >&2 | |
# Test it. | |
RESP=$(curl -o /dev/null --write-out '{"code": %{http_code}, "time": %{time_total}}' "https://ipfs.io/ipfs/${FILE}") | |
ipfs shutdown >/dev/null >&2 | |
wait | |
echo "$RESP" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment