aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-05-24 13:35:02 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-05-24 13:35:02 +0000
commit19245d6f6a0203849b2fa2244d36d981df2e762a (patch)
tree0be9c9a3730c0f2b23db9ae412cd45a457c6dc94
parentb1ac8481c7b2ea0725918f8a286bb7a89d888050 (diff)
downloadgnunet-19245d6f6a0203849b2fa2244d36d981df2e762a.tar.gz
gnunet-19245d6f6a0203849b2fa2244d36d981df2e762a.zip
parsing
-rw-r--r--src/experimentation/gnunet-daemon-experimentation_experiments.c158
1 files changed, 149 insertions, 9 deletions
diff --git a/src/experimentation/gnunet-daemon-experimentation_experiments.c b/src/experimentation/gnunet-daemon-experimentation_experiments.c
index 9740e1f77..78d536059 100644
--- a/src/experimentation/gnunet-daemon-experimentation_experiments.c
+++ b/src/experimentation/gnunet-daemon-experimentation_experiments.c
@@ -31,7 +31,37 @@
31#include "gnunet_statistics_service.h" 31#include "gnunet_statistics_service.h"
32#include "gnunet-daemon-experimentation.h" 32#include "gnunet-daemon-experimentation.h"
33 33
34struct GNUNET_CONTAINER_MultiHashMap *issuer; 34struct Experiment
35{
36 /* Header */
37
38 /* Experiment issuer */
39 struct GNUNET_PeerIdentity issuer;
40
41 /* Experiment version as timestamp of creation */
42 struct GNUNET_TIME_Absolute version;
43
44 /* Description */
45 char *description;
46
47 /* Required capabilities */
48 uint32_t required_capabilities;
49
50 /* Experiment itself */
51
52 /* TBD */
53};
54
55/**
56 * Hashmap containing valid experiment issuer
57 */
58static struct GNUNET_CONTAINER_MultiHashMap *valid_issuers;
59
60void
61GNUNET_EXPERIMENTATION_experiments_verify ()
62{
63
64}
35 65
36/** 66/**
37 * Is peer a valid issuer 67 * Is peer a valid issuer
@@ -41,12 +71,110 @@ struct GNUNET_CONTAINER_MultiHashMap *issuer;
41int 71int
42GNUNET_EXPERIMENTATION_experiments_issuer_accepted (struct GNUNET_PeerIdentity *issuer_ID) 72GNUNET_EXPERIMENTATION_experiments_issuer_accepted (struct GNUNET_PeerIdentity *issuer_ID)
43{ 73{
44 if (GNUNET_CONTAINER_multihashmap_contains (issuer, &issuer_ID->hashPubKey)) 74 if (GNUNET_CONTAINER_multihashmap_contains (valid_issuers, &issuer_ID->hashPubKey))
45 return GNUNET_YES; 75 return GNUNET_YES;
46 else 76 else
47 return GNUNET_NO; 77 return GNUNET_NO;
48} 78}
49 79
80void exp_file_iterator (void *cls,
81 const char *section)
82{
83 struct GNUNET_CONFIGURATION_Handle *exp = cls;
84 struct Experiment *e;
85 struct Issuer *i;
86
87 char *val;
88 unsigned long long number;
89
90 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Parsing section `%s'\n", section);
91
92 e = GNUNET_malloc (sizeof (struct Experiment));
93 /* Mandatory fields */
94
95 /* Issuer */
96 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (exp, section, "ISSUER", &val))
97 {
98 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Section `%s': Issuer missing\n", section);
99 GNUNET_free (e);
100 return;
101 }
102 if (GNUNET_SYSERR == GNUNET_CRYPTO_hash_from_string (section, &e->issuer.hashPubKey))
103 {
104 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Section `%s': Issuer invalid\n", section);
105 GNUNET_free (val);
106 GNUNET_free (e);
107 return;
108 }
109 if (NULL == (i = GNUNET_CONTAINER_multihashmap_get (valid_issuers, &e->issuer.hashPubKey)))
110 {
111 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Section `%s': Issuer not accepted!\n", section);
112 GNUNET_free (val);
113 GNUNET_free (e);
114 return;
115 }
116
117 GNUNET_free (val);
118
119 /* Version */
120 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (exp, section, "VERSION", &number))
121 {
122 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Section `%s': Version missing \n", section);
123 GNUNET_free (e);
124 return;
125 }
126 e->version.abs_value = number;
127
128 /* Required capabilities */
129 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (exp, section, "CAPABILITIES", &number))
130 {
131 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Section `%s': Required capabilities missing \n", section);
132 GNUNET_free (e);
133 return;
134 }
135 if (number > UINT32_MAX)
136 {
137 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Section `%s': Required capabilities invalid \n", section);
138 GNUNET_free (e);
139 return;
140 }
141 e->required_capabilities = number;
142
143 /* Optional fields */
144
145 /* Description */
146 GNUNET_CONFIGURATION_get_value_string (exp, section, "DESCRIPTION", &e->description);
147
148
149 /* verify experiment */
150
151}
152
153/**
154 * Load experiments from file
155 * FIXME: Not yet sure how to store that on disk ...
156 *
157 * @param file source file
158 */
159
160static void
161load_file (const char * file)
162{
163 struct GNUNET_CONFIGURATION_Handle *exp = GNUNET_CONFIGURATION_create();
164 if (NULL == exp)
165 return;
166
167 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_parse (exp, file))
168 {
169 GNUNET_CONFIGURATION_destroy (exp);
170 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to parse file `%s'\n"), file);
171 return;
172 }
173
174 GNUNET_CONFIGURATION_iterate_sections (exp, &exp_file_iterator, exp);
175
176 GNUNET_CONFIGURATION_destroy (exp);
177}
50 178
51/** 179/**
52 * Start experiments management 180 * Start experiments management
@@ -55,6 +183,7 @@ int
55GNUNET_EXPERIMENTATION_experiments_start () 183GNUNET_EXPERIMENTATION_experiments_start ()
56{ 184{
57 char *issuers; 185 char *issuers;
186 char *file;
58 char *pos; 187 char *pos;
59 struct GNUNET_PeerIdentity issuer_ID; 188 struct GNUNET_PeerIdentity issuer_ID;
60 189
@@ -65,7 +194,7 @@ GNUNET_EXPERIMENTATION_experiments_start ()
65 return GNUNET_SYSERR; 194 return GNUNET_SYSERR;
66 } 195 }
67 196
68 issuer = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO); 197 valid_issuers = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO);
69 198
70 for (pos = strtok (issuers, " "); pos != NULL; pos = strtok (NULL, " ")) 199 for (pos = strtok (issuers, " "); pos != NULL; pos = strtok (NULL, " "))
71 { 200 {
@@ -77,20 +206,31 @@ GNUNET_EXPERIMENTATION_experiments_start ()
77 else 206 else
78 { 207 {
79 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "`%s' is a valid issuer \n", GNUNET_i2s (&issuer_ID)); 208 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "`%s' is a valid issuer \n", GNUNET_i2s (&issuer_ID));
80 GNUNET_CONTAINER_multihashmap_put (issuer, &issuer_ID.hashPubKey, 209 GNUNET_CONTAINER_multihashmap_put (valid_issuers, &issuer_ID.hashPubKey,
81 NULL, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); 210 NULL, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
82 } 211 }
83 } 212 }
84 GNUNET_free (issuers); 213 GNUNET_free (issuers);
85 214
86 if (0 == GNUNET_CONTAINER_multihashmap_size (issuer)) 215 if (0 == GNUNET_CONTAINER_multihashmap_size (valid_issuers))
87 { 216 {
88 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("No valid experiment issuers configured! Set value to peer id of issuer! Exit...\n")); 217 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("No valid experiment issuers configured! Set value to peer id of issuer! Exit...\n"));
89 GNUNET_EXPERIMENTATION_experiments_stop (); 218 GNUNET_EXPERIMENTATION_experiments_stop ();
90 return GNUNET_SYSERR; 219 return GNUNET_SYSERR;
91 } 220 }
221 GNUNET_STATISTICS_set (GSE_stats, "# issuer", GNUNET_CONTAINER_multihashmap_size (valid_issuers), GNUNET_NO);
222
223 /* Load experiments from file */
224 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (GSE_cfg, "EXPERIMENTATION", "EXPERIMENTS", &file))
225 return GNUNET_OK;
226
227 if (GNUNET_YES != GNUNET_DISK_file_test (file))
228 {
229 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Cannot read experiments file `%s'\n"), file);
230 return GNUNET_OK;
231 }
232 load_file (file);
92 233
93 GNUNET_STATISTICS_set (GSE_stats, "# issuer", GNUNET_CONTAINER_multihashmap_size (issuer), GNUNET_NO);
94 return GNUNET_OK; 234 return GNUNET_OK;
95} 235}
96 236
@@ -100,9 +240,9 @@ GNUNET_EXPERIMENTATION_experiments_start ()
100void 240void
101GNUNET_EXPERIMENTATION_experiments_stop () 241GNUNET_EXPERIMENTATION_experiments_stop ()
102{ 242{
103 if (NULL != issuer) 243 if (NULL != valid_issuers)
104 GNUNET_CONTAINER_multihashmap_destroy (issuer); 244 GNUNET_CONTAINER_multihashmap_destroy (valid_issuers);
105 issuer = NULL; 245 valid_issuers = NULL;
106} 246}
107 247
108/* end of gnunet-daemon-experimentation_experiments.c */ 248/* end of gnunet-daemon-experimentation_experiments.c */