Projects STRLCPY SeaMoon Commits e7e93bbd
🤬
  • ■ ■ ■ ■ ■ ■
    pkg/api/controller/v1/proxy.go
    skipped 60 lines
    61 61   *obj.StatusMessage = err.Error()
    62 62   } else {
    63 63   // todo: 发送部署请求
    64  - obj.TunnelId = tun.ID
     64 + obj.TunnelID = tun.ID
    65 65   }
    66 66   }
     67 + 
     68 + // 非账户来的,直接带着
    67 69   
    68 70   if res, err := service.SVC.CreateProxy(c, obj.ToModel(true)); err != nil {
    69 71   servant.ErrorMsg(c, http.StatusInternalServerError, errors.ApiError(errors.ApiServiceError, err))
    70 72   return
    71 73   } else {
    72 74   // 发送启动通知
    73  - signal.Signal().SendProxySignal(res.ID, *res.Status)
     75 + signal.Signal().SendProxySignal(res.ID, enum.ProxyStatusActive)
    74 76   servant.SuccessMsg(c, 1, res.ToApi())
    75 77   }
    76 78  }
    skipped 61 lines
  • ■ ■ ■ ■ ■ ■
    pkg/api/enum/proxy.go
    skipped 14 lines
    15 15  type ProxyType string
    16 16   
    17 17  const (
    18  - ProxyTypeAUTO ProxyType = "auto"
    19  - ProxyTypeHTTP ProxyType = "http"
    20  - ProxyTypeSOCKS5 ProxyType = "socks5"
     18 + ProxyTypeAUTO ProxyType = "auto"
     19 + ProxyTypeHTTP ProxyType = "http"
     20 + ProxyTypeSOCKS5 ProxyType = "socks5"
     21 + ProxyTypeSOCKS5Ssr ProxyType = "socks5+ssr"
     22 + ProxyTypeSOCKS5Vmess ProxyType = "socks5+vmess"
     23 + ProxyTypeSOCKS5Vless ProxyType = "socks5+vless"
    21 24  )
    22 25   
    23 26  func (t ProxyType) String() string {
    skipped 15 lines
  • ■ ■ ■ ■ ■
    pkg/api/models/proxy.go
    skipped 55 lines
    56 56   ListenPort *string `json:"listen_port"`
    57 57   Status *enum.ProxyStatus `json:"status"`
    58 58   StatusMessage *string `json:"status_message"`
    59  - TunnelId uint `json:"tunnel_id"`
     59 + TunnelID uint `json:"tunnel_id"`
    60 60   TunnelCreateApi *TunnelCreateApi `json:"tunnel_create_api"`
    61 61  }
    62 62   
    skipped 2 lines
    65 65  }
    66 66   
    67 67  func (p Proxy) ProtoAddr() string {
     68 + if *p.Type == enum.ProxyTypeAUTO || *p.Type == enum.ProxyTypeSOCKS5Vmess || *p.Type == enum.ProxyTypeSOCKS5Vless || *p.Type == enum.ProxyTypeSOCKS5Ssr {
     69 + // 随便选好了
     70 + return fmt.Sprintf("%s://%s", enum.ProxyTypeSOCKS5, strings.Join([]string{*p.ListenAddr, *p.ListenPort}, ":"))
     71 + }
    68 72   return fmt.Sprintf("%s://%s", p.Type, strings.Join([]string{*p.ListenAddr, *p.ListenPort}, ":"))
    69 73  }
    70 74   
    skipped 17 lines
  • ■ ■ ■ ■ ■ ■
    pkg/api/service/proxy.go
    skipped 134 lines
    135 135   return err
    136 136   }
    137 137   s := targets[0]
    138  - err = s.PingTest(nil)
    139  - if err != nil {
     138 + if err = s.PingTest(nil); err != nil {
    140 139   return err
    141 140   }
    142  - err = s.DownloadTest()
    143  - if err != nil {
     141 + if err = s.DownloadTest(); err != nil {
    144 142   return err
    145 143   }
    146  - err = s.UploadTest()
    147  - if err != nil {
     144 + if err = s.UploadTest(); err != nil {
    148 145   return err
    149 146   }
    150 147   
    skipped 8 lines
  • ■ ■ ■ ■ ■ ■
    pkg/proto/tunnel.pb.go
    1  -// Code generated by protoc-gen-go. DO NOT EDIT.
    2  -// versions:
    3  -// protoc-gen-go v1.28.0
    4  -// protoc v3.3.0
    5  -// source: tunnel.proto
    6  - 
    7  -package proto
    8  - 
    9  -import (
    10  - protoreflect "google.golang.org/protobuf/reflect/protoreflect"
    11  - protoimpl "google.golang.org/protobuf/runtime/protoimpl"
    12  - reflect "reflect"
    13  - sync "sync"
    14  -)
    15  - 
    16  -const (
    17  - // Verify that this generated code is sufficiently up-to-date.
    18  - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
    19  - // Verify that runtime/protoimpl is sufficiently up-to-date.
    20  - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
    21  -)
    22  - 
    23  -type Chunk struct {
    24  - state protoimpl.MessageState
    25  - sizeCache protoimpl.SizeCache
    26  - unknownFields protoimpl.UnknownFields
    27  - 
    28  - Body []byte `protobuf:"bytes,1,opt,name=body,proto3" json:"body,omitempty"`
    29  - Size int32 `protobuf:"varint,2,opt,name=size,proto3" json:"size,omitempty"`
    30  -}
    31  - 
    32  -func (x *Chunk) Reset() {
    33  - *x = Chunk{}
    34  - if protoimpl.UnsafeEnabled {
    35  - mi := &file_tunnel_proto_msgTypes[0]
    36  - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
    37  - ms.StoreMessageInfo(mi)
    38  - }
    39  -}
    40  - 
    41  -func (x *Chunk) String() string {
    42  - return protoimpl.X.MessageStringOf(x)
    43  -}
    44  - 
    45  -func (*Chunk) ProtoMessage() {}
    46  - 
    47  -func (x *Chunk) ProtoReflect() protoreflect.Message {
    48  - mi := &file_tunnel_proto_msgTypes[0]
    49  - if protoimpl.UnsafeEnabled && x != nil {
    50  - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
    51  - if ms.LoadMessageInfo() == nil {
    52  - ms.StoreMessageInfo(mi)
    53  - }
    54  - return ms
    55  - }
    56  - return mi.MessageOf(x)
    57  -}
    58  - 
    59  -// Deprecated: Use Chunk.ProtoReflect.Descriptor instead.
    60  -func (*Chunk) Descriptor() ([]byte, []int) {
    61  - return file_tunnel_proto_rawDescGZIP(), []int{0}
    62  -}
    63  - 
    64  -func (x *Chunk) GetBody() []byte {
    65  - if x != nil {
    66  - return x.Body
    67  - }
    68  - return nil
    69  -}
    70  - 
    71  -func (x *Chunk) GetSize() int32 {
    72  - if x != nil {
    73  - return x.Size
    74  - }
    75  - return 0
    76  -}
    77  - 
    78  -var File_tunnel_proto protoreflect.FileDescriptor
    79  - 
    80  -var file_tunnel_proto_rawDesc = []byte{
    81  - 0x0a, 0x0c, 0x74, 0x75, 0x6e, 0x6e, 0x65, 0x6c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x06,
    82  - 0x74, 0x75, 0x6e, 0x6e, 0x65, 0x6c, 0x22, 0x2f, 0x0a, 0x05, 0x43, 0x68, 0x75, 0x6e, 0x6b, 0x12,
    83  - 0x12, 0x0a, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x62,
    84  - 0x6f, 0x64, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x73, 0x69, 0x7a, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28,
    85  - 0x05, 0x52, 0x04, 0x73, 0x69, 0x7a, 0x65, 0x32, 0x5e, 0x0a, 0x06, 0x54, 0x75, 0x6e, 0x6e, 0x65,
    86  - 0x6c, 0x12, 0x28, 0x0a, 0x04, 0x48, 0x74, 0x74, 0x70, 0x12, 0x0d, 0x2e, 0x74, 0x75, 0x6e, 0x6e,
    87  - 0x65, 0x6c, 0x2e, 0x43, 0x68, 0x75, 0x6e, 0x6b, 0x1a, 0x0d, 0x2e, 0x74, 0x75, 0x6e, 0x6e, 0x65,
    88  - 0x6c, 0x2e, 0x43, 0x68, 0x75, 0x6e, 0x6b, 0x28, 0x01, 0x30, 0x01, 0x12, 0x2a, 0x0a, 0x06, 0x53,
    89  - 0x6f, 0x63, 0x6b, 0x73, 0x35, 0x12, 0x0d, 0x2e, 0x74, 0x75, 0x6e, 0x6e, 0x65, 0x6c, 0x2e, 0x43,
    90  - 0x68, 0x75, 0x6e, 0x6b, 0x1a, 0x0d, 0x2e, 0x74, 0x75, 0x6e, 0x6e, 0x65, 0x6c, 0x2e, 0x43, 0x68,
    91  - 0x75, 0x6e, 0x6b, 0x28, 0x01, 0x30, 0x01, 0x42, 0x23, 0x5a, 0x21, 0x67, 0x69, 0x74, 0x68, 0x75,
    92  - 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x64, 0x76, 0x6b, 0x75, 0x6e, 0x69, 0x6f, 0x6e, 0x2f, 0x73,
    93  - 0x65, 0x61, 0x6d, 0x6f, 0x6f, 0x6e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72,
    94  - 0x6f, 0x74, 0x6f, 0x33,
    95  -}
    96  - 
    97  -var (
    98  - file_tunnel_proto_rawDescOnce sync.Once
    99  - file_tunnel_proto_rawDescData = file_tunnel_proto_rawDesc
    100  -)
    101  - 
    102  -func file_tunnel_proto_rawDescGZIP() []byte {
    103  - file_tunnel_proto_rawDescOnce.Do(func() {
    104  - file_tunnel_proto_rawDescData = protoimpl.X.CompressGZIP(file_tunnel_proto_rawDescData)
    105  - })
    106  - return file_tunnel_proto_rawDescData
    107  -}
    108  - 
    109  -var file_tunnel_proto_msgTypes = make([]protoimpl.MessageInfo, 1)
    110  -var file_tunnel_proto_goTypes = []interface{}{
    111  - (*Chunk)(nil), // 0: tunnel.Chunk
    112  -}
    113  -var file_tunnel_proto_depIdxs = []int32{
    114  - 0, // 0: tunnel.Tunnel.Http:input_type -> tunnel.Chunk
    115  - 0, // 1: tunnel.Tunnel.Socks5:input_type -> tunnel.Chunk
    116  - 0, // 2: tunnel.Tunnel.Http:output_type -> tunnel.Chunk
    117  - 0, // 3: tunnel.Tunnel.Socks5:output_type -> tunnel.Chunk
    118  - 2, // [2:4] is the sub-list for method output_type
    119  - 0, // [0:2] is the sub-list for method input_type
    120  - 0, // [0:0] is the sub-list for extension type_name
    121  - 0, // [0:0] is the sub-list for extension extendee
    122  - 0, // [0:0] is the sub-list for field type_name
    123  -}
    124  - 
    125  -func init() { file_tunnel_proto_init() }
    126  -func file_tunnel_proto_init() {
    127  - if File_tunnel_proto != nil {
    128  - return
    129  - }
    130  - if !protoimpl.UnsafeEnabled {
    131  - file_tunnel_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
    132  - switch v := v.(*Chunk); i {
    133  - case 0:
    134  - return &v.state
    135  - case 1:
    136  - return &v.sizeCache
    137  - case 2:
    138  - return &v.unknownFields
    139  - default:
    140  - return nil
    141  - }
    142  - }
    143  - }
    144  - type x struct{}
    145  - out := protoimpl.TypeBuilder{
    146  - File: protoimpl.DescBuilder{
    147  - GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
    148  - RawDescriptor: file_tunnel_proto_rawDesc,
    149  - NumEnums: 0,
    150  - NumMessages: 1,
    151  - NumExtensions: 0,
    152  - NumServices: 1,
    153  - },
    154  - GoTypes: file_tunnel_proto_goTypes,
    155  - DependencyIndexes: file_tunnel_proto_depIdxs,
    156  - MessageInfos: file_tunnel_proto_msgTypes,
    157  - }.Build()
    158  - File_tunnel_proto = out.File
    159  - file_tunnel_proto_rawDesc = nil
    160  - file_tunnel_proto_goTypes = nil
    161  - file_tunnel_proto_depIdxs = nil
    162  -}
    163  - 
  • ■ ■ ■ ■ ■ ■
    pkg/proto/tunnel.proto
    1  -syntax = "proto3";
    2  - 
    3  -package tunnel;
    4  -option go_package = "github.com/dvkunion/seamoon/proto";
    5  - 
    6  -message Chunk {
    7  - bytes body = 1;
    8  - int32 size = 2;
    9  -}
    10  - 
    11  -service Tunnel {
    12  - rpc Http (stream Chunk) returns (stream Chunk);
    13  - rpc Socks5 (stream Chunk) returns (stream Chunk);
    14  -}
  • ■ ■ ■ ■ ■ ■
    pkg/proto/tunnel_grpc.pb.go
    1  -// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
    2  -// versions:
    3  -// - protoc-gen-go-grpc v1.2.0
    4  -// - protoc v3.3.0
    5  -// source: tunnel.proto
    6  - 
    7  -package proto
    8  - 
    9  -import (
    10  - context "context"
    11  - grpc "google.golang.org/grpc"
    12  - codes "google.golang.org/grpc/codes"
    13  - status "google.golang.org/grpc/status"
    14  -)
    15  - 
    16  -// This is a compile-time assertion to ensure that this generated file
    17  -// is compatible with the grpc package it is being compiled against.
    18  -// Requires gRPC-Go v1.32.0 or later.
    19  -const _ = grpc.SupportPackageIsVersion7
    20  - 
    21  -// TunnelClient is the client API for Tunnel service.
    22  -//
    23  -// 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.
    24  -type TunnelClient interface {
    25  - Http(ctx context.Context, opts ...grpc.CallOption) (Tunnel_HttpClient, error)
    26  - Socks5(ctx context.Context, opts ...grpc.CallOption) (Tunnel_Socks5Client, error)
    27  -}
    28  - 
    29  -type tunnelClient struct {
    30  - cc grpc.ClientConnInterface
    31  -}
    32  - 
    33  -func NewTunnelClient(cc grpc.ClientConnInterface) TunnelClient {
    34  - return &tunnelClient{cc}
    35  -}
    36  - 
    37  -func (c *tunnelClient) Http(ctx context.Context, opts ...grpc.CallOption) (Tunnel_HttpClient, error) {
    38  - stream, err := c.cc.NewStream(ctx, &Tunnel_ServiceDesc.Streams[0], "/tunnel.Tunnel/Http", opts...)
    39  - if err != nil {
    40  - return nil, err
    41  - }
    42  - x := &tunnelHttpClient{stream}
    43  - return x, nil
    44  -}
    45  - 
    46  -type Tunnel_HttpClient interface {
    47  - Send(*Chunk) error
    48  - Recv() (*Chunk, error)
    49  - grpc.ClientStream
    50  -}
    51  - 
    52  -type tunnelHttpClient struct {
    53  - grpc.ClientStream
    54  -}
    55  - 
    56  -func (x *tunnelHttpClient) Send(m *Chunk) error {
    57  - return x.ClientStream.SendMsg(m)
    58  -}
    59  - 
    60  -func (x *tunnelHttpClient) Recv() (*Chunk, error) {
    61  - m := new(Chunk)
    62  - if err := x.ClientStream.RecvMsg(m); err != nil {
    63  - return nil, err
    64  - }
    65  - return m, nil
    66  -}
    67  - 
    68  -func (c *tunnelClient) Socks5(ctx context.Context, opts ...grpc.CallOption) (Tunnel_Socks5Client, error) {
    69  - stream, err := c.cc.NewStream(ctx, &Tunnel_ServiceDesc.Streams[1], "/tunnel.Tunnel/Socks5", opts...)
    70  - if err != nil {
    71  - return nil, err
    72  - }
    73  - x := &tunnelSocks5Client{stream}
    74  - return x, nil
    75  -}
    76  - 
    77  -type Tunnel_Socks5Client interface {
    78  - Send(*Chunk) error
    79  - Recv() (*Chunk, error)
    80  - grpc.ClientStream
    81  -}
    82  - 
    83  -type tunnelSocks5Client struct {
    84  - grpc.ClientStream
    85  -}
    86  - 
    87  -func (x *tunnelSocks5Client) Send(m *Chunk) error {
    88  - return x.ClientStream.SendMsg(m)
    89  -}
    90  - 
    91  -func (x *tunnelSocks5Client) Recv() (*Chunk, error) {
    92  - m := new(Chunk)
    93  - if err := x.ClientStream.RecvMsg(m); err != nil {
    94  - return nil, err
    95  - }
    96  - return m, nil
    97  -}
    98  - 
    99  -// TunnelServer is the server API for Tunnel service.
    100  -// All implementations must embed UnimplementedTunnelServer
    101  -// for forward compatibility
    102  -type TunnelServer interface {
    103  - Http(Tunnel_HttpServer) error
    104  - Socks5(Tunnel_Socks5Server) error
    105  - mustEmbedUnimplementedTunnelServer()
    106  -}
    107  - 
    108  -// UnimplementedTunnelServer must be embedded to have forward compatible implementations.
    109  -type UnimplementedTunnelServer struct {
    110  -}
    111  - 
    112  -func (UnimplementedTunnelServer) Http(Tunnel_HttpServer) error {
    113  - return status.Errorf(codes.Unimplemented, "method Http not implemented")
    114  -}
    115  -func (UnimplementedTunnelServer) Socks5(Tunnel_Socks5Server) error {
    116  - return status.Errorf(codes.Unimplemented, "method Socks5 not implemented")
    117  -}
    118  -func (UnimplementedTunnelServer) mustEmbedUnimplementedTunnelServer() {}
    119  - 
    120  -// UnsafeTunnelServer may be embedded to opt out of forward compatibility for this service.
    121  -// Use of this interface is not recommended, as added methods to TunnelServer will
    122  -// result in compilation errors.
    123  -type UnsafeTunnelServer interface {
    124  - mustEmbedUnimplementedTunnelServer()
    125  -}
    126  - 
    127  -func RegisterTunnelServer(s grpc.ServiceRegistrar, srv TunnelServer) {
    128  - s.RegisterService(&Tunnel_ServiceDesc, srv)
    129  -}
    130  - 
    131  -func _Tunnel_Http_Handler(srv interface{}, stream grpc.ServerStream) error {
    132  - return srv.(TunnelServer).Http(&tunnelHttpServer{stream})
    133  -}
    134  - 
    135  -type Tunnel_HttpServer interface {
    136  - Send(*Chunk) error
    137  - Recv() (*Chunk, error)
    138  - grpc.ServerStream
    139  -}
    140  - 
    141  -type tunnelHttpServer struct {
    142  - grpc.ServerStream
    143  -}
    144  - 
    145  -func (x *tunnelHttpServer) Send(m *Chunk) error {
    146  - return x.ServerStream.SendMsg(m)
    147  -}
    148  - 
    149  -func (x *tunnelHttpServer) Recv() (*Chunk, error) {
    150  - m := new(Chunk)
    151  - if err := x.ServerStream.RecvMsg(m); err != nil {
    152  - return nil, err
    153  - }
    154  - return m, nil
    155  -}
    156  - 
    157  -func _Tunnel_Socks5_Handler(srv interface{}, stream grpc.ServerStream) error {
    158  - return srv.(TunnelServer).Socks5(&tunnelSocks5Server{stream})
    159  -}
    160  - 
    161  -type Tunnel_Socks5Server interface {
    162  - Send(*Chunk) error
    163  - Recv() (*Chunk, error)
    164  - grpc.ServerStream
    165  -}
    166  - 
    167  -type tunnelSocks5Server struct {
    168  - grpc.ServerStream
    169  -}
    170  - 
    171  -func (x *tunnelSocks5Server) Send(m *Chunk) error {
    172  - return x.ServerStream.SendMsg(m)
    173  -}
    174  - 
    175  -func (x *tunnelSocks5Server) Recv() (*Chunk, error) {
    176  - m := new(Chunk)
    177  - if err := x.ServerStream.RecvMsg(m); err != nil {
    178  - return nil, err
    179  - }
    180  - return m, nil
    181  -}
    182  - 
    183  -// Tunnel_ServiceDesc is the grpc.ServiceDesc for Tunnel service.
    184  -// It's only intended for direct use with grpc.RegisterService,
    185  -// and not to be introspected or modified (even as a copy)
    186  -var Tunnel_ServiceDesc = grpc.ServiceDesc{
    187  - ServiceName: "tunnel.Tunnel",
    188  - HandlerType: (*TunnelServer)(nil),
    189  - Methods: []grpc.MethodDesc{},
    190  - Streams: []grpc.StreamDesc{
    191  - {
    192  - StreamName: "Http",
    193  - Handler: _Tunnel_Http_Handler,
    194  - ServerStreams: true,
    195  - ClientStreams: true,
    196  - },
    197  - {
    198  - StreamName: "Socks5",
    199  - Handler: _Tunnel_Socks5_Handler,
    200  - ServerStreams: true,
    201  - ClientStreams: true,
    202  - },
    203  - },
    204  - Metadata: "tunnel.proto",
    205  -}
    206  - 
  • ■ ■ ■ ■ ■ ■
    pkg/service/grpc.go
    skipped 11 lines
    12 12   "google.golang.org/grpc/keepalive"
    13 13   
    14 14   "github.com/DVKunion/SeaMoon/pkg/api/enum"
    15  - pb "github.com/DVKunion/SeaMoon/pkg/proto"
     15 + pb "github.com/DVKunion/SeaMoon/pkg/service/proto"
     16 + "github.com/DVKunion/SeaMoon/pkg/service/proto/gost"
     17 + "github.com/DVKunion/SeaMoon/pkg/system/consts"
    16 18   "github.com/DVKunion/SeaMoon/pkg/system/errors"
    17 19   "github.com/DVKunion/SeaMoon/pkg/system/xlog"
    18 20   "github.com/DVKunion/SeaMoon/pkg/transfer"
    skipped 1 lines
    20 22  )
    21 23   
    22 24  type GRPCService struct {
    23  - addr net.Addr
    24  - cc *grpc.ClientConn
    25  - server *grpc.Server
    26  - 
     25 + addr net.Addr
     26 + cc *grpc.ClientConn
     27 + server *grpc.Server
     28 + startAt time.Time
    27 29   pb.UnimplementedTunnelServer
     30 + gost.UnimplementedGostTunelServer
    28 31  }
    29 32   
    30 33  func init() {
    skipped 99 lines
    130 133   server := grpc.NewServer(gRPCOpts...)
    131 134   
    132 135   pb.RegisterTunnelServer(server, &g)
     136 + gost.RegisterGostTunelServer(server, &g)
    133 137   
     138 + g.startAt = time.Now()
    134 139   return server.Serve(ln)
     140 +}
     141 + 
     142 +func (g GRPCService) Auto(server pb.Tunnel_AutoServer) error {
     143 + gt := tunnel.GRPCWrapConn(g.addr, server)
     144 + 
     145 + if err := transfer.AutoTransport(gt); err != nil {
     146 + xlog.Error(errors.ServiceTransportError, "type", "socks5", "err", err)
     147 + return err
     148 + }
     149 + return nil
    135 150  }
    136 151   
    137 152  func (g GRPCService) Http(server pb.Tunnel_HttpServer) error {
    skipped 17 lines
    155 170   return nil
    156 171  }
    157 172   
     173 +func (g GRPCService) V2RaySsr(server pb.Tunnel_V2RaySsrServer) error {
     174 + gt := tunnel.GRPCWrapConn(g.addr, server)
     175 + 
     176 + if err := transfer.V2rayTransport(gt, "shadowsocks"); err != nil {
     177 + xlog.Error(errors.ServiceTransportError, "type", "v2ray-ssr", "err", err)
     178 + return err
     179 + }
     180 + return nil
     181 +}
     182 + 
     183 +func (g GRPCService) V2RayVmess(server pb.Tunnel_V2RayVmessServer) error {
     184 + gt := tunnel.GRPCWrapConn(g.addr, server)
     185 + 
     186 + if err := transfer.V2rayTransport(gt, "vmess"); err != nil {
     187 + xlog.Error(errors.ServiceTransportError, "type", "vmess", "err", err)
     188 + return err
     189 + }
     190 + return nil
     191 +}
     192 + 
     193 +func (g GRPCService) V2RayVless(server pb.Tunnel_V2RayVlessServer) error {
     194 + gt := tunnel.GRPCWrapConn(g.addr, server)
     195 + 
     196 + if err := transfer.V2rayTransport(gt, "vless"); err != nil {
     197 + xlog.Error(errors.ServiceTransportError, "type", "vless", "err", err)
     198 + return err
     199 + }
     200 + return nil
     201 +}
     202 + 
     203 +// Tunnel gost grpc 适配, 实际上直接做一个 auto 协议就好了
     204 +func (g GRPCService) Tunnel(server gost.GostTunel_TunnelServer) error {
     205 + gt := tunnel.GRPCWrapConn(g.addr, server)
     206 + 
     207 + if err := transfer.AutoTransport(gt); err != nil {
     208 + xlog.Error(errors.ServiceTransportError, "type", "socks5", "err", err)
     209 + return err
     210 + }
     211 + return nil
     212 +}
     213 + 
     214 +func (g GRPCService) Health(ctx context.Context, p *pb.Ping) (*pb.Pong, error) {
     215 + return &pb.Pong{
     216 + Status: "OK",
     217 + Time: g.startAt.Format("2006-01-02 15:04:05"),
     218 + Version: consts.Version,
     219 + Commit: consts.Commit,
     220 + }, nil
     221 +}
     222 + 
  • ■ ■ ■ ■ ■ ■
    pkg/proto/Makefile pkg/service/proto/Makefile
    skipped 4 lines
    5 5  generate:
    6 6   protoc --proto_path=./ --go_out=./ \
    7 7   --go_opt=Mtunnel.proto=./ \
     8 + --go_opt=Mgost.proto=./gost \
    8 9   --go-grpc_out=./ \
    9 10   --go-grpc_opt=Mtunnel.proto=./ \
     11 + --go-grpc_opt=Mgost.proto=./gost \
    10 12   ./*.proto
    11 13   
  • ■ ■ ■ ■ ■ ■
    pkg/service/proto/gost/gost.pb.go
     1 +// Code generated by protoc-gen-go. DO NOT EDIT.
     2 +// versions:
     3 +// protoc-gen-go v1.28.0
     4 +// protoc v3.3.0
     5 +// source: gost.proto
     6 + 
     7 +package gost
     8 + 
     9 +import (
     10 + protoreflect "google.golang.org/protobuf/reflect/protoreflect"
     11 + protoimpl "google.golang.org/protobuf/runtime/protoimpl"
     12 + reflect "reflect"
     13 + sync "sync"
     14 +)
     15 + 
     16 +const (
     17 + // Verify that this generated code is sufficiently up-to-date.
     18 + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
     19 + // Verify that runtime/protoimpl is sufficiently up-to-date.
     20 + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
     21 +)
     22 + 
     23 +type Chunk struct {
     24 + state protoimpl.MessageState
     25 + sizeCache protoimpl.SizeCache
     26 + unknownFields protoimpl.UnknownFields
     27 + 
     28 + Data []byte `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"`
     29 +}
     30 + 
     31 +func (x *Chunk) Reset() {
     32 + *x = Chunk{}
     33 + if protoimpl.UnsafeEnabled {
     34 + mi := &file_gost_proto_msgTypes[0]
     35 + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
     36 + ms.StoreMessageInfo(mi)
     37 + }
     38 +}
     39 + 
     40 +func (x *Chunk) String() string {
     41 + return protoimpl.X.MessageStringOf(x)
     42 +}
     43 + 
     44 +func (*Chunk) ProtoMessage() {}
     45 + 
     46 +func (x *Chunk) ProtoReflect() protoreflect.Message {
     47 + mi := &file_gost_proto_msgTypes[0]
     48 + if protoimpl.UnsafeEnabled && x != nil {
     49 + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
     50 + if ms.LoadMessageInfo() == nil {
     51 + ms.StoreMessageInfo(mi)
     52 + }
     53 + return ms
     54 + }
     55 + return mi.MessageOf(x)
     56 +}
     57 + 
     58 +// Deprecated: Use Chunk.ProtoReflect.Descriptor instead.
     59 +func (*Chunk) Descriptor() ([]byte, []int) {
     60 + return file_gost_proto_rawDescGZIP(), []int{0}
     61 +}
     62 + 
     63 +func (x *Chunk) GetData() []byte {
     64 + if x != nil {
     65 + return x.Data
     66 + }
     67 + return nil
     68 +}
     69 + 
     70 +var File_gost_proto protoreflect.FileDescriptor
     71 + 
     72 +var file_gost_proto_rawDesc = []byte{
     73 + 0x0a, 0x0a, 0x67, 0x6f, 0x73, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x1b, 0x0a, 0x05,
     74 + 0x43, 0x68, 0x75, 0x6e, 0x6b, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20,
     75 + 0x01, 0x28, 0x0c, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x32, 0x29, 0x0a, 0x09, 0x47, 0x6f, 0x73,
     76 + 0x74, 0x54, 0x75, 0x6e, 0x65, 0x6c, 0x12, 0x1c, 0x0a, 0x06, 0x54, 0x75, 0x6e, 0x6e, 0x65, 0x6c,
     77 + 0x12, 0x06, 0x2e, 0x43, 0x68, 0x75, 0x6e, 0x6b, 0x1a, 0x06, 0x2e, 0x43, 0x68, 0x75, 0x6e, 0x6b,
     78 + 0x28, 0x01, 0x30, 0x01, 0x42, 0x30, 0x5a, 0x2e, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63,
     79 + 0x6f, 0x6d, 0x2f, 0x67, 0x6f, 0x2d, 0x67, 0x6f, 0x73, 0x74, 0x2f, 0x63, 0x6f, 0x72, 0x65, 0x2f,
     80 + 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2f, 0x75, 0x74, 0x69, 0x6c, 0x2f, 0x67, 0x72, 0x70, 0x63,
     81 + 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
     82 +}
     83 + 
     84 +var (
     85 + file_gost_proto_rawDescOnce sync.Once
     86 + file_gost_proto_rawDescData = file_gost_proto_rawDesc
     87 +)
     88 + 
     89 +func file_gost_proto_rawDescGZIP() []byte {
     90 + file_gost_proto_rawDescOnce.Do(func() {
     91 + file_gost_proto_rawDescData = protoimpl.X.CompressGZIP(file_gost_proto_rawDescData)
     92 + })
     93 + return file_gost_proto_rawDescData
     94 +}
     95 + 
     96 +var file_gost_proto_msgTypes = make([]protoimpl.MessageInfo, 1)
     97 +var file_gost_proto_goTypes = []interface{}{
     98 + (*Chunk)(nil), // 0: Chunk
     99 +}
     100 +var file_gost_proto_depIdxs = []int32{
     101 + 0, // 0: GostTunel.Tunnel:input_type -> Chunk
     102 + 0, // 1: GostTunel.Tunnel:output_type -> Chunk
     103 + 1, // [1:2] is the sub-list for method output_type
     104 + 0, // [0:1] is the sub-list for method input_type
     105 + 0, // [0:0] is the sub-list for extension type_name
     106 + 0, // [0:0] is the sub-list for extension extendee
     107 + 0, // [0:0] is the sub-list for field type_name
     108 +}
     109 + 
     110 +func init() { file_gost_proto_init() }
     111 +func file_gost_proto_init() {
     112 + if File_gost_proto != nil {
     113 + return
     114 + }
     115 + if !protoimpl.UnsafeEnabled {
     116 + file_gost_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
     117 + switch v := v.(*Chunk); i {
     118 + case 0:
     119 + return &v.state
     120 + case 1:
     121 + return &v.sizeCache
     122 + case 2:
     123 + return &v.unknownFields
     124 + default:
     125 + return nil
     126 + }
     127 + }
     128 + }
     129 + type x struct{}
     130 + out := protoimpl.TypeBuilder{
     131 + File: protoimpl.DescBuilder{
     132 + GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
     133 + RawDescriptor: file_gost_proto_rawDesc,
     134 + NumEnums: 0,
     135 + NumMessages: 1,
     136 + NumExtensions: 0,
     137 + NumServices: 1,
     138 + },
     139 + GoTypes: file_gost_proto_goTypes,
     140 + DependencyIndexes: file_gost_proto_depIdxs,
     141 + MessageInfos: file_gost_proto_msgTypes,
     142 + }.Build()
     143 + File_gost_proto = out.File
     144 + file_gost_proto_rawDesc = nil
     145 + file_gost_proto_goTypes = nil
     146 + file_gost_proto_depIdxs = nil
     147 +}
     148 + 
  • ■ ■ ■ ■ ■ ■
    pkg/service/proto/gost/gost_grpc.pb.go
     1 +// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
     2 +// versions:
     3 +// - protoc-gen-go-grpc v1.2.0
     4 +// - protoc v3.3.0
     5 +// source: gost.proto
     6 + 
     7 +package gost
     8 + 
     9 +import (
     10 + context "context"
     11 + 
     12 + grpc "google.golang.org/grpc"
     13 + codes "google.golang.org/grpc/codes"
     14 + status "google.golang.org/grpc/status"
     15 +)
     16 + 
     17 +// This is a compile-time assertion to ensure that this generated file
     18 +// is compatible with the grpc package it is being compiled against.
     19 +// Requires gRPC-Go v1.32.0 or later.
     20 +const _ = grpc.SupportPackageIsVersion7
     21 + 
     22 +// GostTunelClient is the client API for GostTunel service.
     23 +//
     24 +// 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.
     25 +type GostTunelClient interface {
     26 + Tunnel(ctx context.Context, opts ...grpc.CallOption) (GostTunel_TunnelClient, error)
     27 +}
     28 + 
     29 +type gostTunelClient struct {
     30 + cc grpc.ClientConnInterface
     31 +}
     32 + 
     33 +func NewGostTunelClient(cc grpc.ClientConnInterface) GostTunelClient {
     34 + return &gostTunelClient{cc}
     35 +}
     36 + 
     37 +func (c *gostTunelClient) Tunnel(ctx context.Context, opts ...grpc.CallOption) (GostTunel_TunnelClient, error) {
     38 + stream, err := c.cc.NewStream(ctx, &GostTunel_ServiceDesc.Streams[0], "/GostTunel/Tunnel", opts...)
     39 + if err != nil {
     40 + return nil, err
     41 + }
     42 + x := &gostTunelTunnelClient{stream}
     43 + return x, nil
     44 +}
     45 + 
     46 +type GostTunel_TunnelClient interface {
     47 + Send(*Chunk) error
     48 + Recv() (*Chunk, error)
     49 + grpc.ClientStream
     50 +}
     51 + 
     52 +type gostTunelTunnelClient struct {
     53 + grpc.ClientStream
     54 +}
     55 + 
     56 +func (x *gostTunelTunnelClient) Send(m *Chunk) error {
     57 + return x.ClientStream.SendMsg(m)
     58 +}
     59 + 
     60 +func (x *gostTunelTunnelClient) Recv() (*Chunk, error) {
     61 + m := new(Chunk)
     62 + if err := x.ClientStream.RecvMsg(m); err != nil {
     63 + return nil, err
     64 + }
     65 + return m, nil
     66 +}
     67 + 
     68 +// GostTunelServer is the server API for GostTunel service.
     69 +// All implementations must embed UnimplementedGostTunelServer
     70 +// for forward compatibility
     71 +type GostTunelServer interface {
     72 + Tunnel(GostTunel_TunnelServer) error
     73 + mustEmbedUnimplementedGostTunelServer()
     74 +}
     75 + 
     76 +// UnimplementedGostTunelServer must be embedded to have forward compatible implementations.
     77 +type UnimplementedGostTunelServer struct {
     78 +}
     79 + 
     80 +func (UnimplementedGostTunelServer) Tunnel(GostTunel_TunnelServer) error {
     81 + return status.Errorf(codes.Unimplemented, "method Tunnel not implemented")
     82 +}
     83 +func (UnimplementedGostTunelServer) mustEmbedUnimplementedGostTunelServer() {}
     84 + 
     85 +// UnsafeGostTunelServer may be embedded to opt out of forward compatibility for this service.
     86 +// Use of this interface is not recommended, as added methods to GostTunelServer will
     87 +// result in compilation errors.
     88 +type UnsafeGostTunelServer interface {
     89 + mustEmbedUnimplementedGostTunelServer()
     90 +}
     91 + 
     92 +func RegisterGostTunelServer(s grpc.ServiceRegistrar, srv GostTunelServer) {
     93 + s.RegisterService(&GostTunel_ServiceDesc, srv)
     94 +}
     95 + 
     96 +func _GostTunel_Tunnel_Handler(srv interface{}, stream grpc.ServerStream) error {
     97 + return srv.(GostTunelServer).Tunnel(&gostTunelTunnelServer{stream})
     98 +}
     99 + 
     100 +type GostTunel_TunnelServer interface {
     101 + Send(*Chunk) error
     102 + Recv() (*Chunk, error)
     103 + grpc.ServerStream
     104 +}
     105 + 
     106 +type gostTunelTunnelServer struct {
     107 + grpc.ServerStream
     108 +}
     109 + 
     110 +func (x *gostTunelTunnelServer) Send(m *Chunk) error {
     111 + return x.ServerStream.SendMsg(m)
     112 +}
     113 + 
     114 +func (x *gostTunelTunnelServer) Recv() (*Chunk, error) {
     115 + m := new(Chunk)
     116 + if err := x.ServerStream.RecvMsg(m); err != nil {
     117 + return nil, err
     118 + }
     119 + return m, nil
     120 +}
     121 + 
     122 +// GostTunel_ServiceDesc is the grpc.ServiceDesc for GostTunel service.
     123 +// It's only intended for direct use with grpc.RegisterService,
     124 +// and not to be introspected or modified (even as a copy)
     125 +var GostTunel_ServiceDesc = grpc.ServiceDesc{
     126 + ServiceName: "GostTunel",
     127 + HandlerType: (*GostTunelServer)(nil),
     128 + Methods: []grpc.MethodDesc{},
     129 + Streams: []grpc.StreamDesc{
     130 + {
     131 + StreamName: "Tunnel",
     132 + Handler: _GostTunel_Tunnel_Handler,
     133 + ServerStreams: true,
     134 + ClientStreams: true,
     135 + },
     136 + },
     137 + Metadata: "gost.proto",
     138 +}
     139 + 
  • ■ ■ ■ ■ ■ ■
    pkg/service/proto/gost.proto
     1 +syntax = "proto3";
     2 +option go_package = "github.com/go-gost/core/common/util/grpc/proto";
     3 + 
     4 +message Chunk {
     5 + bytes data = 1;
     6 +}
     7 + 
     8 +service GostTunel {
     9 + rpc Tunnel (stream Chunk) returns (stream Chunk);
     10 +}
  • ■ ■ ■ ■ ■ ■
    pkg/service/proto/tunnel.pb.go
     1 +// Code generated by protoc-gen-go. DO NOT EDIT.
     2 +// versions:
     3 +// protoc-gen-go v1.28.0
     4 +// protoc v3.3.0
     5 +// source: tunnel.proto
     6 + 
     7 +package proto
     8 + 
     9 +import (
     10 + protoreflect "google.golang.org/protobuf/reflect/protoreflect"
     11 + protoimpl "google.golang.org/protobuf/runtime/protoimpl"
     12 + reflect "reflect"
     13 + sync "sync"
     14 +)
     15 + 
     16 +const (
     17 + // Verify that this generated code is sufficiently up-to-date.
     18 + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
     19 + // Verify that runtime/protoimpl is sufficiently up-to-date.
     20 + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
     21 +)
     22 + 
     23 +type Ping struct {
     24 + state protoimpl.MessageState
     25 + sizeCache protoimpl.SizeCache
     26 + unknownFields protoimpl.UnknownFields
     27 + 
     28 + Version string `protobuf:"bytes,1,opt,name=version,proto3" json:"version,omitempty"`
     29 +}
     30 + 
     31 +func (x *Ping) Reset() {
     32 + *x = Ping{}
     33 + if protoimpl.UnsafeEnabled {
     34 + mi := &file_tunnel_proto_msgTypes[0]
     35 + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
     36 + ms.StoreMessageInfo(mi)
     37 + }
     38 +}
     39 + 
     40 +func (x *Ping) String() string {
     41 + return protoimpl.X.MessageStringOf(x)
     42 +}
     43 + 
     44 +func (*Ping) ProtoMessage() {}
     45 + 
     46 +func (x *Ping) ProtoReflect() protoreflect.Message {
     47 + mi := &file_tunnel_proto_msgTypes[0]
     48 + if protoimpl.UnsafeEnabled && x != nil {
     49 + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
     50 + if ms.LoadMessageInfo() == nil {
     51 + ms.StoreMessageInfo(mi)
     52 + }
     53 + return ms
     54 + }
     55 + return mi.MessageOf(x)
     56 +}
     57 + 
     58 +// Deprecated: Use Ping.ProtoReflect.Descriptor instead.
     59 +func (*Ping) Descriptor() ([]byte, []int) {
     60 + return file_tunnel_proto_rawDescGZIP(), []int{0}
     61 +}
     62 + 
     63 +func (x *Ping) GetVersion() string {
     64 + if x != nil {
     65 + return x.Version
     66 + }
     67 + return ""
     68 +}
     69 + 
     70 +type Pong struct {
     71 + state protoimpl.MessageState
     72 + sizeCache protoimpl.SizeCache
     73 + unknownFields protoimpl.UnknownFields
     74 + 
     75 + Status string `protobuf:"bytes,1,opt,name=status,proto3" json:"status,omitempty"`
     76 + Time string `protobuf:"bytes,2,opt,name=time,proto3" json:"time,omitempty"`
     77 + Version string `protobuf:"bytes,3,opt,name=version,proto3" json:"version,omitempty"`
     78 + Commit string `protobuf:"bytes,4,opt,name=commit,proto3" json:"commit,omitempty"`
     79 +}
     80 + 
     81 +func (x *Pong) Reset() {
     82 + *x = Pong{}
     83 + if protoimpl.UnsafeEnabled {
     84 + mi := &file_tunnel_proto_msgTypes[1]
     85 + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
     86 + ms.StoreMessageInfo(mi)
     87 + }
     88 +}
     89 + 
     90 +func (x *Pong) String() string {
     91 + return protoimpl.X.MessageStringOf(x)
     92 +}
     93 + 
     94 +func (*Pong) ProtoMessage() {}
     95 + 
     96 +func (x *Pong) ProtoReflect() protoreflect.Message {
     97 + mi := &file_tunnel_proto_msgTypes[1]
     98 + if protoimpl.UnsafeEnabled && x != nil {
     99 + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
     100 + if ms.LoadMessageInfo() == nil {
     101 + ms.StoreMessageInfo(mi)
     102 + }
     103 + return ms
     104 + }
     105 + return mi.MessageOf(x)
     106 +}
     107 + 
     108 +// Deprecated: Use Pong.ProtoReflect.Descriptor instead.
     109 +func (*Pong) Descriptor() ([]byte, []int) {
     110 + return file_tunnel_proto_rawDescGZIP(), []int{1}
     111 +}
     112 + 
     113 +func (x *Pong) GetStatus() string {
     114 + if x != nil {
     115 + return x.Status
     116 + }
     117 + return ""
     118 +}
     119 + 
     120 +func (x *Pong) GetTime() string {
     121 + if x != nil {
     122 + return x.Time
     123 + }
     124 + return ""
     125 +}
     126 + 
     127 +func (x *Pong) GetVersion() string {
     128 + if x != nil {
     129 + return x.Version
     130 + }
     131 + return ""
     132 +}
     133 + 
     134 +func (x *Pong) GetCommit() string {
     135 + if x != nil {
     136 + return x.Commit
     137 + }
     138 + return ""
     139 +}
     140 + 
     141 +type Chunk struct {
     142 + state protoimpl.MessageState
     143 + sizeCache protoimpl.SizeCache
     144 + unknownFields protoimpl.UnknownFields
     145 + 
     146 + Body []byte `protobuf:"bytes,1,opt,name=body,proto3" json:"body,omitempty"`
     147 + Size int32 `protobuf:"varint,2,opt,name=size,proto3" json:"size,omitempty"`
     148 +}
     149 + 
     150 +func (x *Chunk) Reset() {
     151 + *x = Chunk{}
     152 + if protoimpl.UnsafeEnabled {
     153 + mi := &file_tunnel_proto_msgTypes[2]
     154 + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
     155 + ms.StoreMessageInfo(mi)
     156 + }
     157 +}
     158 + 
     159 +func (x *Chunk) String() string {
     160 + return protoimpl.X.MessageStringOf(x)
     161 +}
     162 + 
     163 +func (*Chunk) ProtoMessage() {}
     164 + 
     165 +func (x *Chunk) ProtoReflect() protoreflect.Message {
     166 + mi := &file_tunnel_proto_msgTypes[2]
     167 + if protoimpl.UnsafeEnabled && x != nil {
     168 + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
     169 + if ms.LoadMessageInfo() == nil {
     170 + ms.StoreMessageInfo(mi)
     171 + }
     172 + return ms
     173 + }
     174 + return mi.MessageOf(x)
     175 +}
     176 + 
     177 +// Deprecated: Use Chunk.ProtoReflect.Descriptor instead.
     178 +func (*Chunk) Descriptor() ([]byte, []int) {
     179 + return file_tunnel_proto_rawDescGZIP(), []int{2}
     180 +}
     181 + 
     182 +func (x *Chunk) GetBody() []byte {
     183 + if x != nil {
     184 + return x.Body
     185 + }
     186 + return nil
     187 +}
     188 + 
     189 +func (x *Chunk) GetSize() int32 {
     190 + if x != nil {
     191 + return x.Size
     192 + }
     193 + return 0
     194 +}
     195 + 
     196 +var File_tunnel_proto protoreflect.FileDescriptor
     197 + 
     198 +var file_tunnel_proto_rawDesc = []byte{
     199 + 0x0a, 0x0c, 0x74, 0x75, 0x6e, 0x6e, 0x65, 0x6c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x06,
     200 + 0x74, 0x75, 0x6e, 0x6e, 0x65, 0x6c, 0x22, 0x20, 0x0a, 0x04, 0x50, 0x69, 0x6e, 0x67, 0x12, 0x18,
     201 + 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52,
     202 + 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x22, 0x64, 0x0a, 0x04, 0x50, 0x6f, 0x6e, 0x67,
     203 + 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
     204 + 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x69, 0x6d, 0x65,
     205 + 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x69, 0x6d, 0x65, 0x12, 0x18, 0x0a, 0x07,
     206 + 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x76,
     207 + 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x16, 0x0a, 0x06, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74,
     208 + 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x22, 0x2f,
     209 + 0x0a, 0x05, 0x43, 0x68, 0x75, 0x6e, 0x6b, 0x12, 0x12, 0x0a, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x18,
     210 + 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x73,
     211 + 0x69, 0x7a, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x73, 0x69, 0x7a, 0x65, 0x32,
     212 + 0xbc, 0x02, 0x0a, 0x06, 0x54, 0x75, 0x6e, 0x6e, 0x65, 0x6c, 0x12, 0x28, 0x0a, 0x04, 0x41, 0x75,
     213 + 0x74, 0x6f, 0x12, 0x0d, 0x2e, 0x74, 0x75, 0x6e, 0x6e, 0x65, 0x6c, 0x2e, 0x43, 0x68, 0x75, 0x6e,
     214 + 0x6b, 0x1a, 0x0d, 0x2e, 0x74, 0x75, 0x6e, 0x6e, 0x65, 0x6c, 0x2e, 0x43, 0x68, 0x75, 0x6e, 0x6b,
     215 + 0x28, 0x01, 0x30, 0x01, 0x12, 0x28, 0x0a, 0x04, 0x48, 0x74, 0x74, 0x70, 0x12, 0x0d, 0x2e, 0x74,
     216 + 0x75, 0x6e, 0x6e, 0x65, 0x6c, 0x2e, 0x43, 0x68, 0x75, 0x6e, 0x6b, 0x1a, 0x0d, 0x2e, 0x74, 0x75,
     217 + 0x6e, 0x6e, 0x65, 0x6c, 0x2e, 0x43, 0x68, 0x75, 0x6e, 0x6b, 0x28, 0x01, 0x30, 0x01, 0x12, 0x2a,
     218 + 0x0a, 0x06, 0x53, 0x6f, 0x63, 0x6b, 0x73, 0x35, 0x12, 0x0d, 0x2e, 0x74, 0x75, 0x6e, 0x6e, 0x65,
     219 + 0x6c, 0x2e, 0x43, 0x68, 0x75, 0x6e, 0x6b, 0x1a, 0x0d, 0x2e, 0x74, 0x75, 0x6e, 0x6e, 0x65, 0x6c,
     220 + 0x2e, 0x43, 0x68, 0x75, 0x6e, 0x6b, 0x28, 0x01, 0x30, 0x01, 0x12, 0x2c, 0x0a, 0x08, 0x56, 0x32,
     221 + 0x72, 0x61, 0x79, 0x53, 0x73, 0x72, 0x12, 0x0d, 0x2e, 0x74, 0x75, 0x6e, 0x6e, 0x65, 0x6c, 0x2e,
     222 + 0x43, 0x68, 0x75, 0x6e, 0x6b, 0x1a, 0x0d, 0x2e, 0x74, 0x75, 0x6e, 0x6e, 0x65, 0x6c, 0x2e, 0x43,
     223 + 0x68, 0x75, 0x6e, 0x6b, 0x28, 0x01, 0x30, 0x01, 0x12, 0x2e, 0x0a, 0x0a, 0x56, 0x32, 0x72, 0x61,
     224 + 0x79, 0x56, 0x6d, 0x65, 0x73, 0x73, 0x12, 0x0d, 0x2e, 0x74, 0x75, 0x6e, 0x6e, 0x65, 0x6c, 0x2e,
     225 + 0x43, 0x68, 0x75, 0x6e, 0x6b, 0x1a, 0x0d, 0x2e, 0x74, 0x75, 0x6e, 0x6e, 0x65, 0x6c, 0x2e, 0x43,
     226 + 0x68, 0x75, 0x6e, 0x6b, 0x28, 0x01, 0x30, 0x01, 0x12, 0x2e, 0x0a, 0x0a, 0x56, 0x32, 0x72, 0x61,
     227 + 0x79, 0x56, 0x6c, 0x65, 0x73, 0x73, 0x12, 0x0d, 0x2e, 0x74, 0x75, 0x6e, 0x6e, 0x65, 0x6c, 0x2e,
     228 + 0x43, 0x68, 0x75, 0x6e, 0x6b, 0x1a, 0x0d, 0x2e, 0x74, 0x75, 0x6e, 0x6e, 0x65, 0x6c, 0x2e, 0x43,
     229 + 0x68, 0x75, 0x6e, 0x6b, 0x28, 0x01, 0x30, 0x01, 0x12, 0x24, 0x0a, 0x06, 0x48, 0x65, 0x61, 0x6c,
     230 + 0x74, 0x68, 0x12, 0x0c, 0x2e, 0x74, 0x75, 0x6e, 0x6e, 0x65, 0x6c, 0x2e, 0x50, 0x69, 0x6e, 0x67,
     231 + 0x1a, 0x0c, 0x2e, 0x74, 0x75, 0x6e, 0x6e, 0x65, 0x6c, 0x2e, 0x50, 0x6f, 0x6e, 0x67, 0x42, 0x23,
     232 + 0x5a, 0x21, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x64, 0x76, 0x6b,
     233 + 0x75, 0x6e, 0x69, 0x6f, 0x6e, 0x2f, 0x73, 0x65, 0x61, 0x6d, 0x6f, 0x6f, 0x6e, 0x2f, 0x70, 0x72,
     234 + 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
     235 +}
     236 + 
     237 +var (
     238 + file_tunnel_proto_rawDescOnce sync.Once
     239 + file_tunnel_proto_rawDescData = file_tunnel_proto_rawDesc
     240 +)
     241 + 
     242 +func file_tunnel_proto_rawDescGZIP() []byte {
     243 + file_tunnel_proto_rawDescOnce.Do(func() {
     244 + file_tunnel_proto_rawDescData = protoimpl.X.CompressGZIP(file_tunnel_proto_rawDescData)
     245 + })
     246 + return file_tunnel_proto_rawDescData
     247 +}
     248 + 
     249 +var file_tunnel_proto_msgTypes = make([]protoimpl.MessageInfo, 3)
     250 +var file_tunnel_proto_goTypes = []interface{}{
     251 + (*Ping)(nil), // 0: tunnel.Ping
     252 + (*Pong)(nil), // 1: tunnel.Pong
     253 + (*Chunk)(nil), // 2: tunnel.Chunk
     254 +}
     255 +var file_tunnel_proto_depIdxs = []int32{
     256 + 2, // 0: tunnel.Tunnel.Auto:input_type -> tunnel.Chunk
     257 + 2, // 1: tunnel.Tunnel.Http:input_type -> tunnel.Chunk
     258 + 2, // 2: tunnel.Tunnel.Socks5:input_type -> tunnel.Chunk
     259 + 2, // 3: tunnel.Tunnel.V2raySsr:input_type -> tunnel.Chunk
     260 + 2, // 4: tunnel.Tunnel.V2rayVmess:input_type -> tunnel.Chunk
     261 + 2, // 5: tunnel.Tunnel.V2rayVless:input_type -> tunnel.Chunk
     262 + 0, // 6: tunnel.Tunnel.Health:input_type -> tunnel.Ping
     263 + 2, // 7: tunnel.Tunnel.Auto:output_type -> tunnel.Chunk
     264 + 2, // 8: tunnel.Tunnel.Http:output_type -> tunnel.Chunk
     265 + 2, // 9: tunnel.Tunnel.Socks5:output_type -> tunnel.Chunk
     266 + 2, // 10: tunnel.Tunnel.V2raySsr:output_type -> tunnel.Chunk
     267 + 2, // 11: tunnel.Tunnel.V2rayVmess:output_type -> tunnel.Chunk
     268 + 2, // 12: tunnel.Tunnel.V2rayVless:output_type -> tunnel.Chunk
     269 + 1, // 13: tunnel.Tunnel.Health:output_type -> tunnel.Pong
     270 + 7, // [7:14] is the sub-list for method output_type
     271 + 0, // [0:7] is the sub-list for method input_type
     272 + 0, // [0:0] is the sub-list for extension type_name
     273 + 0, // [0:0] is the sub-list for extension extendee
     274 + 0, // [0:0] is the sub-list for field type_name
     275 +}
     276 + 
     277 +func init() { file_tunnel_proto_init() }
     278 +func file_tunnel_proto_init() {
     279 + if File_tunnel_proto != nil {
     280 + return
     281 + }
     282 + if !protoimpl.UnsafeEnabled {
     283 + file_tunnel_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
     284 + switch v := v.(*Ping); i {
     285 + case 0:
     286 + return &v.state
     287 + case 1:
     288 + return &v.sizeCache
     289 + case 2:
     290 + return &v.unknownFields
     291 + default:
     292 + return nil
     293 + }
     294 + }
     295 + file_tunnel_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
     296 + switch v := v.(*Pong); i {
     297 + case 0:
     298 + return &v.state
     299 + case 1:
     300 + return &v.sizeCache
     301 + case 2:
     302 + return &v.unknownFields
     303 + default:
     304 + return nil
     305 + }
     306 + }
     307 + file_tunnel_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
     308 + switch v := v.(*Chunk); i {
     309 + case 0:
     310 + return &v.state
     311 + case 1:
     312 + return &v.sizeCache
     313 + case 2:
     314 + return &v.unknownFields
     315 + default:
     316 + return nil
     317 + }
     318 + }
     319 + }
     320 + type x struct{}
     321 + out := protoimpl.TypeBuilder{
     322 + File: protoimpl.DescBuilder{
     323 + GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
     324 + RawDescriptor: file_tunnel_proto_rawDesc,
     325 + NumEnums: 0,
     326 + NumMessages: 3,
     327 + NumExtensions: 0,
     328 + NumServices: 1,
     329 + },
     330 + GoTypes: file_tunnel_proto_goTypes,
     331 + DependencyIndexes: file_tunnel_proto_depIdxs,
     332 + MessageInfos: file_tunnel_proto_msgTypes,
     333 + }.Build()
     334 + File_tunnel_proto = out.File
     335 + file_tunnel_proto_rawDesc = nil
     336 + file_tunnel_proto_goTypes = nil
     337 + file_tunnel_proto_depIdxs = nil
     338 +}
     339 + 
  • ■ ■ ■ ■ ■ ■
    pkg/service/proto/tunnel.proto
     1 +syntax = "proto3";
     2 + 
     3 +package tunnel;
     4 +option go_package = "github.com/dvkunion/seamoon/proto";
     5 + 
     6 +message Ping {
     7 + string version = 1;
     8 +}
     9 + 
     10 +message Pong {
     11 + string status = 1;
     12 + string time = 2;
     13 + string version = 3;
     14 + string commit = 4;
     15 +}
     16 + 
     17 +message Chunk {
     18 + bytes body = 1;
     19 + int32 size = 2;
     20 +}
     21 + 
     22 +service Tunnel {
     23 + rpc Auto (stream Chunk) returns (stream Chunk);
     24 + rpc Http (stream Chunk) returns (stream Chunk);
     25 + rpc Socks5 (stream Chunk) returns (stream Chunk);
     26 + rpc V2raySsr (stream Chunk) returns (stream Chunk);
     27 + rpc V2rayVmess (stream Chunk) returns (stream Chunk);
     28 + rpc V2rayVless (stream Chunk) returns (stream Chunk);
     29 + rpc Health(Ping) returns (Pong);
     30 +}
  • ■ ■ ■ ■ ■ ■
    pkg/service/proto/tunnel_grpc.pb.go
     1 +// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
     2 +// versions:
     3 +// - protoc-gen-go-grpc v1.2.0
     4 +// - protoc v3.3.0
     5 +// source: tunnel.proto
     6 + 
     7 +package proto
     8 + 
     9 +import (
     10 + context "context"
     11 + grpc "google.golang.org/grpc"
     12 + codes "google.golang.org/grpc/codes"
     13 + status "google.golang.org/grpc/status"
     14 +)
     15 + 
     16 +// This is a compile-time assertion to ensure that this generated file
     17 +// is compatible with the grpc package it is being compiled against.
     18 +// Requires gRPC-Go v1.32.0 or later.
     19 +const _ = grpc.SupportPackageIsVersion7
     20 + 
     21 +// TunnelClient is the client API for Tunnel service.
     22 +//
     23 +// 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.
     24 +type TunnelClient interface {
     25 + Auto(ctx context.Context, opts ...grpc.CallOption) (Tunnel_AutoClient, error)
     26 + Http(ctx context.Context, opts ...grpc.CallOption) (Tunnel_HttpClient, error)
     27 + Socks5(ctx context.Context, opts ...grpc.CallOption) (Tunnel_Socks5Client, error)
     28 + V2RaySsr(ctx context.Context, opts ...grpc.CallOption) (Tunnel_V2RaySsrClient, error)
     29 + V2RayVmess(ctx context.Context, opts ...grpc.CallOption) (Tunnel_V2RayVmessClient, error)
     30 + V2RayVless(ctx context.Context, opts ...grpc.CallOption) (Tunnel_V2RayVlessClient, error)
     31 + Health(ctx context.Context, in *Ping, opts ...grpc.CallOption) (*Pong, error)
     32 +}
     33 + 
     34 +type tunnelClient struct {
     35 + cc grpc.ClientConnInterface
     36 +}
     37 + 
     38 +func NewTunnelClient(cc grpc.ClientConnInterface) TunnelClient {
     39 + return &tunnelClient{cc}
     40 +}
     41 + 
     42 +func (c *tunnelClient) Auto(ctx context.Context, opts ...grpc.CallOption) (Tunnel_AutoClient, error) {
     43 + stream, err := c.cc.NewStream(ctx, &Tunnel_ServiceDesc.Streams[0], "/tunnel.Tunnel/Auto", opts...)
     44 + if err != nil {
     45 + return nil, err
     46 + }
     47 + x := &tunnelAutoClient{stream}
     48 + return x, nil
     49 +}
     50 + 
     51 +type Tunnel_AutoClient interface {
     52 + Send(*Chunk) error
     53 + Recv() (*Chunk, error)
     54 + grpc.ClientStream
     55 +}
     56 + 
     57 +type tunnelAutoClient struct {
     58 + grpc.ClientStream
     59 +}
     60 + 
     61 +func (x *tunnelAutoClient) Send(m *Chunk) error {
     62 + return x.ClientStream.SendMsg(m)
     63 +}
     64 + 
     65 +func (x *tunnelAutoClient) Recv() (*Chunk, error) {
     66 + m := new(Chunk)
     67 + if err := x.ClientStream.RecvMsg(m); err != nil {
     68 + return nil, err
     69 + }
     70 + return m, nil
     71 +}
     72 + 
     73 +func (c *tunnelClient) Http(ctx context.Context, opts ...grpc.CallOption) (Tunnel_HttpClient, error) {
     74 + stream, err := c.cc.NewStream(ctx, &Tunnel_ServiceDesc.Streams[1], "/tunnel.Tunnel/Http", opts...)
     75 + if err != nil {
     76 + return nil, err
     77 + }
     78 + x := &tunnelHttpClient{stream}
     79 + return x, nil
     80 +}
     81 + 
     82 +type Tunnel_HttpClient interface {
     83 + Send(*Chunk) error
     84 + Recv() (*Chunk, error)
     85 + grpc.ClientStream
     86 +}
     87 + 
     88 +type tunnelHttpClient struct {
     89 + grpc.ClientStream
     90 +}
     91 + 
     92 +func (x *tunnelHttpClient) Send(m *Chunk) error {
     93 + return x.ClientStream.SendMsg(m)
     94 +}
     95 + 
     96 +func (x *tunnelHttpClient) Recv() (*Chunk, error) {
     97 + m := new(Chunk)
     98 + if err := x.ClientStream.RecvMsg(m); err != nil {
     99 + return nil, err
     100 + }
     101 + return m, nil
     102 +}
     103 + 
     104 +func (c *tunnelClient) Socks5(ctx context.Context, opts ...grpc.CallOption) (Tunnel_Socks5Client, error) {
     105 + stream, err := c.cc.NewStream(ctx, &Tunnel_ServiceDesc.Streams[2], "/tunnel.Tunnel/Socks5", opts...)
     106 + if err != nil {
     107 + return nil, err
     108 + }
     109 + x := &tunnelSocks5Client{stream}
     110 + return x, nil
     111 +}
     112 + 
     113 +type Tunnel_Socks5Client interface {
     114 + Send(*Chunk) error
     115 + Recv() (*Chunk, error)
     116 + grpc.ClientStream
     117 +}
     118 + 
     119 +type tunnelSocks5Client struct {
     120 + grpc.ClientStream
     121 +}
     122 + 
     123 +func (x *tunnelSocks5Client) Send(m *Chunk) error {
     124 + return x.ClientStream.SendMsg(m)
     125 +}
     126 + 
     127 +func (x *tunnelSocks5Client) Recv() (*Chunk, error) {
     128 + m := new(Chunk)
     129 + if err := x.ClientStream.RecvMsg(m); err != nil {
     130 + return nil, err
     131 + }
     132 + return m, nil
     133 +}
     134 + 
     135 +func (c *tunnelClient) V2RaySsr(ctx context.Context, opts ...grpc.CallOption) (Tunnel_V2RaySsrClient, error) {
     136 + stream, err := c.cc.NewStream(ctx, &Tunnel_ServiceDesc.Streams[3], "/tunnel.Tunnel/V2raySsr", opts...)
     137 + if err != nil {
     138 + return nil, err
     139 + }
     140 + x := &tunnelV2RaySsrClient{stream}
     141 + return x, nil
     142 +}
     143 + 
     144 +type Tunnel_V2RaySsrClient interface {
     145 + Send(*Chunk) error
     146 + Recv() (*Chunk, error)
     147 + grpc.ClientStream
     148 +}
     149 + 
     150 +type tunnelV2RaySsrClient struct {
     151 + grpc.ClientStream
     152 +}
     153 + 
     154 +func (x *tunnelV2RaySsrClient) Send(m *Chunk) error {
     155 + return x.ClientStream.SendMsg(m)
     156 +}
     157 + 
     158 +func (x *tunnelV2RaySsrClient) Recv() (*Chunk, error) {
     159 + m := new(Chunk)
     160 + if err := x.ClientStream.RecvMsg(m); err != nil {
     161 + return nil, err
     162 + }
     163 + return m, nil
     164 +}
     165 + 
     166 +func (c *tunnelClient) V2RayVmess(ctx context.Context, opts ...grpc.CallOption) (Tunnel_V2RayVmessClient, error) {
     167 + stream, err := c.cc.NewStream(ctx, &Tunnel_ServiceDesc.Streams[4], "/tunnel.Tunnel/V2rayVmess", opts...)
     168 + if err != nil {
     169 + return nil, err
     170 + }
     171 + x := &tunnelV2RayVmessClient{stream}
     172 + return x, nil
     173 +}
     174 + 
     175 +type Tunnel_V2RayVmessClient interface {
     176 + Send(*Chunk) error
     177 + Recv() (*Chunk, error)
     178 + grpc.ClientStream
     179 +}
     180 + 
     181 +type tunnelV2RayVmessClient struct {
     182 + grpc.ClientStream
     183 +}
     184 + 
     185 +func (x *tunnelV2RayVmessClient) Send(m *Chunk) error {
     186 + return x.ClientStream.SendMsg(m)
     187 +}
     188 + 
     189 +func (x *tunnelV2RayVmessClient) Recv() (*Chunk, error) {
     190 + m := new(Chunk)
     191 + if err := x.ClientStream.RecvMsg(m); err != nil {
     192 + return nil, err
     193 + }
     194 + return m, nil
     195 +}
     196 + 
     197 +func (c *tunnelClient) V2RayVless(ctx context.Context, opts ...grpc.CallOption) (Tunnel_V2RayVlessClient, error) {
     198 + stream, err := c.cc.NewStream(ctx, &Tunnel_ServiceDesc.Streams[5], "/tunnel.Tunnel/V2rayVless", opts...)
     199 + if err != nil {
     200 + return nil, err
     201 + }
     202 + x := &tunnelV2RayVlessClient{stream}
     203 + return x, nil
     204 +}
     205 + 
     206 +type Tunnel_V2RayVlessClient interface {
     207 + Send(*Chunk) error
     208 + Recv() (*Chunk, error)
     209 + grpc.ClientStream
     210 +}
     211 + 
     212 +type tunnelV2RayVlessClient struct {
     213 + grpc.ClientStream
     214 +}
     215 + 
     216 +func (x *tunnelV2RayVlessClient) Send(m *Chunk) error {
     217 + return x.ClientStream.SendMsg(m)
     218 +}
     219 + 
     220 +func (x *tunnelV2RayVlessClient) Recv() (*Chunk, error) {
     221 + m := new(Chunk)
     222 + if err := x.ClientStream.RecvMsg(m); err != nil {
     223 + return nil, err
     224 + }
     225 + return m, nil
     226 +}
     227 + 
     228 +func (c *tunnelClient) Health(ctx context.Context, in *Ping, opts ...grpc.CallOption) (*Pong, error) {
     229 + out := new(Pong)
     230 + err := c.cc.Invoke(ctx, "/tunnel.Tunnel/Health", in, out, opts...)
     231 + if err != nil {
     232 + return nil, err
     233 + }
     234 + return out, nil
     235 +}
     236 + 
     237 +// TunnelServer is the server API for Tunnel service.
     238 +// All implementations must embed UnimplementedTunnelServer
     239 +// for forward compatibility
     240 +type TunnelServer interface {
     241 + Auto(Tunnel_AutoServer) error
     242 + Http(Tunnel_HttpServer) error
     243 + Socks5(Tunnel_Socks5Server) error
     244 + V2RaySsr(Tunnel_V2RaySsrServer) error
     245 + V2RayVmess(Tunnel_V2RayVmessServer) error
     246 + V2RayVless(Tunnel_V2RayVlessServer) error
     247 + Health(context.Context, *Ping) (*Pong, error)
     248 + mustEmbedUnimplementedTunnelServer()
     249 +}
     250 + 
     251 +// UnimplementedTunnelServer must be embedded to have forward compatible implementations.
     252 +type UnimplementedTunnelServer struct {
     253 +}
     254 + 
     255 +func (UnimplementedTunnelServer) Auto(Tunnel_AutoServer) error {
     256 + return status.Errorf(codes.Unimplemented, "method Auto not implemented")
     257 +}
     258 +func (UnimplementedTunnelServer) Http(Tunnel_HttpServer) error {
     259 + return status.Errorf(codes.Unimplemented, "method Http not implemented")
     260 +}
     261 +func (UnimplementedTunnelServer) Socks5(Tunnel_Socks5Server) error {
     262 + return status.Errorf(codes.Unimplemented, "method Socks5 not implemented")
     263 +}
     264 +func (UnimplementedTunnelServer) V2RaySsr(Tunnel_V2RaySsrServer) error {
     265 + return status.Errorf(codes.Unimplemented, "method V2RaySsr not implemented")
     266 +}
     267 +func (UnimplementedTunnelServer) V2RayVmess(Tunnel_V2RayVmessServer) error {
     268 + return status.Errorf(codes.Unimplemented, "method V2RayVmess not implemented")
     269 +}
     270 +func (UnimplementedTunnelServer) V2RayVless(Tunnel_V2RayVlessServer) error {
     271 + return status.Errorf(codes.Unimplemented, "method V2RayVless not implemented")
     272 +}
     273 +func (UnimplementedTunnelServer) Health(context.Context, *Ping) (*Pong, error) {
     274 + return nil, status.Errorf(codes.Unimplemented, "method Health not implemented")
     275 +}
     276 +func (UnimplementedTunnelServer) mustEmbedUnimplementedTunnelServer() {}
     277 + 
     278 +// UnsafeTunnelServer may be embedded to opt out of forward compatibility for this service.
     279 +// Use of this interface is not recommended, as added methods to TunnelServer will
     280 +// result in compilation errors.
     281 +type UnsafeTunnelServer interface {
     282 + mustEmbedUnimplementedTunnelServer()
     283 +}
     284 + 
     285 +func RegisterTunnelServer(s grpc.ServiceRegistrar, srv TunnelServer) {
     286 + s.RegisterService(&Tunnel_ServiceDesc, srv)
     287 +}
     288 + 
     289 +func _Tunnel_Auto_Handler(srv interface{}, stream grpc.ServerStream) error {
     290 + return srv.(TunnelServer).Auto(&tunnelAutoServer{stream})
     291 +}
     292 + 
     293 +type Tunnel_AutoServer interface {
     294 + Send(*Chunk) error
     295 + Recv() (*Chunk, error)
     296 + grpc.ServerStream
     297 +}
     298 + 
     299 +type tunnelAutoServer struct {
     300 + grpc.ServerStream
     301 +}
     302 + 
     303 +func (x *tunnelAutoServer) Send(m *Chunk) error {
     304 + return x.ServerStream.SendMsg(m)
     305 +}
     306 + 
     307 +func (x *tunnelAutoServer) Recv() (*Chunk, error) {
     308 + m := new(Chunk)
     309 + if err := x.ServerStream.RecvMsg(m); err != nil {
     310 + return nil, err
     311 + }
     312 + return m, nil
     313 +}
     314 + 
     315 +func _Tunnel_Http_Handler(srv interface{}, stream grpc.ServerStream) error {
     316 + return srv.(TunnelServer).Http(&tunnelHttpServer{stream})
     317 +}
     318 + 
     319 +type Tunnel_HttpServer interface {
     320 + Send(*Chunk) error
     321 + Recv() (*Chunk, error)
     322 + grpc.ServerStream
     323 +}
     324 + 
     325 +type tunnelHttpServer struct {
     326 + grpc.ServerStream
     327 +}
     328 + 
     329 +func (x *tunnelHttpServer) Send(m *Chunk) error {
     330 + return x.ServerStream.SendMsg(m)
     331 +}
     332 + 
     333 +func (x *tunnelHttpServer) Recv() (*Chunk, error) {
     334 + m := new(Chunk)
     335 + if err := x.ServerStream.RecvMsg(m); err != nil {
     336 + return nil, err
     337 + }
     338 + return m, nil
     339 +}
     340 + 
     341 +func _Tunnel_Socks5_Handler(srv interface{}, stream grpc.ServerStream) error {
     342 + return srv.(TunnelServer).Socks5(&tunnelSocks5Server{stream})
     343 +}
     344 + 
     345 +type Tunnel_Socks5Server interface {
     346 + Send(*Chunk) error
     347 + Recv() (*Chunk, error)
     348 + grpc.ServerStream
     349 +}
     350 + 
     351 +type tunnelSocks5Server struct {
     352 + grpc.ServerStream
     353 +}
     354 + 
     355 +func (x *tunnelSocks5Server) Send(m *Chunk) error {
     356 + return x.ServerStream.SendMsg(m)
     357 +}
     358 + 
     359 +func (x *tunnelSocks5Server) Recv() (*Chunk, error) {
     360 + m := new(Chunk)
     361 + if err := x.ServerStream.RecvMsg(m); err != nil {
     362 + return nil, err
     363 + }
     364 + return m, nil
     365 +}
     366 + 
     367 +func _Tunnel_V2RaySsr_Handler(srv interface{}, stream grpc.ServerStream) error {
     368 + return srv.(TunnelServer).V2RaySsr(&tunnelV2RaySsrServer{stream})
     369 +}
     370 + 
     371 +type Tunnel_V2RaySsrServer interface {
     372 + Send(*Chunk) error
     373 + Recv() (*Chunk, error)
     374 + grpc.ServerStream
     375 +}
     376 + 
     377 +type tunnelV2RaySsrServer struct {
     378 + grpc.ServerStream
     379 +}
     380 + 
     381 +func (x *tunnelV2RaySsrServer) Send(m *Chunk) error {
     382 + return x.ServerStream.SendMsg(m)
     383 +}
     384 + 
     385 +func (x *tunnelV2RaySsrServer) Recv() (*Chunk, error) {
     386 + m := new(Chunk)
     387 + if err := x.ServerStream.RecvMsg(m); err != nil {
     388 + return nil, err
     389 + }
     390 + return m, nil
     391 +}
     392 + 
     393 +func _Tunnel_V2RayVmess_Handler(srv interface{}, stream grpc.ServerStream) error {
     394 + return srv.(TunnelServer).V2RayVmess(&tunnelV2RayVmessServer{stream})
     395 +}
     396 + 
     397 +type Tunnel_V2RayVmessServer interface {
     398 + Send(*Chunk) error
     399 + Recv() (*Chunk, error)
     400 + grpc.ServerStream
     401 +}
     402 + 
     403 +type tunnelV2RayVmessServer struct {
     404 + grpc.ServerStream
     405 +}
     406 + 
     407 +func (x *tunnelV2RayVmessServer) Send(m *Chunk) error {
     408 + return x.ServerStream.SendMsg(m)
     409 +}
     410 + 
     411 +func (x *tunnelV2RayVmessServer) Recv() (*Chunk, error) {
     412 + m := new(Chunk)
     413 + if err := x.ServerStream.RecvMsg(m); err != nil {
     414 + return nil, err
     415 + }
     416 + return m, nil
     417 +}
     418 + 
     419 +func _Tunnel_V2RayVless_Handler(srv interface{}, stream grpc.ServerStream) error {
     420 + return srv.(TunnelServer).V2RayVless(&tunnelV2RayVlessServer{stream})
     421 +}
     422 + 
     423 +type Tunnel_V2RayVlessServer interface {
     424 + Send(*Chunk) error
     425 + Recv() (*Chunk, error)
     426 + grpc.ServerStream
     427 +}
     428 + 
     429 +type tunnelV2RayVlessServer struct {
     430 + grpc.ServerStream
     431 +}
     432 + 
     433 +func (x *tunnelV2RayVlessServer) Send(m *Chunk) error {
     434 + return x.ServerStream.SendMsg(m)
     435 +}
     436 + 
     437 +func (x *tunnelV2RayVlessServer) Recv() (*Chunk, error) {
     438 + m := new(Chunk)
     439 + if err := x.ServerStream.RecvMsg(m); err != nil {
     440 + return nil, err
     441 + }
     442 + return m, nil
     443 +}
     444 + 
     445 +func _Tunnel_Health_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
     446 + in := new(Ping)
     447 + if err := dec(in); err != nil {
     448 + return nil, err
     449 + }
     450 + if interceptor == nil {
     451 + return srv.(TunnelServer).Health(ctx, in)
     452 + }
     453 + info := &grpc.UnaryServerInfo{
     454 + Server: srv,
     455 + FullMethod: "/tunnel.Tunnel/Health",
     456 + }
     457 + handler := func(ctx context.Context, req interface{}) (interface{}, error) {
     458 + return srv.(TunnelServer).Health(ctx, req.(*Ping))
     459 + }
     460 + return interceptor(ctx, in, info, handler)
     461 +}
     462 + 
     463 +// Tunnel_ServiceDesc is the grpc.ServiceDesc for Tunnel service.
     464 +// It's only intended for direct use with grpc.RegisterService,
     465 +// and not to be introspected or modified (even as a copy)
     466 +var Tunnel_ServiceDesc = grpc.ServiceDesc{
     467 + ServiceName: "tunnel.Tunnel",
     468 + HandlerType: (*TunnelServer)(nil),
     469 + Methods: []grpc.MethodDesc{
     470 + {
     471 + MethodName: "Health",
     472 + Handler: _Tunnel_Health_Handler,
     473 + },
     474 + },
     475 + Streams: []grpc.StreamDesc{
     476 + {
     477 + StreamName: "Auto",
     478 + Handler: _Tunnel_Auto_Handler,
     479 + ServerStreams: true,
     480 + ClientStreams: true,
     481 + },
     482 + {
     483 + StreamName: "Http",
     484 + Handler: _Tunnel_Http_Handler,
     485 + ServerStreams: true,
     486 + ClientStreams: true,
     487 + },
     488 + {
     489 + StreamName: "Socks5",
     490 + Handler: _Tunnel_Socks5_Handler,
     491 + ServerStreams: true,
     492 + ClientStreams: true,
     493 + },
     494 + {
     495 + StreamName: "V2raySsr",
     496 + Handler: _Tunnel_V2RaySsr_Handler,
     497 + ServerStreams: true,
     498 + ClientStreams: true,
     499 + },
     500 + {
     501 + StreamName: "V2rayVmess",
     502 + Handler: _Tunnel_V2RayVmess_Handler,
     503 + ServerStreams: true,
     504 + ClientStreams: true,
     505 + },
     506 + {
     507 + StreamName: "V2rayVless",
     508 + Handler: _Tunnel_V2RayVless_Handler,
     509 + ServerStreams: true,
     510 + ClientStreams: true,
     511 + },
     512 + },
     513 + Metadata: "tunnel.proto",
     514 +}
     515 + 
  • ■ ■ ■ ■ ■ ■
    pkg/signal/signal.go
    skipped 55 lines
    56 56   // proxy sync change task
    57 57   proxy, err := service.SVC.GetProxyById(ctx, pys.id)
    58 58   if err != nil {
    59  - xlog.Error(errors.SignalGetObjError, "err", err)
     59 + _ = service.SVC.UpdateProxyStatus(ctx, pys.id, enum.ProxyStatusError, err.Error())
     60 + xlog.Error(errors.SignalGetObjError, "obj", "proxy", "err", err)
    60 61   continue
    61 62   }
    62 63   switch pys.next {
    skipped 1 lines
    64 65   sigCtx, cancel := context.WithCancel(ctx)
    65 66   tun, err := service.SVC.GetTunnelById(ctx, proxy.TunnelID)
    66 67   if err != nil {
    67  - xlog.Error(errors.SignalGetObjError, "err", err)
     68 + _ = service.SVC.UpdateProxyStatus(ctx, pys.id, enum.ProxyStatusError, err.Error())
     69 + xlog.Error(errors.SignalGetObjError, "obj", "tunnel", "err", err)
    68 70   continue
    69 71   }
    70 72   server, err := listener.TCPListen(sigCtx, proxy, tun)
    skipped 3 lines
    74 76   sb.canceler[pys.id] = cancel
    75 77   sb.listener[pys.id] = server
    76 78   xlog.Info(xlog.SignalListenStart, "id", pys.id, "type", proxy.Type, "addr", proxy.Addr())
     79 + _ = service.SVC.UpdateProxyStatus(ctx, pys.id, enum.ProxyStatusActive, "")
    77 80   case enum.ProxyStatusInactive:
    78 81   if cancel, ok := sb.canceler[pys.id]; ok {
    79 82   // 先调一下 cancel
    skipped 12 lines
    92 95   if err = service.SVC.SpeedProxy(ctx, proxy); err != nil {
    93 96   _ = service.SVC.UpdateProxyStatus(ctx, proxy.ID, enum.ProxyStatusError, err.Error())
    94 97   xlog.Error(errors.SignalSpeedTestError, "id", pys.id, "type", proxy.Type, "addr", proxy.Addr(), "err", err)
     98 + continue
    95 99   }
    96 100   if err = service.SVC.UpdateProxyStatus(ctx, proxy.ID, enum.ProxyStatusActive, ""); err != nil {
    97 101   xlog.Error(errors.SignalUpdateObjError, "id", pys.id, "type", proxy.Type, "addr", proxy.Addr(), "err", err)
    skipped 3 lines
    101 105   // todo: provider sync change task
    102 106   _, err := service.SVC.GetProviderById(ctx, prs.id)
    103 107   if err != nil {
    104  - xlog.Error(errors.SignalGetObjError, "err", err)
     108 + xlog.Error(errors.SignalGetObjError, "obj", "provider", "err", err)
    105 109   }
    106 110   case ts := <-sb.tunnelChannel:
    107 111   // todo: provider sync change task
    108 112   _, err := service.SVC.GetTunnelById(ctx, ts.id)
    109 113   if err != nil {
    110  - xlog.Error(errors.SignalGetObjError, "err", err)
     114 + xlog.Error(errors.SignalGetObjError, "obj", "tunnel", "err", err)
    111 115   }
    112 116   }
    113 117   }
    skipped 39 lines
  • ■ ■ ■ ■ ■ ■
    pkg/tunnel/grpc.go
    skipped 8 lines
    9 9   
    10 10   "google.golang.org/grpc"
    11 11   
    12  - pb "github.com/DVKunion/SeaMoon/pkg/proto"
     12 + "github.com/DVKunion/SeaMoon/pkg/service/proto"
    13 13  )
    14 14   
    15 15  type grpcConn struct {
    skipped 31 lines
    47 47  }
    48 48   
    49 49  func (c *grpcConn) Write(b []byte) (n int, err error) {
    50  - chunk := &pb.Chunk{
     50 + chunk := &proto.Chunk{
    51 51   Body: b,
    52 52   Size: int32(len(b)),
    53 53   }
    skipped 8 lines
    62 62   
    63 63  func (c *grpcConn) Close() error {
    64 64   switch cost := c.cc.(type) {
    65  - case pb.Tunnel_HttpClient:
    66  - case pb.Tunnel_Socks5Client:
     65 + case proto.Tunnel_HttpClient:
     66 + case proto.Tunnel_Socks5Client:
    67 67   return cost.CloseSend()
    68 68   }
    69 69   return nil
    skipped 26 lines
    96 96   return context.Background()
    97 97  }
    98 98   
    99  -func (c *grpcConn) send(data *pb.Chunk) error {
     99 +func (c *grpcConn) send(data *proto.Chunk) error {
    100 100   sender, ok := c.cc.(interface {
    101  - Send(*pb.Chunk) error
     101 + Send(*proto.Chunk) error
    102 102   })
    103 103   if !ok {
    104 104   // todo
    skipped 2 lines
    107 107   return sender.Send(data)
    108 108  }
    109 109   
    110  -func (c *grpcConn) recv() (*pb.Chunk, error) {
     110 +func (c *grpcConn) recv() (*proto.Chunk, error) {
    111 111   receiver, ok := c.cc.(interface {
    112  - Recv() (*pb.Chunk, error)
     112 + Recv() (*proto.Chunk, error)
    113 113   })
    114 114   if !ok {
    115 115   // todo
    skipped 5 lines
Please wait...
Page is in error, reload to recover