protocol

package
v0.0.0-...-6588121 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2018 License: GPL-3.0, LGPL-3.0, AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package protocol contains an example demonstrating how to write a protocol and a simulation.

The protocol has two messages:

  • Announce which is sent from the root down the tree
  • Reply which is sent back up to the root

If you want to add other messages, be sure to follow the way Announce and StructAnnounce are set up.

A simple protocol uses four files: - struct.go defines the messages sent around - protocol.go defines the actions for each message - protocol_test.go tests the protocol in a local test - simulation.go tests the protocol on distant platforms like deterlab

Index

Constants

View Source
const Name = "Template"

Name can be used from other packages to refer to this protocol.

Variables

This section is empty.

Functions

func NewProtocol

func NewProtocol(n *onet.TreeNodeInstance) (onet.ProtocolInstance, error)

NewProtocol initialises the structure for use in one round

Types

type Announce

type Announce struct {
	Message string
}

Announce is used to pass a message to all children.

type Reply

type Reply struct {
	ChildrenCount int
}

Reply returns the count of all children.

type StructAnnounce

type StructAnnounce struct {
	*onet.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 {
	*onet.TreeNode
	Reply
}

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

type TemplateProtocol

type TemplateProtocol struct {
	*onet.TreeNodeInstance
	ChildCount chan int
}

TemplateProtocol holds the state of a given protocol.

For this example, it defines a channel that will receive the number of children. Only the root-node will write to the channel.

func (*TemplateProtocol) HandleAnnounce

func (p *TemplateProtocol) HandleAnnounce(msg StructAnnounce) error

HandleAnnounce is the first message and is used to send an ID that is stored in all nodes.

func (*TemplateProtocol) HandleReply

func (p *TemplateProtocol) HandleReply(reply []StructReply) error

HandleReply is the message going up the tree and holding a counter to verify the number of nodes.

func (*TemplateProtocol) Start

func (p *TemplateProtocol) Start() error

Start sends the Announce-message to all children

Jump to

Keyboard shortcuts

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