summaryrefslogtreecommitdiffstats
path: root/doc/paper/main.tex
blob: eeb0b15381989d21c5de2f0dffda744c8f347a8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
\documentclass[conference]{IEEEtran}
\IEEEoverridecommandlockouts
% The preceding line is only needed to identify funding in the first footnote. If that is unneeded, please comment it out.
\usepackage{cite}
\usepackage{amsmath,amssymb,amsfonts}
\usepackage{algorithmic}
\usepackage{graphicx}
\usepackage{textcomp}
\usepackage{xcolor}
\usepackage{url}
\usepackage{listings}
\def\BibTeX{{\rm B\kern-.05em{\sc i\kern-.025em b}\kern-.08em
    T\kern-.1667em\lower.7ex\hbox{E}\kern-.125emX}}

\colorlet{punct}{red!60!black}
\definecolor{background}{HTML}{EEEEEE}
\definecolor{delim}{RGB}{20,105,176}
\colorlet{numb}{magenta!60!black}

\lstdefinelanguage{json}{
    basicstyle=\normalfont\ttfamily,
    numbers=left,
    numberstyle=\scriptsize,
    stepnumber=1,
    numbersep=8pt,
    showstringspaces=false,
    breaklines=true,
    frame=lines,
    backgroundcolor=\color{background},
    literate=
     *{0}{{{\color{numb}0}}}{1}
      {1}{{{\color{numb}1}}}{1}
      {2}{{{\color{numb}2}}}{1}
      {3}{{{\color{numb}3}}}{1}
      {4}{{{\color{numb}4}}}{1}
      {5}{{{\color{numb}5}}}{1}
      {6}{{{\color{numb}6}}}{1}
      {7}{{{\color{numb}7}}}{1}
      {8}{{{\color{numb}8}}}{1}
      {9}{{{\color{numb}9}}}{1}
      {:}{{{\color{punct}{:}}}}{1}
      {,}{{{\color{punct}{,}}}}{1}
      {\{}{{{\color{delim}{\{}}}}{1}
      {\}}{{{\color{delim}{\}}}}}{1}
      {[}{{{\color{delim}{[}}}}{1}
      {]}{{{\color{delim}{]}}}}{1},
}

\begin{document}

\title{How to implement a distributed social network using IPFS}

\author{\IEEEauthorblockN{Matthias Beyer}
\IEEEauthorblockA{Tübingen, Germany \\
mail@beyermatthias.de}
}

\maketitle

\begin{abstract}
    This document describes how one can implement a distributed social network
    or publishing platform using the IPFS\cite{ipfsbennet}, \cite{ipfsio} and related technologies.
    It proposes a block data format for a blockchain and conceptual ideas for
    implementing "profiles" upon this data format.
    It also describes profile discovery algorithms and lays out problems with
    trust and how they could be approached.
    Finally, it proposes an architecture how a client for such a social network
    could be implemented, focusing on reusability of components to be able to
    make them available to a broader audience, for example for federated caching
    or even embedded usage.
\end{abstract}

\begin{IEEEkeywords}
\end{IEEEkeywords}

\section{Introduction}
% Intro about the general idea

\section{Data types}
% Intro about the data types required for building the blockchain

The implementation of an IPFS-based social network would be based on a DAG of
blocks of data.
Each DAG would resemble a "profile" in the social network.
A "profile", though, would not necessarily be bound to a person, but would
represent a unique identity.
Embedded ("smart") devices or automated tools (bots) posting to a profile without
human interaction could be possible and are imaginable.

Because distribution and availability is curcial, two "layers" of blocks should
be considered:

\begin{itemize}
    \item A more general "block", implementing nothing more than the chain and
        some minimal meta data, e.g. a format version and a, and a pointer to
        the actual "metadata block"
    \item A "metadata block", holding all the information about the profile,
        the content and other valuable metadata, such as timestamps, a mimetype
        of the content linked and, of course, a link to the actual content
\end{itemize}

The third data type required for implementing a block would be holding the data
itself.
Thus, it would be only a stream of bytes - which would be added to IPFS
directly.

In the following chapters, details of the individual types are layed out.
For simplicity, JSON is used for examples of objects of the layed out
types.


\subsection{Block}
% What a "block" is used for and what data it holds
% - metadata pointer

As described above, the "Block" data type is used for building the blockchain.
Because this kind of object must be easy to distribute to ensure high
availability of blocks of a single chain, this type must be small in size.
Thus, it should only hold the following elements:

\begin{itemize}
    \item A version number, which describes the version of the format used
    \item A list of pointers to parent blocks
    \item A pointer to a metadata Block
\end{itemize}

A block may hold more than one pointer to a parent block to make merges possible
on the block-level.

\begin{lstlisting}[language=json,caption={Example of a Block},label=jsonblock]
{
"v": 1,
"parents": ["Qmabc...", "Qmdef..."],
"content": "Qmghi..."
}
\end{lstlisting}

As shown in \ref{jsonblock}, minimal data is held in the "Block" object.
Because of the small size, replication of block objects is cheap and every
modern end-user device can easily hold millions of blocks.

If $S_{parents}(b)$ is the size of the list of parents of a block $b$,
and
$S_{base}$ is the size of a block without any parents,
the required disk space can be described by

\begin{equation}
    S_{sum} = n * S_{base} + \sum_{i=1}^{n} S_{parents}(b_i)
\end{equation}

where $b_i$ is a block and $n$ is the number of blocks.
Depending on the overhead of the encoding technology used, the size of an
individual block is in the lower bytes range.
E.G. assuming a size of 46 bytes for a IPFS hash, a block with only one parent fits
into 100 bytes, even if encoded as JSON. That means that one Gigabyte of storage
could hold more than 10 Million blocks.


\subsection{Metadata-Block}
% What a "metadata-block" is used for and what data it holds
% - mime
% - timestamp
% - IPNS List
% - content
%   - content pointer
%   - references to other blocks

A "metadata" block would hold the actual profile post data, although not the
actual content of the post to the profile.
As its name tells, it holds the metadata of the post, that is

\begin{itemize}
    \item A format version number
    \item Date and Time when the block was created
    \item A list of public keys that post to the profile
    \item a sub-object that is either
        \begin{itemize}
            \item Empty

            \item A "post" object, holding
                \begin{itemize}
                    \item A pointer to the content "blob" (see \ref{sec:datatypecontent})
                    \item A mimetype for the content
                    \item An (optional) "In-Reply-To" reference
                    \item A (optional) list of references to other (metadata) blocks
                    \item possibly more (to be defined)
                \end{itemize}

            \item A "profile" object, holding for example
                \begin{itemize}
                    \item a Profile name
                    \item a Profile picture
                    \item a Profile description/text
                    \item possibly more (to be defined)
                \end{itemize}

            \item A ref object, holding a reference to another block or metadata
                block that is referenced (see \ref{sec:postreplies})

            \item or something else (to be defined)
        \end{itemize}
\end{itemize}

Because of its size, this object type might not be replicated as much as the
"block" object type.


\subsection{Content}\label{sec:datatypecontent}
% What a "content" object is (and what it is not)

\subsection{Data format}
% Short note about possible data formats



\section{Profiles}
% How profiles are implemented on top of the data types

\subsection{Multi-device support}
% How multi-device support for a profile is implemented using IPNS

\subsection{Device "Authorization"}
% How devices are authorized to post to a profile

\subsection{Device "De-authorization"}
% How devices are de-authorized from posting to a profile


\section{Posts}
% what a post is

\subsection{Post types}
% What kinds of posts exist

\subsection{Replies}\label{sec:postreplies}
% How comments on posts could be implemented


\section{Traversing Chains and profile discovery}
% What needs to be done for traversing a block chain and discover a profile

\subsection{Profile fetching}
% How profiles are fetched

\subsection{Trusting a chain}
% How a chain can be trusted



\section{Possibilities for Optimization}
% Possibilities how the block chain model could be optimized


\section{Implementation}
% Intro for architecture description

\subsection{Architecture}
% Description of the general architecture

\subsection{Backend}
% Interfacing with IPFS and providing an abstraction to
% interact with "blocks" and "profiles", using either
% - a REST interface to be run as a (possibly network-local) server, or
% - a library API for embedding into a "fat" application


\subsection{Middleware}
% Middleware library, providing
% - interfaces for working with a backend (either REST or library)
% - public-private-key crypto interfaces for IPNS name publishing

% Itself providing either a REST interface via a webserver or
% a library API for embedding into a "fat" application


\subsection{Frontend}
% Frontend implementation, abstract over the middleware implementation, which
% needs to be trusted.
%
% A frontend impl could be started on a embedded device where no public-private
% key crypto is possible, so the middleware runs on a better-suited device
%
% The frontend could also embedd the middleware and implement a desktop client
% using a CLI, TUI, GUI or WUI.


\section{Future work}
% What could be implemented on top of this idea

\section*{Acknowledgment}

\section*{References}

\begin{thebibliography}{00}
\bibitem{ipfsbennet} J. Bennet, IPFS - Content Addressed, Versioned, P2P File System(DRAFT 3)
\bibitem{ipfsio} \url{https://docs.ipfs.io/}
\end{thebibliography}
\end{document}