config+test: use default port for RPC server if one isn't specified

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.
This commit is contained in:
Olaoluwa Osuntokun
2017-01-05 13:15:58 -08:00
parent 8fe5c09e21
commit ad76899a57
3 changed files with 12 additions and 8 deletions

16
lnd.go
View File

@@ -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,