github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/service/tlf.go (about)

     1  // Copyright 2015 Keybase, Inc. All rights reserved. Use of
     2  // this source code is governed by the included BSD license.
     3  
     4  package service
     5  
     6  import (
     7  	"fmt"
     8  
     9  	"golang.org/x/net/context"
    10  
    11  	"github.com/keybase/client/go/chat"
    12  	"github.com/keybase/client/go/chat/globals"
    13  	"github.com/keybase/client/go/chat/utils"
    14  	keybase1 "github.com/keybase/client/go/protocol/keybase1"
    15  	"github.com/keybase/go-framed-msgpack-rpc/rpc"
    16  )
    17  
    18  type tlfHandler struct {
    19  	*BaseHandler
    20  	utils.DebugLabeler
    21  	globals.Contextified
    22  
    23  	tlfInfoSource *chat.KBFSNameInfoSource
    24  }
    25  
    26  func newTlfHandler(xp rpc.Transporter, g *globals.Context) *tlfHandler {
    27  	return &tlfHandler{
    28  		BaseHandler:   NewBaseHandler(g.ExternalG(), xp),
    29  		Contextified:  globals.NewContextified(g),
    30  		DebugLabeler:  utils.NewDebugLabeler(g.ExternalG(), "TlfHandler", false),
    31  		tlfInfoSource: chat.NewKBFSNameInfoSource(g),
    32  	}
    33  }
    34  
    35  func (h *tlfHandler) CryptKeys(ctx context.Context, arg keybase1.TLFQuery) (res keybase1.GetTLFCryptKeysRes, err error) {
    36  	defer h.Trace(ctx, &err,
    37  		fmt.Sprintf("CryptKeys(tlf=%s,mode=%v)", arg.TlfName, arg.IdentifyBehavior))()
    38  	var breaks []keybase1.TLFIdentifyFailure
    39  	ctx = globals.ChatCtx(ctx, h.G(), arg.IdentifyBehavior, &breaks, chat.NewCachingIdentifyNotifier(h.G()))
    40  	return h.tlfInfoSource.CryptKeys(ctx, arg.TlfName)
    41  }
    42  
    43  func (h *tlfHandler) PublicCanonicalTLFNameAndID(ctx context.Context, arg keybase1.TLFQuery) (res keybase1.CanonicalTLFNameAndIDWithBreaks, err error) {
    44  	defer h.Trace(ctx, &err,
    45  		fmt.Sprintf("PublicCanonicalTLFNameAndID(tlf=%s,mode=%v)", arg.TlfName,
    46  			arg.IdentifyBehavior))()
    47  	var breaks []keybase1.TLFIdentifyFailure
    48  	ctx = globals.ChatCtx(ctx, h.G(), arg.IdentifyBehavior, &breaks, chat.NewCachingIdentifyNotifier(h.G()))
    49  	return h.tlfInfoSource.PublicCanonicalTLFNameAndID(ctx, arg.TlfName)
    50  }
    51  
    52  func (h *tlfHandler) CompleteAndCanonicalizePrivateTlfName(ctx context.Context, arg keybase1.TLFQuery) (res keybase1.CanonicalTLFNameAndIDWithBreaks, err error) {
    53  	defer h.Trace(ctx, &err,
    54  		fmt.Sprintf("CompleteAndCanonicalizePrivateTlfName(tlf=%s,mode=%v)", arg.TlfName,
    55  			arg.IdentifyBehavior))()
    56  	var breaks []keybase1.TLFIdentifyFailure
    57  	ctx = globals.ChatCtx(ctx, h.G(), arg.IdentifyBehavior, &breaks, chat.NewCachingIdentifyNotifier(h.G()))
    58  	return h.tlfInfoSource.CompleteAndCanonicalizePrivateTlfName(ctx, arg.TlfName)
    59  }