feat(batch18): implement group-a server core helpers
This commit is contained in:
@@ -265,6 +265,22 @@ public sealed partial class NatsServer
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns S2 writer options for the selected route compression mode.
|
||||
/// Mirrors Go <c>s2WriterOptions</c>.
|
||||
/// </summary>
|
||||
internal static string[]? S2WriterOptions(string cm)
|
||||
{
|
||||
var opts = new List<string> { "writer_concurrency=1" };
|
||||
return cm switch
|
||||
{
|
||||
CompressionMode.S2Uncompressed => [.. opts, "writer_uncompressed"],
|
||||
CompressionMode.S2Best => [.. opts, "writer_best_compression"],
|
||||
CompressionMode.S2Better => [.. opts, "writer_better_compression"],
|
||||
_ => null,
|
||||
};
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// Factory methods (features 2983–2985)
|
||||
// =========================================================================
|
||||
@@ -509,20 +525,27 @@ public sealed partial class NatsServer
|
||||
/// Background loop that logs TLS rate-limited connection rejections every second.
|
||||
/// Mirrors Go <c>Server.logRejectedTLSConns</c>.
|
||||
/// </summary>
|
||||
internal async Task LogRejectedTlsConnsAsync(CancellationToken ct)
|
||||
internal Task LogRejectedTlsConnsAsync(CancellationToken ct) =>
|
||||
LogRejectedTLSConns(ct);
|
||||
|
||||
/// <summary>
|
||||
/// Background loop that logs TLS rate-limited connection rejections every second.
|
||||
/// Mirrors Go <c>Server.logRejectedTLSConns</c>.
|
||||
/// </summary>
|
||||
internal async Task LogRejectedTLSConns(CancellationToken ct, TimeSpan? interval = null)
|
||||
{
|
||||
using var timer = new PeriodicTimer(TimeSpan.FromSeconds(1));
|
||||
using var timer = new PeriodicTimer(interval ?? TimeSpan.FromSeconds(1));
|
||||
while (!ct.IsCancellationRequested)
|
||||
{
|
||||
try { await timer.WaitForNextTickAsync(ct); }
|
||||
catch (OperationCanceledException) { break; }
|
||||
|
||||
if (_connRateCounter is not null)
|
||||
{
|
||||
var blocked = _connRateCounter.CountBlocked();
|
||||
if (blocked > 0)
|
||||
Warnf("Rejected {0} connections due to TLS rate limiting", blocked);
|
||||
}
|
||||
|
||||
try { await timer.WaitForNextTickAsync(ct); }
|
||||
catch (OperationCanceledException) { break; }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user