Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        public void TestObjectPut()
        {
            var rand    = new Random();
            var payload = new byte[1024];

            rand.NextBytes(payload);
            var obj = new FSObject
            {
                Header = new Header
                {
                    OwnerId     = OwnerID.FromScriptHash(key.PublicKey().PublicKeyToScriptHash()),
                    ContainerId = cid,
                },
                Payload = ByteString.CopyFrom(payload),
            };

            using var client = new Client.Client(key, host);
            using var source = new CancellationTokenSource();
            source.CancelAfter(TimeSpan.FromMinutes(10));
            var session = client.CreateSession(20).Result;
            var o       = client.PutObject(obj, new CallOptions {
                Ttl = 1, Session = session
            }, source.Token).Result;

            Console.WriteLine(o.String());
            Assert.AreNotEqual("", o.String());
        }
Exemplo n.º 3
0
        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());
Exemplo n.º 4
0
        public void TestObjectPut()
        {
            var host    = "localhost:8080";
            var key     = "KxDgvEKzgSBPPfuVfw67oPQBSjidEiqTHURKSDL1R7yGaGYAeYnr".LoadWif();
            var cid     = ContainerID.FromBase58String("RuzuV3RDstuVtWoDzsTsuNFiakaaGGN24EbNSUFGaiQ");
            var payload = Encoding.ASCII.GetBytes("hello");
            var obj     = new V2Object
            {
                Header = new Header
                {
                    OwnerId     = key.ToOwnerID(),
                    ContainerId = cid,
                },
                Payload = ByteString.CopyFrom(payload),
            };
            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.PutObject(source2.Token, new PutObjectParams {
                Object = obj
            }, new CallOptions {
                Ttl = 2, Session = session
            }).Result;

            Console.WriteLine(o.ToBase58String());
            Assert.AreNotEqual("", o.ToBase58String());
        }
Exemplo n.º 5
0
        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));
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        public void TestSessionCreate()
        {
            using var client = new Client.Client(key, host);
            using var source = new CancellationTokenSource();
            source.CancelAfter(10000);
            var token = client.CreateSession(ulong.MaxValue, context: source.Token).Result;

            Assert.AreEqual(OwnerID.FromScriptHash(key.PublicKey().PublicKeyToScriptHash()), token.Body.OwnerId);
            Console.WriteLine($"id={token.Body.Id.ToUUID()}, key={token.Body.SessionKey.ToByteArray().ToHexString()}");
        }
Exemplo n.º 9
0
        public void TestSessionCreate()
        {
            var host   = "localhost:8080";
            var key    = "KxDgvEKzgSBPPfuVfw67oPQBSjidEiqTHURKSDL1R7yGaGYAeYnr".LoadWif();
            var client = new Client.Client(key, host);
            var source = new CancellationTokenSource();

            source.CancelAfter(10000);
            var token = client.CreateSession(source.Token, ulong.MaxValue);

            Assert.AreEqual(key.ToOwnerID(), token.Body.OwnerId);
            Console.WriteLine($"id={token.Body.Id.ToUUID()}, key={token.Body.SessionKey.ToByteArray().ToHexString()}");
        }
Exemplo n.º 10
0
        public void TestObjectDelete()
        {
            using var client  = new Client.Client(key, host);
            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.DeleteObject(Address, new CallOptions {
                Ttl = 2, Session = session
            }, source2.Token).Result;

            Assert.IsNotNull(o);
            Console.WriteLine(o.ObjectId.String());
        }
Exemplo n.º 11
0
        public void TestObjectPutStream()
        {
            string path    = "objectputstream.data";
            var    rand    = new Random();
            var    payload = new byte[1024];

            rand.NextBytes(payload);
            var file = File.Create(path);

            file.Write(payload, 0, 1024);
            file.Flush();
            file.Seek(0, SeekOrigin.Begin);
            var obj = new FSObject
            {
                Header = new Header
                {
                    OwnerId     = OwnerID.FromScriptHash(key.PublicKey().PublicKeyToScriptHash()),
                    ContainerId = cid,
                },
            };

            obj.Attributes.Add(new Header.Types.Attribute
            {
                Key   = "category",
                Value = "test"
            });
            using var client = new Client.Client(key, host);
            using var source = new CancellationTokenSource();
            source.CancelAfter(TimeSpan.FromMinutes(10));
            var session = client.CreateSession(20).Result;
            var o       = client.PutObject(obj.Header, file, new CallOptions {
                Ttl = 1, Session = session
            }, source.Token).Result;

            Console.WriteLine(o.String());
            Assert.AreNotEqual("", o.String());
            File.Delete(path);
        }
Exemplo n.º 12
0
        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());
        }