@@ -2,12 +2,10 @@ package terminal
2
2
3
3
import (
4
4
"context"
5
- "crypto/tls"
6
5
"encoding/base64"
7
6
"encoding/hex"
8
7
"fmt"
9
8
"io/ioutil"
10
- "net"
11
9
"net/http"
12
10
"strings"
13
11
"sync/atomic"
@@ -21,12 +19,9 @@ import (
21
19
"github.com/lightningnetwork/lnd/macaroons"
22
20
grpcProxy "github.com/mwitkow/grpc-proxy/proxy"
23
21
"google.golang.org/grpc"
24
- "google.golang.org/grpc/backoff"
25
22
"google.golang.org/grpc/codes"
26
- "google.golang.org/grpc/credentials"
27
23
"google.golang.org/grpc/metadata"
28
24
"google.golang.org/grpc/status"
29
- "google.golang.org/grpc/test/bufconn"
30
25
"gopkg.in/macaroon.v2"
31
26
)
32
27
@@ -65,7 +60,7 @@ func (e *proxyErr) Unwrap() error {
65
60
// component.
66
61
func newRpcProxy (cfg * Config , validator macaroons.MacaroonValidator ,
67
62
superMacValidator session.SuperMacaroonValidator ,
68
- permsMgr * perms.Manager , bufListener * bufconn. Listener ) * rpcProxy {
63
+ permsMgr * perms.Manager ) * rpcProxy {
69
64
70
65
// The gRPC web calls are protected by HTTP basic auth which is defined
71
66
// by base64(username:password). Because we only have a password, we
@@ -85,7 +80,6 @@ func newRpcProxy(cfg *Config, validator macaroons.MacaroonValidator,
85
80
permsMgr : permsMgr ,
86
81
macValidator : validator ,
87
82
superMacValidator : superMacValidator ,
88
- bufListener : bufListener ,
89
83
}
90
84
p .grpcServer = grpc .NewServer (
91
85
// From the grpxProxy doc: This codec is *crucial* to the
@@ -162,7 +156,6 @@ type rpcProxy struct {
162
156
163
157
macValidator macaroons.MacaroonValidator
164
158
superMacValidator session.SuperMacaroonValidator
165
- bufListener * bufconn.Listener
166
159
167
160
superMacaroon string
168
161
@@ -176,21 +169,9 @@ type rpcProxy struct {
176
169
}
177
170
178
171
// Start creates initial connection to lnd.
179
- func (p * rpcProxy ) Start () error {
172
+ func (p * rpcProxy ) Start (lndConn * grpc. ClientConn ) error {
180
173
var err error
181
-
182
- // Setup the connection to lnd.
183
- host , _ , tlsPath , _ , _ := p .cfg .lndConnectParams ()
184
-
185
- // We use a bufconn to connect to lnd in integrated mode.
186
- if p .cfg .LndMode == ModeIntegrated {
187
- p .lndConn , err = dialBufConnBackend (p .bufListener )
188
- } else {
189
- p .lndConn , err = dialBackend ("lnd" , host , tlsPath )
190
- }
191
- if err != nil {
192
- return fmt .Errorf ("could not dial lnd: %v" , err )
193
- }
174
+ p .lndConn = lndConn
194
175
195
176
// Make sure we can connect to all the daemons that are configured to be
196
177
// running in remote mode.
@@ -242,13 +223,6 @@ func (p *rpcProxy) hasStarted() bool {
242
223
func (p * rpcProxy ) Stop () error {
243
224
p .grpcServer .Stop ()
244
225
245
- if p .lndConn != nil {
246
- if err := p .lndConn .Close (); err != nil {
247
- log .Errorf ("Error closing lnd connection: %v" , err )
248
- return err
249
- }
250
- }
251
-
252
226
if p .faradayConn != nil {
253
227
if err := p .faradayConn .Close (); err != nil {
254
228
log .Errorf ("Error closing faraday connection: %v" , err )
@@ -681,68 +655,6 @@ func (p *rpcProxy) convertSuperMacaroon(ctx context.Context, macHex string,
681
655
return nil , nil
682
656
}
683
657
684
- // dialBufConnBackend dials an in-memory connection to an RPC listener and
685
- // ignores any TLS certificate mismatches.
686
- func dialBufConnBackend (listener * bufconn.Listener ) (* grpc.ClientConn , error ) {
687
- tlsConfig := credentials .NewTLS (& tls.Config {
688
- InsecureSkipVerify : true ,
689
- })
690
- conn , err := grpc .Dial (
691
- "" ,
692
- grpc .WithContextDialer (
693
- func (context.Context , string ) (net.Conn , error ) {
694
- return listener .Dial ()
695
- },
696
- ),
697
- grpc .WithTransportCredentials (tlsConfig ),
698
-
699
- // From the grpcProxy doc: This codec is *crucial* to the
700
- // functioning of the proxy.
701
- grpc .WithCodec (grpcProxy .Codec ()), // nolint
702
- grpc .WithTransportCredentials (tlsConfig ),
703
- grpc .WithDefaultCallOptions (maxMsgRecvSize ),
704
- grpc .WithConnectParams (grpc.ConnectParams {
705
- Backoff : backoff .DefaultConfig ,
706
- MinConnectTimeout : defaultConnectTimeout ,
707
- }),
708
- )
709
-
710
- return conn , err
711
- }
712
-
713
- // dialBackend connects to a gRPC backend through the given address and uses the
714
- // given TLS certificate to authenticate the connection.
715
- func dialBackend (name , dialAddr , tlsCertPath string ) (* grpc.ClientConn , error ) {
716
- var opts []grpc.DialOption
717
- tlsConfig , err := credentials .NewClientTLSFromFile (tlsCertPath , "" )
718
- if err != nil {
719
- return nil , fmt .Errorf ("could not read %s TLS cert %s: %v" ,
720
- name , tlsCertPath , err )
721
- }
722
-
723
- opts = append (
724
- opts ,
725
-
726
- // From the grpcProxy doc: This codec is *crucial* to the
727
- // functioning of the proxy.
728
- grpc .WithCodec (grpcProxy .Codec ()), // nolint
729
- grpc .WithTransportCredentials (tlsConfig ),
730
- grpc .WithDefaultCallOptions (maxMsgRecvSize ),
731
- grpc .WithConnectParams (grpc.ConnectParams {
732
- Backoff : backoff .DefaultConfig ,
733
- MinConnectTimeout : defaultConnectTimeout ,
734
- }),
735
- )
736
-
737
- log .Infof ("Dialing %s gRPC server at %s" , name , dialAddr )
738
- cc , err := grpc .Dial (dialAddr , opts ... )
739
- if err != nil {
740
- return nil , fmt .Errorf ("failed dialing %s backend: %v" , name ,
741
- err )
742
- }
743
- return cc , nil
744
- }
745
-
746
658
// readMacaroon tries to read the macaroon file at the specified path and create
747
659
// gRPC dial options from it.
748
660
func readMacaroon (macPath string ) ([]byte , error ) {
0 commit comments