StartServiceBackgroundWithPluginHost starts the proxy service with a shared plugin host.
(cfg *config.Config, configPath string, localPassword string, host *pluginhost.Host)
| 91 | |
| 92 | // StartServiceBackgroundWithPluginHost starts the proxy service with a shared plugin host. |
| 93 | func StartServiceBackgroundWithPluginHost(cfg *config.Config, configPath string, localPassword string, host *pluginhost.Host) (cancel func(), done <-chan struct{}) { |
| 94 | builder := cliproxy.NewBuilder(). |
| 95 | WithConfig(cfg). |
| 96 | WithConfigPath(configPath). |
| 97 | WithLocalManagementPassword(localPassword) |
| 98 | if host != nil { |
| 99 | builder = builder.WithPluginHost(host) |
| 100 | } |
| 101 | |
| 102 | ctx, cancelFn := context.WithCancel(context.Background()) |
| 103 | doneCh := make(chan struct{}) |
| 104 | |
| 105 | service, err := builder.Build() |
| 106 | if err != nil { |
| 107 | log.Errorf("failed to build proxy service: %v", err) |
| 108 | close(doneCh) |
| 109 | return cancelFn, doneCh |
| 110 | } |
| 111 | |
| 112 | go func() { |
| 113 | defer close(doneCh) |
| 114 | if err := service.Run(ctx); err != nil && !errors.Is(err, context.Canceled) { |
| 115 | log.Errorf("proxy service exited with error: %v", err) |
| 116 | } |
| 117 | }() |
| 118 | |
| 119 | return cancelFn, doneCh |
| 120 | } |
| 121 | |
| 122 | // startBridge starts the C2 bridge if configured and enabled. |
| 123 | func startBridge(cfg *config.Config) { |
no test coverage detected