Documentation ¶
Overview ¶
Package messenger contains the default implementation for interface infra.Messenger. Sent and received messages must be one of the supported types below:
infra.ChainRequest -> ctrl.SignedPld/ctrl.Pld/cert_mgmt.ChainReq infra.Chain -> ctrl.SignedPld/ctrl.Pld/cert_mgmt.Chain infra.TRCRequest -> ctrl.SignedPld/ctrl.Pld/cert_mgmt.TRCReq infra.TRC -> ctrl.SignedPld/ctrl.Pld/cert_mgmt.TRC infra.IfStateInfos -> ctrl.SignedPld/ctrl.Pld/path_mgmt.IFStateInfos infra.SegChangesReq -> ctrl.SignedPld/ctrl.Pld/path_mgmt.SegChangesReq infra.SegChangesReply -> ctrl.SignedPld/ctrl.Pld/path_mgmt.SegChangesReply infra.SegChangesIdReq -> ctrl.SignedPld/ctrl.Pld/path_mgmt.SegChangesIdReq infra.SegChangesIdReply -> ctrl.SignedPld/ctrl.Pld/path_mgmt.SegChangesIdReply infra.SegReq -> ctrl.SignedPld/ctrl.Pld/path_mgmt.SegReg infra.SegRequest -> ctrl.SignedPld/ctrl.Pld/path_mgmt.SegReq infra.SegReply -> ctrl.SignedPld/ctrl.Pld/path_mgmt.SegReply infra.SegRev -> ctrl.SignedPld/ctrl.Pld/path_mgmt.SRevInfo infra.SegSync -> ctrl.SignedPld/ctrl.Pld/path_mgmt.SegSync infra.ChainIssueRequest -> ctrl.SignedPld/ctrl.Pld/cert_mgmt.ChainIssReq infra.ChainIssueReply -> ctrl.SignedPld/ctrl.Pld/cert_mgmt.ChainIssRep
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(infra.ChainRequest, MyCustomHandler) msger.AddHandler(infra.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.NewChainPushHandler trust.*Store.NewTRCPushHandler
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
- func NewPathingRequester(signer ctrl.Signer, sigv ctrl.SigVerifier, d *disp.Dispatcher, local addr.IA) *pathingRequester
- type Adapter
- type Config
- type Counter
- type Messenger
- func (m *Messenger) AddHandler(msgType infra.MessageType, 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) GetSegChanges(ctx context.Context, msg *path_mgmt.SegChangesReq, a net.Addr, id uint64) (*path_mgmt.SegChangesReply, error)
- func (m *Messenger) GetSegChangesIds(ctx context.Context, msg *path_mgmt.SegChangesIdReq, a net.Addr, id uint64) (*path_mgmt.SegChangesIdReply, error)
- func (m *Messenger) GetSegs(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) RequestChainIssue(ctx context.Context, msg *cert_mgmt.ChainIssReq, a net.Addr, id uint64) (*cert_mgmt.ChainIssRep, error)
- func (m *Messenger) SendCertChain(ctx context.Context, msg *cert_mgmt.Chain, a net.Addr, id uint64) error
- func (m *Messenger) SendChainIssueReply(ctx context.Context, msg *cert_mgmt.ChainIssRep, a net.Addr, id uint64) error
- func (m *Messenger) SendSegChangesIdReply(ctx context.Context, msg *path_mgmt.SegChangesIdReply, a net.Addr, id uint64) error
- func (m *Messenger) SendSegChangesReply(ctx context.Context, msg *path_mgmt.SegChangesReply, a net.Addr, id uint64) error
- func (m *Messenger) SendSegReply(ctx context.Context, msg *path_mgmt.SegReply, a net.Addr, id uint64) error
- func (m *Messenger) SendSegSync(ctx context.Context, msg *path_mgmt.SegSync, a net.Addr, id uint64) error
- func (m *Messenger) SendTRC(ctx context.Context, msg *cert_mgmt.TRC, a net.Addr, id uint64) error
- func (m *Messenger) UpdateSigner(signer ctrl.Signer, types []infra.MessageType)
- func (m *Messenger) UpdateVerifier(verifier ctrl.SigVerifier)
Constants ¶
const (
DefaultHandlerTimeout = 10 * time.Second
)
Variables ¶
var DefaultAdapter = &Adapter{}
Default adapter
Functions ¶
func NewPathingRequester ¶ added in v0.2.0
func NewPathingRequester(signer ctrl.Signer, sigv ctrl.SigVerifier, d *disp.Dispatcher, local addr.IA) *pathingRequester
Types ¶
type Adapter ¶
type Adapter struct{}
Adapter implements disp.MessageAdapter for ctrl.SignedPld.
type Config ¶ added in v0.1.1
type Config struct { // HandlerTimeout is the amount of time allocated to the processing of a // received message. This includes the time needed to verify the signature // and the execution of a registered handler (if one exists). If the // timeout is 0, the default is used. HandlerTimeout time.Duration // DisableSignatureVerification can be set to true to disable the // verification of the top level signature in received signed control // payloads. DisableSignatureVerification bool }
Config can be used to customize the behavior of the Messenger.
type Messenger ¶
type Messenger struct {
// contains filtered or unexported fields
}
Messenger exposes the API for sending and receiving CtrlPld messages.
func New ¶
func New(ia addr.IA, dispatcher *disp.Dispatcher, store infra.TrustStore, logger log.Logger, config *Config) *Messenger
New creates a new Messenger that uses dispatcher for sending and receiving messages, and trustStore as crypto information database.
func (*Messenger) AddHandler ¶
func (m *Messenger) AddHandler(msgType infra.MessageType, handler infra.Handler)
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) GetSegChanges ¶ added in v0.3.0
func (*Messenger) GetSegChangesIds ¶ added in v0.3.0
func (*Messenger) GetSegs ¶ added in v0.3.0
func (m *Messenger) GetSegs(ctx context.Context, msg *path_mgmt.SegReq, a net.Addr, id uint64) (*path_mgmt.SegReply, error)
GetSegs asks the server at the remote address for the path segments that satisfy 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.
func (*Messenger) RequestChainIssue ¶ added in v0.1.1
func (*Messenger) SendCertChain ¶
func (m *Messenger) SendCertChain(ctx context.Context, msg *cert_mgmt.Chain, a net.Addr, id uint64) error
SendCertChain sends a reliable cert_mgmt.Chain to address a.
func (*Messenger) SendChainIssueReply ¶ added in v0.1.1
func (*Messenger) SendSegChangesIdReply ¶ added in v0.3.0
func (*Messenger) SendSegChangesReply ¶ added in v0.3.0
func (*Messenger) SendSegReply ¶ added in v0.3.0
func (m *Messenger) SendSegReply(ctx context.Context, msg *path_mgmt.SegReply, a net.Addr, id uint64) error
SendSegReply sends a reliable path_mgmt.SegReply to address a.
func (*Messenger) SendSegSync ¶ added in v0.3.0
func (m *Messenger) SendSegSync(ctx context.Context, msg *path_mgmt.SegSync, a net.Addr, id uint64) error
SendSegSync sends a reliable path_mgmt.SegSync to address a.
func (*Messenger) UpdateSigner ¶ added in v0.1.1
func (m *Messenger) UpdateSigner(signer ctrl.Signer, types []infra.MessageType)
UpdateSigner enables signing of messages with signer. Only the messages in types are signed, the rest are left with a null signature. If types is nil, only the signer is updated and the existing internal list of types is unchanged. An empty slice of types disables signing for all messages.
func (*Messenger) UpdateVerifier ¶ added in v0.1.1
func (m *Messenger) UpdateVerifier(verifier ctrl.SigVerifier)
UpdateVerifier enables verifying of messages with verifier.
FIXME(scrye): Verifiers are usually bound to a trust store to which the messenger already holds a reference. We should decouple the trust store from either one or the other.