目录

什么是 IPFS?

什么是 IPFS?

让我们用一句话定义IPFS:

IPFS 是一个用来存储及访问文件、站点、应用和数据的分布式系统。

准确的讲那是什么意思? 假设我们要开始访问Aardvark的维基百科资料,你应该使用下面这个链接开始访问维基百科: https://en.wikipedia.org/wiki/Aardvark

当你把上面那个 URL 输入到你的浏览器地址栏,计算机会询问维基百科的一台服务器:“ Aardvark 页面在哪里?”。这台服务器可能在国家的另一边甚至在另外一个星球。

其实,这里不止一个方式让你可以找到 Aardvark 页面!在 IPFS 里,存有一个维基百科的镜像可用作备用。如果你用了 IPFS,你的计算机会以下面的方式获取到 Aardvark 页面:

/ipfs/QmXoypizjW3WknFiJnKLwHCnL72vedxjQkDDP1mXWo6uco/wiki/Aardvark.html

提示 访问上面链接最简单的方法是在浏览器里通过 IPFS 网关来访问。只需要把 https://ipfs.io 加到上面链接的前面即可。这样你就可以通过这个 访问了:https://ipfs.io/ipfs/QmXoypizjW3WknFiJnKLwHCnL72vedxjQkDDP1mXWo6uco/wiki/Aardvark.html 注意:ipfs.io这个域名在国内无法访问。

IPFS 知道怎么找到 Aardvark 页面,但是是通过文件内容而不是文件位置,这种技术叫做内容定位。Aardvark 页面的 IPFS 版本URL用上面的一串十六进制数字(QmXo…) 定位页面内容,而不是向维基百科服务器询问文件在哪里。在 IPFS, 你的计算机用 IPFS 向全世界大量的计算机询问你要的 Aardvark 页面内容,任何拥有这个信息的人都可以向你提供Aardvark 页面,而不仅仅是维基百科。

而且,当你使用 IPFS 时,你不仅仅从别人那下载文件,你的计算机也会帮助别人存放信息。当你的朋友需要一些维基百科页面时,你会跟你上面做的一样,可能会通过 IPFS 从你这里获取某个维基百科页面。

IPFS 不仅仅可以保存 web 页面,也可以保存很多种类文件,包括文档,邮件、甚至是数据库记录。

去中心化

从多个位置下载文件,而不是从某个受监管的组织那里下载。

  • 构建弹性网络. 如果有人攻击了维基百科的网站或者维基百科的一个员工误操作导致机房着火,你还可以从其他地方获取到想要的信息。
  • 让审查内容更难. 因为 IPFS 上的文件可以来自任何地方,很难(无论是政府、企业或其他组织)封锁某些内容。我们希望当审查发生时, IPFS 可以给人们提供一些规避方式。
  • 当距离太远或者链接断开时可以加速web访问. 如果你可以从很近的邻居哪里获得文件,而不是从上百活上千公里之外的服务器上获取,访问速度可以得到很大提升。如果你的社区网络不太好,这就有特别重要的意义了(有钱有专家的组织会使用多数据中心或CDN 服务来解决。IPFS 希望每个人都可以做到)

最后一点,实际上IPFS 的全名来自于:星际文件系统( InterPlanetary File System)。我们努力构建一个能跨越网络受限地域或偏远地区的系统。这是一个理想化的目标,它让我们坚持努力工作和思考,现在,我们为这些目标的努力产出也非常有用。

内容定位

考虑到初学者友好的原则,关于为什么使用加密哈希和内容定位的事情,请参考 ProtoSchool 的教程,去中心化web的内容定位 /images/extlink.svg

上面 Aardvark 页面链接是怎么回事?有点不同寻常:

/ipfs/QmXoypizjW3WknFiJnKLwHCnL72vedxjQkDDP1mXWo6uco/wiki/Aardvark.html /ipfs/后面的字符被称为内容标识(content identifier,简称CID),它也是 IPFS 如何从多个地方找到内容的关键。

传统 URL 和文件路径是这样的:

用这些路径来描述文件是在哪里的——文件在哪台计算机上、在哪个驱动器里。如果文件在多个地方,这个方法就不奏效了,比如在你邻居的电脑里或者隔了几座城的朋友电脑里。

为了代替位置定位,IPFS 用文件夹里面有什么或者用文件内容来定位文件。上面的内容标识是那个地址所包含文件内容的加密哈希值。这哈希值是文件内容唯一的,即使内容长度可能远远大于内容标识的长度。内容标识也可以用来对文件进行校验,避免有人修改了你的数据(如果不了解哈希,请参考哈希概念介绍)。

NOTE Why do we say “content” instead of “files” or “web pages” here? Because a content identifier can point to many different types of data, such as a single small file, a piece of a larger file, or metadata. (In case you don’t know, metadata is “data about the data.” You use metadata when you access the date, location, or file size of your digital pictures, for example.) So, an individual IPFS address can refer to the metadata of just a single piece of a file, a whole file, a directory, a whole website, or any other kind of content. For more on this, check out our guide to how IPFS works.

Because the address of a file in IPFS is created from the content itself, links in IPFS can’t be changed. For example …

  • If the text on a web page is changed, the new version gets a new, different address.
  • Content can’t be moved to a different address. On today’s internet, a company could reorganize content on their website and move a page at http://mycompany.com/what_we_do to http://mycompany.com/services. In IPFS, the old link you have would still point to the same old content.

Of course, people want to update and change content all the time and don’t want to send new links every time they do it. This is entirely possible in an IPFS world, but explaining it requires a little more info than what’s within the scope of this IPFS introduction. Check out the concept guides on IPNS, the Mutable File System (MFS), and DNSLink to learn more about how changing content can work in a content-addressed, distributed system.

It’s important to remember in all of these situations, using IPFS is participatory and collaborative. If nobody using IPFS has the content identified by a given address available for others to access, you won’t be able to get it. On the other hand, content can’t be removed from IPFS as long as someone is interested enough to make it available, whether that person is the original author or not. Note that this is similar to the current web, where it is also impossible to remove content that’s been copied across an unknowable number of websites; the difference with IPFS is that you are always able to find those copies.

Participation

While there’s lots of complex technology in IPFS, the fundamental ideas are about changing how networks of people and computers communicate. Today’s World Wide Web is structured on ownership and access, meaning that you get files from whoever owns them — if they choose to grant you access. IPFS is based on the ideas of possession and participation, where many people possess each others’ files and participate in making them available.

That means IPFS only works well when people are actively participating. If you use your computer to share files using IPFS, but then you turn your computer off, other people won’t be able to get those files from you anymore. But if you or others make sure that copies of those files are stored on more than one computer that’s powered on and running IPFS, those files will be more reliably available to other IPFS users who want them. This happens to some extent automatically: by default, your computer shares a file with others for a limited time after you’ve downloaded it using IPFS. You can also make content available more permanently by pinning it, which saves it to your computer and makes it available on the IPFS network until you decide to unpin it. (You can learn more about this in our guide to persistence and pinning.)

If you want to make sure one of your own files is permanently shared on the internet today, you might use a for-pay file-sharing service like Dropbox. Some people have begun offering similar services based on IPFS called pinning services. But since IPFS makes this kind of sharing a built-in feature, you can also collaborate with friends or partner with institutions (for example, museums and libraries might work together) to share each others’ files. We hope IPFS can be the low-level tool that allows a rich fabric of communities, business, and cooperative organizations to all form a distributed web that is much more reliable, robust, and equitable than the one we have today.