example_channels

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_channels contains an example demonstrating how to write a protocol and a simulation using channels for message communication.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewExampleChannels

func NewExampleChannels(n *sda.TreeNodeInstance) (sda.ProtocolInstance, error)

NewExampleChannels 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.

Types

type Announce

type Announce struct {
	Message string
}

Announce is used to pass a message to all children

type ProtocolExampleChannels

type ProtocolExampleChannels struct {
	*sda.TreeNodeInstance
	Message         string
	ChildCount      chan int
	ChannelAnnounce chan StructAnnounce
	ChannelReply    chan []StructReply
}

ProtocolExampleChannels 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 (*ProtocolExampleChannels) Dispatch

func (p *ProtocolExampleChannels) Dispatch() error

Dispatch is an infinite loop to handle messages from channels

func (*ProtocolExampleChannels) Start

func (p *ProtocolExampleChannels) 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 contains Announce and the data necessary to identify the message in the sda framework.

type StructReply

type StructReply struct {
	*sda.TreeNode
	Reply
}

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

Jump to

Keyboard shortcuts

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