示例#1
0
        public static ListResponse ListContainers(this Channel chan, uint ttl, ECDsa key, bool debug = false)
        {
            var req = new ListRequest
            {
                OwnerID = ByteString.CopyFrom(key.Address()),
            };

            req.SetTTL(ttl);
            req.SignHeader(key, debug);

            return(new Service.ServiceClient(chan).List(req));
        }
示例#2
0
        public static BalanceResponse GetBalance(this Channel chan, uint ttl, ECDsa key, bool debug = false)
        {
            var req = new BalanceRequest
            {
                OwnerID = ByteString.CopyFrom(key.Address()),
            };

            req.SetTTL(ttl);
            req.SignHeader(key, debug);

            return(new Accounting.AccountingClient(chan).Balance(req));
        }
示例#3
0
        public static Object Prepare(byte[] cid, byte[] oid, ulong size, ECDsa key)
        {
            byte[] owner = key.Address();

            return(new Object
            {
                SystemHeader = new SystemHeader
                {
                    ID = ByteString.CopyFrom(oid),
                    CID = ByteString.CopyFrom(cid),
                    OwnerID = ByteString.CopyFrom(owner),
                    PayloadLength = size,
                    CreatedAt = new CreationPoint
                    {
                        UnixTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds(),
                    }
                },
            });
        }
示例#4
0
        public static async Task <DeleteResponse> ObjectDelete(this Channel chan, byte[] cid, Guid oid, uint ttl, ECDsa key, bool debug = false)
        {
            var token = await chan.EstablishSession(oid, ttl, key, debug);

            var req = new DeleteRequest
            {
                Token   = token,
                OwnerID = ByteString.CopyFrom(key.Address()),
                Address = new Refs.Address
                {
                    CID      = ByteString.CopyFrom(cid),
                    ObjectID = ByteString.CopyFrom(oid.Bytes()),
                },
            };

            req.SetTTL(ttl);
            req.SignHeader(key, debug);

            return(new Service.ServiceClient(chan).Delete(req));
        }
示例#5
0
        public static PutResponse PutContainer(this Channel chan, int size, uint basicACL, uint ttl, ECDsa key, bool debug = false)
        {
            Netmap.PlacementRule rules;

            { // hardcoded placement rule:
                rules = new Netmap.PlacementRule {
                    ReplFactor = 2
                };

                var group     = new Netmap.SFGroup();
                var selectors = new Google.Protobuf.Collections.RepeatedField <Netmap.Select>();

                selectors.Add(
                    new Netmap.Select
                {
                    Count = 3,
                    Key   = "Node",
                });

                group.Selectors.Add(selectors);
                rules.SFGroups.Add(group);
            }

            var req = new PutRequest
            {
                Rules     = rules,
                BasicACL  = basicACL,
                Capacity  = Units.GB * (ulong)size,
                OwnerID   = ByteString.CopyFrom(key.Address()),
                MessageID = ByteString.CopyFrom(new Guid().Bytes()),
            };

            req.SetTTL(ttl);
            req.SignHeader(key, debug);

            return(new Service.ServiceClient(chan).Put(req));
        }
示例#6
0
        public static async Task <Token> EstablishSession(this Channel chan, byte[] oid, uint ttl, ECDsa key, bool debug = false)
        {
            var tkn = new Session.SessionClient(chan).Create();

            // Prepare Session and Token:
            var publey = ByteString.CopyFrom(key.Peer());
            var owner  = ByteString.CopyFrom(key.Address());
            var empty  = new byte[0];

            var token = new Token
            {
                OwnerID    = owner,
                LastEpoch  = ulong.MaxValue,
                FirstEpoch = ulong.MinValue,

                // empty TokenID
                ID = ByteString.CopyFrom(new byte[16]),

                // initialize verification header
                Header = new VerificationHeader
                {
                    PublicKey    = ByteString.CopyFrom(empty),
                    KeySignature = ByteString.CopyFrom(empty),
                },
            };

            // Set Owner ID:
            token.PublicKeys.Add(publey);

            // Set Object ID:
            token.ObjectID.Add(ByteString.CopyFrom(oid));

            // Send token to node
            await tkn.RequestStream.WriteAsync(token.PrepareInit(ttl, key, debug));

            // Wait to complete request
            await tkn.ResponseStream.MoveNext();

            // Receive session token
            var response = tkn.ResponseStream.Current;

            if (!response.Unsigned.IsSame(token))
            {
                throw new Exception("wrong token received");
            }


            // Sign received token
            token = response.Unsigned;
            token.Sign(key);

            // Send signed token
            await tkn.RequestStream.WriteAsync(token.PrepareSigned(ttl, key, debug));;

            // Wait to complete request
            await tkn.ResponseStream.MoveNext();

            await tkn.RequestStream.CompleteAsync();

            // Store received token:
            return(tkn.ResponseStream.Current.Result);
        }
示例#7
0
 public static string ToAddress(this ECDsa key)
 {
     return(Base58.Encode(key.Address()));
 }