mirror of
https://github.com/OPCFoundation/UA-.NETStandard.git
synced 2026-10-20 08:41:51 +08:00
c781514ad5
Three changes addressing the design feedback on PR #3855: 1. Renamed Stack/Opc.Ua.Diagnostics.Pcap -> Stack/Opc.Ua.Bindings.Pcap (and the corresponding test project). PackageId, AssemblyName and RootNamespace updated to Opc.Ua.Bindings.Pcap; references in McpServer, signlists, slnx files, docs, and the interop-tester agent updated; Opc.Ua.Core's InternalsVisibleTo entries updated. 2. Replaced UaSCUaBinaryChannel.FrameCaptureSink + per-call NotifyFrameCaptureSink null check with a transport-binding decorator. New files in Opc.Ua.Bindings.Pcap/Bindings: - IChannelCaptureRegistry / ChannelCaptureRegistry: singleton with a volatile IFrameCaptureSink slot (1 atomic write to switch recording on/off). - CapturingMessageSocket / CapturingMessageSocketFactory: IMessageSocket decorator that taps Send/Receive bytes via a single volatile read of CurrentObserver. - PcapTransportChannelBinding: ITransportChannelFactory decorator that injects the capturing socket factory into every TcpTransportChannel and wires ISecureChannel.OnTokenActivated through to the active observer. - PcapBindings.Install(): non-DI installer for direct TransportBindings.Channels.SetBinding wiring. IFrameCaptureSink moved to Opc.Ua.Core/Stack/Bindings and gained an OnTokenActivated method so the binding can publish key material alongside chunks. UaSCUaBinaryChannel.FrameCaptureSink property and all three NotifyFrameCaptureSink call sites removed - hot path returns to original shape with zero indirection when the binding is not installed. IMessageSocketAsyncEventArgs gains Offset + Count getters (additive). AddOpcUaDiagnosticsPcap/Formatters/Replay extension methods renamed to AddOpcUaBindingsPcap[Formatters|Replay]; the new AddOpcUaBindingsPcap also installs the binding into TransportBindings.Channels. InProcessClientCaptureSource / InProcessServerCaptureSource: dropped reflection-based AttachClientChannel/AttachServerChannel. The source itself implements IFrameCaptureSink and on Start publishes itself as the registry observer; on Stop clears it. McpServer's PacketCaptureTools simplified accordingly (no more per-channel attach loop). 3. Discarded the source-generator suggestion. Confirmed that the dissection path already 100% reuses the source-generated decoders: UaSCUaBinaryChannel.ReadSymmetricMessage for chunk decryption and BinaryDecoder.ReadEncodeable + EncodeableFactory.GlobalFactory (populated by Tools/Opc.Ua.SourceGeneration's DataTypeGenerator) for service-type decoding. Emitting additional dissection code would duplicate what's already there. Validation: - Full UA.slnx builds clean: 0 errors, 2 pre-existing unrelated warnings. - All 53 tests pass on net10.0 (49 existing + 4 new CapturingMessageSocketTests covering hot-path: not-installed/installed-off/installed-on costs, byte equality, exception isolation). - CI command line (dotnet build/test --framework net10.0 --configuration Release /p:CustomTestTarget=net10.0) reproduces clean locally.
122 lines
4.4 KiB
C#
122 lines
4.4 KiB
C#
/* ========================================================================
|
|
* Copyright (c) 2005-2026 The OPC Foundation, Inc. All rights reserved.
|
|
*
|
|
* OPC Foundation MIT License 1.00
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person
|
|
* obtaining a copy of this software and associated documentation
|
|
* files (the "Software"), to deal in the Software without
|
|
* restriction, including without limitation the rights to use,
|
|
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
* copies of the Software, and to permit persons to whom the
|
|
* Software is furnished to do so, subject to the following
|
|
* conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be
|
|
* included in all copies or substantial portions of the Software.
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
*
|
|
* The complete license agreement can be found here:
|
|
* http://opcfoundation.org/License/MIT/1.00/
|
|
* ======================================================================*/
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Opc.Ua.Bindings.Pcap.Dissection
|
|
{
|
|
/// <summary>
|
|
/// One reassembled OPC UA service request / response observed during
|
|
/// a capture. Populated by <c>ServiceCallReassembler</c> after offline
|
|
/// decryption.
|
|
/// </summary>
|
|
public sealed class DecodedServiceCall
|
|
{
|
|
/// <summary>
|
|
/// Numeric secure-channel id this call belongs to.
|
|
/// </summary>
|
|
public uint ChannelId { get; init; }
|
|
|
|
/// <summary>
|
|
/// Token id that secured this call.
|
|
/// </summary>
|
|
public uint TokenId { get; init; }
|
|
|
|
/// <summary>
|
|
/// Request id assigned by the client.
|
|
/// </summary>
|
|
public uint RequestId { get; init; }
|
|
|
|
/// <summary>
|
|
/// Capture timestamp of the first request chunk.
|
|
/// </summary>
|
|
public DateTimeOffset RequestTimestamp { get; init; }
|
|
|
|
/// <summary>
|
|
/// Capture timestamp of the last response chunk, if observed.
|
|
/// </summary>
|
|
public DateTimeOffset? ResponseTimestamp { get; init; }
|
|
|
|
/// <summary>
|
|
/// Service name (e.g. <c>ReadRequest</c>,
|
|
/// <c>OpenSecureChannelRequest</c>). <c>null</c> when the request
|
|
/// was not decoded.
|
|
/// </summary>
|
|
public string? RequestName { get; init; }
|
|
|
|
/// <summary>
|
|
/// Service name of the response. <c>null</c> when the response was
|
|
/// not decoded.
|
|
/// </summary>
|
|
public string? ResponseName { get; init; }
|
|
|
|
/// <summary>
|
|
/// Status code reported in the response header (if available).
|
|
/// </summary>
|
|
public StatusCode? ResponseStatus { get; init; }
|
|
|
|
/// <summary>
|
|
/// Size of the request body in bytes (all chunks summed).
|
|
/// </summary>
|
|
public int RequestBodySize { get; init; }
|
|
|
|
/// <summary>
|
|
/// Size of the response body in bytes.
|
|
/// </summary>
|
|
public int ResponseBodySize { get; init; }
|
|
|
|
/// <summary>
|
|
/// Optional one-line summary of the request body (e.g.
|
|
/// "ReadRequest 3 nodes, max age 0"). Implementations should keep
|
|
/// this short - it is intended for human reading.
|
|
/// </summary>
|
|
public string? RequestSummary { get; init; }
|
|
|
|
/// <summary>
|
|
/// Optional one-line summary of the response body.
|
|
/// </summary>
|
|
public string? ResponseSummary { get; init; }
|
|
|
|
/// <summary>
|
|
/// Latency between request and response. <c>null</c> when the
|
|
/// response was not observed.
|
|
/// </summary>
|
|
public TimeSpan? Latency => ResponseTimestamp - RequestTimestamp;
|
|
|
|
/// <summary>
|
|
/// Decoded annotations (key/value) attached to the call. Used by
|
|
/// formatters that want to show extra detail without breaking the
|
|
/// model.
|
|
/// </summary>
|
|
public IReadOnlyDictionary<string, string?> Annotations { get; init; }
|
|
= new Dictionary<string, string?>();
|
|
}
|
|
}
|