MoShiro__MinAgentVersion makes the backend refuse agents below it at hello (fleet_version_required); fleet.min_server_version or MOSHIRO_MIN_SERVER_VERSION makes the agent drop a backend below it. Either side waits five seconds and shakes hands again, because the other one may be updating.
96 lines
3.6 KiB
C#
96 lines
3.6 KiB
C#
using System.Text.Json.Serialization;
|
|
using MoShiro.Measurement;
|
|
|
|
namespace MoShiro.Agent;
|
|
|
|
/// <summary>
|
|
/// <c>agent.json</c>:节点本地配置,面板无法修改。其中 <c>limits</c> 是本地硬上限:期望任务集超出这些范围时,
|
|
/// 调和器拒绝执行并在 <c>rejected[]</c> 里给出原因。默认不使用 443,目标任务默认不开放。
|
|
/// </summary>
|
|
public sealed class AgentConfig
|
|
{
|
|
[JsonPropertyName("fleet")]
|
|
public FleetSection Fleet { get; set; } = new();
|
|
|
|
[JsonPropertyName("listen")]
|
|
public ListenSection Listen { get; set; } = new();
|
|
|
|
[JsonPropertyName("limits")]
|
|
public LimitsSection Limits { get; set; } = new();
|
|
|
|
[JsonPropertyName("fleet_policy")]
|
|
public PolicySection Policy { get; set; } = new();
|
|
|
|
[JsonPropertyName("reporting")]
|
|
public ReportingSection Reporting { get; set; } = new();
|
|
|
|
/// <summary>每天定时重启一次,例如 <c>04:00+08:00</c>(不写偏移按 UTC);不写就不重启。环境变量 <c>MOSHIRO_RESTART_AT</c> 优先。</summary>
|
|
[JsonPropertyName("restart_at")]
|
|
public string? RestartAt { get; set; }
|
|
}
|
|
|
|
public sealed class FleetSection
|
|
{
|
|
[JsonPropertyName("server")]
|
|
public string Server { get; set; } = "";
|
|
|
|
[JsonPropertyName("identity_dir")]
|
|
public string IdentityDir { get; set; } = "/etc/moshiro";
|
|
|
|
/// <summary>节点自己要求有属主(passkey):没有就不运行。见 <c>OwnerGuard</c>。</summary>
|
|
[JsonPropertyName("require_owner")]
|
|
public bool RequireOwner { get; set; } = true;
|
|
|
|
/// <summary>面板至少要是哪个版本才继续连接(如 <c>0.4.2-dev.80</c>);空 = 不要求。不够就不发任何东西,5 秒后重新握手(面板可能正在更新)。环境变量 <c>MOSHIRO_MIN_SERVER_VERSION</c> 优先。</summary>
|
|
[JsonPropertyName("min_server_version")]
|
|
public string? MinServerVersion { get; set; }
|
|
}
|
|
|
|
public sealed class ListenSection
|
|
{
|
|
/// <summary>是否接受拨号方的连接。关闭时节点只拨出:不开任何端口,在 Backend 的目录里也不是拨号目标(家宽和 NAT 后的节点用这个配置)。</summary>
|
|
[JsonPropertyName("enabled")]
|
|
public bool Enabled { get; set; } = true;
|
|
|
|
[JsonPropertyName("bind")]
|
|
public string Bind { get; set; } = "::";
|
|
|
|
/// <summary>拨号方 控制通道(TLS,点对点会话)。</summary>
|
|
[JsonPropertyName("control_port")]
|
|
public int ControlPort { get; set; } = 7443;
|
|
|
|
[JsonPropertyName("quic_ports")]
|
|
public List<int> QuicPorts { get; set; } = [7443];
|
|
|
|
[JsonPropertyName("tcp_ports")]
|
|
public List<int> TcpPorts { get; set; } = [7444];
|
|
}
|
|
|
|
public sealed class LimitsSection
|
|
{
|
|
[JsonPropertyName("max_total_mbps")]
|
|
public double MaxTotalMbps { get; set; } = 1200;
|
|
|
|
[JsonPropertyName("max_total_pps")]
|
|
public long MaxTotalPps { get; set; } = 20_000;
|
|
|
|
/// <summary>默认为空:不允许执行任何目标任务。</summary>
|
|
[JsonPropertyName("allowed_target_cidrs")]
|
|
public List<string> AllowedTargetCidrs { get; set; } = [];
|
|
|
|
[JsonPropertyName("max_concurrent_tests")]
|
|
public int MaxConcurrentTests { get; set; } = 1;
|
|
}
|
|
|
|
public sealed class PolicySection
|
|
{
|
|
/// <summary>在默认值的基础上进一步收窄:只响应这些产品方法。为空表示不收窄。</summary>
|
|
[JsonPropertyName("allow_methods")]
|
|
public List<string>? AllowMethods { get; set; }
|
|
}
|
|
|
|
[JsonSerializable(typeof(AgentConfig))]
|
|
[JsonSerializable(typeof(DialCache))]
|
|
[JsonSerializable(typeof(OpenWrtHealth))]
|
|
public sealed partial class AgentConfigContext : System.Text.Json.Serialization.JsonSerializerContext;
|