From ad76899a574096b6323c074664b430b119a8d604 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Thu, 5 Jan 2017 13:15:58 -0800 Subject: [PATCH] config+test: use default port for RPC server if one isn't specified MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit alters the configuration parsing a bit along with the documentation to expect the RPCHost configuration paramter to also have the target port specified. If the port isn’t included, then the default btcd RPC port for that chain is used. Additionally, within the integration testing framework, when creating the lnd nodes, we now use the configuration from the btcd harness to set the proper RPC host. --- config.go | 2 +- lnd.go | 16 ++++++++++------ networktest.go | 2 +- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/config.go b/config.go index 5b14e77ce..defcfbe98 100644 --- a/config.go +++ b/config.go @@ -63,7 +63,7 @@ type config struct { PeerPort int `long:"peerport" description:"The port to listen on for incoming p2p connections"` RPCPort int `long:"rpcport" description:"The port for the rpc server"` SPVMode bool `long:"spv" description:"assert to enter spv wallet mode"` - RPCHost string `long:"btcdhost" description:"The btcd rpc listening address."` + RPCHost string `long:"btcdhost" description:"The btcd rpc listening address. If a port is omitted, then the default port for the selected chain parameters will be used."` RPCUser string `short:"u" long:"rpcuser" description:"Username for RPC connections"` RPCPass string `short:"P" long:"rpcpass" default-mask:"-" description:"Password for RPC connections"` diff --git a/lnd.go b/lnd.go index d40d73299..bf0643cb0 100644 --- a/lnd.go +++ b/lnd.go @@ -11,6 +11,7 @@ import ( "path/filepath" "runtime" "strconv" + "strings" "golang.org/x/net/context" @@ -90,13 +91,16 @@ func lndMain() error { } } - rpcIP, err := net.LookupHost(cfg.RPCHost) - if err != nil { - fmt.Printf("unable to resolve rpc host: %v", err) - return err + // If the specified host for the btcd RPC server already has a port + // specified, then we use that directly. Otherwise, we assume the + // default port according to the selected chain parameters. + var btcdHost string + if strings.Contains(cfg.RPCHost, ":") { + btcdHost = cfg.RPCHost + } else { + btcdHost = fmt.Sprintf("%v:%v", cfg.RPCHost, activeNetParams.rpcPort) } - btcdHost := fmt.Sprintf("%v:%v", cfg.RPCHost, activeNetParams.rpcPort) btcdUser := cfg.RPCUser btcdPass := cfg.RPCPass @@ -120,7 +124,7 @@ func lndMain() error { walletConfig := &btcwallet.Config{ PrivatePass: []byte("hello"), DataDir: filepath.Join(cfg.DataDir, "lnwallet"), - RpcHost: fmt.Sprintf("%v:%v", rpcIP[0], activeNetParams.rpcPort), + RpcHost: btcdHost, RpcUser: cfg.RPCUser, RpcPass: cfg.RPCPass, CACert: rpcCert, diff --git a/networktest.go b/networktest.go index f346b979b..ea86da650 100644 --- a/networktest.go +++ b/networktest.go @@ -106,7 +106,7 @@ func newLightningNode(rpcConfig *btcrpcclient.ConnConfig, lndArgs []string) (*li var err error cfg := &config{ - RPCHost: "127.0.0.1", + RPCHost: rpcConfig.Host, RPCUser: rpcConfig.User, RPCPass: rpcConfig.Pass, }