Skip to content

Commit 7635079

Browse files
committed
config: extract LND dial address helper
so that we can use it elsewhere.
1 parent 313262d commit 7635079

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

config.go

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -235,21 +235,32 @@ type Config struct {
235235
func (c *Config) lndConnectParams() (string, lndclient.Network, string,
236236
string, []byte) {
237237

238+
lndDialAddr := c.lndDialAddr()
239+
238240
// In remote lnd mode, we just pass along what was configured in the
239241
// remote section of the lnd config.
240-
if c.LndMode == ModeRemote {
241-
return c.Remote.Lnd.RPCServer,
242+
if c.lndRemote {
243+
return lndDialAddr,
242244
lndclient.Network(c.Network),
243245
lncfg.CleanAndExpandPath(c.Remote.Lnd.TLSCertPath),
244246
lncfg.CleanAndExpandPath(c.Remote.Lnd.MacaroonPath),
245247
nil
246248
}
247249

248-
// When we start lnd internally, we take the listen address as
249-
// the client dial address. But with TLS enabled by default, we
250-
// cannot call 0.0.0.0 internally when dialing lnd as that IP
251-
// address isn't in the cert. We need to rewrite it to the
252-
// loopback address.
250+
return lndDialAddr, lndclient.Network(c.Network), "", "",
251+
c.lndAdminMacaroon
252+
}
253+
254+
// lndDialAddr returns the address to connect to LND on.
255+
func (c *Config) lndDialAddr() string {
256+
if c.lndRemote {
257+
return c.Remote.Lnd.RPCServer
258+
}
259+
260+
// When we start lnd internally, we take the listen address as the
261+
// client dial address. But with TLS enabled by default, we cannot call
262+
// 0.0.0.0 internally when dialing lnd as that IP address isn't in the
263+
// cert. We need to rewrite it to the loopback address.
253264
lndDialAddr := c.Lnd.RPCListeners[0].String()
254265
switch {
255266
case strings.Contains(lndDialAddr, "0.0.0.0"):
@@ -258,13 +269,10 @@ func (c *Config) lndConnectParams() (string, lndclient.Network, string,
258269
)
259270

260271
case strings.Contains(lndDialAddr, "[::]"):
261-
lndDialAddr = strings.Replace(
262-
lndDialAddr, "[::]", "[::1]", 1,
263-
)
272+
lndDialAddr = strings.Replace(lndDialAddr, "[::]", "[::1]", 1)
264273
}
265274

266-
return lndDialAddr, lndclient.Network(c.Network), "", "",
267-
c.lndAdminMacaroon
275+
return lndDialAddr
268276
}
269277

270278
// defaultConfig returns a configuration struct with all default values set.

0 commit comments

Comments
 (0)