]> git.ipfire.org Git - thirdparty/FORT-validator.git/commitdiff
Do not apply "rsync by module" hack to TA rsyncs
authorAlberto Leiva Popper <ydahhrk@gmail.com>
Mon, 3 Nov 2025 22:20:20 +0000 (16:20 -0600)
committerAlberto Leiva Popper <ydahhrk@gmail.com>
Mon, 3 Nov 2025 22:20:20 +0000 (16:20 -0600)
Let:

- A = The TA and RPP share rsync modules
- B = RRDP is available

If the "rsync by module" hack is applied to TAs and Fort downloads the
TA by rsync,

- If A and B, Fort performs 1 big rsync and 1 big RRDP update
- If A and !B, Fort performs 1 big rsync
- If !A and B, Fort performs 1 single-file rsync and 1 big RRDP update
- If !A and !B, Fort performs 1 single-file rsync and 1 big rsync

If the "rsync by module" hack is not applied to TAs and Fort downloads
the TA by rsync,

- If A and B, Fort performs 1 single-file rsync and 1 big RRDP update
- If A and !B, Fort performs 1 single-file rsync and 1 big rsync
- If !A and B, Fort performs 1 single-file rsync and 1 big RRDP update
- If !A and !B, Fort performs 1 single-file rsync and 1 big rsync

So not applying the hack on TAs is more cache-efficient.

src/cache.c
src/cache.h
src/object/tal.c
src/types/uri.c
src/types/uri.h

index 82b6413af21131da8e5296d48116099a02668393..2978e410f0babdad736b6a367c85ef3b5c969732 100644 (file)
@@ -894,12 +894,11 @@ write_metadata(struct cache_node *node)
 }
 
 /*
- * @uri is either a caRepository or a rpkiNotify
- * By contract, only sets @result on return 0.
- * By contract, @result->state will be DLS_FRESH on return 0.
+ * By contract, only sets @result on return VV_CONTINUE.
+ * By contract, @result->state will be DLS_FRESH on return VV_CONTINUE.
  */
 static validation_verdict
-do_refresh(struct cache_table *tbl, struct uri const *uri,
+do_refresh(struct cache_table *tbl, struct uri const *uri, bool single,
     struct cache_node **result)
 {
        struct uri module;
@@ -914,7 +913,9 @@ do_refresh(struct cache_table *tbl, struct uri const *uri,
        }
 
        if (tbl == &cache.rsync) {
-               if (!get_rsync_module(uri, &module))
+               if (single)
+                       module = *uri;
+               else if (!get_rsync_module(uri, &module))
                        return VV_FAIL;
                mutex_lock(&tbl->lock);
                node = provide_node(tbl, NULL, &module);
@@ -1008,36 +1009,38 @@ get_fallback(struct extension_uris *uris)
        return (difftime(rsync->success_ts, rrdp->success_ts) > 0) ? rsync : rrdp;
 }
 
-validation_verdict
-cache_refresh_by_url(struct uri const *url, char **result)
+static validation_verdict
+cache_refresh_url(struct cache_table *table, struct uri const *url,
+    char const **result)
 {
-       struct cache_node *node = NULL;
+       struct cache_node *node;
        validation_verdict vv;
 
-       if (uri_is_https(url)) {
-               vv = do_refresh(&cache.https, url, &node);
-               if (vv != VV_CONTINUE)
-                       goto oops;
-               *result = node ? pstrdup(node->path) : NULL;
-               return VV_CONTINUE;
+       vv = do_refresh(table, url, true, &node);
+       if (vv != VV_CONTINUE) {
+               *result = NULL;
+               return vv;
        }
 
-       if (uri_is_rsync(url)) {
-               vv = do_refresh(&cache.rsync, url, &node);
-               if (vv != VV_CONTINUE)
-                       goto oops;
-               *result = path_join(node->path, strip_rsync_module(uri_str(url)));
-               return VV_CONTINUE;
-       }
+       *result = node->path;
+       return VV_CONTINUE;
+}
 
-       vv = VV_FAIL;
-oops:  *result = NULL;
-       return vv;
+validation_verdict
+cache_refresh_url_https(struct uri const *url, char const **result)
+{
+       return cache_refresh_url(&cache.https, url, result);
+}
+
+validation_verdict
+cache_refresh_url_rsync(struct uri const *url, char const **result)
+{
+       return cache_refresh_url(&cache.rsync, url, result);
 }
 
 /* HTTPS (TAs) and rsync only; don't use this for RRDP. */
 validation_verdict
-cache_get_fallback(struct uri const *url, char **result)
+cache_get_fallback(struct uri const *url, char const **result)
 {
        struct cache_node *node;
 
@@ -1055,7 +1058,7 @@ cache_get_fallback(struct uri const *url, char **result)
                return VV_CONTINUE;
        }
 
-       *result = pstrdup(node->path);
+       *result = node->path;
        return VV_CONTINUE;
 }
 
@@ -1076,7 +1079,7 @@ cache_refresh_by_uris(struct extension_uris *uris, struct cache_cage **result)
 
        /* Try RRDP + optional fallback */
        if (uri_str(&uris->rpkiNotify) != NULL) {
-               vv = do_refresh(&cache.rrdp, &uris->rpkiNotify, &node);
+               vv = do_refresh(&cache.rrdp, &uris->rpkiNotify, false, &node);
                if (vv == VV_CONTINUE)
                        goto refresh_success;
                if (vv == VV_BUSY)
@@ -1084,7 +1087,7 @@ cache_refresh_by_uris(struct extension_uris *uris, struct cache_cage **result)
        }
 
        /* Try rsync + optional fallback */
-       vv = do_refresh(&cache.rsync, &uris->caRepository, &node);
+       vv = do_refresh(&cache.rsync, &uris->caRepository, false, &node);
        if (vv == VV_CONTINUE)
                goto refresh_success;
        if (vv == VV_BUSY)
index 258d6139cae822b9a9201fc9490f4643c9db1867..fd1a2f2e2478a76a06b81da54d3fff1df520017b 100644 (file)
@@ -36,8 +36,9 @@ struct extension_uris {
 void exturis_init(struct extension_uris *);
 void exturis_cleanup(struct extension_uris *);
 
-validation_verdict cache_refresh_by_url(struct uri const *, char **);
-validation_verdict cache_get_fallback(struct uri const *, char **);
+validation_verdict cache_refresh_url_https(struct uri const *, char const **);
+validation_verdict cache_refresh_url_rsync(struct uri const *, char const **);
+validation_verdict cache_get_fallback(struct uri const *, char const **);
 
 struct cache_cage;
 validation_verdict cache_refresh_by_uris(struct extension_uris *,
index fa0831f24b1493ca20a1c071028419dd170a94ff..278c2ed996f9ac386a59d6277bdfb78908c60d0e 100644 (file)
@@ -157,16 +157,16 @@ validate_ta(struct tal *tal, struct cache_mapping const *ta_map)
 }
 
 static validation_verdict
-try_urls(struct tal *tal, bool (*url_is_protocol)(struct uri const *),
-    validation_verdict (*get_path)(struct uri const *, char **))
+try_urls(struct tal *tal, char const *proto,
+    validation_verdict (*get_path)(struct uri const *, char const **))
 {
        struct uri *url;
-       char *path;
+       char const *path;
        struct cache_mapping map;
        validation_verdict vv;
 
        ARRAYLIST_FOREACH(&tal->urls, url) {
-               if (!url_is_protocol(url))
+               if (!uri_is_proto(url, proto))
                        continue;
 
                vv = get_path(url, &path);
@@ -176,23 +176,19 @@ try_urls(struct tal *tal, bool (*url_is_protocol)(struct uri const *),
                        continue;
 
                map.url = *url;
-               map.path = path;
+               map.path = (char *)path;
 
                vv = validate_ta(tal, &map);
-               if (vv == VV_BUSY) {
-                       free(path);
+               if (vv == VV_BUSY)
                        return VV_BUSY;
-               }
-               if (vv == VV_FAIL) {
-                       free(path);
+               if (vv == VV_FAIL)
                        continue;
-               }
 
                cache_commit_file(&map);
-               free(path);
                return VV_CONTINUE;
        }
 
+       pr_trc("No URIs match the protocol.");
        return VV_FAIL;
 }
 
@@ -212,20 +208,20 @@ traverse_tal(char const *path)
 
        /* Online attempts */
        pr_trc("Trying HTTP refresh.");
-       vv = try_urls(tal, uri_is_https, cache_refresh_by_url);
+       vv = try_urls(tal, "https:", cache_refresh_url_https);
        if (vv != VV_FAIL)
                goto end2;
        pr_trc("Trying rsync refresh.");
-       vv = try_urls(tal, uri_is_rsync, cache_refresh_by_url);
+       vv = try_urls(tal, "rsync:", cache_refresh_url_rsync);
        if (vv != VV_FAIL)
                goto end2;
        /* Offline fallback attempts */
        pr_trc("Trying HTTP fallback.");
-       vv = try_urls(tal, uri_is_https, cache_get_fallback);
+       vv = try_urls(tal, "https:", cache_get_fallback);
        if (vv != VV_FAIL)
                goto end2;
        pr_trc("Trying rsync fallback.");
-       vv = try_urls(tal, uri_is_rsync, cache_get_fallback);
+       vv = try_urls(tal, "rsync:", cache_get_fallback);
        if (vv != VV_FAIL)
                goto end2;
 
index c9c2b46ed2f51534973cadd5243d6f6392be8a33..b5eb5ad956923cc569decfc28fb3efec9136f89e 100644 (file)
@@ -933,16 +933,22 @@ uri_cleanup(struct uri *url)
        url->_str = NULL;
 }
 
+bool
+uri_is_proto(struct uri const *url, char const *proto)
+{
+       return str_starts_with(url->_str, proto);
+}
+
 bool
 uri_is_rsync(struct uri const *url)
 {
-       return str_starts_with(url->_str, "rsync:");
+       return uri_is_proto(url, "rsync:");
 }
 
 bool
 uri_is_https(struct uri const *url)
 {
-       return str_starts_with(url->_str, "https:");
+       return uri_is_proto(url, "https:");
 }
 
 bool
index ba877dd457db7aed8e9f50ec53f833a76670ed63..9a3489d59fd66eb135d538bcadfe41b6f64e2eae 100644 (file)
@@ -24,6 +24,7 @@ void uri_cleanup(struct uri *);
 #define uri_str(u) ((char const *)((u)->_str))
 #define uri_len(u) ((size_t const)((u)->_len))
 
+bool uri_is_proto(struct uri const *, char const *);
 bool uri_is_rsync(struct uri const *);
 bool uri_is_https(struct uri const *);