diff options
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 0000000000..7f6699dd22 --- /dev/null +++ b/doc/documentation/tutorial-examples/001.c @@ -0,0 +1,29 @@ +#include <gnunet/platform.h> +#include <gnunet/gnunet_util_lib.h> + +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/documentation/tutorial-examples/002.c b/doc/documentation/tutorial-examples/002.c new file mode 100644 index 0000000000..02233fd619 --- /dev/null +++ b/doc/documentation/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/documentation/tutorial-examples/003.c b/doc/documentation/tutorial-examples/003.c new file mode 100644 index 0000000000..d158d7e756 --- /dev/null +++ b/doc/documentation/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/documentation/tutorial-examples/004.c b/doc/documentation/tutorial-examples/004.c new file mode 100644 index 0000000000..0ef0079070 --- /dev/null +++ b/doc/documentation/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/documentation/tutorial-examples/005.c b/doc/documentation/tutorial-examples/005.c new file mode 100644 index 0000000000..0c459f509d --- /dev/null +++ b/doc/documentation/tutorial-examples/005.c @@ -0,0 +1,8 @@ +struct GNUNET_MQ_Envelope *env; +struct GNUNET_MessageHeader *msg; + +env = GNUNET_MQ_msg_extra (msg, payload_size, GNUNET_MY_MESSAGE_TYPE); +memcpy (&msg[1], &payload, payload_size); +// Send message via message queue 'mq' +GNUNET_mq_send (mq, env); + diff --git a/doc/documentation/tutorial-examples/006.c b/doc/documentation/tutorial-examples/006.c new file mode 100644 index 0000000000..944d2b18c7 --- /dev/null +++ b/doc/documentation/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/documentation/tutorial-examples/007.c b/doc/documentation/tutorial-examples/007.c new file mode 100644 index 0000000000..096539e432 --- /dev/null +++ b/doc/documentation/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/documentation/tutorial-examples/008.c b/doc/documentation/tutorial-examples/008.c new file mode 100644 index 0000000000..2dffe2cf91 --- /dev/null +++ b/doc/documentation/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/documentation/tutorial-examples/009.c b/doc/documentation/tutorial-examples/009.c new file mode 100644 index 0000000000..26d918fb02 --- /dev/null +++ b/doc/documentation/tutorial-examples/009.c @@ -0,0 +1,9 @@ +#include <gnunet/gnunet_core_service.h> + +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/documentation/tutorial-examples/010.c b/doc/documentation/tutorial-examples/010.c new file mode 100644 index 0000000000..33494490db --- /dev/null +++ b/doc/documentation/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/documentation/tutorial-examples/011.c b/doc/documentation/tutorial-examples/011.c new file mode 100644 index 0000000000..23bc051de1 --- /dev/null +++ b/doc/documentation/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/documentation/tutorial-examples/012.c b/doc/documentation/tutorial-examples/012.c new file mode 100644 index 0000000000..cb21d78ab2 --- /dev/null +++ b/doc/documentation/tutorial-examples/012.c @@ -0,0 +1,4 @@ +#include "gnunet_peerstore_service.h" + +peerstore_handle = GNUNET_PEERSTORE_connect (cfg); + diff --git a/doc/documentation/tutorial-examples/013.1.c b/doc/documentation/tutorial-examples/013.1.c new file mode 100644 index 0000000000..fa52128685 --- /dev/null +++ b/doc/documentation/tutorial-examples/013.1.c @@ -0,0 +1,3 @@ +void +GNUNET_PEERSTORE_store_cancel (struct GNUNET_PEERSTORE_StoreContext + *sc); diff --git a/doc/documentation/tutorial-examples/013.c b/doc/documentation/tutorial-examples/013.c new file mode 100644 index 0000000000..6792417e19 --- /dev/null +++ b/doc/documentation/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/documentation/tutorial-examples/014.c b/doc/documentation/tutorial-examples/014.c new file mode 100644 index 0000000000..ce204f7956 --- /dev/null +++ b/doc/documentation/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/documentation/tutorial-examples/015.c b/doc/documentation/tutorial-examples/015.c new file mode 100644 index 0000000000..0dd267e8e3 --- /dev/null +++ b/doc/documentation/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/documentation/tutorial-examples/016.c b/doc/documentation/tutorial-examples/016.c new file mode 100644 index 0000000000..d169da16d0 --- /dev/null +++ b/doc/documentation/tutorial-examples/016.c @@ -0,0 +1,4 @@ +void +GNUNET_PEERSTORE_watch_cancel (struct GNUNET_PEERSTORE_WatchContext + *wc); + diff --git a/doc/documentation/tutorial-examples/017.c b/doc/documentation/tutorial-examples/017.c new file mode 100644 index 0000000000..c86fbcd1ff --- /dev/null +++ b/doc/documentation/tutorial-examples/017.c @@ -0,0 +1,4 @@ +void +GNUNET_PEERSTORE_disconnect (struct GNUNET_PEERSTORE_Handle *h, + int sync_first); + diff --git a/doc/documentation/tutorial-examples/018.c b/doc/documentation/tutorial-examples/018.c new file mode 100644 index 0000000000..3fc22584c8 --- /dev/null +++ b/doc/documentation/tutorial-examples/018.c @@ -0,0 +1,2 @@ +dht_handle = GNUNET_DHT_connect (cfg, parallel_requests); + diff --git a/doc/documentation/tutorial-examples/019.c b/doc/documentation/tutorial-examples/019.c new file mode 100644 index 0000000000..aaf0015169 --- /dev/null +++ b/doc/documentation/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/documentation/tutorial-examples/020.c b/doc/documentation/tutorial-examples/020.c new file mode 100644 index 0000000000..596db30693 --- /dev/null +++ b/doc/documentation/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/documentation/tutorial-examples/021.c b/doc/documentation/tutorial-examples/021.c new file mode 100644 index 0000000000..688a31fe0e --- /dev/null +++ b/doc/documentation/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/documentation/tutorial-examples/022.c b/doc/documentation/tutorial-examples/022.c new file mode 100644 index 0000000000..a373619bd3 --- /dev/null +++ b/doc/documentation/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/documentation/tutorial-examples/023.c b/doc/documentation/tutorial-examples/023.c new file mode 100644 index 0000000000..820c38b10a --- /dev/null +++ b/doc/documentation/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/documentation/tutorial-examples/024.c b/doc/documentation/tutorial-examples/024.c new file mode 100644 index 0000000000..2e84b5905c --- /dev/null +++ b/doc/documentation/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/documentation/tutorial-examples/025.c b/doc/documentation/tutorial-examples/025.c new file mode 100644 index 0000000000..66d4f80eca --- /dev/null +++ b/doc/documentation/tutorial-examples/025.c @@ -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/documentation/tutorial-examples/026.c b/doc/documentation/tutorial-examples/026.c new file mode 100644 index 0000000000..264e0b6b97 --- /dev/null +++ b/doc/documentation/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); + |