using System; using System.Buffers; using System.Security.Cryptography; using FrostFS.SDK.Cryptography; using Grpc.Net.Client; namespace FrostFS.SDK.ClientV2; public class ClientContext(FrostFSClient client, ECDsa? key, FrostFsOwner? owner, GrpcChannel channel, FrostFsVersion version) : IDisposable { private ArrayPool? _arrayPool; private string? sessionKey; internal FrostFsOwner? Owner { get; } = owner; internal string? Address { get; } = channel.Target; internal GrpcChannel Channel { get; private set; } = channel; internal FrostFsVersion Version { get; } = version; internal NetworkSettings? NetworkSettings { get; set; } internal FrostFSClient Client { get; } = client; internal ClientKey? Key { get; } = key != null ? new ClientKey(key) : null; internal SessionCache SessionCache { get; set; } internal string? SessionCacheKey { get { if (sessionKey == null && Key != null && Address != null) { sessionKey = Pool.FormCacheKey(Address, Key.ECDsaKey.PrivateKey().ToString()); } return sessionKey; } } /// /// Custom pool is used for predefined sizes of buffers like grpc chunk /// internal ArrayPool GetArrayPool(int size) { _arrayPool ??= ArrayPool.Create(size, 256); return _arrayPool; } public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } protected virtual void Dispose(bool disposing) { if (disposing) { Channel?.Dispose(); } } }