messenger

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2019 License: Apache-2.0 Imports: 37 Imported by: 0

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.IfId                -> ctrl.SignedPld/ctrl.Pld/ifid.IFID
infra.IfStateInfos        -> ctrl.SignedPld/ctrl.Pld/path_mgmt.IFStateInfos
infra.IfStateReq          -> ctrl.SignedPld/ctrl.Pld/path_mgmt.IFStateReq
infra.Seg                 -> ctrl.SignedPld/ctrl.Pld/seg.PathSegment
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.SegReg              -> 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.SignedRev           -> ctrl.SignedPld/ctrl.Pld/path_mgmt.SignedRevInfo
infra.SegSync             -> ctrl.SignedPld/ctrl.Pld/path_mgmt.SegSync
infra.HPSegReg            -> ctrl.SignedPld/ctrl.Pld/path_mgmt.HPSegReg
infra.HPSegRequest        -> ctrl.SignedPld/ctrl.Pld/path_mgmt.HPSegReq
infra.HPSegReply          -> ctrl.SignedPld/ctrl.Pld/path_mgmt.HPSegReply
infra.HPCfgRequest        -> ctrl.SignedPld/ctrl.Pld/path_mgmt.HPCfgReq
infra.HPCfgReply          -> ctrl.SignedPld/ctrl.Pld/path_mgmt.HPCfgReply
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

View Source
const (
	AckRejectFailedToParse  = "Failed to parse"
	AckRejectFailedToVerify = "Failed to verfiy"
	AckRejectPolicyError    = "Message rejected due to policy"
	AckRetryDBError         = "DB Error"
)
View Source
const (
	DefaultHandlerTimeout = 10 * time.Second
)

Variables

View Source
var DefaultAdapter = &Adapter{}

Default adapter

Functions

func BuildReply added in v0.4.0

func BuildReply(address *addr.AppAddr) *svc.Reply

BuildReply constructs a reply from an application address. If the application address is not well formed (has L3, has L4, UDP/IP protocols), the returned reply is non-nil and empty.

func NextId added in v0.4.0

func NextId() uint64

NextId is a concurrency-safe generator of unique request IDs for the messenger.

func SendAckHelper added in v0.4.0

func SendAckHelper(ctx context.Context, rw infra.ResponseWriter) func(proto.Ack_ErrCode, string)

SendAckHelper binds the given arguments and returns a function that is convenient to call. This is only to reduce boilerplate code in message handlers. Note that ctx should have a logger attached.

Types

type Adapter

type Adapter struct{}

Adapter implements disp.MessageAdapter for ctrl.SignedPld.

func (*Adapter) MsgKey

func (a *Adapter) MsgKey(msg proto.Cerealizable) string

func (*Adapter) MsgToRaw

func (a *Adapter) MsgToRaw(msg proto.Cerealizable) (common.RawBytes, error)

func (*Adapter) RawToMsg

func (a *Adapter) RawToMsg(b common.RawBytes) (proto.Cerealizable, error)

type AddressRewriter added in v0.4.0

type AddressRewriter struct {
	// Router obtains path information to fill in address paths, if they are
	// required and missing.
	Router snet.Router
	// SVCRouter builds overlay addresses for intra-AS SVC traffic, based on
	// information found in the topology.
	SVCRouter LocalSVCRouter
	// Resolver performs SVC resolution if enabled.
	Resolver Resolver
	// SVCResolutionFraction enables SVC resolution for traffic to SVC
	// destinations in a way that is also compatible with control plane servers
	// that do not implement the SVC Resolution Mechanism. The value represents
	// the percentage of time, out of the total available context timeout,
	// spent attempting to perform SVC resolution. If SVCResolutionFraction is
	// 0 or less, SVC resolution is never attempted. If it is between 0 and 1,
	// the remaining context timeout is multiplied by the value, and that
	// amount of time is spent waiting for an SVC resolution reply from the
	// server. If this times out, the data packet is sent with an SVC
	// destination. If the value is 1 or more, then legacy behavior is
	// disabled, and data packets are never sent to SVC destinations unless the
	// resolution step is successful.
	SVCResolutionFraction float64
}

AddressRewriter is used to compute paths and replace SVC destinations with unicast addresses.

func (AddressRewriter) RedirectToQUIC added in v0.4.0

func (r AddressRewriter) RedirectToQUIC(ctx context.Context, a net.Addr) (net.Addr, bool, error)

RedirectToQUIC takes an address and adds a path (if one does not already exist but is required), and replaces SVC destinations with QUIC unicast ones, if possible.

The returned boolean value is set to true if the remote server is QUIC-compatible and we have successfully discovered its address.

If the address is already unicast, no redirection to QUIC is attempted.

type Config added in v0.1.1

type Config struct {
	// IA is the local ISD-AS number.
	IA addr.IA
	// Dispatcher to use for associating requests with replies.
	Dispatcher *disp.Dispatcher
	// AddressRewriter is used to compute paths and replace SVC destinations with
	// unicast addresses.
	AddressRewriter *AddressRewriter
	// 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
	// Logger is used for internal Messenger logging. If it is nil, the default
	// root logger is used.
	Logger log.Logger
	// QUIC defines whether the Messenger should also operate on top of QUIC
	// instead of only on UDP.
	QUIC *QUICConfig
}

Config can be used to customize the behavior of the Messenger.

func (*Config) InitDefaults added in v0.4.0

func (c *Config) InitDefaults()

type LocalSVCRouter added in v0.4.0

type LocalSVCRouter interface {
	// GetOverlay returns the overlay address of a SVC server of the specified
	// type. When multiple servers are available, the choice is random.
	GetOverlay(svc addr.HostSVC) (*overlay.OverlayAddr, error)
}

LocalSVCRouter is used to construct overlay information for SVC servers running in the local AS.

func NewSVCRouter added in v0.4.0

func NewSVCRouter(tp itopo.ProviderI) LocalSVCRouter

NewSVCRouter build a SVC router backed by topology information from the specified provider.

type Messenger

type Messenger struct {
	// contains filtered or unexported fields
}

Messenger exposes the API for sending and receiving CtrlPld messages.

func New

func New(config *Config) *Messenger

New creates a new Messenger based on config.

func (*Messenger) AddHandler

func (m *Messenger) AddHandler(msgType infra.MessageType, handler infra.Handler)

AddHandler registers a handler for msgType.

func (*Messenger) CloseServer

func (m *Messenger) CloseServer() error

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)

func (*Messenger) GetHPCfgs added in v0.4.0

func (m *Messenger) GetHPCfgs(ctx context.Context, msg *path_mgmt.HPCfgReq, a net.Addr,
	id uint64) (*path_mgmt.HPCfgReply, error)

func (*Messenger) GetHPSegs added in v0.4.0

func (m *Messenger) GetHPSegs(ctx context.Context, msg *path_mgmt.HPSegReq, a net.Addr,
	id uint64) (*path_mgmt.HPSegReply, error)

func (*Messenger) GetSegChanges added in v0.3.0

func (m *Messenger) GetSegChanges(ctx context.Context, msg *path_mgmt.SegChangesReq,
	a net.Addr, id uint64) (*path_mgmt.SegChangesReply, error)

func (*Messenger) GetSegChangesIds added in v0.3.0

func (m *Messenger) GetSegChangesIds(ctx context.Context, msg *path_mgmt.SegChangesIdReq,
	a net.Addr, id uint64) (*path_mgmt.SegChangesIdReply, error)

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)

func (*Messenger) GetTRC

func (m *Messenger) GetTRC(ctx context.Context, msg *cert_mgmt.TRCReq,
	a net.Addr, id uint64) (*cert_mgmt.TRC, error)

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 (m *Messenger) RequestChainIssue(ctx context.Context, msg *cert_mgmt.ChainIssReq, a net.Addr,
	id uint64) (*cert_mgmt.ChainIssRep, error)

func (*Messenger) SendAck added in v0.4.0

func (m *Messenger) SendAck(ctx context.Context, msg *ack.Ack, a net.Addr, id uint64) error

func (*Messenger) SendBeacon added in v0.4.0

func (m *Messenger) SendBeacon(ctx context.Context, msg *seg.Beacon, a net.Addr, id uint64) error

func (*Messenger) SendCertChain

func (m *Messenger) SendCertChain(ctx context.Context, msg *cert_mgmt.Chain, a net.Addr,
	id uint64) error

func (*Messenger) SendChainIssueReply added in v0.1.1

func (m *Messenger) SendChainIssueReply(ctx context.Context, msg *cert_mgmt.ChainIssRep,
	a net.Addr, id uint64) error

func (*Messenger) SendHPCfgReply added in v0.4.0

func (m *Messenger) SendHPCfgReply(ctx context.Context, msg *path_mgmt.HPCfgReply, a net.Addr,
	id uint64) error

func (*Messenger) SendHPSegReg added in v0.4.0

func (m *Messenger) SendHPSegReg(ctx context.Context, msg *path_mgmt.HPSegReg, a net.Addr,
	id uint64) error

func (*Messenger) SendHPSegReply added in v0.4.0

func (m *Messenger) SendHPSegReply(ctx context.Context, msg *path_mgmt.HPSegReply, a net.Addr,
	id uint64) error

func (*Messenger) SendIfId added in v0.4.0

func (m *Messenger) SendIfId(ctx context.Context, msg *ifid.IFID, a net.Addr, id uint64) error

func (*Messenger) SendIfStateInfos added in v0.4.0

func (m *Messenger) SendIfStateInfos(ctx context.Context, msg *path_mgmt.IFStateInfos,
	a net.Addr, id uint64) error

func (*Messenger) SendRev added in v0.4.0

func (m *Messenger) SendRev(ctx context.Context, msg *path_mgmt.SignedRevInfo,
	a net.Addr, id uint64) error

func (*Messenger) SendSegChangesIdReply added in v0.3.0

func (m *Messenger) SendSegChangesIdReply(ctx context.Context, msg *path_mgmt.SegChangesIdReply,
	a net.Addr, id uint64) error

func (*Messenger) SendSegChangesReply added in v0.3.0

func (m *Messenger) SendSegChangesReply(ctx context.Context, msg *path_mgmt.SegChangesReply,
	a net.Addr, id uint64) error

func (*Messenger) SendSegReg added in v0.4.0

func (m *Messenger) SendSegReg(ctx context.Context, msg *path_mgmt.SegReg,
	a net.Addr, id uint64) error

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

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

func (*Messenger) SendTRC

func (m *Messenger) SendTRC(ctx context.Context, msg *cert_mgmt.TRC, a net.Addr, id uint64) error

func (*Messenger) UpdateSigner added in v0.1.1

func (m *Messenger) UpdateSigner(signer infra.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 infra.Verifier)

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 QUICConfig added in v0.4.0

type QUICConfig struct {
	Conn       net.PacketConn
	TLSConfig  *tls.Config
	QUICConfig *quic.Config
}

type QUICHandler added in v0.4.0

type QUICHandler struct {
	// contains filtered or unexported fields
}

QUICHandler is a QUIC RPC handler for Messenger messages. Infra handlers can be registered for various message types by calling Handle.

func (*QUICHandler) Handle added in v0.4.0

func (h *QUICHandler) Handle(msgType infra.MessageType, handler infra.Handler)

Handle registers the handler for the given message type.

func (*QUICHandler) ServeRPC added in v0.4.0

func (h *QUICHandler) ServeRPC(rw rpc.ReplyWriter, request *rpc.Request)

type QUICRequester added in v0.4.0

type QUICRequester struct {
	QUICClientConfig *rpc.Client
	AddressRewriter  *AddressRewriter
	Signer           ctrl.Signer
}

func (*QUICRequester) Request added in v0.4.0

func (r *QUICRequester) Request(ctx context.Context, pld *ctrl.Pld,
	a net.Addr) (*ctrl.Pld, error)

type QUICResponseWriter added in v0.4.0

type QUICResponseWriter struct {
	ReplyWriter rpc.ReplyWriter
	ID          uint64
}

QUICResponseWriter implements the infra ResponseWriter over QUIC.

func (*QUICResponseWriter) SendAckReply added in v0.4.0

func (rw *QUICResponseWriter) SendAckReply(ctx context.Context, msg *ack.Ack) error

func (*QUICResponseWriter) SendCertChainReply added in v0.4.0

func (rw *QUICResponseWriter) SendCertChainReply(ctx context.Context, msg *cert_mgmt.Chain) error

func (*QUICResponseWriter) SendChainIssueReply added in v0.4.0

func (rw *QUICResponseWriter) SendChainIssueReply(ctx context.Context,
	msg *cert_mgmt.ChainIssRep) error

func (*QUICResponseWriter) SendHPCfgReply added in v0.4.0

func (rw *QUICResponseWriter) SendHPCfgReply(ctx context.Context, msg *path_mgmt.HPCfgReply) error

func (*QUICResponseWriter) SendHPSegReply added in v0.4.0

func (rw *QUICResponseWriter) SendHPSegReply(ctx context.Context, msg *path_mgmt.HPSegReply) error

func (*QUICResponseWriter) SendIfStateInfoReply added in v0.4.0

func (rw *QUICResponseWriter) SendIfStateInfoReply(ctx context.Context,
	msg *path_mgmt.IFStateInfos) error

func (*QUICResponseWriter) SendSegReply added in v0.4.0

func (rw *QUICResponseWriter) SendSegReply(ctx context.Context, msg *path_mgmt.SegReply) error

func (*QUICResponseWriter) SendTRCReply added in v0.4.0

func (rw *QUICResponseWriter) SendTRCReply(ctx context.Context, msg *cert_mgmt.TRC) error

type Resolver added in v0.4.0

type Resolver interface {
	// LookupSVC resolves the SVC address for the AS terminating the path.
	LookupSVC(ctx context.Context, path snet.Path, svc addr.HostSVC) (*svc.Reply, error)
}

Resolver performs SVC resolution for a remote AS, thus converting an anycast SVC address to a unicast IP/UDP one.

type UDPResponseWriter added in v0.4.0

type UDPResponseWriter struct {
	Messenger infra.Messenger
	Remote    net.Addr
	ID        uint64
}

func (*UDPResponseWriter) SendAckReply added in v0.4.0

func (rw *UDPResponseWriter) SendAckReply(ctx context.Context, msg *ack.Ack) error

func (*UDPResponseWriter) SendCertChainReply added in v0.4.0

func (rw *UDPResponseWriter) SendCertChainReply(ctx context.Context, msg *cert_mgmt.Chain) error

func (*UDPResponseWriter) SendChainIssueReply added in v0.4.0

func (rw *UDPResponseWriter) SendChainIssueReply(ctx context.Context,
	msg *cert_mgmt.ChainIssRep) error

func (*UDPResponseWriter) SendHPCfgReply added in v0.4.0

func (rw *UDPResponseWriter) SendHPCfgReply(ctx context.Context, msg *path_mgmt.HPCfgReply) error

func (*UDPResponseWriter) SendHPSegReply added in v0.4.0

func (rw *UDPResponseWriter) SendHPSegReply(ctx context.Context, msg *path_mgmt.HPSegReply) error

func (*UDPResponseWriter) SendIfStateInfoReply added in v0.4.0

func (rw *UDPResponseWriter) SendIfStateInfoReply(ctx context.Context,
	msg *path_mgmt.IFStateInfos) error

func (*UDPResponseWriter) SendSegReply added in v0.4.0

func (rw *UDPResponseWriter) SendSegReply(ctx context.Context, msg *path_mgmt.SegReply) error

func (*UDPResponseWriter) SendTRCReply added in v0.4.0

func (rw *UDPResponseWriter) SendTRCReply(ctx context.Context, msg *cert_mgmt.TRC) error

Directories

Path Synopsis
internal
Package mock_messenger is a generated GoMock package.
Package mock_messenger is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL