frdrpcserver

package
v0.2.13-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 21, 2024 License: MIT Imports: 37 Imported by: 2

Documentation

Overview

Package frdrpcserver contains the server logic for faraday's grpc server which serves requests for close recommendations.

The Faraday server interface is implemented by the RPCServer struct. To keep this file readable, each function implemented by the interface has a file named after the function call which contains rpc parsing code for the request and response. If the call requires extensive additional logic, and unexported function with the same name should be created in this file as well.

Index

Constants

View Source
const Subsystem = "FRPC"

Subsystem defines the logging code for this subsystem.

Variables

View Source
var (
	// ErrNoCategoryName is returned if a category does not have a name.
	ErrNoCategoryName = errors.New("category must have a name")

	// ErrSetChain is returned when on on/off chain boolean is set for
	// a category
	ErrSetChain = errors.New("category must be for on chain, off chain " +
		"or both")
)
View Source
var (

	// ErrBitcoinNodeRequired is required when an endpoint which requires
	// a bitcoin node backend is hit and we are not connected to one.
	ErrBitcoinNodeRequired = errors.New("bitcoin node required")
)

Functions

func UseLogger

func UseLogger(logger btclog.Logger)

UseLogger uses a specified Logger to output package logging info. This should be used in preference to SetLogWriter if the caller is also using btclog.

Types

type Config

type Config struct {
	// Lnd is a client which can be used to query lnd.
	Lnd lndclient.LndServices

	// RPCListen is the address:port that the gRPC server should listen on.
	RPCListen string

	// RESTListen is the address:port that the REST server should listen on.
	RESTListen string

	// CORSOrigin specifies the CORS header that should be set on REST
	// responses. No header is added if the value is empty.
	CORSOrigin string

	// BitcoinClient is set if the client opted to connect to a bitcoin
	// backend, if not, it will be nil.
	BitcoinClient chain.BitcoinClient

	// TLSServerConfig is the configuration to serve a secure connection
	// over TLS.
	TLSServerConfig *tls.Config

	// RestClientConfig is the client configuration to connect to a TLS
	// server started with the TLS config above. This is used for the REST
	// proxy that connects internally to the gRPC server and therefore is a
	// TLS client.
	RestClientConfig *credentials.TransportCredentials

	// FaradayDir is the main directory faraday uses. The macaroon database
	// will be created there.
	FaradayDir string

	// MacaroonPath is the full path to the default faraday macaroon file
	// that is created automatically. This path normally is within
	// FaradayDir unless otherwise specified by the user.
	MacaroonPath string
}

Config provides closures and settings required to run the rpc server.

type RPCServer

type RPCServer struct {

	// Required by the grpc-gateway/v2 library for forward compatibility.
	// Must be after the atomically used variables to not break struct
	// alignment.
	frdrpc.UnimplementedFaradayServerServer
	// contains filtered or unexported fields
}

RPCServer implements the faraday service, serving requests over grpc.

func NewRPCServer

func NewRPCServer(cfg *Config) *RPCServer

NewRPCServer returns a server which will listen for rpc requests on the rpc listen address provided. Note that the server returned is not running, and should be started using Start().

func (*RPCServer) ChannelInsights

ChannelInsights returns the channel insights for our currently open set of channels.

func (*RPCServer) CloseReport

CloseReport returns a close report for the channel provided. Note that this endpoint requires connection to an external bitcoind node.

func (*RPCServer) ExchangeRate

ExchangeRate provides a fiat estimate for a set of timestamped bitcoin prices.

func (*RPCServer) NodeAudit

NodeAudit returns an on chain report for the period requested.

func (*RPCServer) OutlierRecommendations

OutlierRecommendations provides a set of close recommendations for the current set of open channels based on whether they are outliers.

func (*RPCServer) RevenueReport

RevenueReport returns a pairwise revenue report for a channel over the period requested.

func (*RPCServer) Start

func (s *RPCServer) Start() error

Start starts the listener and server.

func (*RPCServer) StartAsSubserver

func (s *RPCServer) StartAsSubserver(lndClient lndclient.LndServices,
	withMacaroonService bool) error

StartAsSubserver is an alternative to Start where the RPC server does not create its own gRPC server but registers to an existing one. The same goes for REST (if enabled), instead of creating an own mux and HTTP server, we register to an existing one.

func (*RPCServer) Stop

func (s *RPCServer) Stop() error

Stop stops the grpc listener and server.

func (*RPCServer) ThresholdRecommendations

ThresholdRecommendations provides a set of close recommendations for the current set of open channels based on whether they are above or below a given threshold.

func (*RPCServer) ValidateMacaroon

func (s *RPCServer) ValidateMacaroon(ctx context.Context,
	requiredPermissions []bakery.Op, fullMethod string) error

ValidateMacaroon extracts the macaroon from the context's gRPC metadata, checks its signature, makes sure all specified permissions for the called method are contained within and finally ensures all caveat conditions are met. A non-nil error is returned if any of the checks fail. This method is needed to enable faraday running as an external subserver in the same process as lnd but still validate its own macaroons.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL