Created
March 6, 2019 21:16
-
-
Save Stebalien/02867e89c16f173350ff34f7ff6b4948 to your computer and use it in GitHub Desktop.
This file contains 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" | |
trap "$(printf 'rm -rf "%s"' "$REPO")" INT EXIT | |
ipfs init --profile=randomports >/dev/null | |
ipfs config Addresses.API "/ip4/127.0.0.1/tcp/0" # random API port. | |
ipfs config Addresses.Gateway "" # no gateway | |
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