diff --git a/internal/db/models/ns_node_dao_test.go b/internal/db/models/ns_node_dao_test.go new file mode 100644 index 00000000..6595eab6 --- /dev/null +++ b/internal/db/models/ns_node_dao_test.go @@ -0,0 +1,6 @@ +package models_test + +import ( + _ "github.com/go-sql-driver/mysql" + _ "github.com/iwind/TeaGo/bootstrap" +) diff --git a/internal/db/models/ns_node_model.go b/internal/db/models/ns_node_model.go index e5fa00e9..de922113 100644 --- a/internal/db/models/ns_node_model.go +++ b/internal/db/models/ns_node_model.go @@ -22,6 +22,7 @@ type NSNode struct { InactiveNotifiedAt uint64 `field:"inactiveNotifiedAt"` // 离线通知时间 ConnectedAPINodes dbs.JSON `field:"connectedAPINodes"` // 当前连接的API节点 DdosProtection dbs.JSON `field:"ddosProtection"` // DDoS防护设置 + ApiNodeAddrs dbs.JSON `field:"apiNodeAddrs"` // API节点地址 } type NSNodeOperator struct { @@ -43,6 +44,7 @@ type NSNodeOperator struct { InactiveNotifiedAt any // 离线通知时间 ConnectedAPINodes any // 当前连接的API节点 DdosProtection any // DDoS防护设置 + ApiNodeAddrs any // API节点地址 } func NewNSNodeOperator() *NSNodeOperator { diff --git a/internal/db/models/ns_node_model_ext.go b/internal/db/models/ns_node_model_ext.go index b8b95944..2640e7f9 100644 --- a/internal/db/models/ns_node_model_ext.go +++ b/internal/db/models/ns_node_model_ext.go @@ -1,79 +1 @@ package models - -import ( - "encoding/json" - "github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs" - "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/ddosconfigs" - "time" -) - -// DecodeInstallStatus 安装状态 -func (this *NSNode) DecodeInstallStatus() (*NodeInstallStatus, error) { - if len(this.InstallStatus) == 0 { - return NewNodeInstallStatus(), nil - } - status := &NodeInstallStatus{} - err := json.Unmarshal(this.InstallStatus, status) - if err != nil { - return NewNodeInstallStatus(), err - } - - // 如果N秒钟没有更新状态,则认为不在运行 - if status.IsRunning && status.UpdatedAt < time.Now().Unix()-10 { - status.IsRunning = false - status.IsFinished = true - status.Error = "timeout" - } - - return status, nil -} - -// DecodeStatus 节点状态 -func (this *NSNode) DecodeStatus() (*nodeconfigs.NodeStatus, error) { - if len(this.Status) == 0 { - return nil, nil - } - status := &nodeconfigs.NodeStatus{} - err := json.Unmarshal(this.Status, status) - if err != nil { - return nil, err - } - return status, nil -} - -// DecodeDDoSProtection 解析DDoS Protection设置 -func (this *NSNode) DecodeDDoSProtection() *ddosconfigs.ProtectionConfig { - if IsNull(this.DdosProtection) { - return nil - } - - var result = &ddosconfigs.ProtectionConfig{} - err := json.Unmarshal(this.DdosProtection, &result) - if err != nil { - // ignore err - } - return result -} - -// HasDDoSProtection 检查是否有DDOS设置 -func (this *NSNode) HasDDoSProtection() bool { - var config = this.DecodeDDoSProtection() - if config != nil { - return !config.IsPriorEmpty() - } - return false -} - -// DecodeConnectedAPINodes 解析连接的API节点列表 -func (this *NSNode) DecodeConnectedAPINodes() []int64 { - if IsNull(this.ConnectedAPINodes) { - return nil - } - - var result = []int64{} - err := json.Unmarshal(this.ConnectedAPINodes, &result) - if err != nil { - // ignore err - } - return result -} diff --git a/internal/rpc/services/service_node.go b/internal/rpc/services/service_node.go index bce64057..61f675dc 100644 --- a/internal/rpc/services/service_node.go +++ b/internal/rpc/services/service_node.go @@ -546,7 +546,7 @@ func (this *NodeService) FindEnabledNode(ctx context.Context, req *pb.FindEnable if err != nil { return nil, err } - installStatusResult := &pb.NodeInstallStatus{} + var installStatusResult = &pb.NodeInstallStatus{} if installStatus != nil { installStatusResult = &pb.NodeInstallStatus{ IsRunning: installStatus.IsRunning, @@ -678,6 +678,7 @@ func (this *NodeService) FindEnabledNode(ctx context.Context, req *pb.FindEnable LnAddrs: node.DecodeLnAddrs(), DnsRoutes: pbRoutes, EnableIPLists: node.EnableIPLists, + ApiNodeAddrsJSON: node.ApiNodeAddrs, }}, nil }