lncli: add support for unix sockets

This commit is contained in:
Oliver Gugger 2018-05-23 15:41:36 +02:00 committed by Oliver Gugger
parent c1b1dd96ef
commit 9f0e39f881
No known key found for this signature in database
GPG Key ID: 8E4256593F177720

@ -14,6 +14,7 @@ import (
macaroon "gopkg.in/macaroon.v2"
"github.com/lightningnetwork/lnd/lncfg"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/macaroons"
"github.com/roasbeef/btcutil"
@ -26,6 +27,8 @@ import (
const (
defaultTLSCertFilename = "tls.cert"
defaultMacaroonFilename = "admin.macaroon"
defaultRpcPort = "10009"
defaultRpcHostPort = "localhost:" + defaultRpcPort
)
var (
@ -143,6 +146,13 @@ func getClientConn(ctx *cli.Context, skipMacaroons bool) *grpc.ClientConn {
opts = append(opts, grpc.WithPerRPCCredentials(cred))
}
// We need to use a custom dialer so we can also connect to unix sockets
// and not just TCP addresses.
opts = append(
opts, grpc.WithDialer(
lncfg.ClientAddressDialer(defaultRpcPort),
),
)
conn, err := grpc.Dial(ctx.GlobalString("rpcserver"), opts...)
if err != nil {
fatal(err)
@ -159,7 +169,7 @@ func main() {
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "rpcserver",
Value: "localhost:10009",
Value: defaultRpcHostPort,
Usage: "host:port of ln daemon",
},
cli.StringFlag{