mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-04-29 16:58:34 +00:00
Add gRPC Transport support (#356)
Co-authored-by: JimhHan <50871214+JimhHan@users.noreply.github.com>
This commit is contained in:
parent
60b06877bf
commit
a0a32ee00d
23 changed files with 1564 additions and 4 deletions
60
transport/internet/grpc/encoding/customSeviceName.go
Normal file
60
transport/internet/grpc/encoding/customSeviceName.go
Normal file
|
@ -0,0 +1,60 @@
|
|||
package encoding
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func ServerDesc(name 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 string, opts ...grpc.CallOption) (GRPCService_TunClient, error) {
|
||||
stream, err := c.cc.NewStream(ctx, &ServerDesc(name).Streams[0], "/"+name+"/Tun", opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
x := &gRPCServiceTunClient{stream}
|
||||
return x, nil
|
||||
}
|
||||
|
||||
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...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
x := &gRPCServiceTunMultiClient{stream}
|
||||
return x, nil
|
||||
}
|
||||
|
||||
type GRPCServiceClientX interface {
|
||||
TunCustomName(ctx context.Context, name string, opts ...grpc.CallOption) (GRPCService_TunClient, error)
|
||||
TunMultiCustomName(ctx context.Context, name 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 string) {
|
||||
desc := ServerDesc(name)
|
||||
s.RegisterService(&desc, srv)
|
||||
}
|
3
transport/internet/grpc/encoding/encoding.go
Normal file
3
transport/internet/grpc/encoding/encoding.go
Normal file
|
@ -0,0 +1,3 @@
|
|||
package encoding
|
||||
|
||||
//go:generate go run github.com/xtls/xray-core/common/errors/errorgen
|
9
transport/internet/grpc/encoding/errors.generated.go
Normal file
9
transport/internet/grpc/encoding/errors.generated.go
Normal file
|
@ -0,0 +1,9 @@
|
|||
package encoding
|
||||
|
||||
import "github.com/xtls/xray-core/common/errors"
|
||||
|
||||
type errPathObjHolder struct{}
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).WithPathObj(errPathObjHolder{})
|
||||
}
|
123
transport/internet/grpc/encoding/hunkconn.go
Normal file
123
transport/internet/grpc/encoding/hunkconn.go
Normal file
|
@ -0,0 +1,123 @@
|
|||
package encoding
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net"
|
||||
|
||||
"github.com/xtls/xray-core/common/buf"
|
||||
"github.com/xtls/xray-core/common/net/cnc"
|
||||
"github.com/xtls/xray-core/common/signal/done"
|
||||
)
|
||||
|
||||
type HunkConn interface {
|
||||
Send(*Hunk) error
|
||||
Recv() (*Hunk, error)
|
||||
SendMsg(m interface{}) error
|
||||
RecvMsg(m interface{}) error
|
||||
}
|
||||
|
||||
type StreamCloser interface {
|
||||
CloseSend() error
|
||||
}
|
||||
|
||||
type HunkReaderWriter struct {
|
||||
hc HunkConn
|
||||
cancel context.CancelFunc
|
||||
done *done.Instance
|
||||
|
||||
buf []byte
|
||||
index int
|
||||
}
|
||||
|
||||
func NewHunkReadWriter(hc HunkConn, cancel context.CancelFunc) *HunkReaderWriter {
|
||||
return &HunkReaderWriter{hc, cancel, done.New(), nil, 0}
|
||||
}
|
||||
|
||||
func NewHunkConn(hc HunkConn, cancel context.CancelFunc) net.Conn {
|
||||
wrc := NewHunkReadWriter(hc, cancel)
|
||||
return cnc.NewConnection(
|
||||
cnc.ConnectionInput(wrc),
|
||||
cnc.ConnectionOutput(wrc),
|
||||
cnc.ConnectionOnClose(wrc),
|
||||
)
|
||||
}
|
||||
|
||||
func (h *HunkReaderWriter) forceFetch() error {
|
||||
hunk, err := h.hc.Recv()
|
||||
if err != nil {
|
||||
if err == io.EOF {
|
||||
return err
|
||||
}
|
||||
|
||||
return newError("failed to fetch hunk from gRPC tunnel").Base(err)
|
||||
}
|
||||
|
||||
h.buf = hunk.Data
|
||||
h.index = 0
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *HunkReaderWriter) Read(buf []byte) (int, error) {
|
||||
if h.done.Done() {
|
||||
return 0, io.EOF
|
||||
}
|
||||
|
||||
if h.index >= len(h.buf) {
|
||||
if err := h.forceFetch(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
n := copy(buf, h.buf[h.index:])
|
||||
h.index += n
|
||||
|
||||
return n, nil
|
||||
}
|
||||
|
||||
func (h *HunkReaderWriter) ReadMultiBuffer() (buf.MultiBuffer, error) {
|
||||
if h.done.Done() {
|
||||
return nil, io.EOF
|
||||
}
|
||||
if h.index >= len(h.buf) {
|
||||
if err := h.forceFetch(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if cap(h.buf) == buf.Size {
|
||||
b := h.buf
|
||||
h.index = len(h.buf)
|
||||
return buf.MultiBuffer{buf.NewExisted(b)}, nil
|
||||
}
|
||||
|
||||
b := buf.New()
|
||||
_, err := b.ReadFrom(h)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return buf.MultiBuffer{b}, nil
|
||||
}
|
||||
|
||||
func (h *HunkReaderWriter) Write(buf []byte) (int, error) {
|
||||
if h.done.Done() {
|
||||
return 0, io.ErrClosedPipe
|
||||
}
|
||||
|
||||
err := h.hc.Send(&Hunk{Data: buf[:]})
|
||||
if err != nil {
|
||||
return 0, newError("failed to send data over gRPC tunnel").Base(err)
|
||||
}
|
||||
return len(buf), nil
|
||||
}
|
||||
|
||||
func (h *HunkReaderWriter) Close() error {
|
||||
if h.cancel != nil {
|
||||
h.cancel()
|
||||
}
|
||||
if sc, match := h.hc.(StreamCloser); match {
|
||||
return sc.CloseSend()
|
||||
}
|
||||
|
||||
return h.done.Close()
|
||||
}
|
108
transport/internet/grpc/encoding/multiconn.go
Normal file
108
transport/internet/grpc/encoding/multiconn.go
Normal file
|
@ -0,0 +1,108 @@
|
|||
package encoding
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net"
|
||||
|
||||
"github.com/xtls/xray-core/common/buf"
|
||||
"github.com/xtls/xray-core/common/net/cnc"
|
||||
"github.com/xtls/xray-core/common/signal/done"
|
||||
)
|
||||
|
||||
type MultiHunkConn interface {
|
||||
Send(*MultiHunk) error
|
||||
Recv() (*MultiHunk, error)
|
||||
SendMsg(m interface{}) error
|
||||
RecvMsg(m interface{}) error
|
||||
}
|
||||
|
||||
type MultiHunkReaderWriter struct {
|
||||
hc MultiHunkConn
|
||||
cancel context.CancelFunc
|
||||
done *done.Instance
|
||||
|
||||
buf [][]byte
|
||||
}
|
||||
|
||||
func NewMultiHunkReadWriter(hc MultiHunkConn, cancel context.CancelFunc) *MultiHunkReaderWriter {
|
||||
return &MultiHunkReaderWriter{hc, cancel, done.New(), nil}
|
||||
}
|
||||
|
||||
func NewMultiHunkConn(hc MultiHunkConn, cancel context.CancelFunc) net.Conn {
|
||||
wrc := NewMultiHunkReadWriter(hc, cancel)
|
||||
return cnc.NewConnection(
|
||||
cnc.ConnectionInputMulti(wrc),
|
||||
cnc.ConnectionOutputMulti(wrc),
|
||||
cnc.ConnectionOnClose(wrc),
|
||||
)
|
||||
}
|
||||
|
||||
func (h *MultiHunkReaderWriter) forceFetch() error {
|
||||
hunk, err := h.hc.Recv()
|
||||
if err != nil {
|
||||
if err == io.EOF {
|
||||
return err
|
||||
}
|
||||
|
||||
return newError("failed to fetch hunk from gRPC tunnel").Base(err)
|
||||
}
|
||||
|
||||
h.buf = hunk.Data
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *MultiHunkReaderWriter) ReadMultiBuffer() (buf.MultiBuffer, error) {
|
||||
if h.done.Done() {
|
||||
return nil, io.EOF
|
||||
}
|
||||
|
||||
if err := h.forceFetch(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var mb = make(buf.MultiBuffer, 0, len(h.buf))
|
||||
for _, b := range h.buf {
|
||||
if cap(b) >= buf.Size {
|
||||
mb = append(mb, buf.NewExisted(b))
|
||||
continue
|
||||
}
|
||||
|
||||
nb := buf.New()
|
||||
nb.Extend(int32(len(b)))
|
||||
copy(nb.Bytes(), b)
|
||||
|
||||
mb = append(mb, nb)
|
||||
}
|
||||
return mb, nil
|
||||
}
|
||||
|
||||
func (h *MultiHunkReaderWriter) WriteMultiBuffer(mb buf.MultiBuffer) error {
|
||||
defer buf.ReleaseMulti(mb)
|
||||
if h.done.Done() {
|
||||
return io.ErrClosedPipe
|
||||
}
|
||||
|
||||
hunk := &MultiHunk{Data: make([][]byte, len(mb))}
|
||||
for _, b := range mb {
|
||||
hunk.Data = append(hunk.Data, b.Bytes())
|
||||
}
|
||||
|
||||
err := h.hc.Send(hunk)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *MultiHunkReaderWriter) Close() error {
|
||||
if h.cancel != nil {
|
||||
h.cancel()
|
||||
}
|
||||
if sc, match := h.hc.(StreamCloser); match {
|
||||
return sc.CloseSend()
|
||||
}
|
||||
|
||||
return h.done.Close()
|
||||
}
|
234
transport/internet/grpc/encoding/stream.pb.go
Normal file
234
transport/internet/grpc/encoding/stream.pb.go
Normal file
|
@ -0,0 +1,234 @@
|
|||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.25.0
|
||||
// protoc v3.15.6
|
||||
// source: transport/internet/grpc/encoding/stream.proto
|
||||
|
||||
package encoding
|
||||
|
||||
import (
|
||||
proto "github.com/golang/protobuf/proto"
|
||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||
reflect "reflect"
|
||||
sync "sync"
|
||||
)
|
||||
|
||||
const (
|
||||
// Verify that this generated code is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
|
||||
// Verify that runtime/protoimpl is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
|
||||
)
|
||||
|
||||
// This is a compile-time assertion that a sufficiently up-to-date version
|
||||
// of the legacy proto package is being used.
|
||||
const _ = proto.ProtoPackageIsVersion4
|
||||
|
||||
type Hunk struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Data []byte `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"`
|
||||
}
|
||||
|
||||
func (x *Hunk) Reset() {
|
||||
*x = Hunk{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_transport_internet_grpc_encoding_stream_proto_msgTypes[0]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *Hunk) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*Hunk) ProtoMessage() {}
|
||||
|
||||
func (x *Hunk) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_transport_internet_grpc_encoding_stream_proto_msgTypes[0]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use Hunk.ProtoReflect.Descriptor instead.
|
||||
func (*Hunk) Descriptor() ([]byte, []int) {
|
||||
return file_transport_internet_grpc_encoding_stream_proto_rawDescGZIP(), []int{0}
|
||||
}
|
||||
|
||||
func (x *Hunk) GetData() []byte {
|
||||
if x != nil {
|
||||
return x.Data
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type MultiHunk struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Data [][]byte `protobuf:"bytes,1,rep,name=data,proto3" json:"data,omitempty"`
|
||||
}
|
||||
|
||||
func (x *MultiHunk) Reset() {
|
||||
*x = MultiHunk{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_transport_internet_grpc_encoding_stream_proto_msgTypes[1]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *MultiHunk) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*MultiHunk) ProtoMessage() {}
|
||||
|
||||
func (x *MultiHunk) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_transport_internet_grpc_encoding_stream_proto_msgTypes[1]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use MultiHunk.ProtoReflect.Descriptor instead.
|
||||
func (*MultiHunk) Descriptor() ([]byte, []int) {
|
||||
return file_transport_internet_grpc_encoding_stream_proto_rawDescGZIP(), []int{1}
|
||||
}
|
||||
|
||||
func (x *MultiHunk) GetData() [][]byte {
|
||||
if x != nil {
|
||||
return x.Data
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var File_transport_internet_grpc_encoding_stream_proto protoreflect.FileDescriptor
|
||||
|
||||
var file_transport_internet_grpc_encoding_stream_proto_rawDesc = []byte{
|
||||
0x0a, 0x2d, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65,
|
||||
0x72, 0x6e, 0x65, 0x74, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x2f, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x69,
|
||||
0x6e, 0x67, 0x2f, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12,
|
||||
0x25, 0x78, 0x72, 0x61, 0x79, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e,
|
||||
0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x65, 0x6e,
|
||||
0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x22, 0x1a, 0x0a, 0x04, 0x48, 0x75, 0x6e, 0x6b, 0x12, 0x12,
|
||||
0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x64, 0x61,
|
||||
0x74, 0x61, 0x22, 0x1f, 0x0a, 0x09, 0x4d, 0x75, 0x6c, 0x74, 0x69, 0x48, 0x75, 0x6e, 0x6b, 0x12,
|
||||
0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0c, 0x52, 0x04, 0x64,
|
||||
0x61, 0x74, 0x61, 0x32, 0xe6, 0x01, 0x0a, 0x0b, 0x47, 0x52, 0x50, 0x43, 0x53, 0x65, 0x72, 0x76,
|
||||
0x69, 0x63, 0x65, 0x12, 0x63, 0x0a, 0x03, 0x54, 0x75, 0x6e, 0x12, 0x2b, 0x2e, 0x78, 0x72, 0x61,
|
||||
0x79, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65,
|
||||
0x72, 0x6e, 0x65, 0x74, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x69,
|
||||
0x6e, 0x67, 0x2e, 0x48, 0x75, 0x6e, 0x6b, 0x1a, 0x2b, 0x2e, 0x78, 0x72, 0x61, 0x79, 0x2e, 0x74,
|
||||
0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65,
|
||||
0x74, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x2e,
|
||||
0x48, 0x75, 0x6e, 0x6b, 0x28, 0x01, 0x30, 0x01, 0x12, 0x72, 0x0a, 0x08, 0x54, 0x75, 0x6e, 0x4d,
|
||||
0x75, 0x6c, 0x74, 0x69, 0x12, 0x30, 0x2e, 0x78, 0x72, 0x61, 0x79, 0x2e, 0x74, 0x72, 0x61, 0x6e,
|
||||
0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x67,
|
||||
0x72, 0x70, 0x63, 0x2e, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x2e, 0x4d, 0x75, 0x6c,
|
||||
0x74, 0x69, 0x48, 0x75, 0x6e, 0x6b, 0x1a, 0x30, 0x2e, 0x78, 0x72, 0x61, 0x79, 0x2e, 0x74, 0x72,
|
||||
0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74,
|
||||
0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x2e, 0x4d,
|
||||
0x75, 0x6c, 0x74, 0x69, 0x48, 0x75, 0x6e, 0x6b, 0x28, 0x01, 0x30, 0x01, 0x42, 0x3c, 0x5a, 0x3a,
|
||||
0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x78, 0x74, 0x6c, 0x73, 0x2f,
|
||||
0x78, 0x72, 0x61, 0x79, 0x2d, 0x63, 0x6f, 0x72, 0x65, 0x2f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70,
|
||||
0x6f, 0x72, 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2f, 0x67, 0x72, 0x70,
|
||||
0x63, 0x2f, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74,
|
||||
0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
file_transport_internet_grpc_encoding_stream_proto_rawDescOnce sync.Once
|
||||
file_transport_internet_grpc_encoding_stream_proto_rawDescData = file_transport_internet_grpc_encoding_stream_proto_rawDesc
|
||||
)
|
||||
|
||||
func file_transport_internet_grpc_encoding_stream_proto_rawDescGZIP() []byte {
|
||||
file_transport_internet_grpc_encoding_stream_proto_rawDescOnce.Do(func() {
|
||||
file_transport_internet_grpc_encoding_stream_proto_rawDescData = protoimpl.X.CompressGZIP(file_transport_internet_grpc_encoding_stream_proto_rawDescData)
|
||||
})
|
||||
return file_transport_internet_grpc_encoding_stream_proto_rawDescData
|
||||
}
|
||||
|
||||
var file_transport_internet_grpc_encoding_stream_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
|
||||
var file_transport_internet_grpc_encoding_stream_proto_goTypes = []interface{}{
|
||||
(*Hunk)(nil), // 0: xray.transport.internet.grpc.encoding.Hunk
|
||||
(*MultiHunk)(nil), // 1: xray.transport.internet.grpc.encoding.MultiHunk
|
||||
}
|
||||
var file_transport_internet_grpc_encoding_stream_proto_depIdxs = []int32{
|
||||
0, // 0: xray.transport.internet.grpc.encoding.GRPCService.Tun:input_type -> xray.transport.internet.grpc.encoding.Hunk
|
||||
1, // 1: xray.transport.internet.grpc.encoding.GRPCService.TunMulti:input_type -> xray.transport.internet.grpc.encoding.MultiHunk
|
||||
0, // 2: xray.transport.internet.grpc.encoding.GRPCService.Tun:output_type -> xray.transport.internet.grpc.encoding.Hunk
|
||||
1, // 3: xray.transport.internet.grpc.encoding.GRPCService.TunMulti:output_type -> xray.transport.internet.grpc.encoding.MultiHunk
|
||||
2, // [2:4] is the sub-list for method output_type
|
||||
0, // [0:2] is the sub-list for method input_type
|
||||
0, // [0:0] is the sub-list for extension type_name
|
||||
0, // [0:0] is the sub-list for extension extendee
|
||||
0, // [0:0] is the sub-list for field type_name
|
||||
}
|
||||
|
||||
func init() { file_transport_internet_grpc_encoding_stream_proto_init() }
|
||||
func file_transport_internet_grpc_encoding_stream_proto_init() {
|
||||
if File_transport_internet_grpc_encoding_stream_proto != nil {
|
||||
return
|
||||
}
|
||||
if !protoimpl.UnsafeEnabled {
|
||||
file_transport_internet_grpc_encoding_stream_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*Hunk); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_transport_internet_grpc_encoding_stream_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*MultiHunk); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
type x struct{}
|
||||
out := protoimpl.TypeBuilder{
|
||||
File: protoimpl.DescBuilder{
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: file_transport_internet_grpc_encoding_stream_proto_rawDesc,
|
||||
NumEnums: 0,
|
||||
NumMessages: 2,
|
||||
NumExtensions: 0,
|
||||
NumServices: 1,
|
||||
},
|
||||
GoTypes: file_transport_internet_grpc_encoding_stream_proto_goTypes,
|
||||
DependencyIndexes: file_transport_internet_grpc_encoding_stream_proto_depIdxs,
|
||||
MessageInfos: file_transport_internet_grpc_encoding_stream_proto_msgTypes,
|
||||
}.Build()
|
||||
File_transport_internet_grpc_encoding_stream_proto = out.File
|
||||
file_transport_internet_grpc_encoding_stream_proto_rawDesc = nil
|
||||
file_transport_internet_grpc_encoding_stream_proto_goTypes = nil
|
||||
file_transport_internet_grpc_encoding_stream_proto_depIdxs = nil
|
||||
}
|
17
transport/internet/grpc/encoding/stream.proto
Normal file
17
transport/internet/grpc/encoding/stream.proto
Normal file
|
@ -0,0 +1,17 @@
|
|||
syntax = "proto3";
|
||||
|
||||
package xray.transport.internet.grpc.encoding;
|
||||
option go_package = "github.com/xtls/xray-core/transport/internet/grpc/encoding";
|
||||
|
||||
message Hunk {
|
||||
bytes data = 1;
|
||||
}
|
||||
|
||||
message MultiHunk {
|
||||
repeated bytes data = 1;
|
||||
}
|
||||
|
||||
service GRPCService {
|
||||
rpc Tun (stream Hunk) returns (stream Hunk);
|
||||
rpc TunMulti (stream MultiHunk) returns (stream MultiHunk);
|
||||
}
|
201
transport/internet/grpc/encoding/stream_grpc.pb.go
Normal file
201
transport/internet/grpc/encoding/stream_grpc.pb.go
Normal file
|
@ -0,0 +1,201 @@
|
|||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||
|
||||
package encoding
|
||||
|
||||
import (
|
||||
context "context"
|
||||
grpc "google.golang.org/grpc"
|
||||
codes "google.golang.org/grpc/codes"
|
||||
status "google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the grpc package it is being compiled against.
|
||||
// Requires gRPC-Go v1.32.0 or later.
|
||||
const _ = grpc.SupportPackageIsVersion7
|
||||
|
||||
// GRPCServiceClient is the client API for GRPCService service.
|
||||
//
|
||||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
||||
type GRPCServiceClient interface {
|
||||
Tun(ctx context.Context, opts ...grpc.CallOption) (GRPCService_TunClient, error)
|
||||
TunMulti(ctx context.Context, opts ...grpc.CallOption) (GRPCService_TunMultiClient, error)
|
||||
}
|
||||
|
||||
type gRPCServiceClient struct {
|
||||
cc grpc.ClientConnInterface
|
||||
}
|
||||
|
||||
func NewGRPCServiceClient(cc grpc.ClientConnInterface) GRPCServiceClient {
|
||||
return &gRPCServiceClient{cc}
|
||||
}
|
||||
|
||||
func (c *gRPCServiceClient) Tun(ctx context.Context, opts ...grpc.CallOption) (GRPCService_TunClient, error) {
|
||||
stream, err := c.cc.NewStream(ctx, &GRPCService_ServiceDesc.Streams[0], "/xray.transport.internet.grpc.encoding.GRPCService/Tun", opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
x := &gRPCServiceTunClient{stream}
|
||||
return x, nil
|
||||
}
|
||||
|
||||
type GRPCService_TunClient interface {
|
||||
Send(*Hunk) error
|
||||
Recv() (*Hunk, error)
|
||||
grpc.ClientStream
|
||||
}
|
||||
|
||||
type gRPCServiceTunClient struct {
|
||||
grpc.ClientStream
|
||||
}
|
||||
|
||||
func (x *gRPCServiceTunClient) Send(m *Hunk) error {
|
||||
return x.ClientStream.SendMsg(m)
|
||||
}
|
||||
|
||||
func (x *gRPCServiceTunClient) Recv() (*Hunk, error) {
|
||||
m := new(Hunk)
|
||||
if err := x.ClientStream.RecvMsg(m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (c *gRPCServiceClient) TunMulti(ctx context.Context, opts ...grpc.CallOption) (GRPCService_TunMultiClient, error) {
|
||||
stream, err := c.cc.NewStream(ctx, &GRPCService_ServiceDesc.Streams[1], "/xray.transport.internet.grpc.encoding.GRPCService/TunMulti", opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
x := &gRPCServiceTunMultiClient{stream}
|
||||
return x, nil
|
||||
}
|
||||
|
||||
type GRPCService_TunMultiClient interface {
|
||||
Send(*MultiHunk) error
|
||||
Recv() (*MultiHunk, error)
|
||||
grpc.ClientStream
|
||||
}
|
||||
|
||||
type gRPCServiceTunMultiClient struct {
|
||||
grpc.ClientStream
|
||||
}
|
||||
|
||||
func (x *gRPCServiceTunMultiClient) Send(m *MultiHunk) error {
|
||||
return x.ClientStream.SendMsg(m)
|
||||
}
|
||||
|
||||
func (x *gRPCServiceTunMultiClient) Recv() (*MultiHunk, error) {
|
||||
m := new(MultiHunk)
|
||||
if err := x.ClientStream.RecvMsg(m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GRPCServiceServer is the server API for GRPCService service.
|
||||
// All implementations must embed UnimplementedGRPCServiceServer
|
||||
// for forward compatibility
|
||||
type GRPCServiceServer interface {
|
||||
Tun(GRPCService_TunServer) error
|
||||
TunMulti(GRPCService_TunMultiServer) error
|
||||
mustEmbedUnimplementedGRPCServiceServer()
|
||||
}
|
||||
|
||||
// UnimplementedGRPCServiceServer must be embedded to have forward compatible implementations.
|
||||
type UnimplementedGRPCServiceServer struct {
|
||||
}
|
||||
|
||||
func (UnimplementedGRPCServiceServer) Tun(GRPCService_TunServer) error {
|
||||
return status.Errorf(codes.Unimplemented, "method Tun not implemented")
|
||||
}
|
||||
func (UnimplementedGRPCServiceServer) TunMulti(GRPCService_TunMultiServer) error {
|
||||
return status.Errorf(codes.Unimplemented, "method TunMulti not implemented")
|
||||
}
|
||||
func (UnimplementedGRPCServiceServer) mustEmbedUnimplementedGRPCServiceServer() {}
|
||||
|
||||
// UnsafeGRPCServiceServer may be embedded to opt out of forward compatibility for this service.
|
||||
// Use of this interface is not recommended, as added methods to GRPCServiceServer will
|
||||
// result in compilation errors.
|
||||
type UnsafeGRPCServiceServer interface {
|
||||
mustEmbedUnimplementedGRPCServiceServer()
|
||||
}
|
||||
|
||||
func RegisterGRPCServiceServer(s grpc.ServiceRegistrar, srv GRPCServiceServer) {
|
||||
s.RegisterService(&GRPCService_ServiceDesc, srv)
|
||||
}
|
||||
|
||||
func _GRPCService_Tun_Handler(srv interface{}, stream grpc.ServerStream) error {
|
||||
return srv.(GRPCServiceServer).Tun(&gRPCServiceTunServer{stream})
|
||||
}
|
||||
|
||||
type GRPCService_TunServer interface {
|
||||
Send(*Hunk) error
|
||||
Recv() (*Hunk, error)
|
||||
grpc.ServerStream
|
||||
}
|
||||
|
||||
type gRPCServiceTunServer struct {
|
||||
grpc.ServerStream
|
||||
}
|
||||
|
||||
func (x *gRPCServiceTunServer) Send(m *Hunk) error {
|
||||
return x.ServerStream.SendMsg(m)
|
||||
}
|
||||
|
||||
func (x *gRPCServiceTunServer) Recv() (*Hunk, error) {
|
||||
m := new(Hunk)
|
||||
if err := x.ServerStream.RecvMsg(m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func _GRPCService_TunMulti_Handler(srv interface{}, stream grpc.ServerStream) error {
|
||||
return srv.(GRPCServiceServer).TunMulti(&gRPCServiceTunMultiServer{stream})
|
||||
}
|
||||
|
||||
type GRPCService_TunMultiServer interface {
|
||||
Send(*MultiHunk) error
|
||||
Recv() (*MultiHunk, error)
|
||||
grpc.ServerStream
|
||||
}
|
||||
|
||||
type gRPCServiceTunMultiServer struct {
|
||||
grpc.ServerStream
|
||||
}
|
||||
|
||||
func (x *gRPCServiceTunMultiServer) Send(m *MultiHunk) error {
|
||||
return x.ServerStream.SendMsg(m)
|
||||
}
|
||||
|
||||
func (x *gRPCServiceTunMultiServer) Recv() (*MultiHunk, error) {
|
||||
m := new(MultiHunk)
|
||||
if err := x.ServerStream.RecvMsg(m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GRPCService_ServiceDesc is the grpc.ServiceDesc for GRPCService service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
var GRPCService_ServiceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "xray.transport.internet.grpc.encoding.GRPCService",
|
||||
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: "transport/internet/grpc/encoding/stream.proto",
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue