id int32 0 167k | repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens listlengths 21 1.41k | docstring stringlengths 6 2.61k | docstring_tokens listlengths 3 215 | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
160,100 | keybase/client | go/chat/utils/utils.go | GetDesktopNotificationSnippet | func GetDesktopNotificationSnippet(conv *chat1.ConversationLocal, currentUsername string,
fromMsg *chat1.MessageUnboxed) string {
if conv == nil {
return ""
}
var msg chat1.MessageUnboxed
if fromMsg != nil {
msg = *fromMsg
} else if conv.Info.SnippetMsg != nil {
msg = *conv.Info.SnippetMsg
} else {
return ""
}
if !msg.IsValid() {
return ""
}
mvalid := msg.Valid()
var snippet string
if !mvalid.IsEphemeral() {
switch msg.GetMessageType() {
case chat1.MessageType_REACTION:
reaction, err := GetReaction(msg)
if err != nil {
snippet = ""
} else {
var prefix string
if showSenderPrefix(mvalid, *conv) {
prefix = mvalid.SenderUsername + " "
}
snippet = emoji.Sprintf("%sreacted to your message with %v", prefix, reaction)
}
default:
snippet, _ = GetMsgSnippet(msg, *conv, currentUsername)
}
return snippet
}
// If the message is already exploded, nothing to see here.
if !msg.IsValidFull() {
return ""
}
switch msg.GetMessageType() {
case chat1.MessageType_TEXT, chat1.MessageType_ATTACHMENT:
return "💣 exploding message."
default:
return ""
}
} | go | func GetDesktopNotificationSnippet(conv *chat1.ConversationLocal, currentUsername string,
fromMsg *chat1.MessageUnboxed) string {
if conv == nil {
return ""
}
var msg chat1.MessageUnboxed
if fromMsg != nil {
msg = *fromMsg
} else if conv.Info.SnippetMsg != nil {
msg = *conv.Info.SnippetMsg
} else {
return ""
}
if !msg.IsValid() {
return ""
}
mvalid := msg.Valid()
var snippet string
if !mvalid.IsEphemeral() {
switch msg.GetMessageType() {
case chat1.MessageType_REACTION:
reaction, err := GetReaction(msg)
if err != nil {
snippet = ""
} else {
var prefix string
if showSenderPrefix(mvalid, *conv) {
prefix = mvalid.SenderUsername + " "
}
snippet = emoji.Sprintf("%sreacted to your message with %v", prefix, reaction)
}
default:
snippet, _ = GetMsgSnippet(msg, *conv, currentUsername)
}
return snippet
}
// If the message is already exploded, nothing to see here.
if !msg.IsValidFull() {
return ""
}
switch msg.GetMessageType() {
case chat1.MessageType_TEXT, chat1.MessageType_ATTACHMENT:
return "💣 exploding message."
default:
return ""
}
} | [
"func",
"GetDesktopNotificationSnippet",
"(",
"conv",
"*",
"chat1",
".",
"ConversationLocal",
",",
"currentUsername",
"string",
",",
"fromMsg",
"*",
"chat1",
".",
"MessageUnboxed",
")",
"string",
"{",
"if",
"conv",
"==",
"nil",
"{",
"return",
"\"",
"\"",
"\n",... | // We don't want to display the contents of an exploding message in notifications | [
"We",
"don",
"t",
"want",
"to",
"display",
"the",
"contents",
"of",
"an",
"exploding",
"message",
"in",
"notifications"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/chat/utils/utils.go#L967-L1014 |
160,101 | keybase/client | go/chat/utils/utils.go | AssetsForMessage | func AssetsForMessage(g *globals.Context, msgBody chat1.MessageBody) (assets []chat1.Asset) {
typ, err := msgBody.MessageType()
if err != nil {
// Log and drop the error for a malformed MessageBody.
g.Log.Warning("error getting assets for message: %s", err)
return assets
}
switch typ {
case chat1.MessageType_ATTACHMENT:
body := msgBody.Attachment()
if body.Object.Path != "" {
assets = append(assets, body.Object)
}
if body.Preview != nil {
assets = append(assets, *body.Preview)
}
assets = append(assets, body.Previews...)
case chat1.MessageType_ATTACHMENTUPLOADED:
body := msgBody.Attachmentuploaded()
if body.Object.Path != "" {
assets = append(assets, body.Object)
}
assets = append(assets, body.Previews...)
}
return assets
} | go | func AssetsForMessage(g *globals.Context, msgBody chat1.MessageBody) (assets []chat1.Asset) {
typ, err := msgBody.MessageType()
if err != nil {
// Log and drop the error for a malformed MessageBody.
g.Log.Warning("error getting assets for message: %s", err)
return assets
}
switch typ {
case chat1.MessageType_ATTACHMENT:
body := msgBody.Attachment()
if body.Object.Path != "" {
assets = append(assets, body.Object)
}
if body.Preview != nil {
assets = append(assets, *body.Preview)
}
assets = append(assets, body.Previews...)
case chat1.MessageType_ATTACHMENTUPLOADED:
body := msgBody.Attachmentuploaded()
if body.Object.Path != "" {
assets = append(assets, body.Object)
}
assets = append(assets, body.Previews...)
}
return assets
} | [
"func",
"AssetsForMessage",
"(",
"g",
"*",
"globals",
".",
"Context",
",",
"msgBody",
"chat1",
".",
"MessageBody",
")",
"(",
"assets",
"[",
"]",
"chat1",
".",
"Asset",
")",
"{",
"typ",
",",
"err",
":=",
"msgBody",
".",
"MessageType",
"(",
")",
"\n",
... | // AssetsForMessage gathers all assets on a message | [
"AssetsForMessage",
"gathers",
"all",
"assets",
"on",
"a",
"message"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/chat/utils/utils.go#L1768-L1793 |
160,102 | keybase/client | go/chat/utils/utils.go | GetQueryRe | func GetQueryRe(query string) (*regexp.Regexp, error) {
return regexp.Compile("(?i)" + regexp.QuoteMeta(query))
} | go | func GetQueryRe(query string) (*regexp.Regexp, error) {
return regexp.Compile("(?i)" + regexp.QuoteMeta(query))
} | [
"func",
"GetQueryRe",
"(",
"query",
"string",
")",
"(",
"*",
"regexp",
".",
"Regexp",
",",
"error",
")",
"{",
"return",
"regexp",
".",
"Compile",
"(",
"\"",
"\"",
"+",
"regexp",
".",
"QuoteMeta",
"(",
"query",
")",
")",
"\n",
"}"
] | // GetQueryRe returns a regex to match the query string on message text. This
// is used for result highlighting. | [
"GetQueryRe",
"returns",
"a",
"regex",
"to",
"match",
"the",
"query",
"string",
"on",
"message",
"text",
".",
"This",
"is",
"used",
"for",
"result",
"highlighting",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/chat/utils/utils.go#L1894-L1896 |
160,103 | keybase/client | go/kbfs/libfs/remote_status.go | Init | func (r *RemoteStatus) Init(ctx context.Context, log logger.Logger, config libkbfs.Config, rs RemoteStatusUpdater) {
r.failingServices = map[string]error{}
r.callbacks = rs
// A time in the far past that is not IsZero
r.failingSince.Add(time.Second)
go r.loop(ctx, log, config)
} | go | func (r *RemoteStatus) Init(ctx context.Context, log logger.Logger, config libkbfs.Config, rs RemoteStatusUpdater) {
r.failingServices = map[string]error{}
r.callbacks = rs
// A time in the far past that is not IsZero
r.failingSince.Add(time.Second)
go r.loop(ctx, log, config)
} | [
"func",
"(",
"r",
"*",
"RemoteStatus",
")",
"Init",
"(",
"ctx",
"context",
".",
"Context",
",",
"log",
"logger",
".",
"Logger",
",",
"config",
"libkbfs",
".",
"Config",
",",
"rs",
"RemoteStatusUpdater",
")",
"{",
"r",
".",
"failingServices",
"=",
"map",
... | // Init a RemoteStatus and register it with libkbfs. | [
"Init",
"a",
"RemoteStatus",
"and",
"register",
"it",
"with",
"libkbfs",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfs/remote_status.go#L48-L54 |
160,104 | keybase/client | go/kbfs/libfs/remote_status.go | ExtraFileName | func (r *RemoteStatus) ExtraFileName() string {
r.Lock()
defer r.Unlock()
if r.extraFileName == "" || time.Since(r.failingSince) < failureDisplayThreshold {
return ""
}
return r.extraFileName
} | go | func (r *RemoteStatus) ExtraFileName() string {
r.Lock()
defer r.Unlock()
if r.extraFileName == "" || time.Since(r.failingSince) < failureDisplayThreshold {
return ""
}
return r.extraFileName
} | [
"func",
"(",
"r",
"*",
"RemoteStatus",
")",
"ExtraFileName",
"(",
")",
"string",
"{",
"r",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"r",
".",
"extraFileName",
"==",
"\"",
"\"",
"||",
"time",
".",
"Since",
... | // ExtraFileName returns the extra file name or an empty string for none. | [
"ExtraFileName",
"returns",
"the",
"extra",
"file",
"name",
"or",
"an",
"empty",
"string",
"for",
"none",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfs/remote_status.go#L128-L137 |
160,105 | keybase/client | go/kbfs/libfs/remote_status.go | ExtraFileNameAndSize | func (r *RemoteStatus) ExtraFileNameAndSize() (string, int64) {
r.Lock()
defer r.Unlock()
if r.extraFileName == "" || time.Since(r.failingSince) < failureDisplayThreshold {
return "", 0
}
return r.extraFileName, int64(len(r.humanReadableBytesLocked()))
} | go | func (r *RemoteStatus) ExtraFileNameAndSize() (string, int64) {
r.Lock()
defer r.Unlock()
if r.extraFileName == "" || time.Since(r.failingSince) < failureDisplayThreshold {
return "", 0
}
return r.extraFileName, int64(len(r.humanReadableBytesLocked()))
} | [
"func",
"(",
"r",
"*",
"RemoteStatus",
")",
"ExtraFileNameAndSize",
"(",
")",
"(",
"string",
",",
"int64",
")",
"{",
"r",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"r",
".",
"extraFileName",
"==",
"\"",
"\"",... | // ExtraFileNameAndSize returns the extra file name or an empty string for none and the size of the extra file. | [
"ExtraFileNameAndSize",
"returns",
"the",
"extra",
"file",
"name",
"or",
"an",
"empty",
"string",
"for",
"none",
"and",
"the",
"size",
"of",
"the",
"extra",
"file",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfs/remote_status.go#L140-L149 |
160,106 | keybase/client | go/kbfs/libfs/remote_status.go | humanReadableBytesLocked | func (r *RemoteStatus) humanReadableBytesLocked() []byte {
if r.extraFileContents != nil {
return r.extraFileContents
}
var ss []string
needLogin := false
for service, err := range r.failingServices {
switch err.(type) {
case *libkb.LoginRequiredError:
needLogin = true
default:
ss = append(ss, service+": "+err.Error())
}
}
if len(ss) == 0 {
if needLogin {
ss = append(ss, "Not logged in")
} else {
ss = append(ss, "Everything appears ok")
}
}
ss = append(ss, "")
res := []byte(strings.Join(ss, newline))
r.extraFileContents = res
return res
} | go | func (r *RemoteStatus) humanReadableBytesLocked() []byte {
if r.extraFileContents != nil {
return r.extraFileContents
}
var ss []string
needLogin := false
for service, err := range r.failingServices {
switch err.(type) {
case *libkb.LoginRequiredError:
needLogin = true
default:
ss = append(ss, service+": "+err.Error())
}
}
if len(ss) == 0 {
if needLogin {
ss = append(ss, "Not logged in")
} else {
ss = append(ss, "Everything appears ok")
}
}
ss = append(ss, "")
res := []byte(strings.Join(ss, newline))
r.extraFileContents = res
return res
} | [
"func",
"(",
"r",
"*",
"RemoteStatus",
")",
"humanReadableBytesLocked",
"(",
")",
"[",
"]",
"byte",
"{",
"if",
"r",
".",
"extraFileContents",
"!=",
"nil",
"{",
"return",
"r",
".",
"extraFileContents",
"\n",
"}",
"\n\n",
"var",
"ss",
"[",
"]",
"string",
... | // humanReadableBytesNeedsLock should be called with lock already held. | [
"humanReadableBytesNeedsLock",
"should",
"be",
"called",
"with",
"lock",
"already",
"held",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfs/remote_status.go#L152-L180 |
160,107 | keybase/client | go/kbfs/libfs/remote_status.go | NewSpecialReadFunc | func (r *RemoteStatus) NewSpecialReadFunc(ctx context.Context) ([]byte, time.Time, error) {
r.Lock()
defer r.Unlock()
return r.humanReadableBytesLocked(), time.Time{}, nil
} | go | func (r *RemoteStatus) NewSpecialReadFunc(ctx context.Context) ([]byte, time.Time, error) {
r.Lock()
defer r.Unlock()
return r.humanReadableBytesLocked(), time.Time{}, nil
} | [
"func",
"(",
"r",
"*",
"RemoteStatus",
")",
"NewSpecialReadFunc",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"[",
"]",
"byte",
",",
"time",
".",
"Time",
",",
"error",
")",
"{",
"r",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"Unlock",
... | // NewSpecialReadFunc implements a special read file that contains human readable
// current status. | [
"NewSpecialReadFunc",
"implements",
"a",
"special",
"read",
"file",
"that",
"contains",
"human",
"readable",
"current",
"status",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfs/remote_status.go#L184-L189 |
160,108 | keybase/client | go/libkb/secwords.go | secWordListN | func secWordListN(n int) ([]string, error) {
var res []string
max := big.NewInt(int64(len(secwords)))
for i := 0; i < n; i++ {
x, err := rand.Int(rand.Reader, max)
if err != nil {
return []string{}, err
}
res = append(res, secwords[x.Int64()])
}
return res, nil
} | go | func secWordListN(n int) ([]string, error) {
var res []string
max := big.NewInt(int64(len(secwords)))
for i := 0; i < n; i++ {
x, err := rand.Int(rand.Reader, max)
if err != nil {
return []string{}, err
}
res = append(res, secwords[x.Int64()])
}
return res, nil
} | [
"func",
"secWordListN",
"(",
"n",
"int",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"var",
"res",
"[",
"]",
"string",
"\n",
"max",
":=",
"big",
".",
"NewInt",
"(",
"int64",
"(",
"len",
"(",
"secwords",
")",
")",
")",
"\n",
"for",
"i"... | // secWordListN returns n random words from secwords. | [
"secWordListN",
"returns",
"n",
"random",
"words",
"from",
"secwords",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/secwords.go#L25-L36 |
160,109 | keybase/client | go/kbfs/fsrpc/path.go | NewPath | func NewPath(pathStr string) (Path, error) {
components, err := split(pathStr)
if err != nil {
return Path{}, err
}
len := len(components)
if (len >= 1 && components[0] != topName) ||
(len >= 2 && components[1] != publicName && components[1] != privateName) {
return Path{}, InvalidPathErr{pathStr}
}
if len == 0 {
p := Path{
PathType: RootPathType,
}
return p, nil
}
if len == 1 {
p := Path{
PathType: KeybasePathType,
}
return p, nil
}
if len == 2 {
p := Path{
PathType: KeybaseChildPathType,
TLFType: listTypeToTLFType(components[1]),
}
return p, nil
}
p := Path{
PathType: TLFPathType,
TLFType: listTypeToTLFType(components[1]),
TLFName: components[2],
TLFComponents: components[3:],
}
return p, nil
} | go | func NewPath(pathStr string) (Path, error) {
components, err := split(pathStr)
if err != nil {
return Path{}, err
}
len := len(components)
if (len >= 1 && components[0] != topName) ||
(len >= 2 && components[1] != publicName && components[1] != privateName) {
return Path{}, InvalidPathErr{pathStr}
}
if len == 0 {
p := Path{
PathType: RootPathType,
}
return p, nil
}
if len == 1 {
p := Path{
PathType: KeybasePathType,
}
return p, nil
}
if len == 2 {
p := Path{
PathType: KeybaseChildPathType,
TLFType: listTypeToTLFType(components[1]),
}
return p, nil
}
p := Path{
PathType: TLFPathType,
TLFType: listTypeToTLFType(components[1]),
TLFName: components[2],
TLFComponents: components[3:],
}
return p, nil
} | [
"func",
"NewPath",
"(",
"pathStr",
"string",
")",
"(",
"Path",
",",
"error",
")",
"{",
"components",
",",
"err",
":=",
"split",
"(",
"pathStr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"Path",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"le... | // NewPath constructs a Path from a string | [
"NewPath",
"constructs",
"a",
"Path",
"from",
"a",
"string"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/fsrpc/path.go#L85-L126 |
160,110 | keybase/client | go/kbfs/fsrpc/path.go | DirAndBasename | func (p Path) DirAndBasename() (dir Path, basename string, err error) {
switch p.PathType {
case KeybasePathType:
dir = Path{
PathType: RootPathType,
}
basename = topName
return
case KeybaseChildPathType:
dir = Path{
PathType: KeybasePathType,
}
switch p.TLFType {
case tlf.Public:
basename = publicName
case tlf.Private:
basename = privateName
default:
panic(fmt.Sprintf("Unknown TLF type: %s", p.TLFType))
}
return
case TLFPathType:
len := len(p.TLFComponents)
if len == 0 {
dir = Path{
PathType: KeybaseChildPathType,
TLFType: p.TLFType,
}
basename = p.TLFName
} else {
dir = Path{
PathType: TLFPathType,
TLFType: p.TLFType,
TLFName: p.TLFName,
TLFComponents: p.TLFComponents[:len-1],
}
basename = p.TLFComponents[len-1]
}
return
}
err = errors.New("cannot split path")
return
} | go | func (p Path) DirAndBasename() (dir Path, basename string, err error) {
switch p.PathType {
case KeybasePathType:
dir = Path{
PathType: RootPathType,
}
basename = topName
return
case KeybaseChildPathType:
dir = Path{
PathType: KeybasePathType,
}
switch p.TLFType {
case tlf.Public:
basename = publicName
case tlf.Private:
basename = privateName
default:
panic(fmt.Sprintf("Unknown TLF type: %s", p.TLFType))
}
return
case TLFPathType:
len := len(p.TLFComponents)
if len == 0 {
dir = Path{
PathType: KeybaseChildPathType,
TLFType: p.TLFType,
}
basename = p.TLFName
} else {
dir = Path{
PathType: TLFPathType,
TLFType: p.TLFType,
TLFName: p.TLFName,
TLFComponents: p.TLFComponents[:len-1],
}
basename = p.TLFComponents[len-1]
}
return
}
err = errors.New("cannot split path")
return
} | [
"func",
"(",
"p",
"Path",
")",
"DirAndBasename",
"(",
")",
"(",
"dir",
"Path",
",",
"basename",
"string",
",",
"err",
"error",
")",
"{",
"switch",
"p",
".",
"PathType",
"{",
"case",
"KeybasePathType",
":",
"dir",
"=",
"Path",
"{",
"PathType",
":",
"R... | // DirAndBasename returns directory and base filename | [
"DirAndBasename",
"returns",
"directory",
"and",
"base",
"filename"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/fsrpc/path.go#L155-L201 |
160,111 | keybase/client | go/kbfs/fsrpc/path.go | Join | func (p Path) Join(childName string) (childPath Path, err error) {
switch p.PathType {
case RootPathType:
if childName != topName {
err = CannotJoinPathErr{p, childName}
return
}
childPath = Path{
PathType: KeybasePathType,
}
return
case KeybasePathType:
if childName != publicName && childName != privateName {
err = CannotJoinPathErr{p, childName}
}
childPath = Path{
PathType: KeybaseChildPathType,
TLFType: listTypeToTLFType(childName),
}
return
case KeybaseChildPathType:
childPath = Path{
PathType: TLFPathType,
TLFType: p.TLFType,
TLFName: childName,
}
return
case TLFPathType:
childPath = Path{
PathType: TLFPathType,
TLFType: p.TLFType,
TLFName: p.TLFName,
TLFComponents: append(p.TLFComponents, childName),
}
return
}
err = CannotJoinPathErr{p, childName}
return
} | go | func (p Path) Join(childName string) (childPath Path, err error) {
switch p.PathType {
case RootPathType:
if childName != topName {
err = CannotJoinPathErr{p, childName}
return
}
childPath = Path{
PathType: KeybasePathType,
}
return
case KeybasePathType:
if childName != publicName && childName != privateName {
err = CannotJoinPathErr{p, childName}
}
childPath = Path{
PathType: KeybaseChildPathType,
TLFType: listTypeToTLFType(childName),
}
return
case KeybaseChildPathType:
childPath = Path{
PathType: TLFPathType,
TLFType: p.TLFType,
TLFName: childName,
}
return
case TLFPathType:
childPath = Path{
PathType: TLFPathType,
TLFType: p.TLFType,
TLFName: p.TLFName,
TLFComponents: append(p.TLFComponents, childName),
}
return
}
err = CannotJoinPathErr{p, childName}
return
} | [
"func",
"(",
"p",
"Path",
")",
"Join",
"(",
"childName",
"string",
")",
"(",
"childPath",
"Path",
",",
"err",
"error",
")",
"{",
"switch",
"p",
".",
"PathType",
"{",
"case",
"RootPathType",
":",
"if",
"childName",
"!=",
"topName",
"{",
"err",
"=",
"C... | // Join will append a path to this path | [
"Join",
"will",
"append",
"a",
"path",
"to",
"this",
"path"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/fsrpc/path.go#L204-L248 |
160,112 | keybase/client | go/kbfs/fsrpc/path.go | ParseTlfHandle | func ParseTlfHandle(
ctx context.Context, kbpki libkbfs.KBPKI, mdOps libkbfs.MDOps,
osg idutil.OfflineStatusGetter, name string, t tlf.Type) (
*tlfhandle.Handle, error) {
var tlfHandle *tlfhandle.Handle
outer:
for {
var parseErr error
tlfHandle, parseErr = tlfhandle.ParseHandle(
ctx, kbpki, mdOps, osg, name, t)
switch parseErr := errors.Cause(parseErr).(type) {
case nil:
// No error.
break outer
case idutil.TlfNameNotCanonical:
// Non-canonical name, so try again.
name = parseErr.NameToTry
default:
// Some other error.
return nil, parseErr
}
}
return tlfHandle, nil
} | go | func ParseTlfHandle(
ctx context.Context, kbpki libkbfs.KBPKI, mdOps libkbfs.MDOps,
osg idutil.OfflineStatusGetter, name string, t tlf.Type) (
*tlfhandle.Handle, error) {
var tlfHandle *tlfhandle.Handle
outer:
for {
var parseErr error
tlfHandle, parseErr = tlfhandle.ParseHandle(
ctx, kbpki, mdOps, osg, name, t)
switch parseErr := errors.Cause(parseErr).(type) {
case nil:
// No error.
break outer
case idutil.TlfNameNotCanonical:
// Non-canonical name, so try again.
name = parseErr.NameToTry
default:
// Some other error.
return nil, parseErr
}
}
return tlfHandle, nil
} | [
"func",
"ParseTlfHandle",
"(",
"ctx",
"context",
".",
"Context",
",",
"kbpki",
"libkbfs",
".",
"KBPKI",
",",
"mdOps",
"libkbfs",
".",
"MDOps",
",",
"osg",
"idutil",
".",
"OfflineStatusGetter",
",",
"name",
"string",
",",
"t",
"tlf",
".",
"Type",
")",
"("... | // ParseTlfHandle is a wrapper around libkbfs.ParseTlfHandle that
// automatically resolves non-canonical names. | [
"ParseTlfHandle",
"is",
"a",
"wrapper",
"around",
"libkbfs",
".",
"ParseTlfHandle",
"that",
"automatically",
"resolves",
"non",
"-",
"canonical",
"names",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/fsrpc/path.go#L252-L278 |
160,113 | keybase/client | go/kbfs/fsrpc/path.go | GetNode | func (p Path) GetNode(ctx context.Context, config libkbfs.Config) (libkbfs.Node, data.EntryInfo, error) {
if p.PathType != TLFPathType {
entryInfo := data.EntryInfo{
Type: data.Dir,
}
return nil, entryInfo, nil
}
tlfHandle, err := ParseTlfHandle(
ctx, config.KBPKI(), config.MDOps(), config, p.TLFName, p.TLFType)
if err != nil {
return nil, data.EntryInfo{}, err
}
node, entryInfo, err := config.KBFSOps().GetOrCreateRootNode(ctx, tlfHandle, data.MasterBranch)
if err != nil {
return nil, data.EntryInfo{}, err
}
for _, component := range p.TLFComponents {
lookupNode, lookupEntryInfo, lookupErr := config.KBFSOps().Lookup(ctx, node, component)
if lookupErr != nil {
return nil, data.EntryInfo{}, lookupErr
}
node = lookupNode
entryInfo = lookupEntryInfo
}
return node, entryInfo, nil
} | go | func (p Path) GetNode(ctx context.Context, config libkbfs.Config) (libkbfs.Node, data.EntryInfo, error) {
if p.PathType != TLFPathType {
entryInfo := data.EntryInfo{
Type: data.Dir,
}
return nil, entryInfo, nil
}
tlfHandle, err := ParseTlfHandle(
ctx, config.KBPKI(), config.MDOps(), config, p.TLFName, p.TLFType)
if err != nil {
return nil, data.EntryInfo{}, err
}
node, entryInfo, err := config.KBFSOps().GetOrCreateRootNode(ctx, tlfHandle, data.MasterBranch)
if err != nil {
return nil, data.EntryInfo{}, err
}
for _, component := range p.TLFComponents {
lookupNode, lookupEntryInfo, lookupErr := config.KBFSOps().Lookup(ctx, node, component)
if lookupErr != nil {
return nil, data.EntryInfo{}, lookupErr
}
node = lookupNode
entryInfo = lookupEntryInfo
}
return node, entryInfo, nil
} | [
"func",
"(",
"p",
"Path",
")",
"GetNode",
"(",
"ctx",
"context",
".",
"Context",
",",
"config",
"libkbfs",
".",
"Config",
")",
"(",
"libkbfs",
".",
"Node",
",",
"data",
".",
"EntryInfo",
",",
"error",
")",
"{",
"if",
"p",
".",
"PathType",
"!=",
"TL... | // GetNode returns a node | [
"GetNode",
"returns",
"a",
"node"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/fsrpc/path.go#L281-L310 |
160,114 | keybase/client | go/kbfs/fsrpc/path.go | GetFileNode | func (p Path) GetFileNode(ctx context.Context, config libkbfs.Config) (libkbfs.Node, error) {
n, de, err := p.GetNode(ctx, config)
if err != nil {
return nil, err
}
// TODO: What to do with symlinks?
if de.Type != data.File && de.Type != data.Exec {
return nil, fmt.Errorf("openFile: %s is not a file, but a %s", p, de.Type)
}
return n, nil
} | go | func (p Path) GetFileNode(ctx context.Context, config libkbfs.Config) (libkbfs.Node, error) {
n, de, err := p.GetNode(ctx, config)
if err != nil {
return nil, err
}
// TODO: What to do with symlinks?
if de.Type != data.File && de.Type != data.Exec {
return nil, fmt.Errorf("openFile: %s is not a file, but a %s", p, de.Type)
}
return n, nil
} | [
"func",
"(",
"p",
"Path",
")",
"GetFileNode",
"(",
"ctx",
"context",
".",
"Context",
",",
"config",
"libkbfs",
".",
"Config",
")",
"(",
"libkbfs",
".",
"Node",
",",
"error",
")",
"{",
"n",
",",
"de",
",",
"err",
":=",
"p",
".",
"GetNode",
"(",
"c... | // GetFileNode returns a file node | [
"GetFileNode",
"returns",
"a",
"file",
"node"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/fsrpc/path.go#L313-L326 |
160,115 | keybase/client | go/kbfs/fsrpc/path.go | GetDirNode | func (p Path) GetDirNode(ctx context.Context, config libkbfs.Config) (libkbfs.Node, error) {
// TODO: Handle non-TLFPathTypes.
n, de, err := p.GetNode(ctx, config)
if err != nil {
return nil, err
}
// TODO: What to do with symlinks?
if de.Type != data.Dir {
return nil, fmt.Errorf("openDir: %s is not a dir, but a %s", p, de.Type)
}
return n, nil
} | go | func (p Path) GetDirNode(ctx context.Context, config libkbfs.Config) (libkbfs.Node, error) {
// TODO: Handle non-TLFPathTypes.
n, de, err := p.GetNode(ctx, config)
if err != nil {
return nil, err
}
// TODO: What to do with symlinks?
if de.Type != data.Dir {
return nil, fmt.Errorf("openDir: %s is not a dir, but a %s", p, de.Type)
}
return n, nil
} | [
"func",
"(",
"p",
"Path",
")",
"GetDirNode",
"(",
"ctx",
"context",
".",
"Context",
",",
"config",
"libkbfs",
".",
"Config",
")",
"(",
"libkbfs",
".",
"Node",
",",
"error",
")",
"{",
"// TODO: Handle non-TLFPathTypes.",
"n",
",",
"de",
",",
"err",
":=",
... | // GetDirNode returns a nil node if this doesn't have type TLFPathType | [
"GetDirNode",
"returns",
"a",
"nil",
"node",
"if",
"this",
"doesn",
"t",
"have",
"type",
"TLFPathType"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/fsrpc/path.go#L329-L344 |
160,116 | keybase/client | go/libkb/identify_outcome.go | NumProofFailures | func (i IdentifyOutcome) NumProofFailures() int {
nfails := 0
for _, c := range i.ProofChecks {
if c.err != nil {
nfails++
}
}
return nfails
} | go | func (i IdentifyOutcome) NumProofFailures() int {
nfails := 0
for _, c := range i.ProofChecks {
if c.err != nil {
nfails++
}
}
return nfails
} | [
"func",
"(",
"i",
"IdentifyOutcome",
")",
"NumProofFailures",
"(",
")",
"int",
"{",
"nfails",
":=",
"0",
"\n",
"for",
"_",
",",
"c",
":=",
"range",
"i",
".",
"ProofChecks",
"{",
"if",
"c",
".",
"err",
"!=",
"nil",
"{",
"nfails",
"++",
"\n",
"}",
... | // The number of proofs that failed. | [
"The",
"number",
"of",
"proofs",
"that",
"failed",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/identify_outcome.go#L98-L106 |
160,117 | keybase/client | go/libkb/identify_outcome.go | NumProofSuccesses | func (i IdentifyOutcome) NumProofSuccesses() int {
nsucc := 0
for _, c := range i.ProofChecks {
if c.err == nil {
nsucc++
}
}
return nsucc
} | go | func (i IdentifyOutcome) NumProofSuccesses() int {
nsucc := 0
for _, c := range i.ProofChecks {
if c.err == nil {
nsucc++
}
}
return nsucc
} | [
"func",
"(",
"i",
"IdentifyOutcome",
")",
"NumProofSuccesses",
"(",
")",
"int",
"{",
"nsucc",
":=",
"0",
"\n",
"for",
"_",
",",
"c",
":=",
"range",
"i",
".",
"ProofChecks",
"{",
"if",
"c",
".",
"err",
"==",
"nil",
"{",
"nsucc",
"++",
"\n",
"}",
"... | // The number of proofs that actually worked | [
"The",
"number",
"of",
"proofs",
"that",
"actually",
"worked"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/identify_outcome.go#L109-L117 |
160,118 | keybase/client | go/libkb/identify_outcome.go | NumTrackFailures | func (i IdentifyOutcome) NumTrackFailures() int {
ntf := 0
check := func(d TrackDiff) bool {
return d != nil && d.BreaksTracking()
}
for _, c := range i.ProofChecks {
if check(c.diff) || check(c.remoteDiff) {
ntf++
}
}
for _, k := range i.KeyDiffs {
if check(k) {
ntf++
}
}
return ntf
} | go | func (i IdentifyOutcome) NumTrackFailures() int {
ntf := 0
check := func(d TrackDiff) bool {
return d != nil && d.BreaksTracking()
}
for _, c := range i.ProofChecks {
if check(c.diff) || check(c.remoteDiff) {
ntf++
}
}
for _, k := range i.KeyDiffs {
if check(k) {
ntf++
}
}
return ntf
} | [
"func",
"(",
"i",
"IdentifyOutcome",
")",
"NumTrackFailures",
"(",
")",
"int",
"{",
"ntf",
":=",
"0",
"\n",
"check",
":=",
"func",
"(",
"d",
"TrackDiff",
")",
"bool",
"{",
"return",
"d",
"!=",
"nil",
"&&",
"d",
".",
"BreaksTracking",
"(",
")",
"\n",
... | // A "Track Failure" is when we previously tracked this user, and
// some aspect of their proof changed. Like their key changed, or
// they changed Twitter names | [
"A",
"Track",
"Failure",
"is",
"when",
"we",
"previously",
"tracked",
"this",
"user",
"and",
"some",
"aspect",
"of",
"their",
"proof",
"changed",
".",
"Like",
"their",
"key",
"changed",
"or",
"they",
"changed",
"Twitter",
"names"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/identify_outcome.go#L122-L140 |
160,119 | keybase/client | go/libkb/identify_outcome.go | NumTrackChanges | func (i IdentifyOutcome) NumTrackChanges() int {
ntc := 0
check := func(d TrackDiff) bool {
return d != nil && !d.IsSameAsTracked()
}
for _, c := range i.ProofChecks {
if check(c.diff) || check(c.remoteDiff) {
ntc++
}
}
for _, k := range i.KeyDiffs {
if check(k) {
ntc++
}
}
return ntc
} | go | func (i IdentifyOutcome) NumTrackChanges() int {
ntc := 0
check := func(d TrackDiff) bool {
return d != nil && !d.IsSameAsTracked()
}
for _, c := range i.ProofChecks {
if check(c.diff) || check(c.remoteDiff) {
ntc++
}
}
for _, k := range i.KeyDiffs {
if check(k) {
ntc++
}
}
return ntc
} | [
"func",
"(",
"i",
"IdentifyOutcome",
")",
"NumTrackChanges",
"(",
")",
"int",
"{",
"ntc",
":=",
"0",
"\n",
"check",
":=",
"func",
"(",
"d",
"TrackDiff",
")",
"bool",
"{",
"return",
"d",
"!=",
"nil",
"&&",
"!",
"d",
".",
"IsSameAsTracked",
"(",
")",
... | // A "Track Change" isn't necessary a failure, maybe they upgraded
// a proof from HTTP to HTTPS. But we still should retrack if we can. | [
"A",
"Track",
"Change",
"isn",
"t",
"necessary",
"a",
"failure",
"maybe",
"they",
"upgraded",
"a",
"proof",
"from",
"HTTP",
"to",
"HTTPS",
".",
"But",
"we",
"still",
"should",
"retrack",
"if",
"we",
"can",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/identify_outcome.go#L144-L160 |
160,120 | keybase/client | go/teams/get.go | GetMaybeAdminByStringName | func GetMaybeAdminByStringName(ctx context.Context, g *libkb.GlobalContext, name string, public bool) (*Team, error) {
// Find out our up-to-date role.
team, err := Load(ctx, g, keybase1.LoadTeamArg{
Name: name,
Public: public,
ForceRepoll: true,
RefreshUIDMapper: true,
AllowNameLookupBurstCache: true,
})
if err != nil {
return nil, fixupTeamGetError(ctx, g, err, name, public)
}
me, err := loadUserVersionByUID(ctx, g, g.Env.GetUID())
if err != nil {
return nil, err
}
role, err := team.MemberRole(ctx, me)
if err != nil {
return nil, err
}
if role.IsAdminOrAbove() {
// Will hit the cache _unless_ we had a cached non-admin team
// and are now an admin.
team, err = Load(ctx, g, keybase1.LoadTeamArg{
Name: name,
Public: public,
NeedAdmin: true,
AllowNameLookupBurstCache: true,
})
if err != nil {
return nil, err
}
}
return team, nil
} | go | func GetMaybeAdminByStringName(ctx context.Context, g *libkb.GlobalContext, name string, public bool) (*Team, error) {
// Find out our up-to-date role.
team, err := Load(ctx, g, keybase1.LoadTeamArg{
Name: name,
Public: public,
ForceRepoll: true,
RefreshUIDMapper: true,
AllowNameLookupBurstCache: true,
})
if err != nil {
return nil, fixupTeamGetError(ctx, g, err, name, public)
}
me, err := loadUserVersionByUID(ctx, g, g.Env.GetUID())
if err != nil {
return nil, err
}
role, err := team.MemberRole(ctx, me)
if err != nil {
return nil, err
}
if role.IsAdminOrAbove() {
// Will hit the cache _unless_ we had a cached non-admin team
// and are now an admin.
team, err = Load(ctx, g, keybase1.LoadTeamArg{
Name: name,
Public: public,
NeedAdmin: true,
AllowNameLookupBurstCache: true,
})
if err != nil {
return nil, err
}
}
return team, nil
} | [
"func",
"GetMaybeAdminByStringName",
"(",
"ctx",
"context",
".",
"Context",
",",
"g",
"*",
"libkb",
".",
"GlobalContext",
",",
"name",
"string",
",",
"public",
"bool",
")",
"(",
"*",
"Team",
",",
"error",
")",
"{",
"// Find out our up-to-date role.",
"team",
... | // Get a team with no stubbed links if we are an admin. Use this instead of NeedAdmin when you don't
// know whether you are an admin. This always causes roundtrips. Doesn't work for implicit admins. | [
"Get",
"a",
"team",
"with",
"no",
"stubbed",
"links",
"if",
"we",
"are",
"an",
"admin",
".",
"Use",
"this",
"instead",
"of",
"NeedAdmin",
"when",
"you",
"don",
"t",
"know",
"whether",
"you",
"are",
"an",
"admin",
".",
"This",
"always",
"causes",
"round... | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/teams/get.go#L74-L108 |
160,121 | keybase/client | go/kbfs/libfuse/tlf.go | loadDirAllowNonexistent | func (tlf *TLF) loadDirAllowNonexistent(ctx context.Context) (
*Dir, bool, error) {
return tlf.loadDirHelper(ctx, libkbfs.ReadMode, data.MasterBranch, true)
} | go | func (tlf *TLF) loadDirAllowNonexistent(ctx context.Context) (
*Dir, bool, error) {
return tlf.loadDirHelper(ctx, libkbfs.ReadMode, data.MasterBranch, true)
} | [
"func",
"(",
"tlf",
"*",
"TLF",
")",
"loadDirAllowNonexistent",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"*",
"Dir",
",",
"bool",
",",
"error",
")",
"{",
"return",
"tlf",
".",
"loadDirHelper",
"(",
"ctx",
",",
"libkbfs",
".",
"ReadMode",
",",
... | // loadDirAllowNonexistent loads a TLF if it's not already loaded. If
// the TLF doesn't yet exist, it still returns a nil error and
// indicates that the calling function should pretend it's an empty
// folder. | [
"loadDirAllowNonexistent",
"loads",
"a",
"TLF",
"if",
"it",
"s",
"not",
"already",
"loaded",
".",
"If",
"the",
"TLF",
"doesn",
"t",
"yet",
"exist",
"it",
"still",
"returns",
"a",
"nil",
"error",
"and",
"indicates",
"that",
"the",
"calling",
"function",
"sh... | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfuse/tlf.go#L144-L147 |
160,122 | keybase/client | go/kbfs/libfuse/tlf.go | Attr | func (tlf *TLF) Attr(ctx context.Context, a *fuse.Attr) error {
dir := tlf.getStoredDir()
a.Inode = tlf.inode
if dir == nil {
tlf.vlog().CLogf(
ctx, libkb.VLog1, "Faking Attr for TLF %s", tlf.folder.name())
// Have a low non-zero value for Valid to avoid being
// swamped with requests, while still not showing
// stale data for too long if we end up loading the
// dir.
a.Valid = 1 * time.Second
a.Mode = os.ModeDir | 0500
a.Uid = uint32(os.Getuid())
return nil
}
return dir.Attr(ctx, a)
} | go | func (tlf *TLF) Attr(ctx context.Context, a *fuse.Attr) error {
dir := tlf.getStoredDir()
a.Inode = tlf.inode
if dir == nil {
tlf.vlog().CLogf(
ctx, libkb.VLog1, "Faking Attr for TLF %s", tlf.folder.name())
// Have a low non-zero value for Valid to avoid being
// swamped with requests, while still not showing
// stale data for too long if we end up loading the
// dir.
a.Valid = 1 * time.Second
a.Mode = os.ModeDir | 0500
a.Uid = uint32(os.Getuid())
return nil
}
return dir.Attr(ctx, a)
} | [
"func",
"(",
"tlf",
"*",
"TLF",
")",
"Attr",
"(",
"ctx",
"context",
".",
"Context",
",",
"a",
"*",
"fuse",
".",
"Attr",
")",
"error",
"{",
"dir",
":=",
"tlf",
".",
"getStoredDir",
"(",
")",
"\n",
"a",
".",
"Inode",
"=",
"tlf",
".",
"inode",
"\n... | // Attr implements the fs.Node interface for TLF. | [
"Attr",
"implements",
"the",
"fs",
".",
"Node",
"interface",
"for",
"TLF",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfuse/tlf.go#L162-L179 |
160,123 | keybase/client | go/kbfs/libfuse/tlf.go | Lookup | func (tlf *TLF) Lookup(ctx context.Context, req *fuse.LookupRequest, resp *fuse.LookupResponse) (fs.Node, error) {
if tlfLoadAvoidingLookupNames[req.Name] {
dir := tlf.getStoredDir()
if dir == nil {
tlf.vlog().CLogf(
ctx, libkb.VLog1, "Avoiding TLF loading for name %s", req.Name)
return nil, fuse.ENOENT
}
return dir.Lookup(ctx, req, resp)
}
dir, exitEarly, err := tlf.loadDirAllowNonexistent(ctx)
if err != nil {
return nil, err
}
if exitEarly {
if node := handleTLFSpecialFile(
req.Name, tlf.folder, &resp.EntryValid); node != nil {
return node, nil
}
return nil, fuse.ENOENT
}
branch, isArchivedBranch := libfs.BranchNameFromArchiveRefDir(req.Name)
if isArchivedBranch {
archivedTLF := newTLF(ctx,
tlf.folder.list, tlf.folder.h, tlf.folder.hPreferredName)
_, _, err := archivedTLF.loadArchivedDir(ctx, branch)
if err != nil {
return nil, err
}
return archivedTLF, nil
}
linkTarget, isArchivedTimeLink, err := libfs.LinkTargetFromTimeString(
ctx, tlf.folder.fs.config, tlf.folder.h, req.Name)
if err != nil {
return nil, err
}
if isArchivedTimeLink {
return &Alias{
realPath: linkTarget,
inode: 0,
}, nil
}
_, isRelTimeLink, err := libfs.FileDataFromRelativeTimeString(
ctx, tlf.folder.fs.config, tlf.folder.h, req.Name)
if err != nil {
return nil, err
}
if isRelTimeLink {
return NewArchiveRelTimeFile(
tlf.folder.fs, tlf.folder.h, req.Name, &resp.EntryValid), nil
}
return dir.Lookup(ctx, req, resp)
} | go | func (tlf *TLF) Lookup(ctx context.Context, req *fuse.LookupRequest, resp *fuse.LookupResponse) (fs.Node, error) {
if tlfLoadAvoidingLookupNames[req.Name] {
dir := tlf.getStoredDir()
if dir == nil {
tlf.vlog().CLogf(
ctx, libkb.VLog1, "Avoiding TLF loading for name %s", req.Name)
return nil, fuse.ENOENT
}
return dir.Lookup(ctx, req, resp)
}
dir, exitEarly, err := tlf.loadDirAllowNonexistent(ctx)
if err != nil {
return nil, err
}
if exitEarly {
if node := handleTLFSpecialFile(
req.Name, tlf.folder, &resp.EntryValid); node != nil {
return node, nil
}
return nil, fuse.ENOENT
}
branch, isArchivedBranch := libfs.BranchNameFromArchiveRefDir(req.Name)
if isArchivedBranch {
archivedTLF := newTLF(ctx,
tlf.folder.list, tlf.folder.h, tlf.folder.hPreferredName)
_, _, err := archivedTLF.loadArchivedDir(ctx, branch)
if err != nil {
return nil, err
}
return archivedTLF, nil
}
linkTarget, isArchivedTimeLink, err := libfs.LinkTargetFromTimeString(
ctx, tlf.folder.fs.config, tlf.folder.h, req.Name)
if err != nil {
return nil, err
}
if isArchivedTimeLink {
return &Alias{
realPath: linkTarget,
inode: 0,
}, nil
}
_, isRelTimeLink, err := libfs.FileDataFromRelativeTimeString(
ctx, tlf.folder.fs.config, tlf.folder.h, req.Name)
if err != nil {
return nil, err
}
if isRelTimeLink {
return NewArchiveRelTimeFile(
tlf.folder.fs, tlf.folder.h, req.Name, &resp.EntryValid), nil
}
return dir.Lookup(ctx, req, resp)
} | [
"func",
"(",
"tlf",
"*",
"TLF",
")",
"Lookup",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"fuse",
".",
"LookupRequest",
",",
"resp",
"*",
"fuse",
".",
"LookupResponse",
")",
"(",
"fs",
".",
"Node",
",",
"error",
")",
"{",
"if",
"tlfLoa... | // Lookup implements the fs.NodeRequestLookuper interface for TLF. | [
"Lookup",
"implements",
"the",
"fs",
".",
"NodeRequestLookuper",
"interface",
"for",
"TLF",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfuse/tlf.go#L195-L252 |
160,124 | keybase/client | go/kbfs/libfuse/tlf.go | Create | func (tlf *TLF) Create(ctx context.Context, req *fuse.CreateRequest, resp *fuse.CreateResponse) (fs.Node, fs.Handle, error) {
dir, err := tlf.loadDir(ctx)
if err != nil {
return nil, nil, err
}
return dir.Create(ctx, req, resp)
} | go | func (tlf *TLF) Create(ctx context.Context, req *fuse.CreateRequest, resp *fuse.CreateResponse) (fs.Node, fs.Handle, error) {
dir, err := tlf.loadDir(ctx)
if err != nil {
return nil, nil, err
}
return dir.Create(ctx, req, resp)
} | [
"func",
"(",
"tlf",
"*",
"TLF",
")",
"Create",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"fuse",
".",
"CreateRequest",
",",
"resp",
"*",
"fuse",
".",
"CreateResponse",
")",
"(",
"fs",
".",
"Node",
",",
"fs",
".",
"Handle",
",",
"error... | // Create implements the fs.NodeCreater interface for TLF. | [
"Create",
"implements",
"the",
"fs",
".",
"NodeCreater",
"interface",
"for",
"TLF",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfuse/tlf.go#L255-L261 |
160,125 | keybase/client | go/kbfs/libfuse/tlf.go | Mkdir | func (tlf *TLF) Mkdir(ctx context.Context, req *fuse.MkdirRequest) (_ fs.Node, err error) {
dir, err := tlf.loadDir(ctx)
if err != nil {
return nil, err
}
return dir.Mkdir(ctx, req)
} | go | func (tlf *TLF) Mkdir(ctx context.Context, req *fuse.MkdirRequest) (_ fs.Node, err error) {
dir, err := tlf.loadDir(ctx)
if err != nil {
return nil, err
}
return dir.Mkdir(ctx, req)
} | [
"func",
"(",
"tlf",
"*",
"TLF",
")",
"Mkdir",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"fuse",
".",
"MkdirRequest",
")",
"(",
"_",
"fs",
".",
"Node",
",",
"err",
"error",
")",
"{",
"dir",
",",
"err",
":=",
"tlf",
".",
"loadDir",
... | // Mkdir implements the fs.NodeMkdirer interface for TLF. | [
"Mkdir",
"implements",
"the",
"fs",
".",
"NodeMkdirer",
"interface",
"for",
"TLF",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfuse/tlf.go#L264-L270 |
160,126 | keybase/client | go/kbfs/libfuse/tlf.go | Symlink | func (tlf *TLF) Symlink(ctx context.Context, req *fuse.SymlinkRequest) (
fs.Node, error) {
dir, err := tlf.loadDir(ctx)
if err != nil {
return nil, err
}
return dir.Symlink(ctx, req)
} | go | func (tlf *TLF) Symlink(ctx context.Context, req *fuse.SymlinkRequest) (
fs.Node, error) {
dir, err := tlf.loadDir(ctx)
if err != nil {
return nil, err
}
return dir.Symlink(ctx, req)
} | [
"func",
"(",
"tlf",
"*",
"TLF",
")",
"Symlink",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"fuse",
".",
"SymlinkRequest",
")",
"(",
"fs",
".",
"Node",
",",
"error",
")",
"{",
"dir",
",",
"err",
":=",
"tlf",
".",
"loadDir",
"(",
"ctx"... | // Symlink implements the fs.NodeSymlinker interface for TLF. | [
"Symlink",
"implements",
"the",
"fs",
".",
"NodeSymlinker",
"interface",
"for",
"TLF",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfuse/tlf.go#L273-L280 |
160,127 | keybase/client | go/kbfs/libfuse/tlf.go | Rename | func (tlf *TLF) Rename(ctx context.Context, req *fuse.RenameRequest,
newDir fs.Node) error {
dir, err := tlf.loadDir(ctx)
if err != nil {
return err
}
return dir.Rename(ctx, req, newDir)
} | go | func (tlf *TLF) Rename(ctx context.Context, req *fuse.RenameRequest,
newDir fs.Node) error {
dir, err := tlf.loadDir(ctx)
if err != nil {
return err
}
return dir.Rename(ctx, req, newDir)
} | [
"func",
"(",
"tlf",
"*",
"TLF",
")",
"Rename",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"fuse",
".",
"RenameRequest",
",",
"newDir",
"fs",
".",
"Node",
")",
"error",
"{",
"dir",
",",
"err",
":=",
"tlf",
".",
"loadDir",
"(",
"ctx",
... | // Rename implements the fs.NodeRenamer interface for TLF. | [
"Rename",
"implements",
"the",
"fs",
".",
"NodeRenamer",
"interface",
"for",
"TLF",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfuse/tlf.go#L283-L290 |
160,128 | keybase/client | go/kbfs/libfuse/tlf.go | Remove | func (tlf *TLF) Remove(ctx context.Context, req *fuse.RemoveRequest) error {
dir, err := tlf.loadDir(ctx)
if err != nil {
return err
}
return dir.Remove(ctx, req)
} | go | func (tlf *TLF) Remove(ctx context.Context, req *fuse.RemoveRequest) error {
dir, err := tlf.loadDir(ctx)
if err != nil {
return err
}
return dir.Remove(ctx, req)
} | [
"func",
"(",
"tlf",
"*",
"TLF",
")",
"Remove",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"fuse",
".",
"RemoveRequest",
")",
"error",
"{",
"dir",
",",
"err",
":=",
"tlf",
".",
"loadDir",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil... | // Remove implements the fs.NodeRemover interface for TLF. | [
"Remove",
"implements",
"the",
"fs",
".",
"NodeRemover",
"interface",
"for",
"TLF",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfuse/tlf.go#L293-L299 |
160,129 | keybase/client | go/kbfs/libfuse/tlf.go | ReadDirAll | func (tlf *TLF) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
dir, exitEarly, err := tlf.loadDirAllowNonexistent(ctx)
if err != nil || exitEarly {
return nil, err
}
return dir.ReadDirAll(ctx)
} | go | func (tlf *TLF) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
dir, exitEarly, err := tlf.loadDirAllowNonexistent(ctx)
if err != nil || exitEarly {
return nil, err
}
return dir.ReadDirAll(ctx)
} | [
"func",
"(",
"tlf",
"*",
"TLF",
")",
"ReadDirAll",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"[",
"]",
"fuse",
".",
"Dirent",
",",
"error",
")",
"{",
"dir",
",",
"exitEarly",
",",
"err",
":=",
"tlf",
".",
"loadDirAllowNonexistent",
"(",
"ctx",... | // ReadDirAll implements the fs.NodeReadDirAller interface for TLF. | [
"ReadDirAll",
"implements",
"the",
"fs",
".",
"NodeReadDirAller",
"interface",
"for",
"TLF",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfuse/tlf.go#L302-L308 |
160,130 | keybase/client | go/kbfs/libfuse/tlf.go | Setattr | func (tlf *TLF) Setattr(ctx context.Context, req *fuse.SetattrRequest, resp *fuse.SetattrResponse) error {
dir, err := tlf.loadDir(ctx)
if err != nil {
return err
}
return dir.Setattr(ctx, req, resp)
} | go | func (tlf *TLF) Setattr(ctx context.Context, req *fuse.SetattrRequest, resp *fuse.SetattrResponse) error {
dir, err := tlf.loadDir(ctx)
if err != nil {
return err
}
return dir.Setattr(ctx, req, resp)
} | [
"func",
"(",
"tlf",
"*",
"TLF",
")",
"Setattr",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"fuse",
".",
"SetattrRequest",
",",
"resp",
"*",
"fuse",
".",
"SetattrResponse",
")",
"error",
"{",
"dir",
",",
"err",
":=",
"tlf",
".",
"loadDir"... | // Setattr implements the fs.NodeSetattrer interface for TLF. | [
"Setattr",
"implements",
"the",
"fs",
".",
"NodeSetattrer",
"interface",
"for",
"TLF",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfuse/tlf.go#L319-L325 |
160,131 | keybase/client | go/kbfs/libfuse/tlf.go | Fsync | func (tlf *TLF) Fsync(ctx context.Context, req *fuse.FsyncRequest) (err error) {
dir := tlf.getStoredDir()
if dir == nil {
// The directory hasn't been loaded yet, so there's nothing to do.
return nil
}
return dir.Fsync(ctx, req)
} | go | func (tlf *TLF) Fsync(ctx context.Context, req *fuse.FsyncRequest) (err error) {
dir := tlf.getStoredDir()
if dir == nil {
// The directory hasn't been loaded yet, so there's nothing to do.
return nil
}
return dir.Fsync(ctx, req)
} | [
"func",
"(",
"tlf",
"*",
"TLF",
")",
"Fsync",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"fuse",
".",
"FsyncRequest",
")",
"(",
"err",
"error",
")",
"{",
"dir",
":=",
"tlf",
".",
"getStoredDir",
"(",
")",
"\n",
"if",
"dir",
"==",
"ni... | // Fsync implements the fs.NodeFsyncer interface for TLF. | [
"Fsync",
"implements",
"the",
"fs",
".",
"NodeFsyncer",
"interface",
"for",
"TLF",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfuse/tlf.go#L328-L336 |
160,132 | keybase/client | go/kbfs/libfuse/tlf.go | Open | func (tlf *TLF) Open(ctx context.Context, req *fuse.OpenRequest,
resp *fuse.OpenResponse) (fs.Handle, error) {
// Explicitly load the directory when a TLF is opened, because
// some OSX programs like ls have a bug that doesn't report errors
// on a ReadDirAll.
_, _, err := tlf.loadDirAllowNonexistent(ctx)
if err != nil {
return nil, err
}
return tlf, nil
} | go | func (tlf *TLF) Open(ctx context.Context, req *fuse.OpenRequest,
resp *fuse.OpenResponse) (fs.Handle, error) {
// Explicitly load the directory when a TLF is opened, because
// some OSX programs like ls have a bug that doesn't report errors
// on a ReadDirAll.
_, _, err := tlf.loadDirAllowNonexistent(ctx)
if err != nil {
return nil, err
}
return tlf, nil
} | [
"func",
"(",
"tlf",
"*",
"TLF",
")",
"Open",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"fuse",
".",
"OpenRequest",
",",
"resp",
"*",
"fuse",
".",
"OpenResponse",
")",
"(",
"fs",
".",
"Handle",
",",
"error",
")",
"{",
"// Explicitly load... | // Open implements the fs.NodeOpener interface for TLF. | [
"Open",
"implements",
"the",
"fs",
".",
"NodeOpener",
"interface",
"for",
"TLF",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfuse/tlf.go#L343-L353 |
160,133 | keybase/client | go/protocol/keybase1/reachability.go | StartReachability | func (c ReachabilityClient) StartReachability(ctx context.Context) (res Reachability, err error) {
err = c.Cli.Call(ctx, "keybase.1.reachability.startReachability", []interface{}{StartReachabilityArg{}}, &res)
return
} | go | func (c ReachabilityClient) StartReachability(ctx context.Context) (res Reachability, err error) {
err = c.Cli.Call(ctx, "keybase.1.reachability.startReachability", []interface{}{StartReachabilityArg{}}, &res)
return
} | [
"func",
"(",
"c",
"ReachabilityClient",
")",
"StartReachability",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"res",
"Reachability",
",",
"err",
"error",
")",
"{",
"err",
"=",
"c",
".",
"Cli",
".",
"Call",
"(",
"ctx",
",",
"\"",
"\"",
",",
"[",
... | // Start reachability checks and return current status, which
// may be cached. | [
"Start",
"reachability",
"checks",
"and",
"return",
"current",
"status",
"which",
"may",
"be",
"cached",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/protocol/keybase1/reachability.go#L124-L127 |
160,134 | keybase/client | go/protocol/keybase1/reachability.go | CheckReachability | func (c ReachabilityClient) CheckReachability(ctx context.Context) (res Reachability, err error) {
err = c.Cli.Call(ctx, "keybase.1.reachability.checkReachability", []interface{}{CheckReachabilityArg{}}, &res)
return
} | go | func (c ReachabilityClient) CheckReachability(ctx context.Context) (res Reachability, err error) {
err = c.Cli.Call(ctx, "keybase.1.reachability.checkReachability", []interface{}{CheckReachabilityArg{}}, &res)
return
} | [
"func",
"(",
"c",
"ReachabilityClient",
")",
"CheckReachability",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"res",
"Reachability",
",",
"err",
"error",
")",
"{",
"err",
"=",
"c",
".",
"Cli",
".",
"Call",
"(",
"ctx",
",",
"\"",
"\"",
",",
"[",
... | // Performs a reachability check. This is not a cached response. | [
"Performs",
"a",
"reachability",
"check",
".",
"This",
"is",
"not",
"a",
"cached",
"response",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/protocol/keybase1/reachability.go#L130-L133 |
160,135 | keybase/client | go/kbfs/libkbfs/state_checker.go | findAllFileBlocks | func (sc *StateChecker) findAllFileBlocks(ctx context.Context,
lState *kbfssync.LockState, ops *folderBranchOps, kmd libkey.KeyMetadata,
file data.Path, blockSizes map[data.BlockPointer]uint32) error {
infos, err := ops.blocks.GetIndirectFileBlockInfos(ctx, lState, kmd, file)
if err != nil {
return err
}
for _, info := range infos {
blockSizes[info.BlockPointer] = info.EncodedSize
}
return nil
} | go | func (sc *StateChecker) findAllFileBlocks(ctx context.Context,
lState *kbfssync.LockState, ops *folderBranchOps, kmd libkey.KeyMetadata,
file data.Path, blockSizes map[data.BlockPointer]uint32) error {
infos, err := ops.blocks.GetIndirectFileBlockInfos(ctx, lState, kmd, file)
if err != nil {
return err
}
for _, info := range infos {
blockSizes[info.BlockPointer] = info.EncodedSize
}
return nil
} | [
"func",
"(",
"sc",
"*",
"StateChecker",
")",
"findAllFileBlocks",
"(",
"ctx",
"context",
".",
"Context",
",",
"lState",
"*",
"kbfssync",
".",
"LockState",
",",
"ops",
"*",
"folderBranchOps",
",",
"kmd",
"libkey",
".",
"KeyMetadata",
",",
"file",
"data",
".... | // findAllFileBlocks adds all file blocks found under this block to
// the blockSizes map, if the given path represents an indirect block. | [
"findAllFileBlocks",
"adds",
"all",
"file",
"blocks",
"found",
"under",
"this",
"block",
"to",
"the",
"blockSizes",
"map",
"if",
"the",
"given",
"path",
"represents",
"an",
"indirect",
"block",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/state_checker.go#L39-L51 |
160,136 | keybase/client | go/kbfs/libkbfs/state_checker.go | findAllBlocksInPath | func (sc *StateChecker) findAllBlocksInPath(ctx context.Context,
lState *kbfssync.LockState, ops *folderBranchOps, kmd libkey.KeyMetadata,
dir data.Path, blockSizes map[data.BlockPointer]uint32) error {
children, err := ops.blocks.GetEntries(ctx, lState, kmd, dir)
if err != nil {
return err
}
err = sc.findAllDirBlocks(ctx, lState, ops, kmd, dir, blockSizes)
if err != nil {
return err
}
for name, de := range children {
if de.Type == data.Sym {
continue
}
blockSizes[de.BlockPointer] = de.EncodedSize
p := dir.ChildPath(name, de.BlockPointer)
if de.Type == data.Dir {
err := sc.findAllBlocksInPath(ctx, lState, ops, kmd, p, blockSizes)
if err != nil {
return err
}
} else {
// If it's a file, check to see if it's indirect.
err := sc.findAllFileBlocks(ctx, lState, ops, kmd, p, blockSizes)
if err != nil {
return err
}
}
}
return nil
} | go | func (sc *StateChecker) findAllBlocksInPath(ctx context.Context,
lState *kbfssync.LockState, ops *folderBranchOps, kmd libkey.KeyMetadata,
dir data.Path, blockSizes map[data.BlockPointer]uint32) error {
children, err := ops.blocks.GetEntries(ctx, lState, kmd, dir)
if err != nil {
return err
}
err = sc.findAllDirBlocks(ctx, lState, ops, kmd, dir, blockSizes)
if err != nil {
return err
}
for name, de := range children {
if de.Type == data.Sym {
continue
}
blockSizes[de.BlockPointer] = de.EncodedSize
p := dir.ChildPath(name, de.BlockPointer)
if de.Type == data.Dir {
err := sc.findAllBlocksInPath(ctx, lState, ops, kmd, p, blockSizes)
if err != nil {
return err
}
} else {
// If it's a file, check to see if it's indirect.
err := sc.findAllFileBlocks(ctx, lState, ops, kmd, p, blockSizes)
if err != nil {
return err
}
}
}
return nil
} | [
"func",
"(",
"sc",
"*",
"StateChecker",
")",
"findAllBlocksInPath",
"(",
"ctx",
"context",
".",
"Context",
",",
"lState",
"*",
"kbfssync",
".",
"LockState",
",",
"ops",
"*",
"folderBranchOps",
",",
"kmd",
"libkey",
".",
"KeyMetadata",
",",
"dir",
"data",
"... | // findAllBlocksInPath adds all blocks found within this directory to
// the blockSizes map, and then recursively checks all
// subdirectories. | [
"findAllBlocksInPath",
"adds",
"all",
"blocks",
"found",
"within",
"this",
"directory",
"to",
"the",
"blockSizes",
"map",
"and",
"then",
"recursively",
"checks",
"all",
"subdirectories",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/state_checker.go#L72-L107 |
160,137 | keybase/client | go/kbfs/libkbfs/disk_block_cache_helper.go | PrefetchStatus | func (dbcm DiskBlockCacheMetadata) PrefetchStatus() PrefetchStatus {
if dbcm.FinishedPrefetch {
return FinishedPrefetch
} else if dbcm.TriggeredPrefetch {
return TriggeredPrefetch
}
return NoPrefetch
} | go | func (dbcm DiskBlockCacheMetadata) PrefetchStatus() PrefetchStatus {
if dbcm.FinishedPrefetch {
return FinishedPrefetch
} else if dbcm.TriggeredPrefetch {
return TriggeredPrefetch
}
return NoPrefetch
} | [
"func",
"(",
"dbcm",
"DiskBlockCacheMetadata",
")",
"PrefetchStatus",
"(",
")",
"PrefetchStatus",
"{",
"if",
"dbcm",
".",
"FinishedPrefetch",
"{",
"return",
"FinishedPrefetch",
"\n",
"}",
"else",
"if",
"dbcm",
".",
"TriggeredPrefetch",
"{",
"return",
"TriggeredPre... | // PrefetchStatus returns the overall prefetch status corresponding to
// this metadata. | [
"PrefetchStatus",
"returns",
"the",
"overall",
"prefetch",
"status",
"corresponding",
"to",
"this",
"metadata",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/disk_block_cache_helper.go#L46-L53 |
160,138 | keybase/client | go/libkb/passphrase_helper.go | Check | func (w *CheckerWrapper) Check(m MetaContext, s string) error {
if w.checker.F(s) {
return nil
}
return errors.New(w.checker.Hint)
} | go | func (w *CheckerWrapper) Check(m MetaContext, s string) error {
if w.checker.F(s) {
return nil
}
return errors.New(w.checker.Hint)
} | [
"func",
"(",
"w",
"*",
"CheckerWrapper",
")",
"Check",
"(",
"m",
"MetaContext",
",",
"s",
"string",
")",
"error",
"{",
"if",
"w",
".",
"checker",
".",
"F",
"(",
"s",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"errors",
".",
"New",
"(",... | // Check s using checker, respond with checker.Hint if check
// fails. | [
"Check",
"s",
"using",
"checker",
"respond",
"with",
"checker",
".",
"Hint",
"if",
"check",
"fails",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/passphrase_helper.go#L195-L200 |
160,139 | keybase/client | go/libkb/passphrase_helper.go | Check | func (p *PaperChecker) Check(m MetaContext, s string) error {
phrase := NewPaperKeyPhrase(s)
// check for empty
if len(phrase.String()) == 0 {
m.Debug("paper phrase is empty")
return PassphraseError{Msg: "Empty paper key. Please try again."}
}
// check for at least PaperKeyWordCountMin words
if phrase.NumWords() < PaperKeyWordCountMin {
return PassphraseError{Msg: "Your paper key should have more words than this. Please double check."}
}
// check for invalid words
invalids := phrase.InvalidWords()
if len(invalids) > 0 {
m.Debug("paper phrase has invalid word(s) in it")
var perr PassphraseError
if len(invalids) > 1 {
perr.Msg = fmt.Sprintf("Please try again. These words are invalid: %s", strings.Join(invalids, ", "))
} else {
perr.Msg = fmt.Sprintf("Please try again. This word is invalid: %s", invalids[0])
}
return perr
}
// check version
version, err := phrase.Version()
if err != nil {
m.Debug("error getting paper key version: %s", err)
// despite the error, just tell the user the paper key is wrong:
return PassphraseError{Msg: "Wrong paper key. Please try again."}
}
if version != PaperKeyVersion {
m.Debug("paper key version mismatch: generated version = %d, libkb version = %d", version, PaperKeyVersion)
return PassphraseError{Msg: "Wrong paper key. Please try again."}
}
return nil
} | go | func (p *PaperChecker) Check(m MetaContext, s string) error {
phrase := NewPaperKeyPhrase(s)
// check for empty
if len(phrase.String()) == 0 {
m.Debug("paper phrase is empty")
return PassphraseError{Msg: "Empty paper key. Please try again."}
}
// check for at least PaperKeyWordCountMin words
if phrase.NumWords() < PaperKeyWordCountMin {
return PassphraseError{Msg: "Your paper key should have more words than this. Please double check."}
}
// check for invalid words
invalids := phrase.InvalidWords()
if len(invalids) > 0 {
m.Debug("paper phrase has invalid word(s) in it")
var perr PassphraseError
if len(invalids) > 1 {
perr.Msg = fmt.Sprintf("Please try again. These words are invalid: %s", strings.Join(invalids, ", "))
} else {
perr.Msg = fmt.Sprintf("Please try again. This word is invalid: %s", invalids[0])
}
return perr
}
// check version
version, err := phrase.Version()
if err != nil {
m.Debug("error getting paper key version: %s", err)
// despite the error, just tell the user the paper key is wrong:
return PassphraseError{Msg: "Wrong paper key. Please try again."}
}
if version != PaperKeyVersion {
m.Debug("paper key version mismatch: generated version = %d, libkb version = %d", version, PaperKeyVersion)
return PassphraseError{Msg: "Wrong paper key. Please try again."}
}
return nil
} | [
"func",
"(",
"p",
"*",
"PaperChecker",
")",
"Check",
"(",
"m",
"MetaContext",
",",
"s",
"string",
")",
"error",
"{",
"phrase",
":=",
"NewPaperKeyPhrase",
"(",
"s",
")",
"\n\n",
"// check for empty",
"if",
"len",
"(",
"phrase",
".",
"String",
"(",
")",
... | // Check a paper key format. Will return a detailed error message
// specific to the problems found in s. | [
"Check",
"a",
"paper",
"key",
"format",
".",
"Will",
"return",
"a",
"detailed",
"error",
"message",
"specific",
"to",
"the",
"problems",
"found",
"in",
"s",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/passphrase_helper.go#L220-L260 |
160,140 | keybase/client | go/libkb/passphrase_login.go | GetTriplesecMaybePrompt | func GetTriplesecMaybePrompt(m MetaContext) (tsec Triplesec, ppgen PassphraseGeneration, err error) {
defer m.Trace("GetTriplesecMaybePrompt", func() error { return err })()
// 1. try cached
m.Debug("| trying cached triplesec")
if tsec, ppgen = m.TriplesecAndGeneration(); tsec != nil && !ppgen.IsNil() {
m.Debug("| cached trieplsec stream ok, using it")
return tsec, ppgen, nil
}
// 2. login and get it
m.Debug("| using full GetPassphraseStreamViaPrompt")
var pps *PassphraseStream
pps, tsec, err = GetPassphraseStreamViaPrompt(m)
if err != nil {
return nil, ppgen, err
}
if pps == nil {
m.Debug("| Got back empty passphrase stream; returning nil")
return nil, ppgen, NewNoTriplesecError()
}
if tsec == nil {
m.Debug("| Got back empty triplesec")
return nil, ppgen, NewNoTriplesecError()
}
ppgen = pps.Generation()
if ppgen.IsNil() {
m.Debug("| Got back a non-nill Triplesec but an invalid ppgen; returning nil")
return nil, ppgen, NewNoTriplesecError()
}
m.Debug("| got non-nil Triplesec back from prompt")
return tsec, ppgen, err
} | go | func GetTriplesecMaybePrompt(m MetaContext) (tsec Triplesec, ppgen PassphraseGeneration, err error) {
defer m.Trace("GetTriplesecMaybePrompt", func() error { return err })()
// 1. try cached
m.Debug("| trying cached triplesec")
if tsec, ppgen = m.TriplesecAndGeneration(); tsec != nil && !ppgen.IsNil() {
m.Debug("| cached trieplsec stream ok, using it")
return tsec, ppgen, nil
}
// 2. login and get it
m.Debug("| using full GetPassphraseStreamViaPrompt")
var pps *PassphraseStream
pps, tsec, err = GetPassphraseStreamViaPrompt(m)
if err != nil {
return nil, ppgen, err
}
if pps == nil {
m.Debug("| Got back empty passphrase stream; returning nil")
return nil, ppgen, NewNoTriplesecError()
}
if tsec == nil {
m.Debug("| Got back empty triplesec")
return nil, ppgen, NewNoTriplesecError()
}
ppgen = pps.Generation()
if ppgen.IsNil() {
m.Debug("| Got back a non-nill Triplesec but an invalid ppgen; returning nil")
return nil, ppgen, NewNoTriplesecError()
}
m.Debug("| got non-nil Triplesec back from prompt")
return tsec, ppgen, err
} | [
"func",
"GetTriplesecMaybePrompt",
"(",
"m",
"MetaContext",
")",
"(",
"tsec",
"Triplesec",
",",
"ppgen",
"PassphraseGeneration",
",",
"err",
"error",
")",
"{",
"defer",
"m",
".",
"Trace",
"(",
"\"",
"\"",
",",
"func",
"(",
")",
"error",
"{",
"return",
"e... | // GetTriplesecMaybePrompt will try to get the user's current triplesec.
// It will either pluck it out of the environment or prompt the user for
// a passphrase if it can't be found. The secret store is of no use here,
// so skip it. Recall that the full passphrase stream isn't stored to
// the secret store, only the bits that encrypt local keys. | [
"GetTriplesecMaybePrompt",
"will",
"try",
"to",
"get",
"the",
"user",
"s",
"current",
"triplesec",
".",
"It",
"will",
"either",
"pluck",
"it",
"out",
"of",
"the",
"environment",
"or",
"prompt",
"the",
"user",
"for",
"a",
"passphrase",
"if",
"it",
"can",
"t... | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/passphrase_login.go#L353-L385 |
160,141 | keybase/client | go/libkb/passphrase_login.go | GetPassphraseStreamViaPrompt | func GetPassphraseStreamViaPrompt(m MetaContext) (pps *PassphraseStream, tsec Triplesec, err error) {
// We have to get the current username before we install the new provisional login context,
// which will shadow the logged in username.
nun := m.CurrentUsername()
defer m.Trace(fmt.Sprintf("GetPassphraseStreamViaPrompt(%s)", nun), func() error { return err })()
m = m.WithNewProvisionalLoginContext()
err = PassphraseLoginPromptThenSecretStore(m, nun.String(), 5, false /* failOnStoreError */)
if err != nil {
return nil, nil, err
}
pps, tsec = m.PassphraseStreamAndTriplesec()
m.CommitProvisionalLogin()
return pps, tsec, nil
} | go | func GetPassphraseStreamViaPrompt(m MetaContext) (pps *PassphraseStream, tsec Triplesec, err error) {
// We have to get the current username before we install the new provisional login context,
// which will shadow the logged in username.
nun := m.CurrentUsername()
defer m.Trace(fmt.Sprintf("GetPassphraseStreamViaPrompt(%s)", nun), func() error { return err })()
m = m.WithNewProvisionalLoginContext()
err = PassphraseLoginPromptThenSecretStore(m, nun.String(), 5, false /* failOnStoreError */)
if err != nil {
return nil, nil, err
}
pps, tsec = m.PassphraseStreamAndTriplesec()
m.CommitProvisionalLogin()
return pps, tsec, nil
} | [
"func",
"GetPassphraseStreamViaPrompt",
"(",
"m",
"MetaContext",
")",
"(",
"pps",
"*",
"PassphraseStream",
",",
"tsec",
"Triplesec",
",",
"err",
"error",
")",
"{",
"// We have to get the current username before we install the new provisional login context,",
"// which will shad... | // GetPassphraseStreamViaPrompt prompts the user for a passphrase and on
// success returns a PassphraseStream and Triplesec derived from the user's
// passphrase. As a side effect, it stores the full LKSec in the secret store. | [
"GetPassphraseStreamViaPrompt",
"prompts",
"the",
"user",
"for",
"a",
"passphrase",
"and",
"on",
"success",
"returns",
"a",
"PassphraseStream",
"and",
"Triplesec",
"derived",
"from",
"the",
"user",
"s",
"passphrase",
".",
"As",
"a",
"side",
"effect",
"it",
"stor... | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/passphrase_login.go#L390-L406 |
160,142 | keybase/client | go/libkb/passphrase_login.go | GetPassphraseStreamViaPromptInLoginContext | func GetPassphraseStreamViaPromptInLoginContext(m MetaContext) (pps *PassphraseStream, err error) {
defer m.Trace("GetPassphraseStreamViaPromptInLoginContext", func() error { return err })()
if pps = m.PassphraseStream(); pps != nil {
return pps, nil
}
nun := m.CurrentUsername()
if nun.IsNil() {
return nil, NewNoUsernameError()
}
if err = PassphraseLoginPrompt(m, nun.String(), 5); err != nil {
return nil, err
}
return m.PassphraseStream(), nil
} | go | func GetPassphraseStreamViaPromptInLoginContext(m MetaContext) (pps *PassphraseStream, err error) {
defer m.Trace("GetPassphraseStreamViaPromptInLoginContext", func() error { return err })()
if pps = m.PassphraseStream(); pps != nil {
return pps, nil
}
nun := m.CurrentUsername()
if nun.IsNil() {
return nil, NewNoUsernameError()
}
if err = PassphraseLoginPrompt(m, nun.String(), 5); err != nil {
return nil, err
}
return m.PassphraseStream(), nil
} | [
"func",
"GetPassphraseStreamViaPromptInLoginContext",
"(",
"m",
"MetaContext",
")",
"(",
"pps",
"*",
"PassphraseStream",
",",
"err",
"error",
")",
"{",
"defer",
"m",
".",
"Trace",
"(",
"\"",
"\"",
",",
"func",
"(",
")",
"error",
"{",
"return",
"err",
"}",
... | // GetFullPassphraseStreamViaPrompt gets the user's passphrase stream either cached from the
// LoginContext or from the prompt. It doesn't involve the secret store at all, since
// the full passphrase stream isn't stored in the secret store. And also it doesn't
// write the secret store because this function is called right before the user
// changes to a new passphrase, so what's the point. It's assumed that the login context is
// set to non-nil by the caller. | [
"GetFullPassphraseStreamViaPrompt",
"gets",
"the",
"user",
"s",
"passphrase",
"stream",
"either",
"cached",
"from",
"the",
"LoginContext",
"or",
"from",
"the",
"prompt",
".",
"It",
"doesn",
"t",
"involve",
"the",
"secret",
"store",
"at",
"all",
"since",
"the",
... | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/passphrase_login.go#L414-L427 |
160,143 | keybase/client | go/libkb/passphrase_login.go | VerifyPassphraseGetStreamInLoginContext | func VerifyPassphraseGetStreamInLoginContext(m MetaContext, passphrase string) (pps *PassphraseStream, err error) {
defer m.Trace("VerifyPassphraseGetStreamInLoginContext", func() error { return err })()
nun := m.CurrentUsername()
if nun.IsNil() {
return nil, NewNoUsernameError()
}
if err = PassphraseLoginNoPrompt(m, nun.String(), passphrase); err != nil {
return nil, err
}
return m.PassphraseStream(), nil
} | go | func VerifyPassphraseGetStreamInLoginContext(m MetaContext, passphrase string) (pps *PassphraseStream, err error) {
defer m.Trace("VerifyPassphraseGetStreamInLoginContext", func() error { return err })()
nun := m.CurrentUsername()
if nun.IsNil() {
return nil, NewNoUsernameError()
}
if err = PassphraseLoginNoPrompt(m, nun.String(), passphrase); err != nil {
return nil, err
}
return m.PassphraseStream(), nil
} | [
"func",
"VerifyPassphraseGetStreamInLoginContext",
"(",
"m",
"MetaContext",
",",
"passphrase",
"string",
")",
"(",
"pps",
"*",
"PassphraseStream",
",",
"err",
"error",
")",
"{",
"defer",
"m",
".",
"Trace",
"(",
"\"",
"\"",
",",
"func",
"(",
")",
"error",
"... | // VerifyPassphraseGetFullStream verifies the current passphrase is a correct login
// and if so, will return a full passphrase stream derived from it. Assumes the caller
// made a non-nil LoginContext for us to operate in. | [
"VerifyPassphraseGetFullStream",
"verifies",
"the",
"current",
"passphrase",
"is",
"a",
"correct",
"login",
"and",
"if",
"so",
"will",
"return",
"a",
"full",
"passphrase",
"stream",
"derived",
"from",
"it",
".",
"Assumes",
"the",
"caller",
"made",
"a",
"non",
... | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/passphrase_login.go#L432-L442 |
160,144 | keybase/client | go/libkb/passphrase_login.go | VerifyPassphraseForLoggedInUser | func VerifyPassphraseForLoggedInUser(m MetaContext, pp string) (pps *PassphraseStream, err error) {
defer m.Trace("VerifyPassphraseForLoggedInUser", func() error { return err })()
uv, un := m.ActiveDevice().GetUsernameAndUserVersionIfValid(m)
if uv.IsNil() {
return nil, NewLoginRequiredError("for VerifyPassphraseForLoggedInUser")
}
m = m.WithNewProvisionalLoginContextForUserVersionAndUsername(uv, un)
pps, err = VerifyPassphraseGetStreamInLoginContext(m, pp)
return pps, err
} | go | func VerifyPassphraseForLoggedInUser(m MetaContext, pp string) (pps *PassphraseStream, err error) {
defer m.Trace("VerifyPassphraseForLoggedInUser", func() error { return err })()
uv, un := m.ActiveDevice().GetUsernameAndUserVersionIfValid(m)
if uv.IsNil() {
return nil, NewLoginRequiredError("for VerifyPassphraseForLoggedInUser")
}
m = m.WithNewProvisionalLoginContextForUserVersionAndUsername(uv, un)
pps, err = VerifyPassphraseGetStreamInLoginContext(m, pp)
return pps, err
} | [
"func",
"VerifyPassphraseForLoggedInUser",
"(",
"m",
"MetaContext",
",",
"pp",
"string",
")",
"(",
"pps",
"*",
"PassphraseStream",
",",
"err",
"error",
")",
"{",
"defer",
"m",
".",
"Trace",
"(",
"\"",
"\"",
",",
"func",
"(",
")",
"error",
"{",
"return",
... | // VerifyPassphraseForLoggedInUser verifies that the current passphrase is correct for the logged
// in user, returning nil if correct, and an error if not. Only used in tests right now, but
// it's fine to use in production code if it seems appropriate. | [
"VerifyPassphraseForLoggedInUser",
"verifies",
"that",
"the",
"current",
"passphrase",
"is",
"correct",
"for",
"the",
"logged",
"in",
"user",
"returning",
"nil",
"if",
"correct",
"and",
"an",
"error",
"if",
"not",
".",
"Only",
"used",
"in",
"tests",
"right",
"... | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/passphrase_login.go#L447-L456 |
160,145 | keybase/client | go/libkb/passphrase_login.go | ComputeLoginPackage2 | func ComputeLoginPackage2(m MetaContext, pps *PassphraseStream) (ret PDPKALoginPackage, err error) {
defer m.Trace("ComputeLoginPackage2", func() error { return err })()
var ls *LoginSession
if m.LoginContext() != nil {
ls = m.LoginContext().LoginSession()
}
if ls == nil {
ls, err = pplGetLoginSession(m, m.CurrentUsername().String())
if err != nil {
return ret, err
}
}
var loginSessionRaw []byte
loginSessionRaw, err = ls.Session()
if err != nil {
return ret, err
}
return computeLoginPackageFromUID(m.CurrentUID(), pps, loginSessionRaw)
} | go | func ComputeLoginPackage2(m MetaContext, pps *PassphraseStream) (ret PDPKALoginPackage, err error) {
defer m.Trace("ComputeLoginPackage2", func() error { return err })()
var ls *LoginSession
if m.LoginContext() != nil {
ls = m.LoginContext().LoginSession()
}
if ls == nil {
ls, err = pplGetLoginSession(m, m.CurrentUsername().String())
if err != nil {
return ret, err
}
}
var loginSessionRaw []byte
loginSessionRaw, err = ls.Session()
if err != nil {
return ret, err
}
return computeLoginPackageFromUID(m.CurrentUID(), pps, loginSessionRaw)
} | [
"func",
"ComputeLoginPackage2",
"(",
"m",
"MetaContext",
",",
"pps",
"*",
"PassphraseStream",
")",
"(",
"ret",
"PDPKALoginPackage",
",",
"err",
"error",
")",
"{",
"defer",
"m",
".",
"Trace",
"(",
"\"",
"\"",
",",
"func",
"(",
")",
"error",
"{",
"return",... | // ComputeLoginPackage2 computes the login package for the given UID as dictated by
// the context. It assumes that a passphrase stream has already been loaded. A LoginSession
// is optional. If not available, a new one is requested. Eventually we will kill ComputeLoginPackage
// and rename this to that. | [
"ComputeLoginPackage2",
"computes",
"the",
"login",
"package",
"for",
"the",
"given",
"UID",
"as",
"dictated",
"by",
"the",
"context",
".",
"It",
"assumes",
"that",
"a",
"passphrase",
"stream",
"has",
"already",
"been",
"loaded",
".",
"A",
"LoginSession",
"is"... | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/passphrase_login.go#L462-L481 |
160,146 | keybase/client | go/libkb/passphrase_login.go | UnverifiedPassphraseStream | func UnverifiedPassphraseStream(m MetaContext, uid keybase1.UID, passphrase string) (tsec Triplesec, ret *PassphraseStream, err error) {
var salt []byte
if lctx := m.LoginContext(); lctx != nil && lctx.GetUID().Equal(uid) {
salt = lctx.Salt()
}
if salt == nil {
salt, err = LookupSaltForUID(m, uid)
if err != nil {
return nil, nil, err
}
}
return StretchPassphrase(m.G(), passphrase, salt)
} | go | func UnverifiedPassphraseStream(m MetaContext, uid keybase1.UID, passphrase string) (tsec Triplesec, ret *PassphraseStream, err error) {
var salt []byte
if lctx := m.LoginContext(); lctx != nil && lctx.GetUID().Equal(uid) {
salt = lctx.Salt()
}
if salt == nil {
salt, err = LookupSaltForUID(m, uid)
if err != nil {
return nil, nil, err
}
}
return StretchPassphrase(m.G(), passphrase, salt)
} | [
"func",
"UnverifiedPassphraseStream",
"(",
"m",
"MetaContext",
",",
"uid",
"keybase1",
".",
"UID",
",",
"passphrase",
"string",
")",
"(",
"tsec",
"Triplesec",
",",
"ret",
"*",
"PassphraseStream",
",",
"err",
"error",
")",
"{",
"var",
"salt",
"[",
"]",
"byt... | // UnverifiedPassphraseStream takes a passphrase as a parameter and
// also the salt from the Account and computes a Triplesec and
// a passphrase stream. It's not verified through a Login. | [
"UnverifiedPassphraseStream",
"takes",
"a",
"passphrase",
"as",
"a",
"parameter",
"and",
"also",
"the",
"salt",
"from",
"the",
"Account",
"and",
"computes",
"a",
"Triplesec",
"and",
"a",
"passphrase",
"stream",
".",
"It",
"s",
"not",
"verified",
"through",
"a"... | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/passphrase_login.go#L486-L498 |
160,147 | keybase/client | go/engine/puk_roll.go | NewPerUserKeyRoll | func NewPerUserKeyRoll(g *libkb.GlobalContext, args *PerUserKeyRollArgs) *PerUserKeyRoll {
return &PerUserKeyRoll{
args: args,
Contextified: libkb.NewContextified(g),
}
} | go | func NewPerUserKeyRoll(g *libkb.GlobalContext, args *PerUserKeyRollArgs) *PerUserKeyRoll {
return &PerUserKeyRoll{
args: args,
Contextified: libkb.NewContextified(g),
}
} | [
"func",
"NewPerUserKeyRoll",
"(",
"g",
"*",
"libkb",
".",
"GlobalContext",
",",
"args",
"*",
"PerUserKeyRollArgs",
")",
"*",
"PerUserKeyRoll",
"{",
"return",
"&",
"PerUserKeyRoll",
"{",
"args",
":",
"args",
",",
"Contextified",
":",
"libkb",
".",
"NewContextif... | // NewPerUserKeyRoll creates a PerUserKeyRoll engine. | [
"NewPerUserKeyRoll",
"creates",
"a",
"PerUserKeyRoll",
"engine",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/engine/puk_roll.go#L27-L32 |
160,148 | keybase/client | go/engine/puk_roll.go | getPukReceivers | func (e *PerUserKeyRoll) getPukReceivers(mctx libkb.MetaContext, meUPAK *keybase1.UserPlusAllKeys) (res []libkb.NaclDHKeyPair, err error) {
for _, dk := range meUPAK.Base.DeviceKeys {
if dk.IsSibkey == false && !dk.IsRevoked {
receiver, err := libkb.ImportNaclDHKeyPairFromHex(dk.KID.String())
if err != nil {
return res, err
}
res = append(res, receiver)
}
}
return res, nil
} | go | func (e *PerUserKeyRoll) getPukReceivers(mctx libkb.MetaContext, meUPAK *keybase1.UserPlusAllKeys) (res []libkb.NaclDHKeyPair, err error) {
for _, dk := range meUPAK.Base.DeviceKeys {
if dk.IsSibkey == false && !dk.IsRevoked {
receiver, err := libkb.ImportNaclDHKeyPairFromHex(dk.KID.String())
if err != nil {
return res, err
}
res = append(res, receiver)
}
}
return res, nil
} | [
"func",
"(",
"e",
"*",
"PerUserKeyRoll",
")",
"getPukReceivers",
"(",
"mctx",
"libkb",
".",
"MetaContext",
",",
"meUPAK",
"*",
"keybase1",
".",
"UserPlusAllKeys",
")",
"(",
"res",
"[",
"]",
"libkb",
".",
"NaclDHKeyPair",
",",
"err",
"error",
")",
"{",
"f... | // Get the receivers of the new per-user-key boxes.
// Includes all the user's device subkeys. | [
"Get",
"the",
"receivers",
"of",
"the",
"new",
"per",
"-",
"user",
"-",
"key",
"boxes",
".",
"Includes",
"all",
"the",
"user",
"s",
"device",
"subkeys",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/engine/puk_roll.go#L211-L222 |
160,149 | keybase/client | go/kbfs/libkbfs/disk_block_metadata_store.go | newDiskBlockMetadataStore | func newDiskBlockMetadataStore(
config diskBlockMetadataStoreConfig) (BlockMetadataStore, error) {
log := config.MakeLogger("BMS")
db, err := openVersionedLevelDB(log, config.StorageRoot(),
blockMetadataFolderName, currentBlockMetadataStoreVersion, blockMetadataDbFilename)
if err != nil {
return nil, err
}
return &diskBlockMetadataStore{
log: log,
config: config,
hitMeter: NewCountMeter(),
missMeter: NewCountMeter(),
putMeter: NewCountMeter(),
db: db,
shutdownCh: make(chan struct{}),
}, err
} | go | func newDiskBlockMetadataStore(
config diskBlockMetadataStoreConfig) (BlockMetadataStore, error) {
log := config.MakeLogger("BMS")
db, err := openVersionedLevelDB(log, config.StorageRoot(),
blockMetadataFolderName, currentBlockMetadataStoreVersion, blockMetadataDbFilename)
if err != nil {
return nil, err
}
return &diskBlockMetadataStore{
log: log,
config: config,
hitMeter: NewCountMeter(),
missMeter: NewCountMeter(),
putMeter: NewCountMeter(),
db: db,
shutdownCh: make(chan struct{}),
}, err
} | [
"func",
"newDiskBlockMetadataStore",
"(",
"config",
"diskBlockMetadataStoreConfig",
")",
"(",
"BlockMetadataStore",
",",
"error",
")",
"{",
"log",
":=",
"config",
".",
"MakeLogger",
"(",
"\"",
"\"",
")",
"\n",
"db",
",",
"err",
":=",
"openVersionedLevelDB",
"(",... | // newDiskBlockMetadataStore creates a new disk BlockMetadata storage. | [
"newDiskBlockMetadataStore",
"creates",
"a",
"new",
"disk",
"BlockMetadata",
"storage",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/disk_block_metadata_store.go#L63-L80 |
160,150 | keybase/client | go/kbfs/libkbfs/disk_block_metadata_store.go | Shutdown | func (s *diskBlockMetadataStore) Shutdown() {
s.log.Debug("Shutting down diskBlockMetadataStore")
s.lock.Lock()
defer s.lock.Unlock()
// shutdownCh has to be checked under lock, otherwise we can race.
select {
case <-s.shutdownCh:
s.log.Warning("Shutdown called more than once")
default:
}
close(s.shutdownCh)
if s.db == nil {
return
}
s.db.Close()
s.db = nil
s.hitMeter.Shutdown()
s.missMeter.Shutdown()
s.putMeter.Shutdown()
} | go | func (s *diskBlockMetadataStore) Shutdown() {
s.log.Debug("Shutting down diskBlockMetadataStore")
s.lock.Lock()
defer s.lock.Unlock()
// shutdownCh has to be checked under lock, otherwise we can race.
select {
case <-s.shutdownCh:
s.log.Warning("Shutdown called more than once")
default:
}
close(s.shutdownCh)
if s.db == nil {
return
}
s.db.Close()
s.db = nil
s.hitMeter.Shutdown()
s.missMeter.Shutdown()
s.putMeter.Shutdown()
} | [
"func",
"(",
"s",
"*",
"diskBlockMetadataStore",
")",
"Shutdown",
"(",
")",
"{",
"s",
".",
"log",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"s",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",... | // Shutdown shuts done this storae. | [
"Shutdown",
"shuts",
"done",
"this",
"storae",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/disk_block_metadata_store.go#L83-L102 |
160,151 | keybase/client | go/kbfs/libkbfs/disk_block_metadata_store.go | GetMetadata | func (s *diskBlockMetadataStore) GetMetadata(ctx context.Context,
blockID kbfsblock.ID) (value BlockMetadataValue, err error) {
s.lock.RLock()
defer s.lock.RUnlock()
select {
case <-s.shutdownCh:
return BlockMetadataValue{}, ErrBlockMetadataStoreShutdown{}
default:
}
encoded, err := s.db.GetWithMeter(blockID.Bytes(), s.hitMeter, s.missMeter)
switch errors.Cause(err) {
case ldberrors.ErrNotFound:
return BlockMetadataValue{}, err
case nil:
if err = s.config.Codec().Decode(encoded, &value); err != nil {
s.log.CWarningf(ctx, "decoding block metadata error: %v", err)
return BlockMetadataValue{}, ldberrors.ErrNotFound
}
return value, nil
default:
s.log.CWarningf(ctx, "GetMetadata error: %v", err)
return BlockMetadataValue{}, ldberrors.ErrNotFound
}
} | go | func (s *diskBlockMetadataStore) GetMetadata(ctx context.Context,
blockID kbfsblock.ID) (value BlockMetadataValue, err error) {
s.lock.RLock()
defer s.lock.RUnlock()
select {
case <-s.shutdownCh:
return BlockMetadataValue{}, ErrBlockMetadataStoreShutdown{}
default:
}
encoded, err := s.db.GetWithMeter(blockID.Bytes(), s.hitMeter, s.missMeter)
switch errors.Cause(err) {
case ldberrors.ErrNotFound:
return BlockMetadataValue{}, err
case nil:
if err = s.config.Codec().Decode(encoded, &value); err != nil {
s.log.CWarningf(ctx, "decoding block metadata error: %v", err)
return BlockMetadataValue{}, ldberrors.ErrNotFound
}
return value, nil
default:
s.log.CWarningf(ctx, "GetMetadata error: %v", err)
return BlockMetadataValue{}, ldberrors.ErrNotFound
}
} | [
"func",
"(",
"s",
"*",
"diskBlockMetadataStore",
")",
"GetMetadata",
"(",
"ctx",
"context",
".",
"Context",
",",
"blockID",
"kbfsblock",
".",
"ID",
")",
"(",
"value",
"BlockMetadataValue",
",",
"err",
"error",
")",
"{",
"s",
".",
"lock",
".",
"RLock",
"(... | // GetMetadata implements the BlockMetadataStore interface. | [
"GetMetadata",
"implements",
"the",
"BlockMetadataStore",
"interface",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/disk_block_metadata_store.go#L116-L141 |
160,152 | keybase/client | go/kbfs/libkbfs/disk_block_metadata_store.go | UpdateMetadata | func (s *diskBlockMetadataStore) UpdateMetadata(ctx context.Context,
blockID kbfsblock.ID, updater BlockMetadataUpdater) error {
bid := blockID.Bytes()
s.lock.Lock()
defer s.lock.Unlock()
select {
case <-s.shutdownCh:
return ErrBlockMetadataStoreShutdown{}
default:
}
var value BlockMetadataValue
encoded, err := s.db.Get(bid, nil)
switch errors.Cause(err) {
case ldberrors.ErrNotFound:
case nil:
if err = s.config.Codec().Decode(encoded, &value); err != nil {
s.log.CWarningf(ctx, "decoding block metadata error: %v", err)
}
default:
s.log.CWarningf(ctx, "GetMetadata error: %v", err)
}
if err = updater(&value); err != nil {
return err
}
if encoded, err = s.config.Codec().Encode(value); err != nil {
return err
}
return s.db.PutWithMeter(bid, encoded, s.putMeter)
} | go | func (s *diskBlockMetadataStore) UpdateMetadata(ctx context.Context,
blockID kbfsblock.ID, updater BlockMetadataUpdater) error {
bid := blockID.Bytes()
s.lock.Lock()
defer s.lock.Unlock()
select {
case <-s.shutdownCh:
return ErrBlockMetadataStoreShutdown{}
default:
}
var value BlockMetadataValue
encoded, err := s.db.Get(bid, nil)
switch errors.Cause(err) {
case ldberrors.ErrNotFound:
case nil:
if err = s.config.Codec().Decode(encoded, &value); err != nil {
s.log.CWarningf(ctx, "decoding block metadata error: %v", err)
}
default:
s.log.CWarningf(ctx, "GetMetadata error: %v", err)
}
if err = updater(&value); err != nil {
return err
}
if encoded, err = s.config.Codec().Encode(value); err != nil {
return err
}
return s.db.PutWithMeter(bid, encoded, s.putMeter)
} | [
"func",
"(",
"s",
"*",
"diskBlockMetadataStore",
")",
"UpdateMetadata",
"(",
"ctx",
"context",
".",
"Context",
",",
"blockID",
"kbfsblock",
".",
"ID",
",",
"updater",
"BlockMetadataUpdater",
")",
"error",
"{",
"bid",
":=",
"blockID",
".",
"Bytes",
"(",
")",
... | // UpdateMetadata implements the BlockMetadataStore interface. | [
"UpdateMetadata",
"implements",
"the",
"BlockMetadataStore",
"interface",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/disk_block_metadata_store.go#L144-L177 |
160,153 | keybase/client | go/kbfs/libkbfs/disk_block_metadata_store.go | NewXattrStoreFromBlockMetadataStore | func NewXattrStoreFromBlockMetadataStore(store BlockMetadataStore) XattrStore {
return xattrStore{
store: store,
hitMeter: NewCountMeter(),
missMeter: NewCountMeter(),
putMeter: NewCountMeter(),
}
} | go | func NewXattrStoreFromBlockMetadataStore(store BlockMetadataStore) XattrStore {
return xattrStore{
store: store,
hitMeter: NewCountMeter(),
missMeter: NewCountMeter(),
putMeter: NewCountMeter(),
}
} | [
"func",
"NewXattrStoreFromBlockMetadataStore",
"(",
"store",
"BlockMetadataStore",
")",
"XattrStore",
"{",
"return",
"xattrStore",
"{",
"store",
":",
"store",
",",
"hitMeter",
":",
"NewCountMeter",
"(",
")",
",",
"missMeter",
":",
"NewCountMeter",
"(",
")",
",",
... | // NewXattrStoreFromBlockMetadataStore returns a XattrStore which is a wrapper
// around the passed in store. | [
"NewXattrStoreFromBlockMetadataStore",
"returns",
"a",
"XattrStore",
"which",
"is",
"a",
"wrapper",
"around",
"the",
"passed",
"in",
"store",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/disk_block_metadata_store.go#L192-L199 |
160,154 | keybase/client | go/kbfs/libkbfs/disk_block_metadata_store.go | GetXattr | func (s xattrStore) GetXattr(ctx context.Context,
blockID kbfsblock.ID, xattrType XattrType) ([]byte, error) {
blockMetadata, err := s.store.GetMetadata(ctx, blockID)
switch errors.Cause(err) {
case ldberrors.ErrNotFound:
s.missMeter.Mark(1)
return nil, err
case nil:
default:
return nil, err
}
v, ok := blockMetadata.Xattr[xattrType]
if !ok {
s.missMeter.Mark(1)
return nil, ldberrors.ErrNotFound
}
s.hitMeter.Mark(1)
return v, nil
} | go | func (s xattrStore) GetXattr(ctx context.Context,
blockID kbfsblock.ID, xattrType XattrType) ([]byte, error) {
blockMetadata, err := s.store.GetMetadata(ctx, blockID)
switch errors.Cause(err) {
case ldberrors.ErrNotFound:
s.missMeter.Mark(1)
return nil, err
case nil:
default:
return nil, err
}
v, ok := blockMetadata.Xattr[xattrType]
if !ok {
s.missMeter.Mark(1)
return nil, ldberrors.ErrNotFound
}
s.hitMeter.Mark(1)
return v, nil
} | [
"func",
"(",
"s",
"xattrStore",
")",
"GetXattr",
"(",
"ctx",
"context",
".",
"Context",
",",
"blockID",
"kbfsblock",
".",
"ID",
",",
"xattrType",
"XattrType",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"blockMetadata",
",",
"err",
":=",
"s",
... | // GetXattr implements the XattrStore interface. | [
"GetXattr",
"implements",
"the",
"XattrStore",
"interface",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/disk_block_metadata_store.go#L204-L224 |
160,155 | keybase/client | go/kbfs/libkbfs/disk_block_metadata_store.go | SetXattr | func (s xattrStore) SetXattr(ctx context.Context,
blockID kbfsblock.ID, xattrType XattrType, xattrValue []byte) (err error) {
if err = s.store.UpdateMetadata(ctx, blockID,
func(v *BlockMetadataValue) error {
if v.Xattr == nil {
v.Xattr = make(map[XattrType][]byte)
}
v.Xattr[xattrType] = xattrValue
return nil
}); err != nil {
return err
}
s.putMeter.Mark(1)
return nil
} | go | func (s xattrStore) SetXattr(ctx context.Context,
blockID kbfsblock.ID, xattrType XattrType, xattrValue []byte) (err error) {
if err = s.store.UpdateMetadata(ctx, blockID,
func(v *BlockMetadataValue) error {
if v.Xattr == nil {
v.Xattr = make(map[XattrType][]byte)
}
v.Xattr[xattrType] = xattrValue
return nil
}); err != nil {
return err
}
s.putMeter.Mark(1)
return nil
} | [
"func",
"(",
"s",
"xattrStore",
")",
"SetXattr",
"(",
"ctx",
"context",
".",
"Context",
",",
"blockID",
"kbfsblock",
".",
"ID",
",",
"xattrType",
"XattrType",
",",
"xattrValue",
"[",
"]",
"byte",
")",
"(",
"err",
"error",
")",
"{",
"if",
"err",
"=",
... | // SetXattr implements the XattrStore interface. | [
"SetXattr",
"implements",
"the",
"XattrStore",
"interface",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/disk_block_metadata_store.go#L227-L242 |
160,156 | keybase/client | go/kbfs/libkbfs/disk_block_metadata_store.go | GetMetadata | func (NoopBlockMetadataStore) GetMetadata(ctx context.Context,
blockID kbfsblock.ID) (value BlockMetadataValue, err error) {
return BlockMetadataValue{}, ldberrors.ErrNotFound
} | go | func (NoopBlockMetadataStore) GetMetadata(ctx context.Context,
blockID kbfsblock.ID) (value BlockMetadataValue, err error) {
return BlockMetadataValue{}, ldberrors.ErrNotFound
} | [
"func",
"(",
"NoopBlockMetadataStore",
")",
"GetMetadata",
"(",
"ctx",
"context",
".",
"Context",
",",
"blockID",
"kbfsblock",
".",
"ID",
")",
"(",
"value",
"BlockMetadataValue",
",",
"err",
"error",
")",
"{",
"return",
"BlockMetadataValue",
"{",
"}",
",",
"... | // GetMetadata always returns ldberrors.ErrNotFound. | [
"GetMetadata",
"always",
"returns",
"ldberrors",
".",
"ErrNotFound",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/disk_block_metadata_store.go#L251-L254 |
160,157 | keybase/client | go/kbfs/libkbfs/disk_block_metadata_store.go | UpdateMetadata | func (NoopBlockMetadataStore) UpdateMetadata(ctx context.Context,
blockID kbfsblock.ID, updater BlockMetadataUpdater) error {
return nil
} | go | func (NoopBlockMetadataStore) UpdateMetadata(ctx context.Context,
blockID kbfsblock.ID, updater BlockMetadataUpdater) error {
return nil
} | [
"func",
"(",
"NoopBlockMetadataStore",
")",
"UpdateMetadata",
"(",
"ctx",
"context",
".",
"Context",
",",
"blockID",
"kbfsblock",
".",
"ID",
",",
"updater",
"BlockMetadataUpdater",
")",
"error",
"{",
"return",
"nil",
"\n",
"}"
] | // UpdateMetadata returns nil error but does nothing. | [
"UpdateMetadata",
"returns",
"nil",
"error",
"but",
"does",
"nothing",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/disk_block_metadata_store.go#L257-L260 |
160,158 | keybase/client | go/kbfs/libkbfs/crypto_client_rpc.go | NewCryptoClientRPC | func NewCryptoClientRPC(config Config, kbCtx Context) *CryptoClientRPC {
log := config.MakeLogger("")
deferLog := log.CloneWithAddedDepth(1)
c := &CryptoClientRPC{
CryptoClient: CryptoClient{
CryptoCommon: MakeCryptoCommon(config.Codec(), config),
log: log,
deferLog: deferLog,
},
config: config,
}
conn := NewSharedKeybaseConnection(kbCtx, config, c)
c.CryptoClient.client = keybase1.CryptoClient{Cli: conn.GetClient()}
c.CryptoClient.teamsClient = keybase1.TeamsClient{Cli: conn.GetClient()}
c.CryptoClient.shutdownFn = conn.Shutdown
return c
} | go | func NewCryptoClientRPC(config Config, kbCtx Context) *CryptoClientRPC {
log := config.MakeLogger("")
deferLog := log.CloneWithAddedDepth(1)
c := &CryptoClientRPC{
CryptoClient: CryptoClient{
CryptoCommon: MakeCryptoCommon(config.Codec(), config),
log: log,
deferLog: deferLog,
},
config: config,
}
conn := NewSharedKeybaseConnection(kbCtx, config, c)
c.CryptoClient.client = keybase1.CryptoClient{Cli: conn.GetClient()}
c.CryptoClient.teamsClient = keybase1.TeamsClient{Cli: conn.GetClient()}
c.CryptoClient.shutdownFn = conn.Shutdown
return c
} | [
"func",
"NewCryptoClientRPC",
"(",
"config",
"Config",
",",
"kbCtx",
"Context",
")",
"*",
"CryptoClientRPC",
"{",
"log",
":=",
"config",
".",
"MakeLogger",
"(",
"\"",
"\"",
")",
"\n",
"deferLog",
":=",
"log",
".",
"CloneWithAddedDepth",
"(",
"1",
")",
"\n"... | // NewCryptoClientRPC constructs a new RPC based Crypto implementation. | [
"NewCryptoClientRPC",
"constructs",
"a",
"new",
"RPC",
"based",
"Crypto",
"implementation",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/crypto_client_rpc.go#L27-L43 |
160,159 | keybase/client | go/kbfs/libkbfs/crypto_client_rpc.go | newCryptoClientWithClient | func newCryptoClientWithClient(codec kbfscodec.Codec, log logger.Logger, client rpc.GenericClient) *CryptoClientRPC {
deferLog := log.CloneWithAddedDepth(1)
return &CryptoClientRPC{
CryptoClient: CryptoClient{
CryptoCommon: MakeCryptoCommon(codec, nil),
log: log,
deferLog: deferLog,
client: keybase1.CryptoClient{Cli: client},
teamsClient: keybase1.TeamsClient{Cli: client},
},
}
} | go | func newCryptoClientWithClient(codec kbfscodec.Codec, log logger.Logger, client rpc.GenericClient) *CryptoClientRPC {
deferLog := log.CloneWithAddedDepth(1)
return &CryptoClientRPC{
CryptoClient: CryptoClient{
CryptoCommon: MakeCryptoCommon(codec, nil),
log: log,
deferLog: deferLog,
client: keybase1.CryptoClient{Cli: client},
teamsClient: keybase1.TeamsClient{Cli: client},
},
}
} | [
"func",
"newCryptoClientWithClient",
"(",
"codec",
"kbfscodec",
".",
"Codec",
",",
"log",
"logger",
".",
"Logger",
",",
"client",
"rpc",
".",
"GenericClient",
")",
"*",
"CryptoClientRPC",
"{",
"deferLog",
":=",
"log",
".",
"CloneWithAddedDepth",
"(",
"1",
")",... | // newCryptoClientWithClient should only be used for testing. | [
"newCryptoClientWithClient",
"should",
"only",
"be",
"used",
"for",
"testing",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/crypto_client_rpc.go#L46-L57 |
160,160 | keybase/client | go/stellar/util.go | NewOwnAccountLookupCache | func NewOwnAccountLookupCache(mctx libkb.MetaContext) OwnAccountLookupCache {
c := &ownAccountLookupCacheImpl{
accounts: make(map[stellar1.AccountID]*string),
}
c.Lock()
go c.fetch(mctx)
return c
} | go | func NewOwnAccountLookupCache(mctx libkb.MetaContext) OwnAccountLookupCache {
c := &ownAccountLookupCacheImpl{
accounts: make(map[stellar1.AccountID]*string),
}
c.Lock()
go c.fetch(mctx)
return c
} | [
"func",
"NewOwnAccountLookupCache",
"(",
"mctx",
"libkb",
".",
"MetaContext",
")",
"OwnAccountLookupCache",
"{",
"c",
":=",
"&",
"ownAccountLookupCacheImpl",
"{",
"accounts",
":",
"make",
"(",
"map",
"[",
"stellar1",
".",
"AccountID",
"]",
"*",
"string",
")",
... | // NewOwnAccountLookupCache fetches the list of accounts in the background and stores them. | [
"NewOwnAccountLookupCache",
"fetches",
"the",
"list",
"of",
"accounts",
"in",
"the",
"background",
"and",
"stores",
"them",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/stellar/util.go#L62-L69 |
160,161 | keybase/client | go/stellar/util.go | fetch | func (c *ownAccountLookupCacheImpl) fetch(mctx libkb.MetaContext) {
go func() {
mc := mctx.BackgroundWithLogTags()
defer c.Unlock()
bundle, err := remote.FetchSecretlessBundle(mc)
c.loadErr = err
if err != nil {
return
}
for _, account := range bundle.Accounts {
name := account.Name
c.accounts[account.AccountID] = &name
}
}()
} | go | func (c *ownAccountLookupCacheImpl) fetch(mctx libkb.MetaContext) {
go func() {
mc := mctx.BackgroundWithLogTags()
defer c.Unlock()
bundle, err := remote.FetchSecretlessBundle(mc)
c.loadErr = err
if err != nil {
return
}
for _, account := range bundle.Accounts {
name := account.Name
c.accounts[account.AccountID] = &name
}
}()
} | [
"func",
"(",
"c",
"*",
"ownAccountLookupCacheImpl",
")",
"fetch",
"(",
"mctx",
"libkb",
".",
"MetaContext",
")",
"{",
"go",
"func",
"(",
")",
"{",
"mc",
":=",
"mctx",
".",
"BackgroundWithLogTags",
"(",
")",
"\n",
"defer",
"c",
".",
"Unlock",
"(",
")",
... | // Fetch populates the cache in the background. | [
"Fetch",
"populates",
"the",
"cache",
"in",
"the",
"background",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/stellar/util.go#L72-L86 |
160,162 | keybase/client | go/stellar/util.go | OwnAccount | func (c *ownAccountLookupCacheImpl) OwnAccount(ctx context.Context, accountID stellar1.AccountID) (own bool, accountName string, err error) {
c.RLock()
defer c.RLock()
if c.loadErr != nil {
return false, "", c.loadErr
}
name := c.accounts[accountID]
if name == nil {
return false, "", nil
}
return true, *name, nil
} | go | func (c *ownAccountLookupCacheImpl) OwnAccount(ctx context.Context, accountID stellar1.AccountID) (own bool, accountName string, err error) {
c.RLock()
defer c.RLock()
if c.loadErr != nil {
return false, "", c.loadErr
}
name := c.accounts[accountID]
if name == nil {
return false, "", nil
}
return true, *name, nil
} | [
"func",
"(",
"c",
"*",
"ownAccountLookupCacheImpl",
")",
"OwnAccount",
"(",
"ctx",
"context",
".",
"Context",
",",
"accountID",
"stellar1",
".",
"AccountID",
")",
"(",
"own",
"bool",
",",
"accountName",
"string",
",",
"err",
"error",
")",
"{",
"c",
".",
... | // OwnAccount queries the cache. Blocks until the populating RPC returns. | [
"OwnAccount",
"queries",
"the",
"cache",
".",
"Blocks",
"until",
"the",
"populating",
"RPC",
"returns",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/stellar/util.go#L89-L100 |
160,163 | keybase/client | go/minterm/minterm.go | New | func New() (*MinTerm, error) {
m := &MinTerm{}
if err := m.open(); err != nil {
return nil, err
}
return m, nil
} | go | func New() (*MinTerm, error) {
m := &MinTerm{}
if err := m.open(); err != nil {
return nil, err
}
return m, nil
} | [
"func",
"New",
"(",
")",
"(",
"*",
"MinTerm",
",",
"error",
")",
"{",
"m",
":=",
"&",
"MinTerm",
"{",
"}",
"\n",
"if",
"err",
":=",
"m",
".",
"open",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"ret... | // New creates a new MinTerm and opens the terminal file. Any
// errors that happen while opening or getting the terminal size
// are returned. | [
"New",
"creates",
"a",
"new",
"MinTerm",
"and",
"opens",
"the",
"terminal",
"file",
".",
"Any",
"errors",
"that",
"happen",
"while",
"opening",
"or",
"getting",
"the",
"terminal",
"size",
"are",
"returned",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/minterm/minterm.go#L34-L40 |
160,164 | keybase/client | go/minterm/minterm.go | Shutdown | func (m *MinTerm) Shutdown() error {
m.restore()
// this can hang waiting for newline, so do it in a goroutine.
// application shutting down, so will get closed by os anyway...
if m.termIn != nil {
go m.termIn.Close()
}
if m.termOut != nil && m.closeTermOut {
go m.termOut.Close()
}
return nil
} | go | func (m *MinTerm) Shutdown() error {
m.restore()
// this can hang waiting for newline, so do it in a goroutine.
// application shutting down, so will get closed by os anyway...
if m.termIn != nil {
go m.termIn.Close()
}
if m.termOut != nil && m.closeTermOut {
go m.termOut.Close()
}
return nil
} | [
"func",
"(",
"m",
"*",
"MinTerm",
")",
"Shutdown",
"(",
")",
"error",
"{",
"m",
".",
"restore",
"(",
")",
"\n",
"// this can hang waiting for newline, so do it in a goroutine.",
"// application shutting down, so will get closed by os anyway...",
"if",
"m",
".",
"termIn",
... | // Shutdown closes the terminal. | [
"Shutdown",
"closes",
"the",
"terminal",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/minterm/minterm.go#L43-L54 |
160,165 | keybase/client | go/minterm/minterm.go | Prompt | func (m *MinTerm) Prompt(prompt string) (string, error) {
return m.readLine(prompt)
} | go | func (m *MinTerm) Prompt(prompt string) (string, error) {
return m.readLine(prompt)
} | [
"func",
"(",
"m",
"*",
"MinTerm",
")",
"Prompt",
"(",
"prompt",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"return",
"m",
".",
"readLine",
"(",
"prompt",
")",
"\n",
"}"
] | // Prompt gets a line of input from the terminal. It displays the text in
// the prompt parameter first. | [
"Prompt",
"gets",
"a",
"line",
"of",
"input",
"from",
"the",
"terminal",
".",
"It",
"displays",
"the",
"text",
"in",
"the",
"prompt",
"parameter",
"first",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/minterm/minterm.go#L63-L65 |
160,166 | keybase/client | go/minterm/minterm.go | PromptPassword | func (m *MinTerm) PromptPassword(prompt string) (string, error) {
if !strings.HasSuffix(prompt, ": ") {
prompt += ": "
}
return m.readSecret(prompt)
} | go | func (m *MinTerm) PromptPassword(prompt string) (string, error) {
if !strings.HasSuffix(prompt, ": ") {
prompt += ": "
}
return m.readSecret(prompt)
} | [
"func",
"(",
"m",
"*",
"MinTerm",
")",
"PromptPassword",
"(",
"prompt",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"!",
"strings",
".",
"HasSuffix",
"(",
"prompt",
",",
"\"",
"\"",
")",
"{",
"prompt",
"+=",
"\"",
"\"",
"\n",
"}",
... | // PromptPassword gets a line of input from the terminal, but
// nothing is echoed to the terminal to hide the text. | [
"PromptPassword",
"gets",
"a",
"line",
"of",
"input",
"from",
"the",
"terminal",
"but",
"nothing",
"is",
"echoed",
"to",
"the",
"terminal",
"to",
"hide",
"the",
"text",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/minterm/minterm.go#L69-L74 |
160,167 | keybase/client | go/service/kbfs.go | checkConversationRekey | func (h *KBFSHandler) checkConversationRekey(arg keybase1.FSNotification) {
if arg.NotificationType != keybase1.FSNotificationType_REKEYING {
return
}
h.G().Log.Debug("received rekey notification for %s, code: %v", arg.Filename, arg.StatusCode)
if arg.StatusCode != keybase1.FSStatusCode_FINISH {
return
}
uid := h.G().Env.GetUID()
if uid.IsNil() {
h.G().Log.Debug("received rekey finished notification for %s, but have no UID", arg.Filename)
return
}
h.G().Log.Debug("received rekey finished notification for %s, checking for conversations", arg.Filename)
h.notifyConversation(uid, arg.Filename)
} | go | func (h *KBFSHandler) checkConversationRekey(arg keybase1.FSNotification) {
if arg.NotificationType != keybase1.FSNotificationType_REKEYING {
return
}
h.G().Log.Debug("received rekey notification for %s, code: %v", arg.Filename, arg.StatusCode)
if arg.StatusCode != keybase1.FSStatusCode_FINISH {
return
}
uid := h.G().Env.GetUID()
if uid.IsNil() {
h.G().Log.Debug("received rekey finished notification for %s, but have no UID", arg.Filename)
return
}
h.G().Log.Debug("received rekey finished notification for %s, checking for conversations", arg.Filename)
h.notifyConversation(uid, arg.Filename)
} | [
"func",
"(",
"h",
"*",
"KBFSHandler",
")",
"checkConversationRekey",
"(",
"arg",
"keybase1",
".",
"FSNotification",
")",
"{",
"if",
"arg",
".",
"NotificationType",
"!=",
"keybase1",
".",
"FSNotificationType_REKEYING",
"{",
"return",
"\n",
"}",
"\n",
"h",
".",
... | // checkConversationRekey looks for rekey finished notifications and tries to
// find any conversations associated with the rekeyed TLF. If it finds any,
// it will send ChatThreadsStale notifications for them. | [
"checkConversationRekey",
"looks",
"for",
"rekey",
"finished",
"notifications",
"and",
"tries",
"to",
"find",
"any",
"conversations",
"associated",
"with",
"the",
"rekeyed",
"TLF",
".",
"If",
"it",
"finds",
"any",
"it",
"will",
"send",
"ChatThreadsStale",
"notific... | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/service/kbfs.go#L90-L108 |
160,168 | keybase/client | go/service/kbfs.go | getKeyFn | func (h *KBFSHandler) getKeyFn() func(context.Context) ([32]byte, error) {
keyFn := func(ctx context.Context) ([32]byte, error) {
return teams.GetLocalStorageSecretBoxKeyGeneric(ctx, h.G(), favoritesEncryptionReason)
}
return keyFn
} | go | func (h *KBFSHandler) getKeyFn() func(context.Context) ([32]byte, error) {
keyFn := func(ctx context.Context) ([32]byte, error) {
return teams.GetLocalStorageSecretBoxKeyGeneric(ctx, h.G(), favoritesEncryptionReason)
}
return keyFn
} | [
"func",
"(",
"h",
"*",
"KBFSHandler",
")",
"getKeyFn",
"(",
")",
"func",
"(",
"context",
".",
"Context",
")",
"(",
"[",
"32",
"]",
"byte",
",",
"error",
")",
"{",
"keyFn",
":=",
"func",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"[",
"32",
... | // getKeyFn returns a function that gets an encryption key for storing
// favorites. | [
"getKeyFn",
"returns",
"a",
"function",
"that",
"gets",
"an",
"encryption",
"key",
"for",
"storing",
"favorites",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/service/kbfs.go#L158-L163 |
160,169 | keybase/client | go/service/kbfs.go | EncryptFavorites | func (h *KBFSHandler) EncryptFavorites(ctx context.Context,
dataToDecrypt []byte) (res []byte, err error) {
return encrypteddb.EncodeBox(ctx, dataToDecrypt, h.getKeyFn())
} | go | func (h *KBFSHandler) EncryptFavorites(ctx context.Context,
dataToDecrypt []byte) (res []byte, err error) {
return encrypteddb.EncodeBox(ctx, dataToDecrypt, h.getKeyFn())
} | [
"func",
"(",
"h",
"*",
"KBFSHandler",
")",
"EncryptFavorites",
"(",
"ctx",
"context",
".",
"Context",
",",
"dataToDecrypt",
"[",
"]",
"byte",
")",
"(",
"res",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"return",
"encrypteddb",
".",
"EncodeBox",
"... | // EncryptFavorites encrypts cached favorites to store on disk. | [
"EncryptFavorites",
"encrypts",
"cached",
"favorites",
"to",
"store",
"on",
"disk",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/service/kbfs.go#L166-L169 |
160,170 | keybase/client | go/protocol/chat1/extras.go | Eq | func (id TLFID) Eq(other TLFID) bool {
return bytes.Equal([]byte(id), []byte(other))
} | go | func (id TLFID) Eq(other TLFID) bool {
return bytes.Equal([]byte(id), []byte(other))
} | [
"func",
"(",
"id",
"TLFID",
")",
"Eq",
"(",
"other",
"TLFID",
")",
"bool",
"{",
"return",
"bytes",
".",
"Equal",
"(",
"[",
"]",
"byte",
"(",
"id",
")",
",",
"[",
"]",
"byte",
"(",
"other",
")",
")",
"\n",
"}"
] | // Eq compares two TLFIDs | [
"Eq",
"compares",
"two",
"TLFIDs"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/protocol/chat1/extras.go#L39-L41 |
160,171 | keybase/client | go/protocol/chat1/extras.go | EqString | func (id TLFID) EqString(other fmt.Stringer) bool {
return hex.EncodeToString(id) == other.String()
} | go | func (id TLFID) EqString(other fmt.Stringer) bool {
return hex.EncodeToString(id) == other.String()
} | [
"func",
"(",
"id",
"TLFID",
")",
"EqString",
"(",
"other",
"fmt",
".",
"Stringer",
")",
"bool",
"{",
"return",
"hex",
".",
"EncodeToString",
"(",
"id",
")",
"==",
"other",
".",
"String",
"(",
")",
"\n",
"}"
] | // EqString is like EqualsTo, except that it accepts a fmt.Stringer. This
// can be useful for comparing keybase1.TLFID and chat1.TLFID. | [
"EqString",
"is",
"like",
"EqualsTo",
"except",
"that",
"it",
"accepts",
"a",
"fmt",
".",
"Stringer",
".",
"This",
"can",
"be",
"useful",
"for",
"comparing",
"keybase1",
".",
"TLFID",
"and",
"chat1",
".",
"TLFID",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/protocol/chat1/extras.go#L45-L47 |
160,172 | keybase/client | go/protocol/chat1/extras.go | ParseableVersion | func (m MessageUnboxedError) ParseableVersion() bool {
switch m.ErrType {
case MessageUnboxedErrorType_BADVERSION, MessageUnboxedErrorType_BADVERSION_CRITICAL:
// only applies to these types
default:
return false
}
kind := m.VersionKind
version := m.VersionNumber
// This error was stored from an old client, we have parse out the info we
// need from the error message.
// TODO remove this check once it has be live for a few cycles.
if kind == "" && version == 0 {
re := regexp.MustCompile(`.* Chat version error: \[ unhandled: (\w+) version: (\d+) .*\]`)
matches := re.FindStringSubmatch(m.ErrMsg)
if len(matches) != 3 {
return false
}
kind = VersionKind(matches[1])
var err error
version, err = strconv.Atoi(matches[2])
if err != nil {
return false
}
}
var maxVersion int
switch kind {
case VersionErrorMessageBoxed:
maxVersion = int(MaxMessageBoxedVersion)
case VersionErrorHeader:
maxVersion = int(MaxHeaderVersion)
case VersionErrorBody:
maxVersion = int(MaxBodyVersion)
default:
return false
}
return maxVersion >= version
} | go | func (m MessageUnboxedError) ParseableVersion() bool {
switch m.ErrType {
case MessageUnboxedErrorType_BADVERSION, MessageUnboxedErrorType_BADVERSION_CRITICAL:
// only applies to these types
default:
return false
}
kind := m.VersionKind
version := m.VersionNumber
// This error was stored from an old client, we have parse out the info we
// need from the error message.
// TODO remove this check once it has be live for a few cycles.
if kind == "" && version == 0 {
re := regexp.MustCompile(`.* Chat version error: \[ unhandled: (\w+) version: (\d+) .*\]`)
matches := re.FindStringSubmatch(m.ErrMsg)
if len(matches) != 3 {
return false
}
kind = VersionKind(matches[1])
var err error
version, err = strconv.Atoi(matches[2])
if err != nil {
return false
}
}
var maxVersion int
switch kind {
case VersionErrorMessageBoxed:
maxVersion = int(MaxMessageBoxedVersion)
case VersionErrorHeader:
maxVersion = int(MaxHeaderVersion)
case VersionErrorBody:
maxVersion = int(MaxBodyVersion)
default:
return false
}
return maxVersion >= version
} | [
"func",
"(",
"m",
"MessageUnboxedError",
")",
"ParseableVersion",
"(",
")",
"bool",
"{",
"switch",
"m",
".",
"ErrType",
"{",
"case",
"MessageUnboxedErrorType_BADVERSION",
",",
"MessageUnboxedErrorType_BADVERSION_CRITICAL",
":",
"// only applies to these types",
"default",
... | // ParseableVersion checks if this error has a version that is now able to be
// understood by our client. | [
"ParseableVersion",
"checks",
"if",
"this",
"error",
"has",
"a",
"version",
"that",
"is",
"now",
"able",
"to",
"be",
"understood",
"by",
"our",
"client",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/protocol/chat1/extras.go#L547-L586 |
160,173 | keybase/client | go/protocol/chat1/extras.go | TLFNameExpandedSummary | func (c ConversationInfoLocal) TLFNameExpandedSummary() string {
if c.FinalizeInfo == nil {
return c.TlfName
}
return c.TlfName + " " + c.FinalizeInfo.BeforeSummary()
} | go | func (c ConversationInfoLocal) TLFNameExpandedSummary() string {
if c.FinalizeInfo == nil {
return c.TlfName
}
return c.TlfName + " " + c.FinalizeInfo.BeforeSummary()
} | [
"func",
"(",
"c",
"ConversationInfoLocal",
")",
"TLFNameExpandedSummary",
"(",
")",
"string",
"{",
"if",
"c",
".",
"FinalizeInfo",
"==",
"nil",
"{",
"return",
"c",
".",
"TlfName",
"\n",
"}",
"\n",
"return",
"c",
".",
"TlfName",
"+",
"\"",
"\"",
"+",
"c... | // TLFNameExpandedSummary returns a TLF name with a summary of the
// account reset if there was one.
// This version is for display purposes only and cannot be used to lookup the TLF. | [
"TLFNameExpandedSummary",
"returns",
"a",
"TLF",
"name",
"with",
"a",
"summary",
"of",
"the",
"account",
"reset",
"if",
"there",
"was",
"one",
".",
"This",
"version",
"is",
"for",
"display",
"purposes",
"only",
"and",
"cannot",
"be",
"used",
"to",
"lookup",
... | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/protocol/chat1/extras.go#L1025-L1030 |
160,174 | keybase/client | go/protocol/chat1/extras.go | ExpandTLFName | func ExpandTLFName(name string, finalizeInfo *ConversationFinalizeInfo) string {
if finalizeInfo == nil {
return name
}
if len(finalizeInfo.ResetFull) == 0 {
return name
}
if strings.Contains(name, " account reset ") {
return name
}
return name + " " + finalizeInfo.ResetFull
} | go | func ExpandTLFName(name string, finalizeInfo *ConversationFinalizeInfo) string {
if finalizeInfo == nil {
return name
}
if len(finalizeInfo.ResetFull) == 0 {
return name
}
if strings.Contains(name, " account reset ") {
return name
}
return name + " " + finalizeInfo.ResetFull
} | [
"func",
"ExpandTLFName",
"(",
"name",
"string",
",",
"finalizeInfo",
"*",
"ConversationFinalizeInfo",
")",
"string",
"{",
"if",
"finalizeInfo",
"==",
"nil",
"{",
"return",
"name",
"\n",
"}",
"\n",
"if",
"len",
"(",
"finalizeInfo",
".",
"ResetFull",
")",
"=="... | // ExpandTLFName returns a TLF name with a reset suffix if it exists.
// This version can be used in requests to lookup the TLF. | [
"ExpandTLFName",
"returns",
"a",
"TLF",
"name",
"with",
"a",
"reset",
"suffix",
"if",
"it",
"exists",
".",
"This",
"version",
"can",
"be",
"used",
"in",
"requests",
"to",
"lookup",
"the",
"TLF",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/protocol/chat1/extras.go#L1067-L1078 |
160,175 | keybase/client | go/protocol/chat1/extras.go | FirstPage | func (p *Pagination) FirstPage() bool {
return p == nil || p.ForceFirstPage || (len(p.Next) == 0 && len(p.Previous) == 0)
} | go | func (p *Pagination) FirstPage() bool {
return p == nil || p.ForceFirstPage || (len(p.Next) == 0 && len(p.Previous) == 0)
} | [
"func",
"(",
"p",
"*",
"Pagination",
")",
"FirstPage",
"(",
")",
"bool",
"{",
"return",
"p",
"==",
"nil",
"||",
"p",
".",
"ForceFirstPage",
"||",
"(",
"len",
"(",
"p",
".",
"Next",
")",
"==",
"0",
"&&",
"len",
"(",
"p",
".",
"Previous",
")",
"=... | // FirstPage returns true if the pagination object is not pointing in any direction | [
"FirstPage",
"returns",
"true",
"if",
"the",
"pagination",
"object",
"is",
"not",
"pointing",
"in",
"any",
"direction"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/protocol/chat1/extras.go#L1113-L1115 |
160,176 | keybase/client | go/kbfs/libkbfs/disk_block_cache.go | tlfKey | func (*DiskBlockCacheLocal) tlfKey(tlfID tlf.ID, blockKey []byte) []byte {
return append(tlfID.Bytes(), blockKey...)
} | go | func (*DiskBlockCacheLocal) tlfKey(tlfID tlf.ID, blockKey []byte) []byte {
return append(tlfID.Bytes(), blockKey...)
} | [
"func",
"(",
"*",
"DiskBlockCacheLocal",
")",
"tlfKey",
"(",
"tlfID",
"tlf",
".",
"ID",
",",
"blockKey",
"[",
"]",
"byte",
")",
"[",
"]",
"byte",
"{",
"return",
"append",
"(",
"tlfID",
".",
"Bytes",
"(",
")",
",",
"blockKey",
"...",
")",
"\n",
"}"
... | // tlfKey generates a TLF cache key from a tlf.ID and a binary-encoded block
// ID. | [
"tlfKey",
"generates",
"a",
"TLF",
"cache",
"key",
"from",
"a",
"tlf",
".",
"ID",
"and",
"a",
"binary",
"-",
"encoded",
"block",
"ID",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/disk_block_cache.go#L495-L497 |
160,177 | keybase/client | go/kbfs/libkbfs/disk_block_cache.go | updateMetadataLocked | func (cache *DiskBlockCacheLocal) updateMetadataLocked(ctx context.Context,
blockKey []byte, metadata DiskBlockCacheMetadata, metered bool) error {
metadata.LRUTime.Time = cache.config.Clock().Now()
encodedMetadata, err := cache.config.Codec().Encode(&metadata)
if err != nil {
return err
}
var putMeter *CountMeter
if metered {
putMeter = cache.updateMeter
}
err = cache.metaDb.PutWithMeter(blockKey, encodedMetadata, putMeter)
if err != nil {
cache.log.CWarningf(ctx, "Error writing to disk cache meta "+
"database: %+v", err)
}
return err
} | go | func (cache *DiskBlockCacheLocal) updateMetadataLocked(ctx context.Context,
blockKey []byte, metadata DiskBlockCacheMetadata, metered bool) error {
metadata.LRUTime.Time = cache.config.Clock().Now()
encodedMetadata, err := cache.config.Codec().Encode(&metadata)
if err != nil {
return err
}
var putMeter *CountMeter
if metered {
putMeter = cache.updateMeter
}
err = cache.metaDb.PutWithMeter(blockKey, encodedMetadata, putMeter)
if err != nil {
cache.log.CWarningf(ctx, "Error writing to disk cache meta "+
"database: %+v", err)
}
return err
} | [
"func",
"(",
"cache",
"*",
"DiskBlockCacheLocal",
")",
"updateMetadataLocked",
"(",
"ctx",
"context",
".",
"Context",
",",
"blockKey",
"[",
"]",
"byte",
",",
"metadata",
"DiskBlockCacheMetadata",
",",
"metered",
"bool",
")",
"error",
"{",
"metadata",
".",
"LRU... | // updateMetadataLocked updates the LRU time of a block in the LRU cache to
// the current time. | [
"updateMetadataLocked",
"updates",
"the",
"LRU",
"time",
"of",
"a",
"block",
"in",
"the",
"LRU",
"cache",
"to",
"the",
"current",
"time",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/disk_block_cache.go#L501-L518 |
160,178 | keybase/client | go/kbfs/libkbfs/disk_block_cache.go | getLRULocked | func (cache *DiskBlockCacheLocal) getLRULocked(blockID kbfsblock.ID) (
time.Time, error) {
metadata, err := cache.getMetadataLocked(blockID, false)
if err != nil {
return time.Time{}, err
}
return metadata.LRUTime.Time, nil
} | go | func (cache *DiskBlockCacheLocal) getLRULocked(blockID kbfsblock.ID) (
time.Time, error) {
metadata, err := cache.getMetadataLocked(blockID, false)
if err != nil {
return time.Time{}, err
}
return metadata.LRUTime.Time, nil
} | [
"func",
"(",
"cache",
"*",
"DiskBlockCacheLocal",
")",
"getLRULocked",
"(",
"blockID",
"kbfsblock",
".",
"ID",
")",
"(",
"time",
".",
"Time",
",",
"error",
")",
"{",
"metadata",
",",
"err",
":=",
"cache",
".",
"getMetadataLocked",
"(",
"blockID",
",",
"f... | // getLRULocked retrieves the LRU time for a block in the cache, or returns
// leveldb.ErrNotFound and a zero-valued time.Time otherwise. | [
"getLRULocked",
"retrieves",
"the",
"LRU",
"time",
"for",
"a",
"block",
"in",
"the",
"cache",
"or",
"returns",
"leveldb",
".",
"ErrNotFound",
"and",
"a",
"zero",
"-",
"valued",
"time",
".",
"Time",
"otherwise",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/disk_block_cache.go#L542-L549 |
160,179 | keybase/client | go/kbfs/libkbfs/disk_block_cache.go | decodeBlockCacheEntry | func (cache *DiskBlockCacheLocal) decodeBlockCacheEntry(buf []byte) ([]byte,
kbfscrypto.BlockCryptKeyServerHalf, error) {
entry := diskBlockCacheEntry{}
err := cache.config.Codec().Decode(buf, &entry)
if err != nil {
return nil, kbfscrypto.BlockCryptKeyServerHalf{}, err
}
return entry.Buf, entry.ServerHalf, nil
} | go | func (cache *DiskBlockCacheLocal) decodeBlockCacheEntry(buf []byte) ([]byte,
kbfscrypto.BlockCryptKeyServerHalf, error) {
entry := diskBlockCacheEntry{}
err := cache.config.Codec().Decode(buf, &entry)
if err != nil {
return nil, kbfscrypto.BlockCryptKeyServerHalf{}, err
}
return entry.Buf, entry.ServerHalf, nil
} | [
"func",
"(",
"cache",
"*",
"DiskBlockCacheLocal",
")",
"decodeBlockCacheEntry",
"(",
"buf",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"kbfscrypto",
".",
"BlockCryptKeyServerHalf",
",",
"error",
")",
"{",
"entry",
":=",
"diskBlockCacheEntry",
"{",
"}... | // decodeBlockCacheEntry decodes a disk block cache entry buffer into an
// encoded block and server half. | [
"decodeBlockCacheEntry",
"decodes",
"a",
"disk",
"block",
"cache",
"entry",
"buffer",
"into",
"an",
"encoded",
"block",
"and",
"server",
"half",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/disk_block_cache.go#L553-L561 |
160,180 | keybase/client | go/kbfs/libkbfs/disk_block_cache.go | encodeBlockCacheEntry | func (cache *DiskBlockCacheLocal) encodeBlockCacheEntry(buf []byte,
serverHalf kbfscrypto.BlockCryptKeyServerHalf) ([]byte, error) {
entry := diskBlockCacheEntry{
Buf: buf,
ServerHalf: serverHalf,
}
return cache.config.Codec().Encode(&entry)
} | go | func (cache *DiskBlockCacheLocal) encodeBlockCacheEntry(buf []byte,
serverHalf kbfscrypto.BlockCryptKeyServerHalf) ([]byte, error) {
entry := diskBlockCacheEntry{
Buf: buf,
ServerHalf: serverHalf,
}
return cache.config.Codec().Encode(&entry)
} | [
"func",
"(",
"cache",
"*",
"DiskBlockCacheLocal",
")",
"encodeBlockCacheEntry",
"(",
"buf",
"[",
"]",
"byte",
",",
"serverHalf",
"kbfscrypto",
".",
"BlockCryptKeyServerHalf",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"entry",
":=",
"diskBlockCacheEnt... | // encodeBlockCacheEntry encodes an encoded block and serverHalf into a single
// buffer. | [
"encodeBlockCacheEntry",
"encodes",
"an",
"encoded",
"block",
"and",
"serverHalf",
"into",
"a",
"single",
"buffer",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/disk_block_cache.go#L565-L572 |
160,181 | keybase/client | go/kbfs/libkbfs/disk_block_cache.go | Get | func (cache *DiskBlockCacheLocal) Get(
ctx context.Context, tlfID tlf.ID, blockID kbfsblock.ID) (buf []byte,
serverHalf kbfscrypto.BlockCryptKeyServerHalf,
prefetchStatus PrefetchStatus, err error) {
cache.lock.RLock()
defer cache.lock.RUnlock()
err = cache.checkCacheLocked("Block(Get)")
if err != nil {
return nil, kbfscrypto.BlockCryptKeyServerHalf{}, NoPrefetch, err
}
blockKey := blockID.Bytes()
entry, err := cache.blockDb.Get(blockKey, nil)
if err != nil {
return nil, kbfscrypto.BlockCryptKeyServerHalf{}, NoPrefetch,
data.NoSuchBlockError{ID: blockID}
}
md, err := cache.getMetadataLocked(blockID, true)
if err != nil {
return nil, kbfscrypto.BlockCryptKeyServerHalf{}, NoPrefetch, err
}
err = cache.updateMetadataLocked(ctx, blockKey, md, unmetered)
if err != nil {
return nil, kbfscrypto.BlockCryptKeyServerHalf{}, NoPrefetch, err
}
buf, serverHalf, err = cache.decodeBlockCacheEntry(entry)
return buf, serverHalf, md.PrefetchStatus(), err
} | go | func (cache *DiskBlockCacheLocal) Get(
ctx context.Context, tlfID tlf.ID, blockID kbfsblock.ID) (buf []byte,
serverHalf kbfscrypto.BlockCryptKeyServerHalf,
prefetchStatus PrefetchStatus, err error) {
cache.lock.RLock()
defer cache.lock.RUnlock()
err = cache.checkCacheLocked("Block(Get)")
if err != nil {
return nil, kbfscrypto.BlockCryptKeyServerHalf{}, NoPrefetch, err
}
blockKey := blockID.Bytes()
entry, err := cache.blockDb.Get(blockKey, nil)
if err != nil {
return nil, kbfscrypto.BlockCryptKeyServerHalf{}, NoPrefetch,
data.NoSuchBlockError{ID: blockID}
}
md, err := cache.getMetadataLocked(blockID, true)
if err != nil {
return nil, kbfscrypto.BlockCryptKeyServerHalf{}, NoPrefetch, err
}
err = cache.updateMetadataLocked(ctx, blockKey, md, unmetered)
if err != nil {
return nil, kbfscrypto.BlockCryptKeyServerHalf{}, NoPrefetch, err
}
buf, serverHalf, err = cache.decodeBlockCacheEntry(entry)
return buf, serverHalf, md.PrefetchStatus(), err
} | [
"func",
"(",
"cache",
"*",
"DiskBlockCacheLocal",
")",
"Get",
"(",
"ctx",
"context",
".",
"Context",
",",
"tlfID",
"tlf",
".",
"ID",
",",
"blockID",
"kbfsblock",
".",
"ID",
")",
"(",
"buf",
"[",
"]",
"byte",
",",
"serverHalf",
"kbfscrypto",
".",
"Block... | // Get implements the DiskBlockCache interface for DiskBlockCacheLocal. | [
"Get",
"implements",
"the",
"DiskBlockCache",
"interface",
"for",
"DiskBlockCacheLocal",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/disk_block_cache.go#L600-L627 |
160,182 | keybase/client | go/kbfs/libkbfs/disk_block_cache.go | GetMetadata | func (cache *DiskBlockCacheLocal) GetMetadata(ctx context.Context,
blockID kbfsblock.ID) (DiskBlockCacheMetadata, error) {
cache.lock.RLock()
defer cache.lock.RUnlock()
err := cache.checkCacheLocked("Block(GetMetadata)")
if err != nil {
return DiskBlockCacheMetadata{}, err
}
return cache.getMetadataLocked(blockID, false)
} | go | func (cache *DiskBlockCacheLocal) GetMetadata(ctx context.Context,
blockID kbfsblock.ID) (DiskBlockCacheMetadata, error) {
cache.lock.RLock()
defer cache.lock.RUnlock()
err := cache.checkCacheLocked("Block(GetMetadata)")
if err != nil {
return DiskBlockCacheMetadata{}, err
}
return cache.getMetadataLocked(blockID, false)
} | [
"func",
"(",
"cache",
"*",
"DiskBlockCacheLocal",
")",
"GetMetadata",
"(",
"ctx",
"context",
".",
"Context",
",",
"blockID",
"kbfsblock",
".",
"ID",
")",
"(",
"DiskBlockCacheMetadata",
",",
"error",
")",
"{",
"cache",
".",
"lock",
".",
"RLock",
"(",
")",
... | // GetMetadata implements the DiskBlockCache interface for
// DiskBlockCacheLocal. | [
"GetMetadata",
"implements",
"the",
"DiskBlockCache",
"interface",
"for",
"DiskBlockCacheLocal",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/disk_block_cache.go#L761-L770 |
160,183 | keybase/client | go/kbfs/libkbfs/disk_block_cache.go | UpdateMetadata | func (cache *DiskBlockCacheLocal) UpdateMetadata(ctx context.Context,
blockID kbfsblock.ID, prefetchStatus PrefetchStatus) (err error) {
cache.lock.Lock()
defer cache.lock.Unlock()
err = cache.checkCacheLocked("Block(UpdateMetadata)")
if err != nil {
return err
}
md, err := cache.getMetadataLocked(blockID, false)
if err != nil {
return data.NoSuchBlockError{ID: blockID}
}
if md.FinishedPrefetch {
// Don't update md that's already completed.
return nil
}
md.TriggeredPrefetch = false
md.FinishedPrefetch = false
switch prefetchStatus {
case TriggeredPrefetch:
md.TriggeredPrefetch = true
case FinishedPrefetch:
md.TriggeredPrefetch = true
md.FinishedPrefetch = true
}
return cache.updateMetadataLocked(ctx, blockID.Bytes(), md, metered)
} | go | func (cache *DiskBlockCacheLocal) UpdateMetadata(ctx context.Context,
blockID kbfsblock.ID, prefetchStatus PrefetchStatus) (err error) {
cache.lock.Lock()
defer cache.lock.Unlock()
err = cache.checkCacheLocked("Block(UpdateMetadata)")
if err != nil {
return err
}
md, err := cache.getMetadataLocked(blockID, false)
if err != nil {
return data.NoSuchBlockError{ID: blockID}
}
if md.FinishedPrefetch {
// Don't update md that's already completed.
return nil
}
md.TriggeredPrefetch = false
md.FinishedPrefetch = false
switch prefetchStatus {
case TriggeredPrefetch:
md.TriggeredPrefetch = true
case FinishedPrefetch:
md.TriggeredPrefetch = true
md.FinishedPrefetch = true
}
return cache.updateMetadataLocked(ctx, blockID.Bytes(), md, metered)
} | [
"func",
"(",
"cache",
"*",
"DiskBlockCacheLocal",
")",
"UpdateMetadata",
"(",
"ctx",
"context",
".",
"Context",
",",
"blockID",
"kbfsblock",
".",
"ID",
",",
"prefetchStatus",
"PrefetchStatus",
")",
"(",
"err",
"error",
")",
"{",
"cache",
".",
"lock",
".",
... | // UpdateMetadata implements the DiskBlockCache interface for
// DiskBlockCacheLocal. | [
"UpdateMetadata",
"implements",
"the",
"DiskBlockCache",
"interface",
"for",
"DiskBlockCacheLocal",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/disk_block_cache.go#L774-L801 |
160,184 | keybase/client | go/kbfs/libkbfs/disk_block_cache.go | deleteLocked | func (cache *DiskBlockCacheLocal) deleteLocked(ctx context.Context,
blockEntries []kbfsblock.ID) (numRemoved int, sizeRemoved int64,
err error) {
if len(blockEntries) == 0 {
return 0, 0, nil
}
defer func() {
if err == nil {
cache.deleteCountMeter.Mark(int64(numRemoved))
cache.deleteSizeMeter.Mark(sizeRemoved)
}
}()
blockBatch := new(leveldb.Batch)
metadataBatch := new(leveldb.Batch)
tlfBatch := new(leveldb.Batch)
removalCounts := make(map[tlf.ID]int)
removalSizes := make(map[tlf.ID]uint64)
for _, entry := range blockEntries {
blockKey := entry.Bytes()
metadataBytes, err := cache.metaDb.Get(blockKey, nil)
if err != nil {
// If we can't retrieve the block, don't try to delete it, and
// don't account for its non-presence.
continue
}
metadata := DiskBlockCacheMetadata{}
err = cache.config.Codec().Decode(metadataBytes, &metadata)
if err != nil {
return 0, 0, err
}
blockBatch.Delete(blockKey)
metadataBatch.Delete(blockKey)
tlfDbKey := cache.tlfKey(metadata.TlfID, blockKey)
tlfBatch.Delete(tlfDbKey)
removalCounts[metadata.TlfID]++
removalSizes[metadata.TlfID] += uint64(metadata.BlockSize)
sizeRemoved += int64(metadata.BlockSize)
numRemoved++
}
// TODO: more gracefully handle non-atomic failures here.
if err := cache.metaDb.Write(metadataBatch, nil); err != nil {
return 0, 0, err
}
if err := cache.tlfDb.Write(tlfBatch, nil); err != nil {
return 0, 0, err
}
if err := cache.blockDb.Write(blockBatch, nil); err != nil {
return 0, 0, err
}
// Update the cache's totals.
for k, v := range removalCounts {
cache.tlfCounts[k] -= v
cache.priorityBlockCounts[cache.homeDirs[k]] -= v
cache.priorityTlfMap[cache.homeDirs[k]][k] -= v
cache.numBlocks -= v
cache.tlfSizes[k] -= removalSizes[k]
cache.subCurrBytes(removalSizes[k])
}
if cache.useLimiter() {
cache.config.DiskLimiter().release(ctx, cache.cacheType,
sizeRemoved, 0)
}
return numRemoved, sizeRemoved, nil
} | go | func (cache *DiskBlockCacheLocal) deleteLocked(ctx context.Context,
blockEntries []kbfsblock.ID) (numRemoved int, sizeRemoved int64,
err error) {
if len(blockEntries) == 0 {
return 0, 0, nil
}
defer func() {
if err == nil {
cache.deleteCountMeter.Mark(int64(numRemoved))
cache.deleteSizeMeter.Mark(sizeRemoved)
}
}()
blockBatch := new(leveldb.Batch)
metadataBatch := new(leveldb.Batch)
tlfBatch := new(leveldb.Batch)
removalCounts := make(map[tlf.ID]int)
removalSizes := make(map[tlf.ID]uint64)
for _, entry := range blockEntries {
blockKey := entry.Bytes()
metadataBytes, err := cache.metaDb.Get(blockKey, nil)
if err != nil {
// If we can't retrieve the block, don't try to delete it, and
// don't account for its non-presence.
continue
}
metadata := DiskBlockCacheMetadata{}
err = cache.config.Codec().Decode(metadataBytes, &metadata)
if err != nil {
return 0, 0, err
}
blockBatch.Delete(blockKey)
metadataBatch.Delete(blockKey)
tlfDbKey := cache.tlfKey(metadata.TlfID, blockKey)
tlfBatch.Delete(tlfDbKey)
removalCounts[metadata.TlfID]++
removalSizes[metadata.TlfID] += uint64(metadata.BlockSize)
sizeRemoved += int64(metadata.BlockSize)
numRemoved++
}
// TODO: more gracefully handle non-atomic failures here.
if err := cache.metaDb.Write(metadataBatch, nil); err != nil {
return 0, 0, err
}
if err := cache.tlfDb.Write(tlfBatch, nil); err != nil {
return 0, 0, err
}
if err := cache.blockDb.Write(blockBatch, nil); err != nil {
return 0, 0, err
}
// Update the cache's totals.
for k, v := range removalCounts {
cache.tlfCounts[k] -= v
cache.priorityBlockCounts[cache.homeDirs[k]] -= v
cache.priorityTlfMap[cache.homeDirs[k]][k] -= v
cache.numBlocks -= v
cache.tlfSizes[k] -= removalSizes[k]
cache.subCurrBytes(removalSizes[k])
}
if cache.useLimiter() {
cache.config.DiskLimiter().release(ctx, cache.cacheType,
sizeRemoved, 0)
}
return numRemoved, sizeRemoved, nil
} | [
"func",
"(",
"cache",
"*",
"DiskBlockCacheLocal",
")",
"deleteLocked",
"(",
"ctx",
"context",
".",
"Context",
",",
"blockEntries",
"[",
"]",
"kbfsblock",
".",
"ID",
")",
"(",
"numRemoved",
"int",
",",
"sizeRemoved",
"int64",
",",
"err",
"error",
")",
"{",
... | // deleteLocked deletes a set of blocks from the disk block cache. | [
"deleteLocked",
"deletes",
"a",
"set",
"of",
"blocks",
"from",
"the",
"disk",
"block",
"cache",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/disk_block_cache.go#L804-L869 |
160,185 | keybase/client | go/kbfs/libkbfs/disk_block_cache.go | Delete | func (cache *DiskBlockCacheLocal) Delete(ctx context.Context,
blockIDs []kbfsblock.ID) (numRemoved int, sizeRemoved int64, err error) {
cache.lock.Lock()
defer cache.lock.Unlock()
err = cache.checkCacheLocked("Block(Delete)")
if err != nil {
return 0, 0, err
}
cache.log.CDebugf(ctx, "Cache Delete numBlocks=%d", len(blockIDs))
defer func() {
cache.log.CDebugf(ctx, "Deleted numRequested=%d numRemoved=%d sizeRemoved=%d err=%+v", len(blockIDs), numRemoved, sizeRemoved, err)
}()
if cache.config.IsTestMode() {
for _, bID := range blockIDs {
cache.log.CDebugf(ctx, "Cache type=%d delete block ID %s",
cache.cacheType, bID)
}
}
return cache.deleteLocked(ctx, blockIDs)
} | go | func (cache *DiskBlockCacheLocal) Delete(ctx context.Context,
blockIDs []kbfsblock.ID) (numRemoved int, sizeRemoved int64, err error) {
cache.lock.Lock()
defer cache.lock.Unlock()
err = cache.checkCacheLocked("Block(Delete)")
if err != nil {
return 0, 0, err
}
cache.log.CDebugf(ctx, "Cache Delete numBlocks=%d", len(blockIDs))
defer func() {
cache.log.CDebugf(ctx, "Deleted numRequested=%d numRemoved=%d sizeRemoved=%d err=%+v", len(blockIDs), numRemoved, sizeRemoved, err)
}()
if cache.config.IsTestMode() {
for _, bID := range blockIDs {
cache.log.CDebugf(ctx, "Cache type=%d delete block ID %s",
cache.cacheType, bID)
}
}
return cache.deleteLocked(ctx, blockIDs)
} | [
"func",
"(",
"cache",
"*",
"DiskBlockCacheLocal",
")",
"Delete",
"(",
"ctx",
"context",
".",
"Context",
",",
"blockIDs",
"[",
"]",
"kbfsblock",
".",
"ID",
")",
"(",
"numRemoved",
"int",
",",
"sizeRemoved",
"int64",
",",
"err",
"error",
")",
"{",
"cache",... | // Delete implements the DiskBlockCache interface for DiskBlockCacheLocal. | [
"Delete",
"implements",
"the",
"DiskBlockCache",
"interface",
"for",
"DiskBlockCacheLocal",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/disk_block_cache.go#L872-L892 |
160,186 | keybase/client | go/kbfs/libkbfs/disk_block_cache.go | evictSomeBlocks | func (cache *DiskBlockCacheLocal) evictSomeBlocks(ctx context.Context,
numBlocks int, blockIDs blockIDsByTime) (numRemoved int, sizeRemoved int64,
err error) {
defer func() {
cache.log.CDebugf(ctx, "Cache evictSomeBlocks numBlocksRequested=%d "+
"numBlocksEvicted=%d sizeBlocksEvicted=%d err=%+v", numBlocks,
numRemoved, sizeRemoved, err)
}()
if len(blockIDs) <= numBlocks {
numBlocks = len(blockIDs)
} else {
// Only sort if we need to grab a subset of blocks.
sort.Sort(blockIDs)
}
blocksToDelete := blockIDs.ToBlockIDSlice(numBlocks)
return cache.deleteLocked(ctx, blocksToDelete)
} | go | func (cache *DiskBlockCacheLocal) evictSomeBlocks(ctx context.Context,
numBlocks int, blockIDs blockIDsByTime) (numRemoved int, sizeRemoved int64,
err error) {
defer func() {
cache.log.CDebugf(ctx, "Cache evictSomeBlocks numBlocksRequested=%d "+
"numBlocksEvicted=%d sizeBlocksEvicted=%d err=%+v", numBlocks,
numRemoved, sizeRemoved, err)
}()
if len(blockIDs) <= numBlocks {
numBlocks = len(blockIDs)
} else {
// Only sort if we need to grab a subset of blocks.
sort.Sort(blockIDs)
}
blocksToDelete := blockIDs.ToBlockIDSlice(numBlocks)
return cache.deleteLocked(ctx, blocksToDelete)
} | [
"func",
"(",
"cache",
"*",
"DiskBlockCacheLocal",
")",
"evictSomeBlocks",
"(",
"ctx",
"context",
".",
"Context",
",",
"numBlocks",
"int",
",",
"blockIDs",
"blockIDsByTime",
")",
"(",
"numRemoved",
"int",
",",
"sizeRemoved",
"int64",
",",
"err",
"error",
")",
... | // evictSomeBlocks tries to evict `numBlocks` blocks from the cache. If
// `blockIDs` doesn't have enough blocks, we evict them all and report how many
// we evicted. | [
"evictSomeBlocks",
"tries",
"to",
"evict",
"numBlocks",
"blocks",
"from",
"the",
"cache",
".",
"If",
"blockIDs",
"doesn",
"t",
"have",
"enough",
"blocks",
"we",
"evict",
"them",
"all",
"and",
"report",
"how",
"many",
"we",
"evicted",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/disk_block_cache.go#L922-L939 |
160,187 | keybase/client | go/kbfs/libkbfs/disk_block_cache.go | shuffleTLFsAtPriorityWeighted | func (cache *DiskBlockCacheLocal) shuffleTLFsAtPriorityWeighted(
priority evictionPriority) []weightedByCount {
weightedSlice := make([]weightedByCount, 0,
len(cache.priorityTlfMap[priority]))
idx := 0
// Use an exponential distribution to ensure the weights are
// correctly used.
// See http://utopia.duth.gr/~pefraimi/research/data/2007EncOfAlg.pdf
for tlfID, count := range cache.priorityTlfMap[priority] {
if count == 0 {
continue
}
weightedSlice = append(weightedSlice, weightedByCount{
key: math.Pow(rand.Float64(), 1.0/float64(count)),
value: tlfID,
})
idx++
}
sort.Slice(weightedSlice, func(i, j int) bool {
return weightedSlice[i].key > weightedSlice[j].key
})
return weightedSlice
} | go | func (cache *DiskBlockCacheLocal) shuffleTLFsAtPriorityWeighted(
priority evictionPriority) []weightedByCount {
weightedSlice := make([]weightedByCount, 0,
len(cache.priorityTlfMap[priority]))
idx := 0
// Use an exponential distribution to ensure the weights are
// correctly used.
// See http://utopia.duth.gr/~pefraimi/research/data/2007EncOfAlg.pdf
for tlfID, count := range cache.priorityTlfMap[priority] {
if count == 0 {
continue
}
weightedSlice = append(weightedSlice, weightedByCount{
key: math.Pow(rand.Float64(), 1.0/float64(count)),
value: tlfID,
})
idx++
}
sort.Slice(weightedSlice, func(i, j int) bool {
return weightedSlice[i].key > weightedSlice[j].key
})
return weightedSlice
} | [
"func",
"(",
"cache",
"*",
"DiskBlockCacheLocal",
")",
"shuffleTLFsAtPriorityWeighted",
"(",
"priority",
"evictionPriority",
")",
"[",
"]",
"weightedByCount",
"{",
"weightedSlice",
":=",
"make",
"(",
"[",
"]",
"weightedByCount",
",",
"0",
",",
"len",
"(",
"cache... | // shuffleTLFsAtPriorityWeighted shuffles the TLFs at a given priority,
// weighting by per-TLF block count. | [
"shuffleTLFsAtPriorityWeighted",
"shuffles",
"the",
"TLFs",
"at",
"a",
"given",
"priority",
"weighting",
"by",
"per",
"-",
"TLF",
"block",
"count",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/disk_block_cache.go#L996-L1018 |
160,188 | keybase/client | go/kbfs/libkbfs/disk_block_cache.go | evictLocked | func (cache *DiskBlockCacheLocal) evictLocked(ctx context.Context,
numBlocks int) (numRemoved int, sizeRemoved int64, err error) {
numRemoved = 0
sizeRemoved = 0
defer func() {
cache.evictCountMeter.Mark(int64(numRemoved))
cache.evictSizeMeter.Mark(sizeRemoved)
}()
for priorityToEvict := priorityNotHome; (priorityToEvict <= priorityPrivateHome) && (numRemoved < numBlocks); priorityToEvict++ {
// Shuffle the TLFs of this priority, weighting by block count.
shuffledSlice := cache.shuffleTLFsAtPriorityWeighted(priorityToEvict)
// Select some TLFs to evict from.
numElements := (numBlocks - numRemoved) * evictionConsiderationFactor
// blockIDs is a slice of blocks from which evictions will be selected.
blockIDs := make(blockIDsByTime, 0, numElements)
// For each TLF until we get enough elements to select among,
// add its blocks to the eviction slice.
for _, tlfIDStruct := range shuffledSlice {
tlfID := tlfIDStruct.value
if cache.tlfCounts[tlfID] == 0 {
cache.log.CDebugf(ctx, "No blocks to delete in TLF %s", tlfID)
continue
}
tlfBytes := tlfID.Bytes()
blockID, err := cache.getRandomBlockID(numElements,
cache.tlfCounts[tlfID])
if err != nil {
return 0, 0, err
}
rng := &util.Range{
Start: append(tlfBytes, blockID.Bytes()...),
Limit: append(tlfBytes, cache.maxBlockID...),
}
// Extra func exists to make defers work.
func() {
iter := cache.tlfDb.NewIterator(rng, nil)
defer iter.Release()
for i := 0; i < numElements; i++ {
if !iter.Next() {
break
}
key := iter.Key()
blockIDBytes := key[len(tlfBytes):]
blockID, err := kbfsblock.IDFromBytes(blockIDBytes)
if err != nil {
cache.log.CWarningf(ctx, "Error decoding block ID %x", blockIDBytes)
continue
}
lru, err := cache.getLRULocked(blockID)
if err != nil {
cache.log.CWarningf(ctx, "Error decoding LRU time for block %s",
blockID)
continue
}
blockIDs = append(blockIDs, lruEntry{blockID, lru})
}
}()
if len(blockIDs) == numElements {
break
}
}
// Evict some of the selected blocks.
currNumRemoved, currSizeRemoved, err := cache.evictSomeBlocks(ctx,
numBlocks-numRemoved, blockIDs)
if err != nil {
return numRemoved, sizeRemoved, err
}
// Update the evicted count.
numRemoved += currNumRemoved
sizeRemoved += currSizeRemoved
}
return numRemoved, sizeRemoved, nil
} | go | func (cache *DiskBlockCacheLocal) evictLocked(ctx context.Context,
numBlocks int) (numRemoved int, sizeRemoved int64, err error) {
numRemoved = 0
sizeRemoved = 0
defer func() {
cache.evictCountMeter.Mark(int64(numRemoved))
cache.evictSizeMeter.Mark(sizeRemoved)
}()
for priorityToEvict := priorityNotHome; (priorityToEvict <= priorityPrivateHome) && (numRemoved < numBlocks); priorityToEvict++ {
// Shuffle the TLFs of this priority, weighting by block count.
shuffledSlice := cache.shuffleTLFsAtPriorityWeighted(priorityToEvict)
// Select some TLFs to evict from.
numElements := (numBlocks - numRemoved) * evictionConsiderationFactor
// blockIDs is a slice of blocks from which evictions will be selected.
blockIDs := make(blockIDsByTime, 0, numElements)
// For each TLF until we get enough elements to select among,
// add its blocks to the eviction slice.
for _, tlfIDStruct := range shuffledSlice {
tlfID := tlfIDStruct.value
if cache.tlfCounts[tlfID] == 0 {
cache.log.CDebugf(ctx, "No blocks to delete in TLF %s", tlfID)
continue
}
tlfBytes := tlfID.Bytes()
blockID, err := cache.getRandomBlockID(numElements,
cache.tlfCounts[tlfID])
if err != nil {
return 0, 0, err
}
rng := &util.Range{
Start: append(tlfBytes, blockID.Bytes()...),
Limit: append(tlfBytes, cache.maxBlockID...),
}
// Extra func exists to make defers work.
func() {
iter := cache.tlfDb.NewIterator(rng, nil)
defer iter.Release()
for i := 0; i < numElements; i++ {
if !iter.Next() {
break
}
key := iter.Key()
blockIDBytes := key[len(tlfBytes):]
blockID, err := kbfsblock.IDFromBytes(blockIDBytes)
if err != nil {
cache.log.CWarningf(ctx, "Error decoding block ID %x", blockIDBytes)
continue
}
lru, err := cache.getLRULocked(blockID)
if err != nil {
cache.log.CWarningf(ctx, "Error decoding LRU time for block %s",
blockID)
continue
}
blockIDs = append(blockIDs, lruEntry{blockID, lru})
}
}()
if len(blockIDs) == numElements {
break
}
}
// Evict some of the selected blocks.
currNumRemoved, currSizeRemoved, err := cache.evictSomeBlocks(ctx,
numBlocks-numRemoved, blockIDs)
if err != nil {
return numRemoved, sizeRemoved, err
}
// Update the evicted count.
numRemoved += currNumRemoved
sizeRemoved += currSizeRemoved
}
return numRemoved, sizeRemoved, nil
} | [
"func",
"(",
"cache",
"*",
"DiskBlockCacheLocal",
")",
"evictLocked",
"(",
"ctx",
"context",
".",
"Context",
",",
"numBlocks",
"int",
")",
"(",
"numRemoved",
"int",
",",
"sizeRemoved",
"int64",
",",
"err",
"error",
")",
"{",
"numRemoved",
"=",
"0",
"\n",
... | // evictLocked evicts a number of blocks from the cache. We search the lowest
// eviction priority level for blocks to evict first, then the next highest
// priority and so on until enough blocks have been evicted. Within each
// priority, we first shuffle the TLFs, weighting by how many blocks they
// contain, and then we take the top TLFs from that shuffle and evict the
// least recently used blocks from them. | [
"evictLocked",
"evicts",
"a",
"number",
"of",
"blocks",
"from",
"the",
"cache",
".",
"We",
"search",
"the",
"lowest",
"eviction",
"priority",
"level",
"for",
"blocks",
"to",
"evict",
"first",
"then",
"the",
"next",
"highest",
"priority",
"and",
"so",
"on",
... | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/disk_block_cache.go#L1026-L1105 |
160,189 | keybase/client | go/kbfs/libkbfs/disk_block_cache.go | ClearAllTlfBlocks | func (cache *DiskBlockCacheLocal) ClearAllTlfBlocks(
ctx context.Context, tlfID tlf.ID) (err error) {
defer func() {
cache.log.CDebugf(ctx,
"Finished clearing blocks from %s: %+v", tlfID, err)
}()
// Delete the blocks in batches, so we don't keep the lock for too
// long.
for {
cache.log.CDebugf(ctx, "Deleting a batch of blocks from %s", tlfID)
numLeft, err := cache.deleteNextBatchFromClearedTlf(ctx, tlfID)
if err != nil {
return err
}
if numLeft == 0 {
cache.log.CDebugf(ctx, "Deleted all blocks from %s", tlfID)
return nil
}
cache.log.CDebugf(
ctx, "%d blocks left to delete from %s", numLeft, tlfID)
c := time.After(cache.clearTickerDuration)
select {
case <-c:
case <-ctx.Done():
return ctx.Err()
}
}
} | go | func (cache *DiskBlockCacheLocal) ClearAllTlfBlocks(
ctx context.Context, tlfID tlf.ID) (err error) {
defer func() {
cache.log.CDebugf(ctx,
"Finished clearing blocks from %s: %+v", tlfID, err)
}()
// Delete the blocks in batches, so we don't keep the lock for too
// long.
for {
cache.log.CDebugf(ctx, "Deleting a batch of blocks from %s", tlfID)
numLeft, err := cache.deleteNextBatchFromClearedTlf(ctx, tlfID)
if err != nil {
return err
}
if numLeft == 0 {
cache.log.CDebugf(ctx, "Deleted all blocks from %s", tlfID)
return nil
}
cache.log.CDebugf(
ctx, "%d blocks left to delete from %s", numLeft, tlfID)
c := time.After(cache.clearTickerDuration)
select {
case <-c:
case <-ctx.Done():
return ctx.Err()
}
}
} | [
"func",
"(",
"cache",
"*",
"DiskBlockCacheLocal",
")",
"ClearAllTlfBlocks",
"(",
"ctx",
"context",
".",
"Context",
",",
"tlfID",
"tlf",
".",
"ID",
")",
"(",
"err",
"error",
")",
"{",
"defer",
"func",
"(",
")",
"{",
"cache",
".",
"log",
".",
"CDebugf",
... | // ClearAllTlfBlocks implements the DiskBlockCache interface for
// DiskBlockCacheLocal. | [
"ClearAllTlfBlocks",
"implements",
"the",
"DiskBlockCache",
"interface",
"for",
"DiskBlockCacheLocal",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/disk_block_cache.go#L1132-L1161 |
160,190 | keybase/client | go/kbfs/libkbfs/disk_block_cache.go | GetLastUnrefRev | func (cache *DiskBlockCacheLocal) GetLastUnrefRev(
ctx context.Context, tlfID tlf.ID) (kbfsmd.Revision, error) {
cache.lock.RLock()
defer cache.lock.RUnlock()
err := cache.checkCacheLocked("Block(GetLastUnrefRev)")
if err != nil {
return kbfsmd.RevisionUninitialized, err
}
rev, ok := cache.tlfLastUnrefs[tlfID]
if !ok {
// No known unref'd revision.
return kbfsmd.RevisionUninitialized, nil
}
return rev, nil
} | go | func (cache *DiskBlockCacheLocal) GetLastUnrefRev(
ctx context.Context, tlfID tlf.ID) (kbfsmd.Revision, error) {
cache.lock.RLock()
defer cache.lock.RUnlock()
err := cache.checkCacheLocked("Block(GetLastUnrefRev)")
if err != nil {
return kbfsmd.RevisionUninitialized, err
}
rev, ok := cache.tlfLastUnrefs[tlfID]
if !ok {
// No known unref'd revision.
return kbfsmd.RevisionUninitialized, nil
}
return rev, nil
} | [
"func",
"(",
"cache",
"*",
"DiskBlockCacheLocal",
")",
"GetLastUnrefRev",
"(",
"ctx",
"context",
".",
"Context",
",",
"tlfID",
"tlf",
".",
"ID",
")",
"(",
"kbfsmd",
".",
"Revision",
",",
"error",
")",
"{",
"cache",
".",
"lock",
".",
"RLock",
"(",
")",
... | // GetLastUnrefRev implements the DiskBlockCache interface for
// DiskBlockCacheLocal. | [
"GetLastUnrefRev",
"implements",
"the",
"DiskBlockCache",
"interface",
"for",
"DiskBlockCacheLocal",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/disk_block_cache.go#L1165-L1180 |
160,191 | keybase/client | go/kbfs/libkbfs/disk_block_cache.go | PutLastUnrefRev | func (cache *DiskBlockCacheLocal) PutLastUnrefRev(
ctx context.Context, tlfID tlf.ID, rev kbfsmd.Revision) error {
cache.lock.Lock()
defer cache.lock.Unlock()
err := cache.checkCacheLocked("Block(PutLastUnrefRev)")
if err != nil {
return err
}
if currRev, ok := cache.tlfLastUnrefs[tlfID]; ok {
if rev <= currRev {
// A later revision has already been unref'd, so ignore this.
return nil
}
}
buf, err := cache.encodeLastUnref(rev)
if err != nil {
return err
}
err = cache.lastUnrefDb.Put(tlfID.Bytes(), buf, nil)
if err != nil {
return err
}
cache.tlfLastUnrefs[tlfID] = rev
return nil
} | go | func (cache *DiskBlockCacheLocal) PutLastUnrefRev(
ctx context.Context, tlfID tlf.ID, rev kbfsmd.Revision) error {
cache.lock.Lock()
defer cache.lock.Unlock()
err := cache.checkCacheLocked("Block(PutLastUnrefRev)")
if err != nil {
return err
}
if currRev, ok := cache.tlfLastUnrefs[tlfID]; ok {
if rev <= currRev {
// A later revision has already been unref'd, so ignore this.
return nil
}
}
buf, err := cache.encodeLastUnref(rev)
if err != nil {
return err
}
err = cache.lastUnrefDb.Put(tlfID.Bytes(), buf, nil)
if err != nil {
return err
}
cache.tlfLastUnrefs[tlfID] = rev
return nil
} | [
"func",
"(",
"cache",
"*",
"DiskBlockCacheLocal",
")",
"PutLastUnrefRev",
"(",
"ctx",
"context",
".",
"Context",
",",
"tlfID",
"tlf",
".",
"ID",
",",
"rev",
"kbfsmd",
".",
"Revision",
")",
"error",
"{",
"cache",
".",
"lock",
".",
"Lock",
"(",
")",
"\n"... | // PutLastUnrefRev implements the DiskBlockCache interface for
// DiskBlockCacheLocal. | [
"PutLastUnrefRev",
"implements",
"the",
"DiskBlockCache",
"interface",
"for",
"DiskBlockCacheLocal",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/disk_block_cache.go#L1184-L1210 |
160,192 | keybase/client | go/kbfs/libkbfs/disk_block_cache.go | Status | func (cache *DiskBlockCacheLocal) Status(
ctx context.Context) map[string]DiskBlockCacheStatus {
var name string
var maxLimit uint64
limiterStatus := cache.config.DiskLimiter().getStatus(
ctx, keybase1.UserOrTeamID("")).(backpressureDiskLimiterStatus)
switch cache.cacheType {
case syncCacheLimitTrackerType:
name = syncCacheName
maxLimit = uint64(limiterStatus.SyncCacheByteStatus.Max)
case workingSetCacheLimitTrackerType:
name = workingSetCacheName
maxLimit = uint64(limiterStatus.DiskCacheByteStatus.Max)
case crDirtyBlockCacheLimitTrackerType:
name = crDirtyBlockCacheName
}
select {
case <-cache.startedCh:
case <-cache.startErrCh:
return map[string]DiskBlockCacheStatus{name: {StartState: DiskBlockCacheStartStateFailed}}
default:
return map[string]DiskBlockCacheStatus{name: {StartState: DiskBlockCacheStartStateStarting}}
}
availableBytes, totalBytes := uint64(math.MaxInt64), uint64(math.MaxInt64)
if cache.dirPath != "" {
var err error
availableBytes, totalBytes, _, _, err = getDiskLimits(cache.dirPath)
if err != nil {
cache.log.CDebugf(ctx, "Couldn't get disk stats: %+v", err)
}
}
cache.lock.RLock()
defer cache.lock.RUnlock()
// The disk cache status doesn't depend on the chargedTo ID, and
// we don't have easy access to the UID here, so pass in a dummy.
return map[string]DiskBlockCacheStatus{
name: {
StartState: DiskBlockCacheStartStateStarted,
NumBlocks: uint64(cache.numBlocks),
BlockBytes: cache.getCurrBytes(),
CurrByteLimit: maxLimit,
LastUnrefCount: uint64(len(cache.tlfLastUnrefs)),
Hits: rateMeterToStatus(cache.hitMeter),
Misses: rateMeterToStatus(cache.missMeter),
Puts: rateMeterToStatus(cache.putMeter),
MetadataUpdates: rateMeterToStatus(cache.updateMeter),
NumEvicted: rateMeterToStatus(cache.evictCountMeter),
SizeEvicted: rateMeterToStatus(cache.evictSizeMeter),
NumDeleted: rateMeterToStatus(cache.deleteCountMeter),
SizeDeleted: rateMeterToStatus(cache.deleteSizeMeter),
LocalDiskBytesAvailable: availableBytes,
LocalDiskBytesTotal: totalBytes,
},
}
} | go | func (cache *DiskBlockCacheLocal) Status(
ctx context.Context) map[string]DiskBlockCacheStatus {
var name string
var maxLimit uint64
limiterStatus := cache.config.DiskLimiter().getStatus(
ctx, keybase1.UserOrTeamID("")).(backpressureDiskLimiterStatus)
switch cache.cacheType {
case syncCacheLimitTrackerType:
name = syncCacheName
maxLimit = uint64(limiterStatus.SyncCacheByteStatus.Max)
case workingSetCacheLimitTrackerType:
name = workingSetCacheName
maxLimit = uint64(limiterStatus.DiskCacheByteStatus.Max)
case crDirtyBlockCacheLimitTrackerType:
name = crDirtyBlockCacheName
}
select {
case <-cache.startedCh:
case <-cache.startErrCh:
return map[string]DiskBlockCacheStatus{name: {StartState: DiskBlockCacheStartStateFailed}}
default:
return map[string]DiskBlockCacheStatus{name: {StartState: DiskBlockCacheStartStateStarting}}
}
availableBytes, totalBytes := uint64(math.MaxInt64), uint64(math.MaxInt64)
if cache.dirPath != "" {
var err error
availableBytes, totalBytes, _, _, err = getDiskLimits(cache.dirPath)
if err != nil {
cache.log.CDebugf(ctx, "Couldn't get disk stats: %+v", err)
}
}
cache.lock.RLock()
defer cache.lock.RUnlock()
// The disk cache status doesn't depend on the chargedTo ID, and
// we don't have easy access to the UID here, so pass in a dummy.
return map[string]DiskBlockCacheStatus{
name: {
StartState: DiskBlockCacheStartStateStarted,
NumBlocks: uint64(cache.numBlocks),
BlockBytes: cache.getCurrBytes(),
CurrByteLimit: maxLimit,
LastUnrefCount: uint64(len(cache.tlfLastUnrefs)),
Hits: rateMeterToStatus(cache.hitMeter),
Misses: rateMeterToStatus(cache.missMeter),
Puts: rateMeterToStatus(cache.putMeter),
MetadataUpdates: rateMeterToStatus(cache.updateMeter),
NumEvicted: rateMeterToStatus(cache.evictCountMeter),
SizeEvicted: rateMeterToStatus(cache.evictSizeMeter),
NumDeleted: rateMeterToStatus(cache.deleteCountMeter),
SizeDeleted: rateMeterToStatus(cache.deleteSizeMeter),
LocalDiskBytesAvailable: availableBytes,
LocalDiskBytesTotal: totalBytes,
},
}
} | [
"func",
"(",
"cache",
"*",
"DiskBlockCacheLocal",
")",
"Status",
"(",
"ctx",
"context",
".",
"Context",
")",
"map",
"[",
"string",
"]",
"DiskBlockCacheStatus",
"{",
"var",
"name",
"string",
"\n",
"var",
"maxLimit",
"uint64",
"\n",
"limiterStatus",
":=",
"cac... | // Status implements the DiskBlockCache interface for DiskBlockCacheLocal. | [
"Status",
"implements",
"the",
"DiskBlockCache",
"interface",
"for",
"DiskBlockCacheLocal",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/disk_block_cache.go#L1213-L1268 |
160,193 | keybase/client | go/kbfs/libkbfs/disk_block_cache.go | DoesCacheHaveSpace | func (cache *DiskBlockCacheLocal) DoesCacheHaveSpace(
ctx context.Context) bool {
limiterStatus := cache.config.DiskLimiter().getStatus(
ctx, keybase1.UserOrTeamID("")).(backpressureDiskLimiterStatus)
switch cache.cacheType {
case syncCacheLimitTrackerType:
return limiterStatus.SyncCacheByteStatus.UsedFrac <= .99
case workingSetCacheLimitTrackerType:
return limiterStatus.DiskCacheByteStatus.UsedFrac <= .99
case crDirtyBlockCacheLimitTrackerType:
return true
default:
panic(fmt.Sprintf("Unknown cache type: %d", cache.cacheType))
}
} | go | func (cache *DiskBlockCacheLocal) DoesCacheHaveSpace(
ctx context.Context) bool {
limiterStatus := cache.config.DiskLimiter().getStatus(
ctx, keybase1.UserOrTeamID("")).(backpressureDiskLimiterStatus)
switch cache.cacheType {
case syncCacheLimitTrackerType:
return limiterStatus.SyncCacheByteStatus.UsedFrac <= .99
case workingSetCacheLimitTrackerType:
return limiterStatus.DiskCacheByteStatus.UsedFrac <= .99
case crDirtyBlockCacheLimitTrackerType:
return true
default:
panic(fmt.Sprintf("Unknown cache type: %d", cache.cacheType))
}
} | [
"func",
"(",
"cache",
"*",
"DiskBlockCacheLocal",
")",
"DoesCacheHaveSpace",
"(",
"ctx",
"context",
".",
"Context",
")",
"bool",
"{",
"limiterStatus",
":=",
"cache",
".",
"config",
".",
"DiskLimiter",
"(",
")",
".",
"getStatus",
"(",
"ctx",
",",
"keybase1",
... | // DoesCacheHaveSpace returns true if we have more than 1% of space
// left in the cache. | [
"DoesCacheHaveSpace",
"returns",
"true",
"if",
"we",
"have",
"more",
"than",
"1%",
"of",
"space",
"left",
"in",
"the",
"cache",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/disk_block_cache.go#L1272-L1286 |
160,194 | keybase/client | go/kbfs/libkbfs/disk_block_cache.go | Mark | func (cache *DiskBlockCacheLocal) Mark(
ctx context.Context, blockID kbfsblock.ID, tag string) error {
cache.lock.Lock()
defer cache.lock.Unlock()
err := cache.checkCacheLocked("Block(UpdateMetadata)")
if err != nil {
return err
}
md, err := cache.getMetadataLocked(blockID, false)
if err != nil {
return data.NoSuchBlockError{ID: blockID}
}
md.Tag = tag
return cache.updateMetadataLocked(ctx, blockID.Bytes(), md, false)
} | go | func (cache *DiskBlockCacheLocal) Mark(
ctx context.Context, blockID kbfsblock.ID, tag string) error {
cache.lock.Lock()
defer cache.lock.Unlock()
err := cache.checkCacheLocked("Block(UpdateMetadata)")
if err != nil {
return err
}
md, err := cache.getMetadataLocked(blockID, false)
if err != nil {
return data.NoSuchBlockError{ID: blockID}
}
md.Tag = tag
return cache.updateMetadataLocked(ctx, blockID.Bytes(), md, false)
} | [
"func",
"(",
"cache",
"*",
"DiskBlockCacheLocal",
")",
"Mark",
"(",
"ctx",
"context",
".",
"Context",
",",
"blockID",
"kbfsblock",
".",
"ID",
",",
"tag",
"string",
")",
"error",
"{",
"cache",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"cache",
... | // Mark updates the metadata of the given block with the tag. | [
"Mark",
"updates",
"the",
"metadata",
"of",
"the",
"given",
"block",
"with",
"the",
"tag",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/disk_block_cache.go#L1289-L1304 |
160,195 | keybase/client | go/kbfs/libkbfs/disk_block_cache.go | DeleteUnmarked | func (cache *DiskBlockCacheLocal) DeleteUnmarked(
ctx context.Context, tlfID tlf.ID, tag string) (err error) {
defer func() {
cache.log.CDebugf(ctx,
"Finished deleting unmarked blocks (tag=%s) from %s: %+v",
tag, tlfID, err)
}()
// Delete the blocks in batches, so we don't keep the lock for too
// long.
startingKey := cache.tlfKey(tlfID, nil)
for {
cache.log.CDebugf(
ctx, "Deleting a batch of unmarked blocks (tag=%s) from %s",
tag, tlfID)
startingKey, err = cache.deleteNextUnmarkedBatchFromTlf(
ctx, tlfID, tag, startingKey)
if err != nil {
return err
}
if startingKey == nil {
return nil
}
c := time.After(cache.clearTickerDuration)
select {
case <-c:
case <-ctx.Done():
return ctx.Err()
}
}
} | go | func (cache *DiskBlockCacheLocal) DeleteUnmarked(
ctx context.Context, tlfID tlf.ID, tag string) (err error) {
defer func() {
cache.log.CDebugf(ctx,
"Finished deleting unmarked blocks (tag=%s) from %s: %+v",
tag, tlfID, err)
}()
// Delete the blocks in batches, so we don't keep the lock for too
// long.
startingKey := cache.tlfKey(tlfID, nil)
for {
cache.log.CDebugf(
ctx, "Deleting a batch of unmarked blocks (tag=%s) from %s",
tag, tlfID)
startingKey, err = cache.deleteNextUnmarkedBatchFromTlf(
ctx, tlfID, tag, startingKey)
if err != nil {
return err
}
if startingKey == nil {
return nil
}
c := time.After(cache.clearTickerDuration)
select {
case <-c:
case <-ctx.Done():
return ctx.Err()
}
}
} | [
"func",
"(",
"cache",
"*",
"DiskBlockCacheLocal",
")",
"DeleteUnmarked",
"(",
"ctx",
"context",
".",
"Context",
",",
"tlfID",
"tlf",
".",
"ID",
",",
"tag",
"string",
")",
"(",
"err",
"error",
")",
"{",
"defer",
"func",
"(",
")",
"{",
"cache",
".",
"l... | // DeleteUnmarked deletes all the blocks without the given tag. | [
"DeleteUnmarked",
"deletes",
"all",
"the",
"blocks",
"without",
"the",
"given",
"tag",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/disk_block_cache.go#L1370-L1401 |
160,196 | keybase/client | go/kbfs/libkbfs/disk_block_cache.go | AddHomeTLF | func (cache *DiskBlockCacheLocal) AddHomeTLF(ctx context.Context, tlfID tlf.ID) error {
cache.lock.Lock()
defer cache.lock.Unlock()
cache.priorityBlockCounts[cache.homeDirs[tlfID]] -= cache.tlfCounts[tlfID]
cache.priorityTlfMap[cache.homeDirs[tlfID]][tlfID] -= cache.tlfCounts[tlfID]
switch tlfID.Type() {
case tlf.Private:
cache.homeDirs[tlfID] = priorityPrivateHome
case tlf.Public:
cache.homeDirs[tlfID] = priorityPublicHome
default:
return errTeamOrUnknownTLFAddedAsHome
}
cache.priorityBlockCounts[cache.homeDirs[tlfID]] += cache.tlfCounts[tlfID]
cache.priorityTlfMap[cache.homeDirs[tlfID]][tlfID] += cache.tlfCounts[tlfID]
return nil
} | go | func (cache *DiskBlockCacheLocal) AddHomeTLF(ctx context.Context, tlfID tlf.ID) error {
cache.lock.Lock()
defer cache.lock.Unlock()
cache.priorityBlockCounts[cache.homeDirs[tlfID]] -= cache.tlfCounts[tlfID]
cache.priorityTlfMap[cache.homeDirs[tlfID]][tlfID] -= cache.tlfCounts[tlfID]
switch tlfID.Type() {
case tlf.Private:
cache.homeDirs[tlfID] = priorityPrivateHome
case tlf.Public:
cache.homeDirs[tlfID] = priorityPublicHome
default:
return errTeamOrUnknownTLFAddedAsHome
}
cache.priorityBlockCounts[cache.homeDirs[tlfID]] += cache.tlfCounts[tlfID]
cache.priorityTlfMap[cache.homeDirs[tlfID]][tlfID] += cache.tlfCounts[tlfID]
return nil
} | [
"func",
"(",
"cache",
"*",
"DiskBlockCacheLocal",
")",
"AddHomeTLF",
"(",
"ctx",
"context",
".",
"Context",
",",
"tlfID",
"tlf",
".",
"ID",
")",
"error",
"{",
"cache",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"cache",
".",
"lock",
".",
"Unl... | // AddHomeTLF implements this DiskBlockCache interace for DiskBlockCacheLocal. | [
"AddHomeTLF",
"implements",
"this",
"DiskBlockCache",
"interace",
"for",
"DiskBlockCacheLocal",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/disk_block_cache.go#L1404-L1422 |
160,197 | keybase/client | go/kbfs/libkbfs/disk_block_cache.go | ClearHomeTLFs | func (cache *DiskBlockCacheLocal) ClearHomeTLFs(ctx context.Context) error {
cache.lock.Lock()
defer cache.lock.Unlock()
for tlfID, priority := range cache.homeDirs {
cache.priorityBlockCounts[priority] -= cache.tlfCounts[tlfID]
cache.priorityTlfMap[priority][tlfID] -= cache.tlfCounts[tlfID]
cache.priorityBlockCounts[priorityNotHome] += cache.tlfCounts[tlfID]
cache.priorityTlfMap[priorityNotHome][tlfID] += cache.tlfCounts[tlfID]
}
cache.homeDirs = make(map[tlf.ID]evictionPriority)
return nil
} | go | func (cache *DiskBlockCacheLocal) ClearHomeTLFs(ctx context.Context) error {
cache.lock.Lock()
defer cache.lock.Unlock()
for tlfID, priority := range cache.homeDirs {
cache.priorityBlockCounts[priority] -= cache.tlfCounts[tlfID]
cache.priorityTlfMap[priority][tlfID] -= cache.tlfCounts[tlfID]
cache.priorityBlockCounts[priorityNotHome] += cache.tlfCounts[tlfID]
cache.priorityTlfMap[priorityNotHome][tlfID] += cache.tlfCounts[tlfID]
}
cache.homeDirs = make(map[tlf.ID]evictionPriority)
return nil
} | [
"func",
"(",
"cache",
"*",
"DiskBlockCacheLocal",
")",
"ClearHomeTLFs",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"cache",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"cache",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"for",
... | // ClearHomeTLFs implements this DiskBlockCache interace for
// DiskBlockCacheLocal. | [
"ClearHomeTLFs",
"implements",
"this",
"DiskBlockCache",
"interace",
"for",
"DiskBlockCacheLocal",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/disk_block_cache.go#L1426-L1437 |
160,198 | keybase/client | go/kbfs/libkbfs/disk_block_cache.go | GetTlfSize | func (cache *DiskBlockCacheLocal) GetTlfSize(
_ context.Context, tlfID tlf.ID) (uint64, error) {
cache.lock.RLock()
defer cache.lock.RUnlock()
return cache.tlfSizes[tlfID], nil
} | go | func (cache *DiskBlockCacheLocal) GetTlfSize(
_ context.Context, tlfID tlf.ID) (uint64, error) {
cache.lock.RLock()
defer cache.lock.RUnlock()
return cache.tlfSizes[tlfID], nil
} | [
"func",
"(",
"cache",
"*",
"DiskBlockCacheLocal",
")",
"GetTlfSize",
"(",
"_",
"context",
".",
"Context",
",",
"tlfID",
"tlf",
".",
"ID",
")",
"(",
"uint64",
",",
"error",
")",
"{",
"cache",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"cache"... | // GetTlfSize returns the number of bytes stored for the given TLF in
// the cache. | [
"GetTlfSize",
"returns",
"the",
"number",
"of",
"bytes",
"stored",
"for",
"the",
"given",
"TLF",
"in",
"the",
"cache",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/disk_block_cache.go#L1441-L1446 |
160,199 | keybase/client | go/kbfs/libkbfs/disk_block_cache.go | GetTlfIDs | func (cache *DiskBlockCacheLocal) GetTlfIDs(
_ context.Context) (tlfIDs []tlf.ID, err error) {
cache.lock.RLock()
defer cache.lock.RUnlock()
tlfIDs = make([]tlf.ID, 0, len(cache.tlfSizes))
for id := range cache.tlfSizes {
tlfIDs = append(tlfIDs, id)
}
return tlfIDs, nil
} | go | func (cache *DiskBlockCacheLocal) GetTlfIDs(
_ context.Context) (tlfIDs []tlf.ID, err error) {
cache.lock.RLock()
defer cache.lock.RUnlock()
tlfIDs = make([]tlf.ID, 0, len(cache.tlfSizes))
for id := range cache.tlfSizes {
tlfIDs = append(tlfIDs, id)
}
return tlfIDs, nil
} | [
"func",
"(",
"cache",
"*",
"DiskBlockCacheLocal",
")",
"GetTlfIDs",
"(",
"_",
"context",
".",
"Context",
")",
"(",
"tlfIDs",
"[",
"]",
"tlf",
".",
"ID",
",",
"err",
"error",
")",
"{",
"cache",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"ca... | // GetTlfIDs returns the IDs of all the TLFs with blocks stored in
// the cache. | [
"GetTlfIDs",
"returns",
"the",
"IDs",
"of",
"all",
"the",
"TLFs",
"with",
"blocks",
"stored",
"in",
"the",
"cache",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/disk_block_cache.go#L1450-L1459 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.