forked from TrueCloudLab/frostfs-api-go
[#367] session: Support magic_number
field of RequestMetaHeader
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
e9a8451fb7
commit
227a871a04
5 changed files with 47 additions and 1 deletions
|
@ -389,6 +389,7 @@ func (r *RequestMetaHeader) ToGRPCMessage() grpc.Message {
|
|||
m.SetEpoch(r.epoch)
|
||||
m.SetTtl(r.ttl)
|
||||
m.SetOrigin(r.origin.ToGRPCMessage().(*session.RequestMetaHeader))
|
||||
m.SetNetworkMagic(r.netMagic)
|
||||
}
|
||||
|
||||
return m
|
||||
|
@ -465,6 +466,7 @@ func (r *RequestMetaHeader) FromGRPCMessage(m grpc.Message) error {
|
|||
|
||||
r.epoch = v.GetEpoch()
|
||||
r.ttl = v.GetTtl()
|
||||
r.netMagic = v.GetNetworkMagic()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
func (m *ResponseMetaHeader) SetVersion(v *refs.Version) {
|
||||
if m != nil {
|
||||
|
|
|
@ -41,6 +41,7 @@ const (
|
|||
reqMetaHeaderSessionTokenField = 5
|
||||
reqMetaHeaderBearerTokenField = 6
|
||||
reqMetaHeaderOriginField = 7
|
||||
reqMetaHeaderNetMagicField = 8
|
||||
|
||||
reqVerifHeaderBodySignatureField = 1
|
||||
reqVerifHeaderMetaSignatureField = 2
|
||||
|
@ -564,7 +565,14 @@ func (r *RequestMetaHeader) StableMarshal(buf []byte) ([]byte, error) {
|
|||
|
||||
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 {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -591,6 +599,7 @@ func (r *RequestMetaHeader) StableSize() (size int) {
|
|||
size += proto.NestedStructureSize(reqMetaHeaderSessionTokenField, r.sessionToken)
|
||||
size += proto.NestedStructureSize(reqMetaHeaderBearerTokenField, r.bearerToken)
|
||||
size += proto.NestedStructureSize(reqMetaHeaderOriginField, r.origin)
|
||||
size += proto.UInt64Size(reqMetaHeaderNetMagicField, r.netMagic)
|
||||
|
||||
return size
|
||||
}
|
||||
|
|
|
@ -130,6 +130,7 @@ func generateRequestMetaHeader(empty, withOrigin bool) *session.RequestMetaHeade
|
|||
if !empty {
|
||||
m.SetEpoch(13)
|
||||
m.SetTTL(100)
|
||||
m.SetNetworkMagic(1337)
|
||||
}
|
||||
|
||||
m.SetXHeaders(GenerateXHeaders(empty))
|
||||
|
|
|
@ -88,6 +88,8 @@ type RequestMetaHeader struct {
|
|||
bearerToken *acl.BearerToken
|
||||
|
||||
origin *RequestMetaHeader
|
||||
|
||||
netMagic uint64
|
||||
}
|
||||
|
||||
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 {
|
||||
if l != nil {
|
||||
return l.exp
|
||||
|
|
Loading…
Reference in a new issue