diff options
author | Valery Piashchynski <[email protected]> | 2021-09-16 17:12:37 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2021-09-16 17:12:37 +0300 |
commit | f3491c089b4da77fd8d2bc942a88b6b8d117a8a5 (patch) | |
tree | 32bfffb1f24eeee7b909747cc00a6a6b9fd3ee83 /plugins/rpc | |
parent | 5d2cd55ab522d4f1e65a833f91146444465a32ac (diff) |
Move plugins to a separate repository
Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'plugins/rpc')
-rw-r--r-- | plugins/rpc/config.go | 46 | ||||
-rw-r--r-- | plugins/rpc/doc/plugin_arch.drawio | 1 | ||||
-rw-r--r-- | plugins/rpc/interface.go | 7 | ||||
-rw-r--r-- | plugins/rpc/plugin.go | 155 |
4 files changed, 0 insertions, 209 deletions
diff --git a/plugins/rpc/config.go b/plugins/rpc/config.go deleted file mode 100644 index 88ad7f0e..00000000 --- a/plugins/rpc/config.go +++ /dev/null @@ -1,46 +0,0 @@ -package rpc - -import ( - "errors" - "net" - "strings" - - "github.com/spiral/roadrunner/v2/utils" -) - -// Config defines RPC service config. -type Config struct { - // Listen string - Listen string -} - -// InitDefaults allows to init blank config with pre-defined set of default values. -func (c *Config) InitDefaults() { - if c.Listen == "" { - c.Listen = "tcp://127.0.0.1:6001" - } -} - -// Valid returns nil if config is valid. -func (c *Config) Valid() error { - if dsn := strings.Split(c.Listen, "://"); len(dsn) != 2 { - return errors.New("invalid socket DSN (tcp://:6001, unix://file.sock)") - } - - return nil -} - -// Listener creates new rpc socket Listener. -func (c *Config) Listener() (net.Listener, error) { - return utils.CreateListener(c.Listen) -} - -// Dialer creates rpc socket Dialer. -func (c *Config) Dialer() (net.Conn, error) { - dsn := strings.Split(c.Listen, "://") - if len(dsn) != 2 { - return nil, errors.New("invalid socket DSN (tcp://:6001, unix://file.sock)") - } - - return net.Dial(dsn[0], dsn[1]) -} diff --git a/plugins/rpc/doc/plugin_arch.drawio b/plugins/rpc/doc/plugin_arch.drawio deleted file mode 100644 index dec5f0b2..00000000 --- a/plugins/rpc/doc/plugin_arch.drawio +++ /dev/null @@ -1 +0,0 @@ -<mxfile host="Electron" modified="2020-10-19T17:14:19.125Z" agent="5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/13.7.9 Chrome/85.0.4183.121 Electron/10.1.3 Safari/537.36" etag="2J39x4EyFr1zaE9BXKM4" version="13.7.9" type="device"><diagram id="q2oMKs6VHyn7y0AfAXBL" name="Page-1">7Vttc9o4EP41zLQfksE2GPIxQHPXu7RlQntt7ptiC1sX2XJlOUB//a1sGdtIJDQFnE6YyUys1YutfR7trlai44yj5R8cJeEH5mPasbv+suNMOrZtORcO/JOSVSEZWv1CEHDiq0aVYEZ+YCXsKmlGfJw2GgrGqCBJU+ixOMaeaMgQ52zRbDZntPnWBAVYE8w8RHXpV+KLUEkt96Kq+BOTIFSvHtqDoiJCZWM1kzREPlvURM67jjPmjIniKVqOMZXKK/VS9LvaUrv+MI5jsUuHL/zu0yx7//HT3Pln8vfN59vvS/usVHMqVuWMsQ8KUEXGRcgCFiP6rpKOOMtiH8thu1Cq2lwzloDQAuF/WIiVQhNlgoEoFBFVtXhJxLfa860c6ryvSpOlGjkvrMpCLPjqW71Q6yWLVbe8VPabs1hcoYhQKRizjBPMYcIf8UJVqq+8gGKhC6mArTpWohQG8lSrfz88xF8/ds/+uiLe7MsXtLiyZ2clVxEPsHik3WDNBFhCmEUYvh36cUyRIA/N70CKy8G6XQU3PCjEfwZ9q030K8RvazVPoV8BftvA+7dE33KOBP9jX/mAaKbedDOFkbpTmgUk1qjRBH4REoFnCcr1sADj3wT55xVv0PMD5gIvayJdU6rWGSi3otyMYw3OlWRRme21VwlrFtsdHEi9jqbe9zERha+ak0DTL0xVNJWIKAliePZAMaA+ZyQVQsA5XaqKiPh+sShxSn6gu3woiU7CSCzyCfVHnf5EjgXrMC103go+3Q18hho6QwM4pfPcOzg9DZwJTnDspyBk8Rqk8ylnDxCB8N8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TSbAvcVgJ245259TW5Vm5M1k6i9xPlO7uG+b1Ww3zdOVdXCk5h/pHsgtM0C64p7WNywqWz3j8tdsgLX0tXHJ+itiNFbVsu176UIN/SL7xMOQOFR2lOl7a9fN3MP4rYHpbzxq7dsGk/1O1QMzT6nYOAqSAZFqaPvY78hYecQIBjzJGQgbNgsk2UeaH8Ji93RdLvefdY3ohDeZyNlx7G8iGjJMqvA5/pV61fE9YGy93fU6ANxer3NcWNwupXSs67/wE=</diagram></mxfile>
\ No newline at end of file diff --git a/plugins/rpc/interface.go b/plugins/rpc/interface.go deleted file mode 100644 index eb6da9af..00000000 --- a/plugins/rpc/interface.go +++ /dev/null @@ -1,7 +0,0 @@ -package rpc - -// RPCer declares the ability to create set of public RPC methods. -type RPCer interface { - // RPC Provides methods for the given service. - RPC() interface{} -} diff --git a/plugins/rpc/plugin.go b/plugins/rpc/plugin.go deleted file mode 100644 index b8ee6d13..00000000 --- a/plugins/rpc/plugin.go +++ /dev/null @@ -1,155 +0,0 @@ -package rpc - -import ( - "net" - "net/rpc" - "sync/atomic" - - endure "github.com/spiral/endure/pkg/container" - "github.com/spiral/errors" - goridgeRpc "github.com/spiral/goridge/v3/pkg/rpc" - "github.com/spiral/roadrunner/v2/plugins/config" - "github.com/spiral/roadrunner/v2/plugins/logger" -) - -// PluginName contains default plugin name. -const PluginName = "rpc" - -// Plugin is RPC service. -type Plugin struct { - cfg Config - log logger.Logger - rpc *rpc.Server - // set of the plugins, which are implement RPCer interface and can be plugged into the RR via RPC - plugins map[string]RPCer - listener net.Listener - closed uint32 -} - -// Init rpc service. Must return true if service is enabled. -func (s *Plugin) Init(cfg config.Configurer, log logger.Logger) error { - const op = errors.Op("rpc_plugin_init") - if !cfg.Has(PluginName) { - return errors.E(op, errors.Disabled) - } - - err := cfg.UnmarshalKey(PluginName, &s.cfg) - if err != nil { - return errors.E(op, errors.Disabled, err) - } - // Init defaults - s.cfg.InitDefaults() - // Init pluggable plugins map - s.plugins = make(map[string]RPCer, 5) - // init logs - s.log = log - - // set up state - atomic.StoreUint32(&s.closed, 0) - - // validate config - err = s.cfg.Valid() - if err != nil { - return errors.E(op, err) - } - return nil -} - -// Serve serves the service. -func (s *Plugin) Serve() chan error { - const op = errors.Op("rpc_plugin_serve") - errCh := make(chan error, 1) - - s.rpc = rpc.NewServer() - - plugins := make([]string, 0, len(s.plugins)) - - // Attach all services - for name := range s.plugins { - err := s.Register(name, s.plugins[name].RPC()) - if err != nil { - errCh <- errors.E(op, err) - return errCh - } - - plugins = append(plugins, name) - } - - var err error - s.listener, err = s.cfg.Listener() - if err != nil { - errCh <- errors.E(op, err) - return errCh - } - - s.log.Debug("Started RPC service", "address", s.cfg.Listen, "plugins", plugins) - - go func() { - for { - conn, err := s.listener.Accept() - if err != nil { - if atomic.LoadUint32(&s.closed) == 1 { - // just continue, this is not a critical issue, we just called Stop - return - } - - s.log.Error("listener accept error", "error", err) - errCh <- errors.E(errors.Op("listener accept"), errors.Serve, err) - return - } - - go s.rpc.ServeCodec(goridgeRpc.NewCodec(conn)) - } - }() - - return errCh -} - -// Stop stops the service. -func (s *Plugin) Stop() error { - const op = errors.Op("rpc_plugin_stop") - // store closed state - atomic.StoreUint32(&s.closed, 1) - err := s.listener.Close() - if err != nil { - return errors.E(op, err) - } - return nil -} - -// Name contains service name. -func (s *Plugin) Name() string { - return PluginName -} - -// Available interface implementation -func (s *Plugin) Available() { -} - -// Collects all plugins which implement Name + RPCer interfaces -func (s *Plugin) Collects() []interface{} { - return []interface{}{ - s.RegisterPlugin, - } -} - -// RegisterPlugin registers RPC service plugin. -func (s *Plugin) RegisterPlugin(name endure.Named, p RPCer) { - s.plugins[name.Name()] = p -} - -// Register publishes in the server the set of methods of the -// receiver value that satisfy the following conditions: -// - exported method of exported type -// - two arguments, both of exported type -// - the second argument is a pointer -// - one return value, of type error -// It returns an error if the receiver is not an exported type or has -// no suitable methods. It also logs the error using package log. -func (s *Plugin) Register(name string, svc interface{}) error { - if s.rpc == nil { - return errors.E("RPC service is not configured") - } - - return s.rpc.RegisterName(name, svc) -} |