cdb

package
v0.0.0-...-f223905 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 23, 2020 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Day   = time.Hour * 24
	Month = Day * 31
	Year  = Day * 365
)

Variables

View Source
var (
	NO_COMPRESSION = &NoCompression{}

	LZ4      = &LZ4Compressor{}
	LZ4_HIGH = &LZ4HighCompressor{}
	SNAPPY   = &SnappyCompressor{}

	KnownCompressors = map[string]Compressor{
		"LZ4":      LZ4,
		"LZ4_HIGH": LZ4_HIGH,
		"SNAPPY":   SNAPPY,
	}
)
View Source
var (
	NO_ENCRYPTION = &NoBlockCipher{}

	AES = &AESBlockCipher{256}

	NO_ENCRYPTION_MODE = &NoCipherMode{}

	GCM = &GCMCipherMode{}
	CFB = &CFBCipherMode{}

	KnownCiphers = map[string]Cipher{
		"AES": AES,
	}

	KnownCipherModes = map[string]CipherMode{
		"GCM": GCM,
		"CFB": CFB,
	}
)
View Source
var (
	ErrorInvalidKeyLength = errors.New("invalid key length")
)

Functions

func CopyOf

func CopyOf(src []byte) []byte

func CountFilesInDir

func CountFilesInDir(dir, ext string) int

func CreateDirsIfNotExist

func CreateDirsIfNotExist(dirs ...string) error

func DecodeMetadata

func DecodeMetadata(metadata int32) (Compressor, Cipher, CipherMode)

func GetTimeUUID

func GetTimeUUID(key *pb.Key) timeuuid.UUID

func MaxInt

func MaxInt(x, y int) int

func PackValue

func PackValue(key Key, value []byte, compressor Compressor, cipher Cipher, cipherMode CipherMode, keychain Keychain) (output []byte, err error)

func ParseTtlExpr

func ParseTtlExpr(ttlExpr string) (ttl time.Duration, err error)

func ToPrintable

func ToPrintable(data []byte) interface{}

func UnpackValue

func UnpackValue(key Key, value []byte, compressor Compressor, cipher Cipher, cipherMode CipherMode, keychain Keychain) (output []byte, err error)

func VerboseMetadata

func VerboseMetadata(metadata int32) string

Types

type AESBlockCipher

type AESBlockCipher struct {
	// contains filtered or unexported fields
}

func (*AESBlockCipher) Create

func (this *AESBlockCipher) Create(key []byte) (cipher.Block, error)

func (*AESBlockCipher) KeyLengthBits

func (this *AESBlockCipher) KeyLengthBits() int

func (*AESBlockCipher) MetadataFlag

func (this *AESBlockCipher) MetadataFlag() int32

func (*AESBlockCipher) String

func (this *AESBlockCipher) String() string

type Block

type Block []Record

func ParseBlock

func ParseBlock(block *pb.Block, keychain Keychain) (Block, error)

type BlockKey

type BlockKey []byte

type CFBCipherMode

type CFBCipherMode struct {
}

func (*CFBCipherMode) Decrypt

func (this *CFBCipherMode) Decrypt(block cipher.Block, ciphertext []byte) ([]byte, error)

func (*CFBCipherMode) Encrypt

func (this *CFBCipherMode) Encrypt(block cipher.Block, plaintext []byte) ([]byte, error)

func (*CFBCipherMode) MetadataFlag

func (this *CFBCipherMode) MetadataFlag() int32

func (*CFBCipherMode) String

func (this *CFBCipherMode) String() string

type Cipher

type Cipher interface {
	MetadataFlag() int32

	KeyLengthBits() int

	Create(key []byte) (cipher.Block, error)
}

type CipherMode

type CipherMode interface {
	MetadataFlag() int32

	Encrypt(block cipher.Block, plaintext []byte) ([]byte, error)

	Decrypt(block cipher.Block, ciphertext []byte) ([]byte, error)
}

type Client

type Compressor

type Compressor interface {
	MetadataFlag() int32
	Compress(input []byte) ([]byte, error)
	Decompress(input []byte) ([]byte, error)
}

type DefaultClient

type DefaultClient struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(grpcAddress string, keychain Keychain) (*DefaultClient, error)

func (*DefaultClient) Close

func (cli *DefaultClient) Close() error

func (*DefaultClient) Get

func (cli *DefaultClient) Get(builder KeyRequestBuilder) (Record, error)

func (*DefaultClient) GetRange

func (cli *DefaultClient) GetRange(builder RangeRequestBuilder) (Block, error)

func (*DefaultClient) GetRecent

func (cli *DefaultClient) GetRecent(builder KeyRequestBuilder) (Record, error)

func (*DefaultClient) GetRegion

func (cli *DefaultClient) GetRegion(builder KeyRequestBuilder, blockC chan<- Block) error

func (*DefaultClient) GetRow

func (cli *DefaultClient) GetRow(builder KeyRequestBuilder, blockC chan<- Block) error

func (*DefaultClient) GetSpace

func (cli *DefaultClient) GetSpace(builder KeyRequestBuilder, blockC chan<- Block) error

func (*DefaultClient) Put

func (cli *DefaultClient) Put(builder RecordRequestBuilder) (Status, error)

func (*DefaultClient) Remove

func (cli *DefaultClient) Remove(builder KeyRequestBuilder) (Status, error)

func (*DefaultClient) Scan

func (cli *DefaultClient) Scan(builder ScanRequestBuilder, blockC chan<- Block) error

func (*DefaultClient) Touch

func (cli *DefaultClient) Touch(builder RecordRequestBuilder) (Status, error)

type EmptyHead

type EmptyHead struct {
}

func (EmptyHead) DiskSize

func (t EmptyHead) DiskSize() int64

func (EmptyHead) ExpiresAt

func (t EmptyHead) ExpiresAt() uint64

func (EmptyHead) Metadata

func (t EmptyHead) Metadata() int32

func (EmptyHead) String

func (t EmptyHead) String() string

func (EmptyHead) Version

func (t EmptyHead) Version() uint64

type EmptyKey

type EmptyKey struct {
}

func (EmptyKey) MajorKey

func (t EmptyKey) MajorKey() []byte

func (EmptyKey) MinorKey

func (t EmptyKey) MinorKey() []byte

func (EmptyKey) RegionName

func (t EmptyKey) RegionName() []byte

func (EmptyKey) String

func (t EmptyKey) String() string

func (EmptyKey) Timestamp

func (t EmptyKey) Timestamp() timeuuid.UUID

type GCMCipherMode

type GCMCipherMode struct {
}

func (*GCMCipherMode) Decrypt

func (this *GCMCipherMode) Decrypt(block cipher.Block, ciphertext []byte) ([]byte, error)

func (*GCMCipherMode) Encrypt

func (this *GCMCipherMode) Encrypt(block cipher.Block, plaintext []byte) ([]byte, error)

func (*GCMCipherMode) MetadataFlag

func (this *GCMCipherMode) MetadataFlag() int32

func (*GCMCipherMode) String

func (this *GCMCipherMode) String() string
type Head interface {
	Version() uint64
	ExpiresAt() uint64
	DiskSize() int64
	Metadata() int32
}

type HeadResponse

type HeadResponse struct {
	// contains filtered or unexported fields
}

func (HeadResponse) DiskSize

func (t HeadResponse) DiskSize() int64

func (HeadResponse) ExpiresAt

func (t HeadResponse) ExpiresAt() uint64

func (HeadResponse) Metadata

func (t HeadResponse) Metadata() int32

func (HeadResponse) String

func (t HeadResponse) String() string

func (HeadResponse) Version

func (t HeadResponse) Version() uint64

type Key

type Key interface {
	MajorKey() []byte
	RegionName() []byte
	MinorKey() []byte
	Timestamp() timeuuid.UUID
	// contains filtered or unexported methods
}

func ReadAllKeys

func ReadAllKeys(blockC <-chan Block) []Key

type KeyBuilder

type KeyBuilder struct {
	// contains filtered or unexported fields
}

func NewKey

func NewKey() KeyBuilder

func (KeyBuilder) Build

func (t KeyBuilder) Build() Key

func (KeyBuilder) MajorKey

func (t KeyBuilder) MajorKey() []byte

func (KeyBuilder) MinorKey

func (t KeyBuilder) MinorKey() []byte

func (KeyBuilder) RegionName

func (t KeyBuilder) RegionName() []byte

func (KeyBuilder) RemoveTimestamp

func (t KeyBuilder) RemoveTimestamp() KeyBuilder

func (KeyBuilder) SetMajorKey

func (t KeyBuilder) SetMajorKey(majorKey []byte) KeyBuilder

func (KeyBuilder) SetMinorKey

func (t KeyBuilder) SetMinorKey(minorKey []byte) KeyBuilder

func (KeyBuilder) SetRegionName

func (t KeyBuilder) SetRegionName(regionName []byte) KeyBuilder

func (KeyBuilder) String

func (t KeyBuilder) String() string

func (KeyBuilder) Timestamp

func (t KeyBuilder) Timestamp() timeuuid.UUID

func (KeyBuilder) WithMajorKey

func (t KeyBuilder) WithMajorKey(majorKey string) KeyBuilder

func (KeyBuilder) WithMaxTimestamp

func (t KeyBuilder) WithMaxTimestamp() KeyBuilder

func (KeyBuilder) WithMinTimestamp

func (t KeyBuilder) WithMinTimestamp() KeyBuilder

func (KeyBuilder) WithMinorKey

func (t KeyBuilder) WithMinorKey(minorKey string) KeyBuilder

func (KeyBuilder) WithNamedTimestamp

func (t KeyBuilder) WithNamedTimestamp(name []byte, timestampMillis int64) KeyBuilder

func (KeyBuilder) WithRandTimestamp

func (t KeyBuilder) WithRandTimestamp(timestampMillis int64) KeyBuilder

func (KeyBuilder) WithRegionName

func (t KeyBuilder) WithRegionName(regionName string) KeyBuilder

func (KeyBuilder) WithTimestamp

func (t KeyBuilder) WithTimestamp(uuid timeuuid.UUID) KeyBuilder

type KeyRequestBuilder

type KeyRequestBuilder struct {
	// contains filtered or unexported fields
}

func NewRequest

func NewRequest(key Key) KeyRequestBuilder

func (KeyRequestBuilder) HeadOnly

func (t KeyRequestBuilder) HeadOnly() KeyRequestBuilder

func (KeyRequestBuilder) WithTimeout

func (t KeyRequestBuilder) WithTimeout(timeout int) KeyRequestBuilder

type Keychain

type Keychain interface {
	GetBlockKey(majorKey []byte, timestamp timeuuid.UUID, keyLenBits int) (BlockKey, error)
}

type LZ4Compressor

type LZ4Compressor struct {
}

func (*LZ4Compressor) Compress

func (this *LZ4Compressor) Compress(input []byte) (output []byte, err error)

func (*LZ4Compressor) Decompress

func (this *LZ4Compressor) Decompress(input []byte) (output []byte, err error)

func (*LZ4Compressor) MetadataFlag

func (this *LZ4Compressor) MetadataFlag() int32

func (*LZ4Compressor) String

func (this *LZ4Compressor) String() string

type LZ4HighCompressor

type LZ4HighCompressor struct {
}

func (*LZ4HighCompressor) Compress

func (this *LZ4HighCompressor) Compress(input []byte) (output []byte, err error)

func (*LZ4HighCompressor) Decompress

func (this *LZ4HighCompressor) Decompress(input []byte) (output []byte, err error)

func (*LZ4HighCompressor) MetadataFlag

func (this *LZ4HighCompressor) MetadataFlag() int32

func (*LZ4HighCompressor) String

func (this *LZ4HighCompressor) String() string

type NoBlockCipher

type NoBlockCipher struct {
}

func (*NoBlockCipher) Create

func (this *NoBlockCipher) Create(key []byte) (cipher.Block, error)

func (*NoBlockCipher) KeyLengthBits

func (this *NoBlockCipher) KeyLengthBits() int

func (*NoBlockCipher) MetadataFlag

func (this *NoBlockCipher) MetadataFlag() int32

func (*NoBlockCipher) String

func (this *NoBlockCipher) String() string

type NoCipher

type NoCipher struct {
}

func (*NoCipher) BlockSize

func (this *NoCipher) BlockSize() int

func (*NoCipher) Decrypt

func (this *NoCipher) Decrypt(dst, src []byte)

func (*NoCipher) Encrypt

func (this *NoCipher) Encrypt(dst, src []byte)

func (*NoCipher) String

func (this *NoCipher) String() string

type NoCipherMode

type NoCipherMode struct {
}

func (*NoCipherMode) Decrypt

func (this *NoCipherMode) Decrypt(block cipher.Block, ciphertext []byte) ([]byte, error)

func (*NoCipherMode) Encrypt

func (this *NoCipherMode) Encrypt(block cipher.Block, plaintext []byte) ([]byte, error)

func (*NoCipherMode) MetadataFlag

func (this *NoCipherMode) MetadataFlag() int32

func (*NoCipherMode) String

func (this *NoCipherMode) String() string

type NoCompression

type NoCompression struct {
}

func (*NoCompression) Compress

func (this *NoCompression) Compress(input []byte) (output []byte, err error)

func (*NoCompression) Decompress

func (this *NoCompression) Decompress(input []byte) (output []byte, err error)

func (*NoCompression) MetadataFlag

func (this *NoCompression) MetadataFlag() int32

func (*NoCompression) String

func (this *NoCompression) String() string

type PasswordbasedKeychain

type PasswordbasedKeychain struct {
	// contains filtered or unexported fields
}

func NewPasswordbasedKeychain

func NewPasswordbasedKeychain(password string) (kc *PasswordbasedKeychain, err error)

func (*PasswordbasedKeychain) GetBlockKey

func (this *PasswordbasedKeychain) GetBlockKey(majorKey []byte, timestamp timeuuid.UUID, keyLenBits int) (BlockKey, error)

type RangeRequestBuilder

type RangeRequestBuilder struct {
	// contains filtered or unexported fields
}

func NewRangeRequest

func NewRangeRequest(key Key) RangeRequestBuilder

func (RangeRequestBuilder) HeadOnly

func (RangeRequestBuilder) WithNumRecords

func (t RangeRequestBuilder) WithNumRecords(numRecords int) RangeRequestBuilder

func (RangeRequestBuilder) WithTimeout

func (t RangeRequestBuilder) WithTimeout(timeout int) RangeRequestBuilder

type Record

type Record interface {
	Key() Key
	Head() Head

	Exist() bool
	Value() []byte

	ParseTo(pb proto.Message) error
}

func ParseRecord

func ParseRecord(record *pb.Record, keychain Keychain) (rec Record, err error)

func ReadAll

func ReadAll(blockC <-chan Block) []Record

type RecordRequestBuilder

type RecordRequestBuilder struct {
	// contains filtered or unexported fields
}

func NewProtoRecord

func NewProtoRecord(key Key, pb proto.Message) RecordRequestBuilder

func NewRecord

func NewRecord(key Key, value []byte) RecordRequestBuilder

func NewRecordRequest

func NewRecordRequest(key Key) RecordRequestBuilder

func (RecordRequestBuilder) CompareAndSet

func (t RecordRequestBuilder) CompareAndSet(version uint64) RecordRequestBuilder

func (RecordRequestBuilder) OnlyIfAbsent

func (t RecordRequestBuilder) OnlyIfAbsent() RecordRequestBuilder

func (RecordRequestBuilder) SetMetadata

func (t RecordRequestBuilder) SetMetadata(metadata int32) RecordRequestBuilder

func (RecordRequestBuilder) SetTtlSeconds

func (t RecordRequestBuilder) SetTtlSeconds(ttlSeconds int) RecordRequestBuilder

func (RecordRequestBuilder) SetValue

func (t RecordRequestBuilder) SetValue(value []byte) RecordRequestBuilder

func (RecordRequestBuilder) UseCompression

func (t RecordRequestBuilder) UseCompression(compressor Compressor) RecordRequestBuilder

func (RecordRequestBuilder) UseEncryption

func (t RecordRequestBuilder) UseEncryption(cipher Cipher, cipherMode CipherMode) RecordRequestBuilder

func (RecordRequestBuilder) WithTimeout

func (t RecordRequestBuilder) WithTimeout(timeout int) RecordRequestBuilder

func (RecordRequestBuilder) WithTtlSeconds

func (t RecordRequestBuilder) WithTtlSeconds(ttlSeconds int) RecordRequestBuilder

func (RecordRequestBuilder) WithValue

type RecordResponse

type RecordResponse struct {
	// contains filtered or unexported fields
}

func (RecordResponse) Exist

func (t RecordResponse) Exist() bool

func (RecordResponse) Head

func (t RecordResponse) Head() Head

func (RecordResponse) Key

func (t RecordResponse) Key() Key

func (RecordResponse) ParseTo

func (t RecordResponse) ParseTo(pb proto.Message) error

func (RecordResponse) String

func (t RecordResponse) String() string

func (RecordResponse) Value

func (t RecordResponse) Value() []byte

type ScanRequestBuilder

type ScanRequestBuilder struct {
	// contains filtered or unexported fields
}

func NewScanRequest

func NewScanRequest() ScanRequestBuilder

func (ScanRequestBuilder) HeadOnly

type SnappyCompressor

type SnappyCompressor struct {
}

func (*SnappyCompressor) Compress

func (this *SnappyCompressor) Compress(input []byte) (output []byte, err error)

func (*SnappyCompressor) Decompress

func (this *SnappyCompressor) Decompress(input []byte) (output []byte, err error)

func (*SnappyCompressor) MetadataFlag

func (this *SnappyCompressor) MetadataFlag() int32

func (*SnappyCompressor) String

func (this *SnappyCompressor) String() string

type Status

type Status interface {
	Updated() bool
}

type StatusResponse

type StatusResponse struct {
	// contains filtered or unexported fields
}

func (StatusResponse) String

func (t StatusResponse) String() string

func (StatusResponse) Updated

func (t StatusResponse) Updated() bool

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL