#define INITIAL_PUT_INTERVAL GNUNET_TIME_UNIT_MILLISECONDS
/**
- * The upper bound for the zone iteration interval in milliseconds
+ * The lower bound for the zone iteration interval
*/
#define MINIMUM_ZONE_ITERATION_INTERVAL GNUNET_TIME_UNIT_SECONDS
+/**
+ * The upper bound for the zone iteration interval
+ */
+#define MAXIMUM_ZONE_ITERATION_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
+
/**
* The default put interval for the zone iteration. In case
* no option is found
}
else
next_put_interval = put_interval;
+ next_put_interval = GNUNET_TIME_relative_min (next_put_interval,
+ MAXIMUM_ZONE_ITERATION_INTERVAL);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "PUT complete, next PUT in %s!\n",
+ GNUNET_STRINGS_relative_time_to_string (next_put_interval,
+ GNUNET_YES));
GNUNET_STATISTICS_set (statistics,
"Current zone iteration interval (ms)",
label,
GNUNET_STRINGS_absolute_time_to_string (expire),
GNUNET_h2s (&query));
- ret = GNUNET_DHT_put (dht_handle, &query,
+ ret = GNUNET_DHT_put (dht_handle,
+ &query,
DHT_GNS_REPLICATION_LEVEL,
GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
GNUNET_BLOCK_TYPE_GNS_NAMERECORD,
}
+/**
+ * We encountered an error in our zone iteration.
+ */
+static void
+zone_iteration_error (void *cls)
+{
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Got disconnected from namestore database, retrying.\n");
+ namestore_iter = NULL;
+ /* We end up here on error/disconnect/shutdown, so potentially
+ while a zone publish task or a DHT put is still running; hence
+ we need to cancel those. */
+ if (NULL != zone_publish_task)
+ {
+ GNUNET_SCHEDULER_cancel (zone_publish_task);
+ zone_publish_task = NULL;
+ }
+ if (NULL != active_put)
+ {
+ GNUNET_DHT_put_cancel (active_put);
+ active_put = NULL;
+ }
+ zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start,
+ NULL);
+}
+
+
+/**
+ * Zone iteration is completed.
+ */
+static void
+zone_iteration_finished (void *cls)
+{
+ /* we're done with one iteration, calculate when to do the next one */
+ namestore_iter = NULL;
+ last_num_public_records = num_public_records;
+ first_zone_iteration = GNUNET_NO;
+ if (0 == num_public_records)
+ {
+ /**
+ * If no records are known (startup) or none present
+ * we can safely set the interval to the value for a single
+ * record
+ */
+ put_interval = zone_publish_time_window;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
+ "No records in namestore database.\n");
+ }
+ else
+ {
+ /* If records are present, next publication is based on the minimum
+ * relative expiration time of the records published divided by 4
+ */
+ zone_publish_time_window
+ = GNUNET_TIME_relative_min (GNUNET_TIME_relative_divide (min_relative_record_time, 4),
+ zone_publish_time_window_default);
+ put_interval = GNUNET_TIME_relative_divide (zone_publish_time_window,
+ num_public_records);
+ }
+ /* reset for next iteration */
+ min_relative_record_time = GNUNET_TIME_UNIT_FOREVER_REL;
+ put_interval = GNUNET_TIME_relative_max (MINIMUM_ZONE_ITERATION_INTERVAL,
+ put_interval);
+ put_interval = GNUNET_TIME_relative_min (put_interval,
+ MAXIMUM_ZONE_ITERATION_INTERVAL);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Zone iteration finished. Adjusted zone iteration interval to %s\n",
+ GNUNET_STRINGS_relative_time_to_string (put_interval,
+ GNUNET_YES));
+ GNUNET_STATISTICS_set (statistics,
+ "Current zone iteration interval (in ms)",
+ put_interval.rel_value_us / 1000LL,
+ GNUNET_NO);
+ GNUNET_STATISTICS_update (statistics,
+ "Number of zone iterations",
+ 1,
+ GNUNET_NO);
+ GNUNET_STATISTICS_set (statistics,
+ "Number of public records in DHT",
+ last_num_public_records,
+ GNUNET_NO);
+ GNUNET_assert (NULL == zone_publish_task);
+ if (0 == num_public_records)
+ zone_publish_task = GNUNET_SCHEDULER_add_delayed (put_interval,
+ &publish_zone_dht_start,
+ NULL);
+ else
+ zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start,
+ NULL);
+}
+
+
/**
* Function used to put all records successively into the DHT.
*
struct GNUNET_GNSRECORD_Data rd_public[rd_count];
unsigned int rd_public_count;
- if ( (NULL == key) &&
- (NULL == label) &&
- (0 == rd_count) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Got disconnected from namestore database, retrying.\n");
- namestore_iter = NULL;
- if (NULL != zone_publish_task)
- {
- GNUNET_SCHEDULER_cancel (zone_publish_task);
- zone_publish_task = NULL;
- }
- zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start,
- NULL);
- return;
- }
- if (NULL == label)
- {
- /* we're done with one iteration, calculate when to do the next one */
- namestore_iter = NULL;
- last_num_public_records = num_public_records;
- first_zone_iteration = GNUNET_NO;
- if (0 == num_public_records)
- {
- /**
- * If no records are known (startup) or none present
- * we can safely set the interval to the value for a single
- * record
- */
- put_interval = zone_publish_time_window;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
- "No records in namestore database.\n");
- }
- else
- {
- /* If records are present, next publication is based on the minimum
- * relative expiration time of the records published divided by 4
- */
- zone_publish_time_window = GNUNET_TIME_relative_min (
- GNUNET_TIME_relative_divide (min_relative_record_time, 4),
- zone_publish_time_window_default);
- put_interval = GNUNET_TIME_relative_divide (zone_publish_time_window,
- num_public_records);
- }
- /* reset for next iteration */
- min_relative_record_time = GNUNET_TIME_UNIT_FOREVER_REL;
- put_interval = GNUNET_TIME_relative_max (MINIMUM_ZONE_ITERATION_INTERVAL,
- put_interval);
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Zone iteration finished. Adjusted zone iteration interval to %s\n",
- GNUNET_STRINGS_relative_time_to_string (put_interval,
- GNUNET_YES));
- GNUNET_STATISTICS_set (statistics,
- "Current zone iteration interval (in ms)",
- put_interval.rel_value_us / 1000LL,
- GNUNET_NO);
- GNUNET_STATISTICS_update (statistics,
- "Number of zone iterations",
- 1,
- GNUNET_NO);
- GNUNET_STATISTICS_set (statistics,
- "Number of public records in DHT",
- last_num_public_records,
- GNUNET_NO);
- GNUNET_assert (NULL == zone_publish_task);
- if (0 == num_public_records)
- zone_publish_task = GNUNET_SCHEDULER_add_delayed (put_interval,
- &publish_zone_dht_start,
- NULL);
- else
- zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start,
- NULL);
- return;
- }
-
rd_public_count = convert_records_for_export (rd,
rd_count,
rd_public);
- /* We got a set of records to publish */
if (0 == rd_public_count)
{
GNUNET_assert (NULL == zone_publish_task);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Record set empty, moving to next record set\n");
zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_next,
- NULL);
+ NULL);
return;
}
-
+ /* We got a set of records to publish */
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Starting DHT PUT\n");
active_put = perform_dht_put (key,
label,
rd_public,
namestore_iter
= GNUNET_NAMESTORE_zone_iteration_start (namestore_handle,
NULL, /* All zones */
+ &zone_iteration_error,
+ NULL,
&put_gns_record,
+ NULL,
+ &zone_iteration_finished,
NULL);
}
label);
/* filter out records that are not public, and convert to
absolute expiration time. */
- rd_public_count = convert_records_for_export (rd, rd_count,
+ rd_public_count = convert_records_for_export (rd,
+ rd_count,
rd_public);
if (0 == rd_public_count)
return; /* nothing to do */
ma = GNUNET_new (struct MonitorActivity);
- ma->ph = perform_dht_put (zone, label,
- rd, rd_count,
+ ma->ph = perform_dht_put (zone,
+ label,
+ rd,
+ rd_count,
ma);
if (NULL == ma->ph)
{
}
+/**
+ * The zone monitor is now in SYNC with the current state of the
+ * name store. Start to perform periodic iterations.
+ *
+ * @param cls NULL
+ */
+static void
+handle_monitor_error (void *cls)
+{
+ if (NULL != zone_publish_task)
+ {
+ GNUNET_SCHEDULER_cancel (zone_publish_task);
+ zone_publish_task = NULL;
+ }
+ if (NULL != namestore_iter)
+ {
+ GNUNET_NAMESTORE_zone_iteration_stop (namestore_iter);
+ namestore_iter = NULL;
+ }
+ if (NULL != active_put)
+ {
+ GNUNET_DHT_put_cancel (active_put);
+ active_put = NULL;
+ }
+ zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start,
+ NULL);
+}
+
+
/**
* Method called to inform about the ego to be used for the master zone
* for DNS interceptions.
zmon = GNUNET_NAMESTORE_zone_monitor_start (c,
NULL,
GNUNET_NO,
+ &handle_monitor_error,
+ NULL,
&handle_monitor_event,
+ NULL,
&monitor_sync_event,
NULL);
GNUNET_break (NULL != zmon);
}
+/**
+ * Encountered an error in zone-to-name lookup, give up on shortening.
+ */
+static void
+zone_to_name_error_cb (void *cls)
+{
+ struct GetPseuAuthorityHandle* gph = cls;
+
+ gph->namestore_task = NULL;
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Shortening aborted, internal error talking to namestore\n");
+ free_get_pseu_authority_handle (gph);
+}
+
+
/**
* Callback called by namestore for a zone to name result. We're
* trying to see if a short name for a given zone already exists.
const struct GNUNET_GNSRECORD_Data *rd)
{
struct GetPseuAuthorityHandle* gph = cls;
-#if 0
- struct GNUNET_HashCode lookup_key;
-#endif
gph->namestore_task = NULL;
if (0 != rd_len)
gph->namestore_task = GNUNET_NAMESTORE_zone_to_name (namestore_handle,
shorten_zone,
pub,
+ &zone_to_name_error_cb,
+ gph,
&process_zone_to_name_discover,
gph);
}
}
+static void
+token_collect_error_cb (void *cls)
+{
+ // struct EgoEntry *ego_entry = cls;
+
+ GNUNET_assert (0); // FIXME: handle properly!
+}
+
+
+static void
+token_collect_finished_cb (void *cls)
+{
+ struct EgoEntry *ego_entry = cls;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ ">>> Updating Ego finished\n");
+ //Clear attribute map for ego
+ GNUNET_CONTAINER_multihashmap_iterate (ego_entry->attr_map,
+ &clear_ego_attrs,
+ ego_entry);
+ GNUNET_CONTAINER_multihashmap_clear (ego_entry->attr_map);
+ update_task = GNUNET_SCHEDULER_add_now (&update_identities,
+ ego_entry->next);
+}
+
+
/**
*
* Update all ID_TOKEN records for an identity and store them
const struct GNUNET_GNSRECORD_Data *token_metadata_record;
struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key;
- if (NULL == lbl)
- {
- //Done
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- ">>> Updating Ego finished\n");
- //Clear attribute map for ego
- GNUNET_CONTAINER_multihashmap_iterate (ego_entry->attr_map,
- &clear_ego_attrs,
- ego_entry);
- GNUNET_CONTAINER_multihashmap_clear (ego_entry->attr_map);
- update_task = GNUNET_SCHEDULER_add_now (&update_identities,
- ego_entry->next);
- return;
- }
-
//There should be only a single record for a token under a label
if (2 != rd_count)
{
}
+static void
+attribute_collect_error_cb (void *cls)
+{
+ // struct EgoEntry *ego_entry = cls;
+
+ GNUNET_assert (0); // FIXME: handle properly!
+}
+
+
+static void
+attribute_collect_finished_cb (void *cls)
+{
+ struct EgoEntry *ego_entry = cls;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ ">>> Updating Attributes finished\n");
+ ego_entry->attributes_dirty = GNUNET_NO;
+ update_task = GNUNET_SCHEDULER_add_now (&update_identities,
+ ego_entry);
+}
+
+
/**
*
* Collect all ID_ATTR records for an identity and store them
char *val_str;
int i;
- if (NULL == lbl)
- {
- //Done
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- ">>> Updating Attributes finished\n");
- ego_entry->attributes_dirty = GNUNET_NO;
- update_task = GNUNET_SCHEDULER_add_now (&update_identities,
- ego_entry);
- return;
- }
-
if (0 == rd_count)
{
GNUNET_NAMESTORE_zone_iterator_next (ns_it);
attr,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
GNUNET_NAMESTORE_zone_iterator_next (ns_it);
- return;
}
/**
{
struct EgoEntry *next_ego = cls;
const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key;
+
update_task = NULL;
if (NULL == next_ego)
{
//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_error_cb,
+ next_ego,
&attribute_collect,
+ next_ego,
+ &attribute_collect_finished_cb,
next_ego);
}
next_ego->attributes_dirty = GNUNET_YES;
ns_it = GNUNET_NAMESTORE_zone_iteration_start (ns_handle,
priv_key,
+ &token_collect_error_cb,
+ next_ego,
&token_collect,
+ next_ego,
+ &token_collect_finished_cb,
next_ego);
}
}
struct GNUNET_IDENTITY_PROVIDER_IssueResultMessage *irm;
char *ticket_str;
char *token_str;
-
+
handle->ns_qe = NULL;
if (GNUNET_SYSERR == success)
{
GNUNET_free (token_metadata);
}
+
+static void
+attr_collect_error (void *cls)
+{
+ // struct IssueHandle *handle = cls;
+
+ GNUNET_assert (0); // FIXME: handle error!
+}
+
+
+static void
+attr_collect_finished (void *cls)
+{
+ struct IssueHandle *handle = cls;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attribute END: \n");
+ handle->ns_it = NULL;
+ GNUNET_SCHEDULER_add_now (&sign_and_return_token, handle);
+}
+
+
/**
* Collect attributes for token
*/
unsigned int rd_count,
const struct GNUNET_GNSRECORD_Data *rd)
{
+ struct IssueHandle *handle = cls;
int i;
char* data;
- struct IssueHandle *handle = cls;
struct GNUNET_HashCode key;
- if (NULL == label)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attribute END: \n");
- handle->ns_it = NULL;
- GNUNET_SCHEDULER_add_now (&sign_and_return_token, handle);
- return;
- }
-
GNUNET_CRYPTO_hash (label,
strlen (label),
&key);
}
+static void
+find_existing_token_error (void *cls)
+{
+ // struct IssueHandle *handle = cls;
+
+ GNUNET_assert (0); // FIXME: handle properly
+}
+
+
+static void
+find_existing_token_finished (void *cls)
+{
+ struct IssueHandle *handle = cls;
+ uint64_t rnd_key;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ ">>> No existing token found\n");
+ rnd_key =
+ GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG,
+ UINT64_MAX);
+ GNUNET_STRINGS_base64_encode ((char*)&rnd_key,
+ sizeof (uint64_t),
+ &handle->label);
+ handle->ns_it = NULL;
+ handle->ns_it = GNUNET_NAMESTORE_zone_iteration_start (ns_handle,
+ &handle->iss_key,
+ &attr_collect_error,
+ handle,
+ &attr_collect,
+ handle,
+ &attr_collect_finished,
+ handle);
+}
+
+
/**
*
* Look for existing token
struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key;
struct GNUNET_HashCode key;
int scope_count_token;
- uint64_t rnd_key;
char *scope;
char *tmp_scopes;
- if (NULL == lbl)
- {
- //Done
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- ">>> No existing token found\n");
- //Label
- rnd_key =
- GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG,
- UINT64_MAX);
- GNUNET_STRINGS_base64_encode ((char*)&rnd_key,
- sizeof (uint64_t),
- &handle->label);
- handle->ns_it = NULL;
- handle->ns_it = GNUNET_NAMESTORE_zone_iteration_start (ns_handle,
- &handle->iss_key,
- &attr_collect,
- handle);
- return;
- }
-
//There should be only a single record for a token under a label
if (2 != rd_count)
{
if (rd[0].record_type == GNUNET_GNSRECORD_TYPE_ID_TOKEN_METADATA)
{
token_metadata_record = &rd[0];
- } else {
+ }
+ else
+ {
token_metadata_record = &rd[1];
}
if (token_metadata_record->record_type != GNUNET_GNSRECORD_TYPE_ID_TOKEN_METADATA)
handle->ns_it = NULL;
handle->ns_it = GNUNET_NAMESTORE_zone_iteration_start (ns_handle,
&handle->iss_key,
+ &attr_collect_error,
+ handle,
&attr_collect,
+ handle,
+ &attr_collect_finished,
handle);
return;
issue_handle->ns_it = GNUNET_NAMESTORE_zone_iteration_start (ns_handle,
&im->iss_key,
+ &find_existing_token_error,
+ issue_handle,
&find_existing_token,
+ issue_handle,
+ &find_existing_token_finished,
issue_handle);
}
+
/**
* Main function that will be run
*
cleanup_handle (handle);
}
+
+static void
+token_collect_error_cb (void *cls)
+{
+ struct RequestHandle *handle = cls;
+
+ do_error (handle);
+}
+
+
/**
* Collect all tokens for an ego
*
const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
const char *label,
unsigned int rd_count,
- const struct GNUNET_GNSRECORD_Data *rd)
+ const struct GNUNET_GNSRECORD_Data *rd);
+
+
+static void
+token_collect_finished_cb (void *cls)
{
- int i;
- char* data;
struct RequestHandle *handle = cls;
struct EgoEntry *ego_tmp;
- struct GNUNET_JSONAPI_Resource *json_resource;
const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key;
- json_t *issuer;
- json_t *token;
-
- if (NULL == label)
- {
- ego_tmp = handle->ego_head;
- GNUNET_CONTAINER_DLL_remove (handle->ego_head,
- handle->ego_tail,
- ego_tmp);
- GNUNET_free (ego_tmp->identifier);
- GNUNET_free (ego_tmp->keystring);
- GNUNET_free (ego_tmp);
- if (NULL == handle->ego_head)
- {
- //Done
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding token END\n");
- handle->ns_it = NULL;
- GNUNET_SCHEDULER_add_now (&return_token_list, handle);
- return;
- }
+ ego_tmp = handle->ego_head;
+ GNUNET_CONTAINER_DLL_remove (handle->ego_head,
+ handle->ego_tail,
+ ego_tmp);
+ GNUNET_free (ego_tmp->identifier);
+ GNUNET_free (ego_tmp->keystring);
+ GNUNET_free (ego_tmp);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Next ego: %s\n", handle->ego_head->identifier);
- priv_key = GNUNET_IDENTITY_ego_get_private_key (handle->ego_head->ego);
- handle->ns_it = GNUNET_NAMESTORE_zone_iteration_start (handle->ns_handle,
- priv_key,
- &token_collect,
- handle);
+ if (NULL == handle->ego_head)
+ {
+ //Done
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding token END\n");
+ handle->ns_it = NULL;
+ GNUNET_SCHEDULER_add_now (&return_token_list, handle);
return;
}
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Next ego: %s\n",
+ handle->ego_head->identifier);
+ priv_key = GNUNET_IDENTITY_ego_get_private_key (handle->ego_head->ego);
+ handle->ns_it = GNUNET_NAMESTORE_zone_iteration_start (handle->ns_handle,
+ priv_key,
+ &token_collect_error_cb,
+ handle,
+ &token_collect,
+ handle,
+ &token_collect_finished_cb,
+ handle);
+}
+
+
+/**
+ * Collect all tokens for an ego
+ *
+ * TODO move this into the identity-provider service
+ *
+ */
+static void
+token_collect (void *cls,
+ const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
+ const char *label,
+ unsigned int rd_count,
+ const struct GNUNET_GNSRECORD_Data *rd)
+{
+ struct RequestHandle *handle = cls;
+ int i;
+ char* data;
+ struct GNUNET_JSONAPI_Resource *json_resource;
+ json_t *issuer;
+ json_t *token;
+
for (i = 0; i < rd_count; i++)
{
if (rd[i].record_type == GNUNET_GNSRECORD_TYPE_ID_TOKEN)
handle->ns_handle = GNUNET_NAMESTORE_connect (cfg);
handle->ns_it = GNUNET_NAMESTORE_zone_iteration_start (handle->ns_handle,
priv_key,
+ &token_collect_error_cb,
+ handle,
&token_collect,
+ handle,
+ &token_collect_finished_cb,
handle);
}
* Process a record that was stored in the namestore.
*
* @param cls closure
- * @param zone private key of the zone; NULL on disconnect
- * @param label label of the records; NULL on disconnect
+ * @param zone private key of the zone
+ * @param label label of the records
* @param rd_count number of entries in @a rd array, 0 if label was deleted
* @param rd array of records with data to store
*/
* @param h handle to the namestore
* @param pkey private key of the zone
* @param label name that is being mapped
- * @param rm function to call with the result (with 0 records if we don't have that label)
+ * @param error_cb function to call on error (i.e. disconnect)
+ * the handle is afterwards invalid
+ * @param error_cb_cls closure for @a error_cb
+ * @param rm function to call with the result (with 0 records if we don't have that label);
+ * the handle is afterwards invalid
* @param rm_cls closure for @a rm
* @return handle to abort the request
*/
GNUNET_NAMESTORE_records_lookup (struct GNUNET_NAMESTORE_Handle *h,
const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
const char *label,
+ GNUNET_SCHEDULER_TaskCallback error_cb,
+ void *error_cb_cls,
GNUNET_NAMESTORE_RecordMonitor rm,
void *rm_cls);
* @param h handle to the namestore
* @param zone public key of the zone to look up in, never NULL
* @param value_zone public key of the target zone (value), never NULL
+ * @param error_cb function to call on error (i.e. disconnect)
+ * the handle is afterwards invalid
+ * @param error_cb_cls closure for @a error_cb
* @param proc function to call on the matching records, or with
- * NULL (rd_count == 0) if there are no matching records
+ * NULL (rd_count == 0) if there are no matching records;
+ * the handle is afterwards invalid
* @param proc_cls closure for @a proc
* @return a handle that can be used to
* cancel
GNUNET_NAMESTORE_zone_to_name (struct GNUNET_NAMESTORE_Handle *h,
const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
const struct GNUNET_CRYPTO_EcdsaPublicKey *value_zone,
- GNUNET_NAMESTORE_RecordMonitor proc, void *proc_cls);
+ GNUNET_SCHEDULER_TaskCallback error_cb,
+ void *error_cb_cls,
+ GNUNET_NAMESTORE_RecordMonitor proc,
+ void *proc_cls);
/**
/**
* Starts a new zone iteration (used to periodically PUT all of our
- * records into our DHT). This MUST lock the struct GNUNET_NAMESTORE_Handle
- * for any other calls than #GNUNET_NAMESTORE_zone_iterator_next and
+ * records into our DHT). This MUST lock the `struct GNUNET_NAMESTORE_Handle`
+ * for any other calls than #GNUNET_NAMESTORE_zone_iterator_next() and
* #GNUNET_NAMESTORE_zone_iteration_stop. @a proc will be called once
* immediately, and then again after
- * #GNUNET_NAMESTORE_zone_iterator_next is invoked.
+ * #GNUNET_NAMESTORE_zone_iterator_next() is invoked.
+ *
+ * On error (disconnect), @a error_cb will be invoked.
+ * On normal completion, @a finish_cb proc will be
+ * invoked.
*
* @param h handle to the namestore
* @param zone zone to access, NULL for all zones
+ * @param error_cb function to call on error (i.e. disconnect),
+ * the handle is afterwards invalid
+ * @param error_cb_cls closure for @a error_cb
* @param proc function to call on each name from the zone; it
* will be called repeatedly with a value (if available)
- * and always once at the end with a label of NULL.
* @param proc_cls closure for @a proc
+ * @param finish_cb function to call on completion
+ * the handle is afterwards invalid
+ * @param finish_cb_cls closure for @a finish_cb
* @return an iterator handle to use for iteration
*/
struct GNUNET_NAMESTORE_ZoneIterator *
GNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h,
const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
+ GNUNET_SCHEDULER_TaskCallback error_cb,
+ void *error_cb_cls,
GNUNET_NAMESTORE_RecordMonitor proc,
- void *proc_cls);
+ void *proc_cls,
+ GNUNET_SCHEDULER_TaskCallback finish_cb,
+ void *finish_cb_cls);
/**
struct GNUNET_NAMESTORE_ZoneMonitor;
-/**
- * Function called once the monitor has caught up with the current
- * state of the database. Will be called AGAIN after each disconnect
- * (record monitor called with 'NULL' for zone_key) once we're again
- * in sync.
- *
- * @param cls closure
- */
-typedef void
-(*GNUNET_NAMESTORE_RecordsSynchronizedCallback)(void *cls);
-
-
/**
* Begin monitoring a zone for changes. Will first call the @a
* monitor function on all existing records in the selected zone(s) if
* @a iterate_first is #GNUNET_YES. In any case, we will then call @a
* sync_cb, and then afterwards call the @a monitor whenever a record
- * changes. If the namestore disconnects, the @a monitor function is
- * called with a disconnect event; if the connection is
+ * changes. If the namestore disconnects, the @a error_cb function is
+ * called with a disconnect event. Once the connection is
* re-established, the process begins from the start (depending on @a
- * iterate_first, we first do all existing records, then @a sync, then
- * updates).
+ * iterate_first, we will again first do all existing records, then @a
+ * sync, then updates).
*
* @param cfg configuration to use to connect to namestore
* @param zone zone to monitor, NULL for all zones
* @param iterate_first #GNUNET_YES to first iterate over all existing records,
* #GNUNET_NO to only return changes that happen from now on
+ * @param error_cb function to call on error (i.e. disconnect); note that
+ * unlike the other error callbacks in this API, a call to this
+ * function does NOT destroy the monitor handle, it merely signals
+ * that monitoring is down. You need to still explicitly call
+ * #GNUNET_NAMESTORE_zone_monitor_stop().
+ * @param error_cb_cls closure for @a error_cb
* @param monitor function to call on zone changes
+ * @param monitor_cls closure for @a monitor
* @param sync_cb function called when we're in sync with the namestore
- * @param cls closure for @a monitor and @a sync_cb
+ * @param sync_cb_cls closure for @a sync_cb
* @return handle to stop monitoring
*/
struct GNUNET_NAMESTORE_ZoneMonitor *
GNUNET_NAMESTORE_zone_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
int iterate_first,
+ GNUNET_SCHEDULER_TaskCallback error_cb,
+ void *error_cb_cls,
GNUNET_NAMESTORE_RecordMonitor monitor,
- GNUNET_NAMESTORE_RecordsSynchronizedCallback sync_cb,
- void *cls);
+ void *monitor_cls,
+ GNUNET_SCHEDULER_TaskCallback sync_cb,
+ void *sync_cb_cls);
/**
}
+/**
+ * Function called on error in zone iteration.
+ */
+static void
+zone_iteration_error (void *cls)
+{
+ struct ZoneinfoRequest *zr = cls;
+ struct MHD_Response *response;
+
+ zr->list_it = NULL;
+ response = MHD_create_response_from_buffer (strlen ("internal error"),
+ (void *) "internal error",
+ MHD_RESPMEM_PERSISTENT);
+ MHD_queue_response (zr->connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ response);
+ MHD_destroy_response (response);
+ GNUNET_free (zr->zoneinfo);
+ GNUNET_free (zr);
+ run_httpd_now ();
+}
+
+
+/**
+ * Function called once the zone iteration is done.
+ */
+static void
+zone_iteration_end (void *cls)
+{
+ struct ZoneinfoRequest *zr = cls;
+ struct MHD_Response *response;
+ char* full_page;
+
+ zr->list_it = NULL;
+
+ /* return static form */
+ GNUNET_asprintf (&full_page,
+ ZONEINFO_PAGE,
+ zr->zoneinfo,
+ zr->zoneinfo);
+ response = MHD_create_response_from_buffer (strlen (full_page),
+ (void *) full_page,
+ MHD_RESPMEM_MUST_FREE);
+ MHD_add_response_header (response,
+ MHD_HTTP_HEADER_CONTENT_TYPE,
+ MIME_HTML);
+ MHD_queue_response (zr->connection,
+ MHD_HTTP_OK,
+ response);
+ MHD_destroy_response (response);
+ GNUNET_free (zr->zoneinfo);
+ GNUNET_free (zr);
+ run_httpd_now ();
+}
+
+
/**
* Process a record that was stored in the namestore, adding
* the information to the HTML.
const struct GNUNET_GNSRECORD_Data *rd)
{
struct ZoneinfoRequest *zr = cls;
- struct MHD_Response *response;
- char* full_page;
size_t bytes_free;
char* pkey;
char* new_buf;
-
- if (NULL == name)
- {
- zr->list_it = NULL;
-
- /* return static form */
- GNUNET_asprintf (&full_page,
- ZONEINFO_PAGE,
- zr->zoneinfo,
- zr->zoneinfo);
- response = MHD_create_response_from_buffer (strlen (full_page),
- (void *) full_page,
- MHD_RESPMEM_MUST_FREE);
- MHD_add_response_header (response,
- MHD_HTTP_HEADER_CONTENT_TYPE,
- MIME_HTML);
- MHD_queue_response (zr->connection,
- MHD_HTTP_OK,
- response);
- MHD_destroy_response (response);
- GNUNET_free (zr->zoneinfo);
- GNUNET_free (zr);
- run_httpd_now ();
- return;
- }
-
if (1 != rd_len)
{
GNUNET_NAMESTORE_zone_iterator_next (zr->list_it);
zr->write_offset = 0;
zr->list_it = GNUNET_NAMESTORE_zone_iteration_start (ns,
&fcfs_zone_pkey,
+ &zone_iteration_error,
+ zr,
&iterate_cb,
- zr);
+ zr,
+ &zone_iteration_end,
+ zr);
return MHD_YES;
}
}
+/**
+ * Function called if we had an error in zone-to-name mapping.
+ */
+static void
+zone_to_name_error (void *cls)
+{
+ struct Request *request = cls;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Error when mapping zone to name\n"));
+ request->phase = RP_FAIL;
+ run_httpd_now ();
+}
+
+
/**
* Test if a name mapping was found, if so, refuse. If not, initiate storing of the record.
*
{
struct Request *request = cls;
struct GNUNET_GNSRECORD_Data r;
+
request->qe = NULL;
if (0 != rd_count)
run_httpd_now ();
return;
}
- if (NULL == zone_key)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Error when mapping zone to name\n"));
- request->phase = RP_FAIL;
- run_httpd_now ();
- return;
- }
-
r.data = &request->pub;
r.data_size = sizeof (request->pub);
r.expiration_time = UINT64_MAX;
}
+/**
+ * We encountered an error in the name lookup.
+ */
+static void
+lookup_block_error (void *cls)
+{
+ struct Request *request = cls;
+
+ request->qe = NULL;
+ request->phase = RP_FAIL;
+ run_httpd_now ();
+}
+
+
/**
* We got a block back from the namestore. Decrypt it
* and continue to process the result.
request->qe = NULL;
if (0 == rd_count)
{
-
if (GNUNET_OK !=
GNUNET_CRYPTO_ecdsa_public_key_from_string (request->public_key,
strlen (request->public_key),
request->qe = GNUNET_NAMESTORE_zone_to_name (ns,
&fcfs_zone_pkey,
&request->pub,
+ &zone_to_name_error,
+ request,
&zone_to_name_cb,
request);
return;
}
request->phase = RP_LOOKUP;
request->qe = GNUNET_NAMESTORE_records_lookup (ns,
- &fcfs_zone_pkey,
- request->domain_name,
- &lookup_block_processor,
- request);
+ &fcfs_zone_pkey,
+ request->domain_name,
+ &lookup_block_error,
+ request,
+ &lookup_block_processor,
+ request);
break;
case RP_LOOKUP:
break;
}
+/**
+ * Function called when we are done with a zone iteration.
+ */
+static void
+zone_iteration_finished (void *cls)
+{
+ list_it = NULL;
+ test_finished ();
+}
+
+
+/**
+ * Function called when we encountered an error in a zone iteration.
+ */
+static void
+zone_iteration_error_cb (void *cls)
+{
+ list_it = NULL;
+ fprintf (stderr,
+ "Error iterating over zone\n");
+ ret = 1;
+ test_finished ();
+}
+
+
/**
* Process a record that was stored in the namestore.
*
struct GNUNET_TIME_Absolute at;
struct GNUNET_TIME_Relative rt;
- if (NULL == rname)
- {
- list_it = NULL;
- test_finished ();
- return;
- }
if ( (NULL != name) &&
(0 != strcmp (name, rname)) )
{
}
+/**
+ * Function called on errors while monitoring.
+ *
+ * @param cls NULL
+ */
+static void
+monitor_error_cb (void *cls)
+{
+ FPRINTF (stderr, "%s", "Monitor disconnected and out of sync.\n");
+}
+
+
+/**
+ * Function called if lookup fails.
+ */
+static void
+lookup_error_cb (void *cls)
+{
+ add_qe = NULL;
+ GNUNET_break (0);
+ ret = 1;
+ test_finished ();
+}
+
+
/**
* We're storing a record; this function is given the existing record
* so that we can merge the information.
unsigned int i;
add_qe = NULL;
- if ( (NULL != zone_key) &&
- (0 != strcmp (rec_name, name)) )
+ if (0 != strcmp (rec_name, name))
{
GNUNET_break (0);
ret = 1;
}
+/**
+ * Function called if we encountered an error in zone-to-name.
+ */
+static void
+reverse_error_cb (void *cls)
+{
+ reverse_qe = NULL;
+ FPRINTF (stdout,
+ "%s.zkey\n",
+ reverse_pkey);
+}
+
+
/**
* Function called with the result of our attempt to obtain a name for a given
* public key.
}
+/**
+ * Function called if lookup for deletion fails.
+ */
+static void
+del_lookup_error_cb (void *cls)
+{
+ del_qe = NULL;
+ GNUNET_break (0);
+ ret = 1;
+ test_finished ();
+}
+
+
/**
* We were asked to delete something; this function is called with
* the existing records. Now we should determine what should be
ret = 1;
return;
}
- add_qe = GNUNET_NAMESTORE_records_lookup (ns, &zone_pkey, name,
- &get_existing_record, NULL );
+ add_qe = GNUNET_NAMESTORE_records_lookup (ns,
+ &zone_pkey,
+ name,
+ &lookup_error_cb,
+ NULL,
+ &get_existing_record,
+ NULL);
}
if (del)
{
del_qe = GNUNET_NAMESTORE_records_lookup (ns,
&zone_pkey,
name,
+ &del_lookup_error_cb,
+ NULL,
&del_monitor,
NULL);
}
{
list_it = GNUNET_NAMESTORE_zone_iteration_start (ns,
&zone_pkey,
+ &zone_iteration_error_cb,
+ NULL,
&display_record,
+ NULL,
+ &zone_iteration_finished,
NULL);
}
if (NULL != reverse_pkey)
reverse_qe = GNUNET_NAMESTORE_zone_to_name (ns,
&zone_pkey,
&pubkey,
+ &reverse_error_cb,
+ NULL,
&handle_reverse_lookup,
NULL);
}
"gnunet://gns/%52s/%63s",
sh,
sname)) ) ||
- (GNUNET_OK != GNUNET_CRYPTO_ecdsa_public_key_from_string (sh, strlen (sh), &pkey)) )
+ (GNUNET_OK !=
+ GNUNET_CRYPTO_ecdsa_public_key_from_string (sh,
+ strlen (sh),
+ &pkey)) )
{
fprintf (stderr,
_("Invalid URI `%s'\n"),
zm = GNUNET_NAMESTORE_zone_monitor_start (cfg,
&zone_pkey,
GNUNET_YES,
+ &monitor_error_cb,
+ NULL,
&display_record,
+ NULL,
&sync_cb,
NULL);
}
*/
void *proc_cls;
+ /**
+ * Function to call on errors.
+ */
+ GNUNET_SCHEDULER_TaskCallback error_cb;
+
+ /**
+ * Closure for @e error_cb.
+ */
+ void *error_cb_cls;
+
/**
* Envelope of the message to send to the service, if not yet
* sent.
*/
struct GNUNET_NAMESTORE_Handle *h;
+ /**
+ * Function to call on completion.
+ */
+ GNUNET_SCHEDULER_TaskCallback finish_cb;
+
+ /**
+ * Closure for @e error_cb.
+ */
+ void *finish_cb_cls;
+
/**
* The continuation to call with the results
*/
*/
void *proc_cls;
+ /**
+ * Function to call on errors.
+ */
+ GNUNET_SCHEDULER_TaskCallback error_cb;
+
+ /**
+ * Closure for @e error_cb.
+ */
+ void *error_cb_cls;
+
/**
* Envelope of the message to send to the service, if not yet
* sent.
ntohl (msg->gns_header.r_id));
qe = find_qe (h,
ntohl (msg->gns_header.r_id));
- if ( (NULL == ze) && (NULL == qe) )
+ if ( (NULL == ze) &&
+ (NULL == qe) )
return; /* rid not found */
- if ( (NULL != ze) && (NULL != qe) )
+ if ( (NULL != ze) &&
+ (NULL != qe) )
{
GNUNET_break (0); /* rid ambigous */
force_reconnect (h);
force_reconnect (h);
return;
}
- if (NULL != ze->proc)
- ze->proc (ze->proc_cls, NULL, NULL, 0, NULL);
+ if (NULL != ze->finish_cb)
+ ze->finish_cb (ze->finish_cb_cls);
free_ze (ze);
return;
}
qe->proc (qe->proc_cls,
&msg->zone,
name_tmp,
- rd_count, rd);
+ rd_count,
+ rd);
/* return is important here: break would call continuation with error! */
free_qe (qe);
return;
return;
}
/* error case, call continuation with error */
- if (NULL != qe->proc)
- qe->proc (qe->proc_cls, NULL, NULL, 0, NULL);
+ if (NULL != qe->error_cb)
+ qe->error_cb (qe->error_cb_cls);
free_qe (qe);
}
h->mq = NULL;
while (NULL != (ze = h->z_head))
{
- /* FIXME: This does not allow clients to distinguish
- iteration error from successful termination! */
- if (NULL != ze->proc)
- ze->proc (ze->proc_cls, NULL, NULL, 0, NULL);
+ if (NULL != ze->error_cb)
+ ze->error_cb (ze->error_cb_cls);
free_ze (ze);
}
while (NULL != (qe = h->op_head))
{
- /* FIXME: This does not allow clients to distinguish
- iteration error from successful termination! */
- if (NULL != qe->proc)
- qe->proc (qe->proc_cls, NULL, NULL, 0, NULL);
+ if (NULL != qe->error_cb)
+ qe->error_cb (qe->error_cb_cls);
+ if (NULL != qe->cont)
+ qe->cont (qe->cont_cls,
+ GNUNET_SYSERR,
+ "failure in communication with namestore service");
free_qe (qe);
}
* @param h handle to the namestore
* @param pkey private key of the zone
* @param label name that is being mapped (at most 255 characters long)
+ * @param error_cb function to call on error (i.e. disconnect)
+ * @param error_cb_cls closure for @a error_cb
* @param rm function to call with the result (with 0 records if we don't have that label)
* @param rm_cls closure for @a rm
* @return handle to abort the request
GNUNET_NAMESTORE_records_lookup (struct GNUNET_NAMESTORE_Handle *h,
const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
const char *label,
+ GNUNET_SCHEDULER_TaskCallback error_cb,
+ void *error_cb_cls,
GNUNET_NAMESTORE_RecordMonitor rm,
void *rm_cls)
{
qe = GNUNET_new (struct GNUNET_NAMESTORE_QueueEntry);
qe->h = h;
+ qe->error_cb = error_cb;
+ qe->error_cb_cls = error_cb_cls;
qe->proc = rm;
qe->proc_cls = rm_cls;
qe->op_id = get_op_id(h);
* @param h handle to the namestore
* @param zone public key of the zone to look up in, never NULL
* @param value_zone public key of the target zone (value), never NULL
+ * @param error_cb function to call on error (i.e. disconnect)
+ * @param error_cb_cls closure for @a error_cb
* @param proc function to call on the matching records, or with
* NULL (rd_count == 0) if there are no matching records
* @param proc_cls closure for @a proc
GNUNET_NAMESTORE_zone_to_name (struct GNUNET_NAMESTORE_Handle *h,
const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
const struct GNUNET_CRYPTO_EcdsaPublicKey *value_zone,
+ GNUNET_SCHEDULER_TaskCallback error_cb,
+ void *error_cb_cls,
GNUNET_NAMESTORE_RecordMonitor proc,
void *proc_cls)
{
rid = get_op_id(h);
qe = GNUNET_new (struct GNUNET_NAMESTORE_QueueEntry);
qe->h = h;
+ qe->error_cb = error_cb;
+ qe->error_cb_cls = error_cb_cls;
qe->proc = proc;
qe->proc_cls = proc_cls;
qe->op_id = rid;
*
* @param h handle to the namestore
* @param zone zone to access, NULL for all zones
+ * @param error_cb function to call on error (i.e. disconnect)
+ * @param error_cb_cls closure for @a error_cb
* @param proc function to call on each name from the zone; it
* will be called repeatedly with a value (if available)
- * and always once at the end with a name of NULL.
* @param proc_cls closure for @a proc
+ * @param finish_cb function to call on completion
+ * @param finish_cb_cls closure for @a finish_cb
* @return an iterator handle to use for iteration
*/
struct GNUNET_NAMESTORE_ZoneIterator *
GNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h,
const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
+ GNUNET_SCHEDULER_TaskCallback error_cb,
+ void *error_cb_cls,
GNUNET_NAMESTORE_RecordMonitor proc,
- void *proc_cls)
+ void *proc_cls,
+ GNUNET_SCHEDULER_TaskCallback finish_cb,
+ void *finish_cb_cls)
{
struct GNUNET_NAMESTORE_ZoneIterator *it;
struct GNUNET_MQ_Envelope *env;
struct ZoneIterationStartMessage *msg;
uint32_t rid;
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending ZONE_ITERATION_START message\n");
rid = get_op_id (h);
it = GNUNET_new (struct GNUNET_NAMESTORE_ZoneIterator);
it->h = h;
+ it->error_cb = error_cb;
+ it->error_cb_cls = error_cb_cls;
+ it->finish_cb = finish_cb;
+ it->finish_cb_cls = finish_cb_cls;
it->proc = proc;
it->proc_cls = proc_cls;
it->op_id = rid;
*/
struct GNUNET_MQ_Handle *mq;
+ /**
+ * Function to call on errors.
+ */
+ GNUNET_SCHEDULER_TaskCallback error_cb;
+
+ /**
+ * Closure for @e error_cb.
+ */
+ void *error_cb_cls;
+
/**
* Function to call on events.
*/
GNUNET_NAMESTORE_RecordMonitor monitor;
+ /**
+ * Closure for @e monitor.
+ */
+ void *monitor_cls;
+
/**
* Function called when we've synchronized.
*/
- GNUNET_NAMESTORE_RecordsSynchronizedCallback sync_cb;
+ GNUNET_SCHEDULER_TaskCallback sync_cb;
/**
- * Closure for @e monitor and @e sync_cb.
+ * Closure for @e sync_cb.
*/
- void *cls;
+ void *sync_cb_cls;
/**
* Monitored zone.
struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls;
if (NULL != zm->sync_cb)
- zm->sync_cb (zm->cls);
+ zm->sync_cb (zm->sync_cb_cls);
}
rd_ser_tmp,
rd_count,
rd));
- zm->monitor (zm->cls,
+ zm->monitor (zm->monitor_cls,
&lrm->private_key,
name_tmp,
rd_count,
if (NULL != zm->mq)
{
GNUNET_MQ_destroy (zm->mq);
- zm->monitor (zm->cls,
- NULL,
- NULL,
- 0,
- NULL);
+ zm->error_cb (zm->error_cb_cls);
}
zm->mq = GNUNET_CLIENT_connecT (zm->cfg,
"namestore",
* @param zone zone to monitor
* @param iterate_first #GNUNET_YES to first iterate over all existing records,
* #GNUNET_NO to only return changes that happen from now on
+ * @param error_cb function to call on error (i.e. disconnect); note that
+ * unlike the other error callbacks in this API, a call to this
+ * function does NOT destroy the monitor handle, it merely signals
+ * that monitoring is down. You need to still explicitly call
+ * #GNUNET_NAMESTORE_zone_monitor_stop().
+ * @param error_cb_cls closure for @a error_cb
* @param monitor function to call on zone changes
+ * @param monitor_cls closure for @a monitor
* @param sync_cb function called when we're in sync with the namestore
- * @param cls closure for @a monitor and @a sync_cb
+ * @param cls closure for @a sync_cb
* @return handle to stop monitoring
*/
struct GNUNET_NAMESTORE_ZoneMonitor *
GNUNET_NAMESTORE_zone_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
int iterate_first,
+ GNUNET_SCHEDULER_TaskCallback error_cb,
+ void *error_cb_cls,
GNUNET_NAMESTORE_RecordMonitor monitor,
- GNUNET_NAMESTORE_RecordsSynchronizedCallback sync_cb,
- void *cls)
+ void *monitor_cls,
+ GNUNET_SCHEDULER_TaskCallback sync_cb,
+ void *sync_cb_cls)
{
struct GNUNET_NAMESTORE_ZoneMonitor *zm;
if (NULL != zone)
zm->zone = *zone;
zm->iterate_first = iterate_first;
+ zm->error_cb = error_cb;
+ zm->error_cb_cls = error_cb_cls;
zm->monitor = monitor;
+ zm->monitor_cls = monitor_cls;
zm->sync_cb = sync_cb;
- zm->cls = cls;
+ zm->sync_cb_cls = sync_cb_cls;
zm->cfg = cfg;
reconnect (zm);
if (NULL == zm->mq)
}
+/**
+ * Iteration over all results finished, build final
+ * response.
+ *
+ * @param cls the `struct RequestHandle`
+ */
+static void
+namestore_list_finished (void *cls)
+{
+ struct RequestHandle *handle = cls;
+ char *result;
+ struct MHD_Response *resp;
+
+ handle->list_it = NULL;
+ if (GNUNET_SYSERR ==
+ GNUNET_JSONAPI_document_serialize (handle->resp_object,
+ &result))
+ {
+ do_error (handle);
+ return;
+ }
+ resp = GNUNET_REST_create_response (result);
+ handle->proc (handle->proc_cls,
+ resp,
+ MHD_HTTP_OK);
+ GNUNET_free_non_null (result);
+ GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed,
+ handle);
+}
+
+
+
/**
* Create a response with requested records
*
{
struct RequestHandle *handle = cls;
struct GNUNET_JSONAPI_Resource *json_resource;
- struct MHD_Response *resp;
json_t *result_array;
json_t *record_obj;
int i;
- char *result;
if (NULL == handle->resp_object)
handle->resp_object = GNUNET_JSONAPI_document_new ();
- if (NULL == rname)
- {
- handle->list_it = NULL;
- //Handle response
- if (GNUNET_SYSERR == GNUNET_JSONAPI_document_serialize (handle->resp_object, &result))
- {
- GNUNET_SCHEDULER_add_now (&do_error, handle);
- return;
- }
- resp = GNUNET_REST_create_response (result);
- handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
- GNUNET_free_non_null (result);
- GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
- return;
- }
-
if ( (NULL != handle->name) &&
(0 != strcmp (handle->name, rname)) )
{
GNUNET_NAMESTORE_zone_iterator_next (handle->list_it);
}
+
static void
create_finished (void *cls, int32_t success, const char *emsg)
{
struct RequestHandle *handle = cls;
handle->add_qe = NULL;
- if ( (NULL != zone_key) &&
- (0 != strcmp (rec_name, handle->name)) )
+ if (0 != strcmp (rec_name, handle->name))
{
GNUNET_break (0);
- GNUNET_SCHEDULER_add_now (&do_error, handle);
+ do_error (handle);
return;
}
handle);
}
+
static void
del_finished (void *cls,
int32_t success,
GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
}
+
static void
del_cont (void *cls,
const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
const struct GNUNET_GNSRECORD_Data *rd)
{
struct RequestHandle *handle = cls;
+
handle->add_qe = NULL;
if (0 == rd_count)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("There are no records under label `%s' that could be deleted.\n"),
label);
- GNUNET_SCHEDULER_add_now (&do_error, handle);
+ do_error (handle);
return;
}
handle);
}
+
static void
namestore_delete_cont (struct GNUNET_REST_RequestHandle *con,
const char *url,
handle->add_qe = GNUNET_NAMESTORE_records_lookup (handle->ns_handle,
&handle->zone_pkey,
handle->name,
+ &do_error,
+ handle,
&del_cont,
handle);
}
+
static int
json_to_gnsrecord (const json_t *records_json,
struct GNUNET_GNSRECORD_Data **rd,
return GNUNET_OK;
}
+
static void
namestore_create_cont (struct GNUNET_REST_RequestHandle *con,
const char *url,
GNUNET_JSON_spec_jsonapi_document (&json_obj),
GNUNET_JSON_spec_end()
};
-
+
if (strlen (GNUNET_REST_API_NS_NAMESTORE) != strlen (handle->url))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
handle->add_qe = GNUNET_NAMESTORE_records_lookup (handle->ns_handle,
&handle->zone_pkey,
handle->name,
- &create_new_record_cont, handle );
+ &do_error,
+ handle,
+ &create_new_record_cont,
+ handle);
}
+
static void
namestore_zkey_response (void *cls,
const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
GNUNET_JSONAPI_document_delete (json_obj);
GNUNET_free (result);
GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
- return;
-
}
+
static void
namestore_zkey_cont (struct GNUNET_REST_RequestHandle *con,
const char *url,
handle->reverse_qe = GNUNET_NAMESTORE_zone_to_name (handle->ns_handle,
&handle->zone_pkey,
&pubkey,
+ &do_error,
+ handle,
&namestore_zkey_response,
handle);
}
+
static void
namestore_info_cont (struct GNUNET_REST_RequestHandle *con,
const char *url,
void *cls)
{
struct RequestHandle *handle = cls;
+
handle->list_it = GNUNET_NAMESTORE_zone_iteration_start (handle->ns_handle,
&handle->zone_pkey,
+ &do_error,
+ handle,
&namestore_list_response,
+ handle,
+ &namestore_list_finished,
handle);
}
+
static char*
get_name_from_url (const char* url)
{
[nse]
WORKBITS = 0
+
+[transport]
+PLUGINS =
}
+static void
+fail_cb (void *cls)
+{
+ GNUNET_assert (0);
+}
+
+
static void
put_cont (void *cls, int32_t success, const char *emsg)
{
return;
}
/* Lookup */
- nsqe = GNUNET_NAMESTORE_records_lookup (nsh, privkey, name, lookup_it, NULL);
+ nsqe = GNUNET_NAMESTORE_records_lookup (nsh,
+ privkey,
+ name,
+ &fail_cb,
+ NULL,
+ &lookup_it,
+ NULL);
}
+
static void
nick_cont (void *cls, int32_t success, const char *emsg)
{
{
nsqe = NULL;
- if (0 != memcmp(privkey, zone, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
+ if (0 != memcmp (privkey,
+ zone,
+ sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
{
GNUNET_break(0);
GNUNET_SCHEDULER_cancel (endbadly_task);
}
+static void
+fail_cb (void *cls)
+{
+ GNUNET_assert (0);
+}
+
+
static void
put_cont (void *cls, int32_t success, const char *emsg)
{
return;
}
/* Lookup */
- nsqe = GNUNET_NAMESTORE_records_lookup (nsh, privkey, name, lookup_it, NULL);
+ nsqe = GNUNET_NAMESTORE_records_lookup (nsh,
+ privkey,
+ name,
+ &fail_cb,
+ NULL,
+ &lookup_it,
+ NULL);
}
char *label = cls;
if (0 == strcmp (label, s_name_1))
- ns_ops[0] = NULL;
+ ns_ops[0] = NULL;
else if (0 == strcmp (label, s_name_2))
- ns_ops[1] = NULL;
+ ns_ops[1] = NULL;
else if (0 == strcmp (label, s_name_3))
- ns_ops[2] = NULL;
+ ns_ops[2] = NULL;
if (success == GNUNET_OK)
{
}
+static void
+fail_cb (void *cls)
+{
+ GNUNET_assert (0);
+}
+
+
+static void
+sync_cb (void *cls)
+{
+ /* do nothing */
+}
+
+
static void
run (void *cls,
const struct GNUNET_CONFIGURATION_Handle *cfg,
zm = GNUNET_NAMESTORE_zone_monitor_start (cfg,
privkey,
GNUNET_YES,
+ &fail_cb,
+ NULL,
&zone_proc,
NULL,
+ &sync_cb,
NULL);
if (NULL == zm)
{
static char *directory;
+
static void
do_shutdown ()
{
else
GNUNET_SCHEDULER_add_now (&end, NULL);
}
+}
+
+static void
+fail_cb (void *cls)
+{
+ GNUNET_assert (0);
+}
+
+
+static void
+sync_cb (void *cls)
+{
+ /* do nothing */
}
zm = GNUNET_NAMESTORE_zone_monitor_start (cfg,
privkey,
GNUNET_YES,
+ &fail_cb,
+ NULL,
&zone_proc,
NULL,
+ &sync_cb,
NULL);
if (NULL == zm)
{
}
+static void
+zone_end (void *cls)
+{
+ GNUNET_break (3 == returned_records);
+ if (3 == returned_records)
+ {
+ res = 0; /* Last iteraterator callback, we are done */
+ zi = NULL;
+ }
+ else
+ res = 1;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received last result, iteration done after receing %u results\n",
+ returned_records);
+ GNUNET_SCHEDULER_add_now (&end, NULL);
+}
+
+
+static void
+fail_cb (void *cls)
+{
+ GNUNET_assert (0);
+}
+
+
static void
zone_proc (void *cls,
const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
{
int failed = GNUNET_NO;
- if ((zone == NULL) && (label == NULL))
- {
- GNUNET_break (3 == returned_records);
- if (3 == returned_records)
- {
- res = 0; /* Last iteraterator callback, we are done */
- zi = NULL;
- }
- else
- res = 1;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received last result, iteration done after receing %u results\n",
- returned_records);
- GNUNET_SCHEDULER_add_now (&end, NULL);
- return;
- }
GNUNET_assert (NULL != zone);
if (0 == memcmp (zone, privkey, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
{
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_end,
NULL);
if (zi == NULL)
{
unsigned int rd_count,
const struct GNUNET_GNSRECORD_Data *rd)
{
- char *hostkey_file;
-
GNUNET_assert (nsh == cls);
if (NULL != zone)
{
endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
return;
}
+ GNUNET_assert (0);
+}
+static void
+empty_zone_end (void *cls)
+{
+ char *hostkey_file;
+
zi = NULL;
- GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR,
- "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
+ GNUNET_asprintf (&hostkey_file,
+ "zonefiles%s%s",
+ DIR_SEPARATOR_STR,
+ "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Using zonekey file `%s' \n",
+ hostkey_file);
privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
GNUNET_free (hostkey_file);
GNUNET_assert (privkey != NULL);
- GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR,
- "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey");
+ GNUNET_asprintf (&hostkey_file,
+ "zonefiles%s%s",
+ DIR_SEPARATOR_STR,
+ "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey");
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
GNUNET_free (hostkey_file);
GNUNET_asprintf(&s_name_1, "dummy1");
s_rd_1 = create_record(1);
- GNUNET_NAMESTORE_records_store (nsh, privkey, s_name_1,
+ GNUNET_NAMESTORE_records_store (nsh,
+ privkey,
+ s_name_1,
1, s_rd_1,
&put_cont, NULL);
"Created record 2 \n");
GNUNET_asprintf(&s_name_2, "dummy2");
s_rd_2 = create_record(1);
- GNUNET_NAMESTORE_records_store (nsh, privkey, s_name_2,
- 1, s_rd_2, &put_cont, NULL);
+ GNUNET_NAMESTORE_records_store (nsh,
+ privkey,
+ s_name_2,
+ 1, s_rd_2,
+ &put_cont,
+ NULL);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Created record 3\n");
GNUNET_break (NULL != nsh);
/* first, iterate over empty namestore */
zi = GNUNET_NAMESTORE_zone_iteration_start(nsh,
- NULL, &empty_zone_proc, nsh);
+ NULL,
+ &fail_cb,
+ NULL,
+ &empty_zone_proc,
+ nsh,
+ &empty_zone_end,
+ NULL);
if (NULL == zi)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create zone iterator\n");
}
+static void
+zone_proc_end (void *cls)
+{
+ zi = NULL;
+ res = 0;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received last result, iteration done after receing %u results\n",
+ returned_records);
+ GNUNET_SCHEDULER_add_now (&end, NULL);
+}
+
+
static void
zone_proc (void *cls,
const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
const struct GNUNET_GNSRECORD_Data *rd)
{
int failed = GNUNET_NO;
- if ((zone == NULL) && (label == NULL))
- {
- zi = NULL;
- res = 0;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received last result, iteration done after receing %u results\n",
- returned_records);
- GNUNET_SCHEDULER_add_now (&end, NULL);
- return;
- }
+
GNUNET_assert (NULL != zone);
if (0 == memcmp (zone, privkey, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
{
}
+static void
+fail_cb (void *cls)
+{
+ GNUNET_assert (0);
+}
+
+
static void
put_cont (void *cls, int32_t success, const char *emsg)
{
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)
{
unsigned int rd_count,
const struct GNUNET_GNSRECORD_Data *rd)
{
- char *hostkey_file;
GNUNET_assert (nsh == cls);
+
if (NULL != zone)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
return;
}
+ GNUNET_assert (0);
+}
+
+
+static void
+empty_zone_end (void *cls)
+{
+ char *hostkey_file;
+ GNUNET_assert (nsh == cls);
zi = NULL;
GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR,
/* first, iterate over empty namestore */
zi = GNUNET_NAMESTORE_zone_iteration_start(nsh,
- NULL, &empty_zone_proc, nsh);
+ NULL,
+ &fail_cb,
+ NULL,
+ &empty_zone_proc,
+ nsh,
+ &empty_zone_end,
+ nsh);
if (NULL == zi)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
}
+static void
+fail_cb (void *cls)
+{
+ GNUNET_assert (0);
+}
+
+
static void
zone_proc (void *cls,
- const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
- const char *label,
- unsigned int rd_count,
- const struct GNUNET_GNSRECORD_Data *rd)
+ const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
+ const char *label,
+ unsigned int rd_count,
+ const struct GNUNET_GNSRECORD_Data *rd)
{
int failed = GNUNET_NO;
- if ((zone == NULL) && (label == NULL))
- {
- GNUNET_break (2 == returned_records);
- if (2 == returned_records)
- {
- res = 0; /* Last iteraterator callback, we are done */
- zi = NULL;
- }
- else
- res = 1;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received last result, iteration done after receing %u results\n",
- returned_records );
- GNUNET_SCHEDULER_add_now (&end, NULL);
- return;
- }
GNUNET_assert (NULL != zone);
if (0 == memcmp (zone,
privkey,
}
+static void
+zone_proc_end (void *cls)
+{
+ GNUNET_break (2 == returned_records);
+ if (2 == returned_records)
+ {
+ res = 0; /* Last iteraterator callback, we are done */
+ zi = NULL;
+ }
+ else
+ res = 1;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received last result, iteration done after receing %u results\n",
+ returned_records);
+ GNUNET_SCHEDULER_add_now (&end, NULL);
+}
+
+
static void
put_cont (void *cls, int32_t success, const char *emsg)
{
"All records created, starting iteration over all zones \n");
zi = GNUNET_NAMESTORE_zone_iteration_start(nsh,
privkey,
+ &fail_cb,
+ NULL,
&zone_proc,
- NULL);
+ NULL,
+ &zone_proc_end,
+ NULL);
if (zi == NULL)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
unsigned int rd_count,
const struct GNUNET_GNSRECORD_Data *rd)
{
- char *hostkey_file;
-
GNUNET_assert (nsh == cls);
if (NULL != zone)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Expected empty zone but received zone private key\n"));
- GNUNET_break (0);
- if (endbadly_task != NULL)
- GNUNET_SCHEDULER_cancel (endbadly_task);
- endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Expected empty zone but received zone private key\n"));
+ GNUNET_break (0);
+ if (endbadly_task != NULL)
+ GNUNET_SCHEDULER_cancel (endbadly_task);
+ endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
+ return;
+ }
if ((NULL != label) || (NULL != rd) || (0 != rd_count))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Expected no zone content but received data\n"));
- GNUNET_break (0);
- if (endbadly_task != NULL)
- GNUNET_SCHEDULER_cancel (endbadly_task);
- endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Expected no zone content but received data\n"));
+ GNUNET_break (0);
+ if (endbadly_task != NULL)
+ GNUNET_SCHEDULER_cancel (endbadly_task);
+ endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
+ return;
+ }
+ GNUNET_assert (0);
+}
+static void
+empty_zone_proc_end (void *cls)
+{
+ char *hostkey_file;
+
zi = NULL;
- GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR,
- "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
- privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
+ GNUNET_asprintf (&hostkey_file,
+ "zonefiles%s%s",
+ DIR_SEPARATOR_STR,
+ "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Using zonekey file `%s'\n",
+ hostkey_file);
+ privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
GNUNET_free (hostkey_file);
GNUNET_assert (privkey != NULL);
- GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR,
- "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
+ GNUNET_asprintf(&hostkey_file,
+ "zonefiles%s%s",
+ DIR_SEPARATOR_STR,
+ "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Using zonekey file `%s' \n",
+ hostkey_file);
privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
GNUNET_free (hostkey_file);
GNUNET_assert (privkey2 != NULL);
"Created record 1\n");
GNUNET_asprintf(&s_name_1, "dummy1");
- s_rd_1 = create_record(1);
- GNUNET_NAMESTORE_records_store(nsh, privkey, s_name_1,
- 1, s_rd_1, &put_cont, NULL);
+ s_rd_1 = create_record (1);
+ GNUNET_NAMESTORE_records_store (nsh,
+ privkey,
+ s_name_1,
+ 1,
+ s_rd_1,
+ &put_cont,
+ NULL);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Created record 2 \n");
GNUNET_asprintf(&s_name_2, "dummy2");
- s_rd_2 = create_record(1);
- GNUNET_NAMESTORE_records_store(nsh, privkey, s_name_2,
- 1, s_rd_2, &put_cont, NULL);
+ s_rd_2 = create_record (1);
+ GNUNET_NAMESTORE_records_store (nsh,
+ privkey,
+ s_name_2,
+ 1,
+ s_rd_2,
+ &put_cont,
+ NULL);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Created record 3\n");
/* name in different zone */
GNUNET_asprintf(&s_name_3, "dummy3");
- s_rd_3 = create_record(1);
- GNUNET_NAMESTORE_records_store(nsh, privkey2, s_name_3,
- 1, s_rd_3, &put_cont, NULL);
+ s_rd_3 = create_record (1);
+ GNUNET_NAMESTORE_records_store (nsh,
+ privkey2,
+ s_name_3,
+ 1, s_rd_3,
+ &put_cont,
+ NULL);
}
/* first, iterate over empty namestore */
zi = GNUNET_NAMESTORE_zone_iteration_start (nsh,
NULL,
- &empty_zone_proc, nsh);
+ &fail_cb,
+ NULL,
+ &empty_zone_proc,
+ nsh,
+ &empty_zone_proc_end,
+ nsh);
if (NULL == zi)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
}
+static void
+fail_cb (void *cls)
+{
+ GNUNET_assert (0);
+}
+
+
static void
zone_proc (void *cls,
const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
const struct GNUNET_GNSRECORD_Data *rd)
{
int failed = GNUNET_NO;
- if ((zone == NULL) && (label == NULL))
- {
- GNUNET_break (1 <= returned_records);
- if (1 >= returned_records)
- res = 1; /* Last iteraterator callback, we are done */
- else
- res = 0;
- zi = NULL;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received last result, iteration done after receing %u results\n",
- returned_records );
- GNUNET_SCHEDULER_add_now (&end, NULL);
- return;
- }
+
GNUNET_assert (NULL != zone);
if (0 == memcmp (zone, privkey, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
{
}
+static void
+zone_proc_end (void *cls)
+{
+ GNUNET_break (1 <= returned_records);
+ if (1 >= returned_records)
+ res = 1; /* Last iteraterator callback, we are done */
+ else
+ res = 0;
+ zi = NULL;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received last result, iteration done after receing %u results\n",
+ returned_records);
+ GNUNET_SCHEDULER_add_now (&end, NULL);
+}
+
+
static void
put_cont (void *cls, int32_t success, const char *emsg)
{
{
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,
- &zone_proc,
- NULL);
+ 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_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to create zone iterator\n");
GNUNET_break (0);
if (NULL != endbadly_task)
GNUNET_SCHEDULER_cancel (endbadly_task);
unsigned int rd_count,
const struct GNUNET_GNSRECORD_Data *rd)
{
- char *hostkey_file;
GNUNET_assert (nsh == cls);
if (NULL != zone)
endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
return;
}
+ GNUNET_assert (0);
+}
+
+static void
+empty_zone_proc_end (void *cls)
+{
+ char *hostkey_file;
+
+ GNUNET_assert (nsh == cls);
zi = NULL;
- GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR,
- "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
+ GNUNET_asprintf(&hostkey_file,
+ "zonefiles%s%s",
+ DIR_SEPARATOR_STR,
+ "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Using zonekey file `%s' \n",
+ hostkey_file);
privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
GNUNET_free (hostkey_file);
GNUNET_assert (privkey != NULL);
- GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR,
- "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
+ GNUNET_asprintf (&hostkey_file,
+ "zonefiles%s%s",
+ DIR_SEPARATOR_STR,
+ "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Using zonekey file `%s'\n",
+ hostkey_file);
privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
GNUNET_free (hostkey_file);
GNUNET_assert (privkey2 != NULL);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 1\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Created record 1\n");
- GNUNET_asprintf(&s_name_1, "dummy1");
+ GNUNET_asprintf(&s_name_1,
+ "dummy1");
s_rd_1 = create_record(1);
GNUNET_NAMESTORE_records_store(nsh, privkey, s_name_1,
1, s_rd_1, &put_cont, NULL);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n");
- GNUNET_asprintf(&s_name_2, "dummy2");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Created record 2 \n");
+ GNUNET_asprintf(&s_name_2,
+ "dummy2");
s_rd_2 = create_record(1);
- GNUNET_NAMESTORE_records_store(nsh, privkey, s_name_2,
- 1, s_rd_2, &put_cont, NULL);
+ GNUNET_NAMESTORE_records_store (nsh,
+ privkey,
+ s_name_2,
+ 1,
+ s_rd_2,
+ &put_cont, NULL);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 3\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Created record 3\n");
/* name in different zone */
GNUNET_asprintf(&s_name_3, "dummy3");
s_rd_3 = create_record(1);
- GNUNET_NAMESTORE_records_store(nsh, privkey2, s_name_3,
- 1, s_rd_3, &put_cont, NULL);
+ GNUNET_NAMESTORE_records_store(nsh,
+ privkey2,
+ s_name_3,
+ 1,
+ s_rd_3,
+ &put_cont, NULL);
}
GNUNET_break (NULL != nsh);
/* first, iterate over empty namestore */
zi = GNUNET_NAMESTORE_zone_iteration_start(nsh,
- NULL, &empty_zone_proc, nsh);
+ NULL,
+ &fail_cb,
+ NULL,
+ &empty_zone_proc,
+ nsh,
+ &empty_zone_proc_end,
+ nsh);
if (NULL == zi)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,