mirror of
https://github.com/wyx2685/V2bX.git
synced 2026-02-04 20:50:09 +00:00
Compare commits
28 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9bbccf772b | ||
|
|
9483526f3c | ||
|
|
65f2de55ea | ||
|
|
4ed6bc6d87 | ||
|
|
af7b473c13 | ||
|
|
10f66b57ea | ||
|
|
0824bf7a4e | ||
|
|
6e8297c553 | ||
|
|
7d52a8932d | ||
|
|
06441afa79 | ||
|
|
f7b588fb45 | ||
|
|
9be082ede6 | ||
|
|
dce3ec1079 | ||
|
|
2990999f7b | ||
|
|
fe003fcb19 | ||
|
|
ea26985d7c | ||
|
|
32437f5e48 | ||
|
|
39dfd8b6dd | ||
|
|
eb51d3e13c | ||
|
|
dadeb6304b | ||
|
|
4c7b9f5eb9 | ||
|
|
63d88843b6 | ||
|
|
8d225f811b | ||
|
|
f6b587b275 | ||
|
|
d9b3d24465 | ||
|
|
fc284b3b9f | ||
|
|
eb92c4912d | ||
|
|
a68378670f |
6
.github/workflows/release.yml
vendored
6
.github/workflows/release.yml
vendored
@@ -109,7 +109,7 @@ jobs:
|
|||||||
- name: Set up Go
|
- name: Set up Go
|
||||||
uses: actions/setup-go@v5
|
uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version: '1.24.1'
|
go-version: '1.25.0'
|
||||||
|
|
||||||
- name: Get project dependencies
|
- name: Get project dependencies
|
||||||
run: |
|
run: |
|
||||||
@@ -126,13 +126,13 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
echo "version: $version"
|
echo "version: $version"
|
||||||
mkdir -p build_assets
|
mkdir -p build_assets
|
||||||
go build -v -o build_assets/V2bX -tags "sing xray hysteria2 with_reality_server with_quic with_grpc with_utls with_wireguard with_acme with_gvisor" -trimpath -ldflags "-X 'github.com/InazumaV/V2bX/cmd.version=$version' -s -w -buildid="
|
GOEXPERIMENT=jsonv2 go build -v -o build_assets/V2bX -tags "sing xray hysteria2 with_quic with_grpc with_utls with_wireguard with_acme with_gvisor" -trimpath -ldflags "-X 'github.com/InazumaV/V2bX/cmd.version=$version' -s -w -buildid="
|
||||||
|
|
||||||
- name: Build Mips softfloat V2bX
|
- name: Build Mips softfloat V2bX
|
||||||
if: matrix.goarch == 'mips' || matrix.goarch == 'mipsle'
|
if: matrix.goarch == 'mips' || matrix.goarch == 'mipsle'
|
||||||
run: |
|
run: |
|
||||||
echo "version: $version"
|
echo "version: $version"
|
||||||
GOMIPS=softfloat go build -v -o build_assets/V2bX_softfloat -tags "sing xray hysteria2 with_reality_server with_quic with_grpc with_utls with_wireguard with_acme with_gvisor" -trimpath -ldflags "-X 'github.com/InazumaV/V2bX/cmd.version=$version' -s -w -buildid="
|
GOEXPERIMENT=jsonv2 GOMIPS=softfloat go build -v -o build_assets/V2bX_softfloat -tags "sing xray hysteria2 with_quic with_grpc with_utls with_wireguard with_acme with_gvisor" -trimpath -ldflags "-X 'github.com/InazumaV/V2bX/cmd.version=$version' -s -w -buildid="
|
||||||
- name: Rename Windows V2bX
|
- name: Rename Windows V2bX
|
||||||
if: matrix.goos == 'windows'
|
if: matrix.goos == 'windows'
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
# Build go
|
# Build go
|
||||||
FROM golang:1.24.1-alpine AS builder
|
FROM golang:1.25.0-alpine AS builder
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY . .
|
COPY . .
|
||||||
ENV CGO_ENABLED=0
|
ENV CGO_ENABLED=0
|
||||||
RUN go mod download
|
RUN GOEXPERIMENT=jsonv2 go mod download
|
||||||
RUN go build -v -o V2bX -tags "sing xray hysteria2 with_reality_server with_quic with_grpc with_utls with_wireguard with_acme with_gvisor"
|
RUN GOEXPERIMENT=jsonv2 go build -v -o V2bX -tags "sing xray hysteria2 with_quic with_grpc with_utls with_wireguard with_acme with_gvisor"
|
||||||
|
|
||||||
# Release
|
# Release
|
||||||
FROM alpine
|
FROM alpine
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ A V2board node server based on multi core, modified from XrayR.
|
|||||||
## TODO
|
## TODO
|
||||||
|
|
||||||
- [ ] 重新实现动态限速
|
- [ ] 重新实现动态限速
|
||||||
- [ ] 重新实现在线IP同步(跨节点在线IP限制)
|
|
||||||
- [ ] 完善使用文档
|
- [ ] 完善使用文档
|
||||||
|
|
||||||
## 软件安装
|
## 软件安装
|
||||||
@@ -58,7 +57,7 @@ wget -N https://raw.githubusercontent.com/wyx2685/V2bX-script/master/install.sh
|
|||||||
## 构建
|
## 构建
|
||||||
``` bash
|
``` bash
|
||||||
# 通过-tags选项指定要编译的内核, 可选 xray, sing, hysteria2
|
# 通过-tags选项指定要编译的内核, 可选 xray, sing, hysteria2
|
||||||
go build -v -o ./V2bX -tags "xray sing hysteria2 with_reality_server with_quic with_grpc with_utls with_wireguard with_acme" -trimpath -ldflags "-s -w -buildid="
|
GOEXPERIMENT=jsonv2 go build -v -o build_assets/V2bX -tags "sing xray hysteria2 with_quic with_grpc with_utls with_wireguard with_acme with_gvisor" -trimpath -ldflags "-X 'github.com/InazumaV/V2bX/cmd.version=$version' -s -w -buildid="
|
||||||
```
|
```
|
||||||
|
|
||||||
## 配置文件及详细使用教程
|
## 配置文件及详细使用教程
|
||||||
@@ -72,6 +71,10 @@ go build -v -o ./V2bX -tags "xray sing hysteria2 with_reality_server with_quic w
|
|||||||
* 本人不对任何人使用本项目造成的任何后果承担责任。
|
* 本人不对任何人使用本项目造成的任何后果承担责任。
|
||||||
* 本人比较多变,因此本项目可能会随想法或思路的变动随性更改项目结构或大规模重构代码,若不能接受请勿使用。
|
* 本人比较多变,因此本项目可能会随想法或思路的变动随性更改项目结构或大规模重构代码,若不能接受请勿使用。
|
||||||
|
|
||||||
|
## 赞助
|
||||||
|
|
||||||
|
[赞助链接](https://v-50.me/)
|
||||||
|
|
||||||
## Thanks
|
## Thanks
|
||||||
|
|
||||||
* [Project X](https://github.com/XTLS/)
|
* [Project X](https://github.com/XTLS/)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/goccy/go-json"
|
"encoding/json"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Security type
|
// Security type
|
||||||
@@ -33,6 +33,7 @@ type NodeInfo struct {
|
|||||||
Shadowsocks *ShadowsocksNode
|
Shadowsocks *ShadowsocksNode
|
||||||
Trojan *TrojanNode
|
Trojan *TrojanNode
|
||||||
Tuic *TuicNode
|
Tuic *TuicNode
|
||||||
|
AnyTls *AnyTlsNode
|
||||||
Hysteria *HysteriaNode
|
Hysteria *HysteriaNode
|
||||||
Hysteria2 *Hysteria2Node
|
Hysteria2 *Hysteria2Node
|
||||||
Common *CommonNode
|
Common *CommonNode
|
||||||
@@ -66,6 +67,8 @@ type VAllssNode struct {
|
|||||||
Network string `json:"network"`
|
Network string `json:"network"`
|
||||||
NetworkSettings json.RawMessage `json:"network_settings"`
|
NetworkSettings json.RawMessage `json:"network_settings"`
|
||||||
NetworkSettingsBack json.RawMessage `json:"networkSettings"`
|
NetworkSettingsBack json.RawMessage `json:"networkSettings"`
|
||||||
|
Encryption string `json:"encryption"`
|
||||||
|
EncryptionSettings EncSettings `json:"encryption_settings"`
|
||||||
ServerName string `json:"server_name"`
|
ServerName string `json:"server_name"`
|
||||||
|
|
||||||
// vless only
|
// vless only
|
||||||
@@ -74,12 +77,20 @@ type VAllssNode struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type TlsSettings struct {
|
type TlsSettings struct {
|
||||||
ServerName string `json:"server_name"`
|
ServerName string `json:"server_name"`
|
||||||
Dest string `json:"dest"`
|
Dest string `json:"dest"`
|
||||||
ServerPort string `json:"server_port"`
|
ServerPort string `json:"server_port"`
|
||||||
ShortId string `json:"short_id"`
|
ShortId string `json:"short_id"`
|
||||||
PrivateKey string `json:"private_key"`
|
PrivateKey string `json:"private_key"`
|
||||||
Xver uint64 `json:"xver,string"`
|
Mldsa65Seed string `json:"mldsa65Seed"`
|
||||||
|
Xver uint64 `json:"xver,string"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type EncSettings struct {
|
||||||
|
Mode string `json:"mode"`
|
||||||
|
Ticket string `json:"ticket"`
|
||||||
|
ServerPadding string `json:"server_padding"`
|
||||||
|
PrivateKey string `json:"private_key"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type RealityConfig struct {
|
type RealityConfig struct {
|
||||||
@@ -107,6 +118,11 @@ type TuicNode struct {
|
|||||||
ZeroRTTHandshake bool `json:"zero_rtt_handshake"`
|
ZeroRTTHandshake bool `json:"zero_rtt_handshake"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type AnyTlsNode struct {
|
||||||
|
CommonNode
|
||||||
|
PaddingScheme []string `json:"padding_scheme,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
type HysteriaNode struct {
|
type HysteriaNode struct {
|
||||||
CommonNode
|
CommonNode
|
||||||
UpMbps int `json:"up_mbps"`
|
UpMbps int `json:"up_mbps"`
|
||||||
@@ -219,6 +235,15 @@ func (c *Client) GetNodeInfo() (node *NodeInfo, err error) {
|
|||||||
cm = &rsp.CommonNode
|
cm = &rsp.CommonNode
|
||||||
node.Tuic = rsp
|
node.Tuic = rsp
|
||||||
node.Security = Tls
|
node.Security = Tls
|
||||||
|
case "anytls":
|
||||||
|
rsp := &AnyTlsNode{}
|
||||||
|
err = json.Unmarshal(r.Body(), rsp)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("decode anytls params error: %s", err)
|
||||||
|
}
|
||||||
|
cm = &rsp.CommonNode
|
||||||
|
node.AnyTls = rsp
|
||||||
|
node.Security = Tls
|
||||||
case "hysteria":
|
case "hysteria":
|
||||||
rsp := &HysteriaNode{}
|
rsp := &HysteriaNode{}
|
||||||
err = json.Unmarshal(r.Body(), rsp)
|
err = json.Unmarshal(r.Body(), rsp)
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ func New(c *conf.ApiConfig) (*Client, error) {
|
|||||||
"hysteria",
|
"hysteria",
|
||||||
"hysteria2",
|
"hysteria2",
|
||||||
"tuic",
|
"tuic",
|
||||||
|
"anytls",
|
||||||
"vless":
|
"vless":
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("unsupported Node type: %s", c.NodeType)
|
return nil, fmt.Errorf("unsupported Node type: %s", c.NodeType)
|
||||||
|
|||||||
@@ -2,8 +2,12 @@ package panel
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/goccy/go-json"
|
"encoding/json/jsontext"
|
||||||
|
"encoding/json/v2"
|
||||||
|
|
||||||
|
"github.com/vmihailenco/msgpack/v5"
|
||||||
)
|
)
|
||||||
|
|
||||||
type OnlineUser struct {
|
type OnlineUser struct {
|
||||||
@@ -12,15 +16,14 @@ type OnlineUser struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type UserInfo struct {
|
type UserInfo struct {
|
||||||
Id int `json:"id"`
|
Id int `json:"id" msgpack:"id"`
|
||||||
Uuid string `json:"uuid"`
|
Uuid string `json:"uuid" msgpack:"uuid"`
|
||||||
SpeedLimit int `json:"speed_limit"`
|
SpeedLimit int `json:"speed_limit" msgpack:"speed_limit"`
|
||||||
DeviceLimit int `json:"device_limit"`
|
DeviceLimit int `json:"device_limit" msgpack:"device_limit"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type UserListBody struct {
|
type UserListBody struct {
|
||||||
//Msg string `json:"msg"`
|
Users []UserInfo `json:"users" msgpack:"users"`
|
||||||
Users []UserInfo `json:"users"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type AliveMap struct {
|
type AliveMap struct {
|
||||||
@@ -32,7 +35,8 @@ func (c *Client) GetUserList() ([]UserInfo, error) {
|
|||||||
const path = "/api/v1/server/UniProxy/user"
|
const path = "/api/v1/server/UniProxy/user"
|
||||||
r, err := c.client.R().
|
r, err := c.client.R().
|
||||||
SetHeader("If-None-Match", c.userEtag).
|
SetHeader("If-None-Match", c.userEtag).
|
||||||
ForceContentType("application/json").
|
SetHeader("X-Response-Format", "msgpack").
|
||||||
|
SetDoNotParseResponse(true).
|
||||||
Get(path)
|
Get(path)
|
||||||
if r == nil || r.RawResponse == nil {
|
if r == nil || r.RawResponse == nil {
|
||||||
return nil, fmt.Errorf("received nil response or raw response")
|
return nil, fmt.Errorf("received nil response or raw response")
|
||||||
@@ -47,8 +51,40 @@ func (c *Client) GetUserList() ([]UserInfo, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
userlist := &UserListBody{}
|
userlist := &UserListBody{}
|
||||||
if err := json.Unmarshal(r.Body(), userlist); err != nil {
|
if strings.Contains(r.Header().Get("Content-Type"), "application/x-msgpack") {
|
||||||
return nil, fmt.Errorf("unmarshal user list error: %w", err)
|
decoder := msgpack.NewDecoder(r.RawResponse.Body)
|
||||||
|
if err := decoder.Decode(userlist); err != nil {
|
||||||
|
return nil, fmt.Errorf("decode user list error: %w", err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
dec := jsontext.NewDecoder(r.RawResponse.Body)
|
||||||
|
for {
|
||||||
|
tok, err := dec.ReadToken()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("decode user list error: %w", err)
|
||||||
|
}
|
||||||
|
if tok.Kind() == '"' && tok.String() == "users" {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tok, err := dec.ReadToken()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("decode user list error: %w", err)
|
||||||
|
}
|
||||||
|
if tok.Kind() != '[' {
|
||||||
|
return nil, fmt.Errorf(`decode user list error: expected "users" array`)
|
||||||
|
}
|
||||||
|
for dec.PeekKind() != ']' {
|
||||||
|
val, err := dec.ReadValue()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("decode user list error: read user object: %w", err)
|
||||||
|
}
|
||||||
|
var u UserInfo
|
||||||
|
if err := json.Unmarshal(val, &u); err != nil {
|
||||||
|
return nil, fmt.Errorf("decode user list error: unmarshal user error: %w", err)
|
||||||
|
}
|
||||||
|
userlist.Users = append(userlist.Users, u)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
c.userEtag = r.Header().Get("ETag")
|
c.userEtag = r.Header().Get("ETag")
|
||||||
return userlist.Users, nil
|
return userlist.Users, nil
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import (
|
|||||||
"github.com/InazumaV/V2bX/node"
|
"github.com/InazumaV/V2bX/node"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"gopkg.in/natefinch/lumberjack.v2"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -56,14 +55,11 @@ func serverHandle(_ *cobra.Command, _ []string) {
|
|||||||
log.SetLevel(log.ErrorLevel)
|
log.SetLevel(log.ErrorLevel)
|
||||||
}
|
}
|
||||||
if c.LogConfig.Output != "" {
|
if c.LogConfig.Output != "" {
|
||||||
w := &lumberjack.Logger{
|
f, err := os.OpenFile(c.LogConfig.Output, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
|
||||||
Filename: c.LogConfig.Output,
|
if err != nil {
|
||||||
MaxSize: 100,
|
log.WithField("err", err).Error("Open log file failed, using stdout instead")
|
||||||
MaxBackups: 3,
|
|
||||||
MaxAge: 28,
|
|
||||||
Compress: true,
|
|
||||||
}
|
}
|
||||||
log.SetOutput(w)
|
log.SetOutput(f)
|
||||||
}
|
}
|
||||||
limiter.Init()
|
limiter.Init()
|
||||||
log.Info("Start V2bX...")
|
log.Info("Start V2bX...")
|
||||||
@@ -125,7 +121,7 @@ func serverHandle(_ *cobra.Command, _ []string) {
|
|||||||
// wait exit signal
|
// wait exit signal
|
||||||
{
|
{
|
||||||
osSignals := make(chan os.Signal, 1)
|
osSignals := make(chan os.Signal, 1)
|
||||||
signal.Notify(osSignals, syscall.SIGINT, syscall.SIGKILL, syscall.SIGTERM)
|
signal.Notify(osSignals, syscall.SIGINT, syscall.SIGTERM)
|
||||||
<-osSignals
|
<-osSignals
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type TrafficCounter struct {
|
type TrafficCounter struct {
|
||||||
counters sync.Map
|
Counters sync.Map
|
||||||
}
|
}
|
||||||
|
|
||||||
type TrafficStorage struct {
|
type TrafficStorage struct {
|
||||||
@@ -18,26 +18,26 @@ func NewTrafficCounter() *TrafficCounter {
|
|||||||
return &TrafficCounter{}
|
return &TrafficCounter{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *TrafficCounter) GetCounter(id string) *TrafficStorage {
|
func (c *TrafficCounter) GetCounter(uuid string) *TrafficStorage {
|
||||||
if cts, ok := c.counters.Load(id); ok {
|
if cts, ok := c.Counters.Load(uuid); ok {
|
||||||
return cts.(*TrafficStorage)
|
return cts.(*TrafficStorage)
|
||||||
}
|
}
|
||||||
newStorage := &TrafficStorage{}
|
newStorage := &TrafficStorage{}
|
||||||
if cts, loaded := c.counters.LoadOrStore(id, newStorage); loaded {
|
if cts, loaded := c.Counters.LoadOrStore(uuid, newStorage); loaded {
|
||||||
return cts.(*TrafficStorage)
|
return cts.(*TrafficStorage)
|
||||||
}
|
}
|
||||||
return newStorage
|
return newStorage
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *TrafficCounter) GetUpCount(id string) int64 {
|
func (c *TrafficCounter) GetUpCount(uuid string) int64 {
|
||||||
if cts, ok := c.counters.Load(id); ok {
|
if cts, ok := c.Counters.Load(uuid); ok {
|
||||||
return cts.(*TrafficStorage).UpCounter.Load()
|
return cts.(*TrafficStorage).UpCounter.Load()
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *TrafficCounter) GetDownCount(id string) int64 {
|
func (c *TrafficCounter) GetDownCount(uuid string) int64 {
|
||||||
if cts, ok := c.counters.Load(id); ok {
|
if cts, ok := c.Counters.Load(uuid); ok {
|
||||||
return cts.(*TrafficStorage).DownCounter.Load()
|
return cts.(*TrafficStorage).DownCounter.Load()
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
@@ -45,30 +45,30 @@ func (c *TrafficCounter) GetDownCount(id string) int64 {
|
|||||||
|
|
||||||
func (c *TrafficCounter) Len() int {
|
func (c *TrafficCounter) Len() int {
|
||||||
length := 0
|
length := 0
|
||||||
c.counters.Range(func(_, _ interface{}) bool {
|
c.Counters.Range(func(_, _ interface{}) bool {
|
||||||
length++
|
length++
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
return length
|
return length
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *TrafficCounter) Reset(id string) {
|
func (c *TrafficCounter) Reset(uuid string) {
|
||||||
if cts, ok := c.counters.Load(id); ok {
|
if cts, ok := c.Counters.Load(uuid); ok {
|
||||||
cts.(*TrafficStorage).UpCounter.Store(0)
|
cts.(*TrafficStorage).UpCounter.Store(0)
|
||||||
cts.(*TrafficStorage).DownCounter.Store(0)
|
cts.(*TrafficStorage).DownCounter.Store(0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *TrafficCounter) Delete(id string) {
|
func (c *TrafficCounter) Delete(uuid string) {
|
||||||
c.counters.Delete(id)
|
c.Counters.Delete(uuid)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *TrafficCounter) Rx(id string, n int) {
|
func (c *TrafficCounter) Rx(uuid string, n int) {
|
||||||
cts := c.GetCounter(id)
|
cts := c.GetCounter(uuid)
|
||||||
cts.DownCounter.Add(int64(n))
|
cts.DownCounter.Add(int64(n))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *TrafficCounter) Tx(id string, n int) {
|
func (c *TrafficCounter) Tx(uuid string, n int) {
|
||||||
cts := c.GetCounter(id)
|
cts := c.GetCounter(uuid)
|
||||||
cts.UpCounter.Add(int64(n))
|
cts.UpCounter.Add(int64(n))
|
||||||
}
|
}
|
||||||
|
|||||||
25
common/counter/xraytraffic.go
Normal file
25
common/counter/xraytraffic.go
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package counter
|
||||||
|
|
||||||
|
import (
|
||||||
|
"sync/atomic"
|
||||||
|
|
||||||
|
fstats "github.com/xtls/xray-core/features/stats"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ fstats.Counter = (*XrayTrafficCounter)(nil)
|
||||||
|
|
||||||
|
type XrayTrafficCounter struct {
|
||||||
|
V *atomic.Int64
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *XrayTrafficCounter) Value() int64 {
|
||||||
|
return c.V.Load()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *XrayTrafficCounter) Set(newValue int64) int64 {
|
||||||
|
return c.V.Swap(newValue)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *XrayTrafficCounter) Add(delta int64) int64 {
|
||||||
|
return c.V.Add(delta)
|
||||||
|
}
|
||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
|
|
||||||
"github.com/InazumaV/V2bX/common/json5"
|
"github.com/InazumaV/V2bX/common/json5"
|
||||||
|
|
||||||
"github.com/goccy/go-json"
|
"encoding/json/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Conf struct {
|
type Conf struct {
|
||||||
|
|||||||
@@ -7,8 +7,9 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/InazumaV/V2bX/common/json5"
|
"github.com/InazumaV/V2bX/common/json5"
|
||||||
"github.com/goccy/go-json"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type NodeConfig struct {
|
type NodeConfig struct {
|
||||||
@@ -109,6 +110,7 @@ type Options struct {
|
|||||||
ListenIP string `json:"ListenIP"`
|
ListenIP string `json:"ListenIP"`
|
||||||
SendIP string `json:"SendIP"`
|
SendIP string `json:"SendIP"`
|
||||||
DeviceOnlineMinTraffic int64 `json:"DeviceOnlineMinTraffic"`
|
DeviceOnlineMinTraffic int64 `json:"DeviceOnlineMinTraffic"`
|
||||||
|
ReportMinTraffic int64 `json:"ReportMinTraffic"`
|
||||||
LimitConfig LimitConfig `json:"LimitConfig"`
|
LimitConfig LimitConfig `json:"LimitConfig"`
|
||||||
RawOptions json.RawMessage `json:"RawOptions"`
|
RawOptions json.RawMessage `json:"RawOptions"`
|
||||||
XrayOptions *XrayOptions `json:"XrayOptions"`
|
XrayOptions *XrayOptions `json:"XrayOptions"`
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func NewCore(c []conf.CoreConfig) (Core, error) {
|
func NewCore(c []conf.CoreConfig) (Core, error) {
|
||||||
if len(c) < 0 {
|
if len(c) == 0 {
|
||||||
return nil, errors.New("no have vail core")
|
return nil, errors.New("no have vail core")
|
||||||
}
|
}
|
||||||
// multi core
|
// multi core
|
||||||
|
|||||||
@@ -14,9 +14,10 @@ import (
|
|||||||
var _ server.TrafficLogger = (*HookServer)(nil)
|
var _ server.TrafficLogger = (*HookServer)(nil)
|
||||||
|
|
||||||
type HookServer struct {
|
type HookServer struct {
|
||||||
Tag string
|
Tag string
|
||||||
logger *zap.Logger
|
logger *zap.Logger
|
||||||
Counter sync.Map
|
Counter sync.Map
|
||||||
|
ReportMinTrafficBytes int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HookServer) TraceStream(stream quic.Stream, stats *server.StreamStats) {
|
func (h *HookServer) TraceStream(stream quic.Stream, stats *server.StreamStats) {
|
||||||
|
|||||||
@@ -40,8 +40,9 @@ func (h *Hysteria2) AddNode(tag string, info *panel.NodeInfo, config *conf.Optio
|
|||||||
logger: h.Logger,
|
logger: h.Logger,
|
||||||
},
|
},
|
||||||
TrafficLogger: &HookServer{
|
TrafficLogger: &HookServer{
|
||||||
Tag: tag,
|
Tag: tag,
|
||||||
logger: h.Logger,
|
logger: h.Logger,
|
||||||
|
ReportMinTrafficBytes: config.ReportMinTraffic * 1024,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,12 +14,12 @@ var _ server.Authenticator = &V2bX{}
|
|||||||
|
|
||||||
type V2bX struct {
|
type V2bX struct {
|
||||||
usersMap map[string]int
|
usersMap map[string]int
|
||||||
mutex sync.Mutex
|
mutex sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *V2bX) Authenticate(addr net.Addr, auth string, tx uint64) (ok bool, id string) {
|
func (v *V2bX) Authenticate(addr net.Addr, auth string, tx uint64) (ok bool, id string) {
|
||||||
v.mutex.Lock()
|
v.mutex.RLock()
|
||||||
defer v.mutex.Unlock()
|
defer v.mutex.RUnlock()
|
||||||
if _, exists := v.usersMap[auth]; exists {
|
if _, exists := v.usersMap[auth]; exists {
|
||||||
return true, auth
|
return true, auth
|
||||||
}
|
}
|
||||||
@@ -56,15 +56,38 @@ func (h *Hysteria2) DelUsers(users []panel.UserInfo, tag string, _ *panel.NodeIn
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Hysteria2) GetUserTraffic(tag string, uuid string, reset bool) (up int64, down int64) {
|
func (h *Hysteria2) GetUserTrafficSlice(tag string, reset bool) ([]panel.UserTraffic, error) {
|
||||||
if v, ok := h.Hy2nodes[tag].TrafficLogger.(*HookServer).Counter.Load(tag); ok {
|
trafficSlice := make([]panel.UserTraffic, 0)
|
||||||
c := v.(*counter.TrafficCounter)
|
h.Auth.mutex.RLock()
|
||||||
up = c.GetUpCount(uuid)
|
defer h.Auth.mutex.RUnlock()
|
||||||
down = c.GetDownCount(uuid)
|
if _, ok := h.Hy2nodes[tag]; !ok {
|
||||||
if reset {
|
return nil, nil
|
||||||
c.Reset(uuid)
|
|
||||||
}
|
|
||||||
return up, down
|
|
||||||
}
|
}
|
||||||
return 0, 0
|
hook := h.Hy2nodes[tag].TrafficLogger.(*HookServer)
|
||||||
|
if v, ok := hook.Counter.Load(tag); ok {
|
||||||
|
c := v.(*counter.TrafficCounter)
|
||||||
|
c.Counters.Range(func(key, value interface{}) bool {
|
||||||
|
uuid := key.(string)
|
||||||
|
traffic := value.(*counter.TrafficStorage)
|
||||||
|
up := traffic.UpCounter.Load()
|
||||||
|
down := traffic.DownCounter.Load()
|
||||||
|
if up+down > hook.ReportMinTrafficBytes {
|
||||||
|
if reset {
|
||||||
|
traffic.UpCounter.Store(0)
|
||||||
|
traffic.DownCounter.Store(0)
|
||||||
|
}
|
||||||
|
trafficSlice = append(trafficSlice, panel.UserTraffic{
|
||||||
|
UID: h.Auth.usersMap[uuid],
|
||||||
|
Upload: up,
|
||||||
|
Download: down,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
if len(trafficSlice) == 0 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
return trafficSlice, nil
|
||||||
|
}
|
||||||
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ type Core interface {
|
|||||||
AddNode(tag string, info *panel.NodeInfo, config *conf.Options) error
|
AddNode(tag string, info *panel.NodeInfo, config *conf.Options) error
|
||||||
DelNode(tag string) error
|
DelNode(tag string) error
|
||||||
AddUsers(p *AddUsersParams) (added int, err error)
|
AddUsers(p *AddUsersParams) (added int, err error)
|
||||||
GetUserTraffic(tag, uuid string, reset bool) (up int64, down int64)
|
GetUserTrafficSlice(tag string, reset bool) ([]panel.UserTraffic, error)
|
||||||
DelUsers(users []panel.UserInfo, tag string, info *panel.NodeInfo) error
|
DelUsers(users []panel.UserInfo, tag string, info *panel.NodeInfo) error
|
||||||
Protocols() []string
|
Protocols() []string
|
||||||
Type() string
|
Type() string
|
||||||
|
|||||||
@@ -6,8 +6,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/hashicorp/go-multierror"
|
|
||||||
|
|
||||||
"github.com/InazumaV/V2bX/api/panel"
|
"github.com/InazumaV/V2bX/api/panel"
|
||||||
"github.com/InazumaV/V2bX/conf"
|
"github.com/InazumaV/V2bX/conf"
|
||||||
)
|
)
|
||||||
@@ -50,14 +48,13 @@ func (s *Selector) Start() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Selector) Close() error {
|
func (s *Selector) Close() error {
|
||||||
var errs error
|
var errs []error
|
||||||
for i := range s.cores {
|
for i := range s.cores {
|
||||||
err := s.cores[i].Close()
|
if err := s.cores[i].Close(); err != nil {
|
||||||
if err != nil {
|
errs = append(errs, err)
|
||||||
errs = multierror.Append(errs, err)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return errs
|
return errors.Join(errs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func isSupported(protocol string, protocols []string) bool {
|
func isSupported(protocol string, protocols []string) bool {
|
||||||
@@ -128,12 +125,12 @@ func (s *Selector) AddUsers(p *AddUsersParams) (added int, err error) {
|
|||||||
return t.(Core).AddUsers(p)
|
return t.(Core).AddUsers(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Selector) GetUserTraffic(tag, uuid string, reset bool) (up int64, down int64) {
|
func (s *Selector) GetUserTrafficSlice(tag string, reset bool) ([]panel.UserTraffic, error) {
|
||||||
t, e := s.nodes.Load(tag)
|
t, e := s.nodes.Load(tag)
|
||||||
if !e {
|
if !e {
|
||||||
return 0, 0
|
return nil, errors.New("the node is not have")
|
||||||
}
|
}
|
||||||
return t.(Core).GetUserTraffic(tag, uuid, reset)
|
return t.(Core).GetUserTrafficSlice(tag, reset)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Selector) DelUsers(users []panel.UserInfo, tag string, info *panel.NodeInfo) error {
|
func (s *Selector) DelUsers(users []panel.UserInfo, tag string, info *panel.NodeInfo) error {
|
||||||
|
|||||||
@@ -27,13 +27,6 @@ func (h *HookServer) ModeList() []string {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHookServer() *HookServer {
|
|
||||||
server := &HookServer{
|
|
||||||
counter: sync.Map{},
|
|
||||||
}
|
|
||||||
return server
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *HookServer) RoutedConnection(_ context.Context, conn net.Conn, m adapter.InboundContext, _ adapter.Rule, _ adapter.Outbound) net.Conn {
|
func (h *HookServer) RoutedConnection(_ context.Context, conn net.Conn, m adapter.InboundContext, _ adapter.Rule, _ adapter.Outbound) net.Conn {
|
||||||
l, err := limiter.GetLimiter(m.Inbound)
|
l, err := limiter.GetLimiter(m.Inbound)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -51,7 +44,7 @@ func (h *HookServer) RoutedConnection(_ context.Context, conn net.Conn, m adapte
|
|||||||
}
|
}
|
||||||
if l != nil {
|
if l != nil {
|
||||||
destStr := m.Destination.AddrString()
|
destStr := m.Destination.AddrString()
|
||||||
protocol := m.Destination.Network()
|
protocol := m.Protocol
|
||||||
if l.CheckDomainRule(destStr) {
|
if l.CheckDomainRule(destStr) {
|
||||||
log.Error(fmt.Sprintf(
|
log.Error(fmt.Sprintf(
|
||||||
"User %s access domain %s reject by rule",
|
"User %s access domain %s reject by rule",
|
||||||
|
|||||||
@@ -10,9 +10,10 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/InazumaV/V2bX/api/panel"
|
"github.com/InazumaV/V2bX/api/panel"
|
||||||
"github.com/InazumaV/V2bX/conf"
|
"github.com/InazumaV/V2bX/conf"
|
||||||
"github.com/goccy/go-json"
|
|
||||||
"github.com/sagernet/sing-box/option"
|
"github.com/sagernet/sing-box/option"
|
||||||
F "github.com/sagernet/sing/common/format"
|
F "github.com/sagernet/sing/common/format"
|
||||||
"github.com/sagernet/sing/common/json/badoption"
|
"github.com/sagernet/sing/common/json/badoption"
|
||||||
@@ -54,19 +55,10 @@ func getInboundOptions(tag string, info *panel.NodeInfo, c *conf.Options) (optio
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return option.Inbound{}, fmt.Errorf("the listen ip not vail")
|
return option.Inbound{}, fmt.Errorf("the listen ip not vail")
|
||||||
}
|
}
|
||||||
var domainStrategy option.DomainStrategy
|
|
||||||
if c.SingOptions.EnableDNS {
|
|
||||||
domainStrategy = c.SingOptions.DomainStrategy
|
|
||||||
}
|
|
||||||
listen := option.ListenOptions{
|
listen := option.ListenOptions{
|
||||||
Listen: (*badoption.Addr)(&addr),
|
Listen: (*badoption.Addr)(&addr),
|
||||||
ListenPort: uint16(info.Common.ServerPort),
|
ListenPort: uint16(info.Common.ServerPort),
|
||||||
TCPFastOpen: c.SingOptions.TCPFastOpen,
|
TCPFastOpen: c.SingOptions.TCPFastOpen,
|
||||||
InboundOptions: option.InboundOptions{
|
|
||||||
SniffEnabled: c.SingOptions.SniffEnabled,
|
|
||||||
SniffOverrideDestination: c.SingOptions.SniffOverrideDestination,
|
|
||||||
DomainStrategy: domainStrategy,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
var multiplex *option.InboundMultiplexOptions
|
var multiplex *option.InboundMultiplexOptions
|
||||||
if c.SingOptions.Multiplex != nil {
|
if c.SingOptions.Multiplex != nil {
|
||||||
@@ -354,6 +346,15 @@ func getInboundOptions(tag string, info *panel.NodeInfo, c *conf.Options) (optio
|
|||||||
TLS: &tls,
|
TLS: &tls,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
case "anytls":
|
||||||
|
in.Type = "anytls"
|
||||||
|
in.Options = &option.AnyTLSInboundOptions{
|
||||||
|
ListenOptions: listen,
|
||||||
|
PaddingScheme: info.AnyTls.PaddingScheme,
|
||||||
|
InboundTLSOptionsContainer: option.InboundTLSOptionsContainer{
|
||||||
|
TLS: &tls,
|
||||||
|
},
|
||||||
|
}
|
||||||
case "hysteria":
|
case "hysteria":
|
||||||
in.Type = "hysteria"
|
in.Type = "hysteria"
|
||||||
in.Options = &option.HysteriaInboundOptions{
|
in.Options = &option.HysteriaInboundOptions{
|
||||||
@@ -394,6 +395,7 @@ func getInboundOptions(tag string, info *panel.NodeInfo, c *conf.Options) (optio
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *Sing) AddNode(tag string, info *panel.NodeInfo, config *conf.Options) error {
|
func (b *Sing) AddNode(tag string, info *panel.NodeInfo, config *conf.Options) error {
|
||||||
|
b.nodeReportMinTrafficBytes[tag] = config.ReportMinTraffic * 1024
|
||||||
c, err := getInboundOptions(tag, info, config)
|
c, err := getInboundOptions(tag, info, config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/sagernet/sing-box/include"
|
"github.com/sagernet/sing-box/include"
|
||||||
"github.com/sagernet/sing-box/log"
|
"github.com/sagernet/sing-box/log"
|
||||||
@@ -24,11 +25,18 @@ type DNSConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Sing struct {
|
type Sing struct {
|
||||||
box *box.Box
|
box *box.Box
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
hookServer *HookServer
|
hookServer *HookServer
|
||||||
router adapter.Router
|
router adapter.Router
|
||||||
logFactory log.Factory
|
logFactory log.Factory
|
||||||
|
users *UserMap
|
||||||
|
nodeReportMinTrafficBytes map[string]int64
|
||||||
|
}
|
||||||
|
|
||||||
|
type UserMap struct {
|
||||||
|
uidMap map[string]int
|
||||||
|
mapLock sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -37,7 +45,7 @@ func init() {
|
|||||||
|
|
||||||
func New(c *conf.CoreConfig) (vCore.Core, error) {
|
func New(c *conf.CoreConfig) (vCore.Core, error) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
ctx = box.Context(ctx, include.InboundRegistry(), include.OutboundRegistry(), include.EndpointRegistry(), include.DNSTransportRegistry())
|
ctx = box.Context(ctx, include.InboundRegistry(), include.OutboundRegistry(), include.EndpointRegistry(), include.DNSTransportRegistry(), include.ServiceRegistry())
|
||||||
options := option.Options{}
|
options := option.Options{}
|
||||||
if len(c.SingConfig.OriginalPath) != 0 {
|
if len(c.SingConfig.OriginalPath) != 0 {
|
||||||
data, err := os.ReadFile(c.SingConfig.OriginalPath)
|
data, err := os.ReadFile(c.SingConfig.OriginalPath)
|
||||||
@@ -71,14 +79,20 @@ func New(c *conf.CoreConfig) (vCore.Core, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
hs := NewHookServer()
|
hs := &HookServer{
|
||||||
b.Router().SetTracker(hs)
|
counter: sync.Map{},
|
||||||
|
}
|
||||||
|
b.Router().AppendTracker(hs)
|
||||||
return &Sing{
|
return &Sing{
|
||||||
ctx: b.Router().GetCtx(),
|
ctx: b.Router().GetCtx(),
|
||||||
box: b,
|
box: b,
|
||||||
hookServer: hs,
|
hookServer: hs,
|
||||||
router: b.Router(),
|
router: b.Router(),
|
||||||
logFactory: b.LogFactory(),
|
logFactory: b.LogFactory(),
|
||||||
|
users: &UserMap{
|
||||||
|
uidMap: make(map[string]int),
|
||||||
|
},
|
||||||
|
nodeReportMinTrafficBytes: make(map[string]int64),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,6 +111,7 @@ func (b *Sing) Protocols() []string {
|
|||||||
"shadowsocks",
|
"shadowsocks",
|
||||||
"trojan",
|
"trojan",
|
||||||
"tuic",
|
"tuic",
|
||||||
|
"anytls",
|
||||||
"hysteria",
|
"hysteria",
|
||||||
"hysteria2",
|
"hysteria2",
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/InazumaV/V2bX/common/counter"
|
"github.com/InazumaV/V2bX/common/counter"
|
||||||
"github.com/InazumaV/V2bX/core"
|
"github.com/InazumaV/V2bX/core"
|
||||||
"github.com/sagernet/sing-box/option"
|
"github.com/sagernet/sing-box/option"
|
||||||
|
"github.com/sagernet/sing-box/protocol/anytls"
|
||||||
"github.com/sagernet/sing-box/protocol/hysteria"
|
"github.com/sagernet/sing-box/protocol/hysteria"
|
||||||
"github.com/sagernet/sing-box/protocol/hysteria2"
|
"github.com/sagernet/sing-box/protocol/hysteria2"
|
||||||
"github.com/sagernet/sing-box/protocol/shadowsocks"
|
"github.com/sagernet/sing-box/protocol/shadowsocks"
|
||||||
@@ -22,6 +23,11 @@ func (b *Sing) AddUsers(p *core.AddUsersParams) (added int, err error) {
|
|||||||
if !found {
|
if !found {
|
||||||
return 0, errors.New("the inbound not found")
|
return 0, errors.New("the inbound not found")
|
||||||
}
|
}
|
||||||
|
b.users.mapLock.Lock()
|
||||||
|
defer b.users.mapLock.Unlock()
|
||||||
|
for i := range p.Users {
|
||||||
|
b.users.uidMap[p.Users[i].Uuid] = p.Users[i].Id
|
||||||
|
}
|
||||||
switch p.NodeInfo.Type {
|
switch p.NodeInfo.Type {
|
||||||
case "vless":
|
case "vless":
|
||||||
us := make([]option.VLESSUser, len(p.Users))
|
us := make([]option.VLESSUser, len(p.Users))
|
||||||
@@ -99,6 +105,15 @@ func (b *Sing) AddUsers(p *core.AddUsersParams) (added int, err error) {
|
|||||||
id[i] = p.Users[i].Id
|
id[i] = p.Users[i].Id
|
||||||
}
|
}
|
||||||
err = in.(*hysteria2.Inbound).AddUsers(us, id)
|
err = in.(*hysteria2.Inbound).AddUsers(us, id)
|
||||||
|
case "anytls":
|
||||||
|
us := make([]option.AnyTLSUser, len(p.Users))
|
||||||
|
for i := range p.Users {
|
||||||
|
us[i] = option.AnyTLSUser{
|
||||||
|
Name: p.Users[i].Uuid,
|
||||||
|
Password: p.Users[i].Uuid,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
err = in.(*anytls.Inbound).AddUsers(us)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
@@ -119,6 +134,39 @@ func (b *Sing) GetUserTraffic(tag, uuid string, reset bool) (up int64, down int6
|
|||||||
return 0, 0
|
return 0, 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *Sing) GetUserTrafficSlice(tag string, reset bool) ([]panel.UserTraffic, error) {
|
||||||
|
trafficSlice := make([]panel.UserTraffic, 0)
|
||||||
|
hook := b.hookServer
|
||||||
|
b.users.mapLock.RLock()
|
||||||
|
defer b.users.mapLock.RUnlock()
|
||||||
|
if v, ok := hook.counter.Load(tag); ok {
|
||||||
|
c := v.(*counter.TrafficCounter)
|
||||||
|
c.Counters.Range(func(key, value interface{}) bool {
|
||||||
|
uuid := key.(string)
|
||||||
|
traffic := value.(*counter.TrafficStorage)
|
||||||
|
up := traffic.UpCounter.Load()
|
||||||
|
down := traffic.DownCounter.Load()
|
||||||
|
if up+down > b.nodeReportMinTrafficBytes[tag] {
|
||||||
|
if reset {
|
||||||
|
traffic.UpCounter.Store(0)
|
||||||
|
traffic.DownCounter.Store(0)
|
||||||
|
}
|
||||||
|
trafficSlice = append(trafficSlice, panel.UserTraffic{
|
||||||
|
UID: b.users.uidMap[uuid],
|
||||||
|
Upload: up,
|
||||||
|
Download: down,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
if len(trafficSlice) == 0 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
return trafficSlice, nil
|
||||||
|
}
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
type UserDeleter interface {
|
type UserDeleter interface {
|
||||||
DelUsers(uuid []string) error
|
DelUsers(uuid []string) error
|
||||||
}
|
}
|
||||||
@@ -141,12 +189,17 @@ func (b *Sing) DelUsers(users []panel.UserInfo, tag string, info *panel.NodeInfo
|
|||||||
del = i.(*hysteria.Inbound)
|
del = i.(*hysteria.Inbound)
|
||||||
case "hysteria2":
|
case "hysteria2":
|
||||||
del = i.(*hysteria2.Inbound)
|
del = i.(*hysteria2.Inbound)
|
||||||
|
case "anytls":
|
||||||
|
del = i.(*anytls.Inbound)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return errors.New("the inbound not found")
|
return errors.New("the inbound not found")
|
||||||
}
|
}
|
||||||
uuids := make([]string, len(users))
|
uuids := make([]string, len(users))
|
||||||
|
b.users.mapLock.Lock()
|
||||||
|
defer b.users.mapLock.Unlock()
|
||||||
for i := range users {
|
for i := range users {
|
||||||
|
delete(b.users.uidMap, users[i].Uuid)
|
||||||
uuids[i] = users[i].Uuid
|
uuids[i] = users[i].Uuid
|
||||||
}
|
}
|
||||||
err := del.DelUsers(uuids)
|
err := del.DelUsers(uuids)
|
||||||
|
|||||||
37
core/xray/app/dispatcher/countreader.go
Normal file
37
core/xray/app/dispatcher/countreader.go
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
package dispatcher
|
||||||
|
|
||||||
|
import (
|
||||||
|
"sync/atomic"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/xtls/xray-core/common/buf"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ buf.TimeoutReader = (*CounterReader)(nil)
|
||||||
|
|
||||||
|
type CounterReader struct {
|
||||||
|
Reader buf.TimeoutReader
|
||||||
|
Counter *atomic.Int64
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *CounterReader) ReadMultiBufferTimeout(time.Duration) (buf.MultiBuffer, error) {
|
||||||
|
mb, err := c.Reader.ReadMultiBufferTimeout(time.Second)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if mb.Len() > 0 {
|
||||||
|
c.Counter.Add(int64(mb.Len()))
|
||||||
|
}
|
||||||
|
return mb, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *CounterReader) ReadMultiBuffer() (buf.MultiBuffer, error) {
|
||||||
|
mb, err := c.Reader.ReadMultiBuffer()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if mb.Len() > 0 {
|
||||||
|
c.Counter.Add(int64(mb.Len()))
|
||||||
|
}
|
||||||
|
return mb, nil
|
||||||
|
}
|
||||||
@@ -10,9 +10,11 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/InazumaV/V2bX/common/counter"
|
||||||
"github.com/InazumaV/V2bX/common/rate"
|
"github.com/InazumaV/V2bX/common/rate"
|
||||||
"github.com/InazumaV/V2bX/limiter"
|
"github.com/InazumaV/V2bX/limiter"
|
||||||
|
|
||||||
|
"github.com/xtls/xray-core/app/dispatcher"
|
||||||
"github.com/xtls/xray-core/common"
|
"github.com/xtls/xray-core/common"
|
||||||
"github.com/xtls/xray-core/common/buf"
|
"github.com/xtls/xray-core/common/buf"
|
||||||
"github.com/xtls/xray-core/common/errors"
|
"github.com/xtls/xray-core/common/errors"
|
||||||
@@ -35,27 +37,25 @@ var errSniffingTimeout = errors.New("timeout on sniffing")
|
|||||||
|
|
||||||
type cachedReader struct {
|
type cachedReader struct {
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
reader *pipe.Reader
|
reader buf.TimeoutReader
|
||||||
cache buf.MultiBuffer
|
cache buf.MultiBuffer
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *cachedReader) Cache(b *buf.Buffer) {
|
func (r *cachedReader) Cache(b *buf.Buffer, deadline time.Duration) error {
|
||||||
mb, _ := r.reader.ReadMultiBufferTimeout(time.Millisecond * 100)
|
mb, err := r.reader.ReadMultiBufferTimeout(deadline)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
r.Lock()
|
r.Lock()
|
||||||
if !mb.IsEmpty() {
|
if !mb.IsEmpty() {
|
||||||
r.cache, _ = buf.MergeMulti(r.cache, mb)
|
r.cache, _ = buf.MergeMulti(r.cache, mb)
|
||||||
}
|
}
|
||||||
cacheLen := r.cache.Len()
|
b.Clear()
|
||||||
if cacheLen <= b.Cap() {
|
rawBytes := b.Extend(min(r.cache.Len(), b.Cap()))
|
||||||
b.Clear()
|
|
||||||
} else {
|
|
||||||
b.Release()
|
|
||||||
*b = *buf.NewWithSize(cacheLen)
|
|
||||||
}
|
|
||||||
rawBytes := b.Extend(cacheLen)
|
|
||||||
n := r.cache.Copy(rawBytes)
|
n := r.cache.Copy(rawBytes)
|
||||||
b.Resize(0, int32(n))
|
b.Resize(0, int32(n))
|
||||||
r.Unlock()
|
r.Unlock()
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *cachedReader) readInternal() buf.MultiBuffer {
|
func (r *cachedReader) readInternal() buf.MultiBuffer {
|
||||||
@@ -95,17 +95,20 @@ func (r *cachedReader) Interrupt() {
|
|||||||
r.cache = buf.ReleaseMulti(r.cache)
|
r.cache = buf.ReleaseMulti(r.cache)
|
||||||
}
|
}
|
||||||
r.Unlock()
|
r.Unlock()
|
||||||
r.reader.Interrupt()
|
if p, ok := r.reader.(*pipe.Reader); ok {
|
||||||
|
p.Interrupt()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultDispatcher is a default implementation of Dispatcher.
|
// DefaultDispatcher is a default implementation of Dispatcher.
|
||||||
type DefaultDispatcher struct {
|
type DefaultDispatcher struct {
|
||||||
ohm outbound.Manager
|
ohm outbound.Manager
|
||||||
router routing.Router
|
router routing.Router
|
||||||
policy policy.Manager
|
policy policy.Manager
|
||||||
stats stats.Manager
|
stats stats.Manager
|
||||||
dns dns.Client
|
fdns dns.FakeDNSEngine
|
||||||
fdns dns.FakeDNSEngine
|
Counter sync.Map
|
||||||
|
LinkManagers sync.Map // map[string]*LinkManager
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -115,7 +118,7 @@ func init() {
|
|||||||
core.OptionalFeatures(ctx, func(fdns dns.FakeDNSEngine) {
|
core.OptionalFeatures(ctx, func(fdns dns.FakeDNSEngine) {
|
||||||
d.fdns = fdns
|
d.fdns = fdns
|
||||||
})
|
})
|
||||||
return d.Init(config.(*Config), om, router, pm, sm, dc)
|
return d.Init(config.(*Config), om, router, pm, sm)
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -124,12 +127,11 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Init initializes DefaultDispatcher.
|
// Init initializes DefaultDispatcher.
|
||||||
func (d *DefaultDispatcher) Init(config *Config, om outbound.Manager, router routing.Router, pm policy.Manager, sm stats.Manager, dns dns.Client) error {
|
func (d *DefaultDispatcher) Init(config *Config, om outbound.Manager, router routing.Router, pm policy.Manager, sm stats.Manager) error {
|
||||||
d.ohm = om
|
d.ohm = om
|
||||||
d.router = router
|
d.router = router
|
||||||
d.policy = pm
|
d.policy = pm
|
||||||
d.stats = sm
|
d.stats = sm
|
||||||
d.dns = dns
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,7 +167,6 @@ func (d *DefaultDispatcher) getLink(ctx context.Context, network net.Network) (*
|
|||||||
var user *protocol.MemoryUser
|
var user *protocol.MemoryUser
|
||||||
if sessionInbound != nil {
|
if sessionInbound != nil {
|
||||||
user = sessionInbound.User
|
user = sessionInbound.User
|
||||||
sessionInbound.CanSpliceCopy = 3
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var limit *limiter.Limiter
|
var limit *limiter.Limiter
|
||||||
@@ -193,28 +194,44 @@ func (d *DefaultDispatcher) getLink(ctx context.Context, network net.Network) (*
|
|||||||
common.Interrupt(inboundLink.Reader)
|
common.Interrupt(inboundLink.Reader)
|
||||||
return nil, nil, nil, errors.New("Limited ", user.Email, " by conn or ip")
|
return nil, nil, nil, errors.New("Limited ", user.Email, " by conn or ip")
|
||||||
}
|
}
|
||||||
|
var lm *LinkManager
|
||||||
|
if lmloaded, ok := d.LinkManagers.Load(user.Email); !ok {
|
||||||
|
lm = &LinkManager{
|
||||||
|
links: make(map[*ManagedWriter]buf.Reader),
|
||||||
|
}
|
||||||
|
d.LinkManagers.Store(user.Email, lm)
|
||||||
|
} else {
|
||||||
|
lm = lmloaded.(*LinkManager)
|
||||||
|
}
|
||||||
|
managedWriter := &ManagedWriter{
|
||||||
|
writer: uplinkWriter,
|
||||||
|
manager: lm,
|
||||||
|
}
|
||||||
|
lm.AddLink(managedWriter, outboundLink.Reader)
|
||||||
|
inboundLink.Writer = managedWriter
|
||||||
if w != nil {
|
if w != nil {
|
||||||
|
sessionInbound.CanSpliceCopy = 3
|
||||||
inboundLink.Writer = rate.NewRateLimitWriter(inboundLink.Writer, w)
|
inboundLink.Writer = rate.NewRateLimitWriter(inboundLink.Writer, w)
|
||||||
outboundLink.Writer = rate.NewRateLimitWriter(outboundLink.Writer, w)
|
outboundLink.Writer = rate.NewRateLimitWriter(outboundLink.Writer, w)
|
||||||
}
|
}
|
||||||
p := d.policy.ForLevel(user.Level)
|
var t *counter.TrafficCounter
|
||||||
if p.Stats.UserUplink {
|
if c, ok := d.Counter.Load(sessionInbound.Tag); !ok {
|
||||||
name := "user>>>" + user.Email + ">>>traffic>>>uplink"
|
t = counter.NewTrafficCounter()
|
||||||
if c, _ := stats.GetOrRegisterCounter(d.stats, name); c != nil {
|
d.Counter.Store(sessionInbound.Tag, t)
|
||||||
inboundLink.Writer = &SizeStatWriter{
|
} else {
|
||||||
Counter: c,
|
t = c.(*counter.TrafficCounter)
|
||||||
Writer: inboundLink.Writer,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if p.Stats.UserDownlink {
|
|
||||||
name := "user>>>" + user.Email + ">>>traffic>>>downlink"
|
ts := t.GetCounter(user.Email)
|
||||||
if c, _ := stats.GetOrRegisterCounter(d.stats, name); c != nil {
|
upcounter := &counter.XrayTrafficCounter{V: &ts.UpCounter}
|
||||||
outboundLink.Writer = &SizeStatWriter{
|
downcounter := &counter.XrayTrafficCounter{V: &ts.DownCounter}
|
||||||
Counter: c,
|
inboundLink.Writer = &dispatcher.SizeStatWriter{
|
||||||
Writer: outboundLink.Writer,
|
Counter: upcounter,
|
||||||
}
|
Writer: inboundLink.Writer,
|
||||||
}
|
}
|
||||||
|
outboundLink.Writer = &dispatcher.SizeStatWriter{
|
||||||
|
Counter: downcounter,
|
||||||
|
Writer: outboundLink.Writer,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -343,12 +360,79 @@ func (d *DefaultDispatcher) DispatchLink(ctx context.Context, destination net.De
|
|||||||
content = new(session.Content)
|
content = new(session.Content)
|
||||||
ctx = session.ContextWithContent(ctx, content)
|
ctx = session.ContextWithContent(ctx, content)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sessionInbound := session.InboundFromContext(ctx)
|
||||||
|
var user *protocol.MemoryUser
|
||||||
|
if sessionInbound != nil {
|
||||||
|
user = sessionInbound.User
|
||||||
|
}
|
||||||
|
|
||||||
|
var limit *limiter.Limiter
|
||||||
|
var err error
|
||||||
|
if user != nil && len(user.Email) > 0 {
|
||||||
|
limit, err = limiter.GetLimiter(sessionInbound.Tag)
|
||||||
|
if err != nil {
|
||||||
|
errors.LogInfo(ctx, "get limiter ", sessionInbound.Tag, " error: ", err)
|
||||||
|
common.Close(outbound.Writer)
|
||||||
|
common.Interrupt(outbound.Reader)
|
||||||
|
return errors.New("get limiter ", sessionInbound.Tag, " error: ", err)
|
||||||
|
}
|
||||||
|
// Speed Limit and Device Limit
|
||||||
|
w, reject := limit.CheckLimit(user.Email,
|
||||||
|
sessionInbound.Source.Address.IP().String(),
|
||||||
|
destination.Network == net.Network_TCP,
|
||||||
|
sessionInbound.Source.Network == net.Network_TCP)
|
||||||
|
if reject {
|
||||||
|
errors.LogInfo(ctx, "Limited ", user.Email, " by conn or ip")
|
||||||
|
common.Close(outbound.Writer)
|
||||||
|
common.Interrupt(outbound.Reader)
|
||||||
|
return errors.New("Limited ", user.Email, " by conn or ip")
|
||||||
|
}
|
||||||
|
var lm *LinkManager
|
||||||
|
if lmloaded, ok := d.LinkManagers.Load(user.Email); !ok {
|
||||||
|
lm = &LinkManager{
|
||||||
|
links: make(map[*ManagedWriter]buf.Reader),
|
||||||
|
}
|
||||||
|
d.LinkManagers.Store(user.Email, lm)
|
||||||
|
} else {
|
||||||
|
lm = lmloaded.(*LinkManager)
|
||||||
|
}
|
||||||
|
managedWriter := &ManagedWriter{
|
||||||
|
writer: outbound.Writer,
|
||||||
|
manager: lm,
|
||||||
|
}
|
||||||
|
outbound.Writer = managedWriter
|
||||||
|
if w != nil {
|
||||||
|
sessionInbound.CanSpliceCopy = 3
|
||||||
|
outbound.Writer = rate.NewRateLimitWriter(outbound.Writer, w)
|
||||||
|
}
|
||||||
|
var t *counter.TrafficCounter
|
||||||
|
if c, ok := d.Counter.Load(sessionInbound.Tag); !ok {
|
||||||
|
t = counter.NewTrafficCounter()
|
||||||
|
d.Counter.Store(sessionInbound.Tag, t)
|
||||||
|
} else {
|
||||||
|
t = c.(*counter.TrafficCounter)
|
||||||
|
}
|
||||||
|
|
||||||
|
ts := t.GetCounter(user.Email)
|
||||||
|
downcounter := &counter.XrayTrafficCounter{V: &ts.DownCounter}
|
||||||
|
outbound.Reader = &CounterReader{
|
||||||
|
Reader: &buf.TimeoutWrapperReader{Reader: outbound.Reader},
|
||||||
|
Counter: &ts.UpCounter,
|
||||||
|
}
|
||||||
|
lm.AddLink(managedWriter, outbound.Reader)
|
||||||
|
outbound.Writer = &dispatcher.SizeStatWriter{
|
||||||
|
Counter: downcounter,
|
||||||
|
Writer: outbound.Writer,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sniffingRequest := content.SniffingRequest
|
sniffingRequest := content.SniffingRequest
|
||||||
if !sniffingRequest.Enabled {
|
if !sniffingRequest.Enabled {
|
||||||
d.routedDispatch(ctx, outbound, destination, nil, "")
|
d.routedDispatch(ctx, outbound, destination, limit, "")
|
||||||
} else {
|
} else {
|
||||||
cReader := &cachedReader{
|
cReader := &cachedReader{
|
||||||
reader: outbound.Reader.(*pipe.Reader),
|
reader: outbound.Reader.(buf.TimeoutReader),
|
||||||
}
|
}
|
||||||
outbound.Reader = cReader
|
outbound.Reader = cReader
|
||||||
result, err := sniffer(ctx, cReader, sniffingRequest.MetadataOnly, destination.Network)
|
result, err := sniffer(ctx, cReader, sniffingRequest.MetadataOnly, destination.Network)
|
||||||
@@ -364,7 +448,7 @@ func (d *DefaultDispatcher) DispatchLink(ctx context.Context, destination net.De
|
|||||||
protocol = resComp.ProtocolForDomainResult()
|
protocol = resComp.ProtocolForDomainResult()
|
||||||
}
|
}
|
||||||
isFakeIP := false
|
isFakeIP := false
|
||||||
if fkr0, ok := d.fdns.(dns.FakeDNSEngineRev0); ok && ob.Target.Address.Family().IsIP() && fkr0.IsIPInIPPool(ob.Target.Address) {
|
if fkr0, ok := d.fdns.(dns.FakeDNSEngineRev0); ok && fkr0.IsIPInIPPool(ob.Target.Address) {
|
||||||
isFakeIP = true
|
isFakeIP = true
|
||||||
}
|
}
|
||||||
if sniffingRequest.RouteOnly && protocol != "fakedns" && protocol != "fakedns+others" && !isFakeIP {
|
if sniffingRequest.RouteOnly && protocol != "fakedns" && protocol != "fakedns+others" && !isFakeIP {
|
||||||
@@ -372,16 +456,15 @@ func (d *DefaultDispatcher) DispatchLink(ctx context.Context, destination net.De
|
|||||||
} else {
|
} else {
|
||||||
ob.Target = destination
|
ob.Target = destination
|
||||||
}
|
}
|
||||||
destination.Address.Family()
|
|
||||||
}
|
}
|
||||||
d.routedDispatch(ctx, outbound, destination, nil, content.Protocol)
|
d.routedDispatch(ctx, outbound, destination, limit, content.Protocol)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func sniffer(ctx context.Context, cReader *cachedReader, metadataOnly bool, network net.Network) (SniffResult, error) {
|
func sniffer(ctx context.Context, cReader *cachedReader, metadataOnly bool, network net.Network) (SniffResult, error) {
|
||||||
payload := buf.New()
|
payload := buf.NewWithSize(32767)
|
||||||
defer payload.Release()
|
defer payload.Release()
|
||||||
|
|
||||||
sniffer := NewSniffer(ctx)
|
sniffer := NewSniffer(ctx)
|
||||||
@@ -393,26 +476,36 @@ func sniffer(ctx context.Context, cReader *cachedReader, metadataOnly bool, netw
|
|||||||
}
|
}
|
||||||
|
|
||||||
contentResult, contentErr := func() (SniffResult, error) {
|
contentResult, contentErr := func() (SniffResult, error) {
|
||||||
|
cacheDeadline := 200 * time.Millisecond
|
||||||
totalAttempt := 0
|
totalAttempt := 0
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return nil, ctx.Err()
|
return nil, ctx.Err()
|
||||||
default:
|
default:
|
||||||
totalAttempt++
|
cachingStartingTimeStamp := time.Now()
|
||||||
if totalAttempt > 2 {
|
err := cReader.Cache(payload, cacheDeadline)
|
||||||
return nil, errSniffingTimeout
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
|
cachingTimeElapsed := time.Since(cachingStartingTimeStamp)
|
||||||
|
cacheDeadline -= cachingTimeElapsed
|
||||||
|
|
||||||
cReader.Cache(payload)
|
|
||||||
if !payload.IsEmpty() {
|
if !payload.IsEmpty() {
|
||||||
result, err := sniffer.Sniff(ctx, payload.Bytes(), network)
|
result, err := sniffer.Sniff(ctx, payload.Bytes(), network)
|
||||||
if err != common.ErrNoClue {
|
switch err {
|
||||||
|
case common.ErrNoClue: // No Clue: protocol not matches, and sniffer cannot determine whether there will be a match or not
|
||||||
|
totalAttempt++
|
||||||
|
case protocol.ErrProtoNeedMoreData: // Protocol Need More Data: protocol matches, but need more data to complete sniffing
|
||||||
|
// in this case, do not add totalAttempt(allow to read until timeout)
|
||||||
|
default:
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
totalAttempt++
|
||||||
}
|
}
|
||||||
if payload.IsFull() {
|
if totalAttempt >= 2 || cacheDeadline <= 0 {
|
||||||
return nil, errUnknownContent
|
return nil, errSniffingTimeout
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -429,29 +522,10 @@ func sniffer(ctx context.Context, cReader *cachedReader, metadataOnly bool, netw
|
|||||||
func (d *DefaultDispatcher) routedDispatch(ctx context.Context, link *transport.Link, destination net.Destination, l *limiter.Limiter, protocol string) {
|
func (d *DefaultDispatcher) routedDispatch(ctx context.Context, link *transport.Link, destination net.Destination, l *limiter.Limiter, protocol string) {
|
||||||
outbounds := session.OutboundsFromContext(ctx)
|
outbounds := session.OutboundsFromContext(ctx)
|
||||||
ob := outbounds[len(outbounds)-1]
|
ob := outbounds[len(outbounds)-1]
|
||||||
if hosts, ok := d.dns.(dns.HostsLookup); ok && destination.Address.Family().IsDomain() {
|
|
||||||
proxied := hosts.LookupHosts(ob.Target.String())
|
|
||||||
if proxied != nil {
|
|
||||||
ro := ob.RouteTarget == destination
|
|
||||||
destination.Address = *proxied
|
|
||||||
if ro {
|
|
||||||
ob.RouteTarget = destination
|
|
||||||
} else {
|
|
||||||
ob.Target = destination
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sessionInbound := session.InboundFromContext(ctx)
|
sessionInbound := session.InboundFromContext(ctx)
|
||||||
if sessionInbound.User != nil {
|
if sessionInbound.User != nil {
|
||||||
if l != nil {
|
if l == nil {
|
||||||
// del connect count
|
|
||||||
if destination.Network == net.Network_TCP {
|
|
||||||
defer func() {
|
|
||||||
l.ConnLimiter.DelConnCount(sessionInbound.User.Email, sessionInbound.Source.Address.IP().String())
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
var err error
|
var err error
|
||||||
l, err = limiter.GetLimiter(sessionInbound.Tag)
|
l, err = limiter.GetLimiter(sessionInbound.Tag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -510,20 +584,23 @@ func (d *DefaultDispatcher) routedDispatch(ctx context.Context, link *transport.
|
|||||||
outTag := route.GetOutboundTag()
|
outTag := route.GetOutboundTag()
|
||||||
if h := d.ohm.GetHandler(outTag); h != nil {
|
if h := d.ohm.GetHandler(outTag); h != nil {
|
||||||
isPickRoute = 2
|
isPickRoute = 2
|
||||||
errors.LogInfo(ctx, "taking detour [", outTag, "] for [", destination, "]")
|
if route.GetRuleTag() == "" {
|
||||||
|
errors.LogInfo(ctx, "taking detour [", outTag, "] for [", destination, "]")
|
||||||
|
} else {
|
||||||
|
errors.LogInfo(ctx, "Hit route rule: [", route.GetRuleTag(), "] so taking detour [", outTag, "] for [", destination, "]")
|
||||||
|
}
|
||||||
handler = h
|
handler = h
|
||||||
} else {
|
} else {
|
||||||
errors.LogWarning(ctx, "non existing outTag: ", outTag)
|
errors.LogWarning(ctx, "non existing outTag: ", outTag)
|
||||||
|
common.Close(link.Writer)
|
||||||
|
common.Interrupt(link.Reader)
|
||||||
|
return // DO NOT CHANGE: the traffic shouldn't be processed by default outbound if the specified outbound tag doesn't exist (yet), e.g., VLESS Reverse Proxy
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
errors.LogInfo(ctx, "default route for ", destination)
|
errors.LogInfo(ctx, "default route for ", destination)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if handler == nil {
|
|
||||||
handler = d.ohm.GetHandler(inTag)
|
|
||||||
}
|
|
||||||
|
|
||||||
if handler == nil {
|
if handler == nil {
|
||||||
handler = d.ohm.GetDefaultHandler()
|
handler = d.ohm.GetDefaultHandler()
|
||||||
}
|
}
|
||||||
@@ -535,6 +612,7 @@ func (d *DefaultDispatcher) routedDispatch(ctx context.Context, link *transport.
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ob.Tag = handler.Tag()
|
||||||
if accessMessage := log.AccessMessageFromContext(ctx); accessMessage != nil {
|
if accessMessage := log.AccessMessageFromContext(ctx); accessMessage != nil {
|
||||||
if tag := handler.Tag(); tag != "" {
|
if tag := handler.Tag(); tag != "" {
|
||||||
if inTag == "" {
|
if inTag == "" {
|
||||||
|
|||||||
46
core/xray/app/dispatcher/linkmanager.go
Normal file
46
core/xray/app/dispatcher/linkmanager.go
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
package dispatcher
|
||||||
|
|
||||||
|
import (
|
||||||
|
sync "sync"
|
||||||
|
|
||||||
|
"github.com/xtls/xray-core/common"
|
||||||
|
"github.com/xtls/xray-core/common/buf"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ManagedWriter struct {
|
||||||
|
writer buf.Writer
|
||||||
|
manager *LinkManager
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *ManagedWriter) WriteMultiBuffer(mb buf.MultiBuffer) error {
|
||||||
|
return w.writer.WriteMultiBuffer(mb)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *ManagedWriter) Close() error {
|
||||||
|
w.manager.RemoveWriter(w)
|
||||||
|
return common.Close(w.writer)
|
||||||
|
}
|
||||||
|
|
||||||
|
type LinkManager struct {
|
||||||
|
links map[*ManagedWriter]buf.Reader
|
||||||
|
mu sync.Mutex
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *LinkManager) AddLink(writer *ManagedWriter, reader buf.Reader) {
|
||||||
|
m.mu.Lock()
|
||||||
|
defer m.mu.Unlock()
|
||||||
|
m.links[writer] = reader
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *LinkManager) RemoveWriter(writer *ManagedWriter) {
|
||||||
|
m.mu.Lock()
|
||||||
|
defer m.mu.Unlock()
|
||||||
|
delete(m.links, writer)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *LinkManager) CloseAll() {
|
||||||
|
for w, r := range m.links {
|
||||||
|
common.Close(w)
|
||||||
|
common.Interrupt(r)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
package dispatcher
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/xtls/xray-core/common"
|
|
||||||
"github.com/xtls/xray-core/common/buf"
|
|
||||||
"github.com/xtls/xray-core/features/stats"
|
|
||||||
)
|
|
||||||
|
|
||||||
type SizeStatWriter struct {
|
|
||||||
Counter stats.Counter
|
|
||||||
Writer buf.Writer
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *SizeStatWriter) WriteMultiBuffer(mb buf.MultiBuffer) error {
|
|
||||||
w.Counter.Add(int64(mb.Len()))
|
|
||||||
return w.Writer.WriteMultiBuffer(mb)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *SizeStatWriter) Close() error {
|
|
||||||
return common.Close(w.Writer)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *SizeStatWriter) Interrupt() {
|
|
||||||
common.Interrupt(w.Writer)
|
|
||||||
}
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
package dispatcher_test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
. "github.com/xtls/xray-core/app/dispatcher"
|
|
||||||
"github.com/xtls/xray-core/common"
|
|
||||||
"github.com/xtls/xray-core/common/buf"
|
|
||||||
)
|
|
||||||
|
|
||||||
type TestCounter int64
|
|
||||||
|
|
||||||
func (c *TestCounter) Value() int64 {
|
|
||||||
return int64(*c)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *TestCounter) Add(v int64) int64 {
|
|
||||||
x := int64(*c) + v
|
|
||||||
*c = TestCounter(x)
|
|
||||||
return x
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *TestCounter) Set(v int64) int64 {
|
|
||||||
*c = TestCounter(v)
|
|
||||||
return v
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestStatsWriter(t *testing.T) {
|
|
||||||
var c TestCounter
|
|
||||||
writer := &SizeStatWriter{
|
|
||||||
Counter: &c,
|
|
||||||
Writer: buf.Discard,
|
|
||||||
}
|
|
||||||
|
|
||||||
mb := buf.MergeBytes(nil, []byte("abcd"))
|
|
||||||
common.Must(writer.WriteMultiBuffer(mb))
|
|
||||||
|
|
||||||
mb = buf.MergeBytes(nil, []byte("efg"))
|
|
||||||
common.Must(writer.WriteMultiBuffer(mb))
|
|
||||||
|
|
||||||
if c.Value() != 7 {
|
|
||||||
t.Fatal("unexpected counter value. want 7, but got ", c.Value())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -7,8 +7,9 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/InazumaV/V2bX/api/panel"
|
"github.com/InazumaV/V2bX/api/panel"
|
||||||
"github.com/goccy/go-json"
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
coreConf "github.com/xtls/xray-core/infra/conf"
|
coreConf "github.com/xtls/xray-core/infra/conf"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -6,11 +6,13 @@ import (
|
|||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/InazumaV/V2bX/api/panel"
|
"github.com/InazumaV/V2bX/api/panel"
|
||||||
"github.com/InazumaV/V2bX/conf"
|
"github.com/InazumaV/V2bX/conf"
|
||||||
"github.com/goccy/go-json"
|
|
||||||
"github.com/xtls/xray-core/common/net"
|
"github.com/xtls/xray-core/common/net"
|
||||||
"github.com/xtls/xray-core/core"
|
"github.com/xtls/xray-core/core"
|
||||||
coreConf "github.com/xtls/xray-core/infra/conf"
|
coreConf "github.com/xtls/xray-core/infra/conf"
|
||||||
@@ -133,12 +135,14 @@ func buildInbound(option *conf.Options, nodeInfo *panel.NodeInfo, tag string) (*
|
|||||||
in.StreamSetting.REALITYSettings = &coreConf.REALITYConfig{
|
in.StreamSetting.REALITYSettings = &coreConf.REALITYConfig{
|
||||||
Dest: d,
|
Dest: d,
|
||||||
Xver: xver,
|
Xver: xver,
|
||||||
|
Show: false,
|
||||||
ServerNames: []string{v.TlsSettings.ServerName},
|
ServerNames: []string{v.TlsSettings.ServerName},
|
||||||
PrivateKey: v.TlsSettings.PrivateKey,
|
PrivateKey: v.TlsSettings.PrivateKey,
|
||||||
MinClientVer: v.RealityConfig.MinClientVer,
|
MinClientVer: v.RealityConfig.MinClientVer,
|
||||||
MaxClientVer: v.RealityConfig.MaxClientVer,
|
MaxClientVer: v.RealityConfig.MaxClientVer,
|
||||||
MaxTimeDiff: uint64(mtd.Microseconds()),
|
MaxTimeDiff: uint64(mtd.Microseconds()),
|
||||||
ShortIds: []string{v.TlsSettings.ShortId},
|
ShortIds: []string{v.TlsSettings.ShortId},
|
||||||
|
Mldsa65Seed: v.TlsSettings.Mldsa65Seed,
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
@@ -168,8 +172,27 @@ func buildV2ray(config *conf.Options, nodeInfo *panel.NodeInfo, inbound *coreCon
|
|||||||
inbound.Settings = (*json.RawMessage)(&s)
|
inbound.Settings = (*json.RawMessage)(&s)
|
||||||
} else {
|
} else {
|
||||||
var err error
|
var err error
|
||||||
|
decryption := "none"
|
||||||
|
if nodeInfo.VAllss.Encryption != "" {
|
||||||
|
switch nodeInfo.VAllss.Encryption {
|
||||||
|
case "mlkem768x25519plus":
|
||||||
|
encSettings := nodeInfo.VAllss.EncryptionSettings
|
||||||
|
parts := []string{
|
||||||
|
"mlkem768x25519plus",
|
||||||
|
encSettings.Mode,
|
||||||
|
encSettings.Ticket,
|
||||||
|
}
|
||||||
|
if encSettings.ServerPadding != "" {
|
||||||
|
parts = append(parts, encSettings.ServerPadding)
|
||||||
|
}
|
||||||
|
parts = append(parts, encSettings.PrivateKey)
|
||||||
|
decryption = strings.Join(parts, ".")
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("vless decryption method %s is not support", nodeInfo.VAllss.Encryption)
|
||||||
|
}
|
||||||
|
}
|
||||||
s, err := json.Marshal(&coreConf.VLessInboundConfig{
|
s, err := json.Marshal(&coreConf.VLessInboundConfig{
|
||||||
Decryption: "none",
|
Decryption: decryption,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("marshal vless config error: %s", err)
|
return fmt.Errorf("marshal vless config error: %s", err)
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ type DNSConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Xray) AddNode(tag string, info *panel.NodeInfo, config *conf.Options) error {
|
func (c *Xray) AddNode(tag string, info *panel.NodeInfo, config *conf.Options) error {
|
||||||
|
c.nodeReportMinTrafficBytes[tag] = config.ReportMinTraffic * 1024
|
||||||
err := updateDNSConfig(info)
|
err := updateDNSConfig(info)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("build dns error: %s", err)
|
return fmt.Errorf("build dns error: %s", err)
|
||||||
|
|||||||
@@ -3,8 +3,9 @@ package xray
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
conf2 "github.com/InazumaV/V2bX/conf"
|
conf2 "github.com/InazumaV/V2bX/conf"
|
||||||
"github.com/goccy/go-json"
|
|
||||||
"github.com/xtls/xray-core/core"
|
"github.com/xtls/xray-core/core"
|
||||||
"github.com/xtls/xray-core/infra/conf"
|
"github.com/xtls/xray-core/infra/conf"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -5,8 +5,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/InazumaV/V2bX/api/panel"
|
"github.com/InazumaV/V2bX/api/panel"
|
||||||
|
"github.com/InazumaV/V2bX/common/counter"
|
||||||
"github.com/InazumaV/V2bX/common/format"
|
"github.com/InazumaV/V2bX/common/format"
|
||||||
vCore "github.com/InazumaV/V2bX/core"
|
vCore "github.com/InazumaV/V2bX/core"
|
||||||
|
"github.com/InazumaV/V2bX/core/xray/app/dispatcher"
|
||||||
"github.com/xtls/xray-core/common/protocol"
|
"github.com/xtls/xray-core/common/protocol"
|
||||||
"github.com/xtls/xray-core/proxy"
|
"github.com/xtls/xray-core/proxy"
|
||||||
)
|
)
|
||||||
@@ -32,46 +34,68 @@ func (c *Xray) DelUsers(users []panel.UserInfo, tag string, _ *panel.NodeInfo) e
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("get user manager error: %s", err)
|
return fmt.Errorf("get user manager error: %s", err)
|
||||||
}
|
}
|
||||||
var up, down, user string
|
var user string
|
||||||
|
c.users.mapLock.Lock()
|
||||||
|
defer c.users.mapLock.Unlock()
|
||||||
for i := range users {
|
for i := range users {
|
||||||
user = format.UserTag(tag, users[i].Uuid)
|
user = format.UserTag(tag, users[i].Uuid)
|
||||||
err = userManager.RemoveUser(context.Background(), user)
|
err = userManager.RemoveUser(context.Background(), user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
up = "user>>>" + user + ">>>traffic>>>uplink"
|
delete(c.users.uidMap, user)
|
||||||
down = "user>>>" + user + ">>>traffic>>>downlink"
|
if v, ok := c.dispatcher.Counter.Load(tag); ok {
|
||||||
c.shm.UnregisterCounter(up)
|
tc := v.(*counter.TrafficCounter)
|
||||||
c.shm.UnregisterCounter(down)
|
tc.Delete(user)
|
||||||
|
}
|
||||||
|
if v, ok := c.dispatcher.LinkManagers.Load(user); ok {
|
||||||
|
lm := v.(*dispatcher.LinkManager)
|
||||||
|
lm.CloseAll()
|
||||||
|
c.dispatcher.LinkManagers.Delete(user)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Xray) GetUserTraffic(tag, uuid string, reset bool) (up int64, down int64) {
|
func (x *Xray) GetUserTrafficSlice(tag string, reset bool) ([]panel.UserTraffic, error) {
|
||||||
upName := "user>>>" + format.UserTag(tag, uuid) + ">>>traffic>>>uplink"
|
trafficSlice := make([]panel.UserTraffic, 0)
|
||||||
downName := "user>>>" + format.UserTag(tag, uuid) + ">>>traffic>>>downlink"
|
x.users.mapLock.RLock()
|
||||||
upCounter := c.shm.GetCounter(upName)
|
defer x.users.mapLock.RUnlock()
|
||||||
downCounter := c.shm.GetCounter(downName)
|
if v, ok := x.dispatcher.Counter.Load(tag); ok {
|
||||||
if reset {
|
c := v.(*counter.TrafficCounter)
|
||||||
if upCounter != nil {
|
c.Counters.Range(func(key, value interface{}) bool {
|
||||||
up = upCounter.Set(0)
|
email := key.(string)
|
||||||
}
|
traffic := value.(*counter.TrafficStorage)
|
||||||
if downCounter != nil {
|
up := traffic.UpCounter.Load()
|
||||||
down = downCounter.Set(0)
|
down := traffic.DownCounter.Load()
|
||||||
}
|
if up+down > x.nodeReportMinTrafficBytes[tag] {
|
||||||
} else {
|
if reset {
|
||||||
if upCounter != nil {
|
traffic.UpCounter.Store(0)
|
||||||
up = upCounter.Value()
|
traffic.DownCounter.Store(0)
|
||||||
}
|
}
|
||||||
if downCounter != nil {
|
trafficSlice = append(trafficSlice, panel.UserTraffic{
|
||||||
down = downCounter.Value()
|
UID: x.users.uidMap[email],
|
||||||
|
Upload: up,
|
||||||
|
Download: down,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
if len(trafficSlice) == 0 {
|
||||||
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
return trafficSlice, nil
|
||||||
}
|
}
|
||||||
return up, down
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Xray) AddUsers(p *vCore.AddUsersParams) (added int, err error) {
|
func (c *Xray) AddUsers(p *vCore.AddUsersParams) (added int, err error) {
|
||||||
users := make([]*protocol.User, 0, len(p.Users))
|
c.users.mapLock.Lock()
|
||||||
|
defer c.users.mapLock.Unlock()
|
||||||
|
for i := range p.Users {
|
||||||
|
c.users.uidMap[format.UserTag(p.Tag, p.Users[i].Uuid)] = p.Users[i].Id
|
||||||
|
}
|
||||||
|
var users []*protocol.User
|
||||||
switch p.NodeInfo.Type {
|
switch p.NodeInfo.Type {
|
||||||
case "vmess":
|
case "vmess":
|
||||||
users = buildVmessUsers(p.Tag, p.Users)
|
users = buildVmessUsers(p.Tag, p.Users)
|
||||||
|
|||||||
@@ -5,11 +5,12 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"encoding/json/v2"
|
||||||
|
|
||||||
"github.com/InazumaV/V2bX/conf"
|
"github.com/InazumaV/V2bX/conf"
|
||||||
vCore "github.com/InazumaV/V2bX/core"
|
vCore "github.com/InazumaV/V2bX/core"
|
||||||
"github.com/InazumaV/V2bX/core/xray/app/dispatcher"
|
"github.com/InazumaV/V2bX/core/xray/app/dispatcher"
|
||||||
_ "github.com/InazumaV/V2bX/core/xray/distro/all"
|
_ "github.com/InazumaV/V2bX/core/xray/distro/all"
|
||||||
"github.com/goccy/go-json"
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/xtls/xray-core/app/proxyman"
|
"github.com/xtls/xray-core/app/proxyman"
|
||||||
"github.com/xtls/xray-core/app/stats"
|
"github.com/xtls/xray-core/app/stats"
|
||||||
@@ -30,16 +31,29 @@ func init() {
|
|||||||
|
|
||||||
// Xray Structure
|
// Xray Structure
|
||||||
type Xray struct {
|
type Xray struct {
|
||||||
access sync.Mutex
|
access sync.Mutex
|
||||||
Server *core.Instance
|
Server *core.Instance
|
||||||
ihm inbound.Manager
|
ihm inbound.Manager
|
||||||
ohm outbound.Manager
|
ohm outbound.Manager
|
||||||
shm statsFeature.Manager
|
shm statsFeature.Manager
|
||||||
dispatcher *dispatcher.DefaultDispatcher
|
dispatcher *dispatcher.DefaultDispatcher
|
||||||
|
users *UserMap
|
||||||
|
nodeReportMinTrafficBytes map[string]int64
|
||||||
|
}
|
||||||
|
|
||||||
|
type UserMap struct {
|
||||||
|
uidMap map[string]int
|
||||||
|
mapLock sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(c *conf.CoreConfig) (vCore.Core, error) {
|
func New(c *conf.CoreConfig) (vCore.Core, error) {
|
||||||
return &Xray{Server: getCore(c.XrayConfig)}, nil
|
return &Xray{
|
||||||
|
Server: getCore(c.XrayConfig),
|
||||||
|
users: &UserMap{
|
||||||
|
uidMap: make(map[string]int),
|
||||||
|
},
|
||||||
|
nodeReportMinTrafficBytes: make(map[string]int64),
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseConnectionConfig(c *conf.XrayConnectionConfig) (policy *coreConf.Policy) {
|
func parseConnectionConfig(c *conf.XrayConnectionConfig) (policy *coreConf.Policy) {
|
||||||
|
|||||||
@@ -7,14 +7,15 @@
|
|||||||
{
|
{
|
||||||
"Type": "sing",
|
"Type": "sing",
|
||||||
"Log": {
|
"Log": {
|
||||||
"Level": "error",
|
"Level": "info",
|
||||||
"Timestamp": true
|
"Timestamp": true
|
||||||
},
|
},
|
||||||
"NTP": {
|
"NTP": {
|
||||||
"Enable": true,
|
"Enable": false,
|
||||||
"Server": "time.apple.com",
|
"Server": "time.apple.com",
|
||||||
"ServerPort": 0
|
"ServerPort": 0
|
||||||
}
|
},
|
||||||
|
"OriginalPath": "/etc/V2bX/sing_origin.json"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"Nodes": [
|
"Nodes": [
|
||||||
@@ -27,20 +28,19 @@
|
|||||||
"Timeout": 30,
|
"Timeout": 30,
|
||||||
"ListenIP": "0.0.0.0",
|
"ListenIP": "0.0.0.0",
|
||||||
"SendIP": "0.0.0.0",
|
"SendIP": "0.0.0.0",
|
||||||
"EnableProxyProtocol": false,
|
"DeviceOnlineMinTraffic": 200,
|
||||||
"EnableDNS": true,
|
"MinReportTraffic": 0,
|
||||||
"DomainStrategy": "ipv4_only",
|
"TCPFastOpen": false,
|
||||||
"LimitConfig": {
|
"SniffEnabled": true,
|
||||||
"EnableRealtime": false,
|
"CertConfig": {
|
||||||
"SpeedLimit": 0,
|
"CertMode": "self",
|
||||||
"IPLimit": 0,
|
"RejectUnknownSni": false,
|
||||||
"ConnLimit": 0,
|
"CertDomain": "example.com",
|
||||||
"EnableDynamicSpeedLimit": false,
|
"CertFile": "/etc/V2bX/fullchain.cer",
|
||||||
"DynamicSpeedLimitConfig": {
|
"KeyFile": "/etc/V2bX/cert.key",
|
||||||
"Periodic": 60,
|
"Provider": "cloudflare",
|
||||||
"Traffic": 1000,
|
"DNSEnv": {
|
||||||
"SpeedLimit": 100,
|
"EnvName": "env1"
|
||||||
"ExpireTime": 60
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,259 +0,0 @@
|
|||||||
{
|
|
||||||
"Log": {
|
|
||||||
// V2bX 的日志配置,独立于各 Core 的 log 配置
|
|
||||||
|
|
||||||
// 日志等级,info, warn, error, none
|
|
||||||
"Level": "error",
|
|
||||||
// 日志输出路径,默认输出到标准输出
|
|
||||||
"Output": ""
|
|
||||||
},
|
|
||||||
"Cores": [
|
|
||||||
{
|
|
||||||
// Core类型
|
|
||||||
"Type": "sing",
|
|
||||||
// Core标识名,可选,如果需要启动多个同类型内核则必填
|
|
||||||
"Name": "sing1",
|
|
||||||
"Log": {
|
|
||||||
// 同 SingBox log 部分配置
|
|
||||||
|
|
||||||
"Level": "error",
|
|
||||||
"Timestamp": true
|
|
||||||
},
|
|
||||||
"NTP": {
|
|
||||||
// 同 SingBox ntp 部分配置
|
|
||||||
// VMess VLESS 建议开启
|
|
||||||
"Enable": true,
|
|
||||||
"Server": "time.apple.com",
|
|
||||||
"ServerPort": 0
|
|
||||||
},
|
|
||||||
"DnsConfigPath": "/etc/V2bX/dns.json",
|
|
||||||
// SingBox源配置文件目录,用于引用标准SingBox配置文件
|
|
||||||
"OriginalPath": "/etc/V2bX/sing_origin.json"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"Type": "sing",
|
|
||||||
"Name": "sing2",
|
|
||||||
"Log": {
|
|
||||||
"Level": "info",
|
|
||||||
"Timestamp": false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"Type": "xray",
|
|
||||||
"Log": {
|
|
||||||
// 同 Xray-core log 部分配置
|
|
||||||
|
|
||||||
"Level": "error"
|
|
||||||
},
|
|
||||||
// 静态资源文件目录
|
|
||||||
"AssetPath": "",
|
|
||||||
// DNS配置文件目录
|
|
||||||
"DnsConfigPath": "",
|
|
||||||
// 路由配置文件目录
|
|
||||||
"RouteConfigPath": "",
|
|
||||||
// 本地策略相关配置
|
|
||||||
"ConnectionConfig": {
|
|
||||||
// 详见 https://xtls.github.io/config/policy.html#levelpolicyobject
|
|
||||||
|
|
||||||
"handshake": 4,
|
|
||||||
"connIdle": 300,
|
|
||||||
"uplinkOnly": 2,
|
|
||||||
"downlinkOnly": 5,
|
|
||||||
"statsUserUplink": false,
|
|
||||||
"statsUserDownlink": false,
|
|
||||||
"bufferSize": 4
|
|
||||||
},
|
|
||||||
// Inbound配置文件目录
|
|
||||||
"InboundConfigPath": "",
|
|
||||||
// Outbound配置文件目录
|
|
||||||
"OutboundConfigPath": ""
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"Nodes": [
|
|
||||||
// Node配置有两种写法
|
|
||||||
{
|
|
||||||
// 写法1
|
|
||||||
// sing内核
|
|
||||||
|
|
||||||
// Node标识名,便于查看日志,不填将通过下发的节点配置自动生成
|
|
||||||
// 务必注意不要重复,否则会出现问题
|
|
||||||
"Name": "sing_node1",
|
|
||||||
|
|
||||||
// 要使用的Core的类型
|
|
||||||
// 如果填写了CoreName可不填,但单内核务必填写
|
|
||||||
// 建议视情况填写Core和CoreName其中一个,如果均没有填写将随机选择支持的内核
|
|
||||||
"Core": "sing",
|
|
||||||
|
|
||||||
// 要使用的Core的标识名,如果没有定义多个同类型内核可不填
|
|
||||||
"CoreName": "sing1",
|
|
||||||
|
|
||||||
// API接口地址
|
|
||||||
"ApiHost": "http://127.0.0.1",
|
|
||||||
|
|
||||||
// API密钥,即Token
|
|
||||||
"ApiKey": "test",
|
|
||||||
|
|
||||||
// 节点ID
|
|
||||||
"NodeID": 33,
|
|
||||||
|
|
||||||
// 节点类型
|
|
||||||
"NodeType": "shadowsocks",
|
|
||||||
|
|
||||||
// 请求超时时间
|
|
||||||
"Timeout": 30,
|
|
||||||
|
|
||||||
// 监听IP
|
|
||||||
"ListenIP": "0.0.0.0",
|
|
||||||
|
|
||||||
// 发送IP
|
|
||||||
"SendIP": "0.0.0.0",
|
|
||||||
|
|
||||||
// 开启 Proxy Protocol,参见 https://github.com/haproxy/haproxy/blob/master/doc/proxy-protocol.txt
|
|
||||||
"EnableProxyProtocol": false,
|
|
||||||
|
|
||||||
// 开启 TCP Fast Open
|
|
||||||
"EnableTFO": true,
|
|
||||||
|
|
||||||
// 开启 DNS
|
|
||||||
"EnableDNS" : true,
|
|
||||||
// 设置 Domain Strategy 需要开启 DNS ,默认 AsIS
|
|
||||||
// 可选 prefer_ipv4 / prefer_ipv6 / ipv4_only / ipv6_only
|
|
||||||
"DomainStrategy": "ipv4_only",
|
|
||||||
|
|
||||||
// 限制器相关配置
|
|
||||||
"LimitConfig": {
|
|
||||||
// 开启实时连接数及IP数限制
|
|
||||||
"EnableRealtime": false,
|
|
||||||
|
|
||||||
// 用户速度限制
|
|
||||||
"SpeedLimit": 0,
|
|
||||||
|
|
||||||
// 用户IP限制
|
|
||||||
"IPLimit": 0,
|
|
||||||
|
|
||||||
// 用户连接数限制
|
|
||||||
"ConnLimit": 0,
|
|
||||||
|
|
||||||
// 开启动态限速
|
|
||||||
"EnableDynamicSpeedLimit": false,
|
|
||||||
|
|
||||||
// 动态限速相关配置
|
|
||||||
"DynamicSpeedLimitConfig": {
|
|
||||||
// 检查周期
|
|
||||||
"Periodic": 60,
|
|
||||||
|
|
||||||
// 检查周期内触发限制的流量数
|
|
||||||
"Traffic": 1000,
|
|
||||||
|
|
||||||
// 触发限制后的速度限制
|
|
||||||
"SpeedLimit": 100,
|
|
||||||
|
|
||||||
// 速度限制过期时间
|
|
||||||
"ExpireTime": 60
|
|
||||||
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
// 证书相关配置
|
|
||||||
"CertConfig": {
|
|
||||||
// 证书申请模式,none、http、dns、self
|
|
||||||
"CertMode": "none",
|
|
||||||
|
|
||||||
"RejectUnknownSni": false,
|
|
||||||
|
|
||||||
// 证书域名
|
|
||||||
"CertDomain": "test.com",
|
|
||||||
|
|
||||||
// 证书文件目录
|
|
||||||
"CertFile": "/etc/V2bX/cert/1.pem",
|
|
||||||
|
|
||||||
// 密钥文件目录
|
|
||||||
"KeyFile": "/etc/V2bX/cert/1.key",
|
|
||||||
|
|
||||||
// 申请证书时使用的用户邮箱
|
|
||||||
"Email": "1@test.com",
|
|
||||||
|
|
||||||
// DNS解析提供者
|
|
||||||
"Provider": "cloudflare",
|
|
||||||
|
|
||||||
// DNS解析提供者的环境变量,详见 https://go-acme.github.io/lego/dns/
|
|
||||||
"DNSEnv": {
|
|
||||||
"EnvName": "env1"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// xray内核
|
|
||||||
|
|
||||||
"Name": "xray_node1",
|
|
||||||
"Core": "xray",
|
|
||||||
"CoreName": "",
|
|
||||||
"ApiHost": "http://127.0.0.1",
|
|
||||||
"ApiKey": "test",
|
|
||||||
"NodeID": 33,
|
|
||||||
"NodeType": "shadowsocks",
|
|
||||||
"Timeout": 30,
|
|
||||||
"ListenIP": "0.0.0.0",
|
|
||||||
"SendIP": "0.0.0.0",
|
|
||||||
"EnableProxyProtocol": true,
|
|
||||||
"EnableTFO": true,
|
|
||||||
// 以上同 sing
|
|
||||||
|
|
||||||
// 开启自定义DNS
|
|
||||||
"EnableDNS": false,
|
|
||||||
|
|
||||||
// DNS解析类型,AsIs、UseIP、UseIPv4、UseIPv6
|
|
||||||
"DNSType": "AsIs",
|
|
||||||
|
|
||||||
// 开启udp over tcp
|
|
||||||
"EnableUot": false,
|
|
||||||
|
|
||||||
// 禁用IVCheck
|
|
||||||
"DisableIVCheck": false,
|
|
||||||
|
|
||||||
// 禁用嗅探
|
|
||||||
"DisableSniffing": false,
|
|
||||||
|
|
||||||
// 开启回落
|
|
||||||
"EnableFallback": false,
|
|
||||||
|
|
||||||
// 回落相关配置
|
|
||||||
"FallBackConfigs":{
|
|
||||||
// 详见 https://xtls.github.io/config/features/fallback.html#fallbackobject
|
|
||||||
|
|
||||||
"SNI": "",
|
|
||||||
"Alpn": "",
|
|
||||||
"Path": "",
|
|
||||||
"Dest": "",
|
|
||||||
"ProxyProtocolVer": 0
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// 写法2
|
|
||||||
|
|
||||||
// 类似旧配置文件 ApiConfig 部分
|
|
||||||
"ApiConfig": {
|
|
||||||
"ApiHost": "http://127.0.0.1",
|
|
||||||
"ApiKey": "test",
|
|
||||||
"NodeID": 33,
|
|
||||||
"Timeout": 30
|
|
||||||
},
|
|
||||||
// 类似旧配置文件 ControllerConfig 部分
|
|
||||||
"Options": {
|
|
||||||
"Core": "sing",
|
|
||||||
"EnableProxyProtocol": true,
|
|
||||||
"EnableTFO": true,
|
|
||||||
"DomainStrategy": "ipv4_only"
|
|
||||||
// More
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// 引用本地其他配置文件
|
|
||||||
"Include": "../example/config_full_node1.json"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// 通过Http引用远端配置文件
|
|
||||||
"Include": "http://127.0.0.1:11451/config_full_node1.json"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
{
|
|
||||||
"Core": "xray",
|
|
||||||
"ApiHost": "https://127.0.0.1",
|
|
||||||
"ApiKey": "key",
|
|
||||||
"NodeID": 1,
|
|
||||||
"NodeType": "vmess",
|
|
||||||
"Timeout": 30,
|
|
||||||
"ListenIP": "0.0.0.0",
|
|
||||||
"SendIP": "0.0.0.0",
|
|
||||||
"EnableProxyProtocol": false,
|
|
||||||
"EnableTFO": true,
|
|
||||||
"DNSType": "ipv4_only"
|
|
||||||
}
|
|
||||||
328
go.mod
328
go.mod
@@ -1,92 +1,96 @@
|
|||||||
module github.com/InazumaV/V2bX
|
module github.com/InazumaV/V2bX
|
||||||
|
|
||||||
go 1.24
|
go 1.25
|
||||||
|
|
||||||
toolchain go1.24.1
|
toolchain go1.25.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/apernet/hysteria/core/v2 v2.6.1
|
github.com/apernet/hysteria/core/v2 v2.6.3
|
||||||
github.com/apernet/hysteria/extras/v2 v2.6.1
|
github.com/apernet/hysteria/extras/v2 v2.6.3
|
||||||
github.com/apernet/quic-go v0.49.1-0.20250204013113-43c72b1281a0
|
github.com/apernet/quic-go v0.52.1-0.20250607183305-9320c9d14431
|
||||||
github.com/beevik/ntp v1.4.4-0.20240716062501-06ef196b89ec
|
github.com/beevik/ntp v1.4.4-0.20240716062501-06ef196b89ec
|
||||||
github.com/fsnotify/fsnotify v1.8.0
|
github.com/fsnotify/fsnotify v1.9.0
|
||||||
github.com/go-acme/lego/v4 v4.21.1-0.20241220151055-ee7a9e4fa04f
|
github.com/go-acme/lego/v4 v4.25.2
|
||||||
github.com/go-resty/resty/v2 v2.16.2
|
github.com/go-resty/resty/v2 v2.16.5
|
||||||
github.com/goccy/go-json v0.10.4
|
|
||||||
github.com/hashicorp/go-multierror v1.1.2-0.20241119060415-613124da9385
|
|
||||||
github.com/juju/ratelimit v1.0.2
|
github.com/juju/ratelimit v1.0.2
|
||||||
github.com/sagernet/sing v0.6.2-0.20250210072154-8dff604468ff
|
github.com/sagernet/sing v0.7.6-0.20250815070458-d33ece7a184f
|
||||||
github.com/sagernet/sing-box v1.12.0
|
github.com/sagernet/sing-box v1.13.0
|
||||||
github.com/sirupsen/logrus v1.9.3
|
github.com/sirupsen/logrus v1.9.3
|
||||||
github.com/spf13/cobra v1.8.1
|
github.com/spf13/cobra v1.9.1
|
||||||
github.com/spf13/viper v1.19.0
|
github.com/spf13/viper v1.19.0
|
||||||
github.com/xtls/xray-core v1.250306.1-0.20250331123338-ab5d7cf3d2d6
|
github.com/vmihailenco/msgpack/v5 v5.4.1
|
||||||
|
github.com/xtls/xray-core v1.250911.1-0.20250911134820-83c5370eec69
|
||||||
go.uber.org/zap v1.27.0
|
go.uber.org/zap v1.27.0
|
||||||
golang.org/x/crypto v0.36.0
|
golang.org/x/crypto v0.42.0
|
||||||
golang.org/x/sys v0.31.0
|
golang.org/x/sys v0.36.0
|
||||||
google.golang.org/protobuf v1.36.6
|
google.golang.org/protobuf v1.36.9
|
||||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1
|
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
cloud.google.com/go/auth v0.13.0 // indirect
|
cloud.google.com/go/auth v0.16.2 // indirect
|
||||||
cloud.google.com/go/auth/oauth2adapt v0.2.6 // indirect
|
cloud.google.com/go/auth/oauth2adapt v0.2.8 // indirect
|
||||||
cloud.google.com/go/compute/metadata v0.6.0 // indirect
|
cloud.google.com/go/compute/metadata v0.7.0 // indirect
|
||||||
filippo.io/edwards25519 v1.1.0 // indirect
|
filippo.io/edwards25519 v1.1.0 // indirect
|
||||||
github.com/AdamSLevy/jsonrpc2/v14 v14.1.0 // indirect
|
github.com/AdamSLevy/jsonrpc2/v14 v14.1.0 // indirect
|
||||||
github.com/Azure/azure-sdk-for-go v68.0.0+incompatible // indirect
|
github.com/Azure/azure-sdk-for-go v68.0.0+incompatible // indirect
|
||||||
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.16.0 // indirect
|
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.18.1 // indirect
|
||||||
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.8.0 // indirect
|
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.10.1 // indirect
|
||||||
github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0 // indirect
|
github.com/Azure/azure-sdk-for-go/sdk/internal v1.11.1 // indirect
|
||||||
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/dns/armdns v1.2.0 // indirect
|
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/dns/armdns v1.2.0 // indirect
|
||||||
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/privatedns/armprivatedns v1.3.0 // indirect
|
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/privatedns/armprivatedns v1.3.0 // indirect
|
||||||
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resourcegraph/armresourcegraph v0.9.0 // indirect
|
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resourcegraph/armresourcegraph v0.9.0 // indirect
|
||||||
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
|
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
|
||||||
github.com/Azure/go-autorest/autorest v0.11.29 // indirect
|
github.com/Azure/go-autorest/autorest v0.11.30 // indirect
|
||||||
github.com/Azure/go-autorest/autorest/adal v0.9.22 // indirect
|
github.com/Azure/go-autorest/autorest/adal v0.9.22 // indirect
|
||||||
github.com/Azure/go-autorest/autorest/azure/auth v0.5.13 // indirect
|
github.com/Azure/go-autorest/autorest/azure/auth v0.5.13 // indirect
|
||||||
github.com/Azure/go-autorest/autorest/azure/cli v0.4.6 // indirect
|
github.com/Azure/go-autorest/autorest/azure/cli v0.4.6 // indirect
|
||||||
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
|
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
|
||||||
github.com/Azure/go-autorest/autorest/to v0.4.0 // indirect
|
github.com/Azure/go-autorest/autorest/to v0.4.1 // indirect
|
||||||
github.com/Azure/go-autorest/logger v0.2.1 // indirect
|
github.com/Azure/go-autorest/logger v0.2.1 // indirect
|
||||||
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
|
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
|
||||||
github.com/AzureAD/microsoft-authentication-library-for-go v1.2.2 // indirect
|
github.com/AzureAD/microsoft-authentication-library-for-go v1.4.2 // indirect
|
||||||
github.com/OpenDNS/vegadns2client v0.0.0-20180418235048-a3fa4a771d87 // indirect
|
github.com/OpenDNS/vegadns2client v0.0.0-20180418235048-a3fa4a771d87 // indirect
|
||||||
github.com/ajg/form v1.5.1 // indirect
|
github.com/ajg/form v1.5.1 // indirect
|
||||||
github.com/akamai/AkamaiOPEN-edgegrid-golang v1.2.2 // indirect
|
github.com/akamai/AkamaiOPEN-edgegrid-golang v1.2.2 // indirect
|
||||||
github.com/akutz/memconn v0.1.0 // indirect
|
github.com/akutz/memconn v0.1.0 // indirect
|
||||||
github.com/alexbrainman/sspi v0.0.0-20231016080023-1a75b4708caa // indirect
|
github.com/alexbrainman/sspi v0.0.0-20231016080023-1a75b4708caa // indirect
|
||||||
github.com/aliyun/alibaba-cloud-sdk-go v1.63.72 // indirect
|
github.com/alibabacloud-go/alibabacloud-gateway-spi v0.0.5 // indirect
|
||||||
|
github.com/alibabacloud-go/darabonba-openapi/v2 v2.1.8 // indirect
|
||||||
|
github.com/alibabacloud-go/debug v1.0.1 // indirect
|
||||||
|
github.com/alibabacloud-go/endpoint-util v1.1.0 // indirect
|
||||||
|
github.com/alibabacloud-go/openapi-util v0.1.1 // indirect
|
||||||
|
github.com/alibabacloud-go/tea v1.3.9 // indirect
|
||||||
|
github.com/alibabacloud-go/tea-utils/v2 v2.0.7 // indirect
|
||||||
|
github.com/aliyun/credentials-go v1.4.6 // indirect
|
||||||
github.com/andybalholm/brotli v1.1.0 // indirect
|
github.com/andybalholm/brotli v1.1.0 // indirect
|
||||||
github.com/anytls/sing-anytls v0.0.5 // indirect
|
github.com/anytls/sing-anytls v0.0.9-0.20250508103614-8bc6dd599731 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2 v1.32.7 // indirect
|
github.com/aws/aws-sdk-go-v2 v1.36.6 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/config v1.28.7 // indirect
|
github.com/aws/aws-sdk-go-v2/config v1.29.18 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/credentials v1.17.48 // indirect
|
github.com/aws/aws-sdk-go-v2/credentials v1.17.71 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.22 // indirect
|
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.33 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.26 // indirect
|
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.37 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.26 // indirect
|
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.37 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 // indirect
|
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.3 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.1 // indirect
|
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.4 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.7 // indirect
|
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.18 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/service/lightsail v1.42.8 // indirect
|
github.com/aws/aws-sdk-go-v2/service/lightsail v1.43.5 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/service/route53 v1.46.4 // indirect
|
github.com/aws/aws-sdk-go-v2/service/route53 v1.53.1 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/service/sso v1.24.8 // indirect
|
github.com/aws/aws-sdk-go-v2/service/sso v1.25.6 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.7 // indirect
|
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.30.4 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/service/sts v1.33.3 // indirect
|
github.com/aws/aws-sdk-go-v2/service/sts v1.34.1 // indirect
|
||||||
github.com/aws/smithy-go v1.22.1 // indirect
|
github.com/aws/smithy-go v1.22.4 // indirect
|
||||||
github.com/babolivier/go-doh-client v0.0.0-20201028162107-a76cff4cb8b6 // indirect
|
github.com/aziontech/azionapi-go-sdk v0.142.0 // indirect
|
||||||
|
github.com/baidubce/bce-sdk-go v0.9.235 // indirect
|
||||||
github.com/benbjohnson/clock v1.3.0 // indirect
|
github.com/benbjohnson/clock v1.3.0 // indirect
|
||||||
github.com/bits-and-blooms/bitset v1.13.0 // indirect
|
github.com/bits-and-blooms/bitset v1.13.0 // indirect
|
||||||
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc // indirect
|
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc // indirect
|
||||||
github.com/caddyserver/certmagic v0.21.7 // indirect
|
github.com/caddyserver/certmagic v0.23.0 // indirect
|
||||||
github.com/caddyserver/zerossl v0.1.3 // indirect
|
github.com/caddyserver/zerossl v0.1.3 // indirect
|
||||||
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
|
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
|
||||||
github.com/civo/civogo v0.3.11 // indirect
|
github.com/clbanning/mxj/v2 v2.7.0 // indirect
|
||||||
github.com/cloudflare/circl v1.6.0 // indirect
|
github.com/cloudflare/circl v1.6.1 // indirect
|
||||||
github.com/cloudflare/cloudflare-go v0.112.0 // indirect
|
github.com/coder/websocket v1.8.13 // indirect
|
||||||
github.com/coder/websocket v1.8.12 // indirect
|
|
||||||
github.com/coreos/go-iptables v0.7.1-0.20240112124308-65c67c9f46e6 // indirect
|
github.com/coreos/go-iptables v0.7.1-0.20240112124308-65c67c9f46e6 // indirect
|
||||||
github.com/cpu/goacmedns v0.1.1 // indirect
|
|
||||||
github.com/cretz/bine v0.2.0 // indirect
|
github.com/cretz/bine v0.2.0 // indirect
|
||||||
github.com/database64128/netx-go v0.0.0-20240905055117-62795b8b054a // indirect
|
github.com/database64128/netx-go v0.0.0-20240905055117-62795b8b054a // indirect
|
||||||
github.com/database64128/tfo-go/v2 v2.2.2 // indirect
|
github.com/database64128/tfo-go/v2 v2.2.2 // indirect
|
||||||
@@ -95,171 +99,171 @@ require (
|
|||||||
github.com/dgryski/go-metro v0.0.0-20211217172704-adc40b04c140 // indirect
|
github.com/dgryski/go-metro v0.0.0-20211217172704-adc40b04c140 // indirect
|
||||||
github.com/digitalocean/go-smbios v0.0.0-20180907143718-390a4f403a8e // indirect
|
github.com/digitalocean/go-smbios v0.0.0-20180907143718-390a4f403a8e // indirect
|
||||||
github.com/dimchansky/utfbom v1.1.1 // indirect
|
github.com/dimchansky/utfbom v1.1.1 // indirect
|
||||||
github.com/dnsimple/dnsimple-go v1.7.0 // indirect
|
github.com/dnsimple/dnsimple-go/v4 v4.0.0 // indirect
|
||||||
github.com/exoscale/egoscale/v3 v3.1.7 // indirect
|
github.com/exoscale/egoscale/v3 v3.1.24 // indirect
|
||||||
github.com/fatih/structs v1.1.0 // indirect
|
github.com/fatih/structs v1.1.0 // indirect
|
||||||
github.com/felixge/httpsnoop v1.0.4 // indirect
|
github.com/felixge/httpsnoop v1.0.4 // indirect
|
||||||
github.com/fxamacker/cbor/v2 v2.6.0 // indirect
|
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
|
||||||
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
|
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
|
||||||
github.com/gaissmai/bart v0.11.1 // indirect
|
github.com/gaissmai/bart v0.11.1 // indirect
|
||||||
github.com/ghodss/yaml v1.0.1-0.20220118164431-d8423dcdf344 // indirect
|
github.com/ghodss/yaml v1.0.1-0.20220118164431-d8423dcdf344 // indirect
|
||||||
github.com/go-chi/chi/v5 v5.2.1 // indirect
|
github.com/go-acme/alidns-20150109/v4 v4.5.10 // indirect
|
||||||
|
github.com/go-acme/tencentclouddnspod v1.0.1208 // indirect
|
||||||
|
github.com/go-chi/chi/v5 v5.2.2 // indirect
|
||||||
github.com/go-chi/render v1.0.3 // indirect
|
github.com/go-chi/render v1.0.3 // indirect
|
||||||
github.com/go-errors/errors v1.0.1 // indirect
|
github.com/go-errors/errors v1.0.1 // indirect
|
||||||
github.com/go-jose/go-jose/v4 v4.0.4 // indirect
|
github.com/go-jose/go-jose/v4 v4.1.1 // indirect
|
||||||
github.com/go-json-experiment/json v0.0.0-20231102232822-2e55bd4e08b0 // indirect
|
github.com/go-json-experiment/json v0.0.0-20250103232110-6a9a0fde9288 // indirect
|
||||||
github.com/go-logr/logr v1.4.2 // indirect
|
github.com/go-logr/logr v1.4.3 // indirect
|
||||||
github.com/go-logr/stdr v1.2.2 // indirect
|
github.com/go-logr/stdr v1.2.2 // indirect
|
||||||
github.com/go-ole/go-ole v1.3.0 // indirect
|
github.com/go-ole/go-ole v1.3.0 // indirect
|
||||||
github.com/go-playground/locales v0.14.1 // indirect
|
github.com/go-playground/locales v0.14.1 // indirect
|
||||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||||
github.com/go-playground/validator/v10 v10.16.0 // indirect
|
github.com/go-playground/validator/v10 v10.23.0 // indirect
|
||||||
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
|
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
|
||||||
github.com/go-viper/mapstructure/v2 v2.2.1 // indirect
|
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
|
||||||
github.com/gobwas/httphead v0.1.0 // indirect
|
github.com/gobwas/httphead v0.1.0 // indirect
|
||||||
github.com/gobwas/pool v0.2.1 // indirect
|
github.com/gobwas/pool v0.2.1 // indirect
|
||||||
github.com/godbus/dbus/v5 v5.1.1-0.20230522191255-76236955d466 // indirect
|
github.com/godbus/dbus/v5 v5.1.1-0.20230522191255-76236955d466 // indirect
|
||||||
github.com/gofrs/flock v0.12.1 // indirect
|
github.com/gofrs/flock v0.12.1 // indirect
|
||||||
github.com/gofrs/uuid/v5 v5.3.1 // indirect
|
github.com/gofrs/uuid/v5 v5.3.2 // indirect
|
||||||
github.com/golang-jwt/jwt/v4 v4.5.1 // indirect
|
github.com/golang-jwt/jwt/v4 v4.5.2 // indirect
|
||||||
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
|
github.com/golang-jwt/jwt/v5 v5.2.2 // indirect
|
||||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
||||||
|
github.com/golang/protobuf v1.5.4 // indirect
|
||||||
github.com/google/btree v1.1.3 // indirect
|
github.com/google/btree v1.1.3 // indirect
|
||||||
github.com/google/go-cmp v0.7.0 // indirect
|
github.com/google/go-cmp v0.7.0 // indirect
|
||||||
github.com/google/go-querystring v1.1.0 // indirect
|
github.com/google/go-querystring v1.1.0 // indirect
|
||||||
github.com/google/nftables v0.2.1-0.20240414091927-5e242ec57806 // indirect
|
github.com/google/nftables v0.2.1-0.20240414091927-5e242ec57806 // indirect
|
||||||
github.com/google/pprof v0.0.0-20240528025155-186aa0362fba // indirect
|
github.com/google/pprof v0.0.0-20240727154555-813a5fbdbec8 // indirect
|
||||||
github.com/google/s2a-go v0.1.8 // indirect
|
github.com/google/s2a-go v0.1.9 // indirect
|
||||||
github.com/google/uuid v1.6.0 // indirect
|
github.com/google/uuid v1.6.0 // indirect
|
||||||
github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect
|
github.com/googleapis/enterprise-certificate-proxy v0.3.6 // indirect
|
||||||
github.com/googleapis/gax-go/v2 v2.14.0 // indirect
|
github.com/googleapis/gax-go/v2 v2.14.2 // indirect
|
||||||
github.com/gophercloud/gophercloud v1.14.1 // indirect
|
github.com/gophercloud/gophercloud v1.14.1 // indirect
|
||||||
github.com/gophercloud/utils v0.0.0-20231010081019-80377eca5d56 // indirect
|
github.com/gophercloud/utils v0.0.0-20231010081019-80377eca5d56 // indirect
|
||||||
github.com/gorilla/csrf v1.7.2 // indirect
|
github.com/gorilla/csrf v1.7.3-0.20250123201450-9dd6af1f6d30 // indirect
|
||||||
github.com/gorilla/securecookie v1.1.2 // indirect
|
github.com/gorilla/securecookie v1.1.2 // indirect
|
||||||
github.com/gorilla/websocket v1.5.3 // indirect
|
github.com/gorilla/websocket v1.5.3 // indirect
|
||||||
github.com/hashicorp/errwrap v1.1.0 // indirect
|
|
||||||
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
|
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
|
||||||
github.com/hashicorp/go-retryablehttp v0.7.7 // indirect
|
github.com/hashicorp/go-retryablehttp v0.7.8 // indirect
|
||||||
github.com/hashicorp/go-uuid v1.0.3 // indirect
|
github.com/hashicorp/go-uuid v1.0.3 // indirect
|
||||||
github.com/hashicorp/golang-lru/v2 v2.0.5 // indirect
|
github.com/hashicorp/golang-lru/v2 v2.0.5 // indirect
|
||||||
github.com/hashicorp/hcl v1.0.0 // indirect
|
github.com/hashicorp/hcl v1.0.0 // indirect
|
||||||
github.com/hashicorp/yamux v0.1.2 // indirect
|
github.com/hashicorp/yamux v0.1.2 // indirect
|
||||||
github.com/hdevalence/ed25519consensus v0.2.0 // indirect
|
github.com/hdevalence/ed25519consensus v0.2.0 // indirect
|
||||||
github.com/huaweicloud/huaweicloud-sdk-go-v3 v0.1.128 // indirect
|
github.com/huaweicloud/huaweicloud-sdk-go-v3 v0.1.159 // indirect
|
||||||
github.com/iij/doapi v0.0.0-20190504054126-0bbf12d6d7df // indirect
|
github.com/iij/doapi v0.0.0-20190504054126-0bbf12d6d7df // indirect
|
||||||
github.com/illarion/gonotify/v2 v2.0.3 // indirect
|
github.com/illarion/gonotify/v2 v2.0.3 // indirect
|
||||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||||
github.com/infobloxopen/infoblox-go-client v1.1.1 // indirect
|
github.com/infobloxopen/infoblox-go-client/v2 v2.10.0 // indirect
|
||||||
github.com/insomniacslk/dhcp v0.0.0-20250109001534-8abf58130905 // indirect
|
github.com/insomniacslk/dhcp v0.0.0-20250417080101-5f8cf70e8c5f // indirect
|
||||||
github.com/jmespath/go-jmespath v0.4.0 // indirect
|
|
||||||
github.com/josharian/native v1.1.1-0.20230202152459-5c7d0dd6ab86 // indirect
|
|
||||||
github.com/jsimonetti/rtnetlink v1.4.0 // indirect
|
github.com/jsimonetti/rtnetlink v1.4.0 // indirect
|
||||||
github.com/json-iterator/go v1.1.12 // indirect
|
github.com/json-iterator/go v1.1.12 // indirect
|
||||||
github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213 // indirect
|
github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213 // indirect
|
||||||
github.com/klauspost/compress v1.17.11 // indirect
|
github.com/klauspost/compress v1.17.11 // indirect
|
||||||
github.com/klauspost/cpuid/v2 v2.2.9 // indirect
|
github.com/klauspost/cpuid/v2 v2.2.10 // indirect
|
||||||
github.com/kolo/xmlrpc v0.0.0-20220921171641-a4b6fa1dd06b // indirect
|
github.com/kolo/xmlrpc v0.0.0-20220921171641-a4b6fa1dd06b // indirect
|
||||||
github.com/kortschak/wol v0.0.0-20200729010619-da482cc4850a // indirect
|
github.com/kortschak/wol v0.0.0-20200729010619-da482cc4850a // indirect
|
||||||
github.com/kylelemons/godebug v1.1.0 // indirect
|
github.com/kylelemons/godebug v1.1.0 // indirect
|
||||||
github.com/labbsr0x/bindman-dns-webhook v1.0.2 // indirect
|
github.com/labbsr0x/bindman-dns-webhook v1.0.2 // indirect
|
||||||
github.com/labbsr0x/goh v1.0.1 // indirect
|
github.com/labbsr0x/goh v1.0.1 // indirect
|
||||||
github.com/leodido/go-urn v1.2.4 // indirect
|
github.com/leodido/go-urn v1.4.0 // indirect
|
||||||
github.com/libdns/alidns v1.0.3 // indirect
|
github.com/libdns/alidns v1.0.5-libdns.v1.beta1 // indirect
|
||||||
github.com/libdns/cloudflare v0.1.1 // indirect
|
github.com/libdns/cloudflare v0.2.2-0.20250708034226-c574dccb31a6 // indirect
|
||||||
github.com/libdns/libdns v0.2.2 // indirect
|
github.com/libdns/libdns v1.1.0 // indirect
|
||||||
github.com/linode/linodego v1.44.0 // indirect
|
github.com/linode/linodego v1.53.0 // indirect
|
||||||
github.com/liquidweb/liquidweb-cli v0.6.9 // indirect
|
github.com/liquidweb/liquidweb-cli v0.6.9 // indirect
|
||||||
github.com/liquidweb/liquidweb-go v1.6.4 // indirect
|
github.com/liquidweb/liquidweb-go v1.6.4 // indirect
|
||||||
github.com/logrusorgru/aurora v2.0.3+incompatible // indirect
|
github.com/logrusorgru/aurora v2.0.3+incompatible // indirect
|
||||||
github.com/magiconair/properties v1.8.7 // indirect
|
github.com/magiconair/properties v1.8.7 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||||
github.com/mdlayher/genetlink v1.3.2 // indirect
|
github.com/mdlayher/genetlink v1.3.2 // indirect
|
||||||
github.com/mdlayher/netlink v1.7.2 // indirect
|
github.com/mdlayher/netlink v1.7.3-0.20250113171957-fbb4dce95f42 // indirect
|
||||||
github.com/mdlayher/sdnotify v1.0.0 // indirect
|
github.com/mdlayher/sdnotify v1.0.0 // indirect
|
||||||
github.com/mdlayher/socket v0.5.1 // indirect
|
github.com/mdlayher/socket v0.5.1 // indirect
|
||||||
github.com/metacubex/tfo-go v0.0.0-20241231083714-66613d49c422 // indirect
|
github.com/metacubex/tfo-go v0.0.0-20250516165257-e29c16ae41d4 // indirect
|
||||||
github.com/mholt/acmez/v3 v3.0.1 // indirect
|
github.com/metacubex/utls v1.8.0 // indirect
|
||||||
github.com/miekg/dns v1.1.64 // indirect
|
github.com/mholt/acmez/v3 v3.1.2 // indirect
|
||||||
|
github.com/miekg/dns v1.1.68 // indirect
|
||||||
github.com/mimuret/golang-iij-dpf v0.9.1 // indirect
|
github.com/mimuret/golang-iij-dpf v0.9.1 // indirect
|
||||||
github.com/mitchellh/go-homedir v1.1.0 // indirect
|
github.com/mitchellh/go-homedir v1.1.0 // indirect
|
||||||
github.com/mitchellh/go-ps v1.0.0 // indirect
|
github.com/mitchellh/go-ps v1.0.0 // indirect
|
||||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||||
github.com/namedotcom/go v0.0.0-20180403034216-08470befbe04 // indirect
|
github.com/namedotcom/go/v4 v4.0.2 // indirect
|
||||||
github.com/nrdcg/auroradns v1.1.0 // indirect
|
github.com/nrdcg/auroradns v1.1.0 // indirect
|
||||||
github.com/nrdcg/bunny-go v0.0.0-20240207213615-dde5bf4577a3 // indirect
|
github.com/nrdcg/bunny-go v0.0.0-20250327222614-988a091fc7ea // indirect
|
||||||
github.com/nrdcg/desec v0.10.0 // indirect
|
github.com/nrdcg/desec v0.11.0 // indirect
|
||||||
github.com/nrdcg/dnspod-go v0.4.0 // indirect
|
github.com/nrdcg/dnspod-go v0.4.0 // indirect
|
||||||
github.com/nrdcg/freemyip v0.3.0 // indirect
|
github.com/nrdcg/freemyip v0.3.0 // indirect
|
||||||
github.com/nrdcg/goinwx v0.10.0 // indirect
|
github.com/nrdcg/goacmedns v0.2.0 // indirect
|
||||||
|
github.com/nrdcg/goinwx v0.11.0 // indirect
|
||||||
github.com/nrdcg/mailinabox v0.2.0 // indirect
|
github.com/nrdcg/mailinabox v0.2.0 // indirect
|
||||||
github.com/nrdcg/namesilo v0.2.1 // indirect
|
github.com/nrdcg/namesilo v0.2.1 // indirect
|
||||||
github.com/nrdcg/nodion v0.1.0 // indirect
|
github.com/nrdcg/nodion v0.1.0 // indirect
|
||||||
|
github.com/nrdcg/oci-go-sdk/common/v1065 v1065.95.2 // indirect
|
||||||
|
github.com/nrdcg/oci-go-sdk/dns/v1065 v1065.95.2 // indirect
|
||||||
github.com/nrdcg/porkbun v0.4.0 // indirect
|
github.com/nrdcg/porkbun v0.4.0 // indirect
|
||||||
github.com/nzdjb/go-metaname v1.0.0 // indirect
|
github.com/nzdjb/go-metaname v1.0.0 // indirect
|
||||||
github.com/onsi/ginkgo/v2 v2.19.0 // indirect
|
github.com/onsi/ginkgo/v2 v2.20.1 // indirect
|
||||||
github.com/opentracing/opentracing-go v1.2.1-0.20220228012449-10b1cf09e00b // indirect
|
github.com/ovh/go-ovh v1.9.0 // indirect
|
||||||
github.com/oracle/oci-go-sdk/v65 v65.81.1 // indirect
|
|
||||||
github.com/ovh/go-ovh v1.6.0 // indirect
|
|
||||||
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
|
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
|
||||||
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
|
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
|
||||||
github.com/peterhellberg/link v1.2.0 // indirect
|
github.com/peterhellberg/link v1.2.0 // indirect
|
||||||
github.com/pierrec/lz4/v4 v4.1.21 // indirect
|
github.com/pierrec/lz4/v4 v4.1.21 // indirect
|
||||||
github.com/pires/go-proxyproto v0.8.0 // indirect
|
github.com/pires/go-proxyproto v0.8.1 // indirect
|
||||||
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
|
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
|
||||||
github.com/pkg/errors v0.9.1 // indirect
|
github.com/pkg/errors v0.9.1 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
|
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
|
||||||
github.com/pquerna/otp v1.4.0 // indirect
|
github.com/pquerna/otp v1.5.0 // indirect
|
||||||
github.com/prometheus-community/pro-bing v0.4.0 // indirect
|
github.com/prometheus-community/pro-bing v0.4.0 // indirect
|
||||||
github.com/quic-go/qpack v0.5.1 // indirect
|
github.com/quic-go/qpack v0.5.1 // indirect
|
||||||
github.com/quic-go/qtls-go1-20 v0.4.1 // indirect
|
github.com/quic-go/quic-go v0.54.0 // indirect
|
||||||
github.com/quic-go/quic-go v0.50.1 // indirect
|
github.com/refraction-networking/utls v1.8.0 // indirect
|
||||||
github.com/refraction-networking/utls v1.6.7 // indirect
|
|
||||||
github.com/regfish/regfish-dnsapi-go v0.1.1 // indirect
|
github.com/regfish/regfish-dnsapi-go v0.1.1 // indirect
|
||||||
github.com/riobard/go-bloom v0.0.0-20200614022211-cdc8013cb5b3 // indirect
|
github.com/riobard/go-bloom v0.0.0-20200614022211-cdc8013cb5b3 // indirect
|
||||||
github.com/sacloud/api-client-go v0.2.10 // indirect
|
github.com/sacloud/api-client-go v0.3.2 // indirect
|
||||||
github.com/sacloud/go-http v0.1.8 // indirect
|
github.com/sacloud/go-http v0.1.9 // indirect
|
||||||
github.com/sacloud/iaas-api-go v1.14.0 // indirect
|
github.com/sacloud/iaas-api-go v1.16.1 // indirect
|
||||||
github.com/sacloud/packages-go v0.0.10 // indirect
|
github.com/sacloud/packages-go v0.0.11 // indirect
|
||||||
github.com/safchain/ethtool v0.3.0 // indirect
|
github.com/safchain/ethtool v0.3.0 // indirect
|
||||||
github.com/sagernet/bbolt v0.0.0-20231014093535-ea5cb2fe9f0a // indirect
|
github.com/sagernet/bbolt v0.0.0-20231014093535-ea5cb2fe9f0a // indirect
|
||||||
github.com/sagernet/cors v1.2.1 // indirect
|
github.com/sagernet/cors v1.2.1 // indirect
|
||||||
github.com/sagernet/fswatch v0.1.1 // indirect
|
github.com/sagernet/fswatch v0.1.1 // indirect
|
||||||
github.com/sagernet/gvisor v0.0.0-20241123041152-536d05261cff // indirect
|
github.com/sagernet/gvisor v0.0.0-20250325023245-7a9c0f5725fb // indirect
|
||||||
github.com/sagernet/netlink v0.0.0-20240612041022-b9a21c07ac6a // indirect
|
github.com/sagernet/netlink v0.0.0-20240612041022-b9a21c07ac6a // indirect
|
||||||
github.com/sagernet/nftables v0.3.0-beta.4 // indirect
|
github.com/sagernet/nftables v0.3.0-beta.4 // indirect
|
||||||
github.com/sagernet/quic-go v0.49.0-beta.1 // indirect
|
github.com/sagernet/quic-go v0.52.0-beta.1 // indirect
|
||||||
github.com/sagernet/sing-mux v0.3.1 // indirect
|
github.com/sagernet/sing-mux v0.3.3 // indirect
|
||||||
github.com/sagernet/sing-quic v0.4.1-beta.1 // indirect
|
github.com/sagernet/sing-quic v0.5.0 // indirect
|
||||||
github.com/sagernet/sing-shadowsocks v0.2.7 // indirect
|
github.com/sagernet/sing-shadowsocks v0.2.8 // indirect
|
||||||
github.com/sagernet/sing-shadowsocks2 v0.2.0 // indirect
|
github.com/sagernet/sing-shadowsocks2 v0.2.1 // indirect
|
||||||
github.com/sagernet/sing-shadowtls v0.2.0 // indirect
|
github.com/sagernet/sing-shadowtls v0.2.1-0.20250503051639-fcd445d33c11 // indirect
|
||||||
github.com/sagernet/sing-tun v0.6.1 // indirect
|
github.com/sagernet/sing-tun v0.7.0-beta.1 // indirect
|
||||||
github.com/sagernet/sing-vmess v0.2.0 // indirect
|
github.com/sagernet/sing-vmess v0.2.7 // indirect
|
||||||
github.com/sagernet/smux v0.0.0-20231208180855-7041f6ea79e7 // indirect
|
github.com/sagernet/smux v1.5.34-mod.2 // indirect
|
||||||
github.com/sagernet/tailscale v1.79.0-mod.1 // indirect
|
github.com/sagernet/tailscale v1.80.3-mod.5 // indirect
|
||||||
github.com/sagernet/utls v1.6.7 // indirect
|
github.com/sagernet/wireguard-go v0.0.1-beta.7 // indirect
|
||||||
github.com/sagernet/wireguard-go v0.0.1-beta.5 // indirect
|
|
||||||
github.com/sagernet/ws v0.0.0-20231204124109-acfe8907c854 // indirect
|
github.com/sagernet/ws v0.0.0-20231204124109-acfe8907c854 // indirect
|
||||||
github.com/sagikazarmark/locafero v0.4.0 // indirect
|
github.com/sagikazarmark/locafero v0.4.0 // indirect
|
||||||
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
|
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
|
||||||
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.30 // indirect
|
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.34 // indirect
|
||||||
github.com/seiflotfy/cuckoofilter v0.0.0-20240715131351-a2f2c23f1771 // indirect
|
github.com/seiflotfy/cuckoofilter v0.0.0-20240715131351-a2f2c23f1771 // indirect
|
||||||
github.com/selectel/domains-go v1.1.0 // indirect
|
github.com/selectel/domains-go v1.1.0 // indirect
|
||||||
github.com/selectel/go-selvpcclient/v3 v3.2.1 // indirect
|
github.com/selectel/go-selvpcclient/v4 v4.1.0 // indirect
|
||||||
github.com/shopspring/decimal v1.3.1 // indirect
|
github.com/shopspring/decimal v1.4.0 // indirect
|
||||||
github.com/smartystreets/go-aws-auth v0.0.0-20180515143844-0c1422d1fdb9 // indirect
|
github.com/smartystreets/go-aws-auth v0.0.0-20180515143844-0c1422d1fdb9 // indirect
|
||||||
github.com/softlayer/softlayer-go v1.1.7 // indirect
|
github.com/softlayer/softlayer-go v1.1.7 // indirect
|
||||||
github.com/softlayer/xmlrpc v0.0.0-20200409220501-5f089df7cb7e // indirect
|
github.com/softlayer/xmlrpc v0.0.0-20200409220501-5f089df7cb7e // indirect
|
||||||
github.com/sony/gobreaker v0.5.0 // indirect
|
github.com/sony/gobreaker v1.0.0 // indirect
|
||||||
github.com/sourcegraph/conc v0.3.0 // indirect
|
github.com/sourcegraph/conc v0.3.0 // indirect
|
||||||
github.com/spf13/afero v1.11.0 // indirect
|
github.com/spf13/afero v1.11.0 // indirect
|
||||||
github.com/spf13/cast v1.6.0 // indirect
|
github.com/spf13/cast v1.6.0 // indirect
|
||||||
github.com/spf13/pflag v1.0.5 // indirect
|
github.com/spf13/pflag v1.0.6 // indirect
|
||||||
github.com/stretchr/objx v0.5.2 // indirect
|
github.com/stretchr/objx v0.5.2 // indirect
|
||||||
github.com/stretchr/testify v1.10.0 // indirect
|
github.com/stretchr/testify v1.11.1 // indirect
|
||||||
github.com/subosito/gotenv v1.6.0 // indirect
|
github.com/subosito/gotenv v1.6.0 // indirect
|
||||||
github.com/tailscale/certstore v0.1.1-0.20231202035212-d3fa0460f47e // indirect
|
github.com/tailscale/certstore v0.1.1-0.20231202035212-d3fa0460f47e // indirect
|
||||||
github.com/tailscale/go-winio v0.0.0-20231025203758-c4f33415bf55 // indirect
|
github.com/tailscale/go-winio v0.0.0-20231025203758-c4f33415bf55 // indirect
|
||||||
@@ -267,67 +271,67 @@ require (
|
|||||||
github.com/tailscale/goupnp v1.0.1-0.20210804011211-c64d0f06ea05 // indirect
|
github.com/tailscale/goupnp v1.0.1-0.20210804011211-c64d0f06ea05 // indirect
|
||||||
github.com/tailscale/hujson v0.0.0-20221223112325-20486734a56a // indirect
|
github.com/tailscale/hujson v0.0.0-20221223112325-20486734a56a // indirect
|
||||||
github.com/tailscale/netlink v1.1.1-0.20240822203006-4d49adab4de7 // indirect
|
github.com/tailscale/netlink v1.1.1-0.20240822203006-4d49adab4de7 // indirect
|
||||||
github.com/tailscale/peercred v0.0.0-20240214030740-b535050b2aa4 // indirect
|
github.com/tailscale/peercred v0.0.0-20250107143737-35a0c7bd7edc // indirect
|
||||||
github.com/tailscale/web-client-prebuilt v0.0.0-20240226180453-5db17b287bf1 // indirect
|
github.com/tailscale/web-client-prebuilt v0.0.0-20250124233751-d4cd19a26976 // indirect
|
||||||
github.com/tcnksm/go-httpstat v0.2.0 // indirect
|
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1210 // indirect
|
||||||
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1065 // indirect
|
|
||||||
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dnspod v1.0.1065 // indirect
|
|
||||||
github.com/tjfoc/gmsm v1.4.1 // indirect
|
github.com/tjfoc/gmsm v1.4.1 // indirect
|
||||||
github.com/transip/gotransip/v6 v6.26.0 // indirect
|
github.com/transip/gotransip/v6 v6.26.0 // indirect
|
||||||
github.com/txthinking/runnergroup v0.0.0-20210608031112-152c7c4432bf // indirect
|
github.com/txthinking/runnergroup v0.0.0-20210608031112-152c7c4432bf // indirect
|
||||||
github.com/txthinking/socks5 v0.0.0-20230325130024-4230056ae301 // indirect
|
github.com/txthinking/socks5 v0.0.0-20230325130024-4230056ae301 // indirect
|
||||||
github.com/u-root/uio v0.0.0-20240118234441-a3c409a6018e // indirect
|
github.com/u-root/uio v0.0.0-20240224005618-d2acac8f3701 // indirect
|
||||||
github.com/ultradns/ultradns-go-sdk v1.8.0-20241010134910-243eeec // indirect
|
github.com/ultradns/ultradns-go-sdk v1.8.0-20241010134910-243eeec // indirect
|
||||||
github.com/v2fly/ss-bloomring v0.0.0-20210312155135-28617310f63e // indirect
|
github.com/v2fly/ss-bloomring v0.0.0-20210312155135-28617310f63e // indirect
|
||||||
github.com/vinyldns/go-vinyldns v0.9.16 // indirect
|
github.com/vinyldns/go-vinyldns v0.9.16 // indirect
|
||||||
github.com/vishvananda/netlink v1.3.0 // indirect
|
github.com/vishvananda/netlink v1.3.1 // indirect
|
||||||
github.com/vishvananda/netns v0.0.4 // indirect
|
github.com/vishvananda/netns v0.0.5 // indirect
|
||||||
github.com/volcengine/volc-sdk-golang v1.0.189 // indirect
|
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
|
||||||
github.com/vultr/govultr/v3 v3.9.1 // indirect
|
github.com/volcengine/volc-sdk-golang v1.0.216 // indirect
|
||||||
github.com/wyx2685/sing-vmess v0.0.0-20250208043059-9bd6d628dc1c // indirect
|
github.com/vultr/govultr/v3 v3.21.1 // indirect
|
||||||
|
github.com/wyx2685/sing-vmess v0.0.0-20250723121437-95d5ab59ff92 // indirect
|
||||||
github.com/x448/float16 v0.8.4 // indirect
|
github.com/x448/float16 v0.8.4 // indirect
|
||||||
github.com/xtls/reality v0.0.0-20240909153216-e26ae2305463 // indirect
|
github.com/xtls/reality v0.0.0-20250904214705-431b6ff8c67c // indirect
|
||||||
github.com/yandex-cloud/go-genproto v0.0.0-20241220122821-aeb3b05efd1c // indirect
|
github.com/yandex-cloud/go-genproto v0.14.0 // indirect
|
||||||
github.com/yandex-cloud/go-sdk v0.0.0-20241220131134-2393e243c134 // indirect
|
github.com/yandex-cloud/go-sdk/services/dns v0.0.3 // indirect
|
||||||
|
github.com/yandex-cloud/go-sdk/v2 v2.0.8 // indirect
|
||||||
|
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect
|
||||||
github.com/zeebo/blake3 v0.2.4 // indirect
|
github.com/zeebo/blake3 v0.2.4 // indirect
|
||||||
go.mongodb.org/mongo-driver v1.12.0 // indirect
|
go.mongodb.org/mongo-driver v1.13.1 // indirect
|
||||||
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
|
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
|
||||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 // indirect
|
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.61.0 // indirect
|
||||||
go.opentelemetry.io/otel v1.34.0 // indirect
|
go.opentelemetry.io/otel v1.37.0 // indirect
|
||||||
go.opentelemetry.io/otel/metric v1.34.0 // indirect
|
go.opentelemetry.io/otel/metric v1.37.0 // indirect
|
||||||
go.opentelemetry.io/otel/trace v1.34.0 // indirect
|
go.opentelemetry.io/otel/trace v1.37.0 // indirect
|
||||||
go.uber.org/atomic v1.10.0 // indirect
|
go.uber.org/atomic v1.10.0 // indirect
|
||||||
go.uber.org/mock v0.5.0 // indirect
|
go.uber.org/mock v0.5.0 // indirect
|
||||||
go.uber.org/multierr v1.11.0 // indirect
|
go.uber.org/multierr v1.11.0 // indirect
|
||||||
go.uber.org/ratelimit v0.3.0 // indirect
|
go.uber.org/ratelimit v0.3.1 // indirect
|
||||||
go.uber.org/zap/exp v0.3.0 // indirect
|
go.uber.org/zap/exp v0.3.0 // indirect
|
||||||
go4.org/mem v0.0.0-20220726221520-4f986261bf13 // indirect
|
go4.org/mem v0.0.0-20240501181205-ae6ca9944745 // indirect
|
||||||
go4.org/netipx v0.0.0-20231129151722-fdeea329fbba // indirect
|
go4.org/netipx v0.0.0-20231129151722-fdeea329fbba // indirect
|
||||||
golang.org/x/exp v0.0.0-20241210194714-1829a127f884 // indirect
|
golang.org/x/exp v0.0.0-20250506013437-ce4c2cf36ca6 // indirect
|
||||||
golang.org/x/mod v0.23.0 // indirect
|
golang.org/x/mod v0.27.0 // indirect
|
||||||
golang.org/x/net v0.38.0 // indirect
|
golang.org/x/net v0.44.0 // indirect
|
||||||
golang.org/x/oauth2 v0.25.0 // indirect
|
golang.org/x/oauth2 v0.30.0 // indirect
|
||||||
golang.org/x/sync v0.12.0 // indirect
|
golang.org/x/sync v0.17.0 // indirect
|
||||||
golang.org/x/term v0.30.0 // indirect
|
golang.org/x/term v0.35.0 // indirect
|
||||||
golang.org/x/text v0.23.0 // indirect
|
golang.org/x/text v0.29.0 // indirect
|
||||||
golang.org/x/time v0.8.0 // indirect
|
golang.org/x/time v0.12.0 // indirect
|
||||||
golang.org/x/tools v0.30.0 // indirect
|
golang.org/x/tools v0.36.0 // indirect
|
||||||
golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2 // indirect
|
golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2 // indirect
|
||||||
golang.zx2c4.com/wireguard v0.0.0-20231211153847-12269c276173 // indirect
|
golang.zx2c4.com/wireguard v0.0.0-20231211153847-12269c276173 // indirect
|
||||||
golang.zx2c4.com/wireguard/windows v0.5.3 // indirect
|
golang.zx2c4.com/wireguard/windows v0.5.3 // indirect
|
||||||
google.golang.org/api v0.214.0 // indirect
|
google.golang.org/api v0.242.0 // indirect
|
||||||
google.golang.org/genproto v0.0.0-20241021214115-324edc3d5d38 // indirect
|
google.golang.org/genproto/googleapis/api v0.0.0-20250707201910-8d1bb00bc6a7 // indirect
|
||||||
google.golang.org/genproto/googleapis/api v0.0.0-20250106144421-5f5ef82da422 // indirect
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20250707201910-8d1bb00bc6a7 // indirect
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250115164207-1a7da9e5054f // indirect
|
google.golang.org/grpc v1.75.1 // indirect
|
||||||
google.golang.org/grpc v1.71.0 // indirect
|
|
||||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||||
gopkg.in/ns1/ns1-go.v2 v2.13.0 // indirect
|
gopkg.in/ns1/ns1-go.v2 v2.14.4 // indirect
|
||||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
gvisor.dev/gvisor v0.0.0-20240320123526-dc6abceb7ff0 // indirect
|
gvisor.dev/gvisor v0.0.0-20250428193742-2d800c3129d5 // indirect
|
||||||
lukechampine.com/blake3 v1.4.0 // indirect
|
lukechampine.com/blake3 v1.4.1 // indirect
|
||||||
)
|
)
|
||||||
|
|
||||||
//replace github.com/sagernet/sing-box v1.12.0 => ./sing-box_mod
|
replace github.com/sagernet/sing-box v1.13.0 => github.com/wyx2685/sing-box_mod v1.13.0-alpha.5
|
||||||
|
|
||||||
replace github.com/sagernet/sing-box v1.12.0 => github.com/wyx2685/sing-box_mod v1.12.0-test.0.20250308224353-2190e88e821f
|
replace github.com/xtls/xray-core v1.250911.1-0.20250911134820-83c5370eec69 => github.com/wyx2685/xray-core v0.0.0-20250912060919-a74bf884128d
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
package limiter
|
|
||||||
|
|
||||||
import log "github.com/sirupsen/logrus"
|
|
||||||
|
|
||||||
func ClearOnlineIP() error {
|
|
||||||
log.WithField("Type", "Limiter").
|
|
||||||
Debug("Clear online ip...")
|
|
||||||
limitLock.RLock()
|
|
||||||
for _, l := range limiter {
|
|
||||||
l.ConnLimiter.ClearOnlineIP()
|
|
||||||
}
|
|
||||||
limitLock.RUnlock()
|
|
||||||
log.WithField("Type", "Limiter").
|
|
||||||
Debug("Clear online ip done")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
165
limiter/conn.go
165
limiter/conn.go
@@ -1,165 +0,0 @@
|
|||||||
package limiter
|
|
||||||
|
|
||||||
import (
|
|
||||||
"sync"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
type ConnLimiter struct {
|
|
||||||
realtime bool
|
|
||||||
ipLimit int
|
|
||||||
connLimit int
|
|
||||||
count sync.Map // map[string]int
|
|
||||||
ip sync.Map // map[string]map[string]int
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewConnLimiter(conn int, ip int, realtime bool) *ConnLimiter {
|
|
||||||
return &ConnLimiter{
|
|
||||||
realtime: realtime,
|
|
||||||
connLimit: conn,
|
|
||||||
ipLimit: ip,
|
|
||||||
count: sync.Map{},
|
|
||||||
ip: sync.Map{},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *ConnLimiter) AddConnCount(user string, ip string, isTcp bool) (limit bool) {
|
|
||||||
if c.connLimit != 0 {
|
|
||||||
if v, ok := c.count.Load(user); ok {
|
|
||||||
if v.(int) >= c.connLimit {
|
|
||||||
// over connection limit
|
|
||||||
return true
|
|
||||||
} else if isTcp {
|
|
||||||
// tcp protocol
|
|
||||||
// connection count add
|
|
||||||
c.count.Store(user, v.(int)+1)
|
|
||||||
}
|
|
||||||
} else if isTcp {
|
|
||||||
// tcp protocol
|
|
||||||
// store connection count
|
|
||||||
c.count.Store(user, 1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if c.ipLimit == 0 {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
// first user map
|
|
||||||
ipMap := new(sync.Map)
|
|
||||||
if c.realtime {
|
|
||||||
if isTcp {
|
|
||||||
ipMap.Store(ip, 2)
|
|
||||||
} else {
|
|
||||||
ipMap.Store(ip, 1)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ipMap.Store(ip, time.Now())
|
|
||||||
}
|
|
||||||
// check user online ip
|
|
||||||
if v, ok := c.ip.LoadOrStore(user, ipMap); ok {
|
|
||||||
// have user
|
|
||||||
ips := v.(*sync.Map)
|
|
||||||
cn := 0
|
|
||||||
if online, ok := ips.Load(ip); ok {
|
|
||||||
// online ip
|
|
||||||
if c.realtime {
|
|
||||||
if isTcp {
|
|
||||||
// tcp count add
|
|
||||||
ips.Store(ip, online.(int)+2)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// update connect time for not realtime
|
|
||||||
ips.Store(ip, time.Now())
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// not online ip
|
|
||||||
ips.Range(func(_, _ interface{}) bool {
|
|
||||||
cn++
|
|
||||||
if cn >= c.ipLimit {
|
|
||||||
limit = true
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
})
|
|
||||||
if limit {
|
|
||||||
// over ip limit
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if c.realtime {
|
|
||||||
if isTcp {
|
|
||||||
ips.Store(ip, 2)
|
|
||||||
} else {
|
|
||||||
ips.Store(ip, 1)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ips.Store(ip, time.Now())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// DelConnCount Delete tcp connection count, no tcp do not use
|
|
||||||
func (c *ConnLimiter) DelConnCount(user string, ip string) {
|
|
||||||
if !c.realtime {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if c.connLimit != 0 {
|
|
||||||
if v, ok := c.count.Load(user); ok {
|
|
||||||
if v.(int) == 1 {
|
|
||||||
c.count.Delete(user)
|
|
||||||
} else {
|
|
||||||
c.count.Store(user, v.(int)-1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if c.ipLimit == 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if i, ok := c.ip.Load(user); ok {
|
|
||||||
is := i.(*sync.Map)
|
|
||||||
if i, ok := is.Load(ip); ok {
|
|
||||||
if i.(int) == 2 {
|
|
||||||
is.Delete(ip)
|
|
||||||
} else {
|
|
||||||
is.Store(user, i.(int)-2)
|
|
||||||
}
|
|
||||||
notDel := false
|
|
||||||
c.ip.Range(func(_, _ any) bool {
|
|
||||||
notDel = true
|
|
||||||
return false
|
|
||||||
})
|
|
||||||
if !notDel {
|
|
||||||
c.ip.Delete(user)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ClearOnlineIP Clear udp,icmp and other packet protocol online ip
|
|
||||||
func (c *ConnLimiter) ClearOnlineIP() {
|
|
||||||
c.ip.Range(func(u, v any) bool {
|
|
||||||
userIp := v.(*sync.Map)
|
|
||||||
notDel := false
|
|
||||||
userIp.Range(func(ip, v any) bool {
|
|
||||||
notDel = true
|
|
||||||
if _, ok := v.(int); ok {
|
|
||||||
if v.(int) == 1 {
|
|
||||||
// clear packet ip for realtime
|
|
||||||
userIp.Delete(ip)
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
} else {
|
|
||||||
// clear ip for not realtime
|
|
||||||
if v.(time.Time).Before(time.Now().Add(time.Minute)) {
|
|
||||||
// 1 minute no active
|
|
||||||
userIp.Delete(ip)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
})
|
|
||||||
if !notDel {
|
|
||||||
c.ip.Delete(u)
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
package limiter
|
|
||||||
|
|
||||||
import (
|
|
||||||
"sync"
|
|
||||||
"testing"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
var c *ConnLimiter
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
c = NewConnLimiter(1, 1, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestConnLimiter_AddConnCount(t *testing.T) {
|
|
||||||
t.Log(c.AddConnCount("1", "1", true))
|
|
||||||
t.Log(c.AddConnCount("1", "2", true))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestConnLimiter_DelConnCount(t *testing.T) {
|
|
||||||
t.Log(c.AddConnCount("1", "1", true))
|
|
||||||
t.Log(c.AddConnCount("1", "2", true))
|
|
||||||
c.DelConnCount("1", "1")
|
|
||||||
t.Log(c.AddConnCount("1", "2", true))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestConnLimiter_ClearOnlineIP(t *testing.T) {
|
|
||||||
t.Log(c.AddConnCount("1", "1", false))
|
|
||||||
t.Log(c.AddConnCount("1", "2", false))
|
|
||||||
c.ClearOnlineIP()
|
|
||||||
t.Log(c.AddConnCount("1", "2", true))
|
|
||||||
c.DelConnCount("1", "2")
|
|
||||||
t.Log(c.AddConnCount("1", "1", false))
|
|
||||||
// not realtime
|
|
||||||
c.realtime = false
|
|
||||||
t.Log(c.AddConnCount("3", "2", true))
|
|
||||||
c.ClearOnlineIP()
|
|
||||||
t.Log(c.ip.Load("3"))
|
|
||||||
time.Sleep(time.Minute)
|
|
||||||
c.ClearOnlineIP()
|
|
||||||
t.Log(c.ip.Load("3"))
|
|
||||||
}
|
|
||||||
|
|
||||||
func BenchmarkConnLimiter(b *testing.B) {
|
|
||||||
wg := sync.WaitGroup{}
|
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
wg.Add(1)
|
|
||||||
go func() {
|
|
||||||
c.AddConnCount("1", "2", true)
|
|
||||||
c.DelConnCount("1", "2")
|
|
||||||
wg.Done()
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
wg.Wait()
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -11,8 +11,6 @@ import (
|
|||||||
"github.com/InazumaV/V2bX/common/format"
|
"github.com/InazumaV/V2bX/common/format"
|
||||||
"github.com/InazumaV/V2bX/conf"
|
"github.com/InazumaV/V2bX/conf"
|
||||||
"github.com/juju/ratelimit"
|
"github.com/juju/ratelimit"
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
"github.com/xtls/xray-core/common/task"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var limitLock sync.RWMutex
|
var limitLock sync.RWMutex
|
||||||
@@ -20,28 +18,17 @@ var limiter map[string]*Limiter
|
|||||||
|
|
||||||
func Init() {
|
func Init() {
|
||||||
limiter = map[string]*Limiter{}
|
limiter = map[string]*Limiter{}
|
||||||
c := task.Periodic{
|
|
||||||
Interval: time.Minute * 3,
|
|
||||||
Execute: ClearOnlineIP,
|
|
||||||
}
|
|
||||||
go func() {
|
|
||||||
log.WithField("Type", "Limiter").
|
|
||||||
Debug("ClearOnlineIP started")
|
|
||||||
time.Sleep(time.Minute * 3)
|
|
||||||
_ = c.Start()
|
|
||||||
}()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Limiter struct {
|
type Limiter struct {
|
||||||
DomainRules []*regexp.Regexp
|
DomainRules []*regexp.Regexp
|
||||||
ProtocolRules []string
|
ProtocolRules []string
|
||||||
SpeedLimit int
|
SpeedLimit int
|
||||||
UserOnlineIP *sync.Map // Key: Name, value: {Key: Ip, value: Uid}
|
UserOnlineIP *sync.Map // Key: TagUUID, value: {Key: Ip, value: Uid}
|
||||||
OldUserOnline *sync.Map // Key: Ip, value: Uid
|
OldUserOnline *sync.Map // Key: Ip, value: Uid
|
||||||
UUIDtoUID map[string]int // Key: UUID, value: Uid
|
UUIDtoUID map[string]int // Key: UUID, value: Uid
|
||||||
UserLimitInfo *sync.Map // Key: Uid value: UserLimitInfo
|
UserLimitInfo *sync.Map // Key: TagUUID value: UserLimitInfo
|
||||||
ConnLimiter *ConnLimiter // Key: Uid value: ConnLimiter
|
SpeedLimiter *sync.Map // key: TagUUID, value: *ratelimit.Bucket
|
||||||
SpeedLimiter *sync.Map // key: Uid, value: *ratelimit.Bucket
|
|
||||||
AliveList map[int]int // Key: Uid, value: alive_ip
|
AliveList map[int]int // Key: Uid, value: alive_ip
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,7 +46,6 @@ func AddLimiter(tag string, l *conf.LimitConfig, users []panel.UserInfo, aliveLi
|
|||||||
SpeedLimit: l.SpeedLimit,
|
SpeedLimit: l.SpeedLimit,
|
||||||
UserOnlineIP: new(sync.Map),
|
UserOnlineIP: new(sync.Map),
|
||||||
UserLimitInfo: new(sync.Map),
|
UserLimitInfo: new(sync.Map),
|
||||||
ConnLimiter: NewConnLimiter(l.ConnLimit, l.IPLimit, l.EnableRealtime),
|
|
||||||
SpeedLimiter: new(sync.Map),
|
SpeedLimiter: new(sync.Map),
|
||||||
AliveList: aliveList,
|
AliveList: aliveList,
|
||||||
OldUserOnline: new(sync.Map),
|
OldUserOnline: new(sync.Map),
|
||||||
@@ -105,6 +91,7 @@ func (l *Limiter) UpdateUser(tag string, added []panel.UserInfo, deleted []panel
|
|||||||
for i := range deleted {
|
for i := range deleted {
|
||||||
l.UserLimitInfo.Delete(format.UserTag(tag, deleted[i].Uuid))
|
l.UserLimitInfo.Delete(format.UserTag(tag, deleted[i].Uuid))
|
||||||
l.UserOnlineIP.Delete(format.UserTag(tag, deleted[i].Uuid))
|
l.UserOnlineIP.Delete(format.UserTag(tag, deleted[i].Uuid))
|
||||||
|
l.SpeedLimiter.Delete(format.UserTag(tag, deleted[i].Uuid))
|
||||||
delete(l.UUIDtoUID, deleted[i].Uuid)
|
delete(l.UUIDtoUID, deleted[i].Uuid)
|
||||||
delete(l.AliveList, deleted[i].Id)
|
delete(l.AliveList, deleted[i].Id)
|
||||||
}
|
}
|
||||||
@@ -140,10 +127,6 @@ func (l *Limiter) CheckLimit(taguuid string, ip string, isTcp bool, noSSUDP bool
|
|||||||
// check if ipv4 mapped ipv6
|
// check if ipv4 mapped ipv6
|
||||||
ip = strings.TrimPrefix(ip, "::ffff:")
|
ip = strings.TrimPrefix(ip, "::ffff:")
|
||||||
|
|
||||||
// ip and conn limiter
|
|
||||||
if l.ConnLimiter.AddConnCount(taguuid, ip, isTcp) {
|
|
||||||
return nil, true
|
|
||||||
}
|
|
||||||
// check and gen speed limit Bucket
|
// check and gen speed limit Bucket
|
||||||
nodeLimit := l.SpeedLimit
|
nodeLimit := l.SpeedLimit
|
||||||
userLimit := 0
|
userLimit := 0
|
||||||
@@ -169,17 +152,21 @@ func (l *Limiter) CheckLimit(taguuid string, ip string, isTcp bool, noSSUDP bool
|
|||||||
}
|
}
|
||||||
if noSSUDP {
|
if noSSUDP {
|
||||||
// Store online user for device limit
|
// Store online user for device limit
|
||||||
ipMap := new(sync.Map)
|
newipMap := new(sync.Map)
|
||||||
ipMap.Store(ip, uid)
|
newipMap.Store(ip, uid)
|
||||||
aliveIp := l.AliveList[uid]
|
aliveIp := l.AliveList[uid]
|
||||||
// If any device is online
|
// If any device is online
|
||||||
if v, ok := l.UserOnlineIP.LoadOrStore(taguuid, ipMap); ok {
|
if v, loaded := l.UserOnlineIP.LoadOrStore(taguuid, newipMap); loaded {
|
||||||
ipMap := v.(*sync.Map)
|
oldipMap := v.(*sync.Map)
|
||||||
// If this is a new ip
|
// If this is a new ip
|
||||||
if _, ok := ipMap.LoadOrStore(ip, uid); !ok {
|
if _, loaded := oldipMap.LoadOrStore(ip, uid); !loaded {
|
||||||
if deviceLimit > 0 {
|
if v, loaded := l.OldUserOnline.Load(ip); loaded {
|
||||||
|
if v.(int) == uid {
|
||||||
|
l.OldUserOnline.Delete(ip)
|
||||||
|
}
|
||||||
|
} else if deviceLimit > 0 {
|
||||||
if deviceLimit <= aliveIp {
|
if deviceLimit <= aliveIp {
|
||||||
ipMap.Delete(ip)
|
oldipMap.Delete(ip)
|
||||||
return nil, true
|
return nil, true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -214,6 +201,7 @@ func (l *Limiter) CheckLimit(taguuid string, ip string, isTcp bool, noSSUDP bool
|
|||||||
|
|
||||||
func (l *Limiter) GetOnlineDevice() (*[]panel.OnlineUser, error) {
|
func (l *Limiter) GetOnlineDevice() (*[]panel.OnlineUser, error) {
|
||||||
var onlineUser []panel.OnlineUser
|
var onlineUser []panel.OnlineUser
|
||||||
|
l.OldUserOnline = new(sync.Map)
|
||||||
l.UserOnlineIP.Range(func(key, value interface{}) bool {
|
l.UserOnlineIP.Range(func(key, value interface{}) bool {
|
||||||
taguuid := key.(string)
|
taguuid := key.(string)
|
||||||
ipMap := value.(*sync.Map)
|
ipMap := value.(*sync.Map)
|
||||||
|
|||||||
@@ -13,11 +13,12 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/go-acme/lego/v4/certificate"
|
"github.com/go-acme/lego/v4/certificate"
|
||||||
"github.com/go-acme/lego/v4/challenge/http01"
|
"github.com/go-acme/lego/v4/challenge/http01"
|
||||||
"github.com/go-acme/lego/v4/providers/dns"
|
"github.com/go-acme/lego/v4/providers/dns"
|
||||||
"github.com/go-acme/lego/v4/registration"
|
"github.com/go-acme/lego/v4/registration"
|
||||||
"github.com/goccy/go-json"
|
|
||||||
|
|
||||||
"github.com/InazumaV/V2bX/common/file"
|
"github.com/InazumaV/V2bX/common/file"
|
||||||
"github.com/InazumaV/V2bX/conf"
|
"github.com/InazumaV/V2bX/conf"
|
||||||
|
|||||||
17
node/user.go
17
node/user.go
@@ -8,20 +8,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (c *Controller) reportUserTrafficTask() (err error) {
|
func (c *Controller) reportUserTrafficTask() (err error) {
|
||||||
// Get User traffic
|
userTraffic, _ := c.server.GetUserTrafficSlice(c.tag, true)
|
||||||
userTraffic := make([]panel.UserTraffic, 0)
|
|
||||||
for i := range c.userList {
|
|
||||||
up, down := c.server.GetUserTraffic(c.tag, c.userList[i].Uuid, true)
|
|
||||||
if up > 0 || down > 0 {
|
|
||||||
if c.LimitConfig.EnableDynamicSpeedLimit {
|
|
||||||
c.traffic[c.userList[i].Uuid] += up + down
|
|
||||||
}
|
|
||||||
userTraffic = append(userTraffic, panel.UserTraffic{
|
|
||||||
UID: (c.userList)[i].Id,
|
|
||||||
Upload: up,
|
|
||||||
Download: down})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if len(userTraffic) > 0 {
|
if len(userTraffic) > 0 {
|
||||||
err = c.apiClient.ReportUserTraffic(userTraffic)
|
err = c.apiClient.ReportUserTraffic(userTraffic)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -31,6 +18,7 @@ func (c *Controller) reportUserTrafficTask() (err error) {
|
|||||||
}).Info("Report user traffic failed")
|
}).Info("Report user traffic failed")
|
||||||
} else {
|
} else {
|
||||||
log.WithField("tag", c.tag).Infof("Report %d users traffic", len(userTraffic))
|
log.WithField("tag", c.tag).Infof("Report %d users traffic", len(userTraffic))
|
||||||
|
log.WithField("tag", c.tag).Debugf("User traffic: %+v", userTraffic)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,6 +51,7 @@ func (c *Controller) reportUserTrafficTask() (err error) {
|
|||||||
}).Info("Report online users failed")
|
}).Info("Report online users failed")
|
||||||
} else {
|
} else {
|
||||||
log.WithField("tag", c.tag).Infof("Total %d online users, %d Reported", len(*onlineDevice), len(result))
|
log.WithField("tag", c.tag).Infof("Total %d online users, %d Reported", len(*onlineDevice), len(result))
|
||||||
|
log.WithField("tag", c.tag).Debugf("Online users: %+v", data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user