1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-07 00:20:42 +00:00

support chain proxy for grpc

This commit is contained in:
Shelikhoo 2021-05-09 15:13:18 +01:00
parent 31a7fb503c
commit 1038823ee9
No known key found for this signature in database
GPG Key ID: C4D5E79D22B25316

View File

@ -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