metainfo database: add interfaces and types (#434)
This commit is contained in:
parent
b04ea4639f
commit
047ebdc327
26
pkg/storj/encryption.go
Normal file
26
pkg/storj/encryption.go
Normal file
@ -0,0 +1,26 @@
|
||||
// Copyright (C) 2018 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package storj
|
||||
|
||||
// EncryptionScheme is the scheme and parameters used for encryption
|
||||
type EncryptionScheme struct {
|
||||
Algorithm EncryptionAlgorithm
|
||||
}
|
||||
|
||||
// EncryptionAlgorithm specifies an encryption algorithm
|
||||
type EncryptionAlgorithm byte
|
||||
|
||||
// List of supported encryption algorithms
|
||||
const (
|
||||
InvalidEncryptionAlgorithm = EncryptionAlgorithm(iota)
|
||||
Unencrypted
|
||||
AESGCM
|
||||
Secretbox
|
||||
)
|
||||
|
||||
// Nonce represents the largest nonce used by any encryption protocol
|
||||
type Nonce [24]byte // TODO: unify with eestream.Nonce
|
||||
|
||||
// EncryptedPrivateKey is a private key that has been encrypted
|
||||
type EncryptedPrivateKey []byte
|
127
pkg/storj/metainfo.go
Normal file
127
pkg/storj/metainfo.go
Normal file
@ -0,0 +1,127 @@
|
||||
// Copyright (C) 2018 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package storj
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Metainfo represents a database for storing meta-info about objects
|
||||
type Metainfo interface {
|
||||
// MetainfoLimits returns limits for this metainfo database
|
||||
Limits() (MetainfoLimits, error)
|
||||
|
||||
// CreateBucket creates a new bucket with the specified information
|
||||
// Database automatically sets different values in the information
|
||||
CreateBucket(ctx context.Context, bucket string, info *Bucket) (Bucket, error)
|
||||
// DeleteBucket deletes bucket
|
||||
DeleteBucket(ctx context.Context, bucket string) error
|
||||
// GetBucket gets bucket information
|
||||
GetBucket(ctx context.Context, bucket string) (Bucket, error)
|
||||
|
||||
// GetObject returns information about an object
|
||||
GetObject(ctx context.Context, bucket string, path Path) (Object, error)
|
||||
// GetObjectStream returns interface for reading the object stream
|
||||
GetObjectStream(ctx context.Context, bucket string, path Path) (ReadOnlyStream, error)
|
||||
|
||||
// CreateObject creates an uploading object and returns an interface for uploading Object information
|
||||
CreateObject(ctx context.Context, bucket string, path Path, info *CreateObject) (MutableObject, error)
|
||||
// ModifyObject creates an interface for modifying an existing object
|
||||
ModifyObject(ctx context.Context, bucket string, path Path, info Object) (MutableObject, error)
|
||||
// DeleteObject deletes an object from database
|
||||
DeleteObject(ctx context.Context, bucket string, path Path) error
|
||||
|
||||
// ListObjects lists objects in bucket based on the ListOptions
|
||||
ListObjects(ctx context.Context, bucket string, options ListOptions) (ObjectList, error)
|
||||
}
|
||||
|
||||
// CreateObject has optional parameters that can be set
|
||||
type CreateObject struct {
|
||||
Metadata []byte
|
||||
ContentType string
|
||||
Expires time.Time
|
||||
}
|
||||
|
||||
// Object converts the CreateObject to an object with unitialized values
|
||||
func (create CreateObject) Object(bucket string, path Path) Object {
|
||||
return Object{
|
||||
Bucket: bucket,
|
||||
Path: path,
|
||||
Metadata: create.Metadata,
|
||||
ContentType: create.ContentType,
|
||||
Expires: create.Expires,
|
||||
}
|
||||
}
|
||||
|
||||
// ListOptions lists objects
|
||||
type ListOptions struct {
|
||||
Prefix Path
|
||||
First Path // First is relative to Prefix, full path is Prefix + First
|
||||
Delimiter rune
|
||||
Recursive bool
|
||||
Limit int
|
||||
}
|
||||
|
||||
// ObjectList is a list of objects
|
||||
type ObjectList struct {
|
||||
Bucket string
|
||||
Prefix Path
|
||||
|
||||
NextFirst Path // relative to Prefix, to get the full path use Prefix + NextFirst
|
||||
More bool
|
||||
|
||||
// Items paths are relative to Prefix
|
||||
// To get the full path use list.Prefix + list.Items[0].Path
|
||||
Items []Object
|
||||
}
|
||||
|
||||
// MetainfoLimits lists limits specified for the Metainfo database
|
||||
type MetainfoLimits struct {
|
||||
// ListLimit specifies the maximum amount of items that can be listed at a time.
|
||||
ListLimit int64
|
||||
|
||||
// MinimumRemoteSegmentSize specifies the minimum remote segment that is allowed to be stored.
|
||||
MinimumRemoteSegmentSize int64
|
||||
// MaximumInlineSegmentSize specifies the maximum inline segment that is allowed to be stored.
|
||||
MaximumInlineSegmentSize int64
|
||||
}
|
||||
|
||||
// ReadOnlyStream is an interface for reading segment information
|
||||
type ReadOnlyStream interface {
|
||||
Info() Object
|
||||
|
||||
// SegmentsAt returns the segment that contains the byteOffset and following segments.
|
||||
// Limit specifies how much to return at most.
|
||||
SegmentsAt(ctx context.Context, byteOffset int64, limit int64) (infos []Segment, more bool, err error)
|
||||
// Segments returns the segment at index.
|
||||
// Limit specifies how much to return at most.
|
||||
Segments(ctx context.Context, index int64, limit int64) (infos []Segment, more bool, err error)
|
||||
}
|
||||
|
||||
// MutableObject is an interface for manipulating creating/deleting object stream
|
||||
type MutableObject interface {
|
||||
// Info gets the current information about the object
|
||||
Info() (Object, error)
|
||||
|
||||
// CreateStream creates a new stream for the object
|
||||
CreateStream() (MutableStream, error)
|
||||
// ContinueStream starts to continue a partially uploaded stream.
|
||||
// ContinueStream() (MutableStream, error)
|
||||
// DeleteStream deletes any information about this objects stream
|
||||
DeleteStream() error
|
||||
|
||||
// Commit commits the changes to the database
|
||||
Commit() error
|
||||
}
|
||||
|
||||
// MutableStream is an interface for manipulating stream information
|
||||
type MutableStream interface {
|
||||
ReadOnlyStream
|
||||
|
||||
// AddSegments adds segments to the stream.
|
||||
AddSegments(segments ...Segment) error
|
||||
// UpdateSegments updates information about segments.
|
||||
UpdateSegments(segments ...Segment) error
|
||||
}
|
15
pkg/storj/node.go
Normal file
15
pkg/storj/node.go
Normal file
@ -0,0 +1,15 @@
|
||||
// Copyright (C) 2018 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package storj
|
||||
|
||||
import "encoding/hex"
|
||||
|
||||
// NodeID is a unique node identifier
|
||||
type NodeID [32]byte
|
||||
|
||||
// HexString returns NodeID as hex encoded string
|
||||
func (id *NodeID) HexString() string { return hex.EncodeToString(id[:]) }
|
||||
|
||||
// Bytes returns raw bytes of the id
|
||||
func (id NodeID) Bytes() []byte { return id[:] }
|
74
pkg/storj/object.go
Normal file
74
pkg/storj/object.go
Normal file
@ -0,0 +1,74 @@
|
||||
// Copyright (C) 2018 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package storj
|
||||
|
||||
import "time"
|
||||
|
||||
// Bucket contains information about a specific bucket
|
||||
type Bucket struct {
|
||||
Name string
|
||||
Created time.Time
|
||||
}
|
||||
|
||||
// Object contains information about a specific object
|
||||
type Object struct {
|
||||
Version uint32
|
||||
Bucket string
|
||||
Path Path
|
||||
IsPrefix bool
|
||||
|
||||
Metadata []byte
|
||||
|
||||
ContentType string
|
||||
Created time.Time
|
||||
Modified time.Time
|
||||
Expires time.Time
|
||||
|
||||
Stream
|
||||
}
|
||||
|
||||
// Stream is information about an object stream
|
||||
type Stream struct {
|
||||
// Size is the total size of the stream in bytes
|
||||
Size int64
|
||||
// Checksum is the checksum of the segment checksums
|
||||
Checksum []byte
|
||||
|
||||
// SegmentCount is the number of segments
|
||||
SegmentCount int64
|
||||
// FixedSegmentSize is the size of each segment,
|
||||
// when all segments have the same size. It is -1 otherwise.
|
||||
FixedSegmentSize int64
|
||||
|
||||
// RedundancyScheme specifies redundancy strategy used for this stream
|
||||
RedundancyScheme
|
||||
// EncryptionScheme specifies encryption strategy used for this stream
|
||||
EncryptionScheme
|
||||
}
|
||||
|
||||
// Segment is full segment information
|
||||
type Segment struct {
|
||||
Index int64
|
||||
// Size is the size of the content in bytes
|
||||
Size int64
|
||||
// Checksum is the checksum of the content
|
||||
Checksum []byte
|
||||
// Local data
|
||||
Inline []byte
|
||||
// Remote data
|
||||
PieceID PieceID
|
||||
Pieces []Piece
|
||||
// Encryption
|
||||
EncryptedKeyNonce Nonce
|
||||
EncryptedKey EncryptedPrivateKey
|
||||
}
|
||||
|
||||
// PieceID is an identificator for a piece
|
||||
type PieceID []byte
|
||||
|
||||
// Piece is information where a piece is located
|
||||
type Piece struct {
|
||||
Number byte
|
||||
Location NodeID
|
||||
}
|
7
pkg/storj/path.go
Normal file
7
pkg/storj/path.go
Normal file
@ -0,0 +1,7 @@
|
||||
// Copyright (C) 2018 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package storj
|
||||
|
||||
// Path represents a object path
|
||||
type Path = string
|
25
pkg/storj/redundancy.go
Normal file
25
pkg/storj/redundancy.go
Normal file
@ -0,0 +1,25 @@
|
||||
// Copyright (C) 2018 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package storj
|
||||
|
||||
// RedundancyScheme specifies the parameters and the algorithm for redundancy
|
||||
type RedundancyScheme struct {
|
||||
Algorithm RedundancyAlgorithm
|
||||
|
||||
ShareSize int64
|
||||
|
||||
RequiredShares int16
|
||||
RepairShares int16
|
||||
OptimalShares int16
|
||||
TotalShares int16
|
||||
}
|
||||
|
||||
// RedundancyAlgorithm is the algorithm used for redundancy
|
||||
type RedundancyAlgorithm byte
|
||||
|
||||
// List of supported redundancy algorithms
|
||||
const (
|
||||
InvalidRedundancyAlgorithm = RedundancyAlgorithm(iota)
|
||||
ReedSolomon
|
||||
)
|
Loading…
Reference in New Issue
Block a user