Site: the big clouds are machines, not people
Some checks are pending
CI / check (push) Waiting to run
CI / windows-build (push) Waiting to run
CI / macos-build (push) Waiting to run

A Windows installation 'in Cheyenne' right after a release is Microsoft's scanner running
the new program in Azure. The DB-IP Lite ASN database (fetched like the city one) tells
the networks of Microsoft, Amazon, Google, Oracle, Alibaba, Tencent and IBM apart: their
launches are not counted or announced, their downloads and visits count as crawlers.
Small hostings are left alone: people's VPNs run on them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
vrubelroman 2026-10-24 14:58:38 +03:00
parent 7bf4d58cbf
commit 75692ede4d
4 changed files with 60 additions and 6 deletions

View file

@ -69,6 +69,8 @@ struct Config {
/// Geolocation databases (MaxMind DB format): DB-IP Lite City, either the official
/// file or the IPv4/IPv6 pair of ip-location-db; comma-separated.
geoip_paths: Vec<PathBuf>,
/// The network owner (ASN) database: DB-IP Lite ASN, to tell the big clouds apart.
asn_path: PathBuf,
repo: String,
stats_user: String,
stats_password: String,
@ -85,6 +87,7 @@ impl Config {
site_dir: var("SITE_DIR", "site").into(),
site_url: var("SITE_URL", "http://localhost:8080"),
db_path: var("DB_PATH", "data/downloads.sqlite").into(),
asn_path: var("ASN_DB", "data/dbip-asn.mmdb").into(),
geoip_paths: var("GEOIP_DB", "data/dbip-city-ipv4.mmdb,data/dbip-city-ipv6.mmdb")
.split(',')
.map(|s| PathBuf::from(s.trim()))
@ -122,6 +125,7 @@ struct AppState {
site: site::Site,
db: Mutex<rusqlite::Connection>,
geoip: Vec<maxminddb::Reader<Vec<u8>>>,
asn: Option<maxminddb::Reader<Vec<u8>>>,
http: reqwest::Client,
/// The same without following redirects: to learn where GitHub sends a file.
direct: reqwest::Client,
@ -208,6 +212,13 @@ async fn main() {
if geoip.is_empty() {
eprintln!("geolocation off: downloads are stored without a country");
}
let asn = match maxminddb::Reader::open_readfile(&config.asn_path) {
Ok(r) => Some(r),
Err(e) => {
eprintln!("network database {} not used: {e}; clouds are not told apart", config.asn_path.display());
None
}
};
if config.stats_password.is_empty() {
eprintln!("STATS_PASSWORD is empty: /stats is disabled");
}
@ -219,6 +230,7 @@ async fn main() {
config,
db: Mutex::new(db),
geoip,
asn,
http: reqwest::Client::builder()
.user_agent("chesspenguin-site")
.timeout(Duration::from_secs(15))
@ -370,7 +382,7 @@ fn client(state: &AppState, peer: SocketAddr, headers: &HeaderMap) -> Client {
"owner"
} else if is_local(ip) {
"local"
} else if looks_like_bot(&ua, lang.as_deref()) {
} else if looks_like_bot(&ua, lang.as_deref()) || in_cloud(state, ip) {
"bot"
} else {
"human"
@ -619,7 +631,8 @@ async fn api_update(
.filter(|p| LAUNCH_PLATFORMS.contains(&p.as_str()));
if let (Some(install), Some(version), Some(platform)) = (install, version, platform) {
let ip = client_ip(&state.config, peer, &headers);
if !is_local(ip) {
// Neither the local network nor a cloud: a program a scanner runs is no user.
if !is_local(ip) && !in_cloud(&state, ip) {
let (country, region, city) = locate(&state, ip);
let day = chrono::Local::now().format("%Y-%m-%d").to_string();
// A few new installations a day per address (a family, a classroom); more is
@ -837,6 +850,32 @@ fn client_ip(config: &Config, peer: SocketAddr, headers: &HeaderMap) -> IpAddr {
/// both the GeoIP2-style records of the official DB-IP file (`country.iso_code`,
/// `subdivisions[0].names.en`, `city.names.en`) and the flat ones of ip-location-db
/// (`country_code`, `state1`, `city`).
/// The big clouds (their networks, ASN): an address in them is a machine — a security
/// scanner running a new program (Microsoft's, in Cheyenne), a crawler — not a person.
/// Small hostings are not here: people's VPNs run on them.
const CLOUDS: &[u32] = &[
8075, 8068, 8069, 8070, 8071, 8072, 8073, 8074, 12076, // Microsoft (Azure)
16509, 14618, 8987, // Amazon (AWS)
15169, 396982, 19527, 36040, 36492, 43515, // Google (Cloud)
31898, 792, // Oracle
45102, 37963, 24429, // Alibaba
132203, 45090, // Tencent
36351, // IBM (SoftLayer)
];
/// The address is in a big cloud (see [`CLOUDS`]).
fn in_cloud(state: &AppState, ip: IpAddr) -> bool {
let Some(reader) = &state.asn else {
return false;
};
reader
.lookup(ip)
.ok()
.and_then(|r| r.decode::<serde_json::Value>().ok().flatten())
.and_then(|r| r["autonomous_system_number"].as_u64())
.is_some_and(|n| CLOUDS.contains(&(n as u32)))
}
fn locate(state: &AppState, ip: IpAddr) -> (Option<String>, Option<String>, Option<String>) {
let record = state.geoip.iter().find_map(|reader| {
reader