using System.Text.Json.Serialization;
namespace Fleet.Rpc;
///
/// 节点间点对点会话的握手(拨号方 → 监听方,TLS 帧)。除了签名认证,双方各生成一个临时 ECDH 密钥,
/// 经过 HKDF 派生出数据面使用的 session_id 与 session_key(所以不需要单独的“下发密钥”方法)。
///
public static class PeerMethods
{
public const string Challenge = "fleet.peer.challenge";
public const string Auth = "fleet.peer.auth";
}
public sealed class PeerChallengeParams
{
[JsonPropertyName("nonce")]
public string Nonce { get; set; } = "";
/// 服务端(监听方)的临时 ECDH 公钥(SPKI,base64)。
[JsonPropertyName("ecdh_pub")]
public string EcdhPublicKey { get; set; } = "";
}
public sealed class PeerAuthParams
{
[JsonPropertyName("peer_id")]
public string PeerId { get; set; } = "";
/// 发起方的临时 ECDH 公钥(SPKI,base64)。
[JsonPropertyName("ecdh_pub")]
public string EcdhPublicKey { get; set; } = "";
/// 对 fleet|v1|peer|{peer_id}|{nonce}|{client_ecdh_pub}|{server_ecdh_pub} 的签名(base64)。
[JsonPropertyName("signature")]
public string Signature { get; set; } = "";
/// 发起方的程序版本(可选,只用于展示)。
[JsonPropertyName("version")]
public string? Version { get; set; }
}
public sealed class PeerAuthResult
{
[JsonPropertyName("session_id")]
public string SessionId { get; set; } = "";
}
[JsonSerializable(typeof(PeerChallengeParams))]
[JsonSerializable(typeof(PeerAuthParams))]
[JsonSerializable(typeof(PeerAuthResult))]
public sealed partial class PeerRpcContext : JsonSerializerContext;