From b1f6bc977e46aaa3db9a84d7d350db659507c686 Mon Sep 17 00:00:00 2001 From: hieblmi Date: Sat, 16 Apr 2022 20:30:42 +0200 Subject: [PATCH] #4939 Add socks proxy support to lncli --- cmd/lncli/main.go | 31 +++++++++++++++++++--- docs/release-notes/release-notes-0.15.0.md | 4 +++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/cmd/lncli/main.go b/cmd/lncli/main.go index 5db1df4bc..00b5094c0 100644 --- a/cmd/lncli/main.go +++ b/cmd/lncli/main.go @@ -5,8 +5,10 @@ package main import ( + "context" "crypto/tls" "fmt" + "net" "os" "path/filepath" "strings" @@ -17,6 +19,7 @@ import ( "github.com/lightningnetwork/lnd/lncfg" "github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/macaroons" + "github.com/lightningnetwork/lnd/tor" "github.com/urfave/cli" "golang.org/x/term" "google.golang.org/grpc" @@ -173,10 +176,24 @@ 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. - genericDialer := lncfg.ClientAddressDialer(defaultRPCPort) - opts = append(opts, grpc.WithContextDialer(genericDialer)) + // If a socksproxy server is specified we use a tor dialer + // to connect to the grpc server. + if ctx.GlobalIsSet("socksproxy") { + socksProxy := ctx.GlobalString("socksproxy") + torDialer := func(_ context.Context, addr string) (net.Conn, error) { + return tor.Dial( + addr, socksProxy, false, false, + tor.DefaultConnTimeout, + ) + } + opts = append(opts, grpc.WithContextDialer(torDialer)) + } else { + // We need to use a custom dialer so we can also connect to + // unix sockets and not just TCP addresses. + genericDialer := lncfg.ClientAddressDialer(defaultRPCPort) + opts = append(opts, grpc.WithContextDialer(genericDialer)) + } + opts = append(opts, grpc.WithDefaultCallOptions(maxMsgRecvSize)) conn, err := grpc.Dial(profile.RPCServer, opts...) @@ -276,6 +293,12 @@ func main() { Usage: "The path to lnd's base directory.", TakesFile: true, }, + cli.StringFlag{ + Name: "socksproxy", + Usage: "The host:port of a SOCKS proxy through " + + "which all connections to the LN " + + "daemon will be established over.", + }, cli.StringFlag{ Name: "tlscertpath", Value: defaultTLSCertPath, diff --git a/docs/release-notes/release-notes-0.15.0.md b/docs/release-notes/release-notes-0.15.0.md index b118d975b..95a25a97f 100644 --- a/docs/release-notes/release-notes-0.15.0.md +++ b/docs/release-notes/release-notes-0.15.0.md @@ -41,6 +41,9 @@ then watch it on chain. Taproot script spends are also supported through the * Add [update node announcement](https://github.com/lightningnetwork/lnd/pull/5587) for updating and propagating node information. +* Add [--socksproxy](https://github.com/lightningnetwork/lnd/pull/6422) + to allow for RPC calls via Tor. + ## Bug Fixes * [Pipelining an UpdateFulfillHTLC message now only happens when the related UpdateAddHTLC is locked-in.](https://github.com/lightningnetwork/lnd/pull/6246) @@ -281,6 +284,7 @@ gRPC performance metrics (latency to process `GetInfo`, etc)](https://github.com * Eugene Siegel * Hampus Sjöberg * henta +* hieblmi * Joost Jager * Jordi Montes * LightningHelper