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.PathSegmentRequest -> ctrl.SignedPld/ctrl.Pld/path_mgmt.SegReq infra.PathSegmentReply -> ctrl.SignedPld/ctrl.Pld/path_mgmt.SegReply 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
- 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) GetPathSegs(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) 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)
- type MockAddress
- type MockMessenger
- func (m *MockMessenger) AddHandler(msgType infra.MessageType, h infra.Handler)
- func (m *MockMessenger) CloseServer() error
- func (m *MockMessenger) GetCertChain(ctx context.Context, msg *cert_mgmt.ChainReq, a net.Addr, id uint64) (*cert_mgmt.Chain, error)
- func (m *MockMessenger) GetPathSegs(ctx context.Context, msg *path_mgmt.SegReq, a net.Addr, id uint64) (*path_mgmt.SegReply, error)
- func (m *MockMessenger) GetTRC(ctx context.Context, msg *cert_mgmt.TRCReq, a net.Addr, id uint64) (*cert_mgmt.TRC, error)
- func (m *MockMessenger) ListenAndServe()
- func (m *MockMessenger) RecvMsg(ctx context.Context) (proto.Cerealizable, net.Addr, error)
- func (m *MockMessenger) RequestChainIssue(ctx context.Context, msg *cert_mgmt.ChainIssReq, a net.Addr, id uint64) (*cert_mgmt.ChainIssRep, error)
- func (m *MockMessenger) SendCertChain(ctx context.Context, msg *cert_mgmt.Chain, a net.Addr, id uint64) error
- func (m *MockMessenger) SendChainIssueReply(ctx context.Context, msg *cert_mgmt.ChainIssRep, a net.Addr, id uint64) error
- func (m *MockMessenger) SendTRC(ctx context.Context, msg *cert_mgmt.TRC, a net.Addr, id uint64) error
Constants ¶
const (
DefaultHandlerTimeout = 10 * time.Second
)
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 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(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) GetPathSegs ¶
func (m *Messenger) GetPathSegs(ctx context.Context, msg *path_mgmt.SegReq, a net.Addr, id uint64) (*path_mgmt.SegReply, error)
GetPathSegs 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) 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.
type MockAddress ¶
type MockAddress struct{}
func (*MockAddress) Network ¶
func (f *MockAddress) Network() string
func (*MockAddress) String ¶
func (f *MockAddress) String() string
type MockMessenger ¶
func (*MockMessenger) AddHandler ¶
func (m *MockMessenger) AddHandler(msgType infra.MessageType, h infra.Handler)
func (*MockMessenger) CloseServer ¶
func (m *MockMessenger) CloseServer() error
func (*MockMessenger) GetCertChain ¶
func (*MockMessenger) GetPathSegs ¶
func (*MockMessenger) ListenAndServe ¶
func (m *MockMessenger) ListenAndServe()
func (*MockMessenger) RecvMsg ¶
func (m *MockMessenger) RecvMsg(ctx context.Context) (proto.Cerealizable, net.Addr, error)
func (*MockMessenger) RequestChainIssue ¶ added in v0.1.1
func (m *MockMessenger) RequestChainIssue(ctx context.Context, msg *cert_mgmt.ChainIssReq, a net.Addr, id uint64) (*cert_mgmt.ChainIssRep, error)
func (*MockMessenger) SendCertChain ¶
func (*MockMessenger) SendChainIssueReply ¶ added in v0.1.1
func (m *MockMessenger) SendChainIssueReply(ctx context.Context, msg *cert_mgmt.ChainIssRep, a net.Addr, id uint64) error