aboutsummaryrefslogtreecommitdiff
path: root/src/sensor
diff options
context:
space:
mode:
authorOmar Tarabai <tarabai@devegypt.com>2014-06-06 11:55:14 +0000
committerOmar Tarabai <tarabai@devegypt.com>2014-06-06 11:55:14 +0000
commitbdfda4dd17faf721d82bfee411dcaf2777012a9f (patch)
treeda228559f7992fe39e29e7cd4b908ec89a8d5e7e /src/sensor
parentf92f3f8a717f1a3b332bec4f162ad8da237f2e89 (diff)
downloadgnunet-bdfda4dd17faf721d82bfee411dcaf2777012a9f.tar.gz
gnunet-bdfda4dd17faf721d82bfee411dcaf2777012a9f.zip
using PEERSTORE in SENSOR + fixes in PEERSTORE
Diffstat (limited to 'src/sensor')
-rw-r--r--src/sensor/Makefile.am1
-rw-r--r--src/sensor/gnunet-service-sensor.c57
2 files changed, 54 insertions, 4 deletions
diff --git a/src/sensor/Makefile.am b/src/sensor/Makefile.am
index e3d9bbe69..b6c55f5e6 100644
--- a/src/sensor/Makefile.am
+++ b/src/sensor/Makefile.am
@@ -36,6 +36,7 @@ gnunet_service_sensor_SOURCES = \
36gnunet_service_sensor_LDADD = \ 36gnunet_service_sensor_LDADD = \
37 $(top_builddir)/src/util/libgnunetutil.la \ 37 $(top_builddir)/src/util/libgnunetutil.la \
38 $(top_builddir)/src/statistics/libgnunetstatistics.la \ 38 $(top_builddir)/src/statistics/libgnunetstatistics.la \
39 $(top_builddir)/src/peerstore/libgnunetpeerstore.la \
39 $(GN_LIBINTL) 40 $(GN_LIBINTL)
40 41
41libgnunetsensor_la_SOURCES = \ 42libgnunetsensor_la_SOURCES = \
diff --git a/src/sensor/gnunet-service-sensor.c b/src/sensor/gnunet-service-sensor.c
index 6d47cb1e2..b42562ace 100644
--- a/src/sensor/gnunet-service-sensor.c
+++ b/src/sensor/gnunet-service-sensor.c
@@ -28,6 +28,7 @@
28#include "gnunet_util_lib.h" 28#include "gnunet_util_lib.h"
29#include "sensor.h" 29#include "sensor.h"
30#include "gnunet_statistics_service.h" 30#include "gnunet_statistics_service.h"
31#include "gnunet_peerstore_service.h"
31 32
32/** 33/**
33 * Minimum sensor execution interval (in seconds) 34 * Minimum sensor execution interval (in seconds)
@@ -204,6 +205,21 @@ static const char *datatypes[] = { "uint64", "double", "string", NULL };
204struct GNUNET_STATISTICS_Handle *statistics; 205struct GNUNET_STATISTICS_Handle *statistics;
205 206
206/** 207/**
208 * Handle to peerstore service
209 */
210struct GNUNET_PEERSTORE_Handle *peerstore;
211
212/**
213 * Service name
214 */
215char *subsystem = "sensor";
216
217/**
218 * My peer id
219 */
220struct GNUNET_PeerIdentity peerid;
221
222/**
207 * Remove sensor execution from scheduler 223 * Remove sensor execution from scheduler
208 * 224 *
209 * @param cls unused 225 * @param cls unused
@@ -290,7 +306,15 @@ shutdown_task (void *cls,
290 GNUNET_CONTAINER_multihashmap_iterate(sensors, &destroy_sensor, NULL); 306 GNUNET_CONTAINER_multihashmap_iterate(sensors, &destroy_sensor, NULL);
291 GNUNET_CONTAINER_multihashmap_destroy(sensors); 307 GNUNET_CONTAINER_multihashmap_destroy(sensors);
292 if(NULL != statistics) 308 if(NULL != statistics)
309 {
293 GNUNET_STATISTICS_destroy(statistics, GNUNET_YES); 310 GNUNET_STATISTICS_destroy(statistics, GNUNET_YES);
311 statistics = NULL;
312 }
313 if(NULL != peerstore)
314 {
315 GNUNET_PEERSTORE_disconnect(peerstore);
316 peerstore = NULL;
317 }
294 GNUNET_SCHEDULER_shutdown(); 318 GNUNET_SCHEDULER_shutdown();
295} 319}
296 320
@@ -816,8 +840,21 @@ int sensor_statistics_iterator (void *cls,
816 int is_persistent) 840 int is_persistent)
817{ 841{
818 struct SensorInfo *sensorinfo = cls; 842 struct SensorInfo *sensorinfo = cls;
843 struct GNUNET_TIME_Absolute expiry;
819 844
820 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Received a value for sensor `%s': %" PRIu64 "\n", sensorinfo->name, value); 845 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Received a value for sensor `%s': %" PRIu64 "\n", sensorinfo->name, value);
846 //FIXME: store first line, last line or all ??
847 expiry = GNUNET_TIME_relative_to_absolute(sensorinfo->interval);
848 GNUNET_PEERSTORE_store(peerstore,
849 subsystem,
850 &peerid,
851 sensorinfo->name,
852 &value,
853 sizeof(value),
854 expiry,
855 GNUNET_PEERSTORE_STOREOPTION_MULTIPLE,
856 NULL,
857 NULL);
821 return GNUNET_OK; 858 return GNUNET_OK;
822} 859}
823 860
@@ -845,6 +882,7 @@ void end_sensor_run_stat (void *cls, int success)
845void sensor_process_callback (void *cls, const char *line) 882void sensor_process_callback (void *cls, const char *line)
846{ 883{
847 struct SensorInfo *sensorinfo = cls; 884 struct SensorInfo *sensorinfo = cls;
885 struct GNUNET_TIME_Absolute expiry;
848 886
849 if(NULL == line) //end of output 887 if(NULL == line) //end of output
850 { 888 {
@@ -854,6 +892,18 @@ void sensor_process_callback (void *cls, const char *line)
854 return; 892 return;
855 } 893 }
856 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Received a value for sensor `%s': %s\n", sensorinfo->name, line); 894 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Received a value for sensor `%s': %s\n", sensorinfo->name, line);
895 //FIXME: store first line, last line or all ??
896 expiry = GNUNET_TIME_relative_to_absolute(sensorinfo->interval);
897 GNUNET_PEERSTORE_store(peerstore,
898 subsystem,
899 &peerid,
900 sensorinfo->name,
901 line,
902 strlen(line) + 1,
903 expiry,
904 GNUNET_PEERSTORE_STOREOPTION_MULTIPLE,
905 NULL,
906 NULL);
857} 907}
858 908
859/** 909/**
@@ -903,10 +953,6 @@ sensor_run (void *cls,
903 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Starting the execution of sensor `%s'\n", sensorinfo->name); 953 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Starting the execution of sensor `%s'\n", sensorinfo->name);
904 if(sources[0] == sensorinfo->source) //gnunet-statistics 954 if(sources[0] == sensorinfo->source) //gnunet-statistics
905 { 955 {
906 if(NULL == statistics)
907 {
908 statistics = GNUNET_STATISTICS_create("sensor", cfg);
909 }
910 sensorinfo->gnunet_stat_get_handle = GNUNET_STATISTICS_get(statistics, 956 sensorinfo->gnunet_stat_get_handle = GNUNET_STATISTICS_get(statistics,
911 sensorinfo->gnunet_stat_service, 957 sensorinfo->gnunet_stat_service,
912 sensorinfo->gnunet_stat_name, 958 sensorinfo->gnunet_stat_name,
@@ -1032,6 +1078,9 @@ run (void *cls,
1032 sensors = GNUNET_CONTAINER_multihashmap_create(10, GNUNET_NO); 1078 sensors = GNUNET_CONTAINER_multihashmap_create(10, GNUNET_NO);
1033 reload_sensors(); 1079 reload_sensors();
1034 schedule_all_sensors(); 1080 schedule_all_sensors();
1081 statistics = GNUNET_STATISTICS_create("sensor", cfg);
1082 GNUNET_CRYPTO_get_peer_identity(cfg, &peerid);
1083 peerstore = GNUNET_PEERSTORE_connect(cfg);
1035 GNUNET_SERVER_add_handlers (server, handlers); 1084 GNUNET_SERVER_add_handlers (server, handlers);
1036 GNUNET_SERVER_disconnect_notify (server, 1085 GNUNET_SERVER_disconnect_notify (server,
1037 &handle_client_disconnect, 1086 &handle_client_disconnect,