Compare commits

..

No commits in common. "master" and "feature/add-codeowners" have entirely different histories.

4 changed files with 19 additions and 78 deletions

View file

@ -20,9 +20,7 @@ public class FrostFsSplitInfo
public SplitId SplitId => _splitId ??= new SplitId(_splitInfo.SplitId.ToUuid()); public SplitId SplitId => _splitId ??= new SplitId(_splitInfo.SplitId.ToUuid());
public FrostFsObjectId? Link => _link ??= _splitInfo.Link == null public FrostFsObjectId Link => _link ??= FrostFsObjectId.FromHash(_splitInfo.Link.Value.Span);
? null : FrostFsObjectId.FromHash(_splitInfo.Link.Value.Span);
public FrostFsObjectId? LastPart => _lastPart ??= _splitInfo.LastPart == null public FrostFsObjectId LastPart => _lastPart ??= FrostFsObjectId.FromHash(_splitInfo.LastPart.Value.Span);
? null : FrostFsObjectId.FromHash(_splitInfo.LastPart.Value.Span);
} }

View file

@ -39,8 +39,6 @@ public partial class Pool : IFrostFSClient
private OwnerID? _ownerId; private OwnerID? _ownerId;
private FrostFsVersion _version;
private FrostFsOwner? _owner; private FrostFsOwner? _owner;
private FrostFsOwner Owner private FrostFsOwner Owner
@ -96,8 +94,6 @@ public partial class Pool : IFrostFSClient
throw new ArgumentException($"Missed required parameter {nameof(options.Key)}"); throw new ArgumentException($"Missed required parameter {nameof(options.Key)}");
} }
_version = new FrostFsVersion(2, 13);
var nodesParams = AdjustNodeParams(options.NodeParams); var nodesParams = AdjustNodeParams(options.NodeParams);
var cache = new SessionCache(options.SessionExpirationDuration); var cache = new SessionCache(options.SessionExpirationDuration);

View file

@ -268,7 +268,7 @@ internal sealed class ObjectServiceProvider(ObjectService.ObjectServiceClient cl
internal async Task<FrostFsObjectId> PutSingleObjectAsync(PrmSingleObjectPut args, CallContext ctx) internal async Task<FrostFsObjectId> PutSingleObjectAsync(PrmSingleObjectPut args, CallContext ctx)
{ {
var grpcObject = ObjectTools.CreateSingleObject(args.FrostFsObject, ClientContext); var grpcObject = ObjectTools.CreateObject(args.FrostFsObject, ClientContext);
var request = new PutSingleRequest var request = new PutSingleRequest
{ {
@ -565,7 +565,7 @@ internal sealed class ObjectServiceProvider(ObjectService.ObjectServiceClient cl
if (header.Split != null) if (header.Split != null)
{ {
ObjectTools.SetSplitValues(grpcHeader, header.Split, ClientContext.Owner, ClientContext.Version, ClientContext.Key); ObjectTools.SetSplitValues(grpcHeader, header.Split, ClientContext);
} }
var oid = new ObjectID { Value = grpcHeader.Sha256() }; var oid = new ObjectID { Value = grpcHeader.Sha256() };

View file

@ -1,4 +1,3 @@
using System;
using System.Linq; using System.Linq;
using FrostFS.Object; using FrostFS.Object;
@ -10,44 +9,9 @@ using Google.Protobuf;
namespace FrostFS.SDK.Client; namespace FrostFS.SDK.Client;
public static class ObjectTools internal static class ObjectTools
{ {
public static FrostFsObjectId CalculateObjectId( internal static Object.Object CreateObject(FrostFsObject @object, ClientContext ctx)
FrostFsObjectHeader header,
ReadOnlyMemory<byte> payloadHash,
FrostFsOwner owner,
FrostFsVersion version,
ClientKey key)
{
if (header is null)
{
throw new ArgumentNullException(nameof(header));
}
if (owner is null)
{
throw new ArgumentNullException(nameof(owner));
}
if (version is null)
{
throw new ArgumentNullException(nameof(version));
}
if (key is null)
{
throw new ArgumentNullException(nameof(key));
}
var grpcHeader = CreateHeader(header, payloadHash, owner, version);
if (header.Split != null)
SetSplitValues(grpcHeader, header.Split, owner, version, key);
return new ObjectID { Value = grpcHeader.Sha256() }.ToModel();
}
internal static Object.Object CreateSingleObject(FrostFsObject @object, ClientContext ctx)
{ {
@object.Header.OwnerId ??= ctx.Owner; @object.Header.OwnerId ??= ctx.Owner;
@object.Header.Version ??= ctx.Version; @object.Header.Version ??= ctx.Version;
@ -60,7 +24,7 @@ public static class ObjectTools
var split = @object.Header.Split; var split = @object.Header.Split;
if (split != null) if (split != null)
{ {
SetSplitValues(grpcHeader, split, ctx.Owner, ctx.Version, ctx.Key); SetSplitValues(grpcHeader, split, ctx);
} }
var obj = new Object.Object var obj = new Object.Object
@ -79,18 +43,13 @@ public static class ObjectTools
return obj; return obj;
} }
internal static void SetSplitValues( internal static void SetSplitValues(Header grpcHeader, FrostFsSplit split, ClientContext ctx)
Header grpcHeader,
FrostFsSplit split,
FrostFsOwner owner,
FrostFsVersion version,
ClientKey key)
{ {
if (split == null) if (split == null)
return; return;
if (key == null) if (ctx.Key == null)
throw new FrostFsInvalidObjectException(nameof(key)); throw new FrostFsInvalidObjectException(nameof(ctx.Key));
grpcHeader.Split = new Header.Types.Split grpcHeader.Split = new Header.Types.Split
{ {
@ -102,33 +61,30 @@ public static class ObjectTools
if (split.ParentHeader is not null) if (split.ParentHeader is not null)
{ {
var grpcParentHeader = CreateHeader(split.ParentHeader, Array.Empty<byte>().Sha256(), owner, version); var grpcParentHeader = CreateHeader(split.ParentHeader, [], ctx);
grpcHeader.Split.Parent = new ObjectID { Value = grpcParentHeader.Sha256() }; grpcHeader.Split.Parent = new ObjectID { Value = grpcParentHeader.Sha256() };
grpcHeader.Split.ParentHeader = grpcParentHeader; grpcHeader.Split.ParentHeader = grpcParentHeader;
grpcHeader.Split.ParentSignature = new Signature grpcHeader.Split.ParentSignature = new Signature
{ {
Key = key.PublicKeyProto, Key = ctx.Key.PublicKeyProto,
Sign = key.ECDsaKey.SignData(grpcHeader.Split.Parent.ToByteArray()), Sign = ctx.Key.ECDsaKey.SignData(grpcHeader.Split.Parent.ToByteArray()),
}; };
} }
grpcHeader.Split.Previous = split.Previous?.ToMessage(); grpcHeader.Split.Previous = split.Previous?.ToMessage();
} }
internal static Header CreateHeader( internal static Header CreateHeader(FrostFsObjectHeader header, byte[]? payload, ClientContext ctx)
FrostFsObjectHeader header,
ReadOnlyMemory<byte> payloadChecksum,
FrostFsOwner owner,
FrostFsVersion version)
{ {
header.OwnerId ??= owner; header.OwnerId ??= ctx.Owner;
header.Version ??= version; header.Version ??= ctx.Version;
var grpcHeader = header.GetHeader(); var grpcHeader = header.GetHeader();
grpcHeader.PayloadHash = ChecksumFromSha256(payloadChecksum); if (payload != null) // && payload.Length > 0
grpcHeader.PayloadHash = Sha256Checksum(payload);
return grpcHeader; return grpcHeader;
} }
@ -140,13 +96,4 @@ public static class ObjectTools
Sum = ByteString.CopyFrom(data.Sha256()) Sum = ByteString.CopyFrom(data.Sha256())
}; };
} }
internal static Checksum ChecksumFromSha256(ReadOnlyMemory<byte> dataHash)
{
return new Checksum
{
Type = ChecksumType.Sha256,
Sum = UnsafeByteOperations.UnsafeWrap(dataHash)
};
}
} }