优化修复
This commit is contained in:
@@ -176,8 +176,13 @@ type Stats struct {
|
||||
func NewServer(config *config.DNSConfig, shieldConfig *config.ShieldConfig, shieldManager *shield.ShieldManager, gfwConfig *config.GFWListConfig, gfwManager *gfw.GFWListManager) *Server {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
||||
// 从配置中读取DNS缓存TTL值(分钟)
|
||||
cacheTTL := time.Duration(config.CacheTTL) * time.Minute
|
||||
// 从配置中读取DNS缓存TTL值(秒)
|
||||
cacheTTL := time.Duration(config.CacheTTL) * time.Second
|
||||
// 保存间隔(秒)
|
||||
saveInterval := time.Duration(config.SaveInterval) * time.Second
|
||||
// 最大和最小缓存TTL(秒)
|
||||
maxCacheTTL := time.Duration(config.MaxCacheTTL) * time.Second
|
||||
minCacheTTL := time.Duration(config.MinCacheTTL) * time.Second
|
||||
|
||||
server := &Server{
|
||||
config: config,
|
||||
@@ -220,7 +225,7 @@ func NewServer(config *config.DNSConfig, shieldConfig *config.ShieldConfig, shie
|
||||
stopped: false, // 初始化为未停止状态
|
||||
|
||||
// DNS查询缓存初始化
|
||||
DnsCache: NewDNSCache(cacheTTL),
|
||||
DnsCache: NewDNSCache(cacheTTL, config.CacheMode, config.CacheSize, config.CacheFilePath, saveInterval, maxCacheTTL, minCacheTTL),
|
||||
// 初始化域名DNSSEC状态映射表
|
||||
domainDNSSECStatus: make(map[string]bool),
|
||||
// 初始化服务器状态跟踪
|
||||
@@ -2645,10 +2650,16 @@ func (s *Server) GetTopBlockedDomains(limit int) []BlockedDomain {
|
||||
s.blockedDomainsMutex.RLock()
|
||||
defer s.blockedDomainsMutex.RUnlock()
|
||||
|
||||
// 转换为切片
|
||||
// 计算30天前的时间戳
|
||||
thirtyDaysAgo := time.Now().Add(-30 * 24 * time.Hour).Unix()
|
||||
|
||||
// 转换为切片并过滤最近30天的数据
|
||||
domains := make([]BlockedDomain, 0, len(s.blockedDomains))
|
||||
for _, entry := range s.blockedDomains {
|
||||
domains = append(domains, *entry)
|
||||
// 只包含最近30天的数据
|
||||
if entry.LastSeen >= thirtyDaysAgo {
|
||||
domains = append(domains, *entry)
|
||||
}
|
||||
}
|
||||
|
||||
// 按计数排序
|
||||
@@ -2668,10 +2679,16 @@ func (s *Server) GetTopResolvedDomains(limit int) []BlockedDomain {
|
||||
s.resolvedDomainsMutex.RLock()
|
||||
defer s.resolvedDomainsMutex.RUnlock()
|
||||
|
||||
// 转换为切片
|
||||
// 计算30天前的时间戳
|
||||
thirtyDaysAgo := time.Now().Add(-30 * 24 * time.Hour).Unix()
|
||||
|
||||
// 转换为切片并过滤最近30天的数据
|
||||
domains := make([]BlockedDomain, 0, len(s.resolvedDomains))
|
||||
for _, entry := range s.resolvedDomains {
|
||||
domains = append(domains, *entry)
|
||||
// 只包含最近30天的数据
|
||||
if entry.LastSeen >= thirtyDaysAgo {
|
||||
domains = append(domains, *entry)
|
||||
}
|
||||
}
|
||||
|
||||
// 按数量排序
|
||||
|
||||
Reference in New Issue
Block a user