public void TestObjectGet() { var host = "localhost:8080"; var key = "KxDgvEKzgSBPPfuVfw67oPQBSjidEiqTHURKSDL1R7yGaGYAeYnr".LoadWif(); var cid = ContainerID.FromBase58String("RuzuV3RDstuVtWoDzsTsuNFiakaaGGN24EbNSUFGaiQ"); var oid = ObjectID.FromBase58String("6VLqsZAvYTRzt8yY4NvGweWfGmqBiAfQwd6novRNFYiG"); var address = new Address(cid, oid); var client = new Client.Client(key, host); var source1 = new CancellationTokenSource(); source1.CancelAfter(TimeSpan.FromMinutes(1)); var session = client.CreateSession(source1.Token, ulong.MaxValue); source1.Cancel(); var source2 = new CancellationTokenSource(); source2.CancelAfter(TimeSpan.FromMinutes(1)); var o = client.GetObject(source2.Token, new GetObjectParams { Address = address }, new CallOptions { Ttl = 2, Session = session }).Result; Assert.AreEqual(oid, o.ObjectId); }
/// <summary> /// GetAsync returns neofs object from the provided url. /// If Command is not provided, full object is requested. /// </summary> /// <param name="uri">URI scheme is "neofs:<Container-ID>/<Object-ID>/<Command>/<offset|length>".</param> /// <param name="host">Client host.</param> /// <param name="cancellation">Cancellation token object.</param> /// <returns>Returns neofs object.</returns> private Task <string> GetAsync(Uri uri, string host, CancellationToken cancellation) { string[] ps = uri.AbsolutePath.Split("/"); if (ps.Length < 2) { throw new FormatException("Invalid neofs url"); } ContainerID containerID = ContainerID.FromBase58String(ps[0]); ObjectID objectID = ObjectID.FromBase58String(ps[1]); Address objectAddr = new() { ContainerId = containerID, ObjectId = objectID }; Client client = new(privateKey, host); var tokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellation); tokenSource.CancelAfter(Settings.Default.NeoFS.Timeout); if (ps.Length == 2) { return(GetPayloadAsync(client, objectAddr, tokenSource.Token)); } return(ps[2] switch { "range" => GetRangeAsync(client, objectAddr, ps.Skip(3).ToArray(), tokenSource.Token), "header" => GetHeaderAsync(client, objectAddr, tokenSource.Token), "hash" => GetHashAsync(client, objectAddr, ps.Skip(3).ToArray(), tokenSource.Token), _ => throw new Exception("invalid command") }); }
public void TestObjectGetRangeHash() { var host = "localhost:8080"; var key = "KxDgvEKzgSBPPfuVfw67oPQBSjidEiqTHURKSDL1R7yGaGYAeYnr".LoadWif(); var cid = ContainerID.FromBase58String("Bun3sfMBpnjKc3Tx7SdwrMxyNi8ha8JT3dhuFGvYBRTz"); var oid = ObjectID.FromBase58String("vWt34r4ddnq61jcPec4rVaXHg7Y7GiEYFmcTB2Qwhtx"); var address = new Address(cid, oid); var client = new Client.Client(key, host); var source1 = new CancellationTokenSource(); source1.CancelAfter(TimeSpan.FromMinutes(1)); var session = client.CreateSession(source1.Token, ulong.MaxValue); source1.Cancel(); var source2 = new CancellationTokenSource(); source2.CancelAfter(TimeSpan.FromMinutes(1)); var o = client.GetObjectPayloadRangeHash(source2.Token, new RangeChecksumParams { Address = address, Ranges = new List <Object.Range> { new Object.Range { Offset = 0, Length = 3 } }, Salt = new byte[] { 0x00 }, Type = ChecksumType.Sha256 }, new CallOptions { Ttl = 2, Session = session }); Assert.AreEqual(1, o.Count); Assert.AreEqual(Encoding.ASCII.GetBytes("hello")[..3].Sha256().ToHexString(), o[0].ToHexString());
public void TestObjectGetRange() { var host = "localhost:8080"; var key = "KxDgvEKzgSBPPfuVfw67oPQBSjidEiqTHURKSDL1R7yGaGYAeYnr".LoadWif(); var cid = ContainerID.FromBase58String("Bun3sfMBpnjKc3Tx7SdwrMxyNi8ha8JT3dhuFGvYBRTz"); var oid = ObjectID.FromBase58String("vWt34r4ddnq61jcPec4rVaXHg7Y7GiEYFmcTB2Qwhtx"); var address = new Address(cid, oid); var client = new Client.Client(key, host); var source1 = new CancellationTokenSource(); source1.CancelAfter(TimeSpan.FromMinutes(1)); var session = client.CreateSession(source1.Token, ulong.MaxValue); source1.Cancel(); var source2 = new CancellationTokenSource(); source2.CancelAfter(TimeSpan.FromMinutes(1)); var o = client.GetObjectPayloadRangeData(source2.Token, new RangeDataParams { Address = address, Range = new Object.Range { Offset = 0, Length = 3 } }, new CallOptions { Ttl = 2, Session = session }).Result; Assert.AreEqual("hel", Encoding.ASCII.GetString(o)); }
public void TestObjectHeaderGet() { var host = "localhost:8080"; var key = "KxDgvEKzgSBPPfuVfw67oPQBSjidEiqTHURKSDL1R7yGaGYAeYnr".LoadWif(); var cid = ContainerID.FromBase58String("Bun3sfMBpnjKc3Tx7SdwrMxyNi8ha8JT3dhuFGvYBRTz"); var oid = ObjectID.FromBase58String("vWt34r4ddnq61jcPec4rVaXHg7Y7GiEYFmcTB2Qwhtx"); var address = new Address(cid, oid); var client = new Client.Client(key, host); var source1 = new CancellationTokenSource(); source1.CancelAfter(TimeSpan.FromMinutes(1)); var session = client.CreateSession(source1.Token, ulong.MaxValue); source1.Cancel(); var source2 = new CancellationTokenSource(); source2.CancelAfter(TimeSpan.FromMinutes(1)); var o = client.GetObjectHeader(source2.Token, new ObjectHeaderParams { Address = address, Short = false }, new CallOptions { Ttl = 2, Session = session }); Assert.AreEqual(oid, o.ObjectId); }
public void TestObjectDelete() { var host = "localhost:8080"; var key = "KxDgvEKzgSBPPfuVfw67oPQBSjidEiqTHURKSDL1R7yGaGYAeYnr".LoadWif(); var cid = ContainerID.FromBase58String("Bun3sfMBpnjKc3Tx7SdwrMxyNi8ha8JT3dhuFGvYBRTz"); var oid = ObjectID.FromBase58String("CnBNgUmXiA5KJeGvMDgUEGiKrbZctjwxT5v3sBYjnmf1"); var address = new Address(cid, oid); var client = new Client.Client(key, host); var source1 = new CancellationTokenSource(); source1.CancelAfter(TimeSpan.FromMinutes(1)); var session = client.CreateSession(source1.Token, ulong.MaxValue); source1.Cancel(); var source2 = new CancellationTokenSource(); source2.CancelAfter(TimeSpan.FromMinutes(1)); var o = client.DeleteObject(source2.Token, new DeleteObjectParams { Address = address }, new CallOptions { Ttl = 2, Session = session }); Assert.IsTrue(o); }
public void TestAddObjectIDFilters() { var sf = new SearchFilters(); var oid = ObjectID.FromBase58String("vWt34r4ddnq61jcPec4rVaXHg7Y7GiEYFmcTB2Qwhtx"); sf.AddObjectIDFilter(MatchType.StringEqual, oid); Assert.AreEqual(1, sf.Filters.Length); var f = sf.Filters[0]; Assert.AreEqual(MatchType.StringEqual, f.MatchType); Assert.AreEqual(Filter.FilterHeaderObjectID, f.Key); Assert.AreEqual("vWt34r4ddnq61jcPec4rVaXHg7Y7GiEYFmcTB2Qwhtx", f.Value); }