mirror of
https://github.com/lightninglabs/lightning-terminal.git
synced 2026-08-13 12:33:36 +02:00
terminal: init the autopilot client
This commit is contained in:
parent
4639e7e5ba
commit
683cdbd566
2 changed files with 60 additions and 0 deletions
|
|
@ -17,6 +17,7 @@ import (
|
|||
"github.com/lightninglabs/faraday"
|
||||
"github.com/lightninglabs/faraday/chain"
|
||||
"github.com/lightninglabs/faraday/frdrpcserver"
|
||||
"github.com/lightninglabs/lightning-terminal/autopilotserver"
|
||||
mid "github.com/lightninglabs/lightning-terminal/rpcmiddleware"
|
||||
"github.com/lightninglabs/lndclient"
|
||||
"github.com/lightninglabs/loop/loopd"
|
||||
|
|
@ -185,6 +186,8 @@ type Config struct {
|
|||
|
||||
RPCMiddleware *mid.Config `group:"RPC middleware options" namespace:"rpcmiddleware"`
|
||||
|
||||
Autopilot *autopilotserver.Config `group:"Autopilot server options" namespace:"autopilot"`
|
||||
|
||||
// faradayRpcConfig is a subset of faraday's full configuration that is
|
||||
// passed into faraday's RPC server.
|
||||
faradayRpcConfig *frdrpcserver.Config
|
||||
|
|
@ -325,6 +328,9 @@ func defaultConfig() *Config {
|
|||
Pool: &poolDefaultConfig,
|
||||
RPCMiddleware: mid.DefaultConfig(),
|
||||
FirstLNCConnDeadline: defaultFirstLNCConnTimeout,
|
||||
Autopilot: &autopilotserver.Config{
|
||||
PingCadence: time.Hour,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
54
terminal.go
54
terminal.go
|
|
@ -22,6 +22,7 @@ import (
|
|||
"github.com/lightninglabs/faraday/frdrpc"
|
||||
"github.com/lightninglabs/faraday/frdrpcserver"
|
||||
"github.com/lightninglabs/lightning-terminal/accounts"
|
||||
"github.com/lightninglabs/lightning-terminal/autopilotserver"
|
||||
"github.com/lightninglabs/lightning-terminal/firewall"
|
||||
"github.com/lightninglabs/lightning-terminal/firewalldb"
|
||||
"github.com/lightninglabs/lightning-terminal/litrpc"
|
||||
|
|
@ -64,6 +65,9 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
MainnetServer = "autopilot.lightning.finance:12010"
|
||||
TestnetServer = "test.autopilot.lightning.finance:12010"
|
||||
|
||||
defaultServerTimeout = 10 * time.Second
|
||||
defaultConnectTimeout = 15 * time.Second
|
||||
defaultStartupTimeout = 5 * time.Second
|
||||
|
|
@ -156,6 +160,8 @@ type LightningTerminal struct {
|
|||
faradayServer *frdrpcserver.RPCServer
|
||||
faradayStarted bool
|
||||
|
||||
autopilotClient autopilotserver.Autopilot
|
||||
|
||||
ruleMgrs rules.ManagerSet
|
||||
|
||||
loopServer *loopd.Daemon
|
||||
|
|
@ -261,6 +267,35 @@ func (g *LightningTerminal) Run() error {
|
|||
return fmt.Errorf("error creating session DB: %v", err)
|
||||
}
|
||||
|
||||
if !g.cfg.Autopilot.Disable {
|
||||
if g.cfg.Autopilot.Address == "" &&
|
||||
len(g.cfg.Autopilot.DialOpts) == 0 {
|
||||
|
||||
switch g.cfg.Network {
|
||||
case "mainnet":
|
||||
g.cfg.Autopilot.Address = MainnetServer
|
||||
case "testnet":
|
||||
g.cfg.Autopilot.Address = TestnetServer
|
||||
default:
|
||||
return errors.New("no autopilot server " +
|
||||
"address specified")
|
||||
}
|
||||
}
|
||||
|
||||
g.cfg.Autopilot.LitVersion = autopilotserver.Version{
|
||||
Major: uint32(appMajor),
|
||||
Minor: uint32(appMinor),
|
||||
Patch: uint32(appPatch),
|
||||
}
|
||||
|
||||
g.autopilotClient, err = autopilotserver.NewClient(
|
||||
g.cfg.Autopilot,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
g.sessionRpcServer, err = newSessionRPCServer(&sessionRpcServerConfig{
|
||||
basicAuth: g.rpcProxy.basicAuth,
|
||||
dbDir: filepath.Join(g.cfg.LitDir, g.cfg.Network),
|
||||
|
|
@ -649,6 +684,21 @@ func (g *LightningTerminal) startSubservers() error {
|
|||
}
|
||||
g.macaroonServiceStarted = true
|
||||
|
||||
if !g.cfg.Autopilot.Disable {
|
||||
withLndVersion := func(cfg *autopilotserver.Config) {
|
||||
cfg.LndVersion = autopilotserver.Version{
|
||||
Major: g.lndClient.Version.AppMajor,
|
||||
Minor: g.lndClient.Version.AppMinor,
|
||||
Patch: g.lndClient.Version.AppPatch,
|
||||
}
|
||||
}
|
||||
|
||||
if err = g.autopilotClient.Start(withLndVersion); err != nil {
|
||||
return fmt.Errorf("could not start the autopilot "+
|
||||
"client: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
log.Infof("Starting LiT session server")
|
||||
if err = g.sessionRpcServer.start(); err != nil {
|
||||
return err
|
||||
|
|
@ -970,6 +1020,10 @@ func (g *LightningTerminal) shutdown() error {
|
|||
}
|
||||
}
|
||||
|
||||
if g.autopilotClient != nil {
|
||||
g.autopilotClient.Stop()
|
||||
}
|
||||
|
||||
if g.sessionRpcServerStarted {
|
||||
if err := g.sessionRpcServer.stop(); err != nil {
|
||||
log.Errorf("Error closing session DB: %v", err)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue