mirror of
				https://github.com/TeaOSLab/EdgeAPI.git
				synced 2025-11-04 16:00:24 +08:00 
			
		
		
		
	Ln节点可以指定访问IP
This commit is contained in:
		@@ -199,7 +199,7 @@ func (this *NodeDAO) CreateNode(tx *dbs.Tx, adminId int64, name string, clusterI
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// UpdateNode 修改节点
 | 
			
		||||
func (this *NodeDAO) UpdateNode(tx *dbs.Tx, nodeId int64, name string, clusterId int64, secondaryClusterIds []int64, groupId int64, regionId int64, isOn bool, level int) error {
 | 
			
		||||
func (this *NodeDAO) UpdateNode(tx *dbs.Tx, nodeId int64, name string, clusterId int64, secondaryClusterIds []int64, groupId int64, regionId int64, isOn bool, level int, lnAddrs []string) error {
 | 
			
		||||
	if nodeId <= 0 {
 | 
			
		||||
		return errors.New("invalid nodeId")
 | 
			
		||||
	}
 | 
			
		||||
@@ -248,6 +248,15 @@ func (this *NodeDAO) UpdateNode(tx *dbs.Tx, nodeId int64, name string, clusterId
 | 
			
		||||
 | 
			
		||||
	if teaconst.IsPlus {
 | 
			
		||||
		op.Level = level
 | 
			
		||||
 | 
			
		||||
		if lnAddrs == nil {
 | 
			
		||||
			lnAddrs = []string{}
 | 
			
		||||
		}
 | 
			
		||||
		lnAddrsJSON, err := json.Marshal(lnAddrs)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
		op.LnAddrs = lnAddrsJSON
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	err = this.Save(tx, op)
 | 
			
		||||
@@ -605,7 +614,7 @@ func (this *NodeDAO) FindEnabledNodesWithGroupIdAndLevel(tx *dbs.Tx, groupId int
 | 
			
		||||
	}
 | 
			
		||||
	_, err = this.Query(tx).
 | 
			
		||||
		State(NodeStateEnabled).
 | 
			
		||||
		Result("id", "clusterId", "secondaryClusterIds", "uniqueId", "secret").
 | 
			
		||||
		Result("id", "clusterId", "secondaryClusterIds", "uniqueId", "secret", "lnAddrs").
 | 
			
		||||
		Attr("isOn", true).
 | 
			
		||||
		Attr("groupId", groupId).
 | 
			
		||||
		Attr("level", level).
 | 
			
		||||
@@ -1881,14 +1890,18 @@ func (this *NodeDAO) FindParentNodeConfigs(tx *dbs.Tx, nodeId int64, groupId int
 | 
			
		||||
 | 
			
		||||
	if len(parentNodes) > 0 {
 | 
			
		||||
		for _, node := range parentNodes {
 | 
			
		||||
			addrs, err := SharedNodeIPAddressDAO.FindNodeAccessAndUpIPAddresses(tx, int64(node.Id), nodeconfigs.NodeRoleNode)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				return nil, err
 | 
			
		||||
			}
 | 
			
		||||
			var addrStrings = []string{}
 | 
			
		||||
			for _, addr := range addrs {
 | 
			
		||||
				if addr.IsOn {
 | 
			
		||||
					addrStrings = append(addrStrings, addr.DNSIP())
 | 
			
		||||
			// 是否有Ln地址
 | 
			
		||||
			var addrStrings = node.DecodeLnAddrs()
 | 
			
		||||
			if len(addrStrings) == 0 {
 | 
			
		||||
				// 如果没有就取节点的可访问地址
 | 
			
		||||
				addrs, err := SharedNodeIPAddressDAO.FindNodeAccessAndUpIPAddresses(tx, int64(node.Id), nodeconfigs.NodeRoleNode)
 | 
			
		||||
				if err != nil {
 | 
			
		||||
					return nil, err
 | 
			
		||||
				}
 | 
			
		||||
				for _, addr := range addrs {
 | 
			
		||||
					if addr.IsOn {
 | 
			
		||||
						addrStrings = append(addrStrings, addr.DNSIP())
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -8,6 +8,7 @@ type Node struct {
 | 
			
		||||
	AdminId                uint32   `field:"adminId"`                // 管理员ID
 | 
			
		||||
	UserId                 uint32   `field:"userId"`                 // 用户ID
 | 
			
		||||
	Level                  uint8    `field:"level"`                  // 级别
 | 
			
		||||
	LnAddrs                dbs.JSON `field:"lnAddrs"`                // Ln级别访问地址
 | 
			
		||||
	IsOn                   bool     `field:"isOn"`                   // 是否启用
 | 
			
		||||
	IsUp                   bool     `field:"isUp"`                   // 是否在线
 | 
			
		||||
	CountUp                uint32   `field:"countUp"`                // 连续在线次数
 | 
			
		||||
@@ -42,41 +43,42 @@ type Node struct {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type NodeOperator struct {
 | 
			
		||||
	Id                     interface{} // ID
 | 
			
		||||
	AdminId                interface{} // 管理员ID
 | 
			
		||||
	UserId                 interface{} // 用户ID
 | 
			
		||||
	Level                  interface{} // 级别
 | 
			
		||||
	IsOn                   interface{} // 是否启用
 | 
			
		||||
	IsUp                   interface{} // 是否在线
 | 
			
		||||
	CountUp                interface{} // 连续在线次数
 | 
			
		||||
	CountDown              interface{} // 连续下线次数
 | 
			
		||||
	IsActive               interface{} // 是否活跃
 | 
			
		||||
	InactiveNotifiedAt     interface{} // 离线通知时间
 | 
			
		||||
	UniqueId               interface{} // 节点ID
 | 
			
		||||
	Secret                 interface{} // 密钥
 | 
			
		||||
	Name                   interface{} // 节点名
 | 
			
		||||
	Code                   interface{} // 代号
 | 
			
		||||
	ClusterId              interface{} // 主集群ID
 | 
			
		||||
	SecondaryClusterIds    interface{} // 从集群ID
 | 
			
		||||
	RegionId               interface{} // 区域ID
 | 
			
		||||
	GroupId                interface{} // 分组ID
 | 
			
		||||
	CreatedAt              interface{} // 创建时间
 | 
			
		||||
	Status                 interface{} // 最新的状态
 | 
			
		||||
	Version                interface{} // 当前版本号
 | 
			
		||||
	LatestVersion          interface{} // 最后版本号
 | 
			
		||||
	InstallDir             interface{} // 安装目录
 | 
			
		||||
	IsInstalled            interface{} // 是否已安装
 | 
			
		||||
	InstallStatus          interface{} // 安装状态
 | 
			
		||||
	State                  interface{} // 状态
 | 
			
		||||
	ConnectedAPINodes      interface{} // 当前连接的API节点
 | 
			
		||||
	MaxCPU                 interface{} // 可以使用的最多CPU
 | 
			
		||||
	MaxThreads             interface{} // 最大线程数
 | 
			
		||||
	DdosProtection         interface{} // DDOS配置
 | 
			
		||||
	DnsRoutes              interface{} // DNS线路设置
 | 
			
		||||
	MaxCacheDiskCapacity   interface{} // 硬盘缓存容量
 | 
			
		||||
	MaxCacheMemoryCapacity interface{} // 内存缓存容量
 | 
			
		||||
	CacheDiskDir           interface{} // 缓存目录
 | 
			
		||||
	DnsResolver            interface{} // DNS解析器
 | 
			
		||||
	Id                     any // ID
 | 
			
		||||
	AdminId                any // 管理员ID
 | 
			
		||||
	UserId                 any // 用户ID
 | 
			
		||||
	Level                  any // 级别
 | 
			
		||||
	LnAddrs                any // Ln级别访问地址
 | 
			
		||||
	IsOn                   any // 是否启用
 | 
			
		||||
	IsUp                   any // 是否在线
 | 
			
		||||
	CountUp                any // 连续在线次数
 | 
			
		||||
	CountDown              any // 连续下线次数
 | 
			
		||||
	IsActive               any // 是否活跃
 | 
			
		||||
	InactiveNotifiedAt     any // 离线通知时间
 | 
			
		||||
	UniqueId               any // 节点ID
 | 
			
		||||
	Secret                 any // 密钥
 | 
			
		||||
	Name                   any // 节点名
 | 
			
		||||
	Code                   any // 代号
 | 
			
		||||
	ClusterId              any // 主集群ID
 | 
			
		||||
	SecondaryClusterIds    any // 从集群ID
 | 
			
		||||
	RegionId               any // 区域ID
 | 
			
		||||
	GroupId                any // 分组ID
 | 
			
		||||
	CreatedAt              any // 创建时间
 | 
			
		||||
	Status                 any // 最新的状态
 | 
			
		||||
	Version                any // 当前版本号
 | 
			
		||||
	LatestVersion          any // 最后版本号
 | 
			
		||||
	InstallDir             any // 安装目录
 | 
			
		||||
	IsInstalled            any // 是否已安装
 | 
			
		||||
	InstallStatus          any // 安装状态
 | 
			
		||||
	State                  any // 状态
 | 
			
		||||
	ConnectedAPINodes      any // 当前连接的API节点
 | 
			
		||||
	MaxCPU                 any // 可以使用的最多CPU
 | 
			
		||||
	MaxThreads             any // 最大线程数
 | 
			
		||||
	DdosProtection         any // DDOS配置
 | 
			
		||||
	DnsRoutes              any // DNS线路设置
 | 
			
		||||
	MaxCacheDiskCapacity   any // 硬盘缓存容量
 | 
			
		||||
	MaxCacheMemoryCapacity any // 内存缓存容量
 | 
			
		||||
	CacheDiskDir           any // 缓存目录
 | 
			
		||||
	DnsResolver            any // DNS解析器
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func NewNodeOperator() *NodeOperator {
 | 
			
		||||
 
 | 
			
		||||
@@ -168,3 +168,16 @@ func (this *Node) DecodeDNSResolver() *nodeconfigs.DNSResolverConfig {
 | 
			
		||||
	}
 | 
			
		||||
	return resolverConfig
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *Node) DecodeLnAddrs() []string {
 | 
			
		||||
	if IsNull(this.LnAddrs) {
 | 
			
		||||
		return nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var result = []string{}
 | 
			
		||||
	err := json.Unmarshal(this.LnAddrs, &result)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		// ignore error
 | 
			
		||||
	}
 | 
			
		||||
	return result
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -475,7 +475,7 @@ func (this *NodeService) UpdateNode(ctx context.Context, req *pb.UpdateNodeReque
 | 
			
		||||
 | 
			
		||||
	var tx = this.NullTx()
 | 
			
		||||
 | 
			
		||||
	err = models.SharedNodeDAO.UpdateNode(tx, req.NodeId, req.Name, req.NodeClusterId, req.SecondaryNodeClusterIds, req.NodeGroupId, req.NodeRegionId, req.IsOn, int(req.Level))
 | 
			
		||||
	err = models.SharedNodeDAO.UpdateNode(tx, req.NodeId, req.Name, req.NodeClusterId, req.SecondaryNodeClusterIds, req.NodeGroupId, req.NodeRegionId, req.IsOn, int(req.Level), req.LnAddrs)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
@@ -673,6 +673,7 @@ func (this *NodeService) FindEnabledNode(ctx context.Context, req *pb.FindEnable
 | 
			
		||||
		MaxCacheMemoryCapacity: pbMaxCacheMemoryCapacity,
 | 
			
		||||
		CacheDiskDir:           node.CacheDiskDir,
 | 
			
		||||
		Level:                  int32(node.Level),
 | 
			
		||||
		LnAddrs:                node.DecodeLnAddrs(),
 | 
			
		||||
		DnsRoutes:              pbRoutes,
 | 
			
		||||
	}}, nil
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
		Reference in New Issue
	
	Block a user