First views on IPFS?

Tram Ho

At the present time, the main role on the Internet is the HTTP protocol vs the role of the HyperText Transfer Protocol with the client – server model. Until recently, an emerging name was It is expected that this protocol will be able to replace IPFS. So what is IPFS? How does it work? Those are the questions you will find answers through this article, let’s find out.

What is IPFS?

The limitations that HTTP currently encounters are that it depends a lot on the server (representing the client-server model). And due to server dependencies, it has limitations such as if the server goes down, the client will not be able to access, or the server holds too much of the user’s data, leading to scandals related to personal data, … Therefore, IPFS was born with the idea of ​​P2P model instead of Client-server. IPFS (short for InterPlanetary File System ) is a source code distribution protocol of hypermedia protocol based on content and identity. A combination of many technologies such as DHT , Git and BitTorrent

To make it easier for us to understand that we normally upload an information online, the data will be uploaded to the server for storage, which is a potential risk if the server goes down. But with IPFS, you will upload it to other computers that are participating in the network (of course, the data is already encrypted), so there is no need to worry if the server goes down, you will not be able to access it. Moreover, it will also be faster because the network will calculate the bandwidth so the data download will be from the machine containing the closest data, not fixed as in the client server model.

We can sum up some of the following benefits:

  • Avoid server dependencies
  • There is no centralized model
  • Reduce costs (for developers, for example, server money, …)
  • Speed ​​improvements (the more you use this, the faster it is like BitTorrent)

How does it work?

First we will have to review everything that is instead of the types of objects that the server stores such as photos, text, videos, … then on IPFS they will be saved as hash codes (also called opposites). IPFS icon). The idea is that if your browser wants to access a certain page on IPFS, then just give the hash code and the network will find the machine that stores the data vs the same hash code and then download that page from the computer. on for you.

So IPFS will have 2 parts:

  1. Identify a file with a content address (the hash value of that file)
  2. Search for it (when you have a hash of the file or web page to download, it will find and connect to the best machine to download for you)

It is the result of a P2P overlay that gives you fast routing capabilities

Deeper, IPFS objects form a cryptographically valid data structure called DAG Merkle and this data structure can be used to model many other data structures. I will introduce IPFS and Merkle DAG objects and give examples of structures that can be modeled with IPFS.

IPFS Objects

This part is a bit of a practice so you can go to IPFS here

An IPFS object is a data structure with two fields:

  • Data: a pile of unstructured binary data with the size <256 kB.
  • Links: an array of Links structures. Here are links to other IPFS objects.

The structure of Link has three fields:

  • Name: The name of the link
  • Hash: hash of the linked IPFS object
  • Size: the cumulative size of the associated IPFS object, including its following links (Size field is primarily used to optimize P2P networks)

IPFS objects are often called with their Base58 hash function.

Illustration

Merkle DAG

DAG (Direct Acyclic Graph) is a form of graph that each node will link to another node and does not allow joining nodes. For example A-> B-> C is an instance of DAG in which B is a child of A or can be said that A is associated with B. We say the node that is not a child of another node is the DAG root nodes.

Merkle-DAG is a DAG in which each node has a unique id and this is the result of the content hash of that node. This brings a few things to note:

  1. Child nodes will have to be born before the parent node has the id to link to.
  2. Each node in Merkle-DAG is the root of a Merkle-DAG sub
  3. The Merkle-DAG buttons are immutable. Any change in a node will change its id and thus affect all elements in the DAG.

You can check out the illustration of merkle here

Practice a little to make it easier to understand:

When you successfully install ipfs on your computer. Then try uploading something online. I will upload the correct cover image for this post.

Try uploading something online

Now the image file has been uploaded to the network and other computers can be downloaded by command

Or can be viewed online by going to the link with the last path is the hash code: https://gateway.ipfs.io/ipfs/QmVMFbKgoG2r1BZQW5hpiYUAt2ZTJFFBs6tW6UCRqeKRrM

(sort of they have a server for me to see but users do not need to download ipfs, also due to the cumbersome approach so it is not used so much ? )

Basically the output of the hash code would look like this:

There are 2 underground steps below, Raw and Digest

When we first upload an image, the image will be converted into RAW data (in binary format) that the computer can understand. Now, to make it content-addressable , we have to devise a method so that we can convert this image data into a unique id for internal content. its content.

The next job is the hash function. The hash function takes data (any data from text, images, etc.) as input and gives us a unique ( Digest ) output. If we change even one pixel in this image, the output will be different. This shows its anti-forgery properties. So if you transfer this image to anyone, he / she can check if the received image has been faked.

After we pass the Raw data to the SHA256 hash and get the unique Digest. Now, we need to convert this Digest into CID (Content Identifier). This CID is what IPFS will look for when we try to download images again. To do this, IPFS uses something called Multihash . To say more about it I will mention in the following article.

Going back a bit to illustrate the theoretical fields above we try to run the command

For the image we just uploaded, it doesn’t have much links so it will only see the “Data” field and “Links” is empty. But for the hashes like the original readme when we successfully init.

You will see that the Link section will be very long because each file in it like about, contact, … is linked to different files on the network.

Data and Links of IPFS objects are saved to the Merkle DAG data structure (Directed Acyclic Graph). To make it easier to imagine, it looks like this

illustration for the original readme file

File systems

IPFS can easily represent a file system consisting of files and directories

Small Files

A small file defined as <256kB is represented by an IPFS object with a Data field of empty file contents and an array of Links .

Note that the file name is not part of the IPFS object, so two files with different names and the same content will have the same representation of the IPFS object and therefore the same hash function

For example, let’s try uploading a Hello World content file. Same as above then run

Large Files

Defined as files> 256kB is represented by a list of links to files <256 kB.

Directory Structures

Just like a large file we can go to each directory by adding paths to that directory behind the hash. Continue as if in some files have the same file content the same. That’s also the beauty of hashes, files with the same content will have the same hash so just link to one place instead of backing up many of the same. For example, as shown below

Versioned File Systems

Basically it is just like git other than it is distributed rather than on the server of git. The basic idea is that it will hash the files if modified, it will generate another hash or it will still link to the old file.

The work of trying to understand the technology of something is like gold mining so my next article will try to go deeper into the mechanism of ipfs operation as well as other concepts of ipfs.

The following article: I love you so much

Reference

Share the news now

Source : Viblo