The checks engine, the path and the cards: me-web? 0.1 reads the connection
MeWeb.Core runs seven checks concurrently and reports each as it settles:
online or behind a login page, this connection, the public IPv4 and IPv6
seen from v4./v6.meweb, the provider from a built-in map, the router
(UPnP IGD, NAT-PMP and PCP, read-only), address sharing (router WAN
against the echo, TTL hops only as a hint), and the history kept on the
device. The app draws the path from this device to the internet and lights
it node by node, with a card per check and a sheet listing every host it
contacts.
The provider map is iptoasn's table compressed to 2.1 MB by
tools/knowledge.cs and built before every app release; eleven Italian
provider profiles carry each fact with who said it, the source and the
month. The server gains a download page (en, it) and /download/{platform}
from the latest Gitea release.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012CzABvBkbcFqoHdmi8b9WB
This commit is contained in:
1 parent
16a1cecaae
commit
0dffbc27d6
61 files changed
+3750
-149
No files matched your search
@@ -0,0 +1,83 @@
|
||||
using Android.Content;
|
||||
using Android.Net;
|
||||
using Android.Net.Wifi;
|
||||
|
||||
using MeWeb.Core.Net;
|
||||
|
||||
namespace MeWeb.Android;
|
||||
|
||||
public class AndroidPlatform : SystemPlatform
|
||||
{
|
||||
static Context Context => global::Android.App.Application.Context;
|
||||
|
||||
public override DeviceKind Device => DeviceKind.Phone;
|
||||
|
||||
public override IDisposable AllowMulticast()
|
||||
{
|
||||
if (Context.GetSystemService(Context.WifiService) is not WifiManager wifi) return base.AllowMulticast();
|
||||
var multicast = wifi.CreateMulticastLock("meweb");
|
||||
multicast.SetReferenceCounted(false);
|
||||
multicast.Acquire();
|
||||
return new Held(multicast);
|
||||
}
|
||||
|
||||
public override LocalSnapshot ReadNetwork()
|
||||
{
|
||||
var snapshot = new LocalSnapshot();
|
||||
if (Context.GetSystemService(Context.ConnectivityService) is not ConnectivityManager connectivity) return base.ReadNetwork();
|
||||
var network = connectivity.ActiveNetwork;
|
||||
if (network is null) return snapshot;
|
||||
var link = connectivity.GetLinkProperties(network);
|
||||
var capabilities = connectivity.GetNetworkCapabilities(network);
|
||||
if (link is null) return base.ReadNetwork();
|
||||
|
||||
var item = new LocalInterface
|
||||
{
|
||||
Name = link.InterfaceName,
|
||||
Kind = capabilities switch
|
||||
{
|
||||
not null when capabilities.HasTransport(TransportType.Wifi) => LinkKind.Wifi,
|
||||
not null when capabilities.HasTransport(TransportType.Cellular) => LinkKind.Mobile,
|
||||
not null when capabilities.HasTransport(TransportType.Ethernet) => LinkKind.Cable,
|
||||
_ => LinkKind.Unknown,
|
||||
},
|
||||
};
|
||||
foreach (var address in link.LinkAddresses)
|
||||
{
|
||||
var text = Usable(address.Address?.HostAddress);
|
||||
if (text is not null) item.Addresses.Add(text);
|
||||
}
|
||||
foreach (var route in link.Routes)
|
||||
{
|
||||
var gateway = route.Gateway?.HostAddress;
|
||||
if (!route.IsDefaultRoute || gateway is null || gateway is "0.0.0.0" or "::") continue;
|
||||
if (!item.Gateways.Contains(gateway)) item.Gateways.Add(gateway);
|
||||
}
|
||||
item.Gateways = item.Gateways.OrderBy(g => g.Contains(':') ? 1 : 0).ToList();
|
||||
if (item.Kind == LinkKind.Wifi) item.SpeedMbps = WifiSpeed(capabilities);
|
||||
snapshot.Interfaces.Add(item);
|
||||
snapshot.Dns = link.DnsServers.Select(d => d.HostAddress).Where(d => d is not null).Distinct().ToList();
|
||||
return snapshot;
|
||||
}
|
||||
|
||||
static string Usable(string text)
|
||||
{
|
||||
var address = Addresses.Parse(text?.Split('%')[0]);
|
||||
if (address is null) return null;
|
||||
return Addresses.Classify(address) is AddressKind.Loopback or AddressKind.LinkLocal or AddressKind.Unspecified ? null : address.ToString();
|
||||
}
|
||||
|
||||
static long WifiSpeed(NetworkCapabilities capabilities)
|
||||
{
|
||||
if (OperatingSystem.IsAndroidVersionAtLeast(29) && capabilities?.TransportInfo is WifiInfo info) return Math.Max(0, info.LinkSpeed);
|
||||
return Context.GetSystemService(Context.WifiService) is WifiManager wifi ? Math.Max(0, wifi.ConnectionInfo?.LinkSpeed ?? 0) : 0;
|
||||
}
|
||||
|
||||
sealed class Held(WifiManager.MulticastLock multicast) : IDisposable
|
||||
{
|
||||
public void Dispose()
|
||||
{
|
||||
if (multicast.IsHeld) multicast.Release();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user