From 5fc2644c680d04f8f56df3f33562764f7155e922 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Fri, 16 Sep 2022 19:09:25 +0400 Subject: [PATCH] [#416] session: Support new format of object session context Signed-off-by: Leonard Lyubich --- netmap/grpc/types.pb.go | Bin 45526 -> 45734 bytes object/grpc/service_grpc.pb.go | Bin 31238 -> 31238 bytes session/convert.go | 19 +++++++---- session/grpc/types.go | 9 +++-- session/grpc/types.pb.go | Bin 53262 -> 56844 bytes session/marshal.go | 18 ++++++---- session/test/generate.go | 2 +- session/types.go | 58 ++++++++++++++++++++++++++++++--- 8 files changed, 83 insertions(+), 23 deletions(-) diff --git a/netmap/grpc/types.pb.go b/netmap/grpc/types.pb.go index 265bc243c8b6b6316641176ecd846316d33b1d04..c34f6bb0ebaf2244b9d4017399f9cc1349e6ee5e 100644 GIT binary patch delta 219 zcmX|*OA5k342D5)<0-Ne1lu!+3NCyg;@ZYG#lUo?Oj4>V58)kLxe&aI7ZC5^_-YnE z{Dgd8?vK{_*}6u_DcQ7-9`%PA^5 zD^RoUfPMf-4U<)g{*>Xj!)mfvPe)J*f$k_I1{H~r0Ou1Zod|CYHFvX0G?=U+TfmPK Z`$8pp)bNYpuy#2Vl~L|DtXnU+EMHj_O=kcA delta 14 WcmZ4Xl$<6cC*~M}CrPZMg)i0Bu@_m|oBwlW_p}PslMHqhCeAa6b%&92;*&OQM2$R6{ i!>6DmWanY^!{pW^v&}an!jKih{Q(Sm!OdcEAEW_uO_z`W delta 390 zcmZqs!r1nOaf3PgIyZmcVJj{V8 cE@#%`;+$NYWViWdL>No~k`Fd>#Ql>70N%lzT>t<8 diff --git a/session/convert.go b/session/convert.go index d7662b4d..b9a93e66 100644 --- a/session/convert.go +++ b/session/convert.go @@ -674,7 +674,7 @@ func (c *ObjectSessionContext) ToGRPCMessage() grpc.Message { m = new(session.ObjectSessionContext) m.SetVerb(ObjectSessionVerbToGRPCField(c.verb)) - m.SetAddress(c.addr.ToGRPCMessage().(*refsGRPC.Address)) + m.SetTarget(c.cnr.ToGRPCMessage().(*refsGRPC.ContainerID), refs.ObjectIDListToGRPCMessage(c.objs)) } return m @@ -688,20 +688,25 @@ func (c *ObjectSessionContext) FromGRPCMessage(m grpc.Message) error { var err error - addr := v.GetAddress() - if addr == nil { - c.addr = nil + cnr := v.GetTarget().GetContainer() + if cnr == nil { + c.cnr = nil } else { - if c.addr == nil { - c.addr = new(refs.Address) + if c.cnr == nil { + c.cnr = new(refs.ContainerID) } - err = c.addr.FromGRPCMessage(addr) + err = c.cnr.FromGRPCMessage(cnr) if err != nil { return err } } + c.objs, err = refs.ObjectIDListFromGRPCMessage(v.GetTarget().GetObjects()) + if err != nil { + return err + } + c.verb = ObjectSessionVerbFromGRPCField(v.GetVerb()) return nil diff --git a/session/grpc/types.go b/session/grpc/types.go index 64133a8d..7cdb7d51 100644 --- a/session/grpc/types.go +++ b/session/grpc/types.go @@ -65,9 +65,12 @@ func (m *SessionToken_Body) SetContainerSessionContext(v *ContainerSessionContex } } -// SetAddress sets address of the object related to the session. -func (m *ObjectSessionContext) SetAddress(v *refs.Address) { - m.Address = v +// SetTarget specifies objects involved in the object session. +func (m *ObjectSessionContext) SetTarget(cnr *refs.ContainerID, objs []*refs.ObjectID) { + m.Target = &ObjectSessionContext_Target{ + Container: cnr, + Objects: objs, + } } // SetVerb sets type of request for which the token is issued. diff --git a/session/grpc/types.pb.go b/session/grpc/types.pb.go index 81b3f048d172dc8244fe57a6cf3d0300e86fbdcc..c964738d16746dd132051d439f6e295f092de22f 100644 GIT binary patch delta 4291 zcmai1dr+L!6(0yJ>}HejTwYo7@hAjl1N#6LVk2gRU|tRB+EFGZu)tzA!tS!WyxBk= z5(0q*erOPaK%QVm^B@{q8-k8)9it{4+d8eSgGTL4r<0PI>e#BW=icvIz}RX3f%~0% z?>Xo9JHK=G`+CQh9sA|7ixc5(JIeQ2D%^t0;&NH-HoR42o-jx zllH5dgetqU#!@MmZIyJGPHe6c%Iy5It4tx!%oM7umg-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hZXXfV~k=XlG;gBdkl?wvOw zc07eikfR_4|2iea`{S>%MtFofe$GzjYY5l)0eTQVy(K_`60c51V#h>28NRUr_)=GW z0>qO!YxpUd%wwEC#%jc2UnptfxByQ2>Z9|(N;nYXo2dde`1un=%RVcK9fRAxJXie& zoO(}(A4ft+yKMR|;F2z@Ss??Oq+R~XWlq6?(P*YRFcd?5NrC0dSxl%FW;8M_k}W#I z?=}hX(*+flyVB6RVC2-nBu?XCWr2+j->wg;*YR~4VYR&i<$`!De=YPq_;t;Cd{QF8 zmsgbd-EZaCwKBjmu*08(cz*=y{9c{`+H2{--1lB3?AM}1YyB~J?HiuX=lu9`a4^A6VjHmSLz;mU z=IiMptNGLZYBj2UsgfM0kLV@9#P|l@zp2g=`iWfrrnFz}z8}MM|3VK)el8?%8D8E?b SW%_P?v4=+xrF``V-oF70%=df% diff --git a/session/marshal.go b/session/marshal.go index d7db4d21..2c82179b 100644 --- a/session/marshal.go +++ b/session/marshal.go @@ -21,8 +21,8 @@ const ( lifetimeNotValidBeforeField = 2 lifetimeIssuedAtField = 3 - objectCtxVerbField = 1 - objectCtxAddressField = 2 + objectCtxVerbField = 1 + objectCtxTargetField = 2 sessionTokenBodyIDField = 1 sessionTokenBodyOwnerField = 2 @@ -210,10 +210,11 @@ func (c *ObjectSessionContext) StableMarshal(buf []byte) []byte { buf = make([]byte, c.StableSize()) } - var offset int - - offset += proto.EnumMarshal(objectCtxVerbField, buf[offset:], int32(c.verb)) - proto.NestedStructureMarshal(objectCtxAddressField, buf[offset:], c.addr) + offset := proto.EnumMarshal(objectCtxVerbField, buf, int32(c.verb)) + proto.NestedStructureMarshal(objectCtxTargetField, buf[offset:], &objectSessionContextTarget{ + cnr: c.cnr, + objs: c.objs, + }) return buf } @@ -224,7 +225,10 @@ func (c *ObjectSessionContext) StableSize() (size int) { } size += proto.EnumSize(objectCtxVerbField, int32(c.verb)) - size += proto.NestedStructureSize(objectCtxAddressField, c.addr) + size += proto.NestedStructureSize(objectCtxTargetField, &objectSessionContextTarget{ + cnr: c.cnr, + objs: c.objs, + }) return size } diff --git a/session/test/generate.go b/session/test/generate.go index 25976bce..8bb2c82c 100644 --- a/session/test/generate.go +++ b/session/test/generate.go @@ -195,7 +195,7 @@ func GenerateObjectSessionContext(empty bool) *session.ObjectSessionContext { if !empty { m.SetVerb(session.ObjectVerbHead) - m.SetAddress(refstest.GenerateAddress(false)) + m.SetTarget(refstest.GenerateContainerID(false), refstest.GenerateObjectIDs(false)...) } return m diff --git a/session/types.go b/session/types.go index dfa8c5e8..cb148254 100644 --- a/session/types.go +++ b/session/types.go @@ -4,6 +4,7 @@ import ( "github.com/nspcc-dev/neofs-api-go/v2/acl" "github.com/nspcc-dev/neofs-api-go/v2/refs" "github.com/nspcc-dev/neofs-api-go/v2/status" + "github.com/nspcc-dev/neofs-api-go/v2/util/proto" ) type CreateRequestBody struct { @@ -40,10 +41,48 @@ type TokenLifetime struct { type ObjectSessionVerb uint32 +type objectSessionContextTarget struct { + cnr *refs.ContainerID + + objs []refs.ObjectID +} + +const ( + _ = iota + fNumObjectTargetContainer + fNumObjectTargetObjects +) + +func (x objectSessionContextTarget) StableMarshal(buf []byte) []byte { + if buf == nil { + buf = make([]byte, x.StableSize()) + } + + offset := proto.NestedStructureMarshal(fNumObjectTargetContainer, buf, x.cnr) + + for i := range x.objs { + offset += proto.NestedStructureMarshal(fNumObjectTargetObjects, buf[offset:], &x.objs[i]) + } + + return buf +} + +func (x objectSessionContextTarget) StableSize() (size int) { + size += proto.NestedStructureSize(fNumObjectTargetContainer, x.cnr) + + for i := range x.objs { + size += proto.NestedStructureSize(fNumObjectTargetObjects, &x.objs[i]) + } + + return size +} + type ObjectSessionContext struct { verb ObjectSessionVerb - addr *refs.Address + cnr *refs.ContainerID + + objs []refs.ObjectID } type TokenContext interface { @@ -617,16 +656,25 @@ func (c *ObjectSessionContext) SetVerb(v ObjectSessionVerb) { c.verb = v } -func (c *ObjectSessionContext) GetAddress() *refs.Address { +func (c *ObjectSessionContext) GetContainer() *refs.ContainerID { if c != nil { - return c.addr + return c.cnr } return nil } -func (c *ObjectSessionContext) SetAddress(v *refs.Address) { - c.addr = v +func (c *ObjectSessionContext) GetObjects() []refs.ObjectID { + if c != nil { + return c.objs + } + + return nil +} + +func (c *ObjectSessionContext) SetTarget(cnr *refs.ContainerID, objs ...refs.ObjectID) { + c.cnr = cnr + c.objs = objs } func (t *TokenBody) GetID() []byte {