Skip to content

Instantly share code, notes, and snippets.

@Stebalien
Created March 16, 2019 04:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Stebalien/dd0b0f09cdbc766aeb7a3caac19280bc to your computer and use it in GitHub Desktop.
Save Stebalien/dd0b0f09cdbc766aeb7a3caac19280bc to your computer and use it in GitHub Desktop.
#!/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