MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / ApplyConfig

Method ApplyConfig

internal/pluginhost/host.go:182–322  ·  view source on GitHub ↗
(ctx context.Context, cfg *config.Config)

Source from the content-addressed store, hash-verified

180}
181
182func (h *Host) ApplyConfig(ctx context.Context, cfg *config.Config) {
183 if h == nil {
184 return
185 }
186 h.applyMu.Lock()
187 defer h.applyMu.Unlock()
188
189 rc := runtimeConfigFromConfig(cfg)
190 h.mu.Lock()
191 h.runtimeConfig = cfg
192 h.mu.Unlock()
193
194 if !rc.Enabled {
195 h.mu.Lock()
196 h.managementRoutes = make(map[string]managementRouteRecord)
197 h.resourceRoutes = make(map[string]resourceRouteRecord)
198 h.rebuildActivePluginMapsLocked(nil)
199 h.snapshot.Store(emptySnapshot())
200 h.mu.Unlock()
201 h.refreshThinkingProviders(nil)
202 return
203 }
204
205 desiredVersions := desiredPluginVersions(rc.Items)
206 files, errSelect := selectPluginFiles(rc.Dir, desiredVersions)
207 if errSelect != nil {
208 log.Warnf("pluginhost: failed to select plugin files: %v", errSelect)
209 h.mu.Lock()
210 h.managementRoutes = make(map[string]managementRouteRecord)
211 h.resourceRoutes = make(map[string]resourceRouteRecord)
212 h.rebuildActivePluginMapsLocked(nil)
213 h.snapshot.Store(emptySnapshot())
214 h.mu.Unlock()
215 h.refreshThinkingProviders(nil)
216 return
217 }
218 files = h.withLoadedPluginFallbacks(files, rc.Items, desiredVersions)
219
220 records := make([]capabilityRecord, 0, len(files))
221 loadedFiles := make([]pluginFile, 0, len(files))
222 hotReloadLogs := make([]log.Fields, 0)
223 for _, file := range files {
224 item, ok := rc.Items[file.ID]
225 if !ok {
226 item = defaultRuntimeItemConfig(file.ID)
227 }
228 if !item.Enabled {
229 continue
230 }
231 h.mu.Lock()
232 lp := h.loaded[file.ID]
233 var replaced *loadedPlugin
234 if lp != nil && cleanPluginPath(lp.path) != cleanPluginPath(file.Path) {
235 replaced = lp
236 lp = nil
237 }
238 _, disabled := h.fused[file.ID]
239 h.mu.Unlock()

Calls 15

loadMethod · 0.95
callRegisterMethod · 0.95
runtimeConfigFromConfigFunction · 0.85
emptySnapshotFunction · 0.85
desiredPluginVersionsFunction · 0.85
selectPluginFilesFunction · 0.85
defaultRuntimeItemConfigFunction · 0.85