feat(nat): say in a report which observers are one address
Two names can be one address and one name can be two, so a report now numbers its observers' addresses and the replay reads its destinations from that line, as Codex's 39db6f6a does. Whether a campus network's counter follows the destination's address could not be told from report 025 for want of it. Version 0.5.3.
This commit is contained in:
1 parent
70aadaca6b
commit
cac7c7fa97
5 files changed
+38
-10
No files matched your search
Generated
+1
-1
@@ -4,4 +4,4 @@ version = 4
|
||||
|
||||
[[package]]
|
||||
name = "piik-nat"
|
||||
version = "0.5.2"
|
||||
version = "0.5.3"
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "piik-nat"
|
||||
version = "0.5.2"
|
||||
version = "0.5.3"
|
||||
edition = "2021"
|
||||
rust-version = "1.91"
|
||||
publish = false
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
|
||||
## For whoever reads the reports
|
||||
|
||||
`cargo run --example replay -- [--drop <text in an observer's name>] [--only <address letter>] 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 <text in an observer's name>] [--only <address letter>] 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
|
||||
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
//!
|
||||
//! cargo run --example replay -- [--drop <text in an observer's name>]... [--only <address letter>] 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<String> = 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<Vec<u8>> =
|
||||
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::<u16>(), port.parse::<u16>()) 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<Sample>>::new();
|
||||
|
||||
@@ -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<Ipv4Addr> = Vec::new();
|
||||
let groups: Vec<String> = 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::<Vec<_>>().join(", "));
|
||||
// Whether the mapping follows the destination's port: the same socket, the same address, two ports.
|
||||
|
||||
Reference in new issue
Block a user