<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% EPFL report package, main thesis file
% Goal: provide formatting for theses and project reports
% Author: Mathias Payer &lt;mathias.payer@epfl.ch&gt;
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\documentclass[a4paper,11pt,oneside]{report}
% Options: MScThesis, BScThesis, MScProject, BScProject
\usepackage[BScProject,lablogo]{EPFLreport}
\usepackage{xspace}
\usepackage{listings}
\usepackage{caption}
\usepackage{subcaption}

\renewcommand{\lstlistingname}{Configuration}
\lstset{
  basicstyle=\footnotesize\ttfamily,
  columns=flexible,
  literate={-}{-}1,
  breaklines=true,
}
\lstset{captionpos=b}
\AtBeginDocument{\def\chapterautorefname{Chapter}}
\AtBeginDocument{\def\sectionautorefname{Section}}%
\AtBeginDocument{\def\subsectionautorefname{Subsection}}%
%

\title{Smallworld: Gossiping with Raspberry Pis Locally}
\author{Paulette Vazquez and Guilhem Niot}
\supervisor{Dr. Erick Lavoie}
\adviser{Professor Anne-Marie Kermarrec}

\newcommand{\sysname}{FooSystem\xspace}

\begin{document}
\maketitle

\maketoc


\chapter{Another application: Dat Protocol}

Dat Protocol is a peer-to-peer protocol that allows sharing files in a distributed network.

It differs from BitTorrent in that contents can be updated by their author.


\section{Installation}

The installation of Dat is quite straightforward. The commands in \ref{cmd:dat_install} are used to install dat-cli.

It must be installed on both the emitter and the receiver devices.

\begin{figure}
  \begin{lstlisting}[label=cmd:dat_install, caption=Installing dat-cli]
    wget -qO- https://raw.githubusercontent.com/datproject/dat/master/download.sh | bash
    
    # or
    npm install -g dat-cli
  \end{lstlisting}
\end{figure}

\section{Using dat}

The dat-cli command utility allows to simply interact with Dat files.

It is possible to create a shared folder using \emph{dat share} in the folder to share. This command will give a dat url starting with \emph{dat://} that can be used to retrieve the files on other clients.

A set of useful commands:
\begin{itemize}
  \item \emph{dat share}, to share a folder (starts a daemon that waits for incoming connexions)
  \item \emph{dat sync}, tries to retrieve newer version of the files, and share the files for incoming connexions
  \item \emph{dat clone &lt;url&gt; &lt;folder&gt;}, retrieves files from a dat url
  \item \emph{dat pull}, tries to retrieve a newer version of the files
\end{itemize}

\subsection{Real time synchronization with dat-share}

Dat does not directly provide a daemon to run in background and automatically synchronize folders for you. \\

A tool to do just that is \emph{dat-store}. It provides a service that can be run in background, can be remotely controlled, and does all the work for you.

It should be installed on both the client and the Raspberry Pi using 
\begin{lstlisting}
  npm install -g dat-store
\end{lstlisting}

\textbf{Note:} In case you have permission errors, you should NOT try running it with sudo. The correct solution is to fix the permissions of your npm installation. See the \href{https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally#manually-change-npms-default-directory}{manual guide}.

You should then configure a systemd service to run the store in background. The configuration on the user's device is done according to figure \ref{cmd:dat_store_systemd_user}. The configuration on the Raspberry Pi is achieved following figure \ref{cmd:dat_store_systemd_rasp}.

\begin{figure}
  \begin{lstlisting}[label=cmd:dat_store_systemd_user, caption=Configure dat-store systemd service on the user device]
    
# This will create the service file.
sudo cat &lt;&lt; EOF | sudo tee /etc/systemd/system/dat-store.service &gt; /dev/null
[Unit]
Description=Dat storage provider, keeps dats alive in the background.

[Service]
Type=simple
# Check that dat-store is present at this location
# If it's not, replace the path with its location
ExecStart=$(which dat-store) run-service
Restart=always

[Install]
WantedBy=multi-user.target
EOF

sudo chmod 644 /etc/systemd/system/dat-store.service

sudo systemctl daemon-reload
sudo systemctl enable dat-store
sudo systemctl start dat-store

sudo systemctl status dat-store
  \end{lstlisting}
\end{figure}

\begin{figure}
  \begin{lstlisting}[label=cmd:dat_store_systemd_rasp, caption=Configure dat-store systemd service on the raspberry pi]
    
# This will create the service file.
sudo cat &lt;&lt; EOF | sudo tee /etc/systemd/system/dat-store.service &gt; /dev/null
[Unit]
Description=Dat storage provider exposed to the internet (for the raspberry pi).

[Service]
Type=simple
# Check that dat-store is present at this location
# If it's not, replace the path with its location
ExecStart=$(which dat-store) run-service --expose-to-internet
Restart=always

[Install]
WantedBy=multi-user.target
EOF

sudo chmod 644 /etc/systemd/system/dat-store.service

sudo systemctl daemon-reload
sudo systemctl enable dat-store
sudo systemctl start dat-store

sudo systemctl status dat-store
  \end{lstlisting}
\end{figure}

Dat-store uses the concept of provider. Providers are instances of dat-store running either locally or remotely. The default one is your local instance, but you can also configure other providers, like the Raspberry Pi. \\
This notion is particularly useful for remote control of other providers. \\

Dat-store provides interesting commands that we will use in our demo:
\begin{itemize}
  \item \emph{dat-store add &lt;url|path&gt; [provider]}: Adds a folder or a dat url to the dat-store of the specified provider.
  \item \emph{dat-store set-provider &lt;url&gt; [provider]}: Sets the url of the specified provider.
  \item \emph{dat-store list [provider]}: Retrieves the list of available Dats in the specified provider.
  \item \emph{dat-store clone &lt;path&gt; &lt;url&gt; [provider]}: Clones \emph{&lt;url&gt;} into a local folder.
\end{itemize}

We can then imagine the case where we have two clients A and B and one Raspberry Pi used as a permanent store to synchronize a folder from A to B.

First, A executes the following commands:
\begin{lstlisting}[label=cmd:dat_store_example_A, caption=Commands executed by client A]

  dat-store set-provider http://raspberrypi.local:3472 raspberry
  mkdir mydat
  dat-store add ./mydat
  dat-store list
  dat-store add &lt;url from previous command corresponding to ./mydat&gt; raspberry
  # You can check that the content is actually replicated by accessing
  # http://raspberrypi.local/gateway/&lt;token from hyper url corresponding to ./mydat&gt;/
\end{lstlisting}

Then, client B executes:
\begin{lstlisting}[label=cmd:dat_store_example_A, caption=Commands executed by client B]

  dat-store set-provider http://raspberrypi.local:3472 raspberry
  dat-store list raspberry
  dat-store clone ./mydat &lt;url obtained from the previous command&gt;
\end{lstlisting}


\cleardoublepage
\phantomsection
\addcontentsline{toc}{chapter}{Bibliography}
\printbibliography

\end{document}
</pre></body></html>