Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Connect through Tor #3

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.15

require (
github.com/GeertJohan/go.rice v1.0.0
github.com/cretz/bine v0.1.0
github.com/didip/tollbooth/v6 v6.0.2
github.com/knadh/koanf v0.14.0
github.com/labstack/echo/v4 v4.1.17
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ github.com/coreos/etcd v3.3.22+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc
github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/cretz/bine v0.1.0 h1:1/fvhLE+fk0bPzjdO5Ci+0ComYxEMuB1JhM4X5skT3g=
github.com/cretz/bine v0.1.0/go.mod h1:6PF6fWAvYtwjRGkAuDEJeWNOv3a2hUouSP/yRYXmvHw=
github.com/daaku/go.zipexe v1.0.0 h1:VSOgZtH418pH9L16hC/JrgSNJbbAL26pj7lmD1+CGdY=
github.com/daaku/go.zipexe v1.0.0/go.mod h1:z8IiR6TsVLEYKwXAoE/I+8ys/sDkgTzSL0CLnGVd57E=
github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
20 changes: 19 additions & 1 deletion ln/lnd.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ import (
"log"
"os"
"crypto/x509"
"net"

"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/macaroons"
"gopkg.in/macaroon.v2"

"google.golang.org/grpc"
"google.golang.org/grpc/credentials"

"github.com/cretz/bine/tor"
)

var stdOutLogger = log.New(os.Stdout, "", log.LstdFlags)
Expand Down Expand Up @@ -51,6 +54,7 @@ func (c LNDclient) AddInvoice(value int64, memo string) (Invoice, error) {
Memo: memo,
Value: value,
}

res, err := c.lndClient.AddInvoice(c.ctx, &invoice)
if err != nil {
return result, err
Expand Down Expand Up @@ -107,6 +111,16 @@ func (c LNDclient) GetInvoice(paymentHashStr string) (Invoice, error) {
func NewLNDclient(lndOptions LNDoptions) (LNDclient, error) {
result := LNDclient{}

// Start Tor
t, err := tor.Start(nil, nil)
if err != nil {
return result, err
}
dialer, err := t.Dialer(context.Background(), nil)
if err != nil {
return result, err
}

// Get credentials either from a hex string or a file
var creds credentials.TransportCredentials
// if a hex string is provided
Expand Down Expand Up @@ -156,7 +170,11 @@ func NewLNDclient(lndOptions LNDoptions) (LNDclient, error) {
macCred := macaroons.NewMacaroonCredential(mac)
opts = append(opts, grpc.WithPerRPCCredentials(macCred))

conn, err := grpc.Dial(lndOptions.Address, opts...)
opts = append(opts, grpc.WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) {
return dialer.DialContext(ctx, "tcp", addr)
}))

conn, err := grpc.Dial(lndOptions.Address, opts...)
if err != nil {
return result, err
}
Expand Down