IPFS learning -IPNS

Star Name System (IPNS) is a variable to create a link to update IPFS content of the system, because the object is a content addressable IPFS, they will lead to changes in the contents of the address change. For changing things it is useful. But it is difficult to obtain the latest versions of some of the content.

In IPNS the name is a hash of the public key. It is associated with a record that contains information about its link hash of the message signed by the corresponding private key. The new record can be signed and released at any time.
View IPNS addresses, use the /ipns/prefix:

/ipns/QmSrPmbaUKA3ZodhzPWZnpFgcPMFWF4QsxXbkWfEptTBJd

IPNS is not the only way to create variable address on IPFS. You can also use DNSLink (IPNS much faster than the current, and also uses a more readable name). Other community members are exploring ways to use the generic name block chain store records.

For example:
Suppose you want to publish your website in IPFS. You can use the Files API to publish static Web site, and then you can get a link to the CID. However, when you need to make changes, problems will appear: You will get a new CID, because you now have a different content. Also, you can not always give the new address others.
This is the Name API handy place. Using it, you can create a stable IPNS addresses that point to your website the latest version of CID.

//文件的地址
const addr = '/ipfs/QmbezGequPwcsWo8UL4wDF6a8hYwM1hmbzYv2mnKkEWaUp'

ipfs.name.publish(addr, function (err, res) {
    // 接收到包含两个字段的资源:
    //   - name: 被发布的内容的名字
    //   - value: 名字指向的"真实"的地址
    console.log(`https://gateway.ipfs.io/ipns/${res.name}`)
})

In this way, the same address can be used to re-release a new version of the page, by default, ipfs.name.publishwill use the node ID.

Guess you like

Origin www.cnblogs.com/cbkj-xd/p/12059887.html