From 1038823ee95d91d63b0096830717dcf33f5820c1 Mon Sep 17 00:00:00 2001 From: Shelikhoo Date: Sun, 9 May 2021 15:13:18 +0100 Subject: [PATCH] support chain proxy for grpc --- transport/internet/grpc/dial.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/transport/internet/grpc/dial.go b/transport/internet/grpc/dial.go index d376fc2b4..e5410dcd5 100644 --- a/transport/internet/grpc/dial.go +++ b/transport/internet/grpc/dial.go @@ -50,7 +50,7 @@ func dialgRPC(ctx context.Context, dest net.Destination, streamSettings *interne dialOption = grpc.WithTransportCredentials(credentials.NewTLS(config.GetTLSConfig())) } - conn, err := getGrpcClient(dest, dialOption) + conn, err := getGrpcClient(ctx, dest, dialOption) if err != nil { return nil, newError("Cannot dial grpc").Base(err) @@ -63,7 +63,7 @@ func dialgRPC(ctx context.Context, dest net.Destination, streamSettings *interne return encoding.NewGunConn(gunService, nil), nil } -func getGrpcClient(dest net.Destination, dialOption grpc.DialOption) (*grpc.ClientConn, error) { +func getGrpcClient(ctx context.Context, dest net.Destination, dialOption grpc.DialOption) (*grpc.ClientConn, error) { globalDialerAccess.Lock() defer globalDialerAccess.Unlock() @@ -71,6 +71,7 @@ func getGrpcClient(dest net.Destination, dialOption grpc.DialOption) (*grpc.Clie globalDialerMap = make(map[net.Destination]*grpc.ClientConn) } + //TODO Should support chain proxy to the same destination if client, found := globalDialerMap[dest]; found && client.GetState() != connectivity.Shutdown { return client, nil } @@ -87,7 +88,7 @@ func getGrpcClient(dest net.Destination, dialOption grpc.DialOption) (*grpc.Clie }, MinConnectTimeout: 5 * time.Second, }), - grpc.WithContextDialer(func(ctx context.Context, s string) (gonet.Conn, error) { + grpc.WithContextDialer(func(ctxGrpc context.Context, s string) (gonet.Conn, error) { rawHost, rawPort, err := net.SplitHostPort(s) if err != nil { return nil, err