# 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.
# Functions
BatchDowngradeReferences archives or deletes a batch of references, handling all batching and throttles.
FakeID returns an ID derived from the given byte, suitable for testing.
FakeIDAdd returns an ID derived from the given ID and the given byte, suitable for testing.
FakeIDMul returns an ID derived from the given ID and given byte using *, suitable for testing.
GetLiveCounts computes the maximum live count for each ID over its RefNonces.
GetReferenceCount returns the number of live references (at least as "live" as `refStatus`) for each block ID.
IDFromBytes creates a ID from the given bytes.
IDFromString creates a ID from the given string.
IsThrottleError returns whether or not the given error signals throttling.
MakeAddReferenceArg builds a keybase1.AddReferenceArg from the given params.
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.
MakeFakeID generates a fake block ID with a valid hash type using a CSPRNG.
MakeFirstContext makes the initial context for a block with the given creator.
MakeGetBlockArg builds a keybase1.GetBlockArg from the given params.
MakePermanentID computes the permanent ID of a block given its encoded and encrypted contents.
MakePutBlockAgainArg builds a keybase1.PutBlockAgainArg from the given params.
MakePutBlockArg builds a keybase1.PutBlockArg from the given params.
MakeRandomIDInRange generates a random block ID using a CSPRNG, distributing the random variable over the interval [start, end), where the full range is [0, MaxUint64).
MakeRefNonce generates a non-zero block reference nonce using a CSPRNG.
MakeTemporaryID generates a temporary block ID with an invalid hash type using a CSPRNG.
NewQuotaInfo returns a newly constructed QuotaInfo.
NewUsageStat creates a new UsageStat.
ParseGetBlockRes parses the given keybase1.GetBlockRes into its components.
ParseGetQuotaInfoRes parses the given quota result into a *QuotaInfo.
QuotaInfoDecode decodes b into a QuotaInfo.
VerifyID verifies that the given block ID is the permanent block ID for the given encoded and encrypted data.
# Constants
MaxIDStringLength is the maximum length of the string representation of a ID.
NumUsage indicates the number of usage types.
24 hours.
ServerTokenServer is the expected server type for bserver authentication.
StatusCodeServerError is the error code for a generic block server error.
StatusCodeServerErrorBadRequest is the error code for a generic client error.
StatusCodeServerErrorBlockArchived is the error code for a block has been archived.
StatusCodeServerErrorBlockDeleted is the error code for a block has been deleted.
StatusCodeServerErrorBlockNonExistent is the error code for when bserver cannot find a block.
StatusCodeServerErrorMaxRefExceeded is the error code to indicate there are too many refs to a block.
StatusCodeServerErrorNonceNonExistent is the error code when a nonce cannot be found.
StatusCodeServerErrorNoPermission is the error code for when there's no permission.
StatusCodeServerErrorOverQuota is the error code for when the user has exceeded his quota.
StatusCodeServerErrorThrottle is the error code to indicate the client should initiate backoff.
StatusCodeServerErrorUnauthorized is the error code for when the session has not been validated.
UsageArchive indicates an existing (data) block is archived.
UsageGitArchive indicates an existing git block is archived.
UsageGitWrite indicates a git block is written.
UsageMDWrite indicates a MD block is written.
UsageRead indicates a block is read.
UsageWrite indicates a data block is written (written blocks include archived blocks).
UseMathRandForTest tells MakeRandomIDInRange to use math/rand for PRNG.
UseRealRandomness tells MakeRandomIDInRange to use crypto/rand for PRNG.
# Variables
ZeroID is a zero-valued ID.
ZeroRefNonce is a special BlockRefNonce used for the initial reference to a block.
# Structs
Context contains all the information used by the server to identify blocks (other than the ID).
ID is the (usually content-based) ID for a data block.
QuotaInfo contains a user's quota usage information.
ServerError is a generic bserver-side error.
ServerErrorBadRequest is a generic client-side error.
ServerErrorBlockArchived is an exportable error from bserver.
ServerErrorBlockDeleted is an exportable error from bserver.
ServerErrorBlockNonExistent is an exportable error from bserver.
ServerErrorMaxRefExceeded is an exportable error from bserver.
ServerErrorNonceNonExistent is an exportable error from bserver.
ServerErrorNoPermission is an exportable error from bserver.
ServerErrorOverQuota is returned when a user is over quota.
ServerErrorThrottle is returned when the server wants the client to backoff.
ServerErrorUnauthorized is a generic client-side error.
ServerErrorUnwrapper unwraps errors from a remote block server.
UsageStat tracks the amount of bytes/blocks used, broken down by usage types.
# Type aliases
ContextMap is a map from a block ID to a list of its contexts.
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.
UsageType indicates the type of usage that quota manager is keeping stats of.