mirror of
https://github.com/bumi/lntip
synced 2026-02-15 21:47:49 +00:00
Add support to connect to TOR nodes
This requires tor to be installed/running on the system
This commit is contained in:
18
ln/lnd.go
18
ln/lnd.go
@@ -7,12 +7,15 @@ import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/lightningnetwork/lnd/lnrpc"
|
||||
"github.com/lightningnetwork/lnd/macaroons"
|
||||
"gopkg.in/macaroon.v2"
|
||||
|
||||
"github.com/cretz/bine/tor"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials"
|
||||
)
|
||||
@@ -132,6 +135,21 @@ func NewLNDclient(lndOptions LNDoptions) (LNDclient, error) {
|
||||
grpc.WithTransportCredentials(creds),
|
||||
}
|
||||
|
||||
if strings.Contains(lndOptions.Address, ".onion") {
|
||||
// Start Tor
|
||||
t, err := tor.Start(nil, nil)
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
torDialer, err := t.Dialer(context.Background(), nil)
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
opts = append(opts, grpc.WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) {
|
||||
return torDialer.DialContext(ctx, "tcp", addr)
|
||||
}))
|
||||
}
|
||||
|
||||
var macaroonData []byte
|
||||
if lndOptions.MacaroonHex != "" {
|
||||
macBytes, err := hex.DecodeString(lndOptions.MacaroonHex)
|
||||
|
||||
Reference in New Issue
Block a user