github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/service/rekey_log_handler.go (about)

     1  package service
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"golang.org/x/net/context"
     7  
     8  	"github.com/keybase/client/go/gregor"
     9  	"github.com/keybase/client/go/libkb"
    10  	gregor1 "github.com/keybase/client/go/protocol/gregor1"
    11  )
    12  
    13  // RekeyLogHandler is a gregor inband message handler that logs
    14  // all kbfs_tlf_rekey_needed items.
    15  type RekeyLogHandler struct {
    16  	libkb.Contextified
    17  }
    18  
    19  var _ libkb.GregorInBandMessageHandler = (*RekeyLogHandler)(nil)
    20  
    21  func newRekeyLogHandler(g *libkb.GlobalContext) *RekeyLogHandler {
    22  	return &RekeyLogHandler{
    23  		Contextified: libkb.NewContextified(g),
    24  	}
    25  }
    26  
    27  func (r *RekeyLogHandler) Create(ctx context.Context, cli gregor1.IncomingInterface, category string, item gregor.Item) (bool, error) {
    28  	switch category {
    29  	case "kbfs_tlf_rekey_needed":
    30  		r.log(category, item)
    31  		return true, nil
    32  	default:
    33  		return false, nil
    34  	}
    35  }
    36  
    37  func (r *RekeyLogHandler) Dismiss(ctx context.Context, cli gregor1.IncomingInterface, category string, item gregor.Item) (bool, error) {
    38  	return false, nil
    39  }
    40  
    41  func (r *RekeyLogHandler) IsAlive() bool {
    42  	return true
    43  }
    44  
    45  func (r *RekeyLogHandler) Name() string {
    46  	return "RekeyLogHandler"
    47  }
    48  
    49  func (r *RekeyLogHandler) timeOrOffsetString(t gregor.TimeOrOffset) string {
    50  	if t == nil {
    51  		return "[empty]"
    52  	}
    53  	if t.Time() != nil {
    54  		return fmt.Sprintf("time: %s", t.Time())
    55  	}
    56  	if t.Offset() != nil {
    57  		return fmt.Sprintf("offset: %s", t.Offset())
    58  	}
    59  	return "[empty]"
    60  }
    61  
    62  func (r *RekeyLogHandler) log(category string, item gregor.Item) {
    63  	md := item.Metadata()
    64  	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())
    65  	r.G().Log.Debug("RekeyLogHandler: %s item dtime = %s, remind times = %v", category, r.timeOrOffsetString(item.DTime()), item.RemindTimes())
    66  	r.G().Log.Debug("RekeyLogHandler: %s item body: %s", category, item.Body())
    67  }