feat: execute full-repo remaining parity closure plan
This commit is contained in:
26
src/NATS.Server/Routes/RouteCompressionCodec.cs
Normal file
26
src/NATS.Server/Routes/RouteCompressionCodec.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System.IO.Compression;
|
||||
|
||||
namespace NATS.Server.Routes;
|
||||
|
||||
public static class RouteCompressionCodec
|
||||
{
|
||||
public static byte[] Compress(ReadOnlySpan<byte> payload)
|
||||
{
|
||||
using var output = new MemoryStream();
|
||||
using (var stream = new DeflateStream(output, CompressionLevel.Fastest, leaveOpen: true))
|
||||
{
|
||||
stream.Write(payload);
|
||||
}
|
||||
|
||||
return output.ToArray();
|
||||
}
|
||||
|
||||
public static byte[] Decompress(ReadOnlySpan<byte> payload)
|
||||
{
|
||||
using var input = new MemoryStream(payload.ToArray());
|
||||
using var stream = new DeflateStream(input, CompressionMode.Decompress);
|
||||
using var output = new MemoryStream();
|
||||
stream.CopyTo(output);
|
||||
return output.ToArray();
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using NATS.Server.Subscriptions;
|
||||
|
||||
namespace NATS.Server.Routes;
|
||||
@@ -252,6 +253,17 @@ public sealed class RouteConnection(Socket socket) : IAsyncDisposable
|
||||
=> token.Contains('.', StringComparison.Ordinal)
|
||||
|| token.Contains('*', StringComparison.Ordinal)
|
||||
|| token.Contains('>', StringComparison.Ordinal);
|
||||
|
||||
public static string BuildConnectInfoJson(string serverId, IEnumerable<string>? accounts, string? topologySnapshot)
|
||||
{
|
||||
var payload = new
|
||||
{
|
||||
server_id = serverId,
|
||||
accounts = (accounts ?? []).ToArray(),
|
||||
topology = topologySnapshot ?? string.Empty,
|
||||
};
|
||||
return JsonSerializer.Serialize(payload);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed record RouteMessage(string Subject, string? ReplyTo, ReadOnlyMemory<byte> Payload);
|
||||
|
||||
@@ -25,6 +25,14 @@ public sealed class RouteManager : IAsyncDisposable
|
||||
|
||||
public string ListenEndpoint => $"{_options.Host}:{_options.Port}";
|
||||
|
||||
public RouteTopologySnapshot BuildTopologySnapshot()
|
||||
{
|
||||
return new RouteTopologySnapshot(
|
||||
_serverId,
|
||||
_routes.Count,
|
||||
_connectedServerIds.Keys.OrderBy(static k => k, StringComparer.Ordinal).ToArray());
|
||||
}
|
||||
|
||||
public RouteManager(
|
||||
ClusterOptions options,
|
||||
ServerStats stats,
|
||||
@@ -254,3 +262,8 @@ public sealed class RouteManager : IAsyncDisposable
|
||||
|
||||
public int RouteCount => _routes.Count;
|
||||
}
|
||||
|
||||
public sealed record RouteTopologySnapshot(
|
||||
string ServerId,
|
||||
int RouteCount,
|
||||
IReadOnlyList<string> ConnectedServerIds);
|
||||
|
||||
Reference in New Issue
Block a user