Skip to content

Commit 07aeac1

Browse files
author
Michal Witkowski
authored
Merge pull request mwitkow#2 from daniellowtw/master
Fix compatibility with latest grpc library
2 parents 52be0a5 + e5c3df5 commit 07aeac1

File tree

4 files changed

+739
-45
lines changed

4 files changed

+739
-45
lines changed

options.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
)
1919

2020
type options struct {
21-
creds credentials.Credentials
21+
creds credentials.TransportCredentials
2222
logger grpclog.Logger
2323
maxConcurrentStreams uint32
2424
}
@@ -43,7 +43,7 @@ func MaxConcurrentStreams(n uint32) ProxyOption {
4343
}
4444

4545
// Creds returns a ProxyOption that sets credentials for server connections.
46-
func Creds(c credentials.Credentials) ProxyOption {
46+
func Creds(c credentials.TransportCredentials) ProxyOption {
4747
return func(o *options) {
4848
o.creds = c
4949
}

patch/get_transport.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package grpc
2+
3+
import (
4+
"golang.org/x/net/context"
5+
"google.golang.org/grpc/transport"
6+
)
7+
8+
// GetTransport returns the balancer of the connection.
9+
func (cc *ClientConn) GetTransport(ctx context.Context) (transport.ClientTransport, func(), error) {
10+
return cc.getTransport(ctx, BalancerGetOptions{})
11+
}

proxy.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func (s *Proxy) Serve(lis net.Listener) error {
8484
return err
8585
}
8686
var authInfo credentials.AuthInfo = nil
87-
if creds, ok := s.opts.creds.(credentials.TransportAuthenticator); ok {
87+
if creds, ok := s.opts.creds.(credentials.TransportCredentials); ok {
8888
var conn net.Conn
8989
conn, authInfo, err = creds.ServerHandshake(c)
9090
if err != nil {
@@ -206,8 +206,9 @@ func backendTransportStream(director StreamDirector, ctx context.Context) (trans
206206
return nil, nil, grpc.Errorf(codes.Aborted, "cant dial to backend: %v", err)
207207
}
208208
}
209-
// TODO(michal): ClientConn.Picker() IS NOT IN UPSTREAM GRPC! https://github.com/grpc/grpc-go/pull/397
210-
backendTrans, err := grpcConn.Picker().Pick(ctx)
209+
// TODO(michal): ClientConn.GetTransport() IS NOT IN UPSTREAM GRPC!
210+
// To make this work, copy patch/get_transport.go to google.golang.org/grpc/
211+
backendTrans, _, err := grpcConn.GetTransport(ctx)
211212
frontendStream, _ := transport.StreamFromContext(ctx)
212213
callHdr := &transport.CallHdr{
213214
Method: frontendStream.Method(),

0 commit comments

Comments
 (0)