Skip to content

Commit

Permalink
support environment proxies on outbound dials (#737)
Browse files Browse the repository at this point in the history
* support environment proxies on outbound dials
  • Loading branch information
willscott committed Aug 8, 2020
1 parent fbc0fc6 commit bdadb6f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ require (
github.com/weaveworks/common v0.0.0-20200512154658-384f10054ec5
go.etcd.io/bbolt v1.3.4
golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9
golang.org/x/net v0.0.0-20200602114024-627f9648deb9 // indirect
golang.org/x/net v0.0.0-20200602114024-627f9648deb9
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543
google.golang.org/genproto v0.0.0-20200608115520-7c474a2e3482 // indirect
google.golang.org/grpc v1.29.1
Expand Down
13 changes: 12 additions & 1 deletion net/client_grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto/tls"
"fmt"
"io"
"net"
"net/http"
"sync"
"time"
Expand All @@ -14,6 +15,7 @@ import (
"github.com/drand/drand/protobuf/drand"
"github.com/weaveworks/common/httpgrpc"
httpgrpcserver "github.com/weaveworks/common/httpgrpc/server"
"golang.org/x/net/proxy"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
)
Expand All @@ -35,11 +37,13 @@ var defaultTimeout = 1 * time.Minute
// NewGrpcClient returns an implementation of an InternalClient and
// ExternalClient using gRPC connections
func NewGrpcClient(opts ...grpc.DialOption) Client {
return &grpcClient{
client := grpcClient{
opts: opts,
conns: make(map[string]*grpc.ClientConn),
timeout: defaultTimeout,
}
client.loadEnvironment()
return &client
}

// NewGrpcClientFromCertManager returns a Client using gRPC with the given trust
Expand All @@ -58,6 +62,13 @@ func NewGrpcClientWithTimeout(timeout time.Duration, opts ...grpc.DialOption) Cl
return c
}

func (g *grpcClient) loadEnvironment() {
opt := grpc.WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) {
return proxy.Dial(ctx, "tcp", addr)
})
g.opts = append([]grpc.DialOption{opt}, g.opts...)
}

func (g *grpcClient) getTimeoutContext(ctx context.Context) (context.Context, context.CancelFunc) {
g.Lock()
defer g.Unlock()
Expand Down

0 comments on commit bdadb6f

Please sign in to comment.