rpc

package
v0.0.0-...-d8427d5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 3, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultPort is the port that the RPC server will listen on.
	DefaultPort uint16 = 44045
	// DefaultTimeout is the time the server will spend waiting for a response from other threads.
	DefaultTimeout = time.Second
)

Variables

View Source
var (
	// ErrTimeout is an error that is given if the RPC server isn't able to respond in time.
	ErrTimeout = errors.New("timed out waiting for internal response")
)

Functions

This section is empty.

Types

type Message

type Message struct {
	// Command is a command that comes from an RPC client.
	Command proto.DaemonCommand
	// Context is a context used to cancel downstream events. It should be set with a timeout.
	Context context.Context
	// ResponseCh is a channel to send a response down. The response may simply be nil, indicating
	// success. An error sent down this channel will likely be sent to the client (i3x3ctl).
	ResponseCh chan<- error
}

Message is a message container that provides the structure to have more of a request / response cycle. Once the message has been processed, a response can be issued by passing the result (an error, or nil) to the response channel.

func NewMessage

func NewMessage(ctx context.Context, command *proto.DaemonCommand) (Message, chan error)

NewMessage creates a new RPC message, and returns a channel that a response should be passed to.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service is the GRPC server used to listen to commands to control i3x3. At it's core, it is what propagates messages throughout the application.

func NewService

func NewService(logger log15.Logger, msgCh chan<- Message) *Service

NewService creates a new i3x3 RPC server.

func (*Service) HandleCommand

func (s *Service) HandleCommand(ctx context.Context, cmd *proto.DaemonCommand) (*proto.DaemonCommandResponse, error)

HandleCommand routes a command through the application so that it may be handled appropriately by other

type Thread

type Thread struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Thread is a thread that when started will start an RPC server.

func NewThread

func NewThread(logger log15.Logger, service *Service) *Thread

NewThread creates a new RPC thread.

func (*Thread) Start

func (t *Thread) Start() error

Start attempts to start listening on the configured port.

func (*Thread) Stop

func (t *Thread) Stop() error

Stop gracefully stops this server.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL