feat: execute full-repo remaining parity closure plan

This commit is contained in:
Joseph Doherty
2026-02-23 13:08:52 -05:00
parent cbe1fa6121
commit 2b64d762f6
75 changed files with 2325 additions and 121 deletions

View File

@@ -0,0 +1,30 @@
namespace NATS.Server.LeafNodes;
public enum LeafMapDirection
{
Inbound,
Outbound,
}
public sealed record LeafMappingResult(string Account, string Subject);
public sealed class LeafHubSpokeMapper
{
private readonly IReadOnlyDictionary<string, string> _hubToSpoke;
private readonly IReadOnlyDictionary<string, string> _spokeToHub;
public LeafHubSpokeMapper(IReadOnlyDictionary<string, string> hubToSpoke)
{
_hubToSpoke = hubToSpoke;
_spokeToHub = hubToSpoke.ToDictionary(static p => p.Value, static p => p.Key, StringComparer.Ordinal);
}
public LeafMappingResult Map(string account, string subject, LeafMapDirection direction)
{
if (direction == LeafMapDirection.Outbound && _hubToSpoke.TryGetValue(account, out var spoke))
return new LeafMappingResult(spoke, subject);
if (direction == LeafMapDirection.Inbound && _spokeToHub.TryGetValue(account, out var hub))
return new LeafMappingResult(hub, subject);
return new LeafMappingResult(account, subject);
}
}