func (c *Client) syncFromTime(cli gregor1.IncomingInterface, t *time.Time) (msgs []gregor.InBandMessage, err error) { ctx, _ := context.WithTimeout(context.Background(), time.Second) arg := gregor1.SyncArg{ Uid: gregor1.UID(c.user.Bytes()), Deviceid: gregor1.DeviceID(c.device.Bytes()), } if t != nil { arg.Ctime = gregor1.ToTime(*t) } // Grab the events from gregord c.log.Debug("syncFromTime from: %s", gregor1.FromTime(arg.Ctime)) res, err := cli.Sync(ctx, arg) if err != nil { return nil, err } c.log.Debug("syncFromTime consuming %d messages", len(res.Msgs)) for _, ibm := range res.Msgs { m := gregor1.Message{Ibm_: &ibm} msgs = append(msgs, ibm) c.sm.ConsumeMessage(m) } // Check to make sure the server state is legit state, err := c.sm.State(c.user, c.device, nil) if err != nil { return nil, err } hash, err := state.Hash() if err != nil { return nil, err } if !bytes.Equal(res.Hash, hash) { return nil, errHashMismatch{} } return msgs, nil }
func rekeyBroadcast(tc libkb.TestContext, gUID gregor1.UID, h *gregorHandler, body string) { msgID := gregor1.MsgID("my_random_id") m := gregor1.Message{ Ibm_: &gregor1.InBandMessage{ StateUpdate_: &gregor1.StateUpdateMessage{ Md_: gregor1.Metadata{ MsgID_: msgID, Ctime_: gregor1.ToTime(tc.G.Clock().Now()), Uid_: gUID, }, Creation_: &gregor1.Item{ Category_: gregor1.Category("kbfs_tlf_rekey_needed"), Body_: gregor1.Body(body), }, }, }, } if err := h.BroadcastMessage(context.Background(), m); err != nil { tc.T.Fatal(err) } }