mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-22 01:57:12 -05:00
support chain proxy for grpc
This commit is contained in:
parent
31a7fb503c
commit
1038823ee9
@ -50,7 +50,7 @@ func dialgRPC(ctx context.Context, dest net.Destination, streamSettings *interne
|
|||||||
dialOption = grpc.WithTransportCredentials(credentials.NewTLS(config.GetTLSConfig()))
|
dialOption = grpc.WithTransportCredentials(credentials.NewTLS(config.GetTLSConfig()))
|
||||||
}
|
}
|
||||||
|
|
||||||
conn, err := getGrpcClient(dest, dialOption)
|
conn, err := getGrpcClient(ctx, dest, dialOption)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, newError("Cannot dial grpc").Base(err)
|
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
|
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()
|
globalDialerAccess.Lock()
|
||||||
defer globalDialerAccess.Unlock()
|
defer globalDialerAccess.Unlock()
|
||||||
|
|
||||||
@ -71,6 +71,7 @@ func getGrpcClient(dest net.Destination, dialOption grpc.DialOption) (*grpc.Clie
|
|||||||
globalDialerMap = make(map[net.Destination]*grpc.ClientConn)
|
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 {
|
if client, found := globalDialerMap[dest]; found && client.GetState() != connectivity.Shutdown {
|
||||||
return client, nil
|
return client, nil
|
||||||
}
|
}
|
||||||
@ -87,7 +88,7 @@ func getGrpcClient(dest net.Destination, dialOption grpc.DialOption) (*grpc.Clie
|
|||||||
},
|
},
|
||||||
MinConnectTimeout: 5 * time.Second,
|
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)
|
rawHost, rawPort, err := net.SplitHostPort(s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
Loading…
Reference in New Issue
Block a user