80 lines
3.1 KiB
C#
80 lines
3.1 KiB
C#
using System.Text.Json.Serialization;
|
||
using MoShiro.Protocol;
|
||
|
||
namespace MoShiro.Probe;
|
||
|
||
/// <summary>
|
||
/// <c>probe.json</c>:本地配置,和 Agent 一样由 <c>fleet-enroll</c> 注册之后写出身份目录(节点自己生成的两把密钥),这里只放面板地址和本地硬上限。
|
||
/// <c>limits</c> 是本地硬上限,面板无法修改;在路由器上建议调低,避免 Probe 自己的 CPU 成为瓶颈、反过来影响测量。
|
||
/// </summary>
|
||
public sealed class ProbeFile
|
||
{
|
||
[JsonPropertyName("fleet")]
|
||
public ProbeFleetSection Fleet { get; set; } = new();
|
||
|
||
/// <summary>每天定时重启一次,例如 <c>04:00+08:00</c>(不写偏移按 UTC);不写就不重启。环境变量 <c>MOSHIRO_RESTART_AT</c> 优先;这里是本地配置,从面板重新下载 probe.json 会丢掉它,所以容器里推荐用环境变量。</summary>
|
||
[JsonPropertyName("restart_at")]
|
||
public string? RestartAt { get; set; }
|
||
|
||
[JsonPropertyName("limits")]
|
||
public ProbeLimits Limits { get; set; } = new();
|
||
}
|
||
|
||
public sealed class ProbeFleetSection
|
||
{
|
||
/// <summary>面板的地址(http 或 https)。Probe 直接连它:身份、Agent 列表、更新都从这里来。</summary>
|
||
[JsonPropertyName("server")]
|
||
public string Server { get; set; } = "";
|
||
|
||
/// <summary><c>fleet-enroll</c> 写出的身份目录:<c>node.json</c>、<c>node.key</c>(连面板的密钥)、<c>tls.pfx</c>(对等面的密钥)。</summary>
|
||
[JsonPropertyName("identity_dir")]
|
||
public string IdentityDir { get; set; } = "/etc/moshiro/probe-id";
|
||
}
|
||
|
||
public sealed class KnownAgent
|
||
{
|
||
[JsonPropertyName("ip_version")]
|
||
public string IpVersion { get; set; } = IpVersions.V4;
|
||
|
||
[JsonIgnore]
|
||
public string PathKey => AgentId + "~" + IpVersion;
|
||
|
||
[JsonPropertyName("agent_id")]
|
||
public string AgentId { get; set; } = "";
|
||
|
||
[JsonPropertyName("host")]
|
||
public string Host { get; set; } = "";
|
||
|
||
[JsonPropertyName("tcp_port")]
|
||
public int TcpPort { get; set; }
|
||
|
||
/// <summary>Agent 的 TLS 证书公钥(SPKI,base64):证书按它的 SHA-256 指纹固定,敲门密钥由它派生。</summary>
|
||
[JsonPropertyName("public_key")]
|
||
public string PublicKey { get; set; } = "";
|
||
}
|
||
|
||
public sealed class ProbeLimits
|
||
{
|
||
/// <summary>按需测试里单个阶段允许的最大码率(Mbit/s)。</summary>
|
||
[JsonPropertyName("max_test_mbps")]
|
||
public double MaxTestMbps { get; set; } = 100;
|
||
|
||
/// <summary>按需测试里单个阶段允许的最大包速率。</summary>
|
||
[JsonPropertyName("max_total_pps")]
|
||
public long MaxTotalPps { get; set; } = 20_000;
|
||
}
|
||
|
||
[JsonSerializable(typeof(ProbeFile))]
|
||
[JsonSerializable(typeof(AgentsCache))]
|
||
public sealed partial class ProbeConfigContext : JsonSerializerContext;
|
||
|
||
/// <summary><c>agents.json</c>:最近一次从面板同步到的 Agent 列表(配置,不是测量数据);面板连不上时 Probe 靠它继续测量。</summary>
|
||
public sealed class AgentsCache
|
||
{
|
||
[JsonPropertyName("version")]
|
||
public long Version { get; set; }
|
||
|
||
[JsonPropertyName("agents")]
|
||
public List<KnownAgent> Agents { get; set; } = [];
|
||
}
|