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

     1  package chat
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/keybase/client/go/chat/globals"
     7  	"github.com/keybase/client/go/chat/types"
     8  	"github.com/keybase/client/go/chat/utils"
     9  	"github.com/keybase/go-framed-msgpack-rpc/rpc"
    10  	"golang.org/x/net/context"
    11  )
    12  
    13  type RemoteClient struct {
    14  	utils.DebugLabeler
    15  
    16  	cli rpc.GenericClient
    17  }
    18  
    19  func NewRemoteClient(g *globals.Context, cli rpc.GenericClient) *RemoteClient {
    20  	return &RemoteClient{
    21  		DebugLabeler: utils.NewDebugLabeler(g.ExternalG(), "RemoteClient", false),
    22  		cli:          cli,
    23  	}
    24  }
    25  
    26  func (c *RemoteClient) Call(ctx context.Context, method string, arg interface{},
    27  	res interface{}, timeout time.Duration) (err error) {
    28  	defer c.Trace(ctx, &err, method)()
    29  	err = c.cli.Call(ctx, method, arg, res, timeout)
    30  	if err == nil {
    31  		if rlRes, ok := res.(types.RateLimitedResult); ok {
    32  			globals.CtxAddRateLimit(ctx, rlRes.GetRateLimit())
    33  		}
    34  	}
    35  	return err
    36  }
    37  
    38  func (c *RemoteClient) CallCompressed(ctx context.Context, method string, arg interface{},
    39  	res interface{}, ctype rpc.CompressionType, timeout time.Duration) (err error) {
    40  	defer c.Trace(ctx, &err, method)()
    41  	err = c.cli.CallCompressed(ctx, method, arg, res, ctype, timeout)
    42  	if err == nil {
    43  		if rlRes, ok := res.(types.RateLimitedResult); ok {
    44  			globals.CtxAddRateLimit(ctx, rlRes.GetRateLimit())
    45  		}
    46  	}
    47  	return err
    48  }
    49  
    50  func (c *RemoteClient) Notify(ctx context.Context, method string, arg interface{}, timeout time.Duration) (err error) {
    51  	defer c.Trace(ctx, &err, method)()
    52  	return c.cli.Notify(ctx, method, arg, timeout)
    53  }