kbfsedits

package
v0.0.0-...-f10651d Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2024 License: BSD-3-Clause, BSD-3-Clause Imports: 16 Imported by: 3

Documentation

Index

Constants

View Source
const (
	// MaxClusters is the max number of TLF writer clusters to return
	// in a user history.
	MaxClusters = 10
)

Variables

This section is empty.

Functions

func Prepare

func Prepare(edits []NotificationMessage) (string, error)

Prepare converts the given slice of notifications into a string suitable for sending/storing them.

func PrepareSelfWrite

func PrepareSelfWrite(msg SelfWriteMessage) (string, error)

PrepareSelfWrite converts the given message into a string suitable for sending/storing it.

Types

type EntryType

type EntryType string

EntryType indicates the type of the file that was edited.

const (
	// EntryTypeFile is for files that have been edited.  Note that
	// covers both regular files and executables.
	EntryTypeFile EntryType = "file"
	// EntryTypeDir is for directories that have been edited.
	EntryTypeDir EntryType = "dir"
	// EntryTypeSym is for symlinks that have been edited.
	EntryTypeSym EntryType = "sym"
)

type ModifyRange

type ModifyRange struct {
	Offset uint64
	Length uint64
}

ModifyRange represents a file modification. Length is 0 for a truncate.

type NotificationMessage

type NotificationMessage struct {
	Version  NotificationVersion
	Filename string
	Type     NotificationOpType
	Time     time.Time // server-reported time
	FileType EntryType
	Revision kbfsmd.Revision
	Device   kbfscrypto.VerifyingKey
	UID      keybase1.UID
	FolderID tlf.ID
	Params   *NotificationParams `json:",omitempty"`
	// contains filtered or unexported fields
}

NotificationMessage is a summary of a single edit notification in KBFS. It is meant to be encoded and decoded with JSON.

type NotificationOpType

type NotificationOpType string

NotificationOpType indicates the type of the operation that caused the notification.

const (
	// NotificationCreate is the type of an edit notification
	// representing a new file or directory creation.
	NotificationCreate NotificationOpType = "create"
	// NotificationModify is the type of an edit notification
	// representing a file modification.
	NotificationModify NotificationOpType = "modify"
	// NotificationRename is the type of an edit notification
	// representing a file or directory getting renamed.
	NotificationRename NotificationOpType = "rename"
	// NotificationDelete is the type of an edit notification
	// representing a file or directory getting deleted.
	NotificationDelete NotificationOpType = "delete"
)

type NotificationParams

type NotificationParams struct {
	OldFilename string        `json:",omitempty"` // for renames
	Modifies    []ModifyRange `json:",omitempty"` // for modifies
}

NotificationParams is used for op-type-specific data.

type NotificationVersion

type NotificationVersion int

NotificationVersion is the numeric version of the edit notification data structure.

const (
	// NotificationV1 is unused, but represents the original,
	// MD-ops-based edit notification list.
	NotificationV1 NotificationVersion = 1
	// NotificationV2 is the first version that stores JSON-encoded
	// notifications in chat messages.
	NotificationV2 NotificationVersion = 2
)

type SelfWriteMessage

type SelfWriteMessage struct {
	Version    NotificationVersion
	Folder     keybase1.Folder
	ConvID     chat1.ConversationID
	ServerTime time.Time
}

SelfWriteMessage is written into a special, private channel when the user writes to some TLF.

func ReadSelfWrite

func ReadSelfWrite(msg string) (ret SelfWriteMessage, err error)

ReadSelfWrite converts the given message string into the SelfWriteMessage type, if possible.

type TlfHistory

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

TlfHistory maintains a history of the last N file edits from each writer in the TLF.

There will be two users of a TlfHistory instance:

  • One user (likely something outside of the kbfsedits package, e.g. libkbfs.folderBranchOps) will read notifications from the corresponding TLF and add them to this history. After adding a batch or several batches of messages, it should call `Recompute()`, and if some writers need more, earlier revisions, it should fetch more notifications for the indicated writer and repeat.

  • The other user (within the kbfsedits package) will collate the histories from multiple TlfHistory instances together using `getHistory()` from each one. It may also construct pretty versions of individual edit histories for a particular TLF.

func NewTlfHistory

func NewTlfHistory() *TlfHistory

NewTlfHistory constructs a new TlfHistory instance.

func (*TlfHistory) AddNotifications

func (th *TlfHistory) AddNotifications(
	writerName string, messages []string) (maxRev kbfsmd.Revision, err error)

AddNotifications takes in a set of messages in this TLF by `writer`, and adds them to the history. Once done adding messages, the caller should call `Recompute` to find out if more messages should be added for any particular writer. It returns the maximum known revision including an update from this writer.

func (*TlfHistory) AddUnflushedNotifications

func (th *TlfHistory) AddUnflushedNotifications(
	loggedInUser string, msgs []NotificationMessage)

AddUnflushedNotifications adds notifications to a special "unflushed" list that takes precedences over the regular notifications with revision numbers equal or greater to the minimum unflushed revision.

func (*TlfHistory) ClearAllUnflushed

func (th *TlfHistory) ClearAllUnflushed()

ClearAllUnflushed clears all unflushed notifications.

func (*TlfHistory) FlushRevision

func (th *TlfHistory) FlushRevision(rev kbfsmd.Revision)

FlushRevision clears all any unflushed notifications with a revision equal or less than `rev`.

func (*TlfHistory) Recompute

func (th *TlfHistory) Recompute(loggedInUser string) (
	writersWhoNeedMore map[string]bool)

Recompute processes (and caches) the history so that it reflects all recently-added notifications, and returns the names of writers which don't yet have the maximum number of edits in the history.

type UserHistory

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

UserHistory keeps a sorted list of the top known TLF edit histories, and can convert those histories into keybase1 protocol structs. TLF histories must be updated by an external caller whenever they change.

func NewUserHistory

func NewUserHistory(log logger.Logger, vlog *libkb.VDebugLog) *UserHistory

NewUserHistory constructs a UserHistory instance.

func (*UserHistory) Clear

func (uh *UserHistory) Clear()

Clear erases all saved histories; TLFs must be re-added.

func (*UserHistory) ClearTLF

func (uh *UserHistory) ClearTLF(tlfName tlf.CanonicalName, tlfType tlf.Type)

ClearTLF removes a TLF from this UserHistory.

func (*UserHistory) Get

func (uh *UserHistory) Get(loggedInUser string) (
	history []keybase1.FSFolderEditHistory)

Get returns the full edit history for the user, converted to keybase1 protocol structs.

func (*UserHistory) GetTlfHistory

func (uh *UserHistory) GetTlfHistory(
	tlfName tlf.CanonicalName, tlfType tlf.Type) (
	history keybase1.FSFolderEditHistory)

GetTlfHistory returns the edit history of a given TLF, converted to keybase1 protocol structs.

func (*UserHistory) UpdateHistory

func (uh *UserHistory) UpdateHistory(
	tlfName tlf.CanonicalName, tlfType tlf.Type, tlfHistory *TlfHistory,
	loggedInUser string)

UpdateHistory should be called whenever the edit history for a given TLF gets new information.

Jump to

Keyboard shortcuts

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