2 This file is part of GNUnet.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * @author Omar Tarabai
25 * @defgroup sensor Sensor Utilities library
30 #ifndef GNUNET_SENSOR_UTIL_LIB_H
31 #define GNUNET_SENSOR_UTIL_LIB_H
36 #if 0 /* keep Emacsens' auto-indent happy */
42 * Structure containing sensor definition
44 struct GNUNET_SENSOR_SensorInfo
48 * The configuration handle
49 * carrying sensor information
51 struct GNUNET_CONFIGURATION_Handle *cfg;
59 * Path to definition file
64 * First part of version number
66 uint16_t version_major;
69 * Second part of version number
71 uint16_t version_minor;
79 * Sensor currently enabled
84 * Category under which the sensor falls (e.g. tcp, datastore)
89 * When does the sensor become active
91 struct GNUNET_TIME_Absolute *start_time;
94 * When does the sensor expire
96 struct GNUNET_TIME_Absolute *end_time;
99 * Time interval to collect sensor information (e.g. every 1 min)
101 struct GNUNET_TIME_Relative interval;
104 * Lifetime of an information sample after which it is deleted from storage
105 * If not supplied, will default to the interval value
107 struct GNUNET_TIME_Relative lifetime;
110 * A set of required peer capabilities for the sensor to collect meaningful information (e.g. ipv6)
115 * Either "gnunet-statistics" or external "process"
120 * Name of the GNUnet service that is the source for the gnunet-statistics entry
122 char *gnunet_stat_service;
125 * Name of the gnunet-statistics entry
127 char *gnunet_stat_name;
130 * Handle to statistics get request (OR NULL)
132 struct GNUNET_STATISTICS_GetHandle *gnunet_stat_get_handle;
135 * Name of the external process to be executed
140 * Arguments to be passed to the external process
145 * Handle to the external process
147 struct GNUNET_OS_CommandHandle *ext_cmd;
150 * Did we already receive a value
151 * from the currently running external
152 * proccess ? #GNUNET_YES / #GNUNET_NO
154 int ext_cmd_value_received;
157 * The output datatype to be expected
159 char *expected_datatype;
162 * Peer-identity of peer running collection point
164 struct GNUNET_PeerIdentity *collection_point;
167 * Do we report received sensor values to collection point?
168 * #GNUNET_YES / #GNUNET_NO
173 * Time interval to send sensor values to collection point (e.g. every 30 mins)
175 struct GNUNET_TIME_Relative value_reporting_interval;
178 * Do we report anomalies to collection point?
179 * #GNUNET_YES / #GNUNET_NO
181 int report_anomalies;
184 * Execution task (OR NULL)
186 struct GNUNET_SCHEDULER_Task * execution_task;
189 * Is the sensor being executed
196 * Anomaly report received and stored by sensor dashboard.
197 * Sensor name and peer id are not included because they are part of the
200 struct GNUNET_SENSOR_DashboardAnomalyEntry
209 * Percentage of neighbors reported the same anomaly
211 float anomalous_neighbors;
215 GNUNET_NETWORK_STRUCT_BEGIN
217 * Used to communicate brief information about a sensor.
219 struct GNUNET_SENSOR_SensorBriefMessage
223 * GNUNET general message header.
225 struct GNUNET_MessageHeader header;
228 * Size of sensor name string, allocated at position 0 after this struct.
233 * First part of sensor version number
235 uint16_t version_major;
238 * Second part of sensor version number
240 uint16_t version_minor;
245 * Used to communicate full information about a sensor.
247 struct GNUNET_SENSOR_SensorFullMessage
251 * GNUNET general message header.
253 struct GNUNET_MessageHeader header;
256 * Size of sensor name.
257 * Name allocated at position 0 after this struct.
259 uint16_t sensorname_size;
262 * Size of the sensor definition file carrying full sensor information.
263 * The file content allocated at position 1 after this struct.
265 uint16_t sensorfile_size;
268 * Name of the file (usually script) associated with this sensor.
269 * At the moment we only support having one file per sensor.
270 * The file name is allocated at position 2 after this struct.
272 uint16_t scriptname_size;
275 * Size of the file (usually script) associated with this sensor.
276 * The file content is allocated at position 3 after this struct.
278 uint16_t scriptfile_size;
283 * Used to communicate sensor values to
284 * collection points (SENSORDASHBAORD service)
286 struct GNUNET_SENSOR_ValueMessage
290 * GNUNET general message header
292 struct GNUNET_MessageHeader header;
295 * Hash of sensor name
297 struct GNUNET_HashCode sensorname_hash;
300 * First part of sensor version number
302 uint16_t sensorversion_major;
305 * Second part of sensor version number
307 uint16_t sensorversion_minor;
310 * Timestamp of recorded reading
312 struct GNUNET_TIME_Absolute timestamp;
315 * Size of sensor value, allocated at poistion 0 after this struct
322 * Message carrying an anomaly status change report
324 struct GNUNET_SENSOR_AnomalyReportMessage
328 * Hash of sensor name
330 struct GNUNET_HashCode sensorname_hash;
333 * First part of sensor version number
335 uint16_t sensorversion_major;
338 * Second part of sensor version name
340 uint16_t sensorversion_minor;
348 * Percentage of neighbors reported the same anomaly
350 float anomalous_neighbors;
354 GNUNET_NETWORK_STRUCT_END
356 * Given two version numbers as major and minor, compare them.
358 * @param v1_major First part of first version number
359 * @param v1_minor Second part of first version number
360 * @param v2_major First part of second version number
361 * @param v2_minor Second part of second version number
364 GNUNET_SENSOR_version_compare (uint16_t v1_major, uint16_t v1_minor,
365 uint16_t v2_major, uint16_t v2_minor);
369 * Reads sensor definitions from given sensor directory.
371 * @param sensordir Path to sensor directory.
372 * @return a multihashmap of loaded sensors
374 struct GNUNET_CONTAINER_MultiHashMap *
375 GNUNET_SENSOR_load_all_sensors (char *sensor_dir);
379 * Get path to the default directory containing the sensor definition files with
380 * a trailing directory separator.
382 * @return Default sensor files directory full path
385 GNUNET_SENSOR_get_default_sensor_dir ();
389 * Destroys a group of sensors in a hashmap and the hashmap itself
391 * @param sensors hashmap containing the sensors
394 GNUNET_SENSOR_destroy_sensors (struct GNUNET_CONTAINER_MultiHashMap *sensors);
397 struct GNUNET_SENSOR_crypto_pow_context;
400 * Block carrying arbitrary data + its proof-of-work + signature
402 struct GNUNET_SENSOR_crypto_pow_block
406 * Proof-of-work value
413 struct GNUNET_CRYPTO_EddsaSignature signature;
416 * Size of the msg component (allocated after this struct)
421 * Purpose of signing.
422 * Data is allocated after this (timestamp, public_key, msg).
424 struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
427 * First part of data - timestamp
429 struct GNUNET_TIME_Absolute timestamp;
432 * Second part of data - Public key
434 struct GNUNET_CRYPTO_EddsaPublicKey public_key;
440 * Continuation called with a status result.
443 * @param pow Proof-of-work value
444 * @param purpose Signed block (size, purpose, data)
445 * @param signature Signature, NULL on error
447 typedef void (*GNUNET_SENSOR_UTIL_pow_callback) (void *cls,
449 GNUNET_SENSOR_crypto_pow_block
454 * Cancel an operation started by #GNUNET_SENSOR_crypto_pow_sign().
455 * Call only before callback function passed to #GNUNET_SENSOR_crypto_pow_sign()
456 * is called with the result.
459 GNUNET_SENSOR_crypto_pow_sign_cancel (struct GNUNET_SENSOR_crypto_pow_context
464 * Calculate proof-of-work and sign a message.
466 * @param msg Message to calculate pow and sign
467 * @param msg_size size of msg
468 * @param timestamp Timestamp to add to the message to protect against replay attacks
469 * @param public_key Public key of the origin peer, to protect against redirect attacks
470 * @param private_key Private key of the origin peer to sign the result
471 * @param matching_bits Number of leading zeros required in the result hash
472 * @param callback Callback function to call with the result
473 * @param callback_cls Closure for callback
474 * @return Operation context
476 struct GNUNET_SENSOR_crypto_pow_context *
477 GNUNET_SENSOR_crypto_pow_sign (void *msg, size_t msg_size,
478 struct GNUNET_TIME_Absolute *timestamp,
479 struct GNUNET_CRYPTO_EddsaPublicKey *public_key,
480 struct GNUNET_CRYPTO_EddsaPrivateKey
481 *private_key, int matching_bits,
482 GNUNET_SENSOR_UTIL_pow_callback callback,
487 * Verify that proof-of-work and signature in the given block are valid.
488 * If all valid, a pointer to the payload within the block is set and the size
489 * of the payload is returned.
491 * **VERY IMPORTANT** : You will still need to verify the timestamp yourself.
493 * @param block The block received and needs to be verified
494 * @param matching_bits Number of leading zeros in the hash used to verify pow
495 * @param public_key Public key of the peer that sent this block
496 * @param payload Where to store the pointer to the payload
497 * @return Size of the payload
500 GNUNET_SENSOR_crypto_verify_pow_sign (struct GNUNET_SENSOR_crypto_pow_block *
501 block, int matching_bits,
502 struct GNUNET_CRYPTO_EddsaPublicKey *
503 public_key, void **payload);
506 #if 0 /* keep Emacsens' auto-indent happy */
513 /* ifndef GNUNET_SENSOR_UTIL_LIB_H */
516 /** @} */ /* end of group */
518 /* end of gnunet_sensor_util_lib.h */