2 This file is part of GNUnet.
3 (C) 2009 Christian Grothoff (and other contributing authors)
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 experimentation/gnunet-daemon-experimentation_experiments.c
23 * @brief experimentation daemon: experiment management
24 * @author Christian Grothoff
25 * @author Matthias Wachs
28 #include "gnunet_getopt_lib.h"
29 #include "gnunet_util_lib.h"
30 #include "gnunet_core_service.h"
31 #include "gnunet_statistics_service.h"
32 #include "gnunet-daemon-experimentation.h"
38 /* Experiment issuer */
39 struct GNUNET_PeerIdentity issuer;
41 /* Experiment version as timestamp of creation */
42 struct GNUNET_TIME_Absolute version;
47 /* Required capabilities */
48 uint32_t required_capabilities;
50 /* Experiment itself */
56 * Hashmap containing valid experiment issuer
58 static struct GNUNET_CONTAINER_MultiHashMap *valid_issuers;
61 GNUNET_EXPERIMENTATION_experiments_verify ()
67 * Is peer a valid issuer
69 * @return GNUNET_YES or GNUNET_NO
72 GNUNET_EXPERIMENTATION_experiments_issuer_accepted (struct GNUNET_PeerIdentity *issuer_ID)
74 if (GNUNET_CONTAINER_multihashmap_contains (valid_issuers, &issuer_ID->hashPubKey))
80 void exp_file_iterator (void *cls,
83 struct GNUNET_CONFIGURATION_Handle *exp = cls;
88 unsigned long long number;
90 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Parsing section `%s'\n", section);
92 e = GNUNET_malloc (sizeof (struct Experiment));
93 /* Mandatory fields */
96 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (exp, section, "ISSUER", &val))
98 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Section `%s': Issuer missing\n", section);
102 if (GNUNET_SYSERR == GNUNET_CRYPTO_hash_from_string (section, &e->issuer.hashPubKey))
104 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Section `%s': Issuer invalid\n", section);
109 if (NULL == (i = GNUNET_CONTAINER_multihashmap_get (valid_issuers, &e->issuer.hashPubKey)))
111 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Section `%s': Issuer not accepted!\n", section);
120 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (exp, section, "VERSION", &number))
122 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Section `%s': Version missing \n", section);
126 e->version.abs_value = number;
128 /* Required capabilities */
129 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (exp, section, "CAPABILITIES", &number))
131 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Section `%s': Required capabilities missing \n", section);
135 if (number > UINT32_MAX)
137 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Section `%s': Required capabilities invalid \n", section);
141 e->required_capabilities = number;
143 /* Optional fields */
146 GNUNET_CONFIGURATION_get_value_string (exp, section, "DESCRIPTION", &e->description);
149 /* verify experiment */
154 * Load experiments from file
155 * FIXME: Not yet sure how to store that on disk ...
157 * @param file source file
161 load_file (const char * file)
163 struct GNUNET_CONFIGURATION_Handle *exp = GNUNET_CONFIGURATION_create();
167 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_parse (exp, file))
169 GNUNET_CONFIGURATION_destroy (exp);
170 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to parse file `%s'\n"), file);
174 GNUNET_CONFIGURATION_iterate_sections (exp, &exp_file_iterator, exp);
176 GNUNET_CONFIGURATION_destroy (exp);
180 * Start experiments management
183 GNUNET_EXPERIMENTATION_experiments_start ()
188 struct GNUNET_PeerIdentity issuer_ID;
190 /* Load valid issuer */
191 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (GSE_cfg, "EXPERIMENTATION", "ISSUERS", &issuers))
193 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("No valid experiment issuers configured! Set value to peer id of issuer! Exit...\n"));
194 return GNUNET_SYSERR;
197 valid_issuers = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO);
199 for (pos = strtok (issuers, " "); pos != NULL; pos = strtok (NULL, " "))
202 if (GNUNET_SYSERR == GNUNET_CRYPTO_hash_from_string (pos, &issuer_ID.hashPubKey))
204 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Invalid value `%s'\n"), pos);
208 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "`%s' is a valid issuer \n", GNUNET_i2s (&issuer_ID));
209 GNUNET_CONTAINER_multihashmap_put (valid_issuers, &issuer_ID.hashPubKey,
210 NULL, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
213 GNUNET_free (issuers);
215 if (0 == GNUNET_CONTAINER_multihashmap_size (valid_issuers))
217 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("No valid experiment issuers configured! Set value to peer id of issuer! Exit...\n"));
218 GNUNET_EXPERIMENTATION_experiments_stop ();
219 return GNUNET_SYSERR;
221 GNUNET_STATISTICS_set (GSE_stats, "# issuer", GNUNET_CONTAINER_multihashmap_size (valid_issuers), GNUNET_NO);
223 /* Load experiments from file */
224 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (GSE_cfg, "EXPERIMENTATION", "EXPERIMENTS", &file))
227 if (GNUNET_YES != GNUNET_DISK_file_test (file))
229 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Cannot read experiments file `%s'\n"), file);
238 * Stop experiments management
241 GNUNET_EXPERIMENTATION_experiments_stop ()
243 if (NULL != valid_issuers)
244 GNUNET_CONTAINER_multihashmap_destroy (valid_issuers);
245 valid_issuers = NULL;
248 /* end of gnunet-daemon-experimentation_experiments.c */