diff options
author | Omar Tarabai <tarabai@devegypt.com> | 2014-07-29 14:01:37 +0000 |
---|---|---|
committer | Omar Tarabai <tarabai@devegypt.com> | 2014-07-29 14:01:37 +0000 |
commit | 5051244c80bd93e1599c5c39aeeefebaeef40d61 (patch) | |
tree | 5b64b237d5af7a25f2e75b150fbb3396a360820e /src | |
parent | 764a37c57035bb131d4cf265bf24396c1e422efb (diff) | |
download | gnunet-5051244c80bd93e1599c5c39aeeefebaeef40d61.tar.gz gnunet-5051244c80bd93e1599c5c39aeeefebaeef40d61.zip |
sensor, sensordashboard: doxygen fixes + indentation
Diffstat (limited to 'src')
-rw-r--r-- | src/include/gnunet_sensor_service.h | 20 | ||||
-rw-r--r-- | src/include/gnunet_sensor_util_lib.h | 7 | ||||
-rw-r--r-- | src/sensor/gnunet-sensor.c | 95 | ||||
-rw-r--r-- | src/sensor/gnunet-service-sensor-analysis.c | 106 | ||||
-rw-r--r-- | src/sensor/gnunet-service-sensor-reporting.c | 148 | ||||
-rw-r--r-- | src/sensor/gnunet-service-sensor-update.c | 191 | ||||
-rw-r--r-- | src/sensor/gnunet-service-sensor.c | 408 | ||||
-rw-r--r-- | src/sensor/gnunet_sensor_model_plugin.h | 9 | ||||
-rw-r--r-- | src/sensor/plugin_sensor_model_gaussian.c | 58 | ||||
-rw-r--r-- | src/sensor/sensor.h | 35 | ||||
-rw-r--r-- | src/sensor/sensor_api.c | 125 | ||||
-rw-r--r-- | src/sensor/sensor_util_lib.c | 345 | ||||
-rw-r--r-- | src/sensor/test_sensor_api.c | 32 | ||||
-rw-r--r-- | src/sensordashboard/gnunet-sensordashboard.c | 11 | ||||
-rw-r--r-- | src/sensordashboard/gnunet-service-sensordashboard.c | 143 | ||||
-rw-r--r-- | src/sensordashboard/sensordashboard.h | 4 |
16 files changed, 864 insertions, 873 deletions
diff --git a/src/include/gnunet_sensor_service.h b/src/include/gnunet_sensor_service.h index eb4fbdc67..4ef2885e6 100644 --- a/src/include/gnunet_sensor_service.h +++ b/src/include/gnunet_sensor_service.h | |||
@@ -79,8 +79,9 @@ struct SensorInfoShort | |||
79 | * @param error message | 79 | * @param error message |
80 | */ | 80 | */ |
81 | typedef void (*GNUNET_SENSOR_SensorIteratorCB) (void *cls, | 81 | typedef void (*GNUNET_SENSOR_SensorIteratorCB) (void *cls, |
82 | const struct SensorInfoShort *sensor, | 82 | const struct SensorInfoShort * |
83 | const char *err_msg); | 83 | sensor, const char *err_msg); |
84 | |||
84 | 85 | ||
85 | /** | 86 | /** |
86 | * Continuation called with a status result. | 87 | * Continuation called with a status result. |
@@ -88,8 +89,8 @@ typedef void (*GNUNET_SENSOR_SensorIteratorCB) (void *cls, | |||
88 | * @param cls closure | 89 | * @param cls closure |
89 | * @param emsg error message, NULL on success | 90 | * @param emsg error message, NULL on success |
90 | */ | 91 | */ |
91 | typedef void (*GNUNET_SENSOR_Continuation)(void *cls, | 92 | typedef void (*GNUNET_SENSOR_Continuation) (void *cls, const char *emsg); |
92 | const char *emsg); | 93 | |
93 | 94 | ||
94 | /** | 95 | /** |
95 | * Connect to the sensor service. | 96 | * Connect to the sensor service. |
@@ -99,13 +100,15 @@ typedef void (*GNUNET_SENSOR_Continuation)(void *cls, | |||
99 | struct GNUNET_SENSOR_Handle * | 100 | struct GNUNET_SENSOR_Handle * |
100 | GNUNET_SENSOR_connect (const struct GNUNET_CONFIGURATION_Handle *cfg); | 101 | GNUNET_SENSOR_connect (const struct GNUNET_CONFIGURATION_Handle *cfg); |
101 | 102 | ||
103 | |||
102 | /** | 104 | /** |
103 | * Disconnect from the sensor service | 105 | * Disconnect from the sensor service |
104 | * | 106 | * |
105 | * @param h handle to disconnect | 107 | * @param h handle to disconnect |
106 | */ | 108 | */ |
107 | void | 109 | void |
108 | GNUNET_SENSOR_disconnect(struct GNUNET_SENSOR_Handle *h); | 110 | GNUNET_SENSOR_disconnect (struct GNUNET_SENSOR_Handle *h); |
111 | |||
109 | 112 | ||
110 | /** | 113 | /** |
111 | * Client asking to iterate all available sensors | 114 | * Client asking to iterate all available sensors |
@@ -120,9 +123,10 @@ GNUNET_SENSOR_disconnect(struct GNUNET_SENSOR_Handle *h); | |||
120 | */ | 123 | */ |
121 | struct GNUNET_SENSOR_SensorIteratorContext * | 124 | struct GNUNET_SENSOR_SensorIteratorContext * |
122 | GNUNET_SENSOR_iterate_sensors (struct GNUNET_SENSOR_Handle *h, | 125 | GNUNET_SENSOR_iterate_sensors (struct GNUNET_SENSOR_Handle *h, |
123 | struct GNUNET_TIME_Relative timeout, | 126 | struct GNUNET_TIME_Relative timeout, |
124 | const char* sensorname, size_t sensorname_len, | 127 | const char *sensorname, size_t sensorname_len, |
125 | GNUNET_SENSOR_SensorIteratorCB callback, void *callback_cls); | 128 | GNUNET_SENSOR_SensorIteratorCB callback, |
129 | void *callback_cls); | ||
126 | 130 | ||
127 | #if 0 /* keep Emacsens' auto-indent happy */ | 131 | #if 0 /* keep Emacsens' auto-indent happy */ |
128 | { | 132 | { |
diff --git a/src/include/gnunet_sensor_util_lib.h b/src/include/gnunet_sensor_util_lib.h index 090465140..e048cb9f0 100644 --- a/src/include/gnunet_sensor_util_lib.h +++ b/src/include/gnunet_sensor_util_lib.h | |||
@@ -188,12 +188,11 @@ struct GNUNET_SENSOR_SensorInfo | |||
188 | }; | 188 | }; |
189 | 189 | ||
190 | GNUNET_NETWORK_STRUCT_BEGIN | 190 | GNUNET_NETWORK_STRUCT_BEGIN |
191 | |||
192 | /** | 191 | /** |
193 | * Used to communicate sensor readings to | 192 | * Used to communicate sensor readings to |
194 | * collection points (SENSORDASHBAORD service) | 193 | * collection points (SENSORDASHBAORD service) |
195 | */ | 194 | */ |
196 | struct GNUNET_SENSOR_ReadingMessage | 195 | struct GNUNET_SENSOR_ReadingMessage |
197 | { | 196 | { |
198 | 197 | ||
199 | /** | 198 | /** |
@@ -297,8 +296,6 @@ struct GNUNET_SENSOR_SensorFullMessage | |||
297 | }; | 296 | }; |
298 | 297 | ||
299 | GNUNET_NETWORK_STRUCT_END | 298 | GNUNET_NETWORK_STRUCT_END |
300 | |||
301 | |||
302 | /** | 299 | /** |
303 | * Given two version numbers as major and minor, compare them. | 300 | * Given two version numbers as major and minor, compare them. |
304 | * | 301 | * |
@@ -307,7 +304,7 @@ GNUNET_NETWORK_STRUCT_END | |||
307 | * @param v2_major First part of second version number | 304 | * @param v2_major First part of second version number |
308 | * @param v2_minor Second part of second version number | 305 | * @param v2_minor Second part of second version number |
309 | */ | 306 | */ |
310 | int | 307 | int |
311 | GNUNET_SENSOR_version_compare (uint16_t v1_major, uint16_t v1_minor, | 308 | GNUNET_SENSOR_version_compare (uint16_t v1_major, uint16_t v1_minor, |
312 | uint16_t v2_major, uint16_t v2_minor); | 309 | uint16_t v2_major, uint16_t v2_minor); |
313 | 310 | ||
diff --git a/src/sensor/gnunet-sensor.c b/src/sensor/gnunet-sensor.c index fa7930832..ffd61f8b4 100644 --- a/src/sensor/gnunet-sensor.c +++ b/src/sensor/gnunet-sensor.c | |||
@@ -51,16 +51,16 @@ static struct GNUNET_SENSOR_Handle *sensor_handle; | |||
51 | * @param tc scheduler context | 51 | * @param tc scheduler context |
52 | */ | 52 | */ |
53 | static void | 53 | static void |
54 | shutdown_task (void *cls, | 54 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
55 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
56 | { | 55 | { |
57 | if(NULL != sensor_handle) | 56 | if (NULL != sensor_handle) |
58 | { | 57 | { |
59 | GNUNET_SENSOR_disconnect(sensor_handle); | 58 | GNUNET_SENSOR_disconnect (sensor_handle); |
60 | sensor_handle = NULL; | 59 | sensor_handle = NULL; |
61 | } | 60 | } |
62 | } | 61 | } |
63 | 62 | ||
63 | |||
64 | /** | 64 | /** |
65 | * Callback for getting sensor info from service | 65 | * Callback for getting sensor info from service |
66 | * | 66 | * |
@@ -68,27 +68,26 @@ shutdown_task (void *cls, | |||
68 | * @param sensor brief information about sensor (NULL means end of transmission) | 68 | * @param sensor brief information about sensor (NULL means end of transmission) |
69 | * @param err_msg contains error string if any | 69 | * @param err_msg contains error string if any |
70 | */ | 70 | */ |
71 | void print_sensor_info(void *cls, | 71 | void |
72 | const struct SensorInfoShort *sensor, | 72 | print_sensor_info (void *cls, const struct SensorInfoShort *sensor, |
73 | const char *err_msg) | 73 | const char *err_msg) |
74 | { | 74 | { |
75 | if(NULL != err_msg) | 75 | if (NULL != err_msg) |
76 | { | 76 | { |
77 | printf("Error: %s\n", err_msg); | 77 | printf ("Error: %s\n", err_msg); |
78 | GNUNET_SCHEDULER_shutdown(); | 78 | GNUNET_SCHEDULER_shutdown (); |
79 | return; | 79 | return; |
80 | } | 80 | } |
81 | if(NULL == sensor) /* no more sensors from service */ | 81 | if (NULL == sensor) /* no more sensors from service */ |
82 | return; | 82 | return; |
83 | printf("Name: %s\nVersion: %d.%d\n", | 83 | printf ("Name: %s\nVersion: %d.%d\n", sensor->name, sensor->version_major, |
84 | sensor->name, | 84 | sensor->version_minor); |
85 | sensor->version_major, | 85 | if (NULL != sensor->description) |
86 | sensor->version_minor); | 86 | printf ("Description: %s\n", sensor->description); |
87 | if(NULL != sensor->description) | 87 | printf ("\n"); |
88 | printf("Description: %s\n", sensor->description); | ||
89 | printf("\n"); | ||
90 | } | 88 | } |
91 | 89 | ||
90 | |||
92 | /** | 91 | /** |
93 | * Main function that will be run by the scheduler. | 92 | * Main function that will be run by the scheduler. |
94 | * | 93 | * |
@@ -98,41 +97,31 @@ void print_sensor_info(void *cls, | |||
98 | * @param cfg configuration | 97 | * @param cfg configuration |
99 | */ | 98 | */ |
100 | static void | 99 | static void |
101 | run (void *cls, | 100 | run (void *cls, char *const *args, const char *cfgfile, |
102 | char *const *args, | ||
103 | const char *cfgfile, | ||
104 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 101 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
105 | { | 102 | { |
106 | |||
107 | sensor_handle = NULL; | 103 | sensor_handle = NULL; |
108 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 104 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, |
109 | &shutdown_task, | 105 | NULL); |
110 | NULL); | 106 | sensor_handle = GNUNET_SENSOR_connect (cfg); |
111 | sensor_handle = GNUNET_SENSOR_connect(cfg); | 107 | GNUNET_assert (NULL != sensor_handle); |
112 | GNUNET_assert(NULL != sensor_handle); | 108 | if (GNUNET_YES == get_all) |
113 | if(GNUNET_YES == get_all) | ||
114 | { | 109 | { |
115 | GNUNET_SENSOR_iterate_sensors(sensor_handle, | 110 | GNUNET_SENSOR_iterate_sensors (sensor_handle, GNUNET_TIME_UNIT_FOREVER_REL, |
116 | GNUNET_TIME_UNIT_FOREVER_REL, | 111 | NULL, 0, &print_sensor_info, NULL); |
117 | NULL, | ||
118 | 0, | ||
119 | &print_sensor_info, | ||
120 | NULL); | ||
121 | } | 112 | } |
122 | else if(NULL != get_sensor) | 113 | else if (NULL != get_sensor) |
123 | { | 114 | { |
124 | GNUNET_SENSOR_iterate_sensors(sensor_handle, | 115 | GNUNET_SENSOR_iterate_sensors (sensor_handle, GNUNET_TIME_UNIT_FOREVER_REL, |
125 | GNUNET_TIME_UNIT_FOREVER_REL, | 116 | get_sensor, strlen (get_sensor), |
126 | get_sensor, | 117 | &print_sensor_info, NULL); |
127 | strlen(get_sensor), | ||
128 | &print_sensor_info, | ||
129 | NULL); | ||
130 | } | 118 | } |
131 | 119 | ||
132 | GNUNET_SCHEDULER_shutdown(); | 120 | GNUNET_SCHEDULER_shutdown (); |
133 | ret = 0; | 121 | ret = 0; |
134 | } | 122 | } |
135 | 123 | ||
124 | |||
136 | /** | 125 | /** |
137 | * The main function to sensor. | 126 | * The main function to sensor. |
138 | * | 127 | * |
@@ -144,21 +133,19 @@ int | |||
144 | main (int argc, char *const *argv) | 133 | main (int argc, char *const *argv) |
145 | { | 134 | { |
146 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | 135 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { |
147 | {'a', "all", NULL, | 136 | {'a', "all", NULL, |
148 | gettext_noop("Retrieve information about all defined sensors"), | 137 | gettext_noop ("Retrieve information about all defined sensors"), |
149 | 0, &GNUNET_GETOPT_set_one, &get_all}, | 138 | 0, &GNUNET_GETOPT_set_one, &get_all}, |
150 | {'g', "get-sensor", NULL, | 139 | {'g', "get-sensor", NULL, |
151 | gettext_noop("Retrieve information about a single sensor"), | 140 | gettext_noop ("Retrieve information about a single sensor"), |
152 | 1, &GNUNET_GETOPT_set_string, &get_sensor}, | 141 | 1, &GNUNET_GETOPT_set_string, &get_sensor}, |
153 | GNUNET_GETOPT_OPTION_END | 142 | GNUNET_GETOPT_OPTION_END |
154 | }; | 143 | }; |
144 | |||
155 | return (GNUNET_OK == | 145 | return (GNUNET_OK == |
156 | GNUNET_PROGRAM_run (argc, | 146 | GNUNET_PROGRAM_run (argc, argv, "gnunet-sensor [options [value]]", |
157 | argv, | 147 | gettext_noop ("sensor"), options, &run, |
158 | "gnunet-sensor [options [value]]", | 148 | NULL)) ? ret : 1; |
159 | gettext_noop | ||
160 | ("sensor"), | ||
161 | options, &run, NULL)) ? ret : 1; | ||
162 | } | 149 | } |
163 | 150 | ||
164 | /* end of gnunet-sensor.c */ | 151 | /* end of gnunet-sensor.c */ |
diff --git a/src/sensor/gnunet-service-sensor-analysis.c b/src/sensor/gnunet-service-sensor-analysis.c index 4b99045ff..f4a1269a4 100644 --- a/src/sensor/gnunet-service-sensor-analysis.c +++ b/src/sensor/gnunet-service-sensor-analysis.c | |||
@@ -100,19 +100,18 @@ static struct SensorModel *models_tail; | |||
100 | */ | 100 | */ |
101 | struct GNUNET_PeerIdentity peerid; | 101 | struct GNUNET_PeerIdentity peerid; |
102 | 102 | ||
103 | /* | 103 | /** |
104 | * Destroy a created model | 104 | * Destroy a created model |
105 | */ | 105 | */ |
106 | static void | 106 | static void |
107 | destroy_sensor_model (struct SensorModel *sensor_model) | 107 | destroy_sensor_model (struct SensorModel *sensor_model) |
108 | { | 108 | { |
109 | GNUNET_assert (NULL != sensor_model); | 109 | GNUNET_assert (NULL != sensor_model); |
110 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 110 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Destroying sensor model for `%s'.\n", |
111 | "Destroying sensor model for `%s'.\n", | 111 | sensor_model->sensor->name); |
112 | sensor_model->sensor->name); | ||
113 | if (NULL != sensor_model->wc) | 112 | if (NULL != sensor_model->wc) |
114 | { | 113 | { |
115 | GNUNET_PEERSTORE_watch_cancel(sensor_model->wc); | 114 | GNUNET_PEERSTORE_watch_cancel (sensor_model->wc); |
116 | sensor_model->wc = NULL; | 115 | sensor_model->wc = NULL; |
117 | } | 116 | } |
118 | if (NULL != sensor_model->cls) | 117 | if (NULL != sensor_model->cls) |
@@ -120,14 +119,16 @@ destroy_sensor_model (struct SensorModel *sensor_model) | |||
120 | model_api->destroy_model (sensor_model->cls); | 119 | model_api->destroy_model (sensor_model->cls); |
121 | sensor_model->cls = NULL; | 120 | sensor_model->cls = NULL; |
122 | } | 121 | } |
123 | GNUNET_free(sensor_model); | 122 | GNUNET_free (sensor_model); |
124 | sensor_model = NULL; | 123 | sensor_model = NULL; |
125 | } | 124 | } |
126 | 125 | ||
127 | /* | 126 | |
127 | /** | ||
128 | * Stop the sensor analysis module | 128 | * Stop the sensor analysis module |
129 | */ | 129 | */ |
130 | void SENSOR_analysis_stop() | 130 | void |
131 | SENSOR_analysis_stop () | ||
131 | { | 132 | { |
132 | struct SensorModel *sm; | 133 | struct SensorModel *sm; |
133 | 134 | ||
@@ -135,12 +136,12 @@ void SENSOR_analysis_stop() | |||
135 | while (NULL != models_head) | 136 | while (NULL != models_head) |
136 | { | 137 | { |
137 | sm = models_head; | 138 | sm = models_head; |
138 | GNUNET_CONTAINER_DLL_remove(models_head, models_tail, sm); | 139 | GNUNET_CONTAINER_DLL_remove (models_head, models_tail, sm); |
139 | destroy_sensor_model(sm); | 140 | destroy_sensor_model (sm); |
140 | } | 141 | } |
141 | if (NULL != peerstore) | 142 | if (NULL != peerstore) |
142 | { | 143 | { |
143 | GNUNET_PEERSTORE_disconnect(peerstore, GNUNET_YES); | 144 | GNUNET_PEERSTORE_disconnect (peerstore, GNUNET_YES); |
144 | peerstore = NULL; | 145 | peerstore = NULL; |
145 | } | 146 | } |
146 | if (NULL != model_api) | 147 | if (NULL != model_api) |
@@ -151,40 +152,39 @@ void SENSOR_analysis_stop() | |||
151 | } | 152 | } |
152 | } | 153 | } |
153 | 154 | ||
154 | /* | 155 | |
156 | /** | ||
155 | * Sensor value watch callback | 157 | * Sensor value watch callback |
156 | */ | 158 | */ |
157 | static int | 159 | static int |
158 | sensor_watcher (void *cls, | 160 | sensor_watcher (void *cls, struct GNUNET_PEERSTORE_Record *record, char *emsg) |
159 | struct GNUNET_PEERSTORE_Record *record, | ||
160 | char *emsg) | ||
161 | { | 161 | { |
162 | struct SensorModel *sensor_model = cls; | 162 | struct SensorModel *sensor_model = cls; |
163 | double *val; | 163 | double *val; |
164 | int anomalous; | 164 | int anomalous; |
165 | 165 | ||
166 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 166 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
167 | "Received a sensor value, will feed to sensor model.\n"); | 167 | "Received a sensor value, will feed to sensor model.\n"); |
168 | if (sizeof(double) != record->value_size) | 168 | if (sizeof (double) != record->value_size) |
169 | { | 169 | { |
170 | LOG (GNUNET_ERROR_TYPE_ERROR, | 170 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Received an invalid sensor value.")); |
171 | _("Received an invalid sensor value.")); | ||
172 | return GNUNET_YES; | 171 | return GNUNET_YES; |
173 | } | 172 | } |
174 | val = (double *)(record->value); | 173 | val = (double *) (record->value); |
175 | anomalous = model_api->feed_model (sensor_model->cls, *val); | 174 | anomalous = model_api->feed_model (sensor_model->cls, *val); |
176 | if (GNUNET_YES == anomalous) | 175 | if (GNUNET_YES == anomalous) |
177 | { | 176 | { |
178 | LOG (GNUNET_ERROR_TYPE_WARNING, | 177 | LOG (GNUNET_ERROR_TYPE_WARNING, |
179 | "Anomaly detected in sensor `%s', value: %f.\n", | 178 | "Anomaly detected in sensor `%s', value: %f.\n", |
180 | sensor_model->sensor->name, *val); | 179 | sensor_model->sensor->name, *val); |
181 | } | 180 | } |
182 | else | 181 | else |
183 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Value non-anomalous.\n"); | 182 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Value non-anomalous.\n"); |
184 | return GNUNET_YES; | 183 | return GNUNET_YES; |
185 | } | 184 | } |
186 | 185 | ||
187 | /* | 186 | |
187 | /** | ||
188 | * Iterator for defined sensors | 188 | * Iterator for defined sensors |
189 | * Creates sensor model for numeric sensors | 189 | * Creates sensor model for numeric sensors |
190 | * | 190 | * |
@@ -194,28 +194,27 @@ sensor_watcher (void *cls, | |||
194 | * @return #GNUNET_YES to continue iterations | 194 | * @return #GNUNET_YES to continue iterations |
195 | */ | 195 | */ |
196 | static int | 196 | static int |
197 | init_sensor_model (void *cls, | 197 | init_sensor_model (void *cls, const struct GNUNET_HashCode *key, void *value) |
198 | const struct GNUNET_HashCode *key, | ||
199 | void *value) | ||
200 | { | 198 | { |
201 | struct GNUNET_SENSOR_SensorInfo *sensor = value; | 199 | struct GNUNET_SENSOR_SensorInfo *sensor = value; |
202 | struct SensorModel *sensor_model; | 200 | struct SensorModel *sensor_model; |
203 | 201 | ||
204 | if (0 != strcmp("numeric", sensor->expected_datatype)) | 202 | if (0 != strcmp ("numeric", sensor->expected_datatype)) |
205 | return GNUNET_YES; | 203 | return GNUNET_YES; |
206 | sensor_model = GNUNET_new(struct SensorModel); | 204 | sensor_model = GNUNET_new (struct SensorModel); |
207 | sensor_model->sensor = sensor; | 205 | sensor_model->sensor = sensor; |
208 | sensor_model->wc = GNUNET_PEERSTORE_watch(peerstore, | 206 | sensor_model->wc = |
209 | "sensor", &peerid, sensor->name, | 207 | GNUNET_PEERSTORE_watch (peerstore, "sensor", &peerid, sensor->name, |
210 | &sensor_watcher, sensor_model); | 208 | &sensor_watcher, sensor_model); |
211 | sensor_model->cls = model_api->create_model(model_api->cls); | 209 | sensor_model->cls = model_api->create_model (model_api->cls); |
212 | GNUNET_CONTAINER_DLL_insert(models_head, models_tail, sensor_model); | 210 | GNUNET_CONTAINER_DLL_insert (models_head, models_tail, sensor_model); |
213 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 211 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Created sensor model for `%s'.\n", |
214 | "Created sensor model for `%s'.\n", sensor->name); | 212 | sensor->name); |
215 | return GNUNET_YES; | 213 | return GNUNET_YES; |
216 | } | 214 | } |
217 | 215 | ||
218 | /* | 216 | |
217 | /** | ||
219 | * Start the sensor analysis module | 218 | * Start the sensor analysis module |
220 | * | 219 | * |
221 | * @param c our service configuration | 220 | * @param c our service configuration |
@@ -223,38 +222,41 @@ init_sensor_model (void *cls, | |||
223 | * @return #GNUNET_OK if started successfully, #GNUNET_SYSERR otherwise | 222 | * @return #GNUNET_OK if started successfully, #GNUNET_SYSERR otherwise |
224 | */ | 223 | */ |
225 | int | 224 | int |
226 | SENSOR_analysis_start(const struct GNUNET_CONFIGURATION_Handle *c, | 225 | SENSOR_analysis_start (const struct GNUNET_CONFIGURATION_Handle *c, |
227 | struct GNUNET_CONTAINER_MultiHashMap *sensors) | 226 | struct GNUNET_CONTAINER_MultiHashMap *sensors) |
228 | { | 227 | { |
229 | char *model_name; | 228 | char *model_name; |
230 | 229 | ||
231 | GNUNET_assert(NULL != sensors); | 230 | GNUNET_assert (NULL != sensors); |
232 | cfg = c; | 231 | cfg = c; |
233 | if (GNUNET_OK != | 232 | if (GNUNET_OK != |
234 | GNUNET_CONFIGURATION_get_value_string (cfg, "sensor-analysis", "MODEL", | 233 | GNUNET_CONFIGURATION_get_value_string (cfg, "sensor-analysis", "MODEL", |
235 | &model_name)) | 234 | &model_name)) |
236 | { | 235 | { |
237 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Analysis model not defined in configuration.\n")); | 236 | LOG (GNUNET_ERROR_TYPE_ERROR, |
237 | _("Analysis model not defined in configuration.\n")); | ||
238 | return GNUNET_SYSERR; | 238 | return GNUNET_SYSERR; |
239 | } | 239 | } |
240 | GNUNET_asprintf (&model_lib_name, "libgnunet_plugin_sensor_model_%s", model_name); | 240 | GNUNET_asprintf (&model_lib_name, "libgnunet_plugin_sensor_model_%s", |
241 | model_api = GNUNET_PLUGIN_load(model_lib_name, (void *) cfg); | 241 | model_name); |
242 | GNUNET_free(model_name); | 242 | model_api = GNUNET_PLUGIN_load (model_lib_name, (void *) cfg); |
243 | if(NULL == model_api) | 243 | GNUNET_free (model_name); |
244 | if (NULL == model_api) | ||
244 | { | 245 | { |
245 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Could not load analysis model `%s'.\n"), model_lib_name); | 246 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Could not load analysis model `%s'.\n"), |
247 | model_lib_name); | ||
246 | return GNUNET_SYSERR; | 248 | return GNUNET_SYSERR; |
247 | } | 249 | } |
248 | peerstore = GNUNET_PEERSTORE_connect(cfg); | 250 | peerstore = GNUNET_PEERSTORE_connect (cfg); |
249 | if (NULL == peerstore) | 251 | if (NULL == peerstore) |
250 | { | 252 | { |
251 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Could not connect to peerstore service.\n")); | 253 | LOG (GNUNET_ERROR_TYPE_ERROR, |
252 | SENSOR_analysis_stop(); | 254 | _("Could not connect to peerstore service.\n")); |
255 | SENSOR_analysis_stop (); | ||
253 | return GNUNET_SYSERR; | 256 | return GNUNET_SYSERR; |
254 | } | 257 | } |
255 | GNUNET_CRYPTO_get_peer_identity(cfg, &peerid); | 258 | GNUNET_CRYPTO_get_peer_identity (cfg, &peerid); |
256 | GNUNET_CONTAINER_multihashmap_iterate(sensors, &init_sensor_model, NULL); | 259 | GNUNET_CONTAINER_multihashmap_iterate (sensors, &init_sensor_model, NULL); |
257 | |||
258 | return GNUNET_OK; | 260 | return GNUNET_OK; |
259 | } | 261 | } |
260 | 262 | ||
diff --git a/src/sensor/gnunet-service-sensor-reporting.c b/src/sensor/gnunet-service-sensor-reporting.c index 0a422002f..b935328d4 100644 --- a/src/sensor/gnunet-service-sensor-reporting.c +++ b/src/sensor/gnunet-service-sensor-reporting.c | |||
@@ -182,7 +182,6 @@ struct CadetChannelContext *cc_head; | |||
182 | */ | 182 | */ |
183 | struct CadetChannelContext *cc_tail; | 183 | struct CadetChannelContext *cc_tail; |
184 | 184 | ||
185 | |||
186 | /** | 185 | /** |
187 | * Destroy a reporting context structure | 186 | * Destroy a reporting context structure |
188 | */ | 187 | */ |
@@ -196,7 +195,7 @@ destroy_reporting_context (struct ReportingContext *rc) | |||
196 | } | 195 | } |
197 | if (GNUNET_SCHEDULER_NO_TASK != rc->cp_task) | 196 | if (GNUNET_SCHEDULER_NO_TASK != rc->cp_task) |
198 | { | 197 | { |
199 | GNUNET_SCHEDULER_cancel(rc->cp_task); | 198 | GNUNET_SCHEDULER_cancel (rc->cp_task); |
200 | rc->cp_task = GNUNET_SCHEDULER_NO_TASK; | 199 | rc->cp_task = GNUNET_SCHEDULER_NO_TASK; |
201 | } | 200 | } |
202 | if (NULL != rc->last_value) | 201 | if (NULL != rc->last_value) |
@@ -204,9 +203,10 @@ destroy_reporting_context (struct ReportingContext *rc) | |||
204 | GNUNET_free (rc->last_value); | 203 | GNUNET_free (rc->last_value); |
205 | rc->last_value_size = 0; | 204 | rc->last_value_size = 0; |
206 | } | 205 | } |
207 | GNUNET_free(rc); | 206 | GNUNET_free (rc); |
208 | } | 207 | } |
209 | 208 | ||
209 | |||
210 | /** | 210 | /** |
211 | * Destroy a CADET channel context struct | 211 | * Destroy a CADET channel context struct |
212 | */ | 212 | */ |
@@ -242,8 +242,7 @@ SENSOR_reporting_stop () | |||
242 | struct ReportingContext *rc; | 242 | struct ReportingContext *rc; |
243 | struct CadetChannelContext *cc; | 243 | struct CadetChannelContext *cc; |
244 | 244 | ||
245 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 245 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Stopping sensor reporting module.\n"); |
246 | "Stopping sensor reporting module.\n"); | ||
247 | while (NULL != cc_head) | 246 | while (NULL != cc_head) |
248 | { | 247 | { |
249 | cc = cc_head; | 248 | cc = cc_head; |
@@ -289,11 +288,10 @@ get_cadet_channel (struct GNUNET_PeerIdentity pid) | |||
289 | cc = cc->next; | 288 | cc = cc->next; |
290 | } | 289 | } |
291 | cc = GNUNET_new (struct CadetChannelContext); | 290 | cc = GNUNET_new (struct CadetChannelContext); |
292 | cc->c = GNUNET_CADET_channel_create(cadet, | 291 | cc->c = |
293 | cc, | 292 | GNUNET_CADET_channel_create (cadet, cc, &pid, |
294 | &pid, | 293 | GNUNET_APPLICATION_TYPE_SENSORDASHBOARD, |
295 | GNUNET_APPLICATION_TYPE_SENSORDASHBOARD, | 294 | GNUNET_CADET_OPTION_DEFAULT); |
296 | GNUNET_CADET_OPTION_DEFAULT); | ||
297 | cc->pid = pid; | 295 | cc->pid = pid; |
298 | cc->sending = GNUNET_NO; | 296 | cc->sending = GNUNET_NO; |
299 | cc->destroying = GNUNET_NO; | 297 | cc->destroying = GNUNET_NO; |
@@ -319,8 +317,8 @@ construct_reading_message (struct ReportingContext *rc, | |||
319 | void *dummy; | 317 | void *dummy; |
320 | 318 | ||
321 | sensorname_size = strlen (rc->sensor->name) + 1; | 319 | sensorname_size = strlen (rc->sensor->name) + 1; |
322 | total_size = sizeof(struct GNUNET_SENSOR_ReadingMessage) + | 320 | total_size = |
323 | sensorname_size + | 321 | sizeof (struct GNUNET_SENSOR_ReadingMessage) + sensorname_size + |
324 | rc->last_value_size; | 322 | rc->last_value_size; |
325 | ret = GNUNET_malloc (total_size); | 323 | ret = GNUNET_malloc (total_size); |
326 | ret->header.size = htons (total_size); | 324 | ret->header.size = htons (total_size); |
@@ -357,18 +355,17 @@ do_report_collection_point (void *cls, size_t size, void *buf) | |||
357 | 355 | ||
358 | cc->th = NULL; | 356 | cc->th = NULL; |
359 | cc->sending = GNUNET_NO; | 357 | cc->sending = GNUNET_NO; |
360 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 358 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Copying to CADET transmit buffer.\n"); |
361 | "Copying to CADET transmit buffer.\n"); | ||
362 | if (NULL == buf) | 359 | if (NULL == buf) |
363 | { | 360 | { |
364 | LOG (GNUNET_ERROR_TYPE_WARNING, | 361 | LOG (GNUNET_ERROR_TYPE_WARNING, |
365 | "CADET failed to transmit message (NULL buf), discarding.\n"); | 362 | "CADET failed to transmit message (NULL buf), discarding.\n"); |
366 | } | 363 | } |
367 | else if (size < cc->pending_msg_size) | 364 | else if (size < cc->pending_msg_size) |
368 | { | 365 | { |
369 | LOG (GNUNET_ERROR_TYPE_WARNING, | 366 | LOG (GNUNET_ERROR_TYPE_WARNING, |
370 | "CADET failed to transmit message (small size, expected: %u, got: %u)" | 367 | "CADET failed to transmit message (small size, expected: %u, got: %u)" |
371 | ", discarding.\n", cc->pending_msg_size, size); | 368 | ", discarding.\n", cc->pending_msg_size, size); |
372 | } | 369 | } |
373 | else | 370 | else |
374 | { | 371 | { |
@@ -390,7 +387,7 @@ do_report_collection_point (void *cls, size_t size, void *buf) | |||
390 | */ | 387 | */ |
391 | static void | 388 | static void |
392 | report_collection_point (void *cls, | 389 | report_collection_point (void *cls, |
393 | const struct GNUNET_SCHEDULER_TaskContext* tc) | 390 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
394 | { | 391 | { |
395 | struct ReportingContext *rc = cls; | 392 | struct ReportingContext *rc = cls; |
396 | struct GNUNET_SENSOR_SensorInfo *sensor = rc->sensor; | 393 | struct GNUNET_SENSOR_SensorInfo *sensor = rc->sensor; |
@@ -404,13 +401,13 @@ report_collection_point (void *cls, | |||
404 | LOG (GNUNET_ERROR_TYPE_WARNING, | 401 | LOG (GNUNET_ERROR_TYPE_WARNING, |
405 | "Did not receive a value from `%s' to report yet.\n", | 402 | "Did not receive a value from `%s' to report yet.\n", |
406 | rc->sensor->name); | 403 | rc->sensor->name); |
407 | rc->cp_task = GNUNET_SCHEDULER_add_delayed (sensor->collection_interval, | 404 | rc->cp_task = |
408 | &report_collection_point, rc); | 405 | GNUNET_SCHEDULER_add_delayed (sensor->collection_interval, |
406 | &report_collection_point, rc); | ||
409 | return; | 407 | return; |
410 | } | 408 | } |
411 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 409 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
412 | "Now trying to report last seen value of `%s' " | 410 | "Now trying to report last seen value of `%s' " "to collection point.\n", |
413 | "to collection point.\n", | ||
414 | rc->sensor->name); | 411 | rc->sensor->name); |
415 | GNUNET_assert (NULL != sensor->collection_point); | 412 | GNUNET_assert (NULL != sensor->collection_point); |
416 | cc = get_cadet_channel (*sensor->collection_point); | 413 | cc = get_cadet_channel (*sensor->collection_point); |
@@ -418,26 +415,26 @@ report_collection_point (void *cls, | |||
418 | { | 415 | { |
419 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 416 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
420 | "Cadet channel to collection point busy, " | 417 | "Cadet channel to collection point busy, " |
421 | "trying again for sensor `%s' after %d seconds.\n", | 418 | "trying again for sensor `%s' after %d seconds.\n", rc->sensor->name, |
422 | rc->sensor->name, | ||
423 | COLLECTION_RETRY); | 419 | COLLECTION_RETRY); |
424 | rc->cp_task = GNUNET_SCHEDULER_add_delayed ( | 420 | rc->cp_task = |
425 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, COLLECTION_RETRY), | 421 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
426 | &report_collection_point, rc); | 422 | (GNUNET_TIME_UNIT_SECONDS, |
423 | COLLECTION_RETRY), | ||
424 | &report_collection_point, rc); | ||
427 | return; | 425 | return; |
428 | } | 426 | } |
429 | msg_size = construct_reading_message (rc, &msg); | 427 | msg_size = construct_reading_message (rc, &msg); |
430 | cc->sending = GNUNET_YES; | 428 | cc->sending = GNUNET_YES; |
431 | cc->pending_msg = msg; | 429 | cc->pending_msg = msg; |
432 | cc->pending_msg_size = msg_size; | 430 | cc->pending_msg_size = msg_size; |
433 | cc->th = GNUNET_CADET_notify_transmit_ready (cc->c, | 431 | cc->th = |
434 | GNUNET_YES, | 432 | GNUNET_CADET_notify_transmit_ready (cc->c, GNUNET_YES, |
435 | sensor->collection_interval, | 433 | sensor->collection_interval, msg_size, |
436 | msg_size, | 434 | &do_report_collection_point, cc); |
437 | &do_report_collection_point, | 435 | rc->cp_task = |
438 | cc); | 436 | GNUNET_SCHEDULER_add_delayed (sensor->collection_interval, |
439 | rc->cp_task = GNUNET_SCHEDULER_add_delayed (sensor->collection_interval, | 437 | &report_collection_point, rc); |
440 | &report_collection_point, rc); | ||
441 | } | 438 | } |
442 | 439 | ||
443 | 440 | ||
@@ -445,9 +442,7 @@ report_collection_point (void *cls, | |||
445 | * Sensor value watch callback | 442 | * Sensor value watch callback |
446 | */ | 443 | */ |
447 | static int | 444 | static int |
448 | sensor_watch_cb (void *cls, | 445 | sensor_watch_cb (void *cls, struct GNUNET_PEERSTORE_Record *record, char *emsg) |
449 | struct GNUNET_PEERSTORE_Record *record, | ||
450 | char *emsg) | ||
451 | { | 446 | { |
452 | struct ReportingContext *rc = cls; | 447 | struct ReportingContext *rc = cls; |
453 | 448 | ||
@@ -458,14 +453,13 @@ sensor_watch_cb (void *cls, | |||
458 | GNUNET_free (rc->last_value); | 453 | GNUNET_free (rc->last_value); |
459 | rc->last_value_size = 0; | 454 | rc->last_value_size = 0; |
460 | } | 455 | } |
461 | rc->last_value = GNUNET_malloc(record->value_size); | 456 | rc->last_value = GNUNET_malloc (record->value_size); |
462 | memcpy (rc->last_value, record->value, record->value_size); | 457 | memcpy (rc->last_value, record->value, record->value_size); |
463 | rc->last_value_size = record->value_size; | 458 | rc->last_value_size = record->value_size; |
464 | rc->timestamp = GNUNET_TIME_absolute_get().abs_value_us; | 459 | rc->timestamp = GNUNET_TIME_absolute_get ().abs_value_us; |
465 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 460 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
466 | "Received a sensor `%s' watch value at " | 461 | "Received a sensor `%s' watch value at " "timestamp %" PRIu64 |
467 | "timestamp %" PRIu64 ", updating notification last_value.\n", | 462 | ", updating notification last_value.\n", rc->sensor->name, |
468 | rc->sensor->name, | ||
469 | rc->timestamp); | 463 | rc->timestamp); |
470 | return GNUNET_YES; | 464 | return GNUNET_YES; |
471 | } | 465 | } |
@@ -481,46 +475,40 @@ sensor_watch_cb (void *cls, | |||
481 | * @return #GNUNET_YES to continue iterations | 475 | * @return #GNUNET_YES to continue iterations |
482 | */ | 476 | */ |
483 | static int | 477 | static int |
484 | init_sensor_reporting (void *cls, | 478 | init_sensor_reporting (void *cls, const struct GNUNET_HashCode *key, |
485 | const struct GNUNET_HashCode *key, | ||
486 | void *value) | 479 | void *value) |
487 | { | 480 | { |
488 | struct GNUNET_SENSOR_SensorInfo *sensor = value; | 481 | struct GNUNET_SENSOR_SensorInfo *sensor = value; |
489 | struct ReportingContext *rc; | 482 | struct ReportingContext *rc; |
490 | 483 | ||
491 | if (NULL == sensor->collection_point && | 484 | if (NULL == sensor->collection_point && GNUNET_NO == sensor->p2p_report) |
492 | GNUNET_NO == sensor->p2p_report) | ||
493 | return GNUNET_YES; | 485 | return GNUNET_YES; |
494 | rc = GNUNET_new (struct ReportingContext); | 486 | rc = GNUNET_new (struct ReportingContext); |
495 | rc->sensor = sensor; | 487 | rc->sensor = sensor; |
496 | rc->last_value = NULL; | 488 | rc->last_value = NULL; |
497 | rc->last_value_size = 0; | 489 | rc->last_value_size = 0; |
498 | rc->wc = GNUNET_PEERSTORE_watch(peerstore, | 490 | rc->wc = |
499 | "sensor", | 491 | GNUNET_PEERSTORE_watch (peerstore, "sensor", &mypeerid, sensor->name, |
500 | &mypeerid, | 492 | &sensor_watch_cb, rc); |
501 | sensor->name, | ||
502 | &sensor_watch_cb, | ||
503 | rc); | ||
504 | if (NULL != sensor->collection_point) | 493 | if (NULL != sensor->collection_point) |
505 | { | 494 | { |
506 | LOG (GNUNET_ERROR_TYPE_INFO, | 495 | LOG (GNUNET_ERROR_TYPE_INFO, |
507 | "Will start reporting sensor `%s' values to " | 496 | "Will start reporting sensor `%s' values to " |
508 | "collection point `%s' every %s.\n", | 497 | "collection point `%s' every %s.\n", sensor->name, |
509 | sensor->name, GNUNET_i2s_full(sensor->collection_point), | 498 | GNUNET_i2s_full (sensor->collection_point), |
510 | GNUNET_STRINGS_relative_time_to_string(sensor->collection_interval, | 499 | GNUNET_STRINGS_relative_time_to_string (sensor->collection_interval, |
511 | GNUNET_YES)); | 500 | GNUNET_YES)); |
512 | rc->cp_task = | 501 | rc->cp_task = |
513 | GNUNET_SCHEDULER_add_delayed (sensor->collection_interval, | 502 | GNUNET_SCHEDULER_add_delayed (sensor->collection_interval, |
514 | &report_collection_point, | 503 | &report_collection_point, rc); |
515 | rc); | ||
516 | } | 504 | } |
517 | if (GNUNET_YES == sensor->p2p_report) | 505 | if (GNUNET_YES == sensor->p2p_report) |
518 | { | 506 | { |
519 | LOG (GNUNET_ERROR_TYPE_INFO, | 507 | LOG (GNUNET_ERROR_TYPE_INFO, |
520 | "Will start reporting sensor `%s' values to p2p network every %s.\n", | 508 | "Will start reporting sensor `%s' values to p2p network every %s.\n", |
521 | sensor->name, | 509 | sensor->name, |
522 | GNUNET_STRINGS_relative_time_to_string(sensor->p2p_interval, | 510 | GNUNET_STRINGS_relative_time_to_string (sensor->p2p_interval, |
523 | GNUNET_YES)); | 511 | GNUNET_YES)); |
524 | } | 512 | } |
525 | GNUNET_CONTAINER_DLL_insert (rc_head, rc_tail, rc); | 513 | GNUNET_CONTAINER_DLL_insert (rc_head, rc_tail, rc); |
526 | return GNUNET_YES; | 514 | return GNUNET_YES; |
@@ -539,8 +527,7 @@ init_sensor_reporting (void *cls, | |||
539 | * with the channel is stored | 527 | * with the channel is stored |
540 | */ | 528 | */ |
541 | static void | 529 | static void |
542 | cadet_channel_destroyed (void *cls, | 530 | cadet_channel_destroyed (void *cls, const struct GNUNET_CADET_Channel *channel, |
543 | const struct GNUNET_CADET_Channel *channel, | ||
544 | void *channel_ctx) | 531 | void *channel_ctx) |
545 | { | 532 | { |
546 | struct CadetChannelContext *cc = channel_ctx; | 533 | struct CadetChannelContext *cc = channel_ctx; |
@@ -567,38 +554,31 @@ SENSOR_reporting_start (const struct GNUNET_CONFIGURATION_Handle *c, | |||
567 | struct GNUNET_CONTAINER_MultiHashMap *sensors) | 554 | struct GNUNET_CONTAINER_MultiHashMap *sensors) |
568 | { | 555 | { |
569 | static struct GNUNET_CADET_MessageHandler cadet_handlers[] = { | 556 | static struct GNUNET_CADET_MessageHandler cadet_handlers[] = { |
570 | {NULL, 0, 0} | 557 | {NULL, 0, 0} |
571 | }; | 558 | }; |
572 | 559 | ||
573 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 560 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting sensor reporting module.\n"); |
574 | "Starting sensor reporting module.\n"); | 561 | GNUNET_assert (NULL != sensors); |
575 | GNUNET_assert(NULL != sensors); | ||
576 | cfg = c; | 562 | cfg = c; |
577 | peerstore = GNUNET_PEERSTORE_connect(cfg); | 563 | peerstore = GNUNET_PEERSTORE_connect (cfg); |
578 | if (NULL == peerstore) | 564 | if (NULL == peerstore) |
579 | { | 565 | { |
580 | LOG (GNUNET_ERROR_TYPE_ERROR, | 566 | LOG (GNUNET_ERROR_TYPE_ERROR, |
581 | _("Failed to connect to peerstore service.\n")); | 567 | _("Failed to connect to peerstore service.\n")); |
582 | SENSOR_reporting_stop (); | 568 | SENSOR_reporting_stop (); |
583 | return GNUNET_SYSERR; | 569 | return GNUNET_SYSERR; |
584 | } | 570 | } |
585 | cadet = GNUNET_CADET_connect(cfg, | 571 | cadet = |
586 | NULL, | 572 | GNUNET_CADET_connect (cfg, NULL, NULL, &cadet_channel_destroyed, |
587 | NULL, | 573 | cadet_handlers, NULL); |
588 | &cadet_channel_destroyed, | ||
589 | cadet_handlers, | ||
590 | NULL); | ||
591 | if (NULL == cadet) | 574 | if (NULL == cadet) |
592 | { | 575 | { |
593 | LOG (GNUNET_ERROR_TYPE_ERROR, | 576 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Failed to connect to CADET service.\n")); |
594 | _("Failed to connect to CADET service.\n")); | ||
595 | SENSOR_reporting_stop (); | 577 | SENSOR_reporting_stop (); |
596 | return GNUNET_SYSERR; | 578 | return GNUNET_SYSERR; |
597 | } | 579 | } |
598 | GNUNET_CRYPTO_get_peer_identity (cfg, | 580 | GNUNET_CRYPTO_get_peer_identity (cfg, &mypeerid); |
599 | &mypeerid); | 581 | GNUNET_CONTAINER_multihashmap_iterate (sensors, &init_sensor_reporting, NULL); |
600 | GNUNET_CONTAINER_multihashmap_iterate(sensors, | ||
601 | &init_sensor_reporting, NULL); | ||
602 | return GNUNET_OK; | 582 | return GNUNET_OK; |
603 | } | 583 | } |
604 | 584 | ||
diff --git a/src/sensor/gnunet-service-sensor-update.c b/src/sensor/gnunet-service-sensor-update.c index db79b4c04..3d3eb335d 100644 --- a/src/sensor/gnunet-service-sensor-update.c +++ b/src/sensor/gnunet-service-sensor-update.c | |||
@@ -168,7 +168,7 @@ GNUNET_SCHEDULER_TaskIdentifier update_task; | |||
168 | /** | 168 | /** |
169 | * Pointer to service reset function called when we have new sensor updates. | 169 | * Pointer to service reset function called when we have new sensor updates. |
170 | */ | 170 | */ |
171 | void (*reset_cb)(); | 171 | void (*reset_cb) (); |
172 | 172 | ||
173 | 173 | ||
174 | /** | 174 | /** |
@@ -178,8 +178,8 @@ void (*reset_cb)(); | |||
178 | * @param tc GNUnet scheduler task context | 178 | * @param tc GNUnet scheduler task context |
179 | */ | 179 | */ |
180 | static void | 180 | static void |
181 | check_for_updates (void *cls, | 181 | check_for_updates (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); |
182 | const struct GNUNET_SCHEDULER_TaskContext *tc); | 182 | |
183 | 183 | ||
184 | /** | 184 | /** |
185 | * Trigger sending next pending message to the default update point if any. | 185 | * Trigger sending next pending message to the default update point if any. |
@@ -249,8 +249,7 @@ SENSOR_update_stop () | |||
249 | GNUNET_CADET_disconnect (cadet); | 249 | GNUNET_CADET_disconnect (cadet); |
250 | cadet = NULL; | 250 | cadet = NULL; |
251 | } | 251 | } |
252 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 252 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Sensor update module stopped.\n"); |
253 | "Sensor update module stopped.\n"); | ||
254 | } | 253 | } |
255 | 254 | ||
256 | 255 | ||
@@ -277,8 +276,9 @@ fail () | |||
277 | up->failed = GNUNET_NO; | 276 | up->failed = GNUNET_NO; |
278 | up = up->next; | 277 | up = up->next; |
279 | } | 278 | } |
280 | update_task = GNUNET_SCHEDULER_add_delayed (SENSOR_UPDATE_CHECK_INTERVAL, | 279 | update_task = |
281 | &check_for_updates, NULL); | 280 | GNUNET_SCHEDULER_add_delayed (SENSOR_UPDATE_CHECK_INTERVAL, |
281 | &check_for_updates, NULL); | ||
282 | return; | 282 | return; |
283 | } | 283 | } |
284 | LOG (GNUNET_ERROR_TYPE_WARNING, | 284 | LOG (GNUNET_ERROR_TYPE_WARNING, |
@@ -342,11 +342,9 @@ trigger_send_next_msg () | |||
342 | return; | 342 | return; |
343 | pm = up_default->pm_head; | 343 | pm = up_default->pm_head; |
344 | up_default->th = | 344 | up_default->th = |
345 | GNUNET_CADET_notify_transmit_ready (up_default->ch, | 345 | GNUNET_CADET_notify_transmit_ready (up_default->ch, GNUNET_YES, |
346 | GNUNET_YES, | ||
347 | GNUNET_TIME_UNIT_FOREVER_REL, | 346 | GNUNET_TIME_UNIT_FOREVER_REL, |
348 | ntohs (pm->msg->size), | 347 | ntohs (pm->msg->size), &do_send_msg, |
349 | &do_send_msg, | ||
350 | NULL); | 348 | NULL); |
351 | } | 349 | } |
352 | 350 | ||
@@ -362,9 +360,9 @@ queue_msg (struct GNUNET_MessageHeader *msg) | |||
362 | struct PendingMessage *pm; | 360 | struct PendingMessage *pm; |
363 | 361 | ||
364 | pm = GNUNET_new (struct PendingMessage); | 362 | pm = GNUNET_new (struct PendingMessage); |
363 | |||
365 | pm->msg = msg; | 364 | pm->msg = msg; |
366 | GNUNET_CONTAINER_DLL_insert_tail (up_default->pm_head, | 365 | GNUNET_CONTAINER_DLL_insert_tail (up_default->pm_head, up_default->pm_tail, |
367 | up_default->pm_tail, | ||
368 | pm); | 366 | pm); |
369 | trigger_send_next_msg (); | 367 | trigger_send_next_msg (); |
370 | } | 368 | } |
@@ -377,8 +375,7 @@ queue_msg (struct GNUNET_MessageHeader *msg) | |||
377 | * @param tc GNUnet scheduler task context | 375 | * @param tc GNUnet scheduler task context |
378 | */ | 376 | */ |
379 | static void | 377 | static void |
380 | check_for_updates (void *cls, | 378 | check_for_updates (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
381 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
382 | { | 379 | { |
383 | struct GNUNET_MessageHeader *msg; | 380 | struct GNUNET_MessageHeader *msg; |
384 | size_t msg_size; | 381 | size_t msg_size; |
@@ -393,18 +390,16 @@ check_for_updates (void *cls, | |||
393 | "Retrying in %s.\n", | 390 | "Retrying in %s.\n", |
394 | GNUNET_STRINGS_relative_time_to_string (SENSOR_UPDATE_CHECK_RETRY, | 391 | GNUNET_STRINGS_relative_time_to_string (SENSOR_UPDATE_CHECK_RETRY, |
395 | GNUNET_NO)); | 392 | GNUNET_NO)); |
396 | update_task = GNUNET_SCHEDULER_add_delayed (SENSOR_UPDATE_CHECK_RETRY, | 393 | update_task = |
397 | &check_for_updates, NULL); | 394 | GNUNET_SCHEDULER_add_delayed (SENSOR_UPDATE_CHECK_RETRY, |
395 | &check_for_updates, NULL); | ||
398 | return; | 396 | return; |
399 | } | 397 | } |
400 | updating = GNUNET_YES; | 398 | updating = GNUNET_YES; |
401 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 399 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Checking for sensor updates.\n"); |
402 | "Checking for sensor updates.\n"); | ||
403 | GNUNET_assert (NULL != up_default); | 400 | GNUNET_assert (NULL != up_default); |
404 | up_default->ch = | 401 | up_default->ch = |
405 | GNUNET_CADET_channel_create (cadet, | 402 | GNUNET_CADET_channel_create (cadet, up_default, &up_default->peer_id, |
406 | up_default, | ||
407 | &up_default->peer_id, | ||
408 | GNUNET_APPLICATION_TYPE_SENSORUPDATE, | 403 | GNUNET_APPLICATION_TYPE_SENSORUPDATE, |
409 | GNUNET_CADET_OPTION_DEFAULT); | 404 | GNUNET_CADET_OPTION_DEFAULT); |
410 | if (NULL == up_default->ch) | 405 | if (NULL == up_default->ch) |
@@ -422,8 +417,9 @@ check_for_updates (void *cls, | |||
422 | msg->size = htons (msg_size); | 417 | msg->size = htons (msg_size); |
423 | msg->type = htons (GNUNET_MESSAGE_TYPE_SENSOR_LIST_REQ); | 418 | msg->type = htons (GNUNET_MESSAGE_TYPE_SENSOR_LIST_REQ); |
424 | queue_msg (msg); | 419 | queue_msg (msg); |
425 | update_task = GNUNET_SCHEDULER_add_delayed (SENSOR_UPDATE_CHECK_INTERVAL, | 420 | update_task = |
426 | &check_for_updates, NULL); | 421 | GNUNET_SCHEDULER_add_delayed (SENSOR_UPDATE_CHECK_INTERVAL, |
422 | &check_for_updates, NULL); | ||
427 | } | 423 | } |
428 | 424 | ||
429 | 425 | ||
@@ -444,18 +440,16 @@ load_update_points () | |||
444 | struct GNUNET_CRYPTO_EddsaPublicKey public_key; | 440 | struct GNUNET_CRYPTO_EddsaPublicKey public_key; |
445 | struct UpdatePoint *up; | 441 | struct UpdatePoint *up; |
446 | 442 | ||
447 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, | 443 | if (GNUNET_OK != |
448 | "sensor", | 444 | GNUNET_CONFIGURATION_get_value_string (cfg, "sensor", "UPDATE_POINTS", |
449 | "UPDATE_POINTS", | 445 | &points_list)) |
450 | &points_list)) | ||
451 | { | 446 | { |
452 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 447 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "sensor", |
453 | "sensor", | ||
454 | "UPDATE_POINTS"); | 448 | "UPDATE_POINTS"); |
455 | return GNUNET_SYSERR; | 449 | return GNUNET_SYSERR; |
456 | } | 450 | } |
457 | points_list_len = strlen (points_list) + 1; | 451 | points_list_len = strlen (points_list) + 1; |
458 | for (i = 0; i < points_list_len; i ++) | 452 | for (i = 0; i < points_list_len; i++) |
459 | { | 453 | { |
460 | if (' ' == points_list[i]) | 454 | if (' ' == points_list[i]) |
461 | continue; | 455 | continue; |
@@ -463,20 +457,20 @@ load_update_points () | |||
463 | len = 0; | 457 | len = 0; |
464 | while (' ' != points_list[i] && '\0' != points_list[i]) | 458 | while (' ' != points_list[i] && '\0' != points_list[i]) |
465 | { | 459 | { |
466 | len ++; | 460 | len++; |
467 | i ++; | 461 | i++; |
468 | } | 462 | } |
469 | if (GNUNET_OK != | 463 | if (GNUNET_OK != |
470 | GNUNET_CRYPTO_eddsa_public_key_from_string (points_list + start, | 464 | GNUNET_CRYPTO_eddsa_public_key_from_string (points_list + start, len, |
471 | len, | ||
472 | &public_key)) | 465 | &public_key)) |
473 | { | 466 | { |
474 | LOG (GNUNET_ERROR_TYPE_ERROR, | 467 | LOG (GNUNET_ERROR_TYPE_ERROR, |
475 | "Invalid EDDSA public key `%.*s' for update point.\n", | 468 | "Invalid EDDSA public key `%.*s' for update point.\n", len, |
476 | len, points_list + len); | 469 | points_list + len); |
477 | continue; | 470 | continue; |
478 | } | 471 | } |
479 | up = GNUNET_new (struct UpdatePoint); | 472 | up = GNUNET_new (struct UpdatePoint); |
473 | |||
480 | up->peer_id.public_key = public_key; | 474 | up->peer_id.public_key = public_key; |
481 | up->ch = NULL; | 475 | up->ch = NULL; |
482 | up->th = NULL; | 476 | up->th = NULL; |
@@ -484,8 +478,7 @@ load_update_points () | |||
484 | up->expected_sensor_updates = 0; | 478 | up->expected_sensor_updates = 0; |
485 | up->failed = GNUNET_NO; | 479 | up->failed = GNUNET_NO; |
486 | GNUNET_CONTAINER_DLL_insert (up_head, up_tail, up); | 480 | GNUNET_CONTAINER_DLL_insert (up_head, up_tail, up); |
487 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 481 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Loaded update point `%s'.\n", |
488 | "Loaded update point `%s'.\n", | ||
489 | GNUNET_i2s_full (&up->peer_id)); | 482 | GNUNET_i2s_full (&up->peer_id)); |
490 | } | 483 | } |
491 | GNUNET_free (points_list); | 484 | GNUNET_free (points_list); |
@@ -505,8 +498,7 @@ load_update_points () | |||
505 | * #GNUNET_NO if we have it | 498 | * #GNUNET_NO if we have it |
506 | */ | 499 | */ |
507 | static int | 500 | static int |
508 | update_required (char *sensorname, | 501 | update_required (char *sensorname, uint16_t sensorversion_major, |
509 | uint16_t sensorversion_major, | ||
510 | uint16_t sensorversion_minor) | 502 | uint16_t sensorversion_minor) |
511 | { | 503 | { |
512 | struct GNUNET_HashCode key; | 504 | struct GNUNET_HashCode key; |
@@ -516,10 +508,9 @@ update_required (char *sensorname, | |||
516 | local_sensor = GNUNET_CONTAINER_multihashmap_get (sensors, &key); | 508 | local_sensor = GNUNET_CONTAINER_multihashmap_get (sensors, &key); |
517 | if (NULL == local_sensor) | 509 | if (NULL == local_sensor) |
518 | return GNUNET_YES; | 510 | return GNUNET_YES; |
519 | if (GNUNET_SENSOR_version_compare (local_sensor->version_major, | 511 | if (GNUNET_SENSOR_version_compare |
520 | local_sensor->version_minor, | 512 | (local_sensor->version_major, local_sensor->version_minor, |
521 | sensorversion_major, | 513 | sensorversion_major, sensorversion_minor) < 0) |
522 | sensorversion_minor) < 0) | ||
523 | return GNUNET_YES; | 514 | return GNUNET_YES; |
524 | return GNUNET_NO; | 515 | return GNUNET_NO; |
525 | } | 516 | } |
@@ -536,8 +527,7 @@ update_required (char *sensorname, | |||
536 | * #GNUNET_SYSERR to close it (signal serious error). | 527 | * #GNUNET_SYSERR to close it (signal serious error). |
537 | */ | 528 | */ |
538 | static int | 529 | static int |
539 | handle_sensor_brief (void *cls, | 530 | handle_sensor_brief (void *cls, struct GNUNET_CADET_Channel *channel, |
540 | struct GNUNET_CADET_Channel *channel, | ||
541 | void **channel_ctx, | 531 | void **channel_ctx, |
542 | const struct GNUNET_MessageHeader *message) | 532 | const struct GNUNET_MessageHeader *message) |
543 | { | 533 | { |
@@ -569,16 +559,15 @@ handle_sensor_brief (void *cls, | |||
569 | } | 559 | } |
570 | else | 560 | else |
571 | { | 561 | { |
572 | sbm = (struct GNUNET_SENSOR_SensorBriefMessage *)message; | 562 | sbm = (struct GNUNET_SENSOR_SensorBriefMessage *) message; |
573 | version_major = ntohs (sbm->version_major); | 563 | version_major = ntohs (sbm->version_major); |
574 | version_minor = ntohs (sbm->version_minor); | 564 | version_minor = ntohs (sbm->version_minor); |
575 | if (GNUNET_YES == update_required ((char *)&sbm[1], | 565 | if (GNUNET_YES == |
576 | version_major, | 566 | update_required ((char *) &sbm[1], version_major, version_minor)) |
577 | version_minor)) | ||
578 | { | 567 | { |
579 | LOG (GNUNET_ERROR_TYPE_INFO, | 568 | LOG (GNUNET_ERROR_TYPE_INFO, |
580 | "Requesting sensor %s %d.%d from update point.\n", | 569 | "Requesting sensor %s %d.%d from update point.\n", &sbm[1], |
581 | &sbm[1], version_major, version_minor); | 570 | version_major, version_minor); |
582 | /* We duplicate the same msg received but change the type and send it | 571 | /* We duplicate the same msg received but change the type and send it |
583 | * back to update point to ask for full sensor information. */ | 572 | * back to update point to ask for full sensor information. */ |
584 | msg_size = ntohs (message->size); | 573 | msg_size = ntohs (message->size); |
@@ -586,7 +575,7 @@ handle_sensor_brief (void *cls, | |||
586 | memcpy (pull_req, message, msg_size); | 575 | memcpy (pull_req, message, msg_size); |
587 | pull_req->type = htons (GNUNET_MESSAGE_TYPE_SENSOR_FULL_REQ); | 576 | pull_req->type = htons (GNUNET_MESSAGE_TYPE_SENSOR_FULL_REQ); |
588 | queue_msg (pull_req); | 577 | queue_msg (pull_req); |
589 | up_default->expected_sensor_updates ++; | 578 | up_default->expected_sensor_updates++; |
590 | } | 579 | } |
591 | } | 580 | } |
592 | GNUNET_CADET_receive_done (channel); | 581 | GNUNET_CADET_receive_done (channel); |
@@ -606,39 +595,28 @@ handle_sensor_brief (void *cls, | |||
606 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 595 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
607 | */ | 596 | */ |
608 | static int | 597 | static int |
609 | update_sensor (char *sensorname, | 598 | update_sensor (char *sensorname, void *sensorfile, uint16_t sensorfile_size, |
610 | void *sensorfile, uint16_t sensorfile_size, | 599 | char *scriptname, void *scriptfile, uint16_t scriptfile_size) |
611 | char *scriptname, | ||
612 | void *scriptfile, uint16_t scriptfile_size) | ||
613 | { | 600 | { |
614 | char *sensors_dir; | 601 | char *sensors_dir; |
615 | char *sensor_path; | 602 | char *sensor_path; |
616 | char *script_path; | 603 | char *script_path; |
617 | 604 | ||
618 | LOG (GNUNET_ERROR_TYPE_INFO, | 605 | LOG (GNUNET_ERROR_TYPE_INFO, |
619 | "Received new sensor information:\n" | 606 | "Received new sensor information:\n" "Name: %s\n" |
620 | "Name: %s\n" | 607 | "Sensor file size: %d\n" "Script name: %s\n" "Script file size: %d.\n", |
621 | "Sensor file size: %d\n" | 608 | sensorname, sensorfile_size, (NULL == scriptname) ? "None" : scriptname, |
622 | "Script name: %s\n" | ||
623 | "Script file size: %d.\n", | ||
624 | sensorname, | ||
625 | sensorfile_size, | ||
626 | (NULL == scriptname) ? "None" : scriptname, | ||
627 | scriptfile_size); | 609 | scriptfile_size); |
628 | sensors_dir = GNUNET_SENSOR_get_sensor_dir (); | 610 | sensors_dir = GNUNET_SENSOR_get_sensor_dir (); |
629 | GNUNET_asprintf (&sensor_path, "%s%s", sensors_dir, sensorname); | 611 | GNUNET_asprintf (&sensor_path, "%s%s", sensors_dir, sensorname); |
630 | GNUNET_DISK_fn_write (sensor_path, sensorfile, sensorfile_size, | 612 | GNUNET_DISK_fn_write (sensor_path, sensorfile, sensorfile_size, |
631 | GNUNET_DISK_PERM_USER_READ | | 613 | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_GROUP_READ |
632 | GNUNET_DISK_PERM_GROUP_READ | | 614 | | GNUNET_DISK_PERM_OTHER_READ | |
633 | GNUNET_DISK_PERM_OTHER_READ | | ||
634 | GNUNET_DISK_PERM_USER_WRITE); | 615 | GNUNET_DISK_PERM_USER_WRITE); |
635 | if (NULL != scriptname) | 616 | if (NULL != scriptname) |
636 | { | 617 | { |
637 | GNUNET_asprintf (&script_path, | 618 | GNUNET_asprintf (&script_path, "%s-files%s%s", sensor_path, |
638 | "%s-files%s%s", | 619 | DIR_SEPARATOR_STR, scriptname); |
639 | sensor_path, | ||
640 | DIR_SEPARATOR_STR, | ||
641 | scriptname); | ||
642 | GNUNET_DISK_fn_write (script_path, scriptfile, scriptfile_size, | 620 | GNUNET_DISK_fn_write (script_path, scriptfile, scriptfile_size, |
643 | GNUNET_DISK_PERM_USER_READ | | 621 | GNUNET_DISK_PERM_USER_READ | |
644 | GNUNET_DISK_PERM_GROUP_READ | | 622 | GNUNET_DISK_PERM_GROUP_READ | |
@@ -661,7 +639,8 @@ update_sensor (char *sensorname, | |||
661 | * @param cls unused | 639 | * @param cls unused |
662 | * @param tc unused | 640 | * @param tc unused |
663 | */ | 641 | */ |
664 | void reset (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 642 | void |
643 | reset (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
665 | { | 644 | { |
666 | reset_cb (); | 645 | reset_cb (); |
667 | } | 646 | } |
@@ -678,10 +657,9 @@ void reset (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
678 | * #GNUNET_SYSERR to close it (signal serious error). | 657 | * #GNUNET_SYSERR to close it (signal serious error). |
679 | */ | 658 | */ |
680 | static int | 659 | static int |
681 | handle_sensor_full (void *cls, | 660 | handle_sensor_full (void *cls, struct GNUNET_CADET_Channel *channel, |
682 | struct GNUNET_CADET_Channel *channel, | 661 | void **channel_ctx, |
683 | void **channel_ctx, | 662 | const struct GNUNET_MessageHeader *message) |
684 | const struct GNUNET_MessageHeader *message) | ||
685 | { | 663 | { |
686 | struct GNUNET_SENSOR_SensorFullMessage *sfm; | 664 | struct GNUNET_SENSOR_SensorFullMessage *sfm; |
687 | uint16_t msg_size; | 665 | uint16_t msg_size; |
@@ -703,8 +681,8 @@ handle_sensor_full (void *cls, | |||
703 | return GNUNET_OK; | 681 | return GNUNET_OK; |
704 | } | 682 | } |
705 | /* parse received msg */ | 683 | /* parse received msg */ |
706 | sfm = (struct GNUNET_SENSOR_SensorFullMessage *)message; | 684 | sfm = (struct GNUNET_SENSOR_SensorFullMessage *) message; |
707 | sensorname_ptr = (char *)&sfm[1]; | 685 | sensorname_ptr = (char *) &sfm[1]; |
708 | sensorfile_ptr = sensorname_ptr + ntohs (sfm->sensorname_size); | 686 | sensorfile_ptr = sensorname_ptr + ntohs (sfm->sensorname_size); |
709 | sensorfile_size = ntohs (sfm->sensorfile_size); | 687 | sensorfile_size = ntohs (sfm->sensorfile_size); |
710 | scriptfile_size = ntohs (sfm->scriptfile_size); | 688 | scriptfile_size = ntohs (sfm->scriptfile_size); |
@@ -718,13 +696,9 @@ handle_sensor_full (void *cls, | |||
718 | scriptname_ptr = NULL; | 696 | scriptname_ptr = NULL; |
719 | scriptfile_ptr = NULL; | 697 | scriptfile_ptr = NULL; |
720 | } | 698 | } |
721 | update_sensor ((char *)&sfm[1], | 699 | update_sensor ((char *) &sfm[1], sensorfile_ptr, sensorfile_size, |
722 | sensorfile_ptr, | 700 | scriptname_ptr, scriptfile_ptr, scriptfile_size); |
723 | sensorfile_size, | 701 | up_default->expected_sensor_updates--; |
724 | scriptname_ptr, | ||
725 | scriptfile_ptr, | ||
726 | scriptfile_size); | ||
727 | up_default->expected_sensor_updates --; | ||
728 | if (0 == up_default->expected_sensor_updates) | 702 | if (0 == up_default->expected_sensor_updates) |
729 | { | 703 | { |
730 | updating = GNUNET_NO; | 704 | updating = GNUNET_NO; |
@@ -749,8 +723,7 @@ handle_sensor_full (void *cls, | |||
749 | * with the channel is stored | 723 | * with the channel is stored |
750 | */ | 724 | */ |
751 | static void | 725 | static void |
752 | cadet_channel_destroyed (void *cls, | 726 | cadet_channel_destroyed (void *cls, const struct GNUNET_CADET_Channel *channel, |
753 | const struct GNUNET_CADET_Channel *channel, | ||
754 | void *channel_ctx) | 727 | void *channel_ctx) |
755 | { | 728 | { |
756 | struct UpdatePoint *up = channel_ctx; | 729 | struct UpdatePoint *up = channel_ctx; |
@@ -769,52 +742,46 @@ cadet_channel_destroyed (void *cls, | |||
769 | * Start the sensor update module | 742 | * Start the sensor update module |
770 | * | 743 | * |
771 | * @param c our service configuration | 744 | * @param c our service configuration |
772 | * @param sensors multihashmap of loaded sensors | 745 | * @param s multihashmap of loaded sensors |
773 | * @param cb callback to reset service components when we have new updates | 746 | * @param cb callback to reset service components when we have new updates |
774 | * @return #GNUNET_OK if started successfully, #GNUNET_SYSERR otherwise | 747 | * @return #GNUNET_OK if started successfully, #GNUNET_SYSERR otherwise |
775 | */ | 748 | */ |
776 | int | 749 | int |
777 | SENSOR_update_start (const struct GNUNET_CONFIGURATION_Handle *c, | 750 | SENSOR_update_start (const struct GNUNET_CONFIGURATION_Handle *c, |
778 | struct GNUNET_CONTAINER_MultiHashMap *s, | 751 | struct GNUNET_CONTAINER_MultiHashMap *s, void (*cb) ()) |
779 | void (*cb)()) | ||
780 | { | 752 | { |
781 | static struct GNUNET_CADET_MessageHandler cadet_handlers[] = { | 753 | static struct GNUNET_CADET_MessageHandler cadet_handlers[] = { |
782 | {&handle_sensor_brief, GNUNET_MESSAGE_TYPE_SENSOR_BRIEF, 0}, | 754 | {&handle_sensor_brief, GNUNET_MESSAGE_TYPE_SENSOR_BRIEF, 0}, |
783 | {&handle_sensor_brief, GNUNET_MESSAGE_TYPE_SENSOR_END, 0}, | 755 | {&handle_sensor_brief, GNUNET_MESSAGE_TYPE_SENSOR_END, 0}, |
784 | {&handle_sensor_full, GNUNET_MESSAGE_TYPE_SENSOR_FULL, 0}, | 756 | {&handle_sensor_full, GNUNET_MESSAGE_TYPE_SENSOR_FULL, 0}, |
785 | {NULL, 0, 0} | 757 | {NULL, 0, 0} |
786 | }; | 758 | }; |
787 | 759 | ||
788 | GNUNET_assert(NULL != s); | 760 | GNUNET_assert (NULL != s); |
789 | cfg = c; | 761 | cfg = c; |
790 | sensors = s; | 762 | sensors = s; |
791 | reset_cb = cb; | 763 | reset_cb = cb; |
792 | cadet = GNUNET_CADET_connect(cfg, | 764 | cadet = |
793 | NULL, | 765 | GNUNET_CADET_connect (cfg, NULL, NULL, &cadet_channel_destroyed, |
794 | NULL, | 766 | cadet_handlers, NULL); |
795 | &cadet_channel_destroyed, | ||
796 | cadet_handlers, | ||
797 | NULL); | ||
798 | if (NULL == cadet) | 767 | if (NULL == cadet) |
799 | { | 768 | { |
800 | LOG (GNUNET_ERROR_TYPE_ERROR, | 769 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Failed to connect to CADET service.\n")); |
801 | _("Failed to connect to CADET service.\n")); | ||
802 | SENSOR_update_stop (); | 770 | SENSOR_update_stop (); |
803 | return GNUNET_SYSERR; | 771 | return GNUNET_SYSERR; |
804 | } | 772 | } |
805 | if (GNUNET_OK != load_update_points ()) | 773 | if (GNUNET_OK != load_update_points ()) |
806 | { | 774 | { |
807 | LOG (GNUNET_ERROR_TYPE_ERROR, | 775 | LOG (GNUNET_ERROR_TYPE_ERROR, "Failed to load update points.\n"); |
808 | "Failed to load update points.\n"); | ||
809 | SENSOR_update_stop (); | 776 | SENSOR_update_stop (); |
810 | return GNUNET_SYSERR; | 777 | return GNUNET_SYSERR; |
811 | } | 778 | } |
812 | up_default = up_head; | 779 | up_default = up_head; |
813 | updating = GNUNET_NO; | 780 | updating = GNUNET_NO; |
814 | update_task = GNUNET_SCHEDULER_add_delayed (SENSOR_UPDATE_CHECK_INTERVAL, | 781 | update_task = |
815 | &check_for_updates, NULL); | 782 | GNUNET_SCHEDULER_add_delayed (SENSOR_UPDATE_CHECK_INTERVAL, |
816 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 783 | &check_for_updates, NULL); |
817 | "Sensor update module started.\n"); | 784 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Sensor update module started.\n"); |
818 | return GNUNET_OK; | 785 | return GNUNET_OK; |
819 | } | 786 | } |
820 | 787 | ||
diff --git a/src/sensor/gnunet-service-sensor.c b/src/sensor/gnunet-service-sensor.c index 4f2942fec..24cb8d2aa 100644 --- a/src/sensor/gnunet-service-sensor.c +++ b/src/sensor/gnunet-service-sensor.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) | 3 | (C) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published |
@@ -79,14 +79,11 @@ reset (); | |||
79 | static void | 79 | static void |
80 | set_sensor_enabled (struct GNUNET_SENSOR_SensorInfo *sensor, int state) | 80 | set_sensor_enabled (struct GNUNET_SENSOR_SensorInfo *sensor, int state) |
81 | { | 81 | { |
82 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 82 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sensor `%s': Setting enabled to %d.\n", |
83 | "Sensor `%s': Setting enabled to %d.\n", | 83 | sensor->name, state); |
84 | sensor->name, state); | ||
85 | sensor->enabled = GNUNET_NO; | 84 | sensor->enabled = GNUNET_NO; |
86 | GNUNET_assert (NULL != sensor->cfg); | 85 | GNUNET_assert (NULL != sensor->cfg); |
87 | GNUNET_CONFIGURATION_set_value_string (sensor->cfg, | 86 | GNUNET_CONFIGURATION_set_value_string (sensor->cfg, sensor->name, "ENABLED", |
88 | sensor->name, | ||
89 | "ENABLED", | ||
90 | (GNUNET_YES == state) ? "YES" : "NO"); | 87 | (GNUNET_YES == state) ? "YES" : "NO"); |
91 | GNUNET_CONFIGURATION_write (sensor->cfg, sensor->def_file); | 88 | GNUNET_CONFIGURATION_write (sensor->cfg, sensor->def_file); |
92 | } | 89 | } |
@@ -112,8 +109,7 @@ stop () | |||
112 | * @param tc unused | 109 | * @param tc unused |
113 | */ | 110 | */ |
114 | static void | 111 | static void |
115 | shutdown_task (void *cls, | 112 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
116 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
117 | { | 113 | { |
118 | stop (); | 114 | stop (); |
119 | if (NULL != statistics) | 115 | if (NULL != statistics) |
@@ -137,11 +133,11 @@ shutdown_task (void *cls, | |||
137 | * @param client identification of the client | 133 | * @param client identification of the client |
138 | */ | 134 | */ |
139 | static void | 135 | static void |
140 | handle_client_disconnect (void *cls, | 136 | handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) |
141 | struct GNUNET_SERVER_Client *client) | ||
142 | { | 137 | { |
143 | } | 138 | } |
144 | 139 | ||
140 | |||
145 | /** | 141 | /** |
146 | * Creates a structure with basic sensor info to be sent to a client. | 142 | * Creates a structure with basic sensor info to be sent to a client. |
147 | * | 143 | * |
@@ -157,34 +153,35 @@ create_sensor_info_msg (struct GNUNET_SENSOR_SensorInfo *sensor) | |||
157 | size_t desc_len; | 153 | size_t desc_len; |
158 | char *str_ptr; | 154 | char *str_ptr; |
159 | 155 | ||
160 | name_len = strlen(sensor->name); | 156 | name_len = strlen (sensor->name); |
161 | if(NULL == sensor->description) | 157 | if (NULL == sensor->description) |
162 | desc_len = 0; | 158 | desc_len = 0; |
163 | else | 159 | else |
164 | desc_len = strlen(sensor->description) + 1; | 160 | desc_len = strlen (sensor->description) + 1; |
165 | len = 0; | 161 | len = 0; |
166 | len += sizeof(struct SensorInfoMessage); | 162 | len += sizeof (struct SensorInfoMessage); |
167 | len += name_len; | 163 | len += name_len; |
168 | len += desc_len; | 164 | len += desc_len; |
169 | msg = GNUNET_malloc(len); | 165 | msg = GNUNET_malloc (len); |
170 | msg->header.size = htons(len); | 166 | msg->header.size = htons (len); |
171 | msg->header.type = htons(GNUNET_MESSAGE_TYPE_SENSOR_INFO); | 167 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_SENSOR_INFO); |
172 | msg->name_len = htons(name_len); | 168 | msg->name_len = htons (name_len); |
173 | msg->description_len = htons(desc_len); | 169 | msg->description_len = htons (desc_len); |
174 | msg->version_major = htons(sensor->version_major); | 170 | msg->version_major = htons (sensor->version_major); |
175 | msg->version_minor = htons(sensor->version_minor); | 171 | msg->version_minor = htons (sensor->version_minor); |
176 | str_ptr = (char*) &msg[1]; | 172 | str_ptr = (char *) &msg[1]; |
177 | memcpy(str_ptr, sensor->name, name_len); | 173 | memcpy (str_ptr, sensor->name, name_len); |
178 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending sensor name (%d): %.*s\n", | 174 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending sensor name (%d): %.*s\n", |
179 | name_len, name_len, str_ptr); | 175 | name_len, name_len, str_ptr); |
180 | str_ptr += name_len; | 176 | str_ptr += name_len; |
181 | memcpy(str_ptr, sensor->description, desc_len); | 177 | memcpy (str_ptr, sensor->description, desc_len); |
182 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending sensor description (%d): %.*s\n", | 178 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
183 | desc_len, desc_len, str_ptr); | 179 | "Sending sensor description (%d): %.*s\n", desc_len, desc_len, |
184 | 180 | str_ptr); | |
185 | return msg; | 181 | return msg; |
186 | } | 182 | } |
187 | 183 | ||
184 | |||
188 | /** | 185 | /** |
189 | * Handle GET SENSOR message. | 186 | * Handle GET SENSOR message. |
190 | * | 187 | * |
@@ -193,8 +190,7 @@ create_sensor_info_msg (struct GNUNET_SENSOR_SensorInfo *sensor) | |||
193 | * @param message the actual message | 190 | * @param message the actual message |
194 | */ | 191 | */ |
195 | static void | 192 | static void |
196 | handle_get_sensor (void *cls, | 193 | handle_get_sensor (void *cls, struct GNUNET_SERVER_Client *client, |
197 | struct GNUNET_SERVER_Client *client, | ||
198 | const struct GNUNET_MessageHeader *message) | 194 | const struct GNUNET_MessageHeader *message) |
199 | { | 195 | { |
200 | struct GNUNET_SERVER_TransmitContext *tc; | 196 | struct GNUNET_SERVER_TransmitContext *tc; |
@@ -204,27 +200,36 @@ handle_get_sensor (void *cls, | |||
204 | struct GNUNET_SENSOR_SensorInfo *sensorinfo; | 200 | struct GNUNET_SENSOR_SensorInfo *sensorinfo; |
205 | struct SensorInfoMessage *msg; | 201 | struct SensorInfoMessage *msg; |
206 | 202 | ||
207 | sensorname = (char *)&message[1]; | 203 | sensorname = (char *) &message[1]; |
208 | sensorname_len = ntohs(message->size) - sizeof(struct GNUNET_MessageHeader); | 204 | sensorname_len = ntohs (message->size) - sizeof (struct GNUNET_MessageHeader); |
209 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "`%s' message received for sensor (%d) `%.*s'\n", | 205 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
210 | "GET SENSOR", sensorname_len, sensorname_len, sensorname); | 206 | "`%s' message received for sensor (%d) `%.*s'\n", "GET SENSOR", |
207 | sensorname_len, sensorname_len, sensorname); | ||
211 | tc = GNUNET_SERVER_transmit_context_create (client); | 208 | tc = GNUNET_SERVER_transmit_context_create (client); |
212 | GNUNET_CRYPTO_hash(sensorname, sensorname_len, &key); | 209 | GNUNET_CRYPTO_hash (sensorname, sensorname_len, &key); |
213 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created key hash for requested sensor\n"); | 210 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
214 | sensorinfo = (struct GNUNET_SENSOR_SensorInfo *)GNUNET_CONTAINER_multihashmap_get(sensors, &key); | 211 | "Created key hash for requested sensor\n"); |
215 | if(NULL != sensorinfo) | 212 | sensorinfo = |
213 | (struct GNUNET_SENSOR_SensorInfo *) | ||
214 | GNUNET_CONTAINER_multihashmap_get (sensors, &key); | ||
215 | if (NULL != sensorinfo) | ||
216 | { | 216 | { |
217 | msg = create_sensor_info_msg(sensorinfo); | 217 | msg = create_sensor_info_msg (sensorinfo); |
218 | GNUNET_SERVER_transmit_context_append_message(tc, (struct GNUNET_MessageHeader *)msg); | 218 | GNUNET_SERVER_transmit_context_append_message (tc, |
219 | GNUNET_free(msg); | 219 | (struct GNUNET_MessageHeader |
220 | *) msg); | ||
221 | GNUNET_free (msg); | ||
220 | } | 222 | } |
221 | else | 223 | else |
222 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Requested sensor `%.*s' was not found\n", | 224 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
223 | sensorname_len, sensorname); | 225 | "Requested sensor `%.*s' was not found\n", sensorname_len, |
224 | GNUNET_SERVER_transmit_context_append_data(tc, NULL, 0, GNUNET_MESSAGE_TYPE_SENSOR_END); | 226 | sensorname); |
227 | GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, | ||
228 | GNUNET_MESSAGE_TYPE_SENSOR_END); | ||
225 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); | 229 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); |
226 | } | 230 | } |
227 | 231 | ||
232 | |||
228 | /** | 233 | /** |
229 | * Iterator for sensors and adds them to transmit context | 234 | * Iterator for sensors and adds them to transmit context |
230 | * | 235 | * |
@@ -233,22 +238,22 @@ handle_get_sensor (void *cls, | |||
233 | * @param value a `struct GNUNET_SENSOR_SensorInfo *` | 238 | * @param value a `struct GNUNET_SENSOR_SensorInfo *` |
234 | */ | 239 | */ |
235 | static int | 240 | static int |
236 | add_sensor_to_tc (void *cls, | 241 | add_sensor_to_tc (void *cls, const struct GNUNET_HashCode *key, void *value) |
237 | const struct GNUNET_HashCode *key, | ||
238 | void *value) | ||
239 | { | 242 | { |
240 | struct GNUNET_SERVER_TransmitContext *tc = cls; | 243 | struct GNUNET_SERVER_TransmitContext *tc = cls; |
241 | struct GNUNET_SENSOR_SensorInfo *sensorinfo = value; | 244 | struct GNUNET_SENSOR_SensorInfo *sensorinfo = value; |
242 | struct SensorInfoMessage *msg; | 245 | struct SensorInfoMessage *msg; |
243 | 246 | ||
244 | msg = create_sensor_info_msg(sensorinfo); | 247 | msg = create_sensor_info_msg (sensorinfo); |
245 | GNUNET_SERVER_transmit_context_append_message(tc, (struct GNUNET_MessageHeader *)msg); | 248 | GNUNET_SERVER_transmit_context_append_message (tc, |
246 | 249 | (struct GNUNET_MessageHeader *) | |
247 | GNUNET_free(msg); | 250 | msg); |
248 | 251 | ||
252 | GNUNET_free (msg); | ||
249 | return GNUNET_YES; | 253 | return GNUNET_YES; |
250 | } | 254 | } |
251 | 255 | ||
256 | |||
252 | /** | 257 | /** |
253 | * Handle GET ALL SENSORS message. | 258 | * Handle GET ALL SENSORS message. |
254 | * | 259 | * |
@@ -258,86 +263,86 @@ add_sensor_to_tc (void *cls, | |||
258 | */ | 263 | */ |
259 | static void | 264 | static void |
260 | handle_get_all_sensors (void *cls, struct GNUNET_SERVER_Client *client, | 265 | handle_get_all_sensors (void *cls, struct GNUNET_SERVER_Client *client, |
261 | const struct GNUNET_MessageHeader *message) | 266 | const struct GNUNET_MessageHeader *message) |
262 | { | 267 | { |
263 | struct GNUNET_SERVER_TransmitContext *tc; | 268 | struct GNUNET_SERVER_TransmitContext *tc; |
264 | 269 | ||
265 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "`%s' message received.\n", | 270 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "`%s' message received.\n", |
266 | "GET ALL SENSOR"); | 271 | "GET ALL SENSOR"); |
267 | tc = GNUNET_SERVER_transmit_context_create (client); | 272 | tc = GNUNET_SERVER_transmit_context_create (client); |
268 | GNUNET_CONTAINER_multihashmap_iterate(sensors, &add_sensor_to_tc, tc); | 273 | GNUNET_CONTAINER_multihashmap_iterate (sensors, &add_sensor_to_tc, tc); |
269 | GNUNET_SERVER_transmit_context_append_data(tc, NULL, 0, GNUNET_MESSAGE_TYPE_SENSOR_END); | 274 | GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, |
275 | GNUNET_MESSAGE_TYPE_SENSOR_END); | ||
270 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); | 276 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); |
271 | } | 277 | } |
272 | 278 | ||
279 | |||
273 | /** | 280 | /** |
274 | * Do a series of checks to determine if sensor should execute | 281 | * Do a series of checks to determine if sensor should execute |
275 | * | 282 | * |
276 | * @return #GNUNET_YES / #GNUNET_NO | 283 | * @return #GNUNET_YES / #GNUNET_NO |
277 | */ | 284 | */ |
278 | static int | 285 | static int |
279 | should_run_sensor(struct GNUNET_SENSOR_SensorInfo *sensorinfo) | 286 | should_run_sensor (struct GNUNET_SENSOR_SensorInfo *sensorinfo) |
280 | { | 287 | { |
281 | struct GNUNET_TIME_Absolute now; | 288 | struct GNUNET_TIME_Absolute now; |
282 | 289 | ||
283 | if(GNUNET_NO == sensorinfo->enabled) | 290 | if (GNUNET_NO == sensorinfo->enabled) |
284 | { | 291 | { |
285 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Sensor `%s' is disabled, will not run\n", sensorinfo->name); | 292 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
293 | "Sensor `%s' is disabled, will not run\n", sensorinfo->name); | ||
286 | return GNUNET_NO; | 294 | return GNUNET_NO; |
287 | } | 295 | } |
288 | now = GNUNET_TIME_absolute_get(); | 296 | now = GNUNET_TIME_absolute_get (); |
289 | if(NULL != sensorinfo->start_time | 297 | if (NULL != sensorinfo->start_time && |
290 | && now.abs_value_us < sensorinfo->start_time->abs_value_us) | 298 | now.abs_value_us < sensorinfo->start_time->abs_value_us) |
291 | { | 299 | { |
292 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Start time for sensor `%s' not reached yet, will not run\n", sensorinfo->name); | 300 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
301 | "Start time for sensor `%s' not reached yet, will not run\n", | ||
302 | sensorinfo->name); | ||
293 | return GNUNET_NO; | 303 | return GNUNET_NO; |
294 | } | 304 | } |
295 | if(NULL != sensorinfo->end_time | 305 | if (NULL != sensorinfo->end_time && |
296 | && now.abs_value_us >= sensorinfo->end_time->abs_value_us) | 306 | now.abs_value_us >= sensorinfo->end_time->abs_value_us) |
297 | { | 307 | { |
298 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Sensor `%s' expired, disabling.\n", sensorinfo->name); | 308 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Sensor `%s' expired, disabling.\n", |
299 | set_sensor_enabled(sensorinfo, GNUNET_NO); | 309 | sensorinfo->name); |
310 | set_sensor_enabled (sensorinfo, GNUNET_NO); | ||
300 | return GNUNET_NO; | 311 | return GNUNET_NO; |
301 | } | 312 | } |
302 | return GNUNET_YES; | 313 | return GNUNET_YES; |
303 | } | 314 | } |
304 | 315 | ||
316 | |||
305 | /** | 317 | /** |
306 | * Callback function to process statistic values | 318 | * Callback function to process statistic values |
307 | * | 319 | * |
308 | * @param cls `struct GNUNET_SENSOR_SensorInfo *` | 320 | * @param cls `struct GNUNET_SENSOR_SensorInfo *` |
309 | * @param subsystem name of subsystem that created the statistic | 321 | * @param ss name of subsystem that created the statistic |
310 | * @param name the name of the datum | 322 | * @param name the name of the datum |
311 | * @param value the current value | 323 | * @param value the current value |
312 | * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not | 324 | * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not |
313 | * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration | 325 | * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration |
314 | */ | 326 | */ |
315 | static int | 327 | static int |
316 | sensor_statistics_iterator (void *cls, | 328 | sensor_statistics_iterator (void *cls, const char *ss, const char *name, |
317 | const char *ss, | 329 | uint64_t value, int is_persistent) |
318 | const char *name, | ||
319 | uint64_t value, | ||
320 | int is_persistent) | ||
321 | { | 330 | { |
322 | struct GNUNET_SENSOR_SensorInfo *sensorinfo = cls; | 331 | struct GNUNET_SENSOR_SensorInfo *sensorinfo = cls; |
323 | double dvalue = (double)value; | 332 | double dvalue = (double) value; |
324 | struct GNUNET_TIME_Absolute expiry; | 333 | struct GNUNET_TIME_Absolute expiry; |
325 | 334 | ||
326 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Received a value for sensor `%s': %" PRIu64 "\n", sensorinfo->name, value); | 335 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
327 | expiry = GNUNET_TIME_relative_to_absolute(sensorinfo->lifetime); | 336 | "Received a value for sensor `%s': %" PRIu64 "\n", |
328 | GNUNET_PEERSTORE_store(peerstore, | 337 | sensorinfo->name, value); |
329 | subsystem, | 338 | expiry = GNUNET_TIME_relative_to_absolute (sensorinfo->lifetime); |
330 | &peerid, | 339 | GNUNET_PEERSTORE_store (peerstore, subsystem, &peerid, sensorinfo->name, |
331 | sensorinfo->name, | 340 | &dvalue, sizeof (dvalue), expiry, |
332 | &dvalue, | 341 | GNUNET_PEERSTORE_STOREOPTION_MULTIPLE, NULL, NULL); |
333 | sizeof(dvalue), | 342 | return GNUNET_SYSERR; /* We only want one value */ |
334 | expiry, | ||
335 | GNUNET_PEERSTORE_STOREOPTION_MULTIPLE, | ||
336 | NULL, | ||
337 | NULL); | ||
338 | return GNUNET_SYSERR; /* We only want one value */ | ||
339 | } | 343 | } |
340 | 344 | ||
345 | |||
341 | /** | 346 | /** |
342 | * Continuation called after sensor gets all gnunet statistics values | 347 | * Continuation called after sensor gets all gnunet statistics values |
343 | * | 348 | * |
@@ -354,6 +359,7 @@ end_sensor_run_stat (void *cls, int success) | |||
354 | sensorinfo->running = GNUNET_NO; | 359 | sensorinfo->running = GNUNET_NO; |
355 | } | 360 | } |
356 | 361 | ||
362 | |||
357 | /** | 363 | /** |
358 | * Tries to parse a received sensor value to its | 364 | * Tries to parse a received sensor value to its |
359 | * expected datatype | 365 | * expected datatype |
@@ -364,8 +370,7 @@ end_sensor_run_stat (void *cls, int success) | |||
364 | * @return size of new parsed value, 0 for error | 370 | * @return size of new parsed value, 0 for error |
365 | */ | 371 | */ |
366 | static size_t | 372 | static size_t |
367 | parse_sensor_value (const char *value, | 373 | parse_sensor_value (const char *value, struct GNUNET_SENSOR_SensorInfo *sensor, |
368 | struct GNUNET_SENSOR_SensorInfo *sensor, | ||
369 | void **ret) | 374 | void **ret) |
370 | { | 375 | { |
371 | double *dval; | 376 | double *dval; |
@@ -374,25 +379,28 @@ parse_sensor_value (const char *value, | |||
374 | *ret = NULL; | 379 | *ret = NULL; |
375 | if ('\0' == *value) | 380 | if ('\0' == *value) |
376 | return 0; | 381 | return 0; |
377 | if(0 == strcmp("numeric", sensor->expected_datatype)) | 382 | if (0 == strcmp ("numeric", sensor->expected_datatype)) |
378 | { | 383 | { |
379 | dval = GNUNET_new(double); | 384 | dval = GNUNET_new (double); |
380 | *dval = strtod(value, &endptr); | 385 | |
381 | if(value == endptr) | 386 | *dval = strtod (value, &endptr); |
387 | if (value == endptr) | ||
382 | return 0; | 388 | return 0; |
383 | *ret = dval; | 389 | *ret = dval; |
384 | return sizeof(double); | 390 | return sizeof (double); |
385 | } | 391 | } |
386 | if(0 == strcmp("string", sensor->expected_datatype)) | 392 | if (0 == strcmp ("string", sensor->expected_datatype)) |
387 | { | 393 | { |
388 | *ret = GNUNET_strdup(value); | 394 | *ret = GNUNET_strdup (value); |
389 | return strlen(value) + 1; | 395 | return strlen (value) + 1; |
390 | } | 396 | } |
391 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 397 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
392 | _("Unknown value type expected by sensor, this should not happen.\n")); | 398 | _ |
399 | ("Unknown value type expected by sensor, this should not happen.\n")); | ||
393 | return 0; | 400 | return 0; |
394 | } | 401 | } |
395 | 402 | ||
403 | |||
396 | /** | 404 | /** |
397 | * Callback for output of executed sensor process | 405 | * Callback for output of executed sensor process |
398 | * | 406 | * |
@@ -407,62 +415,58 @@ sensor_process_callback (void *cls, const char *line) | |||
407 | size_t valsize; | 415 | size_t valsize; |
408 | struct GNUNET_TIME_Absolute expiry; | 416 | struct GNUNET_TIME_Absolute expiry; |
409 | 417 | ||
410 | if(NULL == line) | 418 | if (NULL == line) |
411 | { | 419 | { |
412 | GNUNET_OS_command_stop(sensorinfo->ext_cmd); | 420 | GNUNET_OS_command_stop (sensorinfo->ext_cmd); |
413 | sensorinfo->ext_cmd = NULL; | 421 | sensorinfo->ext_cmd = NULL; |
414 | sensorinfo->running = GNUNET_NO; | 422 | sensorinfo->running = GNUNET_NO; |
415 | sensorinfo->ext_cmd_value_received = GNUNET_NO; | 423 | sensorinfo->ext_cmd_value_received = GNUNET_NO; |
416 | return; | 424 | return; |
417 | } | 425 | } |
418 | if(GNUNET_YES == sensorinfo->ext_cmd_value_received) | 426 | if (GNUNET_YES == sensorinfo->ext_cmd_value_received) |
419 | return; /* We only want one *valid* value */ | 427 | return; /* We only want one *valid* value */ |
420 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Received a value for sensor `%s': %s\n", sensorinfo->name, line); | 428 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received a value for sensor `%s': %s\n", |
421 | valsize = parse_sensor_value(line, sensorinfo, &value); | 429 | sensorinfo->name, line); |
422 | if (valsize == 0) /* invalid value, FIXME: should we disable the sensor now? */ | 430 | valsize = parse_sensor_value (line, sensorinfo, &value); |
431 | if (valsize == 0) /* invalid value, FIXME: should we disable the sensor now? */ | ||
423 | { | 432 | { |
424 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 433 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
425 | _("Received an invalid value for sensor `%s': %s\n"), | 434 | _("Received an invalid value for sensor `%s': %s\n"), |
426 | sensorinfo->name, line); | 435 | sensorinfo->name, line); |
427 | } | 436 | } |
428 | else | 437 | else |
429 | { | 438 | { |
430 | sensorinfo->ext_cmd_value_received = GNUNET_YES; | 439 | sensorinfo->ext_cmd_value_received = GNUNET_YES; |
431 | expiry = GNUNET_TIME_relative_to_absolute(sensorinfo->lifetime); | 440 | expiry = GNUNET_TIME_relative_to_absolute (sensorinfo->lifetime); |
432 | GNUNET_PEERSTORE_store(peerstore, | 441 | GNUNET_PEERSTORE_store (peerstore, subsystem, &peerid, sensorinfo->name, |
433 | subsystem, | 442 | value, valsize, expiry, |
434 | &peerid, | 443 | GNUNET_PEERSTORE_STOREOPTION_MULTIPLE, NULL, NULL); |
435 | sensorinfo->name, | ||
436 | value, | ||
437 | valsize, | ||
438 | expiry, | ||
439 | GNUNET_PEERSTORE_STOREOPTION_MULTIPLE, | ||
440 | NULL, | ||
441 | NULL); | ||
442 | GNUNET_free (value); | 444 | GNUNET_free (value); |
443 | } | 445 | } |
444 | } | 446 | } |
445 | 447 | ||
448 | |||
446 | /** | 449 | /** |
447 | * Checks if the given file is a path | 450 | * Checks if the given file is a path |
448 | * | 451 | * |
449 | * @return #GNUNET_YES / #GNUNET_NO | 452 | * @return #GNUNET_YES / #GNUNET_NO |
450 | */ | 453 | */ |
451 | static int | 454 | static int |
452 | is_path(char *filename) | 455 | is_path (char *filename) |
453 | { | 456 | { |
454 | size_t filename_len; | 457 | size_t filename_len; |
455 | int i; | 458 | int i; |
456 | 459 | ||
457 | filename_len = strlen(filename); | 460 | filename_len = strlen (filename); |
458 | for(i = 0; i < filename_len; i++) | 461 | for (i = 0; i < filename_len; i++) |
459 | { | 462 | { |
460 | if(DIR_SEPARATOR == filename[i]) | 463 | if (DIR_SEPARATOR == filename[i]) |
461 | return GNUNET_YES; | 464 | return GNUNET_YES; |
462 | } | 465 | } |
463 | return GNUNET_NO; | 466 | return GNUNET_NO; |
464 | } | 467 | } |
465 | 468 | ||
469 | |||
466 | /** | 470 | /** |
467 | * Actual execution of a sensor | 471 | * Actual execution of a sensor |
468 | * | 472 | * |
@@ -470,92 +474,91 @@ is_path(char *filename) | |||
470 | * @param tc unsed | 474 | * @param tc unsed |
471 | */ | 475 | */ |
472 | static void | 476 | static void |
473 | sensor_run (void *cls, | 477 | sensor_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
474 | const struct GNUNET_SCHEDULER_TaskContext * tc) | ||
475 | { | 478 | { |
476 | struct GNUNET_SENSOR_SensorInfo *sensorinfo = cls; | 479 | struct GNUNET_SENSOR_SensorInfo *sensorinfo = cls; |
477 | int check_result; | 480 | int check_result; |
478 | char *sensors_dir; | 481 | char *sensors_dir; |
479 | char *process_path; | 482 | char *process_path; |
480 | 483 | ||
481 | sensorinfo->execution_task = GNUNET_SCHEDULER_add_delayed(sensorinfo->interval, &sensor_run, sensorinfo); | 484 | sensorinfo->execution_task = |
482 | if(GNUNET_YES == sensorinfo->running) //FIXME: should we try to kill? | 485 | GNUNET_SCHEDULER_add_delayed (sensorinfo->interval, &sensor_run, |
486 | sensorinfo); | ||
487 | if (GNUNET_YES == sensorinfo->running) //FIXME: should we try to kill? | ||
483 | { | 488 | { |
484 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Sensor `%s' running for too long, will try again next interval\n", sensorinfo->name); | 489 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
490 | "Sensor `%s' running for too long, will try again next interval\n", | ||
491 | sensorinfo->name); | ||
485 | return; | 492 | return; |
486 | } | 493 | } |
487 | if(GNUNET_NO == should_run_sensor(sensorinfo)) | 494 | if (GNUNET_NO == should_run_sensor (sensorinfo)) |
488 | return; | 495 | return; |
489 | sensorinfo->running = GNUNET_YES; | 496 | sensorinfo->running = GNUNET_YES; |
490 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Starting the execution of sensor `%s'\n", sensorinfo->name); | 497 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
491 | if(0 == strcmp ("gnunet-statistics", sensorinfo->source)) | 498 | "Starting the execution of sensor `%s'\n", sensorinfo->name); |
499 | if (0 == strcmp ("gnunet-statistics", sensorinfo->source)) | ||
492 | { | 500 | { |
493 | sensorinfo->gnunet_stat_get_handle = GNUNET_STATISTICS_get(statistics, | 501 | sensorinfo->gnunet_stat_get_handle = GNUNET_STATISTICS_get (statistics, sensorinfo->gnunet_stat_service, sensorinfo->gnunet_stat_name, sensorinfo->interval, //try to get values only for the interval of the sensor |
494 | sensorinfo->gnunet_stat_service, | 502 | &end_sensor_run_stat, |
495 | sensorinfo->gnunet_stat_name, | 503 | &sensor_statistics_iterator, |
496 | sensorinfo->interval, //try to get values only for the interval of the sensor | 504 | sensorinfo); |
497 | &end_sensor_run_stat, | ||
498 | &sensor_statistics_iterator, | ||
499 | sensorinfo); | ||
500 | } | 505 | } |
501 | else if(0 == strcmp ("process", sensorinfo->source)) | 506 | else if (0 == strcmp ("process", sensorinfo->source)) |
502 | { | 507 | { |
503 | if(GNUNET_YES == is_path(sensorinfo->ext_process)) | 508 | if (GNUNET_YES == is_path (sensorinfo->ext_process)) |
504 | { | 509 | { |
505 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 510 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
506 | _("Sensor `%s': External process should not be a path, disabling sensor.\n"), | 511 | _ |
507 | sensorinfo->name); | 512 | ("Sensor `%s': External process should not be a path, disabling sensor.\n"), |
508 | set_sensor_enabled(sensorinfo, GNUNET_NO); | 513 | sensorinfo->name); |
514 | set_sensor_enabled (sensorinfo, GNUNET_NO); | ||
509 | return; | 515 | return; |
510 | } | 516 | } |
511 | //check if the process exists in $PATH | 517 | //check if the process exists in $PATH |
512 | process_path = GNUNET_strdup(sensorinfo->ext_process); | 518 | process_path = GNUNET_strdup (sensorinfo->ext_process); |
513 | check_result = | 519 | check_result = |
514 | GNUNET_OS_check_helper_binary(process_path, GNUNET_NO, NULL); | 520 | GNUNET_OS_check_helper_binary (process_path, GNUNET_NO, NULL); |
515 | if(GNUNET_SYSERR == check_result) | 521 | if (GNUNET_SYSERR == check_result) |
516 | { | 522 | { |
517 | //search in sensor directory | 523 | //search in sensor directory |
518 | sensors_dir = GNUNET_SENSOR_get_sensor_dir (); | 524 | sensors_dir = GNUNET_SENSOR_get_sensor_dir (); |
519 | GNUNET_free(process_path); | 525 | GNUNET_free (process_path); |
520 | GNUNET_asprintf(&process_path, | 526 | GNUNET_asprintf (&process_path, "%s%s-files%s%s", sensors_dir, |
521 | "%s%s-files%s%s", | 527 | sensorinfo->name, DIR_SEPARATOR_STR, |
522 | sensors_dir, | 528 | sensorinfo->ext_process); |
523 | sensorinfo->name, | 529 | GNUNET_free (sensors_dir); |
524 | DIR_SEPARATOR_STR, | ||
525 | sensorinfo->ext_process); | ||
526 | GNUNET_free(sensors_dir); | ||
527 | check_result = | 530 | check_result = |
528 | GNUNET_OS_check_helper_binary(process_path, GNUNET_NO, NULL); | 531 | GNUNET_OS_check_helper_binary (process_path, GNUNET_NO, NULL); |
529 | } | 532 | } |
530 | if(GNUNET_SYSERR == check_result) | 533 | if (GNUNET_SYSERR == check_result) |
531 | { | 534 | { |
532 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 535 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
533 | _("Sensor `%s' process `%s' problem: binary doesn't exist or not executable\n"), | 536 | _ |
534 | sensorinfo->name, | 537 | ("Sensor `%s' process `%s' problem: binary doesn't exist or not executable\n"), |
535 | sensorinfo->ext_process); | 538 | sensorinfo->name, sensorinfo->ext_process); |
536 | set_sensor_enabled(sensorinfo, GNUNET_NO); | 539 | set_sensor_enabled (sensorinfo, GNUNET_NO); |
537 | sensorinfo->running = GNUNET_NO; | 540 | sensorinfo->running = GNUNET_NO; |
538 | GNUNET_free(process_path); | 541 | GNUNET_free (process_path); |
539 | return; | 542 | return; |
540 | } | 543 | } |
541 | sensorinfo->ext_cmd_value_received = GNUNET_NO; | 544 | sensorinfo->ext_cmd_value_received = GNUNET_NO; |
542 | sensorinfo->ext_cmd = GNUNET_OS_command_run(&sensor_process_callback, | 545 | sensorinfo->ext_cmd = |
543 | sensorinfo, | 546 | GNUNET_OS_command_run (&sensor_process_callback, sensorinfo, |
544 | GNUNET_TIME_UNIT_FOREVER_REL, | 547 | GNUNET_TIME_UNIT_FOREVER_REL, process_path, |
545 | process_path, | 548 | sensorinfo->ext_process, sensorinfo->ext_args, |
546 | sensorinfo->ext_process, | 549 | NULL); |
547 | sensorinfo->ext_args, | 550 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Process started for sensor `%s'\n", |
548 | NULL); | 551 | sensorinfo->name); |
549 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Process started for sensor `%s'\n", sensorinfo->name); | 552 | GNUNET_free (process_path); |
550 | GNUNET_free(process_path); | ||
551 | } | 553 | } |
552 | else | 554 | else |
553 | { | 555 | { |
554 | sensorinfo->running = GNUNET_NO; | 556 | sensorinfo->running = GNUNET_NO; |
555 | GNUNET_break(0); //shouldn't happen | 557 | GNUNET_break (0); //shouldn't happen |
556 | } | 558 | } |
557 | } | 559 | } |
558 | 560 | ||
561 | |||
559 | /** | 562 | /** |
560 | * Starts the execution of a sensor | 563 | * Starts the execution of a sensor |
561 | * | 564 | * |
@@ -571,28 +574,34 @@ schedule_sensor (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
571 | { | 574 | { |
572 | struct GNUNET_SENSOR_SensorInfo *sensorinfo = value; | 575 | struct GNUNET_SENSOR_SensorInfo *sensorinfo = value; |
573 | 576 | ||
574 | if(GNUNET_NO == should_run_sensor(sensorinfo)) | 577 | if (GNUNET_NO == should_run_sensor (sensorinfo)) |
575 | return GNUNET_YES; | 578 | return GNUNET_YES; |
576 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Scheduling sensor `%s' to run after %" PRIu64 " microseconds\n", | 579 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
577 | sensorinfo->name, sensorinfo->interval.rel_value_us); | 580 | "Scheduling sensor `%s' to run after %" PRIu64 " microseconds\n", |
578 | if(GNUNET_SCHEDULER_NO_TASK != sensorinfo->execution_task) | 581 | sensorinfo->name, sensorinfo->interval.rel_value_us); |
582 | if (GNUNET_SCHEDULER_NO_TASK != sensorinfo->execution_task) | ||
579 | { | 583 | { |
580 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 584 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
581 | _("Sensor `%s' execution task already set, this should not happen\n"), sensorinfo->name); | 585 | _ |
586 | ("Sensor `%s' execution task already set, this should not happen\n"), | ||
587 | sensorinfo->name); | ||
582 | return GNUNET_NO; | 588 | return GNUNET_NO; |
583 | } | 589 | } |
584 | sensorinfo->execution_task = GNUNET_SCHEDULER_add_delayed(sensorinfo->interval, &sensor_run, sensorinfo); | 590 | sensorinfo->execution_task = |
591 | GNUNET_SCHEDULER_add_delayed (sensorinfo->interval, &sensor_run, | ||
592 | sensorinfo); | ||
585 | return GNUNET_YES; | 593 | return GNUNET_YES; |
586 | } | 594 | } |
587 | 595 | ||
596 | |||
588 | /** | 597 | /** |
589 | * Starts the execution of all enabled sensors | 598 | * Starts the execution of all enabled sensors |
590 | * | 599 | * |
591 | */ | 600 | */ |
592 | static void | 601 | static void |
593 | schedule_all_sensors() | 602 | schedule_all_sensors () |
594 | { | 603 | { |
595 | GNUNET_CONTAINER_multihashmap_iterate(sensors, &schedule_sensor, NULL); | 604 | GNUNET_CONTAINER_multihashmap_iterate (sensors, &schedule_sensor, NULL); |
596 | } | 605 | } |
597 | 606 | ||
598 | 607 | ||
@@ -603,9 +612,9 @@ static void | |||
603 | start () | 612 | start () |
604 | { | 613 | { |
605 | sensors = GNUNET_SENSOR_load_all_sensors (); | 614 | sensors = GNUNET_SENSOR_load_all_sensors (); |
606 | schedule_all_sensors(); | 615 | schedule_all_sensors (); |
607 | SENSOR_analysis_start(cfg, sensors); | 616 | SENSOR_analysis_start (cfg, sensors); |
608 | SENSOR_reporting_start(cfg, sensors); | 617 | SENSOR_reporting_start (cfg, sensors); |
609 | SENSOR_update_start (cfg, sensors, &reset); | 618 | SENSOR_update_start (cfg, sensors, &reset); |
610 | } | 619 | } |
611 | 620 | ||
@@ -618,8 +627,7 @@ start () | |||
618 | * @param c configuration to use | 627 | * @param c configuration to use |
619 | */ | 628 | */ |
620 | static void | 629 | static void |
621 | run (void *cls, | 630 | run (void *cls, struct GNUNET_SERVER_Handle *server, |
622 | struct GNUNET_SERVER_Handle *server, | ||
623 | const struct GNUNET_CONFIGURATION_Handle *c) | 631 | const struct GNUNET_CONFIGURATION_Handle *c) |
624 | { | 632 | { |
625 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { | 633 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { |
@@ -631,16 +639,13 @@ run (void *cls, | |||
631 | }; | 639 | }; |
632 | 640 | ||
633 | cfg = c; | 641 | cfg = c; |
634 | statistics = GNUNET_STATISTICS_create("sensor", cfg); | 642 | statistics = GNUNET_STATISTICS_create ("sensor", cfg); |
635 | GNUNET_CRYPTO_get_peer_identity(cfg, &peerid); | 643 | GNUNET_CRYPTO_get_peer_identity (cfg, &peerid); |
636 | peerstore = GNUNET_PEERSTORE_connect(cfg); | 644 | peerstore = GNUNET_PEERSTORE_connect (cfg); |
637 | GNUNET_SERVER_add_handlers (server, handlers); | 645 | GNUNET_SERVER_add_handlers (server, handlers); |
638 | GNUNET_SERVER_disconnect_notify (server, | 646 | GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL); |
639 | &handle_client_disconnect, | 647 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, |
640 | NULL); | 648 | NULL); |
641 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | ||
642 | &shutdown_task, | ||
643 | NULL); | ||
644 | start (); | 649 | start (); |
645 | } | 650 | } |
646 | 651 | ||
@@ -668,11 +673,8 @@ int | |||
668 | main (int argc, char *const *argv) | 673 | main (int argc, char *const *argv) |
669 | { | 674 | { |
670 | return (GNUNET_OK == | 675 | return (GNUNET_OK == |
671 | GNUNET_SERVICE_run (argc, | 676 | GNUNET_SERVICE_run (argc, argv, "sensor", GNUNET_SERVICE_OPTION_NONE, |
672 | argv, | 677 | &run, NULL)) ? 0 : 1; |
673 | "sensor", | ||
674 | GNUNET_SERVICE_OPTION_NONE, | ||
675 | &run, NULL)) ? 0 : 1; | ||
676 | } | 678 | } |
677 | 679 | ||
678 | /* end of gnunet-service-sensor.c */ | 680 | /* end of gnunet-service-sensor.c */ |
diff --git a/src/sensor/gnunet_sensor_model_plugin.h b/src/sensor/gnunet_sensor_model_plugin.h index ddb39a928..15631487c 100644 --- a/src/sensor/gnunet_sensor_model_plugin.h +++ b/src/sensor/gnunet_sensor_model_plugin.h | |||
@@ -54,16 +54,14 @@ struct GNUNET_SENSOR_ModelFunctions | |||
54 | * @param cls closure (plugin state) | 54 | * @param cls closure (plugin state) |
55 | * @return model state to be used for later calls | 55 | * @return model state to be used for later calls |
56 | */ | 56 | */ |
57 | void * | 57 | void *(*create_model) (void *cls); |
58 | (*create_model) (void *cls); | ||
59 | 58 | ||
60 | /* | 59 | /* |
61 | * Destroy a model instance | 60 | * Destroy a model instance |
62 | * | 61 | * |
63 | * @param cls closure (model state) | 62 | * @param cls closure (model state) |
64 | */ | 63 | */ |
65 | void | 64 | void (*destroy_model) (void *cls); |
66 | (*destroy_model) (void *cls); | ||
67 | 65 | ||
68 | /* | 66 | /* |
69 | * Feed a new value to a model | 67 | * Feed a new value to a model |
@@ -72,8 +70,7 @@ struct GNUNET_SENSOR_ModelFunctions | |||
72 | * @param val value to be fed to the model | 70 | * @param val value to be fed to the model |
73 | * @return #GNUNET_YES in case of a detected outlier, #GNUNET_NO otherwise | 71 | * @return #GNUNET_YES in case of a detected outlier, #GNUNET_NO otherwise |
74 | */ | 72 | */ |
75 | int | 73 | int (*feed_model) (void *cls, double val); |
76 | (*feed_model) (void *cls, double val); | ||
77 | 74 | ||
78 | }; | 75 | }; |
79 | 76 | ||
diff --git a/src/sensor/plugin_sensor_model_gaussian.c b/src/sensor/plugin_sensor_model_gaussian.c index 052b1a94a..95d74f073 100644 --- a/src/sensor/plugin_sensor_model_gaussian.c +++ b/src/sensor/plugin_sensor_model_gaussian.c | |||
@@ -82,15 +82,22 @@ struct Model | |||
82 | 82 | ||
83 | }; | 83 | }; |
84 | 84 | ||
85 | /** | ||
86 | * Update local sums of model with a new value. | ||
87 | * | ||
88 | * @param model Targe model | ||
89 | * @param val New value | ||
90 | */ | ||
85 | static void | 91 | static void |
86 | update_sums (struct Model *model, double val) | 92 | update_sums (struct Model *model, double val) |
87 | { | 93 | { |
88 | model->sum += val; | 94 | model->sum += val; |
89 | model->sumsq += val * val; | 95 | model->sumsq += val * val; |
90 | model->n ++; | 96 | model->n++; |
91 | } | 97 | } |
92 | 98 | ||
93 | /* | 99 | |
100 | /** | ||
94 | * Feed a new value to a model | 101 | * Feed a new value to a model |
95 | * | 102 | * |
96 | * @param cls closure (model state) | 103 | * @param cls closure (model state) |
@@ -108,23 +115,21 @@ sensor_gaussian_model_feed (void *cls, double val) | |||
108 | 115 | ||
109 | if (model->n < plugin->training_window) | 116 | if (model->n < plugin->training_window) |
110 | { | 117 | { |
111 | update_sums(model, val); | 118 | update_sums (model, val); |
112 | return GNUNET_NO; | 119 | return GNUNET_NO; |
113 | } | 120 | } |
114 | mean = model->sum / model->n; | 121 | mean = model->sum / model->n; |
115 | stddev = sqrt( | 122 | stddev = |
116 | (model->sumsq - 2 * mean * model->sum + model->n * mean * mean) | 123 | sqrt ((model->sumsq - 2 * mean * model->sum + |
117 | / | 124 | model->n * mean * mean) / (model->n - 1)); |
118 | (model->n - 1) | ||
119 | ); | ||
120 | allowed_variance = (plugin->confidence_interval * stddev); | 125 | allowed_variance = (plugin->confidence_interval * stddev); |
121 | if ((val < (mean - allowed_variance)) || | 126 | if ((val < (mean - allowed_variance)) || (val > (mean + allowed_variance))) |
122 | (val > (mean + allowed_variance))) | ||
123 | return GNUNET_YES; | 127 | return GNUNET_YES; |
124 | return GNUNET_NO; | 128 | return GNUNET_NO; |
125 | } | 129 | } |
126 | 130 | ||
127 | /* | 131 | |
132 | /** | ||
128 | * Destroy a model instance | 133 | * Destroy a model instance |
129 | * | 134 | * |
130 | * @param cls closure (model state) | 135 | * @param cls closure (model state) |
@@ -134,10 +139,11 @@ sensor_gaussian_model_destroy_model (void *cls) | |||
134 | { | 139 | { |
135 | struct Model *model = cls; | 140 | struct Model *model = cls; |
136 | 141 | ||
137 | GNUNET_free(model); | 142 | GNUNET_free (model); |
138 | } | 143 | } |
139 | 144 | ||
140 | /* | 145 | |
146 | /** | ||
141 | * Create a model instance | 147 | * Create a model instance |
142 | * | 148 | * |
143 | * @param cls closure (plugin state) | 149 | * @param cls closure (plugin state) |
@@ -149,12 +155,14 @@ sensor_gaussian_model_create_model (void *cls) | |||
149 | struct Plugin *plugin = cls; | 155 | struct Plugin *plugin = cls; |
150 | struct Model *model; | 156 | struct Model *model; |
151 | 157 | ||
152 | model = GNUNET_new(struct Model); | 158 | model = GNUNET_new (struct Model); |
159 | |||
153 | model->plugin = plugin; | 160 | model->plugin = plugin; |
154 | return model; | 161 | return model; |
155 | } | 162 | } |
156 | 163 | ||
157 | /* | 164 | |
165 | /** | ||
158 | * Entry point for the plugin. | 166 | * Entry point for the plugin. |
159 | * | 167 | * |
160 | * @param cls The struct GNUNET_CONFIGURATION_Handle. | 168 | * @param cls The struct GNUNET_CONFIGURATION_Handle. |
@@ -172,32 +180,36 @@ libgnunet_plugin_sensor_model_gaussian_init (void *cls) | |||
172 | return NULL; /* can only initialize once! */ | 180 | return NULL; /* can only initialize once! */ |
173 | memset (&plugin, 0, sizeof (struct Plugin)); | 181 | memset (&plugin, 0, sizeof (struct Plugin)); |
174 | plugin.cfg = cfg; | 182 | plugin.cfg = cfg; |
175 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(cfg, | 183 | if (GNUNET_OK != |
176 | "sensor-model-gaussian", "TRAINING_WINDOW", &num)) | 184 | GNUNET_CONFIGURATION_get_value_number (cfg, "sensor-model-gaussian", |
185 | "TRAINING_WINDOW", &num)) | ||
177 | { | 186 | { |
178 | LOG (GNUNET_ERROR_TYPE_ERROR, | 187 | LOG (GNUNET_ERROR_TYPE_ERROR, |
179 | _("Missing `TRAINING_WINDOW' value in configuration.\n")); | 188 | _("Missing `TRAINING_WINDOW' value in configuration.\n")); |
180 | return NULL; | 189 | return NULL; |
181 | } | 190 | } |
182 | plugin.training_window = (int) num; | 191 | plugin.training_window = (int) num; |
183 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(cfg, | 192 | if (GNUNET_OK != |
184 | "sensor-model-gaussian", "CONFIDENCE_INTERVAL", &num)) | 193 | GNUNET_CONFIGURATION_get_value_number (cfg, "sensor-model-gaussian", |
194 | "CONFIDENCE_INTERVAL", &num)) | ||
185 | { | 195 | { |
186 | LOG (GNUNET_ERROR_TYPE_ERROR, | 196 | LOG (GNUNET_ERROR_TYPE_ERROR, |
187 | _("Missing `CONFIDENCE_INTERVAL' value in configuration.\n")); | 197 | _("Missing `CONFIDENCE_INTERVAL' value in configuration.\n")); |
188 | return NULL; | 198 | return NULL; |
189 | } | 199 | } |
190 | plugin.confidence_interval = (int) num; | 200 | plugin.confidence_interval = (int) num; |
191 | api = GNUNET_new (struct GNUNET_SENSOR_ModelFunctions); | 201 | api = GNUNET_new (struct GNUNET_SENSOR_ModelFunctions); |
202 | |||
192 | api->cls = &plugin; | 203 | api->cls = &plugin; |
193 | api->create_model = &sensor_gaussian_model_create_model; | 204 | api->create_model = &sensor_gaussian_model_create_model; |
194 | api->destroy_model = &sensor_gaussian_model_destroy_model; | 205 | api->destroy_model = &sensor_gaussian_model_destroy_model; |
195 | api->feed_model = &sensor_gaussian_model_feed; | 206 | api->feed_model = &sensor_gaussian_model_feed; |
196 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Gaussian model plugin is running.\n"); | 207 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Gaussian model plugin is running.\n"); |
197 | return api; | 208 | return api; |
198 | } | 209 | } |
199 | 210 | ||
200 | /* | 211 | |
212 | /** | ||
201 | * Exit point from the plugin. | 213 | * Exit point from the plugin. |
202 | * | 214 | * |
203 | * @param cls The plugin context (as returned by "init") | 215 | * @param cls The plugin context (as returned by "init") |
diff --git a/src/sensor/sensor.h b/src/sensor/sensor.h index cf36c7d86..633f18e03 100644 --- a/src/sensor/sensor.h +++ b/src/sensor/sensor.h | |||
@@ -28,12 +28,11 @@ | |||
28 | 28 | ||
29 | 29 | ||
30 | GNUNET_NETWORK_STRUCT_BEGIN | 30 | GNUNET_NETWORK_STRUCT_BEGIN |
31 | |||
32 | /** | 31 | /** |
33 | * Carries a summary of a sensor | 32 | * Carries a summary of a sensor |
34 | * | 33 | * |
35 | */ | 34 | */ |
36 | struct SensorInfoMessage | 35 | struct SensorInfoMessage |
37 | { | 36 | { |
38 | /** | 37 | /** |
39 | * Message header | 38 | * Message header |
@@ -63,26 +62,31 @@ struct SensorInfoMessage | |||
63 | 62 | ||
64 | GNUNET_NETWORK_STRUCT_END | 63 | GNUNET_NETWORK_STRUCT_END |
65 | 64 | ||
66 | /* | 65 | /** |
67 | * Stop the sensor analysis module | 66 | * Stop the sensor analysis module |
68 | */ | 67 | */ |
69 | void SENSOR_analysis_stop(); | 68 | void |
69 | SENSOR_analysis_stop (); | ||
70 | 70 | ||
71 | /* | 71 | |
72 | /** | ||
72 | * Start the sensor analysis module | 73 | * Start the sensor analysis module |
73 | * | 74 | * |
74 | * @param c our service configuration | 75 | * @param c our service configuration |
75 | * @param sensors_mhm multihashmap of loaded sensors | 76 | * @param sensors multihashmap of loaded sensors |
76 | * @return #GNUNET_OK if started successfully, #GNUNET_SYSERR otherwise | 77 | * @return #GNUNET_OK if started successfully, #GNUNET_SYSERR otherwise |
77 | */ | 78 | */ |
78 | int | 79 | int |
79 | SENSOR_analysis_start(const struct GNUNET_CONFIGURATION_Handle *c, | 80 | SENSOR_analysis_start (const struct GNUNET_CONFIGURATION_Handle *c, |
80 | struct GNUNET_CONTAINER_MultiHashMap *sensors_mhm); | 81 | struct GNUNET_CONTAINER_MultiHashMap *sensors); |
82 | |||
81 | 83 | ||
82 | /** | 84 | /** |
83 | * Stop sensor reporting module | 85 | * Stop sensor reporting module |
84 | */ | 86 | */ |
85 | void SENSOR_reporting_stop(); | 87 | void |
88 | SENSOR_reporting_stop (); | ||
89 | |||
86 | 90 | ||
87 | /** | 91 | /** |
88 | * Start the sensor reporting module | 92 | * Start the sensor reporting module |
@@ -92,8 +96,9 @@ void SENSOR_reporting_stop(); | |||
92 | * @return #GNUNET_OK if started successfully, #GNUNET_SYSERR otherwise | 96 | * @return #GNUNET_OK if started successfully, #GNUNET_SYSERR otherwise |
93 | */ | 97 | */ |
94 | int | 98 | int |
95 | SENSOR_reporting_start(const struct GNUNET_CONFIGURATION_Handle *c, | 99 | SENSOR_reporting_start (const struct GNUNET_CONFIGURATION_Handle *c, |
96 | struct GNUNET_CONTAINER_MultiHashMap *sensors); | 100 | struct GNUNET_CONTAINER_MultiHashMap *sensors); |
101 | |||
97 | 102 | ||
98 | /** | 103 | /** |
99 | * Stop the sensor update module | 104 | * Stop the sensor update module |
@@ -101,16 +106,16 @@ SENSOR_reporting_start(const struct GNUNET_CONFIGURATION_Handle *c, | |||
101 | void | 106 | void |
102 | SENSOR_update_stop (); | 107 | SENSOR_update_stop (); |
103 | 108 | ||
109 | |||
104 | /** | 110 | /** |
105 | * Start the sensor update module | 111 | * Start the sensor update module |
106 | * | 112 | * |
107 | * @param c our service configuration | 113 | * @param c our service configuration |
108 | * @param sensors multihashmap of loaded sensors | 114 | * @param s multihashmap of loaded sensors |
109 | * @param reset_cb callback to reset service components when we have new updates | 115 | * @param cb callback to reset service components when we have new updates |
110 | * @return #GNUNET_OK if started successfully, #GNUNET_SYSERR otherwise | 116 | * @return #GNUNET_OK if started successfully, #GNUNET_SYSERR otherwise |
111 | */ | 117 | */ |
112 | int | 118 | int |
113 | SENSOR_update_start (const struct GNUNET_CONFIGURATION_Handle *c, | 119 | SENSOR_update_start (const struct GNUNET_CONFIGURATION_Handle *c, |
114 | struct GNUNET_CONTAINER_MultiHashMap *s, | 120 | struct GNUNET_CONTAINER_MultiHashMap *s, |
115 | void (*reset_cb)()); | 121 | void (*cb) ()); |
116 | |||
diff --git a/src/sensor/sensor_api.c b/src/sensor/sensor_api.c index bb248315b..a143df087 100644 --- a/src/sensor/sensor_api.c +++ b/src/sensor/sensor_api.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) | 3 | (C) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published |
@@ -42,7 +42,7 @@ struct GNUNET_SENSOR_Handle | |||
42 | /** | 42 | /** |
43 | * Our configuration. | 43 | * Our configuration. |
44 | */ | 44 | */ |
45 | const struct GNUNET_CONFIGURATION_Handle *cfg; | 45 | const struct GNUNET_CONFIGURATION_Handle *cfg; |
46 | 46 | ||
47 | /** | 47 | /** |
48 | * Connection to the service. | 48 | * Connection to the service. |
@@ -190,6 +190,7 @@ struct GNUNET_SENSOR_SensorIteratorContext | |||
190 | static void | 190 | static void |
191 | reconnect (struct GNUNET_SENSOR_Handle *h); | 191 | reconnect (struct GNUNET_SENSOR_Handle *h); |
192 | 192 | ||
193 | |||
193 | /** | 194 | /** |
194 | * Check if we have a request pending in the transmission queue and are | 195 | * Check if we have a request pending in the transmission queue and are |
195 | * able to transmit it right now. If so, schedule transmission. | 196 | * able to transmit it right now. If so, schedule transmission. |
@@ -215,7 +216,7 @@ GNUNET_SENSOR_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
215 | struct GNUNET_SENSOR_Handle *h; | 216 | struct GNUNET_SENSOR_Handle *h; |
216 | 217 | ||
217 | client = GNUNET_CLIENT_connect ("sensor", cfg); | 218 | client = GNUNET_CLIENT_connect ("sensor", cfg); |
218 | if(NULL == client) | 219 | if (NULL == client) |
219 | return NULL; | 220 | return NULL; |
220 | h = GNUNET_new (struct GNUNET_SENSOR_Handle); | 221 | h = GNUNET_new (struct GNUNET_SENSOR_Handle); |
221 | h->client = client; | 222 | h->client = client; |
@@ -223,13 +224,14 @@ GNUNET_SENSOR_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
223 | return h; | 224 | return h; |
224 | } | 225 | } |
225 | 226 | ||
227 | |||
226 | /** | 228 | /** |
227 | * Disconnect from the sensor service | 229 | * Disconnect from the sensor service |
228 | * | 230 | * |
229 | * @param h handle to disconnect | 231 | * @param h handle to disconnect |
230 | */ | 232 | */ |
231 | void | 233 | void |
232 | GNUNET_SENSOR_disconnect(struct GNUNET_SENSOR_Handle *h) | 234 | GNUNET_SENSOR_disconnect (struct GNUNET_SENSOR_Handle *h) |
233 | { | 235 | { |
234 | if (NULL != h->client) | 236 | if (NULL != h->client) |
235 | { | 237 | { |
@@ -239,6 +241,7 @@ GNUNET_SENSOR_disconnect(struct GNUNET_SENSOR_Handle *h) | |||
239 | GNUNET_free (h); | 241 | GNUNET_free (h); |
240 | } | 242 | } |
241 | 243 | ||
244 | |||
242 | /** | 245 | /** |
243 | * Task scheduled to re-try connecting to the sensor service. | 246 | * Task scheduled to re-try connecting to the sensor service. |
244 | * | 247 | * |
@@ -254,6 +257,7 @@ reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
254 | reconnect (h); | 257 | reconnect (h); |
255 | } | 258 | } |
256 | 259 | ||
260 | |||
257 | /** | 261 | /** |
258 | * Close the existing connection to SENSOR and reconnect. | 262 | * Close the existing connection to SENSOR and reconnect. |
259 | * | 263 | * |
@@ -299,7 +303,8 @@ reconnect (struct GNUNET_SENSOR_Handle *h) | |||
299 | * @param ic context of the iterator to cancel | 303 | * @param ic context of the iterator to cancel |
300 | */ | 304 | */ |
301 | void | 305 | void |
302 | GNUNET_SENSOR_iterate_sensor_cancel (struct GNUNET_SENSOR_SensorIteratorContext *ic) | 306 | GNUNET_SENSOR_iterate_sensor_cancel (struct GNUNET_SENSOR_SensorIteratorContext |
307 | *ic) | ||
303 | { | 308 | { |
304 | struct GNUNET_SENSOR_Handle *h; | 309 | struct GNUNET_SENSOR_Handle *h; |
305 | 310 | ||
@@ -312,9 +317,7 @@ GNUNET_SENSOR_iterate_sensor_cancel (struct GNUNET_SENSOR_SensorIteratorContext | |||
312 | ic->callback = NULL; | 317 | ic->callback = NULL; |
313 | if (GNUNET_YES == ic->request_transmitted) | 318 | if (GNUNET_YES == ic->request_transmitted) |
314 | return; /* need to finish processing */ | 319 | return; /* need to finish processing */ |
315 | GNUNET_CONTAINER_DLL_remove (h->ic_head, | 320 | GNUNET_CONTAINER_DLL_remove (h->ic_head, h->ic_tail, ic); |
316 | h->ic_tail, | ||
317 | ic); | ||
318 | if (NULL != ic->rc) | 321 | if (NULL != ic->rc) |
319 | { | 322 | { |
320 | GNUNET_CONTAINER_DLL_remove (h->rc_head, h->rc_tail, ic->rc); | 323 | GNUNET_CONTAINER_DLL_remove (h->rc_head, h->rc_tail, ic->rc); |
@@ -323,6 +326,7 @@ GNUNET_SENSOR_iterate_sensor_cancel (struct GNUNET_SENSOR_SensorIteratorContext | |||
323 | GNUNET_free (ic); | 326 | GNUNET_free (ic); |
324 | } | 327 | } |
325 | 328 | ||
329 | |||
326 | /** | 330 | /** |
327 | * Iteration request has timed out. | 331 | * Iteration request has timed out. |
328 | * | 332 | * |
@@ -330,7 +334,8 @@ GNUNET_SENSOR_iterate_sensor_cancel (struct GNUNET_SENSOR_SensorIteratorContext | |||
330 | * @param tc scheduler context | 334 | * @param tc scheduler context |
331 | */ | 335 | */ |
332 | static void | 336 | static void |
333 | signal_sensor_iteration_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 337 | signal_sensor_iteration_timeout (void *cls, |
338 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
334 | { | 339 | { |
335 | struct GNUNET_SENSOR_SensorIteratorContext *ic = cls; | 340 | struct GNUNET_SENSOR_SensorIteratorContext *ic = cls; |
336 | GNUNET_SENSOR_SensorIteratorCB cb; | 341 | GNUNET_SENSOR_SensorIteratorCB cb; |
@@ -342,9 +347,10 @@ signal_sensor_iteration_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskCo | |||
342 | GNUNET_SENSOR_iterate_sensor_cancel (ic); | 347 | GNUNET_SENSOR_iterate_sensor_cancel (ic); |
343 | if (NULL != cb) | 348 | if (NULL != cb) |
344 | cb (cb_cls, NULL, | 349 | cb (cb_cls, NULL, |
345 | _("Timeout transmitting iteration request to `SENSOR' service.")); | 350 | _("Timeout transmitting iteration request to `SENSOR' service.")); |
346 | } | 351 | } |
347 | 352 | ||
353 | |||
348 | /** | 354 | /** |
349 | * Type of a function to call when we receive a message from the | 355 | * Type of a function to call when we receive a message from the |
350 | * service. Call the iterator with the result and (if applicable) | 356 | * service. Call the iterator with the result and (if applicable) |
@@ -355,7 +361,7 @@ signal_sensor_iteration_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskCo | |||
355 | * @param msg message received, NULL on timeout or fatal error | 361 | * @param msg message received, NULL on timeout or fatal error |
356 | */ | 362 | */ |
357 | static void | 363 | static void |
358 | sensor_handler(void *cls, const struct GNUNET_MessageHeader *msg) | 364 | sensor_handler (void *cls, const struct GNUNET_MessageHeader *msg) |
359 | { | 365 | { |
360 | struct GNUNET_SENSOR_Handle *h = cls; | 366 | struct GNUNET_SENSOR_Handle *h = cls; |
361 | struct GNUNET_SENSOR_SensorIteratorContext *ic = h->ic_head; | 367 | struct GNUNET_SENSOR_SensorIteratorContext *ic = h->ic_head; |
@@ -376,7 +382,7 @@ sensor_handler(void *cls, const struct GNUNET_MessageHeader *msg) | |||
376 | { | 382 | { |
377 | cb = ic->callback; | 383 | cb = ic->callback; |
378 | cb_cls = ic->callback_cls; | 384 | cb_cls = ic->callback_cls; |
379 | GNUNET_SENSOR_iterate_sensor_cancel(ic); | 385 | GNUNET_SENSOR_iterate_sensor_cancel (ic); |
380 | } | 386 | } |
381 | else | 387 | else |
382 | { | 388 | { |
@@ -384,8 +390,7 @@ sensor_handler(void *cls, const struct GNUNET_MessageHeader *msg) | |||
384 | } | 390 | } |
385 | reconnect (h); | 391 | reconnect (h); |
386 | if (NULL != cb) | 392 | if (NULL != cb) |
387 | cb (cb_cls, NULL, | 393 | cb (cb_cls, NULL, _("Failed to receive response from `SENSOR' service.")); |
388 | _("Failed to receive response from `SENSOR' service.")); | ||
389 | return; | 394 | return; |
390 | } | 395 | } |
391 | if (NULL == ic) | 396 | if (NULL == ic) |
@@ -402,14 +407,14 @@ sensor_handler(void *cls, const struct GNUNET_MessageHeader *msg) | |||
402 | /* normal end of list of sensors, signal end, process next pending request */ | 407 | /* normal end of list of sensors, signal end, process next pending request */ |
403 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 408 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
404 | "Received end of list of sensors from `%s' service\n", "SENSOR"); | 409 | "Received end of list of sensors from `%s' service\n", "SENSOR"); |
405 | GNUNET_SENSOR_iterate_sensor_cancel(ic); | 410 | GNUNET_SENSOR_iterate_sensor_cancel (ic); |
406 | trigger_transmit (h); | 411 | trigger_transmit (h); |
407 | if ( (GNUNET_NO == h->in_receive) && | 412 | if ((GNUNET_NO == h->in_receive) && (NULL != h->ic_head)) |
408 | (NULL != h->ic_head) ) | ||
409 | { | 413 | { |
410 | h->in_receive = GNUNET_YES; | 414 | h->in_receive = GNUNET_YES; |
411 | GNUNET_CLIENT_receive (h->client, &sensor_handler, h, | 415 | GNUNET_CLIENT_receive (h->client, &sensor_handler, h, |
412 | GNUNET_TIME_absolute_get_remaining (h->ic_head->timeout)); | 416 | GNUNET_TIME_absolute_get_remaining (h-> |
417 | ic_head->timeout)); | ||
413 | } | 418 | } |
414 | if (NULL != cb) | 419 | if (NULL != cb) |
415 | cb (cb_cls, NULL, NULL); | 420 | cb (cb_cls, NULL, NULL); |
@@ -417,34 +422,33 @@ sensor_handler(void *cls, const struct GNUNET_MessageHeader *msg) | |||
417 | } | 422 | } |
418 | ms = ntohs (msg->size); | 423 | ms = ntohs (msg->size); |
419 | im = (const struct SensorInfoMessage *) msg; | 424 | im = (const struct SensorInfoMessage *) msg; |
420 | name_len = ntohs(im->name_len); | 425 | name_len = ntohs (im->name_len); |
421 | desc_len = ntohs(im->description_len); | 426 | desc_len = ntohs (im->description_len); |
422 | if ((ms != sizeof (struct SensorInfoMessage) + name_len + desc_len) || | 427 | if ((ms != sizeof (struct SensorInfoMessage) + name_len + desc_len) || |
423 | (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_SENSOR_INFO)) | 428 | (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_SENSOR_INFO)) |
424 | { | 429 | { |
425 | /* malformed message */ | 430 | /* malformed message */ |
426 | GNUNET_break (0); | 431 | GNUNET_break (0); |
427 | GNUNET_SENSOR_iterate_sensor_cancel(ic); | 432 | GNUNET_SENSOR_iterate_sensor_cancel (ic); |
428 | reconnect (h); | 433 | reconnect (h); |
429 | if (NULL != cb) | 434 | if (NULL != cb) |
430 | cb (cb_cls, NULL, | 435 | cb (cb_cls, NULL, _("Received invalid message from `SENSOR' service.")); |
431 | _("Received invalid message from `SENSOR' service.")); | ||
432 | return; | 436 | return; |
433 | } | 437 | } |
434 | sensor = GNUNET_new(struct SensorInfoShort); | 438 | sensor = GNUNET_new (struct SensorInfoShort); |
435 | str_ptr = (char *)&im[1]; | 439 | str_ptr = (char *) &im[1]; |
436 | sensor->name = GNUNET_strndup(str_ptr, name_len); | 440 | sensor->name = GNUNET_strndup (str_ptr, name_len); |
437 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Received sensor name (%d): %.*s\n", | 441 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Received sensor name (%d): %.*s\n", name_len, |
438 | name_len, name_len, str_ptr); | 442 | name_len, str_ptr); |
439 | str_ptr += name_len; | 443 | str_ptr += name_len; |
440 | if(desc_len > 0) | 444 | if (desc_len > 0) |
441 | { | 445 | { |
442 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Received sensor description (%d): %.*s\n", | 446 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Received sensor description (%d): %.*s\n", |
443 | desc_len, desc_len, str_ptr); | 447 | desc_len, desc_len, str_ptr); |
444 | sensor->description = GNUNET_strndup(str_ptr, desc_len); | 448 | sensor->description = GNUNET_strndup (str_ptr, desc_len); |
445 | } | 449 | } |
446 | sensor->version_major = ntohs(im->version_major); | 450 | sensor->version_major = ntohs (im->version_major); |
447 | sensor->version_minor = ntohs(im->version_minor); | 451 | sensor->version_minor = ntohs (im->version_minor); |
448 | h->in_receive = GNUNET_YES; | 452 | h->in_receive = GNUNET_YES; |
449 | GNUNET_CLIENT_receive (h->client, &sensor_handler, h, | 453 | GNUNET_CLIENT_receive (h->client, &sensor_handler, h, |
450 | GNUNET_TIME_absolute_get_remaining (ic->timeout)); | 454 | GNUNET_TIME_absolute_get_remaining (ic->timeout)); |
@@ -452,6 +456,7 @@ sensor_handler(void *cls, const struct GNUNET_MessageHeader *msg) | |||
452 | cb (cb_cls, sensor, NULL); | 456 | cb (cb_cls, sensor, NULL); |
453 | } | 457 | } |
454 | 458 | ||
459 | |||
455 | /** | 460 | /** |
456 | * We've transmitted the iteration request. Now get ready to process | 461 | * We've transmitted the iteration request. Now get ready to process |
457 | * the results (or handle transmission error). | 462 | * the results (or handle transmission error). |
@@ -485,10 +490,11 @@ sensor_iterator_start_receive (void *cls, const char *emsg) | |||
485 | { | 490 | { |
486 | h->in_receive = GNUNET_YES; | 491 | h->in_receive = GNUNET_YES; |
487 | GNUNET_CLIENT_receive (h->client, &sensor_handler, h, | 492 | GNUNET_CLIENT_receive (h->client, &sensor_handler, h, |
488 | GNUNET_TIME_absolute_get_remaining (ic->timeout)); | 493 | GNUNET_TIME_absolute_get_remaining (ic->timeout)); |
489 | } | 494 | } |
490 | } | 495 | } |
491 | 496 | ||
497 | |||
492 | /** | 498 | /** |
493 | * Transmit the request at the head of the transmission queue | 499 | * Transmit the request at the head of the transmission queue |
494 | * and trigger continuation (if any). | 500 | * and trigger continuation (if any). |
@@ -507,7 +513,7 @@ do_transmit (void *cls, size_t size, void *buf) | |||
507 | 513 | ||
508 | h->th = NULL; | 514 | h->th = NULL; |
509 | if (NULL == rc) | 515 | if (NULL == rc) |
510 | return 0; /* request was cancelled in the meantime */ | 516 | return 0; /* request was cancelled in the meantime */ |
511 | if (NULL == buf) | 517 | if (NULL == buf) |
512 | { | 518 | { |
513 | /* sensor service died */ | 519 | /* sensor service died */ |
@@ -538,6 +544,7 @@ do_transmit (void *cls, size_t size, void *buf) | |||
538 | return ret; | 544 | return ret; |
539 | } | 545 | } |
540 | 546 | ||
547 | |||
541 | /** | 548 | /** |
542 | * Check if we have a request pending in the transmission queue and are | 549 | * Check if we have a request pending in the transmission queue and are |
543 | * able to transmit it right now. If so, schedule transmission. | 550 | * able to transmit it right now. If so, schedule transmission. |
@@ -550,9 +557,9 @@ trigger_transmit (struct GNUNET_SENSOR_Handle *h) | |||
550 | struct GNUNET_SENSOR_RequestContext *rc; | 557 | struct GNUNET_SENSOR_RequestContext *rc; |
551 | 558 | ||
552 | if (NULL == (rc = h->rc_head)) | 559 | if (NULL == (rc = h->rc_head)) |
553 | return; /* no requests queued */ | 560 | return; /* no requests queued */ |
554 | if (NULL != h->th) | 561 | if (NULL != h->th) |
555 | return; /* request already pending */ | 562 | return; /* request already pending */ |
556 | if (NULL == h->client) | 563 | if (NULL == h->client) |
557 | { | 564 | { |
558 | /* disconnected, try to reconnect */ | 565 | /* disconnected, try to reconnect */ |
@@ -560,12 +567,12 @@ trigger_transmit (struct GNUNET_SENSOR_Handle *h) | |||
560 | return; | 567 | return; |
561 | } | 568 | } |
562 | h->th = | 569 | h->th = |
563 | GNUNET_CLIENT_notify_transmit_ready (h->client, rc->size, | 570 | GNUNET_CLIENT_notify_transmit_ready (h->client, rc->size, |
564 | GNUNET_TIME_UNIT_FOREVER_REL, | 571 | GNUNET_TIME_UNIT_FOREVER_REL, |
565 | GNUNET_YES, | 572 | GNUNET_YES, &do_transmit, h); |
566 | &do_transmit, h); | ||
567 | } | 573 | } |
568 | 574 | ||
575 | |||
569 | /** | 576 | /** |
570 | * Client asking to iterate all available sensors | 577 | * Client asking to iterate all available sensors |
571 | * | 578 | * |
@@ -579,41 +586,40 @@ trigger_transmit (struct GNUNET_SENSOR_Handle *h) | |||
579 | */ | 586 | */ |
580 | struct GNUNET_SENSOR_SensorIteratorContext * | 587 | struct GNUNET_SENSOR_SensorIteratorContext * |
581 | GNUNET_SENSOR_iterate_sensors (struct GNUNET_SENSOR_Handle *h, | 588 | GNUNET_SENSOR_iterate_sensors (struct GNUNET_SENSOR_Handle *h, |
582 | struct GNUNET_TIME_Relative timeout, | 589 | struct GNUNET_TIME_Relative timeout, |
583 | const char* sensorname, size_t sensorname_len, | 590 | const char *sensorname, size_t sensorname_len, |
584 | GNUNET_SENSOR_SensorIteratorCB callback, void *callback_cls) | 591 | GNUNET_SENSOR_SensorIteratorCB callback, |
592 | void *callback_cls) | ||
585 | { | 593 | { |
586 | struct GNUNET_SENSOR_SensorIteratorContext *ic; | 594 | struct GNUNET_SENSOR_SensorIteratorContext *ic; |
587 | struct GNUNET_SENSOR_RequestContext *rc; | 595 | struct GNUNET_SENSOR_RequestContext *rc; |
588 | struct GNUNET_MessageHeader *mh; | 596 | struct GNUNET_MessageHeader *mh; |
589 | 597 | ||
590 | ic = GNUNET_new (struct GNUNET_SENSOR_SensorIteratorContext); | 598 | ic = GNUNET_new (struct GNUNET_SENSOR_SensorIteratorContext); |
599 | |||
591 | if (NULL == sensorname) | 600 | if (NULL == sensorname) |
592 | { | 601 | { |
593 | LOG (GNUNET_ERROR_TYPE_INFO, | 602 | LOG (GNUNET_ERROR_TYPE_INFO, |
594 | "Requesting list of sensors from SENSOR service\n"); | 603 | "Requesting list of sensors from SENSOR service\n"); |
595 | rc = | 604 | rc = GNUNET_malloc (sizeof (struct GNUNET_SENSOR_RequestContext) + |
596 | GNUNET_malloc (sizeof (struct GNUNET_SENSOR_RequestContext) + | 605 | sizeof (struct GNUNET_MessageHeader)); |
597 | sizeof (struct GNUNET_MessageHeader)); | ||
598 | rc->size = sizeof (struct GNUNET_MessageHeader); | 606 | rc->size = sizeof (struct GNUNET_MessageHeader); |
599 | mh = (struct GNUNET_MessageHeader *) &rc[1]; | 607 | mh = (struct GNUNET_MessageHeader *) &rc[1]; |
600 | mh->size = htons(sizeof (struct GNUNET_MessageHeader)); | 608 | mh->size = htons (sizeof (struct GNUNET_MessageHeader)); |
601 | mh->type = htons(GNUNET_MESSAGE_TYPE_SENSOR_GETALL); | 609 | mh->type = htons (GNUNET_MESSAGE_TYPE_SENSOR_GETALL); |
602 | } | 610 | } |
603 | else | 611 | else |
604 | { | 612 | { |
605 | LOG (GNUNET_ERROR_TYPE_INFO, | 613 | LOG (GNUNET_ERROR_TYPE_INFO, |
606 | "Requesting information on sensor `%s' from SENSOR service\n", | 614 | "Requesting information on sensor `%s' from SENSOR service\n", |
607 | sensorname); | 615 | sensorname); |
608 | rc = | 616 | rc = GNUNET_malloc (sizeof (struct GNUNET_SENSOR_RequestContext) + |
609 | GNUNET_malloc (sizeof (struct GNUNET_SENSOR_RequestContext) + | 617 | sizeof (struct GNUNET_MessageHeader) + sensorname_len); |
610 | sizeof (struct GNUNET_MessageHeader) + | ||
611 | sensorname_len); | ||
612 | rc->size = sizeof (struct GNUNET_MessageHeader) + sensorname_len; | 618 | rc->size = sizeof (struct GNUNET_MessageHeader) + sensorname_len; |
613 | mh = (struct GNUNET_MessageHeader *) &rc[1]; | 619 | mh = (struct GNUNET_MessageHeader *) &rc[1]; |
614 | mh->size = htons(rc->size); | 620 | mh->size = htons (rc->size); |
615 | mh->type = htons(GNUNET_MESSAGE_TYPE_SENSOR_GET); | 621 | mh->type = htons (GNUNET_MESSAGE_TYPE_SENSOR_GET); |
616 | memcpy(&mh[1], sensorname, sensorname_len); | 622 | memcpy (&mh[1], sensorname, sensorname_len); |
617 | } | 623 | } |
618 | ic->h = h; | 624 | ic->h = h; |
619 | ic->rc = rc; | 625 | ic->rc = rc; |
@@ -621,13 +627,12 @@ GNUNET_SENSOR_iterate_sensors (struct GNUNET_SENSOR_Handle *h, | |||
621 | ic->callback_cls = callback_cls; | 627 | ic->callback_cls = callback_cls; |
622 | ic->timeout = GNUNET_TIME_relative_to_absolute (timeout); | 628 | ic->timeout = GNUNET_TIME_relative_to_absolute (timeout); |
623 | ic->timeout_task = | 629 | ic->timeout_task = |
624 | GNUNET_SCHEDULER_add_delayed (timeout, &signal_sensor_iteration_timeout, ic); | 630 | GNUNET_SCHEDULER_add_delayed (timeout, &signal_sensor_iteration_timeout, |
631 | ic); | ||
625 | rc->cont = &sensor_iterator_start_receive; | 632 | rc->cont = &sensor_iterator_start_receive; |
626 | rc->cont_cls = ic; | 633 | rc->cont_cls = ic; |
627 | GNUNET_CONTAINER_DLL_insert_tail (h->rc_head, h->rc_tail, rc); | 634 | GNUNET_CONTAINER_DLL_insert_tail (h->rc_head, h->rc_tail, rc); |
628 | GNUNET_CONTAINER_DLL_insert_tail (h->ic_head, | 635 | GNUNET_CONTAINER_DLL_insert_tail (h->ic_head, h->ic_tail, ic); |
629 | h->ic_tail, | ||
630 | ic); | ||
631 | trigger_transmit (h); | 636 | trigger_transmit (h); |
632 | return ic; | 637 | return ic; |
633 | } | 638 | } |
diff --git a/src/sensor/sensor_util_lib.c b/src/sensor/sensor_util_lib.c index 0302c2046..756c193ef 100644 --- a/src/sensor/sensor_util_lib.c +++ b/src/sensor/sensor_util_lib.c | |||
@@ -52,28 +52,28 @@ static const char *datatypes[] = { "numeric", "string", NULL }; | |||
52 | * @param version full version string | 52 | * @param version full version string |
53 | * @param major pointer to parsed major value | 53 | * @param major pointer to parsed major value |
54 | * @param minor pointer to parsed minor value | 54 | * @param minor pointer to parsed minor value |
55 | * @return #GNUNET_OK if parsing went ok, #GNUNET_SYSERROR in case of error | 55 | * @return #GNUNET_OK if parsing went ok, #GNUNET_SYSERR in case of error |
56 | */ | 56 | */ |
57 | static int | 57 | static int |
58 | version_parse(char *version, uint16_t *major, uint16_t *minor) | 58 | version_parse (char *version, uint16_t * major, uint16_t * minor) |
59 | { | 59 | { |
60 | int majorval = 0; | 60 | int majorval = 0; |
61 | int minorval = 0; | 61 | int minorval = 0; |
62 | 62 | ||
63 | for(; isdigit(*version); version++) | 63 | for (; isdigit (*version); version++) |
64 | { | 64 | { |
65 | majorval *= 10; | 65 | majorval *= 10; |
66 | majorval += *version - '0'; | 66 | majorval += *version - '0'; |
67 | } | 67 | } |
68 | if(*version != '.') | 68 | if (*version != '.') |
69 | return GNUNET_SYSERR; | 69 | return GNUNET_SYSERR; |
70 | version++; | 70 | version++; |
71 | for(; isdigit(*version); version++) | 71 | for (; isdigit (*version); version++) |
72 | { | 72 | { |
73 | minorval *= 10; | 73 | minorval *= 10; |
74 | minorval += *version - '0'; | 74 | minorval += *version - '0'; |
75 | } | 75 | } |
76 | if(*version != 0) | 76 | if (*version != 0) |
77 | return GNUNET_SYSERR; | 77 | return GNUNET_SYSERR; |
78 | *major = majorval; | 78 | *major = majorval; |
79 | *minor = minorval; | 79 | *minor = minorval; |
@@ -81,6 +81,7 @@ version_parse(char *version, uint16_t *major, uint16_t *minor) | |||
81 | return GNUNET_OK; | 81 | return GNUNET_OK; |
82 | } | 82 | } |
83 | 83 | ||
84 | |||
84 | /** | 85 | /** |
85 | * Load sensor definition from configuration | 86 | * Load sensor definition from configuration |
86 | * | 87 | * |
@@ -88,7 +89,8 @@ version_parse(char *version, uint16_t *major, uint16_t *minor) | |||
88 | * @param sectionname configuration section containing definition | 89 | * @param sectionname configuration section containing definition |
89 | */ | 90 | */ |
90 | static struct GNUNET_SENSOR_SensorInfo * | 91 | static struct GNUNET_SENSOR_SensorInfo * |
91 | load_sensor_from_cfg(struct GNUNET_CONFIGURATION_Handle *cfg, const char *sectionname) | 92 | load_sensor_from_cfg (struct GNUNET_CONFIGURATION_Handle *cfg, |
93 | const char *sectionname) | ||
92 | { | 94 | { |
93 | struct GNUNET_SENSOR_SensorInfo *sensor; | 95 | struct GNUNET_SENSOR_SensorInfo *sensor; |
94 | char *version_str; | 96 | char *version_str; |
@@ -98,152 +100,209 @@ load_sensor_from_cfg(struct GNUNET_CONFIGURATION_Handle *cfg, const char *sectio | |||
98 | char *dummy; | 100 | char *dummy; |
99 | struct GNUNET_CRYPTO_EddsaPublicKey public_key; | 101 | struct GNUNET_CRYPTO_EddsaPublicKey public_key; |
100 | 102 | ||
101 | sensor = GNUNET_new(struct GNUNET_SENSOR_SensorInfo); | 103 | sensor = GNUNET_new (struct GNUNET_SENSOR_SensorInfo); |
104 | |||
102 | //name | 105 | //name |
103 | sensor->name = GNUNET_strdup(sectionname); | 106 | sensor->name = GNUNET_strdup (sectionname); |
104 | //version | 107 | //version |
105 | if(GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, sectionname, "VERSION", &version_str)) | 108 | if (GNUNET_OK != |
109 | GNUNET_CONFIGURATION_get_value_string (cfg, sectionname, "VERSION", | ||
110 | &version_str)) | ||
106 | { | 111 | { |
107 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Error reading sensor version\n")); | 112 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Error reading sensor version\n")); |
108 | GNUNET_free(sensor); | 113 | GNUNET_free (sensor); |
109 | return NULL; | 114 | return NULL; |
110 | } | 115 | } |
111 | if(GNUNET_OK != version_parse(version_str, &(sensor->version_major), &(sensor->version_minor))) | 116 | if (GNUNET_OK != |
117 | version_parse (version_str, &(sensor->version_major), | ||
118 | &(sensor->version_minor))) | ||
112 | { | 119 | { |
113 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid sensor version number, format should be major.minor\n")); | 120 | LOG (GNUNET_ERROR_TYPE_ERROR, |
114 | GNUNET_free(sensor); | 121 | _("Invalid sensor version number, format should be major.minor\n")); |
115 | GNUNET_free(version_str); | 122 | GNUNET_free (sensor); |
123 | GNUNET_free (version_str); | ||
116 | return NULL; | 124 | return NULL; |
117 | } | 125 | } |
118 | GNUNET_free(version_str); | 126 | GNUNET_free (version_str); |
119 | //description | 127 | //description |
120 | GNUNET_CONFIGURATION_get_value_string(cfg, sectionname, "DESCRIPTION", &sensor->description); | 128 | GNUNET_CONFIGURATION_get_value_string (cfg, sectionname, "DESCRIPTION", |
129 | &sensor->description); | ||
121 | //category | 130 | //category |
122 | if(GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, sectionname, "CATEGORY", &sensor->category) || | 131 | if (GNUNET_OK != |
123 | NULL == sensor->category) | 132 | GNUNET_CONFIGURATION_get_value_string (cfg, sectionname, "CATEGORY", |
133 | &sensor->category) || | ||
134 | NULL == sensor->category) | ||
124 | { | 135 | { |
125 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Error reading sensor category\n")); | 136 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Error reading sensor category\n")); |
126 | GNUNET_free(sensor); | 137 | GNUNET_free (sensor); |
127 | return NULL; | 138 | return NULL; |
128 | } | 139 | } |
129 | //enabled | 140 | //enabled |
130 | if(GNUNET_NO == GNUNET_CONFIGURATION_get_value_yesno(cfg, sectionname, "ENABLED")) | 141 | if (GNUNET_NO == |
142 | GNUNET_CONFIGURATION_get_value_yesno (cfg, sectionname, "ENABLED")) | ||
131 | sensor->enabled = GNUNET_NO; | 143 | sensor->enabled = GNUNET_NO; |
132 | else | 144 | else |
133 | sensor->enabled = GNUNET_YES; | 145 | sensor->enabled = GNUNET_YES; |
134 | //start time | 146 | //start time |
135 | sensor->start_time = NULL; | 147 | sensor->start_time = NULL; |
136 | if(GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, sectionname, "START_TIME", &starttime_str)) | 148 | if (GNUNET_OK == |
149 | GNUNET_CONFIGURATION_get_value_string (cfg, sectionname, "START_TIME", | ||
150 | &starttime_str)) | ||
137 | { | 151 | { |
138 | GNUNET_STRINGS_fancy_time_to_absolute(starttime_str, sensor->start_time); | 152 | GNUNET_STRINGS_fancy_time_to_absolute (starttime_str, sensor->start_time); |
139 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Start time loaded: `%s'. Parsed: %d\n", starttime_str, (NULL != sensor->start_time)); | 153 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Start time loaded: `%s'. Parsed: %d\n", |
140 | GNUNET_free(starttime_str); | 154 | starttime_str, (NULL != sensor->start_time)); |
155 | GNUNET_free (starttime_str); | ||
141 | } | 156 | } |
142 | //end time | 157 | //end time |
143 | sensor->end_time = NULL; | 158 | sensor->end_time = NULL; |
144 | if(GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, sectionname, "END_TIME", &endtime_str)) | 159 | if (GNUNET_OK == |
160 | GNUNET_CONFIGURATION_get_value_string (cfg, sectionname, "END_TIME", | ||
161 | &endtime_str)) | ||
145 | { | 162 | { |
146 | GNUNET_STRINGS_fancy_time_to_absolute(endtime_str, sensor->end_time); | 163 | GNUNET_STRINGS_fancy_time_to_absolute (endtime_str, sensor->end_time); |
147 | LOG (GNUNET_ERROR_TYPE_DEBUG, "End time loaded: `%s'. Parsed: %d\n", endtime_str, (NULL != sensor->end_time)); | 164 | LOG (GNUNET_ERROR_TYPE_DEBUG, "End time loaded: `%s'. Parsed: %d\n", |
148 | GNUNET_free(endtime_str); | 165 | endtime_str, (NULL != sensor->end_time)); |
166 | GNUNET_free (endtime_str); | ||
149 | } | 167 | } |
150 | //interval | 168 | //interval |
151 | if(GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(cfg, sectionname, "INTERVAL", &time_sec)) | 169 | if (GNUNET_OK != |
170 | GNUNET_CONFIGURATION_get_value_number (cfg, sectionname, "INTERVAL", | ||
171 | &time_sec)) | ||
152 | { | 172 | { |
153 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Error reading sensor run interval\n")); | 173 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Error reading sensor run interval\n")); |
154 | GNUNET_free(sensor); | 174 | GNUNET_free (sensor); |
155 | return NULL; | 175 | return NULL; |
156 | } | 176 | } |
157 | if(time_sec < MIN_INTERVAL) | 177 | if (time_sec < MIN_INTERVAL) |
158 | { | 178 | { |
159 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Sensor run interval too low (%" PRIu64 " < %d)\n"), | 179 | LOG (GNUNET_ERROR_TYPE_ERROR, |
160 | time_sec, MIN_INTERVAL); | 180 | _("Sensor run interval too low (%" PRIu64 " < %d)\n"), time_sec, |
161 | GNUNET_free(sensor); | 181 | MIN_INTERVAL); |
182 | GNUNET_free (sensor); | ||
162 | return NULL; | 183 | return NULL; |
163 | } | 184 | } |
164 | sensor->interval = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, time_sec); | 185 | sensor->interval = |
186 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, time_sec); | ||
165 | //lifetime | 187 | //lifetime |
166 | if(GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(cfg, sectionname, "LIFETIME", &time_sec)) | 188 | if (GNUNET_OK == |
189 | GNUNET_CONFIGURATION_get_value_number (cfg, sectionname, "LIFETIME", | ||
190 | &time_sec)) | ||
167 | { | 191 | { |
168 | sensor->lifetime = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, time_sec); | 192 | sensor->lifetime = |
193 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, time_sec); | ||
169 | if (sensor->lifetime.rel_value_us < sensor->interval.rel_value_us) | 194 | if (sensor->lifetime.rel_value_us < sensor->interval.rel_value_us) |
170 | LOG (GNUNET_ERROR_TYPE_WARNING, | 195 | LOG (GNUNET_ERROR_TYPE_WARNING, |
171 | "Lifetime of sensor data is preferred to be higher than interval for sensor `%s'.\n", | 196 | "Lifetime of sensor data is preferred to be higher than interval for sensor `%s'.\n", |
172 | sensor->name); | 197 | sensor->name); |
173 | } | 198 | } |
174 | else | 199 | else |
175 | sensor->lifetime = GNUNET_TIME_UNIT_FOREVER_REL; | 200 | sensor->lifetime = GNUNET_TIME_UNIT_FOREVER_REL; |
176 | //capabilities TODO | 201 | //capabilities TODO |
177 | //source | 202 | //source |
178 | if(GNUNET_OK != GNUNET_CONFIGURATION_get_value_choice(cfg, sectionname, "SOURCE", sources, (const char **)&sensor->source)) | 203 | if (GNUNET_OK != |
204 | GNUNET_CONFIGURATION_get_value_choice (cfg, sectionname, "SOURCE", | ||
205 | sources, | ||
206 | (const char **) &sensor->source)) | ||
179 | { | 207 | { |
180 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Error reading sensor source\n")); | 208 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Error reading sensor source\n")); |
181 | GNUNET_free(sensor); | 209 | GNUNET_free (sensor); |
182 | return NULL; | 210 | return NULL; |
183 | } | 211 | } |
184 | if(sources[0] == sensor->source) //gnunet-statistics | 212 | if (sources[0] == sensor->source) //gnunet-statistics |
185 | { | 213 | { |
186 | if(GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, sectionname, "GNUNET_STAT_SERVICE", &sensor->gnunet_stat_service) || | 214 | if (GNUNET_OK != |
187 | GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, sectionname, "GNUNET_STAT_NAME", &sensor->gnunet_stat_name)) | 215 | GNUNET_CONFIGURATION_get_value_string (cfg, sectionname, |
216 | "GNUNET_STAT_SERVICE", | ||
217 | &sensor->gnunet_stat_service) || | ||
218 | GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, sectionname, | ||
219 | "GNUNET_STAT_NAME", | ||
220 | &sensor->gnunet_stat_name)) | ||
188 | { | 221 | { |
189 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Error reading sensor gnunet-statistics source information\n")); | 222 | LOG (GNUNET_ERROR_TYPE_ERROR, |
190 | GNUNET_free(sensor); | 223 | _("Error reading sensor gnunet-statistics source information\n")); |
224 | GNUNET_free (sensor); | ||
191 | return NULL; | 225 | return NULL; |
192 | } | 226 | } |
193 | sensor->gnunet_stat_get_handle = NULL; | 227 | sensor->gnunet_stat_get_handle = NULL; |
194 | } | 228 | } |
195 | else if(sources[1] == sensor->source) //process | 229 | else if (sources[1] == sensor->source) //process |
196 | { | 230 | { |
197 | if(GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, sectionname, "EXT_PROCESS", &sensor->ext_process)) | 231 | if (GNUNET_OK != |
232 | GNUNET_CONFIGURATION_get_value_string (cfg, sectionname, "EXT_PROCESS", | ||
233 | &sensor->ext_process)) | ||
198 | { | 234 | { |
199 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Error reading sensor process name\n")); | 235 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Error reading sensor process name\n")); |
200 | GNUNET_free(sensor); | 236 | GNUNET_free (sensor); |
201 | return NULL; | 237 | return NULL; |
202 | } | 238 | } |
203 | GNUNET_CONFIGURATION_get_value_string(cfg, sectionname, "EXT_ARGS", &sensor->ext_args); | 239 | GNUNET_CONFIGURATION_get_value_string (cfg, sectionname, "EXT_ARGS", |
240 | &sensor->ext_args); | ||
204 | } | 241 | } |
205 | //expected datatype | 242 | //expected datatype |
206 | if(GNUNET_OK != GNUNET_CONFIGURATION_get_value_choice(cfg, sectionname, "EXPECTED_DATATYPE", datatypes, (const char **)&sensor->expected_datatype)) | 243 | if (GNUNET_OK != |
244 | GNUNET_CONFIGURATION_get_value_choice (cfg, sectionname, | ||
245 | "EXPECTED_DATATYPE", datatypes, | ||
246 | (const char **) | ||
247 | &sensor->expected_datatype)) | ||
207 | { | 248 | { |
208 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Error reading sensor expected datatype\n")); | 249 | LOG (GNUNET_ERROR_TYPE_ERROR, |
209 | GNUNET_free(sensor); | 250 | _("Error reading sensor expected datatype\n")); |
251 | GNUNET_free (sensor); | ||
210 | return NULL; | 252 | return NULL; |
211 | } | 253 | } |
212 | if(sources[0] == sensor->source && datatypes[0] != sensor->expected_datatype) | 254 | if (sources[0] == sensor->source && datatypes[0] != sensor->expected_datatype) |
213 | { | 255 | { |
214 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid expected datatype, gnunet-statistics returns uint64 values\n")); | 256 | LOG (GNUNET_ERROR_TYPE_ERROR, |
215 | GNUNET_free(sensor); | 257 | _ |
258 | ("Invalid expected datatype, gnunet-statistics returns uint64 values\n")); | ||
259 | GNUNET_free (sensor); | ||
216 | return NULL; | 260 | return NULL; |
217 | } | 261 | } |
218 | //reporting mechanism | 262 | //reporting mechanism |
219 | sensor->collection_point = NULL; | 263 | sensor->collection_point = NULL; |
220 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, sectionname, "COLLECTION_POINT", &dummy)) | 264 | if (GNUNET_OK == |
265 | GNUNET_CONFIGURATION_get_value_string (cfg, sectionname, | ||
266 | "COLLECTION_POINT", &dummy)) | ||
221 | { | 267 | { |
222 | if(GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(cfg, sectionname, "COLLECTION_INTERVAL", &time_sec)) | 268 | if (GNUNET_OK != |
269 | GNUNET_CONFIGURATION_get_value_number (cfg, sectionname, | ||
270 | "COLLECTION_INTERVAL", | ||
271 | &time_sec)) | ||
223 | { | 272 | { |
224 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Error reading sensor collection interval\n")); | 273 | LOG (GNUNET_ERROR_TYPE_ERROR, |
274 | _("Error reading sensor collection interval\n")); | ||
225 | } | 275 | } |
226 | else | 276 | else |
227 | { | 277 | { |
228 | sensor->collection_interval = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, time_sec); | 278 | sensor->collection_interval = |
229 | if (GNUNET_OK == GNUNET_CRYPTO_eddsa_public_key_from_string(dummy, strlen(dummy), &public_key)) | 279 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, time_sec); |
280 | if (GNUNET_OK == | ||
281 | GNUNET_CRYPTO_eddsa_public_key_from_string (dummy, strlen (dummy), | ||
282 | &public_key)) | ||
230 | { | 283 | { |
231 | sensor->collection_point = GNUNET_new(struct GNUNET_PeerIdentity); | 284 | sensor->collection_point = GNUNET_new (struct GNUNET_PeerIdentity); |
285 | |||
232 | sensor->collection_point->public_key = public_key; | 286 | sensor->collection_point->public_key = public_key; |
233 | } | 287 | } |
234 | } | 288 | } |
235 | GNUNET_free (dummy); | 289 | GNUNET_free (dummy); |
236 | } | 290 | } |
237 | sensor->p2p_report = GNUNET_NO; | 291 | sensor->p2p_report = GNUNET_NO; |
238 | if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno(cfg, sectionname, "P2P_REPORT")) | 292 | if (GNUNET_YES == |
293 | GNUNET_CONFIGURATION_get_value_yesno (cfg, sectionname, "P2P_REPORT")) | ||
239 | { | 294 | { |
240 | if(GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(cfg, sectionname, "P2P_INTERVAL", &time_sec)) | 295 | if (GNUNET_OK != |
296 | GNUNET_CONFIGURATION_get_value_number (cfg, sectionname, "P2P_INTERVAL", | ||
297 | &time_sec)) | ||
241 | { | 298 | { |
242 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Error reading sensor p2p reporting interval\n")); | 299 | LOG (GNUNET_ERROR_TYPE_ERROR, |
300 | _("Error reading sensor p2p reporting interval\n")); | ||
243 | } | 301 | } |
244 | else | 302 | else |
245 | { | 303 | { |
246 | sensor->p2p_interval = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, time_sec); | 304 | sensor->p2p_interval = |
305 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, time_sec); | ||
247 | sensor->p2p_report = GNUNET_YES; | 306 | sensor->p2p_report = GNUNET_YES; |
248 | } | 307 | } |
249 | } | 308 | } |
@@ -255,43 +314,45 @@ load_sensor_from_cfg(struct GNUNET_CONFIGURATION_Handle *cfg, const char *sectio | |||
255 | return sensor; | 314 | return sensor; |
256 | } | 315 | } |
257 | 316 | ||
317 | |||
258 | /** | 318 | /** |
259 | * Load sensor definition from file | 319 | * Load sensor definition from file |
260 | * | 320 | * |
261 | * @param filename full path to file containing sensor definition | 321 | * @param filename full path to file containing sensor definition |
262 | */ | 322 | */ |
263 | static struct GNUNET_SENSOR_SensorInfo * | 323 | static struct GNUNET_SENSOR_SensorInfo * |
264 | load_sensor_from_file(const char *filename) | 324 | load_sensor_from_file (const char *filename) |
265 | { | 325 | { |
266 | struct GNUNET_CONFIGURATION_Handle *sensorcfg; | 326 | struct GNUNET_CONFIGURATION_Handle *sensorcfg; |
267 | const char *filebasename; | 327 | const char *filebasename; |
268 | struct GNUNET_SENSOR_SensorInfo *sensor; | 328 | struct GNUNET_SENSOR_SensorInfo *sensor; |
269 | 329 | ||
270 | //test file | 330 | //test file |
271 | if(GNUNET_YES != GNUNET_DISK_file_test(filename)) | 331 | if (GNUNET_YES != GNUNET_DISK_file_test (filename)) |
272 | { | 332 | { |
273 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Failed to access sensor file: %s\n"), filename); | 333 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Failed to access sensor file: %s\n"), |
334 | filename); | ||
274 | return NULL; | 335 | return NULL; |
275 | } | 336 | } |
276 | //load file as configuration | 337 | //load file as configuration |
277 | sensorcfg = GNUNET_CONFIGURATION_create(); | 338 | sensorcfg = GNUNET_CONFIGURATION_create (); |
278 | if(GNUNET_SYSERR == GNUNET_CONFIGURATION_parse(sensorcfg, filename)) | 339 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_parse (sensorcfg, filename)) |
279 | { | 340 | { |
280 | GNUNET_CONFIGURATION_destroy(sensorcfg); | 341 | GNUNET_CONFIGURATION_destroy (sensorcfg); |
281 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Failed to load sensor definition: %s\n"), filename); | 342 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Failed to load sensor definition: %s\n"), |
343 | filename); | ||
282 | return NULL; | 344 | return NULL; |
283 | } | 345 | } |
284 | //configuration section should be the same as filename | 346 | //configuration section should be the same as filename |
285 | filebasename = GNUNET_STRINGS_get_short_name(filename); | 347 | filebasename = GNUNET_STRINGS_get_short_name (filename); |
286 | sensor = load_sensor_from_cfg(sensorcfg, filebasename); | 348 | sensor = load_sensor_from_cfg (sensorcfg, filebasename); |
287 | if(NULL == sensor) | 349 | if (NULL == sensor) |
288 | { | 350 | { |
289 | GNUNET_CONFIGURATION_destroy(sensorcfg); | 351 | GNUNET_CONFIGURATION_destroy (sensorcfg); |
290 | return NULL; | 352 | return NULL; |
291 | } | 353 | } |
292 | sensor->def_file = GNUNET_strdup(filename); | 354 | sensor->def_file = GNUNET_strdup (filename); |
293 | sensor->cfg = sensorcfg; | 355 | sensor->cfg = sensorcfg; |
294 | |||
295 | return sensor; | 356 | return sensor; |
296 | } | 357 | } |
297 | 358 | ||
@@ -331,14 +392,13 @@ add_sensor_to_hashmap (struct GNUNET_SENSOR_SensorInfo *sensor, | |||
331 | struct GNUNET_HashCode key; | 392 | struct GNUNET_HashCode key; |
332 | struct GNUNET_SENSOR_SensorInfo *existing; | 393 | struct GNUNET_SENSOR_SensorInfo *existing; |
333 | 394 | ||
334 | GNUNET_CRYPTO_hash(sensor->name, strlen(sensor->name) + 1, &key); | 395 | GNUNET_CRYPTO_hash (sensor->name, strlen (sensor->name) + 1, &key); |
335 | existing = GNUNET_CONTAINER_multihashmap_get(map, &key); | 396 | existing = GNUNET_CONTAINER_multihashmap_get (map, &key); |
336 | if(NULL != existing) //sensor with same name already exists | 397 | if (NULL != existing) //sensor with same name already exists |
337 | { | 398 | { |
338 | if(GNUNET_SENSOR_version_compare (existing->version_major, | 399 | if (GNUNET_SENSOR_version_compare |
339 | existing->version_minor, | 400 | (existing->version_major, existing->version_minor, |
340 | sensor->version_major, | 401 | sensor->version_major, sensor->version_minor) >= 0) |
341 | sensor->version_minor) >= 0) | ||
342 | { | 402 | { |
343 | LOG (GNUNET_ERROR_TYPE_INFO, | 403 | LOG (GNUNET_ERROR_TYPE_INFO, |
344 | _("Sensor `%s' already exists with same or newer version\n"), | 404 | _("Sensor `%s' already exists with same or newer version\n"), |
@@ -347,24 +407,24 @@ add_sensor_to_hashmap (struct GNUNET_SENSOR_SensorInfo *sensor, | |||
347 | } | 407 | } |
348 | else | 408 | else |
349 | { | 409 | { |
350 | GNUNET_CONTAINER_multihashmap_remove(map, &key, existing); //remove the old version | 410 | GNUNET_CONTAINER_multihashmap_remove (map, &key, existing); //remove the old version |
351 | GNUNET_free(existing); | 411 | GNUNET_free (existing); |
352 | LOG (GNUNET_ERROR_TYPE_INFO, | 412 | LOG (GNUNET_ERROR_TYPE_INFO, "Upgrading sensor `%s' to a newer version\n", |
353 | "Upgrading sensor `%s' to a newer version\n", | ||
354 | sensor->name); | 413 | sensor->name); |
355 | } | 414 | } |
356 | } | 415 | } |
357 | if(GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put(map, &key, sensor, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | 416 | if (GNUNET_SYSERR == |
417 | GNUNET_CONTAINER_multihashmap_put (map, &key, sensor, | ||
418 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
358 | { | 419 | { |
359 | LOG (GNUNET_ERROR_TYPE_ERROR, | 420 | LOG (GNUNET_ERROR_TYPE_ERROR, |
360 | _("Error adding new sensor `%s' to global hashmap.\n"), | 421 | _("Error adding new sensor `%s' to global hashmap.\n"), sensor->name); |
361 | sensor->name); | ||
362 | return GNUNET_NO; | 422 | return GNUNET_NO; |
363 | } | 423 | } |
364 | |||
365 | return GNUNET_YES; | 424 | return GNUNET_YES; |
366 | } | 425 | } |
367 | 426 | ||
427 | |||
368 | /** | 428 | /** |
369 | * Iterating over files in sensors directory | 429 | * Iterating over files in sensors directory |
370 | * | 430 | * |
@@ -373,27 +433,27 @@ add_sensor_to_hashmap (struct GNUNET_SENSOR_SensorInfo *sensor, | |||
373 | * @return #GNUNET_OK to continue to iterate | 433 | * @return #GNUNET_OK to continue to iterate |
374 | */ | 434 | */ |
375 | static int | 435 | static int |
376 | reload_sensors_dir_cb(void *cls, const char *filename) | 436 | reload_sensors_dir_cb (void *cls, const char *filename) |
377 | { | 437 | { |
378 | struct GNUNET_CONTAINER_MultiHashMap *sensors = cls; | 438 | struct GNUNET_CONTAINER_MultiHashMap *sensors = cls; |
379 | struct GNUNET_SENSOR_SensorInfo *sensor; | 439 | struct GNUNET_SENSOR_SensorInfo *sensor; |
380 | 440 | ||
381 | if(GNUNET_YES != GNUNET_DISK_file_test(filename)) | 441 | if (GNUNET_YES != GNUNET_DISK_file_test (filename)) |
382 | return GNUNET_OK; | 442 | return GNUNET_OK; |
383 | sensor = load_sensor_from_file(filename); | 443 | sensor = load_sensor_from_file (filename); |
384 | if(NULL == sensor) | 444 | if (NULL == sensor) |
385 | { | 445 | { |
386 | LOG (GNUNET_ERROR_TYPE_ERROR, | 446 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Error loading sensor from file: %s\n"), |
387 | _("Error loading sensor from file: %s\n"), filename); | 447 | filename); |
388 | return GNUNET_OK; | 448 | return GNUNET_OK; |
389 | } | 449 | } |
390 | if(GNUNET_YES != add_sensor_to_hashmap(sensor, sensors)) | 450 | if (GNUNET_YES != add_sensor_to_hashmap (sensor, sensors)) |
391 | LOG (GNUNET_ERROR_TYPE_WARNING, | 451 | LOG (GNUNET_ERROR_TYPE_WARNING, |
392 | "Could not add sensor `%s' to global hashmap\n", sensor->name); | 452 | "Could not add sensor `%s' to global hashmap\n", sensor->name); |
393 | |||
394 | return GNUNET_OK; | 453 | return GNUNET_OK; |
395 | } | 454 | } |
396 | 455 | ||
456 | |||
397 | /* | 457 | /* |
398 | * Get path to the directory containing the sensor definition files with a | 458 | * Get path to the directory containing the sensor definition files with a |
399 | * trailing directory separator. | 459 | * trailing directory separator. |
@@ -403,19 +463,16 @@ reload_sensors_dir_cb(void *cls, const char *filename) | |||
403 | char * | 463 | char * |
404 | GNUNET_SENSOR_get_sensor_dir () | 464 | GNUNET_SENSOR_get_sensor_dir () |
405 | { | 465 | { |
406 | char* datadir; | 466 | char *datadir; |
407 | char* sensordir; | 467 | char *sensordir; |
408 | |||
409 | datadir = GNUNET_OS_installation_get_path(GNUNET_OS_IPK_DATADIR); | ||
410 | GNUNET_asprintf (&sensordir, | ||
411 | "%ssensors%s", | ||
412 | datadir, | ||
413 | DIR_SEPARATOR_STR); | ||
414 | GNUNET_free(datadir); | ||
415 | 468 | ||
469 | datadir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR); | ||
470 | GNUNET_asprintf (&sensordir, "%ssensors%s", datadir, DIR_SEPARATOR_STR); | ||
471 | GNUNET_free (datadir); | ||
416 | return sensordir; | 472 | return sensordir; |
417 | } | 473 | } |
418 | 474 | ||
475 | |||
419 | /** | 476 | /** |
420 | * Reads sensor definitions from local data files | 477 | * Reads sensor definitions from local data files |
421 | * | 478 | * |
@@ -424,20 +481,21 @@ GNUNET_SENSOR_get_sensor_dir () | |||
424 | struct GNUNET_CONTAINER_MultiHashMap * | 481 | struct GNUNET_CONTAINER_MultiHashMap * |
425 | GNUNET_SENSOR_load_all_sensors () | 482 | GNUNET_SENSOR_load_all_sensors () |
426 | { | 483 | { |
427 | char* sensordir; | 484 | char *sensordir; |
428 | struct GNUNET_CONTAINER_MultiHashMap *sensors; | 485 | struct GNUNET_CONTAINER_MultiHashMap *sensors; |
429 | 486 | ||
430 | sensors = GNUNET_CONTAINER_multihashmap_create(10, GNUNET_NO); | 487 | sensors = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO); |
431 | sensordir = GNUNET_SENSOR_get_sensor_dir (); | 488 | sensordir = GNUNET_SENSOR_get_sensor_dir (); |
432 | LOG (GNUNET_ERROR_TYPE_INFO, | 489 | LOG (GNUNET_ERROR_TYPE_INFO, |
433 | "Loading sensor definitions from directory `%s'\n", sensordir); | 490 | "Loading sensor definitions from directory `%s'\n", sensordir); |
434 | GNUNET_assert(GNUNET_YES == GNUNET_DISK_directory_test(sensordir, GNUNET_YES)); | 491 | GNUNET_assert (GNUNET_YES == |
492 | GNUNET_DISK_directory_test (sensordir, GNUNET_YES)); | ||
435 | 493 | ||
436 | //read all files in sensors directory | 494 | //read all files in sensors directory |
437 | GNUNET_DISK_directory_scan(sensordir, &reload_sensors_dir_cb, sensors); | 495 | GNUNET_DISK_directory_scan (sensordir, &reload_sensors_dir_cb, sensors); |
438 | LOG (GNUNET_ERROR_TYPE_INFO, "Loaded %d sensors from directory `%s'\n", | 496 | LOG (GNUNET_ERROR_TYPE_INFO, "Loaded %d sensors from directory `%s'\n", |
439 | GNUNET_CONTAINER_multihashmap_size(sensors), sensordir); | 497 | GNUNET_CONTAINER_multihashmap_size (sensors), sensordir); |
440 | GNUNET_free(sensordir); | 498 | GNUNET_free (sensordir); |
441 | return sensors; | 499 | return sensors; |
442 | } | 500 | } |
443 | 501 | ||
@@ -452,46 +510,45 @@ GNUNET_SENSOR_load_all_sensors () | |||
452 | * iterate, | 510 | * iterate, |
453 | * #GNUNET_NO if not. | 511 | * #GNUNET_NO if not. |
454 | */ | 512 | */ |
455 | static int destroy_sensor(void *cls, | 513 | static int |
456 | const struct GNUNET_HashCode *key, | 514 | destroy_sensor (void *cls, const struct GNUNET_HashCode *key, void *value) |
457 | void *value) | ||
458 | { | 515 | { |
459 | struct GNUNET_SENSOR_SensorInfo *sensor = value; | 516 | struct GNUNET_SENSOR_SensorInfo *sensor = value; |
460 | 517 | ||
461 | if(GNUNET_SCHEDULER_NO_TASK != sensor->execution_task) | 518 | if (GNUNET_SCHEDULER_NO_TASK != sensor->execution_task) |
462 | { | 519 | { |
463 | GNUNET_SCHEDULER_cancel(sensor->execution_task); | 520 | GNUNET_SCHEDULER_cancel (sensor->execution_task); |
464 | sensor->execution_task = GNUNET_SCHEDULER_NO_TASK; | 521 | sensor->execution_task = GNUNET_SCHEDULER_NO_TASK; |
465 | } | 522 | } |
466 | if(NULL != sensor->gnunet_stat_get_handle) | 523 | if (NULL != sensor->gnunet_stat_get_handle) |
467 | { | 524 | { |
468 | GNUNET_STATISTICS_get_cancel(sensor->gnunet_stat_get_handle); | 525 | GNUNET_STATISTICS_get_cancel (sensor->gnunet_stat_get_handle); |
469 | sensor->gnunet_stat_get_handle = NULL; | 526 | sensor->gnunet_stat_get_handle = NULL; |
470 | } | 527 | } |
471 | if(NULL != sensor->ext_cmd) | 528 | if (NULL != sensor->ext_cmd) |
472 | { | 529 | { |
473 | GNUNET_OS_command_stop(sensor->ext_cmd); | 530 | GNUNET_OS_command_stop (sensor->ext_cmd); |
474 | sensor->ext_cmd = NULL; | 531 | sensor->ext_cmd = NULL; |
475 | } | 532 | } |
476 | if(NULL != sensor->cfg) | 533 | if (NULL != sensor->cfg) |
477 | GNUNET_CONFIGURATION_destroy(sensor->cfg); | 534 | GNUNET_CONFIGURATION_destroy (sensor->cfg); |
478 | if(NULL != sensor->name) | 535 | if (NULL != sensor->name) |
479 | GNUNET_free (sensor->name); | 536 | GNUNET_free (sensor->name); |
480 | if(NULL != sensor->def_file) | 537 | if (NULL != sensor->def_file) |
481 | GNUNET_free (sensor->def_file); | 538 | GNUNET_free (sensor->def_file); |
482 | if(NULL != sensor->description) | 539 | if (NULL != sensor->description) |
483 | GNUNET_free (sensor->description); | 540 | GNUNET_free (sensor->description); |
484 | if(NULL != sensor->category) | 541 | if (NULL != sensor->category) |
485 | GNUNET_free (sensor->category); | 542 | GNUNET_free (sensor->category); |
486 | if(NULL != sensor->capabilities) | 543 | if (NULL != sensor->capabilities) |
487 | GNUNET_free (sensor->capabilities); | 544 | GNUNET_free (sensor->capabilities); |
488 | if(NULL != sensor->gnunet_stat_service) | 545 | if (NULL != sensor->gnunet_stat_service) |
489 | GNUNET_free (sensor->gnunet_stat_service); | 546 | GNUNET_free (sensor->gnunet_stat_service); |
490 | if(NULL != sensor->gnunet_stat_name) | 547 | if (NULL != sensor->gnunet_stat_name) |
491 | GNUNET_free (sensor->gnunet_stat_name); | 548 | GNUNET_free (sensor->gnunet_stat_name); |
492 | if(NULL != sensor->ext_process) | 549 | if (NULL != sensor->ext_process) |
493 | GNUNET_free (sensor->ext_process); | 550 | GNUNET_free (sensor->ext_process); |
494 | if(NULL != sensor->ext_args) | 551 | if (NULL != sensor->ext_args) |
495 | GNUNET_free (sensor->ext_args); | 552 | GNUNET_free (sensor->ext_args); |
496 | if (NULL != sensor->collection_point) | 553 | if (NULL != sensor->collection_point) |
497 | GNUNET_free (sensor->collection_point); | 554 | GNUNET_free (sensor->collection_point); |
@@ -499,6 +556,7 @@ static int destroy_sensor(void *cls, | |||
499 | return GNUNET_YES; | 556 | return GNUNET_YES; |
500 | } | 557 | } |
501 | 558 | ||
559 | |||
502 | /** | 560 | /** |
503 | * Destroys a group of sensors in a hashmap and the hashmap itself | 561 | * Destroys a group of sensors in a hashmap and the hashmap itself |
504 | * | 562 | * |
@@ -508,7 +566,6 @@ void | |||
508 | GNUNET_SENSOR_destroy_sensors (struct GNUNET_CONTAINER_MultiHashMap *sensors) | 566 | GNUNET_SENSOR_destroy_sensors (struct GNUNET_CONTAINER_MultiHashMap *sensors) |
509 | { | 567 | { |
510 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Destroying sensor list.\n"); | 568 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Destroying sensor list.\n"); |
511 | GNUNET_CONTAINER_multihashmap_iterate(sensors, &destroy_sensor, NULL); | 569 | GNUNET_CONTAINER_multihashmap_iterate (sensors, &destroy_sensor, NULL); |
512 | GNUNET_CONTAINER_multihashmap_destroy(sensors); | 570 | GNUNET_CONTAINER_multihashmap_destroy (sensors); |
513 | } | 571 | } |
514 | |||
diff --git a/src/sensor/test_sensor_api.c b/src/sensor/test_sensor_api.c index 319360bfc..deb36da29 100644 --- a/src/sensor/test_sensor_api.c +++ b/src/sensor/test_sensor_api.c | |||
@@ -30,9 +30,7 @@ static int ok = 1; | |||
30 | 30 | ||
31 | 31 | ||
32 | static void | 32 | static void |
33 | run (void *cls, | 33 | run (void *cls, char *const *args, const char *cfgfile, |
34 | char *const *args, | ||
35 | const char *cfgfile, | ||
36 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 34 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
37 | { | 35 | { |
38 | ok = 0; | 36 | ok = 0; |
@@ -47,25 +45,27 @@ check () | |||
47 | GNUNET_GETOPT_OPTION_END | 45 | GNUNET_GETOPT_OPTION_END |
48 | }; | 46 | }; |
49 | struct GNUNET_OS_Process *proc; | 47 | struct GNUNET_OS_Process *proc; |
50 | char *path = GNUNET_OS_get_libexec_binary_path ( "gnunet-service-sensor"); | 48 | char *path = GNUNET_OS_get_libexec_binary_path ("gnunet-service-sensor"); |
49 | |||
51 | if (NULL == path) | 50 | if (NULL == path) |
52 | { | 51 | { |
53 | fprintf (stderr, "Service executable not found `%s'\n", "gnunet-service-sensor"); | 52 | fprintf (stderr, "Service executable not found `%s'\n", |
54 | return -1; | 53 | "gnunet-service-sensor"); |
54 | return -1; | ||
55 | } | 55 | } |
56 | 56 | ||
57 | proc = GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_ALL, NULL, | 57 | proc = |
58 | NULL, NULL, path, "gnunet-service-sensor", NULL); | 58 | GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_ALL, NULL, NULL, |
59 | NULL, path, "gnunet-service-sensor", NULL); | ||
59 | 60 | ||
60 | GNUNET_free (path); | 61 | GNUNET_free (path); |
61 | GNUNET_assert (NULL != proc); | 62 | GNUNET_assert (NULL != proc); |
62 | GNUNET_PROGRAM_run (1, argv, "test-sensor-api", "nohelp", | 63 | GNUNET_PROGRAM_run (1, argv, "test-sensor-api", "nohelp", options, &run, &ok); |
63 | options, &run, &ok); | ||
64 | if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) | 64 | if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) |
65 | { | 65 | { |
66 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 66 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); |
67 | ok = 1; | 67 | ok = 1; |
68 | } | 68 | } |
69 | GNUNET_OS_process_wait (proc); | 69 | GNUNET_OS_process_wait (proc); |
70 | GNUNET_OS_process_destroy (proc); | 70 | GNUNET_OS_process_destroy (proc); |
71 | return ok; | 71 | return ok; |
@@ -75,9 +75,7 @@ check () | |||
75 | int | 75 | int |
76 | main (int argc, char *argv[]) | 76 | main (int argc, char *argv[]) |
77 | { | 77 | { |
78 | GNUNET_log_setup ("test_statistics_api", | 78 | GNUNET_log_setup ("test_statistics_api", "WARNING", NULL); |
79 | "WARNING", | ||
80 | NULL); | ||
81 | return check (); | 79 | return check (); |
82 | } | 80 | } |
83 | 81 | ||
diff --git a/src/sensordashboard/gnunet-sensordashboard.c b/src/sensordashboard/gnunet-sensordashboard.c index 630a3cf77..97330f389 100644 --- a/src/sensordashboard/gnunet-sensordashboard.c +++ b/src/sensordashboard/gnunet-sensordashboard.c | |||
@@ -64,11 +64,12 @@ main (int argc, char *const *argv) | |||
64 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 64 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) |
65 | return 2; | 65 | return 2; |
66 | 66 | ||
67 | ret = (GNUNET_OK == | 67 | ret = |
68 | GNUNET_PROGRAM_run (argc, argv, "gnunet-sensordashboard", | 68 | (GNUNET_OK == |
69 | gettext_noop ("help text"), options, &run, | 69 | GNUNET_PROGRAM_run (argc, argv, "gnunet-sensordashboard", |
70 | NULL)) ? ret : 1; | 70 | gettext_noop ("help text"), options, &run, |
71 | GNUNET_free ((void*) argv); | 71 | NULL)) ? ret : 1; |
72 | GNUNET_free ((void *) argv); | ||
72 | return ret; | 73 | return ret; |
73 | } | 74 | } |
74 | 75 | ||
diff --git a/src/sensordashboard/gnunet-service-sensordashboard.c b/src/sensordashboard/gnunet-service-sensordashboard.c index 0046ba488..52302603b 100644 --- a/src/sensordashboard/gnunet-service-sensordashboard.c +++ b/src/sensordashboard/gnunet-service-sensordashboard.c | |||
@@ -251,8 +251,7 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
251 | * with the channel is stored | 251 | * with the channel is stored |
252 | */ | 252 | */ |
253 | static void | 253 | static void |
254 | cadet_channel_destroyed (void *cls, | 254 | cadet_channel_destroyed (void *cls, const struct GNUNET_CADET_Channel *channel, |
255 | const struct GNUNET_CADET_Channel *channel, | ||
256 | void *channel_ctx) | 255 | void *channel_ctx) |
257 | { | 256 | { |
258 | struct ClientPeerContext *cp = channel_ctx; | 257 | struct ClientPeerContext *cp = channel_ctx; |
@@ -284,8 +283,7 @@ cadet_channel_destroyed (void *cls, | |||
284 | * (can be NULL -- that's not an error) | 283 | * (can be NULL -- that's not an error) |
285 | */ | 284 | */ |
286 | static void * | 285 | static void * |
287 | cadet_channel_created (void *cls, | 286 | cadet_channel_created (void *cls, struct GNUNET_CADET_Channel *channel, |
288 | struct GNUNET_CADET_Channel *channel, | ||
289 | const struct GNUNET_PeerIdentity *initiator, | 287 | const struct GNUNET_PeerIdentity *initiator, |
290 | uint32_t port, enum GNUNET_CADET_ChannelOption options) | 288 | uint32_t port, enum GNUNET_CADET_ChannelOption options) |
291 | { | 289 | { |
@@ -295,6 +293,7 @@ cadet_channel_created (void *cls, | |||
295 | "Received a channel connection from peer `%s'.\n", | 293 | "Received a channel connection from peer `%s'.\n", |
296 | GNUNET_i2s (initiator)); | 294 | GNUNET_i2s (initiator)); |
297 | cp = GNUNET_new (struct ClientPeerContext); | 295 | cp = GNUNET_new (struct ClientPeerContext); |
296 | |||
298 | cp->peerid = *initiator; | 297 | cp->peerid = *initiator; |
299 | cp->ch = channel; | 298 | cp->ch = channel; |
300 | cp->destroying = GNUNET_NO; | 299 | cp->destroying = GNUNET_NO; |
@@ -356,12 +355,11 @@ trigger_send_next_msg (struct ClientPeerContext *cp) | |||
356 | if (NULL != cp->th) | 355 | if (NULL != cp->th) |
357 | return; | 356 | return; |
358 | pm = cp->pm_head; | 357 | pm = cp->pm_head; |
359 | cp->th = GNUNET_CADET_notify_transmit_ready (cp->ch, | 358 | cp->th = |
360 | GNUNET_YES, | 359 | GNUNET_CADET_notify_transmit_ready (cp->ch, GNUNET_YES, |
361 | GNUNET_TIME_UNIT_FOREVER_REL, | 360 | GNUNET_TIME_UNIT_FOREVER_REL, |
362 | ntohs (pm->msg->size), | 361 | ntohs (pm->msg->size), &do_send_msg, |
363 | &do_send_msg, | 362 | cp); |
364 | cp); | ||
365 | } | 363 | } |
366 | 364 | ||
367 | 365 | ||
@@ -377,6 +375,7 @@ queue_msg (struct GNUNET_MessageHeader *msg, struct ClientPeerContext *cp) | |||
377 | struct PendingMessage *pm; | 375 | struct PendingMessage *pm; |
378 | 376 | ||
379 | pm = GNUNET_new (struct PendingMessage); | 377 | pm = GNUNET_new (struct PendingMessage); |
378 | |||
380 | pm->msg = msg; | 379 | pm->msg = msg; |
381 | GNUNET_CONTAINER_DLL_insert_tail (cp->pm_head, cp->pm_tail, pm); | 380 | GNUNET_CONTAINER_DLL_insert_tail (cp->pm_head, cp->pm_tail, pm); |
382 | trigger_send_next_msg (cp); | 381 | trigger_send_next_msg (cp); |
@@ -393,9 +392,7 @@ queue_msg (struct GNUNET_MessageHeader *msg, struct ClientPeerContext *cp) | |||
393 | * @return #GNUNET_YES to continue iteration | 392 | * @return #GNUNET_YES to continue iteration |
394 | */ | 393 | */ |
395 | static int | 394 | static int |
396 | send_sensor_brief (void *cls, | 395 | send_sensor_brief (void *cls, const struct GNUNET_HashCode *key, void *value) |
397 | const struct GNUNET_HashCode *key, | ||
398 | void *value) | ||
399 | { | 396 | { |
400 | struct ClientPeerContext *cp = cls; | 397 | struct ClientPeerContext *cp = cls; |
401 | struct GNUNET_SENSOR_SensorInfo *sensor = value; | 398 | struct GNUNET_SENSOR_SensorInfo *sensor = value; |
@@ -405,8 +402,8 @@ send_sensor_brief (void *cls, | |||
405 | 402 | ||
406 | /* Create message struct */ | 403 | /* Create message struct */ |
407 | sensorname_size = strlen (sensor->name) + 1; | 404 | sensorname_size = strlen (sensor->name) + 1; |
408 | total_size = sizeof (struct GNUNET_SENSOR_SensorBriefMessage) + | 405 | total_size = |
409 | sensorname_size; | 406 | sizeof (struct GNUNET_SENSOR_SensorBriefMessage) + sensorname_size; |
410 | msg = GNUNET_malloc (total_size); | 407 | msg = GNUNET_malloc (total_size); |
411 | msg->header.size = htons (total_size); | 408 | msg->header.size = htons (total_size); |
412 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_SENSOR_BRIEF); | 409 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_SENSOR_BRIEF); |
@@ -415,7 +412,7 @@ send_sensor_brief (void *cls, | |||
415 | msg->version_minor = htons (sensor->version_minor); | 412 | msg->version_minor = htons (sensor->version_minor); |
416 | memcpy (&msg[1], sensor->name, sensorname_size); | 413 | memcpy (&msg[1], sensor->name, sensorname_size); |
417 | /* Queue the msg */ | 414 | /* Queue the msg */ |
418 | queue_msg ((struct GNUNET_MessageHeader *)msg, cp); | 415 | queue_msg ((struct GNUNET_MessageHeader *) msg, cp); |
419 | return GNUNET_YES; | 416 | return GNUNET_YES; |
420 | } | 417 | } |
421 | 418 | ||
@@ -435,8 +432,7 @@ send_sensor_brief (void *cls, | |||
435 | * #GNUNET_SYSERR to close it (signal serious error). | 432 | * #GNUNET_SYSERR to close it (signal serious error). |
436 | */ | 433 | */ |
437 | static int | 434 | static int |
438 | handle_sensor_list_req (void *cls, | 435 | handle_sensor_list_req (void *cls, struct GNUNET_CADET_Channel *channel, |
439 | struct GNUNET_CADET_Channel *channel, | ||
440 | void **channel_ctx, | 436 | void **channel_ctx, |
441 | const struct GNUNET_MessageHeader *message) | 437 | const struct GNUNET_MessageHeader *message) |
442 | { | 438 | { |
@@ -446,10 +442,9 @@ handle_sensor_list_req (void *cls, | |||
446 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 442 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
447 | "Received a sensor list request from peer `%s'.\n", | 443 | "Received a sensor list request from peer `%s'.\n", |
448 | GNUNET_i2s (&cp->peerid)); | 444 | GNUNET_i2s (&cp->peerid)); |
449 | GNUNET_CONTAINER_multihashmap_iterate (sensors, | 445 | GNUNET_CONTAINER_multihashmap_iterate (sensors, &send_sensor_brief, cp); |
450 | &send_sensor_brief, | ||
451 | cp); | ||
452 | end_msg = GNUNET_new (struct GNUNET_MessageHeader); | 446 | end_msg = GNUNET_new (struct GNUNET_MessageHeader); |
447 | |||
453 | end_msg->size = htons (sizeof (struct GNUNET_MessageHeader)); | 448 | end_msg->size = htons (sizeof (struct GNUNET_MessageHeader)); |
454 | end_msg->type = htons (GNUNET_MESSAGE_TYPE_SENSOR_END); | 449 | end_msg->type = htons (GNUNET_MESSAGE_TYPE_SENSOR_END); |
455 | queue_msg (end_msg, cp); | 450 | queue_msg (end_msg, cp); |
@@ -485,11 +480,11 @@ parse_reading_message (const struct GNUNET_MessageHeader *msg, | |||
485 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Invalid reading message size.\n"); | 480 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Invalid reading message size.\n"); |
486 | return NULL; | 481 | return NULL; |
487 | } | 482 | } |
488 | rm = (struct GNUNET_SENSOR_ReadingMessage *)msg; | 483 | rm = (struct GNUNET_SENSOR_ReadingMessage *) msg; |
489 | sensorname_size = ntohs (rm->sensorname_size); | 484 | sensorname_size = ntohs (rm->sensorname_size); |
490 | value_size = ntohs (rm->value_size); | 485 | value_size = ntohs (rm->value_size); |
491 | if ((sizeof (struct GNUNET_SENSOR_ReadingMessage) | 486 | if ((sizeof (struct GNUNET_SENSOR_ReadingMessage) + sensorname_size + |
492 | + sensorname_size + value_size) != msg_size) | 487 | value_size) != msg_size) |
493 | { | 488 | { |
494 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Invalid reading message size.\n"); | 489 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Invalid reading message size.\n"); |
495 | return NULL; | 490 | return NULL; |
@@ -497,13 +492,13 @@ parse_reading_message (const struct GNUNET_MessageHeader *msg, | |||
497 | dummy = &rm[1]; | 492 | dummy = &rm[1]; |
498 | sensorname = GNUNET_malloc (sensorname_size); | 493 | sensorname = GNUNET_malloc (sensorname_size); |
499 | memcpy (sensorname, dummy, sensorname_size); | 494 | memcpy (sensorname, dummy, sensorname_size); |
500 | GNUNET_CRYPTO_hash(sensorname, sensorname_size, &key); | 495 | GNUNET_CRYPTO_hash (sensorname, sensorname_size, &key); |
501 | GNUNET_free (sensorname); | 496 | GNUNET_free (sensorname); |
502 | sensor = GNUNET_CONTAINER_multihashmap_get (sensors, &key); | 497 | sensor = GNUNET_CONTAINER_multihashmap_get (sensors, &key); |
503 | if (NULL == sensor) | 498 | if (NULL == sensor) |
504 | { | 499 | { |
505 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 500 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
506 | "Unknown sensor name in reading message.\n"); | 501 | "Unknown sensor name in reading message.\n"); |
507 | return NULL; | 502 | return NULL; |
508 | } | 503 | } |
509 | if ((sensor->version_minor != ntohs (rm->sensorversion_minor)) || | 504 | if ((sensor->version_minor != ntohs (rm->sensorversion_minor)) || |
@@ -546,8 +541,7 @@ parse_reading_message (const struct GNUNET_MessageHeader *msg, | |||
546 | * #GNUNET_SYSERR to close it (signal serious error). | 541 | * #GNUNET_SYSERR to close it (signal serious error). |
547 | */ | 542 | */ |
548 | static int | 543 | static int |
549 | handle_sensor_reading (void *cls, | 544 | handle_sensor_reading (void *cls, struct GNUNET_CADET_Channel *channel, |
550 | struct GNUNET_CADET_Channel *channel, | ||
551 | void **channel_ctx, | 545 | void **channel_ctx, |
552 | const struct GNUNET_MessageHeader *message) | 546 | const struct GNUNET_MessageHeader *message) |
553 | { | 547 | { |
@@ -564,13 +558,9 @@ handle_sensor_reading (void *cls, | |||
564 | } | 558 | } |
565 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 559 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
566 | "Received a sensor reading from peer `%s':\n" | 560 | "Received a sensor reading from peer `%s':\n" |
567 | "# Sensor name: `%s'\n" | 561 | "# Sensor name: `%s'\n" "# Timestamp: %" PRIu64 "\n" |
568 | "# Timestamp: %" PRIu64 "\n" | 562 | "# Value size: %" PRIu64 ".\n", GNUNET_i2s (&cp->peerid), |
569 | "# Value size: %" PRIu64 ".\n", | 563 | reading->sensor->name, reading->timestamp, reading->value_size); |
570 | GNUNET_i2s (&cp->peerid), | ||
571 | reading->sensor->name, | ||
572 | reading->timestamp, | ||
573 | reading->value_size); | ||
574 | GNUNET_PEERSTORE_store (peerstore, subsystem, &cp->peerid, | 564 | GNUNET_PEERSTORE_store (peerstore, subsystem, &cp->peerid, |
575 | reading->sensor->name, reading->value, | 565 | reading->sensor->name, reading->value, |
576 | reading->value_size, GNUNET_TIME_UNIT_FOREVER_ABS, | 566 | reading->value_size, GNUNET_TIME_UNIT_FOREVER_ABS, |
@@ -609,12 +599,10 @@ create_full_sensor_msg (char *sensorname) | |||
609 | if (NULL == sensor) | 599 | if (NULL == sensor) |
610 | return NULL; | 600 | return NULL; |
611 | sensor_dir = GNUNET_SENSOR_get_sensor_dir (); | 601 | sensor_dir = GNUNET_SENSOR_get_sensor_dir (); |
612 | GNUNET_asprintf (&sensor_path, "%s%s", | 602 | GNUNET_asprintf (&sensor_path, "%s%s", sensor_dir, sensorname); |
613 | sensor_dir, sensorname); | 603 | if (GNUNET_OK != |
614 | if (GNUNET_OK != GNUNET_DISK_file_size (sensor_path, | 604 | GNUNET_DISK_file_size (sensor_path, &sensorfile_size, GNUNET_NO, |
615 | &sensorfile_size, | 605 | GNUNET_YES)) |
616 | GNUNET_NO, | ||
617 | GNUNET_YES)) | ||
618 | { | 606 | { |
619 | GNUNET_free (sensor_dir); | 607 | GNUNET_free (sensor_dir); |
620 | GNUNET_free (sensor_path); | 608 | GNUNET_free (sensor_path); |
@@ -626,25 +614,19 @@ create_full_sensor_msg (char *sensorname) | |||
626 | /* Test if there is an associated script */ | 614 | /* Test if there is an associated script */ |
627 | if (NULL != sensor->ext_process) | 615 | if (NULL != sensor->ext_process) |
628 | { | 616 | { |
629 | GNUNET_asprintf (&sensorscript_path, "%s%s-files%s%s", | 617 | GNUNET_asprintf (&sensorscript_path, "%s%s-files%s%s", sensor_dir, |
630 | sensor_dir, | 618 | sensor->name, DIR_SEPARATOR_STR, sensor->ext_process); |
631 | sensor->name, | 619 | if (GNUNET_OK == |
632 | DIR_SEPARATOR_STR, | 620 | GNUNET_DISK_file_size (sensorscript_path, &sensorscript_size, GNUNET_NO, |
633 | sensor->ext_process); | 621 | GNUNET_YES)) |
634 | if (GNUNET_OK == GNUNET_DISK_file_size (sensorscript_path, | ||
635 | &sensorscript_size, | ||
636 | GNUNET_NO, | ||
637 | GNUNET_YES)) | ||
638 | { | 622 | { |
639 | sensorscriptname_size = strlen (sensor->ext_process) + 1; | 623 | sensorscriptname_size = strlen (sensor->ext_process) + 1; |
640 | } | 624 | } |
641 | } | 625 | } |
642 | /* Construct the msg */ | 626 | /* Construct the msg */ |
643 | total_size = sizeof (struct GNUNET_SENSOR_SensorFullMessage) + | 627 | total_size = |
644 | sensorname_size + | 628 | sizeof (struct GNUNET_SENSOR_SensorFullMessage) + sensorname_size + |
645 | sensorfile_size + | 629 | sensorfile_size + sensorscriptname_size + sensorscript_size; |
646 | sensorscriptname_size + | ||
647 | sensorscript_size; | ||
648 | msg = GNUNET_malloc (total_size); | 630 | msg = GNUNET_malloc (total_size); |
649 | msg->header.size = htons (total_size); | 631 | msg->header.size = htons (total_size); |
650 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_SENSOR_FULL); | 632 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_SENSOR_FULL); |
@@ -685,8 +667,7 @@ create_full_sensor_msg (char *sensorname) | |||
685 | * #GNUNET_SYSERR to close it (signal serious error). | 667 | * #GNUNET_SYSERR to close it (signal serious error). |
686 | */ | 668 | */ |
687 | static int | 669 | static int |
688 | handle_sensor_full_req (void *cls, | 670 | handle_sensor_full_req (void *cls, struct GNUNET_CADET_Channel *channel, |
689 | struct GNUNET_CADET_Channel *channel, | ||
690 | void **channel_ctx, | 671 | void **channel_ctx, |
691 | const struct GNUNET_MessageHeader *message) | 672 | const struct GNUNET_MessageHeader *message) |
692 | { | 673 | { |
@@ -700,10 +681,10 @@ handle_sensor_full_req (void *cls, | |||
700 | /* parse & error check */ | 681 | /* parse & error check */ |
701 | if (msg_size > sizeof (struct GNUNET_SENSOR_SensorBriefMessage)) | 682 | if (msg_size > sizeof (struct GNUNET_SENSOR_SensorBriefMessage)) |
702 | { | 683 | { |
703 | sbm = (struct GNUNET_SENSOR_SensorBriefMessage *)message; | 684 | sbm = (struct GNUNET_SENSOR_SensorBriefMessage *) message; |
704 | sensorname_size = ntohs (sbm->name_size); | 685 | sensorname_size = ntohs (sbm->name_size); |
705 | if (msg_size != sizeof (struct GNUNET_SENSOR_SensorBriefMessage) + | 686 | if (msg_size != |
706 | sensorname_size) | 687 | sizeof (struct GNUNET_SENSOR_SensorBriefMessage) + sensorname_size) |
707 | sbm = NULL; | 688 | sbm = NULL; |
708 | } | 689 | } |
709 | if (NULL == sbm) | 690 | if (NULL == sbm) |
@@ -714,15 +695,15 @@ handle_sensor_full_req (void *cls, | |||
714 | return GNUNET_SYSERR; | 695 | return GNUNET_SYSERR; |
715 | } | 696 | } |
716 | /* Create and send msg with full sensor info */ | 697 | /* Create and send msg with full sensor info */ |
717 | sfm = create_full_sensor_msg ((char *)&sbm[1]); | 698 | sfm = create_full_sensor_msg ((char *) &sbm[1]); |
718 | if (NULL == sfm) | 699 | if (NULL == sfm) |
719 | { | 700 | { |
720 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 701 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
721 | "Error creating full sensor info msg for sensor `%s'.\n", | 702 | "Error creating full sensor info msg for sensor `%s'.\n", |
722 | (char *)&sbm[1]); | 703 | (char *) &sbm[1]); |
723 | return GNUNET_SYSERR; | 704 | return GNUNET_SYSERR; |
724 | } | 705 | } |
725 | queue_msg ((struct GNUNET_MessageHeader *)sfm, cp); | 706 | queue_msg ((struct GNUNET_MessageHeader *) sfm, cp); |
726 | GNUNET_CADET_receive_done (channel); | 707 | GNUNET_CADET_receive_done (channel); |
727 | return GNUNET_OK; | 708 | return GNUNET_OK; |
728 | } | 709 | } |
@@ -740,32 +721,30 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
740 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 721 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
741 | { | 722 | { |
742 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { | 723 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { |
743 | {NULL, NULL, 0, 0} | 724 | {NULL, NULL, 0, 0} |
744 | }; | 725 | }; |
745 | static struct GNUNET_CADET_MessageHandler cadet_handlers[] = { | 726 | static struct GNUNET_CADET_MessageHandler cadet_handlers[] = { |
746 | {&handle_sensor_reading, | 727 | {&handle_sensor_reading, |
747 | GNUNET_MESSAGE_TYPE_SENSOR_READING, 0}, | 728 | GNUNET_MESSAGE_TYPE_SENSOR_READING, 0}, |
748 | {&handle_sensor_list_req, | 729 | {&handle_sensor_list_req, |
749 | GNUNET_MESSAGE_TYPE_SENSOR_LIST_REQ, | 730 | GNUNET_MESSAGE_TYPE_SENSOR_LIST_REQ, |
750 | sizeof (struct GNUNET_MessageHeader)}, | 731 | sizeof (struct GNUNET_MessageHeader)}, |
751 | {&handle_sensor_full_req, | 732 | {&handle_sensor_full_req, |
752 | GNUNET_MESSAGE_TYPE_SENSOR_FULL_REQ, | 733 | GNUNET_MESSAGE_TYPE_SENSOR_FULL_REQ, |
753 | sizeof (struct GNUNET_MessageHeader)}, | 734 | sizeof (struct GNUNET_MessageHeader)}, |
754 | {NULL, 0, 0} | 735 | {NULL, 0, 0} |
755 | }; | 736 | }; |
756 | static uint32_t cadet_ports[] = { | 737 | static uint32_t cadet_ports[] = { |
757 | GNUNET_APPLICATION_TYPE_SENSORDASHBOARD, | 738 | GNUNET_APPLICATION_TYPE_SENSORDASHBOARD, |
758 | GNUNET_APPLICATION_TYPE_SENSORUPDATE, | 739 | GNUNET_APPLICATION_TYPE_SENSORUPDATE, |
759 | GNUNET_APPLICATION_TYPE_END | 740 | GNUNET_APPLICATION_TYPE_END |
760 | }; | 741 | }; |
761 | sensors = GNUNET_SENSOR_load_all_sensors (); | 742 | sensors = GNUNET_SENSOR_load_all_sensors (); |
762 | GNUNET_assert (NULL != sensors); | 743 | GNUNET_assert (NULL != sensors); |
763 | cadet = GNUNET_CADET_connect(cfg, | 744 | cadet = |
764 | NULL, | 745 | GNUNET_CADET_connect (cfg, NULL, &cadet_channel_created, |
765 | &cadet_channel_created, | 746 | &cadet_channel_destroyed, cadet_handlers, |
766 | &cadet_channel_destroyed, | 747 | cadet_ports); |
767 | cadet_handlers, | ||
768 | cadet_ports); | ||
769 | if (NULL == cadet) | 748 | if (NULL == cadet) |
770 | { | 749 | { |
771 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 750 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
diff --git a/src/sensordashboard/sensordashboard.h b/src/sensordashboard/sensordashboard.h index c7758e26e..22eba4df1 100644 --- a/src/sensordashboard/sensordashboard.h +++ b/src/sensordashboard/sensordashboard.h | |||
@@ -25,6 +25,4 @@ | |||
25 | 25 | ||
26 | #include "gnunet_sensordashboard_service.h" | 26 | #include "gnunet_sensordashboard_service.h" |
27 | 27 | ||
28 | GNUNET_NETWORK_STRUCT_BEGIN | 28 | GNUNET_NETWORK_STRUCT_BEGIN GNUNET_NETWORK_STRUCT_END |
29 | |||
30 | GNUNET_NETWORK_STRUCT_END | ||