From cda0b6711ea3363dfdf88f75d733ff3cca5ce972 Mon Sep 17 00:00:00 2001 From: yuzuki999 Date: Mon, 24 Jul 2023 01:24:28 +0800 Subject: [PATCH 1/4] fix file cert mode, support null ShortIds for reality --- core/xray/inbound.go | 6 ++++++ node/cert.go | 1 + 2 files changed, 7 insertions(+) diff --git a/core/xray/inbound.go b/core/xray/inbound.go index 55e67b1..96c87f0 100644 --- a/core/xray/inbound.go +++ b/core/xray/inbound.go @@ -80,6 +80,9 @@ func buildInbound(config *conf.ControllerConfig, nodeInfo *panel.NodeInfo, tag s if err != nil { return nil, fmt.Errorf("marshal reality dest error: %s", err) } + if len(in.StreamSetting.REALITYSettings.ShortIds) == 0 { + config.CertConfig.RealityConfig.ShortIds = []string{""} + } in.StreamSetting.REALITYSettings = &coreConf.REALITYConfig{ Dest: d, Xver: config.CertConfig.RealityConfig.Xver, @@ -99,6 +102,9 @@ func buildInbound(config *conf.ControllerConfig, nodeInfo *panel.NodeInfo, tag s if err != nil { return nil, fmt.Errorf("marshal reality dest error: %s", err) } + if len(rc.ShortIds) == 0 { + rc.ShortIds = []string{""} + } Xver, _ := strconv.ParseUint(rc.Xver, 10, 64) MaxTimeDiff, _ := strconv.ParseUint(rc.Xver, 10, 64) in.StreamSetting.REALITYSettings = &coreConf.REALITYConfig{ diff --git a/node/cert.go b/node/cert.go index ed79016..1df319c 100644 --- a/node/cert.go +++ b/node/cert.go @@ -28,6 +28,7 @@ func (c *Controller) requestCert() error { if c.CertConfig.CertFile == "" || c.CertConfig.KeyFile == "" { return fmt.Errorf("cert file path or key file path not exist") } + return nil case "dns", "http": if c.CertConfig.CertFile == "" || c.CertConfig.KeyFile == "" { return fmt.Errorf("cert file path or key file path not exist") From 15118de36711fabf1b8c4c4bf368b0bdf53cf48e Mon Sep 17 00:00:00 2001 From: yuzuki999 Date: Mon, 24 Jul 2023 07:30:22 +0800 Subject: [PATCH 2/4] fix bugs --- core/core.go | 2 +- core/xray/inbound.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/core.go b/core/core.go index 825cac8..d3cc812 100644 --- a/core/core.go +++ b/core/core.go @@ -16,7 +16,7 @@ func NewCore(c *conf.CoreConfig) (Core, error) { if types := strings.Split(c.Type, " "); len(types) > 1 { var cs []Core for _, t := range types { - f, ok := cores[strings.ToLower(c.Type)] + f, ok := cores[strings.ToLower(t)] if !ok { return nil, errors.New("unknown core type: " + t) } diff --git a/core/xray/inbound.go b/core/xray/inbound.go index 96c87f0..1060574 100644 --- a/core/xray/inbound.go +++ b/core/xray/inbound.go @@ -80,7 +80,7 @@ func buildInbound(config *conf.ControllerConfig, nodeInfo *panel.NodeInfo, tag s if err != nil { return nil, fmt.Errorf("marshal reality dest error: %s", err) } - if len(in.StreamSetting.REALITYSettings.ShortIds) == 0 { + if len(config.CertConfig.RealityConfig.ShortIds) == 0 { config.CertConfig.RealityConfig.ShortIds = []string{""} } in.StreamSetting.REALITYSettings = &coreConf.REALITYConfig{ From 1c68cd80c8f037406e10af2cd9e8368dc8e3e754 Mon Sep 17 00:00:00 2001 From: yuzuki999 Date: Mon, 24 Jul 2023 16:58:26 +0800 Subject: [PATCH 3/4] fix dynamic speed limit --- core/hy/resolver.go | 17 +++-------------- node/task.go | 9 +++++---- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/core/hy/resolver.go b/core/hy/resolver.go index cc5edd9..8da3ea8 100644 --- a/core/hy/resolver.go +++ b/core/hy/resolver.go @@ -1,20 +1,9 @@ package hy -import ( - "crypto/tls" - "errors" - "net" - "net/url" - "strings" - - "github.com/Yuzuki616/hysteria/core/utils" - rdns "github.com/folbricht/routedns" -) - -var errInvalidSyntax = errors.New("invalid syntax") +//var errInvalidSyntax = errors.New("invalid syntax") func setResolver(dns string) error { - if net.ParseIP(dns) != nil { + /*if net.ParseIP(dns) != nil { // Just an IP address, treat as UDP 53 dns = "udp://" + net.JoinHostPort(dns, "53") } @@ -118,6 +107,6 @@ func setResolver(dns string) error { return errInvalidSyntax } cache := rdns.NewCache("cache", r, rdns.CacheOptions{}) - net.DefaultResolver = rdns.NewNetResolver(cache) + net.DefaultResolver = rdns.NewNetResolver(cache)*/ return nil } diff --git a/node/task.go b/node/task.go index 8940dd1..d9ce94c 100644 --- a/node/task.go +++ b/node/task.go @@ -41,9 +41,9 @@ func (c *Controller) startTasks(node *panel.NodeInfo) { } if c.LimitConfig.EnableDynamicSpeedLimit { c.traffic = make(map[string]int64) - c.renewCertPeriodic = &task.Task{ - Interval: time.Duration(c.LimitConfig.DynamicSpeedLimitConfig.Periodic) * time.Minute, - Execute: c.reportUserTrafficTask, + c.dynamicSpeedLimitPeriodic = &task.Task{ + Interval: time.Duration(c.LimitConfig.DynamicSpeedLimitConfig.Periodic) * time.Second, + Execute: c.SpeedChecker, } } } @@ -204,7 +204,7 @@ func (c *Controller) nodeInfoMonitor() (err error) { return nil } -func (c *Controller) SpeedChecker() { +func (c *Controller) SpeedChecker() error { for u, t := range c.traffic { if t >= c.LimitConfig.DynamicSpeedLimitConfig.Traffic { err := c.limiter.UpdateDynamicSpeedLimit(c.tag, u, @@ -214,4 +214,5 @@ func (c *Controller) SpeedChecker() { delete(c.traffic, u) } } + return nil } From 968da8effdd831704142c318c42dab29ca582608 Mon Sep 17 00:00:00 2001 From: yuzuki999 Date: Mon, 24 Jul 2023 16:59:59 +0800 Subject: [PATCH 4/4] fix miss --- core/hy/resolver.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/core/hy/resolver.go b/core/hy/resolver.go index 8da3ea8..e1eacbe 100644 --- a/core/hy/resolver.go +++ b/core/hy/resolver.go @@ -1,9 +1,19 @@ package hy -//var errInvalidSyntax = errors.New("invalid syntax") +import ( + "crypto/tls" + "errors" + "github.com/Yuzuki616/hysteria/core/utils" + rdns "github.com/folbricht/routedns" + "net" + "net/url" + "strings" +) + +var errInvalidSyntax = errors.New("invalid syntax") func setResolver(dns string) error { - /*if net.ParseIP(dns) != nil { + if net.ParseIP(dns) != nil { // Just an IP address, treat as UDP 53 dns = "udp://" + net.JoinHostPort(dns, "53") } @@ -107,6 +117,6 @@ func setResolver(dns string) error { return errInvalidSyntax } cache := rdns.NewCache("cache", r, rdns.CacheOptions{}) - net.DefaultResolver = rdns.NewNetResolver(cache)*/ + net.DefaultResolver = rdns.NewNetResolver(cache) return nil }