[#367] session: Support magic_number field of RequestMetaHeader

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2022-01-13 15:25:03 +03:00 committed by LeL
parent e9a8451fb7
commit 227a871a04
5 changed files with 47 additions and 1 deletions

View file

@ -389,6 +389,7 @@ func (r *RequestMetaHeader) ToGRPCMessage() grpc.Message {
m.SetEpoch(r.epoch) m.SetEpoch(r.epoch)
m.SetTtl(r.ttl) m.SetTtl(r.ttl)
m.SetOrigin(r.origin.ToGRPCMessage().(*session.RequestMetaHeader)) m.SetOrigin(r.origin.ToGRPCMessage().(*session.RequestMetaHeader))
m.SetNetworkMagic(r.netMagic)
} }
return m return m
@ -465,6 +466,7 @@ func (r *RequestMetaHeader) FromGRPCMessage(m grpc.Message) error {
r.epoch = v.GetEpoch() r.epoch = v.GetEpoch()
r.ttl = v.GetTtl() r.ttl = v.GetTtl()
r.netMagic = v.GetNetworkMagic()
return nil return nil
} }

View file

@ -185,6 +185,22 @@ func (m *RequestMetaHeader) SetOrigin(v *RequestMetaHeader) {
} }
} }
// GetNetworkMagic returns NeoFS network magic.
func (m *RequestMetaHeader) GetNetworkMagic() uint64 {
if m != nil {
return m.MagicNumber
}
return 0
}
// SetNetworkMagic sets NeoFS network magic.
func (m *RequestMetaHeader) SetNetworkMagic(v uint64) {
if m != nil {
m.MagicNumber = v
}
}
// SetVersion sets server protocol version. // SetVersion sets server protocol version.
func (m *ResponseMetaHeader) SetVersion(v *refs.Version) { func (m *ResponseMetaHeader) SetVersion(v *refs.Version) {
if m != nil { if m != nil {

View file

@ -41,6 +41,7 @@ const (
reqMetaHeaderSessionTokenField = 5 reqMetaHeaderSessionTokenField = 5
reqMetaHeaderBearerTokenField = 6 reqMetaHeaderBearerTokenField = 6
reqMetaHeaderOriginField = 7 reqMetaHeaderOriginField = 7
reqMetaHeaderNetMagicField = 8
reqVerifHeaderBodySignatureField = 1 reqVerifHeaderBodySignatureField = 1
reqVerifHeaderMetaSignatureField = 2 reqVerifHeaderMetaSignatureField = 2
@ -564,7 +565,14 @@ func (r *RequestMetaHeader) StableMarshal(buf []byte) ([]byte, error) {
offset += n offset += n
_, err = proto.NestedStructureMarshal(reqMetaHeaderOriginField, buf[offset:], r.origin) n, err = proto.NestedStructureMarshal(reqMetaHeaderOriginField, buf[offset:], r.origin)
if err != nil {
return nil, err
}
offset += n
_, err = proto.UInt64Marshal(reqMetaHeaderNetMagicField, buf[offset:], r.netMagic)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -591,6 +599,7 @@ func (r *RequestMetaHeader) StableSize() (size int) {
size += proto.NestedStructureSize(reqMetaHeaderSessionTokenField, r.sessionToken) size += proto.NestedStructureSize(reqMetaHeaderSessionTokenField, r.sessionToken)
size += proto.NestedStructureSize(reqMetaHeaderBearerTokenField, r.bearerToken) size += proto.NestedStructureSize(reqMetaHeaderBearerTokenField, r.bearerToken)
size += proto.NestedStructureSize(reqMetaHeaderOriginField, r.origin) size += proto.NestedStructureSize(reqMetaHeaderOriginField, r.origin)
size += proto.UInt64Size(reqMetaHeaderNetMagicField, r.netMagic)
return size return size
} }

View file

@ -130,6 +130,7 @@ func generateRequestMetaHeader(empty, withOrigin bool) *session.RequestMetaHeade
if !empty { if !empty {
m.SetEpoch(13) m.SetEpoch(13)
m.SetTTL(100) m.SetTTL(100)
m.SetNetworkMagic(1337)
} }
m.SetXHeaders(GenerateXHeaders(empty)) m.SetXHeaders(GenerateXHeaders(empty))

View file

@ -88,6 +88,8 @@ type RequestMetaHeader struct {
bearerToken *acl.BearerToken bearerToken *acl.BearerToken
origin *RequestMetaHeader origin *RequestMetaHeader
netMagic uint64
} }
type ResponseVerificationHeader struct { type ResponseVerificationHeader struct {
@ -443,6 +445,22 @@ func (r *RequestMetaHeader) SetOrigin(v *RequestMetaHeader) {
} }
} }
// GetNetworkMagic returns NeoFS network magic.
func (r *RequestMetaHeader) GetNetworkMagic() uint64 {
if r != nil {
return r.netMagic
}
return 0
}
// SetNetworkMagic sets NeoFS network magic.
func (r *RequestMetaHeader) SetNetworkMagic(v uint64) {
if r != nil {
r.netMagic = v
}
}
func (l *TokenLifetime) GetExp() uint64 { func (l *TokenLifetime) GetExp() uint64 {
if l != nil { if l != nil {
return l.exp return l.exp