Skip to content

Commit

Permalink
Merge branch 'mike/CORE-9970' into mike/CORE-9974
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaxim committed Mar 22, 2019
2 parents 1e16799 + 39e447b commit 91f9b48
Show file tree
Hide file tree
Showing 505 changed files with 153,998 additions and 41,569 deletions.
32 changes: 31 additions & 1 deletion Jenkinsfile
Expand Up @@ -381,6 +381,26 @@ def testGo(prefix, packagesToTest) {
sh 'make -s lint'
}
}

if (isUnix()) {
// Windows `gofmt` pukes on CRLF, so only run on *nix.
println "Running mockgen"
retry(5) {
sh 'go get -u github.com/golang/mock/mockgen'
}
dir('kbfs/libkbfs') {
retry(5) {
timeout(activity: true, time: 90, unit: 'SECONDS') {
sh '''
set -e -x
./gen_mocks.sh
git diff --exit-code
'''
}
}
}
}

// Make sure we don't accidentally pull in the testing package.
sh '! go list -f \'{{ join .Deps "\\n" }}\' github.com/keybase/client/go/keybase | grep testing'

Expand All @@ -404,8 +424,14 @@ def testGo(prefix, packagesToTest) {
],
test_linux_go_: [
'*': [],
'github.com/keybase/client/go/kbfs/test': [
name: 'kbfs_test_fuse',
flags: '-tags fuse',
timeout: '15m',
],
'github.com/keybase/client/go/kbfs/libfuse': [
disable: true,
flags: '',
timeout: '3m',
],
'github.com/keybase/client/go/kbfs/idutil': [
flags: '-race',
Expand Down Expand Up @@ -463,6 +489,10 @@ def testGo(prefix, packagesToTest) {
flags: '-race',
timeout: '30s',
],
'github.com/keybase/client/go/kbfs/libkey': [
flags: '-race',
timeout: '5m',
],
'github.com/keybase/client/go/kbfs/libkbfs': [
flags: '-race',
timeout: '5m',
Expand Down
6 changes: 3 additions & 3 deletions go/avatars/fullcaching.go
Expand Up @@ -109,11 +109,11 @@ func (c *FullCachingSource) isStale(m libkb.MetaContext, item lru.DiskLRUEntry)

func (c *FullCachingSource) monitorAppState(m libkb.MetaContext) {
c.debug(m, "monitorAppState: starting up")
state := keybase1.AppState_FOREGROUND
state := keybase1.MobileAppState_FOREGROUND
for {
state = <-m.G().AppState.NextUpdate(&state)
state = <-m.G().MobileAppState.NextUpdate(&state)
switch state {
case keybase1.AppState_BACKGROUND:
case keybase1.MobileAppState_BACKGROUND:
c.debug(m, "monitorAppState: backgrounded")
c.diskLRU.Flush(m.Ctx(), m.G())
}
Expand Down
6 changes: 3 additions & 3 deletions go/avatars/urlcaching.go
Expand Up @@ -50,11 +50,11 @@ func (c *URLCachingSource) isStale(m libkb.MetaContext, item lru.DiskLRUEntry) b

func (c *URLCachingSource) monitorAppState(m libkb.MetaContext) {
c.debug(m, "monitorAppState: starting up")
state := keybase1.AppState_FOREGROUND
state := keybase1.MobileAppState_FOREGROUND
for {
state = <-m.G().AppState.NextUpdate(&state)
state = <-m.G().MobileAppState.NextUpdate(&state)
switch state {
case keybase1.AppState_BACKGROUND:
case keybase1.MobileAppState_BACKGROUND:
c.debug(m, "monitorAppState: backgrounded")
c.diskLRU.Flush(m.Ctx(), m.G())
}
Expand Down
33 changes: 18 additions & 15 deletions go/bind/keybase.go
Expand Up @@ -214,6 +214,8 @@ func Init(homeDir, mobileSharedHome, logFile, runModeStr string,
EK: config.GetEKLogFile(),
}

fmt.Printf("Go: Using config: %+v\n", kbCtx.Env.GetLogFileConfig(config.GetLogFile()))

logSendContext = libkb.LogSendContext{
Contextified: libkb.NewContextified(kbCtx),
Logs: logs,
Expand Down Expand Up @@ -275,7 +277,8 @@ func LogSend(status string, feedback string, sendLogs bool, uiLogPath, traceDir,
logSendContext.Logs.Trace = traceDir
logSendContext.Logs.CPUProfile = cpuProfileDir
env := kbCtx.Env
return logSendContext.LogSend(status, feedback, sendLogs, 10*1024*1024, env.GetUID(), env.GetInstallID(), true /* mergeExtendedStatus */)
sendLogMaxSizeBytes := 10 * 1024 * 1024 // NOTE: If you increase this, check go/libkb/env.go:Env.GetLogFileConfig to make sure we store at least that much.
return logSendContext.LogSend(status, feedback, sendLogs, sendLogMaxSizeBytes, env.GetUID(), env.GetInstallID(), true /* mergeExtendedStatus */)
}

// WriteB64 sends a base64 encoded msgpack rpc payload
Expand Down Expand Up @@ -365,28 +368,28 @@ func SetAppStateForeground() {
return
}
defer kbCtx.Trace("SetAppStateForeground", func() error { return nil })()
kbCtx.AppState.Update(keybase1.AppState_FOREGROUND)
kbCtx.MobileAppState.Update(keybase1.MobileAppState_FOREGROUND)
}
func SetAppStateBackground() {
if !isInited() {
return
}
defer kbCtx.Trace("SetAppStateBackground", func() error { return nil })()
kbCtx.AppState.Update(keybase1.AppState_BACKGROUND)
kbCtx.MobileAppState.Update(keybase1.MobileAppState_BACKGROUND)
}
func SetAppStateInactive() {
if !isInited() {
return
}
defer kbCtx.Trace("SetAppStateInactive", func() error { return nil })()
kbCtx.AppState.Update(keybase1.AppState_INACTIVE)
kbCtx.MobileAppState.Update(keybase1.MobileAppState_INACTIVE)
}
func SetAppStateBackgroundActive() {
if !isInited() {
return
}
defer kbCtx.Trace("SetAppStateBackgroundActive", func() error { return nil })()
kbCtx.AppState.Update(keybase1.AppState_BACKGROUNDACTIVE)
kbCtx.MobileAppState.Update(keybase1.MobileAppState_BACKGROUNDACTIVE)
}

func waitForInit(maxDur time.Duration) error {
Expand Down Expand Up @@ -415,23 +418,23 @@ func BackgroundSync() {
defer kbCtx.Trace("BackgroundSync", func() error { return nil })()

// Skip the sync if we aren't in the background
if state := kbCtx.AppState.State(); state != keybase1.AppState_BACKGROUND {
if state := kbCtx.MobileAppState.State(); state != keybase1.MobileAppState_BACKGROUND {
kbCtx.Log.Debug("BackgroundSync: skipping, app not in background state: %v", state)
return
}

nextState := keybase1.AppState_BACKGROUNDACTIVE
kbCtx.AppState.Update(nextState)
nextState := keybase1.MobileAppState_BACKGROUNDACTIVE
kbCtx.MobileAppState.Update(nextState)
doneCh := make(chan struct{})
go func() {
defer func() { close(doneCh) }()
select {
case state := <-kbCtx.AppState.NextUpdate(&nextState):
case state := <-kbCtx.MobileAppState.NextUpdate(&nextState):
// if literally anything happens, let's get out of here
kbCtx.Log.Debug("BackgroundSync: bailing out early, appstate change: %v", state)
return
case <-time.After(10 * time.Second):
kbCtx.AppState.Update(keybase1.AppState_BACKGROUND)
kbCtx.MobileAppState.Update(keybase1.MobileAppState_BACKGROUND)
return
}
}()
Expand Down Expand Up @@ -513,7 +516,7 @@ func AppWillExit(pusher PushNotifier) {
// stuck
pushPendingMessageFailure(convs[0], pusher)
}
kbCtx.AppState.Update(keybase1.AppState_BACKGROUND)
kbCtx.MobileAppState.Update(keybase1.MobileAppState_BACKGROUND)
}

// AppDidEnterBackground notifies the service that the app is in the background
Expand All @@ -540,7 +543,7 @@ func AppDidEnterBackground() bool {
}
if stayRunning {
kbCtx.Log.Debug("AppDidEnterBackground: setting background active")
kbCtx.AppState.Update(keybase1.AppState_BACKGROUNDACTIVE)
kbCtx.MobileAppState.Update(keybase1.MobileAppState_BACKGROUNDACTIVE)
return true
}
SetAppStateBackground()
Expand All @@ -566,16 +569,16 @@ func AppBeginBackgroundTask(pusher PushNotifier) {
// Poll active deliveries in case we can shutdown early
beginTime := libkb.ForceWallClock(time.Now())
ticker := time.NewTicker(5 * time.Second)
appState := kbCtx.AppState.State()
if appState != keybase1.AppState_BACKGROUNDACTIVE {
appState := kbCtx.MobileAppState.State()
if appState != keybase1.MobileAppState_BACKGROUNDACTIVE {
kbCtx.Log.Debug("AppBeginBackgroundTask: not in background mode, early out")
return
}
var g *errgroup.Group
g, ctx = errgroup.WithContext(ctx)
g.Go(func() error {
select {
case appState = <-kbCtx.AppState.NextUpdate(&appState):
case appState = <-kbCtx.MobileAppState.NextUpdate(&appState):
kbCtx.Log.Debug(
"AppBeginBackgroundTask: app state change, aborting with no task shutdown: %v", appState)
return errors.New("app state change")
Expand Down
8 changes: 4 additions & 4 deletions go/chat/attachment_httpsrv.go
Expand Up @@ -92,13 +92,13 @@ func (r *AttachmentHTTPSrv) OnCacheCleared(mctx libkb.MetaContext) {
func (r *AttachmentHTTPSrv) monitorAppState() {
ctx := context.Background()
r.Debug(ctx, "monitorAppState: starting up")
state := keybase1.AppState_FOREGROUND
state := keybase1.MobileAppState_FOREGROUND
for {
state = <-r.G().AppState.NextUpdate(&state)
state = <-r.G().MobileAppState.NextUpdate(&state)
switch state {
case keybase1.AppState_FOREGROUND:
case keybase1.MobileAppState_FOREGROUND:
r.startHTTPSrv()
case keybase1.AppState_BACKGROUND, keybase1.AppState_INACTIVE:
case keybase1.MobileAppState_BACKGROUND, keybase1.MobileAppState_INACTIVE:
r.httpSrv.Stop()
}
}
Expand Down
8 changes: 4 additions & 4 deletions go/chat/convloader.go
Expand Up @@ -160,19 +160,19 @@ func (b *BackgroundConvLoader) monitorAppState() {
ctx := context.Background()
suspended := false
b.Debug(ctx, "monitorAppState: starting up")
state := keybase1.AppState_FOREGROUND
state := keybase1.MobileAppState_FOREGROUND
for {
state = <-b.G().AppState.NextUpdate(&state)
state = <-b.G().MobileAppState.NextUpdate(&state)
switch state {
case keybase1.AppState_FOREGROUND, keybase1.AppState_BACKGROUNDACTIVE:
case keybase1.MobileAppState_FOREGROUND, keybase1.MobileAppState_BACKGROUNDACTIVE:
b.Debug(ctx, "monitorAppState: active state: %v", state)
// Only resume if we had suspended earlier (frontend can spam us with these)
if suspended {
b.Debug(ctx, "monitorAppState: resuming load thread")
b.Resume(ctx)
suspended = false
}
case keybase1.AppState_BACKGROUND:
case keybase1.MobileAppState_BACKGROUND:
b.Debug(ctx, "monitorAppState: backgrounded, suspending load thread")
if !suspended {
b.Suspend(ctx)
Expand Down
6 changes: 3 additions & 3 deletions go/chat/convloader_test.go
Expand Up @@ -155,7 +155,7 @@ func TestConvLoaderAppState(t *testing.T) {
require.Fail(t, "no remote call")
}
require.True(t, tc.Context().ConvLoader.Suspend(context.TODO()))
tc.G.AppState.Update(keybase1.AppState_FOREGROUND)
tc.G.MobileAppState.Update(keybase1.MobileAppState_FOREGROUND)
select {
case <-appStateCh:
require.Fail(t, "no app state")
Expand Down Expand Up @@ -195,14 +195,14 @@ func TestConvLoaderAppState(t *testing.T) {
case <-time.After(failDuration):
require.Fail(t, "no remote call")
}
tc.G.AppState.Update(keybase1.AppState_BACKGROUND)
tc.G.MobileAppState.Update(keybase1.MobileAppState_BACKGROUND)
select {
case <-appStateCh:
case <-time.After(failDuration):
require.Fail(t, "no app state")
}
tc.ChatG.ConvSource.(*HybridConversationSource).ri = ri
tc.G.AppState.Update(keybase1.AppState_FOREGROUND)
tc.G.MobileAppState.Update(keybase1.MobileAppState_FOREGROUND)
select {
case <-appStateCh:
case <-time.After(failDuration):
Expand Down
4 changes: 4 additions & 0 deletions go/chat/flip/chat_test.go
Expand Up @@ -67,6 +67,10 @@ func (c *chatClient) SendChat(ctx context.Context, conversationID chat1.Conversa
return nil
}

func (c *chatClient) ShouldCommit(ctx context.Context) bool {
return true
}

func (s *chatServer) archive(msg GameMessageWrappedEncoded) {
v := s.gameHistories[GameIDToKey(msg.GameID)]
cl := s.clock
Expand Down
47 changes: 27 additions & 20 deletions go/chat/flip/dealer.go
Expand Up @@ -90,6 +90,7 @@ type Game struct {
// To handle reorderings between CommitmentComplete and commitements,
// wee need some extra bookkeeping.
iWasIncluded bool
iOptedOutOfCommit bool
gotCommitmentComplete bool
latecomers map[UserDeviceKey]bool
}
Expand Down Expand Up @@ -361,7 +362,7 @@ func (g *Game) maybeReveal(ctx context.Context) (err error) {
return nil
}

if !g.iWasIncluded {
if !g.iWasIncluded && !g.iOptedOutOfCommit {
g.clogf(ctx, "The leader didn't include me (%s) so not sending a reveal (%s)", g.me.me, g.md)
return nil
}
Expand Down Expand Up @@ -690,7 +691,7 @@ func (d *Dealer) handleMessageStart(ctx context.Context, msg *GameMessageWrapped

isLeader := true
me := msg.Me
// Make a new follower player controller if one didn't already exit (since we were
// Make a new follower player controller if one didn't already exist (since we were
// the Leader)
if me == nil {
me, err = d.newPlayerControl(d.dh.Me(), md, start)
Expand All @@ -700,25 +701,31 @@ func (d *Dealer) handleMessageStart(ctx context.Context, msg *GameMessageWrapped
isLeader = false
}

optedOutOfCommit := false
if !isLeader {
optedOutOfCommit = !d.dh.ShouldCommit(ctx)
}

msgCh := make(chan *GameMessageWrapped)
game := &Game{
md: msg.GameMetadata(),
isLeader: isLeader,
clockSkew: cs,
start: d.dh.Clock().Now(),
key: key,
params: start,
msgCh: msgCh,
stage: Stage_ROUND1,
stageForTimeout: Stage_ROUND1,
gameUpdateCh: d.gameUpdateCh,
players: make(map[UserDeviceKey]*GamePlayerState),
commitments: make(map[string]bool),
dealer: d,
me: me,
clock: d.dh.Clock,
clogf: d.dh.CLogf,
latecomers: make(map[UserDeviceKey]bool),
md: msg.GameMetadata(),
isLeader: isLeader,
clockSkew: cs,
start: d.dh.Clock().Now(),
key: key,
params: start,
msgCh: msgCh,
stage: Stage_ROUND1,
stageForTimeout: Stage_ROUND1,
gameUpdateCh: d.gameUpdateCh,
players: make(map[UserDeviceKey]*GamePlayerState),
commitments: make(map[string]bool),
dealer: d,
me: me,
clock: d.dh.Clock,
clogf: d.dh.CLogf,
latecomers: make(map[UserDeviceKey]bool),
iOptedOutOfCommit: optedOutOfCommit,
}
d.games[key] = msgCh
d.gameIDs[gameIDKey] = md
Expand All @@ -729,7 +736,7 @@ func (d *Dealer) handleMessageStart(ctx context.Context, msg *GameMessageWrapped
// Once the game has started, we are free to send a message into the channel
// with our commitment. We are now in the inner loop of the Dealer, so we
// have to do this send in a Go-routine, so as not to deadlock the Dealer.
if !isLeader {
if !isLeader && !optedOutOfCommit {
go d.sendCommitment(ctx, md, me)
}
return nil
Expand Down
4 changes: 4 additions & 0 deletions go/chat/flip/dealer_test.go
Expand Up @@ -48,6 +48,10 @@ func (t *testDealersHelper) SendChat(ctx context.Context, conversationID chat1.C
return nil
}

func (t *testDealersHelper) ShouldCommit(ctx context.Context) bool {
return true
}

func randBytes(i int) []byte {
ret := make([]byte, i)
rand.Read(ret[:])
Expand Down
1 change: 1 addition & 0 deletions go/chat/flip/flip.go
Expand Up @@ -72,6 +72,7 @@ type DealersHelper interface {
ServerTime(context.Context) (time.Time, error)
SendChat(ctx context.Context, ch chat1.ConversationID, gameID chat1.FlipGameID, msg GameMessageEncoded) error
Me() UserDevice
ShouldCommit(ctx context.Context) bool // Whether to send new commitments for games.
}

// NewDealer makes a new Dealer with a given DealersHelper
Expand Down

0 comments on commit 91f9b48

Please sign in to comment.