README

The core logic for KBFS. Presentation layers should using the interfaces in this library, particularly KBFSOps, to interact with KBFS.

(TODO: Fill in more details.)

Expand ▾ Collapse ▴

Documentation

Index

Constants

const (
	// BServerDefaultPingIntervalSeconds is the default interval on which the
	// client should contact the block server.
	BServerDefaultPingIntervalSeconds = 10
	// BServerPingTimeout is how long to wait for a ping response
	// before breaking the connection and trying to reconnect.
	BServerPingTimeout = 30 * time.Second
)

const (
	KeybaseServiceName     = "keybase-service"
	MDServiceName          = "md-server"
	LoginStatusUpdateName  = "login"
	LogoutStatusUpdateName = "logout"
)

Service names used in ConnectionStatus.


const (
	// InitDefaultString is the normal mode for when KBFS data will be
	// read and written.
	InitDefaultString string = "default"
	// InitMinimalString is for when KBFS will only be used as a MD
	// lookup layer (e.g., for chat on mobile).
	InitMinimalString = "minimal"
	// InitSingleOpString is for when KBFS will only be used for a
	// single logical operation (e.g., as a git remote helper).
	InitSingleOpString = "singleOp"
	// InitConstrainedString is for when KBFS will use constrained
	// resources.
	InitConstrainedString = "constrained"
)

const (
	// MdServerBackgroundRekeyPeriod is how long the rekey checker
	// waits between runs on average. The timer gets reset after
	// every incoming FolderNeedsRekey RPC.
	// The amount of wait is calculated in nextRekeyTime.
	MdServerBackgroundRekeyPeriod = 1 * time.Hour
	// MdServerDefaultPingIntervalSeconds is the default interval on which the
	// client should contact the MD Server
	MdServerDefaultPingIntervalSeconds = 10
	// MdServerPingTimeout is how long to wait for a ping response
	// before breaking the connection and trying to reconnect.
	MdServerPingTimeout = 30 * time.Second
)

const (
	// EnvTestMDServerAddr is the environment variable name for an
	// mdserver address.
	EnvTestMDServerAddr = "KEYBASE_TEST_MDSERVER_ADDR"
	// EnvTestBServerAddr is the environment variable name for a block
	// server address.
	EnvTestBServerAddr = "KEYBASE_TEST_BSERVER_ADDR"
	// TempdirServerAddr is the special value of the
	// EnvTest{B,MD}ServerAddr environment value to signify that
	// an on-disk implementation of the {b,md}server should be
	// used with a temporary directory.
	TempdirServerAddr = "tempdir"
)

const (
	StallableBlockGet StallableBlockOp = "Get"
	StallableBlockPut StallableBlockOp = "Put"

	StallableMDGetForTLF             StallableMDOp = "GetForTLF"
	StallableMDGetLatestHandleForTLF StallableMDOp = "GetLatestHandleForTLF"
	StallableMDGetUnmergedForTLF     StallableMDOp = "GetUnmergedForTLF"
	StallableMDGetRange              StallableMDOp = "GetRange"
	StallableMDAfterGetRange         StallableMDOp = "AfterGetRange"
	StallableMDGetUnmergedRange      StallableMDOp = "GetUnmergedRange"
	StallableMDPut                   StallableMDOp = "Put"
	StallableMDAfterPut              StallableMDOp = "AfterPut"
	StallableMDPutUnmerged           StallableMDOp = "PutUnmerged"
	StallableMDAfterPutUnmerged      StallableMDOp = "AfterPutUnmerged"
	StallableMDPruneBranch           StallableMDOp = "PruneBranch"
	StallableMDResolveBranch         StallableMDOp = "ResolveBranch"
)

stallable Block Ops and MD Ops


const (

	// ForcedBranchSquashRevThreshold is the minimum number of MD
	// revisions in the journal that will trigger an automatic branch
	// conversion (and subsequent resolution).
	ForcedBranchSquashRevThreshold = 20
	// ForcedBranchSquashBytesThresholdDefault is the minimum number of
	// unsquashed MD bytes in the journal that will trigger an
	// automatic branch conversion (and subsequent resolution).
	ForcedBranchSquashBytesThresholdDefault = uint64(25 << 20) // 25 MB

)

const CtxCROpID = "CRID"

CtxCROpID is the display name for the unique operation conflict resolution ID tag.


const CtxFBMOpID = "FBMID"

CtxFBMOpID is the display name for the unique operation folderBlockManager ID tag.


const CtxFBOOpID = "FBOID"

CtxFBOOpID is the display name for the unique operation folderBranchOps ID tag.


const CtxJournalOpID = "JID"

CtxJournalOpID is the display name for the unique operation enqueued journal ID tag.


const CtxKeybaseServiceOpID = "KSID"

CtxKeybaseServiceOpID is the display name for the unique operation enqueued rekey ID tag.


const CtxMDSROpID = "MDSRID"

CtxMDSROpID is the display name for the unique operation MDServerRemote ID tag.


const CtxRekeyOpID = "REKEYID"

CtxRekeyOpID is the display name for the unique operation enqueued rekey ID tag.


const DefaultBlocksInMemCache = 1024

DefaultBlocksInMemCache is the number of blocks we should keep in the cache.


const ECMRID = "ECMR"

ECMRID is used in EventuallyConsistentMerkleRoot for only background RPCs. More specifically, when we need to spawn a background goroutine for GetCurrentMerkleRoot, a new context with this tag is created and used. This is also used as a prefix for the logger module name in EventuallyConsistentMerkleRoot.


const ECQUID = "ECQU"

ECQUID is used in EventuallyConsistentQuotaUsage for only background RPCs. More specifically, when we need to spawn a background goroutine for GetUserQuotaInfo, a new context with this tag is created and used. This is also used as a prefix for the logger module name in EventuallyConsistentQuotaUsage.


const (
	// MaxBlockSizeBytesDefault is the default maximum block size for KBFS.
	// 512K blocks by default, block changes embedded max == 8K.
	// Block size was chosen somewhat arbitrarily by trying to
	// minimize the overall size of the history written by a user when
	// appending 1KB writes to a file, up to a 1GB total file.  Here
	// is the output of a simple script that approximates that
	// calculation:
	//
	// Total history size for 0065536-byte blocks: 1134341128192 bytes
	// Total history size for 0131072-byte blocks: 618945052672 bytes
	// Total history size for 0262144-byte blocks: 412786622464 bytes
	// Total history size for 0524288-byte blocks: 412786622464 bytes
	// Total history size for 1048576-byte blocks: 618945052672 bytes
	// Total history size for 2097152-byte blocks: 1134341128192 bytes
	// Total history size for 4194304-byte blocks: 2216672886784 bytes
	MaxBlockSizeBytesDefault = 512 << 10
)

Constants used in this file. TODO: Make these configurable?


const (
	// PublicUIDName is the name given to keybase1.PublicUID.  This string
	// should correspond to an illegal or reserved Keybase user name.
	PublicUIDName = "_public"
)

const RPCReconnectInterval = 2 * time.Second

RPCReconnectInterval specifies the time between reconnect attempts for RPC Connections.


const (
	// StatusCodeDiskBlockCacheError is a generic disk cache error.
	StatusCodeDiskBlockCacheError = 0x666
)

Disk Cache Errors


const Version = "1.0.2"

Version is the current version (should be MAJOR.MINOR.PATCH)


Variables

var ErrorFile = ".kbfs_error"

ErrorFile is the name of the virtual file in KBFS that should contain the last reported error(s).


var NoCurrentSessionExpectedError = "no current session"

NoCurrentSessionExpectedError is the error text that will get converted into a NoCurrentSessionError.


var PrereleaseBuild string

PrereleaseBuild is set at compile time for prerelease builds


Functions

func AddDeviceForLocalUserOrBust

func AddDeviceForLocalUserOrBust(t logger.TestLogBackend, config Config,
	uid keybase1.UID) int

AddDeviceForLocalUserOrBust creates a new device for a user and returns the index for that device.

func AddImplicitTeamForTest

func AddImplicitTeamForTest(
	config Config, name, suffix string, teamNumber byte, ty tlf.Type) (
	keybase1.TeamID, error)

AddImplicitTeamForTest adds an implicit team with a TLF ID.

func AddImplicitTeamForTestOrBust

func AddImplicitTeamForTestOrBust(t logger.TestLogBackend,
	config Config, name, suffix string, teamNumber byte,
	ty tlf.Type) keybase1.TeamID

AddImplicitTeamForTestOrBust is like AddImplicitTeamForTest, but dies if there's an error.

func AddNewAssertionForTest

func AddNewAssertionForTest(
	config Config, oldAssertion, newAssertion string) error

AddNewAssertionForTest makes newAssertion, which should be a single assertion that doesn't already resolve to anything, resolve to the same UID as oldAssertion, which should be an arbitrary assertion that does already resolve to something. It only applies to the given config.

func AddNewAssertionForTestOrBust

func AddNewAssertionForTestOrBust(t logger.TestLogBackend, config Config,
	oldAssertion, newAssertion string)

AddNewAssertionForTestOrBust is like AddNewAssertionForTest, but dies if there's an error.

func AddTeamKeyForTest

func AddTeamKeyForTest(config Config, tid keybase1.TeamID) error

AddTeamKeyForTest adds a new key for the given team.

func AddTeamKeyForTestOrBust

func AddTeamKeyForTestOrBust(t logger.TestLogBackend, config Config,
	tid keybase1.TeamID)

AddTeamKeyForTestOrBust is like AddTeamKeyForTest, but dies if there's an error.

func AddTeamReaderForTest

func AddTeamReaderForTest(
	config Config, tid keybase1.TeamID, uid keybase1.UID) error

AddTeamReaderForTest makes the given user a team reader.

func AddTeamReaderForTestOrBust

func AddTeamReaderForTestOrBust(t logger.TestLogBackend, config Config,
	tid keybase1.TeamID, uid keybase1.UID)

AddTeamReaderForTestOrBust is like AddTeamWriterForTest, but dies if there's an error.

func AddTeamWriterForTest

func AddTeamWriterForTest(
	config Config, tid keybase1.TeamID, uid keybase1.UID) error

AddTeamWriterForTest makes the given user a team writer.

func AddTeamWriterForTestOrBust

func AddTeamWriterForTestOrBust(t logger.TestLogBackend, config Config,
	tid keybase1.TeamID, uid keybase1.UID)

AddTeamWriterForTestOrBust is like AddTeamWriterForTest, but dies if there's an error.

func BackgroundContextWithCancellationDelayer

func BackgroundContextWithCancellationDelayer() context.Context

BackgroundContextWithCancellationDelayer generate a "Background" context that is cancellation delayable

func BoolForString

func BoolForString(s string) bool

BoolForString returns false if trimmed string is "" (empty), "0", "false", or "no"

func BuildCanonicalPath

func BuildCanonicalPath(pathType PathType, paths ...string) string

BuildCanonicalPath returns a canonical path for a path components. This a canonical path and may need to be converted to a platform specific path, for example, on Windows, this might correspond to k:\private\username.

func ChangeTeamNameForTest

func ChangeTeamNameForTest(
	config Config, oldName, newName string) error

ChangeTeamNameForTest renames a team.

func ChangeTeamNameForTestOrBust

func ChangeTeamNameForTestOrBust(t logger.TestLogBackend, config Config,
	oldName, newName string)

ChangeTeamNameForTestOrBust is like ChangeTeamNameForTest, but dies if there's an error.

func CheckConfigAndShutdown

func CheckConfigAndShutdown(
	ctx context.Context, t logger.TestLogBackend, config Config)

CheckConfigAndShutdown shuts down the given config, but fails the test if there's an error.

func CheckTlfHandleOffline

func CheckTlfHandleOffline(
	ctx context.Context, name string, t tlf.Type) error

CheckTlfHandleOffline does light checks whether a TLF handle looks ok, it avoids all network calls.

func CleanupCancellationDelayer

func CleanupCancellationDelayer(ctx context.Context) error

CleanupCancellationDelayer cleans up a context (ctx) that is cancellation delayable and makes the go routine spawned in NewContextWithCancellationDelayer exit. As part of the cleanup, this also causes the cancellation delayable context to be canceled, no matter whether the timeout passed into the EnableDelayedCancellationWithGracePeriod has passed or not.

Ideally, the parent ctx's cancelFunc is always called upon completion of handling a request, in which case this wouldn't be necessary.

func ConvertIdentifyError

func ConvertIdentifyError(assertion string, err error) error

ConvertIdentifyError converts a errors during identify into KBFS errors

func CtxWithRandomIDReplayable

func CtxWithRandomIDReplayable(ctx context.Context, tagKey interface{},
	tagName string, log Warninger) context.Context

CtxWithRandomIDReplayable returns a replayable context with a random id associated with the given log key.

func DisableCRForTesting

func DisableCRForTesting(config Config, folderBranch FolderBranch) error

DisableCRForTesting stops conflict resolution for the given folder. RestartCRForTesting should be called to restart it.

func DisableUpdatesForTesting

func DisableUpdatesForTesting(config Config, folderBranch FolderBranch) (
	chan<- struct{}, error)

DisableUpdatesForTesting stops the given folder from acting on new updates. Send a struct{}{} down the returned channel to restart notifications

func DumpPrivateMetadata

func DumpPrivateMetadata(
	codec kbfscodec.Codec, serializedPMDLength int, pmd PrivateMetadata) (string, error)

DumpPrivateMetadata returns a detailed dump of the given PrivateMetadata's contents.

func EnableAdminFeature

func EnableAdminFeature(ctx context.Context, runMode libkb.RunMode, config Config) bool

EnableAdminFeature returns true if admin features should be enabled for the currently-logged-in user.

func EnableDelayedCancellationWithGracePeriod

func EnableDelayedCancellationWithGracePeriod(ctx context.Context, timeout time.Duration) error

EnableDelayedCancellationWithGracePeriod can be called on a "cancellation delayable" context produced by NewContextWithCancellationDelayer, to enable delayed cancellation for ctx. This is useful to indicate that the operation(s) associated with the context has entered a critical state, and it should not be canceled until after timeout or CleanupCancellationDelayer is called.

Note that if EnableDelayedCancellationWithGracePeriod is called for the second time, and the grace period has started due to a cancellation, the grace period would not be extended (i.e. timeout has no effect in this case). Although in this case, no error is returned, since the delayed cancellation is already enabled.

func EnableImplicitTeamsForTest

func EnableImplicitTeamsForTest(config Config) error

EnableImplicitTeamsForTest causes the mdserver to stop returning random TLF IDs for new TLFs.

func ForceQuotaReclamationForTesting

func ForceQuotaReclamationForTesting(config Config,
	folderBranch FolderBranch) error

ForceQuotaReclamationForTesting kicks off quota reclamation under the given config, for the given folder-branch.

func GetDefaultsUsageString

func GetDefaultsUsageString(ctx Context) string

GetDefaultsUsageString returns a string describing the default values of flags based on the run mode.

func GetLocalUsageString

func GetLocalUsageString() string

GetLocalUsageString returns a string describing the flags to use to run in a local testing environment.

func GetRemoteUsageString

func GetRemoteUsageString() string

GetRemoteUsageString returns a string describing the flags to use to run against remote KBFS servers.

func InitLog

func InitLog(params InitParams, ctx Context) (logger.Logger, error)

InitLog sets up logging switching to a log file if necessary. Returns a valid logger even on error, which are non-fatal, thus errors from this function may be ignored. Possible errors are logged to the logger returned.

func InitLogWithPrefix

func InitLogWithPrefix(
	params InitParams, ctx Context, prefix string,
	defaultLogPath string) (logger.Logger, error)

InitLogWithPrefix sets up logging switching to a log file if necessary, given a prefix and a default log path. Returns a valid logger even on error, which are non-fatal, thus errors from this function may be ignored. Possible errors are logged to the logger returned.

func MakeLocalTLFCryptKeyOrBust

func MakeLocalTLFCryptKeyOrBust(
	name string, keyGen kbfsmd.KeyGen) kbfscrypto.TLFCryptKey

MakeLocalTLFCryptKeyOrBust returns a unique private symmetric key for a TLF.

func MakeLocalUserCryptPrivateKeyOrBust

func MakeLocalUserCryptPrivateKeyOrBust(
	name libkb.NormalizedUsername) kbfscrypto.CryptPrivateKey

MakeLocalUserCryptPrivateKeyOrBust returns a unique private encryption key for this user.

func MakeLocalUserCryptPublicKeyOrBust

func MakeLocalUserCryptPublicKeyOrBust(
	name libkb.NormalizedUsername) kbfscrypto.CryptPublicKey

MakeLocalUserCryptPublicKeyOrBust returns the public key corresponding to the crypt private key for this user.

func MakeLocalUserSigningKeyOrBust

func MakeLocalUserSigningKeyOrBust(
	name libkb.NormalizedUsername) kbfscrypto.SigningKey

MakeLocalUserSigningKeyOrBust returns a unique signing key for this user.

func MakeLocalUserVerifyingKeyOrBust

func MakeLocalUserVerifyingKeyOrBust(
	name libkb.NormalizedUsername) kbfscrypto.VerifyingKey

MakeLocalUserVerifyingKeyOrBust makes a new verifying key corresponding to the signing key for this user.

func MakeRandomRequestID

func MakeRandomRequestID() (string, error)

MakeRandomRequestID generates a random ID suitable for tagging a request in KBFS, and very likely to be universally unique.

func NewContextReplayable

func NewContextReplayable(
	ctx context.Context, change CtxReplayFunc) context.Context

NewContextReplayable creates a new context from ctx, with change applied. It also makes this change replayable by NewContextWithReplayFrom. When replayed, the resulting context is replayable as well.

It is important that all WithValue-ish mutations on ctx is done "replayably" (with NewContextReplayable) if any delayed cancellation is used, e.g. through EnableDelayedCancellationWithGracePeriod,

func NewContextWithCancellationDelayer

func NewContextWithCancellationDelayer(
	ctx context.Context) (newCtx context.Context, err error)

NewContextWithCancellationDelayer creates a new context out of ctx. All replay functions attached to ctx are run on the new context. In addition, the new context is made "cancellation delayable". That is, it disconnects the cancelFunc from ctx, and watch for the cancellation. When cancellation happens, it checks if delayed cancellation is enabled for the associated context. If so, it waits until it's disabled before cancelling the new context. This provides a hacky way to allow finer control over cancellation.

Note that, it's important to call context.WithCancel (or its friends) before this function if those cancellations need to be controllable ("cancellation delayable"). Otherwise, the new cancelFunc is inherently NOT ("cancellation delayable").

If this function is called, it is caller's responsibility to either 1) cancel ctx (the context passed in); or 2) call CleanupCancellationDelayer; when operations associated with the context is done. Otherwise it leaks go routines!

func NewContextWithReplayFrom

func NewContextWithReplayFrom(ctx context.Context) (context.Context, error)

NewContextWithReplayFrom constructs a new context out of ctx by calling all attached replay functions. This disconnects any existing context.CancelFunc.

func NewEmptyTLFReaderKeyBundle

func NewEmptyTLFReaderKeyBundle() kbfsmd.TLFReaderKeyBundleV2

NewEmptyTLFReaderKeyBundle creates a new empty kbfsmd.TLFReaderKeyBundleV2

func NewEmptyTLFWriterKeyBundle

func NewEmptyTLFWriterKeyBundle() kbfsmd.TLFWriterKeyBundleV2

NewEmptyTLFWriterKeyBundle creates a new empty kbfsmd.TLFWriterKeyBundleV2

func NewReadAccessError

func NewReadAccessError(h *TlfHandle, username libkb.NormalizedUsername, filename string) error

NewReadAccessError constructs a ReadAccessError for the given directory and user.

func NewRekeyPermissionError

func NewRekeyPermissionError(
	dir *TlfHandle, username libkb.NormalizedUsername) error

NewRekeyPermissionError constructs a RekeyPermissionError for the given directory and user.

func NewSharedKeybaseConnection

func NewSharedKeybaseConnection(kbCtx Context, config Config,
	handler rpc.ConnectionHandler) *rpc.Connection

NewSharedKeybaseConnection returns a connection that tries to connect to the local keybase daemon.

func NewWriteAccessError

func NewWriteAccessError(h *TlfHandle, username libkb.NormalizedUsername, filename string) error

NewWriteAccessError is an access error trying to write a file

func NewWriteUnsupportedError

func NewWriteUnsupportedError(filename string) error

NewWriteUnsupportedError returns unsupported error trying to write a file

func PutBlockCheckLimitErrs

func PutBlockCheckLimitErrs(ctx context.Context, bserv BlockServer,
	reporter Reporter, tlfID tlf.ID, blockPtr BlockPointer,
	readyBlockData ReadyBlockData, tlfName tlf.CanonicalName) error

PutBlockCheckLimitErrs is a thin wrapper around putBlockToServer (which calls either bserver.Put or bserver.AddBlockReference) that reports quota and disk limit errors.

func ReadyBlock

func ReadyBlock(ctx context.Context, bcache BlockCache, bops BlockOps,
	crypto cryptoPure, kmd KeyMetadata, block Block,
	chargedTo keybase1.UserOrTeamID, bType keybase1.BlockType) (
	info BlockInfo, plainSize int, readyBlockData ReadyBlockData, err error)

ReadyBlock is a thin wrapper around BlockOps.Ready() that handles checking for duplicates.

func RegisterOps

func RegisterOps(codec kbfscodec.Codec)

RegisterOps registers all op types with the given codec.

func ResetRootBlock

func ResetRootBlock(ctx context.Context, config Config,
	rmd *RootMetadata) (Block, BlockInfo, ReadyBlockData, error)

ResetRootBlock creates a new empty dir block and sets the given metadata's root block to it.

func RestartCRForTesting

func RestartCRForTesting(baseCtx context.Context, config Config,
	folderBranch FolderBranch) error

RestartCRForTesting re-enables conflict resolution for the given folder. baseCtx must have a cancellation delayer.

func RevokeDeviceForLocalUserOrBust

func RevokeDeviceForLocalUserOrBust(t logger.TestLogBackend, config Config,
	uid keybase1.UID, index int)

RevokeDeviceForLocalUserOrBust revokes a device for a user in the given index.

func Shutdown

func Shutdown()

Shutdown does any necessary shutdown tasks for libkbfs. Shutdown should be called at the end of main.

func StallBlockOp

func StallBlockOp(ctx context.Context, config Config,
	stalledOp StallableBlockOp, maxStalls int) (
	onStalled <-chan struct{}, unstall chan<- struct{}, newCtx context.Context)

StallBlockOp sets a wrapped BlockOps in config so that the specified Op, stalledOp, is stalled. Caller should use the returned newCtx for subsequent operations for the stall to be effective. onStalled is a channel to notify the caller when the stall has happened. unstall is a channel for caller to unstall an Op.

func StallMDOp

func StallMDOp(ctx context.Context, config Config, stalledOp StallableMDOp,
	maxStalls int) (
	onStalled <-chan struct{}, unstall chan<- struct{}, newCtx context.Context)

StallMDOp sets a wrapped MDOps in config so that the specified Op, stalledOp, is stalled. Caller should use the returned newCtx for subsequent operations for the stall to be effective. onStalled is a channel to notify the caller when the stall has happened. unstall is a channel for caller to unstall an Op.

func SwitchDeviceForLocalUserOrBust

func SwitchDeviceForLocalUserOrBust(t logger.TestLogBackend, config Config, index int)

SwitchDeviceForLocalUserOrBust switches the current user's current device

func TLFJournalEnabled

func TLFJournalEnabled(config Config, tlfID tlf.ID) bool

TLFJournalEnabled returns true if journaling is enabled for the given TLF.

func VersionString

func VersionString() string

VersionString returns semantic version string

func WaitForTLFJournal

func WaitForTLFJournal(ctx context.Context, config Config, tlfID tlf.ID,
	log logger.Logger) error

WaitForTLFJournal waits for the corresponding journal to flush, if one exists.

Types

type BadCryptoError

type BadCryptoError struct {
	ID kbfsblock.ID
}

BadCryptoError indicates that KBFS performed a bad crypto operation.

func (BadCryptoError) Error

func (e BadCryptoError) Error() string

Error implements the error interface for BadCryptoError

type BadCryptoMDError

type BadCryptoMDError struct {
	ID tlf.ID
}

BadCryptoMDError indicates that KBFS performed a bad crypto operation, specifically on a MD object.

func (BadCryptoMDError) Error

func (e BadCryptoMDError) Error() string

Error implements the error interface for BadCryptoMDError

type BadDataError

type BadDataError struct {
	ID kbfsblock.ID
}

BadDataError indicates that KBFS is storing corrupt data for a block.

func (BadDataError) Error

func (e BadDataError) Error() string

Error implements the error interface for BadDataError

type BadMDError

type BadMDError struct {
	ID tlf.ID
}

BadMDError indicates that the system is storing corrupt MD object for the given TLF ID.

func (BadMDError) Error

func (e BadMDError) Error() string

Error implements the error interface for BadMDError

type BadSplitError

type BadSplitError struct {
}

BadSplitError indicates that the BlockSplitter has an error.

func (BadSplitError) Error

func (e BadSplitError) Error() string

Error implements the error interface for BadSplitError

type BadTLFNameError

type BadTLFNameError struct {
	Name string
}

BadTLFNameError indicates a top-level folder name that has an incorrect format.

func (BadTLFNameError) Error

func (e BadTLFNameError) Error() string

Error implements the error interface for BadTLFNameError.

type Block

type Block interface {

	// GetEncodedSize returns the encoded size of this block, but only
	// if it has been previously set; otherwise it returns 0.
	GetEncodedSize() uint32
	// SetEncodedSize sets the encoded size of this block, locally
	// caching it.  The encoded size is not serialized.
	SetEncodedSize(size uint32)
	// NewEmpty returns a new block of the same type as this block
	NewEmpty() Block
	// Set sets this block to the same value as the passed-in block
	Set(other Block)
	// ToCommonBlock retrieves this block as a *CommonBlock.
	ToCommonBlock() *CommonBlock
	// contains filtered or unexported methods
}

Block just needs to be (de)serialized using msgpack

func NewCommonBlock

func NewCommonBlock() Block

NewCommonBlock returns a generic block, unsuitable for caching.

func NewDirBlock

func NewDirBlock() Block

NewDirBlock creates a new, empty DirBlock.

func NewFileBlock

func NewFileBlock() Block

NewFileBlock creates a new, empty FileBlock.

type BlockCache

type BlockCache interface {
	BlockCacheSimple
	// CheckForKnownPtr sees whether this cache has a transient
	// entry for the given file block, which must be a direct file
	// block containing data).  Returns the full BlockPointer
	// associated with that ID, including key and data versions.
	// If no ID is known, return an uninitialized BlockPointer and
	// a nil error.
	CheckForKnownPtr(tlf tlf.ID, block *FileBlock) (BlockPointer, error)
	// DeleteTransient removes the transient entry for the given
	// pointer from the cache, as well as any cached IDs so the block
	// won't be reused.
	DeleteTransient(ptr BlockPointer, tlf tlf.ID) error
	// Delete removes the permanent entry for the non-dirty block
	// associated with the given block ID from the cache.  No
	// error is returned if no block exists for the given ID.
	DeletePermanent(id kbfsblock.ID) error
	// DeleteKnownPtr removes the cached ID for the given file
	// block. It does not remove the block itself.
	DeleteKnownPtr(tlf tlf.ID, block *FileBlock) error
	// GetWithPrefetch retrieves a block from the cache, along with the block's
	// prefetch status.
	GetWithPrefetch(ptr BlockPointer) (block Block,
		prefetchStatus PrefetchStatus, lifetime BlockCacheLifetime, err error)
	// PutWithPrefetch puts a block into the cache, along with whether or not
	// it has triggered or finished a prefetch.
	PutWithPrefetch(ptr BlockPointer, tlf tlf.ID, block Block,
		lifetime BlockCacheLifetime, prefetchStatus PrefetchStatus) error

	// SetCleanBytesCapacity atomically sets clean bytes capacity for block
	// cache.
	SetCleanBytesCapacity(capacity uint64)

	// GetCleanBytesCapacity atomically gets clean bytes capacity for block
	// cache.
	GetCleanBytesCapacity() (capacity uint64)
}

BlockCache specifies the interface of BlockCacheSimple, and also more advanced and internal methods.

type BlockCacheLifetime

type BlockCacheLifetime int

BlockCacheLifetime denotes the lifetime of an entry in BlockCache.

const (
	// NoCacheEntry means that the entry will not be cached.
	NoCacheEntry BlockCacheLifetime = iota
	// TransientEntry means that the cache entry may be evicted at
	// any time.
	TransientEntry
	// PermanentEntry means that the cache entry must remain until
	// explicitly removed from the cache.
	PermanentEntry
)

func (BlockCacheLifetime) String

func (l BlockCacheLifetime) String() string

type BlockCacheSimple

type BlockCacheSimple interface {
	// Get gets the block associated with the given block ID.
	Get(ptr BlockPointer) (Block, error)
	// Put stores the final (content-addressable) block associated
	// with the given block ID. If lifetime is TransientEntry,
	// then it is assumed that the block exists on the server and
	// the entry may be evicted from the cache at any time. If
	// lifetime is PermanentEntry, then it is assumed that the
	// block doesn't exist on the server and must remain in the
	// cache until explicitly removed. As an intermediary state,
	// as when a block is being sent to the server, the block may
	// be put into the cache both with TransientEntry and
	// PermanentEntry -- these are two separate entries. This is
	// fine, since the block should be the same.
	Put(ptr BlockPointer, tlf tlf.ID, block Block,
		lifetime BlockCacheLifetime) error
}

BlockCacheSimple gets and puts plaintext dir blocks and file blocks into a cache. These blocks are immutable and identified by their content hash.

type BlockCacheStandard

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

BlockCacheStandard implements the BlockCache interface by storing blocks in an in-memory LRU cache. Clean blocks are identified internally by just their block ID (since blocks are immutable and content-addressable).

func NewBlockCacheStandard

func NewBlockCacheStandard(transientCapacity int,
	cleanBytesCapacity uint64) *BlockCacheStandard

NewBlockCacheStandard constructs a new BlockCacheStandard instance with the given transient capacity (in number of entries) and the clean bytes capacity, which is the total of number of bytes allowed between the transient and permanent clean caches. If putting a block will exceed this bytes capacity, transient entries are evicted until the block will fit in capacity.

func (*BlockCacheStandard) CheckForKnownPtr

func (b *BlockCacheStandard) CheckForKnownPtr(tlf tlf.ID, block *FileBlock) (
	BlockPointer, error)

CheckForKnownPtr implements the BlockCache interface for BlockCacheStandard.

func (*BlockCacheStandard) DeleteKnownPtr

func (b *BlockCacheStandard) DeleteKnownPtr(tlf tlf.ID, block *FileBlock) error

DeleteKnownPtr implements the BlockCache interface for BlockCacheStandard.

func (*BlockCacheStandard) DeletePermanent

func (b *BlockCacheStandard) DeletePermanent(id kbfsblock.ID) error

DeletePermanent implements the BlockCache interface for BlockCacheStandard.

func (*BlockCacheStandard) DeleteTransient

func (b *BlockCacheStandard) DeleteTransient(
	ptr BlockPointer, tlf tlf.ID) error

DeleteTransient implements the BlockCache interface for BlockCacheStandard.

func (*BlockCacheStandard) Get

func (b *BlockCacheStandard) Get(ptr BlockPointer) (Block, error)

Get implements the BlockCache interface for BlockCacheStandard.

func (*BlockCacheStandard) GetCleanBytesCapacity

func (b *BlockCacheStandard) GetCleanBytesCapacity() (capacity uint64)

GetCleanBytesCapacity implements the BlockCache interface for BlockCacheStandard.

func (*BlockCacheStandard) GetWithPrefetch

func (b *BlockCacheStandard) GetWithPrefetch(ptr BlockPointer) (
	Block, PrefetchStatus, BlockCacheLifetime, error)

GetWithPrefetch implements the BlockCache interface for BlockCacheStandard.

func (*BlockCacheStandard) Put

func (b *BlockCacheStandard) Put(
	ptr BlockPointer, tlf tlf.ID, block Block, lifetime BlockCacheLifetime) error

Put implements the BlockCache interface for BlockCacheStandard.

func (*BlockCacheStandard) PutWithPrefetch

func (b *BlockCacheStandard) PutWithPrefetch(
	ptr BlockPointer, tlf tlf.ID, block Block, lifetime BlockCacheLifetime,
	prefetchStatus PrefetchStatus) (err error)

PutWithPrefetch implements the BlockCache interface for BlockCacheStandard. This method is idempotent for a given ptr, but that invariant is not currently goroutine-safe, and it does not hold if a block size changes between Puts. That is, we assume that a cached block associated with a given pointer will never change its size, even when it gets Put into the cache again.

func (*BlockCacheStandard) SetCleanBytesCapacity

func (b *BlockCacheStandard) SetCleanBytesCapacity(capacity uint64)

SetCleanBytesCapacity implements the BlockCache interface for BlockCacheStandard.

type BlockChanges

type BlockChanges struct {
	// If this is set, the actual changes are stored in a block (where
	// the block contains a serialized version of BlockChanges)
	Info BlockInfo `codec:"p,omitempty"`
	// An ordered list of operations completed in this update
	Ops opsList `codec:"o,omitempty"`
	// contains filtered or unexported fields
}

BlockChanges tracks the set of blocks that changed in a commit, and the operations that made the changes. It might consist of just a BlockPointer if the list is too big to embed in the MD structure directly.

If this commit represents a conflict-resolution merge, which may comprise multiple individual operations, then there will be an ordered list of the changes for individual operations. This lets the notification and conflict resolution strategies figure out the difference between a renamed file and a modified file, for example.

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

func (*BlockChanges) AddOp

func (bc *BlockChanges) AddOp(o op)

AddOp starts a new operation for this BlockChanges. Subsequent Add* calls will populate this operation.

func (*BlockChanges) AddRefBlock

func (bc *BlockChanges) AddRefBlock(ptr BlockPointer)

AddRefBlock adds the newly-referenced block to this BlockChanges and updates the size estimate.

func (*BlockChanges) AddUnrefBlock

func (bc *BlockChanges) AddUnrefBlock(ptr BlockPointer)

AddUnrefBlock adds the newly unreferenced block to this BlockChanges and updates the size estimate.

func (*BlockChanges) AddUpdate

func (bc *BlockChanges) AddUpdate(oldPtr BlockPointer, newPtr BlockPointer)

AddUpdate adds the newly updated block to this BlockChanges and updates the size estimate.

func (BlockChanges) Equals

func (bc BlockChanges) Equals(other BlockChanges) bool

Equals returns true if the given BlockChanges is equal to this BlockChanges. Currently does not check for equality at the operation level.

func (*BlockChanges) SizeEstimate

func (bc *BlockChanges) SizeEstimate() uint64

SizeEstimate calculates the estimated size of the encoded version of this BlockChanges.

type BlockDecodeError

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

BlockDecodeError indicates that a block couldn't be decoded as expected; probably it is the wrong type.

func (BlockDecodeError) Error

func (e BlockDecodeError) Error() string

Error implements the error interface for BlockDecodeError

type BlockDirectType

type BlockDirectType int

BlockDirectType indicates to what kind of block (direct or indirect) a BlockPointer points.

const (
	// UnknownDirectType indicates an old block that was written
	// before we started labeling pointers.
	UnknownDirectType BlockDirectType = 0
	// DirectBlock indicates the pointed-to block has no indirect
	// pointers.
	DirectBlock BlockDirectType = 1
	// IndirectBlock indicates the pointed-to block has indirect
	// pointers.
	IndirectBlock BlockDirectType = 2
)

func (BlockDirectType) String

func (bdt BlockDirectType) String() string

type BlockInfo

type BlockInfo struct {
	BlockPointer
	// When non-zero, the size of the encoded (and possibly
	// encrypted) data contained in the block. When non-zero,
	// always at least the size of the plaintext data contained in
	// the block.
	EncodedSize uint32 `codec:"e"`
}

BlockInfo contains all information about a block in KBFS and its contents.

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

func (BlockInfo) String

func (bi BlockInfo) String() string

type BlockOps

type BlockOps interface {

	// Get gets the block associated with the given block pointer
	// (which belongs to the TLF with the given key metadata),
	// decrypts it if necessary, and fills in the provided block
	// object with its contents, if the logged-in user has read
	// permission for that block. cacheLifetime controls the behavior of the
	// write-through cache once a Get completes.
	Get(ctx context.Context, kmd KeyMetadata, blockPtr BlockPointer,
		block Block, cacheLifetime BlockCacheLifetime) error

	// GetEncodedSize gets the encoded size of the block associated
	// with the given block pointer (which belongs to the TLF with the
	// given key metadata).
	GetEncodedSize(ctx context.Context, kmd KeyMetadata,
		blockPtr BlockPointer) (uint32, error)

	// Ready turns the given block (which belongs to the TLF with
	// the given key metadata) into encoded (and encrypted) data,
	// and calculates its ID and size, so that we can do a bunch
	// of block puts in parallel for every write. Ready() must
	// guarantee that plainSize <= readyBlockData.QuotaSize().
	Ready(ctx context.Context, kmd KeyMetadata, block Block) (
		id kbfsblock.ID, plainSize int, readyBlockData ReadyBlockData, err error)

	// Delete instructs the server to delete the given block references.
	// It returns the number of not-yet deleted references to
	// each block reference
	Delete(ctx context.Context, tlfID tlf.ID, ptrs []BlockPointer) (
		liveCounts map[kbfsblock.ID]int, err error)

	// Archive instructs the server to mark the given block references
	// as "archived"; that is, they are not being used in the current
	// view of the folder, and shouldn't be served to anyone other
	// than folder writers.
	Archive(ctx context.Context, tlfID tlf.ID, ptrs []BlockPointer) error

	// TogglePrefetcher activates or deactivates the prefetcher.
	TogglePrefetcher(enable bool) <-chan struct{}

	// Prefetcher retrieves this BlockOps' Prefetcher.
	Prefetcher() Prefetcher

	// Shutdown shuts down all the workers performing Get operations
	Shutdown()
	// contains filtered or unexported methods
}

BlockOps gets and puts data blocks to a BlockServer. It performs the necessary crypto operations on each block.

type BlockOpsConstrained

type BlockOpsConstrained struct {
	BlockOps
	// contains filtered or unexported fields
}

BlockOpsConstrained implements the BlockOps interface by relaying requests to a delegate BlockOps, but it delays all Puts by simulating a bottleneck of the given bandwidth.

func NewBlockOpsConstrained

func NewBlockOpsConstrained(delegate BlockOps, bwKBps int) *BlockOpsConstrained

NewBlockOpsConstrained constructs a new BlockOpsConstrained.

type BlockOpsStandard

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

BlockOpsStandard implements the BlockOps interface by relaying requests to the block server.

func NewBlockOpsStandard

func NewBlockOpsStandard(config blockOpsConfig,
	queueSize, prefetchQueueSize int) *BlockOpsStandard

NewBlockOpsStandard creates a new BlockOpsStandard

func (*BlockOpsStandard) Archive

func (b *BlockOpsStandard) Archive(ctx context.Context, tlfID tlf.ID,
	ptrs []BlockPointer) error

Archive implements the BlockOps interface for BlockOpsStandard.

func (*BlockOpsStandard) BlockRetriever

func (b *BlockOpsStandard) BlockRetriever() BlockRetriever

BlockRetriever implements the BlockOps interface for BlockOpsStandard.

func (*BlockOpsStandard) Delete

func (b *BlockOpsStandard) Delete(ctx context.Context, tlfID tlf.ID,
	ptrs []BlockPointer) (liveCounts map[kbfsblock.ID]int, err error)

Delete implements the BlockOps interface for BlockOpsStandard.

func (*BlockOpsStandard) Get

func (b *BlockOpsStandard) Get(ctx context.Context, kmd KeyMetadata,
	blockPtr BlockPointer, block Block, lifetime BlockCacheLifetime) error

Get implements the BlockOps interface for BlockOpsStandard.

func (*BlockOpsStandard) GetEncodedSize

func (b *BlockOpsStandard) GetEncodedSize(ctx context.Context, kmd KeyMetadata,
	blockPtr BlockPointer) (uint32, error)

GetEncodedSize implements the BlockOps interface for BlockOpsStandard.

func (*BlockOpsStandard) Prefetcher

func (b *BlockOpsStandard) Prefetcher() Prefetcher

Prefetcher implements the BlockOps interface for BlockOpsStandard.

func (*BlockOpsStandard) Ready

func (b *BlockOpsStandard) Ready(ctx context.Context, kmd KeyMetadata,
	block Block) (id kbfsblock.ID, plainSize int, readyBlockData ReadyBlockData,
	err error)

Ready implements the BlockOps interface for BlockOpsStandard.

func (*BlockOpsStandard) Shutdown

func (b *BlockOpsStandard) Shutdown()

Shutdown implements the BlockOps interface for BlockOpsStandard.

func (*BlockOpsStandard) TogglePrefetcher

func (b *BlockOpsStandard) TogglePrefetcher(enable bool) <-chan struct{}

TogglePrefetcher implements the BlockOps interface for BlockOpsStandard.

type BlockPointer

type BlockPointer struct {
	ID         kbfsblock.ID    `codec:"i"`
	KeyGen     kbfsmd.KeyGen   `codec:"k"`           // if valid, which generation of the TLF{Writer,Reader}KeyBundle to use.
	DataVer    DataVer         `codec:"d"`           // if valid, which version of the KBFS data structures is pointed to
	DirectType BlockDirectType `codec:"t,omitempty"` // the type (direct, indirect, or unknown [if omitted]) of the pointed-to block
	kbfsblock.Context
}

BlockPointer contains the identifying information for a block in KBFS.

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

func (BlockPointer) IsInitialized

func (p BlockPointer) IsInitialized() bool

IsInitialized returns whether or not this BlockPointer has non-nil data.

func (BlockPointer) IsValid

func (p BlockPointer) IsValid() bool

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

func (BlockPointer) Ref

func (p BlockPointer) Ref() BlockRef

Ref returns the BlockRef equivalent of this pointer.

func (BlockPointer) String

func (p BlockPointer) String() string

type BlockRef

type BlockRef struct {
	ID       kbfsblock.ID
	RefNonce kbfsblock.RefNonce
}

BlockRef is a block ID/ref nonce pair, which defines a unique reference to a block.

func (BlockRef) IsValid

func (r BlockRef) IsValid() bool

IsValid returns true exactly when ID.IsValid() does.

func (BlockRef) String

func (r BlockRef) String() string

type BlockRetriever

type BlockRetriever interface {
	// Request retrieves blocks asynchronously.
	Request(ctx context.Context, priority int, kmd KeyMetadata,
		ptr BlockPointer, block Block, lifetime BlockCacheLifetime) <-chan error
	// RequestNoPrefetch retrieves blocks asynchronously, but doesn't trigger a
	// prefetch unless the block had to be retrieved from the server.
	RequestNoPrefetch(ctx context.Context, priority int, kmd KeyMetadata,
		ptr BlockPointer, block Block, lifetime BlockCacheLifetime) <-chan error
	// PutInCaches puts the block into the in-memory cache, and ensures that
	// the disk cache metadata is updated.
	PutInCaches(ctx context.Context, ptr BlockPointer, tlfID tlf.ID,
		block Block, lifetime BlockCacheLifetime,
		prefetchStatus PrefetchStatus) error
	// TogglePrefetcher creates a new prefetcher.
	TogglePrefetcher(enable bool, syncCh <-chan struct{}) <-chan struct{}
}

BlockRetriever specifies how to retrieve blocks.

type BlockServer

type BlockServer interface {

	// Get gets the (encrypted) block data associated with the given
	// block ID and context, uses the provided block key to decrypt
	// the block, and fills in the provided block object with its
	// contents, if the logged-in user has read permission for that
	// block.
	Get(ctx context.Context, tlfID tlf.ID, id kbfsblock.ID, context kbfsblock.Context) (
		[]byte, kbfscrypto.BlockCryptKeyServerHalf, error)
	// Put stores the (encrypted) block data under the given ID
	// and context on the server, along with the server half of
	// the block key.  context should contain a kbfsblock.RefNonce
	// of zero.  There will be an initial reference for this block
	// for the given context.
	//
	// Put should be idempotent, although it should also return an
	// error if, for a given ID, any of the other arguments differ
	// from previous Put calls with the same ID.
	//
	// If this returns a kbfsblock.ServerErrorOverQuota, with
	// Throttled=false, the caller can treat it as informational
	// and otherwise ignore the error.
	Put(ctx context.Context, tlfID tlf.ID, id kbfsblock.ID, context kbfsblock.Context,
		buf []byte, serverHalf kbfscrypto.BlockCryptKeyServerHalf) error

	// PutAgain re-stores a previously deleted block under the same ID
	// with the same data.
	PutAgain(ctx context.Context, tlfID tlf.ID, id kbfsblock.ID, context kbfsblock.Context,
		buf []byte, serverHalf kbfscrypto.BlockCryptKeyServerHalf) error

	// AddBlockReference adds a new reference to the given block,
	// defined by the given context (which should contain a
	// non-zero kbfsblock.RefNonce).  (Contexts with a
	// kbfsblock.RefNonce of zero should be used when putting the
	// block for the first time via Put().)  Returns a
	// kbfsblock.ServerErrorBlockNonExistent if id is unknown within this
	// folder.
	//
	// AddBlockReference should be idempotent, although it should
	// also return an error if, for a given ID and refnonce, any
	// of the other fields of context differ from previous
	// AddBlockReference calls with the same ID and refnonce.
	//
	// If this returns a kbfsblock.ServerErrorOverQuota, with
	// Throttled=false, the caller can treat it as informational
	// and otherwise ignore the error.
	AddBlockReference(ctx context.Context, tlfID tlf.ID, id kbfsblock.ID,
		context kbfsblock.Context) error
	// RemoveBlockReferences removes the references to the given block
	// ID defined by the given contexts.  If no references to the block
	// remain after this call, the server is allowed to delete the
	// corresponding block permanently.  If the reference defined by
	// the count has already been removed, the call is a no-op.
	// It returns the number of remaining not-yet-deleted references after this
	// reference has been removed
	RemoveBlockReferences(ctx context.Context, tlfID tlf.ID,
		contexts kbfsblock.ContextMap) (liveCounts map[kbfsblock.ID]int, err error)

	// ArchiveBlockReferences marks the given block references as
	// "archived"; that is, they are not being used in the current
	// view of the folder, and shouldn't be served to anyone other
	// than folder writers.
	//
	// For a given ID/refnonce pair, ArchiveBlockReferences should
	// be idempotent, although it should also return an error if
	// any of the other fields of the context differ from previous
	// calls with the same ID/refnonce pair.
	ArchiveBlockReferences(ctx context.Context, tlfID tlf.ID,
		contexts kbfsblock.ContextMap) error

	// IsUnflushed returns whether a given block is being queued
	// locally for later flushing to another block server.  If the
	// block is currently being flushed to the server, this should
	// return `true`, so that the caller will try to clean it up from
	// the server if it's no longer needed.
	IsUnflushed(ctx context.Context, tlfID tlf.ID, id kbfsblock.ID) (
		bool, error)

	// Shutdown is called to shutdown a BlockServer connection.
	Shutdown(ctx context.Context)

	// GetUserQuotaInfo returns the quota for the logged-in user.
	GetUserQuotaInfo(ctx context.Context) (info *kbfsblock.QuotaInfo, err error)

	// GetTeamQuotaInfo returns the quota for a team.
	GetTeamQuotaInfo(ctx context.Context, tid keybase1.TeamID) (
		info *kbfsblock.QuotaInfo, err error)
	// contains filtered or unexported methods
}

BlockServer gets and puts opaque data blocks. The instantiation should be able to fetch session/user details via KBPKI. On a put/delete, the server is reponsible for: 1) checking that the ID matches the hash of the buffer; and 2) enforcing writer quotas.

func MakeTestBlockServerOrBust

func MakeTestBlockServerOrBust(t logger.TestLogBackend,
	config blockServerRemoteConfig,
	rpcLogFactory rpc.LogFactory) BlockServer

MakeTestBlockServerOrBust makes a block server from the given arguments and environment variables.

type BlockServerDisk

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

BlockServerDisk implements the BlockServer interface by just storing blocks in a local disk store.

func NewBlockServerDir

func NewBlockServerDir(codec kbfscodec.Codec,
	log logger.Logger, dirPath string) *BlockServerDisk

NewBlockServerDir constructs a new BlockServerDisk that stores its data in the given directory.

func NewBlockServerTempDir

func NewBlockServerTempDir(codec kbfscodec.Codec,
	log logger.Logger) (*BlockServerDisk, error)

NewBlockServerTempDir constructs a new BlockServerDisk that stores its data in a temp directory which is cleaned up on shutdown.

func (*BlockServerDisk) AddBlockReference

func (b *BlockServerDisk) AddBlockReference(ctx context.Context, tlfID tlf.ID,
	id kbfsblock.ID, context kbfsblock.Context) error

AddBlockReference implements the BlockServer interface for BlockServerDisk.

func (*BlockServerDisk) ArchiveBlockReferences

func (b *BlockServerDisk) ArchiveBlockReferences(ctx context.Context,
	tlfID tlf.ID, contexts kbfsblock.ContextMap) (err error)

ArchiveBlockReferences implements the BlockServer interface for BlockServerDisk.

func (*BlockServerDisk) Get

func (b *BlockServerDisk) Get(ctx context.Context, tlfID tlf.ID, id kbfsblock.ID,
	context kbfsblock.Context) (
	data []byte, serverHalf kbfscrypto.BlockCryptKeyServerHalf, err error)

Get implements the BlockServer interface for BlockServerDisk.

func (*BlockServerDisk) GetTeamQuotaInfo

func (b *BlockServerDisk) GetTeamQuotaInfo(
	ctx context.Context, _ keybase1.TeamID) (
	info *kbfsblock.QuotaInfo, err error)

GetTeamQuotaInfo implements the BlockServer interface for BlockServerDisk.

func (*BlockServerDisk) GetUserQuotaInfo

func (b *BlockServerDisk) GetUserQuotaInfo(ctx context.Context) (info *kbfsblock.QuotaInfo, err error)

GetUserQuotaInfo implements the BlockServer interface for BlockServerDisk.

func (*BlockServerDisk) IsUnflushed

func (b *BlockServerDisk) IsUnflushed(ctx context.Context, tlfID tlf.ID,
	_ kbfsblock.ID) (bool, error)

IsUnflushed implements the BlockServer interface for BlockServerDisk.

func (*BlockServerDisk) Put

func (b *BlockServerDisk) Put(ctx context.Context, tlfID tlf.ID, id kbfsblock.ID,
	context kbfsblock.Context, buf []byte,
	serverHalf kbfscrypto.BlockCryptKeyServerHalf) (err error)

Put implements the BlockServer interface for BlockServerDisk.

func (*BlockServerDisk) PutAgain

func (b *BlockServerDisk) PutAgain(ctx context.Context, tlfID tlf.ID, id kbfsblock.ID,
	context kbfsblock.Context, buf []byte,
	serverHalf kbfscrypto.BlockCryptKeyServerHalf) (err error)

PutAgain implements the BlockServer interface for BlockServerDisk.

func (*BlockServerDisk) RefreshAuthToken

func (b *BlockServerDisk) RefreshAuthToken(_ context.Context)

RefreshAuthToken implements the BlockServer interface for BlockServerDisk.

func (*BlockServerDisk) RemoveBlockReferences

func (b *BlockServerDisk) RemoveBlockReferences(ctx context.Context,
	tlfID tlf.ID, contexts kbfsblock.ContextMap) (
	liveCounts map[kbfsblock.ID]int, err error)

RemoveBlockReferences implements the BlockServer interface for BlockServerDisk.

func (*BlockServerDisk) Shutdown

func (b *BlockServerDisk) Shutdown(ctx context.Context)

Shutdown implements the BlockServer interface for BlockServerDisk.

type BlockServerMeasured

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

BlockServerMeasured delegates to another BlockServer instance but also keeps track of stats.

func NewBlockServerMeasured

func NewBlockServerMeasured(delegate BlockServer, r metrics.Registry) BlockServerMeasured

NewBlockServerMeasured creates and returns a new BlockServerMeasured instance with the given delegate and registry.

func (BlockServerMeasured) AddBlockReference

func (b BlockServerMeasured) AddBlockReference(ctx context.Context, tlfID tlf.ID,
	id kbfsblock.ID, context kbfsblock.Context) (err error)

AddBlockReference implements the BlockServer interface for BlockServerMeasured.

func (BlockServerMeasured) ArchiveBlockReferences

func (b BlockServerMeasured) ArchiveBlockReferences(ctx context.Context,
	tlfID tlf.ID, contexts kbfsblock.ContextMap) (err error)

ArchiveBlockReferences implements the BlockServer interface for BlockServerRemote

func (BlockServerMeasured) Get

func (b BlockServerMeasured) Get(ctx context.Context, tlfID tlf.ID, id kbfsblock.ID,
	context kbfsblock.Context) (
	buf []byte, serverHalf kbfscrypto.BlockCryptKeyServerHalf, err error)

Get implements the BlockServer interface for BlockServerMeasured.

func (BlockServerMeasured) GetTeamQuotaInfo

func (b BlockServerMeasured) GetTeamQuotaInfo(
	ctx context.Context, tid keybase1.TeamID) (
	info *kbfsblock.QuotaInfo, err error)

GetTeamQuotaInfo implements the BlockServer interface for BlockServerMeasured

func (BlockServerMeasured) GetUserQuotaInfo

func (b BlockServerMeasured) GetUserQuotaInfo(ctx context.Context) (info *kbfsblock.QuotaInfo, err error)

GetUserQuotaInfo implements the BlockServer interface for BlockServerMeasured

func (BlockServerMeasured) IsUnflushed

func (b BlockServerMeasured) IsUnflushed(ctx context.Context, tlfID tlf.ID,
	id kbfsblock.ID) (isUnflushed bool, err error)

IsUnflushed implements the BlockServer interface for BlockServerMeasured.

func (BlockServerMeasured) Put

func (b BlockServerMeasured) Put(ctx context.Context, tlfID tlf.ID, id kbfsblock.ID,
	context kbfsblock.Context, buf []byte,
	serverHalf kbfscrypto.BlockCryptKeyServerHalf) (err error)

Put implements the BlockServer interface for BlockServerMeasured.

func (BlockServerMeasured) PutAgain

func (b BlockServerMeasured) PutAgain(ctx context.Context, tlfID tlf.ID, id kbfsblock.ID,
	context kbfsblock.Context, buf []byte,
	serverHalf kbfscrypto.BlockCryptKeyServerHalf) (err error)

PutAgain implements the BlockServer interface for BlockServerMeasured.

func (BlockServerMeasured) RefreshAuthToken

func (b BlockServerMeasured) RefreshAuthToken(ctx context.Context)

RefreshAuthToken implements the BlockServer interface for BlockServerMeasured.

func (BlockServerMeasured) RemoveBlockReferences

func (b BlockServerMeasured) RemoveBlockReferences(ctx context.Context,
	tlfID tlf.ID, contexts kbfsblock.ContextMap) (
	liveCounts map[kbfsblock.ID]int, err error)

RemoveBlockReferences implements the BlockServer interface for BlockServerMeasured.

func (BlockServerMeasured) Shutdown

func (b BlockServerMeasured) Shutdown(ctx context.Context)

Shutdown implements the BlockServer interface for BlockServerMeasured.

type BlockServerMemory

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

BlockServerMemory implements the BlockServer interface by just storing blocks in memory.

func NewBlockServerMemory

func NewBlockServerMemory(log logger.Logger) *BlockServerMemory

NewBlockServerMemory constructs a new BlockServerMemory that stores its data in memory.

func (*BlockServerMemory) AddBlockReference

func (b *BlockServerMemory) AddBlockReference(ctx context.Context, tlfID tlf.ID,
	id kbfsblock.ID, context kbfsblock.Context) (err error)

AddBlockReference implements the BlockServer interface for BlockServerMemory.

func (*BlockServerMemory) ArchiveBlockReferences

func (b *BlockServerMemory) ArchiveBlockReferences(ctx context.Context,
	tlfID tlf.ID, contexts kbfsblock.ContextMap) (err error)

ArchiveBlockReferences implements the BlockServer interface for BlockServerMemory.

func (*BlockServerMemory) Get

func (b *BlockServerMemory) Get(ctx context.Context, tlfID tlf.ID,
	id kbfsblock.ID, context kbfsblock.Context) (
	data []byte, serverHalf kbfscrypto.BlockCryptKeyServerHalf, err error)

Get implements the BlockServer interface for BlockServerMemory.

func (*BlockServerMemory) GetTeamQuotaInfo

func (b *BlockServerMemory) GetTeamQuotaInfo(
	ctx context.Context, _ keybase1.TeamID) (
	info *kbfsblock.QuotaInfo, err error)

GetTeamQuotaInfo implements the BlockServer interface for BlockServerMemory.

func (*BlockServerMemory) GetUserQuotaInfo

func (b *BlockServerMemory) GetUserQuotaInfo(ctx context.Context) (info *kbfsblock.QuotaInfo, err error)

GetUserQuotaInfo implements the BlockServer interface for BlockServerMemory.

func (*BlockServerMemory) IsUnflushed

func (b *BlockServerMemory) IsUnflushed(ctx context.Context, tlfID tlf.ID,
	_ kbfsblock.ID) (bool, error)

IsUnflushed implements the BlockServer interface for BlockServerMemory.

func (*BlockServerMemory) Put

func (b *BlockServerMemory) Put(ctx context.Context, tlfID tlf.ID,
	id kbfsblock.ID, context kbfsblock.Context, buf []byte,
	serverHalf kbfscrypto.BlockCryptKeyServerHalf) (err error)

Put implements the BlockServer interface for BlockServerMemory.

func (*BlockServerMemory) PutAgain

func (b *BlockServerMemory) PutAgain(ctx context.Context, tlfID tlf.ID,
	id kbfsblock.ID, context kbfsblock.Context, buf []byte,
	serverHalf kbfscrypto.BlockCryptKeyServerHalf) (err error)

PutAgain implements the BlockServer interface for BlockServerMemory.

func (*BlockServerMemory) RefreshAuthToken

func (b *BlockServerMemory) RefreshAuthToken(_ context.Context)

RefreshAuthToken implements the BlockServer interface for BlockServerMemory.

func (*BlockServerMemory) RemoveBlockReferences

func (b *BlockServerMemory) RemoveBlockReferences(ctx context.Context,
	tlfID tlf.ID, contexts kbfsblock.ContextMap) (
	liveCounts map[kbfsblock.ID]int, err error)

RemoveBlockReferences implements the BlockServer interface for BlockServerMemory.

func (*BlockServerMemory) Shutdown

func (b *BlockServerMemory) Shutdown(ctx context.Context)

Shutdown implements the BlockServer interface for BlockServerMemory.

type BlockServerRemote

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

BlockServerRemote implements the BlockServer interface and represents a remote KBFS block server.

func NewBlockServerRemote

func NewBlockServerRemote(config blockServerRemoteConfig,
	blkSrvRemote rpc.Remote, rpcLogFactory rpc.LogFactory) *BlockServerRemote

NewBlockServerRemote constructs a new BlockServerRemote for the given address.

func (*BlockServerRemote) AddBlockReference

func (b *BlockServerRemote) AddBlockReference(ctx context.Context, tlfID tlf.ID,
	id kbfsblock.ID, context kbfsblock.Context) (err error)

AddBlockReference implements the BlockServer interface for BlockServerRemote

func (*BlockServerRemote) ArchiveBlockReferences

func (b *BlockServerRemote) ArchiveBlockReferences(ctx context.Context,
	tlfID tlf.ID, contexts kbfsblock.ContextMap) (err error)

ArchiveBlockReferences implements the BlockServer interface for BlockServerRemote

func (*BlockServerRemote) Get

func (b *BlockServerRemote) Get(ctx context.Context, tlfID tlf.ID, id kbfsblock.ID,
	context kbfsblock.Context) (
	buf []byte, serverHalf kbfscrypto.BlockCryptKeyServerHalf, err error)

Get implements the BlockServer interface for BlockServerRemote.

func (*BlockServerRemote) GetTeamQuotaInfo

func (b *BlockServerRemote) GetTeamQuotaInfo(
	ctx context.Context, tid keybase1.TeamID) (
	info *kbfsblock.QuotaInfo, err error)

GetTeamQuotaInfo implements the BlockServer interface for BlockServerRemote

func (*BlockServerRemote) GetUserQuotaInfo

func (b *BlockServerRemote) GetUserQuotaInfo(ctx context.Context) (info *kbfsblock.QuotaInfo, err error)

GetUserQuotaInfo implements the BlockServer interface for BlockServerRemote

func (*BlockServerRemote) IsUnflushed

func (b *BlockServerRemote) IsUnflushed(
	_ context.Context, _ tlf.ID, _ kbfsblock.ID) (
	bool, error)

IsUnflushed implements the BlockServer interface for BlockServerRemote.

func (*BlockServerRemote) Put

func (b *BlockServerRemote) Put(ctx context.Context, tlfID tlf.ID, id kbfsblock.ID,
	bContext kbfsblock.Context, buf []byte,
	serverHalf kbfscrypto.BlockCryptKeyServerHalf) (err error)

Put implements the BlockServer interface for BlockServerRemote.

func (*BlockServerRemote) PutAgain

func (b *BlockServerRemote) PutAgain(ctx context.Context, tlfID tlf.ID, id kbfsblock.ID,
	bContext kbfsblock.Context, buf []byte, serverHalf kbfscrypto.BlockCryptKeyServerHalf) (err error)

PutAgain implements the BlockServer interface for BlockServerRemote

func (*BlockServerRemote) RefreshAuthToken

func (b *BlockServerRemote) RefreshAuthToken(ctx context.Context)

RefreshAuthToken implements the AuthTokenRefreshHandler interface.

func (*BlockServerRemote) RemoteAddress

func (b *BlockServerRemote) RemoteAddress() string

RemoteAddress returns the remote bserver this client is talking to

func (*BlockServerRemote) RemoveBlockReferences

func (b *BlockServerRemote) RemoveBlockReferences(ctx context.Context,
	tlfID tlf.ID, contexts kbfsblock.ContextMap) (liveCounts map[kbfsblock.ID]int, err error)

RemoveBlockReferences implements the BlockServer interface for BlockServerRemote

func (*BlockServerRemote) Shutdown

func (b *BlockServerRemote) Shutdown(ctx context.Context)

Shutdown implements the BlockServer interface for BlockServerRemote.

type BlockSplitter

type BlockSplitter interface {
	// CopyUntilSplit copies data into the block until we reach the
	// point where we should split, but only if writing to the end of
	// the last block.  If this is writing into the middle of a file,
	// just copy everything that will fit into the block, and assume
	// that block boundaries will be fixed later. Return how much was
	// copied.
	CopyUntilSplit(
		block *FileBlock, lastBlock bool, data []byte, off int64) int64

	// CheckSplit, given a block, figures out whether it ends at the
	// right place.  If so, return 0.  If not, return either the
	// offset in the block where it should be split, or -1 if more
	// bytes from the next block should be appended.
	CheckSplit(block *FileBlock) int64

	// MaxPtrsPerBlock describes the number of indirect pointers we
	// can fit into one indirect block.
	MaxPtrsPerBlock() int

	// ShouldEmbedBlockChanges decides whether we should keep the
	// block changes embedded in the MD or not.
	ShouldEmbedBlockChanges(bc *BlockChanges) bool
}

BlockSplitter decides when a file or directory block needs to be split

type BlockSplitterSimple

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

BlockSplitterSimple implements the BlockSplitter interface by using a simple max-size algorithm to determine when to split blocks.

func NewBlockSplitterSimple

func NewBlockSplitterSimple(desiredBlockSize int64,
	blockChangeEmbedMaxSize uint64, codec kbfscodec.Codec) (
	*BlockSplitterSimple, error)

NewBlockSplitterSimple creates a new BlockSplittleSimple and adjusts the max size to try to match the desired size for file blocks, given the overhead of encoding a file block and the round-up padding we do.

func (*BlockSplitterSimple) CheckSplit

func (b *BlockSplitterSimple) CheckSplit(block *FileBlock) int64

CheckSplit implements the BlockSplitter interface for BlockSplitterSimple.

func (*BlockSplitterSimple) CopyUntilSplit

func (b *BlockSplitterSimple) CopyUntilSplit(
	block *FileBlock, lastBlock bool, data []byte, off int64) int64

CopyUntilSplit implements the BlockSplitter interface for BlockSplitterSimple.

func (*BlockSplitterSimple) MaxPtrsPerBlock

func (b *BlockSplitterSimple) MaxPtrsPerBlock() int

MaxPtrsPerBlock implements the BlockSplitter interface for BlockSplitterSimple.

func (*BlockSplitterSimple) ShouldEmbedBlockChanges

func (b *BlockSplitterSimple) ShouldEmbedBlockChanges(
	bc *BlockChanges) bool

ShouldEmbedBlockChanges implements the BlockSplitter interface for BlockSplitterSimple.

type BranchName

type BranchName string

BranchName is the name given to a KBFS branch, for a particular top-level folder. Currently, the notion of a "branch" is client-side only, and can be used to specify which root to use for a top-level folder. (For example, viewing a historical archive could use a different branch name.)

const (
	// MasterBranch represents the mainline branch for a top-level
	// folder.  Set to the empty string so that the default will be
	// the master branch.
	MasterBranch BranchName = ""
)

type CRAbandonStagedBranchError

type CRAbandonStagedBranchError struct {
	Err error
	Bid kbfsmd.BranchID
}

CRAbandonStagedBranchError indicates that conflict resolution had to abandon a staged branch due to an unresolvable error.

func (CRAbandonStagedBranchError) Error

func (e CRAbandonStagedBranchError) Error() string

type CRWrapError

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

CRWrapError wraps an error that happens during conflict resolution.

func (CRWrapError) Error

func (e CRWrapError) Error() string

Error implements the error interface for CRWrapError.

type Clock

type Clock interface {
	// Now returns the current time.
	Now() time.Time
}

Clock is an interface for getting the current time

type CoalescingContext

type CoalescingContext struct {
	context.Context
	// contains filtered or unexported fields
}

CoalescingContext allows many contexts to be treated as one. It waits on all its contexts' Context.Done() channels, and when all of them have returned, this CoalescingContext is canceled. At any point, a context can be added to the list, and will subsequently also be part of the wait condition. TODO: add timeout channel in case there is a goroutine leak.

func NewCoalescingContext

func NewCoalescingContext(parent context.Context) (*CoalescingContext, context.CancelFunc)

NewCoalescingContext creates a new CoalescingContext. The context _must_ be canceled to avoid a goroutine leak.

func (*CoalescingContext) AddContext

func (ctx *CoalescingContext) AddContext(other context.Context) error

AddContext adds a context to the set of contexts that we're waiting on.

func (*CoalescingContext) Deadline

func (ctx *CoalescingContext) Deadline() (time.Time, bool)

Deadline overrides the default parent's Deadline().

func (*CoalescingContext) Done

func (ctx *CoalescingContext) Done() <-chan struct{}

Done returns a channel that is closed when the CoalescingContext is canceled.

func (*CoalescingContext) Err

func (ctx *CoalescingContext) Err() error

Err returns context.Canceled if the CoalescingContext has been canceled, and nil otherwise.

type CommonBlock

type CommonBlock struct {
	// IsInd indicates where this block is so big it requires indirect pointers
	IsInd bool `codec:"s"`

	codec.UnknownFieldSetHandler
	// contains filtered or unexported fields
}

CommonBlock holds block data that is common for both subdirectories and files.

func (*CommonBlock) DataVersion

func (cb *CommonBlock) DataVersion() DataVer

DataVersion returns data version for this block.

func (*CommonBlock) DeepCopy

func (cb *CommonBlock) DeepCopy() CommonBlock

DeepCopy copies a CommonBlock without the lock.

func (*CommonBlock) GetEncodedSize

func (cb *CommonBlock) GetEncodedSize() uint32

GetEncodedSize implements the Block interface for CommonBlock

func (*CommonBlock) NewEmpty

func (cb *CommonBlock) NewEmpty() Block

NewEmpty implements the Block interface for CommonBlock.

func (*CommonBlock) Set

func (cb *CommonBlock) Set(other Block)

Set implements the Block interface for CommonBlock.

func (*CommonBlock) SetEncodedSize

func (cb *CommonBlock) SetEncodedSize(size uint32)

SetEncodedSize implements the Block interface for CommonBlock

func (*CommonBlock) ToCommonBlock

func (cb *CommonBlock) ToCommonBlock() *CommonBlock

ToCommonBlock implements the Block interface for CommonBlock.

type Config

type Config interface {
	Tracer
	KBFSOps() KBFSOps
	SetKBFSOps(KBFSOps)
	KBPKI() KBPKI
	SetKBPKI(KBPKI)
	KeyManager() KeyManager
	SetKeyManager(KeyManager)
	Reporter() Reporter
	SetReporter(Reporter)
	MDCache() MDCache
	SetMDCache(MDCache)
	KeyCache() KeyCache
	SetKeyBundleCache(kbfsmd.KeyBundleCache)
	KeyBundleCache() kbfsmd.KeyBundleCache
	SetKeyCache(KeyCache)
	SetBlockCache(BlockCache)
	DirtyBlockCache() DirtyBlockCache
	SetDirtyBlockCache(DirtyBlockCache)
	SetCrypto(Crypto)
	SetCodec(kbfscodec.Codec)
	MDOps() MDOps
	SetMDOps(MDOps)
	KeyOps() KeyOps
	SetKeyOps(KeyOps)
	BlockOps() BlockOps
	SetBlockOps(BlockOps)
	MDServer() MDServer
	SetMDServer(MDServer)
	SetBlockServer(BlockServer)
	KeyServer() KeyServer
	SetKeyServer(KeyServer)
	KeybaseService() KeybaseService
	SetKeybaseService(KeybaseService)
	BlockSplitter() BlockSplitter
	SetBlockSplitter(BlockSplitter)
	Notifier() Notifier
	SetNotifier(Notifier)
	SetClock(Clock)
	ConflictRenamer() ConflictRenamer
	SetConflictRenamer(ConflictRenamer)
	MetadataVersion() kbfsmd.MetadataVer
	SetMetadataVersion(kbfsmd.MetadataVer)
	DefaultBlockType() keybase1.BlockType
	SetDefaultBlockType(blockType keybase1.BlockType)
	RekeyQueue() RekeyQueue
	SetRekeyQueue(RekeyQueue)
	// ReqsBufSize indicates the number of read or write operations
	// that can be buffered per folder
	ReqsBufSize() int
	// MaxNameBytes indicates the maximum supported size of a
	// directory entry name in bytes.
	MaxNameBytes() uint32
	// MaxDirBytes indicates the maximum supported plaintext size of a
	// directory in bytes.
	MaxDirBytes() uint64
	// DoBackgroundFlushes says whether we should periodically try to
	// flush dirty files, even without a sync from the user.  Should
	// be true except for during some testing.
	DoBackgroundFlushes() bool
	SetDoBackgroundFlushes(bool)
	// RekeyWithPromptWaitTime indicates how long to wait, after
	// setting the rekey bit, before prompting for a paper key.
	RekeyWithPromptWaitTime() time.Duration
	SetRekeyWithPromptWaitTime(time.Duration)
	// PrefetchStatus returns the prefetch status of a block.
	PrefetchStatus(context.Context, tlf.ID, BlockPointer) PrefetchStatus

	// GracePeriod specifies a grace period for which a delayed cancellation
	// waits before actual cancels the context. This is useful for giving
	// critical portion of a slow remote operation some extra time to finish as
	// an effort to avoid conflicting. Example include an O_EXCL Create call
	// interrupted by ALRM signal actually makes it to the server, while
	// application assumes not since EINTR is returned. A delayed cancellation
	// allows us to distinguish between successful cancel (where remote operation
	// didn't make to server) or failed cancel (where remote operation made to
	// the server). However, the optimal value of this depends on the network
	// conditions. A long grace period for really good network condition would
	// just unnecessarily slow down Ctrl-C.
	//
	// TODO: make this adaptive and self-change over time based on network
	// conditions.
	DelayedCancellationGracePeriod() time.Duration
	SetDelayedCancellationGracePeriod(time.Duration)
	// QuotaReclamationPeriod indicates how often should each TLF
	// should check for quota to reclaim.  If the Duration.Seconds()
	// == 0, quota reclamation should not run automatically.
	QuotaReclamationPeriod() time.Duration
	// QuotaReclamationMinUnrefAge indicates the minimum time a block
	// must have been unreferenced before it can be reclaimed.
	QuotaReclamationMinUnrefAge() time.Duration
	// QuotaReclamationMinHeadAge indicates the minimum age of the
	// most recently merged MD update before we can run reclamation,
	// to avoid conflicting with a currently active writer.
	QuotaReclamationMinHeadAge() time.Duration

	// ResetCaches clears and re-initializes all data and key caches.
	ResetCaches()

	// StorageRoot returns the path to the storage root for this config.
	StorageRoot() string

	// MetricsRegistry may be nil, which should be interpreted as
	// not using metrics at all. (i.e., as if UseNilMetrics were
	// set). This differs from how go-metrics treats nil Registry
	// objects, which is to use the default registry.
	MetricsRegistry() metrics.Registry
	SetMetricsRegistry(metrics.Registry)

	// SetTraceOptions set the options for tracing (via x/net/trace).
	SetTraceOptions(enabled bool)

	// TLFValidDuration is the time TLFs are valid before identification needs to be redone.
	TLFValidDuration() time.Duration
	// SetTLFValidDuration sets TLFValidDuration.
	SetTLFValidDuration(time.Duration)

	// BGFlushDirOpBatchSize returns the directory op batch size for
	// background flushes.
	BGFlushDirOpBatchSize() int
	// SetBGFlushDirOpBatchSize sets the directory op batch size for
	// background flushes.
	SetBGFlushDirOpBatchSize(s int)

	// BGFlushPeriod returns how long to wait for a batch to fill up
	// before syncing a set of changes to the servers.
	BGFlushPeriod() time.Duration
	// SetBGFlushPeriod sets how long to wait for a batch to fill up
	// before syncing a set of changes to the servers.
	SetBGFlushPeriod(p time.Duration)

	// Shutdown is called to free config resources.
	Shutdown(context.Context) error
	// CheckStateOnShutdown tells the caller whether or not it is safe
	// to check the state of the system on shutdown.
	CheckStateOnShutdown() bool

	// GetRekeyFSMLimiter returns the global rekey FSM limiter.
	GetRekeyFSMLimiter() *OngoingWorkLimiter

	// RootNodeWrappers returns the set of root node wrapper functions
	// that will be applied to each newly-created root node.
	RootNodeWrappers() []func(Node) Node
	// AddRootNodeWrapper adds a new wrapper function that will be
	// applied whenever a root Node is created.  This will only apply
	// to TLFs that are first accessed after `AddRootNodeWrapper` is
	// called.
	AddRootNodeWrapper(func(Node) Node)
	// contains filtered or unexported methods
}

Config collects all the singleton instance instantiations needed to run KBFS in one place. The methods below are self-explanatory and do not require comments.

func Init

func Init(
	ctx context.Context, kbCtx Context, params InitParams,
	keybaseServiceCn KeybaseServiceCn, onInterruptFn func(),
	log logger.Logger) (cfg Config, err error)

Init initializes a config and returns it.

onInterruptFn is called whenever an interrupt signal is received (e.g., if the user hits Ctrl-C).

Init should be called at the beginning of main. Shutdown (see below) should then be called at the end of main (usually via defer).

The keybaseServiceCn argument is to specify a custom service and crypto (for non-RPC environments) like mobile. If this is nil, we'll use the default RPC implementation.

func InitWithLogPrefix

func InitWithLogPrefix(
	ctx context.Context, kbCtx Context, params InitParams,
	keybaseServiceCn KeybaseServiceCn, onInterruptFn func(),
	log logger.Logger, logPrefix string) (cfg Config, err error)

InitWithLogPrefix initializes a config and returns it, given a prefix.

onInterruptFn is called whenever an interrupt signal is received (e.g., if the user hits Ctrl-C).

Init should be called at the beginning of main. Shutdown (see below) should then be called at the end of main (usually via defer).

The keybaseServiceCn argument is to specify a custom service and crypto (for non-RPC environments) like mobile. If this is nil, we'll use the default RPC implementation.

type ConfigLocal

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

ConfigLocal implements the Config interface using purely local server objects (no KBFS operations used RPCs).

func ConfigAsUser

func ConfigAsUser(config *ConfigLocal,
	loggedInUser libkb.NormalizedUsername) *ConfigLocal

ConfigAsUser clones a test configuration in default init mode, setting another user as the logged in user. Journaling will not be enabled in the returned Config, regardless of the journal status in `config`.

func ConfigAsUserWithMode

func ConfigAsUserWithMode(config *ConfigLocal,
	loggedInUser libkb.NormalizedUsername, mode InitModeType) *ConfigLocal

ConfigAsUserWithMode clones a test configuration in the given mode, setting another user as the logged in user. Journaling will not be enabled in the returned Config, regardless of the journal status in `config`.

func MakeTestConfigOrBust

func MakeTestConfigOrBust(t logger.TestLogBackend,
	users ...libkb.NormalizedUsername) *ConfigLocal

MakeTestConfigOrBust creates and returns a config suitable for unit-testing with the given list of users.

func MakeTestConfigOrBustLoggedIn

func MakeTestConfigOrBustLoggedIn(t logger.TestLogBackend, loggedInIndex int,
	users ...libkb.NormalizedUsername) *ConfigLocal

MakeTestConfigOrBustLoggedIn creates and returns a config suitable for unit-testing with the given list of users. loggedInIndex specifies the index (in the list) of the user being logged in.

func MakeTestConfigOrBustLoggedInWithMode

func MakeTestConfigOrBustLoggedInWithMode(
	t logger.TestLogBackend, loggedInIndex int,
	mode InitModeType, users ...libkb.NormalizedUsername) *ConfigLocal

MakeTestConfigOrBustLoggedInWithMode creates and returns a config suitable for unit-testing with the given mode and list of users. loggedInIndex specifies the index (in the list) of the user being logged in.

func NewConfigLocal

func NewConfigLocal(mode InitMode,
	loggerFn func(module string) logger.Logger,
	storageRoot string, diskCacheMode DiskCacheMode,
	kbCtx Context) *ConfigLocal

NewConfigLocal constructs a new ConfigLocal with some default components that don't depend on a logger. The caller will have to fill in the rest.

TODO: Now that NewConfigLocal takes loggerFn, add more default components.

func (*ConfigLocal) AddRootNodeWrapper

func (c *ConfigLocal) AddRootNodeWrapper(f func(Node) Node)

AddRootNodeWrapper implements the Config interface for ConfigLocal.

func (*ConfigLocal) BGFlushDirOpBatchSize

func (c *ConfigLocal) BGFlushDirOpBatchSize() int

BGFlushDirOpBatchSize implements the Config interface for ConfigLocal.

func (*ConfigLocal) BGFlushPeriod

func (c *ConfigLocal) BGFlushPeriod() time.Duration

BGFlushPeriod implements the Config interface for ConfigLocal.

func (*ConfigLocal) BlockCache

func (c *ConfigLocal) BlockCache() BlockCache

BlockCache implements the Config interface for ConfigLocal.

func (*ConfigLocal) BlockOps

func (c *ConfigLocal) BlockOps() BlockOps

BlockOps implements the Config interface for ConfigLocal.

func (*ConfigLocal) BlockServer

func (c *ConfigLocal) BlockServer() BlockServer

BlockServer implements the Config interface for ConfigLocal.

func (*ConfigLocal) BlockSplitter

func (c *ConfigLocal) BlockSplitter() BlockSplitter

BlockSplitter implements the Config interface for ConfigLocal.

func (*ConfigLocal) CheckStateOnShutdown

func (c *ConfigLocal) CheckStateOnShutdown() bool

CheckStateOnShutdown implements the Config interface for ConfigLocal.

func (*ConfigLocal) Clock

func (c *ConfigLocal) Clock() Clock

Clock implements the Config interface for ConfigLocal.

func (*ConfigLocal) Codec

func (c *ConfigLocal) Codec() kbfscodec.Codec

Codec implements the Config interface for ConfigLocal.

func (*ConfigLocal) ConflictRenamer

func (c *ConfigLocal) ConflictRenamer() ConflictRenamer

ConflictRenamer implements the Config interface for ConfigLocal.

func (*ConfigLocal) Crypto

func (c *ConfigLocal) Crypto() Crypto

Crypto implements the Config interface for ConfigLocal.

func (*ConfigLocal) CurrentSessionGetter

func (c *ConfigLocal) CurrentSessionGetter() CurrentSessionGetter

CurrentSessionGetter implements the Config interface for ConfigLocal.

func (*ConfigLocal) DataVersion

func (c *ConfigLocal) DataVersion() DataVer

DataVersion implements the Config interface for ConfigLocal.

func (*ConfigLocal) DefaultBlockType

func (c *ConfigLocal) DefaultBlockType() keybase1.BlockType

DefaultBlockType implements the Config interface for ConfigLocal.

func (*ConfigLocal) DelayedCancellationGracePeriod

func (c *ConfigLocal) DelayedCancellationGracePeriod() time.Duration

DelayedCancellationGracePeriod implements the Config interface for ConfigLocal.

func (*ConfigLocal) DirtyBlockCache

func (c *ConfigLocal) DirtyBlockCache() DirtyBlockCache

DirtyBlockCache implements the Config interface for ConfigLocal.

func (*ConfigLocal) DiskBlockCache

func (c *ConfigLocal) DiskBlockCache() DiskBlockCache

DiskBlockCache implements the Config interface for ConfigLocal.

func (*ConfigLocal) DiskLimiter

func (c *ConfigLocal) DiskLimiter() DiskLimiter

DiskLimiter implements the Config interface for ConfigLocal.

func (*ConfigLocal) DoBackgroundFlushes

func (c *ConfigLocal) DoBackgroundFlushes() bool

DoBackgroundFlushes implements the Config interface for ConfigLocal.

func (*ConfigLocal) EnableDiskLimiter

func (c *ConfigLocal) EnableDiskLimiter(configRoot string) error

EnableDiskLimiter fills in c.ciskLimiter for use in journaling and disk caching. It returns the EventuallyConsistentQuotaUsage object used by the disk limiter.

func (*ConfigLocal) EnableJournaling

func (c *ConfigLocal) EnableJournaling(
	ctx context.Context, journalRoot string,
	bws TLFJournalBackgroundWorkStatus) error

EnableJournaling creates a JournalServer and attaches it to this config. journalRoot must be non-empty. Errors returned are non-fatal.

func (*ConfigLocal) GetRekeyFSMLimiter

func (c *ConfigLocal) GetRekeyFSMLimiter() *OngoingWorkLimiter

GetRekeyFSMLimiter implements the Config interface for ConfigLocal.

func (*ConfigLocal) IsSyncedTlf

func (c *ConfigLocal) IsSyncedTlf(tlfID tlf.ID) bool

IsSyncedTlf implements the isSyncedTlfGetter interface for ConfigLocal.

func (*ConfigLocal) IsTestMode

func (c *ConfigLocal) IsTestMode() bool

IsTestMode implements the Config interface for ConfigLocal.

func (*ConfigLocal) KBFSOps

func (c *ConfigLocal) KBFSOps() KBFSOps

KBFSOps implements the Config interface for ConfigLocal.

func (*ConfigLocal) KBPKI

func (c *ConfigLocal) KBPKI() KBPKI

KBPKI implements the Config interface for ConfigLocal.

func (*ConfigLocal) KeyBundleCache

func (c *ConfigLocal) KeyBundleCache() kbfsmd.KeyBundleCache

KeyBundleCache implements the Config interface for ConfigLocal.

func (*ConfigLocal) KeyCache

func (c *ConfigLocal) KeyCache() KeyCache

KeyCache implements the Config interface for ConfigLocal.

func (*ConfigLocal) KeyManager

func (c *ConfigLocal) KeyManager() KeyManager

KeyManager implements the Config interface for ConfigLocal.

func (*ConfigLocal) KeyOps

func (c *ConfigLocal) KeyOps() KeyOps

KeyOps implements the Config interface for ConfigLocal.

func (*ConfigLocal) KeyServer

func (c *ConfigLocal) KeyServer() KeyServer

KeyServer implements the Config interface for ConfigLocal.

func (*ConfigLocal) KeybaseService

func (c *ConfigLocal) KeybaseService() KeybaseService

KeybaseService implements the Config interface for ConfigLocal.

func (*ConfigLocal) MDCache

func (c *ConfigLocal) MDCache() MDCache

MDCache implements the Config interface for ConfigLocal.

func (*ConfigLocal) MDOps

func (c *ConfigLocal) MDOps() MDOps

MDOps implements the Config interface for ConfigLocal.

func (*ConfigLocal) MDServer

func (c *ConfigLocal) MDServer() MDServer

MDServer implements the Config interface for ConfigLocal.

func (*ConfigLocal) MakeDiskBlockCacheIfNotExists

func (c *ConfigLocal) MakeDiskBlockCacheIfNotExists() error

MakeDiskBlockCacheIfNotExists implements the Config interface for ConfigLocal.

func (*ConfigLocal) MakeLogger

func (c *ConfigLocal) MakeLogger(module string) logger.Logger

MakeLogger implements the Config interface for ConfigLocal.

func (*ConfigLocal) MaxDirBytes

func (c *ConfigLocal) MaxDirBytes() uint64

MaxDirBytes implements the Config interface for ConfigLocal.

func (*ConfigLocal) MaxNameBytes

func (c *ConfigLocal) MaxNameBytes() uint32

MaxNameBytes implements the Config interface for ConfigLocal.

func (*ConfigLocal) MaybeFinishTrace

func (c *ConfigLocal) MaybeFinishTrace(ctx context.Context, err error)

MaybeFinishTrace implements the Config interface for ConfigLocal.

func (*ConfigLocal) MaybeStartTrace

func (c *ConfigLocal) MaybeStartTrace(
	ctx context.Context, family, title string) context.Context

MaybeStartTrace implements the Config interface for ConfigLocal.

func (*ConfigLocal) MetadataVersion

func (c *ConfigLocal) MetadataVersion() kbfsmd.MetadataVer

MetadataVersion implements the Config interface for ConfigLocal.

func (*ConfigLocal) MetricsRegistry

func (c *ConfigLocal) MetricsRegistry() metrics.Registry

MetricsRegistry implements the Config interface for ConfigLocal.

func (*ConfigLocal) Mode

func (c *ConfigLocal) Mode() InitMode

Mode implements the Config interface for ConfigLocal.

func (*ConfigLocal) Notifier

func (c *ConfigLocal) Notifier() Notifier

Notifier implements the Config interface for ConfigLocal.

func (*ConfigLocal) PrefetchStatus

func (c *ConfigLocal) PrefetchStatus(ctx context.Context, tlfID tlf.ID,
	ptr BlockPointer) PrefetchStatus

PrefetchStatus implements the Config interface for ConfigLocal.

func (*ConfigLocal) QuotaReclamationMinHeadAge

func (c *ConfigLocal) QuotaReclamationMinHeadAge() time.Duration

QuotaReclamationMinHeadAge implements the Config interface for ConfigLocal.

func (*ConfigLocal) QuotaReclamationMinUnrefAge

func (c *ConfigLocal) QuotaReclamationMinUnrefAge() time.Duration

QuotaReclamationMinUnrefAge implements the Config interface for ConfigLocal.

func (*ConfigLocal) QuotaReclamationPeriod

func (c *ConfigLocal) QuotaReclamationPeriod() time.Duration

QuotaReclamationPeriod implements the Config interface for ConfigLocal.

func (*ConfigLocal) RekeyQueue

func (c *ConfigLocal) RekeyQueue() RekeyQueue

RekeyQueue implements the Config interface for ConfigLocal.

func (*ConfigLocal) RekeyWithPromptWaitTime

func (c *ConfigLocal) RekeyWithPromptWaitTime() time.Duration

RekeyWithPromptWaitTime implements the Config interface for ConfigLocal.

func (*ConfigLocal) Reporter

func (c *ConfigLocal) Reporter() Reporter

Reporter implements the Config interface for ConfigLocal.

func (*ConfigLocal) ReqsBufSize

func (c *ConfigLocal) ReqsBufSize() int

ReqsBufSize implements the Config interface for ConfigLocal.

func (*ConfigLocal) ResetCaches

func (c *ConfigLocal) ResetCaches()

ResetCaches implements the Config interface for ConfigLocal.

func (*ConfigLocal) RootNodeWrappers

func (c *ConfigLocal) RootNodeWrappers() []func(Node) Node

RootNodeWrappers implements the Config interface for ConfigLocal.

func (*ConfigLocal) SetBGFlushDirOpBatchSize

func (c *ConfigLocal) SetBGFlushDirOpBatchSize(s int)

SetBGFlushDirOpBatchSize implements the Config interface for ConfigLocal.

func (*ConfigLocal) SetBGFlushPeriod

func (c *ConfigLocal) SetBGFlushPeriod(p time.Duration)

SetBGFlushPeriod implements the Config interface for ConfigLocal.

func (*ConfigLocal) SetBlockCache

func (c *ConfigLocal) SetBlockCache(b BlockCache)

SetBlockCache implements the Config interface for ConfigLocal.

func (*ConfigLocal) SetBlockOps

func (c *ConfigLocal) SetBlockOps(b BlockOps)

SetBlockOps implements the Config interface for ConfigLocal.

func (*ConfigLocal) SetBlockServer

func (c *ConfigLocal) SetBlockServer(b BlockServer)

SetBlockServer implements the Config interface for ConfigLocal.

func (*ConfigLocal) SetBlockSplitter

func (c *ConfigLocal) SetBlockSplitter(b BlockSplitter)

SetBlockSplitter implements the Config interface for ConfigLocal.

func (*ConfigLocal) SetClock

func (c *ConfigLocal) SetClock(cl Clock)

SetClock implements the Config interface for ConfigLocal.

func (*ConfigLocal) SetCodec

func (c *ConfigLocal) SetCodec(co kbfscodec.Codec)

SetCodec implements the Config interface for ConfigLocal.

func (*ConfigLocal) SetConflictRenamer

func (c *ConfigLocal) SetConflictRenamer(cr ConflictRenamer)

SetConflictRenamer implements the Config interface for ConfigLocal.

func (*ConfigLocal) SetCrypto

func (c *ConfigLocal) SetCrypto(cr Crypto)

SetCrypto implements the Config interface for ConfigLocal.

func (*ConfigLocal) SetDefaultBlockType

func (c *ConfigLocal) SetDefaultBlockType(blockType keybase1.BlockType)

SetDefaultBlockType implements the Config interface for ConfigLocal.

func (*ConfigLocal) SetDelayedCancellationGracePeriod

func (c *ConfigLocal) SetDelayedCancellationGracePeriod(d time.Duration)

SetDelayedCancellationGracePeriod implements the Config interface for ConfigLocal.

func (*ConfigLocal) SetDirtyBlockCache

func (c *ConfigLocal) SetDirtyBlockCache(d DirtyBlockCache)

SetDirtyBlockCache implements the Config interface for ConfigLocal.

func (*ConfigLocal) SetDoBackgroundFlushes

func (c *ConfigLocal) SetDoBackgroundFlushes(doBGFlush bool)

SetDoBackgroundFlushes implements the Config interface for ConfigLocal.

func (*ConfigLocal) SetKBFSOps

func (c *ConfigLocal) SetKBFSOps(k KBFSOps)

SetKBFSOps implements the Config interface for ConfigLocal.

func (*ConfigLocal) SetKBFSService

func (c *ConfigLocal) SetKBFSService(k *KBFSService)

SetKBFSService sets the KBFSService for this ConfigLocal.

func (*ConfigLocal) SetKBPKI

func (c *ConfigLocal) SetKBPKI(k KBPKI)

SetKBPKI implements the Config interface for ConfigLocal.

func (*ConfigLocal) SetKeyBundleCache

func (c *ConfigLocal) SetKeyBundleCache(k kbfsmd.KeyBundleCache)

SetKeyBundleCache implements the Config interface for ConfigLocal.

func (*ConfigLocal) SetKeyCache

func (c *ConfigLocal) SetKeyCache(k KeyCache)

SetKeyCache implements the Config interface for ConfigLocal.

func (*ConfigLocal) SetKeyManager

func (c *ConfigLocal) SetKeyManager(k KeyManager)

SetKeyManager implements the Config interface for ConfigLocal.

func (*ConfigLocal) SetKeyOps

func (c *ConfigLocal) SetKeyOps(k KeyOps)

SetKeyOps implements the Config interface for ConfigLocal.

func (*ConfigLocal) SetKeyServer

func (c *ConfigLocal) SetKeyServer(k KeyServer)

SetKeyServer implements the Config interface for ConfigLocal.

func (*ConfigLocal) SetKeybaseService

func (c *ConfigLocal) SetKeybaseService(k KeybaseService)

SetKeybaseService implements the Config interface for ConfigLocal.

func (*ConfigLocal) SetMDCache

func (c *ConfigLocal) SetMDCache(m MDCache)

SetMDCache implements the Config interface for ConfigLocal.

func (*ConfigLocal) SetMDOps

func (c *ConfigLocal) SetMDOps(m MDOps)

SetMDOps implements the Config interface for ConfigLocal.

func (*ConfigLocal) SetMDServer

func (c *ConfigLocal) SetMDServer(m MDServer)

SetMDServer implements the Config interface for ConfigLocal.

func (*ConfigLocal) SetMetadataVersion

func (c *ConfigLocal) SetMetadataVersion(mdVer kbfsmd.MetadataVer)

SetMetadataVersion implements the Config interface for ConfigLocal.

func (*ConfigLocal) SetMetricsRegistry

func (c *ConfigLocal) SetMetricsRegistry(r metrics.Registry)

SetMetricsRegistry implements the Config interface for ConfigLocal.

func (*ConfigLocal) SetNotifier

func (c *ConfigLocal) SetNotifier(n Notifier)

SetNotifier implements the Config interface for ConfigLocal.

func (*ConfigLocal) SetRekeyQueue

func (c *ConfigLocal) SetRekeyQueue(r RekeyQueue)

SetRekeyQueue implements the Config interface for ConfigLocal.

func (*ConfigLocal) SetRekeyWithPromptWaitTime

func (c *ConfigLocal) SetRekeyWithPromptWaitTime(d time.Duration)

SetRekeyWithPromptWaitTime implements the Config interface for ConfigLocal.

func (*ConfigLocal) SetReporter

func (c *ConfigLocal) SetReporter(r Reporter)

SetReporter implements the Config interface for ConfigLocal.

func (*ConfigLocal) SetTLFValidDuration

func (c *ConfigLocal) SetTLFValidDuration(r time.Duration)

SetTLFValidDuration implements the Config interface for ConfigLocal.

func (*ConfigLocal) SetTlfSyncState

func (c *ConfigLocal) SetTlfSyncState(tlfID tlf.ID, isSynced bool) error

SetTlfSyncState implements the Config interface for ConfigLocal.

func (*ConfigLocal) SetTraceOptions

func (c *ConfigLocal) SetTraceOptions(enabled bool)

SetTraceOptions implements the Config interface for ConfigLocal.

func (*ConfigLocal) Shutdown

func (c *ConfigLocal) Shutdown(ctx context.Context) error

Shutdown implements the Config interface for ConfigLocal.

func (*ConfigLocal) Signer

func (c *ConfigLocal) Signer() kbfscrypto.Signer

Signer implements the Config interface for ConfigLocal.

func (*ConfigLocal) StorageRoot

func (c *ConfigLocal) StorageRoot() string

StorageRoot implements the Config interface for ConfigLocal.

func (*ConfigLocal) TLFValidDuration

func (c *ConfigLocal) TLFValidDuration() time.Duration

TLFValidDuration implements the Config interface for ConfigLocal.

type ConflictRenamer

type ConflictRenamer interface {
	// ConflictRename returns the appropriately modified filename.
	ConflictRename(ctx context.Context, op op, original string) (
		string, error)
}

ConflictRenamer deals with names for conflicting directory entries.

type ConflictResolver

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

ConflictResolver is responsible for resolving conflicts in the background.

func NewConflictResolver

func NewConflictResolver(
	config Config, fbo *folderBranchOps) *ConflictResolver

NewConflictResolver constructs a new ConflictResolver (and launches any necessary background goroutines).

func (*ConflictResolver) BeginNewBranch

func (cr *ConflictResolver) BeginNewBranch()

BeginNewBranch resets any internal state to be ready to accept resolutions from a new branch.

func (*ConflictResolver) ForceCancel

func (cr *ConflictResolver) ForceCancel()

ForceCancel cancels any currently-running CR, regardless of what its inputs were.

func (*ConflictResolver) Pause

func (cr *ConflictResolver) Pause()

Pause cancels any ongoing resolutions and prevents any new ones from starting.

func (*ConflictResolver) Resolve

func (cr *ConflictResolver) Resolve(ctx context.Context,
	unmerged kbfsmd.Revision, merged kbfsmd.Revision)

Resolve takes the latest known unmerged and merged revision numbers, and kicks off the resolution process.

func (*ConflictResolver) Restart

func (cr *ConflictResolver) Restart(baseCtx context.Context)

Restart re-enables conflict resolution, with a base context for CR operations. baseCtx must have a cancellation delayer.

func (*ConflictResolver) Shutdown

func (cr *ConflictResolver) Shutdown()

Shutdown cancels any ongoing resolutions and stops any background goroutines.

func (*ConflictResolver) Wait

func (cr *ConflictResolver) Wait(ctx context.Context) error

Wait blocks until the current set of submitted resolutions are complete (though not necessarily successful), or until the given context is canceled.

type Context

type Context env.Context

Context defines the environment for this package

type ContextAlreadyHasCancellationDelayerError

type ContextAlreadyHasCancellationDelayerError struct{}

ContextAlreadyHasCancellationDelayerError is returned when NewContextWithCancellationDelayer is called for the second time on the same ctx, which is not supported yet.

func (ContextAlreadyHasCancellationDelayerError) Error

func (e ContextAlreadyHasCancellationDelayerError) Error() string

type CountMeter

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

CountMeter counts ticks with a sliding window into the past.

func NewCountMeter

func NewCountMeter() *CountMeter

NewCountMeter returns a new CountMeter.

func (*CountMeter) Count

func (m *CountMeter) Count() int64

Count returns the overall count.

func (*CountMeter) Mark

func (m *CountMeter) Mark(i int64)

Mark ticks the counters.

func (*CountMeter) Rate1

func (m *CountMeter) Rate1() float64

Rate1 returns the number of ticks in the last 1 minute.

func (*CountMeter) Rate15

func (m *CountMeter) Rate15() float64

Rate15 returns the number of ticks in the last 15 minutes.

func (*CountMeter) Rate5

func (m *CountMeter) Rate5() float64

Rate5 returns the number of ticks in the last 5 minutes.

func (*CountMeter) RateMean

func (m *CountMeter) RateMean() float64

RateMean returns the overall count of ticks.

func (*CountMeter) Shutdown

func (m *CountMeter) Shutdown() <-chan struct{}

Shutdown shuts down this CountMeter.

func (*CountMeter) Snapshot

func (m *CountMeter) Snapshot() metrics.Meter

Snapshot returns the snapshot in time of this CountMeter.

type Crypto

type Crypto interface {

	// Duplicate kbfscrypto.Signer here to work around gomock's
	// limitations.
	Sign(context.Context, []byte) (kbfscrypto.SignatureInfo, error)
	SignForKBFS(context.Context, []byte) (kbfscrypto.SignatureInfo, error)
	SignToString(context.Context, []byte) (string, error)

	// DecryptTLFCryptKeyClientHalf decrypts a
	// kbfscrypto.TLFCryptKeyClientHalf using the current device's
	// private key and the TLF's ephemeral public key.
	DecryptTLFCryptKeyClientHalf(ctx context.Context,
		publicKey kbfscrypto.TLFEphemeralPublicKey,
		encryptedClientHalf kbfscrypto.EncryptedTLFCryptKeyClientHalf) (
		kbfscrypto.TLFCryptKeyClientHalf, error)

	// DecryptTLFCryptKeyClientHalfAny decrypts one of the
	// kbfscrypto.TLFCryptKeyClientHalf using the available
	// private keys and the ephemeral public key.  If promptPaper
	// is true, the service will prompt the user for any unlocked
	// paper keys.
	DecryptTLFCryptKeyClientHalfAny(ctx context.Context,
		keys []EncryptedTLFCryptKeyClientAndEphemeral,
		promptPaper bool) (
		kbfscrypto.TLFCryptKeyClientHalf, int, error)

	// Shutdown frees any resources associated with this instance.
	Shutdown()
	// contains filtered or unexported methods
}

Crypto signs, verifies, encrypts, and decrypts stuff.

type CryptoClient

type CryptoClient struct {
	CryptoCommon
	// contains filtered or unexported fields
}

CryptoClient is a keybase1.CryptoInterface based implementation for Crypto.

func NewCryptoClient

func NewCryptoClient(codec kbfscodec.Codec, client keybase1.CryptoInterface, log logger.Logger) *CryptoClient

NewCryptoClient constructs a crypto client for a keybase1.CryptoInterface.

func (*CryptoClient) DecryptTLFCryptKeyClientHalf

func (c *CryptoClient) DecryptTLFCryptKeyClientHalf(ctx context.Context,
	publicKey kbfscrypto.TLFEphemeralPublicKey,
	encryptedClientHalf kbfscrypto.EncryptedTLFCryptKeyClientHalf) (
	clientHalf kbfscrypto.TLFCryptKeyClientHalf, err error)

DecryptTLFCryptKeyClientHalf implements the Crypto interface for CryptoClient.

func (*CryptoClient) DecryptTLFCryptKeyClientHalfAny

func (c *CryptoClient) DecryptTLFCryptKeyClientHalfAny(ctx context.Context,
	keys []EncryptedTLFCryptKeyClientAndEphemeral, promptPaper bool) (
	clientHalf kbfscrypto.TLFCryptKeyClientHalf, index int, err error)

DecryptTLFCryptKeyClientHalfAny implements the Crypto interface for CryptoClient.

func (*CryptoClient) Shutdown

func (c *CryptoClient) Shutdown()

Shutdown implements the Crypto interface for CryptoClient.

func (*CryptoClient) Sign

func (c *CryptoClient) Sign(ctx context.Context, msg []byte) (
	sigInfo kbfscrypto.SignatureInfo, err error)

Sign implements the Crypto interface for CryptoClient.

func (*CryptoClient) SignForKBFS

func (c *CryptoClient) SignForKBFS(ctx context.Context, msg []byte) (
	sigInfo kbfscrypto.SignatureInfo, err error)

SignForKBFS implements the Crypto interface for CryptoClient.

func (*CryptoClient) SignToString

func (c *CryptoClient) SignToString(ctx context.Context, msg []byte) (
	signature string, err error)

SignToString implements the Crypto interface for CryptoClient.

type CryptoClientRPC

type CryptoClientRPC struct {
	CryptoClient
	// contains filtered or unexported fields
}

CryptoClientRPC is an RPC based implementation for Crypto.

func NewCryptoClientRPC

func NewCryptoClientRPC(config Config, kbCtx Context) *CryptoClientRPC

NewCryptoClientRPC constructs a new RPC based Crypto implementation.

func (CryptoClientRPC) HandlerName

func (CryptoClientRPC) HandlerName() string

HandlerName implements the ConnectionHandler interface.

func (*CryptoClientRPC) OnConnect

func (c *CryptoClientRPC) OnConnect(ctx context.Context, conn *rpc.Connection,
	_ rpc.GenericClient, server *rpc.Server) error

OnConnect implements the ConnectionHandler interface.

func (*CryptoClientRPC) OnConnectError

func (c *CryptoClientRPC) OnConnectError(err error, wait time.Duration)

OnConnectError implements the ConnectionHandler interface.

func (*CryptoClientRPC) OnDisconnected

func (c *CryptoClientRPC) OnDisconnected(_ context.Context,
	status rpc.DisconnectStatus)

OnDisconnected implements the ConnectionHandler interface.

func (*CryptoClientRPC) OnDoCommandError

func (c *CryptoClientRPC) OnDoCommandError(err error, wait time.Duration)

OnDoCommandError implements the ConnectionHandler interface.

func (*CryptoClientRPC) ShouldRetry

func (c *CryptoClientRPC) ShouldRetry(rpcName string, err error) bool

ShouldRetry implements the ConnectionHandler interface.

func (*CryptoClientRPC) ShouldRetryOnConnect

func (c *CryptoClientRPC) ShouldRetryOnConnect(err error) bool

ShouldRetryOnConnect implements the ConnectionHandler interface.

type CryptoCommon

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

CryptoCommon contains many of the function implementations need for the Crypto interface, which can be reused by other implementations.

func MakeCryptoCommon

func MakeCryptoCommon(codec kbfscodec.Codec) CryptoCommon

MakeCryptoCommon returns a default CryptoCommon object.

func (CryptoCommon) DecryptBlock

func (c CryptoCommon) DecryptBlock(
	encryptedBlock kbfscrypto.EncryptedBlock, key kbfscrypto.BlockCryptKey,
	block Block) error

DecryptBlock implements the Crypto interface for CryptoCommon.

func (CryptoCommon) DecryptPrivateMetadata

func (c CryptoCommon) DecryptPrivateMetadata(
	encryptedPmd kbfscrypto.EncryptedPrivateMetadata, key kbfscrypto.TLFCryptKey) (
	PrivateMetadata, error)

DecryptPrivateMetadata implements the Crypto interface for CryptoCommon.

func (CryptoCommon) EncryptBlock

func (c CryptoCommon) EncryptBlock(block Block, key kbfscrypto.BlockCryptKey) (
	plainSize int, encryptedBlock kbfscrypto.EncryptedBlock, err error)

EncryptBlock implements the Crypto interface for CryptoCommon.

func (CryptoCommon) EncryptPrivateMetadata

func (c CryptoCommon) EncryptPrivateMetadata(
	pmd PrivateMetadata, key kbfscrypto.TLFCryptKey) (
	encryptedPmd kbfscrypto.EncryptedPrivateMetadata, err error)

EncryptPrivateMetadata implements the Crypto interface for CryptoCommon.

func (CryptoCommon) MakeBlockRefNonce

func (c CryptoCommon) MakeBlockRefNonce() (nonce kbfsblock.RefNonce, err error)

MakeBlockRefNonce implements the Crypto interface for CryptoCommon.

func (CryptoCommon) MakeRandomBlockCryptKeyServerHalf

func (c CryptoCommon) MakeRandomBlockCryptKeyServerHalf() (
	kbfscrypto.BlockCryptKeyServerHalf, error)

MakeRandomBlockCryptKeyServerHalf implements the Crypto interface for CryptoCommon.

func (CryptoCommon) MakeRandomBranchID

func (c CryptoCommon) MakeRandomBranchID() (kbfsmd.BranchID, error)

MakeRandomBranchID implements the Crypto interface for CryptoCommon.

func (CryptoCommon) MakeRandomTLFEphemeralKeys

func (c CryptoCommon) MakeRandomTLFEphemeralKeys() (
	kbfscrypto.TLFEphemeralPublicKey, kbfscrypto.TLFEphemeralPrivateKey,
	error)

MakeRandomTLFEphemeralKeys implements the Crypto interface for CryptoCommon.

func (CryptoCommon) MakeRandomTLFKeys

func (c CryptoCommon) MakeRandomTLFKeys() (kbfscrypto.TLFPublicKey,
	kbfscrypto.TLFPrivateKey, kbfscrypto.TLFCryptKey, error)

MakeRandomTLFKeys implements the Crypto interface for CryptoCommon.

func (CryptoCommon) MakeRandomTlfID

func (c CryptoCommon) MakeRandomTlfID(t tlf.Type) (tlf.ID, error)

MakeRandomTlfID implements the Crypto interface for CryptoCommon.

func (CryptoCommon) MakeTemporaryBlockID

func (c CryptoCommon) MakeTemporaryBlockID() (kbfsblock.ID, error)

MakeTemporaryBlockID implements the Crypto interface for CryptoCommon.

type CryptoLocal

type CryptoLocal struct {
	CryptoCommon
	kbfscrypto.SigningKeySigner
	// contains filtered or unexported fields
}

CryptoLocal implements the Crypto interface by using a local signing key and a local crypt private key.

func NewCryptoLocal

func NewCryptoLocal(codec kbfscodec.Codec,
	signingKey kbfscrypto.SigningKey,
	cryptPrivateKey kbfscrypto.CryptPrivateKey) CryptoLocal

NewCryptoLocal constructs a new CryptoLocal instance with the given signing key.

func (CryptoLocal) DecryptTLFCryptKeyClientHalf

func (c CryptoLocal) DecryptTLFCryptKeyClientHalf(ctx context.Context,
	publicKey kbfscrypto.TLFEphemeralPublicKey,
	encryptedClientHalf kbfscrypto.EncryptedTLFCryptKeyClientHalf) (
	kbfscrypto.TLFCryptKeyClientHalf, error)

DecryptTLFCryptKeyClientHalf implements the Crypto interface for CryptoLocal.

func (CryptoLocal) DecryptTLFCryptKeyClientHalfAny

func (c CryptoLocal) DecryptTLFCryptKeyClientHalfAny(ctx context.Context,
	keys []EncryptedTLFCryptKeyClientAndEphemeral, _ bool) (
	clientHalf kbfscrypto.TLFCryptKeyClientHalf, index int, err error)

DecryptTLFCryptKeyClientHalfAny implements the Crypto interface for CryptoLocal.

func (CryptoLocal) Shutdown

func (c CryptoLocal) Shutdown()

Shutdown implements the Crypto interface for CryptoLocal.

type CtxAllowNameKeyType

type CtxAllowNameKeyType int

CtxAllowNameKeyType is the type for a context allowable name override key.

const (
	// CtxAllowNameKey can be used to set a value in a context, and
	// that value will be treated as an allowable directory entry
	// name, even if it also matches a disallowed prefix.  The value
	// must be of type `string`, or it will panic.
	CtxAllowNameKey CtxAllowNameKeyType = iota
)

type CtxBackgroundSyncKeyType

type CtxBackgroundSyncKeyType int

CtxBackgroundSyncKeyType is the type for a context background sync key.

const (
	// CtxBackgroundSyncKey is set in the context for any change
	// notifications that are triggered from a background sync.
	// Observers can ignore these if they want, since they will have
	// already gotten the relevant notifications via LocalChanges.
	CtxBackgroundSyncKey CtxBackgroundSyncKeyType = iota
)

type CtxCRTagKey

type CtxCRTagKey int

CtxCRTagKey is the type used for unique context tags related to conflict resolution

const (
	// CtxCRIDKey is the type of the tag for unique operation IDs
	// related to conflict resolution
	CtxCRIDKey CtxCRTagKey = iota
)

type CtxCancellationDelayerKeyType

type CtxCancellationDelayerKeyType int

CtxCancellationDelayerKeyType is a type for the context key for using cancellationDelayer

const (
	// CtxCancellationDelayerKey is a context key for using cancellationDelayer
	CtxCancellationDelayerKey CtxCancellationDelayerKeyType = iota
)

type CtxFBMTagKey

type CtxFBMTagKey int

CtxFBMTagKey is the type used for unique context tags within folderBlockManager

const (
	// CtxFBMIDKey is the type of the tag for unique operation IDs
	// within folderBlockManager.
	CtxFBMIDKey CtxFBMTagKey = iota
)

type CtxFBOTagKey

type CtxFBOTagKey int

CtxFBOTagKey is the type used for unique context tags within folderBranchOps

const (
	// CtxFBOIDKey is the type of the tag for unique operation IDs
	// within folderBranchOps.
	CtxFBOIDKey CtxFBOTagKey = iota
)

type CtxJournalTagKey

type CtxJournalTagKey int

CtxJournalTagKey is the type used for unique context tags within background journal work.

const (
	// CtxJournalIDKey is the type of the tag for unique operation IDs
	// within background journal work.
	CtxJournalIDKey CtxJournalTagKey = iota
)

type CtxKeybaseServiceTagKey

type CtxKeybaseServiceTagKey int

CtxKeybaseServiceTagKey is the type used for unique context tags used while servicing incoming keybase requests.

const (
	// CtxKeybaseServiceIDKey is the type of the tag for unique
	// operation IDs used while servicing incoming keybase requests.
	CtxKeybaseServiceIDKey CtxKeybaseServiceTagKey = iota
)

type CtxMDSRTagKey

type CtxMDSRTagKey int

CtxMDSRTagKey is the type used for unique context tags within MDServerRemote

const (
	// CtxMDSRIDKey is the type of the tag for unique operation IDs
	// within MDServerRemote.
	CtxMDSRIDKey CtxMDSRTagKey = iota
)

type CtxNotReplayableError

type CtxNotReplayableError struct{}

CtxNotReplayableError is returned when NewContextWithReplayFrom is called on a ctx with no replay func.

func (CtxNotReplayableError) Error

func (e CtxNotReplayableError) Error() string

type CtxRekeyTagKey

type CtxRekeyTagKey int

CtxRekeyTagKey is the type used for unique context tags within an enqueued Rekey.

const (
	// CtxRekeyIDKey is the type of the tag for unique operation IDs
	// within an enqueued Rekey.
	CtxRekeyIDKey CtxRekeyTagKey = iota
)

type CtxReplayFunc

type CtxReplayFunc func(ctx context.Context) context.Context

CtxReplayFunc is a function for replaying a series of changes done on a context.

type CtxReplayKeyType

type CtxReplayKeyType int

CtxReplayKeyType is a type for the context key for CtxReplayFunc

const (
	// CtxReplayKey is a context key for CtxReplayFunc
	CtxReplayKey CtxReplayKeyType = iota
)

type CurrentSessionGetter

type CurrentSessionGetter interface {
	// GetCurrentSession gets the current session info.
	GetCurrentSession(ctx context.Context) (SessionInfo, error)
}

CurrentSessionGetter is an interface for objects that can return session info.

type DataVer

type DataVer int

DataVer is the type of a version for marshalled KBFS data structures.

1) DataVer is a per-block attribute, not per-file. This means that, in theory, an indirect block with DataVer n may point to blocks with DataVers less than, equal to, or greater than n. However, for now, it's guaranteed that an indirect block will never point to blocks with greater versions than itself. (See #3 for details.)

2) DataVer is an external attribute of a block, meaning that it's not stored as part of the block, but computed by the creator (or anyone with the latest kbfs client), and stored only in pointers to the block.

2.5) A file (or, in the future a dir) can in theory have any arbitrary tree structure of blocks. However, we only write files such that all paths to leaves have the same depth.

Currently, in addition to 2.5, we have the following constraints on block tree structures: a) Direct blocks are always v1. b) Indirect blocks of depth 2 (meaning one indirect block pointing to all direct blocks) can be v1 (if it has no holes) or v2 (if it has holes). However, all its indirect pointers will have DataVer 1, by a). c) Indirect blocks of depth 3 must be v3 and must have at least one indirect pointer with an indirect DirectType [although if it holds for one, it should hold for all], although its indirect pointers may have any combination of DataVer 1 or 2, by b). d) Indirect blocks of dept k > 3 must be v3 and must have at least one indirect pointer with an indirect DirectType [although if it holds for one, it should hold for all], and all of its indirect pointers must have DataVer 3, by c).

const (
	// FirstValidDataVer is the first value that is considered a
	// valid data version. Note that the nil value is not
	// considered valid.
	FirstValidDataVer DataVer = 1
	// ChildHolesDataVer is the data version for any indirect block
	// containing a set of pointers with holes.
	ChildHolesDataVer DataVer = 2
	// AtLeastTwoLevelsOfChildrenDataVer is the data version for
	// blocks that have multiple levels of indirection below them
	// (i.e., indirect blocks that point to other indirect blocks).
	AtLeastTwoLevelsOfChildrenDataVer DataVer = 3
)

func DefaultNewBlockDataVersion

func DefaultNewBlockDataVersion(holes bool) DataVer

DefaultNewBlockDataVersion returns the default data version for new blocks.

type DirBlock

type DirBlock struct {
	CommonBlock
	// if not indirect, a map of path name to directory entry
	Children map[string]DirEntry `codec:"c,omitempty"`
	// if indirect, contains the indirect pointers to the next level of blocks
	IPtrs []IndirectDirPtr `codec:"i,omitempty"`
}

DirBlock is the contents of a directory

func (*DirBlock) DeepCopy

func (db *DirBlock) DeepCopy() *DirBlock

DeepCopy makes a complete copy of a DirBlock

func (*DirBlock) NewEmpty

func (db *DirBlock) NewEmpty() Block

NewEmpty implements the Block interface for DirBlock

func (*DirBlock) Set

func (db *DirBlock) Set(other Block)

Set implements the Block interface for DirBlock

func (*DirBlock) ToCommonBlock

func (db *DirBlock) ToCommonBlock() *CommonBlock

ToCommonBlock implements the Block interface for DirBlock.

type DirEntry

type DirEntry struct {
	BlockInfo
	EntryInfo

	codec.UnknownFieldSetHandler
}

DirEntry is all the data info a directory know about its child.

func (*DirEntry) IsInitialized

func (de *DirEntry) IsInitialized() bool

IsInitialized returns true if this DirEntry has been initialized.

type DirNotEmptyError

type DirNotEmptyError struct {
	Name string
}

DirNotEmptyError indicates that the user tried to unlink a subdirectory that was not empty.

func (DirNotEmptyError) Error

func (e DirNotEmptyError) Error() string

Error implements the error interface for DirNotEmptyError

type DirTooBigError

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

DirTooBigError indicates that the user tried to write a directory that would be bigger than KBFS's supported size.

func (DirTooBigError) Error

func (e DirTooBigError) Error() string

Error implements the error interface for DirTooBigError.

type DirtyBlockCache

type DirtyBlockCache interface {
	// Get gets the block associated with the given block ID.  Returns
	// the dirty block for the given ID, if one exists.
	Get(tlfID tlf.ID, ptr BlockPointer, branch BranchName) (Block, error)
	// Put stores a dirty block currently identified by the
	// given block pointer and branch name.
	Put(tlfID tlf.ID, ptr BlockPointer, branch BranchName, block Block) error
	// Delete removes the dirty block associated with the given block
	// pointer and branch from the cache.  No error is returned if no
	// block exists for the given ID.
	Delete(tlfID tlf.ID, ptr BlockPointer, branch BranchName) error
	// IsDirty states whether or not the block associated with the
	// given block pointer and branch name is dirty in this cache.
	IsDirty(tlfID tlf.ID, ptr BlockPointer, branch BranchName) bool
	// IsAnyDirty returns whether there are any dirty blocks in the
	// cache. tlfID may be ignored.
	IsAnyDirty(tlfID tlf.ID) bool
	// RequestPermissionToDirty is called whenever a user wants to
	// write data to a file.  The caller provides an estimated number
	// of bytes that will become dirty -- this is difficult to know
	// exactly without pre-fetching all the blocks involved, but in
	// practice we can just use the number of bytes sent in via the
	// Write. It returns a channel that blocks until the cache is
	// ready to receive more dirty data, at which point the channel is
	// closed.  The user must call
	// `UpdateUnsyncedBytes(-estimatedDirtyBytes)` once it has
	// completed its write and called `UpdateUnsyncedBytes` for all
	// the exact dirty block sizes.
	RequestPermissionToDirty(ctx context.Context, tlfID tlf.ID,
		estimatedDirtyBytes int64) (DirtyPermChan, error)
	// UpdateUnsyncedBytes is called by a user, who has already been
	// granted permission to write, with the delta in block sizes that
	// were dirtied as part of the write.  So for example, if a
	// newly-dirtied block of 20 bytes was extended by 5 bytes, they
	// should send 25.  If on the next write (before any syncs), bytes
	// 10-15 of that same block were overwritten, they should send 0
	// over the channel because there were no new bytes.  If an
	// already-dirtied block is truncated, or if previously requested
	// bytes have now been updated more accurately in previous
	// requests, newUnsyncedBytes may be negative.  wasSyncing should
	// be true if `BlockSyncStarted` has already been called for this
	// block.
	UpdateUnsyncedBytes(tlfID tlf.ID, newUnsyncedBytes int64, wasSyncing bool)
	// UpdateSyncingBytes is called when a particular block has
	// started syncing, or with a negative number when a block is no
	// longer syncing due to an error (and BlockSyncFinished will
	// never be called).
	UpdateSyncingBytes(tlfID tlf.ID, size int64)
	// BlockSyncFinished is called when a particular block has
	// finished syncing, though the overall sync might not yet be
	// complete.  This lets the cache know it might be able to grant
	// more permission to writers.
	BlockSyncFinished(tlfID tlf.ID, size int64)
	// SyncFinished is called when a complete sync has completed and
	// its dirty blocks have been removed from the cache.  This lets
	// the cache know it might be able to grant more permission to
	// writers.
	SyncFinished(tlfID tlf.ID, size int64)
	// ShouldForceSync returns true if the sync buffer is full enough
	// to force all callers to sync their data immediately.
	ShouldForceSync(tlfID tlf.ID) bool

	// Shutdown frees any resources associated with this instance.  It
	// returns an error if there are any unsynced blocks.
	Shutdown() error
}

DirtyBlockCache gets and puts plaintext dir blocks and file blocks into a cache, which have been modified by the application and not yet committed on the KBFS servers. They are identified by a (potentially random) ID that may not have any relationship with their context, along with a Branch in case the same TLF is being modified via multiple branches. Dirty blocks are never evicted, they must be deleted explicitly.

type DirtyBlockCacheStandard

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

DirtyBlockCacheStandard implements the DirtyBlockCache interface by storing blocks in an in-memory cache. Dirty blocks are identified by their block ID, branch name, and reference nonce, since the same block may be forked and modified on different branches and under different references simultaneously.

DirtyBlockCacheStandard controls how fast uses can write into KBFS, and does so with a TCP-like slow-start algorithm that adjusts itself according to how fast bytes are synced to the server. Conceptually, there are two buffers:

syncBuf: The bytes that are currently syncing, or have finished
syncing, back to the servers.  Each TLF has only one sync at a
time, but multiple TLFs may be syncing at the same time.  We also
track how many bytes within this buffer have finished syncing.

waitBuf: The bytes that have not yet begun syncing to the
servers.  Again, this can be for multiple TLFs, and from multiple
files within a TLF.  In the TCP analogy, think of this as the
congestion window (cwnd).

The goal is to make sure that syncBuf can always be transmitted to the server within the file system operation timeout forced on us by the layer that interacts with the file system (19 seconds on OS X and Windows, defaults to 30 seconds for other layers if not already set). In fact, ideally the data would be transmitted in HALF of the file system operation timeout, in case a user Sync operation gets blocked behind a background Sync operation when there is significant data in waitBuf. At the same time, we want it to be as big as possible, because we get the best performance when writing lots of blocks in parallel to the servers. So, we want an algorithm that allows waitBuf to grow, without causing the next sync (or write, or setattr, etc) operation to timeout. For the purposes of this discussion, let's assume there is only one active TLF at a time.

We allow the user to set a min, start, and max size for waitBuf. Whenever a sync starts, bytes are transferred from waitBuf into syncBuf and a timer is started. When a sync completes successfully, the number of bytes synced is added to the allowed size of waitBuf (i.e., "additive increase" == exponential growth). However, if the number of sync'd bytes is smaller than the min waitBuf size, we don't do additive increase (because we haven't really tested the throughput of the server connection in that case).

If the sync takes more than 33% of half the overall operation timeout, the size of waitBuf is reduced by that same percentage (i.e., "multiplicative decrease"), and any outstanding bytes in the sync will not be used in the "additive increase" phase when the sync completes (they are considered "lost" in the TCP analogy, even though they should eventually succeed). The 33% limit was chosen mostly by trial and error, although if you assume that capacity(waitBuf) will double after each sync, then `2*len(syncBuf) == capacity(waitBuf)`, so at any given point there can be about 3*capacity(syncBuf) bytes buffered; so if syncBuf can't be sync'd in a third of the overall timeout, the next waitBuf should be reduced.

Finally, we need to make sure that the Write calls that are filling up waitBuf while a sync is happening don't timeout. But, we also need to fill waitBuf quickly, so that the next sync is ready to go as soon as the first one completes. Here we implement a compromise. Allow waitBuf to fill up instantly until it holds capacity(syncBuf) bytes. After that, allow it to fill up to 2*capacity(syncBuf), but artificially delay each write by adding backpressure, by some fraction of the system operation timeout that matches the fraction of the progress the buffer has made between capacity(syncBuf) and 2*capacity(syncBuf). As soon as the sync completes, any delayed write is unblocked and gets to start filling up the buffers again.

To avoid keeping the buffer capacity large when network conditions suddenly worsen (say after a laptop sleep when it comes back online on a new, worse network), the capacity is reset back to the minimum if resetBufferCapTime passes without any large syncs. TODO: in the future it might make sense to decrease the buffer capacity, rather than resetting it to the minimum?

func NewDirtyBlockCacheStandard

func NewDirtyBlockCacheStandard(clock Clock,
	log logger.Logger, minSyncBufCap int64,
	maxSyncBufCap int64, startSyncBufCap int64) *DirtyBlockCacheStandard

NewDirtyBlockCacheStandard constructs a new BlockCacheStandard instance. The min and max buffer capacities define the possible range of how many bytes we'll try to sync in any one sync, and the start size defines the initial buffer size.

func (*DirtyBlockCacheStandard) BlockSyncFinished

func (d *DirtyBlockCacheStandard) BlockSyncFinished(_ tlf.ID, size int64)

BlockSyncFinished implements the DirtyBlockCache interface for DirtyBlockCacheStandard.

func (*DirtyBlockCacheStandard) Delete

func (d *DirtyBlockCacheStandard) Delete(_ tlf.ID, ptr BlockPointer,
	branch BranchName) error

Delete implements the DirtyBlockCache interface for DirtyBlockCacheStandard.

func (*DirtyBlockCacheStandard) Get

func (d *DirtyBlockCacheStandard) Get(_ tlf.ID, ptr BlockPointer,
	branch BranchName) (Block, error)

Get implements the DirtyBlockCache interface for DirtyBlockCacheStandard.

func (*DirtyBlockCacheStandard) IsAnyDirty

func (d *DirtyBlockCacheStandard) IsAnyDirty(_ tlf.ID) bool

IsAnyDirty implements the DirtyBlockCache interface for DirtyBlockCacheStandard.

func (*DirtyBlockCacheStandard) IsDirty

func (d *DirtyBlockCacheStandard) IsDirty(_ tlf.ID, ptr BlockPointer,
	branch BranchName) (isDirty bool)

IsDirty implements the DirtyBlockCache interface for DirtyBlockCacheStandard.

func (*DirtyBlockCacheStandard) Put

func (d *DirtyBlockCacheStandard) Put(_ tlf.ID, ptr BlockPointer,
	branch BranchName, block Block) error

Put implements the DirtyBlockCache interface for DirtyBlockCacheStandard.

func (*DirtyBlockCacheStandard) RequestPermissionToDirty

func (d *DirtyBlockCacheStandard) RequestPermissionToDirty(
	ctx context.Context, _ tlf.ID, estimatedDirtyBytes int64) (
	DirtyPermChan, error)

RequestPermissionToDirty implements the DirtyBlockCache interface for DirtyBlockCacheStandard.

func (*DirtyBlockCacheStandard) ShouldForceSync

func (d *DirtyBlockCacheStandard) ShouldForceSync(_ tlf.ID) bool

ShouldForceSync implements the DirtyBlockCache interface for DirtyBlockCacheStandard.

func (*DirtyBlockCacheStandard) Shutdown

func (d *DirtyBlockCacheStandard) Shutdown() error

Shutdown implements the DirtyBlockCache interface for DirtyBlockCacheStandard.

func (*DirtyBlockCacheStandard) SyncFinished

func (d *DirtyBlockCacheStandard) SyncFinished(_ tlf.ID, size int64)

SyncFinished implements the DirtyBlockCache interface for DirtyBlockCacheStandard.

func (*DirtyBlockCacheStandard) UpdateSyncingBytes

func (d *DirtyBlockCacheStandard) UpdateSyncingBytes(_ tlf.ID, size int64)

UpdateSyncingBytes implements the DirtyBlockCache interface for DirtyBlockCacheStandard.

func (*DirtyBlockCacheStandard) UpdateUnsyncedBytes

func (d *DirtyBlockCacheStandard) UpdateUnsyncedBytes(_ tlf.ID,
	newUnsyncedBytes int64, wasSyncing bool)

UpdateUnsyncedBytes implements the DirtyBlockCache interface for DirtyBlockCacheStandard.

type DirtyPermChan

type DirtyPermChan <-chan struct{}

DirtyPermChan is a channel that gets closed when the holder has permission to write. We are forced to define it as a type due to a bug in mockgen that can't handle return values with a chan struct{}.

type DisallowedPrefixError

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

DisallowedPrefixError indicates that the user attempted to create an entry using a name with a disallowed prefix.

func (DisallowedPrefixError) Error

func (e DisallowedPrefixError) Error() string

Error implements the error interface for NoChainFoundError.

type DiskBlockCache

type DiskBlockCache interface {
	// Get gets a block from the disk cache.
	Get(ctx context.Context, tlfID tlf.ID, blockID kbfsblock.ID) (
		buf []byte, serverHalf kbfscrypto.BlockCryptKeyServerHalf,
		prefetchStatus PrefetchStatus, err error)
	// Put puts a block to the disk cache. Returns after it has updated the
	// metadata but before it has finished writing the block.
	Put(ctx context.Context, tlfID tlf.ID, blockID kbfsblock.ID, buf []byte,
		serverHalf kbfscrypto.BlockCryptKeyServerHalf) error
	// Delete deletes some blocks from the disk cache.
	Delete(ctx context.Context, blockIDs []kbfsblock.ID) (numRemoved int,
		sizeRemoved int64, err error)
	// UpdateMetadata updates metadata for a given block in the disk cache.
	UpdateMetadata(ctx context.Context, blockID kbfsblock.ID,
		prefetchStatus PrefetchStatus) error
	// Status returns the current status of the disk cache.
	Status(ctx context.Context) map[string]DiskBlockCacheStatus
	// Shutdown cleanly shuts down the disk block cache.
	Shutdown(ctx context.Context)
}

DiskBlockCache caches blocks to the disk.

type DiskBlockCacheError

type DiskBlockCacheError struct {
	Msg string
}

DiskBlockCacheError is a generic disk cache error.

func (DiskBlockCacheError) Error

func (e DiskBlockCacheError) Error() string

Error implements the Error interface for DiskBlockCacheError.

func (DiskBlockCacheError) ToStatus

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

ToStatus implements the ExportableError interface for DiskBlockCacheError.

type DiskBlockCacheLocal

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

DiskBlockCacheLocal is the standard implementation for DiskBlockCache.

func (*DiskBlockCacheLocal) Delete

func (cache *DiskBlockCacheLocal) Delete(ctx context.Context,
	blockIDs []kbfsblock.ID) (numRemoved int, sizeRemoved int64, err error)

Delete implements the DiskBlockCache interface for DiskBlockCacheStandard.

func (*DiskBlockCacheLocal) Get

func (cache *DiskBlockCacheLocal) Get(ctx context.Context, tlfID tlf.ID,
	blockID kbfsblock.ID) (buf []byte,
	serverHalf kbfscrypto.BlockCryptKeyServerHalf,
	prefetchStatus PrefetchStatus, err error)

Get implements the DiskBlockCache interface for DiskBlockCacheStandard.

func (*DiskBlockCacheLocal) GetMetadata

func (cache *DiskBlockCacheLocal) GetMetadata(ctx context.Context,
	blockID kbfsblock.ID) (DiskBlockCacheMetadata, error)

GetMetadata implements the DiskBlockCache interface for DiskBlockCacheStandard.

func (*DiskBlockCacheLocal) Put

func (cache *DiskBlockCacheLocal) Put(ctx context.Context, tlfID tlf.ID,
	blockID kbfsblock.ID, buf []byte,
	serverHalf kbfscrypto.BlockCryptKeyServerHalf) error

Put implements the DiskBlockCache interface for DiskBlockCacheStandard.

func (*DiskBlockCacheLocal) Shutdown

func (cache *DiskBlockCacheLocal) Shutdown(ctx context.Context)

Shutdown implements the DiskBlockCache interface for DiskBlockCacheStandard.

func (*DiskBlockCacheLocal) Status

func (cache *DiskBlockCacheLocal) Status(
	ctx context.Context) map[string]DiskBlockCacheStatus

Status implements the DiskBlockCache interface for DiskBlockCacheStandard.

func (*DiskBlockCacheLocal) UpdateMetadata

func (cache *DiskBlockCacheLocal) UpdateMetadata(ctx context.Context,
	blockID kbfsblock.ID, prefetchStatus PrefetchStatus) (err error)

UpdateMetadata implements the DiskBlockCache interface for DiskBlockCacheStandard.

func (*DiskBlockCacheLocal) WaitUntilStarted

func (cache *DiskBlockCacheLocal) WaitUntilStarted()

WaitUntilStarted waits until this cache has started.

type DiskBlockCacheMetadata

type DiskBlockCacheMetadata struct {
	// the TLF ID for the block
	TlfID tlf.ID
	// the last time the block was used
	LRUTime time.Time
	// the size of the block
	BlockSize uint32
	// whether the block has triggered prefetches
	// This used to be called "HasPrefetched" so to maintain compatibility with
	// existing disk caches, we have to name it that in the codec tag.
	TriggeredPrefetch bool `codec:"HasPrefetched"`
	// whether the block's triggered prefetches are complete
	FinishedPrefetch bool
}

DiskBlockCacheMetadata packages the metadata needed to make decisions on cache eviction.

type DiskBlockCacheRemote

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

DiskBlockCacheRemote implements a client to access a remote DiskBlockCacheService. It implements the DiskBlockCache interface.

func NewDiskBlockCacheRemote

func NewDiskBlockCacheRemote(kbCtx Context, config diskBlockCacheRemoteConfig) (
	*DiskBlockCacheRemote, error)

NewDiskBlockCacheRemote creates a new remote disk cache client.

func (*DiskBlockCacheRemote) Delete

func (dbcr *DiskBlockCacheRemote) Delete(ctx context.Context,
	blockIDs []kbfsblock.ID) (numRemoved int, sizeRemoved int64, err error)

Delete implements the DiskBlockCache interface for DiskBlockCacheRemote.

func (*DiskBlockCacheRemote) Get

func (dbcr *DiskBlockCacheRemote) Get(ctx context.Context, tlfID tlf.ID,
	blockID kbfsblock.ID) (buf []byte,
	serverHalf kbfscrypto.BlockCryptKeyServerHalf,
	prefetchStatus PrefetchStatus, err error)

Get implements the DiskBlockCache interface for DiskBlockCacheRemote.

func (*DiskBlockCacheRemote) Put

func (dbcr *DiskBlockCacheRemote) Put(ctx context.Context, tlfID tlf.ID,
	blockID kbfsblock.ID, buf []byte,
	serverHalf kbfscrypto.BlockCryptKeyServerHalf) (err error)

Put implements the DiskBlockCache interface for DiskBlockCacheRemote.

func (*DiskBlockCacheRemote) Shutdown

func (dbcr *DiskBlockCacheRemote) Shutdown(ctx context.Context)

Shutdown implements the DiskBlockCache interface for DiskBlockCacheRemote.

func (*DiskBlockCacheRemote) Status

func (dbcr *DiskBlockCacheRemote) Status(ctx context.Context) map[string]DiskBlockCacheStatus

Status implements the DiskBlockCache interface for DiskBlockCacheRemote.

func (*DiskBlockCacheRemote) UpdateMetadata

func (dbcr *DiskBlockCacheRemote) UpdateMetadata(ctx context.Context,
	blockID kbfsblock.ID, prefetchStatus PrefetchStatus) error

UpdateMetadata implements the DiskBlockCache interface for DiskBlockCacheRemote.

type DiskBlockCacheService

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

DiskBlockCacheService delegates requests for blocks to this KBFS instance's disk cache.

func NewDiskBlockCacheService

func NewDiskBlockCacheService(config diskBlockCacheServiceConfig) *DiskBlockCacheService

NewDiskBlockCacheService creates a new DiskBlockCacheService.

func (*DiskBlockCacheService) DeleteBlocks

func (cache *DiskBlockCacheService) DeleteBlocks(ctx context.Context,
	blockIDs [][]byte) (kbgitkbfs.DeleteBlocksRes, error)

DeleteBlocks implements the DiskBlockCacheInterface interface for DiskBlockCacheService.

func (*DiskBlockCacheService) GetBlock

func (cache *DiskBlockCacheService) GetBlock(ctx context.Context,
	arg kbgitkbfs.GetBlockArg) (kbgitkbfs.GetBlockRes, error)

GetBlock implements the DiskBlockCacheInterface interface for Dis