From 417e3431080b4c68669d415c41fd139bf0f2637f Mon Sep 17 00:00:00 2001 From: Shelikhoo Date: Thu, 11 Mar 2021 00:20:45 +0000 Subject: [PATCH 1/7] Added Loop back proxy --- proxy/lo/config.go | 3 + proxy/lo/config.pb.go | 153 +++++++++++++++++++++++++++++++++++ proxy/lo/config.proto | 11 +++ proxy/lo/errors.generated.go | 9 +++ proxy/lo/lo.go | 115 ++++++++++++++++++++++++++ 5 files changed, 291 insertions(+) create mode 100644 proxy/lo/config.go create mode 100644 proxy/lo/config.pb.go create mode 100644 proxy/lo/config.proto create mode 100644 proxy/lo/errors.generated.go create mode 100644 proxy/lo/lo.go diff --git a/proxy/lo/config.go b/proxy/lo/config.go new file mode 100644 index 0000000000..0a52088546 --- /dev/null +++ b/proxy/lo/config.go @@ -0,0 +1,3 @@ +package lo + +//go:generate go run github.com/v2fly/v2ray-core/v4/common/errors/errorgen diff --git a/proxy/lo/config.pb.go b/proxy/lo/config.pb.go new file mode 100644 index 0000000000..7e3534adf1 --- /dev/null +++ b/proxy/lo/config.pb.go @@ -0,0 +1,153 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.25.0 +// protoc v3.13.0 +// source: proxy/lo/config.proto + +package lo + +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 Config struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + InboundTag string `protobuf:"bytes,1,opt,name=inbound_tag,json=inboundTag,proto3" json:"inbound_tag,omitempty"` +} + +func (x *Config) Reset() { + *x = Config{} + if protoimpl.UnsafeEnabled { + mi := &file_proxy_lo_config_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Config) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Config) ProtoMessage() {} + +func (x *Config) ProtoReflect() protoreflect.Message { + mi := &file_proxy_lo_config_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 Config.ProtoReflect.Descriptor instead. +func (*Config) Descriptor() ([]byte, []int) { + return file_proxy_lo_config_proto_rawDescGZIP(), []int{0} +} + +func (x *Config) GetInboundTag() string { + if x != nil { + return x.InboundTag + } + return "" +} + +var File_proxy_lo_config_proto protoreflect.FileDescriptor + +var file_proxy_lo_config_proto_rawDesc = []byte{ + 0x0a, 0x15, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2f, 0x6c, 0x6f, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x69, + 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x13, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, + 0x6f, 0x72, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2e, 0x6c, 0x6f, 0x22, 0x29, 0x0a, 0x06, + 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x1f, 0x0a, 0x0b, 0x69, 0x6e, 0x62, 0x6f, 0x75, 0x6e, + 0x64, 0x5f, 0x74, 0x61, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x69, 0x6e, 0x62, + 0x6f, 0x75, 0x6e, 0x64, 0x54, 0x61, 0x67, 0x42, 0x5a, 0x0a, 0x17, 0x63, 0x6f, 0x6d, 0x2e, 0x76, + 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2e, + 0x6c, 0x6f, 0x50, 0x01, 0x5a, 0x27, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, + 0x2f, 0x76, 0x32, 0x66, 0x6c, 0x79, 0x2f, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2d, 0x63, 0x6f, 0x72, + 0x65, 0x2f, 0x76, 0x34, 0x2f, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2f, 0x6c, 0x6f, 0xaa, 0x02, 0x13, + 0x56, 0x32, 0x52, 0x61, 0x79, 0x2e, 0x43, 0x6f, 0x72, 0x65, 0x2e, 0x50, 0x72, 0x6f, 0x78, 0x79, + 0x2e, 0x4c, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_proxy_lo_config_proto_rawDescOnce sync.Once + file_proxy_lo_config_proto_rawDescData = file_proxy_lo_config_proto_rawDesc +) + +func file_proxy_lo_config_proto_rawDescGZIP() []byte { + file_proxy_lo_config_proto_rawDescOnce.Do(func() { + file_proxy_lo_config_proto_rawDescData = protoimpl.X.CompressGZIP(file_proxy_lo_config_proto_rawDescData) + }) + return file_proxy_lo_config_proto_rawDescData +} + +var file_proxy_lo_config_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_proxy_lo_config_proto_goTypes = []interface{}{ + (*Config)(nil), // 0: v2ray.core.proxy.lo.Config +} +var file_proxy_lo_config_proto_depIdxs = []int32{ + 0, // [0:0] is the sub-list for method output_type + 0, // [0:0] 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_proxy_lo_config_proto_init() } +func file_proxy_lo_config_proto_init() { + if File_proxy_lo_config_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_proxy_lo_config_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Config); 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_proxy_lo_config_proto_rawDesc, + NumEnums: 0, + NumMessages: 1, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_proxy_lo_config_proto_goTypes, + DependencyIndexes: file_proxy_lo_config_proto_depIdxs, + MessageInfos: file_proxy_lo_config_proto_msgTypes, + }.Build() + File_proxy_lo_config_proto = out.File + file_proxy_lo_config_proto_rawDesc = nil + file_proxy_lo_config_proto_goTypes = nil + file_proxy_lo_config_proto_depIdxs = nil +} diff --git a/proxy/lo/config.proto b/proxy/lo/config.proto new file mode 100644 index 0000000000..fcafdef4fc --- /dev/null +++ b/proxy/lo/config.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; + +package v2ray.core.proxy.lo; +option csharp_namespace = "V2Ray.Core.Proxy.Lo"; +option go_package = "github.com/v2fly/v2ray-core/v4/proxy/lo"; +option java_package = "com.v2ray.core.proxy.lo"; +option java_multiple_files = true; + +message Config { + string inbound_tag = 1; +} diff --git a/proxy/lo/errors.generated.go b/proxy/lo/errors.generated.go new file mode 100644 index 0000000000..131d819e28 --- /dev/null +++ b/proxy/lo/errors.generated.go @@ -0,0 +1,9 @@ +package lo + +import "github.com/v2fly/v2ray-core/v4/common/errors" + +type errPathObjHolder struct{} + +func newError(values ...interface{}) *errors.Error { + return errors.New(values...).WithPathObj(errPathObjHolder{}) +} diff --git a/proxy/lo/lo.go b/proxy/lo/lo.go new file mode 100644 index 0000000000..1a4aed761e --- /dev/null +++ b/proxy/lo/lo.go @@ -0,0 +1,115 @@ +package lo + +import ( + "context" + core "github.com/v2fly/v2ray-core/v4" + "github.com/v2fly/v2ray-core/v4/common" + "github.com/v2fly/v2ray-core/v4/common/buf" + "github.com/v2fly/v2ray-core/v4/common/net" + "github.com/v2fly/v2ray-core/v4/common/retry" + "github.com/v2fly/v2ray-core/v4/common/session" + "github.com/v2fly/v2ray-core/v4/common/task" + "github.com/v2fly/v2ray-core/v4/features/policy" + "github.com/v2fly/v2ray-core/v4/features/routing" + "github.com/v2fly/v2ray-core/v4/transport" + "github.com/v2fly/v2ray-core/v4/transport/internet" +) + +type Lo struct { + config *Config + dispatcherInstance routing.Dispatcher + policyManager policy.Manager +} + +func (l Lo) Process(ctx context.Context, link *transport.Link, dialer internet.Dialer) error { + outbound := session.OutboundFromContext(ctx) + if outbound == nil || !outbound.Target.IsValid() { + return newError("target not specified.") + } + destination := outbound.Target + + newError("opening connection to ", destination).WriteToLog(session.ExportIDToError(ctx)) + + input := link.Reader + output := link.Writer + + var conn internet.Connection + err := retry.ExponentialBackoff(5, 100).On(func() error { + dialDest := destination + + content := new(session.Content) + content.SkipDNSResolve = true + + ctx = session.ContextWithContent(ctx, content) + + inbound := session.InboundFromContext(ctx) + + inbound.Tag = l.config.InboundTag + + ctx = session.ContextWithInbound(ctx, inbound) + + rawConn, err := dialer.Dial(ctx, dialDest) + if err != nil { + return err + } + conn = rawConn + return nil + }) + if err != nil { + return newError("failed to open connection to ", destination).Base(err) + } + defer conn.Close() + + requestDone := func() error { + + var writer buf.Writer + if destination.Network == net.Network_TCP { + writer = buf.NewWriter(conn) + } else { + writer = &buf.SequentialWriter{Writer: conn} + } + + if err := buf.Copy(input, writer); err != nil { + return newError("failed to process request").Base(err) + } + + return nil + } + + responseDone := func() error { + + var reader buf.Reader + if destination.Network == net.Network_TCP { + reader = buf.NewReader(conn) + } else { + reader = buf.NewPacketReader(conn) + } + if err := buf.Copy(reader, output); err != nil { + return newError("failed to process response").Base(err) + } + + return nil + } + + if err := task.Run(ctx, requestDone, task.OnSuccess(responseDone, task.Close(output))); err != nil { + return newError("connection ends").Base(err) + } + + return nil +} + +func (l *Lo) init(config *Config, dispatcherInstance routing.Dispatcher) error { + l.dispatcherInstance = dispatcherInstance + l.config = config + return nil +} + +func init() { + common.Must(common.RegisterConfig((*Config)(nil), func(ctx context.Context, config interface{}) (interface{}, error) { + l := new(Lo) + err := core.RequireFeatures(ctx, func(dispatcherInstance routing.Dispatcher) error { + return l.init(config.(*Config), dispatcherInstance) + }) + return l, err + })) +} From 3551718b02359d2af71ceb111e9e7798c262f424 Mon Sep 17 00:00:00 2001 From: Shelikhoo Date: Thu, 11 Mar 2021 00:40:24 +0000 Subject: [PATCH 2/7] Added json processing for lo proxy --- infra/conf/lo.go | 14 ++++++++++++++ infra/conf/v2ray.go | 1 + 2 files changed, 15 insertions(+) create mode 100644 infra/conf/lo.go diff --git a/infra/conf/lo.go b/infra/conf/lo.go new file mode 100644 index 0000000000..01c9a75ee0 --- /dev/null +++ b/infra/conf/lo.go @@ -0,0 +1,14 @@ +package conf + +import ( + "github.com/golang/protobuf/proto" + "github.com/v2fly/v2ray-core/v4/proxy/lo" +) + +type LoConfig struct { + InboundTag string `json:"inboundTag"` +} + +func (l LoConfig) Build() (proto.Message, error) { + return &lo.Config{InboundTag: l.InboundTag}, nil +} diff --git a/infra/conf/v2ray.go b/infra/conf/v2ray.go index e77cfea7b5..c40f937779 100644 --- a/infra/conf/v2ray.go +++ b/infra/conf/v2ray.go @@ -36,6 +36,7 @@ var ( "trojan": func() interface{} { return new(TrojanClientConfig) }, "mtproto": func() interface{} { return new(MTProtoClientConfig) }, "dns": func() interface{} { return new(DNSOutboundConfig) }, + "lo": func() interface{} { return new(LoConfig) }, }, "protocol", "settings") ctllog = log.New(os.Stderr, "v2ctl> ", 0) From d2aa09dab4de989d8f79442d5548c3bb5924491c Mon Sep 17 00:00:00 2001 From: Shelikhoo Date: Thu, 11 Mar 2021 00:52:36 +0000 Subject: [PATCH 3/7] Fix bug for lo proxy --- proxy/lo/lo.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/proxy/lo/lo.go b/proxy/lo/lo.go index 1a4aed761e..8fe304bd5a 100644 --- a/proxy/lo/lo.go +++ b/proxy/lo/lo.go @@ -48,11 +48,19 @@ func (l Lo) Process(ctx context.Context, link *transport.Link, dialer internet.D ctx = session.ContextWithInbound(ctx, inbound) - rawConn, err := dialer.Dial(ctx, dialDest) + rawConn, err := l.dispatcherInstance.Dispatch(ctx, dialDest) if err != nil { return err } - conn = rawConn + + var readerOpt net.ConnectionOption + if dialDest.Network == net.Network_TCP { + readerOpt = net.ConnectionOutputMulti(rawConn.Reader) + } else { + readerOpt = net.ConnectionOutputMultiUDP(rawConn.Reader) + } + + conn = net.NewConnection(net.ConnectionInputMulti(rawConn.Writer), readerOpt) return nil }) if err != nil { From fb17e8f379c14c9a75275af7b9b2c624605d47ab Mon Sep 17 00:00:00 2001 From: Shelikhoo Date: Thu, 11 Mar 2021 00:55:16 +0000 Subject: [PATCH 4/7] Fix bug for lo proxy --- proxy/lo/lo.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/proxy/lo/lo.go b/proxy/lo/lo.go index 8fe304bd5a..4ecf4368c6 100644 --- a/proxy/lo/lo.go +++ b/proxy/lo/lo.go @@ -1,3 +1,5 @@ +// +build !confonly + package lo import ( From 066832969e484a4a12e8fe67b10d2bd19386aa5e Mon Sep 17 00:00:00 2001 From: Shelikhoo Date: Thu, 11 Mar 2021 17:29:39 +0000 Subject: [PATCH 5/7] rename the outbound name --- infra/conf/v2ray.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/infra/conf/v2ray.go b/infra/conf/v2ray.go index c40f937779..3935c443ce 100644 --- a/infra/conf/v2ray.go +++ b/infra/conf/v2ray.go @@ -36,7 +36,7 @@ var ( "trojan": func() interface{} { return new(TrojanClientConfig) }, "mtproto": func() interface{} { return new(MTProtoClientConfig) }, "dns": func() interface{} { return new(DNSOutboundConfig) }, - "lo": func() interface{} { return new(LoConfig) }, + "loopback": func() interface{} { return new(LoConfig) }, }, "protocol", "settings") ctllog = log.New(os.Stderr, "v2ctl> ", 0) From 02cb71e900b0d6aff05250d446253802e6b238fc Mon Sep 17 00:00:00 2001 From: kslr Date: Sat, 13 Mar 2021 08:55:10 +0800 Subject: [PATCH 6/7] Loopback: update naming and fix lint issues --- infra/conf/lo.go | 14 -------------- infra/conf/loopback.go | 14 ++++++++++++++ infra/conf/v2ray.go | 2 +- proxy/{lo => loopback}/config.go | 2 +- proxy/{lo => loopback}/config.pb.go | 2 +- proxy/{lo => loopback}/config.proto | 0 proxy/{lo => loopback}/errors.generated.go | 2 +- proxy/{lo/lo.go => loopback/lookback.go} | 9 +++------ 8 files changed, 21 insertions(+), 24 deletions(-) delete mode 100644 infra/conf/lo.go create mode 100644 infra/conf/loopback.go rename proxy/{lo => loopback}/config.go (81%) rename proxy/{lo => loopback}/config.pb.go (99%) rename proxy/{lo => loopback}/config.proto (100%) rename proxy/{lo => loopback}/errors.generated.go (92%) rename proxy/{lo/lo.go => loopback/lookback.go} (94%) diff --git a/infra/conf/lo.go b/infra/conf/lo.go deleted file mode 100644 index 01c9a75ee0..0000000000 --- a/infra/conf/lo.go +++ /dev/null @@ -1,14 +0,0 @@ -package conf - -import ( - "github.com/golang/protobuf/proto" - "github.com/v2fly/v2ray-core/v4/proxy/lo" -) - -type LoConfig struct { - InboundTag string `json:"inboundTag"` -} - -func (l LoConfig) Build() (proto.Message, error) { - return &lo.Config{InboundTag: l.InboundTag}, nil -} diff --git a/infra/conf/loopback.go b/infra/conf/loopback.go new file mode 100644 index 0000000000..0cdfaf3513 --- /dev/null +++ b/infra/conf/loopback.go @@ -0,0 +1,14 @@ +package conf + +import ( + "github.com/golang/protobuf/proto" + "github.com/v2fly/v2ray-core/v4/proxy/loopback" +) + +type LoopbackConfig struct { + InboundTag string `json:"inboundTag"` +} + +func (l LoopbackConfig) Build() (proto.Message, error) { + return &loopback.Config{InboundTag: l.InboundTag}, nil +} diff --git a/infra/conf/v2ray.go b/infra/conf/v2ray.go index 3935c443ce..55bda336d9 100644 --- a/infra/conf/v2ray.go +++ b/infra/conf/v2ray.go @@ -36,7 +36,7 @@ var ( "trojan": func() interface{} { return new(TrojanClientConfig) }, "mtproto": func() interface{} { return new(MTProtoClientConfig) }, "dns": func() interface{} { return new(DNSOutboundConfig) }, - "loopback": func() interface{} { return new(LoConfig) }, + "loopback": func() interface{} { return new(LoopbackConfig) }, }, "protocol", "settings") ctllog = log.New(os.Stderr, "v2ctl> ", 0) diff --git a/proxy/lo/config.go b/proxy/loopback/config.go similarity index 81% rename from proxy/lo/config.go rename to proxy/loopback/config.go index 0a52088546..7154fabf49 100644 --- a/proxy/lo/config.go +++ b/proxy/loopback/config.go @@ -1,3 +1,3 @@ -package lo +package loopback //go:generate go run github.com/v2fly/v2ray-core/v4/common/errors/errorgen diff --git a/proxy/lo/config.pb.go b/proxy/loopback/config.pb.go similarity index 99% rename from proxy/lo/config.pb.go rename to proxy/loopback/config.pb.go index 7e3534adf1..90ef4a509f 100644 --- a/proxy/lo/config.pb.go +++ b/proxy/loopback/config.pb.go @@ -4,7 +4,7 @@ // protoc v3.13.0 // source: proxy/lo/config.proto -package lo +package loopback import ( proto "github.com/golang/protobuf/proto" diff --git a/proxy/lo/config.proto b/proxy/loopback/config.proto similarity index 100% rename from proxy/lo/config.proto rename to proxy/loopback/config.proto diff --git a/proxy/lo/errors.generated.go b/proxy/loopback/errors.generated.go similarity index 92% rename from proxy/lo/errors.generated.go rename to proxy/loopback/errors.generated.go index 131d819e28..d8b24536de 100644 --- a/proxy/lo/errors.generated.go +++ b/proxy/loopback/errors.generated.go @@ -1,4 +1,4 @@ -package lo +package loopback import "github.com/v2fly/v2ray-core/v4/common/errors" diff --git a/proxy/lo/lo.go b/proxy/loopback/lookback.go similarity index 94% rename from proxy/lo/lo.go rename to proxy/loopback/lookback.go index 4ecf4368c6..87996a63e1 100644 --- a/proxy/lo/lo.go +++ b/proxy/loopback/lookback.go @@ -1,9 +1,10 @@ // +build !confonly -package lo +package loopback import ( "context" + core "github.com/v2fly/v2ray-core/v4" "github.com/v2fly/v2ray-core/v4/common" "github.com/v2fly/v2ray-core/v4/common/buf" @@ -11,7 +12,6 @@ import ( "github.com/v2fly/v2ray-core/v4/common/retry" "github.com/v2fly/v2ray-core/v4/common/session" "github.com/v2fly/v2ray-core/v4/common/task" - "github.com/v2fly/v2ray-core/v4/features/policy" "github.com/v2fly/v2ray-core/v4/features/routing" "github.com/v2fly/v2ray-core/v4/transport" "github.com/v2fly/v2ray-core/v4/transport/internet" @@ -20,10 +20,9 @@ import ( type Lo struct { config *Config dispatcherInstance routing.Dispatcher - policyManager policy.Manager } -func (l Lo) Process(ctx context.Context, link *transport.Link, dialer internet.Dialer) error { +func (l Lo) Process(ctx context.Context, link *transport.Link, _ internet.Dialer) error { outbound := session.OutboundFromContext(ctx) if outbound == nil || !outbound.Target.IsValid() { return newError("target not specified.") @@ -71,7 +70,6 @@ func (l Lo) Process(ctx context.Context, link *transport.Link, dialer internet.D defer conn.Close() requestDone := func() error { - var writer buf.Writer if destination.Network == net.Network_TCP { writer = buf.NewWriter(conn) @@ -87,7 +85,6 @@ func (l Lo) Process(ctx context.Context, link *transport.Link, dialer internet.D } responseDone := func() error { - var reader buf.Reader if destination.Network == net.Network_TCP { reader = buf.NewReader(conn) From dbc48ac48a89372c4c3a7ba1aac47b33cef61f29 Mon Sep 17 00:00:00 2001 From: loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com> Date: Sat, 13 Mar 2021 12:47:50 +0800 Subject: [PATCH 7/7] Chore: change lo to loopback --- proxy/loopback/config.pb.go | 82 +++++++++++++++++++------------------ proxy/loopback/config.proto | 8 ++-- proxy/loopback/lookback.go | 8 ++-- 3 files changed, 50 insertions(+), 48 deletions(-) diff --git a/proxy/loopback/config.pb.go b/proxy/loopback/config.pb.go index 90ef4a509f..dbef555fc8 100644 --- a/proxy/loopback/config.pb.go +++ b/proxy/loopback/config.pb.go @@ -1,8 +1,8 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.25.0 -// protoc v3.13.0 -// source: proxy/lo/config.proto +// protoc v3.15.5 +// source: proxy/loopback/config.proto package loopback @@ -36,7 +36,7 @@ type Config struct { func (x *Config) Reset() { *x = Config{} if protoimpl.UnsafeEnabled { - mi := &file_proxy_lo_config_proto_msgTypes[0] + mi := &file_proxy_loopback_config_proto_msgTypes[0] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -49,7 +49,7 @@ func (x *Config) String() string { func (*Config) ProtoMessage() {} func (x *Config) ProtoReflect() protoreflect.Message { - mi := &file_proxy_lo_config_proto_msgTypes[0] + mi := &file_proxy_loopback_config_proto_msgTypes[0] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -62,7 +62,7 @@ func (x *Config) ProtoReflect() protoreflect.Message { // Deprecated: Use Config.ProtoReflect.Descriptor instead. func (*Config) Descriptor() ([]byte, []int) { - return file_proxy_lo_config_proto_rawDescGZIP(), []int{0} + return file_proxy_loopback_config_proto_rawDescGZIP(), []int{0} } func (x *Config) GetInboundTag() string { @@ -72,40 +72,42 @@ func (x *Config) GetInboundTag() string { return "" } -var File_proxy_lo_config_proto protoreflect.FileDescriptor +var File_proxy_loopback_config_proto protoreflect.FileDescriptor -var file_proxy_lo_config_proto_rawDesc = []byte{ - 0x0a, 0x15, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2f, 0x6c, 0x6f, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x69, - 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x13, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, - 0x6f, 0x72, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2e, 0x6c, 0x6f, 0x22, 0x29, 0x0a, 0x06, - 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x1f, 0x0a, 0x0b, 0x69, 0x6e, 0x62, 0x6f, 0x75, 0x6e, - 0x64, 0x5f, 0x74, 0x61, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x69, 0x6e, 0x62, - 0x6f, 0x75, 0x6e, 0x64, 0x54, 0x61, 0x67, 0x42, 0x5a, 0x0a, 0x17, 0x63, 0x6f, 0x6d, 0x2e, 0x76, +var file_proxy_loopback_config_proto_rawDesc = []byte{ + 0x0a, 0x1b, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2f, 0x6c, 0x6f, 0x6f, 0x70, 0x62, 0x61, 0x63, 0x6b, + 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x19, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2e, - 0x6c, 0x6f, 0x50, 0x01, 0x5a, 0x27, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, - 0x2f, 0x76, 0x32, 0x66, 0x6c, 0x79, 0x2f, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2d, 0x63, 0x6f, 0x72, - 0x65, 0x2f, 0x76, 0x34, 0x2f, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2f, 0x6c, 0x6f, 0xaa, 0x02, 0x13, - 0x56, 0x32, 0x52, 0x61, 0x79, 0x2e, 0x43, 0x6f, 0x72, 0x65, 0x2e, 0x50, 0x72, 0x6f, 0x78, 0x79, - 0x2e, 0x4c, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x6c, 0x6f, 0x6f, 0x70, 0x62, 0x61, 0x63, 0x6b, 0x22, 0x29, 0x0a, 0x06, 0x43, 0x6f, 0x6e, 0x66, + 0x69, 0x67, 0x12, 0x1f, 0x0a, 0x0b, 0x69, 0x6e, 0x62, 0x6f, 0x75, 0x6e, 0x64, 0x5f, 0x74, 0x61, + 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x69, 0x6e, 0x62, 0x6f, 0x75, 0x6e, 0x64, + 0x54, 0x61, 0x67, 0x42, 0x6c, 0x0a, 0x1d, 0x63, 0x6f, 0x6d, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, + 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2e, 0x6c, 0x6f, 0x6f, 0x70, + 0x62, 0x61, 0x63, 0x6b, 0x50, 0x01, 0x5a, 0x2d, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, + 0x6f, 0x6d, 0x2f, 0x76, 0x32, 0x66, 0x6c, 0x79, 0x2f, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2d, 0x63, + 0x6f, 0x72, 0x65, 0x2f, 0x76, 0x34, 0x2f, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2f, 0x6c, 0x6f, 0x6f, + 0x70, 0x62, 0x61, 0x63, 0x6b, 0xaa, 0x02, 0x19, 0x56, 0x32, 0x52, 0x61, 0x79, 0x2e, 0x43, 0x6f, + 0x72, 0x65, 0x2e, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x2e, 0x4c, 0x6f, 0x6f, 0x70, 0x62, 0x61, 0x63, + 0x6b, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( - file_proxy_lo_config_proto_rawDescOnce sync.Once - file_proxy_lo_config_proto_rawDescData = file_proxy_lo_config_proto_rawDesc + file_proxy_loopback_config_proto_rawDescOnce sync.Once + file_proxy_loopback_config_proto_rawDescData = file_proxy_loopback_config_proto_rawDesc ) -func file_proxy_lo_config_proto_rawDescGZIP() []byte { - file_proxy_lo_config_proto_rawDescOnce.Do(func() { - file_proxy_lo_config_proto_rawDescData = protoimpl.X.CompressGZIP(file_proxy_lo_config_proto_rawDescData) +func file_proxy_loopback_config_proto_rawDescGZIP() []byte { + file_proxy_loopback_config_proto_rawDescOnce.Do(func() { + file_proxy_loopback_config_proto_rawDescData = protoimpl.X.CompressGZIP(file_proxy_loopback_config_proto_rawDescData) }) - return file_proxy_lo_config_proto_rawDescData + return file_proxy_loopback_config_proto_rawDescData } -var file_proxy_lo_config_proto_msgTypes = make([]protoimpl.MessageInfo, 1) -var file_proxy_lo_config_proto_goTypes = []interface{}{ - (*Config)(nil), // 0: v2ray.core.proxy.lo.Config +var file_proxy_loopback_config_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_proxy_loopback_config_proto_goTypes = []interface{}{ + (*Config)(nil), // 0: v2ray.core.proxy.loopback.Config } -var file_proxy_lo_config_proto_depIdxs = []int32{ +var file_proxy_loopback_config_proto_depIdxs = []int32{ 0, // [0:0] is the sub-list for method output_type 0, // [0:0] is the sub-list for method input_type 0, // [0:0] is the sub-list for extension type_name @@ -113,13 +115,13 @@ var file_proxy_lo_config_proto_depIdxs = []int32{ 0, // [0:0] is the sub-list for field type_name } -func init() { file_proxy_lo_config_proto_init() } -func file_proxy_lo_config_proto_init() { - if File_proxy_lo_config_proto != nil { +func init() { file_proxy_loopback_config_proto_init() } +func file_proxy_loopback_config_proto_init() { + if File_proxy_loopback_config_proto != nil { return } if !protoimpl.UnsafeEnabled { - file_proxy_lo_config_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + file_proxy_loopback_config_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*Config); i { case 0: return &v.state @@ -136,18 +138,18 @@ func file_proxy_lo_config_proto_init() { out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_proxy_lo_config_proto_rawDesc, + RawDescriptor: file_proxy_loopback_config_proto_rawDesc, NumEnums: 0, NumMessages: 1, NumExtensions: 0, NumServices: 0, }, - GoTypes: file_proxy_lo_config_proto_goTypes, - DependencyIndexes: file_proxy_lo_config_proto_depIdxs, - MessageInfos: file_proxy_lo_config_proto_msgTypes, + GoTypes: file_proxy_loopback_config_proto_goTypes, + DependencyIndexes: file_proxy_loopback_config_proto_depIdxs, + MessageInfos: file_proxy_loopback_config_proto_msgTypes, }.Build() - File_proxy_lo_config_proto = out.File - file_proxy_lo_config_proto_rawDesc = nil - file_proxy_lo_config_proto_goTypes = nil - file_proxy_lo_config_proto_depIdxs = nil + File_proxy_loopback_config_proto = out.File + file_proxy_loopback_config_proto_rawDesc = nil + file_proxy_loopback_config_proto_goTypes = nil + file_proxy_loopback_config_proto_depIdxs = nil } diff --git a/proxy/loopback/config.proto b/proxy/loopback/config.proto index fcafdef4fc..0964ab0e76 100644 --- a/proxy/loopback/config.proto +++ b/proxy/loopback/config.proto @@ -1,9 +1,9 @@ syntax = "proto3"; -package v2ray.core.proxy.lo; -option csharp_namespace = "V2Ray.Core.Proxy.Lo"; -option go_package = "github.com/v2fly/v2ray-core/v4/proxy/lo"; -option java_package = "com.v2ray.core.proxy.lo"; +package v2ray.core.proxy.loopback; +option csharp_namespace = "V2Ray.Core.Proxy.Loopback"; +option go_package = "github.com/v2fly/v2ray-core/v4/proxy/loopback"; +option java_package = "com.v2ray.core.proxy.loopback"; option java_multiple_files = true; message Config { diff --git a/proxy/loopback/lookback.go b/proxy/loopback/lookback.go index 87996a63e1..5691f5607f 100644 --- a/proxy/loopback/lookback.go +++ b/proxy/loopback/lookback.go @@ -17,12 +17,12 @@ import ( "github.com/v2fly/v2ray-core/v4/transport/internet" ) -type Lo struct { +type Loopback struct { config *Config dispatcherInstance routing.Dispatcher } -func (l Lo) Process(ctx context.Context, link *transport.Link, _ internet.Dialer) error { +func (l *Loopback) Process(ctx context.Context, link *transport.Link, _ internet.Dialer) error { outbound := session.OutboundFromContext(ctx) if outbound == nil || !outbound.Target.IsValid() { return newError("target not specified.") @@ -105,7 +105,7 @@ func (l Lo) Process(ctx context.Context, link *transport.Link, _ internet.Dialer return nil } -func (l *Lo) init(config *Config, dispatcherInstance routing.Dispatcher) error { +func (l *Loopback) init(config *Config, dispatcherInstance routing.Dispatcher) error { l.dispatcherInstance = dispatcherInstance l.config = config return nil @@ -113,7 +113,7 @@ func (l *Lo) init(config *Config, dispatcherInstance routing.Dispatcher) error { func init() { common.Must(common.RegisterConfig((*Config)(nil), func(ctx context.Context, config interface{}) (interface{}, error) { - l := new(Lo) + l := new(Loopback) err := core.RequireFeatures(ctx, func(dispatcherInstance routing.Dispatcher) error { return l.init(config.(*Config), dispatcherInstance) })