}
-\lstset{
+\lstset{
language=bash,
-basicstyle=\ttfamily,
+basicstyle=\ttfamily,
upquote=true,
columns=fullflexible,
literate={*}{{\char42}}1
\begin{document}
\begin{center}
-\large {A Tutorial for GNUnet 0.9.x (C version)}
+\large {A Tutorial for GNUnet 0.10.x (C version)}
Christian Grothoff $\qquad$ Bart Polot $\qquad$ Matthias Wachs
\today
\end{center}
-This tutorials explains how to install GNUnet on a GNU/Linux system and gives an introduction how
-GNUnet can be used to develop a Peer-to-Peer application. Detailed installation instructions for
-various operating systems and a detailed list of all dependencies can found on our website at
-\url{https://gnunet.org/installation}.
+This tutorials explains how to install GNUnet on a GNU/Linux system and gives an introduction on how
+GNUnet can be used to develop a Peer-to-Peer application. Detailed installation instructions for
+various operating systems and a detailed list of all dependencies can be found on our website at
+\url{https://gnunet.org/installation}.
-\textbf{Please read this tutorial carefully since every single step is important and do not hesitate to contact the GNUnet team if you have any questions or problems! Check here how to contact the GNUnet team:
-\url{https://gnunet.org/contact_information}}
+\textbf{Please read this tutorial carefully since every single step is
+ important and do not hesitate to contact the GNUnet team if you have
+ any questions or problems! Check here how to contact the GNUnet
+ team: \url{https://gnunet.org/contact_information}}
\section{Installing GNUnet}
-First of all you have to install a current version of GNUnet. You can download a
-tarball of a stable version from GNU FTP mirrors or obtain the latest development
+First of all you have to install a current version of GNUnet. You can download a
+tarball of a stable version from GNU FTP mirrors or obtain the latest development
version from our Subversion repository.
-Most of the time you should prefer to download the stable version since with the
-latest development version things can be broken, functionality can be changed or tests
-can fail. You should only use the development version if you know that you require a
+Most of the time you should prefer to download the stable version since with the
+latest development version things can be broken, functionality can be changed or tests
+can fail. You should only use the development version if you know that you require a
certain feature or a certain issue has been fixed since the last release.
\subsection{Obtaining a stable version}
You can download the latest stable version of GNUnet from GNU FTP mirrors:
\begin{center}
-\url{ftp://ftp.gnu.org/gnu/gnunet/gnunet-0.9.5a.tar.gz}
+\url{ftp://ftp.gnu.org/gnu/gnunet/gnunet-0.10.x.tar.gz}
\end{center}
You should also download the signature file and verify the integrity of the tarball.
\begin{center}
-\url{ftp://ftp.gnu.org/gnu/gnunet/gnunet-0.9.5a.tar.gz.sig}
+\url{ftp://ftp.gnu.org/gnu/gnunet/gnunet-0.10.x.tar.gz.sig}
\end{center}
To verify the signature you should first import the GPG key used to sign the tarball
\begin{lstlisting}
\end{lstlisting}
And use this key to verify the tarball's signature
\begin{lstlisting}
-$ gpg --verify gnunet-0.9.5a.tar.gz.sig gnunet-0.9.5a.tar.gz
+$ gpg --verify gnunet-0.10.x.tar.gz.sig gnunet-0.10.x.tar.gz
\end{lstlisting}
After successfully verifying the integrity you can extract the tarball using
\begin{lstlisting}
-$ tar xvzf gnunet-0.9.5a.tar.gz
-$ mv gnunet-0.9.5a gnunet # we will use the directory "gnunet" in the remainder of this document
+$ tar xvzf gnunet-0.10.x.tar.gz
+$ mv gnunet-0.10.x gnunet # we will use the directory "gnunet" in the remainder of this document
$ cd gnunet
\end{lstlisting}
\subsection{Installing Build Tool Chain and Dependencies}
To successfully compile GNUnet you need the tools to build GNUnet and the required dependencies.
-Please have a look at \url{https://gnunet.org/dependencies} for a list of required dependencies
+Please have a look at \url{https://gnunet.org/dependencies} for a list of required dependencies
and \url{https://gnunet.org/generic_installation} for specific instructions for your operating system.
Please check the notes at the end of the configure process about required dependencies.
For GNUNet bootstrapping support and the http(s) plugin you should install \texttt{libcurl}.
-For the filesharing service you should install at least one of the datastore backends \texttt{mysql},
+For the filesharing service you should install at least one of the datastore backends \texttt{mysql},
\texttt{sqlite} or \texttt{postgresql}.
\subsection{Obtaining the latest version from Subversion}
-The latest development version can obtained from our Subversion (\textit{svn}) repository. To obtain
+The latest development version can obtained from our Subversion (\textit{svn}) repository. To obtain
the code you need Subversion installed and checkout the repository using:
\lstset{language=bash}
\begin{lstlisting}
\subsection{Compiling and Installing GNUnet}
-First, you need to install at least {\tt
- libgnupgerror} version 1.12\footnote{\url{ftp://ftp.gnupg.org/gcrypt/libgpg-error/libgpg-error-1.12.tar.bz2}}and {\tt libgcrypt} version 1.6\footnote{\url{ftp://ftp.gnupg.org/gcrypt/libgcrypt/libgcrypt-1.6.0.tar.bz2}}.
+First, you need to install at least {\tt libgnupgerror} version
+1.12\footnote{\url{ftp://ftp.gnupg.org/gcrypt/libgpg-error/libgpg-error-1.12.tar.bz2}}
+and {\tt libgcrypt} version
+1.6\footnote{\url{ftp://ftp.gnupg.org/gcrypt/libgcrypt/libgcrypt-1.6.0.tar.bz2}}.
\lstset{language=bash}
\begin{lstlisting}
\end{lstlisting}
\label{sub:install}
-Assuming all dependencies are installed, the following commands will compile and install GNUnet in your
-home directory. You can specify the directory where GNUnet will be installed by changing the \lstinline|--prefix| value when calling \lstinline|./configure|. If you do not specifiy a prefix, GNUnet is installed in the directory \lstinline|/usr/local|. When developing new applications you may want to enable
-verbose logging by adding \lstinline|--enable-logging=verbose|:
+Assuming all dependencies are installed, the following commands will
+compile and install GNUnet in your home directory. You can specify the
+directory where GNUnet will be installed by changing the
+\lstinline|--prefix| value when calling \lstinline|./configure|. If
+you do not specifiy a prefix, GNUnet is installed in the directory
+\lstinline|/usr/local|. When developing new applications you may want
+to enable verbose logging by adding
+\lstinline|--enable-logging=verbose|:
\lstset{language=bash}
\begin{lstlisting}
-$ ./configure --prefix=$HOME --enable-logging
+$ ./configure --prefix=$PREFIX --enable-logging
$ make
-$ make install
+$ make install
\end{lstlisting}
-After installing GNUnet you have to set the \lstinline|GNUNET_PREFIX| environmental variable used by GNUnet to detect it's installation directory and add your GNUnet installation to your path environmental variable.
-This configuration is only valid for the current shell session, so you should add \lstinline|export GNUNET_PREFIX=$HOME| to your \lstinline|.bash_rc| or \lstinline|.profile| to be sure the environment variable is always set. In addition you have to create the \lstinline|.gnunet| directory in your home directory where GNUnet stores it's data and an empty GNUnet configuration file:
+After installing GNUnet you have to add your GNUnet installation to your path
+environmental variable. In addition you have to create the \lstinline|.gnunet|
+directory in your home directory where GNUnet stores its data and an empty
+GNUnet configuration file:
\lstset{language=bash}
\begin{lstlisting}
-$ export GNUNET_PREFIX=$HOME
-$ export PATH=$PATH:$GNUNET_PREFIX/bin
-$ echo export GNUNET_PREFIX=$HOME >> ~/.bashrc
-$ echo export PATH=$GNUNET_PREFIX/bin:$PATH >> ~/.bashrc
+$ export PATH=$PATH:$PREFIX/bin
+$ echo export PATH=$PREFIX/bin:\\$PATH >> ~/.bashrc
$ mkdir ~/.gnunet/
$ touch ~/.gnunet/gnunet.conf
\end{lstlisting}
% $
\subsection{Common Issues - Check your GNUnet installation}
-You should check your installation to ensure that installing GNUnet was successful up to this point. You should be able to access GNUnet's binaries and run GNUnet's self check.
+You should check your installation to ensure that installing GNUnet
+was successful up to this point. You should be able to access GNUnet's
+binaries and run GNUnet's self check.
\begin{lstlisting}
-$ which gnunet-arm
+$ which gnunet-arm
\end{lstlisting}
-should return \lstinline|$GNUNET_PREFIX/bin/gnunet-arm|. It should be located in your GNUnet installation and the output should not be empty. If you see an output like:
+should return \lstinline|$PREFIX/bin/gnunet-arm|. It should be
+located in your GNUnet installation and the output should not be
+empty. If you see an output like:
\begin{lstlisting}
$ which gnunet-arm
-$
+$
\end{lstlisting}
check your {\tt PATH} variable to ensure GNUnet's {\tt bin} directory is included.
-GNUnet provides tests for all of it's subcomponents. Run
+GNUnet provides tests for all of its subcomponents. Run
\begin{lstlisting}
$ make check
\end{lstlisting}
-to execute tests for all components. {\tt make check} traverses all subdirectories in {\tt src}.
+to execute tests for all components. {\tt make check} traverses all subdirectories in {\tt src}.
For every subdirectory you should get a message like this:
\begin{lstlisting}
/bin/bash: line 5: 19449 Aborted (core dumped) ${dir}$tst
FAIL: test_program
\end{lstlisting}
-double check your {\tt GNUNET\_PREFIX} environmental variable and double check the steps performed in ~\ref{sub:install}
+double check the steps performed in ~\ref{sub:install}
\section{Background: GNUnet Architecture}
GNUnet is organized in layers and services. Each service is composed of a
-main service implementation and a client library for other programs to use
-the service's functionality, described by an API. This approach is shown in
-figure~\ref{fig:service}. Some services provide an additional command line
+main service implementation and a client library for other programs to use
+the service's functionality, described by an API. This approach is shown in
+figure~\ref{fig:service}. Some services provide an additional command line
tool to enable the user to interact with the service.
Very often it is other GNUnet services that will use these APIs to build the
\includegraphics[width=\textwidth]{figs/Service.pdf}
\caption{Service with API and network protocol}
\label{fig:service}
- \end{subfigure}
+ \end{subfigure}
~~~~~~~~~~
\begin{subfigure}[b]{0.3\textwidth}
\centering
\includegraphics[width=\textwidth]{figs/System.pdf}
\caption{Service interaction}
\label{fig:interaction}
- \end{subfigure}
+ \end{subfigure}
\end{center}
\caption{GNUnet's layered system architecture}
\end{figure}
\section{First Steps with GNUnet}
\subsection{Configure your peer}
-First of all we need to configure your peer. Each peer is started with a configuration containing settings for GNUnet itself and it's services. This configuration is based on the default configuration shipped with GNUnet and can be modified. The default configuration is located in the {\tt \$GNUNET\_PREFIX/share/gnunet/config.d} directory. When starting a peer, you can specify a customized configuration using the the {\tt$-c$} command line switch when starting the ARM service and all other services. When using a modified configuration the default values are loaded and only values specified in the configuration file will replace the default values.
+First of all we need to configure your peer. Each peer is started with a configuration containing settings for GNUnet itself and its services. This configuration is based on the default configuration shipped with GNUnet and can be modified. The default configuration is located in the {\tt \$PREFIX/share/gnunet/config.d} directory. When starting a peer, you can specify a customized configuration using the the {\tt$-c$} command line switch when starting the ARM service and all other services. When using a modified configuration the default values are loaded and only values specified in the configuration file will replace the default values.
-Since we want to start additional peers later, we need
+Since we want to start additional peers later, we need
some modifications from the default configuration. We need to create a separate service home and a file containing our modifications for this peer:
\begin{lstlisting}
$ mkdir ~/gnunet1/
$ touch peer1.conf
\end{lstlisting}
-Now add the following lines to peer1.conf to use this directory. For simplified usage we want to prevent
-the peer to connect to the GNUnet network since this could lead to confusing output. This modifications will replace the default settings:
+Now add the following lines to peer1.conf to use this directory. For
+simplified usage we want to prevent the peer to connect to the GNUnet
+network since this could lead to confusing output. This modifications
+will replace the default settings:
\begin{lstlisting}
[PATHS]
-GNUNET_HOME = ~/gnunet1/ # Use this directory to store GNUnet data
+GNUNET_HOME = ~/gnunet1/ # Use this directory to store GNUnet data
[hostlist]
-SERVERS = # prevent bootstrapping
+SERVERS = # prevent bootstrapping
\end{lstlisting}
\subsection{Start a peer}
-Each GNUnet instance (called peer) has an identity (\textit{peer ID}) based on a
-cryptographic public private key pair. The peer ID is the printable hash of the
-public key. So before starting the peer, you may want to just generate the peer's private
-key using the command
+Each GNUnet instance (called peer) has an identity (\textit{peer ID}) based on a
+cryptographic public private key pair. The peer ID is the printable hash of the
+public key.
+
+GNUnet services are controlled by a master service the so called \textit{Automatic Restart Manager} (ARM).
+ARM starts, stops and even restarts services automatically or on demand when a client connects.
+You interact with the ARM service using the \lstinline|gnunet-arm| tool.
+GNUnet can then be started with \lstinline|gnunet-arm -s| and stopped with
+\lstinline|gnunet-arm -e|. An additional service not automatically started
+can be started using \lstinline|gnunet-arm -i <service name>| and stopped
+using \lstinline|gnunet-arm -k <servicename>|.
+
+Once you have started your peer, you can use many other GNUnet commands
+to interact with it. For example, you can run:
\lstset{language=bash}
\begin{lstlisting}
-$ gnunet-peerinfo -c ~/peer1.conf -s
+$ gnunet-peerinfo -s
\end{lstlisting}
+to obtain the public key of your peer.
You should see an output containing the peer ID similar to:
\lstset{language=bash}
\begin{lstlisting}
I am peer `0PA02UVRKQTS2C .. JL5Q78F6H0B1ACPV1CJI59MEQUMQCC5G'.
\end{lstlisting}
-GNUnet services are controlled by a master service the so called \textit{Automatic Restart Manager} (ARM).
-ARM starts, stops and even restarts services automatically or on demand when a client connects.
-You interact with the ARM service using the \lstinline|gnunet-arm| tool.
-GNUnet can then be started with \lstinline|gnunet-arm -s| and stopped with
-\lstinline|gnunet-arm -e|. An additional service not automatically started
-can be started using \lstinline|gnunet-arm -i <service name>| and stopped
-using \lstinline|gnunet-arm -k <servicename>|.
\subsection{Monitor a peer}
-In this section, we will monitor the behaviour of our peer's DHT service with respect to a
+In this section, we will monitor the behaviour of our peer's DHT service with respect to a
specific key. First we will start GNUnet and then start the DHT service and use the DHT monitor tool
-to monitor the PUT and GET commands we issue ussing the \lstinline|gnunet-dht-put| and
-\lstinline|gnunet-dht-get| command. Using the ``monitor'' line given below, you can observe the behavior of
+to monitor the PUT and GET commands we issue ussing the \lstinline|gnunet-dht-put| and
+\lstinline|gnunet-dht-get| commands. Using the ``monitor'' line given below, you can observe the behavior of
your own peer's DHT with respect to the specified KEY:
\lstset{language=bash}
\begin{lstlisting}
-$ gnunet-arm -c ~/peer1.conf -s # start gnunet with all default services
-$ gnunet-arm -c ~/peer1.conf -i dht # start DHT service
+$ gnunet-arm -c ~/peer1.conf -s # start gnunet with all default services
+$ gnunet-arm -c ~/peer1.conf -i dht # start DHT service
$ cd ~/gnunet/src/dht;
$ ./gnunet-dht-monitor -c ~/peer1.conf -k KEY
\end{lstlisting}
Now open a separate terminal and change again to the \lstinline|gnunet/src/dht| directory:
\begin{lstlisting}
$ cd ~/gnunet/src/dht
-$ ./gnunet-dht-put -c ~/peer1.conf -k KEY -d VALUE # put VALUE under KEY in the DHT
-$ ./gnunet/src/dht/gnunet-dht-get -c ~/peer1.conf -k KEY # get key KEY from the DHT
-$ gnunet-statistics -c ~/peer1.conf # print statistics about current GNUnet state
-$ gnunet-statistics -c ~/peer1.conf -s dht # print statistics about DHT service
+$ ./gnunet-dht-put -c ~/peer1.conf -k KEY -d VALUE # put VALUE under KEY in the DHT
+$ ./gnunet/src/dht/gnunet-dht-get -c ~/peer1.conf -k KEY # get key KEY from the DHT
+$ gnunet-statistics -c ~/peer1.conf # print statistics about current GNUnet state
+$ gnunet-statistics -c ~/peer1.conf -s dht # print statistics about DHT service
\end{lstlisting}
% $
\subsection{Starting Two Peers by Hand}
\subsubsection{Setup a second peer}
We will now start a second peer on your machine.
For the second peer, you will need to manually create a modified
-configuration file to avoid conflicts with ports and directories.
+configuration file to avoid conflicts with ports and directories.
A peers configuration file is by default located in {\tt ~/.gnunet/gnunet.conf}.
This file is typically very short or even empty as only the differences to the
-defaults need to be specified. The defaults are located in
-many files in the {\tt \$GNUNET\_PREFIX/share/gnunet/config.d} directory.
+defaults need to be specified. The defaults are located in
+many files in the {\tt \$PREFIX/share/gnunet/config.d} directory.
To configure the second peer, use the files {\tt
- \$GNUNET\_PREFIX/share/gnunet/config.d} as a template for your main
+ \$PREFIX/share/gnunet/config.d} as a template for your main
configuration file:
%
\lstset{language=bash}
\begin{lstlisting}
-$ cat $GNUNET_PREFIX/share/gnunet/config.d/*.conf > peer2.conf
+$ cat $PREFIX/share/gnunet/config.d/*.conf > peer2.conf
\end{lstlisting}
Now you have to edit {\tt peer2.conf} and change:
\begin{itemize}
\itemsep0em
\item{\texttt{SERVICEHOME} under \texttt{PATHS}}
\item{Every (uncommented) value for ``\texttt{PORT}'' (add 10000) in any
- section (the option may be commented out if \texttt{PORT} is
+ section (the option may be commented out if \texttt{PORT} is
prefixed by "\#", in this case, UNIX domain sockets are used
and the PORT option does not need to be touched) }
\item{Every value for ``\texttt{UNIXPATH}'' in any section (e.g. by adding a "-p2" suffix)}
\item Setup a bootstrap server
\item Connect manually
\end{itemize}
-To setup peer 1 as bootstrapping server change the configuration of the first one to be a hostlist server by adding the following lines to \texttt{peer1.conf} to enable bootstrapping server:
+To setup peer 1 as bootstrapping server change the configuration of
+the first one to be a hostlist server by adding the following lines to
+\texttt{peer1.conf} to enable bootstrapping server:
\begin{lstlisting}
[hostlist]
OPTIONS = -p
Then change {\tt peer2.conf} and replace the ``\texttt{SERVERS}'' line in the ``\texttt{[hostlist]}'' section with
``\texttt{http://localhost:8080/}''. Restart both peers using:
\begin{lstlisting}
-$ gnunet-arm -c peer1.conf -e # stop first peer
-$ gnunet-arm -c peer1.conf -s # start first peer
-$ gnunet-arm -c peer2.conf -s # start second peer
+$ gnunet-arm -c peer1.conf -e # stop first peer
+$ gnunet-arm -c peer1.conf -s # start first peer
+$ gnunet-arm -c peer2.conf -s # start second peer
\end{lstlisting}
Note that if you start your peers without changing these settings, they
will use the ``global'' hostlist servers of the GNUnet P2P network and
likely connect to those peers. At that point, debugging might become
-tricky as you're going to be connected to many more peers and would
+tricky as you're going to be connected to many more peers and would
likely observe traffic and behaviors that are not explicitly controlled
by you.
If you want to use the \texttt{peerinfo} tool to connect your peers, you should:
\begin{itemize}
\itemsep0em
- \item{Remove {\tt hostlist} from {\tt DEFAULTSERVICES} (to not connect to the global GNUnet)}
+ \item{Set {\tt FORCESTART = NO} in section {\tt hostlist} (to not connect to the global GNUnet)}
\item{Start both peers running {\tt gnunet-arm -c peer1.conf -s} and {\tt gnunet-arm -c peer2.conf -s}}
\item{Get \texttt{HELLO} message of the first peer running {\tt gnunet-peerinfo -c peer1.conf -g}}
\item{Give the output to the second peer by running {\tt gnunet-peerinfo -c peer2.conf -p '<output>'}}
\end{itemize}
-Check that they are connected using {\tt gnunet-core -c peer1.conf}, which should give you the other peer's
+Check that they are connected using {\tt gnunet-core -c peer1.conf}, which should give you the other peer's
peer identity:
\begin{lstlisting}
$ gnunet-core -c peer1.conf
-Peer `9TVUCS8P5A7ILLBGO6JSTSSN2B44H3D2MUIFJMLKAITC0I22UVFBFP1H8NRK2IA35VKAK16LLO0MFS7TAQ9M1KNBJ4NGCHP3JPVULDG'
+Peer `9TVUCS8P5A7ILLBGO6 [...shortened...] 1KNBJ4NGCHP3JPVULDG'
\end{lstlisting}
\subsection{Starting Peers Using the Testbed Service}
configuration for the peers. The testbed takes care of modifying relevant
options in the peers' configuration such as SERVICEHOME, PORT, UNIXPATH to
unique values so that peers run without running into conflicts. It also checks
-and assigns the ports in configurations only if they are free.
+and assigns the ports in configurations only if they are free.
Additionally, the testbed service also reads its options from the same
configuration file. Various available options and details about them can be
found in the testbed default configuration file \texttt{src/testbed/testbed.conf}.
With the testbed API, a sample test case can be structured as follows:
+% <lynX> Is there a way to pick a more readable font for this include?
\lstinputlisting[language=C]{testbed_test.c}
The source code for the above listing can be found at
-\url{https://gnunet.org/svn/gnunet/doc/testbed_test.c}. After installing GNUnet, the above source code can be compiled as:
+\url{https://gnunet.org/svn/gnunet/doc/testbed_test.c}
+or in the doc folder of your repository check-out.
+After installing GNUnet, the above source code can be compiled as:
\lstset{language=bash}
\begin{lstlisting}
$ export CPPFLAGS="-I/path/to/gnunet/headers"
$ svn checkout https://gnunet.org/svn/gnunet-ext/
$ cd gnunet-ext/
$ ./bootstrap
-$ ./configure --prefix=$HOME --with-gnunet=$GNUNET_PREFIX
+$ ./configure --prefix=$PREFIX --with-gnunet=$PREFIX
$ make
$ make install
$ make check
\itemsep0em
\item the GNUnet service (\lstinline|gnunet-ext/src/ext/gnunet-service-ext.c|)
\item the client API (\lstinline|gnunet-ext/src/ext/ext_api.c|)
- \item the client application using the service API (\lstinline|gnunet-ext/src/ext/gnunet-ext.c|)
+ \item the client application using the service API (\lstinline|gnunet-ext/src/ext/gnunet-ext.c|)
\end{itemize}
The interfaces for these entities are defined in:
\begin{itemize}
\itemsep0em
- \item client API interface (\lstinline|gnunet-ext/src/ext/ext.h|)
+ \item client API interface (\lstinline|gnunet-ext/src/ext/ext.h|)
\item the service interface (\lstinline|gnunet-ext/src/include/gnunet_service_SERVICE.h|)
\item the P2P protocol (\lstinline|gnunet-ext/src/include/gnunet_protocols_ext.h|)
\end{itemize}
The first step for writing any extension with a new service is to
ensure that the {\tt ext.conf.in} file contains entries for the
\texttt{UNIXPATH}, \texttt{PORT} and \texttt{BINARY} for the service in a section named after
-the service.
+the service.
-If you want to adapt the template rename the {\tt ext.conf.in} to match your
-services name, you have to modify the \texttt{AC\_OUTPUT} section in {\tt configure.ac}
+If you want to adapt the template rename the {\tt ext.conf.in} to match your
+services name, you have to modify the \texttt{AC\_OUTPUT} section in {\tt configure.ac}
in the \texttt{gnunet-ext} root.
\section{Writing a Client Application}
using this approach. Other {\tt GNUNET\_GETOPT\_}-functions can be used
to obtain integer value options, increment counters, etc. You can
even write custom option parsers for special circumstances not covered
-by the available handlers. To check if an argument was specified by the
-user you initialize the variable with a specific value (e.g. NULL for
-a string and GNUNET\_SYSERR for a integer) and check after parsing
+by the available handlers. To check if an argument was specified by the
+user you initialize the variable with a specific value (e.g. NULL for
+a string and GNUNET\_SYSERR for a integer) and check after parsing
happened if the values were modified.
Inside the {\tt run} method, the program would perform the
\subsection{Writing a Client Library}
The first and most important step in writing a client library is to
-decide on an API for the library. Typical API calls include
+decide on an API for the library. Typical API calls include
connecting to the service, performing application-specific requests
and cleaning up. Many examples for such service APIs can be found
in the {\tt gnunet/src/include/gnunet\_*\_service.h} files.
client = GNUNET_CLIENT_connect ("service-name", cfg);
\end{lstlisting}
-As a result a {\tt GNUNET\_CLIENT\_Connection} handle is returned
+As a result a {\tt GNUNET\_CLIENT\_Connection} handle is returned
which has to used in later API calls related to this service.
The complete client API can be found in {\tt gnunet\_client\_lib.h}
\subsubsection{GNUnet Messages}
In GNUnet, messages are always sent beginning with a {\tt struct GNUNET\_MessageHeader}
-in big endian format. This header defines the size and the type of the
+in big endian format. This header defines the size and the type of the
message, the payload follows after this header.
\lstset{language=c}
\lstset{language=c}
\begin{lstlisting}
-struct GNUNET_MessageHeader *msg =
+struct GNUNET_MessageHeader *msg =
GNUNET_malloc(payload_size + sizeof(struct GNUNET_MessageHeader));
msg->size = htons(payload_size + sizeof(struct GNUNET_MessageHeader));
msg->type = htons(GNUNET_MY_MESSAGE_TYPE);
return msg_size;
}
-// ...
+// ...
th = GNUNET_CLIENT_notify_transmit_ready (client,
msg_size,
timeout,
\end{lstlisting}
The client-service protocoll calls {\tt GNUNET\_CLIENT\_notify\_transmit\_ready}
-to be notified when the client is ready to send data to the service.
-Besides other arguments, you have to pass the client returned
-from the {\tt connect} call, the message size and the callback function to
-call when the client is ready to send.
+to be notified when the client is ready to send data to the service.
+Besides other arguments, you have to pass the client returned
+from the {\tt connect} call, the message size and the callback function to
+call when the client is ready to send.
Only a single transmission request can be queued per client at the
same time using this API. The handle {\tt th} can be used to cancel
-the request if necessary (for example, during shutdown).
+the request if necessary (for example, during shutdown).
-When {\tt transmit\_cb} is called the message is copied in the buffer provided and
-the number of bytes copied into the buffer is returned. {\tt transmit\_cb}
+When {\tt transmit\_cb} is called the message is copied in the buffer provided and
+the number of bytes copied into the buffer is returned. {\tt transmit\_cb}
could also return 0 if for some reason no message
could be constructed; this is not an error and the connection to the
service will persist in this case.
// process 'msg'
}
-// ...
+// ...
GNUNET_CLIENT_receive (client,
&receive_message,
arg,
\exercise{Expand your helper function to receive a
response message (for example, containing just the GNUnet MessageHeader
without any payload). Upon receiving the service's response, you should
-call a callback provided to your helper function's API. You'll need to
+call a callback provided to your helper function's API. You'll need to
define a new 'struct' to hold your local context (``closure'').}
at the command-line to the service.}
-
+
\section{Writing a Service}
Before you can test the client you've written so far, you'll need to also
static void my_main (void *cls,
struct GNUNET_SERVER_Handle *server,
const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
- /* do work */
+{
+ /* do work */
}
-int main (int argc, char *const*argv)
+int main (int argc, char *const*argv)
{
- if (GNUNET_OK !=
- GNUNET_SERVICE_run (argc, argv, "my",
- GNUNET_SERVICE_OPTION_NONE,
+ if (GNUNET_OK !=
+ GNUNET_SERVICE_run (argc, argv, "my",
+ GNUNET_SERVICE_OPTION_NONE,
&my_main, NULL);
return 1;
- return 0;
+ return 0;
}
\end{lstlisting}
struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
static void
handle_get (void *cls,
struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
static void my_main (void *cls,
struct GNUNET_SERVER_Handle *server,
const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
+{
static const struct GNUNET_SERVER_MessageHandler handlers[] = {
{&handle_set, NULL, GNUNET_MESSAGE_TYPE_MYNAME_SET, 0},
{&handle_get, NULL, GNUNET_MESSAGE_TYPE_MYNAME_GET, 0},
{NULL, NULL, 0, 0}
};
GNUNET_SERVER_add_handlers (server, handlers);
- /* do more setup work */
-}
+ /* do more setup work */
+}
\end{lstlisting}
Each handler function {\bf must} eventually (possibly in some
return msg_size;
}
-// ...
+// ...
struct GNUNET_SERVER_TransmitHandle *th;
th = GNUNET_SERVER_notify_transmit_ready (client,
msg_size,
Only a single transmission request can be queued per client
at the same time using this API.
Additional APIs for sending messages to clients can be found
-in the {\tt gnunet\_server\_lib.h} header.
+in the {\tt gnunet\_server\_lib.h} header.
\exercise{Change the service respond to the request from your
client. Make sure you handle malformed messages in both directions.}
-
\section{Interacting directly with other Peers using the CORE Service}
-One of the most important services in GNUnet is the \texttt{CORE} service
+One of the most important services in GNUnet is the \texttt{CORE} service
managing connections between peers and handling encryption between peers.
One of the first things any service that extends the P2P protocol typically does
\subsection{Sending P2P Messages}
-In response to events (connect, disconnect, inbound messages,
+In response to events (connect, disconnect, inbound messages,
timing, etc.) services can then use this API to transmit messages:
\lstset{language=C}
\begin{lstlisting}
-typedef size_t
+typedef size_t
(*GNUNET_CONNECTION_TransmitReadyNotify) (void *cls,
- size_t size,
+ size_t size,
void *buf)
{
/* Fill "*buf" with up to "size" bytes, must start with GNUNET_MessageHeader */
\exercise{Fix your service to handle peer disconnects.}
+\section{Storing peer-specific data using the PEERSTORE service}
+
+GNUnet's PEERSTORE service offers a persistorage for arbitrary peer-specific data.
+Other GNUnet services can use the PEERSTORE to store, retrieve and monitor data records.
+Each data record stored with PEERSTORE contains the following fields:
+
+\begin{itemize}
+\itemsep0em
+ \item subsystem: Name of the subsystem responsible for the record.
+ \item peerid: Identity of the peer this record is related to.
+ \item key: a key string identifying the record.
+ \item value: binary record value.
+ \item expiry: record expiry date.
+\end{itemize}
+
+The first step is to start a connection to the PEERSTORE service:
+\begin{lstlisting}
+#include "gnunet_peerstore_service.h"
+
+peerstore_handle = GNUNET_PEERSTORE_connect (cfg);
+\end{lstlisting}
+The service handle \lstinline|peerstore_handle| will be needed for all subsequent
+PEERSTORE operations.
+
+\subsection{Storing records}
+
+To store a new record, use the following function:
+\begin{lstlisting}
+struct GNUNET_PEERSTORE_StoreContext *
+GNUNET_PEERSTORE_store (struct GNUNET_PEERSTORE_Handle *h,
+ const char *sub_system,
+ const struct GNUNET_PeerIdentity *peer,
+ const char *key,
+ const void *value,
+ size_t size,
+ struct GNUNET_TIME_Absolute expiry,
+ enum GNUNET_PEERSTORE_StoreOption options,
+ GNUNET_PEERSTORE_Continuation cont,
+ void *cont_cls);
+\end{lstlisting}
+
+The \lstinline|options| parameter can either be \lstinline|GNUNET_PEERSTORE_STOREOPTION_MULTIPLE|
+which means that multiple values can be stored under the same key combination (subsystem, peerid, key),
+or \lstinline|GNUNET_PEERSTORE_STOREOPTION_REPLACE| which means that PEERSTORE will replace any
+existing values under the given key combination (subsystem, peerid, key) with the new given value.
+
+The continuation function \lstinline|cont| will be called after the store request is successfully
+sent to the PEERSTORE service. This does not guarantee that the record is successfully stored, only
+that it was received by the service.
+
+The \lstinline|GNUNET_PEERSTORE_store| function returns a handle to the store operation. This handle
+can be used to cancel the store operation only before the continuation function is called:
+\begin{lstlisting}
+void
+GNUNET_PEERSTORE_store_cancel (struct GNUNET_PEERSTORE_StoreContext *sc);
+\end{lstlisting}
+
+\subsection{Retrieving records}
+
+To retrieve stored records, use the following function:
+\begin{lstlisting}
+struct GNUNET_PEERSTORE_IterateContext *
+GNUNET_PEERSTORE_iterate (struct GNUNET_PEERSTORE_Handle *h,
+ const char *sub_system,
+ const struct GNUNET_PeerIdentity *peer,
+ const char *key,
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_PEERSTORE_Processor callback,
+ void *callback_cls);
+\end{lstlisting}
+The values of \lstinline|peer| and \lstinline|key| can be \lstinline|NULL|. This allows the
+iteration over values stored under any of the following key combinations:
+\begin{itemize}
+\itemsep0em
+ \item (subsystem)
+ \item (subsystem, peerid)
+ \item (subsystem, key)
+ \item (subsystem, peerid, key)
+\end{itemize}
+
+The \lstinline|callback| function will be called once with each retrieved record and once
+more with a \lstinline|NULL| record to signal the end of results.
+
+The \lstinline|GNUNET_PEERSTORE_iterate| function returns a handle to the iterate operation. This
+handle can be used to cancel the iterate operation only before the callback function is called with
+a \lstinline|NULL| record.
+
+\subsection{Monitoring records}
+
+PEERSTORE offers the functionality of monitoring for new records stored under a specific key
+combination (subsystem, peerid, key). To start the monitoring, use the following function:
+\begin{lstlisting}
+struct GNUNET_PEERSTORE_WatchContext *
+GNUNET_PEERSTORE_watch (struct GNUNET_PEERSTORE_Handle *h,
+ const char *sub_system,
+ const struct GNUNET_PeerIdentity *peer,
+ const char *key,
+ GNUNET_PEERSTORE_Processor callback,
+ void *callback_cls);
+\end{lstlisting}
+
+Whenever a new record is stored under the given key combination, the \lstinline|callback| function
+will be called with this new record. This will continue until the connection to the PEERSTORE service
+is broken or the watch operation is canceled:
+\begin{lstlisting}
+void
+GNUNET_PEERSTORE_watch_cancel (struct GNUNET_PEERSTORE_WatchContext *wc);
+\end{lstlisting}
+
+\subsection{Disconnecting from PEERSTORE}
+
+When the connection to the PEERSTORE service is no longer needed, disconnect using the following
+function:
+\begin{lstlisting}
+void
+GNUNET_PEERSTORE_disconnect (struct GNUNET_PEERSTORE_Handle *h, int sync_first);
+\end{lstlisting}
+
+If the \lstinline|sync_first| flag is set to \lstinline|GNUNET_YES|, the API will delay the
+disconnection until all store requests are received by the PEERSTORE service. Otherwise,
+it will disconnect immediately.
+
\section{Using the DHT}
The DHT allows to store data so other peers in the P2P network can
access it and retrieve data stored by any peers in the network.
}
struct GNUNET_DHT_PutHandle *
-GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle,
+GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle,
const struct GNUNET_HashCode * key,
uint32_t desired_replication_level,
enum GNUNET_DHT_RouteOption options, /* Route options, see next call */
cls)
\end{lstlisting}
-\exercise{Store a value in the DHT and after a while retrieve it. Show the IDs of all
+\exercise{Store a value in the DHT and after a while retrieve it. Show the IDs of all
the peers the requests have gone through. In order to convert a peer ID to a string, use
the function GNUNET\_i2s. Pay attention to the route option parameters in both calls!}
}
\end{lstlisting}
-Note that it is mandatory to detect duplicate replies in this
-function and return the respective status code. Duplicate
+Note that it is mandatory to detect duplicate replies in this
+function and return the respective status code. Duplicate
detection should be done by setting the respective bits in
the Bloom filter {\tt bf}. Failure to do so may cause replies
to circle in the network.
\subsubsection{Shutdown of the plugin}
-Following GNUnet's general plugin API concept, the plugin must
+Following GNUnet's general plugin API concept, the plugin must
export a second function for cleaning up. It usually does very
little.
\lstset{language=make}
\begin{lstlisting}
plugindir = $(libdir)/gnunet
-
+
plugin_LTLIBRARIES = \
libgnunet_plugin_block_ext.la
libgnunet_plugin_block_ext_la_SOURCES = \
\section{Debugging with {\tt gnunet-arm}}
-Even if services are managed by {\tt gnunet-arm}, you can start them with
+Even if services are managed by {\tt gnunet-arm}, you can start them with
{\tt gdb} or {\tt valgrind}. For example, you could add the following lines
to your configuration file to start the DHT service in a {\tt gdb} session in a
fresh {\tt xterm}:
\lstset{language=bash}
\begin{lstlisting}
$ gnunet-arm -k dht
-$ gdb --args gnunet-service-dht -L DEBUG
-$ valgrind gnunet-service-dht -L DEBUG
+$ gdb --args gnunet-service-dht -L DEBUG
+$ valgrind gnunet-service-dht -L DEBUG
\end{lstlisting}
% $
Assuming other services are well-written, they will automatically re-integrate the
restarted service with the peer.
-GNUnet provides a powerful logging mechanism providing log levels \texttt{ERROR},
-\texttt{WARNING}, \texttt{INFO} and \texttt{DEBUG}. The current log level is
+GNUnet provides a powerful logging mechanism providing log levels \texttt{ERROR},
+\texttt{WARNING}, \texttt{INFO} and \texttt{DEBUG}. The current log level is
configured using the \lstinline|$GNUNET_FORCE_LOG| environmental variable.
-The \texttt{DEBUG} level is only available if \lstinline|--enable-logging=verbose| was used when
-running \texttt{configure}. More details about logging can be found under
+The \texttt{DEBUG} level is only available if \lstinline|--enable-logging=verbose| was used when
+running \texttt{configure}. More details about logging can be found under
\url{https://gnunet.org/logging}.
You should also probably enable the creation of core files, by setting