func (s *SQLEngine) consumeCreation(tx *sql.Tx, i gregor.Item) error { md := i.Metadata() qb := s.newQueryBuilder() qb.Build("INSERT INTO gregor_items(uid, msgid, category, body, dtime) VALUES(?,?,?,?,", hexEnc(md.UID()), hexEnc(md.MsgID()), i.Category().String(), i.Body().Bytes(), ) qb.TimeOrOffset(i.DTime()) qb.Build(")") err := qb.Exec(tx) if err != nil { return err } for i, t := range i.RemindTimes() { if t == nil { continue } nqb := s.newQueryBuilder() nqb.Build("INSERT INTO gregor_reminders(uid, msgid, seqno, rtime) VALUES(?,?,?,", hexEnc(md.UID()), hexEnc(md.MsgID()), i) nqb.TimeOrOffset(t) nqb.Build(")") err = nqb.Exec(tx) if err != nil { return err } } return nil }
// addItem adds an item for this user func (u *user) addItem(now time.Time, i gregor.Item) *item { msgID := i.Metadata().MsgID().Bytes() for _, it := range u.items { if bytes.Equal(msgID, it.item.Metadata().MsgID().Bytes()) { return it } } newItem := &item{item: i, ctime: nowIfZero(now, i.Metadata().CTime())} u.items = append(u.items, newItem) return newItem }
func (r *RekeyUIHandler) rekeyNeeded(ctx context.Context, item gregor.Item) (err error) { var msgID string if item.Metadata() != nil && item.Metadata().MsgID() != nil { msgID = item.Metadata().MsgID().String() } else { msgID = "-" } defer r.G().Trace(fmt.Sprintf("rekeyNeeded(%s)", msgID), func() error { return err })() if item.Body() == nil { err = errors.New("gregor handler for kbfs_tlf_rekey_needed: nil message body") return err } var problemSet keybase1.ProblemSet if err = json.Unmarshal(item.Body().Bytes(), &problemSet); err != nil { r.G().Log.Debug("recoverable problem unmarshaling gregor body: %s", err) err = nil } if r.G().Clock().Now().Sub(item.Metadata().CTime()) > 10*time.Second { r.G().Log.Debug("msg %s isn't fresh (born on %s)", msgID, item.Metadata().CTime()) // if the message isn't fresh, get: var err error problemSet, err = r.scorer(r.G(), problemSet) r.G().Log.Debug("updated score for %s", msgID) if err != nil { return err } } // if the tlf list is empty, dismiss the gregor notification if len(problemSet.Tlfs) == 0 { r.G().Log.Debug("problem set tlf list empty, dismissing gregor notification") return r.G().GregorDismisser.DismissItem(item.Metadata().MsgID()) } if currentDeviceSolvesProblemSet(r.G(), problemSet) { r.G().Log.Info("Short-circuiting update; our device is on the solution list") return } return r.startUpdater(ctx, problemSet, item.Metadata().MsgID()) }
func (r *RekeyLogHandler) log(category string, item gregor.Item) { md := item.Metadata() r.G().Log.Debug("RekeyLogHandler: %s item message metadata: uid = %s, msg id = %s, ctime = %s, device = %s, inband type = %d", category, md.UID(), md.MsgID(), md.CTime(), md.DeviceID(), md.InBandMsgType()) r.G().Log.Debug("RekeyLogHandler: %s item dtime = %s, remind times = %v", category, r.timeOrOffsetString(item.DTime()), item.RemindTimes()) r.G().Log.Debug("RekeyLogHandler: %s item body: %s", category, item.Body()) }