gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [gnunet-ext] branch master updated: updating gnunet-ext to


From: gnunet
Subject: [GNUnet-SVN] [gnunet-ext] branch master updated: updating gnunet-ext to current standards
Date: Sat, 25 Feb 2017 03:35:20 +0100

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository gnunet-ext.

The following commit(s) were added to refs/heads/master by this push:
     new 50c57e0  updating gnunet-ext to current standards
50c57e0 is described below

commit 50c57e0ffa957a9d3773844de9851ab2aadbbc82
Author: Christian Grothoff <address@hidden>
AuthorDate: Sat Feb 25 03:35:18 2017 +0100

    updating gnunet-ext to current standards
---
 .gitignore                   |  41 +++++++++++++
 AUTHORS                      |   1 +
 README                       |   3 +-
 m4/libtool.m4                |   1 -
 po/.gitignore                |   6 ++
 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 +
 13 files changed, 167 insertions(+), 60 deletions(-)

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..13020e7
--- /dev/null
+++ 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
index e69de29..eb41b69 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -0,0 +1 @@
+Christian Grothoff
diff --git a/README b/README
index a166810..e628d22 100644
--- 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
index 10ab284..ee80844 100644
--- 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
new file mode 100644
index 0000000..3fbf582
--- /dev/null
+++ 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
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
address@hidden@ PORT = 2087
-
+# PORT = 2500
address@hidden@ 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 <gnunet/platform.h>
 #include <gnunet/gnunet_util_lib.h>
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 <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
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
@@ -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
new file mode 100644
index 0000000..282522d
--- /dev/null
+++ b/src/include/.gitignore
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]