原文:Dweb: Building Cooperation and Trust into the Web with IPFS
做者:Kyle Drake, Marcin Rataj 发表时间:August 29, 2018
译者:西楼听雨 发表时间: 2018/09/02
原文是 Mozilla 开发者网站发布的关于 Dweb 的概念、应用及使用案例介绍的系列文章中的第五篇。(转载请注明出处)javascript
本系列各篇章的翻译连接以下:html
译注:下面是斜体文本为原文的编者按。java
In this series we are covering projects that explore what is possible when the web becomes decentralized or distributed. These projects aren’t affiliated with Mozilla, and some of them rewrite the rules of how we think about a web browser. What they have in common: These projects are open source, and open for participation, and share Mozilla’s mission to keep the web open and accessible for all.node
在这个系列中,咱们会讲到一些正在尝试探索在 Web 变为去中心化或分布式的时候存在哪些可能性的项目,这些项目不附属于 Mozilla,其中一些项目还从新定义了咱们对 web 浏览器的认识。他们都有共同点:这些项目都是开源的,开放参与的,而且和 Mozilla ”keep the web open and accessible for all (让 Web 对全部人保持开放和可访问)“ 的宗旨一致。git
Some projects start small, aiming for incremental improvements. Others start with a grand vision, leapfrogging today’s problems by architecting an idealized world. The InterPlanetary File System (IPFS) is definitely the latter – attempting to replace HTTP entirely, with a network layer that has scale, trust, and anti-DDOS measures all built into the protocol. It’s our pleasure to have an introduction to IPFS today from Kyle Drake, the founder of Neocities and Marcin Rataj, the creator of IPFS Companion, both on the IPFS team at Protocol Labs -Dietrich Ayalagithub
一些项目成立时较小,采起逐步地提高;另一些项目成立时目标远大,经过设计一套美好世界架构来颠覆式地解决当今存在的问题。 行星网文件系统 (IPFS: The InterPlanetary File System) 绝对是后者 —— 经过一个具有可伸缩、可信任、防 DDOS 攻击的网络协议层尝试对 HTTP 作总体替换。咱们很是荣幸请到 Neocities 的创始人 Kyle Drake 和 IPFS Companion 的建立者 Maricin Rataj 对 IPFS 作一个介绍,他们两位都是 Protocol Labs (协议实验室) 的 IPFS 团队成员。——Dietrich Ayalaweb
We’re a team of people all over the world working on IPFS, an implementation of the distributed web that seeks to replace HTTP with a new protocol that is powered by individuals on the internet. The goal of IPFS is to “re-decentralize” the web by replacing the location-oriented HTTP with a content-oriented protocol that does not require trust of third parties. This allows for websites and web apps to be “served” by any computer on the internet with IPFS support, without requiring servers to be run by the original content creator. IPFS and the distributed web unmoor information from physical location and singular distribution, ultimately creating a more affordable, equal, available, faster, and less censorable web.数组
咱们是来自世界各地的人们所组成的一个团队,咱们的工做内容是 IPFS——一种分布式 Web 的实现,旨在用一种新协议替换掉 HTTP,这种新的协议是由各个独立个体所支撑的。 IPFS 的目标是“再去中心化(re-decentrialize)”,将现有的面向地址的 HTTP 替换为面向内容的协议,无需基于对第三方的信任。这使得网站和 Web 应用能够由网络中支持 IPFS 的其余电脑来进行提供,无须内容的最初建立者配备服务器。IPFS 和 分布式 Web 去除了信息的物理位置要求和单一分发节点的特色,最终建立出一个更加可负担、平等、可用、快速和内容审查风险更低的 Web。浏览器
IPFS aims for a “distributed” or “logically decentralized” design. IPFS consists of a network of nodes, which help each other find data using a content hash via a Distributed Hash Table (DHT). The result is that all nodes help find and serve web sites, and even if the original provider of the site goes down, you can still load it as long as one other computer in the network has a copy of it. The web becomes empowered by individuals, rather than depending on the large organizations that can afford to build large content delivery networks and serve a lot of traffic.服务器
The IPFS stack is an abstraction built on top of IPLD and libp2p:
IPFS 的设计理念是 “分布式” 和 “逻辑上去中心化”。IPFS 是由许多节点组成的一张网络,各节点能够经过用一个内容 hash 来查找一张分布式 Hash 表 (Distributed Hash Table (DHT)),以此相互帮助找寻数据。这种特色带来的效果就是全部节点都为数据的找寻提供帮助并提供数据,即使最初的提供者下线了,只要还有一台电脑中有副本,咱们就仍然能够加载到它。这样 Web 就转变为了由个体所支撑,而不是依赖于那些能够提供大规模的内容分发网络和大规模流量访问的大型组织。
IPFS 栈是创建在 IPLD 和 libp2p 之上的一种抽象:
We have a reference implementation in Go (go-ipfs) and a constantly improving one in Javascript (js-ipfs). There is also a long list of API clients for other languages.
Thanks to the JS implementation, using IPFS in web development is extremely easy. The following code snippet…
IPFS 规范如今已经有了 GO 语言和 JavaScript 的实现了,他们分别是 go-ipfs 和 js-ipfs (正在不断完善中)。除此以外,也还有许多其余语言的 API 客户端实现。
得益于这款 JS 实现,在 web 开发中使用 IPFS 变得极其容易。下面这段代码演示了
<script src="https://unpkg.com/ipfs/dist/index.min.js"></script>
请打开控制台 (Ctrl+Shift+K)
<script> const ipfs = new Ipfs() const data = 'Hello from IPFS, <YOUR NAME HERE>!' // Once the ipfs node is ready // 当 ipfs 节点准备完成时 ipfs.once('ready', async () => { console.log('IPFS 节点准备完成! 当前版本为: ' + (await ipfs.id()).agentVersion) // convert your data to a Buffer and add it to IPFS // 将数据转换成一个 Buffer 后再添加到 IPFS console.log('要发布的数据: ' + data) const files = await ipfs.files.add(ipfs.types.Buffer.from(data)) // 'hash', known as CID, is a string uniquely addressing the data // and can be used to get it again. 'files' is an array because // 'add' supports multiple additions, but we only added one entry // 这里的'hash' 就是 CID, 它是一个惟一标志这份数据的字符串,能够用其取回数据。 // 而 'files' 则是一个数组,由于 'add' 操做支持批量添加, // 只不过在这里咱们只添加了一条 const cid = files[0].hash console.log('数据所得到的 CID: ' + cid) // read data back from IPFS: CID is the only identifier you need! // 从 IPFS 回读数据:只须要 CID 就能够了 const dataFromIpfs = await ipfs.files.cat(cid) console.log('从 IPFS 回读出来的数据: ' + String(dataFromIpfs)) // Compatibility layer: HTTP gateway // 兼容性适配层:HTTP 网关 // (译注:为了兼容 HTTP,能够经过公共的 HTTP 网关用 http 连接得到数据) console.log('Bonus: open at one of public HTTP gateways: https://ipfs.io/ipfs/' + cid) }) </script>
复制代码
Everyone with the CID can access it. Sensitive files should be encrypted before publishing.
任何人只要有这份数据的 CID,均可以获得这份数据。因此敏感文件在发布前应该先进行加密。
The permanence of content-addressed data in IPFS is intrinsically bound to the active participation of peers interested in providing it to others. It is impossible to remove data from other peers but if no peer is keeping it alive, it will be “forgotten” by the swarm.
The public HTTP gateway will keep the data available for a few hours — if you want to ensure long term availability make sure to pin important data at nodes you control. Try IPFS Cluster: a stand-alone application and a CLI client to allocate, replicate and track pins across a cluster of IPFS daemons.
IPFS 中数据的存续性本质上取决于各节点的参与度。你没有办法移除别的节点中的数据,但若是没有人再保留着它的话,它将被集体所“遗忘”。
公共的 HTTP 网关会将这份数据保留几个小时——若是你但愿它可以长时间保留,你须要在你所控制的节点上将其持续保留。或者你也能够采用 IPFS 集群:一种用于在 IPFS 集群中各节点中进行分配、克隆和监测的独立应用和命令行客户端。
You can experiment with js-ipfs to make simple browser apps. If you want to run an IPFS server you can install go-ipfs, or run a cluster, as we mentioned above.
There is a growing list of examples, and make sure to see the bi-directional file exchange demo built with js-ipfs.
You can add IPFS to the browser by installing the IPFS Companion extension for Firefox.
你可使用 js-ipfs 来尝试作一些简单的浏览器应用。若是你想跑一台 IPFS 服务器的话,能够安装 go-ipfs;或者能够像上面咱们提到的——跑一个集群。
这有一份示例列表,这个列表还在不断增长,里面有一个双向交换文件的例子,必定要看一下。
你能够经过为 Firefox 安装 IPFS Companion,将 IPFS 添加到浏览器中。
Learn about IPFS concepts by visiting our documentation website at docs.ipfs.io.
Readers can participate by improving documentation, visiting ipfs.io, developing distributed web apps and sites with IPFS, and exploring and contributing to our git repos and various things built by the community.
A great place to ask questions is our friendly community forum: discuss.ipfs.io. We also have an IRC channel, #ipfs on Freenode (or #freenode_#ipfs:matrix.org on Matrix). Join us!
访问咱们的文档网站 docs.ipfs.io 了解更多关于 IPFS 的概念。
读者能够参与文档的完善。访问 ipfs.io,学习如何开发分布式 Web 应用和网站,参与或查看咱们的 git 仓库和其余由社区共同完成的东西。
咱们的社区论坛很是友好,是一个提问的好地方:discuss.ipfs.io。另外咱们还有一个 IRC 频道,频道名称为 #ipfs, 在 Freenode 网站上 (or #freenode_#ipfs:matrix.org on Matrix)。欢迎你们加入!
Kyle Drake 是 Protocol Labs (协议实验室) 的一名开发人员,当前正负责开发 IPFS。
Marcin Rataj 是 Protocol Labs 的一名开发人员,当前正负责开发针对浏览器的 IPFS,另外他仍是一位崇尚天然生活的人 (a carbon based lifeform) 。