-
Notifications
You must be signed in to change notification settings - Fork 11
Introduction to IPFS
The best reference is its home page. IPFS stands for Inter Planetary File System.
Its goal is replace HTTP and build a better web, how it works? To understand it, we need to remove from our heads the idea of centralized servers hosting files to the internet nodes and imagine the whole internet of nodes as a huge storage unit.
-
Each file and all of the blocks within it are given a unique fingerprint called a cryptographic hash.
-
IPFS removes duplications across the network and tracks version history for every file.
-
Each network node stores only content it is interested in, and some indexing information that helps figure out who is storing what.
-
When looking up files, you're asking the network to find nodes storing the content behind a unique hash.
-
Every file can be found by human-readable names using a decentralized naming system called IPNS.
For the reader interested in the particulars, here is The IPFS white paper
All we need to be part of the IPFS is running a version of the IPFS daemon, or having access to a remote IPFS node. INFURA provides an IPFS node for developers.
Just install the executable and run it. Is that simple.
Check the one according to your OS, to test it, enter
> ipfs help
USAGE:
ipfs - Global p2p merkle-dag filesystem.
We review the basic operation of the IPFS daemon in this guide
Docker presents a number of benefits. Among them, that you can
get encapsulated images of an applications, with their libraries, in a way analog to
downloading an App
. Although IPFS has its docker image,
we will use the modified ConsenSys' one, as it has some small modifications, namely, the
inclusion of CORS
support.
You just need to have docker installed in your machine and prepare two directories
mkdir -p $HOME/ipfs/staging
mkdir -p $HOME/ipfs/data
chmod -R 777 $HOME/ipfs
Once the preparations are done, run the following command
docker run -ti \
--rm \
--name ipfs \
-v $HOME/ipfs/staging:/export \
-v $HOME/ipfs/data:/ipfs/data \
-p 4001:4001 \
-p 5001:5001 \
-p 8080:8080 \
consensysllc/go-ipfs:v0.4.4-custom-start
This command does these steps:
- Pulls, if there is not already there, the image
consensysllc/go-ipfs:v0.4.4-custom-start
. - Mounts both two directories prepared above into the image. So we don't start from scratch everytime.
- Maps three ports from the host (your machine) into the image:
4001
,5001
and8080
.
If you are curious, this is the Dockerfile
we are using in our machine
FROM ipfs/go-ipfs:v0.4.4
MAINTAINER Herman Junge <[email protected]>
COPY start_ipfs.sh /usr/local/bin/start_ipfs
ENTRYPOINT ["/usr/local/bin/start_ipfs"]
and the start script
#!/bin/sh
user=$(whoami)
repo="$IPFS_PATH"
# Test whether the mounted directory is writable for us
if [ ! -w "$repo" 2>/dev/null ]; then
echo "error: $repo is not writable for user $user (uid=$(id -u $user))"
exit 1
fi
ipfs version
if [ -e "$repo/config" ]; then
echo "Found IPFS fs-repo at $repo"
else
ipfs init
ipfs config Addresses.API /ip4/0.0.0.0/tcp/5001
ipfs config Addresses.Gateway /ip4/0.0.0.0/tcp/8080
ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["*"]'
ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["PUT", "GET", "POST"]'
fi
# For the love of Krishna, do not use `--debug`!
# You can modify them later, けど. See
# https://ipfs.io/docs/commands/#ipfs-log-level
exec env IPFS_LOGGING=info ipfs daemon --enable-gc
And that'd be!
If you want to run the console tutorial using this very image, you need to add a single flag into docker.
# Add this flag just before the name of the image
--entrypoint /bin/bash
So you override the start of IPFS daemon, and run /bin/bash.
Now, there may be a number of reasons where you don't want to run a local IPFS node, neither installed nor a docker. Enter INFURA.
INFURA maintains a remote IPFS node at the address https://ipfs.infura.io/
.
- Gateway: https://ipfs.infura.io
- RPC: https://ipfs.infura.io:5001