Documentation ¶
Overview ¶
Package gossipswitch implements the gossip switch(receive the message from InPort, filter the received message, and then broadcast the message to OutPort).
The gossipswitch package implements one complete gossip switch, include: switch InPort(receive message), switch OutPort(send message),two common message filter(TxFilter: filter transaction message, BlockFilter:filter block message).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GossipSwitch ¶
type GossipSwitch struct {
// contains filtered or unexported fields
}
GossipSwitch is the implementation of gossip switch. for gossipswitch, if a validated message is received, it will be broadcasted, otherwise it will be dropped.
func NewGossipSwitch ¶
func NewGossipSwitch(filter filter.SwitchFilter) *GossipSwitch
NewGossipSwitch create a new switch instance with given filter. filter is used to verify the received message
func NewGossipSwitchByType ¶
func NewGossipSwitchByType(switchType SwitchType, eventCenter types.EventCenter, switchConfig *config.SwitchConfig) (*GossipSwitch, error)
NewGossipSwitchByType create a new switch instance by type. switchType is used to specify the switch type
func (*GossipSwitch) InPort ¶
func (sw *GossipSwitch) InPort(portId int) *port.InPort
port.InPort get switch's in port by port id, return nil if there is no port with specific id.
func (*GossipSwitch) IsRunning ¶
func (sw *GossipSwitch) IsRunning() bool
IsRunning is used to query switch's current status. Return true if running, otherwise false
func (*GossipSwitch) OutPort ¶
func (sw *GossipSwitch) OutPort(portId int) *port.OutPort
port.InPort get switch's out port by port id, return nil if there is no port with specific id.
func (*GossipSwitch) Start ¶
func (sw *GossipSwitch) Start() error
Start start the switch. Once started, switch will receive message from in port, and broadcast to out port
func (*GossipSwitch) Stop ¶
func (sw *GossipSwitch) Stop() error
Stop stop the switch. Once stopped, switch will stop to receive and broadcast message
type GossipSwitchAPI ¶
type GossipSwitchAPI interface { // InPort get switch's in port by port id, return nil if there is no port with specific id. InPort(portId int) *port.InPort // InPort get switch's out port by port id, return nil if there is no port with specific id. OutPort(portId int) *port.OutPort // Start start the switch. Once started, switch will receive message from in port, and broadcast to // out port Start() error // Stop stop the switch. Once stopped, switch will stop to receive and broadcast message Stop() error // IsRunning is used to query switch's current status. Return true if running, otherwise false IsRunning() bool }
GossipSwitchAPI is gossipswitch's public api.
type SwitchType ¶
type SwitchType int
SwitchType switch type
const ( TxSwitch SwitchType = iota BlockSwitch )