aboutsummaryrefslogtreecommitdiff
path: root/src/escrow/escrow_plugin_helper.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/escrow/escrow_plugin_helper.c')
-rw-r--r--src/escrow/escrow_plugin_helper.c154
1 files changed, 103 insertions, 51 deletions
diff --git a/src/escrow/escrow_plugin_helper.c b/src/escrow/escrow_plugin_helper.c
index 25648dfa1..3ed5ddabe 100644
--- a/src/escrow/escrow_plugin_helper.c
+++ b/src/escrow/escrow_plugin_helper.c
@@ -198,8 +198,52 @@ string_to_upper (const char *str)
198} 198}
199 199
200 200
201static int
202write_config (struct GNUNET_ESCROW_Handle *h)
203{
204 char *conf_file;
205
206 GNUNET_assert (GNUNET_OK ==
207 GNUNET_CONFIGURATION_get_value_filename (h->cfg,
208 "PATHS",
209 "DEFAULTCONFIG",
210 &conf_file));
211 if (GNUNET_OK != GNUNET_CONFIGURATION_write (h->cfg, conf_file))
212 {
213 fprintf (stderr, "unable to write config file\n");
214 GNUNET_free (conf_file);
215 return GNUNET_NO;
216 }
217
218 GNUNET_free (conf_file);
219
220 return GNUNET_OK;
221}
222
223
224static char *
225get_config_section (struct GNUNET_IDENTITY_Ego *ego)
226{
227 struct GNUNET_CRYPTO_EcdsaPublicKey *pub;
228 char *config_section, *pubkey_string;
229
230 pub = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey);
231 GNUNET_IDENTITY_ego_get_public_key (ego, pub);
232 pubkey_string = GNUNET_CRYPTO_ecdsa_public_key_to_string (pub);
233
234 // allocate enough space for "escrow-PUBKEY"
235 config_section = GNUNET_malloc (7 + strlen (pubkey_string) + 1);
236 sprintf (config_section, "escrow-%s", pubkey_string);
237
238 GNUNET_free (pubkey_string);
239
240 return config_section;
241}
242
243
201/** 244/**
202 * Update the status of an escrow in the configuration. 245 * Update the status of an escrow in the configuration after a successful
246 * VERIFY operation.
203 * 247 *
204 * @param h handle for the escrow component 248 * @param h handle for the escrow component
205 * @param ego the ego of which the escrow status is updated 249 * @param ego the ego of which the escrow status is updated
@@ -208,81 +252,89 @@ string_to_upper (const char *str)
208 * @return GNUNET_OK on success 252 * @return GNUNET_OK on success
209 */ 253 */
210int 254int
211ESCROW_update_escrow_status (struct GNUNET_ESCROW_Handle *h, 255ESCROW_update_escrow_status_verify (struct GNUNET_ESCROW_Handle *h,
212 struct GNUNET_IDENTITY_Ego *ego, 256 struct GNUNET_IDENTITY_Ego *ego,
213 const char *plugin_name) 257 const char *plugin_name)
214{ 258{
215 struct GNUNET_CRYPTO_EcdsaPublicKey *pub; 259 char *config_section, *config_option, *plugin_name_upper;
216 char *config_section, *pubkey_string, *config_option, *plugin_name_upper; 260 struct GNUNET_TIME_Absolute now, next_verification;
217 struct GNUNET_TIME_Absolute now, next_escrow;
218 struct GNUNET_TIME_Relative escrow_interval; 261 struct GNUNET_TIME_Relative escrow_interval;
219 char *conf_file;
220 262
221 pub = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey); 263 config_section = get_config_section (ego);
222 GNUNET_IDENTITY_ego_get_public_key (ego, pub);
223 pubkey_string = GNUNET_CRYPTO_ecdsa_public_key_to_string (pub);
224
225 // allocate enough space for "escrow-PUBKEY"
226 config_section = GNUNET_malloc (7 + strlen (pubkey_string) + 1);
227 sprintf (config_section, "escrow-%s", pubkey_string);
228 264
229 // allocate enough space for "<plugin_name>_INTERVAL" 265 // allocate enough space for "<plugin_name>_INTERVAL"
230 config_option = GNUNET_malloc (strlen (plugin_name) + 9 + 1); 266 config_option = GNUNET_malloc (strlen (plugin_name) + 9 + 1);
231 plugin_name_upper = string_to_upper (plugin_name); 267 plugin_name_upper = string_to_upper (plugin_name);
232 sprintf (config_option, "%s_INTERVAL", plugin_name_upper); 268 sprintf (config_option, "%s_VERIFY_INTERVAL", plugin_name_upper);
233 269
234 now = GNUNET_TIME_absolute_get (); 270 now = GNUNET_TIME_absolute_get ();
235 GNUNET_CONFIGURATION_set_value_number (h->cfg, 271 GNUNET_CONFIGURATION_set_value_number (h->cfg,
236 config_section, 272 config_section,
237 "LAST_ESCROW_TIME", 273 "LAST_SUCCESSFUL_VERIFICATION_TIME",
238 (unsigned long long)now.abs_value_us); 274 (unsigned long long)now.abs_value_us);
239 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (h->cfg, 275 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (h->cfg,
240 "escrow", 276 "escrow",
241 config_option, 277 config_option,
242 &escrow_interval)) 278 &escrow_interval))
243 { 279 {
244 fprintf (stderr, "could not find config value for escrow interval\n"); 280 fprintf (stderr, "could not find config value for verification interval\n");
245 GNUNET_free (pub);
246 GNUNET_free (config_section); 281 GNUNET_free (config_section);
247 GNUNET_free (pubkey_string);
248 GNUNET_free (config_option); 282 GNUNET_free (config_option);
249 GNUNET_free (plugin_name_upper); 283 GNUNET_free (plugin_name_upper);
250 return GNUNET_NO; 284 return GNUNET_NO;
251 } 285 }
252 next_escrow = GNUNET_TIME_absolute_add (now, escrow_interval); 286 next_verification = GNUNET_TIME_absolute_add (now, escrow_interval);
253 GNUNET_CONFIGURATION_set_value_number (h->cfg, 287 GNUNET_CONFIGURATION_set_value_number (h->cfg,
254 config_section, 288 config_section,
255 "NEXT_RECOMMENDED_ESCROW_TIME", 289 "NEXT_RECOMMENDED_VERIFICATION_TIME",
256 (unsigned long long)next_escrow.abs_value_us); 290 (unsigned long long)next_verification.abs_value_us);
291
292 if (GNUNET_OK != write_config (h))
293 {
294 GNUNET_free (config_section);
295 GNUNET_free (config_option);
296 GNUNET_free (plugin_name_upper);
297 return GNUNET_NO;
298 }
299
300 GNUNET_free (config_section);
301 GNUNET_free (config_option);
302 GNUNET_free (plugin_name_upper);
303
304 return GNUNET_OK;
305}
306
307
308/**
309 * Update the status of an escrow in the configuration after a PUT operation.
310 *
311 * @param h handle for the escrow component
312 * @param ego the ego of which the escrow status is updated
313 * @param plugin_name the name of the used plugin
314 *
315 * @return GNUNET_OK on success
316 */
317int
318ESCROW_update_escrow_status_put (struct GNUNET_ESCROW_Handle *h,
319 struct GNUNET_IDENTITY_Ego *ego,
320 const char *plugin_name)
321{
322 char *config_section;
323
324 config_section = get_config_section (ego);
257 325
258 GNUNET_CONFIGURATION_set_value_string (h->cfg, 326 GNUNET_CONFIGURATION_set_value_string (h->cfg,
259 config_section, 327 config_section,
260 "ESCROW_METHOD", 328 "ESCROW_METHOD",
261 plugin_name); 329 plugin_name);
262 330
263 GNUNET_assert (GNUNET_OK == 331 if (GNUNET_OK != write_config (h))
264 GNUNET_CONFIGURATION_get_value_filename (h->cfg,
265 "PATHS",
266 "DEFAULTCONFIG",
267 &conf_file));
268 if (GNUNET_OK != GNUNET_CONFIGURATION_write (h->cfg, conf_file))
269 { 332 {
270 fprintf (stderr, "unable to write config file\n");
271 GNUNET_free (pub);
272 GNUNET_free (config_section); 333 GNUNET_free (config_section);
273 GNUNET_free (pubkey_string);
274 GNUNET_free (config_option);
275 GNUNET_free (plugin_name_upper);
276 GNUNET_free (conf_file);
277 return GNUNET_NO; 334 return GNUNET_NO;
278 } 335 }
279 336
280 GNUNET_free (pub);
281 GNUNET_free (config_section); 337 GNUNET_free (config_section);
282 GNUNET_free (pubkey_string);
283 GNUNET_free (config_option);
284 GNUNET_free (plugin_name_upper);
285 GNUNET_free (conf_file);
286 338
287 return GNUNET_OK; 339 return GNUNET_OK;
288} 340}
@@ -301,7 +353,7 @@ ESCROW_get_escrow_status (struct GNUNET_ESCROW_Handle *h,
301 struct GNUNET_IDENTITY_Ego *ego) 353 struct GNUNET_IDENTITY_Ego *ego)
302{ 354{
303 struct GNUNET_ESCROW_Status *status; 355 struct GNUNET_ESCROW_Status *status;
304 unsigned long long conf_last_escrow, conf_next_escrow; 356 unsigned long long conf_last_verification, conf_next_verification;
305 struct GNUNET_CRYPTO_EcdsaPublicKey *pub; 357 struct GNUNET_CRYPTO_EcdsaPublicKey *pub;
306 char *config_section, *pubkey_string, *conf_escrow_method; 358 char *config_section, *pubkey_string, *conf_escrow_method;
307 359
@@ -316,25 +368,25 @@ ESCROW_get_escrow_status (struct GNUNET_ESCROW_Handle *h,
316 status = GNUNET_new (struct GNUNET_ESCROW_Status); 368 status = GNUNET_new (struct GNUNET_ESCROW_Status);
317 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (h->cfg, 369 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (h->cfg,
318 config_section, 370 config_section,
319 "LAST_ESCROW_TIME", 371 "LAST_SUCCESSFUL_VERIFICATION_TIME",
320 &conf_last_escrow)) 372 &conf_last_verification))
321 { 373 {
322 /* failed to get value from config, set last escrow time to zero */ 374 /* failed to get value from config, set last verification time to zero */
323 status->last_escrow_time = GNUNET_TIME_absolute_get_zero_(); 375 status->last_successful_verification_time = GNUNET_TIME_absolute_get_zero_();
324 } 376 }
325 else 377 else
326 status->last_escrow_time.abs_value_us = (uint64_t)conf_last_escrow; 378 status->last_successful_verification_time.abs_value_us = (uint64_t)conf_last_verification;
327 379
328 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (h->cfg, 380 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (h->cfg,
329 config_section, 381 config_section,
330 "NEXT_RECOMMENDED_ESCROW_TIME", 382 "NEXT_RECOMMENDED_VERIFICATION_TIME",
331 &conf_next_escrow)) 383 &conf_next_verification))
332 { 384 {
333 /* failed to get value from config, set next recommended escrow to now */ 385 /* failed to get value from config, set next recommended verification to now */
334 status->next_recommended_escrow_time = GNUNET_TIME_absolute_get (); 386 status->next_recommended_verification_time = GNUNET_TIME_absolute_get ();
335 } 387 }
336 else 388 else
337 status->next_recommended_escrow_time.abs_value_us = (uint64_t)conf_next_escrow; 389 status->next_recommended_verification_time.abs_value_us = (uint64_t)conf_next_verification;
338 390
339 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (h->cfg, 391 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (h->cfg,
340 config_section, 392 config_section,