缘起
我们在2017年下半年至2018年上半年期间,牺牲了大量的业余时间,一直在做IPFS这门新兴技术的相关解读、线下MeetUp工作。我们在知乎专栏和微信公众号上建立的《IPFS指南》是中国第一个系统、全面地介绍这门技术的中文资料站。机械工业出版社华章公司的杨福川老师在第一时间找到我们,希望我们能够为国内开发人员写一本IPFS技术相关的图书,方便国人更好地理解并应用这门技术。于是,便有了你手中的这本书。
为什么要写这本书
IPFS这门技术诞生于2014年,由协议实验室(Protocol Labs)创建。但是,直到2017年年中才逐渐走入大众视野,因为其能与区块链完美结合,所以使得其成为近几年最火热的技术之一。然而,国内却没有与IPFS技术相关、利于国人阅读、知识体系结构相对系统全面的中文学习资料。因此,我联系了当时在这个领域钻研摸索最多的几位布道者和专家,一起撰写了这本书,希望能帮助国内IPFS技术爱好者更加快速地学习、掌握、应用这门技术。
IPFS这门技术还在不断演化中,它引导的是一场真正的网络协议革命,是一种全球化思维的碰撞,是一种突破传统的海量数据共享的模式。IPFS可能不是这场革命的导火索,但是我认为,它至少能带领大家去学习和认识这种思维,这是一件非常有意义的事情。
读者对象
本书适合有一定区块链常识和基础,有软件开发能力,但是不了解IPFS,想学习IPFS的技术原理,并基于IPFS做相关开发工作的读者。主要包含以下人员:
IPFS技术爱好者;
网络协议技术爱好者;
分布式存储技术爱好者;
区块链技术爱好者;
区块链领域从业者;
开设相关课程的大专院校师生。
本书特色
首先,IPFS是在区块链技术蓬勃发展的情况下得到广泛认可的,本书除了针对IPFS技术本身进行讲解以外,还增加了大量区块链相关知识作为铺垫和补充,包括单独设立第5章来重点介绍IPFS的激励层Filecoin区块链项目。
其次,本书不仅介绍了IPFS技术本身的细节,还加入了大量笔者在开发中总结的经验和技巧,并搭配了相关生态链中较新的软件开发工具和前沿的尖端技术。在技术深度和广度两个方面都兼顾得比较妥当,有明显的层次感。
再次,本书提供了大量的项目实例,这些项目实例能够帮助读者更好地理解IPFS技术和应对一些业务场景。
最后,本书是一本相对全面和系统地解读了IPFS和Filecoin技术的书籍,也是一本国内由相关领域中最早期的布道者、专家合力编写的中文权威书籍。
如何阅读本书
本书分为三大部分:
第1部分为基础篇,包括第1章。简单地介绍了IPFS的概念、优势和应用领域,旨在帮助读者了解一些基础背景知识,并从宏观层面来认识IPFS技术所具有的创新性。
第2部分为原理篇,包括第2~5章。从内部详细剖析IPFS的底层基础、协议栈构成,以及libp2p、Multi-Format、Filecoin等模块。
第3部分为实战篇,包括第6~8章。以工程化的方式,从基础至进阶,讲解了IPFS技术的实际使用,并通过讲解两个不同风格的项目案例,让读者了解不同语言实现的IPFS协议栈。
其中,第3部分以接近实战的实例来讲解工程应用,相比于前两部分更独立。如果你是一名资深用户,已经理解IPFS的相关基础知识和使用技巧,那么你可以跳过前两个部分,直接阅读第3部分。如果你是一名初学者,则务必从第1章的基础理论知识开始学习。
勘误和支持
由于作者的水平有限,加之IPFS等相关技术更新迭代快,书中难免会出现一些错误或者不准确的地方,恳请读者批评指正。为此,我们创建了存放本书相关资料和便于信息反馈的Github仓库https://github.com/daijiale/IPFS-and-Blockchain-Principles-and-Practice。如果大家在阅读本书的过程中遇到任何问题,可以通过上述渠道以Issue的形式反馈给我们,我们将在线上为读者提供解答。期待能够得到你们的真挚反馈。本书的相关源码和资料文件除了可以从华章网站下载外,还可以从上述渠道下载。
致谢
首先要感谢协议实验室开创的这款具有划时代意义的新型网络协议。
其次要感谢机械工业出版社华章公司的杨福川、孙海亮、李良三位老师为本书顺利出版所付出的努力,没有他们的支持,本书无法如期顺利完成。
同时感谢知乎专栏《IPFS指南》及国内因IPFS技术自发组织而成的众多爱好者社区,他们对IPFS技术的执着和探索是我们创作的动力,在和他们的交流中我们发现了本书的价值和创作素材。
感谢我的合作者董天一前辈,他在计算机系统、软件工程、经济学基础、博弈论、区块链存储方面学识渊博,使我在与他合作著书的过程中不断进步。同时,董天一前辈对本书的审稿和校稿工作也做出了重要的贡献。
感谢我的另一位合作者黄禹铭,他在区块链学术领域积累丰厚,对本书的众多技术进行了详细的原理解读和分析,尤其是在第1章、第2章、第4章和第5章。
感谢新加坡国立大学Andrew Lim教授对本书的大力支持以及TangJing助理教授对我们技术上的指导。
谨以此书献给我最亲爱的家人,以及中国众多热爱IPFS和区块链技术的朋友们。
戴嘉乐
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创始人
协议实验室创始人