fort_SOURCES += notify.c notify.h
fort_SOURCES += output_printer.h output_printer.c
fort_SOURCES += random.h random.c
-fort_SOURCES += reqs_errors.h reqs_errors.c
fort_SOURCES += resource.h resource.c
fort_SOURCES += rpp.h rpp.c
fort_SOURCES += sorted_array.h sorted_array.c
#include "extension.h"
#include "internal_pool.h"
#include "nid.h"
-#include "reqs_errors.h"
#include "thread_var.h"
#include "validation_run.h"
#include "http/http.h"
error = db_rrdp_init();
if (error)
goto vrps_cleanup;
- error = reqs_errors_init();
- if (error)
- goto db_rrdp_cleanup;
/* Do stuff */
switch (config_get_mode()) {
/* End */
- reqs_errors_cleanup();
-db_rrdp_cleanup:
db_rrdp_cleanup();
vrps_cleanup:
vrps_destroy();
#include "extension.h"
#include "log.h"
#include "nid.h"
-#include "reqs_errors.h"
#include "str_token.h"
#include "thread_var.h"
#include "asn1/decode.h"
/* Reach here on error or when both access methods were utilized */
switch (error) {
case 0:
- /* Remove the error'd URI, since we got the repo files */
- if (working_repo_peek() != NULL)
- reqs_errors_rem_uri(working_repo_peek());
break;
case EREQFAILED:
/* Log that we'll try to work with a local copy */
#include "line_file.h"
#include "log.h"
#include "random.h"
-#include "reqs_errors.h"
#include "state.h"
#include "thread_var.h"
#include "validation_handler.h"
/* At least one URI was sync'd */
thread->retry_local = false;
- if (thread->sync_files && working_repo_peek() != NULL)
- reqs_errors_rem_uri(working_repo_peek());
working_repo_pop();
pr_val_debug("TAL URI '%s' {", uri_val_get_printable(uri));
+++ /dev/null
-#include "reqs_errors.h"
-
-#include <pthread.h>
-#include <syslog.h>
-#include <time.h>
-
-#include "data_structure/uthash.h"
-#include "alloc.h"
-#include "common.h"
-#include "config.h"
-#include "log.h"
-#include "thread_var.h"
-
-/* TODO (#78) Is any of this still useful? */
-
-struct error_uri {
- /* Key */
- char *uri;
- /* Date when the first attempt was made */
- time_t first_attempt;
- /* Related URI (points to a key of another element) */
- char *uri_related;
- /* Refered by (where this.uri == that.uri_related) */
- char *ref_by;
- UT_hash_handle hh;
-};
-
-static struct error_uri *err_uris_db;
-
-/* Prepare for multithreading. */
-static pthread_rwlock_t db_lock;
-
-static int
-error_uri_create(char const *uri, struct error_uri **err_uri)
-{
- struct error_uri *tmp;
- int error;
-
- tmp = pzalloc(sizeof(struct error_uri)); /* Zero needed by uthash */
-
- tmp->uri = pstrdup(uri);
- error = get_current_time(&tmp->first_attempt);
- if (error)
- goto release_uri;
- tmp->uri_related = NULL;
- tmp->ref_by = NULL;
-
- *err_uri = tmp;
- return 0;
-
-release_uri:
- free(tmp->uri);
- free(tmp);
- return error;
-}
-
-static void
-error_uri_destroy(struct error_uri *err_uri)
-{
- free(err_uri->uri);
- free(err_uri);
-}
-
-int
-reqs_errors_init(void)
-{
- int error;
-
- error = pthread_rwlock_init(&db_lock, NULL);
- if (error) {
- pr_op_err("pthread_rwlock_init() errored: %s", strerror(error));
- return error;
- }
-
- err_uris_db = NULL;
-
- return 0;
-}
-
-void
-reqs_errors_cleanup(void)
-{
- /* Remove all the uris */
- struct error_uri *node, *tmp;
-
- HASH_ITER(hh, err_uris_db, node, tmp) {
- HASH_DEL(err_uris_db, node);
- error_uri_destroy(node);
- }
-
- pthread_rwlock_destroy(&db_lock); /* Nothing to do with error code */
-}
-
-static struct error_uri *
-find_error_uri(char const *search, bool lock)
-{
- struct error_uri *found;
-
- if (lock)
- rwlock_read_lock(&db_lock);
- HASH_FIND_STR(err_uris_db, search, found);
- if (lock)
- rwlock_unlock(&db_lock);
-
- return found;
-}
-
-static void
-set_working_repo(struct error_uri *err_uri)
-{
- struct error_uri *ref;
- char const *work_uri;
-
- work_uri = working_repo_peek();
- if (work_uri == NULL)
- return;
-
- ref = find_error_uri(work_uri, true);
- if (ref == NULL)
- return;
-
- err_uri->uri_related = ref->uri;
- ref->ref_by = err_uri->uri;
-}
-
-int
-reqs_errors_add_uri(char const *uri)
-{
- struct error_uri *new_uri, *found_uri;
- int error;
-
- /* Don't overwrite if it already exists */
- found_uri = find_error_uri(uri, true);
- if (found_uri != NULL)
- return 0;
-
- new_uri = NULL;
- error = error_uri_create(uri, &new_uri);
- if (error)
- return error;
-
- set_working_repo(new_uri);
-
- rwlock_write_lock(&db_lock);
- HASH_ADD_STR(err_uris_db, uri, new_uri);
- rwlock_unlock(&db_lock);
-
- return 0;
-}
-
-void
-reqs_errors_rem_uri(char const *uri)
-{
- struct error_uri *found_uri;
- struct error_uri *tmp;
- char *ref_uri;
-
- rwlock_write_lock(&db_lock);
- found_uri = find_error_uri(uri, false);
- if (found_uri == NULL) {
- rwlock_unlock(&db_lock);
- return;
- }
-
- while (found_uri->uri_related != NULL) {
- tmp = find_error_uri(found_uri->uri_related, false);
- if (tmp == NULL)
- break;
- found_uri = tmp;
- }
-
- do {
- ref_uri = found_uri->ref_by;
- HASH_DELETE(hh, err_uris_db, found_uri);
- error_uri_destroy(found_uri);
- if (ref_uri == NULL)
- break;
- HASH_FIND_STR(err_uris_db, ref_uri, found_uri);
- if (found_uri == NULL)
- break;
- } while (true);
- rwlock_unlock(&db_lock);
-}
-
-int
-reqs_errors_foreach(reqs_errors_cb cb, void *arg)
-{
- struct error_uri *node, *tmp;
- int error;
-
- rwlock_read_lock(&db_lock);
- HASH_ITER(hh, err_uris_db, node, tmp) {
- error = cb(node->uri, arg);
- if (error) {
- rwlock_unlock(&db_lock);
- return error;
- }
- }
- rwlock_unlock(&db_lock);
-
- return 0;
-}
+++ /dev/null
-#ifndef SRC_REQS_ERRORS_H_
-#define SRC_REQS_ERRORS_H_
-
-#include <stdbool.h>
-
-/* TODO (#78) removable? */
-
-int reqs_errors_init(void);
-void reqs_errors_cleanup(void);
-
-int reqs_errors_add_uri(char const *);
-void reqs_errors_rem_uri(char const *);
-
-typedef int (reqs_errors_cb)(char const *, void *);
-int reqs_errors_foreach(reqs_errors_cb, void *);
-
-#endif /* SRC_REQS_ERRORS_H_ */
#include "common.h"
#include "config.h"
#include "log.h"
-#include "reqs_errors.h"
#include "thread_var.h"
#include "visited_uris.h"
struct visited_uris *visited;
rrdp_req_status_t requested;
rrdp_uri_cmp_result_t res;
- int error, upd_error;
+ int error;
(*data_updated) = false;
if (upd_notification == NULL) {
pr_val_debug("The Update Notification has not changed.");
- goto upd_end;
+ return 0;
}
pr_val_debug("The Update Notification changed.");
update_notification_destroy(upd_notification);
upd_end:
/* Just return on success */
- if (!error) {
- /* The repository URI is the notification file URI */
- reqs_errors_rem_uri(uri_get_global(uri));
+ if (!error)
return 0;
- }
/* Request failed, store the repository URI */
- if (error == EREQFAILED) {
- upd_error = reqs_errors_add_uri(uri_get_global(uri));
- if (upd_error)
- return upd_error;
- } else {
+ if (error != EREQFAILED) {
/* Reset RSYNC visited URIs, this may force the update */
/* TODO um, what? */
reset_downloaded();
#include "common.h"
#include "config.h"
#include "log.h"
-#include "reqs_errors.h"
#include "str_token.h"
#include "thread_var.h"
return error;
}
-/*
- * Returned values if the ancestor URI of @error_uri:
- * 0 - didn't had a previous request error
- * EEXIST - had a previous request error
- * < 0 - nothing, just something bad happened
- */
-static int
-ancestor_error(char const *error_uri, void *arg)
-{
- struct rpki_uri *search = arg;
- struct rpki_uri *req_err_uri;
- int error;
-
- req_err_uri = NULL;
- error = uri_create_mixed_str(&req_err_uri, error_uri,
- strlen(error_uri));
- switch(error) {
- case 0:
- break;
- default:
- return ENSURE_NEGATIVE(error);
- }
-
- /* Ignore non rsync error'd URIs */
- if (!uri_is_rsync(req_err_uri)) {
- uri_refput(req_err_uri);
- return 0;
- }
-
- error = is_descendant(req_err_uri, search) ? EEXIST : 0;
-
- uri_refput(req_err_uri);
- return error;
-}
-
-/* Validate if the ancestor URI error'd */
-static int
-check_ancestor_error(struct rpki_uri *requested_uri)
-{
- int error;
-
- error = reqs_errors_foreach(ancestor_error, requested_uri);
- if (error < 0)
- return error;
- /* Return the requests error'd code */
- if (error == EEXIST)
- return EREQFAILED;
-
- return 0;
-}
-
/**
* @is_ta: Are we rsync'ing the TA?
* The TA rsync will not be recursive, and will force SYNC_STRICT
if (!force && is_already_downloaded(requested_uri, visited_uris)) {
pr_val_debug("No need to redownload '%s'.",
uri_val_get_printable(requested_uri));
- return check_ancestor_error(requested_uri);
- }
-
- if (!force) {
- error = get_rsync_uri(requested_uri, is_ta, &rsync_uri);
- } else {
- error = check_ancestor_error(requested_uri);
- if (error)
- return error;
- error = handle_strict_strategy(requested_uri, &rsync_uri);
+ return 0;
}
+ error = force
+ ? handle_strict_strategy(requested_uri, &rsync_uri)
+ : get_rsync_uri(requested_uri, is_ta, &rsync_uri);
if (error)
return error;
/* Don't store when "force" and if its already downloaded */
if (!(force && is_already_downloaded(rsync_uri, visited_uris)))
mark_as_downloaded(rsync_uri, visited_uris);
- reqs_errors_rem_uri(uri_get_global(rsync_uri));
break;
case EREQFAILED:
- /* All attempts failed, avoid future requests */
- error = reqs_errors_add_uri(uri_get_global(rsync_uri));
- if (error)
- break;
mark_as_downloaded(rsync_uri, visited_uris);
error = EREQFAILED; /* Return the original error */
break;