Skip to content

Commit

Permalink
Rework the logic for fetching TA files a bit. Move the logic that checks
Browse files Browse the repository at this point in the history
if all possible sources have been used to ta_fetch() this simplifies the
logic in the rsync and http done cases.
Additionally when -R is used, skip https URI and only connect via rsync.
If the TAL file has no rsync URI then the system will fall back to the
cache and not try https instead.
This makes -R a only use rsync flag.
With and OK job@
  • Loading branch information
cjeker committed Aug 12, 2021
1 parent 573c72b commit 9e8ec71
Showing 1 changed file with 30 additions and 19 deletions.
49 changes: 30 additions & 19 deletions usr.sbin/rpki-client/repo.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $OpenBSD: repo.c,v 1.8 2021/06/14 10:01:23 claudio Exp $ */
/* $OpenBSD: repo.c,v 1.9 2021/08/12 15:27:15 claudio Exp $ */
/*
* Copyright (c) 2021 Claudio Jeker <[email protected]>
* Copyright (c) 2019 Kristaps Dzonsons <[email protected]>
Expand Down Expand Up @@ -38,6 +38,7 @@

extern struct stats stats;
extern int noop;
extern int rrdpon;

enum repo_state {
REPO_LOADING = 0,
Expand Down Expand Up @@ -329,6 +330,26 @@ rrdp_state_filename(const struct rrdprepo *rr, int temp)
static void
ta_fetch(struct tarepo *tr)
{
if (!rrdpon) {
for (; tr->uriidx < tr->urisz; tr->uriidx++) {
if (strncasecmp(tr->uri[tr->uriidx],
"rsync://", 8) == 0)
break;
}
}

if (tr->uriidx >= tr->urisz) {
struct repo *rp;

tr->state = REPO_FAILED;
logx("ta/%s: fallback to cache", tr->descr);

SLIST_FOREACH(rp, &repos, entry)
if (rp->ta == tr)
entityq_flush(&rp->queue, rp);
return;
}

logx("ta/%s: pulling from %s", tr->descr, tr->uri[tr->uriidx]);

if (strncasecmp(tr->uri[tr->uriidx], "rsync://", 8) == 0) {
Expand Down Expand Up @@ -914,16 +935,12 @@ rsync_finish(size_t id, int ok)
logx("ta/%s: loaded from network", tr->descr);
stats.rsync_repos++;
tr->state = REPO_DONE;
} else if (++tr->uriidx < tr->urisz) {
logx("ta/%s: load from network failed, retry",
tr->descr);
ta_fetch(tr);
return;
} else {
logx("ta/%s: load from network failed, "
"fallback to cache", tr->descr);
logx("ta/%s: load from network failed", tr->descr);
stats.rsync_fails++;
tr->state = REPO_FAILED;
tr->uriidx++;
ta_fetch(tr);
return;
}
SLIST_FOREACH(rp, &repos, entry)
if (rp->ta == tr)
Expand Down Expand Up @@ -1031,16 +1048,10 @@ http_finish(size_t id, enum http_result res, const char *last_mod)
if (unlink(tr->temp) == -1 && errno != ENOENT)
warn("unlink %s", tr->temp);

if (++tr->uriidx < tr->urisz) {
logx("ta/%s: load from network failed, retry",
tr->descr);
ta_fetch(tr);
return;
}

tr->state = REPO_FAILED;
logx("ta/%s: load from network failed, "
"fallback to cache", tr->descr);
tr->uriidx++;
logx("ta/%s: load from network failed", tr->descr);
ta_fetch(tr);
return;
}

SLIST_FOREACH(rp, &repos, entry)
Expand Down

0 comments on commit 9e8ec71

Please sign in to comment.