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 (
defaultConfigFilename = "lnd.conf"
defaultDataDirname = "data"
defaultLogLevel = "info"
defaultLogDirname = "logs"
defaultLogFilename = "lnd.log"
defaultRPCPort = 10009
defaultSPVMode = false
defaultPeerPort = 10011
defaultRPCHost = "localhost"
defaultRPCUser = "user"
defaultRPCPass = "passwd"
defaultSPVHostAdr = "localhost:18333"
defaultConfigFilename = "lnd.conf"
defaultDataDirname = "data"
defaultLogLevel = "info"
defaultLogDirname = "logs"
defaultLogFilename = "lnd.log"
defaultRPCPort = 10009
defaultSPVMode = false
defaultPeerPort = 10011
defaultRPCHost = "localhost"
defaultRPCUser = "user"
defaultRPCPass = "passwd"
defaultSPVHostAdr = "localhost:18333"
defaultMaxPendingChannels = 1
)
var (
@ -62,13 +63,14 @@ type config struct {
RPCUser string `short:"u" long:"rpcuser" description:"Username 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"`
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."`
TestNet3 bool `long:"testnet" description:"Use the test network"`
SimNet bool `long:"simnet" description:"Use the simulation 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."`
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."`
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"`
SimNet bool `long:"simnet" description:"Use the simulation 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."`
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
@ -81,18 +83,19 @@ type config struct {
// 4) Parse CLI options and overwrite/add any specified options
func loadConfig() (*config, error) {
defaultCfg := config{
ConfigFile: defaultConfigFile,
DataDir: defaultDataDir,
DebugLevel: defaultLogLevel,
LogDir: defaultLogDir,
PeerPort: defaultPeerPort,
RPCPort: defaultRPCPort,
SPVMode: defaultSPVMode,
RPCHost: defaultRPCHost,
RPCUser: defaultRPCUser,
RPCPass: defaultRPCPass,
RPCCert: defaultRPCCertFile,
SPVHostAdr: defaultSPVHostAdr,
ConfigFile: defaultConfigFile,
DataDir: defaultDataDir,
DebugLevel: defaultLogLevel,
LogDir: defaultLogDir,
PeerPort: defaultPeerPort,
RPCPort: defaultRPCPort,
SPVMode: defaultSPVMode,
RPCHost: defaultRPCHost,
RPCUser: defaultRPCUser,
RPCPass: defaultRPCPass,
RPCCert: defaultRPCCertFile,
SPVHostAdr: defaultSPVHostAdr,
MaxPendingChannels: defaultMaxPendingChannels,
}
// 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.
ltndLog.Infof("Version %s", version())
if loadedConfig.SPVMode == true {
shell(loadedConfig.SPVHostAdr, activeNetParams.Params)
if cfg.SPVMode == true {
shell(cfg.SPVHostAdr, activeNetParams.Params)
return err
}
@ -65,7 +65,7 @@ func lndMain() error {
// Open the channeldb, which is dedicated to storing channel, and
// network related meta-data.
chanDB, err := channeldb.Open(loadedConfig.DataDir, activeNetParams.Params)
chanDB, err := channeldb.Open(cfg.DataDir, activeNetParams.Params)
if err != nil {
fmt.Println("unable to open channeldb: ", err)
return err
@ -76,13 +76,13 @@ func lndMain() error {
// specified in the config, then we'll se that directly. Otherwise, we
// attempt to read the cert from the path specified in the config.
var rpcCert []byte
if loadedConfig.RawRPCCert != "" {
rpcCert, err = hex.DecodeString(loadedConfig.RawRPCCert)
if cfg.RawRPCCert != "" {
rpcCert, err = hex.DecodeString(cfg.RawRPCCert)
if err != nil {
return err
}
} else {
certFile, err := os.Open(loadedConfig.RPCCert)
certFile, err := os.Open(cfg.RPCCert)
if err != nil {
return err
}
@ -95,15 +95,15 @@ func lndMain() error {
}
}
rpcIP, err := net.LookupHost(loadedConfig.RPCHost)
rpcIP, err := net.LookupHost(cfg.RPCHost)
if err != nil {
fmt.Printf("unable to resolve rpc host: %v", err)
return err
}
btcdHost := fmt.Sprintf("%v:%v", loadedConfig.RPCHost, activeNetParams.rpcPort)
btcdUser := loadedConfig.RPCUser
btcdPass := loadedConfig.RPCPass
btcdHost := fmt.Sprintf("%v:%v", cfg.RPCHost, activeNetParams.rpcPort)
btcdUser := cfg.RPCUser
btcdPass := cfg.RPCPass
// TODO(roasbeef): parse config here and select chosen notifier instead
rpcConfig := &btcrpcclient.ConnConfig{
@ -121,13 +121,13 @@ func lndMain() error {
return err
}
// TODO(roasbeef): paarse config here select chosen WalletController
// TODO(roasbeef): parse config here select chosen WalletController
walletConfig := &btcwallet.Config{
PrivatePass: []byte("hello"),
DataDir: filepath.Join(loadedConfig.DataDir, "lnwallet"),
DataDir: filepath.Join(cfg.DataDir, "lnwallet"),
RpcHost: fmt.Sprintf("%v:%v", rpcIP[0], activeNetParams.rpcPort),
RpcUser: loadedConfig.RPCUser,
RpcPass: loadedConfig.RPCPass,
RpcUser: cfg.RPCUser,
RpcPass: cfg.RPCPass,
CACert: rpcCert,
NetParams: activeNetParams.Params,
}
@ -156,7 +156,7 @@ func lndMain() error {
// Set up the core server which will listen for incoming peer
// connections.
defaultListenAddrs := []string{
net.JoinHostPort("", strconv.Itoa(loadedConfig.PeerPort)),
net.JoinHostPort("", strconv.Itoa(cfg.PeerPort)),
}
server, err := newServer(defaultListenAddrs, notifier, bio, wallet, chanDB)
if err != nil {

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