routing

package
v0.0.0-...-ecfc0d7 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2024 License: Apache-2.0 Imports: 8 Imported by: 4

Documentation

Index

Constants

View Source
const (
	// BroadcastRoutingNumWorkers determines how many concurrent goroutines are
	// handling broadcast messages
	BroadcastRoutingNumWorkers = 1
)
View Source
const (
	// DirectRoutingNumWorkers determines how many concurrent goroutines are
	// handling direct messages
	DirectRoutingNumWorkers = 1
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BroadcastRouting

type BroadcastRouting struct {
	*Routing
	// contains filtered or unexported fields
}

BroadcastRouting is for message to all other nodes in the network

func NewBroadcastRouting

func NewBroadcastRouting(localMsgChan chan<- *node.RemoteMessage, rxMsgChan <-chan *node.RemoteMessage, localNode *node.LocalNode) (*BroadcastRouting, error)

NewBroadcastRouting creates a new BroadcastRouting

func (BroadcastRouting) ApplyMiddleware

func (store BroadcastRouting) ApplyMiddleware(mw interface{}) error

ApplyMiddleware add a middleware to the store

func (*BroadcastRouting) GetNodeToRoute

func (br *BroadcastRouting) GetNodeToRoute(remoteMsg *node.RemoteMessage) (*node.LocalNode, []*node.RemoteNode, error)

GetNodeToRoute returns the local node and remote nodes to route message to

func (*BroadcastRouting) Start

func (br *BroadcastRouting) Start() error

Start starts handling broadcast message from rxChan

type DirectRouting

type DirectRouting struct {
	*Routing
}

DirectRouting is for message to local node directly from remote node

func NewDirectRouting

func NewDirectRouting(localMsgChan chan<- *node.RemoteMessage, rxMsgChan <-chan *node.RemoteMessage) (*DirectRouting, error)

NewDirectRouting creates a new DirectRouting

func (DirectRouting) ApplyMiddleware

func (store DirectRouting) ApplyMiddleware(mw interface{}) error

ApplyMiddleware add a middleware to the store

func (*DirectRouting) GetNodeToRoute

func (dr *DirectRouting) GetNodeToRoute(remoteMsg *node.RemoteMessage) (*node.LocalNode, []*node.RemoteNode, error)

GetNodeToRoute returns the local node and remote nodes to route message to

func (*DirectRouting) Start

func (dr *DirectRouting) Start() error

Start starts handling direct message from rxChan

type RemoteMessageArrived

type RemoteMessageArrived struct {
	Func     func(*node.RemoteMessage) (*node.RemoteMessage, bool)
	Priority int32
}

RemoteMessageArrived is called when a new remote message arrives and prepare to be handled by the corresponding router. Message with the same message id will each trigger this middleware once. This can be used to process, modify or discard message. Returns the remote message to be used (or nil to discard the message) and if we should proceed to the next middleware.

type RemoteMessageReceived

type RemoteMessageReceived struct {
	Func     func(*node.RemoteMessage) (*node.RemoteMessage, bool)
	Priority int32
}

RemoteMessageReceived is called when a new remote message is received, routed to local node, and prepare to be handled by local node. Message with the same message id will only trigger this middleware once. This can be used to process, modify or discard message. Returns the remote message to be used (or nil to discard the message) and if we should proceed to the next middleware.

type RemoteMessageRouted

type RemoteMessageRouted struct {
	Func     func(*node.RemoteMessage, *node.LocalNode, []*node.RemoteNode) (*node.RemoteMessage, *node.LocalNode, []*node.RemoteNode, bool)
	Priority int32
}

RemoteMessageRouted is called when the router has computed the node to route (could be the local node, remote nodes, or both), and before the message is dispatched to local or remote nodes. Message with the same message id will each trigger this middleware once. This can be used to process, modify or discard message, or change routes. Returns the remote message to be used (or nil to discard the message), local node and remote nodes where the message should be routed to, and if we should proceed to the next middleware.

type Router

type Router interface {
	Start() error
	Stop(error)
	ApplyMiddleware(interface{}) error
	GetNodeToRoute(remoteMsg *node.RemoteMessage) (localNode *node.LocalNode, remoteNodes []*node.RemoteNode, err error)
	SendMessage(router Router, remoteMsg *node.RemoteMessage, hasReply bool, replyTimeout time.Duration) (replyChan <-chan *node.RemoteMessage, success bool, err error)
}

Router is an abstract routing layer that determines how to route a message

type Routing

type Routing struct {
	common.LifeCycle
	// contains filtered or unexported fields
}

Routing is the base struct for all routing

func NewRouting

func NewRouting(localMsgChan chan<- *node.RemoteMessage, rxMsgChan <-chan *node.RemoteMessage) (*Routing, error)

NewRouting creates a new routing

func (Routing) ApplyMiddleware

func (store Routing) ApplyMiddleware(mw interface{}) error

ApplyMiddleware add a middleware to the store

func (*Routing) SendMessage

func (r *Routing) SendMessage(router Router, remoteMsg *node.RemoteMessage, hasReply bool, replyTimeout time.Duration) (<-chan *node.RemoteMessage, bool, error)

SendMessage sends msg to the best next hop, returns reply chan (nil if if hasReply is false), if send success (which is true if successfully send message to at least one next hop), and aggregated errors during message sending

func (*Routing) Start

func (r *Routing) Start(router Router, numWorkers int) error

Start starts the message handling process

func (*Routing) Stop

func (r *Routing) Stop(err error)

Stop stops the routing

Jump to

Keyboard shortcuts

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