2 This file is part of GNUnet.
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file sensor/sensor_util_lib.c
23 * @brief sensor utilities
24 * @author Omar Tarabai
27 #ifndef GNUNET_SENSOR_UTIL_LIB_H
28 #define GNUNET_SENSOR_UTIL_LIB_H
33 #if 0 /* keep Emacsens' auto-indent happy */
39 * Structure containing sensor definition
41 struct GNUNET_SENSOR_SensorInfo
45 * The configuration handle
46 * carrying sensor information
48 struct GNUNET_CONFIGURATION_Handle *cfg;
56 * Path to definition file
61 * First part of version number
63 uint16_t version_major;
66 * Second part of version number
68 uint16_t version_minor;
76 * Sensor currently enabled
81 * Category under which the sensor falls (e.g. tcp, datastore)
86 * When does the sensor become active
88 struct GNUNET_TIME_Absolute *start_time;
91 * When does the sensor expire
93 struct GNUNET_TIME_Absolute *end_time;
96 * Time interval to collect sensor information (e.g. every 1 min)
98 struct GNUNET_TIME_Relative interval;
101 * Lifetime of an information sample after which it is deleted from storage
102 * If not supplied, will default to the interval value
104 struct GNUNET_TIME_Relative lifetime;
107 * A set of required peer capabilities for the sensor to collect meaningful information (e.g. ipv6)
112 * Either "gnunet-statistics" or external "process"
117 * Name of the GNUnet service that is the source for the gnunet-statistics entry
119 char *gnunet_stat_service;
122 * Name of the gnunet-statistics entry
124 char *gnunet_stat_name;
127 * Handle to statistics get request (OR NULL)
129 struct GNUNET_STATISTICS_GetHandle *gnunet_stat_get_handle;
132 * Name of the external process to be executed
137 * Arguments to be passed to the external process
142 * Handle to the external process
144 struct GNUNET_OS_CommandHandle *ext_cmd;
147 * Did we already receive a value
148 * from the currently running external
149 * proccess ? #GNUNET_YES / #GNUNET_NO
151 int ext_cmd_value_received;
154 * The output datatype to be expected
156 char *expected_datatype;
159 * Peer-identity of peer running collection point
161 struct GNUNET_PeerIdentity *collection_point;
164 * Do we report received sensor values to collection point?
165 * #GNUNET_YES / #GNUNET_NO
170 * Time interval to send sensor values to collection point (e.g. every 30 mins)
172 struct GNUNET_TIME_Relative value_reporting_interval;
175 * Do we report anomalies to collection point?
176 * #GNUNET_YES / #GNUNET_NO
178 int report_anomalies;
181 * Execution task (OR NULL)
183 struct GNUNET_SCHEDULER_Task * execution_task;
186 * Is the sensor being executed
193 * Anomaly report received and stored by sensor dashboard.
194 * Sensor name and peer id are not included because they are part of the
197 struct GNUNET_SENSOR_DashboardAnomalyEntry
206 * Percentage of neighbors reported the same anomaly
208 float anomalous_neighbors;
212 GNUNET_NETWORK_STRUCT_BEGIN
214 * Used to communicate brief information about a sensor.
216 struct GNUNET_SENSOR_SensorBriefMessage
220 * GNUNET general message header.
222 struct GNUNET_MessageHeader header;
225 * Size of sensor name string, allocated at position 0 after this struct.
230 * First part of sensor version number
232 uint16_t version_major;
235 * Second part of sensor version number
237 uint16_t version_minor;
242 * Used to communicate full information about a sensor.
244 struct GNUNET_SENSOR_SensorFullMessage
248 * GNUNET general message header.
250 struct GNUNET_MessageHeader header;
253 * Size of sensor name.
254 * Name allocated at position 0 after this struct.
256 uint16_t sensorname_size;
259 * Size of the sensor definition file carrying full sensor information.
260 * The file content allocated at position 1 after this struct.
262 uint16_t sensorfile_size;
265 * Name of the file (usually script) associated with this sensor.
266 * At the moment we only support having one file per sensor.
267 * The file name is allocated at position 2 after this struct.
269 uint16_t scriptname_size;
272 * Size of the file (usually script) associated with this sensor.
273 * The file content is allocated at position 3 after this struct.
275 uint16_t scriptfile_size;
280 * Used to communicate sensor values to
281 * collection points (SENSORDASHBAORD service)
283 struct GNUNET_SENSOR_ValueMessage
287 * GNUNET general message header
289 struct GNUNET_MessageHeader header;
292 * Hash of sensor name
294 struct GNUNET_HashCode sensorname_hash;
297 * First part of sensor version number
299 uint16_t sensorversion_major;
302 * Second part of sensor version number
304 uint16_t sensorversion_minor;
307 * Timestamp of recorded reading
309 struct GNUNET_TIME_Absolute timestamp;
312 * Size of sensor value, allocated at poistion 0 after this struct
319 * Message carrying an anomaly status change report
321 struct GNUNET_SENSOR_AnomalyReportMessage
325 * Hash of sensor name
327 struct GNUNET_HashCode sensorname_hash;
330 * First part of sensor version number
332 uint16_t sensorversion_major;
335 * Second part of sensor version name
337 uint16_t sensorversion_minor;
345 * Percentage of neighbors reported the same anomaly
347 float anomalous_neighbors;
351 GNUNET_NETWORK_STRUCT_END
353 * Given two version numbers as major and minor, compare them.
355 * @param v1_major First part of first version number
356 * @param v1_minor Second part of first version number
357 * @param v2_major First part of second version number
358 * @param v2_minor Second part of second version number
361 GNUNET_SENSOR_version_compare (uint16_t v1_major, uint16_t v1_minor,
362 uint16_t v2_major, uint16_t v2_minor);
366 * Reads sensor definitions from given sensor directory.
368 * @param sensordir Path to sensor directory.
369 * @return a multihashmap of loaded sensors
371 struct GNUNET_CONTAINER_MultiHashMap *
372 GNUNET_SENSOR_load_all_sensors (char *sensor_dir);
376 * Get path to the default directory containing the sensor definition files with
377 * a trailing directory separator.
379 * @return Default sensor files directory full path
382 GNUNET_SENSOR_get_default_sensor_dir ();
386 * Destroys a group of sensors in a hashmap and the hashmap itself
388 * @param sensors hashmap containing the sensors
391 GNUNET_SENSOR_destroy_sensors (struct GNUNET_CONTAINER_MultiHashMap *sensors);
394 struct GNUNET_SENSOR_crypto_pow_context;
397 * Block carrying arbitrary data + its proof-of-work + signature
399 struct GNUNET_SENSOR_crypto_pow_block
403 * Proof-of-work value
410 struct GNUNET_CRYPTO_EddsaSignature signature;
413 * Size of the msg component (allocated after this struct)
418 * Purpose of signing.
419 * Data is allocated after this (timestamp, public_key, msg).
421 struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
424 * First part of data - timestamp
426 struct GNUNET_TIME_Absolute timestamp;
429 * Second part of data - Public key
431 struct GNUNET_CRYPTO_EddsaPublicKey public_key;
437 * Continuation called with a status result.
440 * @param pow Proof-of-work value
441 * @param purpose Signed block (size, purpose, data)
442 * @param signature Signature, NULL on error
444 typedef void (*GNUNET_SENSOR_UTIL_pow_callback) (void *cls,
446 GNUNET_SENSOR_crypto_pow_block
451 * Cancel an operation started by #GNUNET_SENSOR_crypto_pow_sign().
452 * Call only before callback function passed to #GNUNET_SENSOR_crypto_pow_sign()
453 * is called with the result.
456 GNUNET_SENSOR_crypto_pow_sign_cancel (struct GNUNET_SENSOR_crypto_pow_context
461 * Calculate proof-of-work and sign a message.
463 * @param msg Message to calculate pow and sign
464 * @param msg_size size of msg
465 * @param timestamp Timestamp to add to the message to protect against replay attacks
466 * @param public_key Public key of the origin peer, to protect against redirect attacks
467 * @param private_key Private key of the origin peer to sign the result
468 * @param matching_bits Number of leading zeros required in the result hash
469 * @param callback Callback function to call with the result
470 * @param callback_cls Closure for callback
471 * @return Operation context
473 struct GNUNET_SENSOR_crypto_pow_context *
474 GNUNET_SENSOR_crypto_pow_sign (void *msg, size_t msg_size,
475 struct GNUNET_TIME_Absolute *timestamp,
476 struct GNUNET_CRYPTO_EddsaPublicKey *public_key,
477 struct GNUNET_CRYPTO_EddsaPrivateKey
478 *private_key, int matching_bits,
479 GNUNET_SENSOR_UTIL_pow_callback callback,
484 * Verify that proof-of-work and signature in the given block are valid.
485 * If all valid, a pointer to the payload within the block is set and the size
486 * of the payload is returned.
488 * **VERY IMPORTANT** : You will still need to verify the timestamp yourself.
490 * @param block The block received and needs to be verified
491 * @param matching_bits Number of leading zeros in the hash used to verify pow
492 * @param public_key Public key of the peer that sent this block
493 * @param payload Where to store the pointer to the payload
494 * @return Size of the payload
497 GNUNET_SENSOR_crypto_verify_pow_sign (struct GNUNET_SENSOR_crypto_pow_block *
498 block, int matching_bits,
499 struct GNUNET_CRYPTO_EddsaPublicKey *
500 public_key, void **payload);
503 #if 0 /* keep Emacsens' auto-indent happy */
510 /* ifndef GNUNET_SENSOR_UTIL_LIB_H */
512 /* end of gnunet_sensor_util_lib.h */