ipfs-cap2pfs.tex 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143
  1. \documentclass{sig-alternate}
  2. \usepackage{tikz}
  3. \usetikzlibrary{arrows}
  4. \usetikzlibrary{trees}
  5. \usetikzlibrary{positioning}
  6. \usepackage{array}
  7. \usepackage{amstext}
  8. \usepackage{mathtools}
  9. \DeclarePairedDelimiter{\ceil}{\lceil}{\rceil}
  10. \begin{document}
  11. \title{IPFS - Content Addressed, Versioned, P2P File System (DRAFT 3)}
  12. \subtitle{}
  13. \numberofauthors{1}
  14. \author{
  15. \alignauthor
  16. Juan Benet\\
  17. \email{juan@benet.ai}
  18. }
  19. \maketitle
  20. \begin{abstract}
  21. The InterPlanetary File System (IPFS) is a peer-to-peer distributed file system that seeks to connect all computing devices with the same system of files. In some ways, IPFS is similar to the Web, but IPFS could be seen as a single BitTorrent swarm, exchanging objects within one Git repository. In other words, IPFS provides a high throughput content-addressed block storage model, with content-addressed hyper links. This forms a generalized Merkle DAG, a data structure upon which one can build versioned file systems, blockchains, and even a Permanent Web. IPFS combines a distributed hashtable, an incentivized block exchange, and a self-certifying namespace. IPFS has no single point of failure, and nodes do not need to trust each other.
  22. \end{abstract}
  23. \section{Introduction}
  24. There have been many attempts at constructing a global distributed file system. Some systems have seen significant success, and others failed completely. Among the academic attempts, \cite{AFS} has succeeded widely and is still in use today. \cite{Oceanstore}, \cite{CFS}, and others have not attained the same success. Outside of academia, the most successful systems have been peer-to-peer file-sharing applications primarily geared toward large media (audio and video). Most notably, Napster, KaZaA, and BitTorrent \cite{BitTorrent} deployed large file distribution systems supporting millions of simultaneous users. Even today, BitTorrent maintains a massive deployment where tens of millions of nodes churning daily. These applications saw greater numbers of users and files distributed than their academic file system counterparts. However, the applications were not designed as infrastructure to be built upon. While there have been successful repurposing and forks (e.g. Blizzard Updates using BitTorrent \cite{Blizzard}), no general file-system has emerged that offers global, low-latency, and decentralized distribution.
  25. Perhaps this is because a ``good enough'' system for most use cases already exists: HTTP. By far, HTTP is the most successful ``distributed system of files'' ever deployed. Coupled with the browser, HTTP has had enormous technical and social impact. It has become the de facto way to transmit files across the internet. Yet, it fails to take advantage of dozens of brilliant file distribution techniques invented in the last fifteen years. From one prespective, evolving Web infrastructure is near-impossible, given the number of backwards compatibility constraints and the number of strong parties invested in the current model. But from another perspective, new protocols have emerged and gained wide use since the emergence of HTTP. What is lacking is upgrading design: enhancing the current HTTP web, and introducing new functionality without degrading user experience.
  26. Industry has gotten away with using HTTP this long because moving small files around is relatively cheap, even for small organizations with lots of traffic. But we are entering a new era of data distribution with new challenges: (a) hosting and distributing petabyte datasets, (b) computing on large data across organizations, (c) high-volume high-definition on-demand or real-time media streams, (d) versioning and linking of massive datasets, (e) preventing accidental disappearance of important files, and more. Many of these can be boiled down to ``lots of data, accessible everywhere.'' Pressed by critical features and bandwidth concerns, we have already given up HTTP for different data distribution protocols. The next step is making them part of the Web itself.
  27. Orthogonal to efficient data distribution, version control systems have managed to develop important data collaboration workflows. Git, the distributed source code version control system, developed many useful ways to model and implement distributed data operations. The Git toolchain offers versatile versioning functionality that large file distribution systems severely lack. New solutions inspired by Git are emerging, such as Camlistore \cite{Camlistore}, a personal file storage system, and Dat \cite{Dat} a data collaboration toolchain and dataset package manager. Git has already influenced distributed filesystem design \cite{Ori}, as its content addressed Merkle DAG data model enables powerful file distribution strategies. What remains to be explored is how this data structure can influence the design of high-throughput oriented file systems, and how it might upgrade the Web itself.
  28. This paper introduces IPFS, a novel peer-to-peer version-controlled filesystem seeking to reconcile these issues. IPFS synthesizes learnings from many past successful systems. Careful interface-focused integration yields a system greater than the sum of its parts. The central IPFS principle is modeling \textit{all data} as part of the same Merkle DAG.
  29. \section{Background}
  30. This section reviews important properties of successful peer-to-peer systems, which IPFS combines.
  31. \subsection{Distributed Hash Tables}
  32. Distributed Hash Tables (DHTs) are widely used to coordinate and maintain metadata about peer-to-peer systems. For example, the BitTorrent MainlineDHT tracks sets of peers part of a torrent swarm.
  33. \subsubsection{Kademlia DHT}
  34. Kademlia \cite{Kademlia} is a popular DHT that provides:
  35. \begin{enumerate}
  36. \item Efficient lookup through massive networks:
  37. queries on average contact $ \ceil{log_2 (n)} $ nodes.
  38. (e.g. $20$ hops for a network of $10,000,000$ nodes).
  39. \item Low coordination overhead: it optimizes the number of
  40. control messages it sends to other nodes.
  41. \item Resistance to various attacks by preferring long-lived nodes.
  42. \item Wide usage in peer-to-peer applications, including \\
  43. Gnutella and BitTorrent, forming networks of over 20 million nodes \cite{MLDHTmeasurement}.
  44. \end{enumerate}
  45. \subsubsection{Coral DSHT}
  46. While some peer-to-peer filesystems store data blocks directly in DHTs,
  47. this ``wastes storage and bandwidth, as data must be stored at nodes where it
  48. is not needed'' \cite{Coral}. The Coral DSHT extends Kademlia in three
  49. particularly important ways:
  50. \begin{enumerate}
  51. \item Kademlia stores values in nodes whose ids are ``nearest'' (using
  52. XOR-distance) to the key. This does not take into account application
  53. data locality, ignores ``far'' nodes that may already have the data,
  54. and forces ``nearest'' nodes to store it, whether they need it or not.
  55. This wastes significant storage and bandwith. Instead, Coral stores
  56. addresses to peers who can provide the data blocks.
  57. \item Coral relaxes the DHT API from \texttt{get\_value(key)} to
  58. \texttt{get\_any\_values(key)} (the ``sloppy'' in DSHT).
  59. This still works since Coral users only need a single (working) peer,
  60. not the complete list. In return, Coral can distribute only subsets of
  61. the values to the ``nearest'' nodes, avoiding hot-spots (overloading
  62. \textit{all the nearest nodes} when a key becomes popular).
  63. \item Additionally, Coral organizes a hierarchy of separate DSHTs called
  64. \textit{clusters} depending on region and size. This enables nodes to
  65. query peers in their region first, ``finding nearby data without
  66. querying distant nodes'' \cite{Coral} and greatly reducing the latency
  67. of lookups.
  68. \end{enumerate}
  69. \subsubsection{S/Kademlia DHT}
  70. S/Kademlia \cite{skademlia} extends Kademlia to protect against malicious attacks in two particularly important ways:
  71. \begin{enumerate}
  72. \item S/Kademlia provides schemes to secure \texttt{NodeId} generation,
  73. and prevent Sybill attacks. It requires nodes to create a PKI key pair, derive their identity from it, and sign their messages to each other. One scheme includes a proof-of-work crypto puzzle to make generating Sybills expensive.
  74. \item S/Kademlia nodes lookup values over disjoint paths, in order to
  75. ensure honest nodes can connect to each other in the presence of a large fraction of adversaries in the network. S/Kademlia achieves a success rate of 0.85 even with an adversarial fraction as large as half of the nodes.
  76. \end{enumerate}
  77. \subsection{Block Exchanges - BitTorrent}
  78. BitTorrent \cite{BitTorrent} is a widely successful peer-to-peer filesharing system, which succeeds in coordinating networks of untrusting peers (swarms) to cooperate in distributing pieces of files to each other. Key features from BitTorrent and its ecosystem that inform IPFS design include:
  79. \begin{enumerate}
  80. \item BitTorrent's data exchange protocol uses a quasi tit-for-tat strategy
  81. that rewards nodes who contribute to each other, and punishes nodes who only leech others' resources.
  82. \item BitTorrent peers track the availability of file pieces, prioritizing
  83. sending rarest pieces first. This takes load off seeds, making non-seed peers capable of trading with each other.
  84. \item BitTorrent's standard tit-for-tat is vulnerable to some exploitative
  85. bandwidth sharing strategies. PropShare \cite{propshare} is a different peer bandwidth allocation strategy that better resists exploitative strategies, and improves the performance of swarms.
  86. \end{enumerate}
  87. \subsection{Version Control Systems - Git}
  88. Version Control Systems provide facilities to model files changing over time and distribute different versions efficiently. The popular version control system Git provides a powerful Merkle DAG \footnote{Merkle Directed Acyclic Graph -- similar but more general construction than a Merkle Tree. Deduplicated, does not need to be balanced, and non-leaf nodes contain data.} object model that captures changes to a filesystem tree in a distributed-friendly way.
  89. \begin{enumerate}
  90. \item Immutable objects represent Files (\texttt{blob}), Directories (\texttt{tree}), and Changes (\texttt{commit}).
  91. \item Objects are content-addressed, by the cryptographic hash of their contents.
  92. \item Links to other objects are embedded, forming a Merkle DAG. This
  93. provides many useful integrity and workflow properties.
  94. \item Most versioning metadata (branches, tags, etc.) are simply pointer references, and thus inexpensive to create and update.
  95. \item Version changes only update references or add objects.
  96. \item Distributing version changes to other users is simply transferring objects and updating remote references.
  97. \end{enumerate}
  98. \subsection{Self-Certified Filesystems - SFS}
  99. SFS \cite{SFS} proposed compelling implementations of both (a) distributed trust chains, and (b) egalitarian shared global namespaces. SFS introduced a technique for building \textit{Self-Certified Filesystems}: addressing remote filesystems using the following scheme
  100. \begin{verbatim}
  101. /sfs/<Location>:<HostID>
  102. \end{verbatim}
  103. \noindent where \texttt{Location} is the server network address, and:
  104. \begin{verbatim}
  105. HostID = hash(public_key || Location)
  106. \end{verbatim}
  107. Thus the \textit{name} of an SFS file system certifies its server. The user can verify the public key offered by the server, negotiate a shared secret, and secure all traffic. All SFS instances share a global namespace where name allocation is cryptographic, not gated by any centralized body.
  108. \section{IPFS Design}
  109. IPFS is a distributed file system which synthesizes successful ideas from previous peer-to-peer sytems, including DHTs, BitTorrent, Git, and SFS. The contribution of IPFS is simplifying, evolving, and connecting proven techniques into a single cohesive system, greater than the sum of its parts. IPFS presents a new platform for writing and deploying applications, and a new system for distributing and versioning large data. IPFS could even evolve the web itself.
  110. IPFS is peer-to-peer; no nodes are privileged. IPFS nodes store IPFS objects in local storage. Nodes connect to each other and transfer objects. These objects represent files and other data structures. The IPFS Protocol is divided into a stack of sub-protocols responsible for different functionality:
  111. \begin{enumerate}
  112. \item \textbf{Identities} - manage node identity generation and verification. Described in Section 3.1.
  113. \item \textbf{Network} - manages connections to other peers, uses various underlying network protocols. Configurable. Described in Section 3.2.
  114. \item \textbf{Routing} - maintains information to locate specific peers and objects. Responds to both local and remote queries. Defaults to a DHT, but is swappable. Described in Section 3.3.
  115. \item \textbf{Exchange} - a novel block exchange protocol (BitSwap) that governs efficient block distribution. Modelled as a market, weakly incentivizes data replication. Trade Strategies swappable. Described in Section 3.4.
  116. \item \textbf{Objects} - a Merkle DAG of content-addressed immutable objects with links. Used to represent arbitrary datastructures, e.g. file hierarchies and communication systems. Described in Section 3.5.
  117. \item \textbf{Files} - versioned file system hierarchy inspired by Git. Described in Section 3.6.
  118. \item \textbf{Naming} - A self-certifying mutable name system. Described in Section 3.7.
  119. \end{enumerate}
  120. These subsystems are not independent; they are integrated and leverage
  121. blended properties. However, it is useful to describe them separately,
  122. building the protocol stack from the bottom up.
  123. Notation: data structures and functions below are specified in Go syntax.
  124. \subsection{Identities}
  125. Nodes are identified by a \texttt{NodeId}, the cryptographic hash\footnote{Throughout this document, \textit{hash} and \textit{checksum} refer specifically to cryptographic hash checksums of data.} of a public-key, created with S/Kademlia's static crypto puzzle \cite{skademlia}. Nodes store their public and private keys (encrypted with a passphrase). Users are free to instatiate a ``new'' node identity on every launch, though that loses accrued network benefits. Nodes are incentivized to remain the same.
  126. \begin{verbatim}
  127. type NodeId Multihash
  128. type Multihash []byte
  129. // self-describing cryptographic hash digest
  130. type PublicKey []byte
  131. type PrivateKey []byte
  132. // self-describing keys
  133. type Node struct {
  134. NodeId NodeID
  135. PubKey PublicKey
  136. PriKey PrivateKey
  137. }
  138. \end{verbatim}
  139. S/Kademlia based IPFS identity generation:
  140. \begin{verbatim}
  141. difficulty = <integer parameter>
  142. n = Node{}
  143. do {
  144. n.PubKey, n.PrivKey = PKI.genKeyPair()
  145. n.NodeId = hash(hash(n.PubKey))
  146. p = count_preceding_zero_bits(n.NodeId)
  147. } while (p < difficulty)
  148. \end{verbatim}
  149. Upon first connecting, peers exchange public keys, and check: \texttt{hash(other.PublicKey) equals other.NodeId}. If not, the connection is terminated.
  150. \paragraph{Note on Cryptographic Functions} Rather than locking the system to a particular set of function choices, IPFS favors self-describing values. Hash digest values are stored in \texttt{multihash} format, which includes a short header specifying the hash function used, and the digest length in bytes. Example:
  151. \begin{verbatim}
  152. <function code><digest length><digest bytes>
  153. \end{verbatim}
  154. This allows the system to (a) choose the best function for the use case (e.g. stronger security vs faster performance), and (b) evolve as function choices change. Self-describing values allow using different parameter choices compatibly.
  155. \subsection{Network}
  156. IPFS nodes communicate regualarly with hundreds of other nodes in the network, potentially across the wide internet. The IPFS network stack features:
  157. \begin{itemize}
  158. \item \textbf{Transport:} IPFS can use any transport protocol, and is best suited for WebRTC DataChannels \cite{WebRTC} (for browser connectivity) or uTP \cite{uTP} (LEDBAT) \cite{LEDBAT}.
  159. \item \textbf{Reliability:} IPFS can provide reliability if underlying networks do not provide it, using uTP (LEDBAT) \cite{LEDBAT} or SCTP.
  160. \item \textbf{Connectivity:} IPFS also uses the ICE NAT traversal techniques \cite{ICE}.
  161. \item \textbf{Integrity:} optionally checks integrity of messages using a hash checksum.
  162. \item \textbf{Authenticity:} optionally checks authenticity of messages using HMAC with sender's public key.
  163. \end{itemize}
  164. \subsubsection{Note on Peer Addressing}
  165. IPFS can use any network; it does not rely on or assume access to IP. This allows IPFS to be used in overlay networks. IPFS stores addresses as \texttt{multiaddr} formatted byte strings for the underlying network to use. \texttt{multiaddr} provides a way to express addresses and their protocols, including support for encapsulation. For example:
  166. \begin{verbatim}
  167. # an SCTP/IPv4 connection
  168. /ip4/10.20.30.40/sctp/1234/
  169. # an SCTP/IPv4 connection proxied over TCP/IPv4
  170. /ip4/5.6.7.8/tcp/5678/ip4/1.2.3.4/sctp/1234/
  171. \end{verbatim}
  172. \subsection{Routing}
  173. IPFS nodes require a routing system that can find (a) other peers' network addresses and (b) peers who can serve particular objects. IPFS achieves this using a DSHT based on S/Kademlia and Coral, using the properties discussed in 2.1. The size of objects and use patterns of IPFS are similar to Coral \cite{Coral} and Mainline \cite{Mainline}, so the IPFS DHT makes a distinction for values stored based on their size. Small values (equal to or less than \texttt{1KB}) are stored directly on the DHT. For values larger, the DHT stores references, which are the \texttt{NodeIds} of peers who can serve the block.
  174. The interface of this DSHT is the following:
  175. \begin{verbatim}
  176. type IPFSRouting interface {
  177. FindPeer(node NodeId)
  178. // gets a particular peer's network address
  179. SetValue(key []bytes, value []bytes)
  180. // stores a small metadata value in DHT
  181. GetValue(key []bytes)
  182. // retrieves small metadata value from DHT
  183. ProvideValue(key Multihash)
  184. // announces this node can serve a large value
  185. FindValuePeers(key Multihash, min int)
  186. // gets a number of peers serving a large value
  187. }
  188. \end{verbatim}
  189. Note: different use cases will call for substantially different routing systems (e.g. DHT in wide network, static HT in local network). Thus the IPFS routing system can be swapped for one that fits users' needs. As long as the interface above is met, the rest of the system will continue to function.
  190. \subsection{Block Exchange - BitSwap Protocol}
  191. In IPFS, data distribution happens by exchanging blocks with peers using a
  192. BitTorrent inspired protocol: BitSwap. Like BitTorrent, BitSwap peers are
  193. looking to acquire a set of blocks (\texttt{want\_list}), and have another set
  194. of blocks to offer in exchange (\texttt{have\_list}).
  195. Unlike BitTorrent, BitSwap is not limited to the blocks in one torrent.
  196. BitSwap operates as a persistent marketplace where node can acquire the
  197. blocks they need, regardless of what files those blocks are part of. The
  198. blocks could come from completely unrelated files in the filesystem.
  199. Nodes come together to barter in the marketplace.
  200. While the notion of a barter system implies a virtual currency could be
  201. created, this would require a global ledger to track ownership
  202. and transfer of the currency. This can be implemented as a BitSwap Strategy, and will be explored in a future paper.
  203. In the base case, BitSwap nodes have to provide direct value to each other
  204. in the form of blocks. This works fine when the distribution of blocks across
  205. nodes is complementary, meaning they have what the other wants. Often, this
  206. will not be the case. In some cases, nodes must \textit{work} for their
  207. blocks. In the case that a node has nothing that its peers want (or
  208. nothing at all), it seeks the pieces its peers want, with lower
  209. priority than what the node wants itself. This incentivizes nodes to cache and
  210. disseminate rare pieces, even if they are not interested in them directly.
  211. \subsubsection{BitSwap Credit}
  212. The protocol must also incentivize nodes to seed when they do not need
  213. anything in particular, as they might have the blocks others want. Thus,
  214. BitSwap nodes send blocks to their peers optimistically, expecting the debt to
  215. be repaid. But leeches (free-loading nodes that never share) must be protected against. A simple credit-like system solves the problem:
  216. \begin{enumerate}
  217. \item Peers track their balance (in bytes verified) with other nodes.
  218. \item Peers send blocks to debtor peers probabilistically, according to
  219. a function that falls as debt increases.
  220. \end{enumerate}
  221. Note that if a node decides not to send to a peer, the node subsequently
  222. ignores the peer for an \texttt{ignore\_cooldown} timeout. This prevents
  223. senders from trying to game the probability by just causing more dice-rolls.
  224. (Default BitSwap is 10 seconds).
  225. \subsubsection{BitSwap Strategy}
  226. The differing strategies that BitSwap peers might employ have wildly different effects on the performance of the exchange as a whole. In BitTorrent, while a standard strategy is specified (tit-for-tat), a variety of others have been implemented, ranging from BitTyrant \cite{BitTyrant} (sharing the least-possible), to BitThief \cite{BitThief} (exploiting a vulnerability and never share), to PropShare \cite{PropShare} (sharing proportionally). A range of strategies (good and malicious) could similarly be implemented by BitSwap peers. The choice of function, then, should aim to:
  227. \begin{enumerate}
  228. \item maximize the trade performance for the node, and the whole exchange
  229. \item prevent freeloaders from exploiting and degrading the exchange
  230. \item be effective with and resistant to other, unknown
  231. strategies
  232. \item be lenient to trusted peers
  233. \end{enumerate}
  234. The exploration of the space of such strategies is future work.
  235. One choice of function that works in practice is a sigmoid, scaled by a
  236. \textit{debt retio}:
  237. Let the \textit{debt ratio} $ r $ between a node and its peer be:
  238. \[ r = \dfrac{\texttt{bytes\_sent}}{\texttt{bytes\_recv} + 1} \]
  239. Given $r$, let the probability of sending to a debtor be:
  240. \[ P\Big( \; send \; | \; r \;\Big) = 1 - \dfrac{1}{1 + exp(6-3r)} \]
  241. \begin{figure}
  242. \centering
  243. \begin{tikzpicture}[domain=0:4]
  244. \draw[->] (-0,0) -- (4.2,0) node[right] {$r$};
  245. \draw[->] (0,-0) -- (0,1.20) node[above] {$P(\;send\;|\;r\;)$};
  246. %ticks
  247. \foreach \x in {0,...,4}
  248. \draw (\x,1pt) -- (\x,-3pt)
  249. node[anchor=north] {\x};
  250. \foreach \y in {1,...,1}
  251. \draw (1pt,\y) -- (-3pt,\y)
  252. node[anchor=east] {\y};
  253. \draw[color=red] plot[] function{1 - 1/(1+exp(6-3*x))};
  254. \end{tikzpicture}
  255. \caption{Probability of Sending as $r$ increases}
  256. \label{fig:psending-graph}
  257. \end{figure}
  258. As you can see in Figure \ref{fig:psending-graph}, this function drops off quickly as the nodes'
  259. \textit{debt ratio} surpasses twice the established credit.
  260. The \textit{debt ratio} is a measure of trust:
  261. lenient to debts between nodes that have previously exchanged lots of data
  262. successfully, and merciless to unknown, untrusted nodes. This
  263. (a) provides resistance to attackers who would create lots of new nodes
  264. (sybill attacks),
  265. (b) protects previously successful trade relationships, even if one of the
  266. nodes is temporarily unable to provide value, and
  267. (c) eventually chokes relationships that have deteriorated until they
  268. improve.
  269. % \begin{center}
  270. % \begin{tabular}{ >{$}c<{$} >{$}c<{$}}
  271. % P(\;send\;|\quad r) \;\;\;\;\;& \\
  272. % \hline
  273. % \hline
  274. % P(\;send\;|\;0.0) =& 1.00 \\
  275. % P(\;send\;|\;0.5) =& 1.00 \\
  276. % P(\;send\;|\;1.0) =& 0.98 \\
  277. % P(\;send\;|\;1.5) =& 0.92 \\
  278. % P(\;send\;|\;2.0) =& 0.73 \\
  279. % P(\;send\;|\;2.5) =& 0.38 \\
  280. % P(\;send\;|\;3.0) =& 0.12 \\
  281. % P(\;send\;|\;3.5) =& 0.03 \\
  282. % P(\;send\;|\;4.0) =& 0.01 \\
  283. % P(\;send\;|\;4.5) =& 0.00 \\
  284. % \end{tabular}
  285. % \end{center}
  286. % TODO look into computing share of the bandwidth, as described in propshare.
  287. \subsubsection{BitSwap Ledger}
  288. BitSwap nodes keep ledgers accounting the transfers with other nodes. This allows nodes to keep track of history and avoid tampering. When activating a connection, BitSwap nodes exchange their ledger information. If it does not match exactly, the ledger is reinitialized from scratch, losing the accrued credit or debt. It is possible for malicious nodes to purposefully ``lose'' the Ledger, hoping to erase debts. It is unlikely that nodes will have accrued enough debt to warrant also losing the accrued trust; however the partner node is free to count it as misconduct, and refuse to trade.
  289. \begin{verbatim}
  290. type Ledger struct {
  291. owner NodeId
  292. partner NodeId
  293. bytes_sent int
  294. bytes_recv int
  295. timestamp Timestamp
  296. }
  297. \end{verbatim}
  298. Nodes are free to keep the ledger history, though it is not necessary for
  299. correct operation. Only the current ledger entries are useful. Nodes are
  300. also free to garbage collect ledgers as necessary, starting with the less
  301. useful ledgers: the old (peers may not exist anymore) and small.
  302. \subsubsection{BitSwap Specification}
  303. BitSwap nodes follow a simple protocol.
  304. \begin{verbatim}
  305. // Additional state kept
  306. type BitSwap struct {
  307. ledgers map[NodeId]Ledger
  308. // Ledgers known to this node, inc inactive
  309. active map[NodeId]Peer
  310. // currently open connections to other nodes
  311. need_list []Multihash
  312. // checksums of blocks this node needs
  313. have_list []Multihash
  314. // checksums of blocks this node has
  315. }
  316. type Peer struct {
  317. nodeid NodeId
  318. ledger Ledger
  319. // Ledger between the node and this peer
  320. last_seen Timestamp
  321. // timestamp of last received message
  322. want_list []Multihash
  323. // checksums of all blocks wanted by peer
  324. // includes blocks wanted by peer's peers
  325. }
  326. // Protocol interface:
  327. interface Peer {
  328. open (nodeid :NodeId, ledger :Ledger);
  329. send_want_list (want_list :WantList);
  330. send_block (block :Block) -> (complete :Bool);
  331. close (final :Bool);
  332. }
  333. \end{verbatim}
  334. Sketch of the lifetime of a peer connection:
  335. \begin{enumerate}
  336. \item Open: peers send \texttt{ledgers} until they agree.
  337. \item Sending: peers exchange \texttt{want\_lists} and \texttt{blocks}.
  338. \item Close: peers deactivate a connection.
  339. \item Ignored: (special) a peer is ignored (for the duration of a timeout)
  340. if a node's strategy avoids sending
  341. \end{enumerate}
  342. \paragraph{Peer.open(NodeId, Ledger)}
  343. When connecting, a node initializes a connection with a
  344. \texttt{Ledger}, either stored from a connection in the past or a new one
  345. zeroed out. Then, sends an Open message with the \texttt{Ledger} to the peer.
  346. Upon receiving an \texttt{Open} message, a peer chooses whether to activate
  347. the connection. If -- acording to the receiver's \texttt{Ledger} -- the sender
  348. is not a trusted agent (transmission below zero, or large outstanding debt) the
  349. receiver may opt to ignore the request. This should be done probabilistically
  350. with an \texttt{ignore\_cooldown} timeout, as to allow errors to be corrected
  351. and attackers to be thwarted.
  352. If activating the connection, the receiver initializes a Peer object with the
  353. local version of the \texttt{Ledger} and sets the \texttt{last\_seen}
  354. timestamp. Then, it compares the received
  355. \texttt{Ledger} with its own. If they match exactly, the connections have
  356. opened. If they do not match, the peer creates a new zeroed out
  357. \texttt{Ledger} and sends it.
  358. \paragraph{Peer.send\_want\_list(WantList)}
  359. While the connection is open, nodes advertise their
  360. \texttt{want\_list} to all connected peers. This is done (a) upon opening the
  361. connection, (b) after a randomized periodic timeout, (c) after a change in
  362. the \texttt{want\_list} and (d) after receiving a new block.
  363. Upon receiving a \texttt{want\_list}, a node stores it. Then, it checks whether
  364. it has any of the wanted blocks. If so, it sends them according to the
  365. \textit{BitSwap Strategy} above.
  366. \paragraph{Peer.send\_block(Block)}
  367. Sending a block is straightforward. The node simply transmits the block of
  368. data. Upon receiving all the data, the receiver computes the Multihash
  369. checksum to verify it matches the expected one, and returns confirmation.
  370. Upon finalizing the correct transmission of a block, the receiver moves the
  371. block from \texttt{need\_list} to \texttt{have\_list}, and both the receiver
  372. and sender update their ledgers to reflect the additional bytes transmitted.
  373. If a transmission verification fails, the sender is either malfunctioning or
  374. attacking the receiver. The receiver is free to refuse further trades. Note
  375. that BitSwap expects to operate on a reliable transmission channel, so
  376. transmission errors -- which could lead to incorrect penalization of an honest
  377. sender -- are expected to be caught before the data is given to BitSwap.
  378. \paragraph{Peer.close(Bool)}
  379. The \texttt{final} parameter to \texttt{close} signals whether the intention
  380. to tear down the connection is the sender's or not. If false, the receiver
  381. may opt to re-open the connection immediatelty. This avoids premature
  382. closes.
  383. A peer connection should be closed under two conditions:
  384. \begin{itemize}
  385. \item a \texttt{silence\_wait} timeout has expired without receiving any
  386. messages from the peer (default BitSwap uses 30 seconds).
  387. The node issues \texttt{Peer.close(false)}.
  388. \item the node is exiting and BitSwap is being shut down.
  389. In this case, the node issues \texttt{Peer.close(true)}.
  390. \end{itemize}
  391. After a \texttt{close} message, both receiver and sender tear down the
  392. connection, clearing any state stored. The \texttt{Ledger} may be stored for
  393. the future, if it is useful to do so.
  394. \paragraph{Notes}
  395. \begin{itemize}
  396. \item Non-\texttt{open} messages on an inactive connection should be ignored.
  397. In case of a \texttt{send\_block} message, the receiver may check
  398. the block to see if it is needed and correct, and if so, use it.
  399. Regardless, all such out-of-order messages trigger a
  400. \texttt{close(false)} message from the receiver to force
  401. re-initialization of the connection.
  402. \end{itemize}
  403. % TODO: Rate Limiting / Node Silencing
  404. \subsection{Object Merkle DAG}
  405. The DHT and BitSwap allow IPFS to form a massive peer-to-peer system for storing and distributing blocks quickly and robustly. On top of these, IPFS builds a Merkle DAG, a directed acyclic graph where links between objects are cryptographic hashes of the targets embedded in the sources. This is a generalization of the Git data structure. Merkle DAGs provide IPFS many useful properties, including:
  406. \begin{enumerate}
  407. \item \textbf{Content Addressing:} all content is uniquely identified by its
  408. \texttt{multihash} checksum, \textbf{including links}.
  409. \item \textbf{Tamper resistance:} all content is verified with its checksum.
  410. If data is tampered with or corrupted, IPFS detects it.
  411. \item \textbf{Deduplication:} all objects that hold the exact same content
  412. are equal, and only stored once. This is particularly useful with
  413. index objects, such as git \texttt{trees} and \texttt{commits}, or common portions of data.
  414. \end{enumerate}
  415. The IPFS Object format is:
  416. \begin{verbatim}
  417. type IPFSLink struct {
  418. Name string
  419. // name or alias of this link
  420. Hash Multihash
  421. // cryptographic hash of target
  422. Size int
  423. // total size of target
  424. }
  425. type IPFSObject struct {
  426. links []IPFSLink
  427. // array of links
  428. data []byte
  429. // opaque content data
  430. }
  431. \end{verbatim}
  432. The IPFS Merkle DAG is an extremely flexible way to store data. The only requirements are that object references be (a) content addressed, and (b) encoded in the format above. IPFS grants applications complete control over the data field; applications can use any custom data format they chose, which IPFS may not understand. The separate in-object link table allows IPFS to:
  433. \begin{itemize}
  434. \item List all object references in an object. For example:
  435. \begin{verbatim}
  436. > ipfs ls /XLZ1625Jjn7SubMDgEyeaynFuR84ginqvzb
  437. XLYkgq61DYaQ8NhkcqyU7rLcnSa7dSHQ16x 189458 less
  438. XLHBNmRQ5sJJrdMPuu48pzeyTtRo39tNDR5 19441 script
  439. XLF4hwVHsVuZ78FZK6fozf8Jj9WEURMbCX4 5286 template
  440. <object multihash> <object size> <link name>
  441. \end{verbatim}
  442. \item Resolve string path lookups, such as \texttt{foo/bar/baz}. Given an object, IPFS resolves the first path component to a hash in the object's link table, fetches that second object, and repeats with the next component. Thus, string paths can walk the Merkle DAG no matter what the data formats are.
  443. \item Resolve all objects referenced recursively:
  444. \begin{verbatim}
  445. > ipfs refs --recursive \
  446. /XLZ1625Jjn7SubMDgEyeaynFuR84ginqvzb
  447. XLLxhdgJcXzLbtsLRL1twCHA2NrURp4H38s
  448. XLYkgq61DYaQ8NhkcqyU7rLcnSa7dSHQ16x
  449. XLHBNmRQ5sJJrdMPuu48pzeyTtRo39tNDR5
  450. XLWVQDqxo9Km9zLyquoC9gAP8CL1gWnHZ7z
  451. ...
  452. \end{verbatim}
  453. \end{itemize}
  454. A raw data field and a common link structure are the necessary components for constructing arbitrary data structures on top of IPFS. While it is easy to see how the Git object model fits on top of this DAG, consider these other potential data structures:
  455. (a) key-value stores
  456. (b) traditional relational databases
  457. (c) Linked Data triple stores
  458. (d) linked document publishing systems
  459. (e) linked communications platforms
  460. (f) cryptocurrency blockchains.
  461. These can all be modeled on top of the IPFS Merkle DAG, which allows any of these systems to use IPFS as a transport protocol for more complex applications.
  462. \subsubsection{Paths}
  463. IPFS objects can be traversed with a string path API. Paths work as they do in traditional UNIX filesystems and the Web. The Merkle DAG links make traversing it easy. Note that full paths in IPFS are of the form:
  464. \begin{verbatim}
  465. # format
  466. /ipfs/<hash-of-object>/<name-path-to-object>
  467. # example
  468. /ipfs/XLYkgq61DYaQ8NhkcqyU7rLcnSa7dSHQ16x/foo.txt
  469. \end{verbatim}
  470. The \texttt{/ipfs} prefix allows mounting into existing systems at a standard mount point without conflict (mount point names are of course configurable). The second path component (first within IPFS) is the hash of an object. This is always the case, as there is no global root. A root object would have the impossible task of handling consistency of millions of objects in a distributed (and possibly disconnected) environment. Instead, we simulate the root with content addressing. All objects are always accessible via their hash. Note this means that given three objects in path \texttt{<foo>/bar/baz}, the last object is accessible by all:
  471. \begin{verbatim}
  472. /ipfs/<hash-of-foo>/bar/baz
  473. /ipfs/<hash-of-bar>/baz
  474. /ipfs/<hash-of-baz>
  475. \end{verbatim}
  476. \subsubsection{Local Objects}
  477. IPFS clients require some \textit{local storage}, an external system
  478. on which to store and retrieve local raw data for the objects IPFS manages.
  479. The type of storage depends on the node's use case.
  480. In most cases, this is simply a portion of disk space (either managed by
  481. the native filesystem, by a key-value store such as leveldb \cite{leveldb}, or
  482. directly by the IPFS client). In others, for example non-persistent caches,
  483. this storage is just a portion of RAM.
  484. Ultimately, all blocks available in IPFS are in some node's
  485. \textit{local storage}. When users request objects, they are
  486. found, downloaded, and stored locally, at least temporarily. This provides
  487. fast lookup for some configurable amount of time thereafter.
  488. \subsubsection{Object Pinning}
  489. Nodes who wish to ensure the survival of particular objects can do so by
  490. \texttt{pinning} the objects. This ensures the objects are kept in the node's
  491. \textit{local storage}. Pinning can be done recursively, to pin down all
  492. linked descendent objects as well. All objects pointed to are then stored
  493. locally. This is particularly useful to persist files, including references.
  494. This also makes IPFS a Web where links are \textit{permanent}, and Objects can
  495. ensure the survival of others they point to.
  496. \subsubsection{Publishing Objects}
  497. IPFS is globally distributed. It is designed to allow the files of millions of users to coexist together. The DHT, with content-hash addressing, allows publishing objects in a fair, secure, and entirely distributed way. Anyone can publish an object by simply adding its key to the DHT, adding themselves as a peer, and giving other users the object's path. Note that Objects are essentially immutable, just like in Git. New versions hash differently, and thus are new objects. Tracking versions is the job of additional versioning objects.
  498. \subsubsection{Object-level Cryptography}
  499. IPFS is equipped to handle object-level cryptographic operations. An encrypted or signed object is wrapped in a special frame that allows encryption or verification of the raw bytes.
  500. \begin{verbatim}
  501. type EncryptedObject struct {
  502. Object []bytes
  503. // raw object data encrypted
  504. Tag []bytes
  505. // optional tag for encryption groups
  506. }
  507. type SignedObject struct {
  508. Object []bytes
  509. // raw object data signed
  510. Signature []bytes
  511. // hmac signature
  512. PublicKey []multihash
  513. // multihash identifying key
  514. }
  515. \end{verbatim}
  516. Cryptographic operations change the object's hash, defining a different object. IPFS automatically verifies signatures, and can decrypt data with user-specified keychains. Links of encrypted objects are protected as well, making traversal impossible without a decryption key. It is possible to have a parent object encrypted under one key, and a child under another or not at all. This secures links to shared objects.
  517. \subsection{Files}
  518. IPFS also defines a set of objects for modeling a versioned filesystem on top of the Merkle DAG. This object model is similar to Git's:
  519. \begin{enumerate}
  520. \item \texttt{block}: a variable-size block of data.
  521. \item \texttt{list}: a collection of blocks or other lists.
  522. \item \texttt{tree}: a collection of blocks, lists, or other trees.
  523. \item \texttt{commit}: a snapshot in the version history of a tree.
  524. \end{enumerate}
  525. I hoped to use the Git object formats exactly, but had to depart to introduce certain features useful in a distributed filesystem, namely (a) fast size lookups (aggregate byte sizes have been added to objects), (b) large file deduplication (adding a \texttt{list} object), and (c) embedding of \texttt{commits} into \texttt{trees}. However, IPFS File objects are close enough to Git that conversion between the two is possible. Also, a set of Git objects can be introduced to convert without losing any information (unix file permissions, etc).
  526. Notation: File object formats below use JSON. Note that this structure is actually binary encoded using protobufs, though ipfs includes import/export to JSON.
  527. \subsubsection{File Object: \texttt{blob}}
  528. The \texttt{blob} object contains an addressable unit of data, and
  529. represents a file. IPFS Blocks are like Git blobs or filesystem data blocks. They store the users' data. Note that IPFS files can be represented by both \texttt{lists} and \texttt{blobs}. Blobs have no links.
  530. \begin{verbatim}
  531. {
  532. "data": "some data here",
  533. // blobs have no links
  534. }
  535. \end{verbatim}
  536. \subsubsection{File Object: \texttt{list}}
  537. The \texttt{list} object represents a large or deduplicated file made up of
  538. several IPFS \texttt{blobs} concatenated together. \texttt{lists} contain
  539. an ordered sequence of \texttt{blob} or \texttt{list} objects.
  540. In a sense, the IPFS \texttt{list} functions like a filesystem file with
  541. indirect blocks. Since \texttt{lists} can contain other \texttt{lists}, topologies including linked lists and balanced trees are possible. Directed graphs where the same node appears in multiple places allow in-file deduplication. Of course, cycles are not possible, as enforced by hash addressing.
  542. \begin{verbatim}
  543. {
  544. "data": ["blob", "list", "blob"],
  545. // lists have an array of object types as data
  546. "links": [
  547. { "hash": "XLYkgq61DYaQ8NhkcqyU7rLcnSa7dSHQ16x",
  548. "size": 189458 },
  549. { "hash": "XLHBNmRQ5sJJrdMPuu48pzeyTtRo39tNDR5",
  550. "size": 19441 },
  551. { "hash": "XLWVQDqxo9Km9zLyquoC9gAP8CL1gWnHZ7z",
  552. "size": 5286 }
  553. // lists have no names in links
  554. ]
  555. }
  556. \end{verbatim}
  557. \begin{figure}
  558. \centering
  559. \begin{tikzpicture}[->,>=stealth',auto,thick,
  560. minimum height=2em,minimum width=5em]
  561. \tikzstyle{ghost}=[rectangle,rounded corners=.8ex];
  562. \tikzstyle{block}=[rectangle,draw,fill=blue!20,rounded corners=.8ex];
  563. \tikzstyle{list}=[rectangle,draw,fill=cyan!20,rounded corners=.8ex];
  564. \tikzstyle{tree}=[rectangle,draw,fill=green!20,rounded corners=.8ex];
  565. \tikzstyle{commit}=[rectangle,draw,fill=magenta!20,rounded corners=.8ex];
  566. \tikzstyle{every path}=[draw]
  567. \node[commit] (ccc111) {ccc111};
  568. \node[tree] (ttt111) [below=3em of ccc111] {ttt111};
  569. \node[tree] (ttt222) [below left=3em and 3em of ttt111] {ttt222};
  570. \node[tree] (ttt333) [below=3em of ttt111] {ttt333};
  571. \node[ghost] (ghost1) [below right=3em and 3em of ttt111] {};
  572. \node[list] (lll111) [below=3em of ttt333] {lll111};
  573. \node[block] (bbb111) [below=3em of ttt222] {bbb111};
  574. \node[block] (bbb222) [below right=3em and 3em of ttt333] {bbb222};
  575. \node[block] (bbb333) [below left=3em and 3em of lll111] {bbb333};
  576. \node[block] (bbb444) [below=3em of lll111] {bbb444};
  577. \node[block] (bbb555) [below right=3em and 3em of lll111] {bbb555};
  578. \path[every node/.style={font=\sffamily\small}]
  579. (ccc111) edge[out=-90,in=90] (ttt111)
  580. (ttt111) edge[out=-90,in=90] (ttt222)
  581. edge[out=-90,in=90] (ttt333)
  582. to [out=-90,in=90] (ghost1)
  583. to [out=-90,in=90] (bbb222)
  584. (ttt222) edge[out=-90,in=90] (bbb111)
  585. (ttt333) edge[out=-90,in=90] (lll111)
  586. edge[out=-90,in=90] (bbb222)
  587. (lll111) edge[out=-90,in=90] (bbb333)
  588. edge[out=-90,in=90] (bbb444)
  589. edge[out=-90,in=90] (bbb555)
  590. ;
  591. \end{tikzpicture}
  592. \caption{Sample Object Graph} \label{fig:sample-object-graph}
  593. \begin{verbatim}
  594. > ipfs file-cat <ccc111-hash> --json
  595. {
  596. "data": {
  597. "type": "tree",
  598. "date": "2014-09-20 12:44:06Z",
  599. "message": "This is a commit message."
  600. },
  601. "links": [
  602. { "hash": "<ccc000-hash>",
  603. "name": "parent", "size": 25309 },
  604. { "hash": "<ttt111-hash>",
  605. "name": "object", "size": 5198 },
  606. { "hash": "<aaa111-hash>",
  607. "name": "author", "size": 109 }
  608. ]
  609. }
  610. > ipfs file-cat <ttt111-hash> --json
  611. {
  612. "data": ["tree", "tree", "blob"],
  613. "links": [
  614. { "hash": "<ttt222-hash>",
  615. "name": "ttt222-name", "size": 1234 },
  616. { "hash": "<ttt333-hash>",
  617. "name": "ttt333-name", "size": 3456 },
  618. { "hash": "<bbb222-hash>",
  619. "name": "bbb222-name", "size": 22 }
  620. ]
  621. }
  622. > ipfs file-cat <bbb222-hash> --json
  623. {
  624. "data": "blob222 data",
  625. "links": []
  626. }
  627. \end{verbatim}
  628. \caption{Sample Objects} \label{fig:sample-objects}
  629. \end{figure}
  630. \subsubsection{File Object: \texttt{tree}}
  631. The \texttt{tree} object in IPFS is similar to Git's: it represents a
  632. directory, a map of names to hashes. The hashes reference \texttt{blobs}, \texttt{lists}, other \texttt{trees}, or \texttt{commits}. Note that traditional path naming is already implemented by the Merkle DAG.
  633. \begin{verbatim}
  634. {
  635. "data": ["blob", "list", "blob"],
  636. // trees have an array of object types as data
  637. "links": [
  638. { "hash": "XLYkgq61DYaQ8NhkcqyU7rLcnSa7dSHQ16x",
  639. "name": "less", "size": 189458 },
  640. { "hash": "XLHBNmRQ5sJJrdMPuu48pzeyTtRo39tNDR5",
  641. "name": "script", "size": 19441 },
  642. { "hash": "XLWVQDqxo9Km9zLyquoC9gAP8CL1gWnHZ7z",
  643. "name": "template", "size": 5286 }
  644. // trees do have names
  645. ]
  646. }
  647. \end{verbatim}
  648. \subsubsection{File Object: \texttt{commit}}
  649. The \texttt{commit} object in IPFS represents a snapshot in the version history of any object. It is similar to Git's, but can reference any type of object. It also links to author objects.
  650. \begin{verbatim}
  651. {
  652. "data": {
  653. "type": "tree",
  654. "date": "2014-09-20 12:44:06Z",
  655. "message": "This is a commit message."
  656. },
  657. "links": [
  658. { "hash": "XLa1qMBKiSEEDhojb9FFZ4tEvLf7FEQdhdU",
  659. "name": "parent", "size": 25309 },
  660. { "hash": "XLGw74KAy9junbh28x7ccWov9inu1Vo7pnX",
  661. "name": "object", "size": 5198 },
  662. { "hash": "XLF2ipQ4jD3UdeX5xp1KBgeHRhemUtaA8Vm",
  663. "name": "author", "size": 109 }
  664. ]
  665. }
  666. \end{verbatim}
  667. \subsubsection{Version control}
  668. The \texttt{commit} object represents a particular snapshot in the version
  669. history of an object. Comparing the objects (and children) of two
  670. different commits reveals the differences between two versions of the
  671. filesystem. As long as a single \texttt{commit} and all the children objects
  672. it references are accessible, all preceding versions are retrievable and the
  673. full history of the filesystem changes can be accessed. This falls out
  674. of the Merkle DAG object model.
  675. The full power of the Git version control tools is available to IPFS users. The object model is compatible, though not the same. It is possible to (a) build a version of the Git tools modified to use the IPFS object graph, (b) build a mounted FUSE filesystem that mounts an IPFS \texttt{tree} as a Git repo, translating Git filesystem read/writes to the IPFS formats.
  676. \subsubsection{Filesystem Paths}
  677. As we saw in the Merkle DAG section, IPFS objects can be traversed with a string path API. The IPFS File Objects are designed to make mounting IPFS onto a UNIX filesystem simpler. They restrict \texttt{trees} to have no data, in order to represent them as directories. And \texttt{commits} can either be represented as directories or hidden from the filesystem entirely.
  678. \subsubsection{Splitting Files into Lists and Blob}
  679. One of the main challenges with versioning and distributing large files is finding the right way to split them into independent blocks. Rather than assume it can make the right decision for every type of file, IPFS offers the following alternatives:
  680. \begin{enumerate}
  681. \item[(a)] Use Rabin Fingerprints \cite{RabinFingerprints} as in LBFS \cite{LBFS} to pick suitable block boundaries.
  682. \item[(b)] Use the rsync \cite{rsync} rolling-checksum algorithm, to detect blocks that have changed between versions.
  683. \item[(c)] Allow users to specify block-splitting functions highly tuned for specific files.
  684. \end{enumerate}
  685. \paragraph{Path Lookup Performance}
  686. Path-based access traverses the object graph. Retrieving
  687. each object requires looking up its key in the DHT,
  688. connecting to peers, and retrieving its blocks. This is considerable
  689. overhead, particularly when looking up paths with many components.
  690. This is mitigated by:
  691. \begin{itemize}
  692. \item \textbf{tree caching}: since all objects are hash-addressed, they
  693. can be cached indefinitely. Additionally, \texttt{trees} tend to be
  694. small in size so IPFS prioritizes caching them over \texttt{blobs}.
  695. \item \textbf{flattened trees}: for any given \texttt{tree}, a special
  696. \texttt{flattened tree} can be constructed to list all objects
  697. reachable from the \texttt{tree}. Names in the \texttt{flattened tree}
  698. would really be paths parting from the original tree, with slashes.
  699. \end{itemize}
  700. For example, \texttt{flattened tree} for \texttt{ttt111} above:
  701. \begin{verbatim}
  702. {
  703. "data":
  704. ["tree", "blob", "tree", "list", "blob" "blob"],
  705. "links": [
  706. { "hash": "<ttt222-hash>", "size": 1234
  707. "name": "ttt222-name" },
  708. { "hash": "<bbb111-hash>", "size": 123,
  709. "name": "ttt222-name/bbb111-name" },
  710. { "hash": "<ttt333-hash>", "size": 3456,
  711. "name": "ttt333-name" },
  712. { "hash": "<lll111-hash>", "size": 587,
  713. "name": "ttt333-name/lll111-name"},
  714. { "hash": "<bbb222-hash>", "size": 22,
  715. "name": "ttt333-name/lll111-name/bbb222-name" },
  716. { "hash": "<bbb222-hash>", "size": 22
  717. "name": "bbb222-name" }
  718. ] }
  719. \end{verbatim}
  720. \subsection{IPNS: Naming and Mutable State}
  721. So far, the IPFS stack forms a peer-to-peer block exchange constructing a content-addressed DAG of objects. It serves to publish and retrieve immutable objects. It can even track the version history of these objects. However, there is a critical component missing: mutable naming. Without it, all communication of new content must happen off-band, sending IPFS links. What is required is some way to retrieve mutable state at \textit{the same path}.
  722. It is worth stating why -- if mutable data is necessary in the end -- we worked hard to build up an \textit{immutable} Merkle DAG. Consider the properties of IPFS that fall out of the Merkle DAG: objects can be (a) retrieved via their hash, (b) integrity checked, (c) linked to others, and (d) cached indefinitely. In a sense:
  723. \begin{center}
  724. Objects are \textbf{permanent}
  725. \end{center}
  726. \noindent These are the critical properties of a high-performance distributed system, where data is expensive to move across network links. Object content addressing constructs a web with (a) significant bandwidth optimizations, (b) untrusted content serving, (c) permanent links, and (d) the ability to make full permanent backups of any object and its references.
  727. The Merkle DAG, immutable content-addressed objects, and Naming, mutable pointers to the Merkle DAG, instantiate a dichotomy present in many successful distributed systems. These include the Git Version Control System, with its immutable objects and mutable references; and Plan9 \cite{Plan9}, the distributed successor to UNIX, with its mutable Fossil \cite{Fossil} and immutable Venti \cite{Venti} filesystems. LBFS \cite{LBFS} also uses mutable indices and immutable chunks.
  728. \subsubsection{Self-Certified Names}
  729. Using the naming scheme from SFS \cite{SFS} gives us a way to construct self-certified names, in a cryptographically assigned global namespace, that are mutable. The IPFS scheme is as follows.
  730. \begin{enumerate}
  731. \item Recall that in IPFS:
  732. \begin{verbatim}
  733. NodeId = hash(node.PubKey)
  734. \end{verbatim}
  735. \item We assign every user a mutable namespace at:
  736. \begin{verbatim}
  737. /ipns/<NodeId>
  738. \end{verbatim}
  739. \item A user can publish an Object to this path \textbf{Signed} by her private key, say at:
  740. \begin{verbatim}
  741. /ipns/XLF2ipQ4jD3UdeX5xp1KBgeHRhemUtaA8Vm/
  742. \end{verbatim}
  743. \item When other users retrieve the object, they can check the signature matches the public key and NodeId. This verifies the authenticity of the Object published by the user, achieving mutable state retrival.
  744. \end{enumerate}
  745. Note the following details:
  746. \begin{itemize}
  747. \item The \texttt{ipns} (InterPlanetary Name Space) separate prefix is to establish an easily recognizable distinction between \textit{mutable} and \textit{immutable} paths, for both programs and human readers.
  748. \item Because this is \textit{not} a content-addressed object, publishing it relies on the only mutable state distribution system in IPFS, the Routing system. The process is (1) publish the object as a regular immutable IPFS object, (2) publish its hash on the Routing system as a metadata value:
  749. \begin{verbatim}
  750. routing.setValue(NodeId, <ns-object-hash>)
  751. \end{verbatim}
  752. \item Any links in the Object published act as sub-names in the namespace:
  753. \end{itemize}
  754. \begin{verbatim}
  755. /ipns/XLF2ipQ4jD3UdeX5xp1KBgeHRhemUtaA8Vm/
  756. /ipns/XLF2ipQ4jD3UdeX5xp1KBgeHRhemUtaA8Vm/docs
  757. /ipns/XLF2ipQ4jD3UdeX5xp1KBgeHRhemUtaA8Vm/docs/ipfs
  758. \end{verbatim}
  759. \begin{itemize}
  760. \item it is advised to publish a \texttt{commit} object, or some other object with a version history, so that clients may be able to find old names. This is left as a user option, as it is not always desired.
  761. \end{itemize}
  762. Note that when users publish this Object, it cannot be published in the same way
  763. \subsubsection{Human Friendly Names}
  764. While IPNS is indeed a way of assigning and reassigning names, it is not very user friendly, as it exposes long hash values as names, which are notoriously hard to remember. These work for URLs, but not for many kinds of offline transmission. Thus, IPFS increases the user-friendliness of IPNS with the following techniques.
  765. \paragraph{Peer Links}
  766. As encouraged by SFS, users can link other users' Objects directly into their own Objects (namespace, home, etc). This has the benefit of also creating a web of trust (and supports the old Certificate Authority model):
  767. \begin{verbatim}
  768. # Alice links to bob Bob
  769. ipfs link /<alice-pk-hash>/friends/bob /<bob-pk-hash>
  770. # Eve links to Alice
  771. ipfs link /<eve-pk-hash/friends/alice /<alice-pk-hash>
  772. # Eve also has access to Bob
  773. /<eve-pk-hash/friends/alice/friends/bob
  774. # access Verisign certified domains
  775. /<verisign-pk-hash>/foo.com
  776. \end{verbatim}
  777. \paragraph{DNS TXT IPNS Records}
  778. If \texttt{/ipns/<domain>} is a valid domain name, IPFS
  779. looks up key \texttt{ipns} in its \texttt{DNS TXT} records. IPFS
  780. interprets the value as either an object hash or another IPNS path:
  781. \begin{verbatim}
  782. # this DNS TXT record
  783. ipfs.benet.ai. TXT "ipfs=XLF2ipQ4jD3U ..."
  784. # behaves as symlink
  785. ln -s /ipns/XLF2ipQ4jD3U /ipns/fs.benet.ai
  786. \end{verbatim}
  787. \paragraph{Proquint Pronounceable Identifiers}
  788. There have always been schemes to encode binary into pronounceable words. IPNS supports Proquint \cite{Proquint}. Thus:
  789. \begin{verbatim}
  790. # this proquint phrase
  791. /ipns/dahih-dolij-sozuk-vosah-luvar-fuluh
  792. # will resolve to corresponding
  793. /ipns/KhAwNprxYVxKqpDZ
  794. \end{verbatim}
  795. \paragraph{Name Shortening Services}
  796. Services are bound to spring up that will provide name shortening as a service, offering up their namespaces to users. This is similar to what we see today with DNS and Web URLs:
  797. \begin{verbatim}
  798. # User can get a link from
  799. /ipns/shorten.er/foobar
  800. # To her own namespace
  801. /ipns/XLF2ipQ4jD3UdeX5xp1KBgeHRhemUtaA8Vm
  802. \end{verbatim}
  803. \subsection{Using IPFS}
  804. IPFS is designed to be used in a number of different ways. Here are just some of the usecases I will be pursuing:
  805. \begin{enumerate}
  806. \item As a mounted global filesystem, under \texttt{/ipfs} and \texttt{/ipns}.
  807. \item As a mounted personal sync folder that automatically versions, publishes, and backs up any writes.
  808. \item As an encrypted file or data sharing system.
  809. \item As a versioned package manager for \textit{all} software.
  810. \item As the root filesystem of a Virtual Machine.
  811. \item As the boot filesystem of a VM (under a hypervisor).
  812. \item As a database: applications can write directly to the Merkle DAG data model and get all the versioning, caching, and distribution IPFS provides.
  813. \item As a linked (and encrypted) communications platform.
  814. \item As an integrity checked CDN for large files (without SSL).
  815. \item As an encrypted CDN.
  816. \item On webpages, as a web CDN.
  817. \item As a new Permanent Web where links do not die.
  818. \end{enumerate}
  819. The IPFS implementations target:
  820. \begin{enumerate}
  821. \item[(a)] an IPFS library to import in your own applications.
  822. \item[(b)] commandline tools to manipulate objects directly.
  823. \item[(c)] mounted file systems, using FUSE \cite{FUSE} or as kernel modules.
  824. \end{enumerate}
  825. \section{The Future}
  826. The ideas behind IPFS are the product of decades of successful distributed systems research in academia and open source. IPFS synthesizes many of the best ideas from the most successful systems to date. Aside from BitSwap, which is a novel protocol, the main contribution of IPFS is this coupling of systems and synthesis of designs.
  827. IPFS is an ambitious vision of new decentralized Internet infrastructure, upon which many different kinds of applications can be built. At the bare minimum, it can be used as a global, mounted, versioned filesystem and namespace, or as the next generation file sharing system. At its best, it could push the web to new horizons, where publishing valuable information does not impose hosting it on the publisher but upon those interested, where users can trust the content they receive without trusting the peers they receive it from, and where old but important files do not go missing. IPFS looks forward to bringing us toward the Permanent Web.
  828. \section{Acknowledgments}
  829. IPFS is the synthesis of many great ideas and systems. It would be impossible to dare such ambitious goals without standing on the shoulders of such giants. Personal thanks to David Dalrymple, Joe Zimmerman, and Ali Yahya for long discussions on many of these ideas, in particular: exposing the general Merkle DAG (David, Joe), rolling hash blocking (David), and s/kademlia sybill protection (David, Ali). And special thanks to David Mazieres, for his ever brilliant ideas.
  830. \section{References TODO}
  831. %\bibliographystyle{abbrv}
  832. %\bibliography{gfs}
  833. %\balancecolumns
  834. %\subsection{References}
  835. \end{document}