fix dynamic speed limit

This commit is contained in:
yuzuki999 2023-07-24 16:58:26 +08:00
parent 15118de367
commit 1c68cd80c8
2 changed files with 8 additions and 18 deletions

View File

@ -1,20 +1,9 @@
package hy package hy
import ( //var errInvalidSyntax = errors.New("invalid syntax")
"crypto/tls"
"errors"
"net"
"net/url"
"strings"
"github.com/Yuzuki616/hysteria/core/utils"
rdns "github.com/folbricht/routedns"
)
var errInvalidSyntax = errors.New("invalid syntax")
func setResolver(dns string) error { func setResolver(dns string) error {
if net.ParseIP(dns) != nil { /*if net.ParseIP(dns) != nil {
// Just an IP address, treat as UDP 53 // Just an IP address, treat as UDP 53
dns = "udp://" + net.JoinHostPort(dns, "53") dns = "udp://" + net.JoinHostPort(dns, "53")
} }
@ -118,6 +107,6 @@ func setResolver(dns string) error {
return errInvalidSyntax return errInvalidSyntax
} }
cache := rdns.NewCache("cache", r, rdns.CacheOptions{}) cache := rdns.NewCache("cache", r, rdns.CacheOptions{})
net.DefaultResolver = rdns.NewNetResolver(cache) net.DefaultResolver = rdns.NewNetResolver(cache)*/
return nil return nil
} }

View File

@ -41,9 +41,9 @@ func (c *Controller) startTasks(node *panel.NodeInfo) {
} }
if c.LimitConfig.EnableDynamicSpeedLimit { if c.LimitConfig.EnableDynamicSpeedLimit {
c.traffic = make(map[string]int64) c.traffic = make(map[string]int64)
c.renewCertPeriodic = &task.Task{ c.dynamicSpeedLimitPeriodic = &task.Task{
Interval: time.Duration(c.LimitConfig.DynamicSpeedLimitConfig.Periodic) * time.Minute, Interval: time.Duration(c.LimitConfig.DynamicSpeedLimitConfig.Periodic) * time.Second,
Execute: c.reportUserTrafficTask, Execute: c.SpeedChecker,
} }
} }
} }
@ -204,7 +204,7 @@ func (c *Controller) nodeInfoMonitor() (err error) {
return nil return nil
} }
func (c *Controller) SpeedChecker() { func (c *Controller) SpeedChecker() error {
for u, t := range c.traffic { for u, t := range c.traffic {
if t >= c.LimitConfig.DynamicSpeedLimitConfig.Traffic { if t >= c.LimitConfig.DynamicSpeedLimitConfig.Traffic {
err := c.limiter.UpdateDynamicSpeedLimit(c.tag, u, err := c.limiter.UpdateDynamicSpeedLimit(c.tag, u,
@ -214,4 +214,5 @@ func (c *Controller) SpeedChecker() {
delete(c.traffic, u) delete(c.traffic, u)
} }
} }
return nil
} }