PrivaPub now finds CDNs three ways, best first: the address ranges the CDNs publish (Cloudflare, Fastly, Amazon CloudFront, Bunny, Gcore, Imperva), downloaded daily by CdnUpdater and kept in CdnRangeSet; the CDN's fingerprint in the responses it already gets from a server (EdgeHintsHandler on the federation client); and the networks that carry only a CDN. The fixed ASN list is gone; ASNs shared with plain hosting (AWS, DataPacket) no longer hide a server. A server's Geo records the CDN, its domain and how it was found, and weekly snapshots now keep the city and coordinates too. Servers through time (ServerPlaces): /instances/:host/history lists a server's weekly snapshots, a CDN-fronted server's geo names the CDN's domain and where the server was before it (before_cdn), and /api/privapub/v1/cdns and /cdns/:domain group servers by CDN with week by week who joined and who left. Owner decisions recorded in ROADMAP. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LsXgEaXee4GCU1hwYgPJXw
83 lines
2.7 KiB
C#
83 lines
2.7 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
using PrivaPub.Api.Mastodon.Infrastructure;
|
|
using PrivaPub.Domain.Statistics;
|
|
|
|
namespace PrivaPub.Api.Mastodon.Controllers
|
|
{
|
|
// The CDNs in front of the servers this server knows, each named by its own domain (owner decision 2026-10-04): how many
|
|
// servers are behind it, how it is recognised, and week by week who joined and who left.
|
|
public class CdnsController : MastodonController
|
|
{
|
|
const int MaxWeeks = 260;
|
|
|
|
readonly IServerPlaces _places;
|
|
|
|
public CdnsController(IServerPlaces places) => _places = places;
|
|
|
|
[HttpGet("/api/privapub/v1/cdns"), Scope("read", requiresUser: false), AllowAnonymous]
|
|
public async Task<IActionResult> List(CancellationToken token) => Json((await _places.Cdns(token)).Select(Summary).ToList());
|
|
|
|
[HttpGet("/api/privapub/v1/cdns/{key}"), Scope("read", requiresUser: false), AllowAnonymous]
|
|
public async Task<IActionResult> Detail(string key, CancellationToken token)
|
|
{
|
|
var history = await _places.Cdn(key, Math.Clamp(Params.Int("weeks") ?? 52, 1, MaxWeeks), token);
|
|
if (history == default)
|
|
return NotFoundError();
|
|
var detail = new CdnDetail
|
|
{
|
|
Hosts = history.Hosts,
|
|
HostsTruncated = history.Group.Servers > history.Hosts.Count,
|
|
Weeks = history.Weeks.Select(w => new CdnWeekEntry { Week = w.Week, Servers = w.Servers, Joined = w.Joined, Left = w.Left }).ToList()
|
|
};
|
|
Fill(detail, history.Group);
|
|
return Json(detail);
|
|
}
|
|
|
|
static CdnSummary Summary(CdnGroup group)
|
|
{
|
|
var summary = new CdnSummary();
|
|
Fill(summary, group);
|
|
return summary;
|
|
}
|
|
|
|
static void Fill(CdnSummary summary, CdnGroup group)
|
|
{
|
|
summary.Key = group.Key;
|
|
summary.Name = group.Name;
|
|
summary.Domain = group.Domain;
|
|
summary.Servers = group.Servers;
|
|
summary.Ranges = group.Ranges;
|
|
summary.RangesUpdatedAt = group.RangesUpdatedAt is { } at ? MastodonJson.Time(at) : default;
|
|
summary.DetectedBy = group.DetectedBy;
|
|
}
|
|
|
|
public class CdnSummary
|
|
{
|
|
public string Key { get; set; }
|
|
public string Name { get; set; }
|
|
public string Domain { get; set; }
|
|
public int Servers { get; set; }
|
|
public int Ranges { get; set; }
|
|
public string RangesUpdatedAt { get; set; }
|
|
public List<string> DetectedBy { get; set; } = new();
|
|
}
|
|
|
|
public class CdnDetail : CdnSummary
|
|
{
|
|
public List<string> Hosts { get; set; } = new();
|
|
public bool HostsTruncated { get; set; }
|
|
public List<CdnWeekEntry> Weeks { get; set; } = new();
|
|
}
|
|
|
|
public class CdnWeekEntry
|
|
{
|
|
public string Week { get; set; }
|
|
public int Servers { get; set; }
|
|
public List<string> Joined { get; set; } = new();
|
|
public List<string> Left { get; set; } = new();
|
|
}
|
|
}
|
|
}
|