diff --git a/api/panel/user.go b/api/panel/user.go index 3bbb424..1fb607e 100644 --- a/api/panel/user.go +++ b/api/panel/user.go @@ -56,23 +56,22 @@ func (c *Client) GetUserList() ([]UserInfo, error) { // GetUserAlive will fetch the alive_ip count for users func (c *Client) GetUserAlive() (map[int]int, error) { + c.AliveMap = &AliveMap{} const path = "/api/v1/server/UniProxy/alivelist" r, err := c.client.R(). ForceContentType("application/json"). Get(path) - if r == nil || r.RawResponse == nil { - return nil, fmt.Errorf("received nil response or raw response") - } - defer r.RawResponse.Body.Close() - - c.AliveMap = &AliveMap{} if err != nil || r.StatusCode() >= 399 { c.AliveMap.Alive = make(map[int]int) - return c.AliveMap.Alive, nil } - + if r == nil || r.RawResponse == nil { + fmt.Printf("received nil response or raw response") + c.AliveMap.Alive = make(map[int]int) + } + defer r.RawResponse.Body.Close() if err := json.Unmarshal(r.Body(), c.AliveMap); err != nil { - return nil, fmt.Errorf("unmarshal user alive list error: %s", err) + fmt.Printf("unmarshal user alive list error: %s", err) + c.AliveMap.Alive = make(map[int]int) } return c.AliveMap.Alive, nil diff --git a/core/hy2/hook.go b/core/hy2/hook.go index 26f6131..4393186 100644 --- a/core/hy2/hook.go +++ b/core/hy2/hook.go @@ -6,15 +6,25 @@ import ( "github.com/InazumaV/V2bX/common/counter" "github.com/InazumaV/V2bX/common/format" "github.com/InazumaV/V2bX/limiter" + "github.com/apernet/hysteria/core/v2/server" + quic "github.com/apernet/quic-go" "go.uber.org/zap" ) +var _ server.TrafficLogger = (*HookServer)(nil) + type HookServer struct { Tag string logger *zap.Logger Counter sync.Map } +func (h *HookServer) TraceStream(stream quic.Stream, stats *server.StreamStats) { +} + +func (h *HookServer) UntraceStream(stream quic.Stream) { +} + func (h *HookServer) LogTraffic(id string, tx, rx uint64) (ok bool) { var c interface{} var exists bool diff --git a/core/xray/inbound.go b/core/xray/inbound.go index 86ef749..83f2971 100644 --- a/core/xray/inbound.go +++ b/core/xray/inbound.go @@ -208,11 +208,6 @@ func buildV2ray(config *conf.Options, nodeInfo *panel.NodeInfo, inbound *coreCon if err != nil { return fmt.Errorf("unmarshal grpc settings error: %s", err) } - case "http": - err := json.Unmarshal(v.NetworkSettings, &inbound.StreamSetting.HTTPSettings) - if err != nil { - return fmt.Errorf("unmarshal grpc settings error: %s", err) - } case "httpupgrade": err := json.Unmarshal(v.NetworkSettings, &inbound.StreamSetting.HTTPUPGRADESettings) if err != nil { diff --git a/go.mod b/go.mod index bb8683e..8a22eb6 100644 --- a/go.mod +++ b/go.mod @@ -5,8 +5,9 @@ go 1.23 toolchain go1.23.2 require ( - github.com/apernet/hysteria/core/v2 v2.5.3-0.20241019184355-78598bfd1b0c - github.com/apernet/hysteria/extras/v2 v2.5.3-0.20241019184355-78598bfd1b0c + github.com/apernet/hysteria/core/v2 v2.6.0 + github.com/apernet/hysteria/extras/v2 v2.6.0 + github.com/apernet/quic-go v0.48.2-0.20241104191913-cb103fcecfe7 github.com/beevik/ntp v1.2.0 github.com/fsnotify/fsnotify v1.7.0 github.com/go-acme/lego/v4 v4.19.3-0.20241028134924-480950181787 @@ -19,7 +20,7 @@ require ( github.com/sirupsen/logrus v1.9.3 github.com/spf13/cobra v1.8.1 github.com/spf13/viper v1.18.2 - github.com/xtls/xray-core v1.8.25-0.20241121054707-513f18bf531e + github.com/xtls/xray-core v1.8.25-0.20241201231301-03d7d07c5b77 go.uber.org/zap v1.27.0 golang.org/x/crypto v0.29.0 golang.org/x/sys v0.27.0 @@ -54,7 +55,6 @@ require ( github.com/akamai/AkamaiOPEN-edgegrid-golang v1.2.2 // indirect github.com/aliyun/alibaba-cloud-sdk-go v1.63.15 // indirect github.com/andybalholm/brotli v1.1.0 // indirect - github.com/apernet/quic-go v0.47.1-0.20241004180137-a80d14e2080d // indirect github.com/aws/aws-sdk-go-v2 v1.30.5 // indirect github.com/aws/aws-sdk-go-v2/config v1.27.33 // indirect github.com/aws/aws-sdk-go-v2/credentials v1.17.32 // indirect @@ -229,7 +229,7 @@ require ( github.com/spf13/cast v1.6.0 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/stretchr/objx v0.5.2 // indirect - github.com/stretchr/testify v1.9.0 // indirect + github.com/stretchr/testify v1.10.0 // indirect github.com/subosito/gotenv v1.6.0 // indirect github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1002 // indirect github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dnspod v1.0.1002 // indirect diff --git a/go.sum b/go.sum index e4dbd25..df475eb 100644 --- a/go.sum +++ b/go.sum @@ -116,12 +116,12 @@ github.com/aliyun/alibaba-cloud-sdk-go v1.63.15/go.mod h1:SOSDHfe1kX91v3W5QiBsWS github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M= github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= -github.com/apernet/hysteria/core/v2 v2.5.3-0.20241019184355-78598bfd1b0c h1:UdNv16HiUKFoMeLXmFLwLatrfab6JiUh/18v1qSsvw4= -github.com/apernet/hysteria/core/v2 v2.5.3-0.20241019184355-78598bfd1b0c/go.mod h1:DsQ07Ra4F9SbZ6GsYoT6a8skPz2Ur6ezmTGcUtrtDgk= -github.com/apernet/hysteria/extras/v2 v2.5.3-0.20241019184355-78598bfd1b0c h1:fIhIKibTurxu+eNbL2uPhneqK6udvL7vOHHyYuO4xPg= -github.com/apernet/hysteria/extras/v2 v2.5.3-0.20241019184355-78598bfd1b0c/go.mod h1:CyM2bMoQ9qHXwVcw64QyvGyXB8+LX37Pyg5spm+SlDY= -github.com/apernet/quic-go v0.47.1-0.20241004180137-a80d14e2080d h1:KWRCWISqJOgY9/0hhH8Bevjw/k4tCQ7oJlXLyFv8u9s= -github.com/apernet/quic-go v0.47.1-0.20241004180137-a80d14e2080d/go.mod h1:x0paLlmCzNOUDDQIgmgFWmnpWQIEuH1GNfA6NdgSTuM= +github.com/apernet/hysteria/core/v2 v2.6.0 h1:D0MNegEvEH2Gy9NAqOsElWRY2LEpOflmSWkJGVkvjpY= +github.com/apernet/hysteria/core/v2 v2.6.0/go.mod h1:doZ53n2Kcy3B//mscmROCjlVK1de5/QxF+MihSO+Xtc= +github.com/apernet/hysteria/extras/v2 v2.6.0 h1:GfDrRgOM5gFoZQr1qUbc4NxQPKvwD41zrOyZfsGAZNo= +github.com/apernet/hysteria/extras/v2 v2.6.0/go.mod h1:sfG294M/b3OEmE9NJYvLrjYD1Hm1l68jdRYt3E9bPag= +github.com/apernet/quic-go v0.48.2-0.20241104191913-cb103fcecfe7 h1:zO38yBOvQ1dLHbSuaU5BFZ8zalnSDQslj+i/9AGOk9s= +github.com/apernet/quic-go v0.48.2-0.20241104191913-cb103fcecfe7/go.mod h1:LoSUY2chVqNQCDyi4IZGqPpXLy1FuCkE37PKwtJvNGg= github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= github.com/armon/go-metrics v0.3.9/go.mod h1:4O98XIr/9W0sxpJ8UaYkvjk10Iff7SnFrb4QAOwNTFc= @@ -379,8 +379,6 @@ github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= -github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= @@ -847,8 +845,6 @@ github.com/sagernet/quic-go v0.48.0-beta.1/go.mod h1:1WgdDIVD1Gybp40JTWketeSfKA/ github.com/sagernet/reality v0.0.0-20230406110435-ee17307e7691 h1:5Th31OC6yj8byLGkEnIYp6grlXfo1QYUfiYFGjewIdc= github.com/sagernet/reality v0.0.0-20230406110435-ee17307e7691/go.mod h1:B8lp4WkQ1PwNnrVMM6KyuFR20pU8jYBD+A4EhJovEXU= github.com/sagernet/sing v0.2.18/go.mod h1:OL6k2F0vHmEzXz2KW19qQzu172FDgSbUSODylighuVo= -github.com/sagernet/sing v0.5.0 h1:soo2wVwLcieKWWKIksFNK6CCAojUgAppqQVwyRYGkEM= -github.com/sagernet/sing v0.5.0/go.mod h1:ARkL0gM13/Iv5VCZmci/NuoOlePoIsW0m7BWfln/Hak= github.com/sagernet/sing v0.5.1 h1:mhL/MZVq0TjuvHcpYcFtmSD1BFOxZ/+8ofbNZcg1k1Y= github.com/sagernet/sing v0.5.1/go.mod h1:ARkL0gM13/Iv5VCZmci/NuoOlePoIsW0m7BWfln/Hak= github.com/sagernet/sing-dns v0.3.0-rc.2 h1:z1yROBxd/6wik5h53Sz5df1DSmbPTaOu/Z0wAmyXGoQ= @@ -956,8 +952,8 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= -github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= @@ -1007,12 +1003,10 @@ github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQ github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/xtls/reality v0.0.0-20240909153216-e26ae2305463 h1:g1Cj7d+my6k/HHxLAyxPwyX8i7FGRr6ulBDMkBzg2BM= github.com/xtls/reality v0.0.0-20240909153216-e26ae2305463/go.mod h1:BjIOLmkEEtAgloAiVUcYj0Mt+YU00JARZw8AEU0IwAg= -github.com/xtls/xray-core v1.8.25-0.20241112154441-7b4a686b7401 h1:nhOqRGHcU4+bumtMNER4ygw32Vh7oawhU7jCLXcXIkc= -github.com/xtls/xray-core v1.8.25-0.20241112154441-7b4a686b7401/go.mod h1:n8wJBW828YcDQ+9+BnAtbofXVt31VMvz4TwbZK0BaEE= -github.com/xtls/xray-core v1.8.25-0.20241117060325-2d7b0e8cd4f1 h1:HX3IVEscRVjjEL+F2lQ96aiorDz6lw2Zx9JnRlKMo2M= -github.com/xtls/xray-core v1.8.25-0.20241117060325-2d7b0e8cd4f1/go.mod h1:n8wJBW828YcDQ+9+BnAtbofXVt31VMvz4TwbZK0BaEE= -github.com/xtls/xray-core v1.8.25-0.20241121054707-513f18bf531e h1:J5sTv0Sw+BonaI+rBh4Jkw9BfBqDjfAts81/HbIaqNg= -github.com/xtls/xray-core v1.8.25-0.20241121054707-513f18bf531e/go.mod h1:wByClH1yrH8I611sREjG62gxbP5hFtdAWYJfydQF/zI= +github.com/xtls/xray-core v1.8.25-0.20241129020808-4f6f12616ccf h1:vjmZXbLx9HYpYb7Cx50ubGSwCATTqkhynPCsQ2N2Dgk= +github.com/xtls/xray-core v1.8.25-0.20241129020808-4f6f12616ccf/go.mod h1:BCeSy6P4xz8vSk46ziVkg0iby82W2Mmqvz2ub5kfYrc= +github.com/xtls/xray-core v1.8.25-0.20241201231301-03d7d07c5b77 h1:4s1Q/Wb7Iwuzwgkoe1d48hSmexwlUOn+XJQ7sOuWSDQ= +github.com/xtls/xray-core v1.8.25-0.20241201231301-03d7d07c5b77/go.mod h1:BCeSy6P4xz8vSk46ziVkg0iby82W2Mmqvz2ub5kfYrc= github.com/yandex-cloud/go-genproto v0.0.0-20240911120709-1fa0cb6f47c2 h1:WgeEP+8WizCQyccJNHOMLONq23qVAzYHtyg5qTdUWmg= github.com/yandex-cloud/go-genproto v0.0.0-20240911120709-1fa0cb6f47c2/go.mod h1:HEUYX/p8966tMUHHT+TsS0hF/Ca/NYwqprC5WXSDMfE= github.com/yandex-cloud/go-sdk v0.0.0-20240911121212-e4e74d0d02f5 h1:Q4LvUMF4kzaGtopoIdXReL9/qGtmzOewBhF3dQvuHMU= @@ -1517,8 +1511,6 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0 google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= -google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA= -google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io= google.golang.org/protobuf v1.35.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= diff --git a/node/task.go b/node/task.go index 5cee41d..adaf0fc 100644 --- a/node/task.go +++ b/node/task.go @@ -71,7 +71,11 @@ func (c *Controller) nodeInfoMonitor() (err error) { // get user alive newA, err := c.apiClient.GetUserAlive() if err != nil { - return err + log.WithFields(log.Fields{ + "tag": c.tag, + "err": err, + }).Error("Get alive list failed") + return nil } if newN != nil { c.info = newN @@ -100,6 +104,10 @@ func (c *Controller) nodeInfoMonitor() (err error) { l := limiter.AddLimiter(c.tag, &c.LimitConfig, c.userList, newA) c.limiter = l } + // update alive list + if newA != nil { + c.limiter.AliveList = newA + } // Update rule err = c.limiter.UpdateRule(&newN.Rules) if err != nil {