service

package
v0.0.0-...-e4696f9 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2014 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// IDSize is the size of the ID in bytes.
	IDSize int = 4
)

Variables

View Source
var ErrNoResponse = errors.New("no response to request")

ErrNoResponse is returned by Service when a Request did not get a response, and no other error happened

Functions

func RequestKey

func RequestKey(pid peer.ID, rid RequestID) string

RequestKey is the peer.ID concatenated with the RequestID. Use with maps.

Types

type Handler

type Handler interface {

	// HandleMessage receives an incoming message, and potentially returns
	// a response message to send back.
	HandleMessage(context.Context, msg.NetMessage) msg.NetMessage
}

Handler is an interface that objects must implement in order to handle a service's requests.

type Request

type Request struct {

	// ID is the RequestID identifying this Request-Response Flow.
	ID RequestID

	// PeerID identifies the peer from whom to expect the response.
	PeerID peer.ID

	// Response is the channel of incoming responses.
	Response chan msg.NetMessage
}

Request objects are used to multiplex request-response flows.

func NewRequest

func NewRequest(pid peer.ID) (*Request, error)

NewRequest creates a request for given peer.ID

func (*Request) Key

func (r *Request) Key() string

Key returns the RequestKey for this request. Use with maps.

type RequestID

type RequestID []byte

RequestID is a field that identifies request-response flows.

func RandomRequestID

func RandomRequestID() (RequestID, error)

RandomRequestID creates and returns a new random request ID

func (RequestID) IsRequest

func (r RequestID) IsRequest() bool

IsRequest returns whether a RequestID identifies a request

func (RequestID) IsResponse

func (r RequestID) IsResponse() bool

IsResponse returns whether a RequestID identifies a response

func (RequestID) Request

func (r RequestID) Request() RequestID

Request turns a RequestID into a Request (unsetting first bit)

func (RequestID) Response

func (r RequestID) Response() RequestID

Response turns a RequestID into a Response (setting first bit)

type RequestMap

type RequestMap map[string]*Request

RequestMap is a map of Requests. the key = (peer.ID concat RequestID).

type Sender

type Sender interface {
	// SendMessage sends out a given message, without expecting a response.
	SendMessage(ctx context.Context, m msg.NetMessage) error

	// SendRequest sends out a given message, and awaits a response.
	// Set Deadlines or cancellations in the context.Context you pass in.
	SendRequest(ctx context.Context, m msg.NetMessage) (msg.NetMessage, error)
}

Sender interface for network services.

type Service

type Service interface {
	Sender
	ctxc.ContextCloser

	// GetPipe
	GetPipe() *msg.Pipe

	// SetHandler assigns the request Handler for this service.
	SetHandler(Handler)
	GetHandler() Handler
}

Service is an interface for a net resource with both outgoing (sender) and incomig (SetHandler) requests.

func NewService

func NewService(ctx context.Context, h Handler) Service

NewService creates a service object with given type ID and Handler

Directories

Path Synopsis
internal
pb
Package service_pb is a generated protocol buffer package.
Package service_pb is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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