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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
22 * @author Omar Tarabai
27 * @defgroup sensor Sensor Utilities library
32 #ifndef GNUNET_SENSOR_UTIL_LIB_H
33 #define GNUNET_SENSOR_UTIL_LIB_H
38 #if 0 /* keep Emacsens' auto-indent happy */
44 * Structure containing sensor definition
46 struct GNUNET_SENSOR_SensorInfo
50 * The configuration handle
51 * carrying sensor information
53 struct GNUNET_CONFIGURATION_Handle *cfg;
61 * Path to definition file
66 * First part of version number
68 uint16_t version_major;
71 * Second part of version number
73 uint16_t version_minor;
81 * Sensor currently enabled
86 * Category under which the sensor falls (e.g. tcp, datastore)
91 * When does the sensor become active
93 struct GNUNET_TIME_Absolute *start_time;
96 * When does the sensor expire
98 struct GNUNET_TIME_Absolute *end_time;
101 * Time interval to collect sensor information (e.g. every 1 min)
103 struct GNUNET_TIME_Relative interval;
106 * Lifetime of an information sample after which it is deleted from storage
107 * If not supplied, will default to the interval value
109 struct GNUNET_TIME_Relative lifetime;
112 * A set of required peer capabilities for the sensor to collect meaningful information (e.g. ipv6)
117 * Either "gnunet-statistics" or external "process"
122 * Name of the GNUnet service that is the source for the gnunet-statistics entry
124 char *gnunet_stat_service;
127 * Name of the gnunet-statistics entry
129 char *gnunet_stat_name;
132 * Handle to statistics get request (OR NULL)
134 struct GNUNET_STATISTICS_GetHandle *gnunet_stat_get_handle;
137 * Name of the external process to be executed
142 * Arguments to be passed to the external process
147 * Handle to the external process
149 struct GNUNET_OS_CommandHandle *ext_cmd;
152 * Did we already receive a value
153 * from the currently running external
154 * proccess ? #GNUNET_YES / #GNUNET_NO
156 int ext_cmd_value_received;
159 * The output datatype to be expected
161 char *expected_datatype;
164 * Peer-identity of peer running collection point
166 struct GNUNET_PeerIdentity *collection_point;
169 * Do we report received sensor values to collection point?
170 * #GNUNET_YES / #GNUNET_NO
175 * Time interval to send sensor values to collection point (e.g. every 30 mins)
177 struct GNUNET_TIME_Relative value_reporting_interval;
180 * Do we report anomalies to collection point?
181 * #GNUNET_YES / #GNUNET_NO
183 int report_anomalies;
186 * Execution task (OR NULL)
188 struct GNUNET_SCHEDULER_Task * execution_task;
191 * Is the sensor being executed
198 * Anomaly report received and stored by sensor dashboard.
199 * Sensor name and peer id are not included because they are part of the
202 struct GNUNET_SENSOR_DashboardAnomalyEntry
211 * Percentage of neighbors reported the same anomaly
213 float anomalous_neighbors;
217 GNUNET_NETWORK_STRUCT_BEGIN
219 * Used to communicate brief information about a sensor.
221 struct GNUNET_SENSOR_SensorBriefMessage
225 * GNUNET general message header.
227 struct GNUNET_MessageHeader header;
230 * Size of sensor name string, allocated at position 0 after this struct.
235 * First part of sensor version number
237 uint16_t version_major;
240 * Second part of sensor version number
242 uint16_t version_minor;
247 * Used to communicate full information about a sensor.
249 struct GNUNET_SENSOR_SensorFullMessage
253 * GNUNET general message header.
255 struct GNUNET_MessageHeader header;
258 * Size of sensor name.
259 * Name allocated at position 0 after this struct.
261 uint16_t sensorname_size;
264 * Size of the sensor definition file carrying full sensor information.
265 * The file content allocated at position 1 after this struct.
267 uint16_t sensorfile_size;
270 * Name of the file (usually script) associated with this sensor.
271 * At the moment we only support having one file per sensor.
272 * The file name is allocated at position 2 after this struct.
274 uint16_t scriptname_size;
277 * Size of the file (usually script) associated with this sensor.
278 * The file content is allocated at position 3 after this struct.
280 uint16_t scriptfile_size;
285 * Used to communicate sensor values to
286 * collection points (SENSORDASHBAORD service)
288 struct GNUNET_SENSOR_ValueMessage
292 * GNUNET general message header
294 struct GNUNET_MessageHeader header;
297 * Hash of sensor name
299 struct GNUNET_HashCode sensorname_hash;
302 * First part of sensor version number
304 uint16_t sensorversion_major;
307 * Second part of sensor version number
309 uint16_t sensorversion_minor;
312 * Timestamp of recorded reading
314 struct GNUNET_TIME_Absolute timestamp;
317 * Size of sensor value, allocated at poistion 0 after this struct
324 * Message carrying an anomaly status change report
326 struct GNUNET_SENSOR_AnomalyReportMessage
330 * Hash of sensor name
332 struct GNUNET_HashCode sensorname_hash;
335 * First part of sensor version number
337 uint16_t sensorversion_major;
340 * Second part of sensor version name
342 uint16_t sensorversion_minor;
350 * Percentage of neighbors reported the same anomaly
352 float anomalous_neighbors;
356 GNUNET_NETWORK_STRUCT_END
358 * Given two version numbers as major and minor, compare them.
360 * @param v1_major First part of first version number
361 * @param v1_minor Second part of first version number
362 * @param v2_major First part of second version number
363 * @param v2_minor Second part of second version number
366 GNUNET_SENSOR_version_compare (uint16_t v1_major, uint16_t v1_minor,
367 uint16_t v2_major, uint16_t v2_minor);
371 * Reads sensor definitions from given sensor directory.
373 * @param sensordir Path to sensor directory.
374 * @return a multihashmap of loaded sensors
376 struct GNUNET_CONTAINER_MultiHashMap *
377 GNUNET_SENSOR_load_all_sensors (char *sensor_dir);
381 * Get path to the default directory containing the sensor definition files with
382 * a trailing directory separator.
384 * @return Default sensor files directory full path
387 GNUNET_SENSOR_get_default_sensor_dir ();
391 * Destroys a group of sensors in a hashmap and the hashmap itself
393 * @param sensors hashmap containing the sensors
396 GNUNET_SENSOR_destroy_sensors (struct GNUNET_CONTAINER_MultiHashMap *sensors);
399 struct GNUNET_SENSOR_crypto_pow_context;
402 * Block carrying arbitrary data + its proof-of-work + signature
404 struct GNUNET_SENSOR_crypto_pow_block
408 * Proof-of-work value
415 struct GNUNET_CRYPTO_EddsaSignature signature;
418 * Size of the msg component (allocated after this struct)
423 * Purpose of signing.
424 * Data is allocated after this (timestamp, public_key, msg).
426 struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
429 * First part of data - timestamp
431 struct GNUNET_TIME_Absolute timestamp;
434 * Second part of data - Public key
436 struct GNUNET_CRYPTO_EddsaPublicKey public_key;
442 * Continuation called with a status result.
445 * @param pow Proof-of-work value
446 * @param purpose Signed block (size, purpose, data)
447 * @param signature Signature, NULL on error
449 typedef void (*GNUNET_SENSOR_UTIL_pow_callback) (void *cls,
451 GNUNET_SENSOR_crypto_pow_block
456 * Cancel an operation started by #GNUNET_SENSOR_crypto_pow_sign().
457 * Call only before callback function passed to #GNUNET_SENSOR_crypto_pow_sign()
458 * is called with the result.
461 GNUNET_SENSOR_crypto_pow_sign_cancel (struct GNUNET_SENSOR_crypto_pow_context
466 * Calculate proof-of-work and sign a message.
468 * @param msg Message to calculate pow and sign
469 * @param msg_size size of msg
470 * @param timestamp Timestamp to add to the message to protect against replay attacks
471 * @param public_key Public key of the origin peer, to protect against redirect attacks
472 * @param private_key Private key of the origin peer to sign the result
473 * @param matching_bits Number of leading zeros required in the result hash
474 * @param callback Callback function to call with the result
475 * @param callback_cls Closure for callback
476 * @return Operation context
478 struct GNUNET_SENSOR_crypto_pow_context *
479 GNUNET_SENSOR_crypto_pow_sign (void *msg, size_t msg_size,
480 struct GNUNET_TIME_Absolute *timestamp,
481 struct GNUNET_CRYPTO_EddsaPublicKey *public_key,
482 struct GNUNET_CRYPTO_EddsaPrivateKey
483 *private_key, int matching_bits,
484 GNUNET_SENSOR_UTIL_pow_callback callback,
489 * Verify that proof-of-work and signature in the given block are valid.
490 * If all valid, a pointer to the payload within the block is set and the size
491 * of the payload is returned.
493 * **VERY IMPORTANT** : You will still need to verify the timestamp yourself.
495 * @param block The block received and needs to be verified
496 * @param matching_bits Number of leading zeros in the hash used to verify pow
497 * @param public_key Public key of the peer that sent this block
498 * @param payload Where to store the pointer to the payload
499 * @return Size of the payload
502 GNUNET_SENSOR_crypto_verify_pow_sign (struct GNUNET_SENSOR_crypto_pow_block *
503 block, int matching_bits,
504 struct GNUNET_CRYPTO_EddsaPublicKey *
505 public_key, void **payload);
508 #if 0 /* keep Emacsens' auto-indent happy */
515 /* ifndef GNUNET_SENSOR_UTIL_LIB_H */
518 /** @} */ /* end of group */
520 /* end of gnunet_sensor_util_lib.h */