diff --git a/prototype/nat/Cargo.lock b/prototype/nat/Cargo.lock index 02538a6da..fb62545d6 100644 --- a/prototype/nat/Cargo.lock +++ b/prototype/nat/Cargo.lock @@ -4,4 +4,4 @@ version = 4 [[package]] name = "piik-nat" -version = "0.5.2" +version = "0.5.3" diff --git a/prototype/nat/Cargo.toml b/prototype/nat/Cargo.toml index 775b247ec..87b1c8aa4 100644 --- a/prototype/nat/Cargo.toml +++ b/prototype/nat/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "piik-nat" -version = "0.5.2" +version = "0.5.3" edition = "2021" rust-version = "1.91" publish = false diff --git a/prototype/nat/README.md b/prototype/nat/README.md index 1b4be754e..3b71cf3a2 100644 --- a/prototype/nat/README.md +++ b/prototype/nat/README.md @@ -28,7 +28,7 @@ ## For whoever reads the reports -`cargo run --example replay -- [--drop ] [--only
] report.txt...` replays pasted reports offline: how often the aim read from earlier mappings would have held each new one, at several packet budgets. No packet is sent. +`cargo run --example replay -- [--drop ] [--only
] report.txt...` replays pasted reports offline: how often the aim read from earlier mappings would have held each new one, at several packet budgets. No packet is sent. A report says which of its observers are one address by number (`observer address groups`), since names alone do not: the replay reads its destinations from that line. ## The server of our own diff --git a/prototype/nat/examples/replay.rs b/prototype/nat/examples/replay.rs index d248f0193..a42df7088 100644 --- a/prototype/nat/examples/replay.rs +++ b/prototype/nat/examples/replay.rs @@ -2,8 +2,9 @@ //! //! cargo run --example replay -- [--drop ]... [--only
] report.txt... //! -//! A report masks its addresses, so each address letter and each observer host gets a stand-in -//! address; observers on one host share one, as they do in the field. +//! A report masks its addresses, so each address letter and each observer address gets a +//! stand-in address. Which observers are one address comes from the report's own line of +//! address groups, and from the hosts in the observers' names where a report has no such line. use piik_nat::mapping::{replay, Allocator, Holdout, Model, Sample}; use std::{collections::BTreeMap, net::{Ipv4Addr, SocketAddrV4}}; @@ -22,16 +23,29 @@ fn main() { // "observers: 0=stun.example.com:3478 1=..." names each observer index. let mut observers = BTreeMap::new(); let mut hosts: Vec = Vec::new(); + // "observer address groups: 1 2 2 3 ..." says which observers are one address. Reports + // made before that line existed are grouped by the host in an observer's name. + let groups: Option> = + text.lines().find_map(|line| line.trim().strip_prefix("observer address groups: ")?.split_whitespace().map(|group| group.parse().ok()).collect()); for line in text.lines().filter_map(|line| line.trim().strip_prefix("observers: ")) { for entry in line.split_whitespace() { let Some((index, name)) = entry.split_once('=') else { continue }; let Some((host, port)) = name.rsplit_once(':') else { continue }; let (Ok(index), Ok(port)) = (index.parse::(), port.parse::()) else { continue }; - let host_index = hosts.iter().position(|known| known == host).unwrap_or_else(|| { - hosts.push(host.to_owned()); - hosts.len() - 1 - }); - observers.insert(index, (name.to_owned(), SocketAddrV4::new(Ipv4Addr::new(203, 0, 113, host_index as u8 + 1), port))); + let group = match &groups { + Some(groups) => { + let Some(group) = groups.get(usize::from(index)) else { continue }; + *group + } + None => { + let host_index = hosts.iter().position(|known| known == host).unwrap_or_else(|| { + hosts.push(host.to_owned()); + hosts.len() - 1 + }); + host_index as u8 + 1 + } + }; + observers.insert(index, (name.to_owned(), SocketAddrV4::new(Ipv4Addr::new(203, 0, 113, group), port))); } } let mut groups = BTreeMap::<&str, Vec>::new(); diff --git a/prototype/nat/src/main.rs b/prototype/nat/src/main.rs index a3faa8895..c7b773e17 100644 --- a/prototype/nat/src/main.rs +++ b/prototype/nat/src/main.rs @@ -379,6 +379,20 @@ fn report(survey: &Survey, observers: &[(String, SocketAddrV4)], (asked, unasked // A silent first port shows only that it did not answer: the rest of its run was not asked. let left = if unasked > 0 { format!(", {unasked} more not asked after their run's first port stayed silent") } else { String::new() }; println!("observers answered: {} of {} asked{left}; requests answered {}, unanswered {}", observers.len(), asked, survey.answered, survey.unanswered); + // Which observers are one address, by number: names alone do not say, since two names can be + // one address and one name can be two. The replay reads its destinations from this line. + let mut grouped: Vec = Vec::new(); + let groups: Vec = observers + .iter() + .map(|(_, observer)| { + let group = grouped.iter().position(|known| known == observer.ip()).unwrap_or_else(|| { + grouped.push(*observer.ip()); + grouped.len() - 1 + }); + (group + 1).to_string() + }) + .collect(); + println!("observer address groups: {}", groups.join(" ")); println!("local: {network}; global IPv6: {}", if ipv6 { "yes" } else { "no" }); println!("public addresses: {}", addresses.iter().map(|address| format!("{} {}", letter(address), shown(*address))).collect::>().join(", ")); // Whether the mapping follows the destination's port: the same socket, the same address, two ports.