Namespaces, assemblies, projects and directories, the solution, binaries, images, systemd units, config paths, environment variables, protocol method names, the media type and the raw chunk magic all move to MoShiro/moshiro. Existing data and deployments are not compatible and must be recreated. Also fix the architecture tests after the solution layout change and make the update tests independent of their order.
141 lines
4.0 KiB
C#
141 lines
4.0 KiB
C#
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
|
|
namespace Fleet.Rpc;
|
|
|
|
/// <summary>框架保留的方法名。<c>fleet.*</c> 只属于框架,产品使用自己的前缀。</summary>
|
|
public static class FleetMethods
|
|
{
|
|
public const string Challenge = "fleet.challenge";
|
|
public const string Auth = "fleet.auth";
|
|
public const string Hello = "fleet.hello";
|
|
public const string Heartbeat = "fleet.heartbeat";
|
|
public const string StateSync = "fleet.state.sync";
|
|
public const string OutboxAck = "fleet.outbox.ack";
|
|
public const string Revoked = "fleet.revoked";
|
|
}
|
|
|
|
/// <summary>二进制通道:0–15 保留给框架,产品从 16 开始。</summary>
|
|
public static class FleetChannels
|
|
{
|
|
public const byte FirstProductChannel = 16;
|
|
}
|
|
|
|
public sealed class ChallengeParams
|
|
{
|
|
[JsonPropertyName("nonce")]
|
|
public string Nonce { get; set; } = "";
|
|
|
|
[JsonPropertyName("expires_at_ms")]
|
|
public long ExpiresAtMs { get; set; }
|
|
}
|
|
|
|
public sealed class AuthParams
|
|
{
|
|
[JsonPropertyName("node_id")]
|
|
public string NodeId { get; set; } = "";
|
|
|
|
/// <summary>对 <c>fleet|v1|auth|{node_id}|{nonce}</c> 的签名(base64)。</summary>
|
|
[JsonPropertyName("signature")]
|
|
public string Signature { get; set; } = "";
|
|
}
|
|
|
|
public sealed class AuthResult
|
|
{
|
|
/// <summary>pending | active</summary>
|
|
[JsonPropertyName("status")]
|
|
public string Status { get; set; } = "";
|
|
}
|
|
|
|
public sealed class HelloParams
|
|
{
|
|
[JsonPropertyName("node_version")]
|
|
public string NodeVersion { get; set; } = "";
|
|
|
|
[JsonPropertyName("capabilities")]
|
|
public List<string> Capabilities { get; set; } = [];
|
|
|
|
[JsonPropertyName("now_utc_ms")]
|
|
public long NowUtcMs { get; set; }
|
|
|
|
/// <summary>产品自定义的元数据(例如 MoShiro 的 tls_spki、probe_ports、local_limits 摘要)。</summary>
|
|
[JsonPropertyName("meta")]
|
|
public JsonElement? Meta { get; set; }
|
|
}
|
|
|
|
public sealed class HelloResult
|
|
{
|
|
[JsonPropertyName("server_time_ms")]
|
|
public long ServerTimeMs { get; set; }
|
|
|
|
/// <summary>节点时钟 − 服务端时钟(毫秒,未扣除网络往返)。</summary>
|
|
[JsonPropertyName("clock_offset_ms")]
|
|
public long ClockOffsetMs { get; set; }
|
|
}
|
|
|
|
public sealed class HeartbeatParams
|
|
{
|
|
[JsonPropertyName("extra")]
|
|
public JsonElement? Extra { get; set; }
|
|
}
|
|
|
|
public sealed class StateSyncParams
|
|
{
|
|
[JsonPropertyName("type")]
|
|
public string Type { get; set; } = "";
|
|
|
|
[JsonPropertyName("version")]
|
|
public long Version { get; set; }
|
|
|
|
[JsonPropertyName("doc")]
|
|
public JsonElement Doc { get; set; }
|
|
}
|
|
|
|
public sealed class StateSyncResult
|
|
{
|
|
[JsonPropertyName("applied_version")]
|
|
public long AppliedVersion { get; set; }
|
|
|
|
[JsonPropertyName("rejected")]
|
|
public List<RejectedItem> Rejected { get; set; } = [];
|
|
}
|
|
|
|
public sealed class RejectedItem
|
|
{
|
|
[JsonPropertyName("id")]
|
|
public string Id { get; set; } = "";
|
|
|
|
/// <summary>unsupported | budget_exceeded | policy_denied | …</summary>
|
|
[JsonPropertyName("reason")]
|
|
public string Reason { get; set; } = "";
|
|
}
|
|
|
|
public sealed class OutboxAckParams
|
|
{
|
|
[JsonPropertyName("ids")]
|
|
public List<string> Ids { get; set; } = [];
|
|
|
|
[JsonPropertyName("duplicates")]
|
|
public List<string> Duplicates { get; set; } = [];
|
|
}
|
|
|
|
public sealed class RevokedParams
|
|
{
|
|
[JsonPropertyName("reason")]
|
|
public string Reason { get; set; } = "";
|
|
}
|
|
|
|
[JsonSourceGenerationOptions(DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)]
|
|
[JsonSerializable(typeof(RpcMessage))]
|
|
[JsonSerializable(typeof(ChallengeParams))]
|
|
[JsonSerializable(typeof(AuthParams))]
|
|
[JsonSerializable(typeof(AuthResult))]
|
|
[JsonSerializable(typeof(HelloParams))]
|
|
[JsonSerializable(typeof(HelloResult))]
|
|
[JsonSerializable(typeof(HeartbeatParams))]
|
|
[JsonSerializable(typeof(StateSyncParams))]
|
|
[JsonSerializable(typeof(StateSyncResult))]
|
|
[JsonSerializable(typeof(OutboxAckParams))]
|
|
[JsonSerializable(typeof(RevokedParams))]
|
|
public sealed partial class FleetRpcContext : JsonSerializerContext;
|