config: add --pendingchannel lnd flag

This commit is contained in:
Andrey Samokhvalov 2016-10-15 16:45:51 +03:00
parent e6f45a948e
commit 19d8abade8
3 changed files with 51 additions and 47 deletions

@ -13,18 +13,19 @@ import (
) )
const ( const (
defaultConfigFilename = "lnd.conf" defaultConfigFilename = "lnd.conf"
defaultDataDirname = "data" defaultDataDirname = "data"
defaultLogLevel = "info" defaultLogLevel = "info"
defaultLogDirname = "logs" defaultLogDirname = "logs"
defaultLogFilename = "lnd.log" defaultLogFilename = "lnd.log"
defaultRPCPort = 10009 defaultRPCPort = 10009
defaultSPVMode = false defaultSPVMode = false
defaultPeerPort = 10011 defaultPeerPort = 10011
defaultRPCHost = "localhost" defaultRPCHost = "localhost"
defaultRPCUser = "user" defaultRPCUser = "user"
defaultRPCPass = "passwd" defaultRPCPass = "passwd"
defaultSPVHostAdr = "localhost:18333" defaultSPVHostAdr = "localhost:18333"
defaultMaxPendingChannels = 1
) )
var ( var (
@ -62,13 +63,14 @@ type config struct {
RPCUser string `short:"u" long:"rpcuser" description:"Username for RPC connections"` RPCUser string `short:"u" long:"rpcuser" description:"Username for RPC connections"`
RPCPass string `short:"P" long:"rpcpass" default-mask:"-" description:"Password for RPC connections"` RPCPass string `short:"P" long:"rpcpass" default-mask:"-" description:"Password for RPC connections"`
RPCCert string `long:"rpccert" description:"File containing btcd's certificate file"` RPCCert string `long:"rpccert" description:"File containing btcd's certificate file"`
RawRPCCert string `long:"rawrpccert" description:"The raw bytes of btcd's PEM-encoded certificate chain which will be used to authenticate the RPC connection."` RawRPCCert string `long:"rawrpccert" description:"The raw bytes of btcd's PEM-encoded certificate chain which will be used to authenticate the RPC connection."`
SPVHostAdr string `long:"spvhostadr" description:"Address of full bitcoin node. It is used in SPV mode."` SPVHostAdr string `long:"spvhostadr" description:"Address of full bitcoin node. It is used in SPV mode."`
TestNet3 bool `long:"testnet" description:"Use the test network"` TestNet3 bool `long:"testnet" description:"Use the test network"`
SimNet bool `long:"simnet" description:"Use the simulation test network"` SimNet bool `long:"simnet" description:"Use the simulation test network"`
SegNet bool `long:"segnet" description:"Use the segragated witness test network"` SegNet bool `long:"segnet" description:"Use the segragated witness test network"`
DebugHTLC bool `long:"debughtlc" description:"Activate the debug htlc mode. With the debug HTLC mode, all payments sent use a pre-determined R-Hash. Additionally, all HTLC's sent to a node with the debug HTLC R-Hash are immediately settled in the next available state transition."` DebugHTLC bool `long:"debughtlc" description:"Activate the debug htlc mode. With the debug HTLC mode, all payments sent use a pre-determined R-Hash. Additionally, all HTLC's sent to a node with the debug HTLC R-Hash are immediately settled in the next available state transition."`
MaxPendingChannels int `long:"maxpendingchannels" description:"The maximum number of incoming pending channels permitted per peer."`
} }
// loadConfig initializes and parses the config using a config file and command // loadConfig initializes and parses the config using a config file and command
@ -81,18 +83,19 @@ type config struct {
// 4) Parse CLI options and overwrite/add any specified options // 4) Parse CLI options and overwrite/add any specified options
func loadConfig() (*config, error) { func loadConfig() (*config, error) {
defaultCfg := config{ defaultCfg := config{
ConfigFile: defaultConfigFile, ConfigFile: defaultConfigFile,
DataDir: defaultDataDir, DataDir: defaultDataDir,
DebugLevel: defaultLogLevel, DebugLevel: defaultLogLevel,
LogDir: defaultLogDir, LogDir: defaultLogDir,
PeerPort: defaultPeerPort, PeerPort: defaultPeerPort,
RPCPort: defaultRPCPort, RPCPort: defaultRPCPort,
SPVMode: defaultSPVMode, SPVMode: defaultSPVMode,
RPCHost: defaultRPCHost, RPCHost: defaultRPCHost,
RPCUser: defaultRPCUser, RPCUser: defaultRPCUser,
RPCPass: defaultRPCPass, RPCPass: defaultRPCPass,
RPCCert: defaultRPCCertFile, RPCCert: defaultRPCCertFile,
SPVHostAdr: defaultSPVHostAdr, SPVHostAdr: defaultSPVHostAdr,
MaxPendingChannels: defaultMaxPendingChannels,
} }
// Pre-parse the command line options to pick up an alternative config // Pre-parse the command line options to pick up an alternative config

30
lnd.go

@ -47,8 +47,8 @@ func lndMain() error {
// Show version at startup. // Show version at startup.
ltndLog.Infof("Version %s", version()) ltndLog.Infof("Version %s", version())
if loadedConfig.SPVMode == true { if cfg.SPVMode == true {
shell(loadedConfig.SPVHostAdr, activeNetParams.Params) shell(cfg.SPVHostAdr, activeNetParams.Params)
return err return err
} }
@ -65,7 +65,7 @@ func lndMain() error {
// Open the channeldb, which is dedicated to storing channel, and // Open the channeldb, which is dedicated to storing channel, and
// network related meta-data. // network related meta-data.
chanDB, err := channeldb.Open(loadedConfig.DataDir, activeNetParams.Params) chanDB, err := channeldb.Open(cfg.DataDir, activeNetParams.Params)
if err != nil { if err != nil {
fmt.Println("unable to open channeldb: ", err) fmt.Println("unable to open channeldb: ", err)
return err return err
@ -76,13 +76,13 @@ func lndMain() error {
// specified in the config, then we'll se that directly. Otherwise, we // specified in the config, then we'll se that directly. Otherwise, we
// attempt to read the cert from the path specified in the config. // attempt to read the cert from the path specified in the config.
var rpcCert []byte var rpcCert []byte
if loadedConfig.RawRPCCert != "" { if cfg.RawRPCCert != "" {
rpcCert, err = hex.DecodeString(loadedConfig.RawRPCCert) rpcCert, err = hex.DecodeString(cfg.RawRPCCert)
if err != nil { if err != nil {
return err return err
} }
} else { } else {
certFile, err := os.Open(loadedConfig.RPCCert) certFile, err := os.Open(cfg.RPCCert)
if err != nil { if err != nil {
return err return err
} }
@ -95,15 +95,15 @@ func lndMain() error {
} }
} }
rpcIP, err := net.LookupHost(loadedConfig.RPCHost) rpcIP, err := net.LookupHost(cfg.RPCHost)
if err != nil { if err != nil {
fmt.Printf("unable to resolve rpc host: %v", err) fmt.Printf("unable to resolve rpc host: %v", err)
return err return err
} }
btcdHost := fmt.Sprintf("%v:%v", loadedConfig.RPCHost, activeNetParams.rpcPort) btcdHost := fmt.Sprintf("%v:%v", cfg.RPCHost, activeNetParams.rpcPort)
btcdUser := loadedConfig.RPCUser btcdUser := cfg.RPCUser
btcdPass := loadedConfig.RPCPass btcdPass := cfg.RPCPass
// TODO(roasbeef): parse config here and select chosen notifier instead // TODO(roasbeef): parse config here and select chosen notifier instead
rpcConfig := &btcrpcclient.ConnConfig{ rpcConfig := &btcrpcclient.ConnConfig{
@ -121,13 +121,13 @@ func lndMain() error {
return err return err
} }
// TODO(roasbeef): paarse config here select chosen WalletController // TODO(roasbeef): parse config here select chosen WalletController
walletConfig := &btcwallet.Config{ walletConfig := &btcwallet.Config{
PrivatePass: []byte("hello"), PrivatePass: []byte("hello"),
DataDir: filepath.Join(loadedConfig.DataDir, "lnwallet"), DataDir: filepath.Join(cfg.DataDir, "lnwallet"),
RpcHost: fmt.Sprintf("%v:%v", rpcIP[0], activeNetParams.rpcPort), RpcHost: fmt.Sprintf("%v:%v", rpcIP[0], activeNetParams.rpcPort),
RpcUser: loadedConfig.RPCUser, RpcUser: cfg.RPCUser,
RpcPass: loadedConfig.RPCPass, RpcPass: cfg.RPCPass,
CACert: rpcCert, CACert: rpcCert,
NetParams: activeNetParams.Params, NetParams: activeNetParams.Params,
} }
@ -156,7 +156,7 @@ func lndMain() error {
// Set up the core server which will listen for incoming peer // Set up the core server which will listen for incoming peer
// connections. // connections.
defaultListenAddrs := []string{ defaultListenAddrs := []string{
net.JoinHostPort("", strconv.Itoa(loadedConfig.PeerPort)), net.JoinHostPort("", strconv.Itoa(cfg.PeerPort)),
} }
server, err := newServer(defaultListenAddrs, notifier, bio, wallet, chanDB) server, err := newServer(defaultListenAddrs, notifier, bio, wallet, chanDB)
if err != nil { if err != nil {

@ -1,6 +1,7 @@
package lnwallet package lnwallet
// Config.. // Config is a struct which houses configuration parameters which modify the
// behaviour of LightningWallet.
type Config struct { type Config struct {
// default csv time // default csv time
// default cltv time // default cltv time