Skip to content

Instantly share code, notes, and snippets.

@Stebalien
Created March 6, 2019 21:20
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/1ddd10a9afc053de019aa874106599c7 to your computer and use it in GitHub Desktop.
Save Stebalien/1ddd10a9afc053de019aa874106599c7 to your computer and use it in GitHub Desktop.
#!/bin/bash
REPO="$(mktemp -d)"
IPFS_PATH="$REPO"
trap "$(printf 'rm -rf "%s"' "$REPO")" INT EXIT
ipfs init --profile=randomports >/dev/null
ipfs daemon --routing=dhtclient >&2 &
while ! ( [[ -e "$IPFS_PATH/api" ]] && ipfs id >/dev/null >&1 ); do 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 --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