MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / Init

Method Init

internal/iplibrary/manager_ip_list.go:115–166  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

113}
114
115func (this *IPListManager) Init() {
116 // 从数据库中当中读取数据
117 // 检查sqlite文件是否存在,以便决定使用sqlite还是kv
118 var sqlitePath = Tea.Root + "/data/ip_list.db"
119 _, sqliteErr := os.Stat(sqlitePath)
120
121 var db IPListDB
122 var err error
123 if sqliteErr == nil || !teaconst.EnableKVCacheStore {
124 db, err = NewSQLiteIPList()
125 } else {
126 db, err = NewKVIPList()
127 }
128
129 if err != nil {
130 remotelogs.Error("IP_LIST_MANAGER", "create ip list local database failed: "+err.Error())
131 } else {
132 this.db = db
133
134 // 删除本地数据库中过期的条目
135 _ = db.DeleteExpiredItems()
136
137 // 本地数据库中最大版本号
138 this.lastVersion, err = db.ReadMaxVersion()
139 if err != nil {
140 remotelogs.Error("IP_LIST_MANAGER", "find max version failed: "+err.Error())
141 this.lastVersion = 0
142 }
143 remotelogs.Println("IP_LIST_MANAGER", "starting from '"+db.Name()+"' version '"+types.String(this.lastVersion)+"' ...")
144
145 // 从本地数据库中加载
146 var offset int64 = 0
147 var size int64 = 2_000
148
149 var tr = trackers.Begin("IP_LIST_MANAGER:load")
150 defer tr.End()
151
152 for {
153 items, goNext, readErr := db.ReadItems(offset, size)
154 var l = len(items)
155 if readErr != nil {
156 remotelogs.Error("IP_LIST_MANAGER", "read ip list from local database failed: "+readErr.Error())
157 } else {
158 this.processItems(items, false)
159 if !goNext {
160 break
161 }
162 }
163 offset += int64(l)
164 }
165 }
166}
167
168func (this *IPListManager) Loop() error {
169 // 是否同步IP名单

Callers 1

StartMethod · 0.95

Calls 14

DeleteExpiredItemsMethod · 0.95
ReadMaxVersionMethod · 0.95
NameMethod · 0.95
ReadItemsMethod · 0.95
processItemsMethod · 0.95
ErrorFunction · 0.92
PrintlnFunction · 0.92
BeginFunction · 0.92
NewSQLiteIPListFunction · 0.85
NewKVIPListFunction · 0.85
StatMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected