[译] Dweb: 基于 IPFS 的去中心化 Web 文件系统 (中英)

原文Dweb: Building Cooperation and Trust into the Web with IPFS
作者Kyle Drake, Marcin Rataj 发表时间:August 29, 2018
译者:西楼听雨 发表时间: 2018/09/02
原文是 Mozilla 开发者网站发布的关于 Dweb 的概念、应用及使用案例介绍的系列文章中的第五篇。(转载请注明出处)

本系列各篇章的翻译链接如下:

  1. [译] Dweb: 什么是 Dweb?(中英)
  2. [译] Dweb: 基于 Secure Scuttlebutt 的社交消息流 (中英)
  3. [译] Dweb: 用 WebTorrent 搭建一个可复原的 Web (中英)
  4. [译] Dweb: Beaker——去中心化浏览器 (中英)
  5. [译] Dweb: 基于 IPFS 的去中心化 Web 文件系统 (中英)
  6. 待发布…...

译注:下面是斜体文本为原文的编者按。

展开原文

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.

这个系列中,我们会讲到一些正在尝试探索在 Web 变为去中心化或分布式的时候存在哪些可能性的项目,这些项目不附属于 Mozilla,其中一些项目还重新定义了我们对 web 浏览器的认识。他们都有共同点:这些项目都是开源的,开放参与的,并且和 Mozilla ”keep the web open and accessible for all (让 Web 对所有人保持开放和可访问)“ 的宗旨一致。

展开原文

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 Ayala

一些项目成立时较小,采取逐步地提升;另外一些项目成立时目标远大,通过设计一套美好世界架构来颠覆式地解决当今存在的问题。 行星网文件系统 (IPFS: The InterPlanetary File System) 绝对是后者 —— 通过一个具备可伸缩、可信任、防 DDOS 攻击的网络协议层尝试对 HTTP 做整体替换。我们非常荣幸请到 Neocities 的创始人 Kyle DrakeIPFS Companion 的创建者 Maricin Rataj 对 IPFS 做一个介绍,他们两位都是 Protocol Labs (协议实验室) 的 IPFS 团队成员。——Dietrich Ayala

IPFS —— The InterPlanetary File System (行星网文件系统)

展开原文

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 栈是建立在 IPLDlibp2p 之上的一种抽象:

The IPFS Stack: High Level Overview

Hello World

展开原文

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…

  • Starts an IPFS node
  • Adds some data to IPFS
  • Obtains the Content IDentifier (CID) for it
  • Reads that data back from IPFS using the CID

IPFS 规范现在已经有了 GO 语言和 JavaScript 的实现了,他们分别是 go-ipfsjs-ipfs (正在不断完善中)。除此之外,也还有许多其他语言的 API 客户端实现。

得益于这款 JS 实现,在 web 开发中使用 IPFS 变得极其容易。下面这段代码演示了

  • 启动一个 IPFS 节点
  • 往 IPFS 中添加一份数据
  • 获取这份数据的内容 ID(CID,Content IDentifier)
  • 使用获取到的这个内容 ID 回读数据
<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 https://docs.ipfs.io.

Readers can participate by improving documentation, visiting https://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: https://discuss.ipfs.io. We also have an IRC channel, #ipfs on Freenode (or #freenode_#ipfs:matrix.org on Matrix). Join us!

访问我们的文档网站 https://docs.ipfs.io 了解更多关于 IPFS 的概念。

读者可以参与文档的完善。访问 https://ipfs.io,学习如何开发分布式 Web 应用和网站,参与或查看我们的 git 仓库和其他由社区共同完成的东西

我们的社区论坛非常友好,是一个提问的好地方:https://discuss.ipfs.io。另外我们还有一个 IRC 频道,频道名称为 #ipfs, 在 Freenode 网站上 (or #freenode_#ipfs:matrix.org on Matrix)。欢迎大家加入!

关于 Kyle Drake

Kyle Drake 是 Protocol Labs (协议实验室) 的一名开发人员,当前正负责开发 IPFS。

更多 Kyle Drake 写的文章…

关于 Marcin Rataj

Marcin Rataj 是 Protocol Labs 的一名开发人员,当前正负责开发针对浏览器的 IPFS,另外他还是一位崇尚自然生活的人 (a carbon based lifeform) 。

更多 Marcin Rataj 写的文章…

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值