mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-23 00:51:28 +00:00
2be03c56cb
* Pin protobuf packages It happened in the past that I ran with the wrong protobuf version installed locally, and apparently there is even still some file wrong in splithttp. Fix this issue once and for all. * bump protobuf packages * Revert "bump protobuf packages" This reverts commit7a3509346a
. * Revert "Revert "bump protobuf packages"" This reverts commitbb79707d15
. * fix deprecated grpc usage
61 lines
1.9 KiB
Go
61 lines
1.9 KiB
Go
package encoding
|
|
|
|
import (
|
|
"context"
|
|
|
|
"google.golang.org/grpc"
|
|
)
|
|
|
|
func ServerDesc(name, tun, tunMulti string) grpc.ServiceDesc {
|
|
return grpc.ServiceDesc{
|
|
ServiceName: name,
|
|
HandlerType: (*GRPCServiceServer)(nil),
|
|
Methods: []grpc.MethodDesc{},
|
|
Streams: []grpc.StreamDesc{
|
|
{
|
|
StreamName: tun,
|
|
Handler: _GRPCService_Tun_Handler,
|
|
ServerStreams: true,
|
|
ClientStreams: true,
|
|
},
|
|
{
|
|
StreamName: tunMulti,
|
|
Handler: _GRPCService_TunMulti_Handler,
|
|
ServerStreams: true,
|
|
ClientStreams: true,
|
|
},
|
|
},
|
|
Metadata: "grpc.proto",
|
|
}
|
|
}
|
|
|
|
func (c *gRPCServiceClient) TunCustomName(ctx context.Context, name, tun string, opts ...grpc.CallOption) (GRPCService_TunClient, error) {
|
|
stream, err := c.cc.NewStream(ctx, &ServerDesc(name, tun, "").Streams[0], "/"+name+"/"+tun, opts...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
x := &grpc.GenericClientStream[Hunk, Hunk]{ClientStream: stream}
|
|
return x, nil
|
|
}
|
|
|
|
func (c *gRPCServiceClient) TunMultiCustomName(ctx context.Context, name, tunMulti string, opts ...grpc.CallOption) (GRPCService_TunMultiClient, error) {
|
|
stream, err := c.cc.NewStream(ctx, &ServerDesc(name, "", tunMulti).Streams[1], "/"+name+"/"+tunMulti, opts...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
x := &grpc.GenericClientStream[MultiHunk, MultiHunk]{ClientStream: stream}
|
|
return x, nil
|
|
}
|
|
|
|
type GRPCServiceClientX interface {
|
|
TunCustomName(ctx context.Context, name, tun string, opts ...grpc.CallOption) (GRPCService_TunClient, error)
|
|
TunMultiCustomName(ctx context.Context, name, tunMulti string, opts ...grpc.CallOption) (GRPCService_TunMultiClient, error)
|
|
Tun(ctx context.Context, opts ...grpc.CallOption) (GRPCService_TunClient, error)
|
|
TunMulti(ctx context.Context, opts ...grpc.CallOption) (GRPCService_TunMultiClient, error)
|
|
}
|
|
|
|
func RegisterGRPCServiceServerX(s *grpc.Server, srv GRPCServiceServer, name, tun, tunMulti string) {
|
|
desc := ServerDesc(name, tun, tunMulti)
|
|
s.RegisterService(&desc, srv)
|
|
}
|