From 65ae2b77d51de5ca5a6ff3200d7f3dcce0480913 Mon Sep 17 00:00:00 2001 From: yuzuki999 Date: Sun, 4 Sep 2022 20:32:56 +0800 Subject: [PATCH] update dispatcher and distro --- api/panel/node.go | 1 - core/app/dispatcher/config.pb.go | 106 +++++++++++++------------- core/app/dispatcher/config.proto | 8 +- core/app/dispatcher/default.go | 64 ++++------------ core/app/dispatcher/dispatcher.go | 1 - core/app/dispatcher/fakednssniffer.go | 5 +- core/app/dispatcher/limiter.go | 1 - core/app/dispatcher/rule.go | 1 - core/app/dispatcher/sniffer.go | 15 ++-- core/distro/all/all.go | 37 ++++++--- go.mod | 2 +- main.go | 2 +- node/node.go | 2 - 13 files changed, 115 insertions(+), 130 deletions(-) diff --git a/api/panel/node.go b/api/panel/node.go index 3e37f92..22c4a08 100644 --- a/api/panel/node.go +++ b/api/panel/node.go @@ -49,7 +49,6 @@ func readLocalRuleList(path string) (LocalRuleList []DetectRule) { log.Fatalf("Error while reading file: %s", err) return []DetectRule{} } - file.Close() } return LocalRuleList diff --git a/core/app/dispatcher/config.pb.go b/core/app/dispatcher/config.pb.go index dfe83f0..2a22953 100644 --- a/core/app/dispatcher/config.pb.go +++ b/core/app/dispatcher/config.pb.go @@ -1,8 +1,8 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.28.0 -// protoc v3.19.4 -// source: app/mydispatcher/config.proto +// protoc-gen-go v1.28.1 +// protoc v3.21.5 +// source: config.proto package dispatcher @@ -29,7 +29,7 @@ type SessionConfig struct { func (x *SessionConfig) Reset() { *x = SessionConfig{} if protoimpl.UnsafeEnabled { - mi := &file_app_mydispatcher_config_proto_msgTypes[0] + mi := &file_config_proto_msgTypes[0] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -42,7 +42,7 @@ func (x *SessionConfig) String() string { func (*SessionConfig) ProtoMessage() {} func (x *SessionConfig) ProtoReflect() protoreflect.Message { - mi := &file_app_mydispatcher_config_proto_msgTypes[0] + mi := &file_config_proto_msgTypes[0] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -55,7 +55,7 @@ func (x *SessionConfig) ProtoReflect() protoreflect.Message { // Deprecated: Use SessionConfig.ProtoReflect.Descriptor instead. func (*SessionConfig) Descriptor() ([]byte, []int) { - return file_app_mydispatcher_config_proto_rawDescGZIP(), []int{0} + return file_config_proto_rawDescGZIP(), []int{0} } type Config struct { @@ -69,7 +69,7 @@ type Config struct { func (x *Config) Reset() { *x = Config{} if protoimpl.UnsafeEnabled { - mi := &file_app_mydispatcher_config_proto_msgTypes[1] + mi := &file_config_proto_msgTypes[1] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -82,7 +82,7 @@ func (x *Config) String() string { func (*Config) ProtoMessage() {} func (x *Config) ProtoReflect() protoreflect.Message { - mi := &file_app_mydispatcher_config_proto_msgTypes[1] + mi := &file_config_proto_msgTypes[1] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -95,7 +95,7 @@ func (x *Config) ProtoReflect() protoreflect.Message { // Deprecated: Use Config.ProtoReflect.Descriptor instead. func (*Config) Descriptor() ([]byte, []int) { - return file_app_mydispatcher_config_proto_rawDescGZIP(), []int{1} + return file_config_proto_rawDescGZIP(), []int{1} } func (x *Config) GetSettings() *SessionConfig { @@ -105,47 +105,47 @@ func (x *Config) GetSettings() *SessionConfig { return nil } -var File_app_mydispatcher_config_proto protoreflect.FileDescriptor +var File_config_proto protoreflect.FileDescriptor -var file_app_mydispatcher_config_proto_rawDesc = []byte{ - 0x0a, 0x1d, 0x61, 0x70, 0x70, 0x2f, 0x6d, 0x79, 0x64, 0x69, 0x73, 0x70, 0x61, 0x74, 0x63, 0x68, - 0x65, 0x72, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, - 0x16, 0x78, 0x72, 0x61, 0x79, 0x72, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x6d, 0x79, 0x64, 0x69, 0x73, - 0x70, 0x61, 0x74, 0x63, 0x68, 0x65, 0x72, 0x22, 0x15, 0x0a, 0x0d, 0x53, 0x65, 0x73, 0x73, 0x69, - 0x6f, 0x6e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x4a, 0x04, 0x08, 0x01, 0x10, 0x02, 0x22, 0x4b, - 0x0a, 0x06, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x41, 0x0a, 0x08, 0x73, 0x65, 0x74, 0x74, - 0x69, 0x6e, 0x67, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x25, 0x2e, 0x78, 0x72, 0x61, - 0x79, 0x72, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x6d, 0x79, 0x64, 0x69, 0x73, 0x70, 0x61, 0x74, 0x63, - 0x68, 0x65, 0x72, 0x2e, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x43, 0x6f, 0x6e, 0x66, 0x69, - 0x67, 0x52, 0x08, 0x73, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x42, 0x67, 0x0a, 0x1a, 0x63, - 0x6f, 0x6d, 0x2e, 0x78, 0x72, 0x61, 0x79, 0x72, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x6d, 0x79, 0x64, - 0x69, 0x73, 0x70, 0x61, 0x74, 0x63, 0x68, 0x65, 0x72, 0x50, 0x01, 0x5a, 0x2f, 0x67, 0x69, 0x74, - 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x58, 0x72, 0x61, 0x79, 0x52, 0x2d, 0x70, 0x72, - 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x2f, 0x58, 0x72, 0x61, 0x79, 0x52, 0x2f, 0x61, 0x70, 0x70, 0x2f, - 0x6d, 0x79, 0x64, 0x69, 0x73, 0x70, 0x61, 0x74, 0x63, 0x68, 0x65, 0x72, 0xaa, 0x02, 0x15, 0x58, - 0x72, 0x61, 0x79, 0x52, 0x2e, 0x41, 0x70, 0x70, 0x2e, 0x4d, 0x79, 0x69, 0x73, 0x70, 0x61, 0x74, - 0x63, 0x68, 0x65, 0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +var file_config_proto_rawDesc = []byte{ + 0x0a, 0x0c, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x18, + 0x76, 0x32, 0x62, 0x78, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x64, 0x69, + 0x73, 0x70, 0x61, 0x74, 0x63, 0x68, 0x65, 0x72, 0x22, 0x15, 0x0a, 0x0d, 0x53, 0x65, 0x73, 0x73, + 0x69, 0x6f, 0x6e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x4a, 0x04, 0x08, 0x01, 0x10, 0x02, 0x22, + 0x4d, 0x0a, 0x06, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x43, 0x0a, 0x08, 0x73, 0x65, 0x74, + 0x74, 0x69, 0x6e, 0x67, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x27, 0x2e, 0x76, 0x32, + 0x62, 0x78, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x64, 0x69, 0x73, 0x70, + 0x61, 0x74, 0x63, 0x68, 0x65, 0x72, 0x2e, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x43, 0x6f, + 0x6e, 0x66, 0x69, 0x67, 0x52, 0x08, 0x73, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x42, 0x6a, + 0x0a, 0x1c, 0x63, 0x6f, 0x6d, 0x2e, 0x76, 0x32, 0x62, 0x78, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, + 0x61, 0x70, 0x70, 0x2e, 0x64, 0x69, 0x73, 0x70, 0x61, 0x74, 0x63, 0x68, 0x65, 0x72, 0x50, 0x01, + 0x5a, 0x2d, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x59, 0x75, 0x7a, + 0x75, 0x6b, 0x69, 0x36, 0x31, 0x36, 0x2f, 0x56, 0x32, 0x62, 0x58, 0x2f, 0x63, 0x6f, 0x72, 0x65, + 0x2f, 0x61, 0x70, 0x70, 0x2f, 0x64, 0x69, 0x73, 0x70, 0x61, 0x74, 0x63, 0x68, 0x65, 0x72, 0xaa, + 0x02, 0x18, 0x56, 0x32, 0x62, 0x58, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x61, 0x70, 0x70, 0x2e, + 0x64, 0x69, 0x73, 0x70, 0x61, 0x74, 0x63, 0x68, 0x65, 0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x33, } var ( - file_app_mydispatcher_config_proto_rawDescOnce sync.Once - file_app_mydispatcher_config_proto_rawDescData = file_app_mydispatcher_config_proto_rawDesc + file_config_proto_rawDescOnce sync.Once + file_config_proto_rawDescData = file_config_proto_rawDesc ) -func file_app_mydispatcher_config_proto_rawDescGZIP() []byte { - file_app_mydispatcher_config_proto_rawDescOnce.Do(func() { - file_app_mydispatcher_config_proto_rawDescData = protoimpl.X.CompressGZIP(file_app_mydispatcher_config_proto_rawDescData) +func file_config_proto_rawDescGZIP() []byte { + file_config_proto_rawDescOnce.Do(func() { + file_config_proto_rawDescData = protoimpl.X.CompressGZIP(file_config_proto_rawDescData) }) - return file_app_mydispatcher_config_proto_rawDescData + return file_config_proto_rawDescData } -var file_app_mydispatcher_config_proto_msgTypes = make([]protoimpl.MessageInfo, 2) -var file_app_mydispatcher_config_proto_goTypes = []interface{}{ - (*SessionConfig)(nil), // 0: xrayr.app.mydispatcher.SessionConfig - (*Config)(nil), // 1: xrayr.app.mydispatcher.Config +var file_config_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_config_proto_goTypes = []interface{}{ + (*SessionConfig)(nil), // 0: v2bx.core.app.dispatcher.SessionConfig + (*Config)(nil), // 1: v2bx.core.app.dispatcher.Config } -var file_app_mydispatcher_config_proto_depIdxs = []int32{ - 0, // 0: xrayr.app.mydispatcher.Config.settings:type_name -> xrayr.app.mydispatcher.SessionConfig +var file_config_proto_depIdxs = []int32{ + 0, // 0: v2bx.core.app.dispatcher.Config.settings:type_name -> v2bx.core.app.dispatcher.SessionConfig 1, // [1:1] is the sub-list for method output_type 1, // [1:1] is the sub-list for method input_type 1, // [1:1] is the sub-list for extension type_name @@ -153,13 +153,13 @@ var file_app_mydispatcher_config_proto_depIdxs = []int32{ 0, // [0:1] is the sub-list for field type_name } -func init() { file_app_mydispatcher_config_proto_init() } -func file_app_mydispatcher_config_proto_init() { - if File_app_mydispatcher_config_proto != nil { +func init() { file_config_proto_init() } +func file_config_proto_init() { + if File_config_proto != nil { return } if !protoimpl.UnsafeEnabled { - file_app_mydispatcher_config_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + file_config_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*SessionConfig); i { case 0: return &v.state @@ -171,7 +171,7 @@ func file_app_mydispatcher_config_proto_init() { return nil } } - file_app_mydispatcher_config_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + file_config_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*Config); i { case 0: return &v.state @@ -188,18 +188,18 @@ func file_app_mydispatcher_config_proto_init() { out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_app_mydispatcher_config_proto_rawDesc, + RawDescriptor: file_config_proto_rawDesc, NumEnums: 0, NumMessages: 2, NumExtensions: 0, NumServices: 0, }, - GoTypes: file_app_mydispatcher_config_proto_goTypes, - DependencyIndexes: file_app_mydispatcher_config_proto_depIdxs, - MessageInfos: file_app_mydispatcher_config_proto_msgTypes, + GoTypes: file_config_proto_goTypes, + DependencyIndexes: file_config_proto_depIdxs, + MessageInfos: file_config_proto_msgTypes, }.Build() - File_app_mydispatcher_config_proto = out.File - file_app_mydispatcher_config_proto_rawDesc = nil - file_app_mydispatcher_config_proto_goTypes = nil - file_app_mydispatcher_config_proto_depIdxs = nil + File_config_proto = out.File + file_config_proto_rawDesc = nil + file_config_proto_goTypes = nil + file_config_proto_depIdxs = nil } diff --git a/core/app/dispatcher/config.proto b/core/app/dispatcher/config.proto index 26b1464..0c49432 100644 --- a/core/app/dispatcher/config.proto +++ b/core/app/dispatcher/config.proto @@ -1,9 +1,9 @@ syntax = "proto3"; -package xrayr.app.mydispatcher; -option csharp_namespace = "XrayR.App.Myispatcher"; -option go_package = "github.com/Yuzuki616/V2bX/app/mydispatcher"; -option java_package = "com.xrayr.app.mydispatcher"; +package v2bx.core.app.dispatcher; +option csharp_namespace = "V2bX.core.app.dispatcher"; +option go_package = "github.com/Yuzuki616/V2bX/core/app/dispatcher"; +option java_package = "com.v2bx.core.app.dispatcher"; option java_multiple_files = true; message SessionConfig { diff --git a/core/app/dispatcher/default.go b/core/app/dispatcher/default.go index 69ff0b0..176faef 100644 --- a/core/app/dispatcher/default.go +++ b/core/app/dispatcher/default.go @@ -16,7 +16,7 @@ import ( "github.com/xtls/xray-core/features/outbound" "github.com/xtls/xray-core/features/policy" "github.com/xtls/xray-core/features/routing" - routing_session "github.com/xtls/xray-core/features/routing/session" + routingSession "github.com/xtls/xray-core/features/routing/session" "github.com/xtls/xray-core/features/stats" "github.com/xtls/xray-core/transport" "github.com/xtls/xray-core/transport/pipe" @@ -119,9 +119,9 @@ func (d *DefaultDispatcher) Init(config *Config, om outbound.Manager, router rou d.router = router d.policy = pm d.stats = sm + d.dns = dns d.Limiter = NewLimiter() d.RuleManager = NewRule() - d.dns = dns return nil } @@ -169,7 +169,7 @@ func (d *DefaultDispatcher) getLink(ctx context.Context, network net.Network, sn newError("[fakedns client] create a new map").WriteToLog(session.ExportIDToError(ctx)) } domain := addr.Domain() - ips, err := d.dns.LookupIP(domain, dns.IPOption{true, true, false}) + ips, err := d.dns.LookupIP(domain, dns.IPOption{IPv4Enable: true, IPv6Enable: true}) if err == nil { for _, ip := range ips { ip2domain.Store(ip.String(), domain) @@ -261,12 +261,14 @@ func (d *DefaultDispatcher) getLink(ctx context.Context, network net.Network, sn } } } - return inboundLink, outboundLink, nil } func (d *DefaultDispatcher) shouldOverride(ctx context.Context, result SniffResult, request session.SniffingRequest, destination net.Destination) bool { domain := result.Domain() + if domain == "" { + return false + } for _, d := range request.ExcludeForDomain { if strings.ToLower(domain) == d { return false @@ -315,33 +317,15 @@ func (d *DefaultDispatcher) Dispatch(ctx context.Context, destination net.Destin if err != nil { return nil, err } - switch { - case !sniffingRequest.Enabled: + if !sniffingRequest.Enabled { go d.routedDispatch(ctx, outbound, destination, "") - case destination.Network != net.Network_TCP: - // Only metadata sniff will be used for non tcp connection - result, err := sniffer(ctx, nil, true) - if err == nil { - content.Protocol = result.Protocol() - if d.shouldOverride(ctx, result, sniffingRequest, destination) { - domain := result.Domain() - newError("sniffed domain: ", domain).WriteToLog(session.ExportIDToError(ctx)) - destination.Address = net.ParseAddress(domain) - if sniffingRequest.RouteOnly && result.Protocol() != "fakedns" { - ob.RouteTarget = destination - } else { - ob.Target = destination - } - } - } - go d.routedDispatch(ctx, outbound, destination, content.Protocol) - default: + } else { go func() { cReader := &cachedReader{ reader: outbound.Reader.(*pipe.Reader), } outbound.Reader = cReader - result, err := sniffer(ctx, cReader, sniffingRequest.MetadataOnly) + result, err := sniffer(ctx, cReader, sniffingRequest.MetadataOnly, destination.Network) if err == nil { content.Protocol = result.Protocol() } @@ -376,33 +360,15 @@ func (d *DefaultDispatcher) DispatchLink(ctx context.Context, destination net.De ctx = session.ContextWithContent(ctx, content) } sniffingRequest := content.SniffingRequest - switch { - case !sniffingRequest.Enabled: - go d.routedDispatch(ctx, outbound, destination, "") - case destination.Network != net.Network_TCP: - // Only metadata sniff will be used for non tcp connection - result, err := sniffer(ctx, nil, true) - if err == nil { - content.Protocol = result.Protocol() - if d.shouldOverride(ctx, result, sniffingRequest, destination) { - domain := result.Domain() - newError("sniffed domain: ", domain).WriteToLog(session.ExportIDToError(ctx)) - destination.Address = net.ParseAddress(domain) - if sniffingRequest.RouteOnly && result.Protocol() != "fakedns" { - ob.RouteTarget = destination - } else { - ob.Target = destination - } - } - } + if !sniffingRequest.Enabled { go d.routedDispatch(ctx, outbound, destination, content.Protocol) - default: + } else { go func() { cReader := &cachedReader{ reader: outbound.Reader.(*pipe.Reader), } outbound.Reader = cReader - result, err := sniffer(ctx, cReader, sniffingRequest.MetadataOnly) + result, err := sniffer(ctx, cReader, sniffingRequest.MetadataOnly, destination.Network) if err == nil { content.Protocol = result.Protocol() } @@ -422,7 +388,7 @@ func (d *DefaultDispatcher) DispatchLink(ctx context.Context, destination net.De return nil } -func sniffer(ctx context.Context, cReader *cachedReader, metadataOnly bool) (SniffResult, error) { +func sniffer(ctx context.Context, cReader *cachedReader, metadataOnly bool, network net.Network) (SniffResult, error) { payload := buf.New() defer payload.Release() @@ -448,7 +414,7 @@ func sniffer(ctx context.Context, cReader *cachedReader, metadataOnly bool) (Sni cReader.Cache(payload) if !payload.IsEmpty() { - result, err := sniffer.Sniff(ctx, payload.Bytes()) + result, err := sniffer.Sniff(ctx, payload.Bytes(), network) if err != common.ErrNoClue { return result, err } @@ -505,7 +471,7 @@ func (d *DefaultDispatcher) routedDispatch(ctx context.Context, link *transport. } } - routingLink := routing_session.AsRoutingContext(ctx) + routingLink := routingSession.AsRoutingContext(ctx) inTag := routingLink.GetInboundTag() isPickRoute := 0 if forcedOutboundTag := session.GetForcedOutboundTagFromContext(ctx); forcedOutboundTag != "" { diff --git a/core/app/dispatcher/dispatcher.go b/core/app/dispatcher/dispatcher.go index 29b954c..2ae48c8 100644 --- a/core/app/dispatcher/dispatcher.go +++ b/core/app/dispatcher/dispatcher.go @@ -1,4 +1,3 @@ -// Package dispather implement the rate limiter and the onlie device counter package dispatcher //go:generate go run github.com/xtls/xray-core/common/errors/errorgen diff --git a/core/app/dispatcher/fakednssniffer.go b/core/app/dispatcher/fakednssniffer.go index d6bbd63..ad879da 100644 --- a/core/app/dispatcher/fakednssniffer.go +++ b/core/app/dispatcher/fakednssniffer.go @@ -11,7 +11,7 @@ import ( "github.com/xtls/xray-core/features/dns" ) -// newFakeDNSSniffer Create a Fake DNS metadata sniffer +// newFakeDNSSniffer Creates a Fake DNS metadata sniffer func newFakeDNSSniffer(ctx context.Context) (protocolSnifferWithMetadata, error) { var fakeDNSEngine dns.FakeDNSEngine { @@ -85,7 +85,8 @@ func (f DNSThenOthersSniffResult) Domain() string { } func newFakeDNSThenOthers(ctx context.Context, fakeDNSSniffer protocolSnifferWithMetadata, others []protocolSnifferWithMetadata) ( - protocolSnifferWithMetadata, error) { // nolint: unparam + protocolSnifferWithMetadata, error, +) { // nolint: unparam // ctx may be used in the future _ = ctx return protocolSnifferWithMetadata{ diff --git a/core/app/dispatcher/limiter.go b/core/app/dispatcher/limiter.go index fbc1830..1996b1a 100644 --- a/core/app/dispatcher/limiter.go +++ b/core/app/dispatcher/limiter.go @@ -1,4 +1,3 @@ -// Package limiter is to control the links that go into the dispather package dispatcher import ( diff --git a/core/app/dispatcher/rule.go b/core/app/dispatcher/rule.go index 91e8ea8..d6bef83 100644 --- a/core/app/dispatcher/rule.go +++ b/core/app/dispatcher/rule.go @@ -1,4 +1,3 @@ -// Package rule is to control the audit rule behaviors package dispatcher import ( diff --git a/core/app/dispatcher/sniffer.go b/core/app/dispatcher/sniffer.go index 4cb8304..e23277a 100644 --- a/core/app/dispatcher/sniffer.go +++ b/core/app/dispatcher/sniffer.go @@ -4,8 +4,10 @@ import ( "context" "github.com/xtls/xray-core/common" + "github.com/xtls/xray-core/common/net" "github.com/xtls/xray-core/common/protocol/bittorrent" "github.com/xtls/xray-core/common/protocol/http" + "github.com/xtls/xray-core/common/protocol/quic" "github.com/xtls/xray-core/common/protocol/tls" ) @@ -22,6 +24,7 @@ type protocolSnifferWithMetadata struct { // for both TCP and UDP connections // It will not be shown as a traffic type for routing unless there is no other successful sniffing. metadataSniffer bool + network net.Network } type Sniffer struct { @@ -31,9 +34,11 @@ type Sniffer struct { func NewSniffer(ctx context.Context) *Sniffer { ret := &Sniffer{ sniffer: []protocolSnifferWithMetadata{ - {func(c context.Context, b []byte) (SniffResult, error) { return http.SniffHTTP(b) }, false}, - {func(c context.Context, b []byte) (SniffResult, error) { return tls.SniffTLS(b) }, false}, - {func(c context.Context, b []byte) (SniffResult, error) { return bittorrent.SniffBittorrent(b) }, false}, + {func(c context.Context, b []byte) (SniffResult, error) { return http.SniffHTTP(b) }, false, net.Network_TCP}, + {func(c context.Context, b []byte) (SniffResult, error) { return tls.SniffTLS(b) }, false, net.Network_TCP}, + {func(c context.Context, b []byte) (SniffResult, error) { return bittorrent.SniffBittorrent(b) }, false, net.Network_TCP}, + {func(c context.Context, b []byte) (SniffResult, error) { return quic.SniffQUIC(b) }, false, net.Network_UDP}, + {func(c context.Context, b []byte) (SniffResult, error) { return bittorrent.SniffUTP(b) }, false, net.Network_UDP}, }, } if sniffer, err := newFakeDNSSniffer(ctx); err == nil { @@ -49,11 +54,11 @@ func NewSniffer(ctx context.Context) *Sniffer { var errUnknownContent = newError("unknown content") -func (s *Sniffer) Sniff(c context.Context, payload []byte) (SniffResult, error) { +func (s *Sniffer) Sniff(c context.Context, payload []byte, network net.Network) (SniffResult, error) { var pendingSniffer []protocolSnifferWithMetadata for _, si := range s.sniffer { s := si.protocolSniffer - if si.metadataSniffer { + if si.metadataSniffer || si.network != network { continue } result, err := s(c, payload) diff --git a/core/distro/all/all.go b/core/distro/all/all.go index 86d75b6..7c4a999 100644 --- a/core/distro/all/all.go +++ b/core/distro/all/all.go @@ -3,20 +3,24 @@ package all import ( // The following are necessary as they register handlers in their init functions. - // Required features. Can't remove unless there is replacements. + // Mandatory features. Can't remove unless there are replacements. // _ "github.com/xtls/xray-core/app/dispatcher" _ "github.com/Yuzuki616/V2bX/core/app/dispatcher" _ "github.com/xtls/xray-core/app/proxyman/inbound" _ "github.com/xtls/xray-core/app/proxyman/outbound" // Default commander and all its services. This is an optional feature. - _ "github.com/xtls/xray-core/app/commander" - _ "github.com/xtls/xray-core/app/log/command" - _ "github.com/xtls/xray-core/app/proxyman/command" - _ "github.com/xtls/xray-core/app/stats/command" + //_ "github.com/xtls/xray-core/app/commander" + //_ "github.com/xtls/xray-core/app/log/command" + //_ "github.com/xtls/xray-core/app/proxyman/command" + //_ "github.com/xtls/xray-core/app/stats/command" + + // Developer preview services + //_ "github.com/xtls/xray-core/app/observatory/command" // Other optional features. _ "github.com/xtls/xray-core/app/dns" + _ "github.com/xtls/xray-core/app/dns/fakedns" _ "github.com/xtls/xray-core/app/log" _ "github.com/xtls/xray-core/app/metrics" _ "github.com/xtls/xray-core/app/policy" @@ -24,16 +28,31 @@ import ( _ "github.com/xtls/xray-core/app/router" _ "github.com/xtls/xray-core/app/stats" + // Fix dependency cycle caused by core import in internet package + _ "github.com/xtls/xray-core/transport/internet/tagged/taggedimpl" + + // Developer preview features + //_ "github.com/xtls/xray-core/app/observatory" + // Inbound and outbound proxies. _ "github.com/xtls/xray-core/proxy/blackhole" _ "github.com/xtls/xray-core/proxy/dns" _ "github.com/xtls/xray-core/proxy/dokodemo" _ "github.com/xtls/xray-core/proxy/freedom" + _ "github.com/xtls/xray-core/proxy/http" + _ "github.com/xtls/xray-core/proxy/loopback" + _ "github.com/xtls/xray-core/proxy/mtproto" + _ "github.com/xtls/xray-core/proxy/shadowsocks" + _ "github.com/xtls/xray-core/proxy/socks" + _ "github.com/xtls/xray-core/proxy/trojan" + _ "github.com/xtls/xray-core/proxy/vless/inbound" + _ "github.com/xtls/xray-core/proxy/vless/outbound" _ "github.com/xtls/xray-core/proxy/vmess/inbound" _ "github.com/xtls/xray-core/proxy/vmess/outbound" // Transports _ "github.com/xtls/xray-core/transport/internet/domainsocket" + _ "github.com/xtls/xray-core/transport/internet/grpc" _ "github.com/xtls/xray-core/transport/internet/http" _ "github.com/xtls/xray-core/transport/internet/kcp" _ "github.com/xtls/xray-core/transport/internet/quic" @@ -51,12 +70,12 @@ import ( _ "github.com/xtls/xray-core/transport/internet/headers/utp" _ "github.com/xtls/xray-core/transport/internet/headers/wechat" _ "github.com/xtls/xray-core/transport/internet/headers/wireguard" - // JSON & TOML & YAML - _ "github.com/xtls/xray-core/main/json" + //_ "github.com/xtls/xray-core/main/json" //_ "github.com/xtls/xray-core/main/toml" //_ "github.com/xtls/xray-core/main/yaml" - // Load config from file or http(s) - _ "github.com/xtls/xray-core/main/confloader/external" + //_ "github.com/xtls/xray-core/main/confloader/external" + // Commands + //_ "github.com/xtls/xray-core/main/commands/all" ) diff --git a/go.mod b/go.mod index e917280..41b338c 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/Yuzuki616/V2bX -go 1.18 +go 1.19 require ( github.com/deckarep/golang-set v1.8.0 diff --git a/main.go b/main.go index 27733cb..febbcfd 100644 --- a/main.go +++ b/main.go @@ -94,7 +94,7 @@ func main() { // Running backend { osSignals := make(chan os.Signal, 1) - signal.Notify(osSignals, os.Interrupt, os.Kill, syscall.SIGTERM) + signal.Notify(osSignals, syscall.SIGINT, syscall.SIGKILL, syscall.SIGTERM) <-osSignals } } diff --git a/node/node.go b/node/node.go index f28eb95..d0bc88c 100644 --- a/node/node.go +++ b/node/node.go @@ -62,7 +62,6 @@ func (c *Node) Start() error { if err != nil { return err } - err = c.addNewUser(userInfo, newNodeInfo) if err != nil { return err @@ -155,7 +154,6 @@ func (c *Node) nodeInfoMonitor() (err error) { log.Print(err) return nil } - var nodeInfoChanged = false // If nodeInfo changed if newNodeInfo != nil {