feat: execute post-baseline jetstream parity plan
This commit is contained in:
26
src/NATS.Server/LeafNodes/LeafLoopDetector.cs
Normal file
26
src/NATS.Server/LeafNodes/LeafLoopDetector.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
namespace NATS.Server.LeafNodes;
|
||||
|
||||
public static class LeafLoopDetector
|
||||
{
|
||||
private const string LeafLoopPrefix = "$LDS.";
|
||||
|
||||
public static string Mark(string subject, string serverId)
|
||||
=> $"{LeafLoopPrefix}{serverId}.{subject}";
|
||||
|
||||
public static bool IsLooped(string subject, string localServerId)
|
||||
=> subject.StartsWith($"{LeafLoopPrefix}{localServerId}.", StringComparison.Ordinal);
|
||||
|
||||
public static bool TryUnmark(string subject, out string unmarked)
|
||||
{
|
||||
unmarked = subject;
|
||||
if (!subject.StartsWith(LeafLoopPrefix, StringComparison.Ordinal))
|
||||
return false;
|
||||
|
||||
var serverSeparator = subject.IndexOf('.', LeafLoopPrefix.Length);
|
||||
if (serverSeparator < 0 || serverSeparator == subject.Length - 1)
|
||||
return false;
|
||||
|
||||
unmarked = subject[(serverSeparator + 1)..];
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user