本系列各篇章的翻译连接以下:javascript
译注:如下斜体文本是原文的编者按html
In the series introduction, we highlighted the importance of putting people in control their social interactions online, instead of allowing for-profit companies be the arbiters of hate speech or harassment. Our first installment in the Dweb series introduces Secure Scuttlebutt, which envisions a world where users are in full control of their communities online.java
Scuttlebutt is a free and open source social network with unique offline-first and peer-to-peer properties. As a JavaScript open source programmer, I discovered Scuttlebutt two years ago as a promising foundation for a new “social web” that provides an alternative to proprietary platforms. The social metaphor of mainstream platforms is now a more popular way of creating and consuming content than the Web is. Instead of attempting to adapt existing Web technologies for the mobile social era, Scuttlebutt allows us to start from scratch the construction of a new ecosystem.node
Scuttlebutt 是一款免费、开源的社交网络。我是一名 JavaScript 开源程序开发者,两年前我发现了 Scuttlebutt,当时我以为它有望成为一种能够对抗私有化平台的“新型社交 web”形态。如今主流的平台对社交的涵义认识广泛是一种比 Web 的形式更流行的方式——内容的建立和消费。在这样一个移动社交时代,相对于尝试在现有的 Web 技术中进行适应,Scuttlebutt 的方式是从新从零开始构建一个新的生态系统。git
The central idea of the Secure Scuttlebutt (SSB) protocol is simple: your social account is just a cryptographic keypair (your identity) plus a log of messages (your feed) stored in a local database. So far, this has no relation to the Internet, it is just a local database where your posts are stored in an append-only sequence, and allows you to write status updates like you would with a personal diary. SSB becomes a social network when those local feeds are shared among computers through the internet or through local networks. The protocol supports peer-to-peer replication of feeds, so that you can have local (and full) copies of your friends’ feeds, and update them whenever you are online. One implementation of SSB, Scuttlebot, uses Node.js and allows UI applications to interact with the local database and the network stack.github
Secure Scuttlebutt(简称 SSB) 的中心思想很是简单:你的社交帐户就是存放于本地数据库中的一个(密码学上的)密钥对(即你的身份标志)及消息记录本(即消息流)。若是只是这样的话,它只是一个本地数据库,和互联网没有任何关系。不过当这些本地数据库经过互联网或本地网络在多台电脑之间相互共享时,SSB 就变成了一个了社交网络。这种(共享)协议支持点对点的消息流复制(交换),所以在你的本地你会拥有你朋友们的消息流的副本——只要你一上线(联网),这些副本就会更新。Scuttlebot 就是 SSB 的其中一个实现 ,它是使用 Node.js 开发的,提供了用户界面来(方便地)与本地数据库及网络栈进行交互。web
While SSB is being implemented in multiple languages (Go, Rust, C), its main implementation at the moment is the npm package scuttlebot
and Electron desktop apps that use Scuttlebot. To build your own UI application from scratch, you can setup Scuttlebot plus a localhost HTTP server to render the UI in your browser.数据库
如今 SSB 正在被多种语言 (Go、Rust、C) 所实现,不过目前它最主要的实现仍是 scuttlebot 这个 npm 包以及基于它的用 Electron 开发的桌面应用。 若是想要从空白开始构建一款你本身的用户界面应用,你能够采用 Scuttlebot 搭配一个 HTTP 服务的方式经过浏览器来展现界面。npm
Run the following npm
command to add Scuttlebot to your Node.js project:json
运行如下 npm
命令,将 Scuttlebot 添加到你的 Node.js 项目中:
npm install --save scuttlebot复制代码
而后,你能够在本地用命令行界面来发布消息、查看消息,和朋友创建链接。首先,启动服务:
$(npm bin)/sbot server复制代码
In another terminal you can use the server to publish a message in your local feed:
而后在另一个终端窗口中你能够经过这个服务在本地消息流中发布一条消息:
$(npm bin)/sbot publish --type post --text "Hello world"复制代码
You can also consume invite codes to connect with friends and replicate their feeds. Invite codes are generated by
你也可使用你得到的邀请码与朋友创建链接,进而得到他们的消息流。邀请码须要你的朋友使用他本身的 pub servers 来生成,邀请码就像是消息流的一个镜像。使用邀请码就意味着你能够连上其服务,同时你的数据也会成为一个镜像。
$(npm bin)/sbot invite.accept $你的邀请码复制代码
To create a simple web app to render your local feed, you can start the scuttlebot server in a Node.js script (with dependencies ssb-config
and pull-stream
), and serve the feed through an HTTP server:
要建立一个简单的 web 应用来展现你的本地消息流,你能够经过 Node.js 脚本(将 ssb-config 和 pull-stream 做为依赖项)启动 Scuttlebot 服务,而后经过 HTTP 服务来提供消息流(的查询)来实现:
// server.js
const fs = require('fs');
const http = require('http');
const pull = require('pull-stream');
const sbot = require('scuttlebot/index').call(null, require('ssb-config'));
http
.createServer((request, response) => {
if (request.url.endsWith('/feed')) {
pull(
sbot.createFeedStream({live: false, limit: 100}),
pull.collect((err, messages) => {
response.end(JSON.stringify(messages));
}),
);
} else {
response.end(fs.readFileSync('./index.html'));
}
})
.listen(9000);复制代码
运行 node server.js
命令启动服务,而后在浏览器访问 localhost:9000
时,返回内容以下的 index.html :
<html>
<body>
<script> fetch('/feed') .then(res => res.json()) .then(messages => { document.body.innerHTML = ` <h1>Feed</h1> <ul>${messages .filter(msg => msg.value.content.type === 'post') .map(msg => `<li>${msg.value.author} said: ${msg.value.content.text}</li>` ) }</ul> `; }); </script>
</body>
</html>复制代码
SSB applications can accomplish more than social messaging. Secure Scuttlebutt is being used for Git collaboration, chess games, and managing online gatherings.
SSB 应用能够实现的不仅是社交消息功能。Secure Scuttlebutt 还被应用在如 Git 协做、象棋游戏 和 管理在线发布聚会 上。
You build your own applications on top of SSB by creating or using plug-ins for specialized APIs or different ways of querying the database. See secret-stack for details on how to build custom plugins. See flumedb for details on how to create custom indexes in the database. Also there are many useful repositories in our GitHub org.
你能够经过建立或者使用(现有的)针对特定 API 或数据库查询方式的插件来构建你本身的基于 SBB 的应用。关于如何构建自定义插件,可查看 secret-stack 来获取详细的说明。关于如何在数据库中建立自定义索引,可查看 flumedb 来获取详细的说明。另外在咱们的 Github 组织上还有许多有用的仓库。
To learn about the protocol that all of the implementations use, see the protocol guide, which explains the cryptographic primitives used, and data formats agreed on.
要了解关于这些实现所共同使用的这种协议,可查看协议教程,它给出了关于其所使用的加密学基本原理及相关的数据格式的说明。
Finally, don’t miss the frontpage Scuttlebutt.nz, which explains the design decisions and principles we value. We highlight the important role that humans have in internet communities, which should not be delegated to computers.
最后,请不要错过 Scuttlebutt.nz,在其网页中详细说明了咱们崇尚的设计决策和原则。咱们认为人们在互联网的通信中的所扮演的角色很是重要,这种角色不该该由电脑来代理。
André Staltz is an open source hacker who maintains open source libraries and teaches JavaScript at conferences and workshops. He is a core contributor to the Scuttlebutt community, focusing on developing the first Android app as well as representing the community externally.
André Staltz 是一名开源软件黑客(译注:这里所谓的黑客并没有贬义,相反是一种高尚的称号),他维护了许多开源软件库,同时在各类会议上和交流会中教授 JavaScript。他仍是 Scuttlebutt 社区的核心成员,主要专一于(社区的)第一款安卓应用的开发,并在社区以外做为表明出现。