[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [gnunet] branch master updated (c1a9bb5df -> 2efea52ad)
From: |
gnunet |
Subject: |
[GNUnet-SVN] [gnunet] branch master updated (c1a9bb5df -> 2efea52ad) |
Date: |
Tue, 05 Sep 2017 14:23:51 +0200 |
This is an automated email from the git hooks/post-receive script.
ng0 pushed a change to branch master
in repository gnunet.
from c1a9bb5df implement exponential back-off cool down for ARM process
restarts
new d4f04e4d6 doc: gnunet-c-tutorial: move example code to separate files.
new cfba13ba2 doc: gnunet-c-tutorial: include testbed_test.c
new dca832adb doc: gnunet-c-tutorial: include example 4 and 5.
new 0406fa6f2 doc: gnunet-c-tutorial: example 6.
new 298c53e73 doc: gnunet-c-tutorial: more includes of examples.
new 2efea52ad Merge branch 'master' of gnunet.org:gnunet
The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
doc/gnunet-c-tutorial.texi | 443 ++++++--------------------------------------
doc/tutorial-examples/001.c | 29 +++
doc/tutorial-examples/002.c | 17 ++
doc/tutorial-examples/003.c | 7 +
doc/tutorial-examples/004.c | 5 +
doc/tutorial-examples/005.c | 8 +
doc/tutorial-examples/006.c | 31 ++++
doc/tutorial-examples/007.c | 10 +
doc/tutorial-examples/008.c | 22 +++
doc/tutorial-examples/009.c | 9 +
doc/tutorial-examples/010.c | 8 +
doc/tutorial-examples/011.c | 8 +
doc/tutorial-examples/012.c | 4 +
doc/tutorial-examples/013.c | 12 ++
doc/tutorial-examples/014.c | 9 +
doc/tutorial-examples/015.c | 8 +
doc/tutorial-examples/016.c | 3 +
doc/tutorial-examples/017.c | 3 +
doc/tutorial-examples/018.c | 2 +
doc/tutorial-examples/019.c | 15 ++
doc/tutorial-examples/020.c | 24 +++
doc/tutorial-examples/021.c | 13 ++
doc/tutorial-examples/022.c | 8 +
doc/tutorial-examples/023.c | 17 ++
doc/tutorial-examples/024.c | 9 +
doc/tutorial-examples/025.c | 15 ++
doc/tutorial-examples/026.c | 52 ++++++
27 files changed, 404 insertions(+), 387 deletions(-)
create mode 100644 doc/tutorial-examples/001.c
create mode 100644 doc/tutorial-examples/002.c
create mode 100644 doc/tutorial-examples/003.c
create mode 100644 doc/tutorial-examples/004.c
create mode 100644 doc/tutorial-examples/005.c
create mode 100644 doc/tutorial-examples/006.c
create mode 100644 doc/tutorial-examples/007.c
create mode 100644 doc/tutorial-examples/008.c
create mode 100644 doc/tutorial-examples/009.c
create mode 100644 doc/tutorial-examples/010.c
create mode 100644 doc/tutorial-examples/011.c
create mode 100644 doc/tutorial-examples/012.c
create mode 100644 doc/tutorial-examples/013.c
create mode 100644 doc/tutorial-examples/014.c
create mode 100644 doc/tutorial-examples/015.c
create mode 100644 doc/tutorial-examples/016.c
create mode 100644 doc/tutorial-examples/017.c
create mode 100644 doc/tutorial-examples/018.c
create mode 100644 doc/tutorial-examples/019.c
create mode 100644 doc/tutorial-examples/020.c
create mode 100644 doc/tutorial-examples/021.c
create mode 100644 doc/tutorial-examples/022.c
create mode 100644 doc/tutorial-examples/023.c
create mode 100644 doc/tutorial-examples/024.c
create mode 100644 doc/tutorial-examples/025.c
create mode 100644 doc/tutorial-examples/026.c
diff --git a/doc/gnunet-c-tutorial.texi b/doc/gnunet-c-tutorial.texi
index ba443e674..c62c9c076 100644
--- a/doc/gnunet-c-tutorial.texi
+++ b/doc/gnunet-c-tutorial.texi
@@ -457,8 +457,9 @@ found in the testbed default configuration file
@file{src/testbed/testbed.conf}.
With the testbed API, a sample test case can be structured as follows:
@c* <lynX> Is there a way to pick a more readable font for this include?
-\lstset{language=C}
-\lstinputlisting{testbed_test.c}
address@hidden
address@hidden testbed_test.c
address@hidden example
The source code for the above listing can be found at
@uref{https://gnunet.org/git/gnunet.git/tree/doc/testbed_test.c}
or in the @file{doc/} folder of your repository check-out.
@@ -579,37 +580,8 @@ function. This function will parse command-line options,
setup the scheduler
and then invoke the @code{run} function (with the remaining non-option
arguments)
and a handle to the parsed configuration (and the configuration file name that
was
used, which is typically not needed):
-
-\lstset{language=C}
-\begin{lstlisting}
-#include <gnunet/platform.h>
-#include <gnunet/gnunet_util_lib.h>
-
-static int ret;
-
-static void
-run (void *cls,
- char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
- // main code here
- ret = 0;
-}
-
-int
-main (int argc, char *const *argv)
-{
- struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_OPTION_END
- };
- return (GNUNET_OK ==
- GNUNET_PROGRAM_run (argc,
- argv,
- "binary-name",
- gettext_noop ("binary description text"),
- options, &run, NULL)) ? ret : 1;
-}
address@hidden
address@hidden tutorial-examples/001.c
@end example
@subsection Handling command-line options}
@@ -618,25 +590,8 @@ Options can then be added easily by adding global
variables and
expanding the {\tt options} array. For example, the following would
add a string-option and a binary flag (defaulting to @code{NULL} and
@code{GNUNET\_NO} respectively):
-
-\lstset{language=C}
-\begin{lstlisting}
-static char *string_option;
-static int a_flag;
-
-// ...
- struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_option_string ('s', "name", "SOMESTRING",
- gettext_noop ("text describing the string_option NAME"),
- &string_option},
- GNUNET_GETOPT_option_flag ('f', "flag",
- gettext_noop ("text describing the flag option"),
- &a_flag),
- GNUNET_GETOPT_OPTION_END
- };
- string_option = NULL;
- a_flag = GNUNET_SYSERR;
-// ...
address@hidden
address@hidden tutorial-examples/002.c
@end example
Issues such as displaying some helpful text describing options using
@@ -683,16 +638,8 @@ file).
Before a client library can implement the application-specific protocol
with the service, a connection must be created:
-
-\lstset{language=C}
-\begin{lstlisting}
- struct GNUNET_MQ_MessageHandlers handlers[] = {
- // ...
- GNUNET_MQ_handler_end ()
- };
- struct GNUNET_MQ_Handle *mq;
-
- mq = GNUNET_CLIENT_connect (cfg, "service-name", handlers, &error_cb, NULL);
address@hidden
address@hidden tutorial-examples/003.c
@end example
As a result a {\tt GNUNET\_MQ\_Handle} is returned
@@ -710,28 +657,14 @@ there are errors communicating with the service.
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
message, the payload follows after this header.
-
-\lstset{language=C}
-\begin{lstlisting}
-struct GNUNET_MessageHeader
-{
- uint16_t size GNUNET_PACKED;
- uint16_t type GNUNET_PACKED;
-};
address@hidden
address@hidden tutorial-examples/004.c
@end example
Existing message types are defined in @file{gnunet\_protocols.h}\\
A common way to create a message is with an envelope:
-
-\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'
-GNUNET_mq_send (mq, env);
address@hidden
address@hidden tutorial-examples/005.c
@end example
Exercise: Define a message struct that includes a 32-bit
@@ -760,40 +693,8 @@ to actually process the message. Fixed size messages are
fully
checked by the MQ-logic, and thus only need to provide the handler
to process the message. Note that the prefixes {\tt check\_}
and {\tt handle\_} are mandatory.
-
-\lstset{language=c}
-\begin{lstlisting}
-static void
-handle_fix (void *cls, const struct MyMessage *msg)
-{
- // process 'msg'
-}
-
-static int
-check_var (void *cls, const struct MyVarMessage *msg)
-{
- // check 'msg' is well-formed
- return GNUNET_OK;
-}
-
-static void
-handle_var (void *cls, const struct MyVarMessage *msg)
-{
- // process 'msg'
-}
-
-struct GNUNET_MQ_MessageHandler handlers[] = {
- GNUNET_MQ_hd_fixed_size (fix,
- GNUNET_MESSAGE_TYPE_MY_FIX,
- struct MyMessage,
- NULL),
- GNUNET_MQ_hd_fixed_size (var,
- GNUNET_MESSAGE_TYPE_MY_VAR,
- struct MyVarMessage,
- NULL),
-
- GNUNET_MQ_handler_end ()
-};
address@hidden
address@hidden tutorial-examples/006.c
@end example
Exercise: Expand your helper function to receive a response message
@@ -835,18 +736,8 @@ and configuration files.
@subsection Starting a Service}
The key API definition for creating a service is the {\tt
GNUNET\_SERVICE\_MAIN} macro:
-\lstset{language=C}
-\begin{lstlisting}
-GNUNET_SERVICE_MAIN
-("service-name",
- GNUNET_SERVICE_OPTION_NONE,
- &run,
- &client_connect_cb,
- &client_disconnect_cb,
- NULL,
- GNUNET_MQ_hd_fixed_size (...),
- GNUNET_MQ_hd_var_size (...),
- GNUNET_MQ_handler_end ());
address@hidden
address@hidden tutorial-examples/007.c
@end example
In addition to the service name and flags, the macro takes three
@@ -856,31 +747,8 @@ that will be called for incoming messages from clients.
A minimal version of the three central service funtions would look
like this:
-
-\lstset{language=c}
-\begin{lstlisting}
-static void
-run (void *cls,
- const struct GNUNET_CONFIGURATION_Handle *c,
- struct GNUNET_SERVICE_Handle *service)
-{
-}
-
-static void *
-client_connect_cb (void *cls,
- struct GNUNET_SERVICE_Client *c,
- struct GNUNET_MQ_Handle *mq)
-{
- return c;
-}
-
-static void
-client_disconnect_cb (void *cls,
- struct GNUNET_SERVICE_Client *c,
- void *internal_cls)
-{
- GNUNET_assert (c == internal_cls);
-}
address@hidden
address@hidden tutorial-examples/008.c
@end example
Exercise: Write a stub service that processes no messages at all
@@ -914,18 +782,8 @@ managing connections between peers and handling encryption
between peers.
One of the first things any service that extends the P2P protocol typically
does
is connect to the @code{CORE} service using:
-
-\lstset{language=C}
-\begin{lstlisting}
-#include <gnunet/gnunet_core_service.h>
-
-struct GNUNET_CORE_Handle *
-GNUNET_CORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
- void *cls,
- GNUNET_CORE_StartupCallback init,
- GNUNET_CORE_ConnectEventHandler connects,
- GNUNET_CORE_DisconnectEventHandler disconnects,
- const struct GNUNET_MQ_MessageHandler *handlers);
address@hidden
address@hidden tutorial-examples/009.c
@end example
@subsection New P2P connections}
@@ -933,16 +791,8 @@ GNUNET_CORE_connect (const struct
GNUNET_CONFIGURATION_Handle *cfg,
Before any traffic with a different peer can be exchanged, the peer must be
known to the service. This is notified by the @code{CORE} {\tt connects}
callback,
which communicates the identity of the new peer to the service:
-
-\lstset{language=C}
-\begin{lstlisting}
-void *
-connects (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- struct GNUNET_MQ_Handle *mq)
-{
- return mq;
-}
address@hidden
address@hidden tutorial-examples/010.c
@end example
Note that whatever you return from {\tt connects} is given as the
@@ -995,16 +845,8 @@ there is an unrecoverable network disconnection, CORE
notifies the service that
the peer disconnected. After this notification no more messages will be
received
from the peer and the service is no longer allowed to send messages to the
peer.
The disconnect callback looks like the following:
-
-\lstset{language=C}
-\begin{lstlisting}
-void
-disconnects (void *cls,
- const struct GNUNET_PeerIdentity * peer)
-{
- /* Remove peer's identity from known peers */
- /* Make sure no messages are sent to peer from now on */
-}
address@hidden
address@hidden tutorial-examples/011.c
@end example
Exercise: Fix your service to handle peer disconnects.}
@@ -1025,29 +867,18 @@ Each data record stored with PEERSTORE contains the
following fields:
\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);
address@hidden
address@hidden tutorial-examples/012.c
@end example
+
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);
address@hidden
address@hidden tutorial-examples/013.c
@end example
The \lstinline|options| parameter can either be
\lstinline|GNUNET_PEERSTORE_STOREOPTION_MULTIPLE|
@@ -1061,7 +892,7 @@ 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}
address@hidden
void
GNUNET_PEERSTORE_store_cancel (struct GNUNET_PEERSTORE_StoreContext *sc);
@end example
@@ -1069,16 +900,10 @@ GNUNET_PEERSTORE_store_cancel (struct
GNUNET_PEERSTORE_StoreContext *sc);
@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);
address@hidden
address@hidden tutorial-examples/014.c
@end example
+
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}
@@ -1100,31 +925,23 @@ a \lstinline|NULL| record.
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);
address@hidden
address@hidden tutorial-examples/015.c
@end example
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);
address@hidden
address@hidden tutorial-examples/016.c
@end example
@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);
address@hidden
address@hidden tutorial-examples/017.c
@end example
If the \lstinline|sync_first| flag is set to \lstinline|GNUNET_YES|, the API
will delay the
@@ -1138,10 +955,10 @@ 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.
This section will explain how to use the DHT. Of course, the first
thing to do is to connect to the DHT service:
-\lstset{language=C}
-\begin{lstlisting}
-dht_handle = GNUNET_DHT_connect (cfg, parallel_requests);
address@hidden
address@hidden tutorial-examples/018.c
@end example
+
The second parameter indicates how many requests in parallel to expect.
It is not a hard limit, but a good approximation will make the DHT more
efficient.
@@ -1160,24 +977,8 @@ destination. Currently there is no feedback about whether
or not the data
has been sucessfully stored or where it has been stored. In order to improve
the availablilty of the data and to compensate for possible errors, peers
leaving
and other unfavorable events, just make several PUT requests!
-
-\lstset{language=C}
-\begin{lstlisting}
-static void
-message_sent_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
- // 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,
- enum GNUNET_BLOCK_Type type, size_t size, const void *data,
- struct GNUNET_TIME_Absolute exp,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_DHT_PutContinuation cont, void *cont_cls)
address@hidden
address@hidden tutorial-examples/019.c
@end example
Exercise: Store a value in the DHT periodically to make sure it is available
@@ -1198,31 +999,8 @@ It is possible to give a ``forever'' timeout with
If we give a route option {\tt GNUNET\_DHT\_RO\_RECORD\_ROUTE} the callback
will get a list of all the peers the data has travelled, both on the PUT
path and on the GET path.
-\lstset{language=C}
-\begin{lstlisting}
-static void
-get_result_iterator (void *cls, struct GNUNET_TIME_Absolute expiration,
- const struct GNUNET_HashCode *key,
- const struct GNUNET_PeerIdentity *get_path,
- unsigned int get_path_length,
- const struct GNUNET_PeerIdentity *put_path,
- unsigned int put_path_length,
- enum GNUNET_BLOCK_Type type, size_t size, const void
*data)
-{
- // Optionally:
- GNUNET_DHT_get_stop (get_handle);
-}
-
-get_handle =
- GNUNET_DHT_get_start (dht_handle,
- block_type,
- &key,
- replication,
- GNUNET_DHT_RO_NONE,
- NULL,
- 0,
- &get_result_iterator,
- cls)
address@hidden
address@hidden tutorial-examples/020.c
@end example
Exercise: Store a value in the DHT and after a while retrieve it. Show the IDs
of all
@@ -1252,21 +1030,8 @@ the {\tt xquery} argument is application-specific.
Applications that
do not use an extended query should check that the {\tt xquery\_size}
is zero. The block group is typically used to filter duplicate
replies.
-
-\lstset{language=C}
-\begin{lstlisting}
-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)
-{
- // Verify type, block and bg
-}
address@hidden
address@hidden tutorial-examples/021.c
@end example
Note that it is mandatory to detect duplicate replies in this function
@@ -1283,15 +1048,8 @@ function is used to obtain the key of a block --- for
example, by
means of hashing. If deriving the key is not possible, the function
should simply return {\tt GNUNET\_SYSERR} (the DHT will still work
just fine with such blocks).
-
@example
-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)
-{
- // Store the key in the key argument, return GNUNET_OK on success.
-}
address@hidden tutorial-examples/022.c
@end example
@subsubsection Initialization of the plugin
@@ -1301,24 +1059,8 @@ an initialization function which should initialize the
plugin. The
initialization function specifies what block types the plugin cares
about and returns a struct with the functions that are to be used for
validation and obtaining keys (the ones just defined above).
-
@example
-void *
-libgnunet_plugin_block_SERVICE_init (void *cls)
-{
- static enum GNUNET_BLOCK_Type types[] =
- {
- GNUNET_BLOCK_TYPE_SERVICE_BLOCKYPE,
- GNUNET_BLOCK_TYPE_ANY
- };
- struct GNUNET_BLOCK_PluginFunctions *api;
-
- api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions);
- api->evaluate = &block_plugin_SERICE_evaluate;
- api->get_key = &block_plugin_SERVICE_get_key;
- api->types = types;
- return api;
-}
address@hidden tutorial-examples/023.c
@end example
@subsubsection Shutdown of the plugin
@@ -1326,42 +1068,20 @@ libgnunet_plugin_block_SERVICE_init (void *cls)
Following GNUnet's general plugin API concept, the plugin must
export a second function for cleaning up. It usually does very
little.
-
@example
-void *
-libgnunet_plugin_block_SERVICE_done (void *cls)
-{
- struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
-
- GNUNET_free (api);
- return NULL;
-}
address@hidden tutorial-examples/024.c
@end example
-
@subsubsection Integration of the plugin with the build system
In order to compile the plugin, the Makefile.am file for the
service SERVICE should contain a rule similar to this:
-
address@hidden Actually this is a Makefile not c. But the whole structure of
examples
address@hidden must be improved.
@example
- plugindir = $(libdir)/gnunet
-
- plugin_LTLIBRARIES = \
- libgnunet_plugin_block_ext.la
- libgnunet_plugin_block_ext_la_SOURCES = \
- plugin_block_ext.c
- libgnunet_plugin_block_ext_la_LIBADD = \
- $(prefix)/lib/libgnunethello.la \
- $(prefix)/lib/libgnunetblock.la \
- $(prefix)/lib/libgnunetutil.la
- libgnunet_plugin_block_ext_la_LDFLAGS = \
- $(GN_PLUGIN_LDFLAGS)
- libgnunet_plugin_block_ext_la_DEPENDENCIES = \
- $(prefix)/lib/libgnunetblock.la
address@hidden tutorial-examples/025.c
@end example
-
Exercise: Write a block plugin that accepts all queries
and all replies but prints information about queries and replies
when the respective validation hooks are called.
@@ -1378,60 +1098,9 @@ different callbacks (one for each message type) and
optional type and key parame
to allow for filtering of messages. When an event happens, the appropiate
callback
is called with all the information about the event.
@example
-static void
-get_callback (void *cls,
- enum GNUNET_DHT_RouteOption options,
- enum GNUNET_BLOCK_Type type,
- uint32_t hop_count,
- uint32_t desired_replication_level,
- unsigned int path_length,
- const struct GNUNET_PeerIdentity *path,
- const struct GNUNET_HashCode * key)
-{
-}
-
-
-static void
-get_resp_callback (void *cls,
- enum GNUNET_BLOCK_Type type,
- const struct GNUNET_PeerIdentity *get_path,
- unsigned int get_path_length,
- const struct GNUNET_PeerIdentity *put_path,
- unsigned int put_path_length,
- struct GNUNET_TIME_Absolute exp,
- const struct GNUNET_HashCode * key,
- const void *data,
- size_t size)
-{
-}
-
-
-static void
-put_callback (void *cls,
- enum GNUNET_DHT_RouteOption options,
- enum GNUNET_BLOCK_Type type,
- uint32_t hop_count,
- uint32_t desired_replication_level,
- unsigned int path_length,
- const struct GNUNET_PeerIdentity *path,
- struct GNUNET_TIME_Absolute exp,
- const struct GNUNET_HashCode * key,
- const void *data,
- size_t size)
-{
-}
-
-
-monitor_handle = GNUNET_DHT_monitor_start (dht_handle,
- block_type,
- key,
- &get_callback,
- &get_resp_callback,
- &put_callback,
- cls);
address@hidden tutorial-examples/026.c
@end example
-
@section Debugging with gnunet-arm
Even if services are managed by @command{gnunet-arm}, you can start them with
diff --git a/doc/tutorial-examples/001.c b/doc/tutorial-examples/001.c
new file mode 100644
index 000000000..7f6699dd2
--- /dev/null
+++ b/doc/tutorial-examples/001.c
@@ -0,0 +1,29 @@
+#include <gnunet/platform.h>
+#include <gnunet/gnunet_util_lib.h>
+
+static int ret;
+
+static void
+run (void *cls,
+ char *const *args,
+ const char *cfgfile,
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+ // main code here
+ ret = 0;
+}
+
+int
+main (int argc, char *const *argv)
+{
+ struct GNUNET_GETOPT_CommandLineOption options[] = {
+ GNUNET_GETOPT_OPTION_END
+ };
+ return (GNUNET_OK ==
+ GNUNET_PROGRAM_run (argc,
+ argv,
+ "binary-name",
+ gettext_noop ("binary description text"),
+ options, &run, NULL)) ? ret : 1;
+}
+
diff --git a/doc/tutorial-examples/002.c b/doc/tutorial-examples/002.c
new file mode 100644
index 000000000..02233fd61
--- /dev/null
+++ b/doc/tutorial-examples/002.c
@@ -0,0 +1,17 @@
+static char *string_option;
+static int a_flag;
+
+// ...
+ struct GNUNET_GETOPT_CommandLineOption options[] = {
+ GNUNET_GETOPT_option_string ('s', "name", "SOMESTRING",
+ gettext_noop ("text describing the string_option NAME"),
+ &string_option},
+ GNUNET_GETOPT_option_flag ('f', "flag",
+ gettext_noop ("text describing the flag option"),
+ &a_flag),
+ GNUNET_GETOPT_OPTION_END
+ };
+ string_option = NULL;
+ a_flag = GNUNET_SYSERR;
+// ...
+
diff --git a/doc/tutorial-examples/003.c b/doc/tutorial-examples/003.c
new file mode 100644
index 000000000..d13681ca6
--- /dev/null
+++ b/doc/tutorial-examples/003.c
@@ -0,0 +1,7 @@
+ struct GNUNET_MQ_MessageHandlers handlers[] = {
+ // ...
+ GNUNET_MQ_handler_end ()
+ };
+ struct GNUNET_MQ_Handle *mq;
+
+ mq = GNUNET_CLIENT_connect (cfg, "service-name", handlers, &error_cb, NULL);
diff --git a/doc/tutorial-examples/004.c b/doc/tutorial-examples/004.c
new file mode 100644
index 000000000..0ef007907
--- /dev/null
+++ b/doc/tutorial-examples/004.c
@@ -0,0 +1,5 @@
+struct GNUNET_MessageHeader
+{
+ uint16_t size GNUNET_PACKED;
+ uint16_t type GNUNET_PACKED;
+};
diff --git a/doc/tutorial-examples/005.c b/doc/tutorial-examples/005.c
new file mode 100644
index 000000000..0c459f509
--- /dev/null
+++ b/doc/tutorial-examples/005.c
@@ -0,0 +1,8 @@
+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'
+GNUNET_mq_send (mq, env);
+
diff --git a/doc/tutorial-examples/006.c b/doc/tutorial-examples/006.c
new file mode 100644
index 000000000..944d2b18c
--- /dev/null
+++ b/doc/tutorial-examples/006.c
@@ -0,0 +1,31 @@
+static void
+handle_fix (void *cls, const struct MyMessage *msg)
+{
+ // process 'msg'
+}
+
+static int
+check_var (void *cls, const struct MyVarMessage *msg)
+{
+ // check 'msg' is well-formed
+ return GNUNET_OK;
+}
+
+static void
+handle_var (void *cls, const struct MyVarMessage *msg)
+{
+ // process 'msg'
+}
+
+struct GNUNET_MQ_MessageHandler handlers[] = {
+ GNUNET_MQ_hd_fixed_size (fix,
+ GNUNET_MESSAGE_TYPE_MY_FIX,
+ struct MyMessage,
+ NULL),
+ GNUNET_MQ_hd_fixed_size (var,
+ GNUNET_MESSAGE_TYPE_MY_VAR,
+ struct MyVarMessage,
+ NULL),
+
+ GNUNET_MQ_handler_end ()
+};
diff --git a/doc/tutorial-examples/007.c b/doc/tutorial-examples/007.c
new file mode 100644
index 000000000..096539e43
--- /dev/null
+++ b/doc/tutorial-examples/007.c
@@ -0,0 +1,10 @@
+GNUNET_SERVICE_MAIN
+("service-name",
+ GNUNET_SERVICE_OPTION_NONE,
+ &run,
+ &client_connect_cb,
+ &client_disconnect_cb,
+ NULL,
+ GNUNET_MQ_hd_fixed_size (...),
+ GNUNET_MQ_hd_var_size (...),
+ GNUNET_MQ_handler_end ());
diff --git a/doc/tutorial-examples/008.c b/doc/tutorial-examples/008.c
new file mode 100644
index 000000000..2dffe2cf9
--- /dev/null
+++ b/doc/tutorial-examples/008.c
@@ -0,0 +1,22 @@
+static void
+run (void *cls,
+ const struct GNUNET_CONFIGURATION_Handle *c,
+ struct GNUNET_SERVICE_Handle *service)
+{
+}
+
+static void *
+client_connect_cb (void *cls,
+ struct GNUNET_SERVICE_Client *c,
+ struct GNUNET_MQ_Handle *mq)
+{
+ return c;
+}
+
+static void
+client_disconnect_cb (void *cls,
+ struct GNUNET_SERVICE_Client *c,
+ void *internal_cls)
+{
+ GNUNET_assert (c == internal_cls);
+}
diff --git a/doc/tutorial-examples/009.c b/doc/tutorial-examples/009.c
new file mode 100644
index 000000000..26d918fb0
--- /dev/null
+++ b/doc/tutorial-examples/009.c
@@ -0,0 +1,9 @@
+#include <gnunet/gnunet_core_service.h>
+
+struct GNUNET_CORE_Handle *
+GNUNET_CORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
+ void *cls,
+ GNUNET_CORE_StartupCallback init,
+ GNUNET_CORE_ConnectEventHandler connects,
+ GNUNET_CORE_DisconnectEventHandler disconnects,
+ const struct GNUNET_MQ_MessageHandler *handlers);
diff --git a/doc/tutorial-examples/010.c b/doc/tutorial-examples/010.c
new file mode 100644
index 000000000..33494490d
--- /dev/null
+++ b/doc/tutorial-examples/010.c
@@ -0,0 +1,8 @@
+void *
+connects (void *cls,
+ const struct GNUNET_PeerIdentity *peer,
+ struct GNUNET_MQ_Handle *mq)
+{
+ return mq;
+}
+
diff --git a/doc/tutorial-examples/011.c b/doc/tutorial-examples/011.c
new file mode 100644
index 000000000..23bc051de
--- /dev/null
+++ b/doc/tutorial-examples/011.c
@@ -0,0 +1,8 @@
+void
+disconnects (void *cls,
+ const struct GNUNET_PeerIdentity * peer)
+{
+ /* Remove peer's identity from known peers */
+ /* Make sure no messages are sent to peer from now on */
+}
+
diff --git a/doc/tutorial-examples/012.c b/doc/tutorial-examples/012.c
new file mode 100644
index 000000000..cb21d78ab
--- /dev/null
+++ b/doc/tutorial-examples/012.c
@@ -0,0 +1,4 @@
+#include "gnunet_peerstore_service.h"
+
+peerstore_handle = GNUNET_PEERSTORE_connect (cfg);
+
diff --git a/doc/tutorial-examples/013.c b/doc/tutorial-examples/013.c
new file mode 100644
index 000000000..6792417e1
--- /dev/null
+++ b/doc/tutorial-examples/013.c
@@ -0,0 +1,12 @@
+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);
+
diff --git a/doc/tutorial-examples/014.c b/doc/tutorial-examples/014.c
new file mode 100644
index 000000000..ce204f795
--- /dev/null
+++ b/doc/tutorial-examples/014.c
@@ -0,0 +1,9 @@
+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);
+
diff --git a/doc/tutorial-examples/015.c b/doc/tutorial-examples/015.c
new file mode 100644
index 000000000..0dd267e8e
--- /dev/null
+++ b/doc/tutorial-examples/015.c
@@ -0,0 +1,8 @@
+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);
+
diff --git a/doc/tutorial-examples/016.c b/doc/tutorial-examples/016.c
new file mode 100644
index 000000000..d8db4b3b8
--- /dev/null
+++ b/doc/tutorial-examples/016.c
@@ -0,0 +1,3 @@
+void
+GNUNET_PEERSTORE_watch_cancel (struct GNUNET_PEERSTORE_WatchContext *wc);
+
diff --git a/doc/tutorial-examples/017.c b/doc/tutorial-examples/017.c
new file mode 100644
index 000000000..c4acbc088
--- /dev/null
+++ b/doc/tutorial-examples/017.c
@@ -0,0 +1,3 @@
+void
+GNUNET_PEERSTORE_disconnect (struct GNUNET_PEERSTORE_Handle *h, int
sync_first);
+
diff --git a/doc/tutorial-examples/018.c b/doc/tutorial-examples/018.c
new file mode 100644
index 000000000..3fc22584c
--- /dev/null
+++ b/doc/tutorial-examples/018.c
@@ -0,0 +1,2 @@
+dht_handle = GNUNET_DHT_connect (cfg, parallel_requests);
+
diff --git a/doc/tutorial-examples/019.c b/doc/tutorial-examples/019.c
new file mode 100644
index 000000000..d016d381b
--- /dev/null
+++ b/doc/tutorial-examples/019.c
@@ -0,0 +1,15 @@
+message_sent_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ // 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,
+ enum GNUNET_BLOCK_Type type, size_t size, const void *data,
+ struct GNUNET_TIME_Absolute exp,
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_DHT_PutContinuation cont, void *cont_cls)
+
diff --git a/doc/tutorial-examples/020.c b/doc/tutorial-examples/020.c
new file mode 100644
index 000000000..5ecba1c16
--- /dev/null
+++ b/doc/tutorial-examples/020.c
@@ -0,0 +1,24 @@
+static void
+get_result_iterator (void *cls, struct GNUNET_TIME_Absolute expiration,
+ const struct GNUNET_HashCode *key,
+ const struct GNUNET_PeerIdentity *get_path,
+ unsigned int get_path_length,
+ const struct GNUNET_PeerIdentity *put_path,
+ unsigned int put_path_length,
+ enum GNUNET_BLOCK_Type type, size_t size, const void
*data)
+{
+ // Optionally:
+ GNUNET_DHT_get_stop (get_handle);
+}
+
+get_handle =
+ GNUNET_DHT_get_start (dht_handle,
+ block_type,
+ &key,
+ replication,
+ GNUNET_DHT_RO_NONE,
+ NULL,
+ 0,
+ &get_result_iterator,
+ cls)
+
diff --git a/doc/tutorial-examples/021.c b/doc/tutorial-examples/021.c
new file mode 100644
index 000000000..688a31fe0
--- /dev/null
+++ b/doc/tutorial-examples/021.c
@@ -0,0 +1,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)
+{
+ // Verify type, block and bg
+}
+
diff --git a/doc/tutorial-examples/022.c b/doc/tutorial-examples/022.c
new file mode 100644
index 000000000..a373619bd
--- /dev/null
+++ b/doc/tutorial-examples/022.c
@@ -0,0 +1,8 @@
+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)
+{
+ // Store the key in the key argument, return GNUNET_OK on success.
+}
+
diff --git a/doc/tutorial-examples/023.c b/doc/tutorial-examples/023.c
new file mode 100644
index 000000000..820c38b10
--- /dev/null
+++ b/doc/tutorial-examples/023.c
@@ -0,0 +1,17 @@
+void *
+libgnunet_plugin_block_SERVICE_init (void *cls)
+{
+ static enum GNUNET_BLOCK_Type types[] =
+ {
+ GNUNET_BLOCK_TYPE_SERVICE_BLOCKYPE,
+ GNUNET_BLOCK_TYPE_ANY
+ };
+ struct GNUNET_BLOCK_PluginFunctions *api;
+
+ api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions);
+ api->evaluate = &block_plugin_SERICE_evaluate;
+ api->get_key = &block_plugin_SERVICE_get_key;
+ api->types = types;
+ return api;
+}
+
diff --git a/doc/tutorial-examples/024.c b/doc/tutorial-examples/024.c
new file mode 100644
index 000000000..2e84b5905
--- /dev/null
+++ b/doc/tutorial-examples/024.c
@@ -0,0 +1,9 @@
+void *
+libgnunet_plugin_block_SERVICE_done (void *cls)
+{
+ struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
+
+ GNUNET_free (api);
+ return NULL;
+}
+
diff --git a/doc/tutorial-examples/025.c b/doc/tutorial-examples/025.c
new file mode 100644
index 000000000..66d4f80ec
--- /dev/null
+++ b/doc/tutorial-examples/025.c
@@ -0,0 +1,15 @@
+ plugindir = $(libdir)/gnunet
+
+ plugin_LTLIBRARIES = \
+ libgnunet_plugin_block_ext.la
+ libgnunet_plugin_block_ext_la_SOURCES = \
+ plugin_block_ext.c
+ libgnunet_plugin_block_ext_la_LIBADD = \
+ $(prefix)/lib/libgnunethello.la \
+ $(prefix)/lib/libgnunetblock.la \
+ $(prefix)/lib/libgnunetutil.la
+ libgnunet_plugin_block_ext_la_LDFLAGS = \
+ $(GN_PLUGIN_LDFLAGS)
+ libgnunet_plugin_block_ext_la_DEPENDENCIES = \
+ $(prefix)/lib/libgnunetblock.la
+
diff --git a/doc/tutorial-examples/026.c b/doc/tutorial-examples/026.c
new file mode 100644
index 000000000..264e0b6b9
--- /dev/null
+++ b/doc/tutorial-examples/026.c
@@ -0,0 +1,52 @@
+static void
+get_callback (void *cls,
+ enum GNUNET_DHT_RouteOption options,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t hop_count,
+ uint32_t desired_replication_level,
+ unsigned int path_length,
+ const struct GNUNET_PeerIdentity *path,
+ const struct GNUNET_HashCode * key)
+{
+}
+
+
+static void
+get_resp_callback (void *cls,
+ enum GNUNET_BLOCK_Type type,
+ const struct GNUNET_PeerIdentity *get_path,
+ unsigned int get_path_length,
+ const struct GNUNET_PeerIdentity *put_path,
+ unsigned int put_path_length,
+ struct GNUNET_TIME_Absolute exp,
+ const struct GNUNET_HashCode * key,
+ const void *data,
+ size_t size)
+{
+}
+
+
+static void
+put_callback (void *cls,
+ enum GNUNET_DHT_RouteOption options,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t hop_count,
+ uint32_t desired_replication_level,
+ unsigned int path_length,
+ const struct GNUNET_PeerIdentity *path,
+ struct GNUNET_TIME_Absolute exp,
+ const struct GNUNET_HashCode * key,
+ const void *data,
+ size_t size)
+{
+}
+
+
+monitor_handle = GNUNET_DHT_monitor_start (dht_handle,
+ block_type,
+ key,
+ &get_callback,
+ &get_resp_callback,
+ &put_callback,
+ cls);
+
--
To stop receiving notification emails like this one, please contact
address@hidden
- [GNUnet-SVN] [gnunet] branch master updated (c1a9bb5df -> 2efea52ad),
gnunet <=
- [GNUnet-SVN] [gnunet] 02/06: doc: gnunet-c-tutorial: include testbed_test.c, gnunet, 2017/09/05
- [GNUnet-SVN] [gnunet] 01/06: doc: gnunet-c-tutorial: move example code to separate files., gnunet, 2017/09/05
- [GNUnet-SVN] [gnunet] 03/06: doc: gnunet-c-tutorial: include example 4 and 5., gnunet, 2017/09/05
- [GNUnet-SVN] [gnunet] 04/06: doc: gnunet-c-tutorial: example 6., gnunet, 2017/09/05
- [GNUnet-SVN] [gnunet] 06/06: Merge branch 'master' of gnunet.org:gnunet, gnunet, 2017/09/05
- [GNUnet-SVN] [gnunet] 05/06: doc: gnunet-c-tutorial: more includes of examples., gnunet, 2017/09/05