feat(grpc-data): X0 server parses x-otopcua-data-features on every RPC and records requested/effective (effective always empty)

This commit is contained in:
Joseph Doherty
2026-11-23 17:16:24 -05:00
parent 984b1e122a
commit 331350e2f4
2 changed files with 66 additions and 1 deletions
@@ -16,6 +16,29 @@ public sealed class DataConnectionGrpcService(IDataConnectionFactory factory, IO
{
private readonly DataConnectionOptions _options = options.Value;
/// <summary>
/// The optional features this server honours on a call that requests them. X0 reserves the negotiation and
/// supports nothing, so every call's effective set is empty and every RPC keeps its v1 behaviour.
/// </summary>
internal static DataFeatures SupportedFeatures => DataFeatures.None;
/// <summary>The feature set recorded for this call by <see cref="NegotiateFeatures"/> (v1 when absent).</summary>
internal static DataCallFeatures CallFeatures(ServerCallContext context) =>
context.UserState.TryGetValue(typeof(DataCallFeatures), out var value) && value is DataCallFeatures features
? features : DataCallFeatures.None;
/// <summary>
/// Parses <see cref="DataConnectionProtoContract.FeaturesHeader"/> on every RPC (after authentication) and records
/// requested ∩ supported. A binary or oversized value is an <see cref="ArgumentException"/> ⇒ InvalidArgument.
/// </summary>
private static DataCallFeatures NegotiateFeatures(ServerCallContext context)
{
var requested = DataFeatureHeader.Parse(context.RequestHeaders);
var features = requested == DataFeatures.None ? DataCallFeatures.None : new DataCallFeatures(requested, requested & SupportedFeatures);
context.UserState[typeof(DataCallFeatures)] = features;
return features;
}
public override Task<W.CapabilitiesResponse> GetCapabilities(W.CapabilitiesRequest request, ServerCallContext context) =>
Execute(context, async (connection, caller, token) =>
{
@@ -133,6 +156,7 @@ public sealed class DataConnectionGrpcService(IDataConnectionFactory factory, IO
context.WriteOptions = new(WriteFlags.NoCompress);
responses.WriteOptions = new(WriteFlags.NoCompress);
var (caller, target) = AuthenticateCall(context);
NegotiateFeatures(context);
await using var connection = factory.Create(caller, target);
DataCapabilities caps;
IDataSubscription subscription;
@@ -254,6 +278,7 @@ public sealed class DataConnectionGrpcService(IDataConnectionFactory factory, IO
context.WriteOptions = new(WriteFlags.NoCompress);
var http = context.GetHttpContext();
var (caller, target) = AuthenticateCall(context);
NegotiateFeatures(context);
if (!http.Items.ContainsKey(typeof(DataConnectionUnaryLifetime)))
http.Items[typeof(DataConnectionUnaryLifetime)] = new DataConnectionUnaryLifetime(TimeProvider.System, _options.UnaryTimeout);
var timeout = new CancellationTokenSource(_options.UnaryTimeout);