aboutsummaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorng0 <ng0@infotropique.org>2017-09-05 12:22:34 +0000
committerng0 <ng0@infotropique.org>2017-09-05 12:22:34 +0000
commit298c53e73003a7e024713dcf777a6e1c16f5e144 (patch)
tree75d10e3cf0fb0b589aa85070b6c3f977e4e6d419 /doc
parent0406fa6f2e3b6014f465c4d987759324065375df (diff)
downloadgnunet-298c53e73003a7e024713dcf777a6e1c16f5e144.tar.gz
gnunet-298c53e73003a7e024713dcf777a6e1c16f5e144.zip
doc: gnunet-c-tutorial: more includes of examples.
Diffstat (limited to 'doc')
-rw-r--r--doc/gnunet-c-tutorial.texi314
-rw-r--r--doc/tutorial-examples/007.c10
-rw-r--r--doc/tutorial-examples/008.c22
-rw-r--r--doc/tutorial-examples/009.c9
-rw-r--r--doc/tutorial-examples/010.c8
-rw-r--r--doc/tutorial-examples/011.c8
-rw-r--r--doc/tutorial-examples/012.c4
-rw-r--r--doc/tutorial-examples/013.c12
-rw-r--r--doc/tutorial-examples/014.c9
-rw-r--r--doc/tutorial-examples/015.c8
-rw-r--r--doc/tutorial-examples/016.c3
-rw-r--r--doc/tutorial-examples/017.c3
-rw-r--r--doc/tutorial-examples/018.c2
-rw-r--r--doc/tutorial-examples/019.c15
-rw-r--r--doc/tutorial-examples/020.c24
-rw-r--r--doc/tutorial-examples/021.c13
-rw-r--r--doc/tutorial-examples/022.c8
-rw-r--r--doc/tutorial-examples/023.c17
-rw-r--r--doc/tutorial-examples/024.c9
-rw-r--r--doc/tutorial-examples/025.c15
-rw-r--r--doc/tutorial-examples/026.c52
21 files changed, 292 insertions, 273 deletions
diff --git a/doc/gnunet-c-tutorial.texi b/doc/gnunet-c-tutorial.texi
index 6b2c770f3..c62c9c076 100644
--- a/doc/gnunet-c-tutorial.texi
+++ b/doc/gnunet-c-tutorial.texi
@@ -736,18 +736,8 @@ and configuration files.
736@subsection Starting a Service} 736@subsection Starting a Service}
737 737
738The key API definition for creating a service is the {\tt GNUNET\_SERVICE\_MAIN} macro: 738The key API definition for creating a service is the {\tt GNUNET\_SERVICE\_MAIN} macro:
739\lstset{language=C} 739@example
740\begin{lstlisting} 740@verbatiminclude tutorial-examples/007.c
741GNUNET_SERVICE_MAIN
742("service-name",
743 GNUNET_SERVICE_OPTION_NONE,
744 &run,
745 &client_connect_cb,
746 &client_disconnect_cb,
747 NULL,
748 GNUNET_MQ_hd_fixed_size (...),
749 GNUNET_MQ_hd_var_size (...),
750 GNUNET_MQ_handler_end ());
751@end example 741@end example
752 742
753In addition to the service name and flags, the macro takes three 743In addition to the service name and flags, the macro takes three
@@ -757,31 +747,8 @@ that will be called for incoming messages from clients.
757 747
758A minimal version of the three central service funtions would look 748A minimal version of the three central service funtions would look
759like this: 749like this:
760 750@example
761\lstset{language=c} 751@verbatiminclude tutorial-examples/008.c
762\begin{lstlisting}
763static void
764run (void *cls,
765 const struct GNUNET_CONFIGURATION_Handle *c,
766 struct GNUNET_SERVICE_Handle *service)
767{
768}
769
770static void *
771client_connect_cb (void *cls,
772 struct GNUNET_SERVICE_Client *c,
773 struct GNUNET_MQ_Handle *mq)
774{
775 return c;
776}
777
778static void
779client_disconnect_cb (void *cls,
780 struct GNUNET_SERVICE_Client *c,
781 void *internal_cls)
782{
783 GNUNET_assert (c == internal_cls);
784}
785@end example 752@end example
786 753
787Exercise: Write a stub service that processes no messages at all 754Exercise: Write a stub service that processes no messages at all
@@ -815,18 +782,8 @@ managing connections between peers and handling encryption between peers.
815 782
816One of the first things any service that extends the P2P protocol typically does 783One of the first things any service that extends the P2P protocol typically does
817is connect to the @code{CORE} service using: 784is connect to the @code{CORE} service using:
818 785@example
819\lstset{language=C} 786@verbatiminclude tutorial-examples/009.c
820\begin{lstlisting}
821#include <gnunet/gnunet_core_service.h>
822
823struct GNUNET_CORE_Handle *
824GNUNET_CORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
825 void *cls,
826 GNUNET_CORE_StartupCallback init,
827 GNUNET_CORE_ConnectEventHandler connects,
828 GNUNET_CORE_DisconnectEventHandler disconnects,
829 const struct GNUNET_MQ_MessageHandler *handlers);
830@end example 787@end example
831 788
832@subsection New P2P connections} 789@subsection New P2P connections}
@@ -834,16 +791,8 @@ GNUNET_CORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
834Before any traffic with a different peer can be exchanged, the peer must be 791Before any traffic with a different peer can be exchanged, the peer must be
835known to the service. This is notified by the @code{CORE} {\tt connects} callback, 792known to the service. This is notified by the @code{CORE} {\tt connects} callback,
836which communicates the identity of the new peer to the service: 793which communicates the identity of the new peer to the service:
837 794@example
838\lstset{language=C} 795@verbatiminclude tutorial-examples/010.c
839\begin{lstlisting}
840void *
841connects (void *cls,
842 const struct GNUNET_PeerIdentity *peer,
843 struct GNUNET_MQ_Handle *mq)
844{
845 return mq;
846}
847@end example 796@end example
848 797
849Note that whatever you return from {\tt connects} is given as the 798Note that whatever you return from {\tt connects} is given as the
@@ -896,16 +845,8 @@ there is an unrecoverable network disconnection, CORE notifies the service that
896the peer disconnected. After this notification no more messages will be received 845the peer disconnected. After this notification no more messages will be received
897from the peer and the service is no longer allowed to send messages to the peer. 846from the peer and the service is no longer allowed to send messages to the peer.
898The disconnect callback looks like the following: 847The disconnect callback looks like the following:
899 848@example
900\lstset{language=C} 849@verbatiminclude tutorial-examples/011.c
901\begin{lstlisting}
902void
903disconnects (void *cls,
904 const struct GNUNET_PeerIdentity * peer)
905{
906 /* Remove peer's identity from known peers */
907 /* Make sure no messages are sent to peer from now on */
908}
909@end example 850@end example
910 851
911Exercise: Fix your service to handle peer disconnects.} 852Exercise: Fix your service to handle peer disconnects.}
@@ -926,29 +867,18 @@ Each data record stored with PEERSTORE contains the following fields:
926\end{itemize} 867\end{itemize}
927 868
928The first step is to start a connection to the PEERSTORE service: 869The first step is to start a connection to the PEERSTORE service:
929\begin{lstlisting} 870@example
930#include "gnunet_peerstore_service.h" 871@verbatiminclude tutorial-examples/012.c
931
932peerstore_handle = GNUNET_PEERSTORE_connect (cfg);
933@end example 872@end example
873
934The service handle \lstinline|peerstore_handle| will be needed for all subsequent 874The service handle \lstinline|peerstore_handle| will be needed for all subsequent
935PEERSTORE operations. 875PEERSTORE operations.
936 876
937@subsection Storing records} 877@subsection Storing records}
938 878
939To store a new record, use the following function: 879To store a new record, use the following function:
940\begin{lstlisting} 880@example
941struct GNUNET_PEERSTORE_StoreContext * 881@verbatiminclude tutorial-examples/013.c
942GNUNET_PEERSTORE_store (struct GNUNET_PEERSTORE_Handle *h,
943 const char *sub_system,
944 const struct GNUNET_PeerIdentity *peer,
945 const char *key,
946 const void *value,
947 size_t size,
948 struct GNUNET_TIME_Absolute expiry,
949 enum GNUNET_PEERSTORE_StoreOption options,
950 GNUNET_PEERSTORE_Continuation cont,
951 void *cont_cls);
952@end example 882@end example
953 883
954The \lstinline|options| parameter can either be \lstinline|GNUNET_PEERSTORE_STOREOPTION_MULTIPLE| 884The \lstinline|options| parameter can either be \lstinline|GNUNET_PEERSTORE_STOREOPTION_MULTIPLE|
@@ -962,7 +892,7 @@ that it was received by the service.
962 892
963The \lstinline|GNUNET_PEERSTORE_store| function returns a handle to the store operation. This handle 893The \lstinline|GNUNET_PEERSTORE_store| function returns a handle to the store operation. This handle
964can be used to cancel the store operation only before the continuation function is called: 894can be used to cancel the store operation only before the continuation function is called:
965\begin{lstlisting} 895@example
966void 896void
967GNUNET_PEERSTORE_store_cancel (struct GNUNET_PEERSTORE_StoreContext *sc); 897GNUNET_PEERSTORE_store_cancel (struct GNUNET_PEERSTORE_StoreContext *sc);
968@end example 898@end example
@@ -970,16 +900,10 @@ GNUNET_PEERSTORE_store_cancel (struct GNUNET_PEERSTORE_StoreContext *sc);
970@subsection Retrieving records 900@subsection Retrieving records
971 901
972To retrieve stored records, use the following function: 902To retrieve stored records, use the following function:
973\begin{lstlisting} 903@example
974struct GNUNET_PEERSTORE_IterateContext * 904@verbatiminclude tutorial-examples/014.c
975GNUNET_PEERSTORE_iterate (struct GNUNET_PEERSTORE_Handle *h,
976 const char *sub_system,
977 const struct GNUNET_PeerIdentity *peer,
978 const char *key,
979 struct GNUNET_TIME_Relative timeout,
980 GNUNET_PEERSTORE_Processor callback,
981 void *callback_cls);
982@end example 905@end example
906
983The values of \lstinline|peer| and \lstinline|key| can be \lstinline|NULL|. This allows the 907The values of \lstinline|peer| and \lstinline|key| can be \lstinline|NULL|. This allows the
984iteration over values stored under any of the following key combinations: 908iteration over values stored under any of the following key combinations:
985\begin{itemize} 909\begin{itemize}
@@ -1001,31 +925,23 @@ a \lstinline|NULL| record.
1001 925
1002PEERSTORE offers the functionality of monitoring for new records stored under a specific key 926PEERSTORE offers the functionality of monitoring for new records stored under a specific key
1003combination (subsystem, peerid, key). To start the monitoring, use the following function: 927combination (subsystem, peerid, key). To start the monitoring, use the following function:
1004\begin{lstlisting} 928@example
1005struct GNUNET_PEERSTORE_WatchContext * 929@verbatiminclude tutorial-examples/015.c
1006GNUNET_PEERSTORE_watch (struct GNUNET_PEERSTORE_Handle *h,
1007 const char *sub_system,
1008 const struct GNUNET_PeerIdentity *peer,
1009 const char *key,
1010 GNUNET_PEERSTORE_Processor callback,
1011 void *callback_cls);
1012@end example 930@end example
1013 931
1014Whenever a new record is stored under the given key combination, the \lstinline|callback| function 932Whenever a new record is stored under the given key combination, the \lstinline|callback| function
1015will be called with this new record. This will continue until the connection to the PEERSTORE service 933will be called with this new record. This will continue until the connection to the PEERSTORE service
1016is broken or the watch operation is canceled: 934is broken or the watch operation is canceled:
1017\begin{lstlisting} 935@example
1018void 936@verbatiminclude tutorial-examples/016.c
1019GNUNET_PEERSTORE_watch_cancel (struct GNUNET_PEERSTORE_WatchContext *wc);
1020@end example 937@end example
1021 938
1022@subsection Disconnecting from PEERSTORE 939@subsection Disconnecting from PEERSTORE
1023 940
1024When the connection to the PEERSTORE service is no longer needed, disconnect using the following 941When the connection to the PEERSTORE service is no longer needed, disconnect using the following
1025function: 942function:
1026\begin{lstlisting} 943@example
1027void 944@verbatiminclude tutorial-examples/017.c
1028GNUNET_PEERSTORE_disconnect (struct GNUNET_PEERSTORE_Handle *h, int sync_first);
1029@end example 945@end example
1030 946
1031If the \lstinline|sync_first| flag is set to \lstinline|GNUNET_YES|, the API will delay the 947If the \lstinline|sync_first| flag is set to \lstinline|GNUNET_YES|, the API will delay the
@@ -1039,10 +955,10 @@ The DHT allows to store data so other peers in the P2P network can
1039access it and retrieve data stored by any peers in the network. 955access it and retrieve data stored by any peers in the network.
1040This section will explain how to use the DHT. Of course, the first 956This section will explain how to use the DHT. Of course, the first
1041thing to do is to connect to the DHT service: 957thing to do is to connect to the DHT service:
1042\lstset{language=C} 958@example
1043\begin{lstlisting} 959@verbatiminclude tutorial-examples/018.c
1044dht_handle = GNUNET_DHT_connect (cfg, parallel_requests);
1045@end example 960@end example
961
1046The second parameter indicates how many requests in parallel to expect. 962The second parameter indicates how many requests in parallel to expect.
1047It is not a hard limit, but a good approximation will make the DHT more 963It is not a hard limit, but a good approximation will make the DHT more
1048efficient. 964efficient.
@@ -1061,24 +977,8 @@ destination. Currently there is no feedback about whether or not the data
1061has been sucessfully stored or where it has been stored. In order to improve 977has been sucessfully stored or where it has been stored. In order to improve
1062the availablilty of the data and to compensate for possible errors, peers leaving 978the availablilty of the data and to compensate for possible errors, peers leaving
1063and other unfavorable events, just make several PUT requests! 979and other unfavorable events, just make several PUT requests!
1064 980@example
1065\lstset{language=C} 981@verbatiminclude tutorial-examples/019.c
1066\begin{lstlisting}
1067static void
1068message_sent_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1069{
1070 // Request has left local node
1071}
1072
1073struct GNUNET_DHT_PutHandle *
1074GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle,
1075 const struct GNUNET_HashCode *key,
1076 uint32_t desired_replication_level,
1077 enum GNUNET_DHT_RouteOption options,
1078 enum GNUNET_BLOCK_Type type, size_t size, const void *data,
1079 struct GNUNET_TIME_Absolute exp,
1080 struct GNUNET_TIME_Relative timeout,
1081 GNUNET_DHT_PutContinuation cont, void *cont_cls)
1082@end example 982@end example
1083 983
1084Exercise: Store a value in the DHT periodically to make sure it is available 984Exercise: Store a value in the DHT periodically to make sure it is available
@@ -1099,31 +999,8 @@ It is possible to give a ``forever'' timeout with
1099If we give a route option {\tt GNUNET\_DHT\_RO\_RECORD\_ROUTE} the callback 999If we give a route option {\tt GNUNET\_DHT\_RO\_RECORD\_ROUTE} the callback
1100will get a list of all the peers the data has travelled, both on the PUT 1000will get a list of all the peers the data has travelled, both on the PUT
1101path and on the GET path. 1001path and on the GET path.
1102\lstset{language=C} 1002@example
1103\begin{lstlisting} 1003@verbatiminclude tutorial-examples/020.c
1104static void
1105get_result_iterator (void *cls, struct GNUNET_TIME_Absolute expiration,
1106 const struct GNUNET_HashCode *key,
1107 const struct GNUNET_PeerIdentity *get_path,
1108 unsigned int get_path_length,
1109 const struct GNUNET_PeerIdentity *put_path,
1110 unsigned int put_path_length,
1111 enum GNUNET_BLOCK_Type type, size_t size, const void *data)
1112{
1113 // Optionally:
1114 GNUNET_DHT_get_stop (get_handle);
1115}
1116
1117get_handle =
1118 GNUNET_DHT_get_start (dht_handle,
1119 block_type,
1120 &key,
1121 replication,
1122 GNUNET_DHT_RO_NONE,
1123 NULL,
1124 0,
1125 &get_result_iterator,
1126 cls)
1127@end example 1004@end example
1128 1005
1129Exercise: Store a value in the DHT and after a while retrieve it. Show the IDs of all 1006Exercise: Store a value in the DHT and after a while retrieve it. Show the IDs of all
@@ -1153,21 +1030,8 @@ the {\tt xquery} argument is application-specific. Applications that
1153do not use an extended query should check that the {\tt xquery\_size} 1030do not use an extended query should check that the {\tt xquery\_size}
1154is zero. The block group is typically used to filter duplicate 1031is zero. The block group is typically used to filter duplicate
1155replies. 1032replies.
1156 1033@example
1157\lstset{language=C} 1034@verbatiminclude tutorial-examples/021.c
1158\begin{lstlisting}
1159static enum GNUNET_BLOCK_EvaluationResult
1160block_plugin_SERVICE_evaluate (void *cls,
1161 enum GNUNET_BLOCK_Type type,
1162 struct GNUNET_BlockGroup *bg,
1163 const GNUNET_HashCode *query,
1164 const void *xquery,
1165 size_t xquery_size,
1166 const void *reply_block,
1167 size_t reply_block_size)
1168{
1169 // Verify type, block and bg
1170}
1171@end example 1035@end example
1172 1036
1173Note that it is mandatory to detect duplicate replies in this function 1037Note that it is mandatory to detect duplicate replies in this function
@@ -1184,15 +1048,8 @@ function is used to obtain the key of a block --- for example, by
1184means of hashing. If deriving the key is not possible, the function 1048means of hashing. If deriving the key is not possible, the function
1185should simply return {\tt GNUNET\_SYSERR} (the DHT will still work 1049should simply return {\tt GNUNET\_SYSERR} (the DHT will still work
1186just fine with such blocks). 1050just fine with such blocks).
1187
1188@example 1051@example
1189static int 1052@verbatiminclude tutorial-examples/022.c
1190block_plugin_SERVICE_get_key (void *cls, enum GNUNET_BLOCK_Type type,
1191 const void *block, size_t block_size,
1192 struct GNUNET_HashCode *key)
1193{
1194 // Store the key in the key argument, return GNUNET_OK on success.
1195}
1196@end example 1053@end example
1197 1054
1198@subsubsection Initialization of the plugin 1055@subsubsection Initialization of the plugin
@@ -1202,24 +1059,8 @@ an initialization function which should initialize the plugin. The
1202initialization function specifies what block types the plugin cares 1059initialization function specifies what block types the plugin cares
1203about and returns a struct with the functions that are to be used for 1060about and returns a struct with the functions that are to be used for
1204validation and obtaining keys (the ones just defined above). 1061validation and obtaining keys (the ones just defined above).
1205
1206@example 1062@example
1207void * 1063@verbatiminclude tutorial-examples/023.c
1208libgnunet_plugin_block_SERVICE_init (void *cls)
1209{
1210 static enum GNUNET_BLOCK_Type types[] =
1211 {
1212 GNUNET_BLOCK_TYPE_SERVICE_BLOCKYPE,
1213 GNUNET_BLOCK_TYPE_ANY
1214 };
1215 struct GNUNET_BLOCK_PluginFunctions *api;
1216
1217 api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions);
1218 api->evaluate = &block_plugin_SERICE_evaluate;
1219 api->get_key = &block_plugin_SERVICE_get_key;
1220 api->types = types;
1221 return api;
1222}
1223@end example 1064@end example
1224 1065
1225@subsubsection Shutdown of the plugin 1066@subsubsection Shutdown of the plugin
@@ -1227,42 +1068,20 @@ libgnunet_plugin_block_SERVICE_init (void *cls)
1227Following GNUnet's general plugin API concept, the plugin must 1068Following GNUnet's general plugin API concept, the plugin must
1228export a second function for cleaning up. It usually does very 1069export a second function for cleaning up. It usually does very
1229little. 1070little.
1230
1231@example 1071@example
1232void * 1072@verbatiminclude tutorial-examples/024.c
1233libgnunet_plugin_block_SERVICE_done (void *cls)
1234{
1235 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
1236
1237 GNUNET_free (api);
1238 return NULL;
1239}
1240@end example 1073@end example
1241 1074
1242
1243@subsubsection Integration of the plugin with the build system 1075@subsubsection Integration of the plugin with the build system
1244 1076
1245In order to compile the plugin, the Makefile.am file for the 1077In order to compile the plugin, the Makefile.am file for the
1246service SERVICE should contain a rule similar to this: 1078service SERVICE should contain a rule similar to this:
1247 1079@c* Actually this is a Makefile not c. But the whole structure of examples
1080@c* must be improved.
1248@example 1081@example
1249 plugindir = $(libdir)/gnunet 1082@verbatiminclude tutorial-examples/025.c
1250
1251 plugin_LTLIBRARIES = \
1252 libgnunet_plugin_block_ext.la
1253 libgnunet_plugin_block_ext_la_SOURCES = \
1254 plugin_block_ext.c
1255 libgnunet_plugin_block_ext_la_LIBADD = \
1256 $(prefix)/lib/libgnunethello.la \
1257 $(prefix)/lib/libgnunetblock.la \
1258 $(prefix)/lib/libgnunetutil.la
1259 libgnunet_plugin_block_ext_la_LDFLAGS = \
1260 $(GN_PLUGIN_LDFLAGS)
1261 libgnunet_plugin_block_ext_la_DEPENDENCIES = \
1262 $(prefix)/lib/libgnunetblock.la
1263@end example 1083@end example
1264 1084
1265
1266Exercise: Write a block plugin that accepts all queries 1085Exercise: Write a block plugin that accepts all queries
1267and all replies but prints information about queries and replies 1086and all replies but prints information about queries and replies
1268when the respective validation hooks are called. 1087when the respective validation hooks are called.
@@ -1279,60 +1098,9 @@ different callbacks (one for each message type) and optional type and key parame
1279to allow for filtering of messages. When an event happens, the appropiate callback 1098to allow for filtering of messages. When an event happens, the appropiate callback
1280is called with all the information about the event. 1099is called with all the information about the event.
1281@example 1100@example
1282static void 1101@verbatiminclude tutorial-examples/026.c
1283get_callback (void *cls,
1284 enum GNUNET_DHT_RouteOption options,
1285 enum GNUNET_BLOCK_Type type,
1286 uint32_t hop_count,
1287 uint32_t desired_replication_level,
1288 unsigned int path_length,
1289 const struct GNUNET_PeerIdentity *path,
1290 const struct GNUNET_HashCode * key)
1291{
1292}
1293
1294
1295static void
1296get_resp_callback (void *cls,
1297 enum GNUNET_BLOCK_Type type,
1298 const struct GNUNET_PeerIdentity *get_path,
1299 unsigned int get_path_length,
1300 const struct GNUNET_PeerIdentity *put_path,
1301 unsigned int put_path_length,
1302 struct GNUNET_TIME_Absolute exp,
1303 const struct GNUNET_HashCode * key,
1304 const void *data,
1305 size_t size)
1306{
1307}
1308
1309
1310static void
1311put_callback (void *cls,
1312 enum GNUNET_DHT_RouteOption options,
1313 enum GNUNET_BLOCK_Type type,
1314 uint32_t hop_count,
1315 uint32_t desired_replication_level,
1316 unsigned int path_length,
1317 const struct GNUNET_PeerIdentity *path,
1318 struct GNUNET_TIME_Absolute exp,
1319 const struct GNUNET_HashCode * key,
1320 const void *data,
1321 size_t size)
1322{
1323}
1324
1325
1326monitor_handle = GNUNET_DHT_monitor_start (dht_handle,
1327 block_type,
1328 key,
1329 &get_callback,
1330 &get_resp_callback,
1331 &put_callback,
1332 cls);
1333@end example 1102@end example
1334 1103
1335
1336@section Debugging with gnunet-arm 1104@section Debugging with gnunet-arm
1337 1105
1338Even if services are managed by @command{gnunet-arm}, you can start them with 1106Even if services are managed by @command{gnunet-arm}, you can start them with
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 @@
1GNUNET_SERVICE_MAIN
2("service-name",
3 GNUNET_SERVICE_OPTION_NONE,
4 &run,
5 &client_connect_cb,
6 &client_disconnect_cb,
7 NULL,
8 GNUNET_MQ_hd_fixed_size (...),
9 GNUNET_MQ_hd_var_size (...),
10 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 @@
1static void
2run (void *cls,
3 const struct GNUNET_CONFIGURATION_Handle *c,
4 struct GNUNET_SERVICE_Handle *service)
5{
6}
7
8static void *
9client_connect_cb (void *cls,
10 struct GNUNET_SERVICE_Client *c,
11 struct GNUNET_MQ_Handle *mq)
12{
13 return c;
14}
15
16static void
17client_disconnect_cb (void *cls,
18 struct GNUNET_SERVICE_Client *c,
19 void *internal_cls)
20{
21 GNUNET_assert (c == internal_cls);
22}
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 @@
1#include <gnunet/gnunet_core_service.h>
2
3struct GNUNET_CORE_Handle *
4GNUNET_CORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
5 void *cls,
6 GNUNET_CORE_StartupCallback init,
7 GNUNET_CORE_ConnectEventHandler connects,
8 GNUNET_CORE_DisconnectEventHandler disconnects,
9 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 @@
1void *
2connects (void *cls,
3 const struct GNUNET_PeerIdentity *peer,
4 struct GNUNET_MQ_Handle *mq)
5{
6 return mq;
7}
8
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 @@
1void
2disconnects (void *cls,
3 const struct GNUNET_PeerIdentity * peer)
4{
5 /* Remove peer's identity from known peers */
6 /* Make sure no messages are sent to peer from now on */
7}
8
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 @@
1#include "gnunet_peerstore_service.h"
2
3peerstore_handle = GNUNET_PEERSTORE_connect (cfg);
4
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 @@
1struct GNUNET_PEERSTORE_StoreContext *
2GNUNET_PEERSTORE_store (struct GNUNET_PEERSTORE_Handle *h,
3 const char *sub_system,
4 const struct GNUNET_PeerIdentity *peer,
5 const char *key,
6 const void *value,
7 size_t size,
8 struct GNUNET_TIME_Absolute expiry,
9 enum GNUNET_PEERSTORE_StoreOption options,
10 GNUNET_PEERSTORE_Continuation cont,
11 void *cont_cls);
12
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 @@
1struct GNUNET_PEERSTORE_IterateContext *
2GNUNET_PEERSTORE_iterate (struct GNUNET_PEERSTORE_Handle *h,
3 const char *sub_system,
4 const struct GNUNET_PeerIdentity *peer,
5 const char *key,
6 struct GNUNET_TIME_Relative timeout,
7 GNUNET_PEERSTORE_Processor callback,
8 void *callback_cls);
9
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 @@
1struct GNUNET_PEERSTORE_WatchContext *
2GNUNET_PEERSTORE_watch (struct GNUNET_PEERSTORE_Handle *h,
3 const char *sub_system,
4 const struct GNUNET_PeerIdentity *peer,
5 const char *key,
6 GNUNET_PEERSTORE_Processor callback,
7 void *callback_cls);
8
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 @@
1void
2GNUNET_PEERSTORE_watch_cancel (struct GNUNET_PEERSTORE_WatchContext *wc);
3
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 @@
1void
2GNUNET_PEERSTORE_disconnect (struct GNUNET_PEERSTORE_Handle *h, int sync_first);
3
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 @@
1dht_handle = GNUNET_DHT_connect (cfg, parallel_requests);
2
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 @@
1message_sent_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2{
3 // Request has left local node
4}
5
6struct GNUNET_DHT_PutHandle *
7GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle,
8 const struct GNUNET_HashCode *key,
9 uint32_t desired_replication_level,
10 enum GNUNET_DHT_RouteOption options,
11 enum GNUNET_BLOCK_Type type, size_t size, const void *data,
12 struct GNUNET_TIME_Absolute exp,
13 struct GNUNET_TIME_Relative timeout,
14 GNUNET_DHT_PutContinuation cont, void *cont_cls)
15
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 @@
1static void
2get_result_iterator (void *cls, struct GNUNET_TIME_Absolute expiration,
3 const struct GNUNET_HashCode *key,
4 const struct GNUNET_PeerIdentity *get_path,
5 unsigned int get_path_length,
6 const struct GNUNET_PeerIdentity *put_path,
7 unsigned int put_path_length,
8 enum GNUNET_BLOCK_Type type, size_t size, const void *data)
9{
10 // Optionally:
11 GNUNET_DHT_get_stop (get_handle);
12}
13
14get_handle =
15 GNUNET_DHT_get_start (dht_handle,
16 block_type,
17 &key,
18 replication,
19 GNUNET_DHT_RO_NONE,
20 NULL,
21 0,
22 &get_result_iterator,
23 cls)
24
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 @@
1static enum GNUNET_BLOCK_EvaluationResult
2block_plugin_SERVICE_evaluate (void *cls,
3 enum GNUNET_BLOCK_Type type,
4 struct GNUNET_BlockGroup *bg,
5 const GNUNET_HashCode *query,
6 const void *xquery,
7 size_t xquery_size,
8 const void *reply_block,
9 size_t reply_block_size)
10{
11 // Verify type, block and bg
12}
13
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 @@
1static int
2block_plugin_SERVICE_get_key (void *cls, enum GNUNET_BLOCK_Type type,
3 const void *block, size_t block_size,
4 struct GNUNET_HashCode *key)
5{
6 // Store the key in the key argument, return GNUNET_OK on success.
7}
8
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 @@
1void *
2libgnunet_plugin_block_SERVICE_init (void *cls)
3{
4 static enum GNUNET_BLOCK_Type types[] =
5 {
6 GNUNET_BLOCK_TYPE_SERVICE_BLOCKYPE,
7 GNUNET_BLOCK_TYPE_ANY
8 };
9 struct GNUNET_BLOCK_PluginFunctions *api;
10
11 api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions);
12 api->evaluate = &block_plugin_SERICE_evaluate;
13 api->get_key = &block_plugin_SERVICE_get_key;
14 api->types = types;
15 return api;
16}
17
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 @@
1void *
2libgnunet_plugin_block_SERVICE_done (void *cls)
3{
4 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
5
6 GNUNET_free (api);
7 return NULL;
8}
9
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 @@
1 plugindir = $(libdir)/gnunet
2
3 plugin_LTLIBRARIES = \
4 libgnunet_plugin_block_ext.la
5 libgnunet_plugin_block_ext_la_SOURCES = \
6 plugin_block_ext.c
7 libgnunet_plugin_block_ext_la_LIBADD = \
8 $(prefix)/lib/libgnunethello.la \
9 $(prefix)/lib/libgnunetblock.la \
10 $(prefix)/lib/libgnunetutil.la
11 libgnunet_plugin_block_ext_la_LDFLAGS = \
12 $(GN_PLUGIN_LDFLAGS)
13 libgnunet_plugin_block_ext_la_DEPENDENCIES = \
14 $(prefix)/lib/libgnunetblock.la
15
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 @@
1static void
2get_callback (void *cls,
3 enum GNUNET_DHT_RouteOption options,
4 enum GNUNET_BLOCK_Type type,
5 uint32_t hop_count,
6 uint32_t desired_replication_level,
7 unsigned int path_length,
8 const struct GNUNET_PeerIdentity *path,
9 const struct GNUNET_HashCode * key)
10{
11}
12
13
14static void
15get_resp_callback (void *cls,
16 enum GNUNET_BLOCK_Type type,
17 const struct GNUNET_PeerIdentity *get_path,
18 unsigned int get_path_length,
19 const struct GNUNET_PeerIdentity *put_path,
20 unsigned int put_path_length,
21 struct GNUNET_TIME_Absolute exp,
22 const struct GNUNET_HashCode * key,
23 const void *data,
24 size_t size)
25{
26}
27
28
29static void
30put_callback (void *cls,
31 enum GNUNET_DHT_RouteOption options,
32 enum GNUNET_BLOCK_Type type,
33 uint32_t hop_count,
34 uint32_t desired_replication_level,
35 unsigned int path_length,
36 const struct GNUNET_PeerIdentity *path,
37 struct GNUNET_TIME_Absolute exp,
38 const struct GNUNET_HashCode * key,
39 const void *data,
40 size_t size)
41{
42}
43
44
45monitor_handle = GNUNET_DHT_monitor_start (dht_handle,
46 block_type,
47 key,
48 &get_callback,
49 &get_resp_callback,
50 &put_callback,
51 cls);
52