Files
MoShiro/backend/src/MoShiro.Backend.Gateway/GatewayServiceCollectionExtensions.cs
T
justme ad5efc62ff agent: unify listening and dialing with directed mutual measurements
Replace Probe with Agent across node runtime, Fleet contracts, backend state, API and storage. Report incoming sessions and outgoing link health through each Agent uplink, and retain directed link controls and retry.

Update protocol fixtures and end-to-end coverage for the unified model; accept requested cancellation during the Fleet timeout test cleanup.
2026-10-21 11:55:36 +08:00

47 lines
2.1 KiB
C#

using Fleet.Core;
using Fleet.Rpc;
using Fleet.Server;
using Microsoft.Extensions.DependencyInjection;
using MoShiro.Backend.Application;
using MoShiro.Protocol;
namespace MoShiro.Backend.Gateway;
public static class GatewayServiceCollectionExtensions
{
/// <summary>
/// 在 Fleet.Server 之上接入 MoShiro:期望状态(TaskSet、DialTargets)、RawChunk 收件箱、<c>moshiro.*</c> 方法、注册挂钩和节点事件。
/// 需要事先注册 <see cref="IFleetStore"/> 和 <see cref="TimeProvider"/>,并在 <c>AddMoShiroApplication</c> 之后调用。
/// </summary>
public static IServiceCollection AddMoShiroGateway(this IServiceCollection services)
{
services.AddSingleton<IAgentGateway, FleetGateway>();
services.AddHostedService<ConnectionShutdown>();
services.AddFleetEnrollment();
services.AddFleetServer(options => options.NodeIdPrefix = AgentIds.Prefix)
.AddState<TaskSetStateProvider>()
.AddState<DialTargetsStateProvider>()
.AddInbox<RawChunkInbox>()
.WithMethods(MoShiroMethodTable.Table)
.MapMethods(MapMoShiroMethods);
return services;
}
private static void MapMoShiroMethods(RpcRouter<NodeCallContext> router, IServiceProvider services)
{
router
.OnNotify(
MoShiroMethods.Event,
MoShiroJsonContext.Default.AgentEventParams,
(context, parameters, ct) => services.GetRequiredService<AgentEventService>().OnEventAsync(context.Node.Id, parameters, ct))
.OnNotify(
MoShiroMethods.Host,
MoShiroJsonContext.Default.HostSnapshot,
(context, snapshot, ct) => services.GetRequiredService<HostStatusService>().OnHostAsync(context.Node.Id, snapshot, ct))
.OnNotify(
MoShiroMethods.TestStatus,
MoShiroJsonContext.Default.TestStatusParams,
(context, parameters, ct) => services.GetRequiredService<TestService>().OnStatusAsync(context.Node.Id, parameters, ct));
}
}