Documentation ¶
Overview ¶
Package server is used to wrap the p2p services to define multiple req-res messages under one protocol.
Index ¶
- type Item
- type Message
- type MessageServer
- func (p *MessageServer) Close()
- func (p *MessageServer) RegisterBytesMsgHandler(msgType MessageType, reqHandler func(context.Context, []byte) []byte)
- func (p *MessageServer) RegisterMsgHandler(msgType MessageType, reqHandler func(context.Context, Message) []byte)
- func (p *MessageServer) SendRequest(ctx context.Context, msgType MessageType, payload []byte, ...) error
- type MessageType
- type ResponseHandlers
- type Service
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Item ¶
type Item struct {
// contains filtered or unexported fields
}
Item is queue entry used to match responds to sent requests.
type Message ¶
type Message interface { service.DirectMessage Data() service.Data }
Message is helper type for `MessegeServer` messages.
type MessageServer ¶
type MessageServer struct { log.Log ReqID uint64 //request id // contains filtered or unexported fields }
MessageServer is a request-response multiplexer on top of the p2p layer. it provides a way to register message types on top of a protocol and declare request and response handlers. it matches incoming responses to requests.
func NewMsgServer ¶
func NewMsgServer(ctx context.Context, network Service, name string, requestLifetime time.Duration, c chan service.DirectMessage, logger log.Log) *MessageServer
NewMsgServer registers a protocol and returns a new server to declare request and response handlers on.
func (*MessageServer) RegisterBytesMsgHandler ¶
func (p *MessageServer) RegisterBytesMsgHandler(msgType MessageType, reqHandler func(context.Context, []byte) []byte)
RegisterBytesMsgHandler sets the handler to act on a specific message request.
func (*MessageServer) RegisterMsgHandler ¶
func (p *MessageServer) RegisterMsgHandler(msgType MessageType, reqHandler func(context.Context, Message) []byte)
RegisterMsgHandler sets the handler to act on a specific message request.
func (*MessageServer) SendRequest ¶
func (p *MessageServer) SendRequest(ctx context.Context, msgType MessageType, payload []byte, address p2pcrypto.PublicKey, resHandler func(msg []byte), timeoutHandler func(err error)) error
SendRequest sends a request of a specific message.
type MessageType ¶
type MessageType uint32
MessageType is a uint32 used to distinguish between server messages inside a single protocol.
type ResponseHandlers ¶ added in v0.1.16
type ResponseHandlers struct {
// contains filtered or unexported fields
}
ResponseHandlers contains handlers for received response handlers
type Service ¶
type Service interface { RegisterDirectProtocolWithChannel(protocol string, ingressChannel chan service.DirectMessage) chan service.DirectMessage SendWrappedMessage(ctx context.Context, nodeID p2pcrypto.PublicKey, protocol string, payload *service.DataMsgWrapper) error }
Service is the subset of method used by MessageServer for p2p communications.