The InterPlanetary File System (IPFS) has ambitious goals. It aims to decentralise the internet, make it more secure, and enable the creation of purely distributed applications. It combines some of the best features of the peer-to-peer protocol BitTorrent, the version control system Git and distributed hash tables. There is no central node, and nodes do not need to trust each other.
When you add a file to IPFS your node broadcasts to the network the hash of the file (This is the location of the file as far as the network is concerned). This enables any node in the network to ask your node for the file. When a node asks the network for a certain hash, it receives a list of nodes serving that hash and can download from any of them. The result is hashed locally to prove that you got what you asked for. No such thing as a man-in-the-middle attack!
I have recently implemented a Java API to IPFS. This enables easy, type safe access to a local IPFS node over HTTP. It is really simple to use! Just add the (40 KiB!) IPFS.jar to your classpath. We hope to use IPFS to replace the distributed hash table in Peergos, our secure, distributed file storage, sharing and social network.
Ensure that IPFS is installed and running (IPFS is written in Go):
You can then create an accessor in Java with:
To add a file to IPFS simply,
or if you prefer to work with raw byte arrays:
To get the contents of your file back,
If you want to keep a copy of something someone else has added, you can “pin” it. This means that you will keep a local copy of the file, and also act as a server for it. (Files you add are automatically pinned)
Any files you retrieve are temporarily cached, and served. Periodically, the local files that aren’t pinned are garbage collected. You can force this clean up with,
If you want to explicitly remove a file from the local cache, use:
Unleash the power of IPFS on your JVM!