github.com/sagernet/sing-box@v1.9.0-rc.20/transport/v2ray/grpc.go (about) 1 //go:build with_grpc 2 3 package v2ray 4 5 import ( 6 "context" 7 8 "github.com/sagernet/sing-box/adapter" 9 "github.com/sagernet/sing-box/common/tls" 10 "github.com/sagernet/sing-box/option" 11 "github.com/sagernet/sing-box/transport/v2raygrpc" 12 "github.com/sagernet/sing-box/transport/v2raygrpclite" 13 M "github.com/sagernet/sing/common/metadata" 14 N "github.com/sagernet/sing/common/network" 15 ) 16 17 func NewGRPCServer(ctx context.Context, options option.V2RayGRPCOptions, tlsConfig tls.ServerConfig, handler adapter.V2RayServerTransportHandler) (adapter.V2RayServerTransport, error) { 18 if options.ForceLite { 19 return v2raygrpclite.NewServer(ctx, options, tlsConfig, handler) 20 } 21 return v2raygrpc.NewServer(ctx, options, tlsConfig, handler) 22 } 23 24 func NewGRPCClient(ctx context.Context, dialer N.Dialer, serverAddr M.Socksaddr, options option.V2RayGRPCOptions, tlsConfig tls.Config) (adapter.V2RayClientTransport, error) { 25 if options.ForceLite { 26 return v2raygrpclite.NewClient(ctx, dialer, serverAddr, options, tlsConfig), nil 27 } 28 return v2raygrpc.NewClient(ctx, dialer, serverAddr, options, tlsConfig) 29 }