mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-22 12:49:20 +02:00
This reverts commit 0f79126379
.
This commit is contained in:
parent
cd4631ce99
commit
a229a7f85e
|
@ -40,8 +40,6 @@ type dialerConf struct {
|
||||||
*internet.MemoryStreamConfig
|
*internet.MemoryStreamConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
type dialerCanceller func()
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
globalDialerMap map[dialerConf]*grpc.ClientConn
|
globalDialerMap map[dialerConf]*grpc.ClientConn
|
||||||
globalDialerAccess sync.Mutex
|
globalDialerAccess sync.Mutex
|
||||||
|
@ -50,7 +48,8 @@ var (
|
||||||
func dialgRPC(ctx context.Context, dest net.Destination, streamSettings *internet.MemoryStreamConfig) (net.Conn, error) {
|
func dialgRPC(ctx context.Context, dest net.Destination, streamSettings *internet.MemoryStreamConfig) (net.Conn, error) {
|
||||||
grpcSettings := streamSettings.ProtocolSettings.(*Config)
|
grpcSettings := streamSettings.ProtocolSettings.(*Config)
|
||||||
|
|
||||||
conn, canceller, err := getGrpcClient(ctx, dest, streamSettings)
|
conn, err := getGrpcClient(ctx, dest, streamSettings)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, newError("Cannot dial gRPC").Base(err)
|
return nil, newError("Cannot dial gRPC").Base(err)
|
||||||
}
|
}
|
||||||
|
@ -59,7 +58,6 @@ func dialgRPC(ctx context.Context, dest net.Destination, streamSettings *interne
|
||||||
newError("using gRPC multi mode").AtDebug().WriteToLog()
|
newError("using gRPC multi mode").AtDebug().WriteToLog()
|
||||||
grpcService, err := client.(encoding.GRPCServiceClientX).TunMultiCustomName(ctx, grpcSettings.getNormalizedName())
|
grpcService, err := client.(encoding.GRPCServiceClientX).TunMultiCustomName(ctx, grpcSettings.getNormalizedName())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
canceller()
|
|
||||||
return nil, newError("Cannot dial gRPC").Base(err)
|
return nil, newError("Cannot dial gRPC").Base(err)
|
||||||
}
|
}
|
||||||
return encoding.NewMultiHunkConn(grpcService, nil), nil
|
return encoding.NewMultiHunkConn(grpcService, nil), nil
|
||||||
|
@ -67,14 +65,13 @@ func dialgRPC(ctx context.Context, dest net.Destination, streamSettings *interne
|
||||||
|
|
||||||
grpcService, err := client.(encoding.GRPCServiceClientX).TunCustomName(ctx, grpcSettings.getNormalizedName())
|
grpcService, err := client.(encoding.GRPCServiceClientX).TunCustomName(ctx, grpcSettings.getNormalizedName())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
canceller()
|
|
||||||
return nil, newError("Cannot dial gRPC").Base(err)
|
return nil, newError("Cannot dial gRPC").Base(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return encoding.NewHunkConn(grpcService, nil), nil
|
return encoding.NewHunkConn(grpcService, nil), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getGrpcClient(ctx context.Context, dest net.Destination, streamSettings *internet.MemoryStreamConfig) (*grpc.ClientConn, dialerCanceller, error) {
|
func getGrpcClient(ctx context.Context, dest net.Destination, streamSettings *internet.MemoryStreamConfig) (*grpc.ClientConn, error) {
|
||||||
globalDialerAccess.Lock()
|
globalDialerAccess.Lock()
|
||||||
defer globalDialerAccess.Unlock()
|
defer globalDialerAccess.Unlock()
|
||||||
|
|
||||||
|
@ -85,14 +82,8 @@ func getGrpcClient(ctx context.Context, dest net.Destination, streamSettings *in
|
||||||
sockopt := streamSettings.SocketSettings
|
sockopt := streamSettings.SocketSettings
|
||||||
grpcSettings := streamSettings.ProtocolSettings.(*Config)
|
grpcSettings := streamSettings.ProtocolSettings.(*Config)
|
||||||
|
|
||||||
canceller := func() {
|
|
||||||
globalDialerAccess.Lock()
|
|
||||||
defer globalDialerAccess.Unlock()
|
|
||||||
delete(globalDialerMap, dialerConf{dest, streamSettings})
|
|
||||||
}
|
|
||||||
|
|
||||||
if client, found := globalDialerMap[dialerConf{dest, streamSettings}]; found && client.GetState() != connectivity.Shutdown {
|
if client, found := globalDialerMap[dialerConf{dest, streamSettings}]; found && client.GetState() != connectivity.Shutdown {
|
||||||
return client, canceller, nil
|
return client, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var dialOptions = []grpc.DialOption{
|
var dialOptions = []grpc.DialOption{
|
||||||
|
@ -157,5 +148,5 @@ func getGrpcClient(ctx context.Context, dest net.Destination, streamSettings *in
|
||||||
dialOptions...,
|
dialOptions...,
|
||||||
)
|
)
|
||||||
globalDialerMap[dialerConf{dest, streamSettings}] = conn
|
globalDialerMap[dialerConf{dest, streamSettings}] = conn
|
||||||
return conn, canceller, err
|
return conn, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue