[譯] 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 的概念、應用及使用案例介紹的系列文章中的第五篇。(轉載請註明出處)javascript

本系列各篇章的翻譯連接以下:html

  1. [譯] Dweb: 什麼是 Dweb?(中英)
  2. [譯] Dweb: 基於 Secure Scuttlebutt 的社交消息流 (中英)
  3. [譯] Dweb: 用 WebTorrent 搭建一個可復原的 Web (中英)
  4. [譯] Dweb: Beaker——去中心化瀏覽器 (中英)
  5. [譯] Dweb: 基於 IPFS 的去中心化 Web 文件系統 (中英)
  6. 待發布…...

譯註:下面是斜體文本爲原文的編者按。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 DrakeIPFS Companion 的建立者 Maricin Rataj 對 IPFS 作一個介紹,他們兩位都是 Protocol Labs (協議實驗室) 的 IPFS 團隊成員。——Dietrich Ayalaweb

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 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

Kyle Drake 是 Protocol Labs (協議實驗室) 的一名開發人員,當前正負責開發 IPFS。

更多 Kyle Drake 寫的文章…

關於 Marcin Rataj

Marcin Rataj 是 Protocol Labs 的一名開發人員,當前正負責開發針對瀏覽器的 IPFS,另外他仍是一位崇尚天然生活的人 (a carbon based lifeform) 。

更多 Marcin Rataj 寫的文章…

相關文章
相關標籤/搜索