aboutsummaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorng0 <ng0@infotropique.org>2017-09-06 08:10:50 +0000
committerng0 <ng0@infotropique.org>2017-09-06 08:10:50 +0000
commitc62c08a196a8018d2a70d6072d45a52290e66776 (patch)
tree03ecf7b4081b0bb72830b5cdc76c02889a046dce /doc
parent4d4c96237c19efbada15fa2152537ef8250f658f (diff)
downloadgnunet-c62c08a196a8018d2a70d6072d45a52290e66776.tar.gz
gnunet-c62c08a196a8018d2a70d6072d45a52290e66776.zip
doc: gnunet-c-tutorial: some unrelated edits.
Diffstat (limited to 'doc')
-rw-r--r--doc/gnunet-c-tutorial.texi244
1 files changed, 117 insertions, 127 deletions
diff --git a/doc/gnunet-c-tutorial.texi b/doc/gnunet-c-tutorial.texi
index 78d48a386..46ad98480 100644
--- a/doc/gnunet-c-tutorial.texi
+++ b/doc/gnunet-c-tutorial.texi
@@ -150,10 +150,10 @@ $ cd ..
150Assuming all dependencies are installed, the following commands will 150Assuming all dependencies are installed, the following commands will
151compile and install GNUnet in your home directory. You can specify the 151compile and install GNUnet in your home directory. You can specify the
152directory where GNUnet will be installed by changing the 152directory where GNUnet will be installed by changing the
153--prefix value when calling ./configure. If 153@code{--prefix} value when calling @command{./configure}. If
154you do not specifiy a prefix, GNUnet is installed in the directory 154you do not specifiy a prefix, GNUnet is installed in the directory
155/usr/local. When developing new applications you may want 155@file{/usr/local}. When developing new applications you may want
156to enable verbose logging by adding --enable-logging=verbose: 156to enable verbose logging by adding @code{--enable-logging=verbose}:
157 157
158@example 158@example
159$ ./configure --prefix=$PREFIX --enable-logging 159$ ./configure --prefix=$PREFIX --enable-logging
@@ -330,8 +330,8 @@ $ gnunet-statistics -c ~/peer1.conf -s dht # print statistics about DHT service
330 330
331This section describes how to start two peers on the same machine by hand. 331This section describes how to start two peers on the same machine by hand.
332The process is rather painful, but the description is somewhat instructive. 332The process is rather painful, but the description is somewhat instructive.
333In practice, you might prefer the automated method described in 333In practice, you might prefer the automated method
334Section sec:testbed. 334(@pxref{Starting Peers Using the Testbed Service}).
335 335
336@subsubsection Setup a second peer 336@subsubsection Setup a second peer
337We will now start a second peer on your machine. 337We will now start a second peer on your machine.
@@ -348,20 +348,18 @@ configuration file:
348@example 348@example
349$ cat $PREFIX/share/gnunet/config.d/*.conf > peer2.conf 349$ cat $PREFIX/share/gnunet/config.d/*.conf > peer2.conf
350@end example 350@end example
351Now you have to edit peer2.conf and change: 351Now you have to edit @file{peer2.conf} and change:
352\begin{itemize} 352@itemize
353 \itemsep0em 353@item @code{GNUNET\_TEST\_HOME} under @code{PATHS}
354 \item{@code{GNUNET\_TEST\_HOME} under @code{PATHS}} 354@tem Every (uncommented) value for ``@code{PORT}'' (add 10000) in any
355 \item{Every (uncommented) value for ``@code{PORT}'' (add 10000) in any 355section (the option may be commented out if @code{PORT} is
356 section (the option may be commented out if @code{PORT} is 356prefixed by "\#", in this case, UNIX domain sockets are used
357 prefixed by "\#", in this case, UNIX domain sockets are used 357and the PORT option does not need to be touched)
358 and the PORT option does not need to be touched) } 358@item Every value for ``@code{UNIXPATH}'' in any section (e.g. by adding a "-p2" suffix)
359 \item{Every value for ``@code{UNIXPATH}'' in any section (e.g. by adding a "-p2" suffix)} 359@end itemize
360\end{itemize} 360to a fresh, unique value. Make sure that the PORT numbers stay below 65536.
361to a fresh, unique value. Make sure that the PORT numbers stay 361From now on, whenever you interact with the second peer, you need to specify
362below 65536. From now on, whenever you interact with the second 362@command{-c peer2.conf} as an additional command line argument.
363peer, you need to specify @command{-c peer2.conf} as an additional
364command line argument.
365 363
366Now, generate the 2nd peer's private key: 364Now, generate the 2nd peer's private key:
367 365
@@ -384,16 +382,15 @@ $ ~/gnunet/src/dht/gnunet-dht-put -c peer2.conf -k KEY -d VALUE
384$ ~/gnunet/src/dht/gnunet-dht-get -c peer2.conf -k KEY 382$ ~/gnunet/src/dht/gnunet-dht-get -c peer2.conf -k KEY
385@end example 383@end example
386If you want the two peers to connect, you have multiple options: 384If you want the two peers to connect, you have multiple options:
387\begin{itemize} 385@itemize
388\itemsep0em 386@item UDP neighbour discovery (automatic)
389 \item UDP neighbour discovery (automatic) 387@item Setup a bootstrap server
390 \item Setup a bootstrap server 388@item Connect manually
391 \item Connect manually 389@end itemize
392\end{itemize}
393To setup peer 1 as bootstrapping server change the configuration of 390To setup peer 1 as bootstrapping server change the configuration of
394the first one to be a hostlist server by adding the following lines to 391the first one to be a hostlist server by adding the following lines to
395@code{peer1.conf} to enable bootstrapping server: 392@file{peer1.conf} to enable bootstrapping server:
396 @example 393@example
397[hostlist] 394[hostlist]
398OPTIONS = -p 395OPTIONS = -p
399@end example 396@end example
@@ -456,7 +453,6 @@ configuration file. Various available options and details about them can be
456found in the testbed default configuration file @file{src/testbed/testbed.conf}. 453found in the testbed default configuration file @file{src/testbed/testbed.conf}.
457 454
458With the testbed API, a sample test case can be structured as follows: 455With the testbed API, a sample test case can be structured as follows:
459@c* <lynX> Is there a way to pick a more readable font for this include?
460@example 456@example
461@verbatiminclude testbed_test.c 457@verbatiminclude testbed_test.c
462@end example 458@end example
@@ -483,8 +479,8 @@ waiting operations can be executed. Operations will be canceled if they are
483marked as ``done'' before their completion. 479marked as ``done'' before their completion.
484 480
485An operation is treated as completed when it succeeds or fails. Completion of 481An operation is treated as completed when it succeeds or fails. Completion of
486an operation is either conveyed as events through @i{controller event 482an operation is either conveyed as events through @i{controller event callback}
487 callback} or through respective operation completion callbacks. In functions 483or through respective operation completion callbacks. In functions
488which support completion notification through both controller event callback and 484which support completion notification through both controller event callback and
489operation completion callback, first the controller event callback will be 485operation completion callback, first the controller event callback will be
490called. If the operation is not marked as done in that callback or if the 486called. If the operation is not marked as done in that callback or if the
@@ -611,7 +607,7 @@ library is supposed to implement the IPC whereas the service provides
611more persistent P2P functions. 607more persistent P2P functions.
612 608
613Exercise: Add a few command-line options and print them inside 609Exercise: Add a few command-line options and print them inside
614of @code{run}. What happens if the user gives invalid arguments?} 610of @code{run}. What happens if the user gives invalid arguments?
615 611
616@subsection Writing a Client Library} 612@subsection Writing a Client Library}
617 613
@@ -625,11 +621,11 @@ Then, a client-service protocol needs to be designed. This typically
625involves defining various message formats in a header that will be 621involves defining various message formats in a header that will be
626included by both the service and the client library (but is otherwise 622included by both the service and the client library (but is otherwise
627not shared and hence located within the service's directory and not 623not shared and hence located within the service's directory and not
628installed by @command{make install}). Each message must start with a {\tt 624installed by @command{make install}). Each message must start with a
629 struct GNUNET\_MessageHeader} and must be shorter than 64k. By 625@code{struct GNUNET\_MessageHeader} and must be shorter than 64k. By
630convention, all fields in IPC (and P2P) messages must be in big-endian 626convention, all fields in IPC (and P2P) messages must be in big-endian
631format (and thus should be read using {\tt ntohl} and similar 627format (and thus should be read using @code{ntohl} and similar
632functions and written using {\tt htonl} and similar functions). 628functions and written using @code{htonl} and similar functions).
633Unique message types must be defined for each message struct in the 629Unique message types must be defined for each message struct in the
634@file{gnunet\_protocols.h} header (or an extension-specific include 630@file{gnunet\_protocols.h} header (or an extension-specific include
635file). 631file).
@@ -642,26 +638,25 @@ with the service, a connection must be created:
642@verbatiminclude tutorial-examples/003.c 638@verbatiminclude tutorial-examples/003.c
643@end example 639@end example
644 640
645As a result a {\tt GNUNET\_MQ\_Handle} is returned 641As a result a @code{GNUNET\_MQ\_Handle} is returned
646which can to used henceforth to transmit messages to 642which can to used henceforth to transmit messages to the service.
647the service.
648The complete MQ API can be found in @file{gnunet\_mq\_lib.h}. 643The complete MQ API can be found in @file{gnunet\_mq\_lib.h}.
649The {\tt hanlders} array in the example above is incomplete. 644The @code{hanlders} array in the example above is incomplete.
650Here is where you will define which messages you expect to 645Here is where you will define which messages you expect to
651receive from the service, and which functions handle them. 646receive from the service, and which functions handle them.
652The {\tt error\_cb} is a function that is to be called whenever 647The @code{error\_cb} is a function that is to be called whenever
653there are errors communicating with the service. 648there are errors communicating with the service.
654 649
655@subsubsection Sending messages} 650@subsubsection Sending messages}
656 651
657In GNUnet, messages are always sent beginning with a {\tt struct GNUNET\_MessageHeader} 652In GNUnet, messages are always sent beginning with a @code{struct GNUNET\_MessageHeader}
658in big endian format. This header defines the size and the type of the 653in big endian format. This header defines the size and the type of the
659message, the payload follows after this header. 654message, the payload follows after this header.
660@example 655@example
661@verbatiminclude tutorial-examples/004.c 656@verbatiminclude tutorial-examples/004.c
662@end example 657@end example
663 658
664Existing message types are defined in @file{gnunet\_protocols.h}\\ 659Existing message types are defined in @file{gnunet\_protocols.h}.
665A common way to create a message is with an envelope: 660A common way to create a message is with an envelope:
666@example 661@example
667@verbatiminclude tutorial-examples/005.c 662@verbatiminclude tutorial-examples/005.c
@@ -672,37 +667,37 @@ unsigned integer in addition to the standard GNUnet MessageHeader.
672Add a C struct and define a fresh protocol number for your message. 667Add a C struct and define a fresh protocol number for your message.
673Protocol numbers in gnunet-ext are defined in @file{gnunet-ext/src/include/gnunet_protocols_ext.h} 668Protocol numbers in gnunet-ext are defined in @file{gnunet-ext/src/include/gnunet_protocols_ext.h}
674 669
675Exercise: Find out how you can determine the number of messages in a message queue.} 670Exercise: Find out how you can determine the number of messages in a message queue.
676 671
677Exercise: Find out how you can determine when a message you have queued was actually transmitted.} 672Exercise: Find out how you can determine when a message you have queued was actually transmitted.
678 673
679Exercise: Define a helper function to transmit a 32-bit 674Exercise: Define a helper function to transmit a 32-bit
680unsigned integer (as payload) to a service using some given client 675unsigned integer (as payload) to a service using some given client
681handle.} 676handle.
682 677
683 678
684@subsubsection Receiving Replies from the Service} 679@subsubsection Receiving Replies from the Service}
685 680
686Clients can receive messages from the service using the handlers 681Clients can receive messages from the service using the handlers
687specified in the {\tt handlers} array we specified when connecting 682specified in the @code{handlers} array we specified when connecting
688to the service. Entries in the the array are usually created using 683to the service. Entries in the the array are usually created using
689one of two macros, depending on whether the message is fixed size 684one of two macros, depending on whether the message is fixed size
690or variable size. Variable size messages are managed using two 685or variable size. Variable size messages are managed using two
691callbacks, one to check that the message is well-formed, the other 686callbacks, one to check that the message is well-formed, the other
692to actually process the message. Fixed size messages are fully 687to actually process the message. Fixed size messages are fully
693checked by the MQ-logic, and thus only need to provide the handler 688checked by the MQ-logic, and thus only need to provide the handler
694to process the message. Note that the prefixes {\tt check\_} 689to process the message. Note that the prefixes @code{check\_}
695and {\tt handle\_} are mandatory. 690and @code{handle\_} are mandatory.
696@example 691@example
697@verbatiminclude tutorial-examples/006.c 692@verbatiminclude tutorial-examples/006.c
698@end example 693@end example
699 694
700Exercise: Expand your helper function to receive a response message 695Exercise: Expand your helper function to receive a response message
701 (for example, containing just the {\tt struct GNUnet MessageHeader} 696(for example, containing just the @code{struct GNUnet MessageHeader}
702 without any payload). Upon receiving the service's response, you 697without any payload). Upon receiving the service's response, you
703 should call a callback provided to your helper function's API.} 698should call a callback provided to your helper function's API.
704 699
705Exercise: Figure out where you can pass values to the closures ({\tt cls}).} 700Exercise: Figure out where you can pass values to the closures (@code{cls}).
706 701
707 702
708@subsection Writing a user interface} 703@subsection Writing a user interface}
@@ -711,20 +706,17 @@ Given a client library, all it takes to access a service now is to
711combine calls to the client library with parsing command-line 706combine calls to the client library with parsing command-line
712options. 707options.
713 708
714Exercise: Call your client API from your {\tt run()} method in your 709Exercise: Call your client API from your @code{run()} method in your
715 client application to send a request to the service. For example, 710client application to send a request to the service. For example,
716 send a 32-bit integer value based on a number given at the 711send a 32-bit integer value based on a number given at the
717 command-line to the service.} 712command-line to the service.
718
719
720 713
721@section Writing a Service 714@section Writing a Service
722 715
723Before you can test the client you've written so far, you'll need to also 716Before you can test the client you've written so far, you'll need to also
724implement the corresponding service. 717implement the corresponding service.
725 718
726 719@subsection Code Placement
727@subsection Code Placement}
728 720
729New services are placed in their own subdirectory under @file{gnunet/src}. 721New services are placed in their own subdirectory under @file{gnunet/src}.
730This subdirectory should contain the API implementation file @file{SERVICE\_api.c}, 722This subdirectory should contain the API implementation file @file{SERVICE\_api.c},
@@ -735,14 +727,14 @@ and configuration files.
735 727
736@subsection Starting a Service} 728@subsection Starting a Service}
737 729
738The key API definition for creating a service is the {\tt GNUNET\_SERVICE\_MAIN} macro: 730The key API definition for creating a service is the @code{GNUNET\_SERVICE\_MAIN} macro:
739@example 731@example
740@verbatiminclude tutorial-examples/007.c 732@verbatiminclude tutorial-examples/007.c
741@end example 733@end example
742 734
743In addition to the service name and flags, the macro takes three 735In addition to the service name and flags, the macro takes three
744functions, typically called {\tt run}, {\tt client\_connect\_cb} and 736functions, typically called @code{run}, @code{client\_connect\_cb} and
745{\tt client\_disconnect\_cb} as well as an array of message handlers 737@code{client\_disconnect\_cb} as well as an array of message handlers
746that will be called for incoming messages from clients. 738that will be called for incoming messages from clients.
747 739
748A minimal version of the three central service funtions would look 740A minimal version of the three central service funtions would look
@@ -752,25 +744,25 @@ like this:
752@end example 744@end example
753 745
754Exercise: Write a stub service that processes no messages at all 746Exercise: Write a stub service that processes no messages at all
755 in your code. Create a default configuration for it, integrate it 747in your code. Create a default configuration for it, integrate it
756 with the build system and start the service from {\tt 748with the build system and start the service from
757 gnunet-service-arm} using @command{gnunet-arm -i NAME}. 749@command{gnunet-service-arm} using @command{gnunet-arm -i NAME}.
758 750
759Exercise: Figure out how to set the closure ({\tt cls}) for handlers 751Exercise: Figure out how to set the closure (@code{cls}) for handlers
760 of a service. 752of a service.
761 753
762Exercise: Figure out how to send messages from the service back to the 754Exercise: Figure out how to send messages from the service back to the
763 client. 755client.
764 756
765Each handler function in the service {\bf must} eventually (possibly in some 757Each handler function in the service @b{must} eventually (possibly in some
766asynchronous continuation) call {\tt GNUNET\_SERVICE\_client\_continue()}. 758asynchronous continuation) call @code{GNUNET\_SERVICE\_client\_continue()}.
767Only after this call additional messages from the same client may 759Only after this call additional messages from the same client may
768be processed. This way, the service can throttle processing messages 760be processed. This way, the service can throttle processing messages
769from the same client. 761from the same client.
770 762
771Exercise: Change the service to ``handle'' the message from your 763Exercise: Change the service to ``handle'' the message from your
772 client (for now, by printing a message). What happens if you 764client (for now, by printing a message). What happens if you
773 forget to call {\tt GNUNET\_SERVICE\_client\_continue()}?} 765forget to call @code{GNUNET\_SERVICE\_client\_continue()}?
774 766
775 767
776@section Interacting directly with other Peers using the CORE Service 768@section Interacting directly with other Peers using the CORE Service
@@ -789,24 +781,24 @@ is connect to the @code{CORE} service using:
789@subsection New P2P connections} 781@subsection New P2P connections}
790 782
791Before any traffic with a different peer can be exchanged, the peer must be 783Before any traffic with a different peer can be exchanged, the peer must be
792known to the service. This is notified by the @code{CORE} {\tt connects} callback, 784known to the service. This is notified by the @code{CORE} @code{connects} callback,
793which communicates the identity of the new peer to the service: 785which communicates the identity of the new peer to the service:
794@example 786@example
795@verbatiminclude tutorial-examples/010.c 787@verbatiminclude tutorial-examples/010.c
796@end example 788@end example
797 789
798Note that whatever you return from {\tt connects} is given as the 790Note that whatever you return from @code{connects} is given as the
799{\it cls} argument to the message handlers for messages from 791@i{cls} argument to the message handlers for messages from
800the respective peer. 792the respective peer.
801 793
802Exercise: Create a service that connects to the @code{CORE}. Then 794Exercise: Create a service that connects to the @code{CORE}. Then
803start (and connect) two peers and print a message once your connect 795start (and connect) two peers and print a message once your connect
804callback is invoked.} 796callback is invoked.
805 797
806@subsection Receiving P2P Messages 798@subsection Receiving P2P Messages
807 799
808To receive messages from @code{CORE}, you pass the desired 800To receive messages from @code{CORE}, you pass the desired
809{\em handlers} to the {\tt GNUNET\_CORE\_connect()} function, 801@i{handlers} to the @code{GNUNET\_CORE\_connect()} function,
810just as we showed for services. 802just as we showed for services.
811 803
812It is your responsibility to process messages fast enough or 804It is your responsibility to process messages fast enough or
@@ -822,9 +814,9 @@ the two peers are connected? Why?
822 814
823@subsection Sending P2P Messages 815@subsection Sending P2P Messages
824 816
825You can transmit messages to other peers using the {\it mq} you were 817You can transmit messages to other peers using the @i{mq} you were
826given during the {\tt connect} callback. Note that the {\it mq} 818given during the @code{connect} callback. Note that the @i{mq}
827automatically is released upon {\tt disconnect} and that you must 819automatically is released upon @code{disconnect} and that you must
828not use it afterwards. 820not use it afterwards.
829 821
830It is your responsibility to not over-fill the message queue, GNUnet 822It is your responsibility to not over-fill the message queue, GNUnet
@@ -835,12 +827,12 @@ fast as possible to the other peer (the other peer should run a
835service that ``processes'' those messages). How fast is the 827service that ``processes'' those messages). How fast is the
836transmission? Count using the STATISTICS service on both ends. Are 828transmission? Count using the STATISTICS service on both ends. Are
837messages lost? How can you transmit messages faster? What happens if 829messages lost? How can you transmit messages faster? What happens if
838you stop the peer that is receiving your messages?} 830you stop the peer that is receiving your messages?
839 831
840 832
841@subsection End of P2P connections} 833@subsection End of P2P connections}
842 834
843If a message handler returns {\tt GNUNET\_SYSERR}, the remote peer shuts down or 835If a message handler returns @code{GNUNET\_SYSERR}, the remote peer shuts down or
844there is an unrecoverable network disconnection, CORE notifies the service that 836there is an unrecoverable network disconnection, CORE notifies the service that
845the peer disconnected. After this notification no more messages will be received 837the peer disconnected. After this notification no more messages will be received
846from the peer and the service is no longer allowed to send messages to the peer. 838from the peer and the service is no longer allowed to send messages to the peer.
@@ -849,7 +841,7 @@ The disconnect callback looks like the following:
849@verbatiminclude tutorial-examples/011.c 841@verbatiminclude tutorial-examples/011.c
850@end example 842@end example
851 843
852Exercise: Fix your service to handle peer disconnects.} 844Exercise: Fix your service to handle peer disconnects.
853 845
854@section Storing peer-specific data using the PEERSTORE service 846@section Storing peer-specific data using the PEERSTORE service
855 847
@@ -857,21 +849,20 @@ GNUnet's PEERSTORE service offers a persistorage for arbitrary peer-specific dat
857Other GNUnet services can use the PEERSTORE to store, retrieve and monitor data records. 849Other GNUnet services can use the PEERSTORE to store, retrieve and monitor data records.
858Each data record stored with PEERSTORE contains the following fields: 850Each data record stored with PEERSTORE contains the following fields:
859 851
860\begin{itemize} 852@itemize
861\itemsep0em 853@item subsystem: Name of the subsystem responsible for the record.
862 \item subsystem: Name of the subsystem responsible for the record. 854@item peerid: Identity of the peer this record is related to.
863 \item peerid: Identity of the peer this record is related to. 855@item key: a key string identifying the record.
864 \item key: a key string identifying the record. 856@item value: binary record value.
865 \item value: binary record value. 857@item expiry: record expiry date.
866 \item expiry: record expiry date. 858@end itemize
867\end{itemize}
868 859
869The first step is to start a connection to the PEERSTORE service: 860The first step is to start a connection to the PEERSTORE service:
870@example 861@example
871@verbatiminclude tutorial-examples/012.c 862@verbatiminclude tutorial-examples/012.c
872@end example 863@end example
873 864
874The service handle \lstinline|peerstore_handle| will be needed for all subsequent 865The service handle @code{peerstore_handle} will be needed for all subsequent
875PEERSTORE operations. 866PEERSTORE operations.
876 867
877@subsection Storing records} 868@subsection Storing records}
@@ -881,16 +872,16 @@ To store a new record, use the following function:
881@verbatiminclude tutorial-examples/013.c 872@verbatiminclude tutorial-examples/013.c
882@end example 873@end example
883 874
884The \lstinline|options| parameter can either be \lstinline|GNUNET_PEERSTORE_STOREOPTION_MULTIPLE| 875The @code{options} parameter can either be @code{GNUNET_PEERSTORE_STOREOPTION_MULTIPLE}
885which means that multiple values can be stored under the same key combination (subsystem, peerid, key), 876which means that multiple values can be stored under the same key combination (subsystem, peerid, key),
886or \lstinline|GNUNET_PEERSTORE_STOREOPTION_REPLACE| which means that PEERSTORE will replace any 877or @code{GNUNET_PEERSTORE_STOREOPTION_REPLACE} which means that PEERSTORE will replace any
887existing values under the given key combination (subsystem, peerid, key) with the new given value. 878existing values under the given key combination (subsystem, peerid, key) with the new given value.
888 879
889The continuation function \lstinline|cont| will be called after the store request is successfully 880The continuation function @code{cont} will be called after the store request is successfully
890sent to the PEERSTORE service. This does not guarantee that the record is successfully stored, only 881sent to the PEERSTORE service. This does not guarantee that the record is successfully stored, only
891that it was received by the service. 882that it was received by the service.
892 883
893The \lstinline|GNUNET_PEERSTORE_store| function returns a handle to the store operation. This handle 884The @code{GNUNET_PEERSTORE_store} function returns a handle to the store operation. This handle
894can be used to cancel the store operation only before the continuation function is called: 885can be used to cancel the store operation only before the continuation function is called:
895@example 886@example
896void 887void
@@ -904,22 +895,21 @@ To retrieve stored records, use the following function:
904@verbatiminclude tutorial-examples/014.c 895@verbatiminclude tutorial-examples/014.c
905@end example 896@end example
906 897
907The values of \lstinline|peer| and \lstinline|key| can be \lstinline|NULL|. This allows the 898The values of @code{peer} and @code{key} can be @code{NULL}. This allows the
908iteration over values stored under any of the following key combinations: 899iteration over values stored under any of the following key combinations:
909\begin{itemize} 900@itemize
910\itemsep0em 901@item (subsystem)
911 \item (subsystem) 902@item (subsystem, peerid)
912 \item (subsystem, peerid) 903@item (subsystem, key)
913 \item (subsystem, key) 904@item (subsystem, peerid, key)
914 \item (subsystem, peerid, key) 905@end itemize
915\end{itemize} 906
916 907The @code{callback} function will be called once with each retrieved record and once
917The \lstinline|callback| function will be called once with each retrieved record and once 908more with a @code{NULL} record to signal the end of results.
918more with a \lstinline|NULL| record to signal the end of results. 909
919 910The @code{GNUNET_PEERSTORE_iterate} function returns a handle to the iterate operation. This
920The \lstinline|GNUNET_PEERSTORE_iterate| function returns a handle to the iterate operation. This
921handle can be used to cancel the iterate operation only before the callback function is called with 911handle can be used to cancel the iterate operation only before the callback function is called with
922a \lstinline|NULL| record. 912a @code{NULL} record.
923 913
924@subsection Monitoring records 914@subsection Monitoring records
925 915
@@ -929,7 +919,7 @@ combination (subsystem, peerid, key). To start the monitoring, use the following
929@verbatiminclude tutorial-examples/015.c 919@verbatiminclude tutorial-examples/015.c
930@end example 920@end example
931 921
932Whenever a new record is stored under the given key combination, the \lstinline|callback| function 922Whenever a new record is stored under the given key combination, the @code{callback} function
933will be called with this new record. This will continue until the connection to the PEERSTORE service 923will be called with this new record. This will continue until the connection to the PEERSTORE service
934is broken or the watch operation is canceled: 924is broken or the watch operation is canceled:
935@example 925@example
@@ -944,7 +934,7 @@ function:
944@verbatiminclude tutorial-examples/017.c 934@verbatiminclude tutorial-examples/017.c
945@end example 935@end example
946 936
947If the \lstinline|sync_first| flag is set to \lstinline|GNUNET_YES|, the API will delay the 937If the @code{sync_first} flag is set to @code{GNUNET_YES}, the API will delay the
948disconnection until all store requests are received by the PEERSTORE service. Otherwise, 938disconnection until all store requests are received by the PEERSTORE service. Otherwise,
949it will disconnect immediately. 939it will disconnect immediately.
950 940
@@ -982,8 +972,8 @@ and other unfavorable events, just make several PUT requests!
982@end example 972@end example
983 973
984Exercise: Store a value in the DHT periodically to make sure it is available 974Exercise: Store a value in the DHT periodically to make sure it is available
985over time. You might consider using the function GNUNET\_SCHEDULER\_add\_delayed and 975over time. You might consider using the function @code{GNUNET\_SCHEDULER\_add\_delayed}
986call GNUNET\_DHT\_put from inside a helper function.} 976and call @code{GNUNET\_DHT\_put} from inside a helper function.
987 977
988 978
989@subsection Obtaining data from the DHT 979@subsection Obtaining data from the DHT
@@ -994,9 +984,9 @@ API provides a callback. Once started, the request runs in the service,
994the service will try to get as many results as possible (filtering out 984the service will try to get as many results as possible (filtering out
995duplicates) until the timeout expires or we explicitly stop the request. 985duplicates) until the timeout expires or we explicitly stop the request.
996It is possible to give a ``forever'' timeout with 986It is possible to give a ``forever'' timeout with
997{\tt GNUNET\_TIME\_UNIT\_FOREVER\_REL}. 987@code{GNUNET\_TIME\_UNIT\_FOREVER\_REL}.
998 988
999If we give a route option {\tt GNUNET\_DHT\_RO\_RECORD\_ROUTE} the callback 989If we give a route option @code{GNUNET\_DHT\_RO\_RECORD\_ROUTE} the callback
1000will get a list of all the peers the data has travelled, both on the PUT 990will get a list of all the peers the data has travelled, both on the PUT
1001path and on the GET path. 991path and on the GET path.
1002@example 992@example
@@ -1005,7 +995,7 @@ path and on the GET path.
1005 995
1006Exercise: Store a value in the DHT and after a while retrieve it. Show the IDs of all 996Exercise: Store a value in the DHT and after a while retrieve it. Show the IDs of all
1007the peers the requests have gone through. In order to convert a peer ID to a string, use 997the peers the requests have gone through. In order to convert a peer ID to a string, use
1008the function GNUNET\_i2s. Pay attention to the route option parameters in both calls!} 998the function @code{GNUNET\_i2s}. Pay attention to the route option parameters in both calls!
1009 999
1010@subsection Implementing a block plugin 1000@subsection Implementing a block plugin
1011 1001
@@ -1021,13 +1011,13 @@ described in the following sections.
1021@subsubsection Validating requests and replies 1011@subsubsection Validating requests and replies
1022 1012
1023The evaluate function should validate a reply or a request. It returns 1013The evaluate function should validate a reply or a request. It returns
1024a {\tt GNUNET\_BLOCK\_EvaluationResult}, which is an enumeration. All 1014a @code{GNUNET\_BLOCK\_EvaluationResult}, which is an enumeration. All
1025possible answers are in @file{gnunet\_block\_lib.h}. The function will 1015possible answers are in @file{gnunet\_block\_lib.h}. The function will
1026be called with a {\tt reply\_block} argument of {\tt NULL} for 1016be called with a @code{reply\_block} argument of @code{NULL} for
1027requests. Note that depending on how {\tt evaluate} is called, only 1017requests. Note that depending on how @code{evaluate} is called, only
1028some of the possible return values are valid. The specific meaning of 1018some of the possible return values are valid. The specific meaning of
1029the {\tt xquery} argument is application-specific. Applications that 1019the @code{xquery} argument is application-specific. Applications that
1030do not use an extended query should check that the {\tt xquery\_size} 1020do not use an extended query should check that the @code{xquery\_size}
1031is zero. The block group is typically used to filter duplicate 1021is zero. The block group is typically used to filter duplicate
1032replies. 1022replies.
1033@example 1023@example
@@ -1043,10 +1033,10 @@ circle in the network.
1043@subsubsection Deriving a key from a reply 1033@subsubsection Deriving a key from a reply
1044 1034
1045The DHT can operate more efficiently if it is possible to derive a key 1035The DHT can operate more efficiently if it is possible to derive a key
1046from the value of the corresponding block. The {\tt get\_key} 1036from the value of the corresponding block. The @code{get\_key}
1047function is used to obtain the key of a block --- for example, by 1037function is used to obtain the key of a block --- for example, by
1048means of hashing. If deriving the key is not possible, the function 1038means of hashing. If deriving the key is not possible, the function
1049should simply return {\tt GNUNET\_SYSERR} (the DHT will still work 1039should simply return @code{GNUNET\_SYSERR} (the DHT will still work
1050just fine with such blocks). 1040just fine with such blocks).
1051@example 1041@example
1052@verbatiminclude tutorial-examples/022.c 1042@verbatiminclude tutorial-examples/022.c
@@ -1074,9 +1064,9 @@ little.
1074 1064
1075@subsubsection Integration of the plugin with the build system 1065@subsubsection Integration of the plugin with the build system
1076 1066
1077In order to compile the plugin, the Makefile.am file for the 1067In order to compile the plugin, the @file{Makefile.am} file for the
1078service SERVICE should contain a rule similar to this: 1068service SERVICE should contain a rule similar to this:
1079@c* Actually this is a Makefile not c. But the whole structure of examples 1069@c* Actually this is a Makefile not C. But the whole structure of examples
1080@c* must be improved. 1070@c* must be improved.
1081@example 1071@example
1082@verbatiminclude tutorial-examples/025.c 1072@verbatiminclude tutorial-examples/025.c