Documentation ¶
Overview ¶
Package messenger contains the default implementation for interface infra.Messenger. Sent and received messages must be one of the supported types below.
The following message types are valid messages. At the moment, no signature verification is performed on the SignedPld.
ChainRequest -> ctrl.SignedPld/ctrl.Pld/cert_mgmt.ChainReq Chain -> ctrl.SignedPld/ctrl.Pld/cert_mgmt.Chain TRCRequest -> ctrl.SignedPld/ctrl.Pld/cert_mgmt.TRCReq TRC -> ctrl.SignedPld/ctrl.Pld/cert_mgmt.TRC PathRequest -> ctrl.SignedPld/ctrl.Pld/path_mgmt.SegReq
The word "reliable" in method descriptions means a reliable protocol is used to deliver that message.
To start processing messages received via the Messenger, call ListenAndServe. The method runs in the current goroutine, and spawns new goroutines to handle each received message:
msger := New(...) msger.ListenAndServe()
ListenAndServe will log errors for all received messages. To process messages, handlers need to be registered. Handlers allow different infrastructure servers to choose which requests they service, and to exploit shared functionality. One handler can be registered for each message type, identified by its msgType string:
msger.AddHandler(ChainRequest, MyCustomHandler) msger.AddHandler(TRCRequest, MyOtherCustomHandler)
Each handler runs indepedently (i.e., without any synchronization) until completion. Goroutines inherit a reference to the Messenger via the infra.MessengerContextKey context key. This allows handlers to directly send network messages.
Some default handlers are already implemented; for more information, see their package documentation:
trust.*Store.NewChainReqHandler trust.*Store.NewTRCReqHandler trust.*Store.NewPushChainHandler trust.*Store.NewPushTRCHandler
Shut down the server and any running handlers using CloseServer():
msger.CloseServer()
CloseServer() does not do graceful shutdown of the handlers and does not close the Messenger itself.
Index ¶
- Constants
- Variables
- type Adapter
- type Messenger
- func (m *Messenger) AddHandler(msgType string, handler infra.Handler)
- func (m *Messenger) CloseServer() error
- func (m *Messenger) GetCertChain(ctx context.Context, msg *cert_mgmt.ChainReq, a net.Addr, id uint64) (*cert_mgmt.Chain, error)
- func (m *Messenger) GetPaths(ctx context.Context, msg *path_mgmt.SegReq, a net.Addr, id uint64) (*path_mgmt.SegReply, error)
- func (m *Messenger) GetTRC(ctx context.Context, msg *cert_mgmt.TRCReq, a net.Addr, id uint64) (*cert_mgmt.TRC, error)
- func (m *Messenger) ListenAndServe()
- func (m *Messenger) SendCertChain(ctx context.Context, msg *cert_mgmt.Chain, a net.Addr, id uint64) error
- func (m *Messenger) SendTRC(ctx context.Context, msg *cert_mgmt.TRC, a net.Addr, id uint64) error
Constants ¶
const ( ChainRequest = "ChainRequest" Chain = "Chain" TRCRequest = "TRCRequest" TRC = "TRC" )
Variables ¶
var DefaultAdapter = &Adapter{}
Default adapter
Functions ¶
This section is empty.
Types ¶
type Adapter ¶
type Adapter struct{}
Adapter implements disp.MessageAdapter for ctrl.SignedPld.
type Messenger ¶
type Messenger struct {
// contains filtered or unexported fields
}
Messenger exposes the API for sending and receiving CtrlPld messages.
func New ¶
func New(dispatcher *disp.Dispatcher, store infra.TrustStore, logger log.Logger) *Messenger
New creates a new Messenger that uses dispatcher for sending and receiving messages, and trustStore as crypto information database.
func (*Messenger) AddHandler ¶
AddHandler registers a handler for msgType.
func (*Messenger) CloseServer ¶
CloseServer stops any running ListenAndServe functions, and cancels all running handlers. The server's Messenger layer is not closed.
func (*Messenger) GetCertChain ¶
func (m *Messenger) GetCertChain(ctx context.Context, msg *cert_mgmt.ChainReq, a net.Addr, id uint64) (*cert_mgmt.Chain, error)
GetCertChain sends a cert_mgmt.ChainReq to address a, blocks until it receives a reply and returns the reply.
func (*Messenger) GetPaths ¶
func (m *Messenger) GetPaths(ctx context.Context, msg *path_mgmt.SegReq, a net.Addr, id uint64) (*path_mgmt.SegReply, error)
GetPaths asks the server at the remote address for the paths specified by msg, and returns a verified reply.
func (*Messenger) GetTRC ¶
func (m *Messenger) GetTRC(ctx context.Context, msg *cert_mgmt.TRCReq, a net.Addr, id uint64) (*cert_mgmt.TRC, error)
GetTRC sends a cert_mgmt.TRCReq request to address a, blocks until it receives a reply and returns the reply.
func (*Messenger) ListenAndServe ¶
func (m *Messenger) ListenAndServe()
ListenAndServe starts listening and serving messages on srv's Messenger interface. The function runs in the current goroutine. Multiple ListenAndServe methods can run in parallel.