M9 (first part): the means to locate a server
- IConnectedAddresses remembers which address each host's last connection reached, set in SafeHttpHandlerFactory's connect callback. That is once per pooled connection, with no second DNS lookup, and the address is never stored. - IGeoLocator / DbIpLocator reads the offline DB-IP Lite city and ASN databases (MaxMind .mmdb, via MaxMind.Db). It maps memory, swaps to new files within ten minutes, rounds coordinates to one decimal, never looks up a private address, and answers nothing when the files are missing. CdnNetworks names the CDNs whose edge addresses say nothing about where a server is. - deploy/max/geo-update.sh fetches this or last month's databases, checks them and swaps them in atomically. The privapub-geo timer runs it monthly as www-data, and setup.sh installs the directory, the script, the units and a first download. Describing servers will use these in M8. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ELjqpznMFMNrJoJUj6K5p2
This commit is contained in:
1 parent
fc15f6356d
commit
cee85309b8
12 files changed
+357
-7
No files matched your search
@@ -0,0 +1,29 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.Net;
|
||||
|
||||
namespace PrivaPub.Infrastructure.Http
|
||||
{
|
||||
public interface IConnectedAddresses
|
||||
{
|
||||
void Remember(string host, IPAddress address);
|
||||
IPAddress Of(string host);
|
||||
}
|
||||
|
||||
public class ConnectedAddresses : IConnectedAddresses
|
||||
{
|
||||
const int MaxHosts = 50_000;
|
||||
|
||||
readonly ConcurrentDictionary<string, IPAddress> _addresses = new(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
public void Remember(string host, IPAddress address)
|
||||
{
|
||||
if (string.IsNullOrEmpty(host) || address == default)
|
||||
return;
|
||||
if (_addresses.Count >= MaxHosts)
|
||||
_addresses.Clear();
|
||||
_addresses[host] = address.IsIPv4MappedToIPv6 ? address.MapToIPv4() : address;
|
||||
}
|
||||
|
||||
public IPAddress Of(string host) => host != default && _addresses.TryGetValue(host, out var address) ? address : default;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user