From b7a4115393658d5abad59a153af46684f38a2637 Mon Sep 17 00:00:00 2001 From: Mingwei Zhang Date: Mon, 5 Oct 2026 08:50:00 -0700 Subject: [PATCH 1/4] feat(peeringdb): add as_set endpoint (13th table) PeeringDB publishes `/api/as_set` as a single `{asn: name}` map rather than a list of records, so it needs its own parser; it was the one table the module did not mirror yet. `Peeringdb::as_set` keeps the published strings verbatim (a value may hold several space-separated names) and `get_as_set` resolves one ASN. A response that is not one object with integer keys and string values fails as a PeeringDB data-source error instead of parsing to an empty table. `pg_inserter` publishes the map as `peeringdb.as_set` (asn primary key, one text column, the usual `data_as_of`/`source_revision` provenance) inside the existing atomic family refresh. It is the one table without `id`/`record` columns because the string value is the payload. `Peeringdb::new()` now issues one more API call; `new_networks_only()` is unchanged. Verified: cargo fmt --check; cargo clippy --all-features -- -D warnings; cargo test --all-features; cargo test --no-default-features --features pg-inserter-cli --bin pg_inserter; cargo build --no-default-features --features peeringdb; and the ignored live check `test_peeringdb_as_set` against the real endpoint. --- CHANGELOG.md | 1 + README.md | 8 +- src/bin/pg_inserter/main.rs | 2 +- src/bin/pg_inserter/peeringdb.rs | 75 ++++++++++- src/lib.rs | 5 +- src/peeringdb/client.rs | 1 + src/peeringdb/mod.rs | 207 ++++++++++++++++++++++++++++++- 7 files changed, 288 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 09dfc15..9dd42b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ All notable changes to this project will be documented in this file. * `pg-inserter-cli` feature and `pg_inserter` binary: loads BGP reference data into PostgreSQL with one schema per source (`asndata`, `peeringdb`, `irr`), independent snapshot refreshes via a staging COPY + atomic swap, and run provenance in `meta.ingest_run` ([#46](https://github.com/bgpkit/bgpkit-commons/pull/46)). * Container image `bgpkit/pg-inserter`, built from `docker/pg-inserter.Dockerfile` with credentials supplied only through run-time environment variables (`docker/README.md`) ([#48](https://github.com/bgpkit/bgpkit-commons/pull/48)). * `pg_inserter`: TLS is negotiated from the connection string like libpq's `sslmode` (`disable`, `prefer` default, `require`, `verify-ca`, `verify-full`) with `sslrootcert` for the verifying modes, so a deployment can move between plaintext and encrypted database links without a rebuild. `prefer` and `require` encrypt without verifying the certificate; `verify-ca`/`verify-full` verify the chain (and, for the latter, the hostname). +* `peeringdb`: new `as_set` table mirroring PeeringDB's `/api/as_set` endpoint (ASN -> registered as-set names), completing the API mirror at 13 tables; `pg_inserter` publishes it as `peeringdb.as_set`. ### Fixed diff --git a/README.md b/README.md index 6f82a92..9f6966e 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ assert!(commons.bogons_match("23456").unwrap()); // AS23456 is reserved | `bogons` | `bogons` | IANA special registries | Reserved/bogon ASN and IP prefix detection | | `countries` | `countries` | GeoNames | ISO country codes, capitals, continents, neighbors | | `mrt_collectors` | `mrt_collectors` | RouteViews, RIPE RIS | BGP collector metadata (name, project, country, dates) | -| `peeringdb` | `peeringdb` | PeeringDB API | All 12 endpoints: networks, IXPs, facilities, orgs, carriers | +| `peeringdb` | `peeringdb` | PeeringDB API | All 13 endpoints: networks, IXPs, facilities, orgs, carriers, AS-set names | | `rpki` | `rpki` | Cloudflare, RIPE NCC, RPKIviews, RPKISPOOL | ROA and ASPA validation (real-time and historical) | | `delegated` | `delegated` | NRO/RIR delegated stats | RIR allocation records (ASN, IPv4, IPv6) | | `irr` | `irr` | RIPE, APNIC, ARIN, LACNIC, AFRINIC, NTTCOM, RADB, ... | RPSL aut-num, route, route6, as-set records | @@ -110,7 +110,7 @@ assert!(commons.bogons_match_asn(65535).unwrap()); // reserved ASN ```rust use bgpkit_commons::peeringdb::Peeringdb; -let pdb = Peeringdb::new().unwrap(); // all 12 endpoints +let pdb = Peeringdb::new().unwrap(); // all 13 endpoints let cf = pdb.get_network(13335).unwrap(); println!("{}: {} IXP memberships", cf.name.unwrap(), cf.ix_count.unwrap()); ``` @@ -171,7 +171,7 @@ commons-export/ mrt_collectors.parquet as_relationships.parquet rir_delegated.parquet - peeringdb/ # 12 endpoint tables (--with-peeringdb) + peeringdb/ # 13 endpoint tables (--with-peeringdb) irr/records.parquet # RPSL records (--with-irr) rpki/ # ROAs + ASPAs (--with-rpki) asninfo.jsonl # legacy merged output (--with-asninfo-jsonl) @@ -220,7 +220,7 @@ See `docker/README.md` for the image catalog and the credential contract, and | `delegated` | RIR delegated-statistics parser | | `irr` | IRR RPSL record parsing (aut-num, route, as-set) | | `mrt_collectors` | MRT collector metadata | -| `peeringdb` | PeeringDB API data (all 12 endpoints) | +| `peeringdb` | PeeringDB API data (all 13 endpoints) | | `rpki` | RPKI validation (ROA and ASPA) | | `all` *(default)* | Enables all data modules above | | `export` | Parquet export of all loaded sources (adds `arrow` + `parquet`) | diff --git a/src/bin/pg_inserter/main.rs b/src/bin/pg_inserter/main.rs index 67f20b8..5552f52 100644 --- a/src/bin/pg_inserter/main.rs +++ b/src/bin/pg_inserter/main.rs @@ -60,7 +60,7 @@ enum Commands { Delegated, /// Run every asndata task sequentially Asndata, - /// peeringdb schema: full PeeringDB mirror (12 tables) + /// peeringdb schema: full PeeringDB mirror (13 tables) Peeringdb, /// irr schema: full IRR RPSL object store (snapshot-only) Irr, diff --git a/src/bin/pg_inserter/peeringdb.rs b/src/bin/pg_inserter/peeringdb.rs index 03646a4..8fa1b9a 100644 --- a/src/bin/pg_inserter/peeringdb.rs +++ b/src/bin/pg_inserter/peeringdb.rs @@ -1,9 +1,10 @@ -//! `peeringdb` schema: full PeeringDB API mirror (12 tables). +//! `peeringdb` schema: full PeeringDB API mirror (13 tables). //! -//! One `Peeringdb::new()` load (all 12 endpoints) is dumped into 12 snapshot +//! One `Peeringdb::new()` load (all 13 endpoints) is dumped into 13 snapshot //! tables. Per-table shape: native PeeringDB id as PK, typed foreign-key and //! search columns, the complete API object in a `record` JSONB column, and -//! `data_as_of`/`source_revision` provenance. Per-table independence inside +//! `data_as_of`/`source_revision` provenance; `as_set` is the exception (no +//! `id`/`record`, its value is the payload). Per-table independence inside //! the PeeringDB family is deferred: the whole family refreshes atomically. use super::refresh::{SOURCE_REVISION, TableSpec, build_csv_line}; @@ -64,6 +65,7 @@ pub(crate) fn load_all(data_as_of: &str) -> Result)> CARRIERFAC_SPEC, dump_vec(&pdb.carrier_facilities, data_as_of, carrierfac_line)?, ), + (AS_SET_SPEC, dump_as_set(&pdb.as_set, data_as_of)?), ]; Ok(tables) } @@ -285,6 +287,25 @@ const CARRIERFAC_SPEC: TableSpec = TableSpec { index_swaps: &[("peeringdb.carrierfac_staging_pkey", "carrierfac_pkey")], }; +/// Shape exception to the other twelve tables: the upstream `/as_set` +/// payload is a bare `{asn: name}` map, so there are no `id`/`record` +/// columns; the string value itself is the payload. +const AS_SET_SPEC: TableSpec = TableSpec { + task: "peeringdb.as_set", + table: "peeringdb.as_set", + staging_ddl: "CREATE TABLE peeringdb.as_set_staging ( + asn bigint NOT NULL, + as_set text NOT NULL, + data_as_of timestamptz NOT NULL, + source_revision text NOT NULL + )", + copy_columns: "asn, as_set, data_as_of, source_revision", + index_ddl: &[ + "ALTER TABLE peeringdb.as_set_staging ADD CONSTRAINT as_set_staging_pkey PRIMARY KEY (asn)", + ], + index_swaps: &[("peeringdb.as_set_staging_pkey", "as_set_pkey")], +}; + // ---- row mapping ----------------------------------------------------------- /// Serialize one record to a double-quoted JSON field. Serialization cannot @@ -329,6 +350,25 @@ fn dump_networks( .collect() } +/// Dump the `/as_set` map: one line per ASN, sorted by ASN ascending. +fn dump_as_set(map: &HashMap, data_as_of: &str) -> Result, String> { + let mut asns: Vec = map.keys().copied().collect(); + asns.sort_unstable(); + asns.iter() + .map(|asn| { + let value = map + .get(asn) + .ok_or_else(|| format!("missing as_set entry {asn}"))?; + Ok(build_csv_line(&[ + Some(asn.to_string()), + Some(value.clone()), + Some(data_as_of.to_string()), + Some(SOURCE_REVISION.to_string()), + ])) + }) + .collect() +} + fn dump_records( map: &HashMap, data_as_of: &str, @@ -495,4 +535,33 @@ mod tests { ); assert!(line.starts_with("1,,\"3\",\"{")); } + + #[test] + fn as_set_lines_sorted_by_asn_numerically() { + let map = HashMap::from([ + (10u32, "TEN".to_string()), + (2u32, "TWO".to_string()), + (1u32, "ONE".to_string()), + ]); + let lines = dump_as_set(&map, "2026-09-09T00:00:00+00:00").unwrap(); + assert_eq!(lines.len(), 3); + // Numeric order: a lexicographic sort would yield 1, 10, 2. + assert!(lines[0].starts_with("\"1\",")); + assert!(lines[1].starts_with("\"2\",")); + assert!(lines[2].starts_with("\"10\",")); + } + + #[test] + fn as_set_line_escapes_csv_and_stays_one_four_field_line() { + let map = HashMap::from([(13335u32, "a,b\"c\nd".to_string())]); + let lines = dump_as_set(&map, "2026-09-09T00:00:00+00:00").unwrap(); + assert_eq!(lines.len(), 1); + // Exact 4-field shape: asn, escaped value, data_as_of, source_revision. + assert_eq!( + lines[0], + format!( + "\"13335\",\"a,b\"\"c\nd\",\"2026-09-09T00:00:00+00:00\",\"{SOURCE_REVISION}\"" + ) + ); + } } diff --git a/src/lib.rs b/src/lib.rs index 07de88d..c0f04fc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -79,8 +79,9 @@ //! //! - Load: `Peeringdb::new()` (all tables), `Peeringdb::new_networks_only()` (lightweight) //! - Access: `get_network(asn)`, `get_ixp(ix_id)`, `get_ixp_memberships(asn)`, `lookup_ixp_prefix(prefix)`, `get_facility(fac_id)` -//! - Typed structs mirroring all 12 PeeringDB API endpoints: networks, internet exchanges, -//! IXP prefixes, IXP membership, facilities, organizations, carriers, and more +//! - Typed structs and an ASN-to-AS-set map mirroring all 13 PeeringDB API endpoints: +//! networks, internet exchanges, IXP prefixes, IXP membership, facilities, organizations, +//! carriers, AS-set names, and more //! - `PeeringdbData` is a type alias for the full `Network` struct (backward compatible) //! //! ### [`rpki`] — RPKI Validation diff --git a/src/peeringdb/client.rs b/src/peeringdb/client.rs index 2fd08cd..65949a2 100644 --- a/src/peeringdb/client.rs +++ b/src/peeringdb/client.rs @@ -17,6 +17,7 @@ pub(crate) const ORG_API_URL: &str = "https://www.peeringdb.com/api/org"; pub(crate) const CAMPUS_API_URL: &str = "https://www.peeringdb.com/api/campus"; pub(crate) const CARRIER_API_URL: &str = "https://www.peeringdb.com/api/carrier"; pub(crate) const CARRIERFAC_API_URL: &str = "https://www.peeringdb.com/api/carrierfac"; +pub(crate) const AS_SET_API_URL: &str = "https://www.peeringdb.com/api/as_set"; /// Get a reader for a PeeringDB API endpoint with proper authentication headers. /// diff --git a/src/peeringdb/mod.rs b/src/peeringdb/mod.rs index 75cc471..b2aa2ad 100644 --- a/src/peeringdb/mod.rs +++ b/src/peeringdb/mod.rs @@ -31,6 +31,7 @@ //! | [`Campus`] | `/campus` | Facility campus | //! | [`Carrier`] | `/carrier` | Transport carrier | //! | [`CarrierFacility`] | `/carrierfac` | Carrier–facility association | +//! | *(map)* | `/as_set` | AS-set names by ASN | mod client; mod tables; @@ -39,7 +40,8 @@ pub use tables::*; use std::collections::HashMap; -use crate::Result; +use crate::errors::data_sources; +use crate::{BgpkitCommonsError, Result}; use tracing::info; /// PeeringDB data container with all tables loaded from the API. @@ -72,6 +74,9 @@ pub struct Peeringdb { pub carriers: HashMap, /// Carrier–facility association records (`/carrierfac`). pub carrier_facilities: Vec, + /// AS-set names by ASN (`/as_set`); the value is the raw published string + /// and may hold several space-separated names. + pub as_set: HashMap, } impl Peeringdb { @@ -96,6 +101,7 @@ impl Peeringdb { let campuses = Self::load_table_id(client::CAMPUS_API_URL)?; let carriers = Self::load_table_id(client::CARRIER_API_URL)?; let carrier_facilities = Self::load_table(client::CARRIERFAC_API_URL)?; + let as_set = Self::load_as_set(client::AS_SET_API_URL)?; info!("loaded all PeeringDB tables"); Ok(Self { networks, @@ -110,6 +116,7 @@ impl Peeringdb { campuses, carriers, carrier_facilities, + as_set, }) } @@ -137,6 +144,7 @@ impl Peeringdb { campuses: HashMap::new(), carriers: HashMap::new(), carrier_facilities: Vec::new(), + as_set: HashMap::new(), }) } @@ -157,6 +165,58 @@ impl Peeringdb { .collect()) } + /// Load the `/as_set` map. + /// + /// Unlike the other tables, this endpoint returns a single ASN -> as-set + /// name object rather than a list of records, so it needs its own parser. + fn load_as_set(url: &str) -> Result> { + let mut reader = client::get_peeringdb_reader(url)?; + let mut buf = String::new(); + reader.read_to_string(&mut buf)?; + Self::parse_as_set(&buf) + } + + /// Parse a raw `/as_set` response body into an ASN -> as-set names map. + /// + /// `data` must hold exactly one object whose keys are ASNs and whose + /// values are the raw published strings (kept verbatim, including any + /// space-separated names); other top-level fields such as `meta` are + /// ignored. Anything else is refused as a PeeringDB data-source error + /// rather than guessed at. + fn parse_as_set(buf: &str) -> Result> { + let value: serde_json::Value = serde_json::from_str(buf) + .map_err(|e| as_set_parse_error(format!("malformed JSON: {e}")))?; + + let data = value + .get("data") + .and_then(serde_json::Value::as_array) + .ok_or_else(|| as_set_parse_error("expected a top-level object with a 'data' array"))?; + + if data.len() != 1 { + return Err(as_set_parse_error(format!( + "expected exactly one object in 'data', got {} element(s)", + data.len() + ))); + } + + let obj = data[0] + .as_object() + .ok_or_else(|| as_set_parse_error("expected 'data[0]' to be an object"))?; + + let mut as_set = HashMap::with_capacity(obj.len()); + for (key, value) in obj { + let asn: u32 = key + .parse() + .map_err(|_| as_set_parse_error(format!("'{key}' is not a u32 ASN")))?; + let name = value.as_str().ok_or_else(|| { + as_set_parse_error(format!("value for ASN {asn} is not a string")) + })?; + as_set.insert(asn, name.to_string()); + } + + Ok(as_set) + } + // ---- Network accessors ---- /// Get network data for a specific ASN. @@ -241,6 +301,26 @@ impl Peeringdb { pub fn get_organization(&self, org_id: u32) -> Option<&Organization> { self.organizations.get(&org_id) } + + // ---- AS-set accessors ---- + + /// Get the raw published as-set name(s) registered for an ASN (`/as_set`). + /// + /// Returns `None` when the ASN has no registered as-set. + pub fn get_as_set(&self, asn: u32) -> Option<&str> { + self.as_set.get(&asn).map(String::as_str) + } +} + +/// Build the PeeringDB data-source error for an invalid `/as_set` response. +/// +/// All `/as_set` shape-validation and JSON failures are wrapped this way so +/// callers see one error kind naming both the data source and the endpoint. +fn as_set_parse_error(reason: impl std::fmt::Display) -> BgpkitCommonsError { + BgpkitCommonsError::data_source_error( + data_sources::PEERINGDB, + format!("/as_set response is invalid: {reason}"), + ) } /// Trait for structs that have an `id` field, used by `load_table_id`. @@ -268,6 +348,7 @@ impl std::fmt::Debug for Peeringdb { .field("campuses", &self.campuses.len()) .field("carriers", &self.carriers.len()) .field("carrier_facilities", &self.carrier_facilities.len()) + .field("as_set", &self.as_set.len()) .finish() } } @@ -446,6 +527,103 @@ mod tests { assert!(!nxl.is_rs_peer); } + // ---- /as_set parser tests (pure, no network) ---- + + /// Assert that `json` is refused as a PeeringDB data-source error naming + /// the `/as_set` endpoint. Every validation failure must be wrapped this + /// way instead of surfacing as a bare JSON error. + fn assert_invalid_as_set(json: &str) { + match Peeringdb::parse_as_set(json) { + Err(BgpkitCommonsError::DataSourceError { + data_source, + details, + }) => { + assert_eq!(data_source, data_sources::PEERINGDB); + assert!( + details.contains("/as_set"), + "error does not name the endpoint: {details}" + ); + } + other => panic!("expected PeeringDB data-source error, got {other:?}"), + } + } + + #[test] + fn test_parse_as_set_single_object() { + let json = r#"{"data":[{"13335":"AS13335:AS-CLOUDFLARE","15169":"RADB::AS-GOOGLE"}]}"#; + let map = Peeringdb::parse_as_set(json).unwrap(); + assert_eq!(map.len(), 2); + assert_eq!( + map.get(&13335).map(String::as_str), + Some("AS13335:AS-CLOUDFLARE") + ); + assert_eq!(map.get(&15169).map(String::as_str), Some("RADB::AS-GOOGLE")); + } + + #[test] + fn test_parse_as_set_preserves_raw_values() { + // Values are kept verbatim, including several space-separated names. + let json = r#"{"data":[{"13335":"AS13335:AS-CLOUDFLARE AS13335:AS-CLOUDFLARE-V6"}]}"#; + let map = Peeringdb::parse_as_set(json).unwrap(); + assert_eq!( + map.get(&13335).map(String::as_str), + Some("AS13335:AS-CLOUDFLARE AS13335:AS-CLOUDFLARE-V6") + ); + } + + #[test] + fn test_parse_as_set_empty_object_allowed() { + let map = Peeringdb::parse_as_set(r#"{"data":[{}]}"#).unwrap(); + assert!(map.is_empty()); + } + + #[test] + fn test_parse_as_set_refuses_bare_array() { + assert_invalid_as_set("[]"); + } + + #[test] + fn test_parse_as_set_refuses_empty_data_array() { + assert_invalid_as_set(r#"{"data":[]}"#); + } + + #[test] + fn test_parse_as_set_refuses_multiple_elements() { + assert_invalid_as_set(r#"{"data":[{"1":"AS-A"},{"2":"AS-B"}]}"#); + } + + #[test] + fn test_parse_as_set_refuses_non_object_element() { + assert_invalid_as_set(r#"{"data":[["13335","AS-X"]]}"#); + } + + #[test] + fn test_parse_as_set_refuses_non_array_data() { + assert_invalid_as_set(r#"{"data":{"13335":"AS-X"}}"#); + } + + #[test] + fn test_parse_as_set_refuses_non_numeric_key() { + assert_invalid_as_set(r#"{"data":[{"AS13335":"AS-CLOUDFLARE"}]}"#); + } + + #[test] + fn test_parse_as_set_refuses_out_of_range_key() { + // u32::MAX + 1 and negative keys are not valid ASNs. + assert_invalid_as_set(r#"{"data":[{"4294967296":"AS-X"}]}"#); + assert_invalid_as_set(r#"{"data":[{"-1":"AS-X"}]}"#); + } + + #[test] + fn test_parse_as_set_refuses_non_string_value() { + assert_invalid_as_set(r#"{"data":[{"13335":42}]}"#); + } + + #[test] + fn test_parse_as_set_refuses_malformed_json() { + assert_invalid_as_set(r#"{"data":[}"#); + } + // Integration tests that require network access - marked as ignored by default #[test] @@ -477,4 +655,31 @@ mod tests { "Cloudflare should have IXP memberships" ); } + + #[test] + #[ignore] + fn test_peeringdb_as_set() { + // Live check of the `/as_set` endpoint only: the map must be non-empty + // and resolve through the accessor. Values are not pinned because the + // upstream data changes over time. + let as_set = Peeringdb::load_as_set(client::AS_SET_API_URL) + .expect("Failed to load PeeringDB /as_set"); + let pdb = Peeringdb { + networks: HashMap::new(), + internet_exchanges: HashMap::new(), + ixp_lans: HashMap::new(), + ixp_prefixes: Vec::new(), + network_ixp_membership: Vec::new(), + facilities: HashMap::new(), + network_facilities: Vec::new(), + ixp_facilities: Vec::new(), + organizations: HashMap::new(), + campuses: HashMap::new(), + carriers: HashMap::new(), + carrier_facilities: Vec::new(), + as_set, + }; + assert!(!pdb.as_set.is_empty()); + assert!(pdb.get_as_set(13335).is_some()); + } } From e329886d281dcb6b53dd882df2f8e420235cb78b Mon Sep 17 00:00:00 2001 From: Mingwei Zhang Date: Mon, 5 Oct 2026 08:50:31 -0700 Subject: [PATCH 2/4] docs(changelog): link the as_set entry to PR #49 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9dd42b1..f7d5c7e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ All notable changes to this project will be documented in this file. * `pg-inserter-cli` feature and `pg_inserter` binary: loads BGP reference data into PostgreSQL with one schema per source (`asndata`, `peeringdb`, `irr`), independent snapshot refreshes via a staging COPY + atomic swap, and run provenance in `meta.ingest_run` ([#46](https://github.com/bgpkit/bgpkit-commons/pull/46)). * Container image `bgpkit/pg-inserter`, built from `docker/pg-inserter.Dockerfile` with credentials supplied only through run-time environment variables (`docker/README.md`) ([#48](https://github.com/bgpkit/bgpkit-commons/pull/48)). * `pg_inserter`: TLS is negotiated from the connection string like libpq's `sslmode` (`disable`, `prefer` default, `require`, `verify-ca`, `verify-full`) with `sslrootcert` for the verifying modes, so a deployment can move between plaintext and encrypted database links without a rebuild. `prefer` and `require` encrypt without verifying the certificate; `verify-ca`/`verify-full` verify the chain (and, for the latter, the hostname). -* `peeringdb`: new `as_set` table mirroring PeeringDB's `/api/as_set` endpoint (ASN -> registered as-set names), completing the API mirror at 13 tables; `pg_inserter` publishes it as `peeringdb.as_set`. +* `peeringdb`: new `as_set` table mirroring PeeringDB's `/api/as_set` endpoint (ASN -> registered as-set names), completing the API mirror at 13 tables; `pg_inserter` publishes it as `peeringdb.as_set` ([#49](https://github.com/bgpkit/bgpkit-commons/pull/49)). ### Fixed From b08ba512fd27011f6476856792ad9921a360edbf Mon Sep 17 00:00:00 2001 From: Mingwei Zhang Date: Mon, 5 Oct 2026 10:03:20 -0700 Subject: [PATCH 3/4] docs: address Copilot review findings on endpoint coverage claims PeeringDB also exposes /api/poc, and the peeringdb/irr/rpki exporters are not yet implemented, so scope every coverage claim to the 13 supported endpoints. --- CHANGELOG.md | 2 +- README.md | 12 ++++++------ src/bin/pg_inserter/main.rs | 2 +- src/bin/pg_inserter/peeringdb.rs | 6 +++--- src/lib.rs | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f7d5c7e..bc94816 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ All notable changes to this project will be documented in this file. * `pg-inserter-cli` feature and `pg_inserter` binary: loads BGP reference data into PostgreSQL with one schema per source (`asndata`, `peeringdb`, `irr`), independent snapshot refreshes via a staging COPY + atomic swap, and run provenance in `meta.ingest_run` ([#46](https://github.com/bgpkit/bgpkit-commons/pull/46)). * Container image `bgpkit/pg-inserter`, built from `docker/pg-inserter.Dockerfile` with credentials supplied only through run-time environment variables (`docker/README.md`) ([#48](https://github.com/bgpkit/bgpkit-commons/pull/48)). * `pg_inserter`: TLS is negotiated from the connection string like libpq's `sslmode` (`disable`, `prefer` default, `require`, `verify-ca`, `verify-full`) with `sslrootcert` for the verifying modes, so a deployment can move between plaintext and encrypted database links without a rebuild. `prefer` and `require` encrypt without verifying the certificate; `verify-ca`/`verify-full` verify the chain (and, for the latter, the hostname). -* `peeringdb`: new `as_set` table mirroring PeeringDB's `/api/as_set` endpoint (ASN -> registered as-set names), completing the API mirror at 13 tables; `pg_inserter` publishes it as `peeringdb.as_set` ([#49](https://github.com/bgpkit/bgpkit-commons/pull/49)). +* `peeringdb`: new `as_set` table mirroring PeeringDB's `/api/as_set` endpoint (ASN -> registered as-set names), expanding the supported mirror to 13 tables; `pg_inserter` publishes it as `peeringdb.as_set` ([#49](https://github.com/bgpkit/bgpkit-commons/pull/49)). ### Fixed diff --git a/README.md b/README.md index 9f6966e..1dc3e73 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ assert!(commons.bogons_match("23456").unwrap()); // AS23456 is reserved | `bogons` | `bogons` | IANA special registries | Reserved/bogon ASN and IP prefix detection | | `countries` | `countries` | GeoNames | ISO country codes, capitals, continents, neighbors | | `mrt_collectors` | `mrt_collectors` | RouteViews, RIPE RIS | BGP collector metadata (name, project, country, dates) | -| `peeringdb` | `peeringdb` | PeeringDB API | All 13 endpoints: networks, IXPs, facilities, orgs, carriers, AS-set names | +| `peeringdb` | `peeringdb` | PeeringDB API | 13 supported endpoints: networks, IXPs, facilities, orgs, carriers, AS-set names | | `rpki` | `rpki` | Cloudflare, RIPE NCC, RPKIviews, RPKISPOOL | ROA and ASPA validation (real-time and historical) | | `delegated` | `delegated` | NRO/RIR delegated stats | RIR allocation records (ASN, IPv4, IPv6) | | `irr` | `irr` | RIPE, APNIC, ARIN, LACNIC, AFRINIC, NTTCOM, RADB, ... | RPSL aut-num, route, route6, as-set records | @@ -110,7 +110,7 @@ assert!(commons.bogons_match_asn(65535).unwrap()); // reserved ASN ```rust use bgpkit_commons::peeringdb::Peeringdb; -let pdb = Peeringdb::new().unwrap(); // all 13 endpoints +let pdb = Peeringdb::new().unwrap(); // the 13 supported endpoints let cf = pdb.get_network(13335).unwrap(); println!("{}: {} IXP memberships", cf.name.unwrap(), cf.ix_count.unwrap()); ``` @@ -160,7 +160,7 @@ bgpkit-export --output-dir ./output --with-peeringdb --with-irr --with-rpki bgpkit-export --output-dir ./output --with-asninfo-jsonl ``` -Output layout (one file per source): +Output layout (one file per source; `peeringdb/`, `irr/`, and `rpki/` exports are not yet implemented): ``` commons-export/ @@ -189,10 +189,10 @@ an atomic swap, with run provenance in `meta.ingest_run`. cargo install bgpkit-commons --features pg-inserter-cli export DATABASE_URL="postgresql://pg_inserter@db.example:5432/bgpkit_broker" -export PEERINGDB_API_KEY="..." # required for the full peeringdb mirror +export PEERINGDB_API_KEY="..." # required for the peeringdb mirror pg_inserter asndata # asnames, as2org, population, hegemony, delegated -pg_inserter peeringdb # full PeeringDB table mirror +pg_inserter peeringdb # PeeringDB table mirror pg_inserter irr # RPSL object store ``` @@ -220,7 +220,7 @@ See `docker/README.md` for the image catalog and the credential contract, and | `delegated` | RIR delegated-statistics parser | | `irr` | IRR RPSL record parsing (aut-num, route, as-set) | | `mrt_collectors` | MRT collector metadata | -| `peeringdb` | PeeringDB API data (all 13 endpoints) | +| `peeringdb` | PeeringDB API data (13 supported endpoints) | | `rpki` | RPKI validation (ROA and ASPA) | | `all` *(default)* | Enables all data modules above | | `export` | Parquet export of all loaded sources (adds `arrow` + `parquet`) | diff --git a/src/bin/pg_inserter/main.rs b/src/bin/pg_inserter/main.rs index 5552f52..57eb226 100644 --- a/src/bin/pg_inserter/main.rs +++ b/src/bin/pg_inserter/main.rs @@ -60,7 +60,7 @@ enum Commands { Delegated, /// Run every asndata task sequentially Asndata, - /// peeringdb schema: full PeeringDB mirror (13 tables) + /// peeringdb schema: mirror of the 13 supported PeeringDB tables Peeringdb, /// irr schema: full IRR RPSL object store (snapshot-only) Irr, diff --git a/src/bin/pg_inserter/peeringdb.rs b/src/bin/pg_inserter/peeringdb.rs index 8fa1b9a..b12ee66 100644 --- a/src/bin/pg_inserter/peeringdb.rs +++ b/src/bin/pg_inserter/peeringdb.rs @@ -1,6 +1,6 @@ -//! `peeringdb` schema: full PeeringDB API mirror (13 tables). +//! `peeringdb` schema: mirror of the 13 supported PeeringDB API tables. //! -//! One `Peeringdb::new()` load (all 13 endpoints) is dumped into 13 snapshot +//! One `Peeringdb::new()` load (the 13 supported endpoints) is dumped into 13 snapshot //! tables. Per-table shape: native PeeringDB id as PK, typed foreign-key and //! search columns, the complete API object in a `record` JSONB column, and //! `data_as_of`/`source_revision` provenance; `as_set` is the exception (no @@ -15,7 +15,7 @@ use bgpkit_commons::peeringdb::{ use serde::Serialize; use std::collections::HashMap; -/// Load the full PeeringDB dataset and map it to `(TableSpec, lines)` pairs, +/// Load the PeeringDB dataset and map it to `(TableSpec, lines)` pairs, /// one per table. Runs on the blocking pool. pub(crate) fn load_all(data_as_of: &str) -> Result)>, String> { let pdb = Peeringdb::new().map_err(|e| format!("failed to load PeeringDB data: {e}"))?; diff --git a/src/lib.rs b/src/lib.rs index c0f04fc..d699dbe 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -79,7 +79,7 @@ //! //! - Load: `Peeringdb::new()` (all tables), `Peeringdb::new_networks_only()` (lightweight) //! - Access: `get_network(asn)`, `get_ixp(ix_id)`, `get_ixp_memberships(asn)`, `lookup_ixp_prefix(prefix)`, `get_facility(fac_id)` -//! - Typed structs and an ASN-to-AS-set map mirroring all 13 PeeringDB API endpoints: +//! - Typed structs and an ASN-to-AS-set map mirroring the 13 supported PeeringDB API endpoints: //! networks, internet exchanges, IXP prefixes, IXP membership, facilities, organizations, //! carriers, AS-set names, and more //! - `PeeringdbData` is a type alias for the full `Network` struct (backward compatible) From 291159d8dfa695bca4ce1431cd930b8426a9f6f2 Mon Sep 17 00:00:00 2001 From: Mingwei Zhang Date: Mon, 5 Oct 2026 10:03:20 -0700 Subject: [PATCH 4/4] docs: correct the PeeringDB endpoint count in AGENTS.md --- AGENTS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AGENTS.md b/AGENTS.md index a2b9560..33071b4 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -20,7 +20,7 @@ BGPKIT-Commons is a Rust library for common BGP-related data and functions with │ ├── bogons/ # Bogon detection (reserved IPs/ASNs) │ ├── countries/ # Country code mappings │ ├── mrt_collectors/ # BGP collector metadata -│ ├── peeringdb/ # PeeringDB API data (all 12 endpoints) +│ ├── peeringdb/ # PeeringDB API data (all 13 endpoints) │ └── rpki/ # RPKI validation (ROA/ASPA) ├── examples/ # Feature-gated usage examples └── tests/ # Integration tests