Documentation ¶
Overview ¶
Package example_handlers contains an example demonstrating how to write a protocol and a simulation using handlers (aka callbacks) for message communication.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewExampleHandlers ¶
func NewExampleHandlers(n *sda.TreeNodeInstance) (sda.ProtocolInstance, error)
NewExampleHandlers initialises the structure for use in one round
func NewSimulation ¶
func NewSimulation(config string) (sda.Simulation, error)
NewSimulation is used internally to register the simulation (see the init() function above).
Types ¶
type Announce ¶
type Announce struct {
Message string
}
Announce is used to pass a message to all children.
type ProtocolExampleHandlers ¶
type ProtocolExampleHandlers struct { *sda.TreeNodeInstance Message string ChildCount chan int }
ProtocolExampleHandlers just holds a message that is passed to all children. It also defines a channel that will receive the number of children. Only the root-node will write to the channel.
func (*ProtocolExampleHandlers) HandleAnnounce ¶
func (p *ProtocolExampleHandlers) HandleAnnounce(msg StructAnnounce) error
HandleAnnounce is the first message and is used to send an ID that is stored in all nodes.
func (*ProtocolExampleHandlers) HandleReply ¶
func (p *ProtocolExampleHandlers) HandleReply(reply []StructReply) error
HandleReply is the message going up the tree and holding a counter to verify the number of nodes.
func (*ProtocolExampleHandlers) Start ¶
func (p *ProtocolExampleHandlers) Start() error
Starts the protocol
type Simulation ¶
type Simulation struct {
sda.SimulationBFTree
}
Simulation implements sda.Simulation.
func (*Simulation) Run ¶
func (e *Simulation) Run(config *sda.SimulationConfig) error
Run implements sda.Simulation.
func (*Simulation) Setup ¶
func (e *Simulation) Setup(dir string, hosts []string) ( *sda.SimulationConfig, error)
Setup implements sda.Simulation.
type StructAnnounce ¶
StructAnnounce just contains Announce and the data necessary to identify and process the message in the sda framework.
type StructReply ¶
StructReply just contains Reply and the data necessary to identify and process the message in the sda framework.