feat: add control center, multiple relay nodes and P2P-first transport

This commit is contained in:
tongtong committed 2026-11-12 16:56:06 +08:00
1 parent 0988e9c363
commit 2abfb63da9
44 files changed
+3477 -67

No files matched your search

+18
View File
@@ -50,6 +50,12 @@ public sealed record RelayOptions(Uri BaseUri, string Origin, string Token)
public sealed record RelayDevice(string Id, bool Busy);
public sealed record RelayNode(string Id, bool Healthy, int Sessions, int Capacity)
{
public string Description => $"{Id} · {(Healthy ? "在线" : "不可用")} · 通道 {Sessions}/{Capacity}";
}
public sealed record RelayCluster(RelayNode[] Nodes);
public static class RelayApi
{
public static HttpClient CreateClient(RelayOptions options)
@@ -79,6 +85,18 @@ public static class RelayApi
return new HttpClient(handler) { Timeout = TimeSpan.FromSeconds(12) };
}
public static async Task<RelayNode[]> GetNodesAsync(RelayOptions options, CancellationToken cancellation = default)
{
using var http = CreateClient(options);
using var request = new HttpRequestMessage(HttpMethod.Get,
new UriBuilder(options.DevicesUri) { Path = options.BaseUri.AbsolutePath.TrimEnd('/') + "/v2/nodes" }.Uri);
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", options.Token);
using var response = await http.SendAsync(request, cancellation);
if (response.StatusCode == HttpStatusCode.NotFound) return [];
response.EnsureSuccessStatusCode();
return (await response.Content.ReadFromJsonAsync<RelayCluster>(cancellationToken: cancellation))?.Nodes ?? [];
}
public static async Task<RelayDevice[]> GetDevicesAsync(RelayOptions options, CancellationToken cancellation = default)
{
using var http = CreateClient(options);