gnunet-ext

Template for writing GNUnet extensions
Log | Files | Refs | README | LICENSE

commit 50c57e0ffa957a9d3773844de9851ab2aadbbc82
parent 0c1559b66e66be7c9536eb1bc6c850eb3c006377
Author: Christian Grothoff <christian@grothoff.org>
Date:   Sat, 25 Feb 2017 03:35:18 +0100

updating gnunet-ext to current standards

Diffstat:
A.gitignore | 41+++++++++++++++++++++++++++++++++++++++++
MAUTHORS | 1+
MREADME | 3++-
Mm4/libtool.m4 | 1-
Apo/.gitignore | 6++++++
Asrc/.gitignore | 2++
Asrc/ext/.gitignore | 5+++++
Msrc/ext/Makefile.am | 18++++++++----------
Msrc/ext/ext.conf.in | 5++---
Msrc/ext/ext_api.c | 4++--
Msrc/ext/gnunet-ext.c | 5+++--
Msrc/ext/gnunet-service-ext.c | 135++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------
Asrc/include/.gitignore | 2++
13 files changed, 167 insertions(+), 61 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -0,0 +1,41 @@ +*~ +*.a +*.la +*.lo +*.log +*.o +*.orig +*.rej +*.swp +*.trs +*.kdev4 +.deps/ +.libs/ +Makefile +Makefile.in +aclocal.m4 +autom4te.cache/ +compile +config.guess +config.log +config.status +config.sub +configure +depcomp +gnunet_config.h +gnunet_config.h.in +install-sh +libtool +ltmain.sh +missing +po/*.gmo +pkgconfig/*.pc +src/*/*.conf +stamp-h1 +test-driver +INSTALL +confdefs.h +confdefs.c +confdefs.err +gnunet_ext_config.h +gnunet_ext_config.h.in diff --git a/AUTHORS b/AUTHORS @@ -0,0 +1 @@ +Christian Grothoff diff --git a/README b/README @@ -1 +1,2 @@ -This is a template for GNUnet extensions. +This is a template for GNUnet extensions with sample code providing a starting +point for writing new GNUnet services. diff --git a/m4/libtool.m4 b/m4/libtool.m4 @@ -728,7 +728,6 @@ _LT_CONFIG_SAVE_COMMANDS([ cat <<_LT_EOF >> "$cfgfile" #! $SHELL # Generated automatically by $as_me ($PACKAGE) $VERSION -# Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`: # NOTE: Changes made to this file will be lost: look at ltmain.sh. # Provide generalized library-building support services. diff --git a/po/.gitignore b/po/.gitignore @@ -0,0 +1,6 @@ +Makefile.in +Makefile +POTFILES +gnunet-ext.pot +remove-potcdate.sed +stamp-po diff --git a/src/.gitignore b/src/.gitignore @@ -0,0 +1,2 @@ +Makefile +Makefile.in diff --git a/src/ext/.gitignore b/src/ext/.gitignore @@ -0,0 +1,5 @@ +.deps/ +.libs/ +ext.conf +gnunet-ext +gnunet-service-ext diff --git a/src/ext/Makefile.am b/src/ext/Makefile.am @@ -22,7 +22,7 @@ pkgcfgdir= $(prefix)/share/gnunet/config.d/ libexecdir= $(prefix)/lib/gnunet/libexec/ libgnunetext_la_SOURCES = \ - ext_api.c + ext_api.c libgnunetext_la_LIBADD = \ -lgnunetutil libgnunetext_la_LDFLAGS = \ @@ -35,7 +35,7 @@ bin_PROGRAMS = gnunet-ext libexec_PROGRAMS = gnunet-service-ext check_PROGRAMS = \ - test_ext_api + test_ext_api TESTS = $(check_PROGRAMS) @@ -43,17 +43,17 @@ gnunet_service_ext_SOURCES = \ gnunet-service-ext.c gnunet_service_ext_LDADD = \ -lgnunetutil -lgnunetcore -lgnunetdht\ - $(INTLLIBS) + $(INTLLIBS) gnunet_service_ext_LDFLAGS = \ - $(GNUNET_LDFLAGS) $(WINFLAGS) -export-dynamic + $(GNUNET_LDFLAGS) $(WINFLAGS) -export-dynamic gnunet_ext_SOURCES = \ gnunet-ext.c gnunet_ext_LDADD = \ -lgnunetutil \ - $(INTLLIBS) + $(INTLLIBS) gnunet_ext_LDFLAGS = \ - $(GNUNET_LDFLAGS) $(WINFLAGS) -export-dynamic + $(GNUNET_LDFLAGS) $(WINFLAGS) -export-dynamic @@ -64,6 +64,5 @@ test_ext_api_LDADD = \ -lgnunetutil test_ext_api_LDFLAGS = \ $(GNUNET_LDFLAGS) $(WINFLAGS) -export-dynamic - - pkgcfg_DATA = ext.conf - -\ No newline at end of file + +pkgcfg_DATA = ext.conf diff --git a/src/ext/ext.conf.in b/src/ext/ext.conf.in @@ -2,6 +2,5 @@ BINARY = gnunet-service-ext UNIXPATH = /tmp/gnunet-service-ext.sock HOME = $SERVICEHOME -# PORT = 2106 -@UNIXONLY@ PORT = 2087 - +# PORT = 2500 +@UNIXONLY@ PORT = 2500 diff --git a/src/ext/ext_api.c b/src/ext/ext_api.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) + Copyright (C) 20xx GNUnet e.V. GNUnet is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published @@ -21,7 +21,7 @@ /** * @file ext/ext_api.c * @brief API for ext - * @author + * @author */ #include <gnunet/platform.h> #include <gnunet/gnunet_util_lib.h> diff --git a/src/ext/gnunet-ext.c b/src/ext/gnunet-ext.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) + Copyright (C) 20xx GNUnet e.V. GNUnet is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published @@ -21,7 +21,7 @@ /** * @file ext/gnunet-ext.c * @brief ext tool - * @author + * @author */ #include <gnunet/platform.h> #include <gnunet/gnunet_util_lib.h> @@ -46,6 +46,7 @@ run (void *cls, ret = 0; } + /** * The main function to ext. * diff --git a/src/ext/gnunet-service-ext.c b/src/ext/gnunet-service-ext.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) + Copyright (C) 20xx GNUnet e.V. GNUnet is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published @@ -28,24 +28,55 @@ #include "gnunet_protocols_ext.h" /** + * Some state we track per client. + */ +struct ClientContext +{ + /** + * For telling service to continue processing more messages. + */ + struct GNUNET_SERVICE_Client *c; + + /** + * For sending messages to the client. + */ + struct GNUNET_MQ_Handle *mq; + + /** + * Sample state. + */ + uint32_t state; +}; + + +/** * Our configuration. */ static const struct GNUNET_CONFIGURATION_Handle *cfg; + /** * Handle EXT-message. * - * @param cls closure - * @param client identification of the client + * @param cls identification of the client * @param message the actual message */ static void handle_ext (void *cls, - struct GNUNET_SERVER_Client *client, const struct GNUNET_MessageHeader *message) { - GNUNET_SERVER_receive_done (client, - GNUNET_OK); + struct ClientContext *cc = cls; + struct GNUNET_MQ_Envelope *env; + struct GNUNET_MessageHeader *response; + + /* Send same type of message back... */ + env = GNUNET_MQ_msg (response, + GNUNET_MESSAGE_TYPE_EXT); + GNUNET_MQ_send (cc->mq, + env); + + /* Continue processing more messages from client */ + GNUNET_SERVICE_client_continue (cc->c); } @@ -57,19 +88,7 @@ handle_ext (void *cls, static void shutdown_task (void *cls) { -} - - -/** - * A client disconnected. Remove all of its data structure entries. - * - * @param cls closure, NULL - * @param client identification of the client - */ -static void -handle_client_disconnect (void *cls, - struct GNUNET_SERVER_Client * client) -{ + /* Clean up whatever #run() setup here. */ } @@ -85,37 +104,69 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, const struct GNUNET_CONFIGURATION_Handle *c) { - static const struct GNUNET_SERVER_MessageHandler handlers[] = { - {&handle_ext, NULL, GNUNET_MESSAGE_TYPE_EXT, 0}, - {NULL, NULL, 0, 0} - }; cfg = c; - GNUNET_SERVER_add_handlers (server, handlers); - GNUNET_SERVER_disconnect_notify (server, - &handle_client_disconnect, - NULL); - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, - &shutdown_task, - NULL); + GNUNET_SCHEDULER_add_shutdown (&shutdown_task, + NULL); +} + + +/** + * Callback called when a client connects to the service. + * + * @param cls closure for the service + * @param c the new client that connected to the service + * @param mq the message queue used to send messages to the client + * @return @a c + */ +static void * +client_connect_cb (void *cls, + struct GNUNET_SERVICE_Client *c, + struct GNUNET_MQ_Handle *mq) +{ + struct ClientContext *cc; + + cc = GNUNET_new (struct ClientContext); + cc->c = c; + cc->mq = mq; + /* setup more for new client here */ + return cc; } /** - * The main function for the ext service. + * Callback called when a client disconnected from the service * - * @param argc number of arguments from the command line - * @param argv command line arguments - * @return 0 ok, 1 on error + * @param cls closure for the service + * @param c the client that disconnected + * @param internal_cls our `struct ClientContext` */ -int -main (int argc, char *const *argv) +static void +client_disconnect_cb (void *cls, + struct GNUNET_SERVICE_Client *c, + void *internal_cls) { - return (GNUNET_OK == - GNUNET_SERVICE_run (argc, - argv, - "ext", - GNUNET_SERVICE_OPTION_NONE, - &run, NULL)) ? 0 : 1; + struct ClientContext *cc = internal_cls; + + GNUNET_assert (cc->c == c); + /* Tear down rest of client here */ + GNUNET_free (cc); } + +/** + * Define "main" method using service macro. + */ +GNUNET_SERVICE_MAIN +("ext", + GNUNET_SERVICE_OPTION_NONE, + &run, + &client_connect_cb, + &client_disconnect_cb, + NULL, + GNUNET_MQ_hd_fixed_size (ext, + GNUNET_MESSAGE_TYPE_EXT, + struct GNUNET_MessageHeader, + NULL), + GNUNET_MQ_handler_end ()); + /* end of gnunet-service-ext.c */ diff --git a/src/include/.gitignore b/src/include/.gitignore @@ -0,0 +1,2 @@ +Makefile +Makefile.in