[#416] session: Support new format of object session context

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2022-09-16 19:09:25 +04:00 committed by LeL
parent 504e427c18
commit 5fc2644c68
8 changed files with 83 additions and 23 deletions

BIN
netmap/grpc/types.pb.go generated

Binary file not shown.

Binary file not shown.

View file

@ -674,7 +674,7 @@ func (c *ObjectSessionContext) ToGRPCMessage() grpc.Message {
m = new(session.ObjectSessionContext) m = new(session.ObjectSessionContext)
m.SetVerb(ObjectSessionVerbToGRPCField(c.verb)) 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 return m
@ -688,20 +688,25 @@ func (c *ObjectSessionContext) FromGRPCMessage(m grpc.Message) error {
var err error var err error
addr := v.GetAddress() cnr := v.GetTarget().GetContainer()
if addr == nil { if cnr == nil {
c.addr = nil c.cnr = nil
} else { } else {
if c.addr == nil { if c.cnr == nil {
c.addr = new(refs.Address) c.cnr = new(refs.ContainerID)
} }
err = c.addr.FromGRPCMessage(addr) err = c.cnr.FromGRPCMessage(cnr)
if err != nil { if err != nil {
return err return err
} }
} }
c.objs, err = refs.ObjectIDListFromGRPCMessage(v.GetTarget().GetObjects())
if err != nil {
return err
}
c.verb = ObjectSessionVerbFromGRPCField(v.GetVerb()) c.verb = ObjectSessionVerbFromGRPCField(v.GetVerb())
return nil return nil

View file

@ -65,9 +65,12 @@ func (m *SessionToken_Body) SetContainerSessionContext(v *ContainerSessionContex
} }
} }
// SetAddress sets address of the object related to the session. // SetTarget specifies objects involved in the object session.
func (m *ObjectSessionContext) SetAddress(v *refs.Address) { func (m *ObjectSessionContext) SetTarget(cnr *refs.ContainerID, objs []*refs.ObjectID) {
m.Address = v m.Target = &ObjectSessionContext_Target{
Container: cnr,
Objects: objs,
}
} }
// SetVerb sets type of request for which the token is issued. // SetVerb sets type of request for which the token is issued.

BIN
session/grpc/types.pb.go generated

Binary file not shown.

View file

@ -22,7 +22,7 @@ const (
lifetimeIssuedAtField = 3 lifetimeIssuedAtField = 3
objectCtxVerbField = 1 objectCtxVerbField = 1
objectCtxAddressField = 2 objectCtxTargetField = 2
sessionTokenBodyIDField = 1 sessionTokenBodyIDField = 1
sessionTokenBodyOwnerField = 2 sessionTokenBodyOwnerField = 2
@ -210,10 +210,11 @@ func (c *ObjectSessionContext) StableMarshal(buf []byte) []byte {
buf = make([]byte, c.StableSize()) buf = make([]byte, c.StableSize())
} }
var offset int offset := proto.EnumMarshal(objectCtxVerbField, buf, int32(c.verb))
proto.NestedStructureMarshal(objectCtxTargetField, buf[offset:], &objectSessionContextTarget{
offset += proto.EnumMarshal(objectCtxVerbField, buf[offset:], int32(c.verb)) cnr: c.cnr,
proto.NestedStructureMarshal(objectCtxAddressField, buf[offset:], c.addr) objs: c.objs,
})
return buf return buf
} }
@ -224,7 +225,10 @@ func (c *ObjectSessionContext) StableSize() (size int) {
} }
size += proto.EnumSize(objectCtxVerbField, int32(c.verb)) 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 return size
} }

View file

@ -195,7 +195,7 @@ func GenerateObjectSessionContext(empty bool) *session.ObjectSessionContext {
if !empty { if !empty {
m.SetVerb(session.ObjectVerbHead) m.SetVerb(session.ObjectVerbHead)
m.SetAddress(refstest.GenerateAddress(false)) m.SetTarget(refstest.GenerateContainerID(false), refstest.GenerateObjectIDs(false)...)
} }
return m return m

View file

@ -4,6 +4,7 @@ import (
"github.com/nspcc-dev/neofs-api-go/v2/acl" "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/refs"
"github.com/nspcc-dev/neofs-api-go/v2/status" "github.com/nspcc-dev/neofs-api-go/v2/status"
"github.com/nspcc-dev/neofs-api-go/v2/util/proto"
) )
type CreateRequestBody struct { type CreateRequestBody struct {
@ -40,10 +41,48 @@ type TokenLifetime struct {
type ObjectSessionVerb uint32 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 { type ObjectSessionContext struct {
verb ObjectSessionVerb verb ObjectSessionVerb
addr *refs.Address cnr *refs.ContainerID
objs []refs.ObjectID
} }
type TokenContext interface { type TokenContext interface {
@ -617,16 +656,25 @@ func (c *ObjectSessionContext) SetVerb(v ObjectSessionVerb) {
c.verb = v c.verb = v
} }
func (c *ObjectSessionContext) GetAddress() *refs.Address { func (c *ObjectSessionContext) GetContainer() *refs.ContainerID {
if c != nil { if c != nil {
return c.addr return c.cnr
} }
return nil return nil
} }
func (c *ObjectSessionContext) SetAddress(v *refs.Address) { func (c *ObjectSessionContext) GetObjects() []refs.ObjectID {
c.addr = v 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 { func (t *TokenBody) GetID() []byte {