From 8270245455f013f55c4081988ca64408301e429d Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 4 May 2020 14:00:25 +0300 Subject: [PATCH] service: transfer public types to a separate file --- service/alias.go | 12 +++- service/role.go | 3 - service/token.go | 56 ----------------- service/ttl.go | 4 -- service/types.go | 161 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 170 insertions(+), 66 deletions(-) create mode 100644 service/types.go diff --git a/service/alias.go b/service/alias.go index 6c22ecef..9a407027 100644 --- a/service/alias.go +++ b/service/alias.go @@ -4,11 +4,17 @@ import ( "github.com/nspcc-dev/neofs-api-go/refs" ) -// TokenID is type alias of UUID ref. +// TokenID is a type alias of UUID ref. type TokenID = refs.UUID -// OwnerID is type alias of OwnerID ref. +// OwnerID is a type alias of OwnerID ref. type OwnerID = refs.OwnerID -// Address is type alias of Address ref. +// Address is a type alias of Address ref. type Address = refs.Address + +// AddressContainer is a type alias of refs.AddressContainer. +type AddressContainer = refs.AddressContainer + +// OwnerIDContainer is a type alias of refs.OwnerIDContainer. +type OwnerIDContainer = refs.OwnerIDContainer diff --git a/service/role.go b/service/role.go index 53bcdf55..4c405c12 100644 --- a/service/role.go +++ b/service/role.go @@ -1,8 +1,5 @@ package service -// NodeRole to identify in Bootstrap service. -type NodeRole int32 - const ( _ NodeRole = iota // InnerRingNode that work like IR node. diff --git a/service/token.go b/service/token.go index ece44c26..2aa159b4 100644 --- a/service/token.go +++ b/service/token.go @@ -4,65 +4,9 @@ import ( "crypto/ecdsa" "encoding/binary" - "github.com/nspcc-dev/neofs-api-go/refs" crypto "github.com/nspcc-dev/neofs-crypto" ) -// VerbContainer is an interface of the container of a token verb value. -type VerbContainer interface { - GetVerb() Token_Info_Verb - SetVerb(Token_Info_Verb) -} - -// TokenIDContainer is an interface of the container of a token ID value. -type TokenIDContainer interface { - GetID() TokenID - SetID(TokenID) -} - -// CreationEpochContainer is an interface of the container of a creation epoch number. -type CreationEpochContainer interface { - CreationEpoch() uint64 - SetCreationEpoch(uint64) -} - -// ExpirationEpochContainer is an interface of the container of an expiration epoch number. -type ExpirationEpochContainer interface { - ExpirationEpoch() uint64 - SetExpirationEpoch(uint64) -} - -// SessionKeyContainer is an interface of the container of session key bytes. -type SessionKeyContainer interface { - GetSessionKey() []byte - SetSessionKey([]byte) -} - -// SignatureContainer is an interface of the container of signature bytes. -type SignatureContainer interface { - GetSignature() []byte - SetSignature([]byte) -} - -// SessionTokenInfo is an interface that determines the information scope of session token. -type SessionTokenInfo interface { - TokenIDContainer - refs.OwnerIDContainer - VerbContainer - refs.AddressContainer - CreationEpochContainer - ExpirationEpochContainer - SessionKeyContainer -} - -// SessionToken is an interface of token information and signature pair. -type SessionToken interface { - SessionTokenInfo - SignatureContainer -} - -var _ SessionToken = (*Token)(nil) - var tokenEndianness = binary.BigEndian // GetID is an ID field getter. diff --git a/service/ttl.go b/service/ttl.go index f069f547..c79cc85e 100644 --- a/service/ttl.go +++ b/service/ttl.go @@ -12,10 +12,6 @@ type TTLHeader interface { SetTTL(uint32) } -// TTLCondition is a function type that used to verify that TTL value match a specific criterion. -// Nil error indicates compliance with the criterion. -type TTLCondition func(ttl uint32) error - // TTL constants. const ( // ZeroTTL is an upper bound of invalid TTL values. diff --git a/service/types.go b/service/types.go new file mode 100644 index 00000000..cad4b3c4 --- /dev/null +++ b/service/types.go @@ -0,0 +1,161 @@ +package service + +// NodeRole to identify in Bootstrap service. +type NodeRole int32 + +// TTLCondition is a function type that used to verify that TTL values match a specific criterion. +// Nil error indicates compliance with the criterion. +type TTLCondition func(uint32) error + +// RawSource is an interface of the container of a boolean Raw value with read access. +type RawSource interface { + GetRaw() bool +} + +// RawContainer is an interface of the container of a boolean Raw value. +type RawContainer interface { + RawSource + SetRaw(bool) +} + +// VersionContainer is an interface of the container of a numerical Version value with read access. +type VersionSource interface { + GetVersion() uint32 +} + +// VersionContainer is an interface of the container of a numerical Version value. +type VersionContainer interface { + VersionSource + SetVersion(uint32) +} + +// EpochSource is an interface of the container of a NeoFS epoch number with read access. +type EpochSource interface { + GetEpoch() uint64 +} + +// EpochContainer is an interface of the container of a NeoFS epoch number. +type EpochContainer interface { + EpochSource + SetEpoch(uint64) +} + +// TTLSource is an interface of the container of a numerical TTL value with read access. +type TTLSource interface { + GetTTL() uint32 +} + +// TTLContainer is an interface of the container of a numerical TTL value. +type TTLContainer interface { + TTLSource + SetTTL(uint32) +} + +// RequestMetaContainer is an interface of a fixed set of request meta value containers. +// Contains: +// - TTL value; +// - NeoFS epoch number; +// - Protocol version; +// - Raw toggle option. +type RequestMetaContainer interface { + TTLContainer + EpochContainer + VersionContainer + RawContainer +} + +// VerbSource is an interface of the container of a token verb value with read access. +type VerbSource interface { + GetVerb() Token_Info_Verb +} + +// VerbContainer is an interface of the container of a token verb value. +type VerbContainer interface { + VerbSource + SetVerb(Token_Info_Verb) +} + +// TokenIDSource is an interface of the container of a token ID value with read access. +type TokenIDSource interface { + GetID() TokenID +} + +// TokenIDContainer is an interface of the container of a token ID value. +type TokenIDContainer interface { + TokenIDSource + SetID(TokenID) +} + +// CreationEpochSource is an interface of the container of a creation epoch number with read access. +type CreationEpochSource interface { + CreationEpoch() uint64 +} + +// CreationEpochContainer is an interface of the container of a creation epoch number. +type CreationEpochContainer interface { + CreationEpochSource + SetCreationEpoch(uint64) +} + +// ExpirationEpochSource is an interface of the container of an expiration epoch number with read access. +type ExpirationEpochSource interface { + ExpirationEpoch() uint64 +} + +// ExpirationEpochContainer is an interface of the container of an expiration epoch number. +type ExpirationEpochContainer interface { + ExpirationEpochSource + SetExpirationEpoch(uint64) +} + +// SessionKeySource is an interface of the container of session key bytes with read access. +type SessionKeySource interface { + GetSessionKey() []byte +} + +// SessionKeyContainer is an interface of the container of public session key bytes. +type SessionKeyContainer interface { + SessionKeySource + SetSessionKey([]byte) +} + +// SignatureSource is an interface of the container of signature bytes with read access. +type SignatureSource interface { + GetSignature() []byte +} + +// SignatureContainer is an interface of the container of signature bytes. +type SignatureContainer interface { + SignatureSource + SetSignature([]byte) +} + +// SessionTokenSource is an interface of the container of a SessionToken with read access. +type SessionTokenSource interface { + GetSessionToken() SessionToken +} + +// SessionTokenInfo is an interface of a fixed set of token information value containers. +// Contains: +// - ID of the token; +// - ID of the token's owner; +// - verb of the session; +// - address of the session object; +// - creation epoch number of the token; +// - expiration epoch number of the token; +// - public session key bytes. +type SessionTokenInfo interface { + TokenIDContainer + OwnerIDContainer + VerbContainer + AddressContainer + CreationEpochContainer + ExpirationEpochContainer + SessionKeyContainer +} + +// SessionToken is an interface of token information and signature pair. +type SessionToken interface { + SessionTokenInfo + SignatureContainer +}