Merge pull request #618 from XTLS/fix/service-name

gRPC: Use `PathEscape` encoded service name
This commit is contained in:
Arthur Morgan 2021-09-08 00:53:55 +08:00 committed by GitHub
commit c950edede2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 4 deletions

View file

@ -1,6 +1,8 @@
package grpc package grpc
import ( import (
"net/url"
"github.com/xtls/xray-core/common" "github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/transport/internet" "github.com/xtls/xray-core/transport/internet"
) )
@ -12,3 +14,7 @@ func init() {
return new(Config) return new(Config)
})) }))
} }
func (c *Config) getNormalizedName() string {
return url.PathEscape(c.ServiceName)
}

View file

@ -55,14 +55,14 @@ func dialgRPC(ctx context.Context, dest net.Destination, streamSettings *interne
client := encoding.NewGRPCServiceClient(conn) client := encoding.NewGRPCServiceClient(conn)
if grpcSettings.MultiMode { if grpcSettings.MultiMode {
newError("using gRPC multi mode").AtDebug().WriteToLog() newError("using gRPC multi mode").AtDebug().WriteToLog()
grpcService, err := client.(encoding.GRPCServiceClientX).TunMultiCustomName(ctx, grpcSettings.ServiceName) grpcService, err := client.(encoding.GRPCServiceClientX).TunMultiCustomName(ctx, grpcSettings.getNormalizedName())
if err != nil { if err != nil {
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
} }
grpcService, err := client.(encoding.GRPCServiceClientX).TunCustomName(ctx, grpcSettings.ServiceName) grpcService, err := client.(encoding.GRPCServiceClientX).TunCustomName(ctx, grpcSettings.getNormalizedName())
if err != nil { if err != nil {
return nil, newError("Cannot dial gRPC").Base(err) return nil, newError("Cannot dial gRPC").Base(err)
} }

View file

@ -39,7 +39,7 @@ func (c *gRPCServiceClient) TunCustomName(ctx context.Context, name string, opts
} }
func (c *gRPCServiceClient) TunMultiCustomName(ctx context.Context, name string, opts ...grpc.CallOption) (GRPCService_TunMultiClient, error) { func (c *gRPCServiceClient) TunMultiCustomName(ctx context.Context, name string, opts ...grpc.CallOption) (GRPCService_TunMultiClient, error) {
stream, err := c.cc.NewStream(ctx, &ServerDesc(name).Streams[0], "/"+name+"/TunMulti", opts...) stream, err := c.cc.NewStream(ctx, &ServerDesc(name).Streams[1], "/"+name+"/TunMulti", opts...)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -123,7 +123,7 @@ func Listen(ctx context.Context, address net.Address, port net.Port, settings *i
} }
} }
encoding.RegisterGRPCServiceServerX(s, listener, grpcSettings.ServiceName) encoding.RegisterGRPCServiceServerX(s, listener, grpcSettings.getNormalizedName())
if err = s.Serve(streamListener); err != nil { if err = s.Serve(streamListener); err != nil {
newError("Listener for gRPC ended").Base(err).WriteToLog() newError("Listener for gRPC ended").Base(err).WriteToLog()