ipfs-cap2pfs.tex 55 KB

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