diff options
author | ng0 <ng0@infotropique.org> | 2017-10-21 16:37:12 +0000 |
---|---|---|
committer | ng0 <ng0@infotropique.org> | 2017-10-21 16:37:12 +0000 |
commit | 7f07f09d52aed7c449a330d8a82c1280776e49e0 (patch) | |
tree | 01dc30d8791a3b23661f31b046029b9de4cd6a21 /doc/documentation/tutorial-examples | |
parent | c49513a65ed3db8ba7043481d0dab920ab40ee48 (diff) | |
download | gnunet-7f07f09d52aed7c449a330d8a82c1280776e49e0.tar.gz gnunet-7f07f09d52aed7c449a330d8a82c1280776e49e0.zip |
move docmentation to separate folder
Diffstat (limited to 'doc/documentation/tutorial-examples')
27 files changed, 361 insertions, 0 deletions
diff --git a/doc/documentation/tutorial-examples/001.c b/doc/documentation/tutorial-examples/001.c new file mode 100644 index 000000000..7f6699dd2 --- /dev/null +++ b/doc/documentation/tutorial-examples/001.c | |||
@@ -0,0 +1,29 @@ | |||
1 | #include <gnunet/platform.h> | ||
2 | #include <gnunet/gnunet_util_lib.h> | ||
3 | |||
4 | static int ret; | ||
5 | |||
6 | static void | ||
7 | run (void *cls, | ||
8 | char *const *args, | ||
9 | const char *cfgfile, | ||
10 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
11 | { | ||
12 | // main code here | ||
13 | ret = 0; | ||
14 | } | ||
15 | |||
16 | int | ||
17 | main (int argc, char *const *argv) | ||
18 | { | ||
19 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
20 | GNUNET_GETOPT_OPTION_END | ||
21 | }; | ||
22 | return (GNUNET_OK == | ||
23 | GNUNET_PROGRAM_run (argc, | ||
24 | argv, | ||
25 | "binary-name", | ||
26 | gettext_noop ("binary description text"), | ||
27 | options, &run, NULL)) ? ret : 1; | ||
28 | } | ||
29 | |||
diff --git a/doc/documentation/tutorial-examples/002.c b/doc/documentation/tutorial-examples/002.c new file mode 100644 index 000000000..02233fd61 --- /dev/null +++ b/doc/documentation/tutorial-examples/002.c | |||
@@ -0,0 +1,17 @@ | |||
1 | static char *string_option; | ||
2 | static int a_flag; | ||
3 | |||
4 | // ... | ||
5 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
6 | GNUNET_GETOPT_option_string ('s', "name", "SOMESTRING", | ||
7 | gettext_noop ("text describing the string_option NAME"), | ||
8 | &string_option}, | ||
9 | GNUNET_GETOPT_option_flag ('f', "flag", | ||
10 | gettext_noop ("text describing the flag option"), | ||
11 | &a_flag), | ||
12 | GNUNET_GETOPT_OPTION_END | ||
13 | }; | ||
14 | string_option = NULL; | ||
15 | a_flag = GNUNET_SYSERR; | ||
16 | // ... | ||
17 | |||
diff --git a/doc/documentation/tutorial-examples/003.c b/doc/documentation/tutorial-examples/003.c new file mode 100644 index 000000000..d158d7e75 --- /dev/null +++ b/doc/documentation/tutorial-examples/003.c | |||
@@ -0,0 +1,11 @@ | |||
1 | struct GNUNET_MQ_MessageHandlers handlers[] = { | ||
2 | // ... | ||
3 | GNUNET_MQ_handler_end () | ||
4 | }; | ||
5 | struct GNUNET_MQ_Handle *mq; | ||
6 | |||
7 | mq = GNUNET_CLIENT_connect (cfg, | ||
8 | "service-name", | ||
9 | handlers, | ||
10 | &error_cb, | ||
11 | NULL); | ||
diff --git a/doc/documentation/tutorial-examples/004.c b/doc/documentation/tutorial-examples/004.c new file mode 100644 index 000000000..0ef007907 --- /dev/null +++ b/doc/documentation/tutorial-examples/004.c | |||
@@ -0,0 +1,5 @@ | |||
1 | struct GNUNET_MessageHeader | ||
2 | { | ||
3 | uint16_t size GNUNET_PACKED; | ||
4 | uint16_t type GNUNET_PACKED; | ||
5 | }; | ||
diff --git a/doc/documentation/tutorial-examples/005.c b/doc/documentation/tutorial-examples/005.c new file mode 100644 index 000000000..0c459f509 --- /dev/null +++ b/doc/documentation/tutorial-examples/005.c | |||
@@ -0,0 +1,8 @@ | |||
1 | struct GNUNET_MQ_Envelope *env; | ||
2 | struct GNUNET_MessageHeader *msg; | ||
3 | |||
4 | env = GNUNET_MQ_msg_extra (msg, payload_size, GNUNET_MY_MESSAGE_TYPE); | ||
5 | memcpy (&msg[1], &payload, payload_size); | ||
6 | // Send message via message queue 'mq' | ||
7 | GNUNET_mq_send (mq, env); | ||
8 | |||
diff --git a/doc/documentation/tutorial-examples/006.c b/doc/documentation/tutorial-examples/006.c new file mode 100644 index 000000000..944d2b18c --- /dev/null +++ b/doc/documentation/tutorial-examples/006.c | |||
@@ -0,0 +1,31 @@ | |||
1 | static void | ||
2 | handle_fix (void *cls, const struct MyMessage *msg) | ||
3 | { | ||
4 | // process 'msg' | ||
5 | } | ||
6 | |||
7 | static int | ||
8 | check_var (void *cls, const struct MyVarMessage *msg) | ||
9 | { | ||
10 | // check 'msg' is well-formed | ||
11 | return GNUNET_OK; | ||
12 | } | ||
13 | |||
14 | static void | ||
15 | handle_var (void *cls, const struct MyVarMessage *msg) | ||
16 | { | ||
17 | // process 'msg' | ||
18 | } | ||
19 | |||
20 | struct GNUNET_MQ_MessageHandler handlers[] = { | ||
21 | GNUNET_MQ_hd_fixed_size (fix, | ||
22 | GNUNET_MESSAGE_TYPE_MY_FIX, | ||
23 | struct MyMessage, | ||
24 | NULL), | ||
25 | GNUNET_MQ_hd_fixed_size (var, | ||
26 | GNUNET_MESSAGE_TYPE_MY_VAR, | ||
27 | struct MyVarMessage, | ||
28 | NULL), | ||
29 | |||
30 | GNUNET_MQ_handler_end () | ||
31 | }; | ||
diff --git a/doc/documentation/tutorial-examples/007.c b/doc/documentation/tutorial-examples/007.c new file mode 100644 index 000000000..096539e43 --- /dev/null +++ b/doc/documentation/tutorial-examples/007.c | |||
@@ -0,0 +1,10 @@ | |||
1 | GNUNET_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/documentation/tutorial-examples/008.c b/doc/documentation/tutorial-examples/008.c new file mode 100644 index 000000000..2dffe2cf9 --- /dev/null +++ b/doc/documentation/tutorial-examples/008.c | |||
@@ -0,0 +1,22 @@ | |||
1 | static void | ||
2 | run (void *cls, | ||
3 | const struct GNUNET_CONFIGURATION_Handle *c, | ||
4 | struct GNUNET_SERVICE_Handle *service) | ||
5 | { | ||
6 | } | ||
7 | |||
8 | static void * | ||
9 | client_connect_cb (void *cls, | ||
10 | struct GNUNET_SERVICE_Client *c, | ||
11 | struct GNUNET_MQ_Handle *mq) | ||
12 | { | ||
13 | return c; | ||
14 | } | ||
15 | |||
16 | static void | ||
17 | client_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/documentation/tutorial-examples/009.c b/doc/documentation/tutorial-examples/009.c new file mode 100644 index 000000000..26d918fb0 --- /dev/null +++ b/doc/documentation/tutorial-examples/009.c | |||
@@ -0,0 +1,9 @@ | |||
1 | #include <gnunet/gnunet_core_service.h> | ||
2 | |||
3 | struct GNUNET_CORE_Handle * | ||
4 | GNUNET_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/documentation/tutorial-examples/010.c b/doc/documentation/tutorial-examples/010.c new file mode 100644 index 000000000..33494490d --- /dev/null +++ b/doc/documentation/tutorial-examples/010.c | |||
@@ -0,0 +1,8 @@ | |||
1 | void * | ||
2 | connects (void *cls, | ||
3 | const struct GNUNET_PeerIdentity *peer, | ||
4 | struct GNUNET_MQ_Handle *mq) | ||
5 | { | ||
6 | return mq; | ||
7 | } | ||
8 | |||
diff --git a/doc/documentation/tutorial-examples/011.c b/doc/documentation/tutorial-examples/011.c new file mode 100644 index 000000000..23bc051de --- /dev/null +++ b/doc/documentation/tutorial-examples/011.c | |||
@@ -0,0 +1,8 @@ | |||
1 | void | ||
2 | disconnects (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/documentation/tutorial-examples/012.c b/doc/documentation/tutorial-examples/012.c new file mode 100644 index 000000000..cb21d78ab --- /dev/null +++ b/doc/documentation/tutorial-examples/012.c | |||
@@ -0,0 +1,4 @@ | |||
1 | #include "gnunet_peerstore_service.h" | ||
2 | |||
3 | peerstore_handle = GNUNET_PEERSTORE_connect (cfg); | ||
4 | |||
diff --git a/doc/documentation/tutorial-examples/013.1.c b/doc/documentation/tutorial-examples/013.1.c new file mode 100644 index 000000000..fa5212868 --- /dev/null +++ b/doc/documentation/tutorial-examples/013.1.c | |||
@@ -0,0 +1,3 @@ | |||
1 | void | ||
2 | GNUNET_PEERSTORE_store_cancel (struct GNUNET_PEERSTORE_StoreContext | ||
3 | *sc); | ||
diff --git a/doc/documentation/tutorial-examples/013.c b/doc/documentation/tutorial-examples/013.c new file mode 100644 index 000000000..6792417e1 --- /dev/null +++ b/doc/documentation/tutorial-examples/013.c | |||
@@ -0,0 +1,12 @@ | |||
1 | struct GNUNET_PEERSTORE_StoreContext * | ||
2 | GNUNET_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/documentation/tutorial-examples/014.c b/doc/documentation/tutorial-examples/014.c new file mode 100644 index 000000000..ce204f795 --- /dev/null +++ b/doc/documentation/tutorial-examples/014.c | |||
@@ -0,0 +1,9 @@ | |||
1 | struct GNUNET_PEERSTORE_IterateContext * | ||
2 | GNUNET_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/documentation/tutorial-examples/015.c b/doc/documentation/tutorial-examples/015.c new file mode 100644 index 000000000..0dd267e8e --- /dev/null +++ b/doc/documentation/tutorial-examples/015.c | |||
@@ -0,0 +1,8 @@ | |||
1 | struct GNUNET_PEERSTORE_WatchContext * | ||
2 | GNUNET_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/documentation/tutorial-examples/016.c b/doc/documentation/tutorial-examples/016.c new file mode 100644 index 000000000..d169da16d --- /dev/null +++ b/doc/documentation/tutorial-examples/016.c | |||
@@ -0,0 +1,4 @@ | |||
1 | void | ||
2 | GNUNET_PEERSTORE_watch_cancel (struct GNUNET_PEERSTORE_WatchContext | ||
3 | *wc); | ||
4 | |||
diff --git a/doc/documentation/tutorial-examples/017.c b/doc/documentation/tutorial-examples/017.c new file mode 100644 index 000000000..c86fbcd1f --- /dev/null +++ b/doc/documentation/tutorial-examples/017.c | |||
@@ -0,0 +1,4 @@ | |||
1 | void | ||
2 | GNUNET_PEERSTORE_disconnect (struct GNUNET_PEERSTORE_Handle *h, | ||
3 | int sync_first); | ||
4 | |||
diff --git a/doc/documentation/tutorial-examples/018.c b/doc/documentation/tutorial-examples/018.c new file mode 100644 index 000000000..3fc22584c --- /dev/null +++ b/doc/documentation/tutorial-examples/018.c | |||
@@ -0,0 +1,2 @@ | |||
1 | dht_handle = GNUNET_DHT_connect (cfg, parallel_requests); | ||
2 | |||
diff --git a/doc/documentation/tutorial-examples/019.c b/doc/documentation/tutorial-examples/019.c new file mode 100644 index 000000000..aaf001516 --- /dev/null +++ b/doc/documentation/tutorial-examples/019.c | |||
@@ -0,0 +1,18 @@ | |||
1 | message_sent_cont (void *cls, | ||
2 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
3 | { | ||
4 | // Request has left local node | ||
5 | } | ||
6 | |||
7 | struct GNUNET_DHT_PutHandle * | ||
8 | GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle, | ||
9 | const struct GNUNET_HashCode *key, | ||
10 | uint32_t desired_replication_level, | ||
11 | enum GNUNET_DHT_RouteOption options, | ||
12 | enum GNUNET_BLOCK_Type type, | ||
13 | size_t size, | ||
14 | const void *data, | ||
15 | struct GNUNET_TIME_Absolute exp, | ||
16 | struct GNUNET_TIME_Relative timeout, | ||
17 | GNUNET_DHT_PutContinuation cont, void *cont_cls) | ||
18 | |||
diff --git a/doc/documentation/tutorial-examples/020.c b/doc/documentation/tutorial-examples/020.c new file mode 100644 index 000000000..596db3069 --- /dev/null +++ b/doc/documentation/tutorial-examples/020.c | |||
@@ -0,0 +1,25 @@ | |||
1 | static void | ||
2 | get_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, | ||
9 | const void *data) | ||
10 | { | ||
11 | // Optionally: | ||
12 | GNUNET_DHT_get_stop (get_handle); | ||
13 | } | ||
14 | |||
15 | get_handle = | ||
16 | GNUNET_DHT_get_start (dht_handle, | ||
17 | block_type, | ||
18 | &key, | ||
19 | replication, | ||
20 | GNUNET_DHT_RO_NONE, | ||
21 | NULL, | ||
22 | 0, | ||
23 | &get_result_iterator, | ||
24 | cls) | ||
25 | |||
diff --git a/doc/documentation/tutorial-examples/021.c b/doc/documentation/tutorial-examples/021.c new file mode 100644 index 000000000..688a31fe0 --- /dev/null +++ b/doc/documentation/tutorial-examples/021.c | |||
@@ -0,0 +1,13 @@ | |||
1 | static enum GNUNET_BLOCK_EvaluationResult | ||
2 | block_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/documentation/tutorial-examples/022.c b/doc/documentation/tutorial-examples/022.c new file mode 100644 index 000000000..a373619bd --- /dev/null +++ b/doc/documentation/tutorial-examples/022.c | |||
@@ -0,0 +1,8 @@ | |||
1 | static int | ||
2 | block_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/documentation/tutorial-examples/023.c b/doc/documentation/tutorial-examples/023.c new file mode 100644 index 000000000..820c38b10 --- /dev/null +++ b/doc/documentation/tutorial-examples/023.c | |||
@@ -0,0 +1,17 @@ | |||
1 | void * | ||
2 | libgnunet_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/documentation/tutorial-examples/024.c b/doc/documentation/tutorial-examples/024.c new file mode 100644 index 000000000..2e84b5905 --- /dev/null +++ b/doc/documentation/tutorial-examples/024.c | |||
@@ -0,0 +1,9 @@ | |||
1 | void * | ||
2 | libgnunet_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/documentation/tutorial-examples/025.c b/doc/documentation/tutorial-examples/025.c new file mode 100644 index 000000000..66d4f80ec --- /dev/null +++ b/doc/documentation/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/documentation/tutorial-examples/026.c b/doc/documentation/tutorial-examples/026.c new file mode 100644 index 000000000..264e0b6b9 --- /dev/null +++ b/doc/documentation/tutorial-examples/026.c | |||
@@ -0,0 +1,52 @@ | |||
1 | static void | ||
2 | get_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 | |||
14 | static void | ||
15 | get_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 | |||
29 | static void | ||
30 | put_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 | |||
45 | monitor_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 | |||