feat(grpc-data): H3 ProjectedHistoryAccess over deployed connections
Resolves, authorizes (HistoryRead demand: mapping bit + local grant on the mapping scope, ACLs on or off) and pins each projected node, groups the batch per connection / details / issuing endpoint and forwards through IDataHistoryService. Remote cursors bind caller, mapping id+revision, connection route, projection generation, origin view and serving identity, and resend the ORIGINAL details; any change => BadContinuationPointInvalid with the origin token released. Shared per-request assembly budget (min mapping MaxHistoryAssemblyBytesPerRequest) => BadTooManyOperations for the remaining nodes. Releases coalesce per connection. Replaces the H2 refusal pin with the intended behaviour (granted => served, no grant => BadUserAccessDenied).
This commit is contained in:
@@ -130,7 +130,7 @@ public sealed class ProjectedDataAccess : IProjectedDataAccess, IDisposable
|
||||
if (metadata.ValueKind == DataValueKind.Timestamp && value is DateTime timestamp) value = new DateTimeOffset(timestamp.ToUniversalTime());
|
||||
return ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections.DataValue.FromScalar(metadata.ValueKind, value);
|
||||
}
|
||||
private static object? DecodeValue(ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections.DataValue value, DataMetadata metadata)
|
||||
internal static object? DecodeValue(ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections.DataValue value, DataMetadata metadata)
|
||||
{
|
||||
if (value.Kind == DataValueKind.Null) return null;
|
||||
if (value.Kind != metadata.ValueKind) throw new ArgumentException("Value kind does not match metadata.");
|
||||
@@ -154,13 +154,15 @@ public sealed class ProjectedDataAccess : IProjectedDataAccess, IDisposable
|
||||
public bool TryAcquire(NodeId nodeId, RoleCarryingUserIdentity caller, DataOperations operation, out IProjectedDemandLease? demand)
|
||||
{
|
||||
demand = null;
|
||||
if (caller is null || operation is not (DataOperations.Browse or DataOperations.Read or DataOperations.Write or DataOperations.Subscribe)) { ProjectedStreamDiagnostics.Count(ProjectedStreamDiagnostics.Event.AcquireInvalid); return false; }
|
||||
if (caller is null || operation is not (DataOperations.Browse or DataOperations.Read or DataOperations.Write or DataOperations.Subscribe or DataOperations.HistoryRead)) { ProjectedStreamDiagnostics.Count(ProjectedStreamDiagnostics.Event.AcquireInvalid); return false; }
|
||||
try
|
||||
{
|
||||
if (!_nodes.TryResolve(nodeId, out var definition) || definition is null || !definition.AuthorityIsCurrent() ||
|
||||
!_catalog.TryResolveProjected(definition.Realm, definition.LocalIdentifier, out var proof) || proof is null ||
|
||||
proof.Generation != definition.ProjectionGeneration || !MetadataMatches(proof.Metadata, definition.Metadata) ||
|
||||
((operation is DataOperations.Read or DataOperations.Subscribe) && proof.MaximumSampleAge <= TimeSpan.Zero) ||
|
||||
// H3: history only on a node projected Historizing (mapping bit AND origin HistoryInfo), whatever the caller holds.
|
||||
(operation == DataOperations.HistoryRead && (!definition.Historizing || !ProjectedHistoryAccess.Advertises(proof))) ||
|
||||
proof.Metadata.View.MappingId is not { } mapping || proof.Lease.Serving.ServingGeneration <= 0 ||
|
||||
_connectionForMapping(mapping) is not { Length: > 0 } connectionId) { ProjectedStreamDiagnostics.Count(ProjectedStreamDiagnostics.Event.AcquireDefinition); return false; }
|
||||
var identity = new DataCallerIdentity(caller.Principal, caller.ApiKeyId, caller.CredentialVersion, caller.CredentialExpiresUtc);
|
||||
@@ -213,12 +215,24 @@ public sealed class ProjectedDataAccess : IProjectedDataAccess, IDisposable
|
||||
if (lease is Demand demand) await demand.Completion.ConfigureAwait(false);
|
||||
}
|
||||
public bool HasLiveDemand(DataRealm realm, string localIdentifier) { lock (_sync) return _demandCounts.ContainsKey((realm, localIdentifier)); }
|
||||
/// <summary>H3: what a HistoryRead demand is bound to — its mapping, revision, deployed connection and the origin's metadata.</summary>
|
||||
internal bool TryDescribeHistoryDemand(IProjectedDemandLease lease, out ProjectedHistoryTarget? target)
|
||||
{
|
||||
target = null;
|
||||
if (lease is not Demand { RequestedOperation: DataOperations.HistoryRead } demand || !demand.IsValid) return false;
|
||||
var binding = demand.CurrentBinding;
|
||||
if (binding.Proof.Metadata.View.MappingId is not { } mapping) return false;
|
||||
target = new ProjectedHistoryTarget(mapping, binding.Proof.Metadata.View.MappingRevision, binding.ConnectionId,
|
||||
binding.Proof.OriginMetadata, binding.Proof.Lease.Serving, binding.Proof.Generation);
|
||||
return true;
|
||||
}
|
||||
private static OpcUaOperation Operation(DataOperations operation) => operation switch
|
||||
{
|
||||
DataOperations.Browse => OpcUaOperation.Browse,
|
||||
DataOperations.Read => OpcUaOperation.Read,
|
||||
DataOperations.Write => OpcUaOperation.WriteOperate,
|
||||
DataOperations.Subscribe => OpcUaOperation.CreateMonitoredItems,
|
||||
DataOperations.HistoryRead => OpcUaOperation.HistoryRead,
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(operation))
|
||||
};
|
||||
private sealed class Demand(ProjectedDataAccess owner, NodeId nodeId, ProjectedVariableDefinition definition,
|
||||
|
||||
Reference in New Issue
Block a user