IPFS — The Permanent, Distributed Web Continues…..

IPFS by Example from Dr. Christian Lundkvist

IPFS (InterPlanetary File System) is a synthesis of well-tested internet technologies such as DHTs, the Git versioning system, and BitTorrent. It creates a P2P swarm that allows the exchange of IPFS objects. The totality of IPFS objects forms a cryptographically authenticated data structure known as a Merkle DAG and this data structure can be used to model many other data structures. We will in this post introduce IPFS objects and the Merkle DAG and give examples of structures that can be modelled using IPFS.

  • Data — a blob of unstructured binary data of size < 256 kB.
  • Links — an array of Link structures. These are links to other IPFS objects.
  • Name — the name of the Link.
  • Hash — the hash of the linked IPFS object.
  • Size — the cumulative size of the linked IPFS object, including following its links.
$ ipfs object get QmarHSr9aSNaPSR6G9KFPbuLV9aEqJfTk1y9B8pdwqK4Rq{
"Links": [
"Name": "AnotherName",
"Hash": "QmVtYjNij3KeyGmcgg7yVXWskLaBtov3UYL9pgcGK3MCWu",
"Size": 18
"Name": "SomeName",
"Hash": "QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDC",
"Size": 58
"Data": "Hello World!"
$ ls -R ipfsdir/hello.txt ipfssubdiripfsdir//ipfssubdir:ipfsrocks.txt
$ ipfs add ipfsdir -radded QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u ipfsdir/hello.txtadded QmdWAgBc1yjQz6G3wNSmeQk7ZFBAh7LvaL7GSiFDEvCMGT ipfsdir/ipfssubdir/ipfsrocks.txtadded QmSC7kzH6k6W8Pf8i98NivocmT2jcYPgDhZtMWahmZUczg ipfsdir/ipfssubdiradded QmRuftkYACe3pCjyoZGXYyr1HdqctecmPcq8C9oFyMxgaS ipfsdir
$ ipfs add ipfsdir -radded QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u ipfsdir/hello.txtadded QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u ipfsdir/ipfssubdir/helloworld.txtadded QmdWAgBc1yjQz6G3wNSmeQk7ZFBAh7LvaL7GSiFDEvCMGT ipfsdir/ipfssubdir/ipfsrocks.txtadded Qmd2zXenEQVBGt1wbYYDXZFBQiXCvfU7JkZb7u1Sw7ujRd ipfsdir/ipfssubdiradded QmNoX6nF2ccQkH3AHKy4HvphK8WwHa19eez7YqjrxEUE2z ipfsdir
$ ipfs pin add QmNoX6nF2ccQkH3AHKy4HvphK8WwHa19eez7YqjrxEUE2z
$ ipfs daemon
Initializing daemon...
Adjusting current ulimit to 2048...
$ ipfs swarm peers

Versioning of File Systems

To understand the versioning, we will now change the content of file helloworld.txt to Hello World IPFS. We can see a change in the hashes of the changed files and corresponding directories.

$ ipfs add ipfsdir -radded QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u ipfsdir/hello.txtadded QmamMpGqGkkf3v1iApshHoTHjx2PXJPJWvqQ8y55eeeoYn ipfsdir/ipfssubdir/helloworld.txtadded QmdWAgBc1yjQz6G3wNSmeQk7ZFBAh7LvaL7GSiFDEvCMGT ipfsdir/ipfssubdir/ipfsrocks.txtadded QmWtucfHnZhbURkUAnzJtsoj7pVi8TmLp9K1WSD1C2jJqc ipfsdir/ipfssubdiradded QmbzoYKQ8FvWDTQ5KX8LpeRWt4w48QXRgaFaKuLq14pJ4M ipfsdir

Data Immutability

As we have seen that files on IPFS are given a generated hash value. As in the example above —

Data distribution & speed

As I mentioned earlier that IPFS is a peer-to-peer protocol somewhat similar to BitTorrent. When I download a file some of that data can be shared with others. So let say A computer (the client) in San Fransisco request a file from a computer (the server) in Boston City. In traditional HTTP client-server model, it just takes longer to communicate due to the distance between SFO and Boston city. Also in case if the file is popular, lots and lots of client from other locations would be asking this file and hence creating the load on the server in Boston. If in case server machine is down then 404 errors. Whereas in IPFS someone else in San Fransisco may have downloaded this file from the server in Boston then I could just download it from them. If the file is popular then more nodes nearby will have copies to share which will takes the load off the Boston server and distributes it. In this case, even if Server in Boston is down, I might still access the file from other nodes and that too with confidence that nobody would have tampered the file because of immutability feature which we discussed a short while ago.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store