ipfs-cap2pfs.tex 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862
  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 2)}
  12. \subtitle{}
  13. \numberofauthors{1}
  14. \author{
  15. % You can go ahead and credit any number of authors here,
  16. % e.g. one 'row of three' or two rows (consisting of one row of three
  17. % and a second row of one, two or three).
  18. %
  19. % The command \alignauthor (no curly braces needed) should
  20. % precede each author name, affiliation/snail-mail address and
  21. % e-mail address. Additionally, tag each line of
  22. % affiliation/address with \affaddr, and tag the
  23. % e-mail address with \email.
  24. %
  25. % 1st. author
  26. \alignauthor
  27. Juan Benet\\
  28. \email{juan@benet.ai}
  29. }
  30. \maketitle
  31. \begin{abstract}
  32. The InterPlanetary File System is a peer-to-peer distributed file system
  33. capable of sharing the same files with millions of nodes. IPFS combines a
  34. distributed hashtable, cryptographic techniques, merkle trees, content-
  35. addressable storage, bittorrent, and tag-based filesystems to build a single
  36. massive file system shared between peers. IPFS has no single point of failure,
  37. and nodes do not need to trust each other.
  38. \end{abstract}
  39. \section{Introduction}
  40. [Motivate IPFS. Introduce problems. Describe BitTorrent existing problems (
  41. multiple files. one swarm. sloppy dht implementation.) Describe version
  42. control efforts. Propose potential combinations of good ideas.]
  43. [Cite:
  44. CFS,
  45. Kademlia,
  46. Bittorrent,
  47. Chord,
  48. DHash,
  49. SFS,
  50. Ori,
  51. Coral]
  52. This paper introduces
  53. IPFS, a novel peer-to-peer version-controlled filesystem;
  54. and BitSwap, the novel peer-to-peer block exchange protocol serving IPFS.
  55. %The rest of the paper is organized as follows.
  56. %Section 2 describes the design of the filesystem.
  57. %Section 3 evaluates various facets of the system under benchmark and common
  58. %workloads.
  59. %Section 4 presents and evaluates a world-wide deployment of IPFS.
  60. %Section 5 describes existing and potential applications of IPFS.
  61. %Section 6 discusses related and future work.
  62. Notation Notes:
  63. (a) data structures are specified in Go syntax,
  64. (b) rpc protocols are specified in capnp interface,
  65. (c) object formats are specified in text with <fields>.
  66. \section{Design}
  67. \subsection{IPFS Nodes}
  68. IPFS is a distributed file system where all nodes are the same. They are
  69. identified by a \texttt{NodeId}, the cryptographic hash of a public-key
  70. (note that \textit{checksum} will henceforth refer specifically to crypographic
  71. hashes of an object). Nodes also store their public and private keys. Clients
  72. are free to instatiate a new node on every launch, though that means losing any
  73. accrued benefits. It is recommended that nodes remain the same.
  74. \begin{verbatim}
  75. type Checksum string
  76. type PublicKey string
  77. type PrivateKey string
  78. type NodeId Checksum
  79. type Node struct {
  80. nodeid NodeID
  81. pubkey PublicKey
  82. prikey PrivateKey
  83. }
  84. \end{verbatim}
  85. Together, the
  86. nodes store the IPFS files in local storage, and send files to each other.
  87. IPFS implements its features by combining several subsystems with many
  88. desirable properties:
  89. \begin{enumerate}
  90. \item A Coral-based \textbf{Distributed Sloppy Hash Table}\\
  91. (DSHT) to link and coordinate peer-to-peer nodes.
  92. Described in Section 2.2.
  93. \item A Bittorrent-like peer-to-peer \textbf{Block Exchange} (BE) distribute
  94. Blocks efficiently, and to incentivize replication.
  95. Described in Section 2.3.
  96. \item A Git-inspired \textbf{Object Model} (OM) to represent the filesystem.
  97. Described in Section 2.4.
  98. \item An SFS-based self-certifying name system.
  99. Described in Section 2.5.
  100. \end{enumerate}
  101. These subsystems are not independent. They are well integrated and leverage
  102. their blended properties. However, it is useful to describe them separately,
  103. building the system from the bottom up. Note that all IPFS nodes are identical,
  104. and run the same program.
  105. \subsection{Distributed Sloppy Hash Table}
  106. First, IPFS nodes implement a DSHT based on Kademlia and Coral to coordinate
  107. and identify which nodes can serve a particular block of data.
  108. \subsubsection{Kademlia DHT}
  109. Kademlia is a DHT that provides:
  110. \begin{enumerate}
  111. \item Efficient lookup through massive networks:
  112. queries on average contact $ \ceil{log_2 (n)} $ nodes.
  113. (e.g. $20$ hops for a network of $10000000$ nodes).
  114. \item Low coordination overhead: it optimizes the number of
  115. control messages it sends to other nodes.
  116. \item Resistance to various attacks, by preferring nodes who have been
  117. part of the DHT longer.
  118. \item wide useage in peer-to-peer applications, including \\
  119. Gnutella and Bittorrent, forming networks of over 100 million nodes.
  120. \end{enumerate}
  121. While some peer-to-peer filesystems store data blocks directly in DHTs,
  122. this ``wastes storage and bandwidth, as data must be stored at nodes where it
  123. is not needed''. Instead, IPFS stores a list of peers that can provide the data block.
  124. \subsubsection{Coral DSHT}
  125. Coral extends Kademlia in three particularly important ways:
  126. \begin{enumerate}
  127. \item Kademlia stores values in nodes whose ids are ``nearest'' (using
  128. XOR-distance) to the key. This does not take into account application
  129. data locality, ignores ``far'' nodes who may already have the data, and
  130. forces ``nearest'' nodes to store it, whether they need it or not.
  131. This wastes significant storage and bandwith. Instead, Coral stores
  132. addresses to peers who can provide the data blocks.
  133. \item Coral relaxes the DHT API from \texttt{get\_value(key)} to
  134. \texttt{get\_any\_values(key)} (the ``sloppy'' in DSHT).
  135. This still works since Coral users only need a single (working) peer,
  136. not the complete list. In return, Coral can distribute only subsets of
  137. the values to the ``nearest'' nodes, avoiding hot-spots (overloading
  138. \textit{all the nearest nodes} when a key becomes popular).
  139. \item Additionally, Coral organizes a hierarchy of separate DSHTs called
  140. \textit{clusters} depending on region and size. This enables nodes to
  141. query peers in their region first, ``finding nearby data without
  142. querying distant nodes'' and greatly reducing the latency of
  143. lookups.
  144. \end{enumerate}
  145. \subsubsection{IPFS DSHT}
  146. The IPFS DSHT supports four RPC calls:
  147. \subsection{Block Exchange - BitSwap Protocol}
  148. The exchange of data in IPFS happens by exchanging blocks with peers using a
  149. BitTorrent inspired protocol: BitSwap. Like BitTorrent, BitSwap peers are
  150. looking to acquire a set of blocks, and have blocks to offer in exchange.
  151. Unlike BitTorrent, BitSwap is not limited to the blocks in one torrent.
  152. BitSwap operates as a persistent marketplace where node can acquire the
  153. blocks they need, regardless of what files the blocks are part of. The
  154. blocks could come from completely unrelated files in the filesystem.
  155. But nodes come together to barter in the marketplace.
  156. While the notion of a barter system implies a virtual currency could be
  157. created, this would require a global ledger (blockchain) to track ownership
  158. and transfer of the currency. This will be explored in a future paper.
  159. Instead, BitSwap nodes have to provide direct value to each other
  160. in the form of blocks. This works fine when the distribution of blocks across
  161. nodes is such that they have the complements, what each other wants. This will
  162. seldom be the case. Instead, it is more likely that nodes must \textit{work}
  163. for their blocks. In the case that a node has nothing that its peers want (or
  164. nothing at all), it seeks the pieces its peers might want, with lower
  165. priority. This incentivizes nodes to cache and disseminate rare pieces, even
  166. if they are not interested in them directly.
  167. \subsubsection{BitSwap Credit}
  168. The protocol must also incentivize nodes to seed when they do not need
  169. anything in particular, as they might have the blocks others want. Thus,
  170. BitSwap nodes send blocks to their peers, optimistically expecting the debt to
  171. be repaid. But, leeches (free-loading nodes that never share) must be avoided. A simple credit-like system solves the problem:
  172. \begin{enumerate}
  173. \item Peers track their balance (in bytes verified) with other nodes.
  174. \item Peers send blocks to debtor peers probabilistically, according to
  175. a function that falls as debt increases.
  176. \end{enumerate}
  177. Note that if a peer decides not to send, the peer subsequently ignores the
  178. other node for an \texttt{ignore\_cooldown} timeout. This prevents senders
  179. from trying to game the probability by just causing more dice-rolls.
  180. (Default BitSwap is 10 seconds).
  181. \subsubsection{BitSwap Strategy}
  182. The differing strategies that BitSwap peers might employ have wildly different
  183. effects on the performance of the exchange as a whole. In BitTorrent,
  184. while a standard strategy is specified (tit-for-tat), a variety of others have
  185. been implemented, ranging from BitTyrant (sharing the least-possible),
  186. to BitThief (exploiting a vulnerability and never share), to PropShare
  187. (sharing proportionally). A range of strategies (good and malicious) could
  188. similarly be implemented by BitSwap peers. The choice of function, then, should
  189. aim to:
  190. \begin{enumerate}
  191. \item maximize the trade performance for the node, and the whole exchange
  192. \item prevent freeloaders from exploiting and degrading the exchange
  193. \item be effective with and resistant to other, unknown strategies
  194. \item be lenient to trusted peers
  195. \end{enumerate}
  196. The exploration of the space of such strategies is future work.
  197. One choice of function that works in practice is the sigmoid, scaled by a
  198. \textit{debt retio}:
  199. Let the \textit{debt ratio} $ r $ between a node and its peer be:
  200. \[ r = \dfrac{\texttt{bytes\_sent}}{\texttt{bytes\_recv} + 1} \]
  201. Given $r$, let the probability of sending to a debtor be:
  202. \[ P\Big( \; send \; | \; r \;\Big) = 1 - \dfrac{1}{1 + exp(6-3r)} \]
  203. \begin{figure}
  204. \centering
  205. \begin{tikzpicture}[domain=0:4]
  206. \draw[->] (-0,0) -- (4.2,0) node[right] {$r$};
  207. \draw[->] (0,-0) -- (0,1.20) node[above] {$P(\;send\;|\;r\;)$};
  208. %ticks
  209. \foreach \x in {0,...,4}
  210. \draw (\x,1pt) -- (\x,-3pt)
  211. node[anchor=north] {\x};
  212. \foreach \y in {1,...,1}
  213. \draw (1pt,\y) -- (-3pt,\y)
  214. node[anchor=east] {\y};
  215. \draw[color=red] plot[] function{1 - 1/(1+exp(6-3*x))};
  216. \end{tikzpicture}
  217. \caption{Probability of Sending as $r$ increases}
  218. \label{fig:psending-graph}
  219. \end{figure}
  220. As you can see in Figure \ref{fig:psending-graph}, this function drops off quickly as the nodes' \
  221. \textit{debt ratio} surpasses twice the established credit.
  222. The \textit{debt ratio} is a measure of trust:
  223. lenient to debts between nodes that have previously exchanged lots of data
  224. successfully, and merciless to unknown, untrusted nodes. This
  225. (a) provides resistance to attackers who would create lots of new nodes
  226. (sybill attacks),
  227. (b) protects previously successful trade relationships, even if one of the
  228. nodes is temporarily unable to provide value, and
  229. (c) eventually chokes relationships that have deteriorated until they
  230. improve.
  231. % \begin{center}
  232. % \begin{tabular}{ >{$}c<{$} >{$}c<{$}}
  233. % P(\;send\;|\quad r) \;\;\;\;\;& \\
  234. % \hline
  235. % \hline
  236. % P(\;send\;|\;0.0) =& 1.00 \\
  237. % P(\;send\;|\;0.5) =& 1.00 \\
  238. % P(\;send\;|\;1.0) =& 0.98 \\
  239. % P(\;send\;|\;1.5) =& 0.92 \\
  240. % P(\;send\;|\;2.0) =& 0.73 \\
  241. % P(\;send\;|\;2.5) =& 0.38 \\
  242. % P(\;send\;|\;3.0) =& 0.12 \\
  243. % P(\;send\;|\;3.5) =& 0.03 \\
  244. % P(\;send\;|\;4.0) =& 0.01 \\
  245. % P(\;send\;|\;4.5) =& 0.00 \\
  246. % \end{tabular}
  247. % \end{center}
  248. % TODO look into computing share of the bandwidth, as described in propshare.
  249. \subsubsection{BitSwap Ledger}
  250. BitSwap nodes keep ledgers accounting the transfers with other nodes.
  251. A ledger snapshot contains a pointer to the previous snapshot (its checksum),
  252. forming a hash-chain. This allows nodes to keep track of history, and to avoid
  253. tampering. When activating a connection, BitSwap nodes exchange their ledger
  254. information.
  255. If it does not match exactly, the ledger is reinitialized from scratch,
  256. loosing the accrued credit or debt. It is possible for malicious nodes to
  257. purposefully ``loose'' the Ledger, hoping the erase debts. It is unlikely that
  258. nodes will have accrued enough debt to warrant also losing the accrued trust,
  259. however the partner node is free to count it as \textit{misconduct} (discussed
  260. later).
  261. \begin{verbatim}
  262. type Ledger struct {
  263. parent Checksum
  264. owner NodeId
  265. partner NodeId
  266. bytes_sent int
  267. bytes_recv int
  268. timestamp Timestamp
  269. }
  270. \end{verbatim}
  271. Nodes are free to keep the ledger history, though it is not necessary for
  272. correct operation. Only the current ledger entries are useful. Nodes are
  273. also free to garbage collect ledgers as necessary, starting with the less
  274. useful ledgers: the old (peers may not exist anymore) and small.
  275. \subsubsection{BitSwap Specification}
  276. BitSwap nodes follow a simple protocol.
  277. \begin{verbatim}
  278. # Additional state kept:
  279. type BitSwap struct {
  280. ledgers map[NodeId]Ledger
  281. // Ledgers known to this node, inc inactive
  282. active map[NodeId]Peer
  283. // currently open connections to other nodes
  284. need_list []Checksum
  285. // checksums of blocks this node needs
  286. have_list []Checksum
  287. // checksums of blocks this node has
  288. }
  289. type Peer struct {
  290. nodeid NodeId
  291. ledger Ledger
  292. // Ledger between the node and this peer
  293. last_seen Timestamp
  294. // timestamp of last received message
  295. want_list []Checksum
  296. // checksums of all blocks wanted by peer
  297. // includes blocks wanted by peer's peers
  298. }
  299. # Protocol interface:
  300. interface Peer {
  301. open (nodeid :NodeId, ledger :Ledger);
  302. send_want_list (want_list :WantList);
  303. send_block (block :Block) -> (complete :Bool);
  304. close (final :Bool);
  305. }
  306. \end{verbatim}
  307. Sketch of the lifetime of a peer connection:
  308. \begin{enumerate}
  309. \item Open: peers send \texttt{ledgers} until they agree.
  310. \item Sending: peers exchange \texttt{want\_lists} and \texttt{blocks}.
  311. \item Close: peers deactivate a connection.
  312. \item Ignored: (special) a peer is ignored (for the duration of a timeout)
  313. if a node's strategy avoids sending
  314. \end{enumerate}
  315. \paragraph{Peer.open(NodeId, Ledger)}
  316. When connecting, a node initializes a connection with a
  317. \texttt{Ledger}, either stored from a connection in the past or a new one
  318. zeroed out. Then, sends an Open message with the \texttt{Ledger} to the peer.
  319. Upon receiving an \texttt{Open} message, a peer chooses whether to activate
  320. the connection. If -- acording to the receiver's \texttt{Ledger} -- the sender
  321. is not a trusted agent (transmission below zero, or large outstanding debt) the
  322. receiver may opt to ignore the request. This should be done probabilistically
  323. with an \texttt{ignore\_cooldown} timeout, as to allow errors to be corrected
  324. and attackers to be thwarted.
  325. If activating the connection, the receiver initializes a Peer object, with the
  326. local version of the \texttt{Ledger}, and setting the \texttt{last\_seen}
  327. timestamp). Then, it compares the received
  328. \texttt{Ledger} with its own. If they match exactly, the connections have
  329. opened. If they do not match, the peer creates a new zeroed out
  330. \texttt{Ledger}, and sends it.
  331. \paragraph{Peer.send\_want\_list(WantList)}
  332. While the connection is open, nodes advertise their
  333. \texttt{want\_list} to all connected peers. This is done (a) upon opening the
  334. connection, (b) after a randomized periodic timeout, (c) after a change in
  335. the \texttt{want\_list} and (d) after receiving a new block.
  336. Upon receiving a \texttt{want\_list}, a node stores it. Then, it checks whether
  337. it has any of the wanted blocks. If so, it sends them according to the
  338. \textit{BitSwap Strategy} above.
  339. \paragraph{Peer.send\_block(Block)}
  340. Sending a block is straightforward. The node simply transmits the block of
  341. data. Upon receiving all the data, the receiver computes the Checksum to
  342. verify it matches the expected one, and returns confirmation.
  343. Upon finalizing the correct transmission of a block, the receiver moves the
  344. block from \texttt{need\_list} to \texttt{have\_list}, and both the receiver
  345. and sender update their ledgers to reflect the additional bytes transmitted.
  346. If a transmission verfication fails, the receiver instead \textit{penalizes}
  347. the sender. Both receiver and sender should update their ledgers accordingly,
  348. though the sender is either malfunctioning or attacking the receiver. Note that
  349. BitSwap expects to operate on a reliable transmission channel, so data errors
  350. -- which could lead to incorrect penalization of an honest sender -- are
  351. expected to be caught before the data is given to BitSwap. IPFS uses the uTP
  352. protocol.
  353. \paragraph{Peer.close(Bool)}
  354. The \texttt{final} parameter to \texttt{close} signals whether the intention
  355. to tear down the connection is the sender's or not. If false, the receiver
  356. may opt to re-open the connection immediatelty. This avoids premature
  357. closes.
  358. A peer connection should be closed under two conditions:
  359. \begin{itemize}
  360. \item a \texttt{silence\_wait} timeout has expired without receiving any
  361. messages from the peer (default BitSwap uses 30 seconds).
  362. In this case, the node issues a \texttt{Peer.close(false)} message.
  363. \item the node is exiting and BitSwap is being shut down.
  364. In this case, the node issues a \texttt{Peer.close(true)} message.
  365. \end{itemize}
  366. After a \texttt{close} message, both receiver and sender tear down the
  367. connection, clearing any state stored. The \texttt{Ledger} may be stored for
  368. the future, if it is useful to do so.
  369. \paragraph{Notes}
  370. \begin{itemize}
  371. \item Non-\texttt{open} messages on an inactive connection should be ignored.
  372. In case of a \texttt{send\_block} message, the receiver may check
  373. the block to see if it is needed and correct, and if so, use it.
  374. Regardless, all such out-of-order messages trigger a
  375. \texttt{close(false)} message from the receiver, to force
  376. re-initialization of the connection.
  377. \end{itemize}
  378. % TODO: Rate Limiting / Node Silencing
  379. \subsection{Object Model}
  380. The DHT and BitSwap allow IPFS to form a massive peer-to-peer system for storing
  381. and distributing blocks quickly and robustly to users.
  382. IPFS builds a filesystem out of this efficient block distribution system,
  383. constructing files and directories out of blocks.
  384. Files in IPFS are represented as a collection of inter-related objects, like in
  385. the version control system Git. Each object is addressed by the cryptographic
  386. hash of its contents (\texttt{Checksum}). The file objects are:
  387. \begin{enumerate}
  388. \item \texttt{block}: a variable-size block of data.
  389. \item \texttt{list}: a collection of blocks or other lists.
  390. \item \texttt{tree}: a collection of blocks, lists, or other trees.
  391. \item \texttt{commit}: a snapshot in the version history of a tree.
  392. \end{enumerate}
  393. We hoped to use the Git object formats exactly, but had to depart to introduce
  394. certain features useful in a distributed filesystem, for example fast size
  395. lookups (aggregate byte sizes have been added to objects), large file
  396. deduplication and versioning (adding a \texttt{list} object), and more.
  397. However, our objects are perfectly compatible with Git and
  398. conversion between the two does not lose any information.
  399. Notes:
  400. \begin{itemize}
  401. \item \texttt{varint} is a variable size int, as in protocol-buffers.
  402. \item objects are serialized using \texttt{capnp}.
  403. \end{itemize}
  404. \subsubsection{Block Object}
  405. The \texttt{Block} object contains an addressable unit of data, and
  406. represents a file.
  407. IPFS Blocks are like Git blobs or filesystem data blocks. They store the
  408. users' data. (The name \textit{block} is preferred over \textit{blob}, as the
  409. Git-inspired view of a \textit{blob} as a \textit{file} breaks down in IPFS.
  410. IPFS files can be represented by both \texttt{lists} and \texttt{blocks}.)
  411. Format:
  412. \begin{verbatim}
  413. block <size>
  414. <block data bytes>
  415. ...
  416. \end{verbatim}
  417. \subsubsection{List Object}
  418. The \texttt{List} object represents a large or de-duplicated file made up of
  419. several IPFS \texttt{Blocks} concatenated together. \texttt{Lists} contain
  420. an ordered sequence of \texttt{block} or \texttt{list} objects.
  421. In a sense, the IPFS \texttt{List} functions like a filesystem file with
  422. 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. Cycles are not possible (enforced by hash addessing).
  423. Format:
  424. \begin{verbatim}
  425. list <num objects> <size varint>
  426. <list or block> <checksum> <size varint>
  427. <list or block> <checksum> <size varint>
  428. ...
  429. \end{verbatim}
  430. \subsubsection{Tree Object}
  431. The \texttt{tree} object in IPFS is similar to Git trees: it represents a
  432. directory, a list of checksums and names. The checksums reference \texttt{blob}
  433. or other \texttt{tree} objects. Note that traditional path naming
  434. is implemented entirely by the \texttt{tree} objects. \texttt{Blocks} and
  435. \texttt{lists} are only addressed by their \texttt{checksums}.
  436. Format:
  437. \begin{verbatim}
  438. tree <num objects> <size varint>
  439. <tree or list or block> <checksum> <size varint> <name>
  440. <tree or list or block> <checksum> <size varint> <name>
  441. ...
  442. \end{verbatim}
  443. \subsubsection{Commit Object}
  444. The \texttt{commit} object in IPFS is similar to Git's. It represents a
  445. snapshot in the version history of a \texttt{tree}. Note that user
  446. addresses are NodeIds (the hash of the public key).
  447. \begin{verbatim}
  448. commit <size varint>
  449. parent <commit checksum>
  450. tree <tree checksum>
  451. author <author public key> <ISO UTC date>
  452. committer <committer public key> <ISO UTC date>
  453. <commit message>
  454. \end{verbatim}
  455. \subsubsection{Version control}
  456. The \texttt{commit} object represents a particular snapshot in the version
  457. history of a tree. Comparing the \texttt{trees} and children objects of two
  458. different commits reveals the differences between two versions of the
  459. filesystem. As long as a single \texttt{commit} and all the children objects
  460. it references are accessible, all preceding versions are retrievable and the
  461. full history of the filesystem changes can be accessed. This is a consequence
  462. of the \texttt{Git} object model and the graph it forms.
  463. The full power of the \texttt{Git} version control tools is available to IPFS
  464. users. The object model is compatible (though not the same). The standard
  465. \texttt{Git} tools can be used on the \texttt{IPFS} object graph after a
  466. conversion. Additionally, a fork of the tools is under development that will
  467. allow users to use them directly without conversion.
  468. \subsubsection{Object-level Cryptoraphy}
  469. IPFS is equipped to handle object-level cryptographic operations. Any additional
  470. bytes are appended to the bottom of the object. This changes the object's hash
  471. (defining a different object, as it should). IPFS exposes an API that
  472. automatically verifies signatures or decrypts data.
  473. \begin{itemize}
  474. \item \texttt{Signing}. Signature appended.
  475. \item \texttt{Encryption}. Optional recipient's public key appended.
  476. \end{itemize}
  477. \subsubsection{Merkle Trees}
  478. The object model in IPFS forms a \textit{Merkle Tree}, which provides IPFS with
  479. useful properties:
  480. \begin{enumerate}
  481. \item \textbf{Content Addressing:} all content is uniquely identified by its
  482. \texttt{checksum}, \textbf{including child checksums}. This means a
  483. particular \texttt{tree} object points to \textit{specific} children.
  484. Committing changes to a \texttt{block} also commits changes to the
  485. containing \texttt{tree}.
  486. \item \textbf{Tamper resistance:} all content is verified with its Checksum.
  487. If data is tampered with, before being delivered, the client
  488. detects and discards it.
  489. \item \textbf{Deduplication:} all objects who hold the exact same content
  490. are the same, and only stored once. This is particularly useful with
  491. parent objects, such as lists, trees, and commits.
  492. \end{enumerate}
  493. \subsection{The Filesystem}
  494. \subsubsection{Filesystem Paths}
  495. IPFS exposes a slash-delimited path-based API. Paths work the same as in any
  496. traditional UNIX filesystem. Path subcomponents have different meanings per
  497. object:
  498. \begin{center}
  499. \begin{tabular}{ll}
  500. \texttt{object} & subcomponent meaning \\
  501. \hline
  502. \hline
  503. \texttt{block} & N/A (no children) \\
  504. \texttt{list} & integer index \\
  505. \texttt{tree} & string name \\
  506. \texttt{commit} & string name (in tree) \\
  507. \end{tabular}
  508. \end{center}
  509. \begin{figure}
  510. \centering
  511. \begin{tikzpicture}[->,>=stealth',auto,thick,
  512. minimum height=2em,minimum width=5em]
  513. \tikzstyle{ghost}=[rectangle,rounded corners=.8ex];
  514. \tikzstyle{block}=[rectangle,draw,fill=blue!20,rounded corners=.8ex];
  515. \tikzstyle{list}=[rectangle,draw,fill=cyan!20,rounded corners=.8ex];
  516. \tikzstyle{tree}=[rectangle,draw,fill=green!20,rounded corners=.8ex];
  517. \tikzstyle{commit}=[rectangle,draw,fill=magenta!20,rounded corners=.8ex];
  518. \tikzstyle{every path}=[draw]
  519. \node[commit] (ccc111) {ccc111};
  520. \node[tree] (ttt111) [below=3em of ccc111] {ttt111};
  521. \node[tree] (ttt222) [below left=3em and 3em of ttt111] {ttt222};
  522. \node[tree] (ttt333) [below=3em of ttt111] {ttt333};
  523. \node[ghost] (ghost1) [below right=3em and 3em of ttt111] {};
  524. \node[list] (lll111) [below=3em of ttt333] {lll111};
  525. \node[block] (bbb111) [below=3em of ttt222] {bbb111};
  526. \node[block] (bbb222) [below right=3em and 3em of ttt333] {bbb222};
  527. \node[block] (bbb333) [below left=3em and 3em of lll111] {bbb333};
  528. \node[block] (bbb444) [below=3em of lll111] {bbb444};
  529. \node[block] (bbb555) [below right=3em and 3em of lll111] {bbb555};
  530. \path[every node/.style={font=\sffamily\small}]
  531. (ccc111) edge[out=-90,in=90] (ttt111)
  532. (ttt111) edge[out=-90,in=90] (ttt222)
  533. edge[out=-90,in=90] (ttt333)
  534. to [out=-90,in=90] (ghost1)
  535. to [out=-90,in=90] (bbb222)
  536. (ttt222) edge[out=-90,in=90] (bbb111)
  537. (ttt333) edge[out=-90,in=90] (lll111)
  538. edge[out=-90,in=90] (bbb222)
  539. (lll111) edge[out=-90,in=90] (bbb333)
  540. edge[out=-90,in=90] (bbb444)
  541. edge[out=-90,in=90] (bbb555)
  542. ;
  543. \end{tikzpicture}
  544. \caption{Sample Object Graph} \label{fig:sample-object-graph}
  545. \begin{verbatim}
  546. # ccc111 contents
  547. commit 313
  548. tree ttt111
  549. author <author public key> <ISO UTC date>
  550. committer <committer public key> <ISO UTC date>
  551. # ttt111 contents
  552. tree 3 250
  553. tree ttt222 46 ttt222-name
  554. tree ttt333 166 ttt333-name
  555. block bbb222 11 bbb222-name
  556. # ttt222 contents
  557. tree 1 10
  558. block bbb111 10 bbb111-name
  559. # ttt333 contents
  560. tree 2 104
  561. list lll111 93 lll111-name
  562. block bbb222 11 bbb222-eman
  563. # lll111 contents
  564. list 3 39
  565. block bbb333 12
  566. block bbb444 13
  567. block bbb555 14
  568. # bbb111 contents # block bbb222 contents
  569. block 1 block 2
  570. 1 22
  571. # bbb333 contents # block bbb444 contents
  572. block 3 block 4
  573. 333 4444
  574. # bbb555 contents
  575. block 5
  576. 55555
  577. \end{verbatim}
  578. \caption{Sample Objects} \label{fig:sample-objects}
  579. \end{figure}
  580. For example, given the sample objects in Figures \ref{fig:sample-object-graph} and \ref{fig:sample-objects}:
  581. \begin{verbatim}
  582. # to access tree ttt333:
  583. ccc111/ttt333-name
  584. # to access block bbb222:
  585. ccc111/bbb222-name
  586. ccc111/ttt333-name/bbb222-eman
  587. # to access list lll111:
  588. ccc111/ttt333-name/lll111-name
  589. # to access block bbb555:
  590. ccc111/ttt333-name/lll111-name/2
  591. \end{verbatim}
  592. Note that:
  593. \begin{itemize}
  594. \item[(a)] blocks have no children \\
  595. \texttt{.../<block>/<child>} is impossible
  596. \item[(b)] commits implicitly access their trees \\
  597. \texttt{.../<commit>/name}
  598. looks up \texttt{"name"} in \texttt{<commit>}'s \texttt{<tree>}
  599. \item[(c)] \texttt{list} children are accessed by their index \\
  600. \texttt{.../<list>/4} looks up the fifth block.
  601. \end{itemize}
  602. \paragraph{Path Lookup Performance}
  603. Path-based access traverses the object graph. Retrieving
  604. each object requires potentially looking up its key in the DHT,
  605. connecting to peers, and retrieving its blocks. This is considerable
  606. overhead, particularly when looking up paths with many components.
  607. This is mitigated by:
  608. \begin{itemize}
  609. \item \textbf{tree caching}: since all objects are hash-addressed, they
  610. can be cached indefinitely. Additionally, \texttt{trees} tend to be
  611. small in size so IPFS prioritizes caching them over \texttt{blocks}.
  612. \item \textbf{flattened trees}: for any given \texttt{tree}, a special
  613. \texttt{flattened tree} can be constructed to list all objects
  614. reachable from the \texttt{tree}. Figure \ref{flattened-ttt111} shows
  615. an example of a flattened tree. While IPFS does not construct flattened
  616. trees by default, it provides a function for users. For example,
  617. \end{itemize}
  618. \begin{figure}
  619. \begin{verbatim}
  620. tree 5 250
  621. tree ttt222 46 ttt222-name
  622. block bbb111 10 ttt222-name/bbb111-name
  623. tree ttt333 166 ttt333-name
  624. list lll111 93 ttt222-name/lll111-name
  625. block bbb222 11 ttt333-name/bbb222-eman
  626. block bbb222 11 bbb222-name
  627. \end{verbatim}
  628. \caption{Flattened Tree for \texttt{ttt111}} \label{fig:flattened-ttt111}
  629. \end{figure}
  630. \subsubsection{Publishing Objects}
  631. IPFS is globally distributed. It is designed to allow the files of millions
  632. of users to coexist together. The \textbf{DHT} with content-hash addressing
  633. allows publishing objects in a fair, secure, and entirely distributed way.
  634. Anyone can publish an object by simply adding its key to the DHT, adding
  635. themselves as a peer, and giving other users the object's hash.
  636. Additionally, the IPFS root directory supports special functionality to
  637. allow namespacing and naming objects in a fair, secure, and distributed
  638. manner.
  639. \begin{itemize}
  640. \item[(a)] All objects are accessible by their hash. Thus, users can
  641. always reference an object (and its children) using
  642. \texttt{/<object\_hash>}.
  643. \item[(b)] \texttt{/<node\_id>} provides a self-certifying filesystem
  644. for user \texttt{node\_id}. If it exists, the object returned is a
  645. special \texttt{tree} signed by \texttt{node\_id}'s private key. Thus,
  646. a user can publish a \texttt{tree} or \texttt{commit} under their
  647. name, and others can verify it by checking the signature matches.
  648. \item[(c)] If \texttt{/<domain>} is a valid domain name, IPFS
  649. looks up key \texttt{gfs} in its \texttt{DNS TXT} record. IPFS
  650. interprets the value as either an object hash or another IPFS path:
  651. \begin{verbatim}
  652. # this DNS TXT record
  653. fs.benet.ai. TXT "gfs=/aabbccddeeffgg ..."
  654. # behaves as symlink
  655. ln -s /aabbccddeeffgg /fs.benet.ai
  656. \end{verbatim}
  657. \end{itemize}
  658. \subsection{Local Objects}
  659. IPFS clients require some \textit{local storage}, an external system
  660. on which to store and retrieve local raw data for the objects IPFS manages.
  661. The type of storage depends on the node's use case.
  662. In most cases, this is simply a portion of disk space (either managed by
  663. the native filesystem, or directly by the IPFS client). In others, non-
  664. persistent caches for example, this storage is just a portion of RAM.
  665. Ultimately, all blocks available in IPFS are in some node's
  666. \textit{local storage}. And when nodes open files with IPFS, the objects are
  667. downloaded and stored locally, at least temporarily. This provides
  668. fast lookup for some configurable amount of time thereafter.
  669. \subsubsection{Object Pinning}
  670. Nodes who wish to ensure the survival of particular objects can do so by
  671. \texttt{pinning} the objects. This ensures the objects are kept in the node's
  672. \textit{local storage}. Pinning can be done recursively, to pin down all
  673. descendent objects as well. For example, recursively pinning a \texttt{tree}
  674. or \texttt{commit} ensures \textit{all} objects pointed to are stored locally
  675. too. This is particularly useful for nodes wishing to keep all their own files.
  676. %\section{Acknowledgments}
  677. %\bibliographystyle{abbrv}
  678. %\bibliography{gfs}
  679. %\balancecolumns
  680. %\subsection{References}
  681. \end{document}