]> git.ipfire.org Git - thirdparty/FORT-validator.git/commitdiff
Patch FIXME: Call cache_cleanup() on the regular
authorAlberto Leiva Popper <ydahhrk@gmail.com>
Thu, 23 Nov 2023 18:59:30 +0000 (12:59 -0600)
committerAlberto Leiva Popper <ydahhrk@gmail.com>
Thu, 23 Nov 2023 22:25:02 +0000 (16:25 -0600)
I realized I don't have much reason to not call it at the end of every
validation cycle. It's not particularly slow, and it doesn't do anything
risky.

src/cache/local_cache.c
src/cache/local_cache.h
src/rrdp.c
src/types/uri.c

index e33465500079899f387b96eeb4ec05c7da12ca56..90af30d48dc45427a876993f4058861fc6da1563 100644 (file)
@@ -258,27 +258,6 @@ end:       json_decref(json);
        free(filename);
 }
 
-static void
-delete_node(struct rpki_cache *cache, struct cache_node *node)
-{
-       HASH_DEL(cache->ht, node);
-       uri_refput(node->url);
-       free(node);
-}
-
-void
-cache_destroy(struct rpki_cache *cache)
-{
-       struct cache_node *node, *tmp;
-
-       write_metadata_json(cache);
-
-       HASH_ITER(hh, cache->ht, node, tmp)
-               delete_node(cache, node);
-       free(cache->tal);
-       free(cache);
-}
-
 static int
 get_url(struct rpki_uri *uri, const char *tal, struct rpki_uri **url)
 {
@@ -620,6 +599,33 @@ is_node_fresh(struct cache_node *node, time_t epoch)
        return difftime(epoch, node->attempt.ts) < 0;
 }
 
+static void
+delete_node(struct rpki_cache *cache, struct cache_node *node)
+{
+       HASH_DEL(cache->ht, node);
+       uri_refput(node->url);
+       free(node);
+}
+
+static void
+delete_node_and_cage(struct rpki_cache *cache, struct cache_node *node)
+{
+       struct rpki_uri *cage;
+       int error;
+
+       if (uri_get_type(node->url) == UT_HTTPS) {
+               error = __uri_create(&cage, cache->tal, UT_CAGED, node->url,
+                   "", 0);
+               if (!error) {
+                       pr_op_debug("Deleting cage %s.", uri_get_local(cage));
+                       file_rm_rf(uri_get_local(cage));
+                       uri_refput(cage);
+               }
+       }
+
+       delete_node(cache, node);
+}
+
 static time_t
 get_days_ago(int days)
 {
@@ -647,15 +653,17 @@ static void
 cleanup_node(struct rpki_cache *cache, struct cache_node *node,
     time_t last_week)
 {
+       char const *path;
        int error;
 
-       error = file_exists(uri_get_local(node->url));
+       path = uri_get_local(node->url);
+       error = file_exists(path);
        switch (error) {
        case 0:
                break;
        case ENOENT:
                /* Node exists but file doesn't: Delete node */
-               delete_node(cache, node);
+               delete_node_and_cage(cache, node);
                return;
        default:
                pr_op_err("Trouble cleaning '%s'; stat() returned errno %d: %s",
@@ -663,12 +671,14 @@ cleanup_node(struct rpki_cache *cache, struct cache_node *node,
        }
 
        if (!is_node_fresh(node, last_week)) {
-               file_rm_rf(uri_get_local(node->url));
-               delete_node(cache, node);
+               pr_op_debug("Deleting expired cache element %s.", path);
+               file_rm_rf(path);
+               delete_node_and_cage(cache, node);
        }
 }
 
-void
+/* Deletes old untraversed cached files, writes metadata into XML */
+static void
 cache_cleanup(struct rpki_cache *cache)
 {
        struct cache_node *node, *tmp;
@@ -677,6 +687,18 @@ cache_cleanup(struct rpki_cache *cache)
        last_week = get_days_ago(7);
        HASH_ITER(hh, cache->ht, node, tmp)
                cleanup_node(cache, node, last_week);
+}
 
+void
+cache_destroy(struct rpki_cache *cache)
+{
+       struct cache_node *node, *tmp;
+
+       cache_cleanup(cache);
        write_metadata_json(cache);
+
+       HASH_ITER(hh, cache->ht, node, tmp)
+               delete_node(cache, node);
+       free(cache->tal);
+       free(cache);
 }
index 44abf1ff1fc8c1f7fa55132fa7f1012bf726657f..3b677fdbd22e3627cbcdebe64184d172ca41e392 100644 (file)
@@ -28,8 +28,4 @@ struct rpki_uri *cache_recover(struct rpki_cache *, struct uri_list *, bool);
 /* Prints the cache in standard output. */
 void cache_print(struct rpki_cache *);
 
-/* Deletes old untraversed cached files, writes metadata into XML */
-/* FIXME call this */
-void cache_cleanup(struct rpki_cache *);
-
 #endif /* SRC_CACHE_LOCAL_CACHE_H_ */
index c393e9347da3194e84d4e3360495658a39cb956b..2c09fef882d96d878818c419e756492a07d239b1 100644 (file)
@@ -835,6 +835,12 @@ handle_snapshot(struct update_notification *notif)
        pr_val_debug("Processing snapshot '%s'.", uri_val_get_printable(uri));
        fnstack_push_uri(uri);
 
+       /*
+        * TODO (performance) Is there a point in caching the snapshot?
+        * Especially considering we delete it 4 lines afterwards.
+        * Maybe stream it instead.
+        * Same for deltas.
+        */
        error = cache_download(validation_cache(state), uri, NULL);
        if (error)
                goto end;
index 3e30bfb2e276986d3187988d449f10d2769dc972..779b4c6cbb1dfa6cf3088ddbcb3f78a3ef67fb79 100644 (file)
@@ -357,13 +357,17 @@ map_caged(struct rpki_uri *uri, char const *tal, struct rpki_uri *notif)
        error = get_rrdp_workspace(&pb, tal, notif);
        if (error)
                return error;
+
+       if (uri->global[0] == '\0')
+               goto end; /* Caller is only interested in the cage. */
+
        error = append_guri(&pb, uri->global, "rsync://", ENOTRSYNC, true);
        if (error) {
                pb_cleanup(&pb);
                return error;
        }
 
-       uri->local = pb.string;
+end:   uri->local = pb.string;
        return 0;
 }