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

Method callRegister

internal/pluginhost/host.go:592–624  ·  view source on GitHub ↗
(ctx context.Context, lp *loadedPlugin, item runtimeItemConfig)

Source from the content-addressed store, hash-verified

590}
591
592func (h *Host) callRegister(ctx context.Context, lp *loadedPlugin, item runtimeItemConfig) (pluginapi.Plugin, bool) {
593 if lp == nil {
594 return pluginapi.Plugin{}, false
595 }
596
597 method := pluginabi.MethodPluginRegister
598 h.mu.Lock()
599 registered := lp.registered
600 h.mu.Unlock()
601 if registered {
602 method = pluginabi.MethodPluginReconfigure
603 }
604
605 plugin, okCall := h.safePluginCall(ctx, lp.id, method, func() pluginapi.Plugin {
606 plugin, errRegister := registerRPCPlugin(ctx, h, lp.id, lp.client, method, item.ConfigYAML)
607 if errRegister != nil {
608 log.Warnf("pluginhost: plugin %s %s failed: %v", lp.id, method, errRegister)
609 return pluginapi.Plugin{}
610 }
611 return plugin
612 })
613 if !okCall {
614 return pluginapi.Plugin{}, false
615 }
616 h.mu.Lock()
617 lp.registered = true
618 h.mu.Unlock()
619 if !validPlugin(plugin) {
620 log.Warnf("pluginhost: plugin %s returned invalid metadata or no capabilities", lp.id)
621 return pluginapi.Plugin{}, false
622 }
623 return plugin, true
624}
625
626func (h *Host) safePluginCall(ctx context.Context, id, method string, fn func() pluginapi.Plugin) (out pluginapi.Plugin, ok bool) {
627 defer func() {

Callers 1

ApplyConfigMethod · 0.95

Calls 3

safePluginCallMethod · 0.95
registerRPCPluginFunction · 0.85
validPluginFunction · 0.85

Tested by

no test coverage detected