forked from keybase/client
/
track.go
116 lines (96 loc) · 2.84 KB
/
track.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Copyright 2015 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.
package engine
import (
"errors"
"github.com/keybase/client/go/libkb"
keybase1 "github.com/keybase/client/go/protocol/keybase1"
)
type TrackEngineArg struct {
UserAssertion string
Me *libkb.User
Options keybase1.TrackOptions
ForceRemoteCheck bool
AllowSelfIdentify bool
}
type TrackEngine struct {
arg *TrackEngineArg
them *libkb.User
libkb.Contextified
confirmResult keybase1.ConfirmResult
}
// NewTrackEngine creates a default TrackEngine for tracking theirName.
func NewTrackEngine(arg *TrackEngineArg, g *libkb.GlobalContext) *TrackEngine {
return &TrackEngine{
arg: arg,
Contextified: libkb.NewContextified(g),
}
}
func (e *TrackEngine) Name() string {
return "Follow"
}
func (e *TrackEngine) Prereqs() Prereqs {
return Prereqs{
Device: true,
}
}
func (e *TrackEngine) RequiredUIs() []libkb.UIKind {
return []libkb.UIKind{
libkb.SecretUIKind,
libkb.IdentifyUIKind,
}
}
func (e *TrackEngine) SubConsumers() []libkb.UIConsumer {
return []libkb.UIConsumer{
&ResolveThenIdentify2{},
}
}
func (e *TrackEngine) Run(ctx *Context) error {
e.G().LocalSigchainGuard().Set(ctx.GetNetContext(), "TrackEngine")
defer e.G().LocalSigchainGuard().Clear(ctx.GetNetContext(), "TrackEngine")
arg := &keybase1.Identify2Arg{
UserAssertion: e.arg.UserAssertion,
ForceRemoteCheck: e.arg.ForceRemoteCheck,
NeedProofSet: true,
NoErrorOnTrackFailure: true,
AlwaysBlock: true,
}
ieng := NewResolveThenIdentify2WithTrack(e.G(), arg, e.arg.Options)
if err := RunEngine(ieng, ctx); err != nil {
return err
}
upk := ieng.Result().Upk
var err error
loadarg := libkb.NewLoadUserArgBase(e.G()).WithNetContext(ctx.NetContext).WithUID(upk.Uid).WithPublicKeyOptional()
e.them, err = libkb.LoadUser(*loadarg)
if err != nil {
return err
}
e.confirmResult = ieng.ConfirmResult()
if !e.confirmResult.IdentityConfirmed {
e.G().Log.Debug("confirmResult: %+v", e.confirmResult)
return errors.New("Follow not confirmed")
}
// if they didn't specify local only on the command line, then if they answer no to posting
// the tracking statement publicly to keybase, change LocalOnly to true here:
if !e.arg.Options.LocalOnly && !e.confirmResult.RemoteConfirmed {
e.arg.Options.LocalOnly = true
}
if !e.arg.Options.ExpiringLocal && e.confirmResult.ExpiringLocal {
e.G().Log.Debug("-ExpiringLocal-")
e.arg.Options.ExpiringLocal = true
}
targ := &TrackTokenArg{
Token: ieng.TrackToken(),
Me: e.arg.Me,
Options: e.arg.Options,
}
teng := NewTrackToken(targ, e.G())
return RunEngine(teng, ctx)
}
func (e *TrackEngine) User() *libkb.User {
return e.them
}
func (e *TrackEngine) ConfirmResult() keybase1.ConfirmResult {
return e.confirmResult
}