github.com/sagernet/sing-box@v1.9.0-rc.20/transport/v2raygrpc/custom_name.go (about)

     1  package v2raygrpc
     2  
     3  import (
     4  	"context"
     5  
     6  	"google.golang.org/grpc"
     7  )
     8  
     9  type GunService interface {
    10  	Context() context.Context
    11  	Send(*Hunk) error
    12  	Recv() (*Hunk, error)
    13  }
    14  
    15  func ServerDesc(name string) grpc.ServiceDesc {
    16  	return grpc.ServiceDesc{
    17  		ServiceName: name,
    18  		HandlerType: (*GunServiceServer)(nil),
    19  		Methods:     []grpc.MethodDesc{},
    20  		Streams: []grpc.StreamDesc{
    21  			{
    22  				StreamName:    "Tun",
    23  				Handler:       _GunService_Tun_Handler,
    24  				ServerStreams: true,
    25  				ClientStreams: true,
    26  			},
    27  		},
    28  		Metadata: "gun.proto",
    29  	}
    30  }
    31  
    32  func (c *gunServiceClient) TunCustomName(ctx context.Context, name string, opts ...grpc.CallOption) (GunService_TunClient, error) {
    33  	stream, err := c.cc.NewStream(ctx, &ServerDesc(name).Streams[0], "/"+name+"/Tun", opts...)
    34  	if err != nil {
    35  		return nil, err
    36  	}
    37  	x := &gunServiceTunClient{stream}
    38  	return x, nil
    39  }
    40  
    41  var _ GunServiceCustomNameClient = (*gunServiceClient)(nil)
    42  
    43  type GunServiceCustomNameClient interface {
    44  	TunCustomName(ctx context.Context, name string, opts ...grpc.CallOption) (GunService_TunClient, error)
    45  	Tun(ctx context.Context, opts ...grpc.CallOption) (GunService_TunClient, error)
    46  }
    47  
    48  func RegisterGunServiceCustomNameServer(s *grpc.Server, srv GunServiceServer, name string) {
    49  	desc := ServerDesc(name)
    50  	s.RegisterService(&desc, srv)
    51  }