kbfsblock

package
v0.0.0-...-fb60582 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2017 License: BSD-3-Clause Imports: 13 Imported by: 0

README

kbfsblock

Types and functions to work with KBFS blocks. The package is named kbfsblock rather than block to avoid clashes with existing variable names.

All errors returned by this package are wrapped with pkg/errors, and so need errors.Cause() to unwrap them.

Documentation

Index

Constants

View Source
const (
	// StatusCodeBServerError is the error code for a generic block server error.
	StatusCodeBServerError = 2700
	// StatusCodeBServerErrorBadRequest is the error code for a generic client error.
	StatusCodeBServerErrorBadRequest = 2701
	// StatusCodeBServerErrorUnauthorized is the error code for when the session has not been validated
	StatusCodeBServerErrorUnauthorized = 2702
	// StatusCodeBServerErrorOverQuota is the error code for when the user has exceeded his quota
	StatusCodeBServerErrorOverQuota = 2703
	// StatusCodeBServerErrorBlockNonExistent is the error code for when bserver cannot find a block
	StatusCodeBServerErrorBlockNonExistent = 2704
	// StatusCodeBServerErrorBlockArchived is the error code for a block has been archived
	StatusCodeBServerErrorBlockArchived = 2705
	// StatusCodeBServerErrorNoPermission is the error code for when there's no permission
	StatusCodeBServerErrorNoPermission = 2706
	// StatusCodeBServerErrorBlockDeleted is the error code for a block has been deleted
	StatusCodeBServerErrorBlockDeleted = 2707
	// StatusCodeBServerErrorNonceNonExistent is the error code when a nonce cannot be found
	StatusCodeBServerErrorNonceNonExistent = 2708
	// StatusCodeBServerErrorMaxRefExceeded is the error code to indicate there are too many refs to a block
	StatusCodeBServerErrorMaxRefExceeded = 2709
	// StatusCodeBServerErrorThrottle is the error code to indicate the client should initiate backoff.
	StatusCodeBServerErrorThrottle = 2799
)
View Source
const MaxIDStringLength = kbfshash.MaxHashStringLength

MaxIDStringLength is the maximum length of the string representation of a ID.

Variables

View Source
var ZeroRefNonce = RefNonce([8]byte{0, 0, 0, 0, 0, 0, 0, 0})

ZeroRefNonce is a special BlockRefNonce used for the initial reference to a block.

Functions

func VerifyID

func VerifyID(encodedEncryptedData []byte, id ID) error

VerifyID verifies that the given block ID is the permanent block ID for the given encoded and encrypted data.

Types

type BServerError

type BServerError struct {
	Msg string
}

BServerError is a generic bserver-side error.

func (BServerError) Error

func (e BServerError) Error() string

Error implements the Error interface for BServerError.

func (BServerError) ToStatus

func (e BServerError) ToStatus() (s keybase1.Status)

ToStatus implements the ExportableError interface for BServerError.

type BServerErrorBadRequest

type BServerErrorBadRequest struct {
	Msg string
}

BServerErrorBadRequest is a generic client-side error.

func (BServerErrorBadRequest) Error

func (e BServerErrorBadRequest) Error() string

Error implements the Error interface for BServerError.

func (BServerErrorBadRequest) ToStatus

func (e BServerErrorBadRequest) ToStatus() (s keybase1.Status)

ToStatus implements the ExportableError interface for BServerError.

type BServerErrorBlockArchived

type BServerErrorBlockArchived struct {
	Msg string
}

BServerErrorBlockArchived is an exportable error from bserver

func (BServerErrorBlockArchived) Error

Error implements the Error interface for BServerErrorBlockArchived.

func (BServerErrorBlockArchived) ToStatus

func (e BServerErrorBlockArchived) ToStatus() (s keybase1.Status)

ToStatus implements the ExportableError interface for BServerErrorBlockArchived

type BServerErrorBlockDeleted

type BServerErrorBlockDeleted struct {
	Msg string
}

BServerErrorBlockDeleted is an exportable error from bserver

func (BServerErrorBlockDeleted) Error

func (e BServerErrorBlockDeleted) Error() string

Error implements the Error interface for BServerErrorBlockDeleted

func (BServerErrorBlockDeleted) ToStatus

func (e BServerErrorBlockDeleted) ToStatus() (s keybase1.Status)

ToStatus implements the ExportableError interface for BServerErrorBlockDeleted

type BServerErrorBlockNonExistent

type BServerErrorBlockNonExistent struct {
	Msg string
}

BServerErrorBlockNonExistent is an exportable error from bserver

func (BServerErrorBlockNonExistent) Error

Error implements the Error interface for BServerErrorBlockNonExistent.

func (BServerErrorBlockNonExistent) ToStatus

func (e BServerErrorBlockNonExistent) ToStatus() (s keybase1.Status)

ToStatus implements the ExportableError interface for BServerErrorBlockNonExistent

type BServerErrorMaxRefExceeded

type BServerErrorMaxRefExceeded struct {
	Msg string
}

BServerErrorMaxRefExceeded is an exportable error from bserver

func (BServerErrorMaxRefExceeded) Error

Error implements the Error interface for BServerErrorMaxRefExceeded

func (BServerErrorMaxRefExceeded) ToStatus

func (e BServerErrorMaxRefExceeded) ToStatus() (s keybase1.Status)

ToStatus implements the ExportableError interface for BServerErrorMaxRefExceeded

type BServerErrorNoPermission

type BServerErrorNoPermission struct {
	Msg string
}

BServerErrorNoPermission is an exportable error from bserver

func (BServerErrorNoPermission) Error

func (e BServerErrorNoPermission) Error() string

Error implements the Error interface for BServerErrorNoPermission.

func (BServerErrorNoPermission) ToStatus

func (e BServerErrorNoPermission) ToStatus() (s keybase1.Status)

ToStatus implements the ExportableError interface for BServerErrorBlockArchived

type BServerErrorNonceNonExistent

type BServerErrorNonceNonExistent struct {
	Msg string
}

BServerErrorNonceNonExistent is an exportable error from bserver

func (BServerErrorNonceNonExistent) Error

Error implements the Error interface for BServerErrornonceNonExistent.

func (BServerErrorNonceNonExistent) ToStatus

func (e BServerErrorNonceNonExistent) ToStatus() (s keybase1.Status)

ToStatus implements the ExportableError interface for BServerErrorNonceNonExistent

type BServerErrorOverQuota

type BServerErrorOverQuota struct {
	Msg string
	// Usage indicates the current usage
	Usage int64
	// Limit indicates the current quota limit
	Limit int64
	// Throttled indicates if request has not been completed due to server throttle
	Throttled bool
}

BServerErrorOverQuota is a generic client-side error.

func (BServerErrorOverQuota) Error

func (e BServerErrorOverQuota) Error() string

Error implements the Error interface for BServerErrorOverQuota.

func (BServerErrorOverQuota) ToStatus

func (e BServerErrorOverQuota) ToStatus() (s keybase1.Status)

ToStatus implements the ExportableError interface for BServerErrorOverQuota.

type BServerErrorThrottle

type BServerErrorThrottle struct {
	Msg string
}

BServerErrorThrottle is returned when the server wants the client to backoff.

func (BServerErrorThrottle) Error

func (e BServerErrorThrottle) Error() string

Error implements the Error interface for BServerErrorThrottle.

func (BServerErrorThrottle) ToStatus

func (e BServerErrorThrottle) ToStatus() (s keybase1.Status)

ToStatus implements the ExportableError interface for BServerErrorThrottle.

type BServerErrorUnauthorized

type BServerErrorUnauthorized struct {
	Msg string
}

BServerErrorUnauthorized is a generic client-side error.

func (BServerErrorUnauthorized) Errno

Errno implements the fuse.ErrorNumber interface for BServerErrorUnauthorized.

func (BServerErrorUnauthorized) Error

func (e BServerErrorUnauthorized) Error() string

Error implements the Error interface for BServerErrorUnauthorized.

func (BServerErrorUnauthorized) ToStatus

func (e BServerErrorUnauthorized) ToStatus() (s keybase1.Status)

ToStatus implements the ExportableError interface for BServerErrorUnauthorized.

type BServerErrorUnwrapper

type BServerErrorUnwrapper struct{}

BServerErrorUnwrapper unwraps errors from a remote block server.

func (BServerErrorUnwrapper) MakeArg

func (eu BServerErrorUnwrapper) MakeArg() interface{}

MakeArg implements rpc.ErrorUnwrapper.

func (BServerErrorUnwrapper) UnwrapError

func (eu BServerErrorUnwrapper) UnwrapError(arg interface{}) (appError error, dispatchError error)

UnwrapError implements rpc.ErrorUnwrapper.

type Context

type Context struct {
	// Creator is the UID that was first charged for the initial
	// reference to this block.
	Creator keybase1.UID `codec:"c"`
	// Writer is the UID that should be charged for this reference to
	// the block.  If empty, it defaults to Creator.
	Writer keybase1.UID `codec:"w,omitempty"`
	// When RefNonce is all 0s, this is the initial reference to a
	// particular block.  Using a constant refnonce for the initial
	// reference allows the server to identify and optimize for the
	// common case where there is only one reference for a block.  Two
	// initial references cannot happen simultaneously, because the
	// encrypted block contents (and thus the block ID) will be
	// randomized by the server-side block crypt key half.  All
	// subsequent references to the same block must have a random
	// RefNonce (it can't be a monotonically increasing number because
	// that would require coordination among clients).
	RefNonce RefNonce `codec:"r,omitempty"`
}

Context contains all the information used by the server to identify blocks (other than the ID).

NOTE: Don't add or modify anything in this struct without considering how old clients will handle them.

func MakeContext

func MakeContext(creator, writer keybase1.UID, nonce RefNonce) Context

MakeContext makes a context with the given creator, writer, and nonce, where the writer is not necessarily equal to the creator, and the nonce is usually non-zero.

func MakeFirstContext

func MakeFirstContext(creator keybase1.UID) Context

MakeFirstContext makes the initial context for a block with the given creator.

func (Context) GetCreator

func (c Context) GetCreator() keybase1.UID

GetCreator returns the creator of the associated block.

func (Context) GetRefNonce

func (c Context) GetRefNonce() RefNonce

GetRefNonce returns the ref nonce of the associated block.

func (Context) GetWriter

func (c Context) GetWriter() keybase1.UID

GetWriter returns the writer of the associated block.

func (Context) IsFirstRef

func (c Context) IsFirstRef() bool

IsFirstRef returns whether or not p represents the first reference to the corresponding ID.

func (*Context) SetWriter

func (c *Context) SetWriter(newWriter keybase1.UID)

SetWriter sets the Writer field, if necessary.

func (Context) String

func (c Context) String() string

type ContextMap

type ContextMap map[ID][]Context

ContextMap is a map from a block ID to a list of its contexts.

type ID

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

ID is the (usually content-based) ID for a data block.

func FakeID

func FakeID(b byte) ID

FakeID returns an ID derived from the given byte, suitable for testing.

func FakeIDAdd

func FakeIDAdd(id ID, b byte) ID

FakeIDAdd returns an ID derived from the given ID and the given byte, suitable for testing.

func FakeIDMul

func FakeIDMul(id ID, b byte) ID

FakeIDMul returns an ID derived from the given ID and given byte using *, suitable for testing.

TODO: Fix the test that breaks when this is replaced with FakeIDAdd.

func IDFromString

func IDFromString(idStr string) (ID, error)

IDFromString creates a ID from the given string. If the returned error is nil, the returned ID is valid.

func MakePermanentID

func MakePermanentID(encodedEncryptedData []byte) (ID, error)

MakePermanentID computes the permanent ID of a block given its encoded and encrypted contents.

func MakeTemporaryID

func MakeTemporaryID() (ID, error)

MakeTemporaryID generates a temporary block ID using a CSPRNG. This is used for indirect blocks before they're committed to the server.

func (ID) Bytes

func (id ID) Bytes() []byte

Bytes returns the bytes of the block ID.

func (ID) IsValid

func (id ID) IsValid() bool

IsValid returns whether the block ID is valid. A zero block ID is considered invalid.

func (ID) MarshalBinary

func (id ID) MarshalBinary() (data []byte, err error)

MarshalBinary implements the encoding.BinaryMarshaler interface for ID. Returns an error if the ID is invalid and not the zero ID.

func (ID) MarshalText

func (id ID) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface for ID.

func (ID) String

func (id ID) String() string

func (*ID) UnmarshalBinary

func (id *ID) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface for ID. Returns an error if the given byte array is non-empty and the ID is invalid.

func (*ID) UnmarshalText

func (id *ID) UnmarshalText(buf []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface for ID.

type RefNonce

type RefNonce [8]byte

RefNonce is a 64-bit unique sequence of bytes for identifying this reference of a block ID from other references to the same (duplicated) block.

func MakeRefNonce

func MakeRefNonce() (RefNonce, error)

MakeRefNonce generates a non-zero block reference nonce using a CSPRNG. This is used for distinguishing different references to the same ID.

func (RefNonce) String

func (nonce RefNonce) String() string

type UsageStat

type UsageStat struct {
	Bytes  map[UsageType]int64
	Blocks map[UsageType]int64
	// Mtime is in unix nanoseconds
	Mtime int64
}

UsageStat tracks the amount of bytes/blocks used, broken down by usage types

func NewUsageStat

func NewUsageStat() *UsageStat

NewUsageStat creates a new UsageStat

func (*UsageStat) Accum

func (u *UsageStat) Accum(another *UsageStat, accumF func(int64, int64) int64)

Accum combines changes to the existing UserQuotaInfo object using accumulation function accumF.

func (*UsageStat) AccumOne

func (u *UsageStat) AccumOne(change int, usage UsageType)

AccumOne records the usage of one block, whose size is denoted by change A positive change means the block is newly added, negative means the block is deleted. If archive is true, it means the block is archived.

func (*UsageStat) NonZero

func (u *UsageStat) NonZero() bool

NonZero checks whether UsageStat has accumulated any usage info

type UsageType

type UsageType int

UsageType indicates the type of usage that quota manager is keeping stats of

const (
	// UsageWrite indicates a block is written (written blocks include archived blocks)
	UsageWrite UsageType = iota
	// UsageArchive indicates an existing block is archived
	UsageArchive
	// UsageRead indicates a block is read
	UsageRead
	// NumUsage indicates the number of usage types
	NumUsage
)

type UserQuotaInfo

type UserQuotaInfo struct {
	Folders map[string]*UsageStat
	Total   *UsageStat
	Limit   int64
}

UserQuotaInfo contains a user's quota usage information

func NewUserQuotaInfo

func NewUserQuotaInfo() *UserQuotaInfo

NewUserQuotaInfo returns a newly constructed UserQuotaInfo.

func UserQuotaInfoDecode

func UserQuotaInfoDecode(b []byte, codec kbfscodec.Codec) (
	*UserQuotaInfo, error)

UserQuotaInfoDecode decodes b into a UserQuotaInfo

func (*UserQuotaInfo) Accum

func (u *UserQuotaInfo) Accum(another *UserQuotaInfo, accumF func(int64, int64) int64)

Accum combines changes to the existing UserQuotaInfo object using accumulation function accumF.

func (*UserQuotaInfo) AccumOne

func (u *UserQuotaInfo) AccumOne(change int, folder string, usage UsageType)

AccumOne combines one quota charge to the existing UserQuotaInfo

func (*UserQuotaInfo) ToBytes

func (u *UserQuotaInfo) ToBytes(codec kbfscodec.Codec) ([]byte, error)

ToBytes marshals this UserQuotaInfo

Jump to

Keyboard shortcuts

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