[译] Dweb: Beaker--去中心化的浏览器 (中英)

3,763 阅读7分钟

原文Dweb: Serving the Web from the Browser with Beaker
作者Tara Vancil 发表时间:August 22, 2018
译者:西楼听雨 发表时间: 2018/8/25
原文是 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 对所有人保持开放和可访问)“ 的宗旨一致。

展开原文 So far we’ve covered distributed social feeds and sharing files in a decentralized way. with some new tools for developers. Today we’d like to introduce something a bit different: Imagine what an *entire browser experience* would be like if the web was distributed… Beaker browser does exactly this! Beaker is a big vision from a team who are proving out the distributed web from top to bottom. Please enjoy this post from Beaker co-creator Tara Vancil. – Dietrich Ayala

到这篇文章为止,我们已经讲到过分布式的社交消息流去中心化的文件共享两个主题。今天我们想要介绍一些不一样的东西:想象一下,如果整个 web 都是分布式的······浏览器将会变成怎样一种体验。 Beaker 浏览器就是这样一款浏览器!它代表了其背后开发团队的一个宏图愿景,这个团队旨在提供从顶层设计到基础设施各层面的去中心化 Web。这是一篇出自 Beaker 的联合制作人 Tara Vancil 的贴文,请尽情享阅。——Dietrich Ayala

蓝链实验室及 Beaker 浏览器

展开原文We’re Blue Link Labs, a team of three working to improve the Web with the Dat protocol and an experimental peer-to-peer browser called Beaker.

我们是蓝链实验室团队,我们是一个3人团队,我们的任务是用Dat 协议及一个叫做Beaker的点对点浏览器来让 Web 变得更好。

Blue Link Labs team

展开原文We work on Beaker because publishing and sharing is core to the Web’s ethos, yet to publish your own website or even just share a document, you need to know how to run a server, or be able to pay someone to do it for you.

Web 的基础就是发布和分享,现在如果你想发布属于自己的网站或者分享一些文档,你仍然需要懂得如何运营一台服务器,或者具备因雇人帮你做这些而支付报酬的能力。

So we asked ourselves, “What if you could share a website directly from your browser?”

所以我们开始思考“是否我们可以仅在浏览器里就能搭建一个网站?”

展开原文 Peer-to-peer protocols like `dat://` make it possible for regular user devices to host content, so we use `dat://` in Beaker to enable publishing from the browser, where instead of using a server, a website’s author and its visitors help host its files. It’s kind of like BitTorrent, but for websites!

dat:// 这类点对点 (P2P) 协议使得实现这种想法变为可能,普通的用户设备也可以用来提供内容服务,所以我们没有使用服务器——那种需要网站作者和他的访客来支持其文件供应服务的形式 ,而是采用了 data:// 及 Beaker 来支持在浏览器中发布内容。这有点像 BitTorrent,不过是针对浏览器的!

架构

Beaker uses a distributed peer-to-peer network to publish websites and datasets (sometimes we call them “dats”).

Beaker 采用的是一种点对点(P2P)式的网络来发布网站及数据的(有时候我们也称之为 “dats”)。

展开原文 `dat://` websites are addressed with a public key as the URL, and each piece of data added to a `dat://` website is appended to a signed log. Visitors to a `dat://` website find each other with a tracker or [DHT](https://en.wikipedia.org/wiki/Distributed_hash_table), then sync the data between each other, acting both as downloaders and uploaders, and checking that the data hasn’t been tampered with in transit.

dat:// 网站的地址是以公钥作为 URL 来标识的。每份添加到 dat:// 网站的数据都会被追加到一个签名的日志本上。访客们通过 tracker 协议或 DHT 网络来相互找寻各方,然后相互进行数据同步,同时充当下载者(流量下行)和上传者(流行上行),在此过程中还会对数据是否被篡改做检查。

a basic illustration of the dat:// network

展开原文 At its core, a `dat://` website isn’t much different than an https:// website — it’s a collection of files and folders that a browser interprets according to Web standards. But `dat://` websites are special in Beaker because we’ve added [peer-to-peer Web APIs](https://beakerbrowser.com/docs/apis) so developers can do things like read, write, and watch `dat://` files and build peer-to-peer Web apps.

从本质上讲,一个dat://网站和一个 https:// 网站没有什么不同——都是浏览器按照 Web 的系列标准来解释一系列文件及目录的形式。但是 dat:// 网站特殊的地方就在于 Beaker,因为我们为其附加了“点对对 Web 接口”, 以便开发者可以进行读取、写入及监测 dat:// 文件从而构建出点对点 Web 应用。

创建一个 P2P 网站

展开原文Beaker makes it easy for anyone to create a new `dat://` website with one click (see our [tour](https://beakerbrowser.com/docs/tour)). If you’re familiar with HTML, CSS, or JavaScript (even just a little bit!) then you’re ready to publish your first `dat://` website.

Beaker 使得任何人创建一个 dat:// 网站都变得容易——只需一次点击即可完成(查看我们的教程)。如果你对 HTML、CSS 及 JavaScript 熟悉的话(哪怕只一丁点熟悉),你就可以开始发布你的第一个 dat:// 网站了。

Developers can get started by checking out our API documentation or reading through our guides.

开发人员可以通过查看我们的 API 文档或者查阅我们的指导教程来入门。

展开原文This example shows a website editing *itself* to create and save a new JSON file. While this example is contrived, it demonstrates a common pattern for storing data, user profiles, etc. in a `dat://` website—instead of application data being sent away to a server, it can be stored in the website itself!

下面这个例子展示了一个可以自我编辑以此创建和保存文件的网站。虽然这个例子不贴实际,但它完整地展示了一个 dat:// 网站在数据排序,用户信息等数据处理方面所共有的操作模式,和那些把应用数据传输至一台服务器去处理的形式不一样,这种形式可以把数据存储在这个网站本身。

// index.html 文件

发送消息

<script src="index.js"></script>

// index.js 文件

// first get an instance of the website's files
// 首先实例化该网站的文件集合对象
var files = new DatArchive(window.location)

document.getElementById('create-json-button').addEventListener('click', saveMessage)

async function saveMessage () {
    var timestamp = Date.now()
    var filename = timestamp + '.json'
    var content = {
    timestamp,
    message: document.getElementById('message').value
}

// write the message to a JSON file
// this file can be read later using the DatArchive.readFile API
// 将消息写入一个 JSON 文件
// 这个文件在之后还可以通过 DataArchive.readFile 接口进行读取
await files.writeFile(filename, JSON.stringify(content))
}

更多信息

展开原文 We’re always excited to see what people build with `dat://` and Beaker. We especially love seeing when someone builds a personal site or blog, or when they experiment with Beaker’s APIs to build an app.

每次看到大家用 dat:// 及 Beaker 创造出一些东西来的时候,我们都很激动,特别是当有人用其制作出网站或博客的时候,或者当他们尝试用 Beaker 提供的 API 来制作 App 的时候。

展开原文 There’s lots to explore on the peer-to-peer Web!

关于点对点 Web 的信息还有很多!

关于 Tara Vancil

展开原文 Tara is the co-creator of the [Beaker browser](https://beakerbrowser.com/). Previously she worked at Cloudflare and participated in [the Recurse Center](https://recurse.com/).

Tara 是 Beaker 浏览器的联合制作人。她之前在 Cloudflare 工作过,另外她还参加了 the Recurse Center