Distributed File System: IPFS
I will explain The distributed file system with the help of IPFS. IPFS stands for Inter-planetary File System and it is an open-source, peer-to-peer distributed hypermedia protocol that aims to function as a ubiquitous file system for all computing devices.
IPFS addresses the issues associated with the current protocol of the internet (known as HTTP).
The issues with HTTP are as follows
- The increasing number of users requesting data: HTTP seizes a huge amount of bandwidth available in order to provide these data to the users, even if the people who request the data are in proximity to each other which is inefficient considering the huge amount of data which is transferred per second on the internet today.
- The speed of light: As a transfer of data cannot surpass the speed of light. Hence, the reasonable thing to do would be to bring the servers close to the access point. So that if someone requests the data, it would reach sooner.
- Broken/Dead content: HTTP links are unreliable, they get broken a lot of times. If the content is deleted then it is lost forever unless someone has manually copied the data. For example, if someone hacks the Wikipedia page and deletes all of its contents then they are gone forever. You may have encountered this as 404 Error shown below.
How IPFS provides a solution
- IPFS uses a content-based addressing method compared to IP addressing method used by HTTP. Content-based address fetches the data from the closest system which has a copy of it. The content is identified by a cryptographically generated hash which also serves as the fingerprint of the data and it cannot be changed.
- IPFS uses the Merkle DAG protocol inspired by Git. This is also used for controlling the version of different files stored on IPFS.
- User can download parts of a file from various sources at once and combine it at their side rather than downloading the whole file from a single source.
How IPFS Works
- Each file and all of the blocks within it are given a unique fingerprint called a cryptographic hash.
- IPFS removes duplications across the network.
- 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.
IPFS is a distributed file system which synthesizes successful ideas from previous peer-to-peer systems, including DHTs, BitTorrent, Git, and SFS.
Implementation Guide of IPFS
IPFS can be installed using snapcraft, with snap install ipfs
To see whether or not it installed correctly, use
$ ipfs help
This should give an overview of IPFS commands.
To initialize the IPFS repository use the command
$ ipfs init
This will create a key-pair for your node and a repository with some ipfs objects. This should return a start screen like this
Hello and Welcome to IPFS!██╗██████╗ ███████╗███████╗
██║██╔══██╗██╔════╝██╔════╝
██║██████╔╝█████╗ ███████╗
██║██╔═══╝ ██╔══╝ ╚════██║
██║██║ ██║ ███████║
╚═╝╚═╝ ╚═╝ ╚══════╝If you're seeing this, you have successfully installed
IPFS and are now interfacing with the ipfs merkledag!-------------------------------------------------------
| Warning: |
| This is alpha software. Use at your own discretion! |
| Much is missing or lacking polish. There are bugs. |
| Not yet secure. Read the security notes for more. |
-------------------------------------------------------Check out some of the other files in this directory:./about
./help
./quick-start <-- usage examples
./readme <-- this file
./security-notes
After starting the IPFS screen we can Add/Retrieve the file from the network
Adding a file on IPFS
For adding a file in IPFS we have to first create a new file in IPFS test repository by the following code
$ echo "Some text!" > IPFSfileName
We can upload this file to IPFS by the following command
$ ipfs add IPFSfileName
This will return a hash which is 46 characters long base 56 encoding that starts with Qm
that serves as the unique identifier for the content of that file. For example, here we got a hash after uploading a file as follows
$ QmahqCsAUAw7zMv6P6Ae8PjCTck7taQA6FgGQLnWdKG7U8
The file is pinned to the local storage, which means that once this system is connected to the swarm, people that have that hash identifier will be able to request the file.
To see which IPFS files are on system, use:
$ ipfs pin ls
This will list all the pinned files.
Downloading Files from IPFS
We first initialize the IPFS daemon:
$ ipfs daemon
The IPFS daemon set up localhost which allows you to interact with the IPFS network through your browser. The default is 8080.
We can look at files through the web-browser:
$ localhost:8080/ipfs/QmahqCsAUAw7zMv6P6Ae8PjCTck7taQA6FgGQLnWdKG7U8
A quick recap of IPFS system
- Nodes of Distributed Hash Table can store and share data without third-party coordination
- IPNS allows exchanged data to be instantly pre-authenticated and verified using public key cryptography.
- The Merkle DAG enables data to be uniquely identified, tamper-resistant and permanently stored
- You can access past versions of edited data via the Version Control System
We can conclude that IPFS provides high throughput, low latency, data distribution. It is also decentralized and secure. This opens up several interesting and exciting use cases.
References
- https://ipfs.io/
- https://blockonomi.com/interplanetary-file-system/
- https://www.youtube.com/watch?v=BA2rHlbB5i0
- https://medium.com/coinmonks/a-hands-on-introduction-to-ipfs-ee65b594937
- https://medium.com/coinmonks/interplanetary-file-system-ipfs-future-of-the-web-c45c955e384c
- https://hackernoon.com/a-beginners-guide-to-ipfs-20673fedd3f