using Fleet.Rpc;
namespace MoShiro.Protocol;
/// 节点的角色。服务端按节点 ID 的前缀判断;声明表用它限定哪些角色可以参与某个方法或通道。
public static class NodeRoles
{
public const string Agent = "agent";
public const string Probe = "probe";
public static string? Of(string nodeId) =>
nodeId.StartsWith(AgentIds.Prefix, StringComparison.Ordinal) ? Agent
: nodeId.StartsWith(ProbeId.Prefix, StringComparison.Ordinal) ? Probe
: null;
}
///
/// 所有方法和二进制通道的方向声明,单一真源(框架的 fleet.* 见 )。
/// 新增一个方法:在 里加名字和参数,在这里加一行声明,再在对应一侧注册处理函数;
/// 声明了但没人处理、或者处理了但没声明,都会被测试和启动时的检查发现。
/// 同一个方法名只有一个发起方;节点面是服务端和节点(B 和 A、P),对等面是 Probe(拨号方)和 Agent(监听方)。
///
public static class MoShiroMethodTable
{
public static readonly MethodTable Table = MethodTable.Combine(
FleetMethodTable.Table,
new MethodTable(
[
// 节点面:Backend → 节点
MethodSpec.Request(MoShiroMethods.TestRun, RpcSide.Server, NodeRoles.Agent),
MethodSpec.Request(MoShiroMethods.TestCancel, RpcSide.Server, NodeRoles.Agent),
MethodSpec.Request(MoShiroMethods.ProbeDisconnect, RpcSide.Server, NodeRoles.Agent),
MethodSpec.Notification(MoShiroMethods.ProbeLinkRetry, RpcSide.Server, NodeRoles.Probe),
MethodSpec.Notification(MoShiroMethods.UpdateOffer, RpcSide.Server),
MethodSpec.Notification(MoShiroMethods.UpdateApply, RpcSide.Server),
MethodSpec.Notification(MoShiroMethods.Schedule, RpcSide.Server),
// 节点面:节点 → Backend
MethodSpec.Notification(MoShiroMethods.TestStatus, RpcSide.Node, NodeRoles.Agent),
MethodSpec.Notification(MoShiroMethods.Event, RpcSide.Node, NodeRoles.Agent),
MethodSpec.Notification(MoShiroMethods.Host, RpcSide.Node), // Agent 和 Probe 都上报主机资源占用的汇总
// 对等面:Probe(拨号方)→ Agent(监听方)
MethodSpec.Request(MoShiroMethods.Clock, RpcSide.Dialer),
// 对等面:Agent → Probe
MethodSpec.Request(MoShiroMethods.TestPhase, RpcSide.Listener),
MethodSpec.Request(MoShiroMethods.TestPhaseEnd, RpcSide.Listener),
MethodSpec.Notification(MoShiroMethods.TestAbort, RpcSide.Listener),
],
[
// 原始块:只有 Agent 往 Backend 发;列块:Probe 经对等会话发给 Agent
new ChannelSpec(MoShiroChannels.RawChunk, RpcSide.Node, [NodeRoles.Agent]),
new ChannelSpec(MoShiroChannels.ColumnBlock, RpcSide.Dialer),
]));
}