From 7101471b5fc9ad10a0a0c06fb2aaeb5a568dbf56 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 25 Oct 2018 15:46:45 +0200 Subject: doc/documentation split into doc/tutorial and doc/handbook for clarity and to avoid automake freakout --- doc/tutorial/examples/001.c | 29 ++++++++++ doc/tutorial/examples/002.c | 17 ++++++ doc/tutorial/examples/003.c | 11 ++++ doc/tutorial/examples/004.c | 5 ++ doc/tutorial/examples/005.c | 9 ++++ doc/tutorial/examples/006.c | 31 +++++++++++ doc/tutorial/examples/007.c | 10 ++++ doc/tutorial/examples/008.c | 22 ++++++++ doc/tutorial/examples/009.c | 9 ++++ doc/tutorial/examples/010.c | 8 +++ doc/tutorial/examples/011.c | 8 +++ doc/tutorial/examples/012.c | 4 ++ doc/tutorial/examples/013.1.c | 3 ++ doc/tutorial/examples/013.c | 12 +++++ doc/tutorial/examples/014.c | 9 ++++ doc/tutorial/examples/015.c | 8 +++ doc/tutorial/examples/016.c | 4 ++ doc/tutorial/examples/017.c | 4 ++ doc/tutorial/examples/018.c | 2 + doc/tutorial/examples/019.c | 18 +++++++ doc/tutorial/examples/020.c | 25 +++++++++ doc/tutorial/examples/021.c | 13 +++++ doc/tutorial/examples/022.c | 8 +++ doc/tutorial/examples/023.c | 17 ++++++ doc/tutorial/examples/024.c | 9 ++++ doc/tutorial/examples/025.Makefile.am | 15 ++++++ doc/tutorial/examples/026.c | 52 ++++++++++++++++++ doc/tutorial/examples/testbed_test.c | 99 +++++++++++++++++++++++++++++++++++ 28 files changed, 461 insertions(+) create mode 100644 doc/tutorial/examples/001.c create mode 100644 doc/tutorial/examples/002.c create mode 100644 doc/tutorial/examples/003.c create mode 100644 doc/tutorial/examples/004.c create mode 100644 doc/tutorial/examples/005.c create mode 100644 doc/tutorial/examples/006.c create mode 100644 doc/tutorial/examples/007.c create mode 100644 doc/tutorial/examples/008.c create mode 100644 doc/tutorial/examples/009.c create mode 100644 doc/tutorial/examples/010.c create mode 100644 doc/tutorial/examples/011.c create mode 100644 doc/tutorial/examples/012.c create mode 100644 doc/tutorial/examples/013.1.c create mode 100644 doc/tutorial/examples/013.c create mode 100644 doc/tutorial/examples/014.c create mode 100644 doc/tutorial/examples/015.c create mode 100644 doc/tutorial/examples/016.c create mode 100644 doc/tutorial/examples/017.c create mode 100644 doc/tutorial/examples/018.c create mode 100644 doc/tutorial/examples/019.c create mode 100644 doc/tutorial/examples/020.c create mode 100644 doc/tutorial/examples/021.c create mode 100644 doc/tutorial/examples/022.c create mode 100644 doc/tutorial/examples/023.c create mode 100644 doc/tutorial/examples/024.c create mode 100644 doc/tutorial/examples/025.Makefile.am create mode 100644 doc/tutorial/examples/026.c create mode 100644 doc/tutorial/examples/testbed_test.c (limited to 'doc/tutorial/examples') 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 @@ +#include +#include + +static int ret; + +static void +run (void *cls, + char *const *args, + const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *cfg) +{ + // main code here + ret = 0; +} + +int +main (int argc, char *const *argv) +{ + struct GNUNET_GETOPT_CommandLineOption options[] = { + GNUNET_GETOPT_OPTION_END + }; + return (GNUNET_OK == + GNUNET_PROGRAM_run (argc, + argv, + "binary-name", + gettext_noop ("binary description text"), + options, &run, NULL)) ? ret : 1; +} + 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 @@ +static char *string_option; +static int a_flag; + +// ... + struct GNUNET_GETOPT_CommandLineOption options[] = { + GNUNET_GETOPT_option_string ('s', "name", "SOMESTRING", + gettext_noop ("text describing the string_option NAME"), + &string_option}, + GNUNET_GETOPT_option_flag ('f', "flag", + gettext_noop ("text describing the flag option"), + &a_flag), + GNUNET_GETOPT_OPTION_END + }; + string_option = NULL; + a_flag = GNUNET_SYSERR; +// ... + 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 @@ +struct GNUNET_MQ_MessageHandlers handlers[] = { + // ... + GNUNET_MQ_handler_end () +}; +struct GNUNET_MQ_Handle *mq; + +mq = GNUNET_CLIENT_connect (cfg, + "service-name", + handlers, + &error_cb, + 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 @@ +struct GNUNET_MessageHeader +{ + uint16_t size GNUNET_PACKED; + uint16_t type GNUNET_PACKED; +}; 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 @@ +struct GNUNET_MQ_Envelope *env; +struct GNUNET_MessageHeader *msg; + +env = GNUNET_MQ_msg_extra (msg, payload_size, GNUNET_MY_MESSAGE_TYPE); +GNUNET_memcpy (&msg[1], + &payload, + payload_size); +// Send message via message queue 'mq' +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 @@ +static void +handle_fix (void *cls, const struct MyMessage *msg) +{ + // process 'msg' +} + +static int +check_var (void *cls, const struct MyVarMessage *msg) +{ + // check 'msg' is well-formed + return GNUNET_OK; +} + +static void +handle_var (void *cls, const struct MyVarMessage *msg) +{ + // process 'msg' +} + +struct GNUNET_MQ_MessageHandler handlers[] = { + GNUNET_MQ_hd_fixed_size (fix, + GNUNET_MESSAGE_TYPE_MY_FIX, + struct MyMessage, + NULL), + GNUNET_MQ_hd_fixed_size (var, + GNUNET_MESSAGE_TYPE_MY_VAR, + struct MyVarMessage, + NULL), + + GNUNET_MQ_handler_end () +}; 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 @@ +GNUNET_SERVICE_MAIN +("service-name", + GNUNET_SERVICE_OPTION_NONE, + &run, + &client_connect_cb, + &client_disconnect_cb, + NULL, + GNUNET_MQ_hd_fixed_size (...), + GNUNET_MQ_hd_var_size (...), + 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 @@ +static void +run (void *cls, + const struct GNUNET_CONFIGURATION_Handle *c, + struct GNUNET_SERVICE_Handle *service) +{ +} + +static void * +client_connect_cb (void *cls, + struct GNUNET_SERVICE_Client *c, + struct GNUNET_MQ_Handle *mq) +{ + return c; +} + +static void +client_disconnect_cb (void *cls, + struct GNUNET_SERVICE_Client *c, + void *internal_cls) +{ + GNUNET_assert (c == internal_cls); +} 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 @@ +#include + +struct GNUNET_CORE_Handle * +GNUNET_CORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, + void *cls, + GNUNET_CORE_StartupCallback init, + GNUNET_CORE_ConnectEventHandler connects, + GNUNET_CORE_DisconnectEventHandler disconnects, + 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 @@ +void * +connects (void *cls, + const struct GNUNET_PeerIdentity *peer, + struct GNUNET_MQ_Handle *mq) +{ + return mq; +} + 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 @@ +void +disconnects (void *cls, + const struct GNUNET_PeerIdentity * peer) +{ + /* Remove peer's identity from known peers */ + /* Make sure no messages are sent to peer from now on */ +} + 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 @@ +#include "gnunet_peerstore_service.h" + +peerstore_handle = GNUNET_PEERSTORE_connect (cfg); + 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 @@ +void +GNUNET_PEERSTORE_store_cancel (struct GNUNET_PEERSTORE_StoreContext + *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 @@ +struct GNUNET_PEERSTORE_StoreContext * +GNUNET_PEERSTORE_store (struct GNUNET_PEERSTORE_Handle *h, + const char *sub_system, + const struct GNUNET_PeerIdentity *peer, + const char *key, + const void *value, + size_t size, + struct GNUNET_TIME_Absolute expiry, + enum GNUNET_PEERSTORE_StoreOption options, + GNUNET_PEERSTORE_Continuation cont, + void *cont_cls); + 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 @@ +struct GNUNET_PEERSTORE_IterateContext * +GNUNET_PEERSTORE_iterate (struct GNUNET_PEERSTORE_Handle *h, + const char *sub_system, + const struct GNUNET_PeerIdentity *peer, + const char *key, + struct GNUNET_TIME_Relative timeout, + GNUNET_PEERSTORE_Processor callback, + void *callback_cls); + 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 @@ +struct GNUNET_PEERSTORE_WatchContext * +GNUNET_PEERSTORE_watch (struct GNUNET_PEERSTORE_Handle *h, + const char *sub_system, + const struct GNUNET_PeerIdentity *peer, + const char *key, + GNUNET_PEERSTORE_Processor callback, + void *callback_cls); + 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 @@ +void +GNUNET_PEERSTORE_watch_cancel (struct GNUNET_PEERSTORE_WatchContext + *wc); + 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 @@ +void +GNUNET_PEERSTORE_disconnect (struct GNUNET_PEERSTORE_Handle *h, + int sync_first); + 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 @@ +dht_handle = GNUNET_DHT_connect (cfg, parallel_requests); + 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 @@ +message_sent_cont (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + // Request has left local node +} + +struct GNUNET_DHT_PutHandle * +GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle, + const struct GNUNET_HashCode *key, + uint32_t desired_replication_level, + enum GNUNET_DHT_RouteOption options, + enum GNUNET_BLOCK_Type type, + size_t size, + const void *data, + struct GNUNET_TIME_Absolute exp, + struct GNUNET_TIME_Relative timeout, + GNUNET_DHT_PutContinuation cont, void *cont_cls) + 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 @@ +static void +get_result_iterator (void *cls, struct GNUNET_TIME_Absolute expiration, + const struct GNUNET_HashCode *key, + const struct GNUNET_PeerIdentity *get_path, + unsigned int get_path_length, + const struct GNUNET_PeerIdentity *put_path, + unsigned int put_path_length, + enum GNUNET_BLOCK_Type type, size_t size, + const void *data) +{ + // Optionally: + GNUNET_DHT_get_stop (get_handle); +} + +get_handle = + GNUNET_DHT_get_start (dht_handle, + block_type, + &key, + replication, + GNUNET_DHT_RO_NONE, + NULL, + 0, + &get_result_iterator, + cls) + 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 @@ +static enum GNUNET_BLOCK_EvaluationResult +block_plugin_SERVICE_evaluate (void *cls, + enum GNUNET_BLOCK_Type type, + struct GNUNET_BlockGroup *bg, + const GNUNET_HashCode *query, + const void *xquery, + size_t xquery_size, + const void *reply_block, + size_t reply_block_size) +{ + // Verify type, block and bg +} + 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 @@ +static int +block_plugin_SERVICE_get_key (void *cls, enum GNUNET_BLOCK_Type type, + const void *block, size_t block_size, + struct GNUNET_HashCode *key) +{ + // Store the key in the key argument, return GNUNET_OK on success. +} + 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 @@ +void * +libgnunet_plugin_block_SERVICE_init (void *cls) +{ + static enum GNUNET_BLOCK_Type types[] = + { + GNUNET_BLOCK_TYPE_SERVICE_BLOCKYPE, + GNUNET_BLOCK_TYPE_ANY + }; + struct GNUNET_BLOCK_PluginFunctions *api; + + api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); + api->evaluate = &block_plugin_SERICE_evaluate; + api->get_key = &block_plugin_SERVICE_get_key; + api->types = types; + return api; +} + 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 @@ +void * +libgnunet_plugin_block_SERVICE_done (void *cls) +{ + struct GNUNET_TRANSPORT_PluginFunctions *api = cls; + + GNUNET_free (api); + return NULL; +} + 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 @@ + plugindir = $(libdir)/gnunet + + plugin_LTLIBRARIES = \ + libgnunet_plugin_block_ext.la + libgnunet_plugin_block_ext_la_SOURCES = \ + plugin_block_ext.c + libgnunet_plugin_block_ext_la_LIBADD = \ + $(prefix)/lib/libgnunethello.la \ + $(prefix)/lib/libgnunetblock.la \ + $(prefix)/lib/libgnunetutil.la + libgnunet_plugin_block_ext_la_LDFLAGS = \ + $(GN_PLUGIN_LDFLAGS) + libgnunet_plugin_block_ext_la_DEPENDENCIES = \ + $(prefix)/lib/libgnunetblock.la + 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 @@ +static void +get_callback (void *cls, + enum GNUNET_DHT_RouteOption options, + enum GNUNET_BLOCK_Type type, + uint32_t hop_count, + uint32_t desired_replication_level, + unsigned int path_length, + const struct GNUNET_PeerIdentity *path, + const struct GNUNET_HashCode * key) +{ +} + + +static void +get_resp_callback (void *cls, + enum GNUNET_BLOCK_Type type, + const struct GNUNET_PeerIdentity *get_path, + unsigned int get_path_length, + const struct GNUNET_PeerIdentity *put_path, + unsigned int put_path_length, + struct GNUNET_TIME_Absolute exp, + const struct GNUNET_HashCode * key, + const void *data, + size_t size) +{ +} + + +static void +put_callback (void *cls, + enum GNUNET_DHT_RouteOption options, + enum GNUNET_BLOCK_Type type, + uint32_t hop_count, + uint32_t desired_replication_level, + unsigned int path_length, + const struct GNUNET_PeerIdentity *path, + struct GNUNET_TIME_Absolute exp, + const struct GNUNET_HashCode * key, + const void *data, + size_t size) +{ +} + + +monitor_handle = GNUNET_DHT_monitor_start (dht_handle, + block_type, + key, + &get_callback, + &get_resp_callback, + &put_callback, + cls); + 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 @@ +#include +#include +#include +#include +#include + +#define NUM_PEERS 20 + +static struct GNUNET_TESTBED_Operation *dht_op; + +static struct GNUNET_DHT_Handle *dht_handle; + + +struct MyContext +{ + int ht_len; +} ctxt; + + +static int result; + + +static void +shutdown_task (void *cls) +{ + if (NULL != dht_op) + { + GNUNET_TESTBED_operation_done (dht_op); + dht_op = NULL; + dht_handle = NULL; + } + result = GNUNET_OK; +} + + +static void +service_connect_comp (void *cls, + struct GNUNET_TESTBED_Operation *op, + void *ca_result, + const char *emsg) +{ + GNUNET_assert (op == dht_op); + dht_handle = ca_result; + // Do work here... + GNUNET_SCHEDULER_shutdown (); +} + + +static void * +dht_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) +{ + struct MyContext *ctxt = cls; + + dht_handle = GNUNET_DHT_connect (cfg, ctxt->ht_len); + return dht_handle; +} + + +static void +dht_da (void *cls, void *op_result) +{ + struct MyContext *ctxt = cls; + + GNUNET_DHT_disconnect ((struct GNUNET_DHT_Handle *) op_result); + dht_handle = NULL; +} + + +static void +test_master (void *cls, + struct GNUNET_TESTBED_RunHandle *h, + unsigned int num_peers, + struct GNUNET_TESTBED_Peer **peers, + unsigned int links_succeeded, + unsigned int links_failed) +{ + ctxt.ht_len = 10; + dht_op = GNUNET_TESTBED_service_connect + (NULL, peers[0], "dht", + &service_connect_comp, NULL, + &dht_ca, &dht_da, &ctxt); + GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); +} + + +int +main (int argc, char **argv) +{ + int ret; + + result = GNUNET_SYSERR; + ret = GNUNET_TESTBED_test_run + ("awesome-test", "template.conf", + NUM_PEERS, 0LL, + NULL, NULL, &test_master, NULL); + if ( (GNUNET_OK != ret) || (GNUNET_OK != result) ) + return 1; + return 0; +} -- cgit v1.2.3