aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOmar Tarabai <tarabai@devegypt.com>2014-07-01 17:42:04 +0000
committerOmar Tarabai <tarabai@devegypt.com>2014-07-01 17:42:04 +0000
commit82a7032fa39250385877b2b91d79e0601378021a (patch)
tree7ca8f1ea6104c86164d37bba1c9a4e5f412385b5
parent33ccf61eb6b2a102f720111737f3c9b7f6c6099b (diff)
downloadgnunet-82a7032fa39250385877b2b91d79e0601378021a.tar.gz
gnunet-82a7032fa39250385877b2b91d79e0601378021a.zip
sensor dashboard (collection point) initial commit
-rw-r--r--configure.ac2
-rw-r--r--src/Makefile.am4
-rw-r--r--src/include/gnunet_applications.h5
-rw-r--r--src/sensor/Makefile.am1
-rw-r--r--src/sensor/gnunet-service-sensor-reporting.c56
-rw-r--r--src/sensordashboard/Makefile.am50
-rw-r--r--src/sensordashboard/gnunet-sensordashboard.c75
-rw-r--r--src/sensordashboard/gnunet-service-sensordashboard.c152
-rw-r--r--src/sensordashboard/sensordashboard.conf.in4
-rw-r--r--src/sensordashboard/test_sensordashboard_api.c42
10 files changed, 383 insertions, 8 deletions
diff --git a/configure.ac b/configure.ac
index 3c315afe6..d90462329 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1491,6 +1491,8 @@ src/secretsharing/Makefile
1491src/secretsharing/secretsharing.conf 1491src/secretsharing/secretsharing.conf
1492src/sensor/Makefile 1492src/sensor/Makefile
1493src/sensor/sensor.conf 1493src/sensor/sensor.conf
1494src/sensordashboard/Makefile
1495src/sensordashboard/sensordashboard.conf
1494src/scalarproduct/Makefile 1496src/scalarproduct/Makefile
1495src/scalarproduct/scalarproduct.conf 1497src/scalarproduct/scalarproduct.conf
1496src/set/Makefile 1498src/set/Makefile
diff --git a/src/Makefile.am b/src/Makefile.am
index 44ee03555..dd8777c91 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -11,6 +11,7 @@ if HAVE_TESTING
11 SCALARPRODUCT = scalarproduct 11 SCALARPRODUCT = scalarproduct
12 SENSOR = sensor 12 SENSOR = sensor
13 PEERSTORE = peerstore 13 PEERSTORE = peerstore
14 SENSORDASHBOARD = sensordashboard
14endif 15endif
15 16
16if HAVE_EXPERIMENTAL 17if HAVE_EXPERIMENTAL
@@ -26,7 +27,8 @@ if HAVE_EXPERIMENTAL
26 $(SCALARPRODUCT) \ 27 $(SCALARPRODUCT) \
27 $(EXPERIMENTATION) \ 28 $(EXPERIMENTATION) \
28 $(PEERSTORE) \ 29 $(PEERSTORE) \
29 $(SENSOR) 30 $(SENSOR) \
31 $(SENSORDASHBOARD)
30endif 32endif
31 33
32 34
diff --git a/src/include/gnunet_applications.h b/src/include/gnunet_applications.h
index 6e3d82cae..b5fc6bfe3 100644
--- a/src/include/gnunet_applications.h
+++ b/src/include/gnunet_applications.h
@@ -101,6 +101,11 @@ extern "C"
101 */ 101 */
102#define GNUNET_APPLICATION_TYPE_MQTT 23 102#define GNUNET_APPLICATION_TYPE_MQTT 23
103 103
104/**
105 * Application receiving sensor measurements from peers
106 */
107#define GNUNET_APPLICATION_TYPE_SENSORDASHBOARD 24
108
104 109
105#if 0 /* keep Emacsens' auto-indent happy */ 110#if 0 /* keep Emacsens' auto-indent happy */
106{ 111{
diff --git a/src/sensor/Makefile.am b/src/sensor/Makefile.am
index 08b536d0a..e16e41ee5 100644
--- a/src/sensor/Makefile.am
+++ b/src/sensor/Makefile.am
@@ -41,6 +41,7 @@ gnunet_service_sensor_LDADD = \
41 $(top_builddir)/src/util/libgnunetutil.la \ 41 $(top_builddir)/src/util/libgnunetutil.la \
42 $(top_builddir)/src/statistics/libgnunetstatistics.la \ 42 $(top_builddir)/src/statistics/libgnunetstatistics.la \
43 $(top_builddir)/src/peerstore/libgnunetpeerstore.la \ 43 $(top_builddir)/src/peerstore/libgnunetpeerstore.la \
44 $(top_builddir)/src/cadet/libgnunetcadet.la \
44 $(GN_LIBINTL) 45 $(GN_LIBINTL)
45 46
46libgnunetsensor_la_SOURCES = \ 47libgnunetsensor_la_SOURCES = \
diff --git a/src/sensor/gnunet-service-sensor-reporting.c b/src/sensor/gnunet-service-sensor-reporting.c
index 2808f01b8..b1482654b 100644
--- a/src/sensor/gnunet-service-sensor-reporting.c
+++ b/src/sensor/gnunet-service-sensor-reporting.c
@@ -27,6 +27,7 @@
27#include "gnunet_util_lib.h" 27#include "gnunet_util_lib.h"
28#include "sensor.h" 28#include "sensor.h"
29#include "gnunet_peerstore_service.h" 29#include "gnunet_peerstore_service.h"
30#include "gnunet_cadet_service.h"
30 31
31#define LOG(kind,...) GNUNET_log_from (kind, "sensor-reporting",__VA_ARGS__) 32#define LOG(kind,...) GNUNET_log_from (kind, "sensor-reporting",__VA_ARGS__)
32 33
@@ -62,18 +63,23 @@ static struct GNUNET_PEERSTORE_Handle *peerstore;
62/** 63/**
63 * My peer id 64 * My peer id
64 */ 65 */
65struct GNUNET_PeerIdentity peerid; 66static struct GNUNET_PeerIdentity peerid;
67
68/**
69 * Handle to CADET service
70 */
71static struct GNUNET_CADET_Handle *cadet;
66 72
67 73
68/** 74/**
69 * Stop sensor reporting module 75 * Stop sensor reporting module
70 */ 76 */
71void SENSOR_reporting_stop() 77void SENSOR_reporting_stop ()
72{ 78{
73 LOG (GNUNET_ERROR_TYPE_DEBUG, "Stopping sensor reporting module.\n"); 79 LOG (GNUNET_ERROR_TYPE_DEBUG, "Stopping sensor reporting module.\n");
74 if (NULL != peerstore) 80 if (NULL != peerstore)
75 { 81 {
76 GNUNET_PEERSTORE_disconnect(peerstore); 82 GNUNET_PEERSTORE_disconnect (peerstore);
77 peerstore = NULL; 83 peerstore = NULL;
78 } 84 }
79} 85}
@@ -118,7 +124,7 @@ init_sensor_reporting (void *cls,
118 crc = GNUNET_new (struct CollectionReportingContext); 124 crc = GNUNET_new (struct CollectionReportingContext);
119 crc->sensor = sensor; 125 crc->sensor = sensor;
120 crc->task = 126 crc->task =
121 GNUNET_SCHEDULER_add_delayed(sensor->collection_interval, 127 GNUNET_SCHEDULER_add_delayed (sensor->collection_interval,
122 &report_collection_point, 128 &report_collection_point,
123 crc); 129 crc);
124 } 130 }
@@ -133,6 +139,24 @@ init_sensor_reporting (void *cls,
133} 139}
134 140
135/** 141/**
142 * Function called whenever a channel is destroyed. Should clean up
143 * any associated state.
144 *
145 * It must NOT call #GNUNET_CADET_channel_destroy on the channel.
146 *
147 * @param cls closure (set from #GNUNET_CADET_connect)
148 * @param channel connection to the other end (henceforth invalid)
149 * @param channel_ctx place where local state associated
150 * with the channel is stored
151 */
152static void cadet_channel_destroyed (void *cls,
153 const struct GNUNET_CADET_Channel *channel,
154 void *channel_ctx)
155{
156
157}
158
159/**
136 * Start the sensor reporting module 160 * Start the sensor reporting module
137 * 161 *
138 * @param c our service configuration 162 * @param c our service configuration
@@ -140,9 +164,12 @@ init_sensor_reporting (void *cls,
140 * @return #GNUNET_OK if started successfully, #GNUNET_SYSERR otherwise 164 * @return #GNUNET_OK if started successfully, #GNUNET_SYSERR otherwise
141 */ 165 */
142int 166int
143SENSOR_reporting_start(const struct GNUNET_CONFIGURATION_Handle *c, 167SENSOR_reporting_start (const struct GNUNET_CONFIGURATION_Handle *c,
144 struct GNUNET_CONTAINER_MultiHashMap *sensors) 168 struct GNUNET_CONTAINER_MultiHashMap *sensors)
145{ 169{
170 static struct GNUNET_CADET_MessageHandler cadet_handlers[] = {
171 {NULL, 0, 0}
172 };
146 173
147 GNUNET_assert(NULL != sensors); 174 GNUNET_assert(NULL != sensors);
148 cfg = c; 175 cfg = c;
@@ -151,10 +178,25 @@ SENSOR_reporting_start(const struct GNUNET_CONFIGURATION_Handle *c,
151 peerstore = GNUNET_PEERSTORE_connect(cfg); 178 peerstore = GNUNET_PEERSTORE_connect(cfg);
152 if (NULL == peerstore) 179 if (NULL == peerstore)
153 { 180 {
154 LOG (GNUNET_ERROR_TYPE_ERROR, _("Could not connect to peerstore service.\n")); 181 LOG (GNUNET_ERROR_TYPE_ERROR,
155 SENSOR_reporting_stop(); 182 _("Failed to connect to peerstore service.\n"));
183 SENSOR_reporting_stop ();
156 return GNUNET_SYSERR; 184 return GNUNET_SYSERR;
157 } 185 }
186 cadet = GNUNET_CADET_connect(cfg,
187 NULL,
188 NULL,
189 &cadet_channel_destroyed,
190 cadet_handlers,
191 NULL);
192 if (NULL == cadet)
193 {
194 LOG (GNUNET_ERROR_TYPE_ERROR,
195 _("Failed to connect to CADET service.\n"));
196 SENSOR_reporting_stop ();
197 return GNUNET_SYSERR;
198 }
199
158 return GNUNET_OK; 200 return GNUNET_OK;
159} 201}
160 202
diff --git a/src/sensordashboard/Makefile.am b/src/sensordashboard/Makefile.am
new file mode 100644
index 000000000..419486ff4
--- /dev/null
+++ b/src/sensordashboard/Makefile.am
@@ -0,0 +1,50 @@
1AM_CPPFLAGS = -I$(top_srcdir)/src/include
2
3pkgcfgdir= $(pkgdatadir)/config.d/
4
5libexecdir= $(pkglibdir)/libexec/
6
7dist_pkgcfg_DATA = \
8 sensordashboard.conf
9
10if MINGW
11 WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
12endif
13
14if USE_COVERAGE
15 AM_CFLAGS = -fprofile-arcs -ftest-coverage
16endif
17
18bin_PROGRAMS = \
19 gnunet-sensordashboard
20
21libexec_PROGRAMS = \
22 gnunet-service-sensordashboard
23
24gnunet_sensordashboard_SOURCES = \
25 gnunet-sensordashboard.c
26gnunet_sensordashboard_LDADD = \
27 $(top_builddir)/src/util/libgnunetutil.la \
28 $(GN_LIBINTL)
29
30gnunet_service_sensordashboard_SOURCES = \
31 gnunet-service-sensordashboard.c
32gnunet_service_sensordashboard_LDADD = \
33 $(top_builddir)/src/util/libgnunetutil.la \
34 $(top_builddir)/src/cadet/libgnunetcadet.la \
35 $(GN_LIBINTL)
36
37
38check_PROGRAMS = \
39 test_sensordashboard_api
40
41if ENABLE_TEST_RUN
42AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;
43TESTS = $(check_PROGRAMS)
44endif
45
46test_sensordashboard_api_SOURCES = \
47 test_sensordashboard_api.c
48test_sensordashboard_api_LDADD = \
49 $(top_builddir)/src/util/libgnunetutil.la
50
diff --git a/src/sensordashboard/gnunet-sensordashboard.c b/src/sensordashboard/gnunet-sensordashboard.c
new file mode 100644
index 000000000..630a3cf77
--- /dev/null
+++ b/src/sensordashboard/gnunet-sensordashboard.c
@@ -0,0 +1,75 @@
1/*
2 This file is part of GNUnet.
3 (C) 2001, 2002, 2004, 2005, 2006, 2007, 2009 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/**
22 * @file sensordashboard/gnunet-sensordashboard.c
23 * @brief sensor dashboard tool
24 * @author Omar Tarabai
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28
29/**
30 * Final status code.
31 */
32static int ret;
33
34/**
35 * Main function that will be run by the scheduler.
36 *
37 * @param cls closure
38 * @param args remaining command-line arguments
39 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
40 * @param cfg configuration
41 */
42static void
43run (void *cls, char *const *args, const char *cfgfile,
44 const struct GNUNET_CONFIGURATION_Handle *cfg)
45{
46 /* main code here */
47}
48
49
50/**
51 * The main function.
52 *
53 * @param argc number of arguments from the command line
54 * @param argv command line arguments
55 * @return 0 ok, 1 on error
56 */
57int
58main (int argc, char *const *argv)
59{
60 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
61 /* FIMXE: add options here */
62 GNUNET_GETOPT_OPTION_END
63 };
64 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
65 return 2;
66
67 ret = (GNUNET_OK ==
68 GNUNET_PROGRAM_run (argc, argv, "gnunet-sensordashboard",
69 gettext_noop ("help text"), options, &run,
70 NULL)) ? ret : 1;
71 GNUNET_free ((void*) argv);
72 return ret;
73}
74
75/* end of gnunet-sensordashboard.c */
diff --git a/src/sensordashboard/gnunet-service-sensordashboard.c b/src/sensordashboard/gnunet-service-sensordashboard.c
new file mode 100644
index 000000000..b3fbf5d9d
--- /dev/null
+++ b/src/sensordashboard/gnunet-service-sensordashboard.c
@@ -0,0 +1,152 @@
1/*
2 This file is part of GNUnet.
3 (C) 2009 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/**
22 * @file sensordashboard/gnunet-service-sensordashboard.c
23 * @brief Service collecting sensor readings from peers
24 * @author Omar Tarabai
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_applications.h"
29#include "gnunet_cadet_service.h"
30
31static struct GNUNET_CADET_Handle *cadet;
32
33/**
34 * Task run during shutdown.
35 *
36 * @param cls unused
37 * @param tc unused
38 */
39static void
40cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
41{
42 if (NULL != cadet)
43 {
44 GNUNET_CADET_disconnect(cadet);
45 cadet = NULL;
46 }
47 GNUNET_SCHEDULER_shutdown();
48}
49
50/**
51 * Function called whenever a channel is destroyed. Should clean up
52 * any associated state.
53 *
54 * It must NOT call #GNUNET_CADET_channel_destroy on the channel.
55 *
56 * @param cls closure (set from #GNUNET_CADET_connect)
57 * @param channel connection to the other end (henceforth invalid)
58 * @param channel_ctx place where local state associated
59 * with the channel is stored
60 */
61static void cadet_channel_destroyed (void *cls,
62 const struct GNUNET_CADET_Channel *channel,
63 void *channel_ctx)
64{
65
66}
67
68/**
69 * Method called whenever another peer has added us to a channel
70 * the other peer initiated.
71 * Only called (once) upon reception of data with a message type which was
72 * subscribed to in #GNUNET_CADET_connect.
73 *
74 * A call to #GNUNET_CADET_channel_destroy causes the channel to be ignored. In
75 * this case the handler MUST return NULL.
76 *
77 * @param cls closure
78 * @param channel new handle to the channel
79 * @param initiator peer that started the channel
80 * @param port Port this channel is for.
81 * @param options CadetOption flag field, with all active option bits set to 1.
82 *
83 * @return initial channel context for the channel
84 * (can be NULL -- that's not an error)
85 */
86static void *cadet_channel_created (void *cls,
87 struct GNUNET_CADET_Channel *channel,
88 const struct GNUNET_PeerIdentity *initiator,
89 uint32_t port, enum GNUNET_CADET_ChannelOption options)
90{
91 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
92 "CADET channel opened by remote peer `%s'.\n",
93 GNUNET_i2s(initiator));
94 return NULL; /* FIXME */
95}
96
97/**
98 * Process sensordashboard requests.
99 *
100 * @param cls closure
101 * @param server the initialized server
102 * @param cfg configuration to use
103 */
104static void
105run (void *cls, struct GNUNET_SERVER_Handle *server,
106 const struct GNUNET_CONFIGURATION_Handle *cfg)
107{
108 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
109 {NULL, NULL, 0, 0}
110 };
111 static struct GNUNET_CADET_MessageHandler cadet_handlers[] = {
112 {NULL, 0, 0}
113 };
114 static uint32_t cadet_ports[] = {
115 GNUNET_APPLICATION_TYPE_SENSORDASHBOARD,
116 GNUNET_APPLICATION_TYPE_END
117 };
118 cadet = GNUNET_CADET_connect(cfg,
119 NULL,
120 &cadet_channel_created,
121 &cadet_channel_destroyed,
122 cadet_handlers,
123 cadet_ports);
124 if(NULL == cadet)
125 {
126 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
127 _("Failed to connect to CADET service.\n"));
128 GNUNET_SCHEDULER_add_now (&cleanup_task, NULL);
129 return;
130 }
131 GNUNET_SERVER_add_handlers (server, handlers);
132 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task,
133 NULL);
134}
135
136
137/**
138 * The main function for the sensordashboard service.
139 *
140 * @param argc number of arguments from the command line
141 * @param argv command line arguments
142 * @return 0 ok, 1 on error
143 */
144int
145main (int argc, char *const *argv)
146{
147 return (GNUNET_OK ==
148 GNUNET_SERVICE_run (argc, argv, "sensordashboard",
149 GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
150}
151
152/* end of gnunet-service-sensordashboard.c */
diff --git a/src/sensordashboard/sensordashboard.conf.in b/src/sensordashboard/sensordashboard.conf.in
new file mode 100644
index 000000000..a375ca676
--- /dev/null
+++ b/src/sensordashboard/sensordashboard.conf.in
@@ -0,0 +1,4 @@
1[sensordashboard]
2BINARY = gnunet-service-sensordashboard
3UNIXPATH = /tmp/gnunet-service-sensordashboard.sock
4HOME = $SERVICEHOME
diff --git a/src/sensordashboard/test_sensordashboard_api.c b/src/sensordashboard/test_sensordashboard_api.c
new file mode 100644
index 000000000..855fadc2f
--- /dev/null
+++ b/src/sensordashboard/test_sensordashboard_api.c
@@ -0,0 +1,42 @@
1/*
2 This file is part of GNUnet.
3 (C) 2009 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20/**
21 * @file template/test_template_api.c
22 * @brief testcase for template.c
23 */
24#include "platform.h"
25
26static int
27check ()
28{
29 return 0;
30}
31
32int
33main (int argc, char *argv[])
34{
35 int ret;
36
37 ret = check ();
38
39 return ret;
40}
41
42/* end of test_template_api.c */