mirror of
https://github.com/wyx2685/V2bX.git
synced 2026-11-04 01:00:21 +00:00
update
refactor limiter fix getLink bug add connection limit move limit config to ControllerConfig del dynamic speed limit (next version will be re add) del online ip sync (next version will be re add)
This commit is contained in:
1 parent
2d7aaef066
commit
15c36a9580
35 files changed
+564
-617
No files matched your search
@@ -1,7 +1,9 @@
|
||||
package iprecoder
|
||||
|
||||
import "github.com/Yuzuki616/V2bX/core/app/dispatcher"
|
||||
import (
|
||||
"github.com/Yuzuki616/V2bX/limiter"
|
||||
)
|
||||
|
||||
type IpRecorder interface {
|
||||
SyncOnlineIp(Ips []dispatcher.UserIpList) ([]dispatcher.UserIpList, error)
|
||||
SyncOnlineIp(Ips []limiter.UserIpList) ([]limiter.UserIpList, error)
|
||||
}
|
||||
@@ -3,7 +3,7 @@ package iprecoder
|
||||
import (
|
||||
"errors"
|
||||
"github.com/Yuzuki616/V2bX/conf"
|
||||
"github.com/Yuzuki616/V2bX/core/app/dispatcher"
|
||||
"github.com/Yuzuki616/V2bX/limiter"
|
||||
"github.com/go-resty/resty/v2"
|
||||
"github.com/goccy/go-json"
|
||||
"time"
|
||||
@@ -21,7 +21,7 @@ func NewRecorder(c *conf.RecorderConfig) *Recorder {
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Recorder) SyncOnlineIp(ips []dispatcher.UserIpList) ([]dispatcher.UserIpList, error) {
|
||||
func (r *Recorder) SyncOnlineIp(ips []limiter.UserIpList) ([]limiter.UserIpList, error) {
|
||||
rsp, err := r.client.R().
|
||||
SetBody(ips).
|
||||
Post(r.Url + "/api/v1/SyncOnlineIp?token=" + r.Token)
|
||||
@@ -31,7 +31,7 @@ func (r *Recorder) SyncOnlineIp(ips []dispatcher.UserIpList) ([]dispatcher.UserI
|
||||
if rsp.StatusCode() != 200 {
|
||||
return nil, errors.New(rsp.String())
|
||||
}
|
||||
ips = []dispatcher.UserIpList{}
|
||||
ips = []limiter.UserIpList{}
|
||||
err = json.Unmarshal(rsp.Body(), &ips)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/Yuzuki616/V2bX/conf"
|
||||
"github.com/Yuzuki616/V2bX/core/app/dispatcher"
|
||||
"github.com/Yuzuki616/V2bX/limiter"
|
||||
"github.com/go-redis/redis/v8"
|
||||
"strconv"
|
||||
"time"
|
||||
@@ -26,7 +26,7 @@ func NewRedis(c *conf.RedisConfig) *Redis {
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Redis) SyncOnlineIp(Ips []dispatcher.UserIpList) ([]dispatcher.UserIpList, error) {
|
||||
func (r *Redis) SyncOnlineIp(Ips []limiter.UserIpList) ([]limiter.UserIpList, error) {
|
||||
ctx := context.Background()
|
||||
for i := range Ips {
|
||||
err := r.client.SAdd(ctx, "UserList", Ips[i].Uid).Err()
|
||||
@@ -46,7 +46,7 @@ func (r *Redis) SyncOnlineIp(Ips []dispatcher.UserIpList) ([]dispatcher.UserIpLi
|
||||
if c.Err() != nil {
|
||||
return nil, fmt.Errorf("get user list failed: %s", c.Err())
|
||||
}
|
||||
Ips = make([]dispatcher.UserIpList, 0, len(c.Val()))
|
||||
Ips = make([]limiter.UserIpList, 0, len(c.Val()))
|
||||
for _, uid := range c.Val() {
|
||||
uidInt, err := strconv.Atoi(uid)
|
||||
if err != nil {
|
||||
@@ -56,7 +56,7 @@ func (r *Redis) SyncOnlineIp(Ips []dispatcher.UserIpList) ([]dispatcher.UserIpLi
|
||||
if ips.Err() != nil {
|
||||
return nil, fmt.Errorf("get ip list failed: %s", ips.Err())
|
||||
}
|
||||
Ips = append(Ips, dispatcher.UserIpList{
|
||||
Ips = append(Ips, limiter.UserIpList{
|
||||
Uid: uidInt,
|
||||
IpList: ips.Val(),
|
||||
})
|
||||
|
||||
@@ -2,7 +2,7 @@ package iprecoder
|
||||
|
||||
import (
|
||||
"github.com/Yuzuki616/V2bX/conf"
|
||||
"github.com/Yuzuki616/V2bX/core/app/dispatcher"
|
||||
"github.com/Yuzuki616/V2bX/limiter"
|
||||
"log"
|
||||
"testing"
|
||||
)
|
||||
@@ -13,7 +13,7 @@ func TestRedis_SyncOnlineIp(t *testing.T) {
|
||||
Password: "",
|
||||
Db: 0,
|
||||
})
|
||||
users, err := r.SyncOnlineIp([]dispatcher.UserIpList{
|
||||
users, err := r.SyncOnlineIp([]limiter.UserIpList{
|
||||
{1, []string{"5.5.5.5", "4.4.4.4"}},
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
Reference in new issue
Block a user