From 2d675f4281f1e5ca6ffc04f43ad4edbe7cdc3c86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Sun, 24 Dec 2023 11:28:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=BA=90=E7=A0=81=E7=BC=96=E8=AF=91=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E5=A2=9E=E5=8A=A0=E8=8A=82=E7=82=B9=E6=95=B0=E9=99=90?= =?UTF-8?q?=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/const/const_community.go | 9 +++++++++ internal/db/models/node_dao_limit.go | 16 ++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 internal/const/const_community.go diff --git a/internal/const/const_community.go b/internal/const/const_community.go new file mode 100644 index 00000000..71b69ecc --- /dev/null +++ b/internal/const/const_community.go @@ -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 +) diff --git a/internal/db/models/node_dao_limit.go b/internal/db/models/node_dao_limit.go index f801bd75..3ba598ab 100644 --- a/internal/db/models/node_dao_limit.go +++ b/internal/db/models/node_dao_limit.go @@ -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 }