diff --git a/cmds/test-plugin/decider.go b/cmds/test-plugin/decider.go index 539edbe02..c7f003c28 100644 --- a/cmds/test-plugin/decider.go +++ b/cmds/test-plugin/decider.go @@ -7,16 +7,16 @@ import ( "github.com/safing/portmaster/plugin/shared/proto" ) -type DecideHandleFunc func(*proto.Connection) (proto.Verdict, error) +type decideHandleFunc func(*proto.Connection) (proto.Verdict, error) -type TestDeciderPlugin struct { +type testDeciderPlugin struct { l sync.Mutex - handler DecideHandleFunc + handler decideHandleFunc filterDomains []string } -func (d *TestDeciderPlugin) SetHandler(fn DecideHandleFunc, domains ...string) { +func (d *testDeciderPlugin) setHandler(fn decideHandleFunc, domains ...string) { d.l.Lock() defer d.l.Unlock() @@ -24,7 +24,7 @@ func (d *TestDeciderPlugin) SetHandler(fn DecideHandleFunc, domains ...string) { d.filterDomains = domains } -func (d *TestDeciderPlugin) DecideOnConnection(ctx context.Context, conn *proto.Connection) (proto.Verdict, string, error) { +func (d *testDeciderPlugin) DecideOnConnection(ctx context.Context, conn *proto.Connection) (proto.Verdict, string, error) { d.l.Lock() defer d.l.Unlock() diff --git a/cmds/test-plugin/main.go b/cmds/test-plugin/main.go index ebc4caa2b..346ff9efe 100644 --- a/cmds/test-plugin/main.go +++ b/cmds/test-plugin/main.go @@ -20,8 +20,8 @@ type checkResult struct { } var ( - decider = new(TestDeciderPlugin) - reporter = new(TestReporterPlugin) + decider = new(testDeciderPlugin) + reporter = new(testReporterPlugin) resultsLock sync.Mutex results []*checkResult @@ -33,11 +33,15 @@ func getRootCmd() *cobra.Command { Run: func(cmd *cobra.Command, args []string) { // Create a new decider plugin implementation and register it // at the framework - framework.RegisterDecider(decider) + if err := framework.RegisterDecider(decider); err != nil { + log.Fatalf("failed to register decider plugin: %s", err) + } // Create a new reporter plugin implementation and register it // at the framework - framework.RegisterReporter(reporter) + if err := framework.RegisterReporter(reporter); err != nil { + log.Fatalf("failed to register reporter plugin: %s", err) + } // Once the framework is initialized we can start doing our // tests. @@ -119,6 +123,9 @@ func createTestRunNotification() { Message: msg, }) if err != nil { + // we're going to exit anyway but gocritic likes us to unlock before the exit + resultsLock.Unlock() + log.Fatalf("failed to create notification: %s", err) } } @@ -138,6 +145,8 @@ func launchTests() { RunTest("Reporter is called for connections", TestReporterIsCalled) RunTest("Decider is called for connections", TestDeciderIsCalled) RunTest("Blocking deciders should be ignored", TestBlockingDecider) + + createTestFinishedNotification() } func main() { diff --git a/cmds/test-plugin/reporter.go b/cmds/test-plugin/reporter.go index d4de57805..b6a558fe3 100644 --- a/cmds/test-plugin/reporter.go +++ b/cmds/test-plugin/reporter.go @@ -7,16 +7,16 @@ import ( "github.com/safing/portmaster/plugin/shared/proto" ) -type ReportHandlerFunc func(*proto.Connection) +type reportHandlerFunc func(*proto.Connection) -type TestReporterPlugin struct { +type testReporterPlugin struct { l sync.Mutex - reporter ReportHandlerFunc + reporter reportHandlerFunc domainFilter []string } -func (r *TestReporterPlugin) SetHandler(fn ReportHandlerFunc, domains ...string) { +func (r *testReporterPlugin) setHandler(fn reportHandlerFunc, domains ...string) { r.l.Lock() defer r.l.Unlock() @@ -24,7 +24,7 @@ func (r *TestReporterPlugin) SetHandler(fn ReportHandlerFunc, domains ...string) r.domainFilter = domains } -func (r *TestReporterPlugin) ReportConnection(ctx context.Context, conn *proto.Connection) error { +func (r *testReporterPlugin) ReportConnection(ctx context.Context, conn *proto.Connection) error { r.l.Lock() defer r.l.Unlock() diff --git a/cmds/test-plugin/tests.go b/cmds/test-plugin/tests.go index 05c24e854..fcaec233f 100644 --- a/cmds/test-plugin/tests.go +++ b/cmds/test-plugin/tests.go @@ -11,13 +11,13 @@ import ( func TestReporterIsCalled() error { ch := make(chan struct{}, 1) - reporter.SetHandler(func(c *proto.Connection) { + reporter.setHandler(func(c *proto.Connection) { ch <- struct{}{} }, "example.com.") - defer reporter.SetHandler(nil) + defer reporter.setHandler(nil) - go http.Get("https://example.com") + go http.Get("https://example.com") // nolint:errcheck select { case <-ch: @@ -30,14 +30,14 @@ func TestReporterIsCalled() error { func TestDeciderIsCalled() error { ch := make(chan struct{}, 1) - decider.SetHandler(func(c *proto.Connection) (proto.Verdict, error) { + decider.setHandler(func(c *proto.Connection) (proto.Verdict, error) { ch <- struct{}{} return proto.Verdict_VERDICT_ACCEPT, nil }, "example.com.") - defer decider.SetHandler(nil) + defer decider.setHandler(nil) - go http.Get("https://example.com") + go http.Get("https://example.com") // nolint:errcheck select { case <-ch: @@ -48,23 +48,23 @@ func TestDeciderIsCalled() error { } func TestBlockingDecider() error { - decider.SetHandler(func(c *proto.Connection) (proto.Verdict, error) { + decider.setHandler(func(c *proto.Connection) (proto.Verdict, error) { // time.Sleep(1 * time.Second) return proto.Verdict_VERDICT_DROP, nil }, "example.com.") - defer decider.SetHandler(nil) + defer decider.setHandler(nil) connReporter := make(chan proto.Verdict, 1) - reporter.SetHandler(func(c *proto.Connection) { + reporter.setHandler(func(c *proto.Connection) { if c.Type == proto.ConnectionType_CONNECTION_TYPE_IP { connReporter <- c.Verdict } }, "example.com.") - defer reporter.SetHandler(nil) + defer reporter.setHandler(nil) - go http.Get("https://example.com") + go http.Get("https://example.com") // nolint:errcheck select { case verdict := <-connReporter: diff --git a/plugin/framework/cmds/install.go b/plugin/framework/cmds/install.go index b5f3e0bf9..8f652fab3 100644 --- a/plugin/framework/cmds/install.go +++ b/plugin/framework/cmds/install.go @@ -54,7 +54,11 @@ func InstallCommand(cfg *InstallCommandConfig) *cobra.Command { if err != nil { log.Fatalf("failed to open plugin executable: %s", err) } - defer source.Close() + defer func() { + if err := source.Close(); err != nil { + log.Printf("warning: failed to close source file: %s", err) + } + }() // create the executable into the plugins directory target, err := os.OpenFile(pluginTarget, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0555) @@ -65,18 +69,22 @@ func InstallCommand(cfg *InstallCommandConfig) *cobra.Command { // copy the binary to the new location if _, err := io.Copy(target, source); err != nil { target.Close() - os.Remove(target.Name()) + if err := os.Remove(target.Name()); err != nil { + log.Printf("warning: failed to remove stale target file %s: %s", target.Name(), err) + } log.Fatalf("failed to copy binary: %s", err) } - target.Close() + if err := target.Close(); err != nil { + log.Fatalf("warning: failed to close target file: %s", err) + } // try to open and read the plugins.json file - pluginJson := filepath.Join(installDir, "plugins.json") + pluginJSON := filepath.Join(installDir, "plugins.json") var cfgs []shared.PluginConfig - blob, err := os.ReadFile(pluginJson) + blob, err := os.ReadFile(pluginJSON) if err != nil && !os.IsNotExist(err) { log.Fatalf("failed to read plugins.json: %s", err) } @@ -118,7 +126,7 @@ func InstallCommand(cfg *InstallCommandConfig) *cobra.Command { log.Fatalf("failed to marshal JSON configuration file") } - if err := os.WriteFile(pluginJson, blob, 0644); err != nil { + if err := os.WriteFile(pluginJSON, blob, 0644); err != nil { log.Fatalf("failed to write plugins.json: %s", err) } diff --git a/plugin/framework/utils.go b/plugin/framework/utils.go index b9657839c..5537f091f 100644 --- a/plugin/framework/utils.go +++ b/plugin/framework/utils.go @@ -36,7 +36,7 @@ var ( getExecPathOnce sync.Once executablePath string resolvedExecutablePath string - getExecError error + errGetExecPath error ) // DecideOnConnection passes through to fn and implements decider.Decider. @@ -99,12 +99,12 @@ func ChainDeciderFunc(fns ...DeciderFunc) DeciderFunc { func getExecPath() { getExecPathOnce.Do(func() { - executablePath, getExecError = os.Executable() - if getExecError != nil { + executablePath, errGetExecPath = os.Executable() + if errGetExecPath != nil { return } - resolvedExecutablePath, getExecError = filepath.EvalSymlinks(executablePath) + resolvedExecutablePath, errGetExecPath = filepath.EvalSymlinks(executablePath) }) } @@ -120,7 +120,7 @@ func AllowPluginConnections() DeciderFunc { return func(ctx context.Context, c *proto.Connection) (proto.Verdict, string, error) { self, err := IsSelf(c) if err != nil { - return proto.Verdict_VERDICT_UNDECIDED, "", fmt.Errorf("failed to get executable path: %s", getExecError) + return proto.Verdict_VERDICT_UNDECIDED, "", fmt.Errorf("failed to get executable path: %w", errGetExecPath) } if self { return proto.Verdict_VERDICT_ACCEPT, "own plugin connections are allowed", nil @@ -138,8 +138,8 @@ func IsSelf(conn *proto.Connection) (bool, error) { binary := conn.GetProcess().GetBinaryPath() - if getExecError != nil { - return false, getExecError + if errGetExecPath != nil { + return false, errGetExecPath } if binary == resolvedExecutablePath || binary == executablePath { diff --git a/plugin/shared/base/base_grpc.go b/plugin/shared/base/base_grpc.go index d5d6f8b4b..6e92971a3 100644 --- a/plugin/shared/base/base_grpc.go +++ b/plugin/shared/base/base_grpc.go @@ -25,6 +25,7 @@ type ( } ) +// Configure implements the grpc client side of the Base.Configure. func (m *gRPCClient) Configure(ctx context.Context, req *proto.ConfigureRequest, env Environment) error { var s *grpc.Server serverFunc := func(opts []grpc.ServerOption) *grpc.Server { @@ -68,12 +69,14 @@ func (m *gRPCClient) Configure(ctx context.Context, req *proto.ConfigureRequest, return nil } +// Shutdown implements the gRPC client side of Base.Shutdown. func (m *gRPCClient) Shutdown(ctx context.Context) error { _, err := m.client.Shutdown(ctx, &proto.ShutdownRequest{}) return err } +// Configure implements the gRPC server side of Base.Configure. func (m *gRPCServer) Configure(ctx context.Context, req *proto.ConfigureRequest) (*proto.ConfigureResponse, error) { conn, err := m.broker.Dial(req.BackchannelId) if err != nil { @@ -112,6 +115,7 @@ func (m *gRPCServer) Configure(ctx context.Context, req *proto.ConfigureRequest) return new(proto.ConfigureResponse), nil } +// Shutdown implements the gRPC server side of Base.Shutdown. func (m *gRPCServer) Shutdown(ctx context.Context, _ *proto.ShutdownRequest) (*proto.ShutdownResponse, error) { err := m.Impl.Shutdown(ctx) if err != nil { diff --git a/plugin/shared/base/base_interface.go b/plugin/shared/base/base_interface.go index 4da2a1757..30ad3d270 100644 --- a/plugin/shared/base/base_interface.go +++ b/plugin/shared/base/base_interface.go @@ -12,18 +12,38 @@ import ( ) type ( + // Environment holds the plugin environment and provides access + // to different Portmaster subsystems like the configuration and notification + // services. If a plugin is marked as privileged, the environment will also + // provide access to the plugin manager subsystem. Environment struct { - Config config.Service - Notify notification.Service + // Config provides access to the configuration system of Portmaster. + Config config.Service + // Notify provides access to the notification system of Portmaster. + Notify notification.Service + // PluginManager provides access to the plugin system of Portmaster. + // Note that only privileged plugins may access the plugin system + // manager. PluginManager pluginmanager.Service } + // Base describes base plugin requirements that are used to configure + // the plugin and manage it's life-cycle. Plugin implementation normally don't + // need to implement the base plugin themselvs but rather just need to use + // the framework package which handles the more complex parts of the plugin + // system already. Base interface { + // Configure is called after the plugin has been launched and provides addition + // information about the Portmaster host process as well as access to some + // Portmaster sub-systems using the provided environment. Configure(context.Context, *proto.ConfigureRequest, Environment) error + // Shutdown is called when the plugin should stop. Plugin implementations + // can react to shutdown requests using framework.OnShutdown. Shutdown(ctx context.Context) error } + // Plugin implements the plugin.GRPCPlugin interface for Base. Plugin struct { plugin.NetRPCUnsupportedPlugin @@ -31,6 +51,7 @@ type ( } ) +// GRPCServer registers the gRPC server side of Base and implements the plugin.GRPCPlugin interface. func (p *Plugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) error { proto.RegisterBaseServiceServer(s, &gRPCServer{ Impl: p.Impl, @@ -40,6 +61,7 @@ func (p *Plugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) error { return nil } +// GRPCClient returns a gRPC client for Base and implements the plugin.GRPCPlugin interface. func (p *Plugin) GRPCClient(ctx context.Context, broker *plugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error) { return &gRPCClient{ client: proto.NewBaseServiceClient(c), diff --git a/plugin/shared/config/config_grpc.go b/plugin/shared/config/config_grpc.go index c9adae9dc..78642b7cc 100644 --- a/plugin/shared/config/config_grpc.go +++ b/plugin/shared/config/config_grpc.go @@ -7,10 +7,12 @@ import ( ) type ( + // GRPCClient implements the gRPC client side of config.Service. GRPCClient struct { Client proto.ConfigServiceClient } + // GRPCServer implements the gRPC server side of config.Service. GRPCServer struct { proto.UnimplementedConfigServiceServer @@ -19,6 +21,7 @@ type ( } ) +// RegisterOption implements the gRPC client side of Service.RegisterOption. func (cli *GRPCClient) RegisterOption(ctx context.Context, option *proto.Option) error { _, err := cli.Client.RegisterOption(ctx, &proto.RegisterRequest{ Option: option, @@ -30,6 +33,7 @@ func (cli *GRPCClient) RegisterOption(ctx context.Context, option *proto.Option) return nil } +// GetValue implements the gRPC client side of Service.GetValue. func (cli *GRPCClient) GetValue(ctx context.Context, key string) (*proto.Value, error) { res, err := cli.Client.GetValue(ctx, &proto.GetValueRequest{ Key: key, @@ -42,6 +46,7 @@ func (cli *GRPCClient) GetValue(ctx context.Context, key string) (*proto.Value, return res.Value, nil } +// WatchValue implements the gRPC client side of Service.WatchValue. func (cli *GRPCClient) WatchValue(ctx context.Context, key ...string) (<-chan *proto.WatchChangesResponse, error) { res, err := cli.Client.WatchValues(ctx, &proto.WatchChangesRequest{ Keys: key, @@ -70,6 +75,7 @@ func (cli *GRPCClient) WatchValue(ctx context.Context, key ...string) (<-chan *p return ch, nil } +// RegisterOption implements the gRPC server side of Service.RegisterOption. func (srv *GRPCServer) RegisterOption(ctx context.Context, req *proto.RegisterRequest) (*proto.RegisterResponse, error) { err := srv.Impl.RegisterOption(ctx, req.Option) if err != nil { @@ -79,6 +85,7 @@ func (srv *GRPCServer) RegisterOption(ctx context.Context, req *proto.RegisterRe return &proto.RegisterResponse{}, nil } +// GetValue implements the gRPC server side of Service.GetValue. func (srv *GRPCServer) GetValue(ctx context.Context, req *proto.GetValueRequest) (*proto.GetValueResponse, error) { res, err := srv.Impl.GetValue(ctx, req.Key) if err != nil { @@ -90,6 +97,7 @@ func (srv *GRPCServer) GetValue(ctx context.Context, req *proto.GetValueRequest) }, nil } +// WatchValues implements the gRPC server side of Service.WatchValues. func (srv *GRPCServer) WatchValues(req *proto.WatchChangesRequest, stream proto.ConfigService_WatchValuesServer) error { ch, err := srv.Impl.WatchValue(stream.Context(), req.Keys...) if err != nil { @@ -97,7 +105,9 @@ func (srv *GRPCServer) WatchValues(req *proto.WatchChangesRequest, stream proto. } for msg := range ch { - stream.Send(msg) + if err := stream.Send(msg); err != nil { + return err + } } return nil diff --git a/plugin/shared/config/config_interface.go b/plugin/shared/config/config_interface.go index d4fa7055a..f8b67e891 100644 --- a/plugin/shared/config/config_interface.go +++ b/plugin/shared/config/config_interface.go @@ -29,6 +29,9 @@ type ( // Note that plugins only have access to keys the registered. (Plugin keys are scoped // by plugin-name.) GetValue(ctx context.Context, key string) (*proto.Value, error) + + // WatchValue watches a list of configuration keys for changes and emits those + // changes on the returned channel. WatchValue(ctx context.Context, key ...string) (<-chan *proto.WatchChangesResponse, error) } ) diff --git a/plugin/shared/decider/decider_interface.go b/plugin/shared/decider/decider_interface.go index 72857c985..b8062e683 100644 --- a/plugin/shared/decider/decider_interface.go +++ b/plugin/shared/decider/decider_interface.go @@ -21,6 +21,7 @@ type ( } ) +// GRPCServer configures a gRPC Decider Service server on s and implements plugin.GRPCPlugin. func (p *Plugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) error { proto.RegisterDeciderServiceServer(s, &gRPCServer{ Impl: p.Impl, @@ -30,6 +31,7 @@ func (p *Plugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) error { return nil } +// GRPCClient returns a Decider implementation that talks to a gRPC server and implements plugin.GRPCPlugin. func (p *Plugin) GRPCClient(ctx context.Context, broker *plugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error) { return &gRPCClient{ client: proto.NewDeciderServiceClient(c), diff --git a/plugin/shared/notification/notification_grpc.go b/plugin/shared/notification/notification_grpc.go index 7fc6391b3..6a3f5987b 100644 --- a/plugin/shared/notification/notification_grpc.go +++ b/plugin/shared/notification/notification_grpc.go @@ -7,10 +7,12 @@ import ( ) type ( + // GRPCClient is the client side implementation of notification.Service. GRPCClient struct { Client proto.NotificationServiceClient } + // GRPCServer implements the gRPC server side of notification.Service. GRPCServer struct { proto.UnimplementedNotificationServiceServer @@ -19,6 +21,7 @@ type ( } ) +// CreateNotification implements the gRPC client side of Service.CreateNotification. func (cli *GRPCClient) CreateNotification(ctx context.Context, notif *proto.Notification) (<-chan string, error) { stream, err := cli.Client.CreateNotification(ctx, &proto.CreateNotificationRequest{ Notification: notif, @@ -46,6 +49,7 @@ func (cli *GRPCClient) CreateNotification(ctx context.Context, notif *proto.Noti return ch, nil } +// CreateNotification implements the gRPC server side of Service.CreateNotification. func (srv *GRPCServer) CreateNotification(req *proto.CreateNotificationRequest, stream proto.NotificationService_CreateNotificationServer) error { ctx := stream.Context() diff --git a/plugin/shared/pluginmanager/plugin_manager_grpc.go b/plugin/shared/pluginmanager/plugin_manager_grpc.go index 2fe42f023..3fc64b7fe 100644 --- a/plugin/shared/pluginmanager/plugin_manager_grpc.go +++ b/plugin/shared/pluginmanager/plugin_manager_grpc.go @@ -7,17 +7,20 @@ import ( ) type ( + // GRPCServer implements the gRPC server side of pluginmanager.Service. GRPCServer struct { proto.UnimplementedPluginManagerServiceServer Impl Service } + // GRPCClient implements the gRPC client side of pluginmanager.Service. GRPCClient struct { Client proto.PluginManagerServiceClient } ) +// ListPlugins implements the gRPC server side of pluginmanager.Service.ListPlugin. func (srv *GRPCServer) ListPlugins(ctx context.Context, req *proto.ListPluginsRequest) (*proto.ListPluginsResponse, error) { plugins, err := srv.Impl.ListPlugins(ctx) if err != nil { @@ -29,6 +32,7 @@ func (srv *GRPCServer) ListPlugins(ctx context.Context, req *proto.ListPluginsRe }, nil } +// RegisterPlugin implements the gRPC server side of pluginmanager.Service.RegisterPlugin. func (srv *GRPCServer) RegisterPlugin(ctx context.Context, req *proto.RegisterPluginRequest) (*proto.RegisterPluginResponse, error) { if err := srv.Impl.RegisterPlugin(ctx, req.Config); err != nil { return nil, err @@ -37,6 +41,7 @@ func (srv *GRPCServer) RegisterPlugin(ctx context.Context, req *proto.RegisterPl return &proto.RegisterPluginResponse{}, nil } +// UnregisterPlugin implements the gRPC server side of pluginmanager.Service.UnregisterPlugin. func (srv *GRPCServer) UnregisterPlugin(ctx context.Context, req *proto.UnregisterPluginRequest) (*proto.UnregisterPluginResponse, error) { if err := srv.Impl.UnregisterPlugin(ctx, req.Name); err != nil { return nil, err @@ -45,6 +50,7 @@ func (srv *GRPCServer) UnregisterPlugin(ctx context.Context, req *proto.Unregist return &proto.UnregisterPluginResponse{}, nil } +// StopPlugin implements the gRPC server side of pluginmanager.Service.StopPlugin. func (srv *GRPCServer) StopPlugin(ctx context.Context, req *proto.StopPluginRequest) (*proto.StopPluginResponse, error) { if err := srv.Impl.StopPlugin(ctx, req.Name); err != nil { return nil, err @@ -53,6 +59,7 @@ func (srv *GRPCServer) StopPlugin(ctx context.Context, req *proto.StopPluginRequ return &proto.StopPluginResponse{}, nil } +// StartPlugin implements the gRPC server side of pluginmanager.Service.StartPlugin. func (srv *GRPCServer) StartPlugin(ctx context.Context, req *proto.StartPluginRequest) (*proto.StartPluginResponse, error) { if err := srv.Impl.StartPlugin(ctx, req.Name); err != nil { return nil, err @@ -61,6 +68,7 @@ func (srv *GRPCServer) StartPlugin(ctx context.Context, req *proto.StartPluginRe return &proto.StartPluginResponse{}, nil } +// ListPlugins implements the gRPC client side of pluginmanager.Service.ListPlugins. func (cli *GRPCClient) ListPlugins(ctx context.Context) ([]*proto.Plugin, error) { res, err := cli.Client.ListPlugins(ctx, &proto.ListPluginsRequest{}) if err != nil { @@ -70,6 +78,7 @@ func (cli *GRPCClient) ListPlugins(ctx context.Context) ([]*proto.Plugin, error) return res.Plugins, nil } +// RegisterPlugin implements the gRPC client side of pluginmanager.Service.RegisterPlugin. func (cli *GRPCClient) RegisterPlugin(ctx context.Context, config *proto.PluginConfig) error { _, err := cli.Client.RegisterPlugin(ctx, &proto.RegisterPluginRequest{ Config: config, @@ -78,6 +87,7 @@ func (cli *GRPCClient) RegisterPlugin(ctx context.Context, config *proto.PluginC return err } +// UnregisterPlugin implements the gRPC client side of pluginmanager.Service.UnregisterPlugin. func (cli *GRPCClient) UnregisterPlugin(ctx context.Context, name string) error { _, err := cli.Client.UnregisterPlugin(ctx, &proto.UnregisterPluginRequest{ Name: name, @@ -86,6 +96,7 @@ func (cli *GRPCClient) UnregisterPlugin(ctx context.Context, name string) error return err } +// StartPlugin implements the gRPC client side of pluginmanager.Service.StartPlugin. func (cli *GRPCClient) StartPlugin(ctx context.Context, name string) error { _, err := cli.Client.StartPlugin(ctx, &proto.StartPluginRequest{ Name: name, @@ -94,6 +105,7 @@ func (cli *GRPCClient) StartPlugin(ctx context.Context, name string) error { return err } +// StopPlugin implements the gRPC client side of pluginmanager.Service.StopPlugin. func (cli *GRPCClient) StopPlugin(ctx context.Context, name string) error { _, err := cli.Client.StopPlugin(ctx, &proto.StopPluginRequest{ Name: name, diff --git a/plugin/shared/reporter/reporter_grpc.go b/plugin/shared/reporter/reporter_grpc.go index 41ef773f5..80fc2503a 100644 --- a/plugin/shared/reporter/reporter_grpc.go +++ b/plugin/shared/reporter/reporter_grpc.go @@ -21,6 +21,7 @@ type ( } ) +// ReportConnection implements the gRPC client side of reporter.Service.ReportConnection. func (m *gRPCClient) ReportConnection(ctx context.Context, conn *proto.Connection) error { _, err := m.client.ReportConnection(ctx, &proto.ReportConnectionRequest{ Connection: conn, @@ -32,6 +33,7 @@ func (m *gRPCClient) ReportConnection(ctx context.Context, conn *proto.Connectio return nil } +// ReportConnection implements the gRPC server side of reporter.Service.ReportConnection. func (m *gRPCServer) ReportConnection(ctx context.Context, req *proto.ReportConnectionRequest) (*proto.ReportConnectionRespose, error) { err := m.Impl.ReportConnection(ctx, req.Connection) if err != nil { diff --git a/plugin/shared/reporter/reporter_interface.go b/plugin/shared/reporter/reporter_interface.go index 792e3c0f1..156377af5 100644 --- a/plugin/shared/reporter/reporter_interface.go +++ b/plugin/shared/reporter/reporter_interface.go @@ -20,6 +20,7 @@ type ( } ) +// GRPCServer implements the gRPC server side of reporter.Service and implements plugin.GRPCPlugin. func (p *Plugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) error { proto.RegisterReporterServiceServer(s, &gRPCServer{ Impl: p.Impl, @@ -29,6 +30,7 @@ func (p *Plugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) error { return nil } +// GRPCClient implements the gRPC client side of reporter.Service.GRPCClient and implements plugin.GRPCPlugin. func (p *Plugin) GRPCClient(ctx context.Context, broker *plugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error) { return &gRPCClient{ client: proto.NewReporterServiceClient(c), diff --git a/plugin/shared/resolver/resolver_grpc.go b/plugin/shared/resolver/resolver_grpc.go index 3d091036a..ba1fa0bc8 100644 --- a/plugin/shared/resolver/resolver_grpc.go +++ b/plugin/shared/resolver/resolver_grpc.go @@ -20,6 +20,7 @@ type ( } ) +// Resolve implements the gRPC client side of resolver.Service.Resolve. func (cli *gRPCClient) Resolve(ctx context.Context, req *proto.DNSQuestion, conn *proto.Connection) (*proto.DNSResponse, error) { res, err := cli.client.Resolve(ctx, &proto.ResolveRequest{ Question: req, @@ -32,6 +33,7 @@ func (cli *gRPCClient) Resolve(ctx context.Context, req *proto.DNSQuestion, conn return res.GetResponse(), nil } +// Resolve implements the gRPC server side of resolver.Service.Resolve. func (srv *gRPCServer) Resolve(ctx context.Context, req *proto.ResolveRequest) (*proto.ResolveResponse, error) { res, err := srv.Impl.Resolve(ctx, req.GetQuestion(), req.GetConnection()) if err != nil { diff --git a/plugin/shared/resolver/resolver_interface.go b/plugin/shared/resolver/resolver_interface.go index 7a9d7ab7c..1f269bf48 100644 --- a/plugin/shared/resolver/resolver_interface.go +++ b/plugin/shared/resolver/resolver_interface.go @@ -20,6 +20,7 @@ type ( } ) +// GRPCServer implements the gRPC server side of resolver.Service and implements plugin.GRPCPlugin. func (p *Plugin) GRPCServer(_ *plugin.GRPCBroker, s *grpc.Server) error { proto.RegisterResolverServiceServer(s, &gRPCServer{ Impl: p.Impl, @@ -28,6 +29,7 @@ func (p *Plugin) GRPCServer(_ *plugin.GRPCBroker, s *grpc.Server) error { return nil } +// GRPCClient implements the gRPC client side of resolver.Service and implements plugin.GRPCPlugin. func (p *Plugin) GRPCClient(ctx context.Context, broker *plugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error) { return &gRPCClient{ client: proto.NewResolverServiceClient(c),