What is IPFS?

What is IPFS

IPFS (InterPlanetary File System, InterPlanetary File System) is a permanent, decentralized way to save and share files, which is a content-addressable, versioned, peer-to-peer hypermedia distributed protocol.

  • Content-addressable: A file is identified by generating a unique hash of its content, not by where the file is saved. Only one file with the same content exists in the system, saving storage space
  • Versioning: Traceable file modification history
  • Peer-to-peer hypermedia: P2P saves various types of data

Think of IPFS as all file data is in the same BitTorrent group and accessed through the same Git repository.

In short, it combines the advantages of some successful systems (distributed hash table, BitTorrent, Git, self-authenticated file system), and it is a very powerful file access system.

IPFS usage scenarios

Juan Benet ([email protected]), the inventor of IPFS , assumed some usage scenarios in the IPFS technical white paper :

  • Mount global filesystems under /ipfs and /ipns
  • Mounted personal sync folder with version function
  • File encryption, data sharing system
  • Versioned package manager for all software (already implemented: https://github.com/whyrusleeping/gx )
  • Can be used as the root file system of a virtual machine
  • Can be used as a database: applications can directly operate Merkle DAG, with versioning, caching and distributed features provided by IPFS
  • Can do (encrypted) communication platform
  • Various types of CDNs
  • Permanent Web, there are no unreachable links

I think this will be useful for application developers as a database .

Installation and initialization

Download go-ipfs and decompress it (I did the following example on Windows 10, the decompression directory is D:\go-ipfs), and then go to the decompression directory to execute the command ipfs init, and the .ipfs directory will be created under the user's home (~) to store the data , the default maximum storage is 10G. The init command can take parameters, such as modifying the maximum storage, directory, etc., for details ipfs init help.

Continue with the command to ipfs daemonstart the node server:

  • Join the IPFS network
  • Local HTTP server, default port 8080
  • Process client commands for subsequent ipfs

Open a new command line and execute the command ipfs idto view the current node ID:

{
    "ID": "QmSYF1HZxhPUWWGrz5bMn16tdD73AeMVhp7pNSHkVCMF7R",
    "PublicKey": "....",
    "Addresses": [
      "/ip4/169.254.40.215/tcp/4001/ipfs/...",
      ....
    ],
    "AgentVersion": "go-ipfs/0.4.12/",
    "ProtocolVersion": "ipfs/0.1.0"
}

{ "ID": "QmSYF1HZxhPUWWGrz5bMn16tdD73AeMVhp7pNSHkVCMF7R", "PublicKey": "....", "Addresses": [ "/ip4/169.254.40.215/tcp/4001/ipfs/...", .... ], "AgentVersion": "go-ipfs/0.4.12/", "ProtocolVersion": "ipfs/0.1.0" }

Browser access http://localhost:5001/webui to enter the management interface, view the system status, manage files and configure the system.

configure

In addition to using the Web management interface to modify the configuration, you can also directly use the command ipfs config show > ipfs.confline to export the current configuration (JSON format, with few configuration items and obvious meanings), and then use ipfs config replace ipfs.confUpdate configuration after the modification, and restart the server to take effect. Of course, modifying the configuration can also be used directly ipfs config edit.

The final configuration file used by the server is stored in ~/.ipfs/config. Comparing the file just exported, we find that the exported file is only one less than this config Identity.PrivKey, that is, the RSA private key that is automatically generated when the node is initialized.

key pair

The RSA key pair is automatically generated when the node is initialized, and the private key does not have a password set.

The public key obtains the node id (that is, the above ) through multiple hashingQmSYF1HZxhPUWWGrz5bMn16tdD73AeMVhp7pNSHkVCMF7R . After the node server is started, it will exchange the public key with other nodes. In subsequent communication, the other party's public key is used to encrypt data. Verify that you are interacting with the correct node.

The private key is used to decrypt the received data and also used by ipns to bind the filename. The whole process does not introduce certificates, but only uses the PKI mechanism.

In short, I think you can ignore the key pair for the time being, and it may only be needed in some usage scenarios.

add files

My current directory structure is like this:

D:\GO-IPFS
│  build-log
│  config
│  install.sh
│  ipfs.conf
│  ipfs.exe
│  LICENSE
│  README.md
└─b3log
    └─hacpai
            README.md

D:\GO-IPFS │ build-log │ config │ install.sh │ ipfs.conf │ ipfs.exe │ LICENSE │ README.md │ └─b3log └─hacpai README.md

The directory I am going to add is b3log, execute the command:

D:\go-ipfs>ipfs add -r b3log
 94 B / 94 B [========================================== ===============================================] 100.00% 0s
added Qmco94dYP733XwrUqFUhDtDG8RsqmGQ6UDPvnmH4Pvy2rv b3log/hacpai/README.md
added Qmbkno2HVZdW7XfwsVjmuu9VDKBByczFR8qwsBXMjMrjPQ b3log/hacpai
added QmPxebZuW2pgfzj5JWq22KUzxStmqQ6i7YUK9Sq9xepXT9 b3log

D:\go-ipfs>ipfs add -r b3log 94 B / 94 B [=============================================================================================] 100.00% 0s added Qmco94dYP733XwrUqFUhDtDG8RsqmGQ6UDPvnmH4Pvy2rv b3log/hacpai/README.md added Qmbkno2HVZdW7XfwsVjmuu9VDKBByczFR8qwsBXMjMrjPQ b3log/hacpai added QmPxebZuW2pgfzj5JWq22KUzxStmqQ6i7YUK9Sq9xepXT9 b3log

So ipfs cat /ipfs/Qmco94dYP733XwrUqFUhDtDG8RsqmGQ6UDPvnmH4Pvy2rvwe can view the README.md using . It's fine on other nodes, just remember the hash of the file. We can try it on our own HTTP gateway (note that my port was changed to 5002, your default should be 8080):

9070383bdece4f6792a561c7b4fa98c4-image.png

Of course, you can also use the ipfs official HTTP gateway: https://ipfs.io/ipfs/Qmco94dYP733XwrUqFUhDtDG8RsqmGQ6UDPvnmH4Pvy2rv

get file

ipfs get /ipns/QmSYF1HZxhPUWWGrz5bMn16tdD73AeMVhp7pNSHkVCMF7R

ipfs get /ipns/QmSYF1HZxhPUWWGrz5bMn16tdD73AeMVhp7pNSHkVCMF7R

will fetch the b3log directory we just published.

Pin

The original intention of IPFS is to make users feel that all files are local, without "downloading files from remote servers". Pin is to keep files locally for a long time and not be garbage collected.

Execute ipfs pin lsto see which files are persistent locally. Files added through add are pinned by default.

bind node name

Each time the file is modified, add will return a different hash, which makes it impossible for a website to fix the access address, so we need to "bind" the node name through ipns.

The hash of the b3log directory above is QmPxebZuW2pgfzj5JWq22KUzxStmqQ6i7YUK9Sq9xepXT9that we publish the entire directory as the node root:

D:\go-ipfs>ipfs name publish QmPxebZuW2pgfzj5JWq22KUzxStmqQ6i7YUK9Sq9xepXT9
Published to QmSYF1HZxhPUWWGrz5bMn16tdD73AeMVhp7pNSHkVCMF7R: /ipfs/QmPxebZuW2pgfzj5JWq22KUzxStmqQ6i7YUK9Sq9xepXT9

D:\go-ipfs>ipfs name publish QmPxebZuW2pgfzj5JWq22KUzxStmqQ6i7YUK9Sq9xepXT9 Published to QmSYF1HZxhPUWWGrz5bMn16tdD73AeMVhp7pNSHkVCMF7R: /ipfs/QmPxebZuW2pgfzj5JWq22KUzxStmqQ6i7YUK9Sq9xepXT9

Then we can access through ipns, note that it is ipns :

D:\go-ipfs>ipfs cat /ipns/QmSYF1HZxhPUWWGrz5bMn16tdD73AeMVhp7pNSHkVCMF7R/hacpai/README.md
The piper will lead us to reason.

Welcome to the community of hackers and painters https://hacpai.com

D:\go-ipfs>ipfs cat /ipns/QmSYF1HZxhPUWWGrz5bMn16tdD73AeMVhp7pNSHkVCMF7R/hacpai/README.md The piper will lead us to reason. 欢迎访问黑客与画家的社区 https://hacpai.com

Every time you update the file in the future, just publish it again. Currently (v0.4.12) using ipns access will be very slow , it is said that v0.4.14 will solve it.

DNS resolution

IPFS allows users to use the existing domain name system so that files can be accessed with a friendly address, such as:

D:\go-ipfs>ipfs cat /ipns/ipfs.b3log.org/hacpai/README.md
The piper will lead us to reason.

Welcome to the community of hackers and painters https://hacpai.com

D:\go-ipfs>ipfs cat /ipns/ipfs.b3log.org/hacpai/README.md The piper will lead us to reason. 欢迎访问黑客与画家的社区 https://hacpai.com

Just add a TXT record to the DNS resolution:

record type host record record value
TXT ipfs dnslink=/ipns/QmSYF1HZxhPUWWGrz5bMn16tdD73AeMVhp7pNSHkVCMF7R

Summarize

  • IPFS is a permanent, decentralized way to save and share files, a content-addressable, versioned, peer-to-peer hypermedia distributed protocol
  • We can use it to access files and data will never be lost
  • Applications can use it as a database and automatically have versioning, caching and distributed features
  • The official reference implementation is written in golang , and languages ​​such as JavaScript, Python, and C are under development.
  • In short, IPFS is a very powerful file system

Original: https://hacpai.com/article/1511015097370
 

Two practical tutorials related to Ethereum are recommended:

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325063496&siteId=291194637