diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2013-05-28 09:35:18 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2013-05-28 09:35:18 +0000 |
commit | a15d65e1933ba6def1c2519c32d14edf9d70b4cc (patch) | |
tree | 93e2d0bb2d45dee2e9d17d037f3ff579403e8214 | |
parent | eaea0bc446148dd6e211d13a15457c77b879f3a1 (diff) | |
download | gnunet-a15d65e1933ba6def1c2519c32d14edf9d70b4cc.tar.gz gnunet-a15d65e1933ba6def1c2519c32d14edf9d70b4cc.zip |
changes
-rw-r--r-- | src/experimentation/gnunet-daemon-experimentation_experiments.c | 79 |
1 files changed, 75 insertions, 4 deletions
diff --git a/src/experimentation/gnunet-daemon-experimentation_experiments.c b/src/experimentation/gnunet-daemon-experimentation_experiments.c index 26157666a..d6ee32c56 100644 --- a/src/experimentation/gnunet-daemon-experimentation_experiments.c +++ b/src/experimentation/gnunet-daemon-experimentation_experiments.c | |||
@@ -54,6 +54,11 @@ static struct GNUNET_CONTAINER_MultiHashMap *valid_issuers; | |||
54 | static struct GNUNET_CONTAINER_MultiHashMap *experiments; | 54 | static struct GNUNET_CONTAINER_MultiHashMap *experiments; |
55 | 55 | ||
56 | 56 | ||
57 | uint32_t GSE_my_issuer_count; | ||
58 | |||
59 | struct Experimentation_Request_Issuer *GSE_my_issuer; | ||
60 | |||
61 | |||
57 | /** | 62 | /** |
58 | * Verify experiment signature | 63 | * Verify experiment signature |
59 | * | 64 | * |
@@ -102,6 +107,20 @@ int free_issuer (void *cls, | |||
102 | return GNUNET_OK; | 107 | return GNUNET_OK; |
103 | } | 108 | } |
104 | 109 | ||
110 | int create_issuer (void *cls, | ||
111 | const struct GNUNET_HashCode * key, | ||
112 | void *value) | ||
113 | { | ||
114 | static int i = 0; | ||
115 | GNUNET_assert (i < GSE_my_issuer_count); | ||
116 | GSE_my_issuer[i].issuer_id.hashPubKey = *key; | ||
117 | |||
118 | i++; | ||
119 | return GNUNET_OK; | ||
120 | |||
121 | } | ||
122 | |||
123 | |||
105 | 124 | ||
106 | /** | 125 | /** |
107 | * Is peer a valid issuer | 126 | * Is peer a valid issuer |
@@ -117,6 +136,51 @@ GNUNET_EXPERIMENTATION_experiments_issuer_accepted (struct GNUNET_PeerIdentity * | |||
117 | return GNUNET_NO; | 136 | return GNUNET_NO; |
118 | } | 137 | } |
119 | 138 | ||
139 | struct GetCtx | ||
140 | { | ||
141 | struct Node *n; | ||
142 | GNUNET_EXPERIMENTATION_experiments_get_cb get_cb; | ||
143 | }; | ||
144 | |||
145 | static int | ||
146 | get_it (void *cls, | ||
147 | const struct GNUNET_HashCode * key, | ||
148 | void *value) | ||
149 | { | ||
150 | struct GetCtx *get_ctx = cls; | ||
151 | struct Experiment *e = value; | ||
152 | |||
153 | /* Check compability */ | ||
154 | if (get_ctx->n->version.abs_value != e->version.abs_value) | ||
155 | return GNUNET_OK; | ||
156 | |||
157 | get_ctx->get_cb (get_ctx->n, e); | ||
158 | |||
159 | return GNUNET_OK; | ||
160 | } | ||
161 | |||
162 | |||
163 | |||
164 | |||
165 | void | ||
166 | GNUNET_EXPERIMENTATION_experiments_get (struct Node *n, | ||
167 | struct GNUNET_PeerIdentity *issuer, | ||
168 | GNUNET_EXPERIMENTATION_experiments_get_cb get_cb) | ||
169 | { | ||
170 | struct GetCtx get_ctx; | ||
171 | |||
172 | GNUNET_assert (NULL != n); | ||
173 | GNUNET_assert (NULL != experiments); | ||
174 | GNUNET_assert (NULL != get_cb); | ||
175 | |||
176 | get_ctx.n = n; | ||
177 | get_ctx.get_cb = get_cb; | ||
178 | |||
179 | GNUNET_CONTAINER_multihashmap_get_multiple (experiments, | ||
180 | &issuer->hashPubKey, &get_it, &get_ctx); | ||
181 | |||
182 | get_cb (n, NULL); | ||
183 | } | ||
120 | 184 | ||
121 | /** | 185 | /** |
122 | * Add a new experiment | 186 | * Add a new experiment |
@@ -146,8 +210,6 @@ int GNUNET_EXPERIMENTATION_experiments_add (struct Issuer *i, | |||
146 | e->duration = duration; | 210 | e->duration = duration; |
147 | e->stop = stop; | 211 | e->stop = stop; |
148 | 212 | ||
149 | |||
150 | |||
151 | /* verify experiment */ | 213 | /* verify experiment */ |
152 | if (GNUNET_SYSERR == experiment_verify (i, e)) | 214 | if (GNUNET_SYSERR == experiment_verify (i, e)) |
153 | { | 215 | { |
@@ -167,8 +229,6 @@ int GNUNET_EXPERIMENTATION_experiments_add (struct Issuer *i, | |||
167 | GNUNET_CONTAINER_multihashmap_put (experiments, &e->issuer.hashPubKey, e, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 229 | GNUNET_CONTAINER_multihashmap_put (experiments, &e->issuer.hashPubKey, e, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
168 | GNUNET_STATISTICS_set (GSE_stats, "# experiments", GNUNET_CONTAINER_multihashmap_size (experiments), GNUNET_NO); | 230 | GNUNET_STATISTICS_set (GSE_stats, "# experiments", GNUNET_CONTAINER_multihashmap_size (experiments), GNUNET_NO); |
169 | 231 | ||
170 | GNUNET_EXPERIMENTATION_scheduler_add (e); | ||
171 | |||
172 | return GNUNET_OK; | 232 | return GNUNET_OK; |
173 | } | 233 | } |
174 | 234 | ||
@@ -357,6 +417,11 @@ GNUNET_EXPERIMENTATION_experiments_start () | |||
357 | GNUNET_free (pubkey); | 417 | GNUNET_free (pubkey); |
358 | } | 418 | } |
359 | 419 | ||
420 | GSE_my_issuer_count = GNUNET_CONTAINER_multihashmap_size (valid_issuers); | ||
421 | GSE_my_issuer = GNUNET_malloc (GSE_my_issuer_count * sizeof (struct Experimentation_Request_Issuer)); | ||
422 | GNUNET_CONTAINER_multihashmap_iterate (valid_issuers, &create_issuer, GSE_my_issuer); | ||
423 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Daemon has %u issuers\n"), GSE_my_issuer_count); | ||
424 | |||
360 | experiments = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO); | 425 | experiments = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO); |
361 | /* Load experiments from file */ | 426 | /* Load experiments from file */ |
362 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (GSE_cfg, "EXPERIMENTATION", "EXPERIMENTS", &file)) | 427 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (GSE_cfg, "EXPERIMENTATION", "EXPERIMENTS", &file)) |
@@ -380,6 +445,12 @@ GNUNET_EXPERIMENTATION_experiments_start () | |||
380 | void | 445 | void |
381 | GNUNET_EXPERIMENTATION_experiments_stop () | 446 | GNUNET_EXPERIMENTATION_experiments_stop () |
382 | { | 447 | { |
448 | if (NULL != GSE_my_issuer) | ||
449 | { | ||
450 | GNUNET_free (GSE_my_issuer); | ||
451 | GSE_my_issuer = NULL; | ||
452 | GSE_my_issuer_count = 0; | ||
453 | } | ||
383 | if (NULL != valid_issuers) | 454 | if (NULL != valid_issuers) |
384 | { | 455 | { |
385 | GNUNET_CONTAINER_multihashmap_iterate (valid_issuers, &free_issuer, NULL); | 456 | GNUNET_CONTAINER_multihashmap_iterate (valid_issuers, &free_issuer, NULL); |