本系列各篇章的翻譯連接以下: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 社區的核心成員,主要專一於(社區的)第一款安卓應用的開發,並在社區以外做爲表明出現。