aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/gnunet-c-tutorial.pdfbin262596 -> 293947 bytes
-rw-r--r--doc/gnunet-c-tutorial.tex285
-rw-r--r--doc/testbed_test.c112
-rw-r--r--src/arm/gnunet-arm.c44
-rw-r--r--src/consensus/Makefile.am5
-rw-r--r--src/fs/fs_directory.c78
-rw-r--r--src/fs/fs_download.c107
-rw-r--r--src/fs/fs_search.c7
-rw-r--r--src/fs/fs_tree.c6
-rw-r--r--src/fs/fs_unindex.c3
-rw-r--r--src/fs/fs_uri.c22
-rw-r--r--src/include/gnunet_arm_service.h18
-rw-r--r--src/include/gnunet_configuration_lib.h7
-rw-r--r--src/include/gnunet_core_service.h53
-rw-r--r--src/secretsharing/Makefile.am6
-rw-r--r--src/testbed/gnunet-service-testbed_peers.c6
-rw-r--r--src/util/disk.c21
17 files changed, 314 insertions, 466 deletions
diff --git a/doc/gnunet-c-tutorial.pdf b/doc/gnunet-c-tutorial.pdf
index f0dfe58b3f..115ed77028 100644
--- a/doc/gnunet-c-tutorial.pdf
+++ b/doc/gnunet-c-tutorial.pdf
Binary files differ
diff --git a/doc/gnunet-c-tutorial.tex b/doc/gnunet-c-tutorial.tex
index 069c1838fe..2b4a0d8e13 100644
--- a/doc/gnunet-c-tutorial.tex
+++ b/doc/gnunet-c-tutorial.tex
@@ -1,12 +1,13 @@
\documentclass[10pt]{article}
\usepackage[ansinew]{inputenc}
\usepackage{makeidx,amsmath,amssymb,exscale,multicol,epsfig,graphics,verbatim,ulem}
-\usepackage{epsfig,geometry,url,listings, subcaption}
+\usepackage{epsfig,geometry,url,listings,subcaption}
\usepackage{boxedminipage}
\usepackage[T1]{fontenc}%required
\usepackage{textcomp}
\geometry{headsep=3ex,hscale=0.9}
\usepackage{hyperref}
+\usepackage{color}
\hypersetup{pdftitle={GNUnet C Tutorial},
pdfsubject={GNUnet},
pdfauthor={Christian Grothoff <christian@grothoff.org>},
@@ -28,6 +29,26 @@ literate={*}{{\char42}}1
\begin{document}
+\lstset{ %
+language=C, % choose the language of the code
+basicstyle=\footnotesize, % the size of the fonts that are used for the code
+numbers=left, % where to put the line-numbers
+numberstyle=\footnotesize, % the size of the fonts that are used for the line-numbers
+stepnumber=1, % the step between two line-numbers. If it is 1 each line will be numbered
+numbersep=5pt, % how far the line-numbers are from the code
+backgroundcolor=\color{white}, % choose the background color. You must add \usepackage{color}
+showspaces=false, % show spaces adding particular underscores
+showstringspaces=false, % underline spaces within strings
+showtabs=false, % show tabs within strings adding particular underscores
+frame=single, % adds a frame around the code
+tabsize=2, % sets default tabsize to 2 spaces
+captionpos=b, % sets the caption-position to bottom
+breaklines=true, % sets automatic line breaking
+breakatwhitespace=false, % sets if automatic breaks should only happen at whitespace
+escapeinside={\%*}{*)} % if you want to add a comment within your code
+}
+
+
\begin{center}
\large {A Tutorial for GNUnet 0.10.x (C version)}
@@ -68,20 +89,25 @@ You should also download the signature file and verify the integrity of the tarb
\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
+\lstset{language=bash}
\begin{lstlisting}
$ gpg --keyserver keys.gnupg.net --recv-keys 48426C7E
\end{lstlisting}
And use this key to verify the tarball's signature
+\lstset{language=bash}
\begin{lstlisting}
$ 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
+\lstset{language=bash}
\begin{lstlisting}
$ 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}
+However, please note that stable versions can be very outdated, as a developer
+you are strongly encouraged to use the version from \url{https://gnunet.org/git/}.
\subsection{Installing Build Tool Chain and Dependencies}
@@ -116,15 +142,15 @@ The remainder of this tutorial assumes that you have Git Master checked out.
\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}}
+1.27\footnote{\url{ftp://ftp.gnupg.org/gcrypt/libgpg-error/libgpg-error-1.27.tar.bz2}}
and {\tt libgcrypt} version
-1.6\footnote{\url{ftp://ftp.gnupg.org/gcrypt/libgcrypt/libgcrypt-1.6.0.tar.bz2}}.
+1.7.6\footnote{\url{ftp://ftp.gnupg.org/gcrypt/libgcrypt/libgcrypt-1.7.6.tar.bz2}}.
\lstset{language=bash}
\begin{lstlisting}
-$ wget ftp://ftp.gnupg.org/gcrypt/libgpg-error/libgpg-error-1.12.tar.bz2
-$ tar xf libgpg-error-1.12.tar.bz2
-$ cd libgpg-error-1.12
+$ wget ftp://ftp.gnupg.org/gcrypt/libgpg-error/libgpg-error-1.27.tar.bz2
+$ tar xf libgpg-error-1.27.tar.bz2
+$ cd libgpg-error-1.27
$ ./configure
$ sudo make install
$ cd ..
@@ -132,9 +158,9 @@ $ cd ..
\lstset{language=bash}
\begin{lstlisting}
-$ wget ftp://ftp.gnupg.org/gcrypt/libgcrypt/libgcrypt-1.6.0.tar.bz2
-$ tar xf libgcrypt-1.6.0.tar.bz2
-$ cd libgcrypt-1.6.0
+$ wget ftp://ftp.gnupg.org/gcrypt/libgcrypt/libgcrypt-1.7.6.tar.bz2
+$ tar xf libgcrypt-1.7.6.tar.bz2
+$ cd libgcrypt-1.7.6
$ ./configure
$ sudo make install
$ cd ..
@@ -176,12 +202,14 @@ $ touch ~/.config/gnunet.conf
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.
+\lstset{language=bash}
\begin{lstlisting}
$ which gnunet-arm
\end{lstlisting}
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:
+\lstset{language=bash}
\begin{lstlisting}
$ which gnunet-arm
$
@@ -189,29 +217,20 @@ $
check your {\tt PATH} variable to ensure GNUnet's {\tt bin} directory is included.
GNUnet provides tests for all of its subcomponents. Run
+\lstset{language=bash}
\begin{lstlisting}
$ make check
\end{lstlisting}
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}
+\begin{verbatim}
make[2]: Entering directory `/home/$USER/gnunet/contrib'
PASS: test_gnunet_prefix
=============
1 test passed
=============
-\end{lstlisting}
-
-If you see a message like this:
-
-\begin{lstlisting}
-Mar 12 16:57:56-642482 resolver-api-19449 ERROR Must specify `HOSTNAME' for `resolver' in configuration!
-Mar 12 16:57:56-642573 test_program-19449 ERROR Assertion failed at resolver_api.c:204.
-/bin/bash: line 5: 19449 Aborted (core dumped) ${dir}$tst
-FAIL: test_program
-\end{lstlisting}
-double check the steps performed in ~\ref{sub:install}
+\end{verbatim}
\section{Background: GNUnet Architecture}
@@ -262,6 +281,7 @@ First of all we need to configure your peer. Each peer is started with a configu
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:
+\lstset{language=bash}
\begin{lstlisting}
$ mkdir ~/gnunet1/
$ touch peer1.conf
@@ -271,12 +291,12 @@ 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}
+\begin{verbatim}
[PATHS]
GNUNET_HOME = ~/gnunet1/ # Use this directory to store GNUnet data
[hostlist]
SERVERS = # prevent bootstrapping
-\end{lstlisting}
+\end{verbatim}
\subsection{Start a peer}
@@ -322,6 +342,7 @@ $ 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:
+\lstset{language=bash}
\begin{lstlisting}
$ cd ~/gnunet/src/dht
$ ./gnunet-dht-put -c ~/peer1.conf -k KEY -d VALUE # put VALUE under KEY in the DHT
@@ -348,6 +369,7 @@ To configure the second peer, use the files {\tt
configuration file:
%
\lstset{language=bash}
+\lstset{language=bash}
\begin{lstlisting}
$ cat $PREFIX/share/gnunet/config.d/*.conf > peer2.conf
\end{lstlisting}
@@ -399,10 +421,10 @@ If you want the two peers to connect, you have multiple options:
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}
+ \begin{verbatim}
[hostlist]
OPTIONS = -p
-\end{lstlisting}
+\end{verbatim}
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:
@@ -432,6 +454,7 @@ If you want to use the \texttt{peerinfo} tool to connect your peers, you should:
Check that they are connected using {\tt gnunet-core -c peer1.conf}, which should give you the other peer's
peer identity:
+\lstset{language=bash}
\begin{lstlisting}
$ gnunet-core -c peer1.conf
Peer `9TVUCS8P5A7ILLBGO6 [...shortened...] 1KNBJ4NGCHP3JPVULDG'
@@ -463,7 +486,8 @@ 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}
+\lstset{language=C}
+\lstinputlisting{testbed_test.c}
The source code for the above listing can be found at
\url{https://gnunet.org/git/gnunet.git/tree/doc/testbed_test.c}
or in the {\tt doc/} folder of your repository check-out.
@@ -593,7 +617,7 @@ command-line options, setup the scheduler and then invoke the {\tt
to the parsed configuration (and the configuration file name that was
used, which is typically not needed):
-\lstset{language=c}
+\lstset{language=C}
\begin{lstlisting}
#include <gnunet/platform.h>
#include <gnunet/gnunet_util_lib.h>
@@ -606,7 +630,7 @@ run (void *cls,
const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *cfg)
{
- /* main code here */
+ // main code here
ret = 0;
}
@@ -632,6 +656,7 @@ expanding the {\tt options} array. For example, the following would
add a string-option and a binary flag (defaulting to {\tt NULL} and
{\tt GNUNET\_NO} respectively):
+\lstset{language=C}
\begin{lstlisting}
static char *string_option;
static int a_flag;
@@ -696,7 +721,7 @@ file).
Before a client library can implement the application-specific protocol
with the service, a connection must be created:
-\lstset{language=c}
+\lstset{language=C}
\begin{lstlisting}
struct GNUNET_MQ_MessageHandlers handlers[] = {
// ...
@@ -723,36 +748,26 @@ In GNUnet, messages are always sent beginning with a {\tt struct GNUNET\_Message
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
{
-
- /**
- * The length of the struct (in bytes, including the length field itself),
- * in big-endian format.
- */
uint16_t size GNUNET_PACKED;
-
- /**
- * The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
- */
uint16_t type GNUNET_PACKED;
-
};
\end{lstlisting}
Existing message types are defined in {\tt gnunet\_protocols.h}\\
A common way to create a message is with an envelope:
-\lstset{language=c}
+\lstset{language=C}
\begin{lstlisting}
struct GNUNET_MQ_Envelope *env;
struct GNUNET_MessageHeader *msg;
env = GNUNET_MQ_msg_extra (msg, payload_size, GNUNET_MY_MESSAGE_TYPE);
memcpy (&msg[1], &payload, payload_size);
-/* Send message via message queue 'mq': */
+// Send message via message queue 'mq'
GNUNET_mq_send (mq, env);
\end{lstlisting}
@@ -785,38 +800,19 @@ and {\tt handle\_} are mandatory.
\lstset{language=c}
\begin{lstlisting}
-/**
- * Function called with MyMessage messages from service.
- *
- * @param cls closure
- * @param msg message received
- */
static void
handle_fix (void *cls, const struct MyMessage *msg)
{
// process 'msg'
}
-/**
- * Function called with MyVarMessage messages from service.
- *
- * @param cls closure
- * @param msg message received
- * @return #GNUNET_OK if @a msg is well-formed
- */
static int
check_var (void *cls, const struct MyVarMessage *msg)
{
// check 'msg' is well-formed
- return GNUNET_OK; /* suppose yes */
+ return GNUNET_OK;
}
-/**
- * Function called with MyMessage messages from service.
- *
- * @param cls closure
- * @param msg message received
- */
static void
handle_var (void *cls, const struct MyVarMessage *msg)
{
@@ -900,13 +896,6 @@ like this:
\lstset{language=c}
\begin{lstlisting}
-/**
- * Launch service.
- *
- * @param cls closure
- * @param c configuration to use
- * @param service the initialized service
- */
static void
run (void *cls,
const struct GNUNET_CONFIGURATION_Handle *c,
@@ -914,14 +903,6 @@ run (void *cls,
{
}
-/**
- * Callback called when a client connects to the service.
- *
- * @param cls closure for the service
- * @param c the new client that connected to the service
- * @param mq the message queue used to send messages to the client
- * @return @a c
- */
static void *
client_connect_cb (void *cls,
struct GNUNET_SERVICE_Client *c,
@@ -930,13 +911,6 @@ client_connect_cb (void *cls,
return c;
}
-/**
- * Callback called when a client disconnected from the service
- *
- * @param cls closure for the service
- * @param c the client that disconnected
- * @param internal_cls should be equal to @a c
- */
static void
client_disconnect_cb (void *cls,
struct GNUNET_SERVICE_Client *c,
@@ -988,11 +962,7 @@ GNUNET_CORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
GNUNET_CORE_StartupCallback init,
GNUNET_CORE_ConnectEventHandler connects,
GNUNET_CORE_DisconnectEventHandler disconnects,
- GNUNET_CORE_MessageCallback inbound_notify,
- int inbound_hdr_only,
- GNUNET_CORE_MessageCallback outbound_notify,
- int outbound_hdr_only,
- const struct GNUNET_CORE_MessageHandler *handlers);
+ const struct GNUNET_MQ_MessageHandler *handlers);
\end{lstlisting}
\subsection{New P2P connections}
@@ -1003,45 +973,33 @@ which communicates the identity of the new peer to the service:
\lstset{language=C}
\begin{lstlisting}
-void
+void *
connects (void *cls,
- const struct GNUNET_PeerIdentity * peer)
+ const struct GNUNET_PeerIdentity *peer,
+ struct GNUNET_MQ_Handle *mq)
{
- /* Save identity for later use */
- /* Optional: start sending messages to peer */
+ return mq;
}
\end{lstlisting}
+Note that whatever you return from {\tt connects} is given as the
+{\it cls} argument to the message handlers for messages from
+the respective peer.
+
\exercise{Create a service that connects to the \texttt{CORE}. Then
start (and connect) two peers and print a message once your connect
callback is invoked.}
\subsection{Receiving P2P Messages}
-To receive messages from \texttt{CORE}, services register a set of handlers
-(parameter {\tt *handlers} in the \lstinline|GNUNET_CORE_connect| call that are called by \texttt{CORE}
-when a suitable message arrives.
+To receive messages from \texttt{CORE}, you pass the desired
+{\em handlers} to the {\tt GNUNET\_CORE\_connect()} function,
+just as we showed for services.
-\lstset{language=c}
-\begin{lstlisting}
-static int
-callback_function_for_type_one(void *cls,
- const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_MessageHeader *message)
-{
- /* Do stuff */
- return GNUNET_OK; /* or GNUNET_SYSERR to close the connection */
-}
-
-/**
- * Functions to handle messages from core
- */
-static struct GNUNET_CORE_MessageHandler core_handlers[] = {
- {&callback_function_for_type_one, GNUNET_MESSAGE_TYPE_MYSERVICE_TYPE_ONE, 0},
- /* more handlers*/
- {NULL, 0, 0}
-};
-\end{lstlisting}
+It is your responsibility to process messages fast enough or
+to implement flow control. If an application does not process
+CORE messages fast enough, CORE will randomly drop messages
+to not keep a very long queue in memory.
\exercise{Start one peer with a new service that has a message
handler and start a second peer that only has your ``old'' service
@@ -1051,29 +1009,13 @@ the two peers are connected? Why?}
\subsection{Sending P2P Messages}
-In response to events (connect, disconnect, inbound messages,
-timing, etc.) services can then use this API to transmit messages:
+You can transmit messages to other peers using the {\it mq} you were
+given during the {\tt connect} callback. Note that the {\it mq}
+automatically is released upon {\tt disconnect} and that you must
+not use it afterwards.
-\lstset{language=C}
-\begin{lstlisting}
-typedef size_t
-(*GNUNET_CONNECTION_TransmitReadyNotify) (void *cls,
- size_t size,
- void *buf)
-{
- /* Fill "*buf" with up to "size" bytes, must start with GNUNET_MessageHeader */
- return n; /* Total size of the message put in "*buf" */
-}
-
-struct GNUNET_CORE_TransmitHandle *
-GNUNET_CORE_notify_transmit_ready (struct GNUNET_CORE_Handle *handle,
- int cork, uint32_t priority,
- struct GNUNET_TIME_Relative maxdelay,
- const struct GNUNET_PeerIdentity *target,
- size_t notify_size,
- GNUNET_CONNECTION_TransmitReadyNotify notify,
- void *notify_cls);
-\end{lstlisting}
+It is your responsibility to not over-fill the message queue, GNUnet
+will send the messages roughly in the order given as soon as possible.
\exercise{Write a service that upon connect sends messages as
fast as possible to the other peer (the other peer should run a
@@ -1258,22 +1200,21 @@ and other unfavorable events, just make several PUT requests!
\lstset{language=C}
\begin{lstlisting}
-void
+static void
message_sent_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- /* Request has left local node */
+ // Request has left local node
}
struct GNUNET_DHT_PutHandle *
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 */
+ enum GNUNET_DHT_RouteOption options,
enum GNUNET_BLOCK_Type type, size_t size, const void *data,
- struct GNUNET_TIME_Absolute exp, /* When does the data expire? */
- struct GNUNET_TIME_Relative timeout, /* How long to try to send the request */
- GNUNET_DHT_PutContinuation cont,
- void *cont_cls)
+ struct GNUNET_TIME_Absolute exp,
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_DHT_PutContinuation cont, void *cont_cls)
\end{lstlisting}
\exercise{Store a value in the DHT periodically to make sure it is available
@@ -1305,9 +1246,8 @@ get_result_iterator (void *cls, struct GNUNET_TIME_Absolute expiration,
unsigned int put_path_length,
enum GNUNET_BLOCK_Type type, size_t size, const void *data)
{
- /* Do stuff with the data and/or route */
- /* Optionally: */
- GNUNET_DHT_get_stop (get_handle);
+ // Optionally:
+ GNUNET_DHT_get_stop (get_handle);
}
get_handle =
@@ -1315,9 +1255,9 @@ get_handle =
block_type,
&key,
replication,
- GNUNET_DHT_RO_NONE, /* Route options */
- NULL, /* xquery: not used here */
- 0, /* xquery size */
+ GNUNET_DHT_RO_NONE,
+ NULL,
+ 0,
&get_result_iterator,
cls)
\end{lstlisting}
@@ -1356,13 +1296,13 @@ static enum GNUNET_BLOCK_EvaluationResult
block_plugin_SERVICE_evaluate (void *cls,
enum GNUNET_BLOCK_Type type,
struct GNUNET_BlockGroup *bg,
- const GNUNET_HashCode *query,
- const void *xquery,
- size_t xquery_size,
- const void *reply_block,
- size_t reply_block_size)
+ const GNUNET_HashCode *query,
+ const void *xquery,
+ size_t xquery_size,
+ const void *reply_block,
+ size_t reply_block_size)
{
- /* Verify type, block and bg */
+ // Verify type, block and bg
}
\end{lstlisting}
@@ -1385,10 +1325,10 @@ just fine with such blocks).
\begin{lstlisting}
static int
block_plugin_SERVICE_get_key (void *cls, enum GNUNET_BLOCK_Type type,
- const void *block, size_t block_size,
- struct GNUNET_HashCode *key)
+ const void *block, size_t block_size,
+ struct GNUNET_HashCode *key)
{
- /* Store the key in the key argument, return GNUNET_OK on success. */
+ // Store the key in the key argument, return GNUNET_OK on success.
}
\end{lstlisting}
@@ -1407,8 +1347,8 @@ libgnunet_plugin_block_SERVICE_init (void *cls)
{
static enum GNUNET_BLOCK_Type types[] =
{
- GNUNET_BLOCK_TYPE_SERVICE_BLOCKYPE, /* list of blocks we care about, from gnunet_block_lib.h */
- GNUNET_BLOCK_TYPE_ANY /* end of list */
+ GNUNET_BLOCK_TYPE_SERVICE_BLOCKYPE,
+ GNUNET_BLOCK_TYPE_ANY
};
struct GNUNET_BLOCK_PluginFunctions *api;
@@ -1483,7 +1423,7 @@ to allow for filtering of messages. When an event happens, the appropiate callba
is called with all the information about the event.
\lstset{language=C}
\begin{lstlisting}
-void
+static void
get_callback (void *cls,
enum GNUNET_DHT_RouteOption options,
enum GNUNET_BLOCK_Type type,
@@ -1495,7 +1435,8 @@ get_callback (void *cls,
{
}
-void
+
+static void
get_resp_callback (void *cls,
enum GNUNET_BLOCK_Type type,
const struct GNUNET_PeerIdentity *get_path,
@@ -1509,7 +1450,8 @@ get_resp_callback (void *cls,
{
}
-void
+
+static void
put_callback (void *cls,
enum GNUNET_DHT_RouteOption options,
enum GNUNET_BLOCK_Type type,
@@ -1524,13 +1466,14 @@ put_callback (void *cls,
{
}
+
monitor_handle = GNUNET_DHT_monitor_start (dht_handle,
- block_type, /* GNUNET_BLOCK_TYPE_ANY for all */
- key, /* NULL for all */
- &get_callback,
- &get_resp_callback,
- &put_callback,
- cls);
+ block_type,
+ key,
+ &get_callback,
+ &get_resp_callback,
+ &put_callback,
+ cls);
\end{lstlisting}
diff --git a/doc/testbed_test.c b/doc/testbed_test.c
index 0ef0980af0..1696234b05 100644
--- a/doc/testbed_test.c
+++ b/doc/testbed_test.c
@@ -4,65 +4,35 @@
#include <gnunet/gnunet_testbed_service.h>
#include <gnunet/gnunet_dht_service.h>
-/* Number of peers we want to start */
#define NUM_PEERS 20
static struct GNUNET_TESTBED_Operation *dht_op;
static struct GNUNET_DHT_Handle *dht_handle;
-static struct GNUNET_SCHEDULER_Task * shutdown_tid;
-
-/**
- * Closure to 'dht_ca' and 'dht_da' DHT adapters.
- */
struct MyContext
{
- /**
- * Argument we pass to GNUNET_DHT_connect.
- */
int ht_len;
} ctxt;
-/**
- * Global result for testcase.
- */
static int result;
-/**
- * Function run on CTRL-C or shutdown (i.e. success/timeout/etc.).
- * Cleans up.
- */
static void
shutdown_task (void *cls)
{
- shutdown_tid = NULL;
if (NULL != dht_op)
{
- GNUNET_TESTBED_operation_done (dht_op); /* indirectly calls the dht_da() for closing
- down the connection to the DHT */
+ GNUNET_TESTBED_operation_done (dht_op);
dht_op = NULL;
dht_handle = NULL;
}
result = GNUNET_OK;
- GNUNET_SCHEDULER_shutdown (); /* Also kills the testbed */
}
-/**
- * This is where the test logic should be, at least that
- * part of it that uses the DHT of peer "0".
- *
- * @param cls closure, for the example: NULL
- * @param op should be equal to "dht_op"
- * @param ca_result result of the connect operation, the
- * connection to the DHT service
- * @param emsg error message, if testbed somehow failed to
- * connect to the DHT.
- */
static void
service_connect_comp (void *cls,
struct GNUNET_TESTBED_Operation *op,
@@ -71,72 +41,31 @@ service_connect_comp (void *cls,
{
GNUNET_assert (op == dht_op);
dht_handle = ca_result;
- /* Service to DHT successful; here we'd usually do something
- with the DHT (ok, if successful) */
-
- /* for now, just indiscriminately terminate after 10s */
- GNUNET_SCHEDULER_cancel (shutdown_tid);
- shutdown_tid = GNUNET_SCHEDULER_add_delayed
- (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
- &shutdown_task, NULL);
+ // Do work here...
+ GNUNET_SCHEDULER_shutdown ();
}
-/**
- * Testbed has provided us with the configuration to access one
- * of the peers and it is time to do "some" connect operation to
- * "some" subsystem of the peer. For this example, we connect
- * to the DHT subsystem. Testbed doesn't know which subsystem,
- * so we need these adapters to do the actual connecting (and
- * possibly pass additional options to the subsystem connect
- * function, such as the "ht_len" argument for the DHT).
- *
- * @param cls closure
- * @param cfg peer configuration (here: peer[0]
- * @return NULL on error, otherwise some handle to access the
- * subsystem
- */
static void *
dht_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
struct MyContext *ctxt = cls;
- /* Use the provided configuration to connect to service */
dht_handle = GNUNET_DHT_connect (cfg, ctxt->ht_len);
return dht_handle;
}
-/**
- * Dual of 'dht_ca' to perform the 'disconnect'/cleanup operation
- * once we no longer need to access this subsystem.
- *
- * @param cls closure
- * @param op_result whatever we returned from 'dht_ca'
- */
static void
dht_da (void *cls, void *op_result)
{
struct MyContext *ctxt = cls;
- /* Disconnect from DHT service */
GNUNET_DHT_disconnect ((struct GNUNET_DHT_Handle *) op_result);
dht_handle = NULL;
}
-/**
- * Main function inovked from TESTBED once all of the
- * peers are up and running. This one then connects
- * just to the DHT service of peer 0.
- *
- * @param cls closure
- * @param h the run handle
- * @param peers started peers for the test
- * @param num_peers size of the 'peers' array
- * @param links_succeeded number of links between peers that were created
- * @param links_failed number of links testbed was unable to establish
- */
static void
test_master (void *cls,
struct GNUNET_TESTBED_RunHandle *h,
@@ -145,27 +74,12 @@ test_master (void *cls,
unsigned int links_succeeded,
unsigned int links_failed)
{
- /* Testbed is ready with peers running and connected in a pre-defined overlay
- topology */
-
- /* do something */
ctxt.ht_len = 10;
-
- /* connect to a peers service */
dht_op = GNUNET_TESTBED_service_connect
- (NULL, /* Closure for operation */
- peers[0], /* The peer whose service to connect to */
- "dht", /* The name of the service */
- service_connect_comp, /* callback to call after a handle to service
- is opened */
- NULL, /* closure for the above callback */
- dht_ca, /* callback to call with peer's configuration;
- this should open the needed service connection */
- dht_da, /* callback to be called when closing the
- opened service connection */
- &ctxt); /* closure for the above two callbacks */
- shutdown_tid = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
- &shutdown_task, NULL);
+ (NULL, peers[0], "dht",
+ &service_connect_comp, NULL,
+ &dht_ca, &dht_da, &ctxt);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
}
@@ -176,15 +90,9 @@ main (int argc, char **argv)
result = GNUNET_SYSERR;
ret = GNUNET_TESTBED_test_run
- ("awesome-test", /* test case name */
- "template.conf", /* template configuration */
- NUM_PEERS, /* number of peers to start */
- 0LL, /* Event mask - set to 0 for no event notifications */
- NULL, /* Controller event callback */
- NULL, /* Closure for controller event callback */
- &test_master, /* continuation callback to be called when testbed setup is
- complete */
- NULL); /* Closure for the test_master callback */
+ ("awesome-test", "template.conf",
+ NUM_PEERS, 0LL,
+ NULL, NULL, &test_master, NULL);
if ( (GNUNET_OK != ret) || (GNUNET_OK != result) )
return 1;
return 0;
diff --git a/src/arm/gnunet-arm.c b/src/arm/gnunet-arm.c
index 65a6463cfb..49886eb56e 100644
--- a/src/arm/gnunet-arm.c
+++ b/src/arm/gnunet-arm.c
@@ -220,14 +220,8 @@ req_string (enum GNUNET_ARM_RequestStatus rs)
{
case GNUNET_ARM_REQUEST_SENT_OK:
return _("Message was sent successfully");
- case GNUNET_ARM_REQUEST_CONFIGURATION_ERROR:
- return _("Misconfiguration (can not connect to the ARM service)");
case GNUNET_ARM_REQUEST_DISCONNECTED:
return _("We disconnected from ARM before we could send a request");
- case GNUNET_ARM_REQUEST_BUSY:
- return _("ARM API is busy");
- case GNUNET_ARM_REQUEST_TIMEOUT:
- return _("Request timed out");
}
return _("Unknown request status");
}
@@ -245,27 +239,27 @@ ret_string (enum GNUNET_ARM_Result result)
switch (result)
{
case GNUNET_ARM_RESULT_STOPPED:
- return _("%s is stopped");
+ return _("is stopped");
case GNUNET_ARM_RESULT_STARTING:
- return _("%s is starting");
+ return _("is starting");
case GNUNET_ARM_RESULT_STOPPING:
- return _("%s is stopping");
+ return _("is stopping");
case GNUNET_ARM_RESULT_IS_STARTING_ALREADY:
- return _("%s is starting already");
+ return _("is starting already");
case GNUNET_ARM_RESULT_IS_STOPPING_ALREADY:
- return _("%s is stopping already");
+ return _("is stopping already");
case GNUNET_ARM_RESULT_IS_STARTED_ALREADY:
- return _("%s is started already");
+ return _("is started already");
case GNUNET_ARM_RESULT_IS_STOPPED_ALREADY:
- return _("%s is stopped already");
+ return _("is stopped already");
case GNUNET_ARM_RESULT_IS_NOT_KNOWN:
- return _("%s service is not known to ARM");
+ return _("service is not known to ARM");
case GNUNET_ARM_RESULT_START_FAILED:
- return _("%s service failed to start");
+ return _("service failed to start");
case GNUNET_ARM_RESULT_IN_SHUTDOWN:
- return _("%s service cannot be started because ARM is shutting down");
+ return _("service cannot be manipulated because ARM is shutting down");
}
- return _("%.s Unknown result code.");
+ return _("Unknown result code.");
}
@@ -378,10 +372,9 @@ stop_callback (void *cls,
(GNUNET_ARM_RESULT_STOPPED != result) &&
(GNUNET_ARM_RESULT_IS_STOPPED_ALREADY != result))
{
- GNUNET_asprintf (&msg, "%s",
- _("Failed to stop the ARM service: %s\n"));
- FPRINTF (stdout, msg, ret_string (result));
- GNUNET_free (msg);
+ FPRINTF (stdout,
+ _("Failed to stop the ARM service: %s\n"),
+ ret_string (result));
GNUNET_SCHEDULER_shutdown ();
return;
}
@@ -476,11 +469,10 @@ term_callback (void *cls,
if ((GNUNET_ARM_RESULT_STOPPED != result) &&
(GNUNET_ARM_RESULT_IS_STOPPED_ALREADY != result))
{
- GNUNET_asprintf (&msg,
- _("Failed to kill the `%s' service: %s\n"),
- term, ret_string (result));
- FPRINTF (stdout, "%s", msg);
- GNUNET_free (msg);
+ FPRINTF (stdout,
+ _("Failed to kill the `%s' service: %s\n"),
+ term,
+ ret_string (result));
GNUNET_SCHEDULER_shutdown ();
return;
}
diff --git a/src/consensus/Makefile.am b/src/consensus/Makefile.am
index 2b1987fbcb..c0205ee5dc 100644
--- a/src/consensus/Makefile.am
+++ b/src/consensus/Makefile.am
@@ -18,8 +18,6 @@ if USE_COVERAGE
AM_CFLAGS = -fprofile-arcs -ftest-coverage
endif
-bin_PROGRAMS = \
- gnunet-consensus-profiler
libexec_PROGRAMS = \
gnunet-service-consensus
@@ -86,6 +84,9 @@ libgnunet_plugin_block_consensus_la_LDFLAGS = \
if HAVE_TESTING
+bin_PROGRAMS = \
+ gnunet-consensus-profiler
+
check_PROGRAMS = \
test_consensus_api
diff --git a/src/fs/fs_directory.c b/src/fs/fs_directory.c
index a18a903bed..514eb64b3b 100644
--- a/src/fs/fs_directory.c
+++ b/src/fs/fs_directory.c
@@ -170,13 +170,14 @@ find_full_data (void *cls, const char *plugin_name,
* @param data pointer to the beginning of the directory
* @param offset offset of data in the directory
* @param dep function to call on each entry
- * @param dep_cls closure for dep
- * @return GNUNET_OK if this could be a block in a directory,
- * GNUNET_NO if this could be part of a directory (but not 100% OK)
- * GNUNET_SYSERR if 'data' does not represent a directory
+ * @param dep_cls closure for @a dep
+ * @return #GNUNET_OK if this could be a block in a directory,
+ * #GNUNET_NO if this could be part of a directory (but not 100% OK)
+ * #GNUNET_SYSERR if @a data does not represent a directory
*/
int
-GNUNET_FS_directory_list_contents (size_t size, const void *data,
+GNUNET_FS_directory_list_contents (size_t size,
+ const void *data,
uint64_t offset,
GNUNET_FS_DirectoryEntryProcessor dep,
void *dep_cls)
@@ -194,12 +195,16 @@ GNUNET_FS_directory_list_contents (size_t size, const void *data,
if ((offset == 0) &&
((size < 8 + sizeof (uint32_t)) ||
- (0 != memcmp (cdata, GNUNET_FS_DIRECTORY_MAGIC, 8))))
+ (0 != memcmp (cdata,
+ GNUNET_FS_DIRECTORY_MAGIC,
+ 8))))
return GNUNET_SYSERR;
pos = offset;
if (offset == 0)
{
- GNUNET_memcpy (&mdSize, &cdata[8], sizeof (uint32_t));
+ GNUNET_memcpy (&mdSize,
+ &cdata[8],
+ sizeof (uint32_t));
mdSize = ntohl (mdSize);
if (mdSize > size - 8 - sizeof (uint32_t))
{
@@ -215,7 +220,12 @@ GNUNET_FS_directory_list_contents (size_t size, const void *data,
GNUNET_break (0);
return GNUNET_SYSERR; /* malformed ! */
}
- dep (dep_cls, NULL, NULL, md, 0, NULL);
+ dep (dep_cls,
+ NULL,
+ NULL,
+ md,
+ 0,
+ NULL);
GNUNET_CONTAINER_meta_data_destroy (md);
pos = 8 + sizeof (uint32_t) + mdSize;
}
@@ -247,7 +257,7 @@ GNUNET_FS_directory_list_contents (size_t size, const void *data,
uri = GNUNET_FS_uri_parse (&cdata[pos], &emsg);
pos = epos + 1;
- if (uri == NULL)
+ if (NULL == uri)
{
GNUNET_free (emsg);
pos--; /* go back to '\0' to force going to next alignment */
@@ -260,7 +270,9 @@ GNUNET_FS_directory_list_contents (size_t size, const void *data,
return GNUNET_NO; /* illegal in directory! */
}
- GNUNET_memcpy (&mdSize, &cdata[pos], sizeof (uint32_t));
+ GNUNET_memcpy (&mdSize,
+ &cdata[pos],
+ sizeof (uint32_t));
mdSize = ntohl (mdSize);
pos += sizeof (uint32_t);
if (pos + mdSize > size)
@@ -269,8 +281,9 @@ GNUNET_FS_directory_list_contents (size_t size, const void *data,
return GNUNET_NO; /* malformed - or partial download */
}
- md = GNUNET_CONTAINER_meta_data_deserialize (&cdata[pos], mdSize);
- if (md == NULL)
+ md = GNUNET_CONTAINER_meta_data_deserialize (&cdata[pos],
+ mdSize);
+ if (NULL == md)
{
GNUNET_FS_uri_destroy (uri);
GNUNET_break (0);
@@ -282,10 +295,17 @@ GNUNET_FS_directory_list_contents (size_t size, const void *data,
EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME);
full_data.size = 0;
full_data.data = NULL;
- GNUNET_CONTAINER_meta_data_iterate (md, &find_full_data, &full_data);
- if (dep != NULL)
+ GNUNET_CONTAINER_meta_data_iterate (md,
+ &find_full_data,
+ &full_data);
+ if (NULL != dep)
{
- dep (dep_cls, filename, uri, md, full_data.size, full_data.data);
+ dep (dep_cls,
+ filename,
+ uri,
+ md,
+ full_data.size,
+ full_data.data);
}
GNUNET_free_non_null (full_data.data);
GNUNET_free_non_null (filename);
@@ -548,11 +568,12 @@ block_align (size_t start, unsigned int count, const size_t * sizes,
* @param bld directory to finish
* @param rsize set to the number of bytes needed
* @param rdata set to the encoded directory
- * @return GNUNET_OK on success
+ * @return #GNUNET_OK on success
*/
int
GNUNET_FS_directory_builder_finish (struct GNUNET_FS_DirectoryBuilder *bld,
- size_t * rsize, void **rdata)
+ size_t * rsize,
+ void **rdata)
{
char *data;
char *sptr;
@@ -575,9 +596,12 @@ GNUNET_FS_directory_builder_finish (struct GNUNET_FS_DirectoryBuilder *bld,
bes = NULL;
if (0 < bld->count)
{
- sizes = GNUNET_malloc (bld->count * sizeof (size_t));
- perm = GNUNET_malloc (bld->count * sizeof (unsigned int));
- bes = GNUNET_malloc (bld->count * sizeof (struct BuilderEntry *));
+ sizes = GNUNET_new_array (bld->count,
+ size_t);
+ perm = GNUNET_new_array (bld->count,
+ unsigned int);
+ bes = GNUNET_new_array (bld->count,
+ struct BuilderEntry *);
pos = bld->head;
for (i = 0; i < bld->count; i++)
{
@@ -599,7 +623,8 @@ GNUNET_FS_directory_builder_finish (struct GNUNET_FS_DirectoryBuilder *bld,
data = GNUNET_malloc_large (size);
if (data == NULL)
{
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "malloc");
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
+ "malloc");
*rsize = 0;
*rdata = NULL;
GNUNET_free_non_null (sizes);
@@ -608,17 +633,22 @@ GNUNET_FS_directory_builder_finish (struct GNUNET_FS_DirectoryBuilder *bld,
return GNUNET_SYSERR;
}
*rdata = data;
- GNUNET_memcpy (data, GNUNET_DIRECTORY_MAGIC, strlen (GNUNET_DIRECTORY_MAGIC));
+ GNUNET_memcpy (data,
+ GNUNET_DIRECTORY_MAGIC,
+ strlen (GNUNET_DIRECTORY_MAGIC));
off = strlen (GNUNET_DIRECTORY_MAGIC);
sptr = &data[off + sizeof (uint32_t)];
ret =
- GNUNET_CONTAINER_meta_data_serialize (bld->meta, &sptr,
+ GNUNET_CONTAINER_meta_data_serialize (bld->meta,
+ &sptr,
size - off - sizeof (uint32_t),
GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL);
GNUNET_assert (ret != -1);
big = htonl (ret);
- GNUNET_memcpy (&data[off], &big, sizeof (uint32_t));
+ GNUNET_memcpy (&data[off],
+ &big,
+ sizeof (uint32_t));
off += sizeof (uint32_t) + ret;
for (j = 0; j < bld->count; j++)
{
diff --git a/src/fs/fs_download.c b/src/fs/fs_download.c
index 0789162bf9..ce852f2d0b 100644
--- a/src/fs/fs_download.c
+++ b/src/fs/fs_download.c
@@ -37,14 +37,14 @@ static int
is_recursive_download (struct GNUNET_FS_DownloadContext *dc)
{
return (0 != (dc->options & GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE)) &&
- ((GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (dc->meta)) ||
- ((NULL == dc->meta) &&
- ((NULL == dc->filename) ||
- ((strlen (dc->filename) >= strlen (GNUNET_FS_DIRECTORY_EXT)) &&
- (NULL !=
- strstr (dc->filename + strlen (dc->filename) -
- strlen (GNUNET_FS_DIRECTORY_EXT),
- GNUNET_FS_DIRECTORY_EXT))))));
+ ( (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (dc->meta)) ||
+ ( (NULL == dc->meta) &&
+ ( (NULL == dc->filename) ||
+ ( (strlen (dc->filename) >= strlen (GNUNET_FS_DIRECTORY_EXT)) &&
+ (NULL !=
+ strstr (dc->filename + strlen (dc->filename) -
+ strlen (GNUNET_FS_DIRECTORY_EXT),
+ GNUNET_FS_DIRECTORY_EXT)) ) ) ) );
}
@@ -278,10 +278,12 @@ try_reconnect (struct GNUNET_FS_DownloadContext *dc);
* @param data contents of the file (or NULL if they were not inlined)
*/
static void
-trigger_recursive_download (void *cls, const char *filename,
+trigger_recursive_download (void *cls,
+ const char *filename,
const struct GNUNET_FS_Uri *uri,
const struct GNUNET_CONTAINER_MetaData *meta,
- size_t length, const void *data);
+ size_t length,
+ const void *data);
/**
@@ -304,24 +306,28 @@ full_recursive_download (struct GNUNET_FS_DownloadContext *dc)
if (size64 != (uint64_t) size)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _
- ("Recursive downloads of directories larger than 4 GB are not supported on 32-bit systems\n"));
+ _("Recursive downloads of directories larger than 4 GB are not supported on 32-bit systems\n"));
return;
}
if (NULL != dc->filename)
{
- h = GNUNET_DISK_file_open (dc->filename, GNUNET_DISK_OPEN_READ,
+ h = GNUNET_DISK_file_open (dc->filename,
+ GNUNET_DISK_OPEN_READ,
GNUNET_DISK_PERM_NONE);
}
else
{
GNUNET_assert (NULL != dc->temp_filename);
- h = GNUNET_DISK_file_open (dc->temp_filename, GNUNET_DISK_OPEN_READ,
+ h = GNUNET_DISK_file_open (dc->temp_filename,
+ GNUNET_DISK_OPEN_READ,
GNUNET_DISK_PERM_NONE);
}
if (NULL == h)
return; /* oops */
- data = GNUNET_DISK_file_map (h, &m, GNUNET_DISK_MAP_TYPE_READ, size);
+ data = GNUNET_DISK_file_map (h,
+ &m,
+ GNUNET_DISK_MAP_TYPE_READ,
+ size);
if (NULL == data)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -329,15 +335,25 @@ full_recursive_download (struct GNUNET_FS_DownloadContext *dc)
}
else
{
- GNUNET_FS_directory_list_contents (size, data, 0,
- &trigger_recursive_download, dc);
+ if (GNUNET_OK !=
+ GNUNET_FS_directory_list_contents (size,
+ data,
+ 0,
+ &trigger_recursive_download,
+ dc))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Failed to access full directroy contents of `%s' for recursive download\n"),
+ dc->filename);
+ }
GNUNET_DISK_file_unmap (m);
}
GNUNET_DISK_file_close (h);
if (NULL == dc->filename)
{
if (0 != UNLINK (dc->temp_filename))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink",
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
+ "unlink",
dc->temp_filename);
GNUNET_free (dc->temp_filename);
dc->temp_filename = NULL;
@@ -362,14 +378,16 @@ check_completed (struct GNUNET_FS_DownloadContext *dc)
struct GNUNET_FS_DownloadContext *pos;
/* first, check if we need to download children */
- if ((NULL == dc->child_head) && (is_recursive_download (dc)))
+ if (is_recursive_download (dc))
full_recursive_download (dc);
/* then, check if children are done already */
for (pos = dc->child_head; NULL != pos; pos = pos->next)
{
- if ((pos->emsg == NULL) && (pos->completed < pos->length))
+ if ( (NULL == pos->emsg) &&
+ (pos->completed < pos->length) )
return; /* not done yet */
- if ((pos->child_head != NULL) && (pos->has_finished != GNUNET_YES))
+ if ( (NULL != pos->child_head) &&
+ (pos->has_finished != GNUNET_YES) )
return; /* not transitively done yet */
}
/* All of our children are done, so mark this download done */
@@ -471,7 +489,11 @@ try_match_block (struct GNUNET_FS_DownloadContext *dc,
}
GNUNET_CRYPTO_hash (&data[dr->offset], dlen, &in_chk.key);
GNUNET_CRYPTO_hash_to_aes_key (&in_chk.key, &sk, &iv);
- if (-1 == GNUNET_CRYPTO_symmetric_encrypt (&data[dr->offset], dlen, &sk, &iv, enc))
+ if (-1 == GNUNET_CRYPTO_symmetric_encrypt (&data[dr->offset],
+ dlen,
+ &sk,
+ &iv,
+ enc))
{
GNUNET_break (0);
return;
@@ -484,7 +506,9 @@ try_match_block (struct GNUNET_FS_DownloadContext *dc,
dr->state = BRS_RECONSTRUCT_META_UP;
break;
case BRS_CHK_SET:
- if (0 != memcmp (&in_chk, &dr->chk, sizeof (struct ContentHashKey)))
+ if (0 != memcmp (&in_chk,
+ &dr->chk,
+ sizeof (struct ContentHashKey)))
{
/* other peer provided bogus meta data */
GNUNET_break_op (0);
@@ -591,7 +615,10 @@ match_full_data (void *cls, const char *plugin_name,
GNUNET_break_op (0);
return 1; /* bogus meta data */
}
- try_match_block (dc, dc->top_request, data, data_len);
+ try_match_block (dc,
+ dc->top_request,
+ data,
+ data_len);
return 1;
}
@@ -820,10 +847,12 @@ schedule_block_download (struct GNUNET_FS_DownloadContext *dc,
* @param data contents of the file (or NULL if they were not inlined)
*/
static void
-trigger_recursive_download (void *cls, const char *filename,
+trigger_recursive_download (void *cls,
+ const char *filename,
const struct GNUNET_FS_Uri *uri,
const struct GNUNET_CONTAINER_MetaData *meta,
- size_t length, const void *data)
+ size_t length,
+ const void *data)
{
struct GNUNET_FS_DownloadContext *dc = cls;
struct GNUNET_FS_DownloadContext *cpos;
@@ -936,9 +965,17 @@ trigger_recursive_download (void *cls, const char *filename,
(unsigned long long) GNUNET_FS_uri_chk_get_file_size (uri),
(unsigned int)
GNUNET_CONTAINER_meta_data_get_serialized_size (meta));
- GNUNET_FS_download_start (dc->h, uri, meta, full_name, temp_name, 0,
+ GNUNET_FS_download_start (dc->h,
+ uri,
+ meta,
+ full_name,
+ temp_name,
+ 0,
GNUNET_FS_uri_chk_get_file_size (uri),
- dc->anonymity, dc->options, NULL, dc);
+ dc->anonymity,
+ dc->options,
+ NULL,
+ dc);
GNUNET_free_non_null (full_name);
GNUNET_free_non_null (temp_name);
GNUNET_free_non_null (fn);
@@ -953,11 +990,9 @@ trigger_recursive_download (void *cls, const char *filename,
void
GNUNET_FS_free_download_request_ (struct DownloadRequest *dr)
{
- unsigned int i;
-
if (NULL == dr)
return;
- for (i = 0; i < dr->num_children; i++)
+ for (unsigned int i = 0; i < dr->num_children; i++)
GNUNET_FS_free_download_request_ (dr->children[i]);
GNUNET_free_non_null (dr->children);
GNUNET_free (dr);
@@ -1509,13 +1544,17 @@ create_download_request (struct DownloadRequest *parent,
GNUNET_assert (dr->num_children > 0);
dr->children =
- GNUNET_malloc (dr->num_children * sizeof (struct DownloadRequest *));
+ GNUNET_new_array (dr->num_children,
+ struct DownloadRequest *);
for (i = 0; i < dr->num_children; i++)
{
dr->children[i] =
- create_download_request (dr, i + head_skip, depth - 1,
+ create_download_request (dr,
+ i + head_skip,
+ depth - 1,
dr_offset + (i + head_skip) * child_block_size,
- file_start_offset, desired_length);
+ file_start_offset,
+ desired_length);
}
return dr;
}
diff --git a/src/fs/fs_search.c b/src/fs/fs_search.c
index 3cbf2afefd..e31115f39b 100644
--- a/src/fs/fs_search.c
+++ b/src/fs/fs_search.c
@@ -1383,9 +1383,10 @@ GNUNET_FS_search_start_searching_ (struct GNUNET_FS_SearchContext *sc)
GNUNET_assert (0 != sc->uri->data.ksk.keywordCount);
anon = GNUNET_CRYPTO_ecdsa_key_get_anonymous ();
GNUNET_CRYPTO_ecdsa_key_get_public (anon, &anon_pub);
- sc->requests =
- GNUNET_malloc (sizeof (struct SearchRequestEntry) *
- sc->uri->data.ksk.keywordCount);
+ sc->requests
+ = GNUNET_new_array (sc->uri->data.ksk.keywordCount,
+ struct SearchRequestEntry);
+
for (i = 0; i < sc->uri->data.ksk.keywordCount; i++)
{
keyword = &sc->uri->data.ksk.keywords[i][1];
diff --git a/src/fs/fs_tree.c b/src/fs/fs_tree.c
index b3c6322031..e57e4e4943 100644
--- a/src/fs/fs_tree.c
+++ b/src/fs/fs_tree.c
@@ -285,9 +285,9 @@ GNUNET_FS_tree_encoder_create (struct GNUNET_FS_Handle *h, uint64_t size,
te->progress = progress;
te->cont = cont;
te->chk_tree_depth = GNUNET_FS_compute_depth (size);
- te->chk_tree =
- GNUNET_malloc (te->chk_tree_depth * CHK_PER_INODE *
- sizeof (struct ContentHashKey));
+ te->chk_tree
+ = GNUNET_new_array (te->chk_tree_depth * CHK_PER_INODE,
+ struct ContentHashKey);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Created tree encoder for file with %llu bytes and depth %u\n",
(unsigned long long) size,
diff --git a/src/fs/fs_unindex.c b/src/fs/fs_unindex.c
index a672b84d54..ad1499f00d 100644
--- a/src/fs/fs_unindex.c
+++ b/src/fs/fs_unindex.c
@@ -454,7 +454,8 @@ continue_after_remove (void *cls,
* Function called from datastore with result from us looking for
* a UBlock. There are four cases:
* 1) no result, means we move on to the next keyword
- * 2) UID is the same as the first UID, means we move on to next keyword
+ * 2) data hash is the same as an already seen data hash, means we move on to
+ * next keyword
* 3) UBlock for a different CHK, means we keep looking for more
* 4) UBlock is for our CHK, means we remove the block and then move
* on to the next keyword
diff --git a/src/fs/fs_uri.c b/src/fs/fs_uri.c
index fa27e6e9b8..11968b750e 100644
--- a/src/fs/fs_uri.c
+++ b/src/fs/fs_uri.c
@@ -309,7 +309,8 @@ uri_ksk_parse (const char *s,
}
iret = max;
dup = GNUNET_strdup (s);
- keywords = GNUNET_malloc (max * sizeof (char *));
+ keywords = GNUNET_new_array (max,
+ char *);
for (i = slen - 1; i >= (int) pos; i--)
{
if ((s[i] == '%') && (&s[i] == strstr (&s[i], "%22")))
@@ -937,7 +938,8 @@ GNUNET_FS_uri_ksk_merge (const struct GNUNET_FS_Uri *u1,
return NULL;
}
kc = u1->data.ksk.keywordCount;
- kl = GNUNET_malloc ((kc + u2->data.ksk.keywordCount) * sizeof (char *));
+ kl = GNUNET_new_array (kc + u2->data.ksk.keywordCount,
+ char *);
for (i = 0; i < u1->data.ksk.keywordCount; i++)
kl[i] = GNUNET_strdup (u1->data.ksk.keywords[i]);
for (i = 0; i < u2->data.ksk.keywordCount; i++)
@@ -991,8 +993,9 @@ GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri)
}
if (ret->data.ksk.keywordCount > 0)
{
- ret->data.ksk.keywords =
- GNUNET_malloc (ret->data.ksk.keywordCount * sizeof (char *));
+ ret->data.ksk.keywords
+ = GNUNET_new_array (ret->data.ksk.keywordCount,
+ char *);
for (i = 0; i < ret->data.ksk.keywordCount; i++)
ret->data.ksk.keywords[i] = GNUNET_strdup (uri->data.ksk.keywords[i]);
}
@@ -1078,7 +1081,8 @@ GNUNET_FS_uri_ksk_create (const char *keywords,
*emsg = GNUNET_strdup (_("Number of double-quotes not balanced!\n"));
return NULL;
}
- keywordarr = GNUNET_malloc (num_Words * sizeof (char *));
+ keywordarr = GNUNET_new_array (num_Words,
+ char *);
num_Words = 0;
inWord = 0;
pos = searchString;
@@ -1151,7 +1155,8 @@ GNUNET_FS_uri_ksk_create_from_args (unsigned int argc,
uri = GNUNET_new (struct GNUNET_FS_Uri);
uri->type = GNUNET_FS_URI_KSK;
uri->data.ksk.keywordCount = argc;
- uri->data.ksk.keywords = GNUNET_malloc (argc * sizeof (char *));
+ uri->data.ksk.keywords = GNUNET_new_array (argc,
+ char *);
for (i = 0; i < argc; i++)
{
keyword = argv[i];
@@ -1766,8 +1771,9 @@ GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData
}
/* x3 because there might be a normalized variant of every keyword,
plus theoretically one more for mime... */
- ret->data.ksk.keywords = GNUNET_malloc
- (sizeof (char *) * (ent + tok_keywords + paren_keywords) * 3);
+ ret->data.ksk.keywords
+ = GNUNET_new_array ((ent + tok_keywords + paren_keywords) * 3,
+ char *);
GNUNET_CONTAINER_meta_data_iterate (md, &gather_uri_data, ret);
}
if (tok_keywords > 0)
diff --git a/src/include/gnunet_arm_service.h b/src/include/gnunet_arm_service.h
index 7fb14d3ace..f8d71bd8b5 100644
--- a/src/include/gnunet_arm_service.h
+++ b/src/include/gnunet_arm_service.h
@@ -62,25 +62,9 @@ enum GNUNET_ARM_RequestStatus
GNUNET_ARM_REQUEST_SENT_OK = 0,
/**
- * Misconfiguration (can't connect to the ARM service).
- */
- GNUNET_ARM_REQUEST_CONFIGURATION_ERROR = 1,
-
- /**
* We disconnected from ARM, and request was not sent.
*/
- GNUNET_ARM_REQUEST_DISCONNECTED = 2,
-
- /**
- * ARM API is busy (probably trying to connect to ARM),
- * and request was not sent. Try again later.
- */
- GNUNET_ARM_REQUEST_BUSY = 3,
-
- /**
- * Request time ran out before we had a chance to send it.
- */
- GNUNET_ARM_REQUEST_TIMEOUT = 5
+ GNUNET_ARM_REQUEST_DISCONNECTED = 2
};
diff --git a/src/include/gnunet_configuration_lib.h b/src/include/gnunet_configuration_lib.h
index 746dea61fe..c1537e4f8a 100644
--- a/src/include/gnunet_configuration_lib.h
+++ b/src/include/gnunet_configuration_lib.h
@@ -281,8 +281,8 @@ GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
int
-GNUNET_CONFIGURATION_get_value_float (const struct GNUNET_CONFIGURATION_Handle
- *cfg, const char *section,
+GNUNET_CONFIGURATION_get_value_float (const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *section,
const char *option,
float *number);
@@ -454,9 +454,6 @@ GNUNET_CONFIGURATION_get_data (const struct GNUNET_CONFIGURATION_Handle *cfg,
size_t buf_size);
-
-
-
/**
* Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR"
* where either in the "PATHS" section or the environtment "FOO" is
diff --git a/src/include/gnunet_core_service.h b/src/include/gnunet_core_service.h
index 8136770b78..ace223c112 100644
--- a/src/include/gnunet_core_service.h
+++ b/src/include/gnunet_core_service.h
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- Copyright (C) 2009-2014, 2016 GNUnet e.V.
+ Copyright (C) 2009-2017 GNUnet e.V.
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
@@ -197,57 +197,6 @@ GNUNET_CORE_get_mq (const struct GNUNET_CORE_Handle *h,
/**
- * Handle for a transmission request.
- */
-struct GNUNET_CORE_TransmitHandle;
-
-
-/**
- * Ask the core to call @a notify once it is ready to transmit the
- * given number of bytes to the specified @a target. Must only be
- * called after a connection to the respective peer has been
- * established (and the client has been informed about this). You may
- * have one request of this type pending for each connected peer at
- * any time. If a peer disconnects, the application MUST call
- * #GNUNET_CORE_notify_transmit_ready_cancel() on the respective
- * transmission request, if one such request is pending.
- *
- * @param handle connection to core service
- * @param cork is corking allowed for this transmission?
- * @param priority how important is the message?
- * @param maxdelay how long can the message wait? Only effective if @a cork is #GNUNET_YES
- * @param target who should receive the message, never NULL (can be this peer's identity for loopback)
- * @param notify_size how many bytes of buffer space does @a notify want?
- * @param notify function to call when buffer space is available;
- * will be called with NULL on timeout; clients MUST cancel
- * all pending transmission requests DURING the disconnect
- * handler
- * @param notify_cls closure for @a notify
- * @return non-NULL if the notify callback was queued,
- * NULL if we can not even queue the request (request already pending);
- * if NULL is returned, @a notify will NOT be called.
- */
-struct GNUNET_CORE_TransmitHandle *
-GNUNET_CORE_notify_transmit_ready (struct GNUNET_CORE_Handle *handle,
- int cork,
- enum GNUNET_CORE_Priority priority,
- struct GNUNET_TIME_Relative maxdelay,
- const struct GNUNET_PeerIdentity *target,
- size_t notify_size,
- GNUNET_CONNECTION_TransmitReadyNotify notify,
- void *notify_cls);
-
-
-/**
- * Cancel the specified transmission-ready notification.
- *
- * @param th handle that was returned by #GNUNET_CORE_notify_transmit_ready().
- */
-void
-GNUNET_CORE_notify_transmit_ready_cancel (struct GNUNET_CORE_TransmitHandle *th);
-
-
-/**
* Handle to a CORE monitoring operation.
*/
struct GNUNET_CORE_MonitorHandle;
diff --git a/src/secretsharing/Makefile.am b/src/secretsharing/Makefile.am
index 485183e36f..4b9a06c40e 100644
--- a/src/secretsharing/Makefile.am
+++ b/src/secretsharing/Makefile.am
@@ -17,9 +17,6 @@ if USE_COVERAGE
endif
-bin_PROGRAMS = \
- gnunet-secretsharing-profiler
-
libexec_PROGRAMS = \
gnunet-service-secretsharing
@@ -57,6 +54,9 @@ libgnunetsecretsharing_la_LDFLAGS = \
$(GN_LIB_LDFLAGS)
if HAVE_TESTING
+bin_PROGRAMS = \
+ gnunet-secretsharing-profiler
+
check_PROGRAMS = \
test_secretsharing_api
diff --git a/src/testbed/gnunet-service-testbed_peers.c b/src/testbed/gnunet-service-testbed_peers.c
index a977b2b9b5..aacd625832 100644
--- a/src/testbed/gnunet-service-testbed_peers.c
+++ b/src/testbed/gnunet-service-testbed_peers.c
@@ -1137,14 +1137,8 @@ arm_req_string (enum GNUNET_ARM_RequestStatus rs)
{
case GNUNET_ARM_REQUEST_SENT_OK:
return _("Message was sent successfully");
- case GNUNET_ARM_REQUEST_CONFIGURATION_ERROR:
- return _("Misconfiguration (can't connect to the ARM service)");
case GNUNET_ARM_REQUEST_DISCONNECTED:
return _("We disconnected from ARM before we could send a request");
- case GNUNET_ARM_REQUEST_BUSY:
- return _("ARM API is busy");
- case GNUNET_ARM_REQUEST_TIMEOUT:
- return _("Request timed out");
}
return _("Unknown request status");
}
diff --git a/src/util/disk.c b/src/util/disk.c
index d3d5d87dc7..d536ec8979 100644
--- a/src/util/disk.c
+++ b/src/util/disk.c
@@ -329,8 +329,10 @@ GNUNET_DISK_file_get_identifiers (const char *filename, uint64_t * dev,
BY_HANDLE_FILE_INFORMATION info;
int succ;
- fh = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ, 0);
- if (fh == NULL)
+ fh = GNUNET_DISK_file_open (filename,
+ GNUNET_DISK_OPEN_READ,
+ GNUNET_DISK_PERM_NONE);
+ if (NULL == fh)
return GNUNET_SYSERR;
succ = GetFileInformationByHandle (fh->h, &info);
GNUNET_DISK_file_close (fh);
@@ -1191,7 +1193,7 @@ GNUNET_DISK_fn_write (const char *fn,
fh = GNUNET_DISK_file_open (fn,
GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_TRUNCATE
| GNUNET_DISK_OPEN_CREATE, mode);
- if (!fh)
+ if (! fh)
return GNUNET_SYSERR;
ret = GNUNET_DISK_file_write (fh, buffer, n);
GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh));
@@ -1756,9 +1758,10 @@ GNUNET_DISK_file_open (const char *fn,
/**
- * Close an open file
+ * Close an open file.
+ *
* @param h file handle
- * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
*/
int
GNUNET_DISK_file_close (struct GNUNET_DISK_FileHandle *h)
@@ -1773,7 +1776,7 @@ GNUNET_DISK_file_close (struct GNUNET_DISK_FileHandle *h)
ret = GNUNET_OK;
#if MINGW
- if (!CloseHandle (h->h))
+ if (! CloseHandle (h->h))
{
SetErrnoFromWinError (GetLastError ());
LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "close");
@@ -1781,7 +1784,7 @@ GNUNET_DISK_file_close (struct GNUNET_DISK_FileHandle *h)
}
if (h->oOverlapRead)
{
- if (!CloseHandle (h->oOverlapRead->hEvent))
+ if (! CloseHandle (h->oOverlapRead->hEvent))
{
SetErrnoFromWinError (GetLastError ());
LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "close");
@@ -1822,7 +1825,6 @@ struct GNUNET_DISK_FileHandle *
GNUNET_DISK_get_handle_from_w32_handle (HANDLE osfh)
{
struct GNUNET_DISK_FileHandle *fh;
-
DWORD dwret;
enum GNUNET_FILE_Type ftype;
@@ -1836,7 +1838,8 @@ GNUNET_DISK_get_handle_from_w32_handle (HANDLE osfh)
ftype = GNUNET_DISK_HANLDE_TYPE_PIPE;
break;
case FILE_TYPE_UNKNOWN:
- if (GetLastError () == NO_ERROR || GetLastError () == ERROR_INVALID_HANDLE)
+ if ( (GetLastError () == NO_ERROR) ||
+ (GetLastError () == ERROR_INVALID_HANDLE) )
{
if (0 != ResetEvent (osfh))
ftype = GNUNET_DISK_HANLDE_TYPE_EVENT;