ci/woodpecker/push/main-amd64-build Pipeline was successful
Methods, roles and binary channels are declared in one table per plane (node and peer). RpcRouter checks direction, kind and role when handlers are registered, when messages arrive (fleet_protocol_violation, disconnect after repeated violations) and before sending. NodeConnection is split by responsibility.
56 lines
2.9 KiB
C#
56 lines
2.9 KiB
C#
using Fleet.Rpc;
|
|
|
|
namespace MoShiro.Protocol;
|
|
|
|
/// <summary>节点的角色。服务端按节点 ID 的前缀判断;声明表用它限定哪些角色可以参与某个方法或通道。</summary>
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 所有方法和二进制通道的方向声明,单一真源(框架的 <c>fleet.*</c> 见 <see cref="FleetMethodTable"/>)。
|
|
/// 新增一个方法:在 <see cref="MoShiroMethods"/> 里加名字和参数,在这里加一行声明,再在对应一侧注册处理函数;
|
|
/// 声明了但没人处理、或者处理了但没声明,都会被测试和启动时的检查发现。
|
|
/// 同一个方法名只有一个发起方;节点面是服务端和节点(B 和 A、P),对等面是 Probe(拨号方)和 Agent(监听方)。
|
|
/// </summary>
|
|
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.UpdateOffer, RpcSide.Server),
|
|
MethodSpec.Notification(MoShiroMethods.UpdateApply, RpcSide.Server),
|
|
MethodSpec.Notification(MoShiroMethods.Schedule, RpcSide.Server),
|
|
|
|
// 节点面:Agent → Backend
|
|
MethodSpec.Notification(MoShiroMethods.TestStatus, RpcSide.Node, NodeRoles.Agent),
|
|
MethodSpec.Notification(MoShiroMethods.Event, RpcSide.Node, NodeRoles.Agent),
|
|
MethodSpec.Notification(MoShiroMethods.Host, RpcSide.Node, NodeRoles.Agent),
|
|
|
|
// 对等面: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),
|
|
]));
|
|
}
|