diff options
author | ng0 <ng0@infotropique.org> | 2017-09-06 09:43:52 +0000 |
---|---|---|
committer | ng0 <ng0@infotropique.org> | 2017-09-06 09:43:52 +0000 |
commit | 6a2067a3a386856869c60cbf32463947f9f87c5e (patch) | |
tree | 15d7e15da1437f0cf334ff5e7d6019e7eba36955 /doc | |
parent | d5224cf485343f445dead0516d991d0c5cee644b (diff) | |
download | gnunet-6a2067a3a386856869c60cbf32463947f9f87c5e.tar.gz gnunet-6a2067a3a386856869c60cbf32463947f9f87c5e.zip |
doc: gnunet-c-tutorial: Add nodes.
Diffstat (limited to 'doc')
-rw-r--r-- | doc/gnunet-c-tutorial.texi | 63 |
1 files changed, 51 insertions, 12 deletions
diff --git a/doc/gnunet-c-tutorial.texi b/doc/gnunet-c-tutorial.texi index 824834c92..156b6a14e 100644 --- a/doc/gnunet-c-tutorial.texi +++ b/doc/gnunet-c-tutorial.texi | |||
@@ -58,7 +58,7 @@ important and do not hesitate to contact the GNUnet team if you have | |||
58 | any questions or problems! Check here how to contact the GNUnet | 58 | any questions or problems! Check here how to contact the GNUnet |
59 | team: @uref{https://gnunet.org/contact_information} | 59 | team: @uref{https://gnunet.org/contact_information} |
60 | 60 | ||
61 | 61 | @node Installing GNUnet | |
62 | @section Installing GNUnet | 62 | @section Installing GNUnet |
63 | 63 | ||
64 | First of all you have to install a current version of GNUnet. You can download a | 64 | First of all you have to install a current version of GNUnet. You can download a |
@@ -70,6 +70,7 @@ latest development version things can be broken, functionality can be changed or | |||
70 | can fail. You should only use the development version if you know that you require a | 70 | can fail. You should only use the development version if you know that you require a |
71 | certain feature or a certain issue has been fixed since the last release. | 71 | certain feature or a certain issue has been fixed since the last release. |
72 | 72 | ||
73 | @node Obtaining a stable version | ||
73 | @subsection Obtaining a stable version | 74 | @subsection Obtaining a stable version |
74 | 75 | ||
75 | You can download the latest stable version of GNUnet from GNU FTP mirrors: | 76 | You can download the latest stable version of GNUnet from GNU FTP mirrors: |
@@ -95,6 +96,7 @@ $ cd gnunet | |||
95 | However, please note that stable versions can be very outdated, as a developer | 96 | However, please note that stable versions can be very outdated, as a developer |
96 | you are strongly encouraged to use the version from @uref{https://gnunet.org/git/}. | 97 | you are strongly encouraged to use the version from @uref{https://gnunet.org/git/}. |
97 | 98 | ||
99 | @node Installing Build Tool Chain and Dependencies | ||
98 | @subsection Installing Build Tool Chain and Dependencies | 100 | @subsection Installing Build Tool Chain and Dependencies |
99 | 101 | ||
100 | To successfully compile GNUnet you need the tools to build GNUnet and the required dependencies. | 102 | To successfully compile GNUnet you need the tools to build GNUnet and the required dependencies. |
@@ -107,6 +109,7 @@ For GNUnet bootstrapping support and the http(s) plugin you should install libgn | |||
107 | For the filesharing service you should install at least one of the datastore backends mysql, | 109 | For the filesharing service you should install at least one of the datastore backends mysql, |
108 | sqlite or postgresql. | 110 | sqlite or postgresql. |
109 | 111 | ||
112 | @node Obtaining the latest version from Git | ||
110 | @subsection Obtaining the latest version from Git | 113 | @subsection Obtaining the latest version from Git |
111 | 114 | ||
112 | The latest development version can obtained from our Git repository. To obtain | 115 | The latest development version can obtained from our Git repository. To obtain |
@@ -122,6 +125,7 @@ $ ./bootstrap | |||
122 | 125 | ||
123 | The remainder of this tutorial assumes that you have Git branch ``master'' checked out. | 126 | The remainder of this tutorial assumes that you have Git branch ``master'' checked out. |
124 | 127 | ||
128 | @node Compiling and Installing GNUnet | ||
125 | @subsection Compiling and Installing GNUnet | 129 | @subsection Compiling and Installing GNUnet |
126 | 130 | ||
127 | First, you need to install at least libgnupgerror version 1.27 | 131 | First, you need to install at least libgnupgerror version 1.27 |
@@ -146,6 +150,7 @@ $ sudo make install | |||
146 | $ cd .. | 150 | $ cd .. |
147 | @end example | 151 | @end example |
148 | 152 | ||
153 | @node Installing GNUnet | ||
149 | @subsubsection Installing GNUnet | 154 | @subsubsection Installing GNUnet |
150 | Assuming all dependencies are installed, the following commands will | 155 | Assuming all dependencies are installed, the following commands will |
151 | compile and install GNUnet in your home directory. You can specify the | 156 | compile and install GNUnet in your home directory. You can specify the |
@@ -173,6 +178,7 @@ $ mkdir ~/.config/ | |||
173 | $ touch ~/.config/gnunet.conf | 178 | $ touch ~/.config/gnunet.conf |
174 | @end example | 179 | @end example |
175 | 180 | ||
181 | @node Common Issues - Check your GNUnet installation | ||
176 | @subsection Common Issues - Check your GNUnet installation | 182 | @subsection Common Issues - Check your GNUnet installation |
177 | 183 | ||
178 | You should check your installation to ensure that installing GNUnet | 184 | You should check your installation to ensure that installing GNUnet |
@@ -204,6 +210,7 @@ PASS: test_gnunet_prefix | |||
204 | ============= | 210 | ============= |
205 | @end example | 211 | @end example |
206 | 212 | ||
213 | @node Background: GNUnet Architecture | ||
207 | @section Background: GNUnet Architecture | 214 | @section Background: GNUnet Architecture |
208 | 215 | ||
209 | GNUnet is organized in layers and services. Each service is composed of a | 216 | GNUnet is organized in layers and services. Each service is composed of a |
@@ -247,9 +254,10 @@ client do not affect the service process or other clients. The service and the | |||
247 | clients communicate via a message protocol to be defined and implemented by | 254 | clients communicate via a message protocol to be defined and implemented by |
248 | the programmer. | 255 | the programmer. |
249 | 256 | ||
250 | 257 | @node First Steps with GNUnet | |
251 | @section First Steps with GNUnet | 258 | @section First Steps with GNUnet |
252 | 259 | ||
260 | @node Configure your peer | ||
253 | @subsection Configure your peer | 261 | @subsection Configure your peer |
254 | 262 | ||
255 | First of all we need to configure your peer. Each peer is started with a configuration | 263 | First of all we need to configure your peer. Each peer is started with a configuration |
@@ -280,6 +288,7 @@ GNUNET_HOME = ~/gnunet1/ # Use this directory to store GNUnet data | |||
280 | SERVERS = # prevent bootstrapping | 288 | SERVERS = # prevent bootstrapping |
281 | @end example | 289 | @end example |
282 | 290 | ||
291 | @node Start a peer | ||
283 | @subsection Start a peer | 292 | @subsection Start a peer |
284 | Each GNUnet instance (called peer) has an identity (peer ID) based on a | 293 | Each GNUnet instance (called peer) has an identity (peer ID) based on a |
285 | cryptographic public private key pair. The peer ID is the printable hash of the | 294 | cryptographic public private key pair. The peer ID is the printable hash of the |
@@ -304,7 +313,7 @@ You should see an output containing the peer ID similar to: | |||
304 | I am peer `0PA02UVRKQTS2C .. JL5Q78F6H0B1ACPV1CJI59MEQUMQCC5G'. | 313 | I am peer `0PA02UVRKQTS2C .. JL5Q78F6H0B1ACPV1CJI59MEQUMQCC5G'. |
305 | @end example | 314 | @end example |
306 | 315 | ||
307 | 316 | @node Monitor a peer | |
308 | @subsection Monitor a peer | 317 | @subsection Monitor a peer |
309 | 318 | ||
310 | In this section, we will monitor the behaviour of our peer's DHT service with respect to a | 319 | In this section, we will monitor the behaviour of our peer's DHT service with respect to a |
@@ -328,7 +337,7 @@ $ gnunet-statistics -c ~/peer1.conf # print statistics about current GNUnet sta | |||
328 | $ gnunet-statistics -c ~/peer1.conf -s dht # print statistics about DHT service | 337 | $ gnunet-statistics -c ~/peer1.conf -s dht # print statistics about DHT service |
329 | @end example | 338 | @end example |
330 | 339 | ||
331 | 340 | @node Starting Two Peers by Hand | |
332 | @subsection Starting Two Peers by Hand | 341 | @subsection Starting Two Peers by Hand |
333 | 342 | ||
334 | This section describes how to start two peers on the same machine by hand. | 343 | This section describes how to start two peers on the same machine by hand. |
@@ -336,6 +345,7 @@ The process is rather painful, but the description is somewhat instructive. | |||
336 | In practice, you might prefer the automated method | 345 | In practice, you might prefer the automated method |
337 | (@pxref{Starting Peers Using the Testbed Service}). | 346 | (@pxref{Starting Peers Using the Testbed Service}). |
338 | 347 | ||
348 | @node Setup a second peer | ||
339 | @subsubsection Setup a second peer | 349 | @subsubsection Setup a second peer |
340 | We will now start a second peer on your machine. | 350 | We will now start a second peer on your machine. |
341 | For the second peer, you will need to manually create a modified | 351 | For the second peer, you will need to manually create a modified |
@@ -375,6 +385,7 @@ as needed. Also, make sure the output is different from the | |||
375 | gnunet-peerinfo output for the first peer (otherwise you made an | 385 | gnunet-peerinfo output for the first peer (otherwise you made an |
376 | error in the configuration). | 386 | error in the configuration). |
377 | 387 | ||
388 | @node Start the second peer and connect the peers | ||
378 | @subsubsection Start the second peer and connect the peers | 389 | @subsubsection Start the second peer and connect the peers |
379 | 390 | ||
380 | Then, you can start a second peer using: | 391 | Then, you can start a second peer using: |
@@ -413,6 +424,7 @@ tricky as you're going to be connected to many more peers and would | |||
413 | likely observe traffic and behaviors that are not explicitly controlled | 424 | likely observe traffic and behaviors that are not explicitly controlled |
414 | by you. | 425 | by you. |
415 | 426 | ||
427 | @node How to connect manually | ||
416 | @subsubsection How to connect manually | 428 | @subsubsection How to connect manually |
417 | 429 | ||
418 | If you want to use the @code{peerinfo} tool to connect your peers, you should: | 430 | If you want to use the @code{peerinfo} tool to connect your peers, you should: |
@@ -430,6 +442,7 @@ $ gnunet-core -c peer1.conf | |||
430 | Peer `9TVUCS8P5A7ILLBGO6 [...shortened...] 1KNBJ4NGCHP3JPVULDG' | 442 | Peer `9TVUCS8P5A7ILLBGO6 [...shortened...] 1KNBJ4NGCHP3JPVULDG' |
431 | @end example | 443 | @end example |
432 | 444 | ||
445 | @node Starting Peers Using the Testbed Service | ||
433 | @subsection Starting Peers Using the Testbed Service | 446 | @subsection Starting Peers Using the Testbed Service |
434 | @c \label{sec:testbed} | 447 | @c \label{sec:testbed} |
435 | 448 | ||
@@ -518,9 +531,10 @@ options in the configuration file. See @uref{https://gnunet.org/supported-topolo | |||
518 | Then use the DHT API to store and retrieve values in the | 531 | Then use the DHT API to store and retrieve values in the |
519 | network. | 532 | network. |
520 | 533 | ||
521 | 534 | @node Developing Applications | |
522 | @section Developing Applications | 535 | @section Developing Applications |
523 | 536 | ||
537 | @node gnunet-ext | ||
524 | @subsection gnunet-ext | 538 | @subsection gnunet-ext |
525 | To develop a new peer-to-peer application or to extend GNUnet we provide | 539 | To develop a new peer-to-peer application or to extend GNUnet we provide |
526 | a template build system for writing GNUnet extensions in C. It can be | 540 | a template build system for writing GNUnet extensions in C. It can be |
@@ -560,6 +574,7 @@ In addition the ext systems provides: | |||
560 | @item a configuration template for the service (gnunet-ext/src/ext/ext.conf.in) | 574 | @item a configuration template for the service (gnunet-ext/src/ext/ext.conf.in) |
561 | @end itemize | 575 | @end itemize |
562 | 576 | ||
577 | @node Adapting the Template | ||
563 | @subsection Adapting the Template | 578 | @subsection Adapting the Template |
564 | 579 | ||
565 | The first step for writing any extension with a new service is to | 580 | The first step for writing any extension with a new service is to |
@@ -571,6 +586,7 @@ If you want to adapt the template rename the @file{ext.conf.in} to match your | |||
571 | services name, you have to modify the @code{AC\_OUTPUT} section in @file{configure.ac} | 586 | services name, you have to modify the @code{AC\_OUTPUT} section in @file{configure.ac} |
572 | in the @file{gnunet-ext} root. | 587 | in the @file{gnunet-ext} root. |
573 | 588 | ||
589 | @node Writing a Client Application | ||
574 | @section Writing a Client Application | 590 | @section Writing a Client Application |
575 | 591 | ||
576 | When writing any client application (for example, a command-line | 592 | When writing any client application (for example, a command-line |
@@ -583,6 +599,7 @@ used, which is typically not needed): | |||
583 | @verbatiminclude tutorial-examples/001.c | 599 | @verbatiminclude tutorial-examples/001.c |
584 | @end example | 600 | @end example |
585 | 601 | ||
602 | @node Handling command-line options | ||
586 | @subsection Handling command-line options | 603 | @subsection Handling command-line options |
587 | 604 | ||
588 | Options can then be added easily by adding global variables and | 605 | Options can then be added easily by adding global variables and |
@@ -612,6 +629,7 @@ more persistent P2P functions. | |||
612 | Exercise: Add a few command-line options and print them inside | 629 | Exercise: Add a few command-line options and print them inside |
613 | of @code{run}. What happens if the user gives invalid arguments? | 630 | of @code{run}. What happens if the user gives invalid arguments? |
614 | 631 | ||
632 | @node Writing a Client Library | ||
615 | @subsection Writing a Client Library | 633 | @subsection Writing a Client Library |
616 | 634 | ||
617 | The first and most important step in writing a client library is to | 635 | The first and most important step in writing a client library is to |
@@ -633,6 +651,7 @@ Unique message types must be defined for each message struct in the | |||
633 | @file{gnunet\_protocols.h} header (or an extension-specific include | 651 | @file{gnunet\_protocols.h} header (or an extension-specific include |
634 | file). | 652 | file). |
635 | 653 | ||
654 | @node Connecting to the Service | ||
636 | @subsubsection Connecting to the Service | 655 | @subsubsection Connecting to the Service |
637 | 656 | ||
638 | Before a client library can implement the application-specific protocol | 657 | Before a client library can implement the application-specific protocol |
@@ -650,6 +669,7 @@ receive from the service, and which functions handle them. | |||
650 | The @code{error\_cb} is a function that is to be called whenever | 669 | The @code{error\_cb} is a function that is to be called whenever |
651 | there are errors communicating with the service. | 670 | there are errors communicating with the service. |
652 | 671 | ||
672 | @node Sending messages | ||
653 | @subsubsection Sending messages | 673 | @subsubsection Sending messages |
654 | 674 | ||
655 | In GNUnet, messages are always sent beginning with a @code{struct GNUNET\_MessageHeader} | 675 | In GNUnet, messages are always sent beginning with a @code{struct GNUNET\_MessageHeader} |
@@ -678,7 +698,7 @@ Exercise: Define a helper function to transmit a 32-bit | |||
678 | unsigned integer (as payload) to a service using some given client | 698 | unsigned integer (as payload) to a service using some given client |
679 | handle. | 699 | handle. |
680 | 700 | ||
681 | 701 | @node Receiving Replies from the Service | |
682 | @subsubsection Receiving Replies from the Service | 702 | @subsubsection Receiving Replies from the Service |
683 | 703 | ||
684 | Clients can receive messages from the service using the handlers | 704 | Clients can receive messages from the service using the handlers |
@@ -702,7 +722,7 @@ should call a callback provided to your helper function's API. | |||
702 | 722 | ||
703 | Exercise: Figure out where you can pass values to the closures (@code{cls}). | 723 | Exercise: Figure out where you can pass values to the closures (@code{cls}). |
704 | 724 | ||
705 | 725 | @node Writing a user interface | |
706 | @subsection Writing a user interface | 726 | @subsection Writing a user interface |
707 | 727 | ||
708 | Given a client library, all it takes to access a service now is to | 728 | Given a client library, all it takes to access a service now is to |
@@ -714,11 +734,13 @@ client application to send a request to the service. For example, | |||
714 | send a 32-bit integer value based on a number given at the | 734 | send a 32-bit integer value based on a number given at the |
715 | command-line to the service. | 735 | command-line to the service. |
716 | 736 | ||
737 | @node Writing a Service | ||
717 | @section Writing a Service | 738 | @section Writing a Service |
718 | 739 | ||
719 | Before you can test the client you've written so far, you'll need to also | 740 | Before you can test the client you've written so far, you'll need to also |
720 | implement the corresponding service. | 741 | implement the corresponding service. |
721 | 742 | ||
743 | @node Code Placement | ||
722 | @subsection Code Placement | 744 | @subsection Code Placement |
723 | 745 | ||
724 | New services are placed in their own subdirectory under @file{gnunet/src}. | 746 | New services are placed in their own subdirectory under @file{gnunet/src}. |
@@ -728,6 +750,7 @@ the description of the client-service protocol @file{SERVICE.h} and P2P protocol | |||
728 | @file{gnunet-service-SERVICE.h} and several files for tests, including test code | 750 | @file{gnunet-service-SERVICE.h} and several files for tests, including test code |
729 | and configuration files. | 751 | and configuration files. |
730 | 752 | ||
753 | @node Starting a Service | ||
731 | @subsection Starting a Service | 754 | @subsection Starting a Service |
732 | 755 | ||
733 | The key API definition for creating a service is the @code{GNUNET\_SERVICE\_MAIN} macro: | 756 | The key API definition for creating a service is the @code{GNUNET\_SERVICE\_MAIN} macro: |
@@ -767,7 +790,7 @@ Exercise: Change the service to ``handle'' the message from your | |||
767 | client (for now, by printing a message). What happens if you | 790 | client (for now, by printing a message). What happens if you |
768 | forget to call @code{GNUNET\_SERVICE\_client\_continue()}? | 791 | forget to call @code{GNUNET\_SERVICE\_client\_continue()}? |
769 | 792 | ||
770 | 793 | @node Interacting directly with other Peers using the CORE Service | |
771 | @section Interacting directly with other Peers using the CORE Service | 794 | @section Interacting directly with other Peers using the CORE Service |
772 | 795 | ||
773 | FIXME: This section still needs to be updated to the lastest API! | 796 | FIXME: This section still needs to be updated to the lastest API! |
@@ -781,6 +804,7 @@ is connect to the @code{CORE} service using: | |||
781 | @verbatiminclude tutorial-examples/009.c | 804 | @verbatiminclude tutorial-examples/009.c |
782 | @end example | 805 | @end example |
783 | 806 | ||
807 | @node New P2P connections | ||
784 | @subsection New P2P connections | 808 | @subsection New P2P connections |
785 | 809 | ||
786 | Before any traffic with a different peer can be exchanged, the peer must be | 810 | Before any traffic with a different peer can be exchanged, the peer must be |
@@ -798,6 +822,7 @@ Exercise: Create a service that connects to the @code{CORE}. Then | |||
798 | start (and connect) two peers and print a message once your connect | 822 | start (and connect) two peers and print a message once your connect |
799 | callback is invoked. | 823 | callback is invoked. |
800 | 824 | ||
825 | @node Receiving P2P Messages | ||
801 | @subsection Receiving P2P Messages | 826 | @subsection Receiving P2P Messages |
802 | 827 | ||
803 | To receive messages from @code{CORE}, you pass the desired | 828 | To receive messages from @code{CORE}, you pass the desired |
@@ -814,7 +839,7 @@ handler and start a second peer that only has your ``old'' service | |||
814 | without message handlers. Which ``connect'' handlers are invoked when | 839 | without message handlers. Which ``connect'' handlers are invoked when |
815 | the two peers are connected? Why? | 840 | the two peers are connected? Why? |
816 | 841 | ||
817 | 842 | @node Sending P2P Messages | |
818 | @subsection Sending P2P Messages | 843 | @subsection Sending P2P Messages |
819 | 844 | ||
820 | You can transmit messages to other peers using the @i{mq} you were | 845 | You can transmit messages to other peers using the @i{mq} you were |
@@ -832,7 +857,7 @@ transmission? Count using the STATISTICS service on both ends. Are | |||
832 | messages lost? How can you transmit messages faster? What happens if | 857 | messages lost? How can you transmit messages faster? What happens if |
833 | you stop the peer that is receiving your messages? | 858 | you stop the peer that is receiving your messages? |
834 | 859 | ||
835 | 860 | @node End of P2P connections | |
836 | @subsection End of P2P connections | 861 | @subsection End of P2P connections |
837 | 862 | ||
838 | If a message handler returns @code{GNUNET\_SYSERR}, the remote peer shuts down or | 863 | If a message handler returns @code{GNUNET\_SYSERR}, the remote peer shuts down or |
@@ -846,6 +871,7 @@ The disconnect callback looks like the following: | |||
846 | 871 | ||
847 | Exercise: Fix your service to handle peer disconnects. | 872 | Exercise: Fix your service to handle peer disconnects. |
848 | 873 | ||
874 | @node Storing peer-specific data using the PEERSTORE service | ||
849 | @section Storing peer-specific data using the PEERSTORE service | 875 | @section Storing peer-specific data using the PEERSTORE service |
850 | 876 | ||
851 | GNUnet's PEERSTORE service offers a persistorage for arbitrary peer-specific data. | 877 | GNUnet's PEERSTORE service offers a persistorage for arbitrary peer-specific data. |
@@ -868,6 +894,7 @@ The first step is to start a connection to the PEERSTORE service: | |||
868 | The service handle @code{peerstore_handle} will be needed for all subsequent | 894 | The service handle @code{peerstore_handle} will be needed for all subsequent |
869 | PEERSTORE operations. | 895 | PEERSTORE operations. |
870 | 896 | ||
897 | @node Storing records | ||
871 | @subsection Storing records | 898 | @subsection Storing records |
872 | 899 | ||
873 | To store a new record, use the following function: | 900 | To store a new record, use the following function: |
@@ -891,6 +918,7 @@ void | |||
891 | GNUNET_PEERSTORE_store_cancel (struct GNUNET_PEERSTORE_StoreContext *sc); | 918 | GNUNET_PEERSTORE_store_cancel (struct GNUNET_PEERSTORE_StoreContext *sc); |
892 | @end example | 919 | @end example |
893 | 920 | ||
921 | @node Retrieving records | ||
894 | @subsection Retrieving records | 922 | @subsection Retrieving records |
895 | 923 | ||
896 | To retrieve stored records, use the following function: | 924 | To retrieve stored records, use the following function: |
@@ -914,6 +942,7 @@ The @code{GNUNET_PEERSTORE_iterate} function returns a handle to the iterate ope | |||
914 | handle can be used to cancel the iterate operation only before the callback function is called with | 942 | handle can be used to cancel the iterate operation only before the callback function is called with |
915 | a @code{NULL} record. | 943 | a @code{NULL} record. |
916 | 944 | ||
945 | @node Monitoring records | ||
917 | @subsection Monitoring records | 946 | @subsection Monitoring records |
918 | 947 | ||
919 | PEERSTORE offers the functionality of monitoring for new records stored under a specific key | 948 | PEERSTORE offers the functionality of monitoring for new records stored under a specific key |
@@ -929,6 +958,7 @@ is broken or the watch operation is canceled: | |||
929 | @verbatiminclude tutorial-examples/016.c | 958 | @verbatiminclude tutorial-examples/016.c |
930 | @end example | 959 | @end example |
931 | 960 | ||
961 | @node Disconnecting from PEERSTORE | ||
932 | @subsection Disconnecting from PEERSTORE | 962 | @subsection Disconnecting from PEERSTORE |
933 | 963 | ||
934 | When the connection to the PEERSTORE service is no longer needed, disconnect using the following | 964 | When the connection to the PEERSTORE service is no longer needed, disconnect using the following |
@@ -941,7 +971,7 @@ If the @code{sync_first} flag is set to @code{GNUNET_YES}, the API will delay th | |||
941 | disconnection until all store requests are received by the PEERSTORE service. Otherwise, | 971 | disconnection until all store requests are received by the PEERSTORE service. Otherwise, |
942 | it will disconnect immediately. | 972 | it will disconnect immediately. |
943 | 973 | ||
944 | 974 | @node Using the DHT | |
945 | @section Using the DHT | 975 | @section Using the DHT |
946 | 976 | ||
947 | The DHT allows to store data so other peers in the P2P network can | 977 | The DHT allows to store data so other peers in the P2P network can |
@@ -956,6 +986,7 @@ The second parameter indicates how many requests in parallel to expect. | |||
956 | It is not a hard limit, but a good approximation will make the DHT more | 986 | It is not a hard limit, but a good approximation will make the DHT more |
957 | efficient. | 987 | efficient. |
958 | 988 | ||
989 | @node Storing data in the DHT | ||
959 | @subsection Storing data in the DHT | 990 | @subsection Storing data in the DHT |
960 | Since the DHT is a dynamic environment (peers join and leave frequently) | 991 | Since the DHT is a dynamic environment (peers join and leave frequently) |
961 | the data that we put in the DHT does not stay there indefinitely. It is | 992 | the data that we put in the DHT does not stay there indefinitely. It is |
@@ -978,7 +1009,7 @@ Exercise: Store a value in the DHT periodically to make sure it is available | |||
978 | over time. You might consider using the function @code{GNUNET\_SCHEDULER\_add\_delayed} | 1009 | over time. You might consider using the function @code{GNUNET\_SCHEDULER\_add\_delayed} |
979 | and call @code{GNUNET\_DHT\_put} from inside a helper function. | 1010 | and call @code{GNUNET\_DHT\_put} from inside a helper function. |
980 | 1011 | ||
981 | 1012 | @node Obtaining data from the DHT | |
982 | @subsection Obtaining data from the DHT | 1013 | @subsection Obtaining data from the DHT |
983 | As we saw in the previous example, the DHT works in an asynchronous mode. | 1014 | As we saw in the previous example, the DHT works in an asynchronous mode. |
984 | Each request to the DHT is executed ``in the background'' and the API | 1015 | Each request to the DHT is executed ``in the background'' and the API |
@@ -1000,6 +1031,7 @@ Exercise: Store a value in the DHT and after a while retrieve it. Show the IDs o | |||
1000 | the peers the requests have gone through. In order to convert a peer ID to a string, use | 1031 | the peers the requests have gone through. In order to convert a peer ID to a string, use |
1001 | the function @code{GNUNET\_i2s}. Pay attention to the route option parameters in both calls! | 1032 | the function @code{GNUNET\_i2s}. Pay attention to the route option parameters in both calls! |
1002 | 1033 | ||
1034 | @node Implementing a block plugin | ||
1003 | @subsection Implementing a block plugin | 1035 | @subsection Implementing a block plugin |
1004 | 1036 | ||
1005 | In order to store data in the DHT, it is necessary to provide a block | 1037 | In order to store data in the DHT, it is necessary to provide a block |
@@ -1011,6 +1043,7 @@ in the service's respective directory. The | |||
1011 | mandatory functions that need to be implemented for a block plugin are | 1043 | mandatory functions that need to be implemented for a block plugin are |
1012 | described in the following sections. | 1044 | described in the following sections. |
1013 | 1045 | ||
1046 | @node Validating requests and replies | ||
1014 | @subsubsection Validating requests and replies | 1047 | @subsubsection Validating requests and replies |
1015 | 1048 | ||
1016 | The evaluate function should validate a reply or a request. It returns | 1049 | The evaluate function should validate a reply or a request. It returns |
@@ -1033,6 +1066,7 @@ typically done using the Bloom filter block group provided by | |||
1033 | @file{libgnunetblockgroup.so}. Failure to do so may cause replies to | 1066 | @file{libgnunetblockgroup.so}. Failure to do so may cause replies to |
1034 | circle in the network. | 1067 | circle in the network. |
1035 | 1068 | ||
1069 | @node Deriving a key from a reply | ||
1036 | @subsubsection Deriving a key from a reply | 1070 | @subsubsection Deriving a key from a reply |
1037 | 1071 | ||
1038 | The DHT can operate more efficiently if it is possible to derive a key | 1072 | The DHT can operate more efficiently if it is possible to derive a key |
@@ -1045,6 +1079,7 @@ just fine with such blocks). | |||
1045 | @verbatiminclude tutorial-examples/022.c | 1079 | @verbatiminclude tutorial-examples/022.c |
1046 | @end example | 1080 | @end example |
1047 | 1081 | ||
1082 | @node Initialization of the plugin | ||
1048 | @subsubsection Initialization of the plugin | 1083 | @subsubsection Initialization of the plugin |
1049 | 1084 | ||
1050 | The plugin is realized as a shared C library. The library must export | 1085 | The plugin is realized as a shared C library. The library must export |
@@ -1056,6 +1091,7 @@ validation and obtaining keys (the ones just defined above). | |||
1056 | @verbatiminclude tutorial-examples/023.c | 1091 | @verbatiminclude tutorial-examples/023.c |
1057 | @end example | 1092 | @end example |
1058 | 1093 | ||
1094 | @node Shutdown of the plugin | ||
1059 | @subsubsection Shutdown of the plugin | 1095 | @subsubsection Shutdown of the plugin |
1060 | 1096 | ||
1061 | Following GNUnet's general plugin API concept, the plugin must | 1097 | Following GNUnet's general plugin API concept, the plugin must |
@@ -1065,6 +1101,7 @@ little. | |||
1065 | @verbatiminclude tutorial-examples/024.c | 1101 | @verbatiminclude tutorial-examples/024.c |
1066 | @end example | 1102 | @end example |
1067 | 1103 | ||
1104 | @node Integration of the plugin with the build system | ||
1068 | @subsubsection Integration of the plugin with the build system | 1105 | @subsubsection Integration of the plugin with the build system |
1069 | 1106 | ||
1070 | In order to compile the plugin, the @file{Makefile.am} file for the | 1107 | In order to compile the plugin, the @file{Makefile.am} file for the |
@@ -1079,6 +1116,7 @@ Exercise: Write a block plugin that accepts all queries | |||
1079 | and all replies but prints information about queries and replies | 1116 | and all replies but prints information about queries and replies |
1080 | when the respective validation hooks are called. | 1117 | when the respective validation hooks are called. |
1081 | 1118 | ||
1119 | @node Monitoring the DHT | ||
1082 | @subsection Monitoring the DHT | 1120 | @subsection Monitoring the DHT |
1083 | It is possible to monitor the functioning of the local DHT service. When monitoring | 1121 | It is possible to monitor the functioning of the local DHT service. When monitoring |
1084 | the DHT, the service will alert the monitoring program of any events, | 1122 | the DHT, the service will alert the monitoring program of any events, |
@@ -1094,6 +1132,7 @@ is called with all the information about the event. | |||
1094 | @verbatiminclude tutorial-examples/026.c | 1132 | @verbatiminclude tutorial-examples/026.c |
1095 | @end example | 1133 | @end example |
1096 | 1134 | ||
1135 | @node Debugging with gnunet-arm | ||
1097 | @section Debugging with gnunet-arm | 1136 | @section Debugging with gnunet-arm |
1098 | 1137 | ||
1099 | Even if services are managed by @command{gnunet-arm}, you can start them with | 1138 | Even if services are managed by @command{gnunet-arm}, you can start them with |