From 50c57e0ffa957a9d3773844de9851ab2aadbbc82 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 25 Feb 2017 03:35:18 +0100 Subject: updating gnunet-ext to current standards --- src/.gitignore | 2 + src/ext/.gitignore | 5 ++ src/ext/Makefile.am | 17 +++--- src/ext/ext.conf.in | 5 +- src/ext/ext_api.c | 4 +- src/ext/gnunet-ext.c | 5 +- src/ext/gnunet-service-ext.c | 135 +++++++++++++++++++++++++++++-------------- src/include/.gitignore | 2 + 8 files changed, 117 insertions(+), 58 deletions(-) create mode 100644 src/.gitignore create mode 100644 src/ext/.gitignore create mode 100644 src/include/.gitignore (limited to 'src') diff --git a/src/.gitignore b/src/.gitignore new file mode 100644 index 0000000..282522d --- /dev/null +++ b/src/.gitignore @@ -0,0 +1,2 @@ +Makefile +Makefile.in diff --git a/src/ext/.gitignore b/src/ext/.gitignore new file mode 100644 index 0000000..0694e74 --- /dev/null +++ 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 index 977c3d2..b5c04e7 100644 --- 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 index 586e1f1..01a6f54 100644 --- 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 index f4fe779..65637d5 100644 --- 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 #include diff --git a/src/ext/gnunet-ext.c b/src/ext/gnunet-ext.c index 51c7f80..36fc02b 100644 --- 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 #include @@ -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 index 7876047..d292eac 100644 --- 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 @@ -27,25 +27,56 @@ #include #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 new file mode 100644 index 0000000..282522d --- /dev/null +++ b/src/include/.gitignore @@ -0,0 +1,2 @@ +Makefile +Makefile.in -- cgit v1.2.3