me-web? 0.2: the test from outside, calls and games, mail, and what you can host
Phases two and three ship together, because their code grew in the same files. With consent the app asks the router to open 80, 443 and a high port for ten minutes (UPnP, NAT-PMP or PCP), and the server, holding a single-use ticket bound to the caller's own address, connects back and must get an HMAC only the app can give; the mappings are removed after the run and remembered until then, so a crash cannot leave one open. Hairpin is tried from inside. Two STUN servers, the outside one first, tell easy from hard NAT. Mail gets port 25 to Gmail and Outlook, the reverse name and five blocklists through the user's own resolver, network-wide UCEPROTECT listings counted as a caution. DNS, speed against the server (four at a time, twelve an hour per address) and the device follow, and six uses (website, home from outside, files, game server, fediverse, mail) close the run as possible, possible with a named workaround, or can't tell. Findings can be shared after reading the exact JSON: a file per submission under the unit's state directory, ten a day per address, deletable by the token the app keeps, swept after twelve months; /privacy says all of it in English and Italian. QR codes lead to the downloads. Every language carries every string. 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
f79682eaef
commit
7cfc8b6de5
161 files changed
+23159
-305
No files matched your search
@@ -0,0 +1,58 @@
|
||||
using System.Diagnostics;
|
||||
|
||||
using MeWeb.Shared;
|
||||
|
||||
namespace MeWeb.Core.Net;
|
||||
|
||||
public class SpeedReport
|
||||
{
|
||||
public double DownMbps { get; set; }
|
||||
public double UpMbps { get; set; }
|
||||
public int DownBytes { get; set; }
|
||||
public int UpBytes { get; set; }
|
||||
public bool Limited { get; set; }
|
||||
}
|
||||
|
||||
public static class SpeedCheck
|
||||
{
|
||||
public static async Task<SpeedReport> Run(HttpClient https, LinkKind kind, CancellationToken ct)
|
||||
{
|
||||
var mobile = kind == LinkKind.Mobile;
|
||||
var report = new SpeedReport { DownBytes = mobile ? 2 * 1024 * 1024 : 12 * 1024 * 1024, UpBytes = mobile ? 1024 * 1024 : 4 * 1024 * 1024 };
|
||||
try
|
||||
{
|
||||
using var timeout = CancellationTokenSource.CreateLinkedTokenSource(ct);
|
||||
timeout.CancelAfter(TimeSpan.FromSeconds(30));
|
||||
var clock = Stopwatch.StartNew();
|
||||
using (var response = await https.GetAsync(Endpoints.Base + Endpoints.Speed.GET_M_Down(report.DownBytes), HttpCompletionOption.ResponseHeadersRead, timeout.Token))
|
||||
{
|
||||
if ((int)response.StatusCode == 429)
|
||||
{
|
||||
report.Limited = true;
|
||||
return report;
|
||||
}
|
||||
response.EnsureSuccessStatusCode();
|
||||
await using var body = await response.Content.ReadAsStreamAsync(timeout.Token);
|
||||
var buffer = new byte[64 * 1024];
|
||||
long total = 0;
|
||||
int read;
|
||||
while ((read = await body.ReadAsync(buffer, timeout.Token)) > 0) total += read;
|
||||
report.DownMbps = Mbps(total, clock.Elapsed);
|
||||
}
|
||||
|
||||
var payload = new byte[report.UpBytes];
|
||||
Random.Shared.NextBytes(payload);
|
||||
clock.Restart();
|
||||
using (var response = await https.PostAsync(Endpoints.Base + Endpoints.Speed.POST_Up, new ByteArrayContent(payload), timeout.Token))
|
||||
{
|
||||
if (response.IsSuccessStatusCode) report.UpMbps = Mbps(payload.Length, clock.Elapsed);
|
||||
}
|
||||
}
|
||||
catch (Exception ex) when (ex is HttpRequestException or TaskCanceledException or IOException && !ct.IsCancellationRequested)
|
||||
{
|
||||
}
|
||||
return report;
|
||||
}
|
||||
|
||||
static double Mbps(long bytes, TimeSpan elapsed) => elapsed.TotalSeconds <= 0 ? 0 : Math.Round(bytes * 8 / elapsed.TotalSeconds / 1_000_000, 1);
|
||||
}
|
||||
Reference in new issue
Block a user