diff options
author | Christian Grothoff <christian@grothoff.org> | 2018-10-25 15:46:45 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2018-10-25 15:46:45 +0200 |
commit | 7101471b5fc9ad10a0a0c06fb2aaeb5a568dbf56 (patch) | |
tree | 589b209e1943461eccb56e1bed4e4d4323bd8c08 /doc/tutorial/examples | |
parent | 8a4b969fd2e9fb399dfd1d9d1569e95a77d599bb (diff) | |
download | gnunet-7101471b5fc9ad10a0a0c06fb2aaeb5a568dbf56.tar.gz gnunet-7101471b5fc9ad10a0a0c06fb2aaeb5a568dbf56.zip |
doc/documentation split into doc/tutorial and doc/handbook for clarity and to avoid automake freakout
Diffstat (limited to 'doc/tutorial/examples')
28 files changed, 461 insertions, 0 deletions
diff --git a/doc/tutorial/examples/001.c b/doc/tutorial/examples/001.c new file mode 100644 index 000000000..7f6699dd2 --- /dev/null +++ b/doc/tutorial/examples/001.c | |||
@@ -0,0 +1,29 @@ | |||
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/tutorial/examples/002.c b/doc/tutorial/examples/002.c new file mode 100644 index 000000000..02233fd61 --- /dev/null +++ b/doc/tutorial/examples/002.c | |||
@@ -0,0 +1,17 @@ | |||
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/tutorial/examples/003.c b/doc/tutorial/examples/003.c new file mode 100644 index 000000000..d158d7e75 --- /dev/null +++ b/doc/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/tutorial/examples/004.c b/doc/tutorial/examples/004.c new file mode 100644 index 000000000..0ef007907 --- /dev/null +++ b/doc/tutorial/examples/004.c | |||
@@ -0,0 +1,5 @@ | |||
1 | struct GNUNET_MessageHeader | ||
2 | { | ||
3 | uint16_t size GNUNET_PACKED; | ||
4 | uint16_t type GNUNET_PACKED; | ||
5 | }; | ||
diff --git a/doc/tutorial/examples/005.c b/doc/tutorial/examples/005.c new file mode 100644 index 000000000..1b59f85a6 --- /dev/null +++ b/doc/tutorial/examples/005.c | |||
@@ -0,0 +1,9 @@ | |||
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 | GNUNET_memcpy (&msg[1], | ||
6 | &payload, | ||
7 | payload_size); | ||
8 | // Send message via message queue 'mq' | ||
9 | GNUNET_mq_send (mq, env); | ||
diff --git a/doc/tutorial/examples/006.c b/doc/tutorial/examples/006.c new file mode 100644 index 000000000..944d2b18c --- /dev/null +++ b/doc/tutorial/examples/006.c | |||
@@ -0,0 +1,31 @@ | |||
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/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 @@ | |||
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/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 @@ | |||
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/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 | |||
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/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 @@ | |||
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/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 @@ | |||
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/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 | |||
3 | peerstore_handle = GNUNET_PEERSTORE_connect (cfg); | ||
4 | |||
diff --git a/doc/tutorial/examples/013.1.c b/doc/tutorial/examples/013.1.c new file mode 100644 index 000000000..fa5212868 --- /dev/null +++ b/doc/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/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 @@ | |||
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/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 @@ | |||
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/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 @@ | |||
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/tutorial/examples/016.c b/doc/tutorial/examples/016.c new file mode 100644 index 000000000..d169da16d --- /dev/null +++ b/doc/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/tutorial/examples/017.c b/doc/tutorial/examples/017.c new file mode 100644 index 000000000..c86fbcd1f --- /dev/null +++ b/doc/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/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 @@ | |||
1 | dht_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..aaf001516 --- /dev/null +++ b/doc/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/tutorial/examples/020.c b/doc/tutorial/examples/020.c new file mode 100644 index 000000000..596db3069 --- /dev/null +++ b/doc/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/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 @@ | |||
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/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 @@ | |||
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/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 @@ | |||
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/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 @@ | |||
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/tutorial/examples/025.Makefile.am b/doc/tutorial/examples/025.Makefile.am new file mode 100644 index 000000000..66d4f80ec --- /dev/null +++ b/doc/tutorial/examples/025.Makefile.am | |||
@@ -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 @@ | |||
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 | |||
diff --git a/doc/tutorial/examples/testbed_test.c b/doc/tutorial/examples/testbed_test.c new file mode 100644 index 000000000..1696234b0 --- /dev/null +++ b/doc/tutorial/examples/testbed_test.c | |||
@@ -0,0 +1,99 @@ | |||
1 | #include <unistd.h> | ||
2 | #include <gnunet/platform.h> | ||
3 | #include <gnunet/gnunet_util_lib.h> | ||
4 | #include <gnunet/gnunet_testbed_service.h> | ||
5 | #include <gnunet/gnunet_dht_service.h> | ||
6 | |||
7 | #define NUM_PEERS 20 | ||
8 | |||
9 | static struct GNUNET_TESTBED_Operation *dht_op; | ||
10 | |||
11 | static struct GNUNET_DHT_Handle *dht_handle; | ||
12 | |||
13 | |||
14 | struct MyContext | ||
15 | { | ||
16 | int ht_len; | ||
17 | } ctxt; | ||
18 | |||
19 | |||
20 | static int result; | ||
21 | |||
22 | |||
23 | static void | ||
24 | shutdown_task (void *cls) | ||
25 | { | ||
26 | if (NULL != dht_op) | ||
27 | { | ||
28 | GNUNET_TESTBED_operation_done (dht_op); | ||
29 | dht_op = NULL; | ||
30 | dht_handle = NULL; | ||
31 | } | ||
32 | result = GNUNET_OK; | ||
33 | } | ||
34 | |||
35 | |||
36 | static void | ||
37 | service_connect_comp (void *cls, | ||
38 | struct GNUNET_TESTBED_Operation *op, | ||
39 | void *ca_result, | ||
40 | const char *emsg) | ||
41 | { | ||
42 | GNUNET_assert (op == dht_op); | ||
43 | dht_handle = ca_result; | ||
44 | // Do work here... | ||
45 | GNUNET_SCHEDULER_shutdown (); | ||
46 | } | ||
47 | |||
48 | |||
49 | static void * | ||
50 | dht_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
51 | { | ||
52 | struct MyContext *ctxt = cls; | ||
53 | |||
54 | dht_handle = GNUNET_DHT_connect (cfg, ctxt->ht_len); | ||
55 | return dht_handle; | ||
56 | } | ||
57 | |||
58 | |||
59 | static void | ||
60 | dht_da (void *cls, void *op_result) | ||
61 | { | ||
62 | struct MyContext *ctxt = cls; | ||
63 | |||
64 | GNUNET_DHT_disconnect ((struct GNUNET_DHT_Handle *) op_result); | ||
65 | dht_handle = NULL; | ||
66 | } | ||
67 | |||
68 | |||
69 | static void | ||
70 | test_master (void *cls, | ||
71 | struct GNUNET_TESTBED_RunHandle *h, | ||
72 | unsigned int num_peers, | ||
73 | struct GNUNET_TESTBED_Peer **peers, | ||
74 | unsigned int links_succeeded, | ||
75 | unsigned int links_failed) | ||
76 | { | ||
77 | ctxt.ht_len = 10; | ||
78 | dht_op = GNUNET_TESTBED_service_connect | ||
79 | (NULL, peers[0], "dht", | ||
80 | &service_connect_comp, NULL, | ||
81 | &dht_ca, &dht_da, &ctxt); | ||
82 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); | ||
83 | } | ||
84 | |||
85 | |||
86 | int | ||
87 | main (int argc, char **argv) | ||
88 | { | ||
89 | int ret; | ||
90 | |||
91 | result = GNUNET_SYSERR; | ||
92 | ret = GNUNET_TESTBED_test_run | ||
93 | ("awesome-test", "template.conf", | ||
94 | NUM_PEERS, 0LL, | ||
95 | NULL, NULL, &test_master, NULL); | ||
96 | if ( (GNUNET_OK != ret) || (GNUNET_OK != result) ) | ||
97 | return 1; | ||
98 | return 0; | ||
99 | } | ||