In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces how to use IPFS to build a decentralized distributed Wiki system, the content is very detailed, interested friends can refer to, hope to be helpful to you.
IPFS full name InterPlanetary File System, Chinese name: interstellar file system, is a network transfer protocol designed to create persistent and distributed storage and sharing files. It is a content addressable peer-to-peer hypermedia distribution protocol. The nodes in the IPFS network will form a distributed file system. It is an open source project developed by Protocol Labs (Protocol Lab) with the help of the open source community since 2014. It was originally designed by Juan Benet. IPFS is a peer-to-peer hypermedia protocol that makes the network faster, more secure, and more open. It is a global, point-to-point distributed file system that attempts to connect all computing devices with the same file system. Official website: https://ipfs.io/
A brief introduction to IPFS
IPFS- is also called "interstellar file system". To put it simply, it is a point-to-point distributed file system (like Bitcoin technology). Through the underlying protocol, files stored on IPFS systems can be quickly accessed anywhere in the world without the influence of firewalls (no network agents).
The Internet protocol we use today is called the hypertext protocol HTTP. This protocol has the characteristic of hyper-centralization.
In other words, you can download files from the Internet or browse the web, and you can only get the information you need from one data center at a time. If the data center fails, or is restricted or attacked, there will be problems with missing files or web pages that cannot be opened. For example, the information you have in a cloud disk suddenly cannot be downloaded, or the web page you want to visit cannot be opened for some policy reasons.
The purpose of IPFS is to solve these problems. In some ways, IPFS is like Web, and you can also link Internet addresses based on IPFS. But IPFS is decentralized, and it does not have the problem of main network failure of Web. Therefore, it is not impossible for IPFS to completely replace HTTP.
1.1 the difference between IPFS and HTTP four pain points of HTTP:
HTTP is inefficient and the server is expensive. Using the HTTP protocol, you can only download one file at a time from a computer server, rather than getting files from multiple computers at the same time. Video transmission through P2P can save 60% of bandwidth costs.
The average service life of deleted pages of historical documents is 100 days, and a large number of website files cannot be saved for a long time. Some important documents may disappear from the Internet forever because of improper operation.
The centralized network limits the opportunity the Internet has always been the catalytic converter of human progress, but the centralized network is easy to be controlled, which is a threat to the healthy development of the Internet.
Network applications rely too much on backbone networks to ensure the reliability of data, the applications we develop rely too much on large central servers, and ensure the security of data through a large number of backups.
The HTTP protocol has been used for 20 years. From HTTP 1.0 to the current HTTP5, the presentation of the web page is becoming more and more beautiful and rich, but the Browser/Server mode behind it has never changed.
What distinguishes IPFS from HTTP pain points:
IPFS for permanent storage of Internet information is like a distributed storage network (similar to SIA). Any resource stored in the system, including text, pictures, sound, video, and website code, is hashed through IPFS to generate a unique address. In the future, you can open them through this address. And this address can be shared. Due to the protection of the encryption algorithm, the address can not be tampered with and deleted (in a sense, if the password is broken, it is still possible to be tampered with or deleted, but the probability is very low). So, once the data is stored in IPFS, it will be permanent. For example, we often encounter the problem of deleting a resource that is inaccessible. This would not have happened on IPFS. Even if the site is revoked, the page can be accessed normally as long as the network that stores the site's information still exists. The more distributed networks a storage site has, the more reliable it will be. Unlike SIA, IPFS generally stores public information, which is available to the general public. There is a saying that if IPFS completely replaces HTTP, then human history will be preserved forever and will not be tampered with. This means that everything humans do will be recorded, whether it is right or wrong.
Solve the problem of excessive redundancy and achieve a sharing economy if you like a movie and are worried about the loss of movie resources, the usual practice is that you will download the movie on your computer. For example, the movie "Avatar" has been downloaded 16.58 million times in 2016, and the total number of downloads is even more staggering. Then an inevitable problem is that the same movie is stored repeatedly, resulting in a great waste of memory resources. This is the drawback of the HTTP protocol. If the same resource is backed up too many times, it will cause excessive redundancy. The emergence of IPFS can solve this problem very well. IPFS will save the file, do a hash calculation, word-for-word hash of the two files are the same. So, users only need to use the same hash value to access that file, which is the address of the file. As long as you get this address, you can share resources. Based on the permanent storage features above, you no longer have to worry about not finding a movie or backing up, because as long as there are so few people storing it on computers around the world, you can get it. Instead of repeatedly storing hundreds of thousands of copies.
At the same time, it is based on content rather than domain name addressing. There is a chunk chain running on IPFS's network, that is, a hash table used to store Internet files. Every time there is network access, the address of the content (file) is queried on the chain. A file (content) has uniqueness. A file joins IPFS's network and assigns a unique encrypted hash value to the content based on computation. This will change our habit of using domain names to access the network. Provides a historical version controller of the file (similar to Git), and lets multiple nodes save different versions of the file.
Nodes store incentives, and tokens are divided into incentives through the use of tokens (FileCoin) to give each node the motivation to store data. Filecoin is a storage network driven by cryptocurrency. Miners get Filecoin by providing open hard disk space for the network, while users use Filecoin to pay for storing encrypted files in a decentralized network.
1.2 how IPFS works
Each file and all blocks in it are assigned a unique fingerprint called an encrypted hash.
IPFS deletes duplicate files with the same hash value through the network, and it is possible to determine which files are redundant by calculation. And track the version history of each file.
Each network node stores only what it is interested in, as well as some index information, which helps to figure out who is storing what.
When looking for a file, you can find the node where the modified file is stored on the network through the hash value of the file, and find the file you want.
Using a name called IPNS (decentralized naming system), each file can be collaboratively named an easy-to-read name. By searching, you can easily find the file you want to view.
From the introduction of IPFS, we can see that IPFS envisions that all network terminal nodes not only play the role of Browser or Client, in fact, everyone can be the operator of this network, and everyone can be the server.
1.3 IPFS application scenarios
II. IPFS configuration 2.1 IPFS download
Download address: https://dist.ipfs.io/#go-ipfs
The version downloaded and used for this blog is: go-ipfs Version v0.4.13 for OS X 64bit
2.2 IPFS installation
Ipfs-- help / / Open the command line and enter. When the Log message appears, it indicates that the installation is successful. 2.3IPFS local deployment 2.3.1 create nodes.
Create a new warehouse under the local global catalog:
2.3.2 Node configuration cd ~ / .ipfsexport EDITOR=/usr/bin/vimipfs config edit
After ipfs config edit is executed, an ipfs node configuration file opens, and the configuration parameters can be modified as follows:
{"Identity": {"PeerID": "QmXXXXXXXXXXXXXXX", "PrivKey": "XXXXXXXXXXXX"}, "Datastore": {"StorageMax": "10GB", "StorageGCWatermark": 90, "GCPeriod": "1h", "Spec": {"mounts": {"child": {"path": "blocks", "shardFunc": "/ repo/flatfs/shard/v1/next-to-last/2", "sync": true, "type": "flatfs"}, "mountpoint": "/ blocks", "prefix": "flatfs.datastore" "type": "measure"}, {"child": {"compression": "none", "path": "datastore", "type": "levelds"}, "mountpoint": "/", "prefix": "leveldb.datastore", "type": "measure"}], "type": "mount"}, "HashOnRead": false, "BloomFilterSize": 0}, "Addresses": {"Swarm": ["/ ip4/0.0.0.0/tcp/4001", "/ ip6/::/tcp/4001"] "Announce": [], "NoAnnounce": [], "API": "/ ip4/127.0.0.1/tcp/5001", "Gateway": "/ ip4/127.0.0.1/tcp/8080"}, "Mounts": {"IPFS": "/ ipfs", "IPNS": "/ ipns", "FuseAllowOther": false}, "Discovery": {"MDNS": {"Enabled": true, "Interval": 10}, "Ipns": {"RepublishPeriod": "," RecordLifetime ":" "ResolveCacheSize": 128}, "Bootstrap": ["/ dnsaddr/bootstrap.libp2p.io/ipfs/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN", "/ dnsaddr/bootstrap.libp2p.io/ipfs/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa", "/ dnsaddr/bootstrap.libp2p.io/ipfs/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb", "/ dnsaddr/bootstrap.libp2p.io/ipfs/QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt", "/ ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ", "/ ip4/104.236.179.241/tcp/4001/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM" / ip4/128.199.219.111/tcp/4001/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu "," / ip4/104.236.76.40/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64 "," / ip4/178.62.158.247/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd "," / ip6/2604:a880:1:20::203:d001/tcp/4001/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM "," / ip6/2400:6180:0:d0::151:6001/tcp/4001/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu " "/ ip6/2604:a880:800:10::4a:5001/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64", "/ ip6/2a03:b0c0:0:1010::23:1001/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd"], "Gateway": {"HTTPHeaders": {"Access-Control-Allow-Headers": ["X-Requested-With", "Range"], "Access-Control-Allow-Methods": ["GET"], "Access-Control-Allow-Origin": ["*"]}, "RootRedirect": "" "Writable": false, "PathPrefixes": []}, "API": {"HTTPHeaders": null}, "Swarm": {"AddrFilters": null, "DisableBandwidthMetrics": false, "DisableNatPortMap": false, "DisableRelay": false, "EnableRelayHop": false, "ConnMgr": {"Type": "basic", "LowWater": 600, "HighWater": 900, "GracePeriod": "20s"}, "Reprovider": {"Interval": "12h", "Strategy": "all"}, "Experimental": {"FilestoreEnabled": false "ShardingEnabled": false, "Libp2pStreamMounting": false}} 2.3.3 node ID
There will be a unique identity for each node. Check the node ID as follows:
Ipfs id2.3.4 starts the node server ipfs daemon
Port 5001 is occupied, which can be solved by modifying the node configuration file, as shown below:
Find all the places where port 5001 is configured
Replace with port 5002
Start the node again and the service starts successfully.
2.3.5 configure CORS cross-domain resource sharing
To facilitate the development and data access of the subsequent frontend, configure the cross-domain resource sharing CORS in advance, ctrl-c exits the ipfs, and then follow the steps below for cross-domain configuration:
Ipfs config-json API.HTTPHeaders.Access-Control-Allow-Methods'["PUT", "GET", "POST", "OPTIONS"] 'ipfs config-json API.HTTPHeaders.Access-Control-Allow-Origin' ["*"] '2.3.6 verification
The browser opens http://localhost:5002/webui and the Web Console graphical console appears.
Here you can see all the node information of the run on the main network and the configuration data related to the local node.
III. IPFS project practice
Use IPFS to build a decentralized and untampered distributed Wiki system.
3.1 create a new workplace
Taking into account the convenience of later open source and promotion, here I am hosted on github, you can choose their own familiar code hosting services, you can also clone my project-> ipfs-wiki-system, on the basis of your secondary development, if you have any questions, welcome to submit issue to me.
Building cd workplace/ipfs-wiki-system/wiki-releasell in mkdir workplacecd workplacegit clone git@github.com:daijiale/ipfs-wiki-system.git3.2 wiki system
You can see the following file:
Wiki-release
Index.html / / markdown template rendering
Navigation.md / / Navigation markdown
Index.md / / Home markdown
You can refer to ipfs-wiki Demo, according to your own needs, through markdown to customize different wiki content and directories.
3.3 Mount the local node
Remember the hash value of the file root: QmV5ZVQxXURKPDcVDW8WjpLCiQYvNzg173XcB6rYFevoXm
3.4 publish to the main network ipfs daemon
Https://ipfs.io/ipfs/QmV5ZVQxXURKPDcVDW8WjpLCiQYvNzg173XcB6rYFevoXm/#!index.md
3.5 publish to IPNS
Because the hash of ipfs corresponds to an immutable content, after each update of the website, the hash of website will change, and the old link cannot access the new content.
Ipfs provides ipns to solve the update problem.
Ipfs allows users to use a private key to attach a reference to a hash and a public key hash (pubkeyhash for short) to represent the latest version of your site.
The specific actions are:
In the above way, the binding between website and a fixed link is completed: QmPS5NRXPCeAUtofKbW7c58Qm4PpM8mPEVJvaooE13LF78
3.6 bind Verification ipfs name resolve QmPS5NRXPCeAUtofKbW7c58Qm4PpM8mPEVJvaooE13LF78/ipfs/QmV5ZVQxXURKPDcVDW8WjpLCiQYvNzg173XcB6rYFevoXm
IPNS accesses fixed node Hash:
Https://ipfs.io/ipns/QmPS5NRXPCeAUtofKbW7c58Qm4PpM8mPEVJvaooE13LF78
The verification is successful, and the following effect occurs.
3.7 decentralized verification
With the node previously published to the main network as the first node, we create a new node locally to simulate the identity of the second node, and open Web Console:
On the second node, we can still query the ipfs-wiki-system directory file data on the main network of the first node through IPFS HASH.
At the same time, we can also see that the console shows that the number of block nodes we released to the main network has spread to 275.
In other words, individuals from other 274 places around the world have recorded your previously published data in their "bookkeeping book", even if some of the servers are down (natural and man-made disasters, digging cables, doomsday, etc.). As long as there is a node secure, your data will not be lost, the real meaning of the decentralized service mechanism.
IV. Project experience
On how to use IPFS to build decentralized distributed Wiki system to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.