/// <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 async 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.FromString(ps[0]); ObjectID objectID = ObjectID.FromString(ps[1]); Address objectAddr = new() { ContainerId = containerID, ObjectId = objectID }; using Client client = new(privateKey, host); var tokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellation); tokenSource.CancelAfter(Settings.Default.NeoFS.Timeout); if (ps.Length == 2) { return(await GetPayloadAsync(client, objectAddr, tokenSource.Token)); } return(await(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 TestObjectIDDistinct() { var id1 = ObjectID.FromString("6hc8bGUWr22VKWsnzcEqzw6c5qhDh2cdbziASkrme7tu"); var id2 = ObjectID.FromString("6hc8bGUWr22VKWsnzcEqzw6c5qhDh2cdbziASkrme7tu"); var ids = new List <ObjectID>() { id1, id2 }; Assert.AreEqual(1, ids.Distinct().Count()); }
public void TestAddObjectIDFilters() { var sf = new SearchFilters(); var oid = ObjectID.FromString("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); }
public bool Select(string object_ident, int func_id) { if (object_ident == null) { //Log.TraceError("GameSender Select object_ident is null"); return(false); } ObjectID objID = ObjectID.FromString(object_ident); StoreArchive ar = new StoreArchive(m_buffer, m_buffer.Length); ar.WriteInt8(GlobalClineMsgId.CLIENT_SELECT);//消息ID //unsigned char nVerify[4]; // 校验码 //int nSerial; // 消息序列号 //outer_object_t ObjectId; // 对象标识 //int nFunctionId; // 功能号为0表示执行缺省功能 //byte[] message = TypeConvert.encode(m_buffer,ar.GetLength()); byte[] data = new byte[256]; int index = 0; //序号,名字加入校验 MsgEncode.WriteInt16(ref data, ref index, (uint)MsgEncode.Instance.Serial); MsgEncode.WriteInt16(ref data, ref index, (uint)MsgEncode.Instance.MsgSerial); MsgEncode.WriteInt32(ref data, ref index, (uint)func_id); MsgEncode.WriteObject(ref data, ref index, objID); byte[] verify = MsgEncode.Instance.Encode(data, index, 4); ar.WriteUserDataNoLen(verify); //检验码 ar.WriteInt32(MsgEncode.Instance.MsgSerial); //消息序列号 ar.WriteObject(objID); //对象标识 ar.WriteInt32(func_id); return(m_sender.Send(ar.GetData(), ar.GetLength())); }
public bool Select(string object_ident, int func_id) { if (object_ident == null) { LogSystem.LogError("GameSender Select object_ident is null"); return(false); } if (0 == object_ident.Length) { LogSystem.LogError("GameSender Select object_ident is empty"); return(false); } StoreArchive ar = StoreArchive.Load(m_buffer, m_buffer.Length); ar.WriteInt8(GlobalClineMsgId.CLIENT_SELECT);//消息ID //unsigned char nVerify[16]; // 校验码 //int nSerial; // 消息序列号 //outer_object_t ObjectId; // 对象标识 //int nFunctionId; // 功能号为0表示执行缺省功能 //byte[] message = TypeConvert.encode(m_buffer,ar.GetLength()); ObjectID obj = ObjectID.FromString(object_ident); byte[] verify = new byte[16]; fxVerify.GetSelectVerify(func_id, (int)(obj.m_nSerial), mCustomIndex, (int)(obj.m_nIdent), ref verify); ar.WriteUserDataNoLen(verify); //检验码 ar.WriteInt32(mCustomIndex++); //消息序列号 ar.WriteObject(obj); //对象标识 ar.WriteInt32(func_id); return(m_sender.Send(ar.GetData(), ar.GetLength())); }
public void TestObjectPutStorageGroup() { List <ObjectID> oids = new() { ObjectID.FromString("7Q7fPKESmRJ1VGHKcB2pB4JWVebsQzrJypwQiNLU1ekv"), ObjectID.FromString("HwfVt5i9ucjPUhRpHyxamnfTvhKtTUysCZWXcJ6YZsZ4") }; using var client = new Client.Client(key, host); byte[] tzh = null; ulong size = 0; foreach (var oid in oids) { var address = new Address(cid, oid); using var source = new CancellationTokenSource(); source.CancelAfter(TimeSpan.FromMinutes(1)); var oo = client.GetObjectHeader(address, false, false, new CallOptions { Ttl = 2 }, source.Token).Result; if (tzh is null) { tzh = oo.PayloadHomomorphicHash.Sum.ToByteArray(); } else { tzh = TzHash.Concat(new() { tzh, oo.PayloadHomomorphicHash.Sum.ToByteArray() }); } size += oo.PayloadSize; } var epoch = client.Epoch().Result; StorageGroup.StorageGroup sg = new() { ValidationDataSize = size, ValidationHash = new() { Type = ChecksumType.Tz, Sum = ByteString.CopyFrom(tzh) }, ExpirationEpoch = epoch + 100, }; sg.Members.AddRange(oids); var obj = new FSObject { Header = new Header { OwnerId = OwnerID.FromScriptHash(key.PublicKey().PublicKeyToScriptHash()), ContainerId = cid, ObjectType = ObjectType.StorageGroup, }, Payload = ByteString.CopyFrom(sg.ToByteArray()), }; using var source1 = new CancellationTokenSource(); source1.CancelAfter(TimeSpan.FromMinutes(1)); var session = client.CreateSession(ulong.MaxValue, context: source1.Token).Result; source1.Cancel(); using var source2 = new CancellationTokenSource(); source2.CancelAfter(TimeSpan.FromMinutes(1)); var o = client.PutObject(obj, new CallOptions { Ttl = 2, Session = session }, source2.Token).Result; Console.WriteLine(o.String()); Assert.AreNotEqual("", o.String()); }
public void TestSimulation() { var nodes_json_str = "[{\"id\":17245477228755262,\"capacity\":0,\"index\":0,\"price\":22,\"nodeinfo\":{\"publicKey\":\"Aiu0BBxQ1gf/hx3sfkzXd4OI4OpoSdhMy9mqjzLhaoEx\",\"addresses\":[\"/dns4/s01.neofs.devenv/tcp/8080\"],\"attributes\":[{\"key\":\"Capacity\",\"value\":\"0\"},{\"key\":\"Continent\",\"value\":\"Asia\"},{\"key\":\"Country\",\"value\":\"Russia\"},{\"key\":\"CountryCode\",\"value\":\"RU\"},{\"key\":\"Location\",\"value\":\"Mishkino\"},{\"key\":\"Price\",\"value\":\"22\"},{\"key\":\"UN-LOCODE\",\"value\":\"RU MSK\"}],\"state\":\"Online\"}},{\"id\":14040999376522263000,\"capacity\":0,\"index\":1,\"price\":44,\"nodeinfo\":{\"publicKey\":\"A4yGKVnla0PiD3kYfE/p4Lx8jGbBYD5s8Ox/h6trCNw1\",\"addresses\":[\"/dns4/s04.neofs.devenv/tcp/8080\"],\"attributes\":[{\"key\":\"Capacity\",\"value\":\"0\"},{\"key\":\"Continent\",\"value\":\"Europe\"},{\"key\":\"Country\",\"value\":\"Finland\"},{\"key\":\"CountryCode\",\"value\":\"FI\"},{\"key\":\"Location\",\"value\":\"Helsinki (Helsingfors)\"},{\"key\":\"Price\",\"value\":\"44\"},{\"key\":\"SubDiv\",\"value\":\"Uusimaa\"},{\"key\":\"SubDivCode\",\"value\":\"18\"},{\"key\":\"UN-LOCODE\",\"value\":\"FI HEL\"}],\"state\":\"Online\"}},{\"id\":1508609683428895200,\"capacity\":0,\"index\":2,\"price\":33,\"nodeinfo\":{\"publicKey\":\"A/9ltq55E0pNzp0NOdOFHpurTul6v4boHhxbvFDNKCau\",\"addresses\":[\"/dns4/s02.neofs.devenv/tcp/8080\"],\"attributes\":[{\"key\":\"Capacity\",\"value\":\"0\"},{\"key\":\"Continent\",\"value\":\"Europe\"},{\"key\":\"Country\",\"value\":\"Russia\"},{\"key\":\"CountryCode\",\"value\":\"RU\"},{\"key\":\"Location\",\"value\":\"Saint Petersburg (ex Leningrad)\"},{\"key\":\"Price\",\"value\":\"33\"},{\"key\":\"SubDiv\",\"value\":\"Sankt-Peterburg\"},{\"key\":\"SubDivCode\",\"value\":\"SPE\"},{\"key\":\"UN-LOCODE\",\"value\":\"RU LED\"}],\"state\":\"Online\"}},{\"id\":11537578107108880000,\"capacity\":0,\"index\":3,\"price\":11,\"nodeinfo\":{\"publicKey\":\"AqySDNffC2GyiQcua5RuLaThoxuascYhu0deMPpKsQLD\",\"addresses\":[\"/dns4/s03.neofs.devenv/tcp/8080\"],\"attributes\":[{\"key\":\"Capacity\",\"value\":\"0\"},{\"key\":\"Continent\",\"value\":\"Europe\"},{\"key\":\"Country\",\"value\":\"Sweden\"},{\"key\":\"CountryCode\",\"value\":\"SE\"},{\"key\":\"Location\",\"value\":\"Stockholm\"},{\"key\":\"Price\",\"value\":\"11\"},{\"key\":\"SubDiv\",\"value\":\"Stockholms l�n\"},{\"key\":\"SubDivCode\",\"value\":\"AB\"},{\"key\":\"UN-LOCODE\",\"value\":\"SE STO\"}],\"state\":\"Online\"}}]"; var cid = ContainerID.FromString("AaCymCBPpMYeagJcBAxcMHKRZ9GEZYHDfLKsV1FwqAma"); var oid1 = ObjectID.FromString("GMBa69wUJEgfoHnu37MKwudeYsemxHD38ynNsyuAZv2M"); PlacementPolicy policy = new(0, new Replica[] { new(2, "SPB") }, new Selector[] { new("SPB", "City", Clause.Unspecified, 1, "*") }, null);