mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-03 06:40:26 +08:00
源码编译版本增加节点数限制
This commit is contained in:
9
internal/const/const_community.go
Normal file
9
internal/const/const_community.go
Normal file
@@ -0,0 +1,9 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
//go:build !plus
|
||||
|
||||
package teaconst
|
||||
|
||||
const (
|
||||
// DefaultMaxNodes 节点数限制
|
||||
DefaultMaxNodes int32 = 50
|
||||
)
|
||||
@@ -4,7 +4,10 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"errors"
|
||||
teaconst "github.com/TeaOSLab/EdgeAPI/internal/const"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
)
|
||||
|
||||
func (this *NodeDAO) CountAllAuthorityNodes(tx *dbs.Tx) (int64, error) {
|
||||
@@ -15,5 +18,18 @@ func (this *NodeDAO) CountAllAuthorityNodes(tx *dbs.Tx) (int64, error) {
|
||||
}
|
||||
|
||||
func (this *NodeDAO) CheckNodesLimit(tx *dbs.Tx) error {
|
||||
var maxNodes = teaconst.DefaultMaxNodes
|
||||
|
||||
// 检查节点数量
|
||||
if maxNodes > 0 {
|
||||
count, err := this.CountAllAuthorityNodes(tx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if count >= int64(maxNodes) {
|
||||
return errors.New("超出最大节点数限制:" + types.String(maxNodes) + ",当前已用:" + types.String(count) + ",请自行修改源码修改此限制(EdgeAPI/internal/const/const_community.go) 或者 购买商业版本授权。")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user