static void run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_TESTING_Peer *peer) { directory = NULL; GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", "GNUNET_TEST_HOME", &directory)); GNUNET_DISK_directory_remove (directory); endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &endbadly, NULL); nsh = GNUNET_NAMESTORE_connect (cfg); GNUNET_break (NULL != nsh); /* first, iterate over empty namestore */ zi = GNUNET_NAMESTORE_zone_iteration_start(nsh, NULL, &fail_cb, NULL, &empty_zone_proc, nsh, &empty_zone_end, nsh); if (NULL == zi) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create zone iterator\n"); GNUNET_break (0); GNUNET_SCHEDULER_cancel (endbadly_task); endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); } }
/** * * Update identity information for ego. If attribute map is * dirty, first update the attributes. * * @param cls the ego to update * param tc task context * */ static void update_identities(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct EgoEntry *next_ego = cls; const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key; if (NULL == next_ego) { if (min_rel_exp.rel_value_us < MIN_WAIT_TIME.rel_value_us) min_rel_exp = MIN_WAIT_TIME; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, ">>> Finished. Rescheduling in %d\n", min_rel_exp.rel_value_us); ns_it = NULL; //finished -> TODO reschedule update_task = GNUNET_SCHEDULER_add_delayed (min_rel_exp, &update_identities, ego_head); min_rel_exp.rel_value_us = 0; return; } priv_key = GNUNET_IDENTITY_ego_get_private_key (next_ego->ego); if (GNUNET_YES == next_ego->attributes_dirty) { //Starting over. We must update the Attributes for they might have changed. ns_it = GNUNET_NAMESTORE_zone_iteration_start (ns_handle, priv_key, &attribute_collect, next_ego); } else { //Ego will be dirty next time next_ego->attributes_dirty = GNUNET_YES; ns_it = GNUNET_NAMESTORE_zone_iteration_start (ns_handle, priv_key, &token_collect, next_ego); } }
/** * Handler that returns FCFS zoneinfo page. * * @param connection connection to use * @return MHD_YES on success */ static int serve_zoneinfo_page (struct MHD_Connection *connection) { struct ZoneinfoRequest *zr; zr = GNUNET_new (struct ZoneinfoRequest); zr->zoneinfo = GNUNET_malloc (DEFAULT_ZONEINFO_BUFSIZE); zr->buf_len = DEFAULT_ZONEINFO_BUFSIZE; zr->connection = connection; zr->write_offset = 0; zr->list_it = GNUNET_NAMESTORE_zone_iteration_start (ns, &fcfs_zone_pkey, &iterate_cb, zr); return MHD_YES; }
static void put_cont (void *cls, int32_t success, const char *emsg) { static int c = 0; if (success == GNUNET_OK) { c++; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record %u \n", c); } else { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to created records: `%s'\n", emsg); GNUNET_break (0); if (NULL != endbadly_task) GNUNET_SCHEDULER_cancel (endbadly_task); endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); return; } if (c == 3) { res = 1; returned_records = 0; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All records created, starting iteration over all zones \n"); zi = GNUNET_NAMESTORE_zone_iteration_start (nsh, NULL, &fail_cb, NULL, &zone_proc, NULL, &zone_proc_end, NULL); if (zi == NULL) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create zone iterator\n"); GNUNET_break (0); if (NULL != endbadly_task) GNUNET_SCHEDULER_cancel (endbadly_task); endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); return; } } }
/** * Periodically iterate over our zone and store everything in dht * * @param cls NULL * @param tc task context */ static void update_zone_dht_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { unsigned long long interval = 0; zone_update_taskid = GNUNET_SCHEDULER_NO_TASK; GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Scheduling DHT zone update!\n"); if (0 == num_public_records) { /** * If no records are known (startup) or none present * we can safely set the interval to 1s */ record_put_interval = GNUNET_TIME_relative_multiply( GNUNET_TIME_UNIT_SECONDS, 1); GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "No records in db. Adjusted record put interval to 1s\n"); } else { interval = max_record_put_interval/num_public_records; if (interval == 0) interval = 1; record_put_interval = GNUNET_TIME_relative_multiply( GNUNET_TIME_UNIT_SECONDS, interval); GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Adjusted DHT update interval to %ds!\n", interval); } /* start counting again */ num_public_records = 0; namestore_iter = GNUNET_NAMESTORE_zone_iteration_start (namestore_handle, NULL, //All zones GNUNET_NAMESTORE_RF_AUTHORITY, GNUNET_NAMESTORE_RF_PRIVATE, &put_gns_record, NULL); }
/** * Function called with the result from the check if the namestore * service is actually running. If it is, we start the actual * operation. * * @param cls closure with our configuration * @param result #GNUNET_YES if the namestore service is running */ static void testservice_task (void *cls, int result) { const struct GNUNET_CONFIGURATION_Handle *cfg = cls; struct GNUNET_CRYPTO_EcdsaPublicKey pub; struct GNUNET_GNSRECORD_Data rd; if (GNUNET_YES != result) { FPRINTF (stderr, _("Service `%s' is not running\n"), "namestore"); return; } if (! (add|del|list|(NULL != nickstring)|(NULL != uri)|(NULL != reverse_pkey)) ) { /* nothing more to be done */ fprintf (stderr, _("No options given\n")); GNUNET_SCHEDULER_shutdown (); return; } GNUNET_CRYPTO_ecdsa_key_get_public (&zone_pkey, &pub); ns = GNUNET_NAMESTORE_connect (cfg); if (NULL == ns) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to connect to namestore\n")); return; } if (add) { if (NULL == name) { fprintf (stderr, _("Missing option `%s' for operation `%s'\n"), "-n", _("add")); GNUNET_SCHEDULER_shutdown (); ret = 1; return; } if (NULL == typestring) { fprintf (stderr, _("Missing option `%s' for operation `%s'\n"), "-t", _("add")); GNUNET_SCHEDULER_shutdown (); ret = 1; return; } type = GNUNET_GNSRECORD_typename_to_number (typestring); if (UINT32_MAX == type) { fprintf (stderr, _("Unsupported type `%s'\n"), typestring); GNUNET_SCHEDULER_shutdown (); ret = 1; return; } if (NULL == value) { fprintf (stderr, _("Missing option `%s' for operation `%s'\n"), "-V", _("add")); ret = 1; GNUNET_SCHEDULER_shutdown (); return; } if (GNUNET_OK != GNUNET_GNSRECORD_string_to_value (type, value, &data, &data_size)) { fprintf (stderr, _("Value `%s' invalid for record type `%s'\n"), value, typestring); GNUNET_SCHEDULER_shutdown (); ret = 1; return; } if (NULL == expirationstring) { fprintf (stderr, _("Missing option `%s' for operation `%s'\n"), "-e", _("add")); GNUNET_SCHEDULER_shutdown (); ret = 1; return; } if (0 == strcmp (expirationstring, "never")) { etime_abs = GNUNET_TIME_UNIT_FOREVER_ABS; etime_is_rel = GNUNET_NO; } else if (GNUNET_OK == GNUNET_STRINGS_fancy_time_to_relative (expirationstring, &etime_rel)) { etime_is_rel = GNUNET_YES; } else if (GNUNET_OK == GNUNET_STRINGS_fancy_time_to_absolute (expirationstring, &etime_abs)) { etime_is_rel = GNUNET_NO; } else { fprintf (stderr, _("Invalid time format `%s'\n"), expirationstring); GNUNET_SCHEDULER_shutdown (); ret = 1; return; } add_qe = GNUNET_NAMESTORE_records_lookup (ns, &zone_pkey, name, &get_existing_record, NULL ); } if (del) { if (NULL == name) { fprintf (stderr, _("Missing option `%s' for operation `%s'\n"), "-n", _("del")); GNUNET_SCHEDULER_shutdown (); ret = 1; return; } del_qe = GNUNET_NAMESTORE_records_lookup (ns, &zone_pkey, name, &del_monitor, NULL); } if (list) { list_it = GNUNET_NAMESTORE_zone_iteration_start (ns, &zone_pkey, &display_record, NULL); } if (NULL != reverse_pkey) { struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; if (GNUNET_OK != GNUNET_CRYPTO_ecdsa_public_key_from_string (reverse_pkey, strlen (reverse_pkey), &pubkey)) { fprintf (stderr, _("Invalid public key for reverse lookup `%s'\n"), reverse_pkey); GNUNET_SCHEDULER_shutdown (); } reverse_qe = GNUNET_NAMESTORE_zone_to_name (ns, &zone_pkey, &pubkey, &handle_reverse_lookup, NULL); } if (NULL != uri) { char sh[105]; char sname[64]; struct GNUNET_CRYPTO_EcdsaPublicKey pkey; GNUNET_STRINGS_utf8_tolower (uri, uri); if ( (2 != (sscanf (uri, "gnunet://gns/%52s/%63s", sh, sname)) ) || (GNUNET_OK != GNUNET_CRYPTO_ecdsa_public_key_from_string (sh, strlen (sh), &pkey)) ) { fprintf (stderr, _("Invalid URI `%s'\n"), uri); GNUNET_SCHEDULER_shutdown (); ret = 1; return; } memset (&rd, 0, sizeof (rd)); rd.data = &pkey; rd.data_size = sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey); rd.record_type = GNUNET_GNSRECORD_TYPE_PKEY; if (GNUNET_YES == etime_is_rel) { rd.expiration_time = etime_rel.rel_value_us; rd.flags |= GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; } else if (GNUNET_NO == etime_is_rel) rd.expiration_time = etime_abs.abs_value_us; else rd.expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; if (1 == is_shadow) rd.flags |= GNUNET_GNSRECORD_RF_SHADOW_RECORD; add_qe_uri = GNUNET_NAMESTORE_records_store (ns, &zone_pkey, sname, 1, &rd, &add_continuation, &add_qe_uri); } if (NULL != nickstring) { if (0 == strlen(nickstring)) { fprintf (stderr, _("Invalid nick `%s'\n"), nickstring); GNUNET_SCHEDULER_shutdown (); ret = 1; return; } add_qe_uri = GNUNET_NAMESTORE_set_nick(ns, &zone_pkey, nickstring, &add_continuation, &add_qe_uri); } if (monitor) { zm = GNUNET_NAMESTORE_zone_monitor_start (cfg, &zone_pkey, GNUNET_YES, &display_record, &sync_cb, NULL); } }