緣起
我們在2017年下半年至2018年上半年期間,犧牲了大量的業(yè)余時(shí)間,一直在做IPFS這門新興技術(shù)的相關(guān)解讀、線下MeetUp工作。我們在知乎專欄和微信公眾號上建立的《IPFS指南》是中國第一個(gè)系統(tǒng)、全面地介紹這門技術(shù)的中文資料站。機(jī)械工業(yè)出版社華章公司的楊福川老師在第一時(shí)間找到我們,希望我們能夠?yàn)閲鴥?nèi)開發(fā)人員寫一本IPFS技術(shù)相關(guān)的圖書,方便國人更好地理解并應(yīng)用這門技術(shù)。于是,便有了你手中的這本書。
為什么要寫這本書
IPFS這門技術(shù)誕生于2014年,由協(xié)議實(shí)驗(yàn)室(Protocol Labs)創(chuàng)建。但是,直到2017年年中才逐漸走入大眾視野,因?yàn)槠淠芘c區(qū)塊鏈完美結(jié)合,所以使得其成為近幾年最火熱的技術(shù)之一。然而,國內(nèi)卻沒有與IPFS技術(shù)相關(guān)、利于國人閱讀、知識體系結(jié)構(gòu)相對系統(tǒng)全面的中文學(xué)習(xí)資料。因此,我聯(lián)系了當(dāng)時(shí)在這個(gè)領(lǐng)域鉆研摸索最多的幾位布道者和專家,一起撰寫了這本書,希望能幫助國內(nèi)IPFS技術(shù)愛好者更加快速地學(xué)習(xí)、掌握、應(yīng)用這門技術(shù)。
IPFS這門技術(shù)還在不斷演化中,它引導(dǎo)的是一場真正的網(wǎng)絡(luò)協(xié)議革命,是一種全球化思維的碰撞,是一種突破傳統(tǒng)的海量數(shù)據(jù)共享的模式。IPFS可能不是這場革命的導(dǎo)火索,但是我認(rèn)為,它至少能帶領(lǐng)大家去學(xué)習(xí)和認(rèn)識這種思維,這是一件非常有意義的事情。
讀者對象
本書適合有一定區(qū)塊鏈常識和基礎(chǔ),有軟件開發(fā)能力,但是不了解IPFS,想學(xué)習(xí)IPFS的技術(shù)原理,并基于IPFS做相關(guān)開發(fā)工作的讀者。主要包含以下人員:
IPFS技術(shù)愛好者;
網(wǎng)絡(luò)協(xié)議技術(shù)愛好者;
分布式存儲(chǔ)技術(shù)愛好者;
區(qū)塊鏈技術(shù)愛好者;
區(qū)塊鏈領(lǐng)域從業(yè)者;
開設(shè)相關(guān)課程的大專院校師生。
本書特色
首先,IPFS是在區(qū)塊鏈技術(shù)蓬勃發(fā)展的情況下得到廣泛認(rèn)可的,本書除了針對IPFS技術(shù)本身進(jìn)行講解以外,還增加了大量區(qū)塊鏈相關(guān)知識作為鋪墊和補(bǔ)充,包括單獨(dú)設(shè)立第5章來重點(diǎn)介紹IPFS的激勵(lì)層Filecoin區(qū)塊鏈項(xiàng)目。
其次,本書不僅介紹了IPFS技術(shù)本身的細(xì)節(jié),還加入了大量筆者在開發(fā)中總結(jié)的經(jīng)驗(yàn)和技巧,并搭配了相關(guān)生態(tài)鏈中較新的軟件開發(fā)工具和前沿的尖端技術(shù)。在技術(shù)深度和廣度兩個(gè)方面都兼顧得比較妥當(dāng),有明顯的層次感。
再次,本書提供了大量的項(xiàng)目實(shí)例,這些項(xiàng)目實(shí)例能夠幫助讀者更好地理解IPFS技術(shù)和應(yīng)對一些業(yè)務(wù)場景。
最后,本書是一本相對全面和系統(tǒng)地解讀了IPFS和Filecoin技術(shù)的書籍,也是一本國內(nèi)由相關(guān)領(lǐng)域中最早期的布道者、專家合力編寫的中文權(quán)威書籍。
如何閱讀本書
本書分為三大部分:
第1部分為基礎(chǔ)篇,包括第1章。簡單地介紹了IPFS的概念、優(yōu)勢和應(yīng)用領(lǐng)域,旨在幫助讀者了解一些基礎(chǔ)背景知識,并從宏觀層面來認(rèn)識IPFS技術(shù)所具有的創(chuàng)新性。
第2部分為原理篇,包括第2~5章。從內(nèi)部詳細(xì)剖析IPFS的底層基礎(chǔ)、協(xié)議棧構(gòu)成,以及l(fā)ibp2p、Multi-Format、Filecoin等模塊。
第3部分為實(shí)戰(zhàn)篇,包括第6~8章。以工程化的方式,從基礎(chǔ)至進(jìn)階,講解了IPFS技術(shù)的實(shí)際使用,并通過講解兩個(gè)不同風(fēng)格的項(xiàng)目案例,讓讀者了解不同語言實(shí)現(xiàn)的IPFS協(xié)議棧。
其中,第3部分以接近實(shí)戰(zhàn)的實(shí)例來講解工程應(yīng)用,相比于前兩部分更獨(dú)立。如果你是一名資深用戶,已經(jīng)理解IPFS的相關(guān)基礎(chǔ)知識和使用技巧,那么你可以跳過前兩個(gè)部分,直接閱讀第3部分。如果你是一名初學(xué)者,則務(wù)必從第1章的基礎(chǔ)理論知識開始學(xué)習(xí)。
勘誤和支持
由于作者的水平有限,加之IPFS等相關(guān)技術(shù)更新迭代快,書中難免會(huì)出現(xiàn)一些錯(cuò)誤或者不準(zhǔn)確的地方,懇請讀者批評指正。為此,我們創(chuàng)建了存放本書相關(guān)資料和便于信息反饋的Github倉庫https://github.com/daijiale/IPFS-and-Blockchain-Principles-and-Practice。如果大家在閱讀本書的過程中遇到任何問題,可以通過上述渠道以Issue的形式反饋給我們,我們將在線上為讀者提供解答。期待能夠得到你們的真摯反饋。本書的相關(guān)源碼和資料文件除了可以從華章網(wǎng)站下載外,還可以從上述渠道下載。
致謝
首先要感謝協(xié)議實(shí)驗(yàn)室開創(chuàng)的這款具有劃時(shí)代意義的新型網(wǎng)絡(luò)協(xié)議。
其次要感謝機(jī)械工業(yè)出版社華章公司的楊福川、孫海亮、李良三位老師為本書順利出版所付出的努力,沒有他們的支持,本書無法如期順利完成。
同時(shí)感謝知乎專欄《IPFS指南》及國內(nèi)因IPFS技術(shù)自發(fā)組織而成的眾多愛好者社區(qū),他們對IPFS技術(shù)的執(zhí)著和探索是我們創(chuàng)作的動(dòng)力,在和他們的交流中我們發(fā)現(xiàn)了本書的價(jià)值和創(chuàng)作素材。
感謝我的合作者董天一前輩,他在計(jì)算機(jī)系統(tǒng)、軟件工程、經(jīng)濟(jì)學(xué)基礎(chǔ)、博弈論、區(qū)塊鏈存儲(chǔ)方面學(xué)識淵博,使我在與他合作著書的過程中不斷進(jìn)步。同時(shí),董天一前輩對本書的審稿和校稿工作也做出了重要的貢獻(xiàn)。
感謝我的另一位合作者黃禹銘,他在區(qū)塊鏈學(xué)術(shù)領(lǐng)域積累豐厚,對本書的眾多技術(shù)進(jìn)行了詳細(xì)的原理解讀和分析,尤其是在第1章、第2章、第4章和第5章。
感謝新加坡國立大學(xué)Andrew Lim教授對本書的大力支持以及TangJing助理教授對我們技術(shù)上的指導(dǎo)。
謹(jǐn)以此書獻(xiàn)給我最親愛的家人,以及中國眾多熱愛IPFS和區(qū)塊鏈技術(shù)的朋友們。
戴嘉樂
Foreword 推 薦 序
Computing and the internet have transformed humanity. We live in an extraordinary time -- computers have amplified our capabilities and the internet has connected our species together. Software applications grant us all superpowers that our ancestors would have considered magical: we can access and search all information in seconds; we can talk face-to-face with anybody around the planet; we can broadcast our messages and speeches to everyone world-wide; and we have enhanced our minds with external computing and information storage. We have tremendous, awe-inspiring capabilities.
The properties of the internet determine our capabilities. All of these powers hinge on the properties of the internet -- if the internet breaks down, or is insecure, then so are our applications and our capabilities. We must ensure that the super-powers we have acquired continue to work, as our lives now depend on them. Most human coordination and collaboration happens over the internet-from our personal chats, to work emails, to industrial and cross-organization communication. Even hospitals, emergency services, and other systems rely on the internet. Our lives depend on how well the internet works! We must endeavor to make the internet more secure, efficient, resilient, and robust.
IPFS is upgrading the internet. We built IPFS, the InterPlanetary File System, to achieve this. IPFS is a hypermedia protocol that upgrades how we address and distribute content -- its key component is to replace Location Addressing (URLs) with Content Addressing (CID URIs). In the last few years, IPFS has created a powerful and robust application distribution platform, that millions of people benefit from world-wide. There are hundreds of thousands of computers running IPFS nodes today, distributing information and applications, and this number is growing quickly! There are encyclopedias, chat systems, marketplaces, video distribution platforms, knowledge management systems, package managers, developer tools, games, VR environments, and more. As more developers choose to develop applications or content with IPFS, more millions of people benefit world-wide. Are you going to help us upgrade the internet?
Filecoin will upgrade data storage and distribution. The next stage is to make a decentralized storage network, a public, internet-wide utility that helps us store and distribute our data efficiently, robustly, and cheaply. The goal of Filecoin is to build such a storage market, where storage providers (miners) can sell storage space over time, and clients can buy storage that is more efficient, more robust, and lower cost. This is achieved with the use of a blockchain, a token to mediate the value exchange and incent participation, smart contracts to mediate transactions, and more. Using the power of verifiable markets and game theory, we aim to make the world抯 largest, most resilient, and lowest cost storage network. At the time of this writing, Filecoin is under fast-paced development and headed towards its testnet and mainnet launches. This and the next few years are a great time to get involved! We are shaping the future of data storage and distribution, and you can help us make it even better.
I invite you to join this computing revolution! You can get involved by using applications powered with IPFS, or by building them yourself today. You can learn about Filecoin and join the community developing Filecoin and applications on top of it, or you can become a miner and sell storage to the network. You can build lower level applications on top of libp2p, and you can model content and its distribution with IPLD. You can use these technologies, and you can help build them.
This book is a great guide for you. Learning about all these technologies at once can be very confusing. I am thrilled that the authors have written this book, so it can guide you step by step. Though I have only been able to review a machine-translated version -- I found this to be an excellent and thorough guide for both new people just getting started, and experienced IPFS developers who want to understand the internals. It is a solid introduction and guide to IPFS, Filecoin, and all the related protocols. It contains a good overview of the systems and how they work. You will learn how our protocols use multihash, multiaddr, and other multiformats to be self-describing and future-proof. You will learn how libp2p connects computers together across a variety of transports, and makes it easy to build p2p protocols. You will learn how to model data with IPLD and content-address it with CIDs. You will learn how IPFS plugs all these protocols together into a decentralized web protocol, and how to use it to build applications. You will learn about the Filecoin protocol and how it will work. You will learn how all of these protocols work together to store, address, and move information. This book is a comprehensive and thorough guide -- I hope it serves you well! Though note an important warning: like all technology books, this is likely to become outdated as the systems continue to develop. Be sure to check online versions of the book, and the projects抎ocumentation websites. The concepts will remain the same -- and for that, this book will hopefully serve you well for a long time -- but the technical details will surely evolve, and you will want to check up-to-date documentation.
I hope you enjoy this book. I am very grateful to the authors for writing this book: your work will help so many others!
Juan Benet
IPFS和Filecoin創(chuàng)始人
協(xié)議實(shí)驗(yàn)室創(chuàng)始人
董天一(飛向未來)
畢業(yè)于北京大學(xué)軟件工程專業(yè),資深I(lǐng)PFS技術(shù)專家、架構(gòu)師,國內(nèi)IPFS、Filecoin技術(shù)領(lǐng)域的先驅(qū)者和布道者,過去兩年在國內(nèi)舉辦相關(guān)線下活動(dòng)30余場,對 IPFS 技術(shù)在中國的推動(dòng)和普及起到了關(guān)鍵作用,在 IPFS 社區(qū)享有很高的聲譽(yù)。
現(xiàn)就職于電商行業(yè),在中型電商系統(tǒng)的架構(gòu)、設(shè)計(jì)與實(shí)現(xiàn)方面有豐富的經(jīng)驗(yàn),擅長高并發(fā)、微服務(wù)、ServiceMesh等技術(shù)。曾就職于Oracle亞洲研發(fā)中心,專注于數(shù)據(jù)庫相關(guān)的設(shè)計(jì)與開發(fā)工作。
資深區(qū)塊鏈技術(shù)專家,早期的參與者,對區(qū)塊鏈和分布式存儲(chǔ)技術(shù)有著深刻的認(rèn)識和見解,為多家大型上市公司提供過區(qū)塊鏈技術(shù)的咨詢和培訓(xùn)服務(wù)。
戴嘉樂
資深I(lǐng)PFS技術(shù)專家,國內(nèi)首批IPFS技術(shù)布道師,中國IPFS開發(fā)者沙龍系列活動(dòng)創(chuàng)辦人。
畢業(yè)于電子科技大學(xué)軟件工程專業(yè),曾擔(dān)任百度地圖高級后端研發(fā)工程師,參與構(gòu)建過高并發(fā)下的高可用分布式后端系統(tǒng)和基于地理圍欄和實(shí)時(shí)通勤路線的位置推薦系統(tǒng)。
黃禹銘
國內(nèi)IPFS和Filecoin領(lǐng)域早期的研究者、布道者和投資人。新加坡國立大學(xué)博士生,主要研究方向?yàn)榉植际接?jì)算和區(qū)塊鏈。目前的研究興趣包括區(qū)塊鏈的共識機(jī)制、證明機(jī)制和激勵(lì)模型。