Skip to content

Commit 8dde304

Browse files
committed
config: support config for LNC connections
1 parent 57ddbf7 commit 8dde304

File tree

2 files changed

+72
-5
lines changed

2 files changed

+72
-5
lines changed

config.go

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,28 @@ type EtcdConfig struct {
3737
}
3838

3939
type AuthConfig struct {
40+
Network string `long:"network" description:"The network LND is connected to." choice:"regtest" choice:"simnet" choice:"testnet" choice:"mainnet"`
41+
42+
Disable bool `long:"disable" description:"Whether to disable auth."`
43+
4044
// LndHost is the hostname of the LND instance to connect to.
4145
LndHost string `long:"lndhost" description:"Hostname of the LND instance to connect to"`
4246

4347
TLSPath string `long:"tlspath" description:"Path to LND instance's tls certificate"`
4448

4549
MacDir string `long:"macdir" description:"Directory containing LND instance's macaroons"`
4650

47-
Network string `long:"network" description:"The network LND is connected to." choice:"regtest" choice:"simnet" choice:"testnet" choice:"mainnet"`
51+
// The one-time-use passphrase used to set up the connection. This field
52+
// identifies the connection that will be used.
53+
Passphrase string `long:"passphrase" description:"the lnc passphrase"`
54+
55+
// MailboxAddress is the address of the mailbox that the client will
56+
// use for the LNC connection.
57+
MailboxAddress string `long:"mailboxaddress" description:"the host:port of the mailbox server to be used"`
4858

49-
Disable bool `long:"disable" description:"Whether to disable LND auth."`
59+
// DevServer set to true to skip verification of the mailbox server's
60+
// tls cert.
61+
DevServer bool `long:"devserver" description:"set to true to skip verification of the server's tls cert."`
5062
}
5163

5264
func (a *AuthConfig) validate() error {
@@ -55,6 +67,30 @@ func (a *AuthConfig) validate() error {
5567
return nil
5668
}
5769

70+
switch {
71+
// If LndHost is set we connect directly to the LND node.
72+
case a.LndHost != "":
73+
log.Info("Validating lnd configuration")
74+
75+
if a.Passphrase != "" {
76+
return errors.New("passphrase field cannot be set " +
77+
"when connecting directly to the lnd node")
78+
}
79+
80+
return a.validateLNDAuth()
81+
82+
// If Passphrase is set we connect to the LND node through LNC.
83+
case a.Passphrase != "":
84+
log.Info("Validating lnc configuration")
85+
return a.validateLNCAuth()
86+
87+
default:
88+
return errors.New("invalid authenticator configuration")
89+
}
90+
}
91+
92+
// validateLNDAuth validates the direct LND auth configuration.
93+
func (a *AuthConfig) validateLNDAuth() error {
5894
if a.LndHost == "" {
5995
return errors.New("lnd host required")
6096
}
@@ -70,6 +106,22 @@ func (a *AuthConfig) validate() error {
70106
return nil
71107
}
72108

109+
// validateLNCAuth validates the LNC auth configuration.
110+
func (a *AuthConfig) validateLNCAuth() error {
111+
switch {
112+
case a.Passphrase == "":
113+
return errors.New("lnc passphrase required")
114+
115+
case a.MailboxAddress == "":
116+
return errors.New("lnc mailbox address required")
117+
118+
case a.Network == "":
119+
return errors.New("lnc network required")
120+
}
121+
122+
return nil
123+
}
124+
73125
type HashMailConfig struct {
74126
Enabled bool `long:"enabled"`
75127
MessageRate time.Duration `long:"messagerate" description:"The average minimum time that should pass between each message."`
@@ -120,6 +172,8 @@ type Config struct {
120172
// Etcd is the configuration section for the Etcd database backend.
121173
Etcd *EtcdConfig `group:"etcd" namespace:"etcd"`
122174

175+
// Authenticator is the configuration section for connecting directly
176+
// to the LND node.
123177
Authenticator *AuthConfig `group:"authenticator" namespace:"authenticator"`
124178

125179
Tor *TorConfig `group:"tor" namespace:"tor"`
@@ -151,8 +205,10 @@ type Config struct {
151205
}
152206

153207
func (c *Config) validate() error {
154-
if err := c.Authenticator.validate(); err != nil {
155-
return err
208+
if !c.Authenticator.Disable {
209+
if err := c.Authenticator.validate(); err != nil {
210+
return err
211+
}
156212
}
157213

158214
if c.ListenAddr == "" {

sample-conf.yaml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ authenticator:
3737

3838
# The chain network the lnd is active on.
3939
network: "simnet"
40+
41+
# The LNC connection passphrase.
42+
passphrase: "my-own-passphrase"
43+
44+
# The host:port of the mailbox server to be used.
45+
mailboxaddress: "mailbox.terminal.lightning.today:443"
46+
47+
# Set to true to skip verification of the mailbox server's tls cert.
48+
devserver: false
49+
50+
# Set to true to disable any auth.
51+
disable: false
4052

4153
# The selected database backend. The current default backend is "sqlite".
4254
# Aperture also has support for postgres and etcd.
@@ -65,7 +77,6 @@ postgres:
6577
# server.
6678
requireSSL: true
6779

68-
6980
# Settings for the etcd instance which the proxy will use to reliably store and
7081
# retrieve token information.
7182
etcd:

0 commit comments

Comments
 (0)