config: add sub-server config parsing logic for the new Router service

This commit is contained in:
Olaoluwa Osuntokun 2018-10-22 21:46:18 -07:00
parent cfd6a0d860
commit 88252d759b
No known key found for this signature in database
GPG Key ID: CE58F7F8E20FD9A2
2 changed files with 27 additions and 2 deletions

@ -416,7 +416,7 @@ func newRPCServer(s *server, macService *macaroons.Service,
// server configuration struct. // server configuration struct.
err := subServerCgs.PopulateDependencies( err := subServerCgs.PopulateDependencies(
s.cc, networkDir, macService, atpl, invoiceRegistry, s.cc, networkDir, macService, atpl, invoiceRegistry,
activeNetParams.Params, activeNetParams.Params, s.chanRouter,
) )
if err != nil { if err != nil {
return nil, err return nil, err

@ -10,9 +10,11 @@ import (
"github.com/lightningnetwork/lnd/lnrpc/autopilotrpc" "github.com/lightningnetwork/lnd/lnrpc/autopilotrpc"
"github.com/lightningnetwork/lnd/lnrpc/chainrpc" "github.com/lightningnetwork/lnd/lnrpc/chainrpc"
"github.com/lightningnetwork/lnd/lnrpc/invoicesrpc" "github.com/lightningnetwork/lnd/lnrpc/invoicesrpc"
"github.com/lightningnetwork/lnd/lnrpc/routerrpc"
"github.com/lightningnetwork/lnd/lnrpc/signrpc" "github.com/lightningnetwork/lnd/lnrpc/signrpc"
"github.com/lightningnetwork/lnd/lnrpc/walletrpc" "github.com/lightningnetwork/lnd/lnrpc/walletrpc"
"github.com/lightningnetwork/lnd/macaroons" "github.com/lightningnetwork/lnd/macaroons"
"github.com/lightningnetwork/lnd/routing"
) )
// subRPCServerConfigs is special sub-config in the main configuration that // subRPCServerConfigs is special sub-config in the main configuration that
@ -44,6 +46,12 @@ type subRPCServerConfigs struct {
// InvoicesRPC is a sub-RPC server that exposes invoice related methods // InvoicesRPC is a sub-RPC server that exposes invoice related methods
// as a gRPC service. // as a gRPC service.
InvoicesRPC *invoicesrpc.Config `group:"invoicesrpc" namespace:"invoicesrpc"` InvoicesRPC *invoicesrpc.Config `group:"invoicesrpc" namespace:"invoicesrpc"`
// RouterRPC is a sub-RPC server the exposes functionality that allows
// clients to send payments on the network, and perform Lightning
// payment related queries such as requests for estimates of off-chain
// fees.
RouterRPC *routerrpc.Config `group:"routerrpc" namespace:"routerrpc"`
} }
// PopulateDependencies attempts to iterate through all the sub-server configs // PopulateDependencies attempts to iterate through all the sub-server configs
@ -56,7 +64,8 @@ func (s *subRPCServerConfigs) PopulateDependencies(cc *chainControl,
networkDir string, macService *macaroons.Service, networkDir string, macService *macaroons.Service,
atpl *autopilot.Manager, atpl *autopilot.Manager,
invoiceRegistry *invoices.InvoiceRegistry, invoiceRegistry *invoices.InvoiceRegistry,
activeNetParams *chaincfg.Params) error { activeNetParams *chaincfg.Params,
chanRouter *routing.ChannelRouter) error {
// First, we'll use reflect to obtain a version of the config struct // First, we'll use reflect to obtain a version of the config struct
// that allows us to programmatically inspect its fields. // that allows us to programmatically inspect its fields.
@ -150,6 +159,22 @@ func (s *subRPCServerConfigs) PopulateDependencies(cc *chainControl,
reflect.ValueOf(activeNetParams), reflect.ValueOf(activeNetParams),
) )
case *routerrpc.Config:
subCfgValue := extractReflectValue(cfg)
subCfgValue.FieldByName("NetworkDir").Set(
reflect.ValueOf(networkDir),
)
subCfgValue.FieldByName("ActiveNetParams").Set(
reflect.ValueOf(activeNetParams),
)
subCfgValue.FieldByName("MacService").Set(
reflect.ValueOf(macService),
)
subCfgValue.FieldByName("Router").Set(
reflect.ValueOf(chanRouter),
)
default: default:
return fmt.Errorf("unknown field: %v, %T", fieldName, return fmt.Errorf("unknown field: %v, %T", fieldName,
cfg) cfg)