simulation

package
v0.0.0-...-8273b29 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2015 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Network

type Network struct {
	Nodes          []*Node
	NetworkType    string        // "tcp" or "unix"
	GossipInterval time.Duration // The length of a round of gossip
	Stopper        *stop.Stopper
}

Network provides access to a test gossip network of nodes.

func NewNetwork

func NewNetwork(nodeCount int, networkType string,
	gossipInterval time.Duration) *Network

NewNetwork creates nodeCount gossip nodes. The networkType should be set to either "tcp" or "unix". The gossipInterval should be set to a compressed simulation timescale, though large enough to give the concurrent goroutines enough time to pass data back and forth in order to yield accurate estimates of how old data actually ends up being at the various nodes (e.g. DefaultTestGossipInterval). TODO: This method should take `stopper` as an argument.

func (*Network) GetNodeFromAddr

func (n *Network) GetNodeFromAddr(addr string) (*Node, bool)

GetNodeFromAddr returns the simulation node associated with provided network address, or nil if there is no such node.

func (*Network) GetNodeFromID

func (n *Network) GetNodeFromID(nodeID proto.NodeID) (*Node, bool)

GetNodeFromID returns the simulation node associated with provided node ID, or nil if there is no such node.

func (*Network) RunUntilFullyConnected

func (n *Network) RunUntilFullyConnected() int

RunUntilFullyConnected blocks until the gossip network has received gossip from every other node in the network. It returns the gossip cycle at which the network became fully connected.

func (*Network) SimulateNetwork

func (n *Network) SimulateNetwork(
	simCallback func(cycle int, network *Network) bool)

SimulateNetwork runs a number of gossipInterval periods within the given Network. After each gossipInterval period, simCallback is invoked. When it returns false, the simulation ends. If it returns true, the simulation continues another cycle.

Node0 gossips the node count as well as the gossip sentinel. The gossip bootstrap hosts are set to the first three nodes (or fewer if less than three are available).

At each cycle of the simulation, node 0 gossips the sentinel. If the simulation requires other nodes to gossip, this should be done via simCallback.

The simulation callback receives a map of nodes, keyed by node address.

func (*Network) Stop

func (n *Network) Stop()

Stop all servers and gossip nodes.

type Node

type Node struct {
	Gossip *gossip.Gossip
	Server *rpc.Server
}

Node represents a node used in a Network. It includes information about the node's gossip instance, network address, and underlying server.

Jump to

Keyboard shortcuts

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