[#26] All: Remove V2 from naming
Rename project, namespaces and class names Signed-off-by: Pavel Gross <p.gross@yadro.com>
This commit is contained in:
parent
c406df1a78
commit
766f61a5f7
219 changed files with 219 additions and 974 deletions
62
src/FrostFS.SDK.Client/Models/Chain/ChainTarget.cs
Normal file
62
src/FrostFS.SDK.Client/Models/Chain/ChainTarget.cs
Normal file
|
@ -0,0 +1,62 @@
|
|||
using System;
|
||||
|
||||
using Frostfs.V2.Ape;
|
||||
|
||||
namespace FrostFS.SDK.Client;
|
||||
|
||||
public struct FrostFsChainTarget(FrostFsTargetType type, string name) : IEquatable<FrostFsChainTarget>
|
||||
{
|
||||
private ChainTarget? chainTarget;
|
||||
|
||||
public FrostFsTargetType Type { get; } = type;
|
||||
|
||||
public string Name { get; } = name;
|
||||
|
||||
internal ChainTarget GetChainTarget()
|
||||
{
|
||||
return chainTarget ??= new ChainTarget
|
||||
{
|
||||
Type = GetTargetType(Type),
|
||||
Name = Name
|
||||
};
|
||||
}
|
||||
|
||||
private static TargetType GetTargetType(FrostFsTargetType type)
|
||||
{
|
||||
return type switch
|
||||
{
|
||||
FrostFsTargetType.Undefined => TargetType.Undefined,
|
||||
FrostFsTargetType.Namespace => TargetType.Namespace,
|
||||
FrostFsTargetType.Container => TargetType.Container,
|
||||
FrostFsTargetType.User => TargetType.User,
|
||||
FrostFsTargetType.Group => TargetType.Group,
|
||||
_ => throw new ArgumentException("Unexpected value for TargetType", nameof(type)),
|
||||
};
|
||||
}
|
||||
|
||||
public override readonly bool Equals(object obj)
|
||||
{
|
||||
var target = (FrostFsChainTarget)obj;
|
||||
return Equals(target);
|
||||
}
|
||||
|
||||
public override readonly int GetHashCode()
|
||||
{
|
||||
return $"{Name}{Type}".GetHashCode();
|
||||
}
|
||||
|
||||
public static bool operator ==(FrostFsChainTarget left, FrostFsChainTarget right)
|
||||
{
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
public static bool operator !=(FrostFsChainTarget left, FrostFsChainTarget right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
|
||||
public readonly bool Equals(FrostFsChainTarget other)
|
||||
{
|
||||
return Type == other.Type && Name.Equals(other.Name, StringComparison.Ordinal);
|
||||
}
|
||||
}
|
41
src/FrostFS.SDK.Client/Models/Chain/FrostFsChain.cs
Normal file
41
src/FrostFS.SDK.Client/Models/Chain/FrostFsChain.cs
Normal file
|
@ -0,0 +1,41 @@
|
|||
using Google.Protobuf;
|
||||
|
||||
namespace FrostFS.SDK.Client;
|
||||
|
||||
public struct FrostFsChain(byte[] raw) : System.IEquatable<FrostFsChain>
|
||||
{
|
||||
private ByteString? grpcRaw;
|
||||
|
||||
public byte[] Raw { get; } = raw;
|
||||
|
||||
internal ByteString GetRaw()
|
||||
{
|
||||
return grpcRaw ??= ByteString.CopyFrom(Raw);
|
||||
}
|
||||
|
||||
public override readonly bool Equals(object obj)
|
||||
{
|
||||
var chain = (FrostFsChain)obj;
|
||||
return Equals(chain);
|
||||
}
|
||||
|
||||
public override readonly int GetHashCode()
|
||||
{
|
||||
return Raw.GetHashCode();
|
||||
}
|
||||
|
||||
public static bool operator ==(FrostFsChain left, FrostFsChain right)
|
||||
{
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
public static bool operator !=(FrostFsChain left, FrostFsChain right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
|
||||
public readonly bool Equals(FrostFsChain other)
|
||||
{
|
||||
return Raw == other.Raw;
|
||||
}
|
||||
}
|
10
src/FrostFS.SDK.Client/Models/Chain/FrostFsTargetType.cs
Normal file
10
src/FrostFS.SDK.Client/Models/Chain/FrostFsTargetType.cs
Normal file
|
@ -0,0 +1,10 @@
|
|||
namespace FrostFS.SDK.Client;
|
||||
|
||||
public enum FrostFsTargetType
|
||||
{
|
||||
Undefined = 0,
|
||||
Namespace,
|
||||
Container,
|
||||
User,
|
||||
Group
|
||||
}
|
70
src/FrostFS.SDK.Client/Models/Client/ClientSettings.cs
Normal file
70
src/FrostFS.SDK.Client/Models/Client/ClientSettings.cs
Normal file
|
@ -0,0 +1,70 @@
|
|||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
|
||||
namespace FrostFS.SDK;
|
||||
|
||||
public class ClientSettings
|
||||
{
|
||||
protected static readonly string errorTemplate = "{0} is required parameter";
|
||||
|
||||
public string Host { get; set; } = string.Empty;
|
||||
|
||||
public virtual void Validate()
|
||||
{
|
||||
var errors = CheckFields();
|
||||
if (errors != null)
|
||||
ThrowSettingsException(errors);
|
||||
}
|
||||
|
||||
protected Collection<string>? CheckFields()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(Host))
|
||||
{
|
||||
var error = string.Format(CultureInfo.InvariantCulture, errorTemplate, nameof(Host));
|
||||
return new Collection<string>([error]);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected static void ThrowSettingsException(Collection<string> errors)
|
||||
{
|
||||
if (errors is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(errors));
|
||||
}
|
||||
|
||||
StringBuilder messages = new();
|
||||
|
||||
foreach (var error in errors)
|
||||
{
|
||||
messages.AppendLine(error);
|
||||
}
|
||||
|
||||
throw new ArgumentException(messages.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public class SingleOwnerClientSettings : ClientSettings
|
||||
{
|
||||
public string Key { get; set; } = string.Empty;
|
||||
|
||||
public override void Validate()
|
||||
{
|
||||
var errors = CheckFields();
|
||||
if (errors != null)
|
||||
ThrowSettingsException(errors);
|
||||
}
|
||||
|
||||
protected new Collection<string>? CheckFields()
|
||||
{
|
||||
Collection<string>? errors = base.CheckFields();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(Key))
|
||||
(errors ??= []).Add(string.Format(CultureInfo.InvariantCulture, errorTemplate, nameof(Key)));
|
||||
|
||||
return errors;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
using FrostFS.Refs;
|
||||
using FrostFS.SDK.Client;
|
||||
using FrostFS.SDK.Client.Mappers.GRPC;
|
||||
using FrostFS.SDK.Cryptography;
|
||||
|
||||
namespace FrostFS.SDK;
|
||||
|
||||
public class FrostFsContainerId
|
||||
{
|
||||
private string? modelId;
|
||||
private ContainerID? containerID;
|
||||
|
||||
public FrostFsContainerId(string id)
|
||||
{
|
||||
this.modelId = id;
|
||||
}
|
||||
|
||||
internal FrostFsContainerId(ContainerID id)
|
||||
{
|
||||
this.containerID = id;
|
||||
}
|
||||
|
||||
public string GetValue()
|
||||
{
|
||||
if (this.modelId != null)
|
||||
return this.modelId;
|
||||
|
||||
if (containerID != null)
|
||||
{
|
||||
this.modelId = Base58.Encode(containerID.Value.ToByteArray());
|
||||
return this.modelId;
|
||||
}
|
||||
|
||||
throw new FrostFsInvalidObjectException();
|
||||
}
|
||||
|
||||
internal ContainerID ContainerID
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.containerID != null)
|
||||
return this.containerID;
|
||||
|
||||
if (modelId != null)
|
||||
{
|
||||
this.containerID = this.ToMessage();
|
||||
return this.containerID;
|
||||
}
|
||||
|
||||
throw new FrostFsInvalidObjectException();
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return GetValue();
|
||||
}
|
||||
}
|
109
src/FrostFS.SDK.Client/Models/Containers/FrostFsContainerInfo.cs
Normal file
109
src/FrostFS.SDK.Client/Models/Containers/FrostFsContainerInfo.cs
Normal file
|
@ -0,0 +1,109 @@
|
|||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
|
||||
using FrostFS.SDK.Client;
|
||||
using FrostFS.SDK.Client.Mappers.GRPC;
|
||||
using FrostFS.SDK.Cryptography;
|
||||
|
||||
using Google.Protobuf;
|
||||
|
||||
namespace FrostFS.SDK;
|
||||
|
||||
public class FrostFsContainerInfo
|
||||
{
|
||||
private Container.Container.Types.Attribute[]? grpsAttributes;
|
||||
private ReadOnlyCollection<FrostFsAttributePair>? attributes;
|
||||
private FrostFsPlacementPolicy? placementPolicy;
|
||||
private Guid? nonce;
|
||||
|
||||
private Container.Container? container;
|
||||
|
||||
public FrostFsContainerInfo(
|
||||
FrostFsPlacementPolicy placementPolicy,
|
||||
FrostFsAttributePair[]? attributes = null,
|
||||
FrostFsVersion? version = null,
|
||||
FrostFsOwner? owner = null,
|
||||
Guid? nonce = null)
|
||||
{
|
||||
this.placementPolicy = placementPolicy;
|
||||
Version = version;
|
||||
Owner = owner;
|
||||
this.nonce = nonce;
|
||||
|
||||
if (attributes != null)
|
||||
this.attributes = new ReadOnlyCollection<FrostFsAttributePair>(attributes);
|
||||
}
|
||||
|
||||
internal FrostFsContainerInfo(Container.Container container)
|
||||
{
|
||||
this.container = container;
|
||||
}
|
||||
|
||||
public Guid Nonce
|
||||
{
|
||||
get
|
||||
{
|
||||
nonce ??= container?.Nonce != null ? container.Nonce.ToUuid() : Guid.NewGuid();
|
||||
return nonce.Value;
|
||||
}
|
||||
}
|
||||
|
||||
public FrostFsPlacementPolicy? PlacementPolicy
|
||||
{
|
||||
get
|
||||
{
|
||||
placementPolicy ??= container?.PlacementPolicy?.ToModel();
|
||||
return placementPolicy;
|
||||
}
|
||||
}
|
||||
|
||||
public ReadOnlyCollection<FrostFsAttributePair>? Attributes
|
||||
{
|
||||
get
|
||||
{
|
||||
if (attributes == null && grpsAttributes != null)
|
||||
attributes = new ReadOnlyCollection<FrostFsAttributePair>(grpsAttributes.Select(a => new FrostFsAttributePair(a.Key, a.Value)).ToList());
|
||||
|
||||
return attributes;
|
||||
}
|
||||
}
|
||||
|
||||
public FrostFsVersion? Version { get; private set; }
|
||||
|
||||
public FrostFsOwner? Owner { get; private set; }
|
||||
|
||||
internal Container.Container.Types.Attribute[]? GetGrpsAttributes()
|
||||
{
|
||||
grpsAttributes ??= Attributes?
|
||||
.Select(a => new Container.Container.Types.Attribute { Key = a.Key, Value = a.Value })
|
||||
.ToArray();
|
||||
|
||||
return grpsAttributes;
|
||||
}
|
||||
|
||||
internal Container.Container GetContainer()
|
||||
{
|
||||
if (this.container == null)
|
||||
{
|
||||
if (PlacementPolicy == null)
|
||||
{
|
||||
throw new ArgumentNullException("PlacementPolicy is null");
|
||||
}
|
||||
|
||||
this.container = new Container.Container()
|
||||
{
|
||||
PlacementPolicy = PlacementPolicy.Value.GetPolicy(),
|
||||
Nonce = ByteString.CopyFrom(Nonce.ToBytes()),
|
||||
OwnerId = Owner?.OwnerID,
|
||||
Version = Version?.Version
|
||||
};
|
||||
|
||||
var attribs = GetGrpsAttributes();
|
||||
if (attribs != null)
|
||||
this.container.Attributes.AddRange(attribs);
|
||||
}
|
||||
|
||||
return this.container;
|
||||
}
|
||||
}
|
10
src/FrostFS.SDK.Client/Models/Enums/FrostFsMatchType.cs
Normal file
10
src/FrostFS.SDK.Client/Models/Enums/FrostFsMatchType.cs
Normal file
|
@ -0,0 +1,10 @@
|
|||
namespace FrostFS.SDK;
|
||||
|
||||
public enum FrostFsMatchType
|
||||
{
|
||||
Unspecified = 0,
|
||||
Equals = 1,
|
||||
NotEquals = 2,
|
||||
KeyAbsent = 3,
|
||||
StartsWith = 4
|
||||
}
|
8
src/FrostFS.SDK.Client/Models/Enums/FrostFsObjectType.cs
Normal file
8
src/FrostFS.SDK.Client/Models/Enums/FrostFsObjectType.cs
Normal file
|
@ -0,0 +1,8 @@
|
|||
namespace FrostFS.SDK;
|
||||
|
||||
public enum FrostFsObjectType
|
||||
{
|
||||
Regular = 0,
|
||||
Tombstone = 1,
|
||||
Lock = 3
|
||||
}
|
22
src/FrostFS.SDK.Client/Models/Enums/FrostFsStatusCode.cs
Normal file
22
src/FrostFS.SDK.Client/Models/Enums/FrostFsStatusCode.cs
Normal file
|
@ -0,0 +1,22 @@
|
|||
namespace FrostFS.SDK;
|
||||
|
||||
public enum FrostFsStatusCode
|
||||
{
|
||||
Success = 0,
|
||||
Internal = 1024,
|
||||
WrongMagicNumber = 1025,
|
||||
SignatureVerificationFailure = 1026,
|
||||
NodeUnderMaintenance = 1027,
|
||||
ObjectAccessDenied = 2048,
|
||||
ObjectNotFound = 2049,
|
||||
ObjectLocked = 2050,
|
||||
LockNotRegularObject = 2051,
|
||||
ObjectAlreadyRemoved = 2052,
|
||||
OutOfRange = 2053,
|
||||
ContainerNotFound = 3072,
|
||||
EAclNotFound = 3073,
|
||||
ContainerAccessDenied = 3074,
|
||||
TokenNotFound = 4096,
|
||||
TokenExpired = 4097,
|
||||
ApeManagerAccessDenied = 5120
|
||||
}
|
9
src/FrostFS.SDK.Client/Models/Enums/NodeState.cs
Normal file
9
src/FrostFS.SDK.Client/Models/Enums/NodeState.cs
Normal file
|
@ -0,0 +1,9 @@
|
|||
namespace FrostFS.SDK;
|
||||
|
||||
public enum NodeState
|
||||
{
|
||||
Unspecified = 0,
|
||||
Online = 1,
|
||||
Offline = 2,
|
||||
Maintenance = 3
|
||||
}
|
8
src/FrostFS.SDK.Client/Models/Enums/SignatureScheme.cs
Normal file
8
src/FrostFS.SDK.Client/Models/Enums/SignatureScheme.cs
Normal file
|
@ -0,0 +1,8 @@
|
|||
namespace FrostFS.SDK;
|
||||
|
||||
public enum SignatureScheme
|
||||
{
|
||||
EcdsaSha512,
|
||||
EcdsaRfc6979Sha256,
|
||||
EcdsaRfc6979Sha256WalletConnect
|
||||
}
|
7
src/FrostFS.SDK.Client/Models/Misc/CallStatistics.cs
Normal file
7
src/FrostFS.SDK.Client/Models/Misc/CallStatistics.cs
Normal file
|
@ -0,0 +1,7 @@
|
|||
namespace FrostFS.SDK;
|
||||
|
||||
public class CallStatistics
|
||||
{
|
||||
public string? MethodName { get; set; }
|
||||
public long ElapsedMicroSeconds { get; set; }
|
||||
}
|
21
src/FrostFS.SDK.Client/Models/Misc/CheckSum.cs
Normal file
21
src/FrostFS.SDK.Client/Models/Misc/CheckSum.cs
Normal file
|
@ -0,0 +1,21 @@
|
|||
using System;
|
||||
|
||||
using FrostFS.SDK.Cryptography;
|
||||
|
||||
namespace FrostFS.SDK;
|
||||
|
||||
public class CheckSum
|
||||
{
|
||||
private byte[]? hash;
|
||||
private string? text;
|
||||
|
||||
public static CheckSum CreateCheckSum(byte[] content)
|
||||
{
|
||||
return new CheckSum { hash = content.Sha256() };
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return text ??= BitConverter.ToString(hash).Replace("-", "");
|
||||
}
|
||||
}
|
52
src/FrostFS.SDK.Client/Models/Misc/Constants.cs
Normal file
52
src/FrostFS.SDK.Client/Models/Misc/Constants.cs
Normal file
|
@ -0,0 +1,52 @@
|
|||
namespace FrostFS.SDK;
|
||||
|
||||
public static class Constants
|
||||
{
|
||||
public const int ObjectChunkSize = 3 * (1 << 20);
|
||||
public const int Sha256HashLength = 32;
|
||||
|
||||
// HeaderPrefix is a prefix of key to object header value or property.
|
||||
public const string HeaderPrefix = "$Object:";
|
||||
|
||||
// FilterHeaderVersion is a filter key to "version" field of the object header.
|
||||
public const string FilterHeaderVersion = HeaderPrefix + "version";
|
||||
|
||||
// FilterHeaderObjectID is a filter key to "object_id" field of the object.
|
||||
public const string FilterHeaderObjectID = HeaderPrefix + "objectID";
|
||||
|
||||
// FilterHeaderContainerID is a filter key to "container_id" field of the object header.
|
||||
public const string FilterHeaderContainerID = HeaderPrefix + "containerID";
|
||||
|
||||
// FilterHeaderOwnerID is a filter key to "owner_id" field of the object header.
|
||||
public const string FilterHeaderOwnerID = HeaderPrefix + "ownerID";
|
||||
|
||||
// FilterHeaderCreationEpoch is a filter key to "creation_epoch" field of the object header.
|
||||
public const string FilterHeaderCreationEpoch = HeaderPrefix + "creationEpoch";
|
||||
|
||||
// FilterHeaderPayloadLength is a filter key to "payload_length" field of the object header.
|
||||
public const string FilterHeaderPayloadLength = HeaderPrefix + "payloadLength";
|
||||
|
||||
// FilterHeaderPayloadHash is a filter key to "payload_hash" field of the object header.
|
||||
public const string FilterHeaderPayloadHash = HeaderPrefix + "payloadHash";
|
||||
|
||||
// FilterHeaderObjectType is a filter key to "object_type" field of the object header.
|
||||
public const string FilterHeaderObjectType = HeaderPrefix + "objectType";
|
||||
|
||||
// FilterHeaderHomomorphicHash is a filter key to "homomorphic_hash" field of the object header.
|
||||
public const string FilterHeaderHomomorphicHash = HeaderPrefix + "homomorphicHash";
|
||||
|
||||
// FilterHeaderParent is a filter key to "split.parent" field of the object header.
|
||||
public const string FilterHeaderParent = HeaderPrefix + "split.parent";
|
||||
|
||||
// FilterHeaderSplitID is a filter key to "split.splitID" field of the object header.
|
||||
public const string FilterHeaderSplitID = HeaderPrefix + "split.splitID";
|
||||
|
||||
// FilterHeaderECParent is a filter key to "ec.parent" field of the object header.
|
||||
public const string FilterHeaderECParent = HeaderPrefix + "ec.parent";
|
||||
|
||||
// FilterPropertyRoot is a filter key to check if regular object is on top of split hierarchy.
|
||||
public const string FilterHeaderRoot = HeaderPrefix + "ROOT";
|
||||
|
||||
// FilterPropertyPhy is a filter key to check if an object physically stored on a node.
|
||||
public const string FilterHeaderPhy = HeaderPrefix + "PHY";
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace FrostFS.SDK;
|
||||
|
||||
public class FrostFsNetmapSnapshot(ulong epoch, IReadOnlyList<FrostFsNodeInfo> nodeInfoCollection)
|
||||
{
|
||||
public ulong Epoch { get; private set; } = epoch;
|
||||
|
||||
public IReadOnlyList<FrostFsNodeInfo> NodeInfoCollection { get; private set; } = nodeInfoCollection;
|
||||
}
|
18
src/FrostFS.SDK.Client/Models/Netmap/FrostFsNodeInfo.cs
Normal file
18
src/FrostFS.SDK.Client/Models/Netmap/FrostFsNodeInfo.cs
Normal file
|
@ -0,0 +1,18 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace FrostFS.SDK;
|
||||
|
||||
public class FrostFsNodeInfo(
|
||||
FrostFsVersion version,
|
||||
NodeState state,
|
||||
IReadOnlyCollection<string> addresses,
|
||||
IReadOnlyDictionary<string, string> attributes,
|
||||
ReadOnlyMemory<byte> publicKey)
|
||||
{
|
||||
public NodeState State { get; private set; } = state;
|
||||
public FrostFsVersion Version { get; private set; } = version;
|
||||
public IReadOnlyCollection<string> Addresses { get; private set; } = addresses;
|
||||
public IReadOnlyDictionary<string, string> Attributes { get; private set; } = attributes;
|
||||
public ReadOnlyMemory<byte> PublicKey { get; private set; } = publicKey;
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
using FrostFS.Netmap;
|
||||
using FrostFS.SDK.Client;
|
||||
|
||||
namespace FrostFS.SDK;
|
||||
|
||||
public struct FrostFsPlacementPolicy(bool unique, params FrostFsReplica[] replicas)
|
||||
: IEquatable<FrostFsPlacementPolicy>
|
||||
{
|
||||
private PlacementPolicy policy;
|
||||
|
||||
public FrostFsReplica[] Replicas { get; private set; } = replicas;
|
||||
public bool Unique { get; private set; } = unique;
|
||||
|
||||
public override readonly bool Equals(object obj)
|
||||
{
|
||||
if (obj is null)
|
||||
return false;
|
||||
|
||||
var other = (FrostFsPlacementPolicy)obj;
|
||||
|
||||
return Equals(other);
|
||||
}
|
||||
|
||||
public PlacementPolicy GetPolicy()
|
||||
{
|
||||
if (policy == null)
|
||||
{
|
||||
policy = new PlacementPolicy
|
||||
{
|
||||
Filters = { },
|
||||
Selectors = { },
|
||||
Replicas = { },
|
||||
Unique = Unique
|
||||
};
|
||||
|
||||
foreach (var replica in Replicas)
|
||||
{
|
||||
policy.Replicas.Add(replica.ToMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return policy;
|
||||
}
|
||||
|
||||
//public static FrostFsPlacementPolicy ToModel(placementPolicy)
|
||||
//{
|
||||
// return new FrostFsPlacementPolicy(
|
||||
// placementPolicy.Unique,
|
||||
// placementPolicy.Replicas.Select(replica => replica.ToModel()).ToArray()
|
||||
// );
|
||||
//}
|
||||
|
||||
|
||||
public override readonly int GetHashCode()
|
||||
{
|
||||
return Unique ? 17 : 0 + Replicas.GetHashCode();
|
||||
}
|
||||
|
||||
public static bool operator ==(FrostFsPlacementPolicy left, FrostFsPlacementPolicy right)
|
||||
{
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
public static bool operator !=(FrostFsPlacementPolicy left, FrostFsPlacementPolicy right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
|
||||
public readonly bool Equals(FrostFsPlacementPolicy other)
|
||||
{
|
||||
var notEqual = Unique != other.Unique
|
||||
|| Replicas.Length != other.Replicas.Length;
|
||||
|
||||
if (notEqual)
|
||||
return false;
|
||||
|
||||
foreach (var replica in Replicas)
|
||||
{
|
||||
if (!other.Replicas.Any(r => r.Equals(replica)))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
47
src/FrostFS.SDK.Client/Models/Netmap/FrostFsReplica.cs
Normal file
47
src/FrostFS.SDK.Client/Models/Netmap/FrostFsReplica.cs
Normal file
|
@ -0,0 +1,47 @@
|
|||
using System;
|
||||
|
||||
namespace FrostFS.SDK;
|
||||
|
||||
public struct FrostFsReplica : IEquatable<FrostFsReplica>
|
||||
{
|
||||
public int Count { get; set; }
|
||||
public string Selector { get; set; }
|
||||
|
||||
public FrostFsReplica(int count, string? selector = null)
|
||||
{
|
||||
selector ??= string.Empty;
|
||||
|
||||
Count = count;
|
||||
Selector = selector;
|
||||
}
|
||||
|
||||
public override readonly bool Equals(object obj)
|
||||
{
|
||||
if (obj is null)
|
||||
return false;
|
||||
|
||||
var other = (FrostFsReplica)obj;
|
||||
|
||||
return Count == other.Count && Selector == other.Selector;
|
||||
}
|
||||
|
||||
public override readonly int GetHashCode()
|
||||
{
|
||||
return Count + Selector.GetHashCode();
|
||||
}
|
||||
|
||||
public static bool operator ==(FrostFsReplica left, FrostFsReplica right)
|
||||
{
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
public static bool operator !=(FrostFsReplica left, FrostFsReplica right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
|
||||
public readonly bool Equals(FrostFsReplica other)
|
||||
{
|
||||
return Count == other.Count && Selector == other.Selector;
|
||||
}
|
||||
}
|
36
src/FrostFS.SDK.Client/Models/Netmap/FrostFsVersion.cs
Normal file
36
src/FrostFS.SDK.Client/Models/Netmap/FrostFsVersion.cs
Normal file
|
@ -0,0 +1,36 @@
|
|||
using FrostFS.Refs;
|
||||
using FrostFS.SDK.Client.Mappers.GRPC;
|
||||
|
||||
namespace FrostFS.SDK;
|
||||
|
||||
public class FrostFsVersion(int major, int minor)
|
||||
{
|
||||
private Version? version;
|
||||
|
||||
public int Major { get; set; } = major;
|
||||
public int Minor { get; set; } = minor;
|
||||
|
||||
internal Version Version
|
||||
{
|
||||
get
|
||||
{
|
||||
this.version ??= this.ToMessage();
|
||||
return this.version;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsSupported(FrostFsVersion version)
|
||||
{
|
||||
if (version is null)
|
||||
{
|
||||
throw new System.ArgumentNullException(nameof(version));
|
||||
}
|
||||
|
||||
return Major == version.Major;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"v{Major}.{Minor}";
|
||||
}
|
||||
}
|
48
src/FrostFS.SDK.Client/Models/Object/FrostFsAddress.cs
Normal file
48
src/FrostFS.SDK.Client/Models/Object/FrostFsAddress.cs
Normal file
|
@ -0,0 +1,48 @@
|
|||
using FrostFS.Refs;
|
||||
using FrostFS.SDK.Client.Mappers.GRPC;
|
||||
|
||||
namespace FrostFS.SDK;
|
||||
|
||||
public class FrostFsAddress
|
||||
{
|
||||
private FrostFsObjectId? frostFsObjectId;
|
||||
private FrostFsContainerId? frostFsContainerId;
|
||||
private ObjectID? objectId;
|
||||
private ContainerID? containerId;
|
||||
|
||||
public FrostFsAddress(FrostFsContainerId frostFsContainerId, FrostFsObjectId frostFsObjectId)
|
||||
{
|
||||
FrostFsObjectId = frostFsObjectId ?? throw new System.ArgumentNullException(nameof(frostFsObjectId));
|
||||
FrostFsContainerId = frostFsContainerId ?? throw new System.ArgumentNullException(nameof(frostFsContainerId));
|
||||
}
|
||||
|
||||
internal FrostFsAddress(ObjectID objectId, ContainerID containerId)
|
||||
{
|
||||
ObjectId = objectId ?? throw new System.ArgumentNullException(nameof(objectId));
|
||||
ContainerId = containerId ?? throw new System.ArgumentNullException(nameof(containerId));
|
||||
}
|
||||
|
||||
public FrostFsObjectId FrostFsObjectId
|
||||
{
|
||||
get => frostFsObjectId ??= objectId!.ToModel();
|
||||
set => frostFsObjectId = value;
|
||||
}
|
||||
|
||||
public FrostFsContainerId FrostFsContainerId
|
||||
{
|
||||
get => frostFsContainerId ??= containerId!.ToModel();
|
||||
set => frostFsContainerId = value;
|
||||
}
|
||||
|
||||
public ObjectID ObjectId
|
||||
{
|
||||
get => objectId ??= frostFsObjectId!.ToMessage();
|
||||
set => objectId = value;
|
||||
}
|
||||
|
||||
public ContainerID ContainerId
|
||||
{
|
||||
get => containerId ??= frostFsContainerId!.ToMessage();
|
||||
set => containerId = value;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
namespace FrostFS.SDK;
|
||||
|
||||
public class FrostFsAttributePair(string key, string value)
|
||||
{
|
||||
public string Key { get; set; } = key;
|
||||
|
||||
public string Value { get; set; } = value;
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
namespace FrostFS.SDK;
|
||||
|
||||
public class FrostFsLargeObject(FrostFsContainerId container) : FrostFsObject(container)
|
||||
{
|
||||
public ulong PayloadLength
|
||||
{
|
||||
get { return Header!.PayloadLength; }
|
||||
}
|
||||
}
|
21
src/FrostFS.SDK.Client/Models/Object/FrostFsLinkObject.cs
Normal file
21
src/FrostFS.SDK.Client/Models/Object/FrostFsLinkObject.cs
Normal file
|
@ -0,0 +1,21 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace FrostFS.SDK;
|
||||
|
||||
public class FrostFsLinkObject : FrostFsObject
|
||||
{
|
||||
public FrostFsLinkObject(FrostFsContainerId containerId,
|
||||
SplitId splitId,
|
||||
FrostFsObjectHeader largeObjectHeader,
|
||||
IList<FrostFsObjectId> children)
|
||||
: base(containerId)
|
||||
{
|
||||
Header!.Split = new FrostFsSplit(splitId,
|
||||
null,
|
||||
null,
|
||||
largeObjectHeader,
|
||||
null,
|
||||
new ReadOnlyCollection<FrostFsObjectId>(children));
|
||||
}
|
||||
}
|
74
src/FrostFS.SDK.Client/Models/Object/FrostFsObject.cs
Normal file
74
src/FrostFS.SDK.Client/Models/Object/FrostFsObject.cs
Normal file
|
@ -0,0 +1,74 @@
|
|||
using System;
|
||||
|
||||
namespace FrostFS.SDK;
|
||||
|
||||
public class FrostFsObject
|
||||
{
|
||||
private byte[]? bytes;
|
||||
|
||||
/// <summary>
|
||||
/// Creates new instance from <c>ObjectHeader</c>
|
||||
/// </summary>
|
||||
/// <param name="header"></param> <summary>
|
||||
public FrostFsObject(FrostFsObjectHeader header)
|
||||
{
|
||||
Header = header;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates new instance with specified parameters
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
/// <param name="objectType"></param>
|
||||
public FrostFsObject(FrostFsContainerId container, FrostFsObjectType objectType = FrostFsObjectType.Regular)
|
||||
{
|
||||
Header = new FrostFsObjectHeader(containerId: container, type: objectType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Header contains metadata for the object
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public FrostFsObjectHeader Header { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The value is calculated internally as a hash of ObjectHeader. Do not use pre-calculated value is the object has been changed.
|
||||
/// </summary>
|
||||
public FrostFsObjectId? ObjectId
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A payload is obtained via stream reader
|
||||
/// </summary>
|
||||
/// <value>Reader for received data</value>
|
||||
public IObjectReader? ObjectReader { get; set; }
|
||||
|
||||
internal byte[] SingleObjectPayload
|
||||
{
|
||||
get { return bytes ?? []; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The size of payload cannot exceed <c>MaxObjectSize</c> value from <c>NetworkSettings</c>
|
||||
/// Used only for PutSingleObject method
|
||||
/// </summary>
|
||||
/// <value>Buffer for output data</value>
|
||||
public void SetSingleObjectPayload(byte[] bytes)
|
||||
{
|
||||
this.bytes = bytes;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Applied only for the last Object in chain in case of manual multipart uploading
|
||||
/// </summary>
|
||||
/// <param name="largeObject">Parent for multipart object</param>
|
||||
public void SetParent(FrostFsObjectHeader largeObjectHeader)
|
||||
{
|
||||
if (Header?.Split == null)
|
||||
throw new ArgumentNullException(nameof(largeObjectHeader), "Split value must not be null");
|
||||
|
||||
Header.Split.ParentHeader = largeObjectHeader;
|
||||
}
|
||||
}
|
111
src/FrostFS.SDK.Client/Models/Object/FrostFsObjectFilter.cs
Normal file
111
src/FrostFS.SDK.Client/Models/Object/FrostFsObjectFilter.cs
Normal file
|
@ -0,0 +1,111 @@
|
|||
namespace FrostFS.SDK;
|
||||
|
||||
public interface IObjectFilter
|
||||
{
|
||||
public FrostFsMatchType MatchType { get; set; }
|
||||
public string Key { get; set; }
|
||||
|
||||
string? GetSerializedValue();
|
||||
}
|
||||
|
||||
public abstract class FrostFsObjectFilter<T>(FrostFsMatchType matchType, string key, T value) : IObjectFilter
|
||||
{
|
||||
public FrostFsMatchType MatchType { get; set; } = matchType;
|
||||
public string Key { get; set; } = key;
|
||||
|
||||
public T Value { get; set; } = value;
|
||||
|
||||
public string? GetSerializedValue()
|
||||
{
|
||||
return Value?.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates filter to search by Attribute
|
||||
/// </summary>
|
||||
/// <param name="matchType">Match type</param>
|
||||
/// <param name="key">Attribute key</param>
|
||||
/// <param name="value">Attribute value</param>
|
||||
public class FilterByAttributePair(FrostFsMatchType matchType, string key, string value) : FrostFsObjectFilter<string>(matchType, key, value) { }
|
||||
|
||||
/// <summary>
|
||||
/// Creates filter to search by ObjectId
|
||||
/// </summary>
|
||||
/// <param name="matchType">Match type</param>
|
||||
/// <param name="objectId">ObjectId</param>
|
||||
public class FilterByObjectId(FrostFsMatchType matchType, FrostFsObjectId objectId) : FrostFsObjectFilter<FrostFsObjectId>(matchType, Constants.FilterHeaderObjectID, objectId) { }
|
||||
|
||||
/// <summary>
|
||||
/// Creates filter to search by OwnerId
|
||||
/// </summary>
|
||||
/// <param name="matchType">Match type</param>
|
||||
/// <param name="ownerId">ObjectId</param>
|
||||
public class FilterByOwnerId(FrostFsMatchType matchType, FrostFsOwner ownerId) : FrostFsObjectFilter<FrostFsOwner>(matchType, Constants.FilterHeaderOwnerID, ownerId) { }
|
||||
|
||||
/// <summary>
|
||||
/// Creates filter to search by Version
|
||||
/// </summary>
|
||||
/// <param name="matchType">Match type</param>
|
||||
/// <param name="version">Version</param>
|
||||
public class FilterByVersion(FrostFsMatchType matchType, FrostFsVersion version) : FrostFsObjectFilter<FrostFsVersion>(matchType, Constants.FilterHeaderVersion, version) { }
|
||||
|
||||
/// <summary>
|
||||
/// Creates filter to search by ContainerId
|
||||
/// </summary>
|
||||
/// <param name="matchType">Match type</param>
|
||||
/// <param name="containerId">ContainerId</param>
|
||||
public class FilterByContainerId(FrostFsMatchType matchType, FrostFsContainerId containerId) : FrostFsObjectFilter<FrostFsContainerId>(matchType, Constants.FilterHeaderContainerID, containerId) { }
|
||||
|
||||
/// <summary>
|
||||
/// Creates filter to search by creation Epoch
|
||||
/// </summary>
|
||||
/// <param name="matchType">Match type</param>
|
||||
/// <param name="epoch">Creation Epoch</param>
|
||||
public class FilterByEpoch(FrostFsMatchType matchType, ulong epoch) : FrostFsObjectFilter<ulong>(matchType, Constants.FilterHeaderCreationEpoch, epoch) { }
|
||||
|
||||
/// <summary>
|
||||
/// Creates filter to search by Payload Length
|
||||
/// </summary>
|
||||
/// <param name="matchType">Match type</param>
|
||||
/// <param name="payloadLength">Payload Length</param>
|
||||
public class FilterByPayloadLength(FrostFsMatchType matchType, ulong payloadLength) : FrostFsObjectFilter<ulong>(matchType, Constants.FilterHeaderPayloadLength, payloadLength) { }
|
||||
|
||||
/// <summary>
|
||||
/// Creates filter to search by Payload Hash
|
||||
/// </summary>
|
||||
/// <param name="matchType">Match type</param>
|
||||
/// <param name="payloadHash">Payload Hash</param>
|
||||
public class FilterByPayloadHash(FrostFsMatchType matchType, CheckSum payloadHash) : FrostFsObjectFilter<CheckSum>(matchType, Constants.FilterHeaderPayloadHash, payloadHash) { }
|
||||
|
||||
/// <summary>
|
||||
/// Creates filter to search by Parent
|
||||
/// </summary>
|
||||
/// <param name="matchType">Match type</param>
|
||||
/// <param name="parentId">Parent</param>
|
||||
public class FilterByParent(FrostFsMatchType matchType, FrostFsObjectId parentId) : FrostFsObjectFilter<FrostFsObjectId>(matchType, Constants.FilterHeaderParent, parentId) { }
|
||||
|
||||
/// <summary>
|
||||
/// Creates filter to search by SplitId
|
||||
/// </summary>
|
||||
/// <param name="matchType">Match type</param>
|
||||
/// <param name="splitId">SplitId</param>
|
||||
public class FilterBySplitId(FrostFsMatchType matchType, SplitId splitId) : FrostFsObjectFilter<SplitId>(matchType, Constants.FilterHeaderSplitID, splitId) { }
|
||||
|
||||
/// <summary>
|
||||
/// Creates filter to search by Payload Hash
|
||||
/// </summary>
|
||||
/// <param name="matchType">Match type</param>
|
||||
/// <param name="ecParentId">Payload Hash</param>
|
||||
public class FilterByECParent(FrostFsMatchType matchType, FrostFsObjectId ecParentId) : FrostFsObjectFilter<FrostFsObjectId>(matchType, Constants.FilterHeaderECParent, ecParentId) { }
|
||||
|
||||
/// <summary>
|
||||
/// Creates filter to search Root objects
|
||||
/// </summary>
|
||||
public class FilterByRootObject() : FrostFsObjectFilter<string>(FrostFsMatchType.Unspecified, Constants.FilterHeaderRoot, string.Empty) { }
|
||||
|
||||
/// <summary>
|
||||
/// Creates filter to search objects that are physically stored on the server
|
||||
/// </summary
|
||||
public class FilterByPhysicallyStored() : FrostFsObjectFilter<string>(FrostFsMatchType.Unspecified, Constants.FilterHeaderPhy, string.Empty) { }
|
||||
|
90
src/FrostFS.SDK.Client/Models/Object/FrostFsObjectHeader.cs
Normal file
90
src/FrostFS.SDK.Client/Models/Object/FrostFsObjectHeader.cs
Normal file
|
@ -0,0 +1,90 @@
|
|||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
|
||||
using FrostFS.Object;
|
||||
|
||||
using FrostFS.SDK.Client.Mappers.GRPC;
|
||||
|
||||
namespace FrostFS.SDK;
|
||||
|
||||
public class FrostFsObjectHeader(
|
||||
FrostFsContainerId containerId,
|
||||
FrostFsObjectType type = FrostFsObjectType.Regular,
|
||||
FrostFsAttributePair[]? attributes = null,
|
||||
FrostFsSplit? split = null,
|
||||
FrostFsOwner? owner = null,
|
||||
FrostFsVersion? version = null)
|
||||
{
|
||||
private Header? header;
|
||||
private Container.Container.Types.Attribute[]? grpsAttributes;
|
||||
|
||||
public ReadOnlyCollection<FrostFsAttributePair>? Attributes { get; internal set; } =
|
||||
attributes == null ? null :
|
||||
new ReadOnlyCollection<FrostFsAttributePair>(attributes);
|
||||
|
||||
public FrostFsContainerId ContainerId { get; } = containerId;
|
||||
|
||||
public ulong PayloadLength { get; set; }
|
||||
|
||||
public byte[]? PayloadCheckSum { get; set; }
|
||||
|
||||
public FrostFsObjectType ObjectType { get; } = type;
|
||||
|
||||
public FrostFsOwner? OwnerId { get; internal set; } = owner;
|
||||
|
||||
public FrostFsVersion? Version { get; internal set; } = version;
|
||||
|
||||
public FrostFsSplit? Split { get; internal set; } = split;
|
||||
|
||||
internal Container.Container.Types.Attribute[]? GetGrpsAttributes()
|
||||
{
|
||||
grpsAttributes ??= Attributes?
|
||||
.Select(a => new Container.Container.Types.Attribute { Key = a.Key, Value = a.Value })
|
||||
.ToArray();
|
||||
|
||||
return grpsAttributes;
|
||||
}
|
||||
|
||||
public Header GetHeader()
|
||||
{
|
||||
if (header == null)
|
||||
{
|
||||
var objTypeName = ObjectType switch
|
||||
{
|
||||
FrostFsObjectType.Regular => Object.ObjectType.Regular,
|
||||
FrostFsObjectType.Lock => Object.ObjectType.Lock,
|
||||
FrostFsObjectType.Tombstone => Object.ObjectType.Tombstone,
|
||||
_ => throw new ArgumentException($"Unknown ObjectType. Value: '{ObjectType}'.")
|
||||
};
|
||||
|
||||
this.header = new Header
|
||||
{
|
||||
OwnerId = OwnerId?.ToMessage(),
|
||||
Version = Version?.ToMessage(),
|
||||
ContainerId = ContainerId.ToMessage(),
|
||||
ObjectType = objTypeName,
|
||||
PayloadLength = PayloadLength
|
||||
};
|
||||
|
||||
if (Attributes != null)
|
||||
{
|
||||
foreach (var attribute in Attributes)
|
||||
{
|
||||
this.header.Attributes.Add(attribute.ToMessage());
|
||||
}
|
||||
}
|
||||
|
||||
var split = Split;
|
||||
if (split != null)
|
||||
{
|
||||
this.header.Split = new Header.Types.Split
|
||||
{
|
||||
SplitId = split!.SplitId != null ? split.SplitId.GetSplitId() : null
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return this.header;
|
||||
}
|
||||
}
|
33
src/FrostFS.SDK.Client/Models/Object/FrostFsObjectId.cs
Normal file
33
src/FrostFS.SDK.Client/Models/Object/FrostFsObjectId.cs
Normal file
|
@ -0,0 +1,33 @@
|
|||
using System;
|
||||
|
||||
using FrostFS.SDK.Cryptography;
|
||||
|
||||
namespace FrostFS.SDK;
|
||||
|
||||
public class FrostFsObjectId(string id)
|
||||
{
|
||||
public string Value { get; } = id;
|
||||
|
||||
public static FrostFsObjectId FromHash(byte[] hash)
|
||||
{
|
||||
if (hash is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(hash));
|
||||
}
|
||||
|
||||
if (hash.Length != Constants.Sha256HashLength)
|
||||
throw new FormatException("ObjectID must be a sha256 hash.");
|
||||
|
||||
return new FrostFsObjectId(Base58.Encode(hash));
|
||||
}
|
||||
|
||||
public byte[] ToHash()
|
||||
{
|
||||
return Base58.Decode(Value);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Value;
|
||||
}
|
||||
}
|
38
src/FrostFS.SDK.Client/Models/Object/FrostFsOwner.cs
Normal file
38
src/FrostFS.SDK.Client/Models/Object/FrostFsOwner.cs
Normal file
|
@ -0,0 +1,38 @@
|
|||
using System.Security.Cryptography;
|
||||
|
||||
using FrostFS.Refs;
|
||||
using FrostFS.SDK.Client.Mappers.GRPC;
|
||||
using FrostFS.SDK.Cryptography;
|
||||
|
||||
namespace FrostFS.SDK;
|
||||
|
||||
public class FrostFsOwner(string id)
|
||||
{
|
||||
private OwnerID? ownerID;
|
||||
|
||||
public string Value { get; } = id;
|
||||
|
||||
public static FrostFsOwner FromKey(ECDsa key)
|
||||
{
|
||||
return new FrostFsOwner(key.PublicKey().PublicKeyToAddress());
|
||||
}
|
||||
|
||||
internal OwnerID OwnerID
|
||||
{
|
||||
get
|
||||
{
|
||||
ownerID ??= this.ToMessage();
|
||||
return ownerID;
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] ToHash()
|
||||
{
|
||||
return Base58.Decode(Value);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Value;
|
||||
}
|
||||
}
|
27
src/FrostFS.SDK.Client/Models/Object/FrostFsRange.cs
Normal file
27
src/FrostFS.SDK.Client/Models/Object/FrostFsRange.cs
Normal file
|
@ -0,0 +1,27 @@
|
|||
namespace FrostFS.SDK;
|
||||
|
||||
public readonly struct FrostFsRange(ulong offset, ulong length) : System.IEquatable<FrostFsRange>
|
||||
{
|
||||
public ulong Offset { get; } = offset;
|
||||
|
||||
public ulong Length { get; } = length;
|
||||
|
||||
public override readonly bool Equals(object obj) => this == (FrostFsRange)obj;
|
||||
|
||||
public override readonly int GetHashCode() => $"{Offset}{Length}".GetHashCode();
|
||||
|
||||
public static bool operator ==(FrostFsRange left, FrostFsRange right)
|
||||
{
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
public static bool operator !=(FrostFsRange left, FrostFsRange right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
|
||||
public readonly bool Equals(FrostFsRange other)
|
||||
{
|
||||
return this == other;
|
||||
}
|
||||
}
|
28
src/FrostFS.SDK.Client/Models/Object/FrostFsSplit.cs
Normal file
28
src/FrostFS.SDK.Client/Models/Object/FrostFsSplit.cs
Normal file
|
@ -0,0 +1,28 @@
|
|||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace FrostFS.SDK;
|
||||
|
||||
public class FrostFsSplit(SplitId splitId,
|
||||
FrostFsObjectId? previous = null,
|
||||
FrostFsObjectId? parent = null,
|
||||
FrostFsObjectHeader? parentHeader = null,
|
||||
FrostFsSignature? parentSignature = null,
|
||||
ReadOnlyCollection<FrostFsObjectId>? children = null)
|
||||
{
|
||||
public FrostFsSplit() : this(new SplitId())
|
||||
{
|
||||
}
|
||||
|
||||
public SplitId SplitId { get; private set; } = splitId;
|
||||
|
||||
public FrostFsObjectId? Previous { get; } = previous;
|
||||
|
||||
public FrostFsObjectId? Parent { get; } = parent;
|
||||
|
||||
public FrostFsSignature? ParentSignature { get; } = parentSignature;
|
||||
|
||||
public FrostFsObjectHeader? ParentHeader { get; set; } = parentHeader;
|
||||
|
||||
public ReadOnlyCollection<FrostFsObjectId>? Children { get; } = children;
|
||||
|
||||
}
|
10
src/FrostFS.SDK.Client/Models/Object/IObjectReader.cs
Normal file
10
src/FrostFS.SDK.Client/Models/Object/IObjectReader.cs
Normal file
|
@ -0,0 +1,10 @@
|
|||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FrostFS.SDK;
|
||||
|
||||
public interface IObjectReader : IDisposable
|
||||
{
|
||||
ValueTask<ReadOnlyMemory<byte>?> ReadChunk(CancellationToken cancellationToken = default);
|
||||
}
|
62
src/FrostFS.SDK.Client/Models/Object/SplitId.cs
Normal file
62
src/FrostFS.SDK.Client/Models/Object/SplitId.cs
Normal file
|
@ -0,0 +1,62 @@
|
|||
using System;
|
||||
|
||||
using FrostFS.SDK.Cryptography;
|
||||
|
||||
using Google.Protobuf;
|
||||
|
||||
namespace FrostFS.SDK;
|
||||
|
||||
public class SplitId
|
||||
{
|
||||
private readonly Guid id;
|
||||
|
||||
private ByteString? message;
|
||||
|
||||
public SplitId()
|
||||
{
|
||||
this.id = Guid.NewGuid();
|
||||
}
|
||||
|
||||
public SplitId(Guid id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
private SplitId(byte[] binary)
|
||||
{
|
||||
this.id = new Guid(binary);
|
||||
}
|
||||
|
||||
private SplitId(string str)
|
||||
{
|
||||
this.id = new Guid(str);
|
||||
}
|
||||
|
||||
public static SplitId CreateFromBinary(byte[] binaryData)
|
||||
{
|
||||
return new SplitId(binaryData);
|
||||
}
|
||||
|
||||
public static SplitId CreateFromString(string stringData)
|
||||
{
|
||||
return new SplitId(stringData);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return this.id.ToString();
|
||||
}
|
||||
|
||||
public byte[]? ToBinary()
|
||||
{
|
||||
if (this.id == Guid.Empty)
|
||||
return null;
|
||||
|
||||
return this.id.ToBytes();
|
||||
}
|
||||
|
||||
public ByteString? GetSplitId()
|
||||
{
|
||||
return this.message ??= ByteString.CopyFrom(ToBinary());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
namespace FrostFS.SDK;
|
||||
|
||||
public class FrostFsResponseStatus(FrostFsStatusCode code, string? message = null)
|
||||
{
|
||||
public FrostFsStatusCode Code { get; set; } = code;
|
||||
public string Message { get; set; } = message ?? string.Empty;
|
||||
|
||||
public bool IsSuccess => Code == FrostFsStatusCode.Success;
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"Response status: {Code}. Message: {Message}.";
|
||||
}
|
||||
}
|
10
src/FrostFS.SDK.Client/Models/Response/FrostFsSignature.cs
Normal file
10
src/FrostFS.SDK.Client/Models/Response/FrostFsSignature.cs
Normal file
|
@ -0,0 +1,10 @@
|
|||
namespace FrostFS.SDK;
|
||||
|
||||
public class FrostFsSignature()
|
||||
{
|
||||
public byte[]? Key { get; set; }
|
||||
|
||||
public byte[]? Sign { get; set; }
|
||||
|
||||
public SignatureScheme Scheme { get; set; }
|
||||
}
|
20
src/FrostFS.SDK.Client/Models/Response/MetaHeader.cs
Normal file
20
src/FrostFS.SDK.Client/Models/Response/MetaHeader.cs
Normal file
|
@ -0,0 +1,20 @@
|
|||
namespace FrostFS.SDK;
|
||||
|
||||
public class MetaHeader(FrostFsVersion version, int epoch, int ttl)
|
||||
{
|
||||
public FrostFsVersion Version { get; set; } = version;
|
||||
public int Epoch { get; set; } = epoch;
|
||||
public int Ttl { get; set; } = ttl;
|
||||
|
||||
public static MetaHeader Default()
|
||||
{
|
||||
return new MetaHeader(
|
||||
new FrostFsVersion(
|
||||
major: 2,
|
||||
minor: 13
|
||||
),
|
||||
epoch: 0,
|
||||
ttl: 2
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
using System;
|
||||
|
||||
namespace FrostFS.SDK;
|
||||
|
||||
public class FrostFsSessionToken(byte[] token, Guid id)
|
||||
{
|
||||
public Guid Id { get; private set; } = id;
|
||||
public byte[] Token { get; private set; } = token;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue