web: one line per node pair and RTT/loss on the link board

A pair of nodes now has a single line, dialed by the non-listening side or by the smaller id when both listen, so RTT is measured once. The board draws it undirected and colours it by RTT and loss; a manual setting applies to the pair.
This commit is contained in:
justme committed 2026-10-21 16:20:38 +08:00
1 parent e0f6667cd7
commit 48ffa56285
6 files changed
+172 -72

No files matched your search

@@ -26,24 +26,38 @@ public sealed class LinkTests : IClassFixture<BackendFixture>
(await _backend.GetJsonAsync(_backend.Admin, "/api/admin/links"))["items"]!.AsArray().FirstOrDefault(i => i!["dialer_id"]!.GetValue<string>() == dialer && i["listener_id"]!.GetValue<string>() == agent);
[Fact]
public async Task ListeningAgents_AutomaticallyLinkBothDirections_WithoutSelfLinks()
public async Task ListeningAgents_AutomaticallyShareOneLine_DialedBySmallerId()
{
await using AgentSimulator first = await _backend.ConnectAgentAsync();
await using AgentSimulator second = await _backend.ConnectAgentAsync();
string a = first.NodeId.Value;
string b = second.NodeId.Value;
string[] ids = [.. new[] { first.NodeId.Value, second.NodeId.Value }.Order(StringComparer.Ordinal)];
(string a, string b) = (ids[0], ids[1]); // a 拨 b
AgentSimulator listener = a == first.NodeId.Value ? second : first;
AgentSimulator dialer = a == first.NodeId.Value ? first : second;
Assert.True((await LinkAsync(a, b))!["linked"]!.GetValue<bool>());
Assert.True((await LinkAsync(b, a))!["linked"]!.GetValue<bool>());
Assert.Null(await LinkAsync(b, a)); // 反方向不再有一条线路
Assert.Null(await LinkAsync(a, a));
using HttpResponseMessage self = await SetLinkAsync(a, a, true);
Assert.Equal(HttpStatusCode.UnprocessableEntity, self.StatusCode);
await first.WaitForTaskSetAsync(s => s.Peers.Any(p => p.NodeId.Value == b));
await second.WaitForTaskSetAsync(s => s.Peers.Any(p => p.NodeId.Value == a));
await listener.WaitForTaskSetAsync(s => s.Peers.Any(p => p.NodeId.Value == a));
await dialer.WaitForTaskSetAsync(s => s.Peers.All(p => p.NodeId.Value != b)); // 拨出的一方不放行对端拨进来
using HttpResponseMessage off = await SetLinkAsync(a, b, false);
off.EnsureSuccessStatusCode();
Assert.False((await LinkAsync(a, b))!["linked"]!.GetValue<bool>());
// 手动让 b 拨 a:线路换方向,仍然只有一条
using HttpResponseMessage swap = await SetLinkAsync(b, a, true);
swap.EnsureSuccessStatusCode();
Assert.Null(await LinkAsync(a, b));
Assert.True((await LinkAsync(b, a))!["linked"]!.GetValue<bool>());
await dialer.WaitForTaskSetAsync(s => s.Peers.Any(p => p.NodeId.Value == b));
// 关掉这一对:两个方向都不连,线路按默认方向显示,手动设置对这一对生效
using HttpResponseMessage off = await SetLinkAsync(b, a, false);
off.EnsureSuccessStatusCode();
Assert.Null(await LinkAsync(b, a));
JsonNode closed = (await LinkAsync(a, b))!;
Assert.False(closed["linked"]!.GetValue<bool>());
Assert.False(closed["override"]!.GetValue<bool>());
await SetLinkAsync(b, a, null);
Assert.True((await LinkAsync(a, b))!["linked"]!.GetValue<bool>());
}
[Fact]