Documentation
¶
Index ¶
Constants ¶
const ( // IDSize is the size of the ID in bytes. IDSize int = 4 )
Variables ¶
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 ¶
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 ¶
NewRequest creates a request for given peer.ID
type RequestID ¶
type RequestID []byte
RequestID is a field that identifies request-response flows.
func RandomRequestID ¶
RandomRequestID creates and returns a new random request ID
func (RequestID) IsResponse ¶
IsResponse returns whether a RequestID identifies a response
type RequestMap ¶
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.