将fetch pp cache改成使用vcir结构,跑通apnic全量同步

This commit is contained in:
2026-03-13 14:45:41 +08:00
parent e3339533b8
commit cf764c35bb
53 changed files with 8931 additions and 2201 deletions

View File

@@ -2,9 +2,10 @@ use std::collections::HashMap;
use rpki::audit::{DiscoveredFrom, PublicationPointAudit};
use rpki::report::Warning;
use rpki::storage::{FetchCachePpPack, PackFile, PackTime};
use rpki::storage::{PackFile, PackTime};
use rpki::validation::manifest::PublicationPointSource;
use rpki::validation::objects::{ObjectsOutput, ObjectsStats};
use rpki::validation::publication_point::PublicationPointSnapshot;
use rpki::validation::tree::{
CaInstanceHandle, DiscoveredChildCaInstance, PublicationPointRunResult, PublicationPointRunner,
TreeRunConfig, run_tree_serial, run_tree_serial_audit,
@@ -43,8 +44,8 @@ impl PublicationPointRunner for MockRunner {
}
}
fn empty_pack(manifest_uri: &str, pp_uri: &str) -> FetchCachePpPack {
FetchCachePpPack {
fn empty_snapshot(manifest_uri: &str, pp_uri: &str) -> PublicationPointSnapshot {
PublicationPointSnapshot {
format_version: 1,
publication_point_rsync_uri: pp_uri.to_string(),
manifest_rsync_uri: manifest_uri.to_string(),
@@ -66,6 +67,8 @@ fn empty_pack(manifest_uri: &str, pp_uri: &str) -> FetchCachePpPack {
fn ca_handle(manifest_uri: &str) -> CaInstanceHandle {
CaInstanceHandle {
depth: 0,
tal_id: "test-tal".to_string(),
parent_manifest_rsync_uri: None,
ca_certificate_der: Vec::new(),
ca_certificate_rsync_uri: None,
effective_ip_resources: None,
@@ -97,7 +100,7 @@ fn discovered_child(
}
#[test]
fn tree_enqueues_children_only_for_fresh_publication_points() {
fn tree_enqueues_children_for_fresh_and_current_instance_vcir_results() {
let root_manifest = "rsync://example.test/repo/root.mft";
let child1_manifest = "rsync://example.test/repo/child1.mft";
let child2_manifest = "rsync://example.test/repo/child2.mft";
@@ -114,7 +117,7 @@ fn tree_enqueues_children_only_for_fresh_publication_points() {
root_manifest,
PublicationPointRunResult {
source: PublicationPointSource::Fresh,
pack: empty_pack(root_manifest, "rsync://example.test/repo/"),
snapshot: Some(empty_snapshot(root_manifest, "rsync://example.test/repo/")),
warnings: Vec::new(),
objects: ObjectsOutput {
vrps: Vec::new(),
@@ -130,8 +133,11 @@ fn tree_enqueues_children_only_for_fresh_publication_points() {
.with(
child1_manifest,
PublicationPointRunResult {
source: PublicationPointSource::FetchCachePp,
pack: empty_pack(child1_manifest, "rsync://example.test/repo/child1/"),
source: PublicationPointSource::VcirCurrentInstance,
snapshot: Some(empty_snapshot(
child1_manifest,
"rsync://example.test/repo/child1/",
)),
warnings: vec![Warning::new("child1 warning")],
objects: ObjectsOutput {
vrps: Vec::new(),
@@ -148,7 +154,30 @@ fn tree_enqueues_children_only_for_fresh_publication_points() {
child2_manifest,
PublicationPointRunResult {
source: PublicationPointSource::Fresh,
pack: empty_pack(child2_manifest, "rsync://example.test/repo/child2/"),
snapshot: Some(empty_snapshot(
child2_manifest,
"rsync://example.test/repo/child2/",
)),
warnings: Vec::new(),
objects: ObjectsOutput {
vrps: Vec::new(),
aspas: Vec::new(),
warnings: Vec::new(),
stats: ObjectsStats::default(),
audit: Vec::new(),
},
audit: PublicationPointAudit::default(),
discovered_children: Vec::new(),
},
)
.with(
grandchild_manifest,
PublicationPointRunResult {
source: PublicationPointSource::Fresh,
snapshot: Some(empty_snapshot(
grandchild_manifest,
"rsync://example.test/repo/grandchild/",
)),
warnings: Vec::new(),
objects: ObjectsOutput {
vrps: Vec::new(),
@@ -165,14 +194,20 @@ fn tree_enqueues_children_only_for_fresh_publication_points() {
let out = run_tree_serial(ca_handle(root_manifest), &runner, &TreeRunConfig::default())
.expect("run tree");
// root + child1 + child2. grandchild must NOT be processed because child1 used cache.
assert_eq!(out.instances_processed, 3);
// root + child1 + child2 + grandchild. child1 uses current-instance VCIR, but its child
// entry is still restored and processed fresh-first later in the traversal.
assert_eq!(out.instances_processed, 4);
assert_eq!(out.instances_failed, 0);
let called = runner.called();
assert_eq!(
called,
vec![root_manifest, child1_manifest, child2_manifest]
vec![
root_manifest,
child1_manifest,
child2_manifest,
grandchild_manifest
]
);
assert!(
@@ -184,8 +219,8 @@ fn tree_enqueues_children_only_for_fresh_publication_points() {
assert!(
out.warnings
.iter()
.any(|w| w.message.contains("skipping child CA discovery")),
"expected RFC 9286 §6.6 enforcement warning"
.all(|w| !w.message.contains("skipping child CA discovery")),
"did not expect old skip-child warning"
);
}
@@ -199,7 +234,7 @@ fn tree_respects_max_depth_and_max_instances() {
root_manifest,
PublicationPointRunResult {
source: PublicationPointSource::Fresh,
pack: empty_pack(root_manifest, "rsync://example.test/repo/"),
snapshot: Some(empty_snapshot(root_manifest, "rsync://example.test/repo/")),
warnings: Vec::new(),
objects: ObjectsOutput {
vrps: Vec::new(),
@@ -216,7 +251,10 @@ fn tree_respects_max_depth_and_max_instances() {
child_manifest,
PublicationPointRunResult {
source: PublicationPointSource::Fresh,
pack: empty_pack(child_manifest, "rsync://example.test/repo/child/"),
snapshot: Some(empty_snapshot(
child_manifest,
"rsync://example.test/repo/child/",
)),
warnings: Vec::new(),
objects: ObjectsOutput {
vrps: Vec::new(),
@@ -236,7 +274,6 @@ fn tree_respects_max_depth_and_max_instances() {
&TreeRunConfig {
max_depth: Some(0),
max_instances: None,
revalidate_only: false,
},
)
.expect("run tree depth-limited");
@@ -249,7 +286,6 @@ fn tree_respects_max_depth_and_max_instances() {
&TreeRunConfig {
max_depth: None,
max_instances: Some(1),
revalidate_only: false,
},
)
.expect("run tree instance-limited");
@@ -267,7 +303,7 @@ fn tree_audit_includes_parent_and_discovered_from_for_non_root_nodes() {
root_manifest,
PublicationPointRunResult {
source: PublicationPointSource::Fresh,
pack: empty_pack(root_manifest, "rsync://example.test/repo/"),
snapshot: Some(empty_snapshot(root_manifest, "rsync://example.test/repo/")),
warnings: Vec::new(),
objects: ObjectsOutput {
vrps: Vec::new(),
@@ -284,7 +320,10 @@ fn tree_audit_includes_parent_and_discovered_from_for_non_root_nodes() {
child_manifest,
PublicationPointRunResult {
source: PublicationPointSource::Fresh,
pack: empty_pack(child_manifest, "rsync://example.test/repo/child/"),
snapshot: Some(empty_snapshot(
child_manifest,
"rsync://example.test/repo/child/",
)),
warnings: Vec::new(),
objects: ObjectsOutput {
vrps: Vec::new(),
@@ -320,16 +359,23 @@ fn tree_audit_includes_parent_and_discovered_from_for_non_root_nodes() {
}
#[test]
fn tree_revalidate_only_enqueues_children_from_fetch_cache_pp() {
fn tree_prefers_lexicographically_first_discovery_when_duplicate_manifest_is_queued() {
let root_manifest = "rsync://example.test/repo/root.mft";
let child_manifest = "rsync://example.test/repo/child.mft";
let duplicate_manifest = "rsync://example.test/repo/child.mft";
let mut first = discovered_child(root_manifest, duplicate_manifest);
first.discovered_from.child_ca_certificate_rsync_uri =
"rsync://example.test/repo/z-child.cer".to_string();
let mut second = discovered_child(root_manifest, duplicate_manifest);
second.discovered_from.child_ca_certificate_rsync_uri =
"rsync://example.test/repo/a-child.cer".to_string();
let runner = MockRunner::default()
.with(
root_manifest,
PublicationPointRunResult {
source: PublicationPointSource::FetchCachePp,
pack: empty_pack(root_manifest, "rsync://example.test/repo/"),
source: PublicationPointSource::Fresh,
snapshot: Some(empty_snapshot(root_manifest, "rsync://example.test/repo/")),
warnings: Vec::new(),
objects: ObjectsOutput {
vrps: Vec::new(),
@@ -339,14 +385,17 @@ fn tree_revalidate_only_enqueues_children_from_fetch_cache_pp() {
audit: Vec::new(),
},
audit: PublicationPointAudit::default(),
discovered_children: vec![discovered_child(root_manifest, child_manifest)],
discovered_children: vec![first, second],
},
)
.with(
child_manifest,
duplicate_manifest,
PublicationPointRunResult {
source: PublicationPointSource::FetchCachePp,
pack: empty_pack(child_manifest, "rsync://example.test/repo/child/"),
source: PublicationPointSource::Fresh,
snapshot: Some(empty_snapshot(
duplicate_manifest,
"rsync://example.test/repo/child/",
)),
warnings: Vec::new(),
objects: ObjectsOutput {
vrps: Vec::new(),
@@ -360,27 +409,21 @@ fn tree_revalidate_only_enqueues_children_from_fetch_cache_pp() {
},
);
let out = run_tree_serial(
ca_handle(root_manifest),
&runner,
&TreeRunConfig {
max_depth: None,
max_instances: None,
revalidate_only: false,
},
)
.expect("run tree");
assert_eq!(out.instances_processed, 1);
let out = run_tree_serial_audit(ca_handle(root_manifest), &runner, &TreeRunConfig::default())
.expect("run tree audit");
let out = run_tree_serial(
ca_handle(root_manifest),
&runner,
&TreeRunConfig {
max_depth: None,
max_instances: None,
revalidate_only: true,
},
)
.expect("run tree");
assert_eq!(out.instances_processed, 2);
assert_eq!(out.tree.instances_processed, 2);
assert_eq!(
runner.called(),
vec![root_manifest.to_string(), duplicate_manifest.to_string()]
);
let child_audit = &out.publication_points[1];
assert_eq!(
child_audit
.discovered_from
.as_ref()
.expect("child discovered_from")
.child_ca_certificate_rsync_uri,
"rsync://example.test/repo/a-child.cer"
);
}