lnd: make the http profiling server optional w/ a config param
This commit is contained in:
parent
c5f97a17d5
commit
cad0d54e43
28
config.go
28
config.go
@ -5,11 +5,12 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
flags "github.com/btcsuite/go-flags"
|
||||||
"github.com/roasbeef/btcd/chaincfg"
|
"github.com/roasbeef/btcd/chaincfg"
|
||||||
"github.com/roasbeef/btcutil"
|
"github.com/roasbeef/btcutil"
|
||||||
flags "github.com/btcsuite/go-flags"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -17,7 +18,7 @@ const (
|
|||||||
defaultDataDirname = "data"
|
defaultDataDirname = "data"
|
||||||
defaultLogLevel = "info"
|
defaultLogLevel = "info"
|
||||||
defaultLogDirname = "logs"
|
defaultLogDirname = "logs"
|
||||||
defaultLogFilename = "btcd.log"
|
defaultLogFilename = "lnd.log"
|
||||||
defaultRPCPort = 10009
|
defaultRPCPort = 10009
|
||||||
defaultSPVMode = false
|
defaultSPVMode = false
|
||||||
defaultPeerPort = 10011
|
defaultPeerPort = 10011
|
||||||
@ -42,7 +43,7 @@ var (
|
|||||||
defaultRPCCertFile = filepath.Join(btcdHomeDir, "rpc.cert")
|
defaultRPCCertFile = filepath.Join(btcdHomeDir, "rpc.cert")
|
||||||
)
|
)
|
||||||
|
|
||||||
// config defines the configuratino options for lnd.
|
// config defines the configuration options for lnd.
|
||||||
//
|
//
|
||||||
// See loadConfig for further details regarding the configuration
|
// See loadConfig for further details regarding the configuration
|
||||||
// loading+parsing process.
|
// loading+parsing process.
|
||||||
@ -53,11 +54,13 @@ type config struct {
|
|||||||
DataDir string `short:"b" long:"datadir" description:"The directory to store lnd's data within"`
|
DataDir string `short:"b" long:"datadir" description:"The directory to store lnd's data within"`
|
||||||
LogDir string `long:"logdir" description:"Directory to log output."`
|
LogDir string `long:"logdir" description:"Directory to log output."`
|
||||||
|
|
||||||
Listeners []string `long:"listen" description:"Add an interface/port to listen for connections (default all interfaces port: 8333, testnet: 18333)"`
|
Listeners []string `long:"listen" description:"Add an interface/port to listen for connections (default all interfaces port: 10011)"`
|
||||||
ExternalIPs []string `long:"externalip" description:"Add an ip to the list of local addresses we claim to listen on to peers"`
|
ExternalIPs []string `long:"externalip" description:"Add an ip to the list of local addresses we claim to listen on to peers"`
|
||||||
|
|
||||||
DebugLevel string `short:"d" long:"debuglevel" description:"Logging level for all subsystems {trace, debug, info, warn, error, critical} -- You may also specify <subsystem>=<level>,<subsystem2>=<level>,... to set the log level for individual subsystems -- Use show to list available subsystems"`
|
DebugLevel string `short:"d" long:"debuglevel" description:"Logging level for all subsystems {trace, debug, info, warn, error, critical} -- You may also specify <subsystem>=<level>,<subsystem2>=<level>,... to set the log level for individual subsystems -- Use show to list available subsystems"`
|
||||||
|
|
||||||
|
Profile string `long:"profile" description:"Enable HTTP profiling on given port -- NOTE port must be between 1024 and 65536"`
|
||||||
|
|
||||||
PeerPort int `long:"peerport" description:"The port to listen on for incoming p2p connections"`
|
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"`
|
RPCPort int `long:"rpcport" description:"The port for the rpc server"`
|
||||||
SPVMode bool `long:"spv" description:"assert to enter spv wallet mode"`
|
SPVMode bool `long:"spv" description:"assert to enter spv wallet mode"`
|
||||||
@ -168,8 +171,20 @@ func loadConfig() (*config, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Validate profile port number
|
||||||
|
if cfg.Profile != "" {
|
||||||
|
profilePort, err := strconv.Atoi(cfg.Profile)
|
||||||
|
if err != nil || profilePort < 1024 || profilePort > 65535 {
|
||||||
|
str := "%s: The profile port must be between 1024 and 65535"
|
||||||
|
err := fmt.Errorf(str, funcName)
|
||||||
|
fmt.Fprintln(os.Stderr, err)
|
||||||
|
fmt.Fprintln(os.Stderr, usageMessage)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Append the network type to the data directory so it is "namespaced"
|
// Append the network type to the data directory so it is "namespaced"
|
||||||
// per network. In addition to the block database, there are other
|
// per network. In addition to the block database, there are other
|
||||||
// pieces of data that are saved to disk such as address manager state.
|
// pieces of data that are saved to disk such as address manager state.
|
||||||
// All data is specific to a network, so namespacing the data directory
|
// All data is specific to a network, so namespacing the data directory
|
||||||
// means each individual piece of serialized data does not have to
|
// means each individual piece of serialized data does not have to
|
||||||
@ -194,7 +209,6 @@ func loadConfig() (*config, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(roasbeef): logging
|
|
||||||
return &cfg, nil
|
return &cfg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,7 +227,7 @@ func cleanAndExpandPath(path string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// parseAndSetDebugLevels attempts to parse the specified debug level and set
|
// parseAndSetDebugLevels attempts to parse the specified debug level and set
|
||||||
// the levels accordingly. An appropriate error is returned if anything is
|
// the levels accordingly. An appropriate error is returned if anything is
|
||||||
// invalid.
|
// invalid.
|
||||||
func parseAndSetDebugLevels(debugLevel string) error {
|
func parseAndSetDebugLevels(debugLevel string) error {
|
||||||
// When the specified string doesn't have any delimters, treat it as
|
// When the specified string doesn't have any delimters, treat it as
|
||||||
|
17
lnd.go
17
lnd.go
@ -46,13 +46,16 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
// Enable http profiling server if requested.
|
||||||
listenAddr := net.JoinHostPort("", "5009")
|
if cfg.Profile != "" {
|
||||||
profileRedirect := http.RedirectHandler("/debug/pprof",
|
go func() {
|
||||||
http.StatusSeeOther)
|
listenAddr := net.JoinHostPort("", cfg.Profile)
|
||||||
http.Handle("/", profileRedirect)
|
profileRedirect := http.RedirectHandler("/debug/pprof",
|
||||||
fmt.Println(http.ListenAndServe(listenAddr, nil))
|
http.StatusSeeOther)
|
||||||
}()
|
http.Handle("/", profileRedirect)
|
||||||
|
fmt.Println(http.ListenAndServe(listenAddr, nil))
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
// 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.
|
||||||
|
Loading…
Reference in New Issue
Block a user