gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r33890 - in gnunet: . src src/include src/sensor src/sensor


From: gnunet
Subject: [GNUnet-SVN] r33890 - in gnunet: . src src/include src/sensor src/sensordashboard
Date: Tue, 1 Jul 2014 19:42:04 +0200

Author: otarabai
Date: 2014-07-01 19:42:04 +0200 (Tue, 01 Jul 2014)
New Revision: 33890

Added:
   gnunet/src/sensordashboard/
   gnunet/src/sensordashboard/Makefile.am
   gnunet/src/sensordashboard/gnunet-sensordashboard.c
   gnunet/src/sensordashboard/gnunet-service-sensordashboard.c
   gnunet/src/sensordashboard/sensordashboard.conf.in
   gnunet/src/sensordashboard/test_sensordashboard_api.c
Modified:
   gnunet/configure.ac
   gnunet/src/Makefile.am
   gnunet/src/include/gnunet_applications.h
   gnunet/src/sensor/Makefile.am
   gnunet/src/sensor/gnunet-service-sensor-reporting.c
Log:
sensor dashboard (collection point) initial commit


Modified: gnunet/configure.ac
===================================================================
--- gnunet/configure.ac 2014-07-01 17:32:21 UTC (rev 33889)
+++ gnunet/configure.ac 2014-07-01 17:42:04 UTC (rev 33890)
@@ -1491,6 +1491,8 @@
 src/secretsharing/secretsharing.conf
 src/sensor/Makefile
 src/sensor/sensor.conf
+src/sensordashboard/Makefile
+src/sensordashboard/sensordashboard.conf
 src/scalarproduct/Makefile
 src/scalarproduct/scalarproduct.conf
 src/set/Makefile

Modified: gnunet/src/Makefile.am
===================================================================
--- gnunet/src/Makefile.am      2014-07-01 17:32:21 UTC (rev 33889)
+++ gnunet/src/Makefile.am      2014-07-01 17:42:04 UTC (rev 33890)
@@ -11,6 +11,7 @@
  SCALARPRODUCT = scalarproduct
  SENSOR = sensor
  PEERSTORE = peerstore
+ SENSORDASHBOARD = sensordashboard
 endif
 
 if HAVE_EXPERIMENTAL
@@ -26,7 +27,8 @@
   $(SCALARPRODUCT) \
   $(EXPERIMENTATION) \
   $(PEERSTORE) \
-  $(SENSOR)
+  $(SENSOR) \
+  $(SENSORDASHBOARD)
 endif
 
 

Modified: gnunet/src/include/gnunet_applications.h
===================================================================
--- gnunet/src/include/gnunet_applications.h    2014-07-01 17:32:21 UTC (rev 
33889)
+++ gnunet/src/include/gnunet_applications.h    2014-07-01 17:42:04 UTC (rev 
33890)
@@ -101,7 +101,12 @@
  */
 #define GNUNET_APPLICATION_TYPE_MQTT 23
 
+/**
+ * Application receiving sensor measurements from peers
+ */
+#define GNUNET_APPLICATION_TYPE_SENSORDASHBOARD 24
 
+
 #if 0                           /* keep Emacsens' auto-indent happy */
 {
 #endif

Modified: gnunet/src/sensor/Makefile.am
===================================================================
--- gnunet/src/sensor/Makefile.am       2014-07-01 17:32:21 UTC (rev 33889)
+++ gnunet/src/sensor/Makefile.am       2014-07-01 17:42:04 UTC (rev 33890)
@@ -41,6 +41,7 @@
   $(top_builddir)/src/util/libgnunetutil.la \
   $(top_builddir)/src/statistics/libgnunetstatistics.la \
   $(top_builddir)/src/peerstore/libgnunetpeerstore.la \
+  $(top_builddir)/src/cadet/libgnunetcadet.la \
   $(GN_LIBINTL)
 
 libgnunetsensor_la_SOURCES = \

Modified: gnunet/src/sensor/gnunet-service-sensor-reporting.c
===================================================================
--- gnunet/src/sensor/gnunet-service-sensor-reporting.c 2014-07-01 17:32:21 UTC 
(rev 33889)
+++ gnunet/src/sensor/gnunet-service-sensor-reporting.c 2014-07-01 17:42:04 UTC 
(rev 33890)
@@ -27,6 +27,7 @@
 #include "gnunet_util_lib.h"
 #include "sensor.h"
 #include "gnunet_peerstore_service.h"
+#include "gnunet_cadet_service.h"
 
 #define LOG(kind,...) GNUNET_log_from (kind, "sensor-reporting",__VA_ARGS__)
 
@@ -62,18 +63,23 @@
 /**
  * My peer id
  */
-struct GNUNET_PeerIdentity peerid;
+static struct GNUNET_PeerIdentity peerid;
 
+/**
+ * Handle to CADET service
+ */
+static struct GNUNET_CADET_Handle *cadet;
 
+
 /**
  * Stop sensor reporting module
  */
-void SENSOR_reporting_stop()
+void SENSOR_reporting_stop ()
 {
   LOG (GNUNET_ERROR_TYPE_DEBUG, "Stopping sensor reporting module.\n");
   if (NULL != peerstore)
   {
-    GNUNET_PEERSTORE_disconnect(peerstore);
+    GNUNET_PEERSTORE_disconnect (peerstore);
     peerstore = NULL;
   }
 }
@@ -118,7 +124,7 @@
     crc = GNUNET_new (struct CollectionReportingContext);
     crc->sensor = sensor;
     crc->task =
-        GNUNET_SCHEDULER_add_delayed(sensor->collection_interval,
+        GNUNET_SCHEDULER_add_delayed (sensor->collection_interval,
             &report_collection_point,
             crc);
   }
@@ -133,6 +139,24 @@
 }
 
 /**
+ * Function called whenever a channel is destroyed.  Should clean up
+ * any associated state.
+ *
+ * It must NOT call #GNUNET_CADET_channel_destroy on the channel.
+ *
+ * @param cls closure (set from #GNUNET_CADET_connect)
+ * @param channel connection to the other end (henceforth invalid)
+ * @param channel_ctx place where local state associated
+ *                   with the channel is stored
+ */
+static void cadet_channel_destroyed (void *cls,
+    const struct GNUNET_CADET_Channel *channel,
+    void *channel_ctx)
+{
+
+}
+
+/**
  * Start the sensor reporting module
  *
  * @param c our service configuration
@@ -140,9 +164,12 @@
  * @return #GNUNET_OK if started successfully, #GNUNET_SYSERR otherwise
  */
 int
-SENSOR_reporting_start(const struct GNUNET_CONFIGURATION_Handle *c,
+SENSOR_reporting_start (const struct GNUNET_CONFIGURATION_Handle *c,
     struct GNUNET_CONTAINER_MultiHashMap *sensors)
 {
+  static struct GNUNET_CADET_MessageHandler cadet_handlers[] = {
+      {NULL, 0, 0}
+  };
 
   GNUNET_assert(NULL != sensors);
   cfg = c;
@@ -151,10 +178,25 @@
   peerstore = GNUNET_PEERSTORE_connect(cfg);
   if (NULL == peerstore)
   {
-    LOG (GNUNET_ERROR_TYPE_ERROR, _("Could not connect to peerstore 
service.\n"));
-    SENSOR_reporting_stop();
+    LOG (GNUNET_ERROR_TYPE_ERROR,
+        _("Failed to connect to peerstore service.\n"));
+    SENSOR_reporting_stop ();
     return GNUNET_SYSERR;
   }
+  cadet = GNUNET_CADET_connect(cfg,
+      NULL,
+      NULL,
+      &cadet_channel_destroyed,
+      cadet_handlers,
+      NULL);
+  if (NULL == cadet)
+  {
+    LOG (GNUNET_ERROR_TYPE_ERROR,
+        _("Failed to connect to CADET service.\n"));
+    SENSOR_reporting_stop ();
+    return GNUNET_SYSERR;
+  }
+
   return GNUNET_OK;
 }
 

Index: gnunet/src/sensordashboard
===================================================================
--- gnunet/src/sensordashboard  2014-07-01 17:32:21 UTC (rev 33889)
+++ gnunet/src/sensordashboard  2014-07-01 17:42:04 UTC (rev 33890)

Property changes on: gnunet/src/sensordashboard
___________________________________________________________________
Added: svn:ignore
## -0,0 +1,6 ##
+.deps
+gnunet-service-sensordashboard
+Makefile
+gnunet-sensordashboard
+Makefile.in
+sensordashboard.conf
Added: gnunet/src/sensordashboard/Makefile.am
===================================================================
--- gnunet/src/sensordashboard/Makefile.am                              (rev 0)
+++ gnunet/src/sensordashboard/Makefile.am      2014-07-01 17:42:04 UTC (rev 
33890)
@@ -0,0 +1,50 @@
+AM_CPPFLAGS = -I$(top_srcdir)/src/include
+
+pkgcfgdir= $(pkgdatadir)/config.d/
+
+libexecdir= $(pkglibdir)/libexec/
+
+dist_pkgcfg_DATA = \
+  sensordashboard.conf
+
+if MINGW
+ WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols 
+endif
+
+if USE_COVERAGE
+  AM_CFLAGS = -fprofile-arcs -ftest-coverage
+endif
+
+bin_PROGRAMS = \
+ gnunet-sensordashboard 
+
+libexec_PROGRAMS = \
+ gnunet-service-sensordashboard
+
+gnunet_sensordashboard_SOURCES = \
+ gnunet-sensordashboard.c         
+gnunet_sensordashboard_LDADD = \
+  $(top_builddir)/src/util/libgnunetutil.la \
+  $(GN_LIBINTL)
+
+gnunet_service_sensordashboard_SOURCES = \
+ gnunet-service-sensordashboard.c         
+gnunet_service_sensordashboard_LDADD = \
+  $(top_builddir)/src/util/libgnunetutil.la \
+  $(top_builddir)/src/cadet/libgnunetcadet.la \
+  $(GN_LIBINTL)
+
+
+check_PROGRAMS = \
+ test_sensordashboard_api
+
+if ENABLE_TEST_RUN
+AM_TESTS_ENVIRONMENT=export 
GNUNET_PREFIX=$${GNUNET_PREFIX:address@hidden@};export 
PATH=$${GNUNET_PREFIX:address@hidden@}/bin:$$PATH;
+TESTS = $(check_PROGRAMS)
+endif
+
+test_sensordashboard_api_SOURCES = \
+ test_sensordashboard_api.c
+test_sensordashboard_api_LDADD = \
+  $(top_builddir)/src/util/libgnunetutil.la  
+

Added: gnunet/src/sensordashboard/gnunet-sensordashboard.c
===================================================================
--- gnunet/src/sensordashboard/gnunet-sensordashboard.c                         
(rev 0)
+++ gnunet/src/sensordashboard/gnunet-sensordashboard.c 2014-07-01 17:42:04 UTC 
(rev 33890)
@@ -0,0 +1,75 @@
+/*
+     This file is part of GNUnet.
+     (C) 2001, 2002, 2004, 2005, 2006, 2007, 2009 Christian Grothoff (and 
other contributing authors)
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 3, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file sensordashboard/gnunet-sensordashboard.c
+ * @brief sensor dashboard tool
+ * @author Omar Tarabai
+ */
+#include "platform.h"
+#include "gnunet_util_lib.h"
+
+/**
+ * Final status code.
+ */
+static int ret;
+
+/**
+ * Main function that will be run by the scheduler.
+ *
+ * @param cls closure
+ * @param args remaining command-line arguments
+ * @param cfgfile name of the configuration file used (for saving, can be 
NULL!)
+ * @param cfg configuration
+ */
+static void
+run (void *cls, char *const *args, const char *cfgfile,
+     const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+  /* main code here */
+}
+
+
+/**
+ * The main function.
+ *
+ * @param argc number of arguments from the command line
+ * @param argv command line arguments
+ * @return 0 ok, 1 on error
+ */
+int
+main (int argc, char *const *argv)
+{
+  static const struct GNUNET_GETOPT_CommandLineOption options[] = {
+    /* FIMXE: add options here */
+    GNUNET_GETOPT_OPTION_END
+  };
+  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+    return 2;
+
+  ret = (GNUNET_OK ==
+        GNUNET_PROGRAM_run (argc, argv, "gnunet-sensordashboard",
+                            gettext_noop ("help text"), options, &run,
+                            NULL)) ? ret : 1;
+  GNUNET_free ((void*) argv);
+  return ret;
+}
+
+/* end of gnunet-sensordashboard.c */

Added: gnunet/src/sensordashboard/gnunet-service-sensordashboard.c
===================================================================
--- gnunet/src/sensordashboard/gnunet-service-sensordashboard.c                 
        (rev 0)
+++ gnunet/src/sensordashboard/gnunet-service-sensordashboard.c 2014-07-01 
17:42:04 UTC (rev 33890)
@@ -0,0 +1,152 @@
+/*
+     This file is part of GNUnet.
+     (C) 2009 Christian Grothoff (and other contributing authors)
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 3, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file sensordashboard/gnunet-service-sensordashboard.c
+ * @brief Service collecting sensor readings from peers
+ * @author Omar Tarabai
+ */
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_applications.h"
+#include "gnunet_cadet_service.h"
+
+static struct GNUNET_CADET_Handle *cadet;
+
+/**
+ * Task run during shutdown.
+ *
+ * @param cls unused
+ * @param tc unused
+ */
+static void
+cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  if (NULL != cadet)
+  {
+    GNUNET_CADET_disconnect(cadet);
+    cadet = NULL;
+  }
+  GNUNET_SCHEDULER_shutdown();
+}
+
+/**
+ * Function called whenever a channel is destroyed.  Should clean up
+ * any associated state.
+ *
+ * It must NOT call #GNUNET_CADET_channel_destroy on the channel.
+ *
+ * @param cls closure (set from #GNUNET_CADET_connect)
+ * @param channel connection to the other end (henceforth invalid)
+ * @param channel_ctx place where local state associated
+ *                   with the channel is stored
+ */
+static void cadet_channel_destroyed (void *cls,
+    const struct GNUNET_CADET_Channel *channel,
+    void *channel_ctx)
+{
+
+}
+
+/**
+ * Method called whenever another peer has added us to a channel
+ * the other peer initiated.
+ * Only called (once) upon reception of data with a message type which was
+ * subscribed to in #GNUNET_CADET_connect.
+ *
+ * A call to #GNUNET_CADET_channel_destroy causes the channel to be ignored. In
+ * this case the handler MUST return NULL.
+ *
+ * @param cls closure
+ * @param channel new handle to the channel
+ * @param initiator peer that started the channel
+ * @param port Port this channel is for.
+ * @param options CadetOption flag field, with all active option bits set to 1.
+ *
+ * @return initial channel context for the channel
+ *         (can be NULL -- that's not an error)
+ */
+static void *cadet_channel_created (void *cls,
+    struct GNUNET_CADET_Channel *channel,
+    const struct GNUNET_PeerIdentity *initiator,
+    uint32_t port, enum GNUNET_CADET_ChannelOption options)
+{
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+      "CADET channel opened by remote peer `%s'.\n",
+      GNUNET_i2s(initiator));
+  return NULL; /* FIXME */
+}
+
+/**
+ * Process sensordashboard requests.
+ *
+ * @param cls closure
+ * @param server the initialized server
+ * @param cfg configuration to use
+ */
+static void
+run (void *cls, struct GNUNET_SERVER_Handle *server,
+     const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+  static const struct GNUNET_SERVER_MessageHandler handlers[] = {
+    {NULL, NULL, 0, 0}
+  };
+  static struct GNUNET_CADET_MessageHandler cadet_handlers[] = {
+      {NULL, 0, 0}
+  };
+  static uint32_t cadet_ports[] = {
+      GNUNET_APPLICATION_TYPE_SENSORDASHBOARD,
+      GNUNET_APPLICATION_TYPE_END
+  };
+  cadet = GNUNET_CADET_connect(cfg,
+      NULL,
+      &cadet_channel_created,
+      &cadet_channel_destroyed,
+      cadet_handlers,
+      cadet_ports);
+  if(NULL == cadet)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+        _("Failed to connect to CADET service.\n"));
+    GNUNET_SCHEDULER_add_now (&cleanup_task, NULL);
+    return;
+  }
+  GNUNET_SERVER_add_handlers (server, handlers);
+  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task,
+                                NULL);
+}
+
+
+/**
+ * The main function for the sensordashboard service.
+ *
+ * @param argc number of arguments from the command line
+ * @param argv command line arguments
+ * @return 0 ok, 1 on error
+ */
+int
+main (int argc, char *const *argv)
+{
+  return (GNUNET_OK ==
+          GNUNET_SERVICE_run (argc, argv, "sensordashboard",
+                              GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
+}
+
+/* end of gnunet-service-sensordashboard.c */

Added: gnunet/src/sensordashboard/sensordashboard.conf.in
===================================================================
--- gnunet/src/sensordashboard/sensordashboard.conf.in                          
(rev 0)
+++ gnunet/src/sensordashboard/sensordashboard.conf.in  2014-07-01 17:42:04 UTC 
(rev 33890)
@@ -0,0 +1,4 @@
+[sensordashboard]
+BINARY = gnunet-service-sensordashboard
+UNIXPATH = /tmp/gnunet-service-sensordashboard.sock
+HOME = $SERVICEHOME

Added: gnunet/src/sensordashboard/test_sensordashboard_api.c
===================================================================
--- gnunet/src/sensordashboard/test_sensordashboard_api.c                       
        (rev 0)
+++ gnunet/src/sensordashboard/test_sensordashboard_api.c       2014-07-01 
17:42:04 UTC (rev 33890)
@@ -0,0 +1,42 @@
+/*
+     This file is part of GNUnet.
+     (C) 2009 Christian Grothoff (and other contributing authors)
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 3, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+/**
+ * @file template/test_template_api.c
+ * @brief testcase for template.c
+ */
+#include "platform.h"
+
+static int
+check ()
+{
+  return 0;
+}
+
+int
+main (int argc, char *argv[])
+{
+  int ret;
+
+  ret = check ();
+
+  return ret;
+}
+
+/* end of test_template_api.c */




reply via email to

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