lib

package
v0.0.0-...-bc3f6f8 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2019 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// START id
	START = iota
	// END id
	END
	// P2P id
	P2P
)

Variables

View Source
var Message = []byte("Everything that is beautiful and noble is the product of reason and calculation.")

Message that will get signed

Functions

func Divmod

func Divmod(numerator, denominator int) (quotient, remainder int)

Divmod returns the integer results and remainder of the division

func GetFreeTCPPort

func GetFreeTCPPort() int

GetFreeTCPPort returns a free tcp port or panics

func GetFreeUDPPort

func GetFreeUDPPort() int

GetFreeUDPPort returns a free usable UDP address We need to keep an history of the previous port we

allocated, we do this with this global variable.

func WriteAll

func WriteAll(nodes []*Node, p NodeParser, uri string)

WriteAll writes down all the given nodes to the specified URI with the given parser.

Types

type Allocator

type Allocator interface {
	Allocate(plats []Platform, total, offline int) map[string][]*NodeInfo
}

Allocator allocates *total* Handel instances on *len(plats)* platform, where *offline* instances will be set as offline.

func NewRoundRandomOffline

func NewRoundRandomOffline() Allocator

NewRoundRandomOffline returns a RoundRandomOffline allocator

type Config

type Config struct {

	// which network should we use
	// Valid value: "udp" (default)
	Network string
	// which "curve system" should we use
	// Valid value: "bn256" (default)
	Curve string
	// which encoding should we use on the network
	// valid value: "gob" (default)
	Encoding string
	// which allocator to use when experimenting failing nodes
	// valid value: "round" (default) or "random"
	Allocator string
	// which is the port to send measurements to
	MonitorPort int
	// Debug forwards the debug output if set to != 0
	Debug int
	// which simulation are we running -
	// valid values: "handel" (default) or "p2p/udp" or "p2p/libp2p"
	Simulation string
	// Maximum time to wait for the whole thing to finish
	// string because of ugly format of TOML encoding ---
	MaxTimeout string
	// how many time should we repeat each experiment
	Retrials int
	// to which file should we write the results
	ResultFile string
	// config for each run
	Runs []RunConfig
	// contains filtered or unexported fields
}

Config is read from a TOML encoded file and passed to Platform.Config and prepares the platform for specific system-wide configurations.

func LoadConfig

func LoadConfig(path string) *Config

LoadConfig looks up the given file to unmarshal a TOML encoded Config.

func (*Config) GetBinaryPath

func (c *Config) GetBinaryPath() string

GetBinaryPath returns the binary to compile

func (*Config) GetCSVFile

func (c *Config) GetCSVFile() string

GetCSVFile returns a name of the CSV file

func (*Config) GetMaxTimeout

func (c *Config) GetMaxTimeout() time.Duration

GetMaxTimeout returns the global maximum timeout specified in the config

func (*Config) GetMonitorAddress

func (c *Config) GetMonitorAddress(ip string) string

GetMonitorAddress returns a full IP address composed of the given address apprended with the port from the config.

func (*Config) GetResultsDir

func (c *Config) GetResultsDir() string

GetResultsDir returns the directory where results will be written

func (*Config) GetResultsFile

func (c *Config) GetResultsFile() string

GetResultsFile returns the path where to write the resulting csv file

func (*Config) Logger

func (c *Config) Logger() handel.Logger

Logger returns the logger set to the right verbosity with timestamp added

func (*Config) MaxNodes

func (c *Config) MaxNodes() int

MaxNodes returns the maximum number of nodes to test

func (*Config) NewAllocator

func (c *Config) NewAllocator() Allocator

NewAllocator returns the allocation determined by the "Allocator" string field of the config.

func (*Config) NewConstructor

func (c *Config) NewConstructor() Constructor

NewConstructor returns a Constructor that is using the curve denoted by the curve field of the config. Valid input so far is "bn256".

func (*Config) NewEncoding

func (c *Config) NewEncoding() network.Encoding

NewEncoding returns the corresponding network encoding

func (*Config) NewNetwork

func (c *Config) NewNetwork(id handel.Identity) handel.Network

NewNetwork returns the network implementation designated by this config for this given identity

func (*Config) WriteTo

func (c *Config) WriteTo(path string) error

WriteTo writes the config to the specified file path.

type Constructor

type Constructor interface {
	Handel() handel.Constructor
	PublicKey() PublicKey
	SecretKey() SecretKey
	Signature() handel.Signature
	KeyPair(r io.Reader) (SecretKey, PublicKey)
}

Constructor can construct a secret key on top of the regular handel constructor. This is what NEW CURVES must implement in order to be tested on a simulation.

func NewEmptyConstructor

func NewEmptyConstructor() Constructor

NewEmptyConstructor returns a Constructor that construct fake secret key and fake public key that don't do anything. Useful for testing networks and the likes. Do NOT use the public / secret / signatures for anything !

func NewSimulConstructor

func NewSimulConstructor(h handel.Constructor) Constructor

NewSimulConstructor returns a simulation Constructor

type Duration

type Duration time.Duration

Duration is an alias for time.Duration

func (*Duration) MarshalText

func (d *Duration) MarshalText() ([]byte, error)

MarshalText implements the TextMarshaler interface

func (*Duration) UnmarshalText

func (d *Duration) UnmarshalText(text []byte) error

UnmarshalText implements the TextUnmarshaler interface

type Generator

type Generator interface {
	KeyPair(io.Reader) (handel.SecretKey, handel.PublicKey)
}

Generator can generate a new key pair

type HandelConfig

type HandelConfig struct {
	// Period of the periodic update loop
	Period string
	// Number of node do we contact for each periodic update
	UpdateCount int
	// Number of node do we contact when starting level + when finishing level
	// XXX - maybe remove in the futur ! -
	NodeCount int
	// Timeout used to give to the LinearTimeout constructor
	Timeout string
	// UnsafeSleepTimeOnSigVerify
	UnsafeSleepTimeOnSigVerify int

	// which queue evaluator are we choosing
	Evaluator string
}

HandelConfig is a small config that will be converted to handel.Config during the simulation

type Marshallable

type Marshallable interface {
	MarshalBinary() ([]byte, error)
	UnmarshalBinary(buff []byte) error
}

Marshallable represents an interface that can marshal and unmarshals itself

type Node

type Node struct {
	SecretKey
	handel.Identity
	Active bool
}

Node is similar to a NodeRecord but decoded

func GenerateNode

func GenerateNode(cons Constructor, idx int, addr string) *Node

GenerateNode create the necessary key pair & identites out of the given addresses. for a singel node

func GenerateNodes

func GenerateNodes(cons Constructor, addresses []string) []*Node

GenerateNodes create the necessary key pair & identites out of the given addresses. The IDs will be created sequentially from 0.

func GenerateNodesFromAllocation

func GenerateNodesFromAllocation(cons Constructor, alloc map[string][]*NodeInfo) []*Node

GenerateNodesFromAllocation returns a list of Node from the allocation returned by Allocator + filled with the addresses

func (*Node) ToRecord

func (n *Node) ToRecord() (*NodeRecord, error)

ToRecord maps a Node to a NodeRecord, its string-human-readable equivalent

type NodeInfo

type NodeInfo struct {
	ID      int
	Active  bool
	Address string
}

NodeInfo is the output of the allocator. The allocator only tries to assign the ID and the status, not the physical network address since that is dependent on the chosen platform.

type NodeList

type NodeList []*Node

NodeList is a type that contains all informations on all nodes, and that implements the Registry interface. It is useful for binaries that retrieves multiple node information - not only the Identity.

func ReadAll

func ReadAll(uri string, parser NodeParser, c Constructor) (NodeList, error)

ReadAll reads the whole set of nodes from the given parser to the given URI. It returns the node list which can be used as a Registry as well

func (*NodeList) Identities

func (n *NodeList) Identities(from, to int) ([]handel.Identity, bool)

Identities implements the handel.Registry interface

func (*NodeList) Identity

func (n *NodeList) Identity(idx int) (handel.Identity, bool)

Identity implements the handel.Registry interface

func (*NodeList) Node

func (n *NodeList) Node(i int) *Node

Node returns the Node structure at the given index

func (*NodeList) Registry

func (n *NodeList) Registry() handel.Registry

Registry returns a handel.Registry interface

func (*NodeList) Size

func (n *NodeList) Size() int

Size implements the handel.Registry interface

type NodeParser

type NodeParser interface {
	// Reads all NodeRecords  from a given URI. It can be a CSV file
	// encoded for example.
	Read(uri string) ([]*NodeRecord, error)
	// Writes all node records to an URI. It can be a file.
	Write(uri string, records []*NodeRecord) error
}

NodeParser is an interface that can read / write node records.

func NewCSVParser

func NewCSVParser() NodeParser

NewCSVParser is a NodeParser that reads/writes to a CSV file

type NodeRecord

type NodeRecord struct {
	ID      int32
	Addr    string
	Private string // hex encoded
	Public  string // hex encoded
}

NodeRecord holds a node's information in a readable string format

func (*NodeRecord) ToNode

func (n *NodeRecord) ToNode(c Constructor) (*Node, error)

ToNode the private and public key from the given constructor and returns the secret key and the corresponding identity

type Platform

type Platform interface {
	String() string
}

Platform represents the platform where multiple Handel nodes can run. It can be a process for localhost platform's or EC2 instance for aws.

type PublicKey

type PublicKey interface {
	handel.PublicKey
	Marshallable
}

PublicKey can also Marshal itself on top of the regular handel PublicKey

type RoundRandomOffline

type RoundRandomOffline struct {
	Allocator
}

RoundRandomOffline uses RoundRobin allocator to setups the alive nodes but chooses randomly offline nodes in a round robin way for each platforms

func (*RoundRandomOffline) Allocate

func (r *RoundRandomOffline) Allocate(plats []Platform, total, offline int) map[string][]*NodeInfo

Allocate implements the Allocator interface

type RoundRobin

type RoundRobin struct{}

RoundRobin allocates the nodes in a round robin fashion as to minimise the number of nodes on each platforms.

func (*RoundRobin) Allocate

func (r *RoundRobin) Allocate(plats []Platform, total, offline int) map[string][]*NodeInfo

Allocate implements the Allocator2 interface

type RunConfig

type RunConfig struct {
	// How many nodes should we spin for this run
	Nodes int
	// threshold of signatures to wait for
	Threshold int
	// Number of failing nodes
	Failing int
	// Number of processes for this run
	Processes int
	// Handel items configurable  - will be merged with defaults
	Handel *HandelConfig
	// extra for particular information for specific platform for examples
	Extra map[string]string
}

RunConfig is the config holding parameters for a specific run. A platform can start multiple runs sequentially with different parameters each.

func (*RunConfig) GetHandelConfig

func (r *RunConfig) GetHandelConfig() *handel.Config

GetHandelConfig returns the config to pass down to handel instances Returns the default if not set

func (*RunConfig) GetThreshold

func (r *RunConfig) GetThreshold() int

GetThreshold returns the threshold to use for this run config - if 0 it returns the number of nodes

type SecretConstructor

type SecretConstructor interface {
	SecretKey() handel.SecretKey
}

SecretConstructor is an interface that can issue a secret key. Useful since SecretKey() method is not mandatory in Handel.

type SecretKey

type SecretKey interface {
	Marshallable
	handel.SecretKey
}

SecretKey can also Marshal itself on top of the regular handel SecretKey

type SimulConstructor

type SimulConstructor struct {
	// contains filtered or unexported fields
}

SimulConstructor is a constructor that wraps around a handel.Constructor and add useful methods for the simulation (private key generation, etc)

func (*SimulConstructor) Handel

func (h *SimulConstructor) Handel() handel.Constructor

Handel implements the Constructor interface

func (*SimulConstructor) KeyPair

func (h *SimulConstructor) KeyPair(r io.Reader) (SecretKey, PublicKey)

KeyPair implements the Constructor interface

func (*SimulConstructor) PublicKey

func (h *SimulConstructor) PublicKey() PublicKey

PublicKey implements the Constructor interface

func (*SimulConstructor) SecretKey

func (h *SimulConstructor) SecretKey() SecretKey

SecretKey implements the Constructor interface

func (*SimulConstructor) Signature

func (h *SimulConstructor) Signature() handel.Signature

Signature implements the Constructor interface

type SyncMaster

type SyncMaster struct {
	sync.Mutex
	// contains filtered or unexported fields
}

SyncMaster is a struct that handles the synchronization of all launched binaries by first expecting a message from each one of them, then sending them back a "START" message when all are ready. It uses UDP. The "Protocol" looks like this: - the SyncMaster listens on a UDP socket - each node sends a "READY" message to the starter over that socket. - the SyncMaster waits for n different READY messages. - once that is done, the SyncMaster sends a START message to all nodes.

A READY message is a Packet which contains a structure inside the MultiSig field, as to re-use the UDP code already present.

func NewSyncMaster

func NewSyncMaster(addr string, expected, total int) *SyncMaster

NewSyncMaster returns an SyncMaster that listens on the given address, for a expected number of READY messages.

func (*SyncMaster) NewPacket

func (s *SyncMaster) NewPacket(p *handel.Packet)

NewPacket implements the Listener interface

func (*SyncMaster) Stop

func (s *SyncMaster) Stop()

Stop stops the network layer of the syncmaster

func (*SyncMaster) WaitAll

func (s *SyncMaster) WaitAll(id int) chan bool

WaitAll returns

type SyncSlave

type SyncSlave struct {
	sync.Mutex
	// contains filtered or unexported fields
}

SyncSlave sends its state to the master and waits for a START message

func NewSyncSlave

func NewSyncSlave(own, master string, ids []int) *SyncSlave

NewSyncSlave returns a Sync to use as a node in the system to synchronize with the master

func (*SyncSlave) NewPacket

func (s *SyncSlave) NewPacket(p *handel.Packet)

NewPacket implements the Listener interface

func (*SyncSlave) Signal

func (s *SyncSlave) Signal(stateID int, id int)

Signal sends an individual signal for the given state signalling only the given ID.

func (*SyncSlave) SignalAll

func (s *SyncSlave) SignalAll(stateID int)

SignalAll sends a signal for the given state by sending all ids given to the slave in one packet.

func (*SyncSlave) Stop

func (s *SyncSlave) Stop()

Stop the network layer of the syncslave

func (*SyncSlave) WaitMaster

func (s *SyncSlave) WaitMaster(stateID int) chan bool

WaitMaster first signals the master node for this state and returns the channel that gets signaled when the master sends back a message with the same id. This signals all ids given in parameter at once in one packet.

Jump to

Keyboard shortcuts

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