rpc

package
v0.0.0-...-6f2a98a Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2016 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrClosedConn is the error returned when the underlying listener has been closed
	ErrClosedConn = errors.New("use of closed network connection")
)

Functions

This section is empty.

Types

type DialerFn

type DialerFn func(address string, timeout time.Duration) (net.Conn, error)

DialerFn is the function the StreamLayer should use to Dial out to another node

type Handler

type Handler interface {
	net.Listener
	Handoff(net.Conn)
}

Handler is an interface for implementing the backends used by RPC Server

type Request

type Request struct {
	Method string
	Args   []string
}

Request is the structure used for making RPC requests

type Response

type Response struct {
	Err string
}

Response is what's returned from RPC requests

type Server

type Server struct {
	net.Listener
	// contains filtered or unexported fields
}

Server handles routing from an an incoming conneciton to a specified backend. These backends are determined based on the 1st byte read from the incoming connection

func NewServer

func NewServer(l net.Listener, handlers map[byte]Handler) *Server

NewServer creates a new RPC server

type StreamLayer

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

StreamLayer is used for handling rpc requests between nodes (be it raft, or other custom RPC) When a request comes into an RPC Server, the Server will route it to the appropriate StreamLayer StreamLayer implements raft.StreamLayer and net.Listener

func NewStreamLayer

func NewStreamLayer(addr net.Addr, rpcType byte, dialer DialerFn) *StreamLayer

NewStreamLayer creates a new StreamLayer `addr` is used so this can implement the net.Listener interface `rpcType` is the type of Message this StreamLayer will handle

func (*StreamLayer) Accept

func (l *StreamLayer) Accept() (net.Conn, error)

Accept waits for and returns the next connection

func (*StreamLayer) Addr

func (l *StreamLayer) Addr() net.Addr

Addr returns the address the stremLayer is listening on This is used to satisfy the net.Listener interface

func (*StreamLayer) Close

func (l *StreamLayer) Close() error

Close shuts down the stream layer

func (*StreamLayer) Dial

func (l *StreamLayer) Dial(address string, timeout time.Duration) (net.Conn, error)

Dial is used by Raft for RPC

func (*StreamLayer) DialWithRetry

func (l *StreamLayer) DialWithRetry(address string, timeout time.Duration, retry bool) (net.Conn, error)

DialWithRetry is like `Dial` but uses a retry mechanism

func (*StreamLayer) Handoff

func (l *StreamLayer) Handoff(conn net.Conn)

Handoff is used by the RPC server hand-off a conn to this StreamLayer

func (*StreamLayer) ProxyRequest

func (l *StreamLayer) ProxyRequest(addr string, msg *Request, from io.ReadWriter) error

ProxyRequest is a helper function to proxy an rpc request to another node

func (*StreamLayer) RPC

func (l *StreamLayer) RPC(addr string, msg *Request) (*Response, error)

RPC is a helper function for performing RPC requests between nodes

Jump to

Keyboard shortcuts

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