update dispatcher and distro

This commit is contained in:
yuzuki999 2022-09-04 20:32:56 +08:00
parent f41ef6b0fa
commit 65ae2b77d5
13 changed files with 115 additions and 130 deletions

View File

@ -49,7 +49,6 @@ func readLocalRuleList(path string) (LocalRuleList []DetectRule) {
log.Fatalf("Error while reading file: %s", err) log.Fatalf("Error while reading file: %s", err)
return []DetectRule{} return []DetectRule{}
} }
file.Close()
} }
return LocalRuleList return LocalRuleList

View File

@ -1,8 +1,8 @@
// Code generated by protoc-gen-go. DO NOT EDIT. // Code generated by protoc-gen-go. DO NOT EDIT.
// versions: // versions:
// protoc-gen-go v1.28.0 // protoc-gen-go v1.28.1
// protoc v3.19.4 // protoc v3.21.5
// source: app/mydispatcher/config.proto // source: config.proto
package dispatcher package dispatcher
@ -29,7 +29,7 @@ type SessionConfig struct {
func (x *SessionConfig) Reset() { func (x *SessionConfig) Reset() {
*x = SessionConfig{} *x = SessionConfig{}
if protoimpl.UnsafeEnabled { 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 := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi) ms.StoreMessageInfo(mi)
} }
@ -42,7 +42,7 @@ func (x *SessionConfig) String() string {
func (*SessionConfig) ProtoMessage() {} func (*SessionConfig) ProtoMessage() {}
func (x *SessionConfig) ProtoReflect() protoreflect.Message { 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 { if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil { if ms.LoadMessageInfo() == nil {
@ -55,7 +55,7 @@ func (x *SessionConfig) ProtoReflect() protoreflect.Message {
// Deprecated: Use SessionConfig.ProtoReflect.Descriptor instead. // Deprecated: Use SessionConfig.ProtoReflect.Descriptor instead.
func (*SessionConfig) Descriptor() ([]byte, []int) { func (*SessionConfig) Descriptor() ([]byte, []int) {
return file_app_mydispatcher_config_proto_rawDescGZIP(), []int{0} return file_config_proto_rawDescGZIP(), []int{0}
} }
type Config struct { type Config struct {
@ -69,7 +69,7 @@ type Config struct {
func (x *Config) Reset() { func (x *Config) Reset() {
*x = Config{} *x = Config{}
if protoimpl.UnsafeEnabled { 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 := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi) ms.StoreMessageInfo(mi)
} }
@ -82,7 +82,7 @@ func (x *Config) String() string {
func (*Config) ProtoMessage() {} func (*Config) ProtoMessage() {}
func (x *Config) ProtoReflect() protoreflect.Message { 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 { if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil { if ms.LoadMessageInfo() == nil {
@ -95,7 +95,7 @@ func (x *Config) ProtoReflect() protoreflect.Message {
// Deprecated: Use Config.ProtoReflect.Descriptor instead. // Deprecated: Use Config.ProtoReflect.Descriptor instead.
func (*Config) Descriptor() ([]byte, []int) { 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 { func (x *Config) GetSettings() *SessionConfig {
@ -105,47 +105,47 @@ func (x *Config) GetSettings() *SessionConfig {
return nil return nil
} }
var File_app_mydispatcher_config_proto protoreflect.FileDescriptor var File_config_proto protoreflect.FileDescriptor
var file_app_mydispatcher_config_proto_rawDesc = []byte{ var file_config_proto_rawDesc = []byte{
0x0a, 0x1d, 0x61, 0x70, 0x70, 0x2f, 0x6d, 0x79, 0x64, 0x69, 0x73, 0x70, 0x61, 0x74, 0x63, 0x68, 0x0a, 0x0c, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x18,
0x65, 0x72, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x76, 0x32, 0x62, 0x78, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x64, 0x69,
0x16, 0x78, 0x72, 0x61, 0x79, 0x72, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x6d, 0x79, 0x64, 0x69, 0x73, 0x73, 0x70, 0x61, 0x74, 0x63, 0x68, 0x65, 0x72, 0x22, 0x15, 0x0a, 0x0d, 0x53, 0x65, 0x73, 0x73,
0x70, 0x61, 0x74, 0x63, 0x68, 0x65, 0x72, 0x22, 0x15, 0x0a, 0x0d, 0x53, 0x65, 0x73, 0x73, 0x69, 0x69, 0x6f, 0x6e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x4a, 0x04, 0x08, 0x01, 0x10, 0x02, 0x22,
0x6f, 0x6e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x4a, 0x04, 0x08, 0x01, 0x10, 0x02, 0x22, 0x4b, 0x4d, 0x0a, 0x06, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x43, 0x0a, 0x08, 0x73, 0x65, 0x74,
0x0a, 0x06, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x41, 0x0a, 0x08, 0x73, 0x65, 0x74, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x27, 0x2e, 0x76, 0x32,
0x69, 0x6e, 0x67, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x25, 0x2e, 0x78, 0x72, 0x61, 0x62, 0x78, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x64, 0x69, 0x73, 0x70,
0x79, 0x72, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x6d, 0x79, 0x64, 0x69, 0x73, 0x70, 0x61, 0x74, 0x63, 0x61, 0x74, 0x63, 0x68, 0x65, 0x72, 0x2e, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x43, 0x6f,
0x68, 0x65, 0x72, 0x2e, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x08, 0x73, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x42, 0x6a,
0x67, 0x52, 0x08, 0x73, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x42, 0x67, 0x0a, 0x1a, 0x63, 0x0a, 0x1c, 0x63, 0x6f, 0x6d, 0x2e, 0x76, 0x32, 0x62, 0x78, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e,
0x6f, 0x6d, 0x2e, 0x78, 0x72, 0x61, 0x79, 0x72, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x6d, 0x79, 0x64, 0x61, 0x70, 0x70, 0x2e, 0x64, 0x69, 0x73, 0x70, 0x61, 0x74, 0x63, 0x68, 0x65, 0x72, 0x50, 0x01,
0x69, 0x73, 0x70, 0x61, 0x74, 0x63, 0x68, 0x65, 0x72, 0x50, 0x01, 0x5a, 0x2f, 0x67, 0x69, 0x74, 0x5a, 0x2d, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x59, 0x75, 0x7a,
0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x58, 0x72, 0x61, 0x79, 0x52, 0x2d, 0x70, 0x72, 0x75, 0x6b, 0x69, 0x36, 0x31, 0x36, 0x2f, 0x56, 0x32, 0x62, 0x58, 0x2f, 0x63, 0x6f, 0x72, 0x65,
0x6f, 0x6a, 0x65, 0x63, 0x74, 0x2f, 0x58, 0x72, 0x61, 0x79, 0x52, 0x2f, 0x61, 0x70, 0x70, 0x2f, 0x2f, 0x61, 0x70, 0x70, 0x2f, 0x64, 0x69, 0x73, 0x70, 0x61, 0x74, 0x63, 0x68, 0x65, 0x72, 0xaa,
0x6d, 0x79, 0x64, 0x69, 0x73, 0x70, 0x61, 0x74, 0x63, 0x68, 0x65, 0x72, 0xaa, 0x02, 0x15, 0x58, 0x02, 0x18, 0x56, 0x32, 0x62, 0x58, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x61, 0x70, 0x70, 0x2e,
0x72, 0x61, 0x79, 0x52, 0x2e, 0x41, 0x70, 0x70, 0x2e, 0x4d, 0x79, 0x69, 0x73, 0x70, 0x61, 0x74, 0x64, 0x69, 0x73, 0x70, 0x61, 0x74, 0x63, 0x68, 0x65, 0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74,
0x63, 0x68, 0x65, 0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, 0x6f, 0x33,
} }
var ( var (
file_app_mydispatcher_config_proto_rawDescOnce sync.Once file_config_proto_rawDescOnce sync.Once
file_app_mydispatcher_config_proto_rawDescData = file_app_mydispatcher_config_proto_rawDesc file_config_proto_rawDescData = file_config_proto_rawDesc
) )
func file_app_mydispatcher_config_proto_rawDescGZIP() []byte { func file_config_proto_rawDescGZIP() []byte {
file_app_mydispatcher_config_proto_rawDescOnce.Do(func() { file_config_proto_rawDescOnce.Do(func() {
file_app_mydispatcher_config_proto_rawDescData = protoimpl.X.CompressGZIP(file_app_mydispatcher_config_proto_rawDescData) 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_config_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
var file_app_mydispatcher_config_proto_goTypes = []interface{}{ var file_config_proto_goTypes = []interface{}{
(*SessionConfig)(nil), // 0: xrayr.app.mydispatcher.SessionConfig (*SessionConfig)(nil), // 0: v2bx.core.app.dispatcher.SessionConfig
(*Config)(nil), // 1: xrayr.app.mydispatcher.Config (*Config)(nil), // 1: v2bx.core.app.dispatcher.Config
} }
var file_app_mydispatcher_config_proto_depIdxs = []int32{ var file_config_proto_depIdxs = []int32{
0, // 0: xrayr.app.mydispatcher.Config.settings:type_name -> xrayr.app.mydispatcher.SessionConfig 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 output_type
1, // [1:1] is the sub-list for method input_type 1, // [1:1] is the sub-list for method input_type
1, // [1:1] is the sub-list for extension type_name 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 0, // [0:1] is the sub-list for field type_name
} }
func init() { file_app_mydispatcher_config_proto_init() } func init() { file_config_proto_init() }
func file_app_mydispatcher_config_proto_init() { func file_config_proto_init() {
if File_app_mydispatcher_config_proto != nil { if File_config_proto != nil {
return return
} }
if !protoimpl.UnsafeEnabled { 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 { switch v := v.(*SessionConfig); i {
case 0: case 0:
return &v.state return &v.state
@ -171,7 +171,7 @@ func file_app_mydispatcher_config_proto_init() {
return nil 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 { switch v := v.(*Config); i {
case 0: case 0:
return &v.state return &v.state
@ -188,18 +188,18 @@ func file_app_mydispatcher_config_proto_init() {
out := protoimpl.TypeBuilder{ out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{ File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(), GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_app_mydispatcher_config_proto_rawDesc, RawDescriptor: file_config_proto_rawDesc,
NumEnums: 0, NumEnums: 0,
NumMessages: 2, NumMessages: 2,
NumExtensions: 0, NumExtensions: 0,
NumServices: 0, NumServices: 0,
}, },
GoTypes: file_app_mydispatcher_config_proto_goTypes, GoTypes: file_config_proto_goTypes,
DependencyIndexes: file_app_mydispatcher_config_proto_depIdxs, DependencyIndexes: file_config_proto_depIdxs,
MessageInfos: file_app_mydispatcher_config_proto_msgTypes, MessageInfos: file_config_proto_msgTypes,
}.Build() }.Build()
File_app_mydispatcher_config_proto = out.File File_config_proto = out.File
file_app_mydispatcher_config_proto_rawDesc = nil file_config_proto_rawDesc = nil
file_app_mydispatcher_config_proto_goTypes = nil file_config_proto_goTypes = nil
file_app_mydispatcher_config_proto_depIdxs = nil file_config_proto_depIdxs = nil
} }

View File

@ -1,9 +1,9 @@
syntax = "proto3"; syntax = "proto3";
package xrayr.app.mydispatcher; package v2bx.core.app.dispatcher;
option csharp_namespace = "XrayR.App.Myispatcher"; option csharp_namespace = "V2bX.core.app.dispatcher";
option go_package = "github.com/Yuzuki616/V2bX/app/mydispatcher"; option go_package = "github.com/Yuzuki616/V2bX/core/app/dispatcher";
option java_package = "com.xrayr.app.mydispatcher"; option java_package = "com.v2bx.core.app.dispatcher";
option java_multiple_files = true; option java_multiple_files = true;
message SessionConfig { message SessionConfig {

View File

@ -16,7 +16,7 @@ import (
"github.com/xtls/xray-core/features/outbound" "github.com/xtls/xray-core/features/outbound"
"github.com/xtls/xray-core/features/policy" "github.com/xtls/xray-core/features/policy"
"github.com/xtls/xray-core/features/routing" "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/features/stats"
"github.com/xtls/xray-core/transport" "github.com/xtls/xray-core/transport"
"github.com/xtls/xray-core/transport/pipe" "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.router = router
d.policy = pm d.policy = pm
d.stats = sm d.stats = sm
d.dns = dns
d.Limiter = NewLimiter() d.Limiter = NewLimiter()
d.RuleManager = NewRule() d.RuleManager = NewRule()
d.dns = dns
return nil 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)) newError("[fakedns client] create a new map").WriteToLog(session.ExportIDToError(ctx))
} }
domain := addr.Domain() 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 { if err == nil {
for _, ip := range ips { for _, ip := range ips {
ip2domain.Store(ip.String(), domain) ip2domain.Store(ip.String(), domain)
@ -261,12 +261,14 @@ func (d *DefaultDispatcher) getLink(ctx context.Context, network net.Network, sn
} }
} }
} }
return inboundLink, outboundLink, nil return inboundLink, outboundLink, nil
} }
func (d *DefaultDispatcher) shouldOverride(ctx context.Context, result SniffResult, request session.SniffingRequest, destination net.Destination) bool { func (d *DefaultDispatcher) shouldOverride(ctx context.Context, result SniffResult, request session.SniffingRequest, destination net.Destination) bool {
domain := result.Domain() domain := result.Domain()
if domain == "" {
return false
}
for _, d := range request.ExcludeForDomain { for _, d := range request.ExcludeForDomain {
if strings.ToLower(domain) == d { if strings.ToLower(domain) == d {
return false return false
@ -315,33 +317,15 @@ func (d *DefaultDispatcher) Dispatch(ctx context.Context, destination net.Destin
if err != nil { if err != nil {
return nil, err return nil, err
} }
switch { if !sniffingRequest.Enabled {
case !sniffingRequest.Enabled:
go d.routedDispatch(ctx, outbound, destination, "") 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 { } else {
ob.Target = destination
}
}
}
go d.routedDispatch(ctx, outbound, destination, content.Protocol)
default:
go func() { go func() {
cReader := &cachedReader{ cReader := &cachedReader{
reader: outbound.Reader.(*pipe.Reader), reader: outbound.Reader.(*pipe.Reader),
} }
outbound.Reader = cReader outbound.Reader = cReader
result, err := sniffer(ctx, cReader, sniffingRequest.MetadataOnly) result, err := sniffer(ctx, cReader, sniffingRequest.MetadataOnly, destination.Network)
if err == nil { if err == nil {
content.Protocol = result.Protocol() content.Protocol = result.Protocol()
} }
@ -376,33 +360,15 @@ func (d *DefaultDispatcher) DispatchLink(ctx context.Context, destination net.De
ctx = session.ContextWithContent(ctx, content) ctx = session.ContextWithContent(ctx, content)
} }
sniffingRequest := content.SniffingRequest sniffingRequest := content.SniffingRequest
switch { if !sniffingRequest.Enabled {
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
}
}
}
go d.routedDispatch(ctx, outbound, destination, content.Protocol) go d.routedDispatch(ctx, outbound, destination, content.Protocol)
default: } else {
go func() { go func() {
cReader := &cachedReader{ cReader := &cachedReader{
reader: outbound.Reader.(*pipe.Reader), reader: outbound.Reader.(*pipe.Reader),
} }
outbound.Reader = cReader outbound.Reader = cReader
result, err := sniffer(ctx, cReader, sniffingRequest.MetadataOnly) result, err := sniffer(ctx, cReader, sniffingRequest.MetadataOnly, destination.Network)
if err == nil { if err == nil {
content.Protocol = result.Protocol() content.Protocol = result.Protocol()
} }
@ -422,7 +388,7 @@ func (d *DefaultDispatcher) DispatchLink(ctx context.Context, destination net.De
return nil 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() payload := buf.New()
defer payload.Release() defer payload.Release()
@ -448,7 +414,7 @@ func sniffer(ctx context.Context, cReader *cachedReader, metadataOnly bool) (Sni
cReader.Cache(payload) cReader.Cache(payload)
if !payload.IsEmpty() { if !payload.IsEmpty() {
result, err := sniffer.Sniff(ctx, payload.Bytes()) result, err := sniffer.Sniff(ctx, payload.Bytes(), network)
if err != common.ErrNoClue { if err != common.ErrNoClue {
return result, err 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() inTag := routingLink.GetInboundTag()
isPickRoute := 0 isPickRoute := 0
if forcedOutboundTag := session.GetForcedOutboundTagFromContext(ctx); forcedOutboundTag != "" { if forcedOutboundTag := session.GetForcedOutboundTagFromContext(ctx); forcedOutboundTag != "" {

View File

@ -1,4 +1,3 @@
// Package dispather implement the rate limiter and the onlie device counter
package dispatcher package dispatcher
//go:generate go run github.com/xtls/xray-core/common/errors/errorgen //go:generate go run github.com/xtls/xray-core/common/errors/errorgen

View File

@ -11,7 +11,7 @@ import (
"github.com/xtls/xray-core/features/dns" "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) { func newFakeDNSSniffer(ctx context.Context) (protocolSnifferWithMetadata, error) {
var fakeDNSEngine dns.FakeDNSEngine var fakeDNSEngine dns.FakeDNSEngine
{ {
@ -85,7 +85,8 @@ func (f DNSThenOthersSniffResult) Domain() string {
} }
func newFakeDNSThenOthers(ctx context.Context, fakeDNSSniffer protocolSnifferWithMetadata, others []protocolSnifferWithMetadata) ( 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 may be used in the future
_ = ctx _ = ctx
return protocolSnifferWithMetadata{ return protocolSnifferWithMetadata{

View File

@ -1,4 +1,3 @@
// Package limiter is to control the links that go into the dispather
package dispatcher package dispatcher
import ( import (

View File

@ -1,4 +1,3 @@
// Package rule is to control the audit rule behaviors
package dispatcher package dispatcher
import ( import (

View File

@ -4,8 +4,10 @@ import (
"context" "context"
"github.com/xtls/xray-core/common" "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/bittorrent"
"github.com/xtls/xray-core/common/protocol/http" "github.com/xtls/xray-core/common/protocol/http"
"github.com/xtls/xray-core/common/protocol/quic"
"github.com/xtls/xray-core/common/protocol/tls" "github.com/xtls/xray-core/common/protocol/tls"
) )
@ -22,6 +24,7 @@ type protocolSnifferWithMetadata struct {
// for both TCP and UDP connections // for both TCP and UDP connections
// It will not be shown as a traffic type for routing unless there is no other successful sniffing. // It will not be shown as a traffic type for routing unless there is no other successful sniffing.
metadataSniffer bool metadataSniffer bool
network net.Network
} }
type Sniffer struct { type Sniffer struct {
@ -31,9 +34,11 @@ type Sniffer struct {
func NewSniffer(ctx context.Context) *Sniffer { func NewSniffer(ctx context.Context) *Sniffer {
ret := &Sniffer{ ret := &Sniffer{
sniffer: []protocolSnifferWithMetadata{ sniffer: []protocolSnifferWithMetadata{
{func(c context.Context, b []byte) (SniffResult, error) { return http.SniffHTTP(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}, {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}, {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 { if sniffer, err := newFakeDNSSniffer(ctx); err == nil {
@ -49,11 +54,11 @@ func NewSniffer(ctx context.Context) *Sniffer {
var errUnknownContent = newError("unknown content") 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 var pendingSniffer []protocolSnifferWithMetadata
for _, si := range s.sniffer { for _, si := range s.sniffer {
s := si.protocolSniffer s := si.protocolSniffer
if si.metadataSniffer { if si.metadataSniffer || si.network != network {
continue continue
} }
result, err := s(c, payload) result, err := s(c, payload)

View File

@ -3,20 +3,24 @@ package all
import ( import (
// The following are necessary as they register handlers in their init functions. // 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/xtls/xray-core/app/dispatcher"
_ "github.com/Yuzuki616/V2bX/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/inbound"
_ "github.com/xtls/xray-core/app/proxyman/outbound" _ "github.com/xtls/xray-core/app/proxyman/outbound"
// Default commander and all its services. This is an optional feature. // Default commander and all its services. This is an optional feature.
_ "github.com/xtls/xray-core/app/commander" //_ "github.com/xtls/xray-core/app/commander"
_ "github.com/xtls/xray-core/app/log/command" //_ "github.com/xtls/xray-core/app/log/command"
_ "github.com/xtls/xray-core/app/proxyman/command" //_ "github.com/xtls/xray-core/app/proxyman/command"
_ "github.com/xtls/xray-core/app/stats/command" //_ "github.com/xtls/xray-core/app/stats/command"
// Developer preview services
//_ "github.com/xtls/xray-core/app/observatory/command"
// Other optional features. // Other optional features.
_ "github.com/xtls/xray-core/app/dns" _ "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/log"
_ "github.com/xtls/xray-core/app/metrics" _ "github.com/xtls/xray-core/app/metrics"
_ "github.com/xtls/xray-core/app/policy" _ "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/router"
_ "github.com/xtls/xray-core/app/stats" _ "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. // Inbound and outbound proxies.
_ "github.com/xtls/xray-core/proxy/blackhole" _ "github.com/xtls/xray-core/proxy/blackhole"
_ "github.com/xtls/xray-core/proxy/dns" _ "github.com/xtls/xray-core/proxy/dns"
_ "github.com/xtls/xray-core/proxy/dokodemo" _ "github.com/xtls/xray-core/proxy/dokodemo"
_ "github.com/xtls/xray-core/proxy/freedom" _ "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/inbound"
_ "github.com/xtls/xray-core/proxy/vmess/outbound" _ "github.com/xtls/xray-core/proxy/vmess/outbound"
// Transports // Transports
_ "github.com/xtls/xray-core/transport/internet/domainsocket" _ "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/http"
_ "github.com/xtls/xray-core/transport/internet/kcp" _ "github.com/xtls/xray-core/transport/internet/kcp"
_ "github.com/xtls/xray-core/transport/internet/quic" _ "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/utp"
_ "github.com/xtls/xray-core/transport/internet/headers/wechat" _ "github.com/xtls/xray-core/transport/internet/headers/wechat"
_ "github.com/xtls/xray-core/transport/internet/headers/wireguard" _ "github.com/xtls/xray-core/transport/internet/headers/wireguard"
// JSON & TOML & YAML // 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/toml"
//_ "github.com/xtls/xray-core/main/yaml" //_ "github.com/xtls/xray-core/main/yaml"
// Load config from file or http(s) // 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"
) )

2
go.mod
View File

@ -1,6 +1,6 @@
module github.com/Yuzuki616/V2bX module github.com/Yuzuki616/V2bX
go 1.18 go 1.19
require ( require (
github.com/deckarep/golang-set v1.8.0 github.com/deckarep/golang-set v1.8.0

View File

@ -94,7 +94,7 @@ func main() {
// Running backend // Running backend
{ {
osSignals := make(chan os.Signal, 1) 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 <-osSignals
} }
} }

View File

@ -62,7 +62,6 @@ func (c *Node) Start() error {
if err != nil { if err != nil {
return err return err
} }
err = c.addNewUser(userInfo, newNodeInfo) err = c.addNewUser(userInfo, newNodeInfo)
if err != nil { if err != nil {
return err return err
@ -155,7 +154,6 @@ func (c *Node) nodeInfoMonitor() (err error) {
log.Print(err) log.Print(err)
return nil return nil
} }
var nodeInfoChanged = false var nodeInfoChanged = false
// If nodeInfo changed // If nodeInfo changed
if newNodeInfo != nil { if newNodeInfo != nil {