Merge pull request #6422 from hieblmi/lncli-socks-proxy

#4939 Add socks proxy support to lncli
This commit is contained in:
Oliver Gugger 2022-04-20 18:58:09 +02:00 committed by GitHub
commit 3d7d9361f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 4 deletions

View File

@ -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.
// 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,

View File

@ -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)
@ -293,6 +296,7 @@ gRPC performance metrics (latency to process `GetInfo`, etc)](https://github.com
* Eugene Siegel
* Hampus Sjöberg
* henta
* hieblmi
* Joost Jager
* Jordi Montes
* LightningHelper