example_handlers

package
v0.0.0-...-53feb6c Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2016 License: GPL-2.0 Imports: 7 Imported by: 0

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 Reply

type Reply struct {
	ChildrenCount int
}

Reply returns the count of all children.

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

type StructAnnounce struct {
	*sda.TreeNode
	Announce
}

StructAnnounce just contains Announce and the data necessary to identify and process the message in the sda framework.

type StructReply

type StructReply struct {
	*sda.TreeNode
	Reply
}

StructReply just contains Reply and the data necessary to identify and process the message in the sda framework.

Jump to

Keyboard shortcuts

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