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
sequencelengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
sequencelengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
161,200 | keybase/client | go/kbfs/kbfsmd/merkle_leaf.go | Encrypt | func (l MerkleLeaf) Encrypt(codec kbfscodec.Codec,
pubKey kbfscrypto.TLFPublicKey, nonce *[24]byte,
ePrivKey kbfscrypto.TLFEphemeralPrivateKey) (EncryptedMerkleLeaf, error) {
// encode the clear-text leaf
leafBytes, err := codec.Encode(l)
if err != nil {
return EncryptedMerkleLeaf{}, err
}
// encrypt the encoded leaf
pubKeyData := pubKey.Data()
privKeyData := ePrivKey.Data()
encryptedData := box.Seal(
nil, leafBytes[:], nonce, &pubKeyData, &privKeyData)
return EncryptedMerkleLeaf{
Version: kbfscrypto.EncryptionSecretbox,
EncryptedData: encryptedData,
}, nil
} | go | func (l MerkleLeaf) Encrypt(codec kbfscodec.Codec,
pubKey kbfscrypto.TLFPublicKey, nonce *[24]byte,
ePrivKey kbfscrypto.TLFEphemeralPrivateKey) (EncryptedMerkleLeaf, error) {
// encode the clear-text leaf
leafBytes, err := codec.Encode(l)
if err != nil {
return EncryptedMerkleLeaf{}, err
}
// encrypt the encoded leaf
pubKeyData := pubKey.Data()
privKeyData := ePrivKey.Data()
encryptedData := box.Seal(
nil, leafBytes[:], nonce, &pubKeyData, &privKeyData)
return EncryptedMerkleLeaf{
Version: kbfscrypto.EncryptionSecretbox,
EncryptedData: encryptedData,
}, nil
} | [
"func",
"(",
"l",
"MerkleLeaf",
")",
"Encrypt",
"(",
"codec",
"kbfscodec",
".",
"Codec",
",",
"pubKey",
"kbfscrypto",
".",
"TLFPublicKey",
",",
"nonce",
"*",
"[",
"24",
"]",
"byte",
",",
"ePrivKey",
"kbfscrypto",
".",
"TLFEphemeralPrivateKey",
")",
"(",
"EncryptedMerkleLeaf",
",",
"error",
")",
"{",
"// encode the clear-text leaf",
"leafBytes",
",",
"err",
":=",
"codec",
".",
"Encode",
"(",
"l",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"EncryptedMerkleLeaf",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"// encrypt the encoded leaf",
"pubKeyData",
":=",
"pubKey",
".",
"Data",
"(",
")",
"\n",
"privKeyData",
":=",
"ePrivKey",
".",
"Data",
"(",
")",
"\n",
"encryptedData",
":=",
"box",
".",
"Seal",
"(",
"nil",
",",
"leafBytes",
"[",
":",
"]",
",",
"nonce",
",",
"&",
"pubKeyData",
",",
"&",
"privKeyData",
")",
"\n",
"return",
"EncryptedMerkleLeaf",
"{",
"Version",
":",
"kbfscrypto",
".",
"EncryptionSecretbox",
",",
"EncryptedData",
":",
"encryptedData",
",",
"}",
",",
"nil",
"\n",
"}"
] | // Encrypt encrypts a Merkle leaf node with the given key pair. | [
"Encrypt",
"encrypts",
"a",
"Merkle",
"leaf",
"node",
"with",
"the",
"given",
"key",
"pair",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/kbfsmd/merkle_leaf.go#L44-L61 |
161,201 | keybase/client | go/kbfs/kbfsmd/merkle_leaf.go | Decrypt | func (el EncryptedMerkleLeaf) Decrypt(codec kbfscodec.Codec,
privKey kbfscrypto.TLFPrivateKey, nonce *[24]byte,
ePubKey kbfscrypto.TLFEphemeralPublicKey) (MerkleLeaf, error) {
eLeaf := kbfscrypto.MakeEncryptedMerkleLeaf(
el.Version, el.EncryptedData, nonce)
leafBytes, err := kbfscrypto.DecryptMerkleLeaf(privKey, ePubKey, eLeaf)
if err != nil {
return MerkleLeaf{}, err
}
// decode the leaf
var leaf MerkleLeaf
if err := codec.Decode(leafBytes, &leaf); err != nil {
return MerkleLeaf{}, err
}
return leaf, nil
} | go | func (el EncryptedMerkleLeaf) Decrypt(codec kbfscodec.Codec,
privKey kbfscrypto.TLFPrivateKey, nonce *[24]byte,
ePubKey kbfscrypto.TLFEphemeralPublicKey) (MerkleLeaf, error) {
eLeaf := kbfscrypto.MakeEncryptedMerkleLeaf(
el.Version, el.EncryptedData, nonce)
leafBytes, err := kbfscrypto.DecryptMerkleLeaf(privKey, ePubKey, eLeaf)
if err != nil {
return MerkleLeaf{}, err
}
// decode the leaf
var leaf MerkleLeaf
if err := codec.Decode(leafBytes, &leaf); err != nil {
return MerkleLeaf{}, err
}
return leaf, nil
} | [
"func",
"(",
"el",
"EncryptedMerkleLeaf",
")",
"Decrypt",
"(",
"codec",
"kbfscodec",
".",
"Codec",
",",
"privKey",
"kbfscrypto",
".",
"TLFPrivateKey",
",",
"nonce",
"*",
"[",
"24",
"]",
"byte",
",",
"ePubKey",
"kbfscrypto",
".",
"TLFEphemeralPublicKey",
")",
"(",
"MerkleLeaf",
",",
"error",
")",
"{",
"eLeaf",
":=",
"kbfscrypto",
".",
"MakeEncryptedMerkleLeaf",
"(",
"el",
".",
"Version",
",",
"el",
".",
"EncryptedData",
",",
"nonce",
")",
"\n",
"leafBytes",
",",
"err",
":=",
"kbfscrypto",
".",
"DecryptMerkleLeaf",
"(",
"privKey",
",",
"ePubKey",
",",
"eLeaf",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"MerkleLeaf",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"// decode the leaf",
"var",
"leaf",
"MerkleLeaf",
"\n",
"if",
"err",
":=",
"codec",
".",
"Decode",
"(",
"leafBytes",
",",
"&",
"leaf",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"MerkleLeaf",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"return",
"leaf",
",",
"nil",
"\n",
"}"
] | // Decrypt decrypts a Merkle leaf node with the given key pair. | [
"Decrypt",
"decrypts",
"a",
"Merkle",
"leaf",
"node",
"with",
"the",
"given",
"key",
"pair",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/kbfsmd/merkle_leaf.go#L64-L79 |
161,202 | keybase/client | go/libkb/pipeowner_windows.go | currentProcessUserSid | func currentProcessUserSid() (*windows.SID, error) {
tok, err := windows.OpenCurrentProcessToken()
if err != nil {
return nil, err
}
defer tok.Close()
tokUser, err := tok.GetTokenUser()
if err != nil {
return nil, err
}
return (*windows.SID)(tokUser.User.Sid), nil
} | go | func currentProcessUserSid() (*windows.SID, error) {
tok, err := windows.OpenCurrentProcessToken()
if err != nil {
return nil, err
}
defer tok.Close()
tokUser, err := tok.GetTokenUser()
if err != nil {
return nil, err
}
return (*windows.SID)(tokUser.User.Sid), nil
} | [
"func",
"currentProcessUserSid",
"(",
")",
"(",
"*",
"windows",
".",
"SID",
",",
"error",
")",
"{",
"tok",
",",
"err",
":=",
"windows",
".",
"OpenCurrentProcessToken",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"tok",
".",
"Close",
"(",
")",
"\n",
"tokUser",
",",
"err",
":=",
"tok",
".",
"GetTokenUser",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"(",
"*",
"windows",
".",
"SID",
")",
"(",
"tokUser",
".",
"User",
".",
"Sid",
")",
",",
"nil",
"\n",
"}"
] | // currentProcessUserSid is a utility to get the
// SID of the current user running the process. | [
"currentProcessUserSid",
"is",
"a",
"utility",
"to",
"get",
"the",
"SID",
"of",
"the",
"current",
"user",
"running",
"the",
"process",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/pipeowner_windows.go#L46-L57 |
161,203 | keybase/client | go/libkb/pipeowner_windows.go | GetFileUserSid | func GetFileUserSid(name string) (*windows.SID, error) {
var userSID *windows.SID
var secDesc windows.Handle
err := GetNamedSecurityInfo(name, SE_FILE_OBJECT, OWNER_SECURITY_INFORMATION, &userSID, nil, nil, nil, &secDesc)
if err != nil {
return nil, err
}
return userSID, nil
} | go | func GetFileUserSid(name string) (*windows.SID, error) {
var userSID *windows.SID
var secDesc windows.Handle
err := GetNamedSecurityInfo(name, SE_FILE_OBJECT, OWNER_SECURITY_INFORMATION, &userSID, nil, nil, nil, &secDesc)
if err != nil {
return nil, err
}
return userSID, nil
} | [
"func",
"GetFileUserSid",
"(",
"name",
"string",
")",
"(",
"*",
"windows",
".",
"SID",
",",
"error",
")",
"{",
"var",
"userSID",
"*",
"windows",
".",
"SID",
"\n",
"var",
"secDesc",
"windows",
".",
"Handle",
"\n\n",
"err",
":=",
"GetNamedSecurityInfo",
"(",
"name",
",",
"SE_FILE_OBJECT",
",",
"OWNER_SECURITY_INFORMATION",
",",
"&",
"userSID",
",",
"nil",
",",
"nil",
",",
"nil",
",",
"&",
"secDesc",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"userSID",
",",
"nil",
"\n",
"}"
] | // currentProcessUserSid is a utility to get the
// SID of the named pipe | [
"currentProcessUserSid",
"is",
"a",
"utility",
"to",
"get",
"the",
"SID",
"of",
"the",
"named",
"pipe"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/pipeowner_windows.go#L61-L70 |
161,204 | keybase/client | go/chat/retry.go | nextAttemptTime | func (f *FetchRetrier) nextAttemptTime(attempts int, lastAttempt time.Time) time.Time {
wait := time.Duration(float64(attempts) * fetchMultiplier * float64(fetchInitialInterval))
return lastAttempt.Add(time.Duration(wait))
} | go | func (f *FetchRetrier) nextAttemptTime(attempts int, lastAttempt time.Time) time.Time {
wait := time.Duration(float64(attempts) * fetchMultiplier * float64(fetchInitialInterval))
return lastAttempt.Add(time.Duration(wait))
} | [
"func",
"(",
"f",
"*",
"FetchRetrier",
")",
"nextAttemptTime",
"(",
"attempts",
"int",
",",
"lastAttempt",
"time",
".",
"Time",
")",
"time",
".",
"Time",
"{",
"wait",
":=",
"time",
".",
"Duration",
"(",
"float64",
"(",
"attempts",
")",
"*",
"fetchMultiplier",
"*",
"float64",
"(",
"fetchInitialInterval",
")",
")",
"\n",
"return",
"lastAttempt",
".",
"Add",
"(",
"time",
".",
"Duration",
"(",
"wait",
")",
")",
"\n",
"}"
] | // nextAttemptTime calculates the next try for a given retry item. It uses an exponential
// decay calculation. | [
"nextAttemptTime",
"calculates",
"the",
"next",
"try",
"for",
"a",
"given",
"retry",
"item",
".",
"It",
"uses",
"an",
"exponential",
"decay",
"calculation",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/chat/retry.go#L243-L246 |
161,205 | keybase/client | go/chat/retry.go | Failure | func (f *FetchRetrier) Failure(ctx context.Context, uid gregor1.UID, desc types.RetryDescription) (err error) {
f.Lock()
defer f.Unlock()
defer f.Trace(ctx, func() error { return err }, fmt.Sprintf("Failure(%s)", desc))()
if !f.running {
f.Debug(ctx, "Failure: not starting new retrier, not running")
return nil
}
key := f.key(uid, desc)
if _, ok := f.retriers[key]; !ok {
f.Debug(ctx, "Failure: spawning new retrier: desc: %s", desc)
control := newRetrierControl(desc)
f.retriers[key] = control
f.spawnRetrier(ctx, uid, desc, control)
}
return nil
} | go | func (f *FetchRetrier) Failure(ctx context.Context, uid gregor1.UID, desc types.RetryDescription) (err error) {
f.Lock()
defer f.Unlock()
defer f.Trace(ctx, func() error { return err }, fmt.Sprintf("Failure(%s)", desc))()
if !f.running {
f.Debug(ctx, "Failure: not starting new retrier, not running")
return nil
}
key := f.key(uid, desc)
if _, ok := f.retriers[key]; !ok {
f.Debug(ctx, "Failure: spawning new retrier: desc: %s", desc)
control := newRetrierControl(desc)
f.retriers[key] = control
f.spawnRetrier(ctx, uid, desc, control)
}
return nil
} | [
"func",
"(",
"f",
"*",
"FetchRetrier",
")",
"Failure",
"(",
"ctx",
"context",
".",
"Context",
",",
"uid",
"gregor1",
".",
"UID",
",",
"desc",
"types",
".",
"RetryDescription",
")",
"(",
"err",
"error",
")",
"{",
"f",
".",
"Lock",
"(",
")",
"\n",
"defer",
"f",
".",
"Unlock",
"(",
")",
"\n",
"defer",
"f",
".",
"Trace",
"(",
"ctx",
",",
"func",
"(",
")",
"error",
"{",
"return",
"err",
"}",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"desc",
")",
")",
"(",
")",
"\n",
"if",
"!",
"f",
".",
"running",
"{",
"f",
".",
"Debug",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"key",
":=",
"f",
".",
"key",
"(",
"uid",
",",
"desc",
")",
"\n",
"if",
"_",
",",
"ok",
":=",
"f",
".",
"retriers",
"[",
"key",
"]",
";",
"!",
"ok",
"{",
"f",
".",
"Debug",
"(",
"ctx",
",",
"\"",
"\"",
",",
"desc",
")",
"\n",
"control",
":=",
"newRetrierControl",
"(",
"desc",
")",
"\n",
"f",
".",
"retriers",
"[",
"key",
"]",
"=",
"control",
"\n",
"f",
".",
"spawnRetrier",
"(",
"ctx",
",",
"uid",
",",
"desc",
",",
"control",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Failure indicates a failure of type kind has happened when loading a conversation. | [
"Failure",
"indicates",
"a",
"failure",
"of",
"type",
"kind",
"has",
"happened",
"when",
"loading",
"a",
"conversation",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/chat/retry.go#L299-L316 |
161,206 | keybase/client | go/chat/retry.go | Success | func (f *FetchRetrier) Success(ctx context.Context, uid gregor1.UID, desc types.RetryDescription) (err error) {
f.Lock()
defer f.Unlock()
defer f.Trace(ctx, func() error { return err }, fmt.Sprintf("Success(%s)", desc))()
key := f.key(uid, desc)
if control, ok := f.retriers[key]; ok {
control.Shutdown()
}
return nil
} | go | func (f *FetchRetrier) Success(ctx context.Context, uid gregor1.UID, desc types.RetryDescription) (err error) {
f.Lock()
defer f.Unlock()
defer f.Trace(ctx, func() error { return err }, fmt.Sprintf("Success(%s)", desc))()
key := f.key(uid, desc)
if control, ok := f.retriers[key]; ok {
control.Shutdown()
}
return nil
} | [
"func",
"(",
"f",
"*",
"FetchRetrier",
")",
"Success",
"(",
"ctx",
"context",
".",
"Context",
",",
"uid",
"gregor1",
".",
"UID",
",",
"desc",
"types",
".",
"RetryDescription",
")",
"(",
"err",
"error",
")",
"{",
"f",
".",
"Lock",
"(",
")",
"\n",
"defer",
"f",
".",
"Unlock",
"(",
")",
"\n",
"defer",
"f",
".",
"Trace",
"(",
"ctx",
",",
"func",
"(",
")",
"error",
"{",
"return",
"err",
"}",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"desc",
")",
")",
"(",
")",
"\n\n",
"key",
":=",
"f",
".",
"key",
"(",
"uid",
",",
"desc",
")",
"\n",
"if",
"control",
",",
"ok",
":=",
"f",
".",
"retriers",
"[",
"key",
"]",
";",
"ok",
"{",
"control",
".",
"Shutdown",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Success indicates a success of type kind loading a conversation. This effectively removes
// that conversation from the retry queue. | [
"Success",
"indicates",
"a",
"success",
"of",
"type",
"kind",
"loading",
"a",
"conversation",
".",
"This",
"effectively",
"removes",
"that",
"conversation",
"from",
"the",
"retry",
"queue",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/chat/retry.go#L320-L331 |
161,207 | keybase/client | go/chat/retry.go | Disconnected | func (f *FetchRetrier) Disconnected(ctx context.Context) {
f.Lock()
defer f.Unlock()
f.offline = true
} | go | func (f *FetchRetrier) Disconnected(ctx context.Context) {
f.Lock()
defer f.Unlock()
f.offline = true
} | [
"func",
"(",
"f",
"*",
"FetchRetrier",
")",
"Disconnected",
"(",
"ctx",
"context",
".",
"Context",
")",
"{",
"f",
".",
"Lock",
"(",
")",
"\n",
"defer",
"f",
".",
"Unlock",
"(",
")",
"\n",
"f",
".",
"offline",
"=",
"true",
"\n",
"}"
] | // Disconnected is called when we lose connection to the chat server, and pauses attempts
// on the retry queue. | [
"Disconnected",
"is",
"called",
"when",
"we",
"lose",
"connection",
"to",
"the",
"chat",
"server",
"and",
"pauses",
"attempts",
"on",
"the",
"retry",
"queue",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/chat/retry.go#L347-L351 |
161,208 | keybase/client | go/chat/retry.go | IsOffline | func (f *FetchRetrier) IsOffline(ctx context.Context) bool {
f.Lock()
defer f.Unlock()
return f.offline
} | go | func (f *FetchRetrier) IsOffline(ctx context.Context) bool {
f.Lock()
defer f.Unlock()
return f.offline
} | [
"func",
"(",
"f",
"*",
"FetchRetrier",
")",
"IsOffline",
"(",
"ctx",
"context",
".",
"Context",
")",
"bool",
"{",
"f",
".",
"Lock",
"(",
")",
"\n",
"defer",
"f",
".",
"Unlock",
"(",
")",
"\n",
"return",
"f",
".",
"offline",
"\n",
"}"
] | // IsOffline returns if the module thinks we are connected to the chat server. | [
"IsOffline",
"returns",
"if",
"the",
"module",
"thinks",
"we",
"are",
"connected",
"to",
"the",
"chat",
"server",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/chat/retry.go#L354-L358 |
161,209 | keybase/client | go/chat/retry.go | Force | func (f *FetchRetrier) Force(ctx context.Context) {
f.Lock()
defer f.Unlock()
defer f.Trace(ctx, func() error { return nil }, "Force")()
for _, control := range f.retriers {
control.Force()
}
} | go | func (f *FetchRetrier) Force(ctx context.Context) {
f.Lock()
defer f.Unlock()
defer f.Trace(ctx, func() error { return nil }, "Force")()
for _, control := range f.retriers {
control.Force()
}
} | [
"func",
"(",
"f",
"*",
"FetchRetrier",
")",
"Force",
"(",
"ctx",
"context",
".",
"Context",
")",
"{",
"f",
".",
"Lock",
"(",
")",
"\n",
"defer",
"f",
".",
"Unlock",
"(",
")",
"\n",
"defer",
"f",
".",
"Trace",
"(",
"ctx",
",",
"func",
"(",
")",
"error",
"{",
"return",
"nil",
"}",
",",
"\"",
"\"",
")",
"(",
")",
"\n",
"for",
"_",
",",
"control",
":=",
"range",
"f",
".",
"retriers",
"{",
"control",
".",
"Force",
"(",
")",
"\n",
"}",
"\n",
"}"
] | // Force forces a run of the retry loop. | [
"Force",
"forces",
"a",
"run",
"of",
"the",
"retry",
"loop",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/chat/retry.go#L361-L368 |
161,210 | keybase/client | go/service/favorite.go | NewFavoriteHandler | func NewFavoriteHandler(xp rpc.Transporter, g *libkb.GlobalContext) *FavoriteHandler {
return &FavoriteHandler{
BaseHandler: NewBaseHandler(g, xp),
Contextified: libkb.NewContextified(g),
}
} | go | func NewFavoriteHandler(xp rpc.Transporter, g *libkb.GlobalContext) *FavoriteHandler {
return &FavoriteHandler{
BaseHandler: NewBaseHandler(g, xp),
Contextified: libkb.NewContextified(g),
}
} | [
"func",
"NewFavoriteHandler",
"(",
"xp",
"rpc",
".",
"Transporter",
",",
"g",
"*",
"libkb",
".",
"GlobalContext",
")",
"*",
"FavoriteHandler",
"{",
"return",
"&",
"FavoriteHandler",
"{",
"BaseHandler",
":",
"NewBaseHandler",
"(",
"g",
",",
"xp",
")",
",",
"Contextified",
":",
"libkb",
".",
"NewContextified",
"(",
"g",
")",
",",
"}",
"\n",
"}"
] | // NewFavoriteHandler creates a FavoriteHandler with the xp
// protocol. | [
"NewFavoriteHandler",
"creates",
"a",
"FavoriteHandler",
"with",
"the",
"xp",
"protocol",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/service/favorite.go#L22-L27 |
161,211 | keybase/client | go/service/favorite.go | FavoriteAdd | func (h *FavoriteHandler) FavoriteAdd(ctx context.Context, arg keybase1.FavoriteAddArg) error {
eng := engine.NewFavoriteAdd(h.G(), &arg)
uis := libkb.UIs{
IdentifyUI: h.NewRemoteIdentifyUI(arg.SessionID, h.G()),
}
m := libkb.NewMetaContext(ctx, h.G()).WithUIs(uis)
return engine.RunEngine2(m, eng)
} | go | func (h *FavoriteHandler) FavoriteAdd(ctx context.Context, arg keybase1.FavoriteAddArg) error {
eng := engine.NewFavoriteAdd(h.G(), &arg)
uis := libkb.UIs{
IdentifyUI: h.NewRemoteIdentifyUI(arg.SessionID, h.G()),
}
m := libkb.NewMetaContext(ctx, h.G()).WithUIs(uis)
return engine.RunEngine2(m, eng)
} | [
"func",
"(",
"h",
"*",
"FavoriteHandler",
")",
"FavoriteAdd",
"(",
"ctx",
"context",
".",
"Context",
",",
"arg",
"keybase1",
".",
"FavoriteAddArg",
")",
"error",
"{",
"eng",
":=",
"engine",
".",
"NewFavoriteAdd",
"(",
"h",
".",
"G",
"(",
")",
",",
"&",
"arg",
")",
"\n",
"uis",
":=",
"libkb",
".",
"UIs",
"{",
"IdentifyUI",
":",
"h",
".",
"NewRemoteIdentifyUI",
"(",
"arg",
".",
"SessionID",
",",
"h",
".",
"G",
"(",
")",
")",
",",
"}",
"\n",
"m",
":=",
"libkb",
".",
"NewMetaContext",
"(",
"ctx",
",",
"h",
".",
"G",
"(",
")",
")",
".",
"WithUIs",
"(",
"uis",
")",
"\n",
"return",
"engine",
".",
"RunEngine2",
"(",
"m",
",",
"eng",
")",
"\n",
"}"
] | // FavoriteAdd handles the favoriteAdd RPC. | [
"FavoriteAdd",
"handles",
"the",
"favoriteAdd",
"RPC",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/service/favorite.go#L30-L37 |
161,212 | keybase/client | go/service/favorite.go | FavoriteIgnore | func (h *FavoriteHandler) FavoriteIgnore(ctx context.Context, arg keybase1.FavoriteIgnoreArg) error {
eng := engine.NewFavoriteIgnore(h.G(), &arg)
m := libkb.NewMetaContext(ctx, h.G())
return engine.RunEngine2(m, eng)
} | go | func (h *FavoriteHandler) FavoriteIgnore(ctx context.Context, arg keybase1.FavoriteIgnoreArg) error {
eng := engine.NewFavoriteIgnore(h.G(), &arg)
m := libkb.NewMetaContext(ctx, h.G())
return engine.RunEngine2(m, eng)
} | [
"func",
"(",
"h",
"*",
"FavoriteHandler",
")",
"FavoriteIgnore",
"(",
"ctx",
"context",
".",
"Context",
",",
"arg",
"keybase1",
".",
"FavoriteIgnoreArg",
")",
"error",
"{",
"eng",
":=",
"engine",
".",
"NewFavoriteIgnore",
"(",
"h",
".",
"G",
"(",
")",
",",
"&",
"arg",
")",
"\n",
"m",
":=",
"libkb",
".",
"NewMetaContext",
"(",
"ctx",
",",
"h",
".",
"G",
"(",
")",
")",
"\n",
"return",
"engine",
".",
"RunEngine2",
"(",
"m",
",",
"eng",
")",
"\n",
"}"
] | // FavoriteIgnore handles the favoriteIgnore RPC. | [
"FavoriteIgnore",
"handles",
"the",
"favoriteIgnore",
"RPC",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/service/favorite.go#L40-L44 |
161,213 | keybase/client | go/service/favorite.go | GetFavorites | func (h *FavoriteHandler) GetFavorites(ctx context.Context, sessionID int) (keybase1.FavoritesResult, error) {
eng := engine.NewFavoriteList(h.G())
m := libkb.NewMetaContext(ctx, h.G())
if err := engine.RunEngine2(m, eng); err != nil {
return keybase1.FavoritesResult{}, err
}
return eng.Result(), nil
} | go | func (h *FavoriteHandler) GetFavorites(ctx context.Context, sessionID int) (keybase1.FavoritesResult, error) {
eng := engine.NewFavoriteList(h.G())
m := libkb.NewMetaContext(ctx, h.G())
if err := engine.RunEngine2(m, eng); err != nil {
return keybase1.FavoritesResult{}, err
}
return eng.Result(), nil
} | [
"func",
"(",
"h",
"*",
"FavoriteHandler",
")",
"GetFavorites",
"(",
"ctx",
"context",
".",
"Context",
",",
"sessionID",
"int",
")",
"(",
"keybase1",
".",
"FavoritesResult",
",",
"error",
")",
"{",
"eng",
":=",
"engine",
".",
"NewFavoriteList",
"(",
"h",
".",
"G",
"(",
")",
")",
"\n",
"m",
":=",
"libkb",
".",
"NewMetaContext",
"(",
"ctx",
",",
"h",
".",
"G",
"(",
")",
")",
"\n",
"if",
"err",
":=",
"engine",
".",
"RunEngine2",
"(",
"m",
",",
"eng",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"keybase1",
".",
"FavoritesResult",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"return",
"eng",
".",
"Result",
"(",
")",
",",
"nil",
"\n",
"}"
] | // FavoriteList handles the favoriteList RPC. | [
"FavoriteList",
"handles",
"the",
"favoriteList",
"RPC",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/service/favorite.go#L47-L54 |
161,214 | keybase/client | go/kbfs/libfs/status_file.go | GetEncodedFolderStatus | func GetEncodedFolderStatus(ctx context.Context, config libkbfs.Config,
folderBranch data.FolderBranch) (
data []byte, t time.Time, err error) {
var status libkbfs.FolderBranchStatus
status, _, err = config.KBFSOps().FolderStatus(ctx, folderBranch)
if err != nil {
return nil, time.Time{}, err
}
data, err = PrettyJSON(status)
return
} | go | func GetEncodedFolderStatus(ctx context.Context, config libkbfs.Config,
folderBranch data.FolderBranch) (
data []byte, t time.Time, err error) {
var status libkbfs.FolderBranchStatus
status, _, err = config.KBFSOps().FolderStatus(ctx, folderBranch)
if err != nil {
return nil, time.Time{}, err
}
data, err = PrettyJSON(status)
return
} | [
"func",
"GetEncodedFolderStatus",
"(",
"ctx",
"context",
".",
"Context",
",",
"config",
"libkbfs",
".",
"Config",
",",
"folderBranch",
"data",
".",
"FolderBranch",
")",
"(",
"data",
"[",
"]",
"byte",
",",
"t",
"time",
".",
"Time",
",",
"err",
"error",
")",
"{",
"var",
"status",
"libkbfs",
".",
"FolderBranchStatus",
"\n",
"status",
",",
"_",
",",
"err",
"=",
"config",
".",
"KBFSOps",
"(",
")",
".",
"FolderStatus",
"(",
"ctx",
",",
"folderBranch",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"time",
".",
"Time",
"{",
"}",
",",
"err",
"\n",
"}",
"\n\n",
"data",
",",
"err",
"=",
"PrettyJSON",
"(",
"status",
")",
"\n",
"return",
"\n",
"}"
] | // GetEncodedFolderStatus returns serialized JSON containing status information
// for a folder | [
"GetEncodedFolderStatus",
"returns",
"serialized",
"JSON",
"containing",
"status",
"information",
"for",
"a",
"folder"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfs/status_file.go#L18-L29 |
161,215 | keybase/client | go/kbfs/libfs/status_file.go | GetEncodedStatus | func GetEncodedStatus(ctx context.Context, config libkbfs.Config) (
data []byte, t time.Time, err error) {
status, _, err := config.KBFSOps().Status(ctx)
if err != nil {
config.Reporter().ReportErr(ctx, "", tlf.Private, libkbfs.ReadMode, err)
}
data, err = PrettyJSON(status)
return
} | go | func GetEncodedStatus(ctx context.Context, config libkbfs.Config) (
data []byte, t time.Time, err error) {
status, _, err := config.KBFSOps().Status(ctx)
if err != nil {
config.Reporter().ReportErr(ctx, "", tlf.Private, libkbfs.ReadMode, err)
}
data, err = PrettyJSON(status)
return
} | [
"func",
"GetEncodedStatus",
"(",
"ctx",
"context",
".",
"Context",
",",
"config",
"libkbfs",
".",
"Config",
")",
"(",
"data",
"[",
"]",
"byte",
",",
"t",
"time",
".",
"Time",
",",
"err",
"error",
")",
"{",
"status",
",",
"_",
",",
"err",
":=",
"config",
".",
"KBFSOps",
"(",
")",
".",
"Status",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"config",
".",
"Reporter",
"(",
")",
".",
"ReportErr",
"(",
"ctx",
",",
"\"",
"\"",
",",
"tlf",
".",
"Private",
",",
"libkbfs",
".",
"ReadMode",
",",
"err",
")",
"\n",
"}",
"\n",
"data",
",",
"err",
"=",
"PrettyJSON",
"(",
"status",
")",
"\n",
"return",
"\n",
"}"
] | // GetEncodedStatus returns serialized JSON containing top-level KBFS status
// information | [
"GetEncodedStatus",
"returns",
"serialized",
"JSON",
"containing",
"top",
"-",
"level",
"KBFS",
"status",
"information"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfs/status_file.go#L33-L41 |
161,216 | keybase/client | go/kbfs/libkbfs/favorites.go | Initialize | func (f *Favorites) Initialize(ctx context.Context) {
// load cache from disk
err := f.readCacheFromDisk(ctx)
if err != nil {
f.log.CWarningf(nil,
"Failed to read cached favorites from disk: %v", err)
}
// launch background loop
go f.loop()
} | go | func (f *Favorites) Initialize(ctx context.Context) {
// load cache from disk
err := f.readCacheFromDisk(ctx)
if err != nil {
f.log.CWarningf(nil,
"Failed to read cached favorites from disk: %v", err)
}
// launch background loop
go f.loop()
} | [
"func",
"(",
"f",
"*",
"Favorites",
")",
"Initialize",
"(",
"ctx",
"context",
".",
"Context",
")",
"{",
"// load cache from disk",
"err",
":=",
"f",
".",
"readCacheFromDisk",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"f",
".",
"log",
".",
"CWarningf",
"(",
"nil",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// launch background loop",
"go",
"f",
".",
"loop",
"(",
")",
"\n",
"}"
] | // Initialize loads the favorites cache from disk and starts listening for
// requests asynchronously. | [
"Initialize",
"loads",
"the",
"favorites",
"cache",
"from",
"disk",
"and",
"starts",
"listening",
"for",
"requests",
"asynchronously",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/favorites.go#L267-L277 |
161,217 | keybase/client | go/kbfs/libkbfs/favorites.go | sendChangesToEditHistory | func (f *Favorites) sendChangesToEditHistory(oldCache map[favorites.Folder]favorites.Data) {
for oldFav := range oldCache {
if _, present := f.favCache[oldFav]; !present {
f.config.UserHistory().ClearTLF(tlf.CanonicalName(oldFav.Name),
oldFav.Type)
}
}
for newFav := range f.favCache {
if _, present := oldCache[newFav]; !present {
f.config.KBFSOps().RefreshEditHistory(newFav)
}
}
} | go | func (f *Favorites) sendChangesToEditHistory(oldCache map[favorites.Folder]favorites.Data) {
for oldFav := range oldCache {
if _, present := f.favCache[oldFav]; !present {
f.config.UserHistory().ClearTLF(tlf.CanonicalName(oldFav.Name),
oldFav.Type)
}
}
for newFav := range f.favCache {
if _, present := oldCache[newFav]; !present {
f.config.KBFSOps().RefreshEditHistory(newFav)
}
}
} | [
"func",
"(",
"f",
"*",
"Favorites",
")",
"sendChangesToEditHistory",
"(",
"oldCache",
"map",
"[",
"favorites",
".",
"Folder",
"]",
"favorites",
".",
"Data",
")",
"{",
"for",
"oldFav",
":=",
"range",
"oldCache",
"{",
"if",
"_",
",",
"present",
":=",
"f",
".",
"favCache",
"[",
"oldFav",
"]",
";",
"!",
"present",
"{",
"f",
".",
"config",
".",
"UserHistory",
"(",
")",
".",
"ClearTLF",
"(",
"tlf",
".",
"CanonicalName",
"(",
"oldFav",
".",
"Name",
")",
",",
"oldFav",
".",
"Type",
")",
"\n",
"}",
"\n",
"}",
"\n",
"for",
"newFav",
":=",
"range",
"f",
".",
"favCache",
"{",
"if",
"_",
",",
"present",
":=",
"oldCache",
"[",
"newFav",
"]",
";",
"!",
"present",
"{",
"f",
".",
"config",
".",
"KBFSOps",
"(",
")",
".",
"RefreshEditHistory",
"(",
"newFav",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // sendChangesToEditHistory notes any deleted favorites and removes them
// from this user's kbfsedits.UserHistory. | [
"sendChangesToEditHistory",
"notes",
"any",
"deleted",
"favorites",
"and",
"removes",
"them",
"from",
"this",
"user",
"s",
"kbfsedits",
".",
"UserHistory",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/favorites.go#L291-L303 |
161,218 | keybase/client | go/kbfs/libkbfs/favorites.go | Shutdown | func (f *Favorites) Shutdown() error {
if f.disabled {
return nil
}
f.muShutdown.Lock()
defer f.muShutdown.Unlock()
f.shutdown = true
close(f.reqChan)
if f.diskCache != nil {
err := f.diskCache.Close()
if err != nil {
f.log.CWarningf(context.Background(),
"Could not close disk favorites cache: %v", err)
}
}
return f.wg.Wait(context.Background())
} | go | func (f *Favorites) Shutdown() error {
if f.disabled {
return nil
}
f.muShutdown.Lock()
defer f.muShutdown.Unlock()
f.shutdown = true
close(f.reqChan)
if f.diskCache != nil {
err := f.diskCache.Close()
if err != nil {
f.log.CWarningf(context.Background(),
"Could not close disk favorites cache: %v", err)
}
}
return f.wg.Wait(context.Background())
} | [
"func",
"(",
"f",
"*",
"Favorites",
")",
"Shutdown",
"(",
")",
"error",
"{",
"if",
"f",
".",
"disabled",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"f",
".",
"muShutdown",
".",
"Lock",
"(",
")",
"\n",
"defer",
"f",
".",
"muShutdown",
".",
"Unlock",
"(",
")",
"\n",
"f",
".",
"shutdown",
"=",
"true",
"\n",
"close",
"(",
"f",
".",
"reqChan",
")",
"\n",
"if",
"f",
".",
"diskCache",
"!=",
"nil",
"{",
"err",
":=",
"f",
".",
"diskCache",
".",
"Close",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"f",
".",
"log",
".",
"CWarningf",
"(",
"context",
".",
"Background",
"(",
")",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"f",
".",
"wg",
".",
"Wait",
"(",
"context",
".",
"Background",
"(",
")",
")",
"\n",
"}"
] | // Shutdown shuts down this Favorites instance. | [
"Shutdown",
"shuts",
"down",
"this",
"Favorites",
"instance",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/favorites.go#L478-L495 |
161,219 | keybase/client | go/kbfs/libkbfs/favorites.go | Add | func (f *Favorites) Add(ctx context.Context, fav favorites.ToAdd) error {
if f.disabled {
return nil
}
if f.hasShutdown() {
return data.ShutdownHappenedError{}
}
doAdd := true
var err error
// Retry until we get an error that wasn't related to someone
// else's context being canceled.
for doAdd {
req, doSend := f.startOrJoinAddReq(ctx, fav)
if doSend {
return f.sendReq(ctx, req)
}
doAdd, err = f.waitOnReq(ctx, req)
}
return err
} | go | func (f *Favorites) Add(ctx context.Context, fav favorites.ToAdd) error {
if f.disabled {
return nil
}
if f.hasShutdown() {
return data.ShutdownHappenedError{}
}
doAdd := true
var err error
// Retry until we get an error that wasn't related to someone
// else's context being canceled.
for doAdd {
req, doSend := f.startOrJoinAddReq(ctx, fav)
if doSend {
return f.sendReq(ctx, req)
}
doAdd, err = f.waitOnReq(ctx, req)
}
return err
} | [
"func",
"(",
"f",
"*",
"Favorites",
")",
"Add",
"(",
"ctx",
"context",
".",
"Context",
",",
"fav",
"favorites",
".",
"ToAdd",
")",
"error",
"{",
"if",
"f",
".",
"disabled",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"if",
"f",
".",
"hasShutdown",
"(",
")",
"{",
"return",
"data",
".",
"ShutdownHappenedError",
"{",
"}",
"\n",
"}",
"\n",
"doAdd",
":=",
"true",
"\n",
"var",
"err",
"error",
"\n",
"// Retry until we get an error that wasn't related to someone",
"// else's context being canceled.",
"for",
"doAdd",
"{",
"req",
",",
"doSend",
":=",
"f",
".",
"startOrJoinAddReq",
"(",
"ctx",
",",
"fav",
")",
"\n",
"if",
"doSend",
"{",
"return",
"f",
".",
"sendReq",
"(",
"ctx",
",",
"req",
")",
"\n",
"}",
"\n",
"doAdd",
",",
"err",
"=",
"f",
".",
"waitOnReq",
"(",
"ctx",
",",
"req",
")",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] | // Add adds a favorite to your favorites list. | [
"Add",
"adds",
"a",
"favorite",
"to",
"your",
"favorites",
"list",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/favorites.go#L558-L577 |
161,220 | keybase/client | go/kbfs/libkbfs/favorites.go | Delete | func (f *Favorites) Delete(ctx context.Context, fav favorites.Folder) error {
if f.disabled {
return nil
}
if f.hasShutdown() {
return data.ShutdownHappenedError{}
}
return f.sendReq(ctx, &favReq{
ctx: ctx,
toDel: []favorites.Folder{fav},
done: make(chan struct{}),
})
} | go | func (f *Favorites) Delete(ctx context.Context, fav favorites.Folder) error {
if f.disabled {
return nil
}
if f.hasShutdown() {
return data.ShutdownHappenedError{}
}
return f.sendReq(ctx, &favReq{
ctx: ctx,
toDel: []favorites.Folder{fav},
done: make(chan struct{}),
})
} | [
"func",
"(",
"f",
"*",
"Favorites",
")",
"Delete",
"(",
"ctx",
"context",
".",
"Context",
",",
"fav",
"favorites",
".",
"Folder",
")",
"error",
"{",
"if",
"f",
".",
"disabled",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"if",
"f",
".",
"hasShutdown",
"(",
")",
"{",
"return",
"data",
".",
"ShutdownHappenedError",
"{",
"}",
"\n",
"}",
"\n",
"return",
"f",
".",
"sendReq",
"(",
"ctx",
",",
"&",
"favReq",
"{",
"ctx",
":",
"ctx",
",",
"toDel",
":",
"[",
"]",
"favorites",
".",
"Folder",
"{",
"fav",
"}",
",",
"done",
":",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
",",
"}",
")",
"\n",
"}"
] | // Delete deletes a favorite from the favorites list. It is
// idempotent. | [
"Delete",
"deletes",
"a",
"favorite",
"from",
"the",
"favorites",
"list",
".",
"It",
"is",
"idempotent",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/favorites.go#L607-L619 |
161,221 | keybase/client | go/kbfs/libkbfs/favorites.go | RefreshCache | func (f *Favorites) RefreshCache(ctx context.Context) {
if f.disabled || f.hasShutdown() {
return
}
// This request is non-blocking, so use a throw-away done channel
// and context.
req := &favReq{
refresh: true,
done: make(chan struct{}),
ctx: context.Background(),
}
f.wg.Add(1)
select {
case f.reqChan <- req:
case <-ctx.Done():
f.wg.Done()
return
}
} | go | func (f *Favorites) RefreshCache(ctx context.Context) {
if f.disabled || f.hasShutdown() {
return
}
// This request is non-blocking, so use a throw-away done channel
// and context.
req := &favReq{
refresh: true,
done: make(chan struct{}),
ctx: context.Background(),
}
f.wg.Add(1)
select {
case f.reqChan <- req:
case <-ctx.Done():
f.wg.Done()
return
}
} | [
"func",
"(",
"f",
"*",
"Favorites",
")",
"RefreshCache",
"(",
"ctx",
"context",
".",
"Context",
")",
"{",
"if",
"f",
".",
"disabled",
"||",
"f",
".",
"hasShutdown",
"(",
")",
"{",
"return",
"\n",
"}",
"\n",
"// This request is non-blocking, so use a throw-away done channel",
"// and context.",
"req",
":=",
"&",
"favReq",
"{",
"refresh",
":",
"true",
",",
"done",
":",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
",",
"ctx",
":",
"context",
".",
"Background",
"(",
")",
",",
"}",
"\n",
"f",
".",
"wg",
".",
"Add",
"(",
"1",
")",
"\n",
"select",
"{",
"case",
"f",
".",
"reqChan",
"<-",
"req",
":",
"case",
"<-",
"ctx",
".",
"Done",
"(",
")",
":",
"f",
".",
"wg",
".",
"Done",
"(",
")",
"\n",
"return",
"\n",
"}",
"\n",
"}"
] | // RefreshCache refreshes the cached list of favorites. | [
"RefreshCache",
"refreshes",
"the",
"cached",
"list",
"of",
"favorites",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/favorites.go#L622-L640 |
161,222 | keybase/client | go/kbfs/libkbfs/favorites.go | Get | func (f *Favorites) Get(ctx context.Context) ([]favorites.Folder, error) {
if f.disabled {
session, err := f.config.KBPKI().GetCurrentSession(ctx)
if err == nil {
// Add favorites only for the current user.
return []favorites.Folder{
{Name: string(session.Name), Type: tlf.Private},
{Name: string(session.Name), Type: tlf.Public},
}, nil
}
return nil, nil
}
if f.hasShutdown() {
return nil, data.ShutdownHappenedError{}
}
favChan := make(chan []favorites.Folder, 1)
req := &favReq{
ctx: ctx,
favs: favChan,
done: make(chan struct{}),
}
err := f.sendReq(ctx, req)
if err != nil {
return nil, err
}
return <-favChan, nil
} | go | func (f *Favorites) Get(ctx context.Context) ([]favorites.Folder, error) {
if f.disabled {
session, err := f.config.KBPKI().GetCurrentSession(ctx)
if err == nil {
// Add favorites only for the current user.
return []favorites.Folder{
{Name: string(session.Name), Type: tlf.Private},
{Name: string(session.Name), Type: tlf.Public},
}, nil
}
return nil, nil
}
if f.hasShutdown() {
return nil, data.ShutdownHappenedError{}
}
favChan := make(chan []favorites.Folder, 1)
req := &favReq{
ctx: ctx,
favs: favChan,
done: make(chan struct{}),
}
err := f.sendReq(ctx, req)
if err != nil {
return nil, err
}
return <-favChan, nil
} | [
"func",
"(",
"f",
"*",
"Favorites",
")",
"Get",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"[",
"]",
"favorites",
".",
"Folder",
",",
"error",
")",
"{",
"if",
"f",
".",
"disabled",
"{",
"session",
",",
"err",
":=",
"f",
".",
"config",
".",
"KBPKI",
"(",
")",
".",
"GetCurrentSession",
"(",
"ctx",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"// Add favorites only for the current user.",
"return",
"[",
"]",
"favorites",
".",
"Folder",
"{",
"{",
"Name",
":",
"string",
"(",
"session",
".",
"Name",
")",
",",
"Type",
":",
"tlf",
".",
"Private",
"}",
",",
"{",
"Name",
":",
"string",
"(",
"session",
".",
"Name",
")",
",",
"Type",
":",
"tlf",
".",
"Public",
"}",
",",
"}",
",",
"nil",
"\n",
"}",
"\n",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"if",
"f",
".",
"hasShutdown",
"(",
")",
"{",
"return",
"nil",
",",
"data",
".",
"ShutdownHappenedError",
"{",
"}",
"\n",
"}",
"\n",
"favChan",
":=",
"make",
"(",
"chan",
"[",
"]",
"favorites",
".",
"Folder",
",",
"1",
")",
"\n",
"req",
":=",
"&",
"favReq",
"{",
"ctx",
":",
"ctx",
",",
"favs",
":",
"favChan",
",",
"done",
":",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
",",
"}",
"\n",
"err",
":=",
"f",
".",
"sendReq",
"(",
"ctx",
",",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"<-",
"favChan",
",",
"nil",
"\n",
"}"
] | // Get returns the logged-in user's list of favorites. It uses the cache. | [
"Get",
"returns",
"the",
"logged",
"-",
"in",
"user",
"s",
"list",
"of",
"favorites",
".",
"It",
"uses",
"the",
"cache",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/favorites.go#L665-L691 |
161,223 | keybase/client | go/kbfs/libkbfs/favorites.go | setHomeTLFInfo | func (f *Favorites) setHomeTLFInfo(ctx context.Context, info homeTLFInfo) {
if f.hasShutdown() {
return
}
// This request is non-blocking, so use a throw-away done channel
// and context.
req := &favReq{
homeTLFInfo: &info,
done: make(chan struct{}),
ctx: context.Background(),
}
f.wg.Add(1)
select {
case f.reqChan <- req:
case <-ctx.Done():
f.wg.Done()
return
}
} | go | func (f *Favorites) setHomeTLFInfo(ctx context.Context, info homeTLFInfo) {
if f.hasShutdown() {
return
}
// This request is non-blocking, so use a throw-away done channel
// and context.
req := &favReq{
homeTLFInfo: &info,
done: make(chan struct{}),
ctx: context.Background(),
}
f.wg.Add(1)
select {
case f.reqChan <- req:
case <-ctx.Done():
f.wg.Done()
return
}
} | [
"func",
"(",
"f",
"*",
"Favorites",
")",
"setHomeTLFInfo",
"(",
"ctx",
"context",
".",
"Context",
",",
"info",
"homeTLFInfo",
")",
"{",
"if",
"f",
".",
"hasShutdown",
"(",
")",
"{",
"return",
"\n",
"}",
"\n",
"// This request is non-blocking, so use a throw-away done channel",
"// and context.",
"req",
":=",
"&",
"favReq",
"{",
"homeTLFInfo",
":",
"&",
"info",
",",
"done",
":",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
",",
"ctx",
":",
"context",
".",
"Background",
"(",
")",
",",
"}",
"\n",
"f",
".",
"wg",
".",
"Add",
"(",
"1",
")",
"\n",
"select",
"{",
"case",
"f",
".",
"reqChan",
"<-",
"req",
":",
"case",
"<-",
"ctx",
".",
"Done",
"(",
")",
":",
"f",
".",
"wg",
".",
"Done",
"(",
")",
"\n",
"return",
"\n",
"}",
"\n",
"}"
] | // setHomeTLFInfo should be called when a new user logs in so that their home
// TLFs can be returned as favorites. | [
"setHomeTLFInfo",
"should",
"be",
"called",
"when",
"a",
"new",
"user",
"logs",
"in",
"so",
"that",
"their",
"home",
"TLFs",
"can",
"be",
"returned",
"as",
"favorites",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/favorites.go#L695-L713 |
161,224 | keybase/client | go/kbfs/libkbfs/favorites.go | GetAll | func (f *Favorites) GetAll(ctx context.Context) (keybase1.FavoritesResult,
error) {
if f.disabled {
session, err := f.config.KBPKI().GetCurrentSession(ctx)
if err == nil {
// Add favorites only for the current user.
return keybase1.FavoritesResult{
FavoriteFolders: []keybase1.Folder{
{
Name: string(session.Name),
Private: false,
Created: false,
FolderType: keybase1.FolderType_PUBLIC,
TeamID: &f.homeTLFInfo.PublicTeamID,
},
{
Name: string(session.Name),
Private: true,
Created: false,
FolderType: keybase1.FolderType_PRIVATE,
TeamID: &f.homeTLFInfo.PrivateTeamID,
},
},
}, nil
}
return keybase1.FavoritesResult{}, nil
}
if f.hasShutdown() {
return keybase1.FavoritesResult{}, data.ShutdownHappenedError{}
}
favChan := make(chan keybase1.FavoritesResult, 1)
req := &favReq{
ctx: ctx,
favsAll: favChan,
done: make(chan struct{}),
}
err := f.sendReq(ctx, req)
if err != nil {
return keybase1.FavoritesResult{}, err
}
return <-favChan, nil
} | go | func (f *Favorites) GetAll(ctx context.Context) (keybase1.FavoritesResult,
error) {
if f.disabled {
session, err := f.config.KBPKI().GetCurrentSession(ctx)
if err == nil {
// Add favorites only for the current user.
return keybase1.FavoritesResult{
FavoriteFolders: []keybase1.Folder{
{
Name: string(session.Name),
Private: false,
Created: false,
FolderType: keybase1.FolderType_PUBLIC,
TeamID: &f.homeTLFInfo.PublicTeamID,
},
{
Name: string(session.Name),
Private: true,
Created: false,
FolderType: keybase1.FolderType_PRIVATE,
TeamID: &f.homeTLFInfo.PrivateTeamID,
},
},
}, nil
}
return keybase1.FavoritesResult{}, nil
}
if f.hasShutdown() {
return keybase1.FavoritesResult{}, data.ShutdownHappenedError{}
}
favChan := make(chan keybase1.FavoritesResult, 1)
req := &favReq{
ctx: ctx,
favsAll: favChan,
done: make(chan struct{}),
}
err := f.sendReq(ctx, req)
if err != nil {
return keybase1.FavoritesResult{}, err
}
return <-favChan, nil
} | [
"func",
"(",
"f",
"*",
"Favorites",
")",
"GetAll",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"keybase1",
".",
"FavoritesResult",
",",
"error",
")",
"{",
"if",
"f",
".",
"disabled",
"{",
"session",
",",
"err",
":=",
"f",
".",
"config",
".",
"KBPKI",
"(",
")",
".",
"GetCurrentSession",
"(",
"ctx",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"// Add favorites only for the current user.",
"return",
"keybase1",
".",
"FavoritesResult",
"{",
"FavoriteFolders",
":",
"[",
"]",
"keybase1",
".",
"Folder",
"{",
"{",
"Name",
":",
"string",
"(",
"session",
".",
"Name",
")",
",",
"Private",
":",
"false",
",",
"Created",
":",
"false",
",",
"FolderType",
":",
"keybase1",
".",
"FolderType_PUBLIC",
",",
"TeamID",
":",
"&",
"f",
".",
"homeTLFInfo",
".",
"PublicTeamID",
",",
"}",
",",
"{",
"Name",
":",
"string",
"(",
"session",
".",
"Name",
")",
",",
"Private",
":",
"true",
",",
"Created",
":",
"false",
",",
"FolderType",
":",
"keybase1",
".",
"FolderType_PRIVATE",
",",
"TeamID",
":",
"&",
"f",
".",
"homeTLFInfo",
".",
"PrivateTeamID",
",",
"}",
",",
"}",
",",
"}",
",",
"nil",
"\n",
"}",
"\n",
"return",
"keybase1",
".",
"FavoritesResult",
"{",
"}",
",",
"nil",
"\n",
"}",
"\n",
"if",
"f",
".",
"hasShutdown",
"(",
")",
"{",
"return",
"keybase1",
".",
"FavoritesResult",
"{",
"}",
",",
"data",
".",
"ShutdownHappenedError",
"{",
"}",
"\n",
"}",
"\n",
"favChan",
":=",
"make",
"(",
"chan",
"keybase1",
".",
"FavoritesResult",
",",
"1",
")",
"\n",
"req",
":=",
"&",
"favReq",
"{",
"ctx",
":",
"ctx",
",",
"favsAll",
":",
"favChan",
",",
"done",
":",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
",",
"}",
"\n",
"err",
":=",
"f",
".",
"sendReq",
"(",
"ctx",
",",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"keybase1",
".",
"FavoritesResult",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"return",
"<-",
"favChan",
",",
"nil",
"\n",
"}"
] | // GetAll returns the logged-in user's list of favorite, new, and ignored TLFs.
// It uses the cache. | [
"GetAll",
"returns",
"the",
"logged",
"-",
"in",
"user",
"s",
"list",
"of",
"favorite",
"new",
"and",
"ignored",
"TLFs",
".",
"It",
"uses",
"the",
"cache",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/favorites.go#L717-L758 |
161,225 | keybase/client | go/kbnm/handler.go | checkUsernameQuery | func checkUsernameQuery(s string) (string, error) {
if s == "" {
return "", errMissingField
}
if !reUsernameQuery.MatchString(s) {
return "", errInvalidInput
}
return s, nil
} | go | func checkUsernameQuery(s string) (string, error) {
if s == "" {
return "", errMissingField
}
if !reUsernameQuery.MatchString(s) {
return "", errInvalidInput
}
return s, nil
} | [
"func",
"checkUsernameQuery",
"(",
"s",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"s",
"==",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
",",
"errMissingField",
"\n",
"}",
"\n",
"if",
"!",
"reUsernameQuery",
".",
"MatchString",
"(",
"s",
")",
"{",
"return",
"\"",
"\"",
",",
"errInvalidInput",
"\n",
"}",
"\n",
"return",
"s",
",",
"nil",
"\n",
"}"
] | // checkUsernameQuery returns the query if it's valid to use
// We return the valid string so that it can be used as a separate
// pre-validated variable which makes it less likely that the validation will
// be accidentally removed in the future, as opposed to if we just continued
// using the input variable after validating it. | [
"checkUsernameQuery",
"returns",
"the",
"query",
"if",
"it",
"s",
"valid",
"to",
"use",
"We",
"return",
"the",
"valid",
"string",
"so",
"that",
"it",
"can",
"be",
"used",
"as",
"a",
"separate",
"pre",
"-",
"validated",
"variable",
"which",
"makes",
"it",
"less",
"likely",
"that",
"the",
"validation",
"will",
"be",
"accidentally",
"removed",
"in",
"the",
"future",
"as",
"opposed",
"to",
"if",
"we",
"just",
"continued",
"using",
"the",
"input",
"variable",
"after",
"validating",
"it",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbnm/handler.go#L49-L57 |
161,226 | keybase/client | go/kbnm/handler.go | newHandler | func newHandler() *handler {
return &handler{
Run: execRunner,
FindKeybaseBinary: func() (string, error) {
return findKeybaseBinary(keybaseBinary)
},
}
} | go | func newHandler() *handler {
return &handler{
Run: execRunner,
FindKeybaseBinary: func() (string, error) {
return findKeybaseBinary(keybaseBinary)
},
}
} | [
"func",
"newHandler",
"(",
")",
"*",
"handler",
"{",
"return",
"&",
"handler",
"{",
"Run",
":",
"execRunner",
",",
"FindKeybaseBinary",
":",
"func",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"return",
"findKeybaseBinary",
"(",
"keybaseBinary",
")",
"\n",
"}",
",",
"}",
"\n",
"}"
] | // newHandler returns a request handler. | [
"newHandler",
"returns",
"a",
"request",
"handler",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbnm/handler.go#L60-L67 |
161,227 | keybase/client | go/kbnm/handler.go | Handle | func (h *handler) Handle(req *Request) (interface{}, error) {
switch req.Method {
case "chat":
return nil, h.handleChat(req)
case "query":
return h.handleQuery(req)
}
return nil, errInvalidMethod
} | go | func (h *handler) Handle(req *Request) (interface{}, error) {
switch req.Method {
case "chat":
return nil, h.handleChat(req)
case "query":
return h.handleQuery(req)
}
return nil, errInvalidMethod
} | [
"func",
"(",
"h",
"*",
"handler",
")",
"Handle",
"(",
"req",
"*",
"Request",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"switch",
"req",
".",
"Method",
"{",
"case",
"\"",
"\"",
":",
"return",
"nil",
",",
"h",
".",
"handleChat",
"(",
"req",
")",
"\n",
"case",
"\"",
"\"",
":",
"return",
"h",
".",
"handleQuery",
"(",
"req",
")",
"\n",
"}",
"\n",
"return",
"nil",
",",
"errInvalidMethod",
"\n",
"}"
] | // Handle accepts a request, handles it, and returns an optional result if there was no error | [
"Handle",
"accepts",
"a",
"request",
"handles",
"it",
"and",
"returns",
"an",
"optional",
"result",
"if",
"there",
"was",
"no",
"error"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbnm/handler.go#L77-L85 |
161,228 | keybase/client | go/kbnm/handler.go | handleChat | func (h *handler) handleChat(req *Request) error {
if req.Body == "" {
return errMissingField
}
idQuery, err := checkUsernameQuery(req.To)
if err != nil {
return err
}
binPath, err := h.FindKeybaseBinary()
if err != nil {
return err
}
var out bytes.Buffer
cmd := exec.Command(binPath, "chat", "send", "--private", idQuery)
cmd.Env = append(os.Environ(), "KEYBASE_LOG_FORMAT=plain")
cmd.Stdin = strings.NewReader(req.Body)
cmd.Stdout = &out
cmd.Stderr = &out
if err := h.Run(cmd); err != nil {
return parseError(&out, err)
}
return nil
} | go | func (h *handler) handleChat(req *Request) error {
if req.Body == "" {
return errMissingField
}
idQuery, err := checkUsernameQuery(req.To)
if err != nil {
return err
}
binPath, err := h.FindKeybaseBinary()
if err != nil {
return err
}
var out bytes.Buffer
cmd := exec.Command(binPath, "chat", "send", "--private", idQuery)
cmd.Env = append(os.Environ(), "KEYBASE_LOG_FORMAT=plain")
cmd.Stdin = strings.NewReader(req.Body)
cmd.Stdout = &out
cmd.Stderr = &out
if err := h.Run(cmd); err != nil {
return parseError(&out, err)
}
return nil
} | [
"func",
"(",
"h",
"*",
"handler",
")",
"handleChat",
"(",
"req",
"*",
"Request",
")",
"error",
"{",
"if",
"req",
".",
"Body",
"==",
"\"",
"\"",
"{",
"return",
"errMissingField",
"\n",
"}",
"\n",
"idQuery",
",",
"err",
":=",
"checkUsernameQuery",
"(",
"req",
".",
"To",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"binPath",
",",
"err",
":=",
"h",
".",
"FindKeybaseBinary",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"var",
"out",
"bytes",
".",
"Buffer",
"\n",
"cmd",
":=",
"exec",
".",
"Command",
"(",
"binPath",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"idQuery",
")",
"\n",
"cmd",
".",
"Env",
"=",
"append",
"(",
"os",
".",
"Environ",
"(",
")",
",",
"\"",
"\"",
")",
"\n",
"cmd",
".",
"Stdin",
"=",
"strings",
".",
"NewReader",
"(",
"req",
".",
"Body",
")",
"\n",
"cmd",
".",
"Stdout",
"=",
"&",
"out",
"\n",
"cmd",
".",
"Stderr",
"=",
"&",
"out",
"\n\n",
"if",
"err",
":=",
"h",
".",
"Run",
"(",
"cmd",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"parseError",
"(",
"&",
"out",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // handleChat sends a chat message to a user. | [
"handleChat",
"sends",
"a",
"chat",
"message",
"to",
"a",
"user",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbnm/handler.go#L88-L114 |
161,229 | keybase/client | go/kbnm/handler.go | parseQuery | func parseQuery(r io.Reader) (*resultQuery, error) {
scanner := bufio.NewScanner(r)
var lastErrLine string
for scanner.Scan() {
// Find a line that looks like... "[INFO] 001 Identifying someuser"
line := strings.TrimSpace(scanner.Text())
parts := strings.Split(line, " ")
if len(parts) < 4 {
continue
}
// Short circuit errors
if parts[0] == "[ERRO]" {
lastErrLine = strings.Join(parts[2:], " ")
if lastErrLine == "Not found" {
return nil, errUserNotFound
}
continue
}
if parts[2] != "Identifying" {
continue
}
resp := &resultQuery{
Username: parts[3],
}
return resp, nil
}
if err := scanner.Err(); err != nil {
return nil, scanner.Err()
}
// This could happen if the keybase service is broken
return nil, &errUnexpected{lastErrLine}
} | go | func parseQuery(r io.Reader) (*resultQuery, error) {
scanner := bufio.NewScanner(r)
var lastErrLine string
for scanner.Scan() {
// Find a line that looks like... "[INFO] 001 Identifying someuser"
line := strings.TrimSpace(scanner.Text())
parts := strings.Split(line, " ")
if len(parts) < 4 {
continue
}
// Short circuit errors
if parts[0] == "[ERRO]" {
lastErrLine = strings.Join(parts[2:], " ")
if lastErrLine == "Not found" {
return nil, errUserNotFound
}
continue
}
if parts[2] != "Identifying" {
continue
}
resp := &resultQuery{
Username: parts[3],
}
return resp, nil
}
if err := scanner.Err(); err != nil {
return nil, scanner.Err()
}
// This could happen if the keybase service is broken
return nil, &errUnexpected{lastErrLine}
} | [
"func",
"parseQuery",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"*",
"resultQuery",
",",
"error",
")",
"{",
"scanner",
":=",
"bufio",
".",
"NewScanner",
"(",
"r",
")",
"\n\n",
"var",
"lastErrLine",
"string",
"\n",
"for",
"scanner",
".",
"Scan",
"(",
")",
"{",
"// Find a line that looks like... \"[INFO] 001 Identifying someuser\"",
"line",
":=",
"strings",
".",
"TrimSpace",
"(",
"scanner",
".",
"Text",
"(",
")",
")",
"\n",
"parts",
":=",
"strings",
".",
"Split",
"(",
"line",
",",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"parts",
")",
"<",
"4",
"{",
"continue",
"\n",
"}",
"\n\n",
"// Short circuit errors",
"if",
"parts",
"[",
"0",
"]",
"==",
"\"",
"\"",
"{",
"lastErrLine",
"=",
"strings",
".",
"Join",
"(",
"parts",
"[",
"2",
":",
"]",
",",
"\"",
"\"",
")",
"\n",
"if",
"lastErrLine",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"errUserNotFound",
"\n",
"}",
"\n",
"continue",
"\n",
"}",
"\n\n",
"if",
"parts",
"[",
"2",
"]",
"!=",
"\"",
"\"",
"{",
"continue",
"\n",
"}",
"\n\n",
"resp",
":=",
"&",
"resultQuery",
"{",
"Username",
":",
"parts",
"[",
"3",
"]",
",",
"}",
"\n",
"return",
"resp",
",",
"nil",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"scanner",
".",
"Err",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"scanner",
".",
"Err",
"(",
")",
"\n",
"}",
"\n\n",
"// This could happen if the keybase service is broken",
"return",
"nil",
",",
"&",
"errUnexpected",
"{",
"lastErrLine",
"}",
"\n",
"}"
] | // parseQuery reads the stderr from a keybase query command and returns a result | [
"parseQuery",
"reads",
"the",
"stderr",
"from",
"a",
"keybase",
"query",
"command",
"and",
"returns",
"a",
"result"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbnm/handler.go#L121-L158 |
161,230 | keybase/client | go/kbnm/handler.go | parseError | func parseError(r io.Reader, fallback error) error {
scanner := bufio.NewScanner(r)
// Find the final error
var lastErr error
for scanner.Scan() {
// Should be of the form "[ERRO] 001 Not found" or "...: No resolution found"
line := strings.TrimSpace(scanner.Text())
if line == "" {
continue
}
// Check some error states we know about:
if strings.Contains(line, "Keybase isn't running.") {
return errKeybaseNotRunning
}
if strings.Contains(line, "You are not logged into Keybase.") {
return errKeybaseNotLoggedIn
}
parts := strings.SplitN(line, " ", 3)
if len(parts) < 3 {
continue
}
if parts[0] != "[ERRO]" {
continue
}
if strings.HasSuffix(parts[2], "No resolution found") {
return errUserNotFound
}
if strings.HasPrefix(parts[2], "Not found") {
return errUserNotFound
}
lastErr = fmt.Errorf(parts[2])
}
if lastErr != nil {
return lastErr
}
return fallback
} | go | func parseError(r io.Reader, fallback error) error {
scanner := bufio.NewScanner(r)
// Find the final error
var lastErr error
for scanner.Scan() {
// Should be of the form "[ERRO] 001 Not found" or "...: No resolution found"
line := strings.TrimSpace(scanner.Text())
if line == "" {
continue
}
// Check some error states we know about:
if strings.Contains(line, "Keybase isn't running.") {
return errKeybaseNotRunning
}
if strings.Contains(line, "You are not logged into Keybase.") {
return errKeybaseNotLoggedIn
}
parts := strings.SplitN(line, " ", 3)
if len(parts) < 3 {
continue
}
if parts[0] != "[ERRO]" {
continue
}
if strings.HasSuffix(parts[2], "No resolution found") {
return errUserNotFound
}
if strings.HasPrefix(parts[2], "Not found") {
return errUserNotFound
}
lastErr = fmt.Errorf(parts[2])
}
if lastErr != nil {
return lastErr
}
return fallback
} | [
"func",
"parseError",
"(",
"r",
"io",
".",
"Reader",
",",
"fallback",
"error",
")",
"error",
"{",
"scanner",
":=",
"bufio",
".",
"NewScanner",
"(",
"r",
")",
"\n\n",
"// Find the final error",
"var",
"lastErr",
"error",
"\n",
"for",
"scanner",
".",
"Scan",
"(",
")",
"{",
"// Should be of the form \"[ERRO] 001 Not found\" or \"...: No resolution found\"",
"line",
":=",
"strings",
".",
"TrimSpace",
"(",
"scanner",
".",
"Text",
"(",
")",
")",
"\n",
"if",
"line",
"==",
"\"",
"\"",
"{",
"continue",
"\n",
"}",
"\n",
"// Check some error states we know about:",
"if",
"strings",
".",
"Contains",
"(",
"line",
",",
"\"",
"\"",
")",
"{",
"return",
"errKeybaseNotRunning",
"\n",
"}",
"\n",
"if",
"strings",
".",
"Contains",
"(",
"line",
",",
"\"",
"\"",
")",
"{",
"return",
"errKeybaseNotLoggedIn",
"\n",
"}",
"\n",
"parts",
":=",
"strings",
".",
"SplitN",
"(",
"line",
",",
"\"",
"\"",
",",
"3",
")",
"\n",
"if",
"len",
"(",
"parts",
")",
"<",
"3",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"parts",
"[",
"0",
"]",
"!=",
"\"",
"\"",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"strings",
".",
"HasSuffix",
"(",
"parts",
"[",
"2",
"]",
",",
"\"",
"\"",
")",
"{",
"return",
"errUserNotFound",
"\n",
"}",
"\n",
"if",
"strings",
".",
"HasPrefix",
"(",
"parts",
"[",
"2",
"]",
",",
"\"",
"\"",
")",
"{",
"return",
"errUserNotFound",
"\n",
"}",
"\n",
"lastErr",
"=",
"fmt",
".",
"Errorf",
"(",
"parts",
"[",
"2",
"]",
")",
"\n",
"}",
"\n\n",
"if",
"lastErr",
"!=",
"nil",
"{",
"return",
"lastErr",
"\n",
"}",
"\n\n",
"return",
"fallback",
"\n",
"}"
] | // parseError reads stderr output and returns an error made from it. If it
// fails to parse an error, it returns the fallback error. | [
"parseError",
"reads",
"stderr",
"output",
"and",
"returns",
"an",
"error",
"made",
"from",
"it",
".",
"If",
"it",
"fails",
"to",
"parse",
"an",
"error",
"it",
"returns",
"the",
"fallback",
"error",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbnm/handler.go#L162-L201 |
161,231 | keybase/client | go/kbnm/handler.go | handleQuery | func (h *handler) handleQuery(req *Request) (*resultQuery, error) {
idQuery, err := checkUsernameQuery(req.To)
if err != nil {
return nil, err
}
binPath, err := h.FindKeybaseBinary()
if err != nil {
return nil, err
}
// Unfortunately `keybase id ...` does not support JSON output, so we parse the output
var out bytes.Buffer
cmd := exec.Command(binPath, "id", idQuery)
cmd.Env = append(os.Environ(), "KEYBASE_LOG_FORMAT=plain")
cmd.Stdout = &out
cmd.Stderr = &out
if err := h.Run(cmd); err != nil {
return nil, parseError(&out, err)
}
return parseQuery(&out)
} | go | func (h *handler) handleQuery(req *Request) (*resultQuery, error) {
idQuery, err := checkUsernameQuery(req.To)
if err != nil {
return nil, err
}
binPath, err := h.FindKeybaseBinary()
if err != nil {
return nil, err
}
// Unfortunately `keybase id ...` does not support JSON output, so we parse the output
var out bytes.Buffer
cmd := exec.Command(binPath, "id", idQuery)
cmd.Env = append(os.Environ(), "KEYBASE_LOG_FORMAT=plain")
cmd.Stdout = &out
cmd.Stderr = &out
if err := h.Run(cmd); err != nil {
return nil, parseError(&out, err)
}
return parseQuery(&out)
} | [
"func",
"(",
"h",
"*",
"handler",
")",
"handleQuery",
"(",
"req",
"*",
"Request",
")",
"(",
"*",
"resultQuery",
",",
"error",
")",
"{",
"idQuery",
",",
"err",
":=",
"checkUsernameQuery",
"(",
"req",
".",
"To",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"binPath",
",",
"err",
":=",
"h",
".",
"FindKeybaseBinary",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// Unfortunately `keybase id ...` does not support JSON output, so we parse the output",
"var",
"out",
"bytes",
".",
"Buffer",
"\n",
"cmd",
":=",
"exec",
".",
"Command",
"(",
"binPath",
",",
"\"",
"\"",
",",
"idQuery",
")",
"\n",
"cmd",
".",
"Env",
"=",
"append",
"(",
"os",
".",
"Environ",
"(",
")",
",",
"\"",
"\"",
")",
"\n",
"cmd",
".",
"Stdout",
"=",
"&",
"out",
"\n",
"cmd",
".",
"Stderr",
"=",
"&",
"out",
"\n\n",
"if",
"err",
":=",
"h",
".",
"Run",
"(",
"cmd",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"parseError",
"(",
"&",
"out",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"parseQuery",
"(",
"&",
"out",
")",
"\n",
"}"
] | // handleQuery searches whether a user is present in Keybase. | [
"handleQuery",
"searches",
"whether",
"a",
"user",
"is",
"present",
"in",
"Keybase",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbnm/handler.go#L204-L227 |
161,232 | keybase/client | go/client/cmd_simplefs_copy.go | NewCmdSimpleFSCopy | func NewCmdSimpleFSCopy(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
return cli.Command{
Name: "cp",
ArgumentHelp: "<source> [source] <dest>",
Usage: "copy one or more directory elements to dest",
Action: func(c *cli.Context) {
cl.ChooseCommand(&CmdSimpleFSCopy{
Contextified: libkb.NewContextified(g),
opCanceler: NewOpCanceler(g),
}, "cp", c)
cl.SetNoStandalone()
},
Flags: []cli.Flag{
cli.BoolFlag{
Name: "r, recursive",
Usage: "Recurse into subdirectories",
},
cli.BoolFlag{
Name: "i, interactive",
Usage: "Prompt before overwrite",
},
cli.BoolFlag{
Name: "f, force",
Usage: "force overwrite",
},
cli.IntFlag{
Name: "rev",
Usage: "a revision number for the KBFS folder of the source paths",
},
cli.StringFlag{
Name: "time",
Usage: "a time for the KBFS folder of the source paths (eg \"2018-07-27 22:05\")",
},
cli.StringFlag{
Name: "reltime, relative-time",
Usage: "a relative time for the KBFS folder of the source paths (eg \"5m\")",
},
},
}
} | go | func NewCmdSimpleFSCopy(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
return cli.Command{
Name: "cp",
ArgumentHelp: "<source> [source] <dest>",
Usage: "copy one or more directory elements to dest",
Action: func(c *cli.Context) {
cl.ChooseCommand(&CmdSimpleFSCopy{
Contextified: libkb.NewContextified(g),
opCanceler: NewOpCanceler(g),
}, "cp", c)
cl.SetNoStandalone()
},
Flags: []cli.Flag{
cli.BoolFlag{
Name: "r, recursive",
Usage: "Recurse into subdirectories",
},
cli.BoolFlag{
Name: "i, interactive",
Usage: "Prompt before overwrite",
},
cli.BoolFlag{
Name: "f, force",
Usage: "force overwrite",
},
cli.IntFlag{
Name: "rev",
Usage: "a revision number for the KBFS folder of the source paths",
},
cli.StringFlag{
Name: "time",
Usage: "a time for the KBFS folder of the source paths (eg \"2018-07-27 22:05\")",
},
cli.StringFlag{
Name: "reltime, relative-time",
Usage: "a relative time for the KBFS folder of the source paths (eg \"5m\")",
},
},
}
} | [
"func",
"NewCmdSimpleFSCopy",
"(",
"cl",
"*",
"libcmdline",
".",
"CommandLine",
",",
"g",
"*",
"libkb",
".",
"GlobalContext",
")",
"cli",
".",
"Command",
"{",
"return",
"cli",
".",
"Command",
"{",
"Name",
":",
"\"",
"\"",
",",
"ArgumentHelp",
":",
"\"",
"\"",
",",
"Usage",
":",
"\"",
"\"",
",",
"Action",
":",
"func",
"(",
"c",
"*",
"cli",
".",
"Context",
")",
"{",
"cl",
".",
"ChooseCommand",
"(",
"&",
"CmdSimpleFSCopy",
"{",
"Contextified",
":",
"libkb",
".",
"NewContextified",
"(",
"g",
")",
",",
"opCanceler",
":",
"NewOpCanceler",
"(",
"g",
")",
",",
"}",
",",
"\"",
"\"",
",",
"c",
")",
"\n",
"cl",
".",
"SetNoStandalone",
"(",
")",
"\n",
"}",
",",
"Flags",
":",
"[",
"]",
"cli",
".",
"Flag",
"{",
"cli",
".",
"BoolFlag",
"{",
"Name",
":",
"\"",
"\"",
",",
"Usage",
":",
"\"",
"\"",
",",
"}",
",",
"cli",
".",
"BoolFlag",
"{",
"Name",
":",
"\"",
"\"",
",",
"Usage",
":",
"\"",
"\"",
",",
"}",
",",
"cli",
".",
"BoolFlag",
"{",
"Name",
":",
"\"",
"\"",
",",
"Usage",
":",
"\"",
"\"",
",",
"}",
",",
"cli",
".",
"IntFlag",
"{",
"Name",
":",
"\"",
"\"",
",",
"Usage",
":",
"\"",
"\"",
",",
"}",
",",
"cli",
".",
"StringFlag",
"{",
"Name",
":",
"\"",
"\"",
",",
"Usage",
":",
"\"",
"\\\"",
"\\\"",
"\"",
",",
"}",
",",
"cli",
".",
"StringFlag",
"{",
"Name",
":",
"\"",
"\"",
",",
"Usage",
":",
"\"",
"\\\"",
"\\\"",
"\"",
",",
"}",
",",
"}",
",",
"}",
"\n",
"}"
] | // NewCmdSimpleFSCopy creates a new cli.Command. | [
"NewCmdSimpleFSCopy",
"creates",
"a",
"new",
"cli",
".",
"Command",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/client/cmd_simplefs_copy.go#L31-L70 |
161,233 | keybase/client | go/kbfs/dokan/dokan.go | Mount | func Mount(cfg *Config) (*MountHandle, error) {
err := loadDokanDLL(cfg)
if err != nil {
return nil, err
}
var ec = make(chan error, 2)
var slot = fsTableStore(cfg.FileSystem, ec)
flags := cfg.MountFlags
go func() {
ctx := allocCtx(slot)
defer ctx.Free()
ec <- ctx.Run(cfg.Path, flags)
close(ec)
}()
// This gets a send from either
// 1) DokanMain from ctx.Run returns an error before mount
// 2) After the filesystem is mounted from handling the Mounted callback.
// Thus either the filesystem was mounted ok or it was not mounted
// and an err is not nil. DokanMain does not return errors after the
// mount, but if such errors occured they can be catched by BlockTillDone.
err = <-ec
if err != nil {
return nil, err
}
return &MountHandle{ec, cfg.Path}, nil
} | go | func Mount(cfg *Config) (*MountHandle, error) {
err := loadDokanDLL(cfg)
if err != nil {
return nil, err
}
var ec = make(chan error, 2)
var slot = fsTableStore(cfg.FileSystem, ec)
flags := cfg.MountFlags
go func() {
ctx := allocCtx(slot)
defer ctx.Free()
ec <- ctx.Run(cfg.Path, flags)
close(ec)
}()
// This gets a send from either
// 1) DokanMain from ctx.Run returns an error before mount
// 2) After the filesystem is mounted from handling the Mounted callback.
// Thus either the filesystem was mounted ok or it was not mounted
// and an err is not nil. DokanMain does not return errors after the
// mount, but if such errors occured they can be catched by BlockTillDone.
err = <-ec
if err != nil {
return nil, err
}
return &MountHandle{ec, cfg.Path}, nil
} | [
"func",
"Mount",
"(",
"cfg",
"*",
"Config",
")",
"(",
"*",
"MountHandle",
",",
"error",
")",
"{",
"err",
":=",
"loadDokanDLL",
"(",
"cfg",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"var",
"ec",
"=",
"make",
"(",
"chan",
"error",
",",
"2",
")",
"\n",
"var",
"slot",
"=",
"fsTableStore",
"(",
"cfg",
".",
"FileSystem",
",",
"ec",
")",
"\n",
"flags",
":=",
"cfg",
".",
"MountFlags",
"\n",
"go",
"func",
"(",
")",
"{",
"ctx",
":=",
"allocCtx",
"(",
"slot",
")",
"\n",
"defer",
"ctx",
".",
"Free",
"(",
")",
"\n",
"ec",
"<-",
"ctx",
".",
"Run",
"(",
"cfg",
".",
"Path",
",",
"flags",
")",
"\n",
"close",
"(",
"ec",
")",
"\n",
"}",
"(",
")",
"\n",
"// This gets a send from either",
"// 1) DokanMain from ctx.Run returns an error before mount",
"// 2) After the filesystem is mounted from handling the Mounted callback.",
"// Thus either the filesystem was mounted ok or it was not mounted",
"// and an err is not nil. DokanMain does not return errors after the",
"// mount, but if such errors occured they can be catched by BlockTillDone.",
"err",
"=",
"<-",
"ec",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"MountHandle",
"{",
"ec",
",",
"cfg",
".",
"Path",
"}",
",",
"nil",
"\n",
"}"
] | // Mount mounts a FileSystem with the given Config.
// Mount returns when the filesystem has been mounted or there is an error. | [
"Mount",
"mounts",
"a",
"FileSystem",
"with",
"the",
"given",
"Config",
".",
"Mount",
"returns",
"when",
"the",
"filesystem",
"has",
"been",
"mounted",
"or",
"there",
"is",
"an",
"error",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/dokan/dokan.go#L20-L45 |
161,234 | keybase/client | go/kbfs/dokan/dokan.go | IsRequestorUserSidEqualTo | func (fi *FileInfo) IsRequestorUserSidEqualTo(sid *winacl.SID) bool {
return fi.isRequestorUserSidEqualTo(sid)
} | go | func (fi *FileInfo) IsRequestorUserSidEqualTo(sid *winacl.SID) bool {
return fi.isRequestorUserSidEqualTo(sid)
} | [
"func",
"(",
"fi",
"*",
"FileInfo",
")",
"IsRequestorUserSidEqualTo",
"(",
"sid",
"*",
"winacl",
".",
"SID",
")",
"bool",
"{",
"return",
"fi",
".",
"isRequestorUserSidEqualTo",
"(",
"sid",
")",
"\n",
"}"
] | // IsRequestorUserSidEqualTo returns true if the argument is equal
// to the sid of the user associated with the filesystem request. | [
"IsRequestorUserSidEqualTo",
"returns",
"true",
"if",
"the",
"argument",
"is",
"equal",
"to",
"the",
"sid",
"of",
"the",
"user",
"associated",
"with",
"the",
"filesystem",
"request",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/dokan/dokan.go#L80-L82 |
161,235 | keybase/client | go/kbfs/dokan/dokan.go | NumberOfFileHandles | func (fi *FileInfo) NumberOfFileHandles() uint32 {
return fsTableGetFileCount(uint32(fi.ptr.DokanOptions.GlobalContext))
} | go | func (fi *FileInfo) NumberOfFileHandles() uint32 {
return fsTableGetFileCount(uint32(fi.ptr.DokanOptions.GlobalContext))
} | [
"func",
"(",
"fi",
"*",
"FileInfo",
")",
"NumberOfFileHandles",
"(",
")",
"uint32",
"{",
"return",
"fsTableGetFileCount",
"(",
"uint32",
"(",
"fi",
".",
"ptr",
".",
"DokanOptions",
".",
"GlobalContext",
")",
")",
"\n",
"}"
] | // NumberOfFileHandles returns the number of open file handles for
// this filesystem. | [
"NumberOfFileHandles",
"returns",
"the",
"number",
"of",
"open",
"file",
"handles",
"for",
"this",
"filesystem",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/dokan/dokan.go#L86-L88 |
161,236 | keybase/client | go/protocol/keybase1/track.go | TrackWithToken | func (c TrackClient) TrackWithToken(ctx context.Context, __arg TrackWithTokenArg) (err error) {
err = c.Cli.Call(ctx, "keybase.1.track.trackWithToken", []interface{}{__arg}, nil)
return
} | go | func (c TrackClient) TrackWithToken(ctx context.Context, __arg TrackWithTokenArg) (err error) {
err = c.Cli.Call(ctx, "keybase.1.track.trackWithToken", []interface{}{__arg}, nil)
return
} | [
"func",
"(",
"c",
"TrackClient",
")",
"TrackWithToken",
"(",
"ctx",
"context",
".",
"Context",
",",
"__arg",
"TrackWithTokenArg",
")",
"(",
"err",
"error",
")",
"{",
"err",
"=",
"c",
".",
"Cli",
".",
"Call",
"(",
"ctx",
",",
"\"",
"\"",
",",
"[",
"]",
"interface",
"{",
"}",
"{",
"__arg",
"}",
",",
"nil",
")",
"\n",
"return",
"\n",
"}"
] | // Track with token returned from identify. | [
"Track",
"with",
"token",
"returned",
"from",
"identify",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/protocol/keybase1/track.go#L169-L172 |
161,237 | keybase/client | go/kbfs/libfuse/rekey_file.go | Write | func (f *RekeyFile) Write(ctx context.Context, req *fuse.WriteRequest,
resp *fuse.WriteResponse) (err error) {
f.folder.fs.log.CDebugf(ctx, "RekeyFile Write")
defer func() { err = f.folder.processError(ctx, libkbfs.WriteMode, err) }()
if len(req.Data) == 0 {
return nil
}
_, err = libkbfs.RequestRekeyAndWaitForOneFinishEvent(ctx,
f.folder.fs.config.KBFSOps(), f.folder.getFolderBranch().Tlf)
if err != nil {
return err
}
f.folder.fs.NotificationGroupWait()
resp.Size = len(req.Data)
return nil
} | go | func (f *RekeyFile) Write(ctx context.Context, req *fuse.WriteRequest,
resp *fuse.WriteResponse) (err error) {
f.folder.fs.log.CDebugf(ctx, "RekeyFile Write")
defer func() { err = f.folder.processError(ctx, libkbfs.WriteMode, err) }()
if len(req.Data) == 0 {
return nil
}
_, err = libkbfs.RequestRekeyAndWaitForOneFinishEvent(ctx,
f.folder.fs.config.KBFSOps(), f.folder.getFolderBranch().Tlf)
if err != nil {
return err
}
f.folder.fs.NotificationGroupWait()
resp.Size = len(req.Data)
return nil
} | [
"func",
"(",
"f",
"*",
"RekeyFile",
")",
"Write",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"fuse",
".",
"WriteRequest",
",",
"resp",
"*",
"fuse",
".",
"WriteResponse",
")",
"(",
"err",
"error",
")",
"{",
"f",
".",
"folder",
".",
"fs",
".",
"log",
".",
"CDebugf",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"err",
"=",
"f",
".",
"folder",
".",
"processError",
"(",
"ctx",
",",
"libkbfs",
".",
"WriteMode",
",",
"err",
")",
"}",
"(",
")",
"\n",
"if",
"len",
"(",
"req",
".",
"Data",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"_",
",",
"err",
"=",
"libkbfs",
".",
"RequestRekeyAndWaitForOneFinishEvent",
"(",
"ctx",
",",
"f",
".",
"folder",
".",
"fs",
".",
"config",
".",
"KBFSOps",
"(",
")",
",",
"f",
".",
"folder",
".",
"getFolderBranch",
"(",
")",
".",
"Tlf",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"f",
".",
"folder",
".",
"fs",
".",
"NotificationGroupWait",
"(",
")",
"\n",
"resp",
".",
"Size",
"=",
"len",
"(",
"req",
".",
"Data",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // Write implements the fs.HandleWriter interface for RekeyFile. | [
"Write",
"implements",
"the",
"fs",
".",
"HandleWriter",
"interface",
"for",
"RekeyFile",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfuse/rekey_file.go#L36-L51 |
161,238 | keybase/client | go/service/kbfs_mount_windows.go | getVolumeName | func getVolumeName(RootPathName string) (string, error) {
var VolumeNameBuffer = make([]uint16, syscall.MAX_PATH+1)
var nVolumeNameSize = uint32(len(VolumeNameBuffer))
_, _, callErr := getVolumeProc.Call(
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(RootPathName))),
uintptr(unsafe.Pointer(&VolumeNameBuffer[0])),
uintptr(nVolumeNameSize),
uintptr(0),
uintptr(0),
uintptr(0),
uintptr(0),
uintptr(0),
0)
if callErr != nil {
return "", callErr
}
return syscall.UTF16ToString(VolumeNameBuffer), nil
} | go | func getVolumeName(RootPathName string) (string, error) {
var VolumeNameBuffer = make([]uint16, syscall.MAX_PATH+1)
var nVolumeNameSize = uint32(len(VolumeNameBuffer))
_, _, callErr := getVolumeProc.Call(
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(RootPathName))),
uintptr(unsafe.Pointer(&VolumeNameBuffer[0])),
uintptr(nVolumeNameSize),
uintptr(0),
uintptr(0),
uintptr(0),
uintptr(0),
uintptr(0),
0)
if callErr != nil {
return "", callErr
}
return syscall.UTF16ToString(VolumeNameBuffer), nil
} | [
"func",
"getVolumeName",
"(",
"RootPathName",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"var",
"VolumeNameBuffer",
"=",
"make",
"(",
"[",
"]",
"uint16",
",",
"syscall",
".",
"MAX_PATH",
"+",
"1",
")",
"\n",
"var",
"nVolumeNameSize",
"=",
"uint32",
"(",
"len",
"(",
"VolumeNameBuffer",
")",
")",
"\n\n",
"_",
",",
"_",
",",
"callErr",
":=",
"getVolumeProc",
".",
"Call",
"(",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"syscall",
".",
"StringToUTF16Ptr",
"(",
"RootPathName",
")",
")",
")",
",",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"VolumeNameBuffer",
"[",
"0",
"]",
")",
")",
",",
"uintptr",
"(",
"nVolumeNameSize",
")",
",",
"uintptr",
"(",
"0",
")",
",",
"uintptr",
"(",
"0",
")",
",",
"uintptr",
"(",
"0",
")",
",",
"uintptr",
"(",
"0",
")",
",",
"uintptr",
"(",
"0",
")",
",",
"0",
")",
"\n\n",
"if",
"callErr",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"callErr",
"\n",
"}",
"\n\n",
"return",
"syscall",
".",
"UTF16ToString",
"(",
"VolumeNameBuffer",
")",
",",
"nil",
"\n",
"}"
] | // getVolumeName requires a drive letter and colon with a
// trailing backslash | [
"getVolumeName",
"requires",
"a",
"drive",
"letter",
"and",
"colon",
"with",
"a",
"trailing",
"backslash"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/service/kbfs_mount_windows.go#L31-L51 |
161,239 | keybase/client | go/service/kbfs_mount_windows.go | getDosVolumeName | func getDosVolumeName(path string) (string, error) {
var VolumeNameBuffer = make([]uint16, syscall.MAX_PATH+1)
var nVolumeNameSize = uint32(len(VolumeNameBuffer))
ret, _, err := queryDosDeviceProc.Call(
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(path))),
uintptr(unsafe.Pointer(&VolumeNameBuffer[0])),
uintptr(nVolumeNameSize))
if ret == 0 {
return "", err
}
return syscall.UTF16ToString(VolumeNameBuffer), nil
} | go | func getDosVolumeName(path string) (string, error) {
var VolumeNameBuffer = make([]uint16, syscall.MAX_PATH+1)
var nVolumeNameSize = uint32(len(VolumeNameBuffer))
ret, _, err := queryDosDeviceProc.Call(
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(path))),
uintptr(unsafe.Pointer(&VolumeNameBuffer[0])),
uintptr(nVolumeNameSize))
if ret == 0 {
return "", err
}
return syscall.UTF16ToString(VolumeNameBuffer), nil
} | [
"func",
"getDosVolumeName",
"(",
"path",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"var",
"VolumeNameBuffer",
"=",
"make",
"(",
"[",
"]",
"uint16",
",",
"syscall",
".",
"MAX_PATH",
"+",
"1",
")",
"\n",
"var",
"nVolumeNameSize",
"=",
"uint32",
"(",
"len",
"(",
"VolumeNameBuffer",
")",
")",
"\n\n",
"ret",
",",
"_",
",",
"err",
":=",
"queryDosDeviceProc",
".",
"Call",
"(",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"syscall",
".",
"StringToUTF16Ptr",
"(",
"path",
")",
")",
")",
",",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"VolumeNameBuffer",
"[",
"0",
"]",
")",
")",
",",
"uintptr",
"(",
"nVolumeNameSize",
")",
")",
"\n\n",
"if",
"ret",
"==",
"0",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"syscall",
".",
"UTF16ToString",
"(",
"VolumeNameBuffer",
")",
",",
"nil",
"\n",
"}"
] | // getDosVolumeName requires a drive letter and colon with no
// trailing backslash | [
"getDosVolumeName",
"requires",
"a",
"drive",
"letter",
"and",
"colon",
"with",
"no",
"trailing",
"backslash"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/service/kbfs_mount_windows.go#L55-L70 |
161,240 | keybase/client | go/libkb/assertion_parser.go | stripBuffer | func (lx *Lexer) stripBuffer() {
if len(lx.buffer) > 0 {
if match := lexerWhitespaceRxx.FindSubmatchIndex(lx.buffer); match != nil {
lx.buffer = lx.buffer[match[3]:]
}
}
} | go | func (lx *Lexer) stripBuffer() {
if len(lx.buffer) > 0 {
if match := lexerWhitespaceRxx.FindSubmatchIndex(lx.buffer); match != nil {
lx.buffer = lx.buffer[match[3]:]
}
}
} | [
"func",
"(",
"lx",
"*",
"Lexer",
")",
"stripBuffer",
"(",
")",
"{",
"if",
"len",
"(",
"lx",
".",
"buffer",
")",
">",
"0",
"{",
"if",
"match",
":=",
"lexerWhitespaceRxx",
".",
"FindSubmatchIndex",
"(",
"lx",
".",
"buffer",
")",
";",
"match",
"!=",
"nil",
"{",
"lx",
".",
"buffer",
"=",
"lx",
".",
"buffer",
"[",
"match",
"[",
"3",
"]",
":",
"]",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // strip whitespace off the front | [
"strip",
"whitespace",
"off",
"the",
"front"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/assertion_parser.go#L90-L96 |
161,241 | keybase/client | go/libkb/assertion_parser.go | ParseAssertionsWithReaders | func ParseAssertionsWithReaders(ctx AssertionContext, assertions string) (writers, readers []AssertionExpression, err error) {
if len(assertions) == 0 {
return writers, readers, fmt.Errorf("empty assertion")
}
split := strings.Split(assertions, "#")
if len(split) > 2 {
return writers, readers, fmt.Errorf("too many reader divisions ('#') in assertions: %v", assertions)
}
writers, err = ParseAssertionList(ctx, split[0])
if err != nil {
return writers, readers, err
}
if len(split) >= 2 && len(split[1]) > 0 {
readers, err = ParseAssertionList(ctx, split[1])
if err != nil {
return writers, readers, err
}
}
return writers, readers, nil
} | go | func ParseAssertionsWithReaders(ctx AssertionContext, assertions string) (writers, readers []AssertionExpression, err error) {
if len(assertions) == 0 {
return writers, readers, fmt.Errorf("empty assertion")
}
split := strings.Split(assertions, "#")
if len(split) > 2 {
return writers, readers, fmt.Errorf("too many reader divisions ('#') in assertions: %v", assertions)
}
writers, err = ParseAssertionList(ctx, split[0])
if err != nil {
return writers, readers, err
}
if len(split) >= 2 && len(split[1]) > 0 {
readers, err = ParseAssertionList(ctx, split[1])
if err != nil {
return writers, readers, err
}
}
return writers, readers, nil
} | [
"func",
"ParseAssertionsWithReaders",
"(",
"ctx",
"AssertionContext",
",",
"assertions",
"string",
")",
"(",
"writers",
",",
"readers",
"[",
"]",
"AssertionExpression",
",",
"err",
"error",
")",
"{",
"if",
"len",
"(",
"assertions",
")",
"==",
"0",
"{",
"return",
"writers",
",",
"readers",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"split",
":=",
"strings",
".",
"Split",
"(",
"assertions",
",",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"split",
")",
">",
"2",
"{",
"return",
"writers",
",",
"readers",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"assertions",
")",
"\n",
"}",
"\n\n",
"writers",
",",
"err",
"=",
"ParseAssertionList",
"(",
"ctx",
",",
"split",
"[",
"0",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"writers",
",",
"readers",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"split",
")",
">=",
"2",
"&&",
"len",
"(",
"split",
"[",
"1",
"]",
")",
">",
"0",
"{",
"readers",
",",
"err",
"=",
"ParseAssertionList",
"(",
"ctx",
",",
"split",
"[",
"1",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"writers",
",",
"readers",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"writers",
",",
"readers",
",",
"nil",
"\n",
"}"
] | // Parse an assertion list like "alice,bob&&bob@twitter#char"
// OR nodes are not allowed (asides from the commas) | [
"Parse",
"an",
"assertion",
"list",
"like",
"alice",
"bob&&bob"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/assertion_parser.go#L268-L290 |
161,242 | keybase/client | go/libkb/assertion_parser.go | ParseAssertionList | func ParseAssertionList(ctx AssertionContext, assertionsStr string) (res []AssertionExpression, err error) {
expr, err := AssertionParse(ctx, assertionsStr)
if err != nil {
return res, err
}
return unpackAssertionList(expr)
} | go | func ParseAssertionList(ctx AssertionContext, assertionsStr string) (res []AssertionExpression, err error) {
expr, err := AssertionParse(ctx, assertionsStr)
if err != nil {
return res, err
}
return unpackAssertionList(expr)
} | [
"func",
"ParseAssertionList",
"(",
"ctx",
"AssertionContext",
",",
"assertionsStr",
"string",
")",
"(",
"res",
"[",
"]",
"AssertionExpression",
",",
"err",
"error",
")",
"{",
"expr",
",",
"err",
":=",
"AssertionParse",
"(",
"ctx",
",",
"assertionsStr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"res",
",",
"err",
"\n",
"}",
"\n",
"return",
"unpackAssertionList",
"(",
"expr",
")",
"\n",
"}"
] | // Parse a string into one or more assertions. Only AND assertions are allowed within each part.
// like "alice,bob&&bob@twitter" | [
"Parse",
"a",
"string",
"into",
"one",
"or",
"more",
"assertions",
".",
"Only",
"AND",
"assertions",
"are",
"allowed",
"within",
"each",
"part",
".",
"like",
"alice",
"bob&&bob"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/assertion_parser.go#L294-L300 |
161,243 | keybase/client | go/libkb/assertion_parser.go | unpackAssertionList | func unpackAssertionList(expr AssertionExpression) (res []AssertionExpression, err error) {
switch expr := expr.(type) {
case AssertionOr:
// List (or recursive tree) of comma-separated items.
if expr.symbol != "," {
// Don't allow "||". That would be confusing.
return res, fmt.Errorf("disallowed OR expression: '%v'", expr.symbol)
}
for _, sub := range expr.terms {
// Recurse because "a,b,c" could look like (OR a (OR b c))
sublist, err := unpackAssertionList(sub)
if err != nil {
return res, err
}
res = append(res, sublist...)
}
return res, nil
default:
// Just one item.
err = checkAssertionListItem(expr)
return []AssertionExpression{expr}, err
}
} | go | func unpackAssertionList(expr AssertionExpression) (res []AssertionExpression, err error) {
switch expr := expr.(type) {
case AssertionOr:
// List (or recursive tree) of comma-separated items.
if expr.symbol != "," {
// Don't allow "||". That would be confusing.
return res, fmt.Errorf("disallowed OR expression: '%v'", expr.symbol)
}
for _, sub := range expr.terms {
// Recurse because "a,b,c" could look like (OR a (OR b c))
sublist, err := unpackAssertionList(sub)
if err != nil {
return res, err
}
res = append(res, sublist...)
}
return res, nil
default:
// Just one item.
err = checkAssertionListItem(expr)
return []AssertionExpression{expr}, err
}
} | [
"func",
"unpackAssertionList",
"(",
"expr",
"AssertionExpression",
")",
"(",
"res",
"[",
"]",
"AssertionExpression",
",",
"err",
"error",
")",
"{",
"switch",
"expr",
":=",
"expr",
".",
"(",
"type",
")",
"{",
"case",
"AssertionOr",
":",
"// List (or recursive tree) of comma-separated items.",
"if",
"expr",
".",
"symbol",
"!=",
"\"",
"\"",
"{",
"// Don't allow \"||\". That would be confusing.",
"return",
"res",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"expr",
".",
"symbol",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"sub",
":=",
"range",
"expr",
".",
"terms",
"{",
"// Recurse because \"a,b,c\" could look like (OR a (OR b c))",
"sublist",
",",
"err",
":=",
"unpackAssertionList",
"(",
"sub",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"res",
",",
"err",
"\n",
"}",
"\n",
"res",
"=",
"append",
"(",
"res",
",",
"sublist",
"...",
")",
"\n",
"}",
"\n",
"return",
"res",
",",
"nil",
"\n",
"default",
":",
"// Just one item.",
"err",
"=",
"checkAssertionListItem",
"(",
"expr",
")",
"\n",
"return",
"[",
"]",
"AssertionExpression",
"{",
"expr",
"}",
",",
"err",
"\n",
"}",
"\n",
"}"
] | // Unpack an assertion with one or more comma-separated parts. Only AND assertions are allowed within each part. | [
"Unpack",
"an",
"assertion",
"with",
"one",
"or",
"more",
"comma",
"-",
"separated",
"parts",
".",
"Only",
"AND",
"assertions",
"are",
"allowed",
"within",
"each",
"part",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/assertion_parser.go#L303-L326 |
161,244 | keybase/client | go/libkb/assertion_parser.go | checkAssertionListItem | func checkAssertionListItem(expr AssertionExpression) error {
if expr.HasOr() {
return fmt.Errorf("assertions with OR are not allowed here")
}
switch expr.(type) {
case AssertionOr:
// this should never happen
return fmt.Errorf("assertion parse fault: unexpected OR")
}
// Anything else is allowed.
return nil
} | go | func checkAssertionListItem(expr AssertionExpression) error {
if expr.HasOr() {
return fmt.Errorf("assertions with OR are not allowed here")
}
switch expr.(type) {
case AssertionOr:
// this should never happen
return fmt.Errorf("assertion parse fault: unexpected OR")
}
// Anything else is allowed.
return nil
} | [
"func",
"checkAssertionListItem",
"(",
"expr",
"AssertionExpression",
")",
"error",
"{",
"if",
"expr",
".",
"HasOr",
"(",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"switch",
"expr",
".",
"(",
"type",
")",
"{",
"case",
"AssertionOr",
":",
"// this should never happen",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"// Anything else is allowed.",
"return",
"nil",
"\n",
"}"
] | // A single item in a comma-separated assertion list must not have any ORs in its subtree. | [
"A",
"single",
"item",
"in",
"a",
"comma",
"-",
"separated",
"assertion",
"list",
"must",
"not",
"have",
"any",
"ORs",
"in",
"its",
"subtree",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/assertion_parser.go#L329-L340 |
161,245 | keybase/client | go/kbfs/kbfsedits/user_history.go | NewUserHistory | func NewUserHistory(log logger.Logger, vlog *libkb.VDebugLog) *UserHistory {
return &UserHistory{
histories: make(map[tlfKey]writersByRevision),
log: log,
vlog: vlog,
}
} | go | func NewUserHistory(log logger.Logger, vlog *libkb.VDebugLog) *UserHistory {
return &UserHistory{
histories: make(map[tlfKey]writersByRevision),
log: log,
vlog: vlog,
}
} | [
"func",
"NewUserHistory",
"(",
"log",
"logger",
".",
"Logger",
",",
"vlog",
"*",
"libkb",
".",
"VDebugLog",
")",
"*",
"UserHistory",
"{",
"return",
"&",
"UserHistory",
"{",
"histories",
":",
"make",
"(",
"map",
"[",
"tlfKey",
"]",
"writersByRevision",
")",
",",
"log",
":",
"log",
",",
"vlog",
":",
"vlog",
",",
"}",
"\n",
"}"
] | // NewUserHistory constructs a UserHistory instance. | [
"NewUserHistory",
"constructs",
"a",
"UserHistory",
"instance",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/kbfsedits/user_history.go#L46-L52 |
161,246 | keybase/client | go/kbfs/kbfsedits/user_history.go | UpdateHistory | func (uh *UserHistory) UpdateHistory(
tlfName tlf.CanonicalName, tlfType tlf.Type, tlfHistory *TlfHistory,
loggedInUser string) {
uh.vlog.CLogf(nil, libkb.VLog1, "Updating user history for TLF %s, "+
"user %s", tlfName, loggedInUser)
history := tlfHistory.getHistory(loggedInUser)
key := tlfKey{tlfName, tlfType}
uh.lock.Lock()
defer uh.lock.Unlock()
uh.histories[key] = history
} | go | func (uh *UserHistory) UpdateHistory(
tlfName tlf.CanonicalName, tlfType tlf.Type, tlfHistory *TlfHistory,
loggedInUser string) {
uh.vlog.CLogf(nil, libkb.VLog1, "Updating user history for TLF %s, "+
"user %s", tlfName, loggedInUser)
history := tlfHistory.getHistory(loggedInUser)
key := tlfKey{tlfName, tlfType}
uh.lock.Lock()
defer uh.lock.Unlock()
uh.histories[key] = history
} | [
"func",
"(",
"uh",
"*",
"UserHistory",
")",
"UpdateHistory",
"(",
"tlfName",
"tlf",
".",
"CanonicalName",
",",
"tlfType",
"tlf",
".",
"Type",
",",
"tlfHistory",
"*",
"TlfHistory",
",",
"loggedInUser",
"string",
")",
"{",
"uh",
".",
"vlog",
".",
"CLogf",
"(",
"nil",
",",
"libkb",
".",
"VLog1",
",",
"\"",
"\"",
"+",
"\"",
"\"",
",",
"tlfName",
",",
"loggedInUser",
")",
"\n",
"history",
":=",
"tlfHistory",
".",
"getHistory",
"(",
"loggedInUser",
")",
"\n",
"key",
":=",
"tlfKey",
"{",
"tlfName",
",",
"tlfType",
"}",
"\n\n",
"uh",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"uh",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"uh",
".",
"histories",
"[",
"key",
"]",
"=",
"history",
"\n",
"}"
] | // UpdateHistory should be called whenever the edit history for a
// given TLF gets new information. | [
"UpdateHistory",
"should",
"be",
"called",
"whenever",
"the",
"edit",
"history",
"for",
"a",
"given",
"TLF",
"gets",
"new",
"information",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/kbfsedits/user_history.go#L56-L67 |
161,247 | keybase/client | go/kbfs/kbfsedits/user_history.go | GetTlfHistory | func (uh *UserHistory) GetTlfHistory(
tlfName tlf.CanonicalName, tlfType tlf.Type) (
history keybase1.FSFolderEditHistory) {
uh.lock.RLock()
defer uh.lock.RUnlock()
return uh.getTlfHistoryLocked(tlfName, tlfType)
} | go | func (uh *UserHistory) GetTlfHistory(
tlfName tlf.CanonicalName, tlfType tlf.Type) (
history keybase1.FSFolderEditHistory) {
uh.lock.RLock()
defer uh.lock.RUnlock()
return uh.getTlfHistoryLocked(tlfName, tlfType)
} | [
"func",
"(",
"uh",
"*",
"UserHistory",
")",
"GetTlfHistory",
"(",
"tlfName",
"tlf",
".",
"CanonicalName",
",",
"tlfType",
"tlf",
".",
"Type",
")",
"(",
"history",
"keybase1",
".",
"FSFolderEditHistory",
")",
"{",
"uh",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"uh",
".",
"lock",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"uh",
".",
"getTlfHistoryLocked",
"(",
"tlfName",
",",
"tlfType",
")",
"\n",
"}"
] | // GetTlfHistory returns the edit history of a given TLF, converted to
// keybase1 protocol structs. | [
"GetTlfHistory",
"returns",
"the",
"edit",
"history",
"of",
"a",
"given",
"TLF",
"converted",
"to",
"keybase1",
"protocol",
"structs",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/kbfsedits/user_history.go#L128-L134 |
161,248 | keybase/client | go/kbfs/kbfsedits/user_history.go | Get | func (uh *UserHistory) Get(loggedInUser string) (
history []keybase1.FSFolderEditHistory) {
uh.lock.RLock()
defer uh.lock.RUnlock()
uh.vlog.CLogf(nil, libkb.VLog1, "User history requested: %s", loggedInUser)
var clusters historyClusters
for key := range uh.histories {
history := uh.getTlfHistoryLocked(key.tlfName, key.tlfType)
// Only include public TLFs if they match the logged-in user.
if history.Folder.FolderType == keybase1.FolderType_PUBLIC {
names := strings.Split(history.Folder.Name, ",")
match := false
for _, name := range names {
if name == loggedInUser {
match = true
break
}
}
if !match {
continue
}
}
// Break it up into individual clusters
for _, wh := range history.History {
if len(wh.Edits) > 0 || len(wh.Deletes) > 0 {
var serverTime keybase1.Time
if len(wh.Edits) > 0 {
serverTime = wh.Edits[0].ServerTime
}
clusters = append(clusters, keybase1.FSFolderEditHistory{
Folder: history.Folder,
ServerTime: serverTime,
History: []keybase1.FSFolderWriterEditHistory{wh},
})
}
}
}
// We need to sort these by the ServerTime of these particular edits,
// not by the full TLF time.
sort.Sort(clusters)
// TODO: consolidate neighboring clusters that share the same folder?
if len(clusters) > MaxClusters {
// Find the top self-clusters.
loggedInIndices := make([]int, 0, minNumSelfClusters)
for i, c := range clusters {
if c.History[0].WriterName == loggedInUser {
loggedInIndices = append(loggedInIndices, i)
}
if len(loggedInIndices) == minNumSelfClusters {
break
}
}
// Move each self-cluster into its rightful spot at the end of
// the slice, unless it's already at a lower index.
for i, loggedInIndex := range loggedInIndices {
newLoggedInIndex := MaxClusters - (len(loggedInIndices) - i)
if loggedInIndex < newLoggedInIndex {
continue
}
clusters[newLoggedInIndex] = clusters[loggedInIndex]
}
return clusters[:MaxClusters]
}
return clusters
} | go | func (uh *UserHistory) Get(loggedInUser string) (
history []keybase1.FSFolderEditHistory) {
uh.lock.RLock()
defer uh.lock.RUnlock()
uh.vlog.CLogf(nil, libkb.VLog1, "User history requested: %s", loggedInUser)
var clusters historyClusters
for key := range uh.histories {
history := uh.getTlfHistoryLocked(key.tlfName, key.tlfType)
// Only include public TLFs if they match the logged-in user.
if history.Folder.FolderType == keybase1.FolderType_PUBLIC {
names := strings.Split(history.Folder.Name, ",")
match := false
for _, name := range names {
if name == loggedInUser {
match = true
break
}
}
if !match {
continue
}
}
// Break it up into individual clusters
for _, wh := range history.History {
if len(wh.Edits) > 0 || len(wh.Deletes) > 0 {
var serverTime keybase1.Time
if len(wh.Edits) > 0 {
serverTime = wh.Edits[0].ServerTime
}
clusters = append(clusters, keybase1.FSFolderEditHistory{
Folder: history.Folder,
ServerTime: serverTime,
History: []keybase1.FSFolderWriterEditHistory{wh},
})
}
}
}
// We need to sort these by the ServerTime of these particular edits,
// not by the full TLF time.
sort.Sort(clusters)
// TODO: consolidate neighboring clusters that share the same folder?
if len(clusters) > MaxClusters {
// Find the top self-clusters.
loggedInIndices := make([]int, 0, minNumSelfClusters)
for i, c := range clusters {
if c.History[0].WriterName == loggedInUser {
loggedInIndices = append(loggedInIndices, i)
}
if len(loggedInIndices) == minNumSelfClusters {
break
}
}
// Move each self-cluster into its rightful spot at the end of
// the slice, unless it's already at a lower index.
for i, loggedInIndex := range loggedInIndices {
newLoggedInIndex := MaxClusters - (len(loggedInIndices) - i)
if loggedInIndex < newLoggedInIndex {
continue
}
clusters[newLoggedInIndex] = clusters[loggedInIndex]
}
return clusters[:MaxClusters]
}
return clusters
} | [
"func",
"(",
"uh",
"*",
"UserHistory",
")",
"Get",
"(",
"loggedInUser",
"string",
")",
"(",
"history",
"[",
"]",
"keybase1",
".",
"FSFolderEditHistory",
")",
"{",
"uh",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"uh",
".",
"lock",
".",
"RUnlock",
"(",
")",
"\n",
"uh",
".",
"vlog",
".",
"CLogf",
"(",
"nil",
",",
"libkb",
".",
"VLog1",
",",
"\"",
"\"",
",",
"loggedInUser",
")",
"\n",
"var",
"clusters",
"historyClusters",
"\n",
"for",
"key",
":=",
"range",
"uh",
".",
"histories",
"{",
"history",
":=",
"uh",
".",
"getTlfHistoryLocked",
"(",
"key",
".",
"tlfName",
",",
"key",
".",
"tlfType",
")",
"\n\n",
"// Only include public TLFs if they match the logged-in user.",
"if",
"history",
".",
"Folder",
".",
"FolderType",
"==",
"keybase1",
".",
"FolderType_PUBLIC",
"{",
"names",
":=",
"strings",
".",
"Split",
"(",
"history",
".",
"Folder",
".",
"Name",
",",
"\"",
"\"",
")",
"\n",
"match",
":=",
"false",
"\n",
"for",
"_",
",",
"name",
":=",
"range",
"names",
"{",
"if",
"name",
"==",
"loggedInUser",
"{",
"match",
"=",
"true",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"!",
"match",
"{",
"continue",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Break it up into individual clusters",
"for",
"_",
",",
"wh",
":=",
"range",
"history",
".",
"History",
"{",
"if",
"len",
"(",
"wh",
".",
"Edits",
")",
">",
"0",
"||",
"len",
"(",
"wh",
".",
"Deletes",
")",
">",
"0",
"{",
"var",
"serverTime",
"keybase1",
".",
"Time",
"\n",
"if",
"len",
"(",
"wh",
".",
"Edits",
")",
">",
"0",
"{",
"serverTime",
"=",
"wh",
".",
"Edits",
"[",
"0",
"]",
".",
"ServerTime",
"\n",
"}",
"\n",
"clusters",
"=",
"append",
"(",
"clusters",
",",
"keybase1",
".",
"FSFolderEditHistory",
"{",
"Folder",
":",
"history",
".",
"Folder",
",",
"ServerTime",
":",
"serverTime",
",",
"History",
":",
"[",
"]",
"keybase1",
".",
"FSFolderWriterEditHistory",
"{",
"wh",
"}",
",",
"}",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"// We need to sort these by the ServerTime of these particular edits,",
"// not by the full TLF time.",
"sort",
".",
"Sort",
"(",
"clusters",
")",
"\n\n",
"// TODO: consolidate neighboring clusters that share the same folder?",
"if",
"len",
"(",
"clusters",
")",
">",
"MaxClusters",
"{",
"// Find the top self-clusters.",
"loggedInIndices",
":=",
"make",
"(",
"[",
"]",
"int",
",",
"0",
",",
"minNumSelfClusters",
")",
"\n",
"for",
"i",
",",
"c",
":=",
"range",
"clusters",
"{",
"if",
"c",
".",
"History",
"[",
"0",
"]",
".",
"WriterName",
"==",
"loggedInUser",
"{",
"loggedInIndices",
"=",
"append",
"(",
"loggedInIndices",
",",
"i",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"loggedInIndices",
")",
"==",
"minNumSelfClusters",
"{",
"break",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Move each self-cluster into its rightful spot at the end of",
"// the slice, unless it's already at a lower index.",
"for",
"i",
",",
"loggedInIndex",
":=",
"range",
"loggedInIndices",
"{",
"newLoggedInIndex",
":=",
"MaxClusters",
"-",
"(",
"len",
"(",
"loggedInIndices",
")",
"-",
"i",
")",
"\n",
"if",
"loggedInIndex",
"<",
"newLoggedInIndex",
"{",
"continue",
"\n",
"}",
"\n",
"clusters",
"[",
"newLoggedInIndex",
"]",
"=",
"clusters",
"[",
"loggedInIndex",
"]",
"\n",
"}",
"\n\n",
"return",
"clusters",
"[",
":",
"MaxClusters",
"]",
"\n",
"}",
"\n",
"return",
"clusters",
"\n",
"}"
] | // Get returns the full edit history for the user, converted to
// keybase1 protocol structs. | [
"Get",
"returns",
"the",
"full",
"edit",
"history",
"for",
"the",
"user",
"converted",
"to",
"keybase1",
"protocol",
"structs",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/kbfsedits/user_history.go#L165-L235 |
161,249 | keybase/client | go/kbfs/kbfsedits/user_history.go | Clear | func (uh *UserHistory) Clear() {
uh.lock.Lock()
defer uh.lock.Unlock()
uh.histories = make(map[tlfKey]writersByRevision)
} | go | func (uh *UserHistory) Clear() {
uh.lock.Lock()
defer uh.lock.Unlock()
uh.histories = make(map[tlfKey]writersByRevision)
} | [
"func",
"(",
"uh",
"*",
"UserHistory",
")",
"Clear",
"(",
")",
"{",
"uh",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"uh",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"uh",
".",
"histories",
"=",
"make",
"(",
"map",
"[",
"tlfKey",
"]",
"writersByRevision",
")",
"\n",
"}"
] | // Clear erases all saved histories; TLFs must be re-added. | [
"Clear",
"erases",
"all",
"saved",
"histories",
";",
"TLFs",
"must",
"be",
"re",
"-",
"added",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/kbfsedits/user_history.go#L238-L242 |
161,250 | keybase/client | go/kbfs/kbfsedits/user_history.go | ClearTLF | func (uh *UserHistory) ClearTLF(tlfName tlf.CanonicalName, tlfType tlf.Type) {
key := tlfKey{tlfName, tlfType}
uh.lock.Lock()
defer uh.lock.Unlock()
delete(uh.histories, key)
} | go | func (uh *UserHistory) ClearTLF(tlfName tlf.CanonicalName, tlfType tlf.Type) {
key := tlfKey{tlfName, tlfType}
uh.lock.Lock()
defer uh.lock.Unlock()
delete(uh.histories, key)
} | [
"func",
"(",
"uh",
"*",
"UserHistory",
")",
"ClearTLF",
"(",
"tlfName",
"tlf",
".",
"CanonicalName",
",",
"tlfType",
"tlf",
".",
"Type",
")",
"{",
"key",
":=",
"tlfKey",
"{",
"tlfName",
",",
"tlfType",
"}",
"\n",
"uh",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"uh",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"delete",
"(",
"uh",
".",
"histories",
",",
"key",
")",
"\n",
"}"
] | // ClearTLF removes a TLF from this UserHistory. | [
"ClearTLF",
"removes",
"a",
"TLF",
"from",
"this",
"UserHistory",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/kbfsedits/user_history.go#L245-L250 |
161,251 | keybase/client | go/libkb/merkle_tools.go | FindNextMerkleRootAfterRevoke | func FindNextMerkleRootAfterRevoke(m MetaContext, arg keybase1.FindNextMerkleRootAfterRevokeArg) (res keybase1.NextMerkleRootRes, err error) {
defer m.Trace(fmt.Sprintf("FindNextMerkleRootAfterRevoke(%+v)", arg), func() error { return err })()
var u *User
u, err = LoadUser(NewLoadUserArgWithMetaContext(m).WithUID(arg.Uid).WithPublicKeyOptional())
if err != nil {
return res, err
}
comparer := func(leaf *MerkleGenericLeaf, root *MerkleRoot) (bool, error) {
slot := leafSlot(leaf, keybase1.SeqType_PUBLIC)
if slot == nil {
return false, MerkleClientError{fmt.Sprintf("leaf at root %d returned with nil public part", *root.Seqno()), merkleErrorBadLeaf}
}
m.Debug("Comprator at Merkle root %d: found chain location is %d; searching for %d", *root.Seqno(), slot.Seqno, arg.Loc.Seqno)
return (slot.Seqno >= arg.Loc.Seqno), nil
}
leaf, root, err := findFirstLeafWithComparer(m, arg.Uid.AsUserOrTeam(), comparer, arg.Prev.Seqno)
if err != nil {
return res, err
}
if leaf == nil || root == nil {
return res, MerkleClientError{"no suitable leaf found", merkleErrorNoUpdates}
}
sigID := u.GetSigIDFromSeqno(leaf.Public.Seqno)
if sigID.IsNil() {
return res, MerkleClientError{fmt.Sprintf("unknown seqno in sigchain: %d", arg.Loc.Seqno), merkleErrorBadSeqno}
}
if !sigID.Equal(leaf.Public.SigID) {
return res, MerkleClientError{fmt.Sprintf("sigID sent down by server didn't match: %s != %s", sigID.String(), leaf.Public.SigID.String()), merkleErrorBadSigID}
}
res.Res = &keybase1.MerkleRootV2{
HashMeta: root.HashMeta(),
Seqno: *root.Seqno(),
}
m.Debug("res.Res: %+v", *res.Res)
return res, nil
} | go | func FindNextMerkleRootAfterRevoke(m MetaContext, arg keybase1.FindNextMerkleRootAfterRevokeArg) (res keybase1.NextMerkleRootRes, err error) {
defer m.Trace(fmt.Sprintf("FindNextMerkleRootAfterRevoke(%+v)", arg), func() error { return err })()
var u *User
u, err = LoadUser(NewLoadUserArgWithMetaContext(m).WithUID(arg.Uid).WithPublicKeyOptional())
if err != nil {
return res, err
}
comparer := func(leaf *MerkleGenericLeaf, root *MerkleRoot) (bool, error) {
slot := leafSlot(leaf, keybase1.SeqType_PUBLIC)
if slot == nil {
return false, MerkleClientError{fmt.Sprintf("leaf at root %d returned with nil public part", *root.Seqno()), merkleErrorBadLeaf}
}
m.Debug("Comprator at Merkle root %d: found chain location is %d; searching for %d", *root.Seqno(), slot.Seqno, arg.Loc.Seqno)
return (slot.Seqno >= arg.Loc.Seqno), nil
}
leaf, root, err := findFirstLeafWithComparer(m, arg.Uid.AsUserOrTeam(), comparer, arg.Prev.Seqno)
if err != nil {
return res, err
}
if leaf == nil || root == nil {
return res, MerkleClientError{"no suitable leaf found", merkleErrorNoUpdates}
}
sigID := u.GetSigIDFromSeqno(leaf.Public.Seqno)
if sigID.IsNil() {
return res, MerkleClientError{fmt.Sprintf("unknown seqno in sigchain: %d", arg.Loc.Seqno), merkleErrorBadSeqno}
}
if !sigID.Equal(leaf.Public.SigID) {
return res, MerkleClientError{fmt.Sprintf("sigID sent down by server didn't match: %s != %s", sigID.String(), leaf.Public.SigID.String()), merkleErrorBadSigID}
}
res.Res = &keybase1.MerkleRootV2{
HashMeta: root.HashMeta(),
Seqno: *root.Seqno(),
}
m.Debug("res.Res: %+v", *res.Res)
return res, nil
} | [
"func",
"FindNextMerkleRootAfterRevoke",
"(",
"m",
"MetaContext",
",",
"arg",
"keybase1",
".",
"FindNextMerkleRootAfterRevokeArg",
")",
"(",
"res",
"keybase1",
".",
"NextMerkleRootRes",
",",
"err",
"error",
")",
"{",
"defer",
"m",
".",
"Trace",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"arg",
")",
",",
"func",
"(",
")",
"error",
"{",
"return",
"err",
"}",
")",
"(",
")",
"\n\n",
"var",
"u",
"*",
"User",
"\n",
"u",
",",
"err",
"=",
"LoadUser",
"(",
"NewLoadUserArgWithMetaContext",
"(",
"m",
")",
".",
"WithUID",
"(",
"arg",
".",
"Uid",
")",
".",
"WithPublicKeyOptional",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"res",
",",
"err",
"\n",
"}",
"\n\n",
"comparer",
":=",
"func",
"(",
"leaf",
"*",
"MerkleGenericLeaf",
",",
"root",
"*",
"MerkleRoot",
")",
"(",
"bool",
",",
"error",
")",
"{",
"slot",
":=",
"leafSlot",
"(",
"leaf",
",",
"keybase1",
".",
"SeqType_PUBLIC",
")",
"\n",
"if",
"slot",
"==",
"nil",
"{",
"return",
"false",
",",
"MerkleClientError",
"{",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"*",
"root",
".",
"Seqno",
"(",
")",
")",
",",
"merkleErrorBadLeaf",
"}",
"\n",
"}",
"\n",
"m",
".",
"Debug",
"(",
"\"",
"\"",
",",
"*",
"root",
".",
"Seqno",
"(",
")",
",",
"slot",
".",
"Seqno",
",",
"arg",
".",
"Loc",
".",
"Seqno",
")",
"\n",
"return",
"(",
"slot",
".",
"Seqno",
">=",
"arg",
".",
"Loc",
".",
"Seqno",
")",
",",
"nil",
"\n",
"}",
"\n\n",
"leaf",
",",
"root",
",",
"err",
":=",
"findFirstLeafWithComparer",
"(",
"m",
",",
"arg",
".",
"Uid",
".",
"AsUserOrTeam",
"(",
")",
",",
"comparer",
",",
"arg",
".",
"Prev",
".",
"Seqno",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"res",
",",
"err",
"\n",
"}",
"\n",
"if",
"leaf",
"==",
"nil",
"||",
"root",
"==",
"nil",
"{",
"return",
"res",
",",
"MerkleClientError",
"{",
"\"",
"\"",
",",
"merkleErrorNoUpdates",
"}",
"\n",
"}",
"\n",
"sigID",
":=",
"u",
".",
"GetSigIDFromSeqno",
"(",
"leaf",
".",
"Public",
".",
"Seqno",
")",
"\n",
"if",
"sigID",
".",
"IsNil",
"(",
")",
"{",
"return",
"res",
",",
"MerkleClientError",
"{",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"arg",
".",
"Loc",
".",
"Seqno",
")",
",",
"merkleErrorBadSeqno",
"}",
"\n",
"}",
"\n",
"if",
"!",
"sigID",
".",
"Equal",
"(",
"leaf",
".",
"Public",
".",
"SigID",
")",
"{",
"return",
"res",
",",
"MerkleClientError",
"{",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"sigID",
".",
"String",
"(",
")",
",",
"leaf",
".",
"Public",
".",
"SigID",
".",
"String",
"(",
")",
")",
",",
"merkleErrorBadSigID",
"}",
"\n",
"}",
"\n",
"res",
".",
"Res",
"=",
"&",
"keybase1",
".",
"MerkleRootV2",
"{",
"HashMeta",
":",
"root",
".",
"HashMeta",
"(",
")",
",",
"Seqno",
":",
"*",
"root",
".",
"Seqno",
"(",
")",
",",
"}",
"\n",
"m",
".",
"Debug",
"(",
"\"",
"\"",
",",
"*",
"res",
".",
"Res",
")",
"\n",
"return",
"res",
",",
"nil",
"\n",
"}"
] | // FindNextMerkleRootAfterRevoke loads the user for the given UID, and find the
// next merkle root after the given key revocation happens. It uses the
// parameter arg.Prev to figure out where to start looking and then keeps
// searching forward until finding a leaf that matches arg.Loc. | [
"FindNextMerkleRootAfterRevoke",
"loads",
"the",
"user",
"for",
"the",
"given",
"UID",
"and",
"find",
"the",
"next",
"merkle",
"root",
"after",
"the",
"given",
"key",
"revocation",
"happens",
".",
"It",
"uses",
"the",
"parameter",
"arg",
".",
"Prev",
"to",
"figure",
"out",
"where",
"to",
"start",
"looking",
"and",
"then",
"keeps",
"searching",
"forward",
"until",
"finding",
"a",
"leaf",
"that",
"matches",
"arg",
".",
"Loc",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/merkle_tools.go#L137-L176 |
161,252 | keybase/client | go/libkb/merkle_tools.go | MerkleCheckPostedUserSig | func MerkleCheckPostedUserSig(mctx MetaContext, uid keybase1.UID,
seqno keybase1.Seqno, linkID LinkID) (err error) {
defer mctx.TraceTimed(fmt.Sprintf("MerkleCheckPostedUserSig(%v, %v, %v)", uid, seqno, linkID.String()), func() error { return err })()
for _, forcePoll := range []bool{false, true} {
upak, _, err := mctx.G().GetUPAKLoader().LoadV2(
NewLoadUserArgWithMetaContext(mctx).WithPublicKeyOptional().
WithUID(uid).WithForcePoll(forcePoll))
if err != nil {
return err
}
if foundLinkID, found := upak.SeqnoLinkIDs[seqno]; found {
if foundLinkID.Eq(linkID.Export()) {
return nil
}
}
}
return fmt.Errorf("sigchain link not found at seqno %v", seqno)
} | go | func MerkleCheckPostedUserSig(mctx MetaContext, uid keybase1.UID,
seqno keybase1.Seqno, linkID LinkID) (err error) {
defer mctx.TraceTimed(fmt.Sprintf("MerkleCheckPostedUserSig(%v, %v, %v)", uid, seqno, linkID.String()), func() error { return err })()
for _, forcePoll := range []bool{false, true} {
upak, _, err := mctx.G().GetUPAKLoader().LoadV2(
NewLoadUserArgWithMetaContext(mctx).WithPublicKeyOptional().
WithUID(uid).WithForcePoll(forcePoll))
if err != nil {
return err
}
if foundLinkID, found := upak.SeqnoLinkIDs[seqno]; found {
if foundLinkID.Eq(linkID.Export()) {
return nil
}
}
}
return fmt.Errorf("sigchain link not found at seqno %v", seqno)
} | [
"func",
"MerkleCheckPostedUserSig",
"(",
"mctx",
"MetaContext",
",",
"uid",
"keybase1",
".",
"UID",
",",
"seqno",
"keybase1",
".",
"Seqno",
",",
"linkID",
"LinkID",
")",
"(",
"err",
"error",
")",
"{",
"defer",
"mctx",
".",
"TraceTimed",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"uid",
",",
"seqno",
",",
"linkID",
".",
"String",
"(",
")",
")",
",",
"func",
"(",
")",
"error",
"{",
"return",
"err",
"}",
")",
"(",
")",
"\n",
"for",
"_",
",",
"forcePoll",
":=",
"range",
"[",
"]",
"bool",
"{",
"false",
",",
"true",
"}",
"{",
"upak",
",",
"_",
",",
"err",
":=",
"mctx",
".",
"G",
"(",
")",
".",
"GetUPAKLoader",
"(",
")",
".",
"LoadV2",
"(",
"NewLoadUserArgWithMetaContext",
"(",
"mctx",
")",
".",
"WithPublicKeyOptional",
"(",
")",
".",
"WithUID",
"(",
"uid",
")",
".",
"WithForcePoll",
"(",
"forcePoll",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"foundLinkID",
",",
"found",
":=",
"upak",
".",
"SeqnoLinkIDs",
"[",
"seqno",
"]",
";",
"found",
"{",
"if",
"foundLinkID",
".",
"Eq",
"(",
"linkID",
".",
"Export",
"(",
")",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"seqno",
")",
"\n",
"}"
] | // Verify that the given link has been posted to the merkle tree.
// Used to detect a malicious server silently dropping sigchain link posts. | [
"Verify",
"that",
"the",
"given",
"link",
"has",
"been",
"posted",
"to",
"the",
"merkle",
"tree",
".",
"Used",
"to",
"detect",
"a",
"malicious",
"server",
"silently",
"dropping",
"sigchain",
"link",
"posts",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/merkle_tools.go#L279-L296 |
161,253 | keybase/client | go/stellar/loader.go | UpdatePayment | func (p *Loader) UpdatePayment(ctx context.Context, paymentID stellar1.PaymentID) {
if p.done {
return
}
p.enqueuePayment(paymentID)
} | go | func (p *Loader) UpdatePayment(ctx context.Context, paymentID stellar1.PaymentID) {
if p.done {
return
}
p.enqueuePayment(paymentID)
} | [
"func",
"(",
"p",
"*",
"Loader",
")",
"UpdatePayment",
"(",
"ctx",
"context",
".",
"Context",
",",
"paymentID",
"stellar1",
".",
"PaymentID",
")",
"{",
"if",
"p",
".",
"done",
"{",
"return",
"\n",
"}",
"\n\n",
"p",
".",
"enqueuePayment",
"(",
"paymentID",
")",
"\n",
"}"
] | // UpdatePayment schedules a load of paymentID. Gregor status notification handlers
// should call this to update the payment data. | [
"UpdatePayment",
"schedules",
"a",
"load",
"of",
"paymentID",
".",
"Gregor",
"status",
"notification",
"handlers",
"should",
"call",
"this",
"to",
"update",
"the",
"payment",
"data",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/stellar/loader.go#L181-L187 |
161,254 | keybase/client | go/stellar/loader.go | UpdateRequest | func (p *Loader) UpdateRequest(ctx context.Context, requestID stellar1.KeybaseRequestID) {
if p.done {
return
}
p.enqueueRequest(requestID)
} | go | func (p *Loader) UpdateRequest(ctx context.Context, requestID stellar1.KeybaseRequestID) {
if p.done {
return
}
p.enqueueRequest(requestID)
} | [
"func",
"(",
"p",
"*",
"Loader",
")",
"UpdateRequest",
"(",
"ctx",
"context",
".",
"Context",
",",
"requestID",
"stellar1",
".",
"KeybaseRequestID",
")",
"{",
"if",
"p",
".",
"done",
"{",
"return",
"\n",
"}",
"\n\n",
"p",
".",
"enqueueRequest",
"(",
"requestID",
")",
"\n",
"}"
] | // UpdateRequest schedules a load for requestID. Gregor status notification handlers
// should call this to update the request data. | [
"UpdateRequest",
"schedules",
"a",
"load",
"for",
"requestID",
".",
"Gregor",
"status",
"notification",
"handlers",
"should",
"call",
"this",
"to",
"update",
"the",
"request",
"data",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/stellar/loader.go#L191-L197 |
161,255 | keybase/client | go/stellar/loader.go | GetListener | func (p *Loader) GetListener() (id string, ch chan PaymentStatusUpdate, err error) {
ch = make(chan PaymentStatusUpdate, 100)
id, err = libkb.RandString("", 8)
if err != nil {
return id, ch, err
}
p.Lock()
p.listeners[id] = ch
p.Unlock()
return id, ch, nil
} | go | func (p *Loader) GetListener() (id string, ch chan PaymentStatusUpdate, err error) {
ch = make(chan PaymentStatusUpdate, 100)
id, err = libkb.RandString("", 8)
if err != nil {
return id, ch, err
}
p.Lock()
p.listeners[id] = ch
p.Unlock()
return id, ch, nil
} | [
"func",
"(",
"p",
"*",
"Loader",
")",
"GetListener",
"(",
")",
"(",
"id",
"string",
",",
"ch",
"chan",
"PaymentStatusUpdate",
",",
"err",
"error",
")",
"{",
"ch",
"=",
"make",
"(",
"chan",
"PaymentStatusUpdate",
",",
"100",
")",
"\n",
"id",
",",
"err",
"=",
"libkb",
".",
"RandString",
"(",
"\"",
"\"",
",",
"8",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"id",
",",
"ch",
",",
"err",
"\n",
"}",
"\n",
"p",
".",
"Lock",
"(",
")",
"\n",
"p",
".",
"listeners",
"[",
"id",
"]",
"=",
"ch",
"\n",
"p",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"id",
",",
"ch",
",",
"nil",
"\n",
"}"
] | // GetListener returns a channel and an ID for a payment status listener. The ID
// can be used to remove the listener from the loader. | [
"GetListener",
"returns",
"a",
"channel",
"and",
"an",
"ID",
"for",
"a",
"payment",
"status",
"listener",
".",
"The",
"ID",
"can",
"be",
"used",
"to",
"remove",
"the",
"listener",
"from",
"the",
"loader",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/stellar/loader.go#L201-L212 |
161,256 | keybase/client | go/stellar/loader.go | RemoveListener | func (p *Loader) RemoveListener(id string) {
p.Lock()
delete(p.listeners, id)
p.Unlock()
} | go | func (p *Loader) RemoveListener(id string) {
p.Lock()
delete(p.listeners, id)
p.Unlock()
} | [
"func",
"(",
"p",
"*",
"Loader",
")",
"RemoveListener",
"(",
"id",
"string",
")",
"{",
"p",
".",
"Lock",
"(",
")",
"\n",
"delete",
"(",
"p",
".",
"listeners",
",",
"id",
")",
"\n",
"p",
".",
"Unlock",
"(",
")",
"\n",
"}"
] | // RemoveListener removes a listener from the loader when it is no longer needed. | [
"RemoveListener",
"removes",
"a",
"listener",
"from",
"the",
"loader",
"when",
"it",
"is",
"no",
"longer",
"needed",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/stellar/loader.go#L215-L219 |
161,257 | keybase/client | go/stellar/loader.go | storeRequest | func (p *Loader) storeRequest(id stellar1.KeybaseRequestID, request *stellar1.RequestDetailsLocal) (isUpdate bool) {
p.Lock()
x, ok := p.requests[id]
if !ok || x.Status != request.Status {
isUpdate = true
}
p.requests[id] = request
p.rlist = append(p.rlist, id)
p.Unlock()
return isUpdate
} | go | func (p *Loader) storeRequest(id stellar1.KeybaseRequestID, request *stellar1.RequestDetailsLocal) (isUpdate bool) {
p.Lock()
x, ok := p.requests[id]
if !ok || x.Status != request.Status {
isUpdate = true
}
p.requests[id] = request
p.rlist = append(p.rlist, id)
p.Unlock()
return isUpdate
} | [
"func",
"(",
"p",
"*",
"Loader",
")",
"storeRequest",
"(",
"id",
"stellar1",
".",
"KeybaseRequestID",
",",
"request",
"*",
"stellar1",
".",
"RequestDetailsLocal",
")",
"(",
"isUpdate",
"bool",
")",
"{",
"p",
".",
"Lock",
"(",
")",
"\n",
"x",
",",
"ok",
":=",
"p",
".",
"requests",
"[",
"id",
"]",
"\n",
"if",
"!",
"ok",
"||",
"x",
".",
"Status",
"!=",
"request",
".",
"Status",
"{",
"isUpdate",
"=",
"true",
"\n",
"}",
"\n",
"p",
".",
"requests",
"[",
"id",
"]",
"=",
"request",
"\n",
"p",
".",
"rlist",
"=",
"append",
"(",
"p",
".",
"rlist",
",",
"id",
")",
"\n",
"p",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"isUpdate",
"\n",
"}"
] | // storeRequest returns true if it updated an existing value. | [
"storeRequest",
"returns",
"true",
"if",
"it",
"updated",
"an",
"existing",
"value",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/stellar/loader.go#L425-L436 |
161,258 | keybase/client | go/libkb/features.go | StringToFeatureFlags | func StringToFeatureFlags(s string) (ret FeatureFlags) {
s = strings.TrimSpace(s)
if len(s) == 0 {
return ret
}
v := strings.Split(s, ",")
for _, f := range v {
ret = append(ret, Feature(strings.TrimSpace(f)))
}
return ret
} | go | func StringToFeatureFlags(s string) (ret FeatureFlags) {
s = strings.TrimSpace(s)
if len(s) == 0 {
return ret
}
v := strings.Split(s, ",")
for _, f := range v {
ret = append(ret, Feature(strings.TrimSpace(f)))
}
return ret
} | [
"func",
"StringToFeatureFlags",
"(",
"s",
"string",
")",
"(",
"ret",
"FeatureFlags",
")",
"{",
"s",
"=",
"strings",
".",
"TrimSpace",
"(",
"s",
")",
"\n",
"if",
"len",
"(",
"s",
")",
"==",
"0",
"{",
"return",
"ret",
"\n",
"}",
"\n",
"v",
":=",
"strings",
".",
"Split",
"(",
"s",
",",
"\"",
"\"",
")",
"\n",
"for",
"_",
",",
"f",
":=",
"range",
"v",
"{",
"ret",
"=",
"append",
"(",
"ret",
",",
"Feature",
"(",
"strings",
".",
"TrimSpace",
"(",
"f",
")",
")",
")",
"\n",
"}",
"\n",
"return",
"ret",
"\n",
"}"
] | // StringToFeatureFlags returns a set of feature flags | [
"StringToFeatureFlags",
"returns",
"a",
"set",
"of",
"feature",
"flags"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/features.go#L21-L31 |
161,259 | keybase/client | go/libkb/features.go | Admin | func (set FeatureFlags) Admin(uid keybase1.UID) bool {
for _, f := range set {
if f == Feature("admin") {
return true
}
}
return IsKeybaseAdmin(uid)
} | go | func (set FeatureFlags) Admin(uid keybase1.UID) bool {
for _, f := range set {
if f == Feature("admin") {
return true
}
}
return IsKeybaseAdmin(uid)
} | [
"func",
"(",
"set",
"FeatureFlags",
")",
"Admin",
"(",
"uid",
"keybase1",
".",
"UID",
")",
"bool",
"{",
"for",
"_",
",",
"f",
":=",
"range",
"set",
"{",
"if",
"f",
"==",
"Feature",
"(",
"\"",
"\"",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"IsKeybaseAdmin",
"(",
"uid",
")",
"\n",
"}"
] | // Admin returns true if the admin feature set is on or the user is a keybase
// admin. | [
"Admin",
"returns",
"true",
"if",
"the",
"admin",
"feature",
"set",
"is",
"on",
"or",
"the",
"user",
"is",
"a",
"keybase",
"admin",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/features.go#L35-L42 |
161,260 | keybase/client | go/libkb/features.go | EnabledWithError | func (s *FeatureFlagSet) EnabledWithError(m MetaContext, f Feature) (on bool, err error) {
m = m.WithLogTag("FEAT")
slot := s.getOrMakeSlot(f)
slot.Lock()
defer slot.Unlock()
if m.G().Clock().Now().Before(slot.cacheUntil) {
m.Debug("Feature (cached) %q -> %v", f, slot.on)
return slot.on, nil
}
var raw rawFeatures
arg := NewAPIArg("user/features")
arg.SessionType = APISessionTypeREQUIRED
arg.Args = HTTPArgs{
"features": S{Val: string(f)},
}
err = m.G().API.GetDecode(m, arg, &raw)
if err != nil {
return false, err
}
rawFeature, ok := raw.Features[string(f)]
if !ok {
m.Info("Feature %q wasn't returned from server", f)
return false, nil
}
slot.readFrom(m, rawFeature)
m.Debug("Feature (fetched) %q -> %v (will cache for %ds)", f, slot.on, rawFeature.CacheSec)
return slot.on, nil
} | go | func (s *FeatureFlagSet) EnabledWithError(m MetaContext, f Feature) (on bool, err error) {
m = m.WithLogTag("FEAT")
slot := s.getOrMakeSlot(f)
slot.Lock()
defer slot.Unlock()
if m.G().Clock().Now().Before(slot.cacheUntil) {
m.Debug("Feature (cached) %q -> %v", f, slot.on)
return slot.on, nil
}
var raw rawFeatures
arg := NewAPIArg("user/features")
arg.SessionType = APISessionTypeREQUIRED
arg.Args = HTTPArgs{
"features": S{Val: string(f)},
}
err = m.G().API.GetDecode(m, arg, &raw)
if err != nil {
return false, err
}
rawFeature, ok := raw.Features[string(f)]
if !ok {
m.Info("Feature %q wasn't returned from server", f)
return false, nil
}
slot.readFrom(m, rawFeature)
m.Debug("Feature (fetched) %q -> %v (will cache for %ds)", f, slot.on, rawFeature.CacheSec)
return slot.on, nil
} | [
"func",
"(",
"s",
"*",
"FeatureFlagSet",
")",
"EnabledWithError",
"(",
"m",
"MetaContext",
",",
"f",
"Feature",
")",
"(",
"on",
"bool",
",",
"err",
"error",
")",
"{",
"m",
"=",
"m",
".",
"WithLogTag",
"(",
"\"",
"\"",
")",
"\n",
"slot",
":=",
"s",
".",
"getOrMakeSlot",
"(",
"f",
")",
"\n",
"slot",
".",
"Lock",
"(",
")",
"\n",
"defer",
"slot",
".",
"Unlock",
"(",
")",
"\n",
"if",
"m",
".",
"G",
"(",
")",
".",
"Clock",
"(",
")",
".",
"Now",
"(",
")",
".",
"Before",
"(",
"slot",
".",
"cacheUntil",
")",
"{",
"m",
".",
"Debug",
"(",
"\"",
"\"",
",",
"f",
",",
"slot",
".",
"on",
")",
"\n",
"return",
"slot",
".",
"on",
",",
"nil",
"\n",
"}",
"\n",
"var",
"raw",
"rawFeatures",
"\n",
"arg",
":=",
"NewAPIArg",
"(",
"\"",
"\"",
")",
"\n",
"arg",
".",
"SessionType",
"=",
"APISessionTypeREQUIRED",
"\n",
"arg",
".",
"Args",
"=",
"HTTPArgs",
"{",
"\"",
"\"",
":",
"S",
"{",
"Val",
":",
"string",
"(",
"f",
")",
"}",
",",
"}",
"\n",
"err",
"=",
"m",
".",
"G",
"(",
")",
".",
"API",
".",
"GetDecode",
"(",
"m",
",",
"arg",
",",
"&",
"raw",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",
"rawFeature",
",",
"ok",
":=",
"raw",
".",
"Features",
"[",
"string",
"(",
"f",
")",
"]",
"\n",
"if",
"!",
"ok",
"{",
"m",
".",
"Info",
"(",
"\"",
"\"",
",",
"f",
")",
"\n",
"return",
"false",
",",
"nil",
"\n",
"}",
"\n",
"slot",
".",
"readFrom",
"(",
"m",
",",
"rawFeature",
")",
"\n",
"m",
".",
"Debug",
"(",
"\"",
"\"",
",",
"f",
",",
"slot",
".",
"on",
",",
"rawFeature",
".",
"CacheSec",
")",
"\n",
"return",
"slot",
".",
"on",
",",
"nil",
"\n",
"}"
] | // EnabledWithError returns if the given feature is enabled, it will return true if it's
// enabled, and an error if one occurred. | [
"EnabledWithError",
"returns",
"if",
"the",
"given",
"feature",
"is",
"enabled",
"it",
"will",
"return",
"true",
"if",
"it",
"s",
"enabled",
"and",
"an",
"error",
"if",
"one",
"occurred",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/features.go#L143-L170 |
161,261 | keybase/client | go/libkb/features.go | Enabled | func (s *FeatureFlagSet) Enabled(m MetaContext, f Feature) (on bool) {
on, err := s.EnabledWithError(m, f)
if err != nil {
m.Info("Error checking feature %q: %v", f, err)
return false
}
return on
} | go | func (s *FeatureFlagSet) Enabled(m MetaContext, f Feature) (on bool) {
on, err := s.EnabledWithError(m, f)
if err != nil {
m.Info("Error checking feature %q: %v", f, err)
return false
}
return on
} | [
"func",
"(",
"s",
"*",
"FeatureFlagSet",
")",
"Enabled",
"(",
"m",
"MetaContext",
",",
"f",
"Feature",
")",
"(",
"on",
"bool",
")",
"{",
"on",
",",
"err",
":=",
"s",
".",
"EnabledWithError",
"(",
"m",
",",
"f",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"m",
".",
"Info",
"(",
"\"",
"\"",
",",
"f",
",",
"err",
")",
"\n",
"return",
"false",
"\n",
"}",
"\n",
"return",
"on",
"\n",
"}"
] | // Enabled returns if the feature flag is enabled. It ignore errors and just acts
// as if the feature is off. | [
"Enabled",
"returns",
"if",
"the",
"feature",
"flag",
"is",
"enabled",
".",
"It",
"ignore",
"errors",
"and",
"just",
"acts",
"as",
"if",
"the",
"feature",
"is",
"off",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/features.go#L174-L181 |
161,262 | keybase/client | go/libkb/features.go | Clear | func (s *FeatureFlagSet) Clear() {
s.Lock()
defer s.Unlock()
s.features = make(map[Feature]*featureSlot)
} | go | func (s *FeatureFlagSet) Clear() {
s.Lock()
defer s.Unlock()
s.features = make(map[Feature]*featureSlot)
} | [
"func",
"(",
"s",
"*",
"FeatureFlagSet",
")",
"Clear",
"(",
")",
"{",
"s",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"Unlock",
"(",
")",
"\n",
"s",
".",
"features",
"=",
"make",
"(",
"map",
"[",
"Feature",
"]",
"*",
"featureSlot",
")",
"\n",
"}"
] | // Clear clears out the cached feature flags, for instance if the user
// is going to logout. | [
"Clear",
"clears",
"out",
"the",
"cached",
"feature",
"flags",
"for",
"instance",
"if",
"the",
"user",
"is",
"going",
"to",
"logout",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/features.go#L185-L189 |
161,263 | keybase/client | go/libkb/features.go | NewFeatureFlagGate | func NewFeatureFlagGate(f Feature, d time.Duration) *FeatureFlagGate {
return &FeatureFlagGate{
feature: f,
cacheFor: d,
}
} | go | func NewFeatureFlagGate(f Feature, d time.Duration) *FeatureFlagGate {
return &FeatureFlagGate{
feature: f,
cacheFor: d,
}
} | [
"func",
"NewFeatureFlagGate",
"(",
"f",
"Feature",
",",
"d",
"time",
".",
"Duration",
")",
"*",
"FeatureFlagGate",
"{",
"return",
"&",
"FeatureFlagGate",
"{",
"feature",
":",
"f",
",",
"cacheFor",
":",
"d",
",",
"}",
"\n",
"}"
] | // NewFeatureFlagGate makes a gate for the given feature that will cache for the given
// duration. | [
"NewFeatureFlagGate",
"makes",
"a",
"gate",
"for",
"the",
"given",
"feature",
"that",
"will",
"cache",
"for",
"the",
"given",
"duration",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/features.go#L205-L210 |
161,264 | keybase/client | go/libkb/features.go | DigestError | func (f *FeatureFlagGate) DigestError(m MetaContext, err error) {
if err == nil {
return
}
ffe, ok := err.(FeatureFlagError)
if !ok {
return
}
if ffe.Feature() != f.feature {
m.Debug("Got feature flag error for wrong feature: %v", err)
return
}
m.Debug("Server reports feature %q is flagged off", f.feature)
f.Lock()
defer f.Unlock()
f.lastCheck = m.G().Clock().Now()
f.lastError = err
} | go | func (f *FeatureFlagGate) DigestError(m MetaContext, err error) {
if err == nil {
return
}
ffe, ok := err.(FeatureFlagError)
if !ok {
return
}
if ffe.Feature() != f.feature {
m.Debug("Got feature flag error for wrong feature: %v", err)
return
}
m.Debug("Server reports feature %q is flagged off", f.feature)
f.Lock()
defer f.Unlock()
f.lastCheck = m.G().Clock().Now()
f.lastError = err
} | [
"func",
"(",
"f",
"*",
"FeatureFlagGate",
")",
"DigestError",
"(",
"m",
"MetaContext",
",",
"err",
"error",
")",
"{",
"if",
"err",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"ffe",
",",
"ok",
":=",
"err",
".",
"(",
"FeatureFlagError",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"\n",
"}",
"\n",
"if",
"ffe",
".",
"Feature",
"(",
")",
"!=",
"f",
".",
"feature",
"{",
"m",
".",
"Debug",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"m",
".",
"Debug",
"(",
"\"",
"\"",
",",
"f",
".",
"feature",
")",
"\n\n",
"f",
".",
"Lock",
"(",
")",
"\n",
"defer",
"f",
".",
"Unlock",
"(",
")",
"\n",
"f",
".",
"lastCheck",
"=",
"m",
".",
"G",
"(",
")",
".",
"Clock",
"(",
")",
".",
"Now",
"(",
")",
"\n",
"f",
".",
"lastError",
"=",
"err",
"\n",
"}"
] | // DigestError should be called on the result of an API call. It will allow this gate
// to digest the error and maybe set up its internal caching for when to retry this
// feature. | [
"DigestError",
"should",
"be",
"called",
"on",
"the",
"result",
"of",
"an",
"API",
"call",
".",
"It",
"will",
"allow",
"this",
"gate",
"to",
"digest",
"the",
"error",
"and",
"maybe",
"set",
"up",
"its",
"internal",
"caching",
"for",
"when",
"to",
"retry",
"this",
"feature",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/features.go#L215-L234 |
161,265 | keybase/client | go/libkb/features.go | ErrorIfFlagged | func (f *FeatureFlagGate) ErrorIfFlagged(m MetaContext) (err error) {
f.Lock()
defer f.Unlock()
if f.lastError == nil {
return nil
}
diff := m.G().Clock().Now().Sub(f.lastCheck)
if diff > f.cacheFor {
m.Debug("Feature flag %q expired %d ago, let's give it another try", f.feature, diff)
f.lastError = nil
f.lastCheck = time.Time{}
}
return f.lastError
} | go | func (f *FeatureFlagGate) ErrorIfFlagged(m MetaContext) (err error) {
f.Lock()
defer f.Unlock()
if f.lastError == nil {
return nil
}
diff := m.G().Clock().Now().Sub(f.lastCheck)
if diff > f.cacheFor {
m.Debug("Feature flag %q expired %d ago, let's give it another try", f.feature, diff)
f.lastError = nil
f.lastCheck = time.Time{}
}
return f.lastError
} | [
"func",
"(",
"f",
"*",
"FeatureFlagGate",
")",
"ErrorIfFlagged",
"(",
"m",
"MetaContext",
")",
"(",
"err",
"error",
")",
"{",
"f",
".",
"Lock",
"(",
")",
"\n",
"defer",
"f",
".",
"Unlock",
"(",
")",
"\n",
"if",
"f",
".",
"lastError",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"diff",
":=",
"m",
".",
"G",
"(",
")",
".",
"Clock",
"(",
")",
".",
"Now",
"(",
")",
".",
"Sub",
"(",
"f",
".",
"lastCheck",
")",
"\n",
"if",
"diff",
">",
"f",
".",
"cacheFor",
"{",
"m",
".",
"Debug",
"(",
"\"",
"\"",
",",
"f",
".",
"feature",
",",
"diff",
")",
"\n",
"f",
".",
"lastError",
"=",
"nil",
"\n",
"f",
".",
"lastCheck",
"=",
"time",
".",
"Time",
"{",
"}",
"\n",
"}",
"\n",
"return",
"f",
".",
"lastError",
"\n",
"}"
] | // ErrorIfFlagged should be called to avoid a feature if it's recently
// been feature-flagged "off" by the server. In that case, it will return
// the error that was originally returned by the server. | [
"ErrorIfFlagged",
"should",
"be",
"called",
"to",
"avoid",
"a",
"feature",
"if",
"it",
"s",
"recently",
"been",
"feature",
"-",
"flagged",
"off",
"by",
"the",
"server",
".",
"In",
"that",
"case",
"it",
"will",
"return",
"the",
"error",
"that",
"was",
"originally",
"returned",
"by",
"the",
"server",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/features.go#L239-L252 |
161,266 | keybase/client | go/engine/favorite_add.go | NewFavoriteAdd | func NewFavoriteAdd(g *libkb.GlobalContext, arg *keybase1.FavoriteAddArg) *FavoriteAdd {
return &FavoriteAdd{
arg: arg,
checkInviteDone: make(chan struct{}),
Contextified: libkb.NewContextified(g),
}
} | go | func NewFavoriteAdd(g *libkb.GlobalContext, arg *keybase1.FavoriteAddArg) *FavoriteAdd {
return &FavoriteAdd{
arg: arg,
checkInviteDone: make(chan struct{}),
Contextified: libkb.NewContextified(g),
}
} | [
"func",
"NewFavoriteAdd",
"(",
"g",
"*",
"libkb",
".",
"GlobalContext",
",",
"arg",
"*",
"keybase1",
".",
"FavoriteAddArg",
")",
"*",
"FavoriteAdd",
"{",
"return",
"&",
"FavoriteAdd",
"{",
"arg",
":",
"arg",
",",
"checkInviteDone",
":",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
",",
"Contextified",
":",
"libkb",
".",
"NewContextified",
"(",
"g",
")",
",",
"}",
"\n",
"}"
] | // NewFavoriteAdd creates a FavoriteAdd engine. | [
"NewFavoriteAdd",
"creates",
"a",
"FavoriteAdd",
"engine",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/engine/favorite_add.go#L23-L29 |
161,267 | keybase/client | go/service/gregor.go | Init | func (g *gregorHandler) Init() {
// Attempt to create a gregor client initially, if we are not logged in
// or don't have user/device info in G, then this won't work
if err := g.resetGregorClient(context.TODO()); err != nil {
g.Warning(context.Background(), "unable to create push service client: %s", err.Error())
}
// Start broadcast handler goroutine
go g.broadcastMessageHandler()
// Start the app state monitor thread
go g.monitorAppState()
// Start replay thread
go g.syncReplayThread()
} | go | func (g *gregorHandler) Init() {
// Attempt to create a gregor client initially, if we are not logged in
// or don't have user/device info in G, then this won't work
if err := g.resetGregorClient(context.TODO()); err != nil {
g.Warning(context.Background(), "unable to create push service client: %s", err.Error())
}
// Start broadcast handler goroutine
go g.broadcastMessageHandler()
// Start the app state monitor thread
go g.monitorAppState()
// Start replay thread
go g.syncReplayThread()
} | [
"func",
"(",
"g",
"*",
"gregorHandler",
")",
"Init",
"(",
")",
"{",
"// Attempt to create a gregor client initially, if we are not logged in",
"// or don't have user/device info in G, then this won't work",
"if",
"err",
":=",
"g",
".",
"resetGregorClient",
"(",
"context",
".",
"TODO",
"(",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"g",
".",
"Warning",
"(",
"context",
".",
"Background",
"(",
")",
",",
"\"",
"\"",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n\n",
"// Start broadcast handler goroutine",
"go",
"g",
".",
"broadcastMessageHandler",
"(",
")",
"\n\n",
"// Start the app state monitor thread",
"go",
"g",
".",
"monitorAppState",
"(",
")",
"\n\n",
"// Start replay thread",
"go",
"g",
".",
"syncReplayThread",
"(",
")",
"\n",
"}"
] | // Init starts all the background services for managing connection to Gregor | [
"Init",
"starts",
"all",
"the",
"background",
"services",
"for",
"managing",
"connection",
"to",
"Gregor"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/service/gregor.go#L252-L267 |
161,268 | keybase/client | go/service/gregor.go | PushFirehoseHandler | func (g *gregorHandler) PushFirehoseHandler(handler libkb.GregorFirehoseHandler) {
defer g.chatLog.Trace(context.Background(), func() error { return nil }, "PushFirehoseHandler")()
g.Lock()
g.firehoseHandlers = append(g.firehoseHandlers, handler)
g.Unlock()
s, err := g.getState(context.Background())
if err != nil {
g.Warning(context.Background(), "Cannot push state in firehose handler: %s", err)
return
}
g.Debug(context.Background(), "PushFirehoseHandler: pushing state with %d items", len(s.Items_))
handler.PushState(s, keybase1.PushReason_RECONNECTED)
} | go | func (g *gregorHandler) PushFirehoseHandler(handler libkb.GregorFirehoseHandler) {
defer g.chatLog.Trace(context.Background(), func() error { return nil }, "PushFirehoseHandler")()
g.Lock()
g.firehoseHandlers = append(g.firehoseHandlers, handler)
g.Unlock()
s, err := g.getState(context.Background())
if err != nil {
g.Warning(context.Background(), "Cannot push state in firehose handler: %s", err)
return
}
g.Debug(context.Background(), "PushFirehoseHandler: pushing state with %d items", len(s.Items_))
handler.PushState(s, keybase1.PushReason_RECONNECTED)
} | [
"func",
"(",
"g",
"*",
"gregorHandler",
")",
"PushFirehoseHandler",
"(",
"handler",
"libkb",
".",
"GregorFirehoseHandler",
")",
"{",
"defer",
"g",
".",
"chatLog",
".",
"Trace",
"(",
"context",
".",
"Background",
"(",
")",
",",
"func",
"(",
")",
"error",
"{",
"return",
"nil",
"}",
",",
"\"",
"\"",
")",
"(",
")",
"\n",
"g",
".",
"Lock",
"(",
")",
"\n",
"g",
".",
"firehoseHandlers",
"=",
"append",
"(",
"g",
".",
"firehoseHandlers",
",",
"handler",
")",
"\n",
"g",
".",
"Unlock",
"(",
")",
"\n\n",
"s",
",",
"err",
":=",
"g",
".",
"getState",
"(",
"context",
".",
"Background",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"g",
".",
"Warning",
"(",
"context",
".",
"Background",
"(",
")",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n",
"g",
".",
"Debug",
"(",
"context",
".",
"Background",
"(",
")",
",",
"\"",
"\"",
",",
"len",
"(",
"s",
".",
"Items_",
")",
")",
"\n",
"handler",
".",
"PushState",
"(",
"s",
",",
"keybase1",
".",
"PushReason_RECONNECTED",
")",
"\n",
"}"
] | // PushFirehoseHandler pushes a new firehose handler onto the list of currently
// active firehose handles. We can have several of these active at once. All
// get the "firehose" of gregor events. They're removed lazily as their underlying
// connections die. | [
"PushFirehoseHandler",
"pushes",
"a",
"new",
"firehose",
"handler",
"onto",
"the",
"list",
"of",
"currently",
"active",
"firehose",
"handles",
".",
"We",
"can",
"have",
"several",
"of",
"these",
"active",
"at",
"once",
".",
"All",
"get",
"the",
"firehose",
"of",
"gregor",
"events",
".",
"They",
"re",
"removed",
"lazily",
"as",
"their",
"underlying",
"connections",
"die",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/service/gregor.go#L506-L519 |
161,269 | keybase/client | go/service/gregor.go | iterateOverFirehoseHandlers | func (g *gregorHandler) iterateOverFirehoseHandlers(f func(h libkb.GregorFirehoseHandler)) {
var freshHandlers []libkb.GregorFirehoseHandler
for _, h := range g.firehoseHandlers {
if h.IsAlive() {
f(h)
freshHandlers = append(freshHandlers, h)
}
}
g.firehoseHandlers = freshHandlers
return
} | go | func (g *gregorHandler) iterateOverFirehoseHandlers(f func(h libkb.GregorFirehoseHandler)) {
var freshHandlers []libkb.GregorFirehoseHandler
for _, h := range g.firehoseHandlers {
if h.IsAlive() {
f(h)
freshHandlers = append(freshHandlers, h)
}
}
g.firehoseHandlers = freshHandlers
return
} | [
"func",
"(",
"g",
"*",
"gregorHandler",
")",
"iterateOverFirehoseHandlers",
"(",
"f",
"func",
"(",
"h",
"libkb",
".",
"GregorFirehoseHandler",
")",
")",
"{",
"var",
"freshHandlers",
"[",
"]",
"libkb",
".",
"GregorFirehoseHandler",
"\n",
"for",
"_",
",",
"h",
":=",
"range",
"g",
".",
"firehoseHandlers",
"{",
"if",
"h",
".",
"IsAlive",
"(",
")",
"{",
"f",
"(",
"h",
")",
"\n",
"freshHandlers",
"=",
"append",
"(",
"freshHandlers",
",",
"h",
")",
"\n",
"}",
"\n",
"}",
"\n",
"g",
".",
"firehoseHandlers",
"=",
"freshHandlers",
"\n",
"return",
"\n",
"}"
] | // iterateOverFirehoseHandlers applies the function f to all live firehose handlers
// and then resets the list to only include the live ones. | [
"iterateOverFirehoseHandlers",
"applies",
"the",
"function",
"f",
"to",
"all",
"live",
"firehose",
"handlers",
"and",
"then",
"resets",
"the",
"list",
"to",
"only",
"include",
"the",
"live",
"ones",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/service/gregor.go#L523-L533 |
161,270 | keybase/client | go/service/gregor.go | replayInBandMessages | func (g *gregorHandler) replayInBandMessages(ctx context.Context, cli gregor1.IncomingInterface,
t time.Time, handler libkb.GregorInBandMessageHandler) ([]gregor.InBandMessage, error) {
var msgs []gregor.InBandMessage
var err error
gcli, err := g.getGregorCli()
if err != nil {
return nil, err
}
if t.IsZero() {
g.Debug(ctx, "replayInBandMessages: fresh replay: using state items")
state, err := gcli.StateMachineState(ctx, nil, true)
if err != nil {
g.Debug(ctx, "replayInBandMessages: unable to fetch state for replay: %s", err)
return nil, err
}
if msgs, err = gcli.InBandMessagesFromState(state); err != nil {
g.Debug(ctx, "replayInBandMessages: unable to fetch messages from state for replay: %s", err)
return nil, err
}
} else {
g.Debug(ctx, "replayInBandMessages: incremental replay: using ibms since")
if msgs, err = gcli.StateMachineInBandMessagesSince(ctx, t, true); err != nil {
g.Debug(ctx, "replayInBandMessages: unable to fetch messages for replay: %s", err)
return nil, err
}
}
g.Debug(ctx, "replayInBandMessages: replaying %d messages", len(msgs))
for _, msg := range msgs {
g.Debug(ctx, "replayInBandMessages: replaying: %s", msg.Metadata().MsgID())
// If we have a handler, just run it on that, otherwise run it against
// all of the handlers we know about
if handler == nil {
err = g.handleInBandMessage(ctx, cli, msg)
} else {
_, err = g.handleInBandMessageWithHandler(ctx, cli, msg, handler)
}
// If an error happens when replaying, don't kill everything else that
// follows, just make a warning.
if err != nil {
g.Debug(ctx, "replayInBandMessages: failure in message replay: %s", err.Error())
err = nil
}
}
return msgs, nil
} | go | func (g *gregorHandler) replayInBandMessages(ctx context.Context, cli gregor1.IncomingInterface,
t time.Time, handler libkb.GregorInBandMessageHandler) ([]gregor.InBandMessage, error) {
var msgs []gregor.InBandMessage
var err error
gcli, err := g.getGregorCli()
if err != nil {
return nil, err
}
if t.IsZero() {
g.Debug(ctx, "replayInBandMessages: fresh replay: using state items")
state, err := gcli.StateMachineState(ctx, nil, true)
if err != nil {
g.Debug(ctx, "replayInBandMessages: unable to fetch state for replay: %s", err)
return nil, err
}
if msgs, err = gcli.InBandMessagesFromState(state); err != nil {
g.Debug(ctx, "replayInBandMessages: unable to fetch messages from state for replay: %s", err)
return nil, err
}
} else {
g.Debug(ctx, "replayInBandMessages: incremental replay: using ibms since")
if msgs, err = gcli.StateMachineInBandMessagesSince(ctx, t, true); err != nil {
g.Debug(ctx, "replayInBandMessages: unable to fetch messages for replay: %s", err)
return nil, err
}
}
g.Debug(ctx, "replayInBandMessages: replaying %d messages", len(msgs))
for _, msg := range msgs {
g.Debug(ctx, "replayInBandMessages: replaying: %s", msg.Metadata().MsgID())
// If we have a handler, just run it on that, otherwise run it against
// all of the handlers we know about
if handler == nil {
err = g.handleInBandMessage(ctx, cli, msg)
} else {
_, err = g.handleInBandMessageWithHandler(ctx, cli, msg, handler)
}
// If an error happens when replaying, don't kill everything else that
// follows, just make a warning.
if err != nil {
g.Debug(ctx, "replayInBandMessages: failure in message replay: %s", err.Error())
err = nil
}
}
return msgs, nil
} | [
"func",
"(",
"g",
"*",
"gregorHandler",
")",
"replayInBandMessages",
"(",
"ctx",
"context",
".",
"Context",
",",
"cli",
"gregor1",
".",
"IncomingInterface",
",",
"t",
"time",
".",
"Time",
",",
"handler",
"libkb",
".",
"GregorInBandMessageHandler",
")",
"(",
"[",
"]",
"gregor",
".",
"InBandMessage",
",",
"error",
")",
"{",
"var",
"msgs",
"[",
"]",
"gregor",
".",
"InBandMessage",
"\n",
"var",
"err",
"error",
"\n\n",
"gcli",
",",
"err",
":=",
"g",
".",
"getGregorCli",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"t",
".",
"IsZero",
"(",
")",
"{",
"g",
".",
"Debug",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"state",
",",
"err",
":=",
"gcli",
".",
"StateMachineState",
"(",
"ctx",
",",
"nil",
",",
"true",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"g",
".",
"Debug",
"(",
"ctx",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"msgs",
",",
"err",
"=",
"gcli",
".",
"InBandMessagesFromState",
"(",
"state",
")",
";",
"err",
"!=",
"nil",
"{",
"g",
".",
"Debug",
"(",
"ctx",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"else",
"{",
"g",
".",
"Debug",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"if",
"msgs",
",",
"err",
"=",
"gcli",
".",
"StateMachineInBandMessagesSince",
"(",
"ctx",
",",
"t",
",",
"true",
")",
";",
"err",
"!=",
"nil",
"{",
"g",
".",
"Debug",
"(",
"ctx",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"g",
".",
"Debug",
"(",
"ctx",
",",
"\"",
"\"",
",",
"len",
"(",
"msgs",
")",
")",
"\n",
"for",
"_",
",",
"msg",
":=",
"range",
"msgs",
"{",
"g",
".",
"Debug",
"(",
"ctx",
",",
"\"",
"\"",
",",
"msg",
".",
"Metadata",
"(",
")",
".",
"MsgID",
"(",
")",
")",
"\n",
"// If we have a handler, just run it on that, otherwise run it against",
"// all of the handlers we know about",
"if",
"handler",
"==",
"nil",
"{",
"err",
"=",
"g",
".",
"handleInBandMessage",
"(",
"ctx",
",",
"cli",
",",
"msg",
")",
"\n",
"}",
"else",
"{",
"_",
",",
"err",
"=",
"g",
".",
"handleInBandMessageWithHandler",
"(",
"ctx",
",",
"cli",
",",
"msg",
",",
"handler",
")",
"\n",
"}",
"\n\n",
"// If an error happens when replaying, don't kill everything else that",
"// follows, just make a warning.",
"if",
"err",
"!=",
"nil",
"{",
"g",
".",
"Debug",
"(",
"ctx",
",",
"\"",
"\"",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"err",
"=",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"msgs",
",",
"nil",
"\n",
"}"
] | // replayInBandMessages will replay all the messages in the current state from
// the given time. If a handler is specified, it will only replay using it,
// otherwise it will try all of them. gregorHandler needs to be locked when calling
// this function. | [
"replayInBandMessages",
"will",
"replay",
"all",
"the",
"messages",
"in",
"the",
"current",
"state",
"from",
"the",
"given",
"time",
".",
"If",
"a",
"handler",
"is",
"specified",
"it",
"will",
"only",
"replay",
"using",
"it",
"otherwise",
"it",
"will",
"try",
"all",
"of",
"them",
".",
"gregorHandler",
"needs",
"to",
"be",
"locked",
"when",
"calling",
"this",
"function",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/service/gregor.go#L561-L611 |
161,271 | keybase/client | go/service/gregor.go | serverSync | func (g *gregorHandler) serverSync(ctx context.Context,
cli gregor1.IncomingInterface, gcli *grclient.Client, syncRes *chat1.SyncAllNotificationRes) (res []gregor.InBandMessage, err error) {
defer g.chatLog.Trace(ctx, func() error { return err }, "serverSync")()
// Get time of the last message we synced (unless this is our first time syncing)
var t time.Time
if !g.isFirstConnect() {
pt := gcli.StateMachineLatestCTime(ctx)
if pt != nil {
t = *pt
}
g.Debug(ctx, "serverSync: starting replay from: %s", t)
} else {
g.Debug(ctx, "serverSync: performing a fresh replay")
}
// Sync down everything from the server
consumedMsgs, err := gcli.Sync(ctx, cli, syncRes)
if err != nil {
g.Debug(ctx, "serverSync: error syncing from the server, reason: %s", err)
return nil, err
}
g.Debug(ctx, "serverSync: consumed %d messages", len(consumedMsgs))
// Schedule replay of in-band messages
g.replayCh <- replayThreadArg{
cli: cli,
t: t,
ctx: globals.BackgroundChatCtx(ctx, g.G()),
}
g.pushState(keybase1.PushReason_RECONNECTED)
return consumedMsgs, nil
} | go | func (g *gregorHandler) serverSync(ctx context.Context,
cli gregor1.IncomingInterface, gcli *grclient.Client, syncRes *chat1.SyncAllNotificationRes) (res []gregor.InBandMessage, err error) {
defer g.chatLog.Trace(ctx, func() error { return err }, "serverSync")()
// Get time of the last message we synced (unless this is our first time syncing)
var t time.Time
if !g.isFirstConnect() {
pt := gcli.StateMachineLatestCTime(ctx)
if pt != nil {
t = *pt
}
g.Debug(ctx, "serverSync: starting replay from: %s", t)
} else {
g.Debug(ctx, "serverSync: performing a fresh replay")
}
// Sync down everything from the server
consumedMsgs, err := gcli.Sync(ctx, cli, syncRes)
if err != nil {
g.Debug(ctx, "serverSync: error syncing from the server, reason: %s", err)
return nil, err
}
g.Debug(ctx, "serverSync: consumed %d messages", len(consumedMsgs))
// Schedule replay of in-band messages
g.replayCh <- replayThreadArg{
cli: cli,
t: t,
ctx: globals.BackgroundChatCtx(ctx, g.G()),
}
g.pushState(keybase1.PushReason_RECONNECTED)
return consumedMsgs, nil
} | [
"func",
"(",
"g",
"*",
"gregorHandler",
")",
"serverSync",
"(",
"ctx",
"context",
".",
"Context",
",",
"cli",
"gregor1",
".",
"IncomingInterface",
",",
"gcli",
"*",
"grclient",
".",
"Client",
",",
"syncRes",
"*",
"chat1",
".",
"SyncAllNotificationRes",
")",
"(",
"res",
"[",
"]",
"gregor",
".",
"InBandMessage",
",",
"err",
"error",
")",
"{",
"defer",
"g",
".",
"chatLog",
".",
"Trace",
"(",
"ctx",
",",
"func",
"(",
")",
"error",
"{",
"return",
"err",
"}",
",",
"\"",
"\"",
")",
"(",
")",
"\n\n",
"// Get time of the last message we synced (unless this is our first time syncing)",
"var",
"t",
"time",
".",
"Time",
"\n",
"if",
"!",
"g",
".",
"isFirstConnect",
"(",
")",
"{",
"pt",
":=",
"gcli",
".",
"StateMachineLatestCTime",
"(",
"ctx",
")",
"\n",
"if",
"pt",
"!=",
"nil",
"{",
"t",
"=",
"*",
"pt",
"\n",
"}",
"\n",
"g",
".",
"Debug",
"(",
"ctx",
",",
"\"",
"\"",
",",
"t",
")",
"\n",
"}",
"else",
"{",
"g",
".",
"Debug",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Sync down everything from the server",
"consumedMsgs",
",",
"err",
":=",
"gcli",
".",
"Sync",
"(",
"ctx",
",",
"cli",
",",
"syncRes",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"g",
".",
"Debug",
"(",
"ctx",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"g",
".",
"Debug",
"(",
"ctx",
",",
"\"",
"\"",
",",
"len",
"(",
"consumedMsgs",
")",
")",
"\n\n",
"// Schedule replay of in-band messages",
"g",
".",
"replayCh",
"<-",
"replayThreadArg",
"{",
"cli",
":",
"cli",
",",
"t",
":",
"t",
",",
"ctx",
":",
"globals",
".",
"BackgroundChatCtx",
"(",
"ctx",
",",
"g",
".",
"G",
"(",
")",
")",
",",
"}",
"\n\n",
"g",
".",
"pushState",
"(",
"keybase1",
".",
"PushReason_RECONNECTED",
")",
"\n",
"return",
"consumedMsgs",
",",
"nil",
"\n",
"}"
] | // serverSync is called from
// gregord. This can happen either on initial startup, or after a reconnect. Needs
// to be called with gregorHandler locked. | [
"serverSync",
"is",
"called",
"from",
"gregord",
".",
"This",
"can",
"happen",
"either",
"on",
"initial",
"startup",
"or",
"after",
"a",
"reconnect",
".",
"Needs",
"to",
"be",
"called",
"with",
"gregorHandler",
"locked",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/service/gregor.go#L645-L678 |
161,272 | keybase/client | go/service/gregor.go | BroadcastMessage | func (g *gregorHandler) BroadcastMessage(ctx context.Context, m gregor1.Message) error {
// Send the message on a channel so we can return to Gregor as fast as possible. Note
// that this can block, but broadcastCh has a large buffer to try and mitigate
g.broadcastCh <- m
return nil
} | go | func (g *gregorHandler) BroadcastMessage(ctx context.Context, m gregor1.Message) error {
// Send the message on a channel so we can return to Gregor as fast as possible. Note
// that this can block, but broadcastCh has a large buffer to try and mitigate
g.broadcastCh <- m
return nil
} | [
"func",
"(",
"g",
"*",
"gregorHandler",
")",
"BroadcastMessage",
"(",
"ctx",
"context",
".",
"Context",
",",
"m",
"gregor1",
".",
"Message",
")",
"error",
"{",
"// Send the message on a channel so we can return to Gregor as fast as possible. Note",
"// that this can block, but broadcastCh has a large buffer to try and mitigate",
"g",
".",
"broadcastCh",
"<-",
"m",
"\n",
"return",
"nil",
"\n",
"}"
] | // BroadcastMessage is called when we receive a new message from gregord. Grabs
// the lock protect the state machine and handleInBandMessage | [
"BroadcastMessage",
"is",
"called",
"when",
"we",
"receive",
"a",
"new",
"message",
"from",
"gregord",
".",
"Grabs",
"the",
"lock",
"protect",
"the",
"state",
"machine",
"and",
"handleInBandMessage"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/service/gregor.go#L997-L1002 |
161,273 | keybase/client | go/service/gregor.go | handleInBandMessage | func (g *gregorHandler) handleInBandMessage(ctx context.Context, cli gregor1.IncomingInterface,
ibm gregor.InBandMessage) (err error) {
defer g.G().Trace(fmt.Sprintf("gregorHandler#handleInBandMessage with %d handlers", len(g.ibmHandlers)), func() error { return err })()
ctx = libkb.WithLogTag(ctx, "GRGIBM")
var freshHandlers []libkb.GregorInBandMessageHandler
// Loop over all handlers and run the messages against any that are alive
// If the handler is not alive, we prune it from our list
for i, handler := range g.ibmHandlers {
g.Debug(ctx, "trying handler %s at position %d", handler.Name(), i)
if handler.IsAlive() {
if handled, err := g.handleInBandMessageWithHandler(ctx, cli, ibm, handler); err != nil {
if handled {
// Don't stop handling errors on a first failure.
g.Errorf(ctx, "failed to run %s handler: %s", handler.Name(), err)
} else {
g.Debug(ctx, "handleInBandMessage() failed to run %s handler: %s", handler.Name(), err)
}
}
freshHandlers = append(freshHandlers, handler)
} else {
g.Debug(ctx, "skipping handler as it's marked dead: %s", handler.Name())
}
}
if len(g.ibmHandlers) != len(freshHandlers) {
g.Debug(ctx, "Change # of live handlers from %d to %d", len(g.ibmHandlers), len(freshHandlers))
g.ibmHandlers = freshHandlers
}
return nil
} | go | func (g *gregorHandler) handleInBandMessage(ctx context.Context, cli gregor1.IncomingInterface,
ibm gregor.InBandMessage) (err error) {
defer g.G().Trace(fmt.Sprintf("gregorHandler#handleInBandMessage with %d handlers", len(g.ibmHandlers)), func() error { return err })()
ctx = libkb.WithLogTag(ctx, "GRGIBM")
var freshHandlers []libkb.GregorInBandMessageHandler
// Loop over all handlers and run the messages against any that are alive
// If the handler is not alive, we prune it from our list
for i, handler := range g.ibmHandlers {
g.Debug(ctx, "trying handler %s at position %d", handler.Name(), i)
if handler.IsAlive() {
if handled, err := g.handleInBandMessageWithHandler(ctx, cli, ibm, handler); err != nil {
if handled {
// Don't stop handling errors on a first failure.
g.Errorf(ctx, "failed to run %s handler: %s", handler.Name(), err)
} else {
g.Debug(ctx, "handleInBandMessage() failed to run %s handler: %s", handler.Name(), err)
}
}
freshHandlers = append(freshHandlers, handler)
} else {
g.Debug(ctx, "skipping handler as it's marked dead: %s", handler.Name())
}
}
if len(g.ibmHandlers) != len(freshHandlers) {
g.Debug(ctx, "Change # of live handlers from %d to %d", len(g.ibmHandlers), len(freshHandlers))
g.ibmHandlers = freshHandlers
}
return nil
} | [
"func",
"(",
"g",
"*",
"gregorHandler",
")",
"handleInBandMessage",
"(",
"ctx",
"context",
".",
"Context",
",",
"cli",
"gregor1",
".",
"IncomingInterface",
",",
"ibm",
"gregor",
".",
"InBandMessage",
")",
"(",
"err",
"error",
")",
"{",
"defer",
"g",
".",
"G",
"(",
")",
".",
"Trace",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"len",
"(",
"g",
".",
"ibmHandlers",
")",
")",
",",
"func",
"(",
")",
"error",
"{",
"return",
"err",
"}",
")",
"(",
")",
"\n",
"ctx",
"=",
"libkb",
".",
"WithLogTag",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n\n",
"var",
"freshHandlers",
"[",
"]",
"libkb",
".",
"GregorInBandMessageHandler",
"\n\n",
"// Loop over all handlers and run the messages against any that are alive",
"// If the handler is not alive, we prune it from our list",
"for",
"i",
",",
"handler",
":=",
"range",
"g",
".",
"ibmHandlers",
"{",
"g",
".",
"Debug",
"(",
"ctx",
",",
"\"",
"\"",
",",
"handler",
".",
"Name",
"(",
")",
",",
"i",
")",
"\n",
"if",
"handler",
".",
"IsAlive",
"(",
")",
"{",
"if",
"handled",
",",
"err",
":=",
"g",
".",
"handleInBandMessageWithHandler",
"(",
"ctx",
",",
"cli",
",",
"ibm",
",",
"handler",
")",
";",
"err",
"!=",
"nil",
"{",
"if",
"handled",
"{",
"// Don't stop handling errors on a first failure.",
"g",
".",
"Errorf",
"(",
"ctx",
",",
"\"",
"\"",
",",
"handler",
".",
"Name",
"(",
")",
",",
"err",
")",
"\n",
"}",
"else",
"{",
"g",
".",
"Debug",
"(",
"ctx",
",",
"\"",
"\"",
",",
"handler",
".",
"Name",
"(",
")",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"freshHandlers",
"=",
"append",
"(",
"freshHandlers",
",",
"handler",
")",
"\n",
"}",
"else",
"{",
"g",
".",
"Debug",
"(",
"ctx",
",",
"\"",
"\"",
",",
"handler",
".",
"Name",
"(",
")",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"g",
".",
"ibmHandlers",
")",
"!=",
"len",
"(",
"freshHandlers",
")",
"{",
"g",
".",
"Debug",
"(",
"ctx",
",",
"\"",
"\"",
",",
"len",
"(",
"g",
".",
"ibmHandlers",
")",
",",
"len",
"(",
"freshHandlers",
")",
")",
"\n",
"g",
".",
"ibmHandlers",
"=",
"freshHandlers",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // handleInBandMessage runs a message on all the alive handlers. gregorHandler
// must be locked when calling this function. | [
"handleInBandMessage",
"runs",
"a",
"message",
"on",
"all",
"the",
"alive",
"handlers",
".",
"gregorHandler",
"must",
"be",
"locked",
"when",
"calling",
"this",
"function",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/service/gregor.go#L1006-L1038 |
161,274 | keybase/client | go/service/gregor.go | handleInBandMessageWithHandler | func (g *gregorHandler) handleInBandMessageWithHandler(ctx context.Context, cli gregor1.IncomingInterface,
ibm gregor.InBandMessage, handler libkb.GregorInBandMessageHandler) (bool, error) {
g.Debug(ctx, "handleInBand: %+v", ibm)
gcli, err := g.getGregorCli()
if err != nil {
return false, err
}
state, err := gcli.StateMachineState(ctx, nil, false)
if err != nil {
return false, err
}
sync := ibm.ToStateSyncMessage()
if sync != nil {
g.Debug(ctx, "state sync message")
return false, nil
}
update := ibm.ToStateUpdateMessage()
if update != nil {
g.Debug(ctx, "state update message")
item := update.Creation()
if item != nil {
id := item.Metadata().MsgID().String()
g.Debug(ctx, "msg ID %s created ctime: %s", id,
item.Metadata().CTime())
category := ""
if item.Category() != nil {
category = item.Category().String()
g.Debug(ctx, "item %s has category %s", id, category)
}
if handled, err := handler.Create(ctx, cli, category, item); err != nil {
return handled, err
}
}
dismissal := update.Dismissal()
if dismissal != nil {
g.Debug(ctx, "received dismissal")
for _, id := range dismissal.MsgIDsToDismiss() {
item, present := state.GetItem(id)
if !present {
g.Debug(ctx, "tried to dismiss item %s, not present", id.String())
continue
}
g.Debug(ctx, "dismissing item %s", id.String())
category := ""
if item.Category() != nil {
category = item.Category().String()
g.Debug(ctx, "dismissal %s has category %s", id, category)
}
if handled, err := handler.Dismiss(ctx, cli, category, item); handled && err != nil {
return handled, err
}
}
if len(dismissal.RangesToDismiss()) > 0 {
g.Debug(ctx, "message range dismissing not implemented")
}
}
return true, nil
}
return false, nil
} | go | func (g *gregorHandler) handleInBandMessageWithHandler(ctx context.Context, cli gregor1.IncomingInterface,
ibm gregor.InBandMessage, handler libkb.GregorInBandMessageHandler) (bool, error) {
g.Debug(ctx, "handleInBand: %+v", ibm)
gcli, err := g.getGregorCli()
if err != nil {
return false, err
}
state, err := gcli.StateMachineState(ctx, nil, false)
if err != nil {
return false, err
}
sync := ibm.ToStateSyncMessage()
if sync != nil {
g.Debug(ctx, "state sync message")
return false, nil
}
update := ibm.ToStateUpdateMessage()
if update != nil {
g.Debug(ctx, "state update message")
item := update.Creation()
if item != nil {
id := item.Metadata().MsgID().String()
g.Debug(ctx, "msg ID %s created ctime: %s", id,
item.Metadata().CTime())
category := ""
if item.Category() != nil {
category = item.Category().String()
g.Debug(ctx, "item %s has category %s", id, category)
}
if handled, err := handler.Create(ctx, cli, category, item); err != nil {
return handled, err
}
}
dismissal := update.Dismissal()
if dismissal != nil {
g.Debug(ctx, "received dismissal")
for _, id := range dismissal.MsgIDsToDismiss() {
item, present := state.GetItem(id)
if !present {
g.Debug(ctx, "tried to dismiss item %s, not present", id.String())
continue
}
g.Debug(ctx, "dismissing item %s", id.String())
category := ""
if item.Category() != nil {
category = item.Category().String()
g.Debug(ctx, "dismissal %s has category %s", id, category)
}
if handled, err := handler.Dismiss(ctx, cli, category, item); handled && err != nil {
return handled, err
}
}
if len(dismissal.RangesToDismiss()) > 0 {
g.Debug(ctx, "message range dismissing not implemented")
}
}
return true, nil
}
return false, nil
} | [
"func",
"(",
"g",
"*",
"gregorHandler",
")",
"handleInBandMessageWithHandler",
"(",
"ctx",
"context",
".",
"Context",
",",
"cli",
"gregor1",
".",
"IncomingInterface",
",",
"ibm",
"gregor",
".",
"InBandMessage",
",",
"handler",
"libkb",
".",
"GregorInBandMessageHandler",
")",
"(",
"bool",
",",
"error",
")",
"{",
"g",
".",
"Debug",
"(",
"ctx",
",",
"\"",
"\"",
",",
"ibm",
")",
"\n\n",
"gcli",
",",
"err",
":=",
"g",
".",
"getGregorCli",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",
"state",
",",
"err",
":=",
"gcli",
".",
"StateMachineState",
"(",
"ctx",
",",
"nil",
",",
"false",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n\n",
"sync",
":=",
"ibm",
".",
"ToStateSyncMessage",
"(",
")",
"\n",
"if",
"sync",
"!=",
"nil",
"{",
"g",
".",
"Debug",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"return",
"false",
",",
"nil",
"\n",
"}",
"\n\n",
"update",
":=",
"ibm",
".",
"ToStateUpdateMessage",
"(",
")",
"\n",
"if",
"update",
"!=",
"nil",
"{",
"g",
".",
"Debug",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n\n",
"item",
":=",
"update",
".",
"Creation",
"(",
")",
"\n",
"if",
"item",
"!=",
"nil",
"{",
"id",
":=",
"item",
".",
"Metadata",
"(",
")",
".",
"MsgID",
"(",
")",
".",
"String",
"(",
")",
"\n",
"g",
".",
"Debug",
"(",
"ctx",
",",
"\"",
"\"",
",",
"id",
",",
"item",
".",
"Metadata",
"(",
")",
".",
"CTime",
"(",
")",
")",
"\n\n",
"category",
":=",
"\"",
"\"",
"\n",
"if",
"item",
".",
"Category",
"(",
")",
"!=",
"nil",
"{",
"category",
"=",
"item",
".",
"Category",
"(",
")",
".",
"String",
"(",
")",
"\n",
"g",
".",
"Debug",
"(",
"ctx",
",",
"\"",
"\"",
",",
"id",
",",
"category",
")",
"\n",
"}",
"\n\n",
"if",
"handled",
",",
"err",
":=",
"handler",
".",
"Create",
"(",
"ctx",
",",
"cli",
",",
"category",
",",
"item",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"handled",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"dismissal",
":=",
"update",
".",
"Dismissal",
"(",
")",
"\n",
"if",
"dismissal",
"!=",
"nil",
"{",
"g",
".",
"Debug",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"for",
"_",
",",
"id",
":=",
"range",
"dismissal",
".",
"MsgIDsToDismiss",
"(",
")",
"{",
"item",
",",
"present",
":=",
"state",
".",
"GetItem",
"(",
"id",
")",
"\n",
"if",
"!",
"present",
"{",
"g",
".",
"Debug",
"(",
"ctx",
",",
"\"",
"\"",
",",
"id",
".",
"String",
"(",
")",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"g",
".",
"Debug",
"(",
"ctx",
",",
"\"",
"\"",
",",
"id",
".",
"String",
"(",
")",
")",
"\n\n",
"category",
":=",
"\"",
"\"",
"\n",
"if",
"item",
".",
"Category",
"(",
")",
"!=",
"nil",
"{",
"category",
"=",
"item",
".",
"Category",
"(",
")",
".",
"String",
"(",
")",
"\n",
"g",
".",
"Debug",
"(",
"ctx",
",",
"\"",
"\"",
",",
"id",
",",
"category",
")",
"\n",
"}",
"\n\n",
"if",
"handled",
",",
"err",
":=",
"handler",
".",
"Dismiss",
"(",
"ctx",
",",
"cli",
",",
"category",
",",
"item",
")",
";",
"handled",
"&&",
"err",
"!=",
"nil",
"{",
"return",
"handled",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"dismissal",
".",
"RangesToDismiss",
"(",
")",
")",
">",
"0",
"{",
"g",
".",
"Debug",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"true",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"false",
",",
"nil",
"\n",
"}"
] | // handleInBandMessageWithHandler runs a message against the specified handler | [
"handleInBandMessageWithHandler",
"runs",
"a",
"message",
"against",
"the",
"specified",
"handler"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/service/gregor.go#L1041-L1111 |
161,275 | keybase/client | go/service/gregor.go | chatAwareInitialReconnectBackoffWindow | func (g *gregorHandler) chatAwareInitialReconnectBackoffWindow(ctx context.Context) time.Duration {
if g.chatAwareReconnectIsLong(ctx) {
return GregorConnectionLongRetryInterval
}
return 0
} | go | func (g *gregorHandler) chatAwareInitialReconnectBackoffWindow(ctx context.Context) time.Duration {
if g.chatAwareReconnectIsLong(ctx) {
return GregorConnectionLongRetryInterval
}
return 0
} | [
"func",
"(",
"g",
"*",
"gregorHandler",
")",
"chatAwareInitialReconnectBackoffWindow",
"(",
"ctx",
"context",
".",
"Context",
")",
"time",
".",
"Duration",
"{",
"if",
"g",
".",
"chatAwareReconnectIsLong",
"(",
"ctx",
")",
"{",
"return",
"GregorConnectionLongRetryInterval",
"\n",
"}",
"\n",
"return",
"0",
"\n",
"}"
] | // Similar to the backoff above, except that the "short" window is zero, so
// that active clients don't wait at all before their first reconnect attempt. | [
"Similar",
"to",
"the",
"backoff",
"above",
"except",
"that",
"the",
"short",
"window",
"is",
"zero",
"so",
"that",
"active",
"clients",
"don",
"t",
"wait",
"at",
"all",
"before",
"their",
"first",
"reconnect",
"attempt",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/service/gregor.go#L1544-L1549 |
161,276 | keybase/client | go/service/gregor.go | DismissItem | func (g *gregorHandler) DismissItem(ctx context.Context, cli gregor1.IncomingInterface, id gregor.MsgID) error {
if id == nil {
return nil
}
var err error
defer g.G().CTrace(ctx, fmt.Sprintf("gregorHandler.dismissItem(%s)", id.String()),
func() error { return err },
)()
defer g.pushState(keybase1.PushReason_NEW_DATA)
dismissal, err := grutils.FormMessageForDismissItem(ctx, g.currentUID(), id)
if err != nil {
return err
}
gcli, err := g.getGregorCli()
if err != nil {
return err
}
return gcli.ConsumeMessage(ctx, dismissal)
} | go | func (g *gregorHandler) DismissItem(ctx context.Context, cli gregor1.IncomingInterface, id gregor.MsgID) error {
if id == nil {
return nil
}
var err error
defer g.G().CTrace(ctx, fmt.Sprintf("gregorHandler.dismissItem(%s)", id.String()),
func() error { return err },
)()
defer g.pushState(keybase1.PushReason_NEW_DATA)
dismissal, err := grutils.FormMessageForDismissItem(ctx, g.currentUID(), id)
if err != nil {
return err
}
gcli, err := g.getGregorCli()
if err != nil {
return err
}
return gcli.ConsumeMessage(ctx, dismissal)
} | [
"func",
"(",
"g",
"*",
"gregorHandler",
")",
"DismissItem",
"(",
"ctx",
"context",
".",
"Context",
",",
"cli",
"gregor1",
".",
"IncomingInterface",
",",
"id",
"gregor",
".",
"MsgID",
")",
"error",
"{",
"if",
"id",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"var",
"err",
"error",
"\n",
"defer",
"g",
".",
"G",
"(",
")",
".",
"CTrace",
"(",
"ctx",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"id",
".",
"String",
"(",
")",
")",
",",
"func",
"(",
")",
"error",
"{",
"return",
"err",
"}",
",",
")",
"(",
")",
"\n",
"defer",
"g",
".",
"pushState",
"(",
"keybase1",
".",
"PushReason_NEW_DATA",
")",
"\n",
"dismissal",
",",
"err",
":=",
"grutils",
".",
"FormMessageForDismissItem",
"(",
"ctx",
",",
"g",
".",
"currentUID",
"(",
")",
",",
"id",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"gcli",
",",
"err",
":=",
"g",
".",
"getGregorCli",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"gcli",
".",
"ConsumeMessage",
"(",
"ctx",
",",
"dismissal",
")",
"\n",
"}"
] | // `cli` is the interface used to talk to gregor.
// If nil then the global cli will be used.
// Be sure to pass a cli when called from within OnConnect, as the global cli would deadlock. | [
"cli",
"is",
"the",
"interface",
"used",
"to",
"talk",
"to",
"gregor",
".",
"If",
"nil",
"then",
"the",
"global",
"cli",
"will",
"be",
"used",
".",
"Be",
"sure",
"to",
"pass",
"a",
"cli",
"when",
"called",
"from",
"within",
"OnConnect",
"as",
"the",
"global",
"cli",
"would",
"deadlock",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/service/gregor.go#L1642-L1660 |
161,277 | keybase/client | go/kbfs/env/context.go | NewContextFromGlobalContext | func NewContextFromGlobalContext(g *libkb.GlobalContext) *KBFSContext {
c := &KBFSContext{g: g}
c.initKBFSSocket()
return c
} | go | func NewContextFromGlobalContext(g *libkb.GlobalContext) *KBFSContext {
c := &KBFSContext{g: g}
c.initKBFSSocket()
return c
} | [
"func",
"NewContextFromGlobalContext",
"(",
"g",
"*",
"libkb",
".",
"GlobalContext",
")",
"*",
"KBFSContext",
"{",
"c",
":=",
"&",
"KBFSContext",
"{",
"g",
":",
"g",
"}",
"\n",
"c",
".",
"initKBFSSocket",
"(",
")",
"\n",
"return",
"c",
"\n",
"}"
] | // NewContextFromGlobalContext constructs a context | [
"NewContextFromGlobalContext",
"constructs",
"a",
"context"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/env/context.go#L81-L85 |
161,278 | keybase/client | go/kbfs/env/context.go | NewContext | func NewContext() *KBFSContext {
g := libkb.NewGlobalContextInit()
g.ConfigureConfig()
g.ConfigureLogging()
g.ConfigureCaches()
g.ConfigureMerkleClient()
return NewContextFromGlobalContext(g)
} | go | func NewContext() *KBFSContext {
g := libkb.NewGlobalContextInit()
g.ConfigureConfig()
g.ConfigureLogging()
g.ConfigureCaches()
g.ConfigureMerkleClient()
return NewContextFromGlobalContext(g)
} | [
"func",
"NewContext",
"(",
")",
"*",
"KBFSContext",
"{",
"g",
":=",
"libkb",
".",
"NewGlobalContextInit",
"(",
")",
"\n",
"g",
".",
"ConfigureConfig",
"(",
")",
"\n",
"g",
".",
"ConfigureLogging",
"(",
")",
"\n",
"g",
".",
"ConfigureCaches",
"(",
")",
"\n",
"g",
".",
"ConfigureMerkleClient",
"(",
")",
"\n",
"return",
"NewContextFromGlobalContext",
"(",
"g",
")",
"\n",
"}"
] | // NewContext constructs a context. This should only be called once in
// main functions. | [
"NewContext",
"constructs",
"a",
"context",
".",
"This",
"should",
"only",
"be",
"called",
"once",
"in",
"main",
"functions",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/env/context.go#L89-L96 |
161,279 | keybase/client | go/kbfs/env/context.go | NextAppStateUpdate | func (c *KBFSContext) NextAppStateUpdate(lastState *keybase1.MobileAppState) <-chan keybase1.MobileAppState {
return c.g.MobileAppState.NextUpdate(lastState)
} | go | func (c *KBFSContext) NextAppStateUpdate(lastState *keybase1.MobileAppState) <-chan keybase1.MobileAppState {
return c.g.MobileAppState.NextUpdate(lastState)
} | [
"func",
"(",
"c",
"*",
"KBFSContext",
")",
"NextAppStateUpdate",
"(",
"lastState",
"*",
"keybase1",
".",
"MobileAppState",
")",
"<-",
"chan",
"keybase1",
".",
"MobileAppState",
"{",
"return",
"c",
".",
"g",
".",
"MobileAppState",
".",
"NextUpdate",
"(",
"lastState",
")",
"\n",
"}"
] | // NextAppStateUpdate implements AppStateUpdater. | [
"NextAppStateUpdate",
"implements",
"AppStateUpdater",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/env/context.go#L119-L121 |
161,280 | keybase/client | go/kbfs/env/context.go | CheckService | func (c *KBFSContext) CheckService() error {
// Trying to dial the service seems like the best
// platform-agnostic way of seeing if the service is up.
// Stat-ing the socket file, for example, doesn't work for
// Windows named pipes.
s, err := libkb.NewSocket(c.g)
if err != nil {
return err
}
conn, err := s.DialSocket()
if err != nil {
if runtime.GOOS == "darwin" || runtime.GOOS == "windows" {
return errors.New(
"keybase isn't running; open the Keybase app")
}
return errors.New(
"keybase isn't running; try `run_keybase`")
}
err = conn.Close()
if err != nil {
return err
}
return nil
} | go | func (c *KBFSContext) CheckService() error {
// Trying to dial the service seems like the best
// platform-agnostic way of seeing if the service is up.
// Stat-ing the socket file, for example, doesn't work for
// Windows named pipes.
s, err := libkb.NewSocket(c.g)
if err != nil {
return err
}
conn, err := s.DialSocket()
if err != nil {
if runtime.GOOS == "darwin" || runtime.GOOS == "windows" {
return errors.New(
"keybase isn't running; open the Keybase app")
}
return errors.New(
"keybase isn't running; try `run_keybase`")
}
err = conn.Close()
if err != nil {
return err
}
return nil
} | [
"func",
"(",
"c",
"*",
"KBFSContext",
")",
"CheckService",
"(",
")",
"error",
"{",
"// Trying to dial the service seems like the best",
"// platform-agnostic way of seeing if the service is up.",
"// Stat-ing the socket file, for example, doesn't work for",
"// Windows named pipes.",
"s",
",",
"err",
":=",
"libkb",
".",
"NewSocket",
"(",
"c",
".",
"g",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"conn",
",",
"err",
":=",
"s",
".",
"DialSocket",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"runtime",
".",
"GOOS",
"==",
"\"",
"\"",
"||",
"runtime",
".",
"GOOS",
"==",
"\"",
"\"",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"err",
"=",
"conn",
".",
"Close",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // CheckService checks if the service is running and returns nil if
// so, and an error otherwise. | [
"CheckService",
"checks",
"if",
"the",
"service",
"is",
"running",
"and",
"returns",
"nil",
"if",
"so",
"and",
"an",
"error",
"otherwise",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/env/context.go#L125-L148 |
161,281 | keybase/client | go/kbfs/env/context.go | GetSocket | func (c *KBFSContext) GetSocket(clearError bool) (
net.Conn, rpc.Transporter, bool, error) {
return c.g.GetSocket(clearError)
} | go | func (c *KBFSContext) GetSocket(clearError bool) (
net.Conn, rpc.Transporter, bool, error) {
return c.g.GetSocket(clearError)
} | [
"func",
"(",
"c",
"*",
"KBFSContext",
")",
"GetSocket",
"(",
"clearError",
"bool",
")",
"(",
"net",
".",
"Conn",
",",
"rpc",
".",
"Transporter",
",",
"bool",
",",
"error",
")",
"{",
"return",
"c",
".",
"g",
".",
"GetSocket",
"(",
"clearError",
")",
"\n",
"}"
] | // GetSocket returns a socket | [
"GetSocket",
"returns",
"a",
"socket"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/env/context.go#L151-L154 |
161,282 | keybase/client | go/kbfs/env/context.go | NewRPCLogFactory | func (c *KBFSContext) NewRPCLogFactory() rpc.LogFactory {
return &libkb.RPCLogFactory{Contextified: libkb.NewContextified(c.g)}
} | go | func (c *KBFSContext) NewRPCLogFactory() rpc.LogFactory {
return &libkb.RPCLogFactory{Contextified: libkb.NewContextified(c.g)}
} | [
"func",
"(",
"c",
"*",
"KBFSContext",
")",
"NewRPCLogFactory",
"(",
")",
"rpc",
".",
"LogFactory",
"{",
"return",
"&",
"libkb",
".",
"RPCLogFactory",
"{",
"Contextified",
":",
"libkb",
".",
"NewContextified",
"(",
"c",
".",
"g",
")",
"}",
"\n",
"}"
] | // NewRPCLogFactory constructs an RPC logger | [
"NewRPCLogFactory",
"constructs",
"an",
"RPC",
"logger"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/env/context.go#L162-L164 |
161,283 | keybase/client | go/kbfs/env/context.go | cleanupSocketFile | func (c *KBFSContext) cleanupSocketFile() error {
switch sock := c.kbfsSocket.(type) {
case libkb.SocketInfo:
sf := sock.GetBindFile()
if exists, err := libkb.FileExists(sf); err != nil {
return err
} else if exists {
c.g.Log.Debug("removing stale socket file: %s", sf)
if err = os.Remove(sf); err != nil {
c.g.Log.Warning("error removing stale socket file: %s", err)
return err
}
}
case nil:
return errors.New("socket not initialized")
default:
return errors.New("invalid socket type")
}
return nil
} | go | func (c *KBFSContext) cleanupSocketFile() error {
switch sock := c.kbfsSocket.(type) {
case libkb.SocketInfo:
sf := sock.GetBindFile()
if exists, err := libkb.FileExists(sf); err != nil {
return err
} else if exists {
c.g.Log.Debug("removing stale socket file: %s", sf)
if err = os.Remove(sf); err != nil {
c.g.Log.Warning("error removing stale socket file: %s", err)
return err
}
}
case nil:
return errors.New("socket not initialized")
default:
return errors.New("invalid socket type")
}
return nil
} | [
"func",
"(",
"c",
"*",
"KBFSContext",
")",
"cleanupSocketFile",
"(",
")",
"error",
"{",
"switch",
"sock",
":=",
"c",
".",
"kbfsSocket",
".",
"(",
"type",
")",
"{",
"case",
"libkb",
".",
"SocketInfo",
":",
"sf",
":=",
"sock",
".",
"GetBindFile",
"(",
")",
"\n",
"if",
"exists",
",",
"err",
":=",
"libkb",
".",
"FileExists",
"(",
"sf",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"else",
"if",
"exists",
"{",
"c",
".",
"g",
".",
"Log",
".",
"Debug",
"(",
"\"",
"\"",
",",
"sf",
")",
"\n",
"if",
"err",
"=",
"os",
".",
"Remove",
"(",
"sf",
")",
";",
"err",
"!=",
"nil",
"{",
"c",
".",
"g",
".",
"Log",
".",
"Warning",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"case",
"nil",
":",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"default",
":",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // cleanupSocketFile cleans up the socket file for binding. | [
"cleanupSocketFile",
"cleans",
"up",
"the",
"socket",
"file",
"for",
"binding",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/env/context.go#L236-L255 |
161,284 | keybase/client | go/kbfs/env/context.go | BindToKBFSSocket | func (c *KBFSContext) BindToKBFSSocket() (net.Listener, error) {
c.kbfsSocketMtx.Lock()
defer c.kbfsSocketMtx.Unlock()
err := c.cleanupSocketFile()
if err != nil {
return nil, err
}
return c.kbfsSocket.BindToSocket()
} | go | func (c *KBFSContext) BindToKBFSSocket() (net.Listener, error) {
c.kbfsSocketMtx.Lock()
defer c.kbfsSocketMtx.Unlock()
err := c.cleanupSocketFile()
if err != nil {
return nil, err
}
return c.kbfsSocket.BindToSocket()
} | [
"func",
"(",
"c",
"*",
"KBFSContext",
")",
"BindToKBFSSocket",
"(",
")",
"(",
"net",
".",
"Listener",
",",
"error",
")",
"{",
"c",
".",
"kbfsSocketMtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"kbfsSocketMtx",
".",
"Unlock",
"(",
")",
"\n",
"err",
":=",
"c",
".",
"cleanupSocketFile",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"c",
".",
"kbfsSocket",
".",
"BindToSocket",
"(",
")",
"\n",
"}"
] | // BindToKBFSSocket binds to the socket configured in `c.kbfsSocket`. | [
"BindToKBFSSocket",
"binds",
"to",
"the",
"socket",
"configured",
"in",
"c",
".",
"kbfsSocket",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/env/context.go#L258-L266 |
161,285 | keybase/client | go/protocol/keybase1/extras.go | IsSubTeam | func (t TeamID) IsSubTeam() bool {
suffix := t[len(t)-2:]
switch suffix {
case SUB_TEAMID_PRIVATE_SUFFIX_HEX, SUB_TEAMID_PUBLIC_SUFFIX_HEX:
return true
}
return false
} | go | func (t TeamID) IsSubTeam() bool {
suffix := t[len(t)-2:]
switch suffix {
case SUB_TEAMID_PRIVATE_SUFFIX_HEX, SUB_TEAMID_PUBLIC_SUFFIX_HEX:
return true
}
return false
} | [
"func",
"(",
"t",
"TeamID",
")",
"IsSubTeam",
"(",
")",
"bool",
"{",
"suffix",
":=",
"t",
"[",
"len",
"(",
"t",
")",
"-",
"2",
":",
"]",
"\n",
"switch",
"suffix",
"{",
"case",
"SUB_TEAMID_PRIVATE_SUFFIX_HEX",
",",
"SUB_TEAMID_PUBLIC_SUFFIX_HEX",
":",
"return",
"true",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // Can panic if invalid | [
"Can",
"panic",
"if",
"invalid"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/protocol/keybase1/extras.go#L555-L562 |
161,286 | keybase/client | go/protocol/keybase1/extras.go | WrapError | func WrapError(e error) interface{} {
if e == nil {
return nil
}
if ee, ok := e.(ToStatusAble); ok {
tmp := ee.ToStatus()
return &tmp
}
if status, ok := e.(*Status); ok {
return status
}
if status, ok := e.(Status); ok {
return status
}
return Status{
Name: "GENERIC",
Code: int(StatusCode_SCGeneric),
Desc: e.Error(),
}
} | go | func WrapError(e error) interface{} {
if e == nil {
return nil
}
if ee, ok := e.(ToStatusAble); ok {
tmp := ee.ToStatus()
return &tmp
}
if status, ok := e.(*Status); ok {
return status
}
if status, ok := e.(Status); ok {
return status
}
return Status{
Name: "GENERIC",
Code: int(StatusCode_SCGeneric),
Desc: e.Error(),
}
} | [
"func",
"WrapError",
"(",
"e",
"error",
")",
"interface",
"{",
"}",
"{",
"if",
"e",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"if",
"ee",
",",
"ok",
":=",
"e",
".",
"(",
"ToStatusAble",
")",
";",
"ok",
"{",
"tmp",
":=",
"ee",
".",
"ToStatus",
"(",
")",
"\n",
"return",
"&",
"tmp",
"\n",
"}",
"\n\n",
"if",
"status",
",",
"ok",
":=",
"e",
".",
"(",
"*",
"Status",
")",
";",
"ok",
"{",
"return",
"status",
"\n",
"}",
"\n\n",
"if",
"status",
",",
"ok",
":=",
"e",
".",
"(",
"Status",
")",
";",
"ok",
"{",
"return",
"status",
"\n",
"}",
"\n\n",
"return",
"Status",
"{",
"Name",
":",
"\"",
"\"",
",",
"Code",
":",
"int",
"(",
"StatusCode_SCGeneric",
")",
",",
"Desc",
":",
"e",
".",
"Error",
"(",
")",
",",
"}",
"\n",
"}"
] | // WrapError is a generic method that converts a Go Error into a RPC error status object.
// If the error is itself a Status object to being with, then it will just return that
// status object. If it is something that can be made into a Status object via the
// ToStatusAble interface, then we'll try that. Otherwise, we'll just make a generic
// Error type. | [
"WrapError",
"is",
"a",
"generic",
"method",
"that",
"converts",
"a",
"Go",
"Error",
"into",
"a",
"RPC",
"error",
"status",
"object",
".",
"If",
"the",
"error",
"is",
"itself",
"a",
"Status",
"object",
"to",
"being",
"with",
"then",
"it",
"will",
"just",
"return",
"that",
"status",
"object",
".",
"If",
"it",
"is",
"something",
"that",
"can",
"be",
"made",
"into",
"a",
"Status",
"object",
"via",
"the",
"ToStatusAble",
"interface",
"then",
"we",
"ll",
"try",
"that",
".",
"Otherwise",
"we",
"ll",
"just",
"make",
"a",
"generic",
"Error",
"type",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/protocol/keybase1/extras.go#L1133-L1157 |
161,287 | keybase/client | go/protocol/keybase1/extras.go | UnwrapError | func (eu ErrorUnwrapper) UnwrapError(arg interface{}) (appError, dispatchError error) {
targ, ok := arg.(*Status)
if !ok {
dispatchError = errors.New("Error converting status to keybase1.Status object")
return nil, dispatchError
}
if targ == nil {
return nil, nil
}
if targ.Code == int(StatusCode_SCOk) {
return nil, nil
}
if eu.Upcaster != nil {
appError = eu.Upcaster(*targ)
} else {
appError = *targ
}
return appError, nil
} | go | func (eu ErrorUnwrapper) UnwrapError(arg interface{}) (appError, dispatchError error) {
targ, ok := arg.(*Status)
if !ok {
dispatchError = errors.New("Error converting status to keybase1.Status object")
return nil, dispatchError
}
if targ == nil {
return nil, nil
}
if targ.Code == int(StatusCode_SCOk) {
return nil, nil
}
if eu.Upcaster != nil {
appError = eu.Upcaster(*targ)
} else {
appError = *targ
}
return appError, nil
} | [
"func",
"(",
"eu",
"ErrorUnwrapper",
")",
"UnwrapError",
"(",
"arg",
"interface",
"{",
"}",
")",
"(",
"appError",
",",
"dispatchError",
"error",
")",
"{",
"targ",
",",
"ok",
":=",
"arg",
".",
"(",
"*",
"Status",
")",
"\n",
"if",
"!",
"ok",
"{",
"dispatchError",
"=",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"return",
"nil",
",",
"dispatchError",
"\n",
"}",
"\n",
"if",
"targ",
"==",
"nil",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"if",
"targ",
".",
"Code",
"==",
"int",
"(",
"StatusCode_SCOk",
")",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n\n",
"if",
"eu",
".",
"Upcaster",
"!=",
"nil",
"{",
"appError",
"=",
"eu",
".",
"Upcaster",
"(",
"*",
"targ",
")",
"\n",
"}",
"else",
"{",
"appError",
"=",
"*",
"targ",
"\n",
"}",
"\n",
"return",
"appError",
",",
"nil",
"\n",
"}"
] | // UnwrapError takes an incoming RPC object, attempts to coerce it into a Status
// object, and then Upcasts via the Upcaster or just returns if not was provided. | [
"UnwrapError",
"takes",
"an",
"incoming",
"RPC",
"object",
"attempts",
"to",
"coerce",
"it",
"into",
"a",
"Status",
"object",
"and",
"then",
"Upcasts",
"via",
"the",
"Upcaster",
"or",
"just",
"returns",
"if",
"not",
"was",
"provided",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/protocol/keybase1/extras.go#L1180-L1199 |
161,288 | keybase/client | go/protocol/keybase1/extras.go | ShouldSuppressTrackerPopups | func (b TLFIdentifyBehavior) ShouldSuppressTrackerPopups() bool {
switch b {
case TLFIdentifyBehavior_CHAT_GUI,
TLFIdentifyBehavior_CHAT_CLI,
TLFIdentifyBehavior_KBFS_REKEY,
TLFIdentifyBehavior_KBFS_QR,
TLFIdentifyBehavior_SALTPACK,
TLFIdentifyBehavior_RESOLVE_AND_CHECK,
TLFIdentifyBehavior_KBFS_CHAT,
TLFIdentifyBehavior_KBFS_INIT:
// These are identifies that either happen without user interaction at
// all, or happen while you're staring at some Keybase UI that can
// report errors on its own. No popups needed.
return true
default:
// TLFIdentifyBehavior_DEFAULT_KBFS, for filesystem activity that
// doesn't have any other UI to report errors with.
return false
}
} | go | func (b TLFIdentifyBehavior) ShouldSuppressTrackerPopups() bool {
switch b {
case TLFIdentifyBehavior_CHAT_GUI,
TLFIdentifyBehavior_CHAT_CLI,
TLFIdentifyBehavior_KBFS_REKEY,
TLFIdentifyBehavior_KBFS_QR,
TLFIdentifyBehavior_SALTPACK,
TLFIdentifyBehavior_RESOLVE_AND_CHECK,
TLFIdentifyBehavior_KBFS_CHAT,
TLFIdentifyBehavior_KBFS_INIT:
// These are identifies that either happen without user interaction at
// all, or happen while you're staring at some Keybase UI that can
// report errors on its own. No popups needed.
return true
default:
// TLFIdentifyBehavior_DEFAULT_KBFS, for filesystem activity that
// doesn't have any other UI to report errors with.
return false
}
} | [
"func",
"(",
"b",
"TLFIdentifyBehavior",
")",
"ShouldSuppressTrackerPopups",
"(",
")",
"bool",
"{",
"switch",
"b",
"{",
"case",
"TLFIdentifyBehavior_CHAT_GUI",
",",
"TLFIdentifyBehavior_CHAT_CLI",
",",
"TLFIdentifyBehavior_KBFS_REKEY",
",",
"TLFIdentifyBehavior_KBFS_QR",
",",
"TLFIdentifyBehavior_SALTPACK",
",",
"TLFIdentifyBehavior_RESOLVE_AND_CHECK",
",",
"TLFIdentifyBehavior_KBFS_CHAT",
",",
"TLFIdentifyBehavior_KBFS_INIT",
":",
"// These are identifies that either happen without user interaction at",
"// all, or happen while you're staring at some Keybase UI that can",
"// report errors on its own. No popups needed.",
"return",
"true",
"\n",
"default",
":",
"// TLFIdentifyBehavior_DEFAULT_KBFS, for filesystem activity that",
"// doesn't have any other UI to report errors with.",
"return",
"false",
"\n",
"}",
"\n",
"}"
] | // All of the chat modes want to prevent tracker popups. | [
"All",
"of",
"the",
"chat",
"modes",
"want",
"to",
"prevent",
"tracker",
"popups",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/protocol/keybase1/extras.go#L1309-L1328 |
161,289 | keybase/client | go/protocol/keybase1/extras.go | HasKID | func (u UserPlusKeysV2AllIncarnations) HasKID(kid KID) bool {
incarnation, _ := u.FindKID(kid)
return (incarnation != nil)
} | go | func (u UserPlusKeysV2AllIncarnations) HasKID(kid KID) bool {
incarnation, _ := u.FindKID(kid)
return (incarnation != nil)
} | [
"func",
"(",
"u",
"UserPlusKeysV2AllIncarnations",
")",
"HasKID",
"(",
"kid",
"KID",
")",
"bool",
"{",
"incarnation",
",",
"_",
":=",
"u",
".",
"FindKID",
"(",
"kid",
")",
"\n",
"return",
"(",
"incarnation",
"!=",
"nil",
")",
"\n",
"}"
] | // HasKID returns true if u has the given KID in any of its incarnations.
// Useful for deciding if we should repoll a stale UPAK in the UPAK loader. | [
"HasKID",
"returns",
"true",
"if",
"u",
"has",
"the",
"given",
"KID",
"in",
"any",
"of",
"its",
"incarnations",
".",
"Useful",
"for",
"deciding",
"if",
"we",
"should",
"repoll",
"a",
"stale",
"UPAK",
"in",
"the",
"UPAK",
"loader",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/protocol/keybase1/extras.go#L1513-L1516 |
161,290 | keybase/client | go/protocol/keybase1/extras.go | UPAKFromUPKV2AI | func UPAKFromUPKV2AI(uV2 UserPlusKeysV2AllIncarnations) UserPlusAllKeys {
// Convert the PGP keys.
var pgpKeysV1 []PublicKey
for _, keyV2 := range uV2.Current.PGPKeys {
pgpKeysV1 = append(pgpKeysV1, PublicKeyV1FromPGPKeyV2(keyV2))
}
// Convert the device keys.
var deviceKeysV1 []PublicKey
var revokedDeviceKeysV1 []RevokedKey
var resets []ResetSummary
for _, keyV2 := range uV2.Current.DeviceKeys {
if keyV2.Base.Revocation != nil {
revokedDeviceKeysV1 = append(revokedDeviceKeysV1, RevokedKeyV1FromDeviceKeyV2(keyV2))
} else {
deviceKeysV1 = append(deviceKeysV1, PublicKeyV1FromDeviceKeyV2(keyV2))
}
}
sort.Slice(deviceKeysV1, func(i, j int) bool { return deviceKeysV1[i].KID < deviceKeysV1[j].KID })
sort.Slice(revokedDeviceKeysV1, func(i, j int) bool { return revokedDeviceKeysV1[i].Key.KID < revokedDeviceKeysV1[j].Key.KID })
// Assemble the deleted device keys from past incarnations.
var deletedDeviceKeysV1 []PublicKey
for _, incarnation := range uV2.PastIncarnations {
for _, keyV2 := range incarnation.DeviceKeys {
deletedDeviceKeysV1 = append(deletedDeviceKeysV1, PublicKeyV1FromDeviceKeyV2(keyV2))
}
if reset := incarnation.Reset; reset != nil {
resets = append(resets, *reset)
}
}
sort.Slice(deletedDeviceKeysV1, func(i, j int) bool { return deletedDeviceKeysV1[i].KID < deletedDeviceKeysV1[j].KID })
// List and sort the remote tracks. Note that they *must* be sorted.
var remoteTracks []RemoteTrack
for _, track := range uV2.Current.RemoteTracks {
remoteTracks = append(remoteTracks, track)
}
sort.Slice(remoteTracks, func(i, j int) bool { return remoteTracks[i].Username < remoteTracks[j].Username })
// Apart from all the key mangling above, everything else is just naming
// and layout changes. Assemble the final UPAK.
return UserPlusAllKeys{
Base: UserPlusKeys{
Uid: uV2.Current.Uid,
Username: uV2.Current.Username,
EldestSeqno: uV2.Current.EldestSeqno,
Status: uV2.Current.Status,
DeviceKeys: deviceKeysV1,
RevokedDeviceKeys: revokedDeviceKeysV1,
DeletedDeviceKeys: deletedDeviceKeysV1,
PGPKeyCount: len(pgpKeysV1),
Uvv: uV2.Uvv,
PerUserKeys: uV2.Current.PerUserKeys,
Resets: resets,
},
PGPKeys: pgpKeysV1,
RemoteTracks: remoteTracks,
}
} | go | func UPAKFromUPKV2AI(uV2 UserPlusKeysV2AllIncarnations) UserPlusAllKeys {
// Convert the PGP keys.
var pgpKeysV1 []PublicKey
for _, keyV2 := range uV2.Current.PGPKeys {
pgpKeysV1 = append(pgpKeysV1, PublicKeyV1FromPGPKeyV2(keyV2))
}
// Convert the device keys.
var deviceKeysV1 []PublicKey
var revokedDeviceKeysV1 []RevokedKey
var resets []ResetSummary
for _, keyV2 := range uV2.Current.DeviceKeys {
if keyV2.Base.Revocation != nil {
revokedDeviceKeysV1 = append(revokedDeviceKeysV1, RevokedKeyV1FromDeviceKeyV2(keyV2))
} else {
deviceKeysV1 = append(deviceKeysV1, PublicKeyV1FromDeviceKeyV2(keyV2))
}
}
sort.Slice(deviceKeysV1, func(i, j int) bool { return deviceKeysV1[i].KID < deviceKeysV1[j].KID })
sort.Slice(revokedDeviceKeysV1, func(i, j int) bool { return revokedDeviceKeysV1[i].Key.KID < revokedDeviceKeysV1[j].Key.KID })
// Assemble the deleted device keys from past incarnations.
var deletedDeviceKeysV1 []PublicKey
for _, incarnation := range uV2.PastIncarnations {
for _, keyV2 := range incarnation.DeviceKeys {
deletedDeviceKeysV1 = append(deletedDeviceKeysV1, PublicKeyV1FromDeviceKeyV2(keyV2))
}
if reset := incarnation.Reset; reset != nil {
resets = append(resets, *reset)
}
}
sort.Slice(deletedDeviceKeysV1, func(i, j int) bool { return deletedDeviceKeysV1[i].KID < deletedDeviceKeysV1[j].KID })
// List and sort the remote tracks. Note that they *must* be sorted.
var remoteTracks []RemoteTrack
for _, track := range uV2.Current.RemoteTracks {
remoteTracks = append(remoteTracks, track)
}
sort.Slice(remoteTracks, func(i, j int) bool { return remoteTracks[i].Username < remoteTracks[j].Username })
// Apart from all the key mangling above, everything else is just naming
// and layout changes. Assemble the final UPAK.
return UserPlusAllKeys{
Base: UserPlusKeys{
Uid: uV2.Current.Uid,
Username: uV2.Current.Username,
EldestSeqno: uV2.Current.EldestSeqno,
Status: uV2.Current.Status,
DeviceKeys: deviceKeysV1,
RevokedDeviceKeys: revokedDeviceKeysV1,
DeletedDeviceKeys: deletedDeviceKeysV1,
PGPKeyCount: len(pgpKeysV1),
Uvv: uV2.Uvv,
PerUserKeys: uV2.Current.PerUserKeys,
Resets: resets,
},
PGPKeys: pgpKeysV1,
RemoteTracks: remoteTracks,
}
} | [
"func",
"UPAKFromUPKV2AI",
"(",
"uV2",
"UserPlusKeysV2AllIncarnations",
")",
"UserPlusAllKeys",
"{",
"// Convert the PGP keys.",
"var",
"pgpKeysV1",
"[",
"]",
"PublicKey",
"\n",
"for",
"_",
",",
"keyV2",
":=",
"range",
"uV2",
".",
"Current",
".",
"PGPKeys",
"{",
"pgpKeysV1",
"=",
"append",
"(",
"pgpKeysV1",
",",
"PublicKeyV1FromPGPKeyV2",
"(",
"keyV2",
")",
")",
"\n",
"}",
"\n\n",
"// Convert the device keys.",
"var",
"deviceKeysV1",
"[",
"]",
"PublicKey",
"\n",
"var",
"revokedDeviceKeysV1",
"[",
"]",
"RevokedKey",
"\n",
"var",
"resets",
"[",
"]",
"ResetSummary",
"\n",
"for",
"_",
",",
"keyV2",
":=",
"range",
"uV2",
".",
"Current",
".",
"DeviceKeys",
"{",
"if",
"keyV2",
".",
"Base",
".",
"Revocation",
"!=",
"nil",
"{",
"revokedDeviceKeysV1",
"=",
"append",
"(",
"revokedDeviceKeysV1",
",",
"RevokedKeyV1FromDeviceKeyV2",
"(",
"keyV2",
")",
")",
"\n",
"}",
"else",
"{",
"deviceKeysV1",
"=",
"append",
"(",
"deviceKeysV1",
",",
"PublicKeyV1FromDeviceKeyV2",
"(",
"keyV2",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"sort",
".",
"Slice",
"(",
"deviceKeysV1",
",",
"func",
"(",
"i",
",",
"j",
"int",
")",
"bool",
"{",
"return",
"deviceKeysV1",
"[",
"i",
"]",
".",
"KID",
"<",
"deviceKeysV1",
"[",
"j",
"]",
".",
"KID",
"}",
")",
"\n",
"sort",
".",
"Slice",
"(",
"revokedDeviceKeysV1",
",",
"func",
"(",
"i",
",",
"j",
"int",
")",
"bool",
"{",
"return",
"revokedDeviceKeysV1",
"[",
"i",
"]",
".",
"Key",
".",
"KID",
"<",
"revokedDeviceKeysV1",
"[",
"j",
"]",
".",
"Key",
".",
"KID",
"}",
")",
"\n\n",
"// Assemble the deleted device keys from past incarnations.",
"var",
"deletedDeviceKeysV1",
"[",
"]",
"PublicKey",
"\n",
"for",
"_",
",",
"incarnation",
":=",
"range",
"uV2",
".",
"PastIncarnations",
"{",
"for",
"_",
",",
"keyV2",
":=",
"range",
"incarnation",
".",
"DeviceKeys",
"{",
"deletedDeviceKeysV1",
"=",
"append",
"(",
"deletedDeviceKeysV1",
",",
"PublicKeyV1FromDeviceKeyV2",
"(",
"keyV2",
")",
")",
"\n",
"}",
"\n",
"if",
"reset",
":=",
"incarnation",
".",
"Reset",
";",
"reset",
"!=",
"nil",
"{",
"resets",
"=",
"append",
"(",
"resets",
",",
"*",
"reset",
")",
"\n",
"}",
"\n",
"}",
"\n",
"sort",
".",
"Slice",
"(",
"deletedDeviceKeysV1",
",",
"func",
"(",
"i",
",",
"j",
"int",
")",
"bool",
"{",
"return",
"deletedDeviceKeysV1",
"[",
"i",
"]",
".",
"KID",
"<",
"deletedDeviceKeysV1",
"[",
"j",
"]",
".",
"KID",
"}",
")",
"\n\n",
"// List and sort the remote tracks. Note that they *must* be sorted.",
"var",
"remoteTracks",
"[",
"]",
"RemoteTrack",
"\n",
"for",
"_",
",",
"track",
":=",
"range",
"uV2",
".",
"Current",
".",
"RemoteTracks",
"{",
"remoteTracks",
"=",
"append",
"(",
"remoteTracks",
",",
"track",
")",
"\n",
"}",
"\n",
"sort",
".",
"Slice",
"(",
"remoteTracks",
",",
"func",
"(",
"i",
",",
"j",
"int",
")",
"bool",
"{",
"return",
"remoteTracks",
"[",
"i",
"]",
".",
"Username",
"<",
"remoteTracks",
"[",
"j",
"]",
".",
"Username",
"}",
")",
"\n\n",
"// Apart from all the key mangling above, everything else is just naming",
"// and layout changes. Assemble the final UPAK.",
"return",
"UserPlusAllKeys",
"{",
"Base",
":",
"UserPlusKeys",
"{",
"Uid",
":",
"uV2",
".",
"Current",
".",
"Uid",
",",
"Username",
":",
"uV2",
".",
"Current",
".",
"Username",
",",
"EldestSeqno",
":",
"uV2",
".",
"Current",
".",
"EldestSeqno",
",",
"Status",
":",
"uV2",
".",
"Current",
".",
"Status",
",",
"DeviceKeys",
":",
"deviceKeysV1",
",",
"RevokedDeviceKeys",
":",
"revokedDeviceKeysV1",
",",
"DeletedDeviceKeys",
":",
"deletedDeviceKeysV1",
",",
"PGPKeyCount",
":",
"len",
"(",
"pgpKeysV1",
")",
",",
"Uvv",
":",
"uV2",
".",
"Uvv",
",",
"PerUserKeys",
":",
"uV2",
".",
"Current",
".",
"PerUserKeys",
",",
"Resets",
":",
"resets",
",",
"}",
",",
"PGPKeys",
":",
"pgpKeysV1",
",",
"RemoteTracks",
":",
"remoteTracks",
",",
"}",
"\n",
"}"
] | // UPKV2 should supersede UPAK eventually, but lots of older code requires
// UPAK. This is a simple converter function. | [
"UPKV2",
"should",
"supersede",
"UPAK",
"eventually",
"but",
"lots",
"of",
"older",
"code",
"requires",
"UPAK",
".",
"This",
"is",
"a",
"simple",
"converter",
"function",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/protocol/keybase1/extras.go#L1811-L1870 |
161,291 | keybase/client | go/protocol/keybase1/extras.go | ToTeamID | func (t TeamName) ToTeamID(public bool) TeamID {
low := strings.ToLower(t.String())
sum := sha256.Sum256([]byte(low))
var useSuffix byte = TEAMID_PRIVATE_SUFFIX
if public {
useSuffix = TEAMID_PUBLIC_SUFFIX
}
bs := append(sum[:15], useSuffix)
res, err := TeamIDFromString(hex.EncodeToString(bs))
if err != nil {
panic(err)
}
return res
} | go | func (t TeamName) ToTeamID(public bool) TeamID {
low := strings.ToLower(t.String())
sum := sha256.Sum256([]byte(low))
var useSuffix byte = TEAMID_PRIVATE_SUFFIX
if public {
useSuffix = TEAMID_PUBLIC_SUFFIX
}
bs := append(sum[:15], useSuffix)
res, err := TeamIDFromString(hex.EncodeToString(bs))
if err != nil {
panic(err)
}
return res
} | [
"func",
"(",
"t",
"TeamName",
")",
"ToTeamID",
"(",
"public",
"bool",
")",
"TeamID",
"{",
"low",
":=",
"strings",
".",
"ToLower",
"(",
"t",
".",
"String",
"(",
")",
")",
"\n",
"sum",
":=",
"sha256",
".",
"Sum256",
"(",
"[",
"]",
"byte",
"(",
"low",
")",
")",
"\n",
"var",
"useSuffix",
"byte",
"=",
"TEAMID_PRIVATE_SUFFIX",
"\n",
"if",
"public",
"{",
"useSuffix",
"=",
"TEAMID_PUBLIC_SUFFIX",
"\n",
"}",
"\n",
"bs",
":=",
"append",
"(",
"sum",
"[",
":",
"15",
"]",
",",
"useSuffix",
")",
"\n",
"res",
",",
"err",
":=",
"TeamIDFromString",
"(",
"hex",
".",
"EncodeToString",
"(",
"bs",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"res",
"\n",
"}"
] | // Get the top level team id for this team name.
// Only makes sense for non-sub teams.
// The first 15 bytes of the sha256 of the lowercase team name,
// followed by the byte 0x24, encoded as hex. | [
"Get",
"the",
"top",
"level",
"team",
"id",
"for",
"this",
"team",
"name",
".",
"Only",
"makes",
"sense",
"for",
"non",
"-",
"sub",
"teams",
".",
"The",
"first",
"15",
"bytes",
"of",
"the",
"sha256",
"of",
"the",
"lowercase",
"team",
"name",
"followed",
"by",
"the",
"byte",
"0x24",
"encoded",
"as",
"hex",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/protocol/keybase1/extras.go#L2089-L2102 |
161,292 | keybase/client | go/protocol/keybase1/extras.go | LockIDFromBytes | func LockIDFromBytes(data []byte) LockID {
sum := sha512.Sum512(data)
sum[0] = LockIDVersion0
return LockID(binary.BigEndian.Uint64(sum[:8]))
} | go | func LockIDFromBytes(data []byte) LockID {
sum := sha512.Sum512(data)
sum[0] = LockIDVersion0
return LockID(binary.BigEndian.Uint64(sum[:8]))
} | [
"func",
"LockIDFromBytes",
"(",
"data",
"[",
"]",
"byte",
")",
"LockID",
"{",
"sum",
":=",
"sha512",
".",
"Sum512",
"(",
"data",
")",
"\n",
"sum",
"[",
"0",
"]",
"=",
"LockIDVersion0",
"\n",
"return",
"LockID",
"(",
"binary",
".",
"BigEndian",
".",
"Uint64",
"(",
"sum",
"[",
":",
"8",
"]",
")",
")",
"\n",
"}"
] | // LockIDFromBytes takes the first 8 bytes of the sha512 over data, overwrites
// first byte with the version byte, then interprets it as int64 using big
// endian, and returns the value as LockID. | [
"LockIDFromBytes",
"takes",
"the",
"first",
"8",
"bytes",
"of",
"the",
"sha512",
"over",
"data",
"overwrites",
"first",
"byte",
"with",
"the",
"version",
"byte",
"then",
"interprets",
"it",
"as",
"int64",
"using",
"big",
"endian",
"and",
"returns",
"the",
"value",
"as",
"LockID",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/protocol/keybase1/extras.go#L2453-L2457 |
161,293 | keybase/client | go/protocol/keybase1/delegate_ui_ctl.go | RegisterGregorFirehoseFiltered | func (c DelegateUiCtlClient) RegisterGregorFirehoseFiltered(ctx context.Context, systems []string) (err error) {
__arg := RegisterGregorFirehoseFilteredArg{Systems: systems}
err = c.Cli.Call(ctx, "keybase.1.delegateUiCtl.registerGregorFirehoseFiltered", []interface{}{__arg}, nil)
return
} | go | func (c DelegateUiCtlClient) RegisterGregorFirehoseFiltered(ctx context.Context, systems []string) (err error) {
__arg := RegisterGregorFirehoseFilteredArg{Systems: systems}
err = c.Cli.Call(ctx, "keybase.1.delegateUiCtl.registerGregorFirehoseFiltered", []interface{}{__arg}, nil)
return
} | [
"func",
"(",
"c",
"DelegateUiCtlClient",
")",
"RegisterGregorFirehoseFiltered",
"(",
"ctx",
"context",
".",
"Context",
",",
"systems",
"[",
"]",
"string",
")",
"(",
"err",
"error",
")",
"{",
"__arg",
":=",
"RegisterGregorFirehoseFilteredArg",
"{",
"Systems",
":",
"systems",
"}",
"\n",
"err",
"=",
"c",
".",
"Cli",
".",
"Call",
"(",
"ctx",
",",
"\"",
"\"",
",",
"[",
"]",
"interface",
"{",
"}",
"{",
"__arg",
"}",
",",
"nil",
")",
"\n",
"return",
"\n",
"}"
] | // registerGregorFirehoseFilter allows a client to register for a filtered
// firehose, limited to only the OOBMs of the systems provided.
// Like the firehose handler, but less pressure. | [
"registerGregorFirehoseFilter",
"allows",
"a",
"client",
"to",
"register",
"for",
"a",
"filtered",
"firehose",
"limited",
"to",
"only",
"the",
"OOBMs",
"of",
"the",
"systems",
"provided",
".",
"Like",
"the",
"firehose",
"handler",
"but",
"less",
"pressure",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/protocol/keybase1/delegate_ui_ctl.go#L204-L208 |
161,294 | keybase/client | go/libkb/sig.go | OpenSig | func OpenSig(armored string) (ret []byte, id keybase1.SigID, err error) {
if isPGPBundle(armored) {
var ps *ParsedSig
if ps, err = PGPOpenSig(armored); err == nil {
ret = ps.SigBody
id = ps.ID()
}
} else {
if ret, err = KbOpenSig(armored); err == nil {
id = kbcrypto.ComputeSigIDFromSigBody(ret)
}
}
return
} | go | func OpenSig(armored string) (ret []byte, id keybase1.SigID, err error) {
if isPGPBundle(armored) {
var ps *ParsedSig
if ps, err = PGPOpenSig(armored); err == nil {
ret = ps.SigBody
id = ps.ID()
}
} else {
if ret, err = KbOpenSig(armored); err == nil {
id = kbcrypto.ComputeSigIDFromSigBody(ret)
}
}
return
} | [
"func",
"OpenSig",
"(",
"armored",
"string",
")",
"(",
"ret",
"[",
"]",
"byte",
",",
"id",
"keybase1",
".",
"SigID",
",",
"err",
"error",
")",
"{",
"if",
"isPGPBundle",
"(",
"armored",
")",
"{",
"var",
"ps",
"*",
"ParsedSig",
"\n",
"if",
"ps",
",",
"err",
"=",
"PGPOpenSig",
"(",
"armored",
")",
";",
"err",
"==",
"nil",
"{",
"ret",
"=",
"ps",
".",
"SigBody",
"\n",
"id",
"=",
"ps",
".",
"ID",
"(",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"if",
"ret",
",",
"err",
"=",
"KbOpenSig",
"(",
"armored",
")",
";",
"err",
"==",
"nil",
"{",
"id",
"=",
"kbcrypto",
".",
"ComputeSigIDFromSigBody",
"(",
"ret",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // OpenSig takes an armored PGP or Keybase signature and opens
// the armor. It will return the body of the signature, the
// sigID of the body, or an error if it didn't work out. | [
"OpenSig",
"takes",
"an",
"armored",
"PGP",
"or",
"Keybase",
"signature",
"and",
"opens",
"the",
"armor",
".",
"It",
"will",
"return",
"the",
"body",
"of",
"the",
"signature",
"the",
"sigID",
"of",
"the",
"body",
"or",
"an",
"error",
"if",
"it",
"didn",
"t",
"work",
"out",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/sig.go#L52-L65 |
161,295 | keybase/client | go/libkb/sig.go | SigExtractPayloadAndKID | func SigExtractPayloadAndKID(armored string) (payload []byte, kid keybase1.KID, sigID keybase1.SigID, err error) {
if isPGPBundle(armored) {
payload, sigID, err = SigExtractPGPPayload(armored)
} else {
payload, kid, sigID, err = SigExtractKbPayloadAndKID(armored)
}
return payload, kid, sigID, err
} | go | func SigExtractPayloadAndKID(armored string) (payload []byte, kid keybase1.KID, sigID keybase1.SigID, err error) {
if isPGPBundle(armored) {
payload, sigID, err = SigExtractPGPPayload(armored)
} else {
payload, kid, sigID, err = SigExtractKbPayloadAndKID(armored)
}
return payload, kid, sigID, err
} | [
"func",
"SigExtractPayloadAndKID",
"(",
"armored",
"string",
")",
"(",
"payload",
"[",
"]",
"byte",
",",
"kid",
"keybase1",
".",
"KID",
",",
"sigID",
"keybase1",
".",
"SigID",
",",
"err",
"error",
")",
"{",
"if",
"isPGPBundle",
"(",
"armored",
")",
"{",
"payload",
",",
"sigID",
",",
"err",
"=",
"SigExtractPGPPayload",
"(",
"armored",
")",
"\n",
"}",
"else",
"{",
"payload",
",",
"kid",
",",
"sigID",
",",
"err",
"=",
"SigExtractKbPayloadAndKID",
"(",
"armored",
")",
"\n",
"}",
"\n",
"return",
"payload",
",",
"kid",
",",
"sigID",
",",
"err",
"\n",
"}"
] | // SigExtractPayloadAndKID extracts the payload and KID of the key that
// was supposedly used to sign this message. A KID will only be returned
// for KB messages, and not for PGP messages | [
"SigExtractPayloadAndKID",
"extracts",
"the",
"payload",
"and",
"KID",
"of",
"the",
"key",
"that",
"was",
"supposedly",
"used",
"to",
"sign",
"this",
"message",
".",
"A",
"KID",
"will",
"only",
"be",
"returned",
"for",
"KB",
"messages",
"and",
"not",
"for",
"PGP",
"messages"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/sig.go#L70-L77 |
161,296 | keybase/client | go/kbfs/libpages/config/config_v1.go | DefaultV1 | func DefaultV1() *V1 {
v1 := &V1{
Common: Common{
Version: Version1Str,
},
ACLs: map[string]AccessControlV1{
"/": AccessControlV1{
AnonymousPermissions: "read,list",
},
},
}
v1.EnsureInit()
return v1
} | go | func DefaultV1() *V1 {
v1 := &V1{
Common: Common{
Version: Version1Str,
},
ACLs: map[string]AccessControlV1{
"/": AccessControlV1{
AnonymousPermissions: "read,list",
},
},
}
v1.EnsureInit()
return v1
} | [
"func",
"DefaultV1",
"(",
")",
"*",
"V1",
"{",
"v1",
":=",
"&",
"V1",
"{",
"Common",
":",
"Common",
"{",
"Version",
":",
"Version1Str",
",",
"}",
",",
"ACLs",
":",
"map",
"[",
"string",
"]",
"AccessControlV1",
"{",
"\"",
"\"",
":",
"AccessControlV1",
"{",
"AnonymousPermissions",
":",
"\"",
"\"",
",",
"}",
",",
"}",
",",
"}",
"\n",
"v1",
".",
"EnsureInit",
"(",
")",
"\n",
"return",
"v1",
"\n",
"}"
] | // DefaultV1 returns a default V1 config, which allows anonymous read to
// everything. | [
"DefaultV1",
"returns",
"a",
"default",
"V1",
"config",
"which",
"allows",
"anonymous",
"read",
"to",
"everything",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libpages/config/config_v1.go#L49-L62 |
161,297 | keybase/client | go/kbfs/libpages/config/config_v1.go | EnsureInit | func (c *V1) EnsureInit() error {
c.initOnce.Do(c.init)
return c.aclCheckerInitErr
} | go | func (c *V1) EnsureInit() error {
c.initOnce.Do(c.init)
return c.aclCheckerInitErr
} | [
"func",
"(",
"c",
"*",
"V1",
")",
"EnsureInit",
"(",
")",
"error",
"{",
"c",
".",
"initOnce",
".",
"Do",
"(",
"c",
".",
"init",
")",
"\n",
"return",
"c",
".",
"aclCheckerInitErr",
"\n",
"}"
] | // EnsureInit initializes c, and returns any error encountered during the
// initialization. It is not necessary to call EnsureInit. Methods that need it
// does it automatically. | [
"EnsureInit",
"initializes",
"c",
"and",
"returns",
"any",
"error",
"encountered",
"during",
"the",
"initialization",
".",
"It",
"is",
"not",
"necessary",
"to",
"call",
"EnsureInit",
".",
"Methods",
"that",
"need",
"it",
"does",
"it",
"automatically",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libpages/config/config_v1.go#L84-L87 |
161,298 | keybase/client | go/kbfs/libpages/config/config_v1.go | Authenticate | func (c *V1) Authenticate(ctx context.Context, username, cleartextPassword string) bool {
if c.EnsureInit() != nil {
return false
}
p, ok := c.users[username]
if !ok {
return false
}
match, err := p.check(ctx, c.bcryptLimiter, cleartextPassword)
return err == nil && match
} | go | func (c *V1) Authenticate(ctx context.Context, username, cleartextPassword string) bool {
if c.EnsureInit() != nil {
return false
}
p, ok := c.users[username]
if !ok {
return false
}
match, err := p.check(ctx, c.bcryptLimiter, cleartextPassword)
return err == nil && match
} | [
"func",
"(",
"c",
"*",
"V1",
")",
"Authenticate",
"(",
"ctx",
"context",
".",
"Context",
",",
"username",
",",
"cleartextPassword",
"string",
")",
"bool",
"{",
"if",
"c",
".",
"EnsureInit",
"(",
")",
"!=",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"p",
",",
"ok",
":=",
"c",
".",
"users",
"[",
"username",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}",
"\n",
"match",
",",
"err",
":=",
"p",
".",
"check",
"(",
"ctx",
",",
"c",
".",
"bcryptLimiter",
",",
"cleartextPassword",
")",
"\n",
"return",
"err",
"==",
"nil",
"&&",
"match",
"\n",
"}"
] | // Authenticate implements the Config interface. | [
"Authenticate",
"implements",
"the",
"Config",
"interface",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libpages/config/config_v1.go#L95-L106 |
161,299 | keybase/client | go/kbfs/libpages/config/config_v1.go | GetPermissions | func (c *V1) GetPermissions(path string, username *string) (
read, list bool,
possibleRead, possibleList bool,
realm string, err error) {
if err = c.EnsureInit(); err != nil {
return false, false, false, false, "", err
}
perms, maxPerms, realm := c.aclChecker.getPermissions(path, username)
return perms.read, perms.list, maxPerms.read, maxPerms.list, realm, nil
} | go | func (c *V1) GetPermissions(path string, username *string) (
read, list bool,
possibleRead, possibleList bool,
realm string, err error) {
if err = c.EnsureInit(); err != nil {
return false, false, false, false, "", err
}
perms, maxPerms, realm := c.aclChecker.getPermissions(path, username)
return perms.read, perms.list, maxPerms.read, maxPerms.list, realm, nil
} | [
"func",
"(",
"c",
"*",
"V1",
")",
"GetPermissions",
"(",
"path",
"string",
",",
"username",
"*",
"string",
")",
"(",
"read",
",",
"list",
"bool",
",",
"possibleRead",
",",
"possibleList",
"bool",
",",
"realm",
"string",
",",
"err",
"error",
")",
"{",
"if",
"err",
"=",
"c",
".",
"EnsureInit",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"false",
",",
"false",
",",
"false",
",",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"perms",
",",
"maxPerms",
",",
"realm",
":=",
"c",
".",
"aclChecker",
".",
"getPermissions",
"(",
"path",
",",
"username",
")",
"\n",
"return",
"perms",
".",
"read",
",",
"perms",
".",
"list",
",",
"maxPerms",
".",
"read",
",",
"maxPerms",
".",
"list",
",",
"realm",
",",
"nil",
"\n",
"}"
] | // GetPermissions implements the Config interface. | [
"GetPermissions",
"implements",
"the",
"Config",
"interface",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libpages/config/config_v1.go#L109-L119 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.