onet

package module
v3.2.10 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2021 License: LGPL-3.0 Imports: 47 Imported by: 85

README

Build Status Go Report Card Coverage Status Codacy Badge

The Cothority Overlay Network Library - Onet

The Overlay-network (Onet) is a library for simulation and deployment of decentralized, distributed protocols. This library offers a framework for research, simulation, and deployment of crypto-related protocols with an emphasis on decentralized, distributed protocols. It offers an abstraction for tree-based communications between thousands of nodes and it is used both in research for testing out new protocols and running simulations, as well as in production to deploy those protocols as a service in a distributed manner.

Onet is developed by DEDIS/EFPL as part of the Cothority project that aims to deploy a large number of nodes for distributed signing and related projects. In cothority, nodes are commonly named "conodes". A collective authority (cothority) is a set of conodes that work together to handle a distributed, decentralized task.

Onet allows you to set up the following three elements:

  • protocols: a short-lived set of messages being passed back and forth between one or more conodes

  • services: define an API usable by client programs and instantiate protocols

  • apps: communicate with the service-API of one or more conodes

We also provide a set of methods to set up and run simulations.


📖 Table of Contents

General information

Directories

  • app - useful libraries if you want to create a CLI app for the cothority

  • cfgpath - single package to get the configuration-path

  • log - everybody needs its own log-library - this one has log-levels, colors, time, ...

  • network - different type of connections: channels, tcp, tls

  • simul - allowing to run your protocols and services on different platforms with up to 50'000 nodes

Version

The Onet library follows the same development cycle as the one described in the dedis/cothority project.

License

This project and all its files are licensed under the GNU Lesser General Public License, version 3 (SPDX short identifier: LGPL-3.0)

If this license is not suitable for your business or project please contact us for a full commercial license.

Contribution

If you want to contribute, please have a look at CONTRIBUTION for licensing details and feel free to open a pull request.

Contact

You can contact us at https://groups.google.com/forum/#!forum/cothority or privately at dedis@epfl.ch.

Reporting security problems

This library is offered as-is without any guarantees. It would need an independent security review before it should be considered ready for use in security-critical applications. If you integrate Onet into your application it is YOUR RESPONSIBILITY to arrange for that audit.

If you notice a possible security problem, please report it to dedis-security@epfl.ch.

Components

In Onet, you define Services that use Protocols which can send and receive messages. Each Protocol is instantiated when needed as a ProtocolInstance. As multiple Protocols can be run at the same time, there can be more than one ProtocolInstance of the same Protocol. Onet makes sure all messages get routed to the appropriate ProtocolInstance.

Foreign applications can communicate with Onet over the service-API, which is implemented using protobuf over WebSockets for JavaScript compatibility.

This chapter provides a high-level description of the cothority framework. Let's start with a picture and then dive into each main components of the library.

system overview

As you can see there's a bunch of different entities involved. Let's get down the rabbit hole to explain the most important ones!

Router

The Router handles all incoming and outgoing messages from and to the network. A Router can use different underlying types of connection:

  • TCP which uses regular TCP connections,
  • Local which uses channels and is mainly for testing purposes, and
  • TLS which is still in progress.

Conode

A conode is the main entity of a Cothority server. It holds the Router, the Overlay, and the different Services. Generally, for developing an application using the framework, you would create your Router first, then the Conode, and then finally call conode.Start().

Roster

A Roster is simply a list of Conodes denoted by their public key and address. A Roster is identified by its ID, which is unique for each list.

Protocol

A Protocol is an interface where users of the library must implement the logic of the protocol they want to code. It is supposed to be a short term entity that is self-sufficient, i.e. it does not need external access to any other resources of the Cothority framework. A protocol can be launched from SDA itself or by a Service.

Service

A Service is a long term entity that is created when a Conode is created. It serves different purposes:

  • serving external client requests,
  • creating and attaching protocols with the Overlay (and launching them),
  • communicating information to other Services on other Conodes.

ServiceManager

A ServiceManager is the main interface between the Conode and the Service. It transforms and embed the messages created by the Service to its own format and pass it to the Conode for the sending part; vice versa for the reception part.

Tree

A Tree is a standard tree data structure where each node - called TreeNode - is denoted by its public key and address. The Tree is constructed out of a Roster.

Overlay

The Overlay provides an abstraction to communicate over different Trees that the Protocols and Services need. It handles the following tasks:

  • Propagations of the Roster and the Trees between different Conodes
  • Creation of the Protocol
  • Dispatching of incoming and outgoing messages to the right Protocol

TreeNodeInstance

A TreeNodeInstance is created by the Overlay. There is one TreeNodeInstance for each Protocol and it acts as the central point of communication for that Protocol. The TreeNodeInstance offers to its Protocol some common tree methods such as SendParent,SendChild, IsRoot etc. More importantly, it transforms and embeds the message given by the Protocol into its own struct and dispatch it to the Overlay for the sending part; vice versa for the reception part.

App

An application in the context of Onet is a CLI-program that interacts with one or more conodes through the use of the API defined by one or more services. It is mostly written in go, but in the cothority-repository you can also find libraries to interact in javascript and java.

Database Backup and Recovery

Users of Onet have the option to make use of its built-in database.

We use bbolt, which supports "fully serializable ACID transactions" to ensure data integrity for Onet users. Users should be able to do the following:

  • Backup data while Onet is running
  • Recovery from a backup in case of data corruption

Backup

Users are recommended to perform frequent backups such that data can be recovered if Onet nodes fail. Onet stores all of its data in the context folder, specified by $CONODE_SERVICE_PATH. If unset, it defaults to

  • ~/Library/Application Support/conode/data on macOS,
  • $HOME\AppData\Local\Conode on Windows, or
  • ~/.local/share/conode on other Unix/Linux.

Hence, to backup, it is recommended to use a standard backup tool, such as rsync, and copy the folder to a different physical location periodically. The database keeps a transaction log.

Performing backups in the middle of a transaction should not be a problem. However, it is still recommended to check the data integrity of the backed-up file using the bbolt CLI, i.e. bolt check database_name.db.

To install the bbolt CLI, see Bolt Installation.

Recovery

Data corruption is easy to detect as Onet nodes crash when reading from a corrupted database, at startup or during operation. Concretely, the bbolt library would panic (source). This behavior is produced by writing a few blocks of random data using dd to the database.

In case of data corruption, the database must be restored from a backup by simply copying the backup copy to the context directory, and then starting the conode again. It is the user's responsibility to make sure that the data is up to date, e.g. by reading the latest data from running Onet nodes.

Interacting with the database

The primary and recommended methods to interact with the database are Load and Save. If more control on the database is needed, then we can ask the context to return a database handler and bucket name using the function GetAdditionalBucket.

All the bbolt functions can be used with the database handler. However, the user should avoid creating new buckets using the bbolt functions and only use GetAdditionalBucket to avoid bucket name conflicts.

Simulation

Have a look at the simul/README.md for explanations about simulations.

Documentation

Overview

Package onet is the Overlay Network which offers a simple framework for generating your own distributed systems. It is based on a description of your protocol and offers sending and receiving messages, handling trees and host-lists, and easy deploying to Localhost, Deterlab or a real-system.

ONet is based on the following pieces:

  • Local* - offers the user-interface to the API for deploying your protocol locally and for testing
  • Node / ProtocolInstance - gives an interface to define your protocol
  • Server - hold states for the different parts of Onet
  • network - uses secured connections between hosts

If you just want to use an existing protocol, usually the ONet-part is enough. If you want to create your own protocol, you have to learn how to use the ProtocolInstance.

Index

Constants

View Source
const (
	// TCP represents the TCP mode of networking for this local test
	TCP = "tcp"
	// Local represents the Local mode of networking for this local test
	Local = "local"
)
View Source
const (
	// AggregateMessages (if set) tells to aggregate messages from all children
	// before sending to the (parent) Node
	AggregateMessages = 1

	// DefaultChannelLength is the default number of messages that can wait
	// in a channel.
	DefaultChannelLength = 100
)
View Source
const SimulationFileName = "simulation.bin"

SimulationFileName is the name of the (binary encoded) file containing the simulation config.

Variables

ConfigMsgID of the generic config message

View Source
var ErrProtocolRegistered = xerrors.New("a ProtocolInstance already has been registered using this TreeNodeInstance")

ErrProtocolRegistered is when the protocolinstance is already registered to the overlay

View Source
var ErrWrongTreeNodeInstance = xerrors.New("This TreeNodeInstance doesn't exist")

ErrWrongTreeNodeInstance is returned when you already binded a TNI with a PI.

View Source
var NilServiceID = ServiceID(uuid.Nil)

NilServiceID is the empty ServiceID

ProtocolMsgID is to be embedded in every message that is made for a ID of ProtocolMsg message as registered in network

View Source
var RequestRosterMsgID = network.RegisterMessage(RequestRoster{})

RequestRosterMsgID of RequestRoster message as registered in network Deprecated: only the tree is sent, not anymore the roster

View Source
var RequestTreeMsgID = network.RegisterMessage(RequestTree{})

RequestTreeMsgID of RequestTree message as registered in network

View Source
var ResponseTreeMsgID = network.RegisterMessage(ResponseTree{})

ResponseTreeMsgID of TreeMarshal message as registered in network

View Source
var RosterTypeID = network.RegisterMessage(Roster{})

RosterTypeID of Roster message as registered in network

View Source
var SendRosterMsgID = RosterTypeID

SendRosterMsgID of Roster message as registered in network Deprecated: only the tree is sent, not anymore the roster

View Source
var SendTreeMsgID = TreeMarshalTypeID

SendTreeMsgID of TreeMarshal message as registered in network Deprecated: use ResponseTreeMsgID

View Source
var ServiceFactory = serviceFactory{
	// contains filtered or unexported fields
}

ServiceFactory is the global service factory to instantiate Services

View Source
var TreeMarshalTypeID = network.RegisterMessage(TreeMarshal{})

TreeMarshalTypeID of TreeMarshal message as registered in network

Functions

func InformAllServersStopped

func InformAllServersStopped()

InformAllServersStopped allows to set the 'serverStarted' flag to false.

func InformServerStarted

func InformServerStarted()

InformServerStarted allows to set the 'serverStarted' flag to true.

func NewPrivIdentity

func NewPrivIdentity(suite network.Suite, port int) (kyber.Scalar, *network.ServerIdentity)

NewPrivIdentity returns a secret + ServerIdentity. The SI will have "localserver:+port as first address.

func ReadTomlConfig

func ReadTomlConfig(conf interface{}, filename string, dirOpt ...string) error

ReadTomlConfig read any structure from a toml-file Takes a filename and an optional directory-name

func RegisterMessageProxy

func RegisterMessageProxy(n NewMessageProxy)

RegisterMessageProxy saves a new NewMessageProxy under its name. When a Server is instantiated, all MessageProxys will be generated and stored for this Server.

func SimulationRegister

func SimulationRegister(name string, sim simulationCreate)

SimulationRegister is must to be called to register a simulation. Protocol or simulation developers must not forget to call this function with the protocol's name.

func UnregisterService

func UnregisterService(name string) error

UnregisterService removes a service from the global pool.

func WriteTomlConfig

func WriteTomlConfig(conf interface{}, filename string, dirOpt ...string)

WriteTomlConfig write any structure to a toml-file Takes a filename and an optional directory-name.

Types

type BidirectionalStreamer

type BidirectionalStreamer interface {
	// ProcessClientStreamRequest is different from ProcessClientRequest in that
	// it takes a chanel of inputs and watches for additional inputs. Additional
	// inputs are then forwarded to the service.
	ProcessClientStreamRequest(req *http.Request, path string, clientInputs chan []byte) (chan []byte, error)
	// IsStreaming checks if the handler registered at the given path is a
	// streaming handler or not. It returns an error in the case the handler is
	// not found.
	IsStreaming(path string) (bool, error)
}

BidirectionalStreamer specifies the functions needed to handle a bi-directional streamer, where the client is able to use the same chanel in order to send multiple requests.

type CertificateReloader

type CertificateReloader struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

CertificateReloader takes care of reloading a TLS certificate when requested.

func NewCertificateReloader

func NewCertificateReloader(certPath, keyPath string) (*CertificateReloader, error)

NewCertificateReloader takes two file paths as parameter that contain the certificate and the key data to create an automatic reloader. It will try to read again the files when the certificate is almost expired.

func (*CertificateReloader) GetCertificateFunc

func (cr *CertificateReloader) GetCertificateFunc() func(*tls.ClientHelloInfo) (*tls.Certificate, error)

GetCertificateFunc makes a function that can be passed to the TLSConfig so that it resolves the most up-to-date one.

type Client

type Client struct {

	// if not nil, use TLS
	TLSClientConfig *tls.Config

	// How long to wait for a reply
	ReadTimeout time.Duration
	// How long to wait to open a connection
	HandshakeTimeout time.Duration
	sync.Mutex
	// contains filtered or unexported fields
}

Client is a struct used to communicate with a remote Service running on a onet.Server. Using Send it can connect to multiple remote Servers.

func NewClient

func NewClient(suite network.Suite, s string) *Client

NewClient returns a client using the service s. On the first Send, the connection will be started, until Close is called.

func NewClientKeep

func NewClientKeep(suite network.Suite, s string) *Client

NewClientKeep returns a Client that doesn't close the connection between two messages if it's the same server.

func (*Client) Close

func (c *Client) Close() error

Close sends a close-command to all open connections and returns nil if no errors occurred or all errors encountered concatenated together as a string.

func (*Client) Rx

func (c *Client) Rx() uint64

Rx returns the number of bytes read by this Client. It implements the monitor.CounterIOMeasure interface.

func (*Client) Send

func (c *Client) Send(dst *network.ServerIdentity, path string, buf []byte) ([]byte, error)

Send will marshal the message into a ClientRequest message and send it. It has a very simple parallel sending mechanism included: if the send goes to a new or an idle connection, the message is sent right away. If the current connection is busy, it waits for it to be free.

func (*Client) SendProtobuf

func (c *Client) SendProtobuf(dst *network.ServerIdentity, msg interface{}, ret interface{}) error

SendProtobuf wraps protobuf.(En|De)code over the Client.Send-function. It takes the destination, a pointer to a msg-structure that will be protobuf-encoded and sent over the websocket. If ret is non-nil, it has to be a pointer to the struct that is sent back to the client. If there is no error, the ret-structure is filled with the data from the service.

func (*Client) SendProtobufParallel

func (c *Client) SendProtobufParallel(nodes []*network.ServerIdentity, msg interface{}, ret interface{},
	opt *ParallelOptions) (*network.ServerIdentity, error)

SendProtobufParallel sends the msg to a set of nodes in parallel and returns the first successful answer. If all nodes return an error, only the first error is returned. The behaviour of this method can be changed using the ParallelOptions argument. It is kept as a structure for future enhancements. If opt is nil, then standard values will be taken.

func (*Client) SendProtobufParallelWithDecoder

func (c *Client) SendProtobufParallelWithDecoder(nodes []*network.ServerIdentity, msg interface{}, ret interface{},
	opt *ParallelOptions, decoder Decoder) (*network.ServerIdentity, error)

SendProtobufParallelWithDecoder sends the msg to a set of nodes in parallel and returns the first successful answer. If all nodes return an error, only the first error is returned. The behaviour of this method can be changed using the ParallelOptions argument. It is kept as a structure for future enhancements. If opt is nil, then standard values will be taken.

func (*Client) SendToAll

func (c *Client) SendToAll(dst *Roster, path string, buf []byte) ([][]byte, error)

SendToAll sends a message to all ServerIdentities of the Roster and returns all errors encountered concatenated together as a string.

func (*Client) Stream

func (c *Client) Stream(dst *network.ServerIdentity, msg interface{}) (StreamingConn, error)

Stream will send a request to start streaming, it returns a connection where the client can continue to read values from it.

func (*Client) Suite

func (c *Client) Suite() network.Suite

Suite returns the cryptographic suite in use on this connection.

func (*Client) Tx

func (c *Client) Tx() uint64

Tx returns the number of bytes transmitted by this Client. It implements the monitor.CounterIOMeasure interface.

type ConfigMsg

type ConfigMsg struct {
	Config GenericConfig
	Dest   TokenID
}

ConfigMsg is sent by the overlay containing a generic slice of bytes to give to service in the `NewProtocol` method.

type Context

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

Context represents the methods that are available to a service.

func (*Context) CreateProtocol

func (c *Context) CreateProtocol(name string, t *Tree) (ProtocolInstance, error)

CreateProtocol returns a ProtocolInstance bound to the service.

func (*Context) GetAdditionalBucket

func (c *Context) GetAdditionalBucket(name []byte) (*bbolt.DB, []byte)

GetAdditionalBucket makes sure that a bucket with the given name exists, by eventually creating it, and returns the created bucket name, which is the servicename + "_" + the given name.

This function should only be used if the Load and Save functions are not sufficient. Additionally, the user should not create buckets directly on the DB but always call this function to create new buckets to avoid bucket name conflicts.

func (*Context) GetValidPeers

func (c *Context) GetValidPeers(peerID network.PeerSetID) []network.
	ServerIdentityID

GetValidPeers returns the set of peers with which the server underlying this context can communicate. The return value is `nil` in case the set of valid peers has not yet been initialized, meaning that all peers are valid.

func (*Context) Load

func (c *Context) Load(key []byte) (interface{}, error)

Load takes a key and returns the network.Unmarshaled data. Returns a nil value if the key does not exist.

func (*Context) LoadRaw

func (c *Context) LoadRaw(key []byte) ([]byte, error)

LoadRaw takes a key and returns the raw, unmarshalled data. Returns a nil value if the key does not exist.

func (*Context) LoadVersion

func (c *Context) LoadVersion() (int, error)

LoadVersion returns the version of the database, or 0 if no version has been found.

func (*Context) NewPeerSetID

func (c *Context) NewPeerSetID(data []byte) network.PeerSetID

NewPeerSetID creates a new PeerSetID identifying a subset of valid peers. This is to be used by services, providing their own specific identifier, e.g. the SkipChainID for ByzCoin.

func (*Context) NewTreeNodeInstance

func (c *Context) NewTreeNodeInstance(t *Tree, tn *TreeNode, protoName string) *TreeNodeInstance

NewTreeNodeInstance creates a TreeNodeInstance that is bound to a service instead of the Overlay.

func (*Context) ProtocolRegister

func (c *Context) ProtocolRegister(name string, protocol NewProtocol) (ProtocolID, error)

ProtocolRegister signs up a new protocol to this Server. Contrary go GlobalProtocolRegister, the protocol registered here is tied to that server. This is useful for simulations where more than one Server exists in the global namespace. It returns the ID of the protocol.

func (*Context) RegisterMessageProxy

func (c *Context) RegisterMessageProxy(m MessageProxy)

RegisterMessageProxy registers a message proxy only for this server / overlay

func (*Context) RegisterProcessor

func (c *Context) RegisterProcessor(p network.Processor, msgType network.MessageTypeID)

RegisterProcessor overrides the RegisterProcessor methods of the Dispatcher. It delegates the dispatching to the serviceManager.

func (*Context) RegisterProcessorFunc

func (c *Context) RegisterProcessorFunc(msgType network.MessageTypeID, fn func(*network.Envelope) error)

RegisterProcessorFunc takes a message-type and a function that will be called if this message-type is received.

func (*Context) RegisterProtocolInstance

func (c *Context) RegisterProtocolInstance(pi ProtocolInstance) error

RegisterProtocolInstance registers a new instance of a protocol using overlay.

func (*Context) RegisterStatusReporter

func (c *Context) RegisterStatusReporter(name string, s StatusReporter)

RegisterStatusReporter registers a new StatusReporter.

func (*Context) ReportStatus

func (c *Context) ReportStatus() map[string]*Status

ReportStatus returns all status of the services.

func (*Context) Save

func (c *Context) Save(key []byte, data interface{}) error

Save takes a key and an interface. The interface will be network.Marshal'ed and saved in the database under the bucket named after the service name.

The data will be stored in a different bucket for every service.

func (*Context) SaveVersion

func (c *Context) SaveVersion(version int) error

SaveVersion stores the given version as the current database version.

func (*Context) SendRaw

func (c *Context) SendRaw(si *network.ServerIdentity, msg interface{}) error

SendRaw sends a message to the ServerIdentity.

func (*Context) ServerIdentity

func (c *Context) ServerIdentity() *network.ServerIdentity

ServerIdentity returns this server's identity.

func (*Context) Service

func (c *Context) Service(name string) Service

Service returns the corresponding service.

func (*Context) ServiceID

func (c *Context) ServiceID() ServiceID

ServiceID returns the service-id.

func (*Context) SetValidPeers

func (c *Context) SetValidPeers(peerID network.PeerSetID,
	peers []*network.ServerIdentity)

SetValidPeers sets the set of peers with which the server underlying this context can communicate.

func (*Context) String

func (c *Context) String() string

String returns the host it's running on.

func (*Context) Suite

func (c *Context) Suite() network.Suite

Suite returns the suite for the context's associated server.

type ContextDB

type ContextDB interface {
	Load(key []byte) (interface{}, error)
	LoadRaw(key []byte) ([]byte, error)
	LoadVersion() (int, error)
	SaveVersion(version int) error
}

The ContextDB interface allows for easy testing in the services.

type Decoder

type Decoder func(data []byte, ret interface{}) error

Decoder is a function that takes the data and the interface to fill in as input and decodes the message.

type GenericConfig

type GenericConfig struct {
	Data []byte
}

GenericConfig is a config that can hold any type of specific configs for protocols. It is passed down to the service NewProtocol function.

type LeakyTestCheck

type LeakyTestCheck int

LeakyTestCheck represents an enum to indicate how deep CloseAll needs to check the tests.

const (
	// CheckNone will make CloseAll not check anything.
	CheckNone LeakyTestCheck = iota + 1
	// CheckGoroutines will only check for leaking goroutines.
	CheckGoroutines
	// CheckAll will also check for leaking Overlay.Processors and
	// ProtocolInstances.
	CheckAll
)

type LocalTest

type LocalTest struct {
	// A map of ServerIdentity.Id to Servers
	Servers map[network.ServerIdentityID]*Server
	// A map of ServerIdentity.Id to Overlays
	Overlays map[network.ServerIdentityID]*Overlay
	// A map of ServerIdentity.Id to Services
	Services map[network.ServerIdentityID]map[ServiceID]Service
	// A map of Tree.Id to Trees
	Trees map[TreeID]*Tree
	// All single nodes
	Nodes []*TreeNodeInstance
	// How carefully to check for leaking resources at the end of the test.
	Check LeakyTestCheck

	Suite network.Suite

	T *testing.T
	// contains filtered or unexported fields
}

LocalTest represents all that is needed for a local test-run

func NewLocalTest

func NewLocalTest(s network.Suite) *LocalTest

NewLocalTest creates a new Local handler that can be used to test protocols locally

func NewLocalTestT

func NewLocalTestT(s network.Suite, t *testing.T) *LocalTest

NewLocalTestT is like NewLocalTest but also stores the testing.T variable.

func NewTCPTest

func NewTCPTest(s network.Suite) *LocalTest

NewTCPTest returns a LocalTest but using a TCPRouter as the underlying communication layer.

func NewTCPTestWithTLS

func NewTCPTestWithTLS(s network.Suite, wsTLSCertificate []byte,
	wsTLSCertificateKey []byte) *LocalTest

NewTCPTestWithTLS returns a LocalTest but using a TCPRouter as the underlying communication layer and containing information for TLS setup.

func (*LocalTest) CloseAll

func (l *LocalTest) CloseAll()

CloseAll closes all the servers.

func (*LocalTest) CreateProtocol

func (l *LocalTest) CreateProtocol(name string, t *Tree) (ProtocolInstance, error)

CreateProtocol takes a name and a tree and will create a new Node with the protocol 'name' without running it

func (*LocalTest) GenBigTree

func (l *LocalTest) GenBigTree(nbrTreeNodes, nbrServers, bf int, register bool) ([]*Server, *Roster, *Tree)

GenBigTree will create a tree of n servers. If register is true, the Roster and Tree will be registered with the overlay. 'nbrServers' is how many servers are created 'nbrTreeNodes' is how many TreeNodes are created nbrServers can be smaller than nbrTreeNodes, in which case a given server will be used more than once in the tree.

func (*LocalTest) GenRosterFromHost

func (l *LocalTest) GenRosterFromHost(servers ...*Server) *Roster

GenRosterFromHost takes a number of servers as arguments and creates an Roster.

func (*LocalTest) GenServers

func (l *LocalTest) GenServers(n int) []*Server

GenServers returns n Servers with a localRouter

func (*LocalTest) GenTree

func (l *LocalTest) GenTree(n int, register bool) ([]*Server, *Roster, *Tree)

GenTree will create a tree of n servers with a localRouter, and returns the list of servers and the associated roster / tree.

func (*LocalTest) GetPrivate

func (l *LocalTest) GetPrivate(c *Server) kyber.Scalar

GetPrivate returns the private key of a server

func (*LocalTest) GetServices

func (l *LocalTest) GetServices(servers []*Server, sid ServiceID) []Service

GetServices returns a slice of all services asked for. The sid is the id of the service that will be collected.

func (*LocalTest) GetTreeNodeInstances

func (l *LocalTest) GetTreeNodeInstances(id network.ServerIdentityID) []*TreeNodeInstance

GetTreeNodeInstances returns all TreeNodeInstances that belong to a server

func (*LocalTest) MakeSRS

func (l *LocalTest) MakeSRS(s network.Suite, nbr int, sid ServiceID) ([]*Server, *Roster, Service)

MakeSRS creates and returns nbr Servers, the associated Roster and the Service object of the first server in the list having sid as a ServiceID.

func (*LocalTest) NewClient

func (l *LocalTest) NewClient(serviceName string) *Client

NewClient returns *Client for which the types depend on the mode of the LocalContext.

func (*LocalTest) NewClientKeep

func (l *LocalTest) NewClientKeep(serviceName string) *Client

NewClientKeep returns *Client for which the types depend on the mode of the LocalContext, the connection is not closed after sending requests.

func (*LocalTest) NewLocalServer

func (l *LocalTest) NewLocalServer(s network.Suite, port int) *Server

NewLocalServer returns a fresh Host using local connections within the context of this LocalTest

func (*LocalTest) NewServer

func (l *LocalTest) NewServer(s network.Suite, port int) *Server

NewServer returns a new server which type is determined by the local mode: TCP or Local. If it's TCP, then an available port is used, otherwise, the port given in argument is used.

func (*LocalTest) NewTreeNodeInstance

func (l *LocalTest) NewTreeNodeInstance(tn *TreeNode, protName string) (*TreeNodeInstance, error)

NewTreeNodeInstance creates a new node on a TreeNode

func (*LocalTest) StartProtocol

func (l *LocalTest) StartProtocol(name string, t *Tree) (ProtocolInstance, error)

StartProtocol takes a name and a tree and will create a new Node with the protocol 'name' running from the tree-root

func (*LocalTest) WaitDone

func (l *LocalTest) WaitDone(t time.Duration) error

WaitDone loops until all protocolInstances are done or the timeout is reached. If all protocolInstances are closed within the timeout, nil is returned.

type MessageProxy

type MessageProxy interface {
	// Wrap takes a message and the overlay information and returns the message
	// that has to be sent directly to the network alongside with any error that
	// happened.
	// If msg is nil, it is only an internal message of the Overlay.
	Wrap(msg interface{}, info *OverlayMsg) (interface{}, error)
	// Unwrap takes the message coming from the network and returns the
	// inner message that is going to be dispatched to the ProtocolInstance, the
	// OverlayMessage needed by the Overlay to function correctly and then any
	// error that might have occurred.
	Unwrap(msg interface{}) (interface{}, *OverlayMsg, error)
	// PacketType returns the packet type ID that this Protocol expects from the
	// network. This is needed in order for the Overlay to receive those
	// messages and dispatch them to the correct MessageProxy.
	PacketType() network.MessageTypeID
	// Name returns the name associated with this MessageProxy. When creating a
	// protocol, if one use a name used by a MessageProxy, this MessageProxy will be
	// used to Wrap and Unwrap messages.
	Name() string
}

MessageProxy is an interface that allows one protocol to completely define its wire protocol format while still using the Overlay. Cothority sends different messages dynamically as slices of bytes, whereas Google proposes to use union-types: https://developers.google.com/protocol-buffers/docs/techniques#union This is a wrapper to enable union-types while still keeping compatibility with the dynamic cothority-messages. Implementations must provide methods to pass from the 'union-types' to 'cothority-dynamic-messages' with the Wrap and Unwrap method. A default one is provided with defaultMessageProxy so the regular wire-format protocol can still be used.

type MsgHandler

type MsgHandler func([]*interface{})

MsgHandler is called upon reception of a certain message-type

type NewMessageProxy

type NewMessageProxy func() MessageProxy

NewMessageProxy is a function typedef to instantiate a new MessageProxy.

type NewProtocol

type NewProtocol func(*TreeNodeInstance) (ProtocolInstance, error)

NewProtocol is the function-signature needed to instantiate a new protocol

type NewServiceFunc

type NewServiceFunc func(c *Context) (Service, error)

NewServiceFunc is the type of a function that is used to instantiate a given Service A service is initialized with a Server (to send messages to someone).

type Overlay

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

Overlay keeps all trees and entity-lists for a given Server. It creates Nodes and ProtocolInstances upon request and dispatches the messages.

func NewOverlay

func NewOverlay(c *Server) *Overlay

NewOverlay creates a new overlay-structure

func (*Overlay) Close

func (o *Overlay) Close()

Close calls all nodes, deletes them from the list and closes them

func (*Overlay) CreateProtocol

func (o *Overlay) CreateProtocol(name string, t *Tree, sid ServiceID) (ProtocolInstance, error)

CreateProtocol creates a ProtocolInstance, registers it to the Overlay. Additionally, if sid is different than NilServiceID, sid is added to the token so the protocol will be picked up by the correct service and handled by its NewProtocol method. If the sid is NilServiceID, then the protocol is handled by onet alone.

func (*Overlay) NewTreeNodeInstanceFromProtoName

func (o *Overlay) NewTreeNodeInstanceFromProtoName(t *Tree, name string) *TreeNodeInstance

NewTreeNodeInstanceFromProtoName takes a protocol name and a tree and instantiate a TreeNodeInstance for this protocol.

func (*Overlay) NewTreeNodeInstanceFromProtocol

func (o *Overlay) NewTreeNodeInstanceFromProtocol(t *Tree, tn *TreeNode, protoID ProtocolID, io MessageProxy) *TreeNodeInstance

NewTreeNodeInstanceFromProtocol takes a tree and a treenode (normally the root) and and protocolID and returns a fresh TreeNodeInstance.

func (*Overlay) NewTreeNodeInstanceFromService

func (o *Overlay) NewTreeNodeInstanceFromService(t *Tree, tn *TreeNode, protoID ProtocolID, servID ServiceID, io MessageProxy) *TreeNodeInstance

NewTreeNodeInstanceFromService takes a tree, a TreeNode and a service ID and returns a TNI.

func (*Overlay) Process

func (o *Overlay) Process(env *network.Envelope)

Process implements the Processor interface so it process the messages that it wants.

func (*Overlay) RegisterMessageProxy

func (o *Overlay) RegisterMessageProxy(m MessageProxy)

RegisterMessageProxy registers a message proxy only for this overlay

func (*Overlay) RegisterProtocolInstance

func (o *Overlay) RegisterProtocolInstance(pi ProtocolInstance) error

RegisterProtocolInstance takes a PI and stores it for dispatching the message to it.

func (*Overlay) RegisterTree

func (o *Overlay) RegisterTree(t *Tree)

RegisterTree takes a tree and puts it in the map

func (*Overlay) Rx

func (o *Overlay) Rx() uint64

Rx implements the CounterIO interface, should be the same as the server

func (*Overlay) SendToTreeNode

func (o *Overlay) SendToTreeNode(from *Token, to *TreeNode, msg network.Message, io MessageProxy, c *GenericConfig) (uint64, error)

SendToTreeNode sends a message to a treeNode from is the sender token to is the treenode of the destination msg is the message to send io is the messageproxy used to correctly create the wire format c is the generic config that should be sent beforehand in order to get passed in the `NewProtocol` method if a Service has created the protocol and set the config with `SetConfig`. It can be nil.

func (*Overlay) ServerIdentity

func (o *Overlay) ServerIdentity() *network.ServerIdentity

ServerIdentity Returns the entity of the Host

func (*Overlay) StartProtocol

func (o *Overlay) StartProtocol(name string, t *Tree, sid ServiceID) (ProtocolInstance, error)

StartProtocol will create and start a ProtocolInstance.

func (*Overlay) TransmitMsg

func (o *Overlay) TransmitMsg(onetMsg *ProtocolMsg, io MessageProxy) error

TransmitMsg takes a message received from the host and treats it. It might - ask for the identityList - ask for the Tree - create a new protocolInstance - pass it to a given protocolInstance io is the messageProxy to use if a specific wireformat protocol is used. It can be nil: in that case it falls back to the default wire protocol.

func (*Overlay) TreeNodeFromToken

func (o *Overlay) TreeNodeFromToken(t *Token) (*TreeNode, error)

TreeNodeFromToken returns the treeNode corresponding to a token Deprecated: only the overlay should create treeNodes but use TreeNodeFromTree if you need to create one treeNode

func (*Overlay) TreeNodeFromTree

func (o *Overlay) TreeNodeFromTree(tree *Tree, id TreeNodeID) (*TreeNode, error)

TreeNodeFromTree returns the treeNode corresponding to the id

func (*Overlay) Tx

func (o *Overlay) Tx() uint64

Tx implements the CounterIO interface, should be the same as the server

type OverlayMsg

type OverlayMsg struct {
	TreeNodeInfo *TreeNodeInfo

	// Deprecated: roster is not sent/requested anymore, only the tree
	RequestRoster *RequestRoster
	// Deprecated: roster is not sent/requested anymore, only the tree
	Roster *Roster

	RequestTree  *RequestTree
	ResponseTree *ResponseTree
	// Deprecated: use ResponseTree to send the tree and the roster
	TreeMarshal *TreeMarshal

	Config *GenericConfig
}

OverlayMsg contains all routing-information about the tree and the roster.

type ParallelOptions

type ParallelOptions struct {
	// Parallel indicates how many requests are sent in parallel.
	//   Default: half of all nodes in the roster
	Parallel int
	// AskNodes indicates how many requests are sent in total.
	//   Default: all nodes in the roster, except if StartNodes is set > 0
	AskNodes int
	// StartNode indicates where to start in the roster. If StartNode is > 0 and < len(roster),
	// but AskNodes is 0, then AskNodes will be set to len(Roster)-StartNode.
	//   Default: 0
	StartNode int
	// QuitError - if true, the first error received will be returned.
	//   Default: false
	QuitError bool
	// IgnoreNodes is a set of nodes that will not be contacted. They are counted towards
	// AskNodes and StartNode, but not contacted.
	//   Default: false
	IgnoreNodes []*network.ServerIdentity
	// DontShuffle - if true, the nodes will be contacted in the same order as given in the Roster.
	// StartNode will be applied before shuffling.
	//   Default: false
	DontShuffle bool
}

ParallelOptions defines how SendProtobufParallel behaves. Each field has a default value that will be used if 'nil' is passed to SendProtobufParallel. For integers, the default will also be used if the integer = 0.

func (*ParallelOptions) GetList

func (po *ParallelOptions) GetList(nodes []*network.ServerIdentity) (parallel int, nodesChan chan *network.ServerIdentity)

GetList returns how many requests to start in parallel and a channel of nodes to be used. If po == nil, it uses default values.

func (*ParallelOptions) Quit

func (po *ParallelOptions) Quit() bool

Quit return false if po == nil, or the value in po.QuitError.

type ProtocolID

type ProtocolID uuid.UUID

ProtocolID uniquely identifies a protocol

func GlobalProtocolRegister

func GlobalProtocolRegister(name string, protocol NewProtocol) (ProtocolID, error)

GlobalProtocolRegister registers a protocol in the global namespace. This is used in protocols that register themselves in the `init`-method. All registered protocols will be copied to every instantiated Server. If a protocol is tied to a service, use `Server.ProtocolRegisterName`

func ProtocolNameToID

func ProtocolNameToID(name string) ProtocolID

ProtocolNameToID returns the ProtocolID corresponding to the given name.

func (ProtocolID) Equal

func (pid ProtocolID) Equal(pid2 ProtocolID) bool

Equal returns true if and only if pid2 equals this ProtocolID.

func (ProtocolID) IsNil

func (pid ProtocolID) IsNil() bool

IsNil returns true iff the ProtocolID is Nil

func (ProtocolID) String

func (pid ProtocolID) String() string

String returns canonical string representation of the ID

type ProtocolInstance

type ProtocolInstance interface {
	// Start is called when a leader has created its tree configuration and
	// wants to start a protocol, it calls host.StartProtocol(protocolID), that
	// in turn instantiates a new protocol (with a fresh token), and then calls
	// Start on it.
	Start() error
	// Dispatch is called at the beginning by onet for listening on the channels
	Dispatch() error

	// ProcessProtocolMsg is a method that is called each time a message
	// arrives for this protocolInstance. TreeNodeInstance implements that
	// method for you using channels or handlers.
	ProcessProtocolMsg(*ProtocolMsg)
	// The token representing this ProtocolInstance
	Token() *Token
	// Shutdown cleans up the resources used by this protocol instance
	Shutdown() error
}

ProtocolInstance is the interface that instances have to use in order to be recognized as protocols

type ProtocolMsg

type ProtocolMsg struct {
	// Token uniquely identify the protocol instance this msg is made for
	From *Token
	// The TreeNodeId Where the message goes to
	To *Token
	// NOTE: this is taken from network.NetworkMessage
	ServerIdentity *network.ServerIdentity
	// MsgType of the underlying data
	MsgType network.MessageTypeID
	// The interface to the actual Data
	Msg network.Message
	// The actual data as binary blob
	MsgSlice []byte
	// The size of the data
	Size network.Size
	// Config is the config passed to the protocol constructor.
	Config *GenericConfig
}

ProtocolMsg is to be embedded in every message that is made for a ProtocolInstance

type RequestRoster

type RequestRoster struct {
	RosterID RosterID
}

RequestRoster is used to ask the parent for a given Roster

type RequestTree

type RequestTree struct {
	// The treeID of the tree we want
	TreeID TreeID
	// Version of the request tree
	Version uint32
}

RequestTree is used to ask the parent for a given Tree

type ResponseTree

type ResponseTree struct {
	TreeMarshal *TreeMarshal
	Roster      *Roster
}

ResponseTree contains the information to build a tree

type Roster

type Roster struct {
	// Deprecated: ID can be generated using the list of server identities. Use GetID instead.
	ID RosterID
	// List is the list of actual entities.
	List      []*network.ServerIdentity
	Aggregate kyber.Point
}

A Roster is a list of ServerIdentity we choose to run some tree on it ( and therefor some protocols). Access is not safe from multiple goroutines.

func NewRoster

func NewRoster(ids []*network.ServerIdentity) *Roster

NewRoster creates a new roster from a list of entities. It also adds a UUID which is randomly chosen.

func (*Roster) Concat

func (ro *Roster) Concat(sis ...*network.ServerIdentity) *Roster

Concat makes a new roster using an existing one and a list of server identities while preserving the order of the roster by appending at the end

func (*Roster) Contains

func (ro *Roster) Contains(pubs []kyber.Point) bool

Contains checks if the roster contains the given array of public keys and no more

func (*Roster) Equal

func (ro *Roster) Equal(other *Roster) (bool, error)

Equal checks if two roster are the same by checking the generated ID

func (*Roster) GenerateBigNaryTree

func (ro *Roster) GenerateBigNaryTree(N, nodes int) *Tree

GenerateBigNaryTree creates a tree where each node has N children. It will make a tree with exactly 'nodes' elements, regardless of the size of the Roster. If 'nodes' is bigger than the number of elements in the Roster, it will add some or all elements in the Roster more than once. If the length of the Roster is equal to 'nodes', it is guaranteed that all ServerIdentities from the Roster will be used in the tree. However, for some configurations it is impossible to use all ServerIdentities from the Roster and still avoid having a parent and a child from the same host. In this case use-all has preference over not-the-same-host.

func (*Roster) GenerateBinaryTree

func (ro *Roster) GenerateBinaryTree() *Tree

GenerateBinaryTree creates a binary tree out of the Roster out of it. The first element of the Roster will be the root element.

func (*Roster) GenerateNaryTree

func (ro *Roster) GenerateNaryTree(N int) *Tree

GenerateNaryTree creates a tree where each node has N children. The first element of the Roster will be the root element.

func (*Roster) GenerateNaryTreeWithRoot

func (ro *Roster) GenerateNaryTreeWithRoot(N int, root *network.ServerIdentity) *Tree

GenerateNaryTreeWithRoot creates a tree where each node has N children. The root is given as an ServerIdentity. If root doesn't exist in the roster, `nil` will be returned. The generation of the tree is done in a simple for-loop, so that the original roster can be used for tree creation, even if the root is not at position 0. If root == nil, the first element of the roster will be taken as root.

If you need the root node to be at the first position of the roster, then you need to create a new roster using roster.NewRosterWithRoot. Else this method does not change the underlying roster or create a new one.

func (*Roster) GenerateStar

func (ro *Roster) GenerateStar() *Tree

GenerateStar creates a star topology with the first element of Roster as root, and all other elements as children of the root.

func (*Roster) Get

func (ro *Roster) Get(idx int) *network.ServerIdentity

Get simply returns the entity that is stored at that index in the entitylist returns nil if index error

func (*Roster) GetID

func (ro *Roster) GetID() (RosterID, error)

GetID generates the ID for the list of server identities of the roster

func (Roster) IsRotation

func (ro Roster) IsRotation(target *Roster) bool

IsRotation returns true if the target is a rotated (the same roster but with shifted server identities) version of the receiver.

func (*Roster) NewRosterWithRoot

func (ro *Roster) NewRosterWithRoot(root *network.ServerIdentity) *Roster

NewRosterWithRoot returns a copy of the roster but with the given ServerIdentity at the first entry in the roster.

func (*Roster) Publics

func (ro *Roster) Publics() []kyber.Point

Publics returns the public-keys of the underlying Roster. It won't modify the underlying list.

func (*Roster) RandomServerIdentity

func (ro *Roster) RandomServerIdentity() *network.ServerIdentity

RandomServerIdentity returns a random element of the Roster.

func (*Roster) RandomSubset

func (ro *Roster) RandomSubset(root *network.ServerIdentity, n int) *Roster

RandomSubset returns a new Roster which starts with root and is followed by a random subset of n elements of ro, not including root.

func (*Roster) Search

Search searches the Roster for the given ServerIdentityID and returns the corresponding ServerIdentity.

func (Roster) ServiceAggregate

func (ro Roster) ServiceAggregate(name string) (kyber.Point, error)

ServiceAggregate returns the sum of all public keys of a given service. This is often used as the aggregate public key. If one or more of the service public keys are not present, it will return an error.

func (*Roster) ServicePublics

func (ro *Roster) ServicePublics(name string) []kyber.Point

ServicePublics returns the list of public keys for a specific service. If it is registered with a different key pair, it will return the associated one and the default key in the contrary

func (*Roster) Toml

func (ro *Roster) Toml(suite network.Suite) *RosterToml

Toml returns the toml-writable version of this roster.

type RosterID

type RosterID uuid.UUID

RosterID uniquely identifies an Roster

func (RosterID) Equal

func (roID RosterID) Equal(roID2 RosterID) bool

Equal returns true if and only if roID2 equals this RosterID.

func (RosterID) IsNil

func (roID RosterID) IsNil() bool

IsNil returns true iff the RosterID is Nil

func (RosterID) String

func (roID RosterID) String() string

String returns the default representation of the ID (wrapper around uuid.UUID.String()

type RosterToml

type RosterToml struct {
	ID   RosterID
	List []*network.ServerIdentityToml
}

RosterToml is the struct can can embedded ServerIdentityToml to be written in a toml file

func (*RosterToml) Roster

func (rot *RosterToml) Roster(suite network.Suite) *Roster

Roster returns the Id list from this toml read struct

type RosterUnknown

type RosterUnknown struct {
}

RosterUnknown is used in case the entity list is unknown

type RoundID

type RoundID uuid.UUID

RoundID uniquely identifies a round of a protocol run

func (RoundID) Equal

func (rId RoundID) Equal(rID2 RoundID) bool

Equal returns true if and only if rID2 equals this RoundID.

func (RoundID) IsNil

func (rId RoundID) IsNil() bool

IsNil returns true iff the RoundID is Nil

func (RoundID) String

func (rId RoundID) String() string

String returns the canonical representation of the rounds ID (wrapper around // uuid.UUID.String())

type Server

type Server struct {
	*network.Router

	// webservice
	WebSocket *WebSocket

	IsStarted bool
	// contains filtered or unexported fields
}

Server connects the Router, the Overlay, and the Services together. It sets up everything and returns once a working network has been set up.

func NewLocalServer

func NewLocalServer(s network.Suite, port int) *Server

NewLocalServer returns a new server using a LocalRouter (channels) to communicate. At the return of this function, the router is already Run()ing in a go routine.

func NewServerTCP

func NewServerTCP(e *network.ServerIdentity, suite network.Suite) *Server

NewServerTCP returns a new Server out of a private-key and its related public key within the ServerIdentity. The server will use a default TcpRouter as Router.

func NewServerTCPWithListenAddr

func NewServerTCPWithListenAddr(e *network.ServerIdentity, suite network.Suite,
	listenAddr string) *Server

NewServerTCPWithListenAddr returns a new Server out of a private-key and its related public key within the ServerIdentity. The server will use a TcpRouter listening on the given address as Router.

func (*Server) Address

func (c *Server) Address() network.Address

Address returns the address used by the Router.

func (*Server) Close

func (c *Server) Close() error

Close closes the overlay and the Router

func (*Server) GetService

func (c *Server) GetService(name string) Service

GetService is kept for backward-compatibility.

func (*Server) GetStatus

func (c *Server) GetStatus() *Status

GetStatus is a function that returns the status report of the server.

func (*Server) ProtocolRegister

func (c *Server) ProtocolRegister(name string, protocol NewProtocol) (ProtocolID, error)

ProtocolRegister will sign up a new protocol to this Server. It returns the ID of the protocol.

func (*Server) Service

func (c *Server) Service(name string) Service

Service returns the service with the given name.

func (*Server) Start

func (c *Server) Start()

Start makes the router and the WebSocket listen on their respective ports. It returns once all servers are started.

func (*Server) StartInBackground

func (c *Server) StartInBackground()

StartInBackground starts the services and returns once everything is up and running.

func (*Server) Suite

func (c *Server) Suite() network.Suite

Suite can (and should) be used to get the underlying Suite. Currently the suite is hardcoded into the network library. Don't use network.Suite but Host's Suite function instead if possible.

func (*Server) WaitStartup

func (c *Server) WaitStartup()

WaitStartup can be called to ensure that the server is up and running. It will loop and wait 50 milliseconds between each test.

type Service

type Service interface {
	// NewProtocol is called upon a ProtocolInstance's first message when Onet needs
	// to instantiate the protocol. A Service is expected to manually create
	// the ProtocolInstance it is using. If a Service returns (nil,nil), that
	// means this Service lets Onet handle the protocol instance.
	NewProtocol(*TreeNodeInstance, *GenericConfig) (ProtocolInstance, error)
	// ProcessClientRequest is called when a message from an external
	// client is received by the websocket for this service. The message is
	// forwarded to the corresponding handler keyed by the path. If the
	// handler is a normal one, i.e., a request-response handler, it
	// returns a message in the first return value and the second
	// (StreamingTunnel) will be set to nil. If the handler is a streaming
	// handler, the first return value is set to nil but the second
	// (StreamingTunnel) will exist. It should be used to stream messages
	// to the client. See the StreamingTunnel documentation on how it
	// should be used. The returned error will be formatted as a websocket
	// error code 4000, using the string form of the error as the message.
	ProcessClientRequest(req *http.Request, handler string, msg []byte) (reply []byte, tunnel *StreamingTunnel, err error)
	// Processor makes a Service being able to handle any kind of packets
	// directly from the network. It is used for inter service communications,
	// which are mostly single packets with no or little interactions needed. If
	// a complex logic is used for these messages, it's best to put that logic
	// into a ProtocolInstance that the Service will launch, since there's nicer
	// utilities for ProtocolInstance.
	network.Processor
}

Service is a generic interface to define any type of services. A Service has multiple roles:

  • Processing websocket client requests with ProcessClientRequests
  • Handling onet information to ProtocolInstances created with NewProtocol
  • Handling any kind of messages between Services between different hosts with the Processor interface

type ServiceID

type ServiceID uuid.UUID

ServiceID is a type to represent a uuid for a Service

func RegisterNewService

func RegisterNewService(name string, fn NewServiceFunc) (ServiceID, error)

RegisterNewService is a wrapper around service factory to register a service with the default suite

func RegisterNewServiceWithSuite

func RegisterNewServiceWithSuite(name string, suite suites.Suite, fn NewServiceFunc) (ServiceID, error)

RegisterNewServiceWithSuite is wrapper around service factory to register a service with a given suite

func (ServiceID) Equal

func (s ServiceID) Equal(s2 ServiceID) bool

Equal returns true if and only if s2 equals this ServiceID.

func (ServiceID) IsNil

func (s ServiceID) IsNil() bool

IsNil returns true iff the ServiceID is Nil

func (ServiceID) String

func (s ServiceID) String() string

String returns the string representation of this ServiceID

type ServiceProcessor

type ServiceProcessor struct {
	*Context
	// contains filtered or unexported fields
}

ServiceProcessor allows for an easy integration of external messages into the Services. You have to embed it into your Service-struct as a pointer. It will process client requests that have been registered with RegisterMessage.

func NewServiceProcessor

func NewServiceProcessor(c *Context) *ServiceProcessor

NewServiceProcessor initializes your ServiceProcessor.

func (*ServiceProcessor) IsStreaming

func (p *ServiceProcessor) IsStreaming(path string) (bool, error)

IsStreaming tell if the service registered at the given path is a streaming service or not. Return an error if the service is not registered.

func (*ServiceProcessor) NewProtocol

NewProtocol is a stub for services that don't want to intervene in the protocol-handling.

func (*ServiceProcessor) Process

func (p *ServiceProcessor) Process(env *network.Envelope)

Process implements the Processor interface and dispatches ClientRequest messages.

func (*ServiceProcessor) ProcessClientRequest

func (p *ServiceProcessor) ProcessClientRequest(req *http.Request, path string, buf []byte) ([]byte, *StreamingTunnel, error)

ProcessClientRequest implements the Service interface, see the interface documentation.

func (*ServiceProcessor) ProcessClientStreamRequest

func (p *ServiceProcessor) ProcessClientStreamRequest(req *http.Request, path string,
	clientInputs chan []byte) (chan []byte, error)

ProcessClientStreamRequest allows clients to push multiple messages asynchronously to the same service handler with the same connection. Unlike in ProcessClientRequest, we take a channel of inputs that can be filled and will subsequently call the service with any new messages received in the channel. The caller is responsible for closing the client input channel when it is done.

func (*ServiceProcessor) RegisterHandler

func (p *ServiceProcessor) RegisterHandler(f interface{}) error

RegisterHandler will store the given handler that will be used by the service. WebSocket will then forward requests to "ws://service_name/struct_name" to the given function f, which must be in the following form: func(msg interface{})(ret interface{}, err error)

  • msg is a pointer to a structure to the message sent.
  • ret is a pointer to a struct of the return-message.
  • err is an error, it can be nil, or any type that implements error.

struct_name is stripped of its package-name, so a structure like network.Body will be converted to Body.

func (*ServiceProcessor) RegisterHandlers

func (p *ServiceProcessor) RegisterHandlers(procs ...interface{}) error

RegisterHandlers takes a vararg of messages to register and returns the first error encountered or nil if everything was OK.

func (*ServiceProcessor) RegisterRESTHandler

func (p *ServiceProcessor) RegisterRESTHandler(f interface{}, namespace, method string, minVersion, maxVersion int) error

RegisterRESTHandler takes a callback of type func(msg interface{})(ret interface{}, err error), where msg and ret must be pointers to structs. For POST and PUT, the callback is registered on the URL /v$version/$namespace/$msgStructName. The client should serialize the request using JSON and set the conent type to application/json to use the service. The response is also JSON encoded.

For GET requests, the callback is registered on the same URL. But clients can also query individual resources such as /v$version/$namespace/$msgStructName/$id. For this to work, msg in the callback must be a singleton struct with either an integer or a byte slice. For integers, the client can directly query the integer resource, for byte slices, the clients must query the hex encoded representation. Using an empty struct for msg is also supported.

The min/maxVersion argument represents the range of versions where the API is present. If breaking changes must be made then they must use a new version.

This method is experimental.

func (*ServiceProcessor) RegisterStreamingHandler

func (p *ServiceProcessor) RegisterStreamingHandler(f interface{}) error

RegisterStreamingHandler stores a handler that is responsible for streaming messages to the client via a channel. Websocket will accept requests for this handler at "ws://service_name/struct_name", where struct_name is argument of f, which must be in the form: func(msg interface{})(retChan chan interface{}, closeChan chan bool, err error)

  • msg is a pointer to a structure to the message sent.
  • retChan is a channel of a pointer to a struct, everything sent into this channel will be forwarded to the client, if there are no more messages, the service should close retChan.
  • closeChan is a boolean channel, upon receiving a message on this channel, the handler must stop sending messages and close retChan.
  • err is an error, it can be nil, or any type that implements error.

struct_name is stripped of its package-name, so a structure like network.Body will be converted to Body.

func (*ServiceProcessor) RegisterStreamingHandlers

func (p *ServiceProcessor) RegisterStreamingHandlers(procs ...interface{}) error

RegisterStreamingHandlers takes a vararg of messages to register and returns the first error encountered or nil if everything was OK.

type Simulation

type Simulation interface {
	// This has to initialise all necessary files and copy them to the
	// 'dir'-directory. This directory will be accessible to all simulated
	// hosts.
	// Setup also gets a slice of all available hosts. In turn it has
	// to return a tree using one or more of these hosts. It can create
	// the Roster as desired, putting more than one ServerIdentity/Host on the same host.
	// The 'config'-argument holds all arguments read from the runfile in
	// toml-format.
	Setup(dir string, hosts []string) (*SimulationConfig, error)

	// Node will be run for every node and might be used to setup load-
	// creation. It is started once the Host is set up and running, but before
	// 'Run'
	Node(config *SimulationConfig) error

	// Run will begin with the simulation or return an error. It is sure
	// to be run on the host where 'tree.Root' is. It should only return
	// when all rounds are done.
	Run(config *SimulationConfig) error
}

Simulation is an interface needed by every protocol that wants to be available to be used in a simulation.

func NewSimulation

func NewSimulation(name string, conf string) (Simulation, error)

NewSimulation returns a simulation and decodes the 'conf' into the simulation-structure

type SimulationBFTree

type SimulationBFTree struct {
	Rounds     int
	BF         int
	Hosts      int
	SingleHost bool
	Depth      int
	Suite      string
	PreScript  string // executable script to run before the simulation on each machine
	TLS        bool   // tells if using TLS or PlainTCP addresses
}

SimulationBFTree is the main struct storing the data for all the simulations which use a tree with a certain branching factor or depth.

func (*SimulationBFTree) CreateRoster

func (s *SimulationBFTree) CreateRoster(sc *SimulationConfig, addresses []string, port int)

CreateRoster creates an Roster with the host-names in 'addresses'. It creates 's.Hosts' entries, starting from 'port' for each round through 'addresses'. The network.Address(es) created are of type TLS or PlainTCP, depending on the value 'TLS' in 'sc'.

func (*SimulationBFTree) CreateTree

func (s *SimulationBFTree) CreateTree(sc *SimulationConfig) error

CreateTree the tree as defined in SimulationBFTree and stores the result in 'sc'

func (*SimulationBFTree) Node

Node - standard registers the entityList and the Tree with that Overlay, so we don't have to pass that around for the experiments.

type SimulationConfig

type SimulationConfig struct {
	// Represents the tree that has to be used
	Tree *Tree
	// The Roster used by the tree
	Roster *Roster
	// All private keys generated by 'Setup', indexed by the complete addresses
	PrivateKeys map[network.Address]*SimulationPrivateKey
	// If non-nil, points to our overlay
	Overlay *Overlay
	// If non-nil, points to our host
	Server *Server
	// Tells if the simulation should use TLS addresses; if not, use PlainTCP
	TLS bool
	// Additional configuration used to run
	Config string
}

SimulationConfig has to be returned from 'Setup' and will be passed to 'Run'.

func LoadSimulationConfig

func LoadSimulationConfig(s, dir, ca string) ([]*SimulationConfig, error)

LoadSimulationConfig gets all configuration from dir + SimulationFileName and instantiates the corresponding host 'ca'.

func (*SimulationConfig) GetService

func (sc *SimulationConfig) GetService(name string) Service

GetService returns the service with the given name.

func (SimulationConfig) GetSingleHost

func (sc SimulationConfig) GetSingleHost() bool

GetSingleHost returns the 'SingleHost'-flag

func (*SimulationConfig) Save

func (sc *SimulationConfig) Save(dir string) error

Save takes everything in the SimulationConfig structure and saves it to dir + SimulationFileName

type SimulationConfigFile

type SimulationConfigFile struct {
	TreeMarshal *TreeMarshal
	Roster      *Roster
	PrivateKeys map[network.Address]*SimulationPrivateKey
	TLS         bool
	Config      string
}

SimulationConfigFile stores the state of the simulation's config. Only used internally.

type SimulationPrivateKey

type SimulationPrivateKey struct {
	Private  kyber.Scalar
	Services []kyber.Scalar
}

SimulationPrivateKey contains the default private key and the service private keys for the ones registered with a suite.

type Status

type Status struct {
	Field map[string]string
}

Status holds key/value pairs of the status to be returned to the requester.

type StatusReporter

type StatusReporter interface {
	GetStatus() *Status
}

StatusReporter is the interface that all structures that want to return a status will implement.

type StreamingConn

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

StreamingConn allows clients to read from it without sending additional requests.

func (*StreamingConn) Ping added in v3.2.9

func (c *StreamingConn) Ping(data []byte, deadline time.Time) error

Ping sends a ping message. Data can be nil.

func (*StreamingConn) ReadMessage

func (c *StreamingConn) ReadMessage(ret interface{}) error

ReadMessage read more data from the connection, it will block if there are no messages.

func (*StreamingConn) ReadMessageWithOpts added in v3.2.9

func (c *StreamingConn) ReadMessageWithOpts(ret interface{}, opts StreamingReadOpts) error

ReadMessageWithOpts does the same as ReadMessage and allows to pass options.

type StreamingReadOpts added in v3.2.9

type StreamingReadOpts struct {
	Deadline time.Time
}

StreamingReadOpts contains options for the ReadMessageWithOpts. It allows us to add new options in the future without making breaking changes.

type StreamingTunnel

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

StreamingTunnel is used as a tunnel between service processor and its caller, usually the websocket read-loop. When the tunnel is returned to the websocket loop, it should read from the out channel and forward the content to the client. If the client is disconnected, then the close channel should be closed. The signal exists to notify the service to stop streaming.

type TestClose

type TestClose interface {
	// TestClose can clean up things needed in the service.
	TestClose()
}

TestClose interface allows a service to clean up for the tests. It will only be called when a test calls `LocalTest.CloseAll()`.

type Token

type Token struct {
	RosterID RosterID
	TreeID   TreeID
	// TO BE REMOVED
	ProtoID   ProtocolID
	ServiceID ServiceID
	RoundID   RoundID
	// TreeNodeID is defined by the
	TreeNodeID TreeNodeID
}

A Token contains all identifiers needed to uniquely identify one protocol instance. It gets passed when a new protocol instance is created and get used by every protocol instance when they want to send a message. That way, the host knows how to create the ProtocolMsg message around the protocol's message with the right fields set.

func (*Token) ChangeTreeNodeID

func (t *Token) ChangeTreeNodeID(newid TreeNodeID) *Token

ChangeTreeNodeID return a new Token containing a reference to the given TreeNode

func (*Token) Clone

func (t *Token) Clone() *Token

Clone returns a new token out of this one

func (*Token) ID

func (t *Token) ID() TokenID

ID returns the TokenID which can be used to identify by token in map

type TokenID

type TokenID uuid.UUID

TokenID uniquely identifies the start and end-point of a message by an ID (see Token struct)

func (TokenID) Equal

func (t TokenID) Equal(t2 TokenID) bool

Equal returns true if and only if t2 equals this TokenID.

func (TokenID) IsNil

func (t TokenID) IsNil() bool

IsNil returns true iff the TokenID is Nil

func (TokenID) String

func (t TokenID) String() string

String returns the canonical representation of the TokenID (wrapper around // uuid.UUID.String())

type Tree

type Tree struct {
	ID     TreeID
	Roster *Roster
	Root   *TreeNode
}

Tree is a topology to be used by any network layer/host layer. It contains the peer list we use, and the tree we use

func NewTree

func NewTree(roster *Roster, root *TreeNode) *Tree

NewTree creates a new tree using the given roster and root. It also generates the id.

func NewTreeFromMarshal

func NewTreeFromMarshal(s network.Suite, buf []byte, el *Roster) (*Tree, error)

NewTreeFromMarshal takes a slice of bytes and an Roster to re-create the original tree

func (*Tree) BinaryMarshaler

func (t *Tree) BinaryMarshaler() ([]byte, error)

BinaryMarshaler does the same as Marshal

func (*Tree) BinaryUnmarshaler

func (t *Tree) BinaryUnmarshaler(s network.Suite, b []byte) error

BinaryUnmarshaler takes a TreeMarshal and stores it in the tree

func (*Tree) Dump

func (t *Tree) Dump() string

Dump returns string about the tree

func (*Tree) Equal

func (t *Tree) Equal(t2 *Tree) bool

Equal verifies if the given tree is equal

func (*Tree) IsBinary

func (t *Tree) IsBinary(root *TreeNode) bool

IsBinary returns true if every node has two or no children

func (*Tree) IsNary

func (t *Tree) IsNary(root *TreeNode, N int) bool

IsNary returns true if every node has two or no children

func (*Tree) List

func (t *Tree) List() (ret []*TreeNode)

List returns a list of TreeNodes generated by DFS-iterating the Tree

func (*Tree) MakeTreeMarshal

func (t *Tree) MakeTreeMarshal() *TreeMarshal

MakeTreeMarshal creates a replacement-tree that is safe to send: no parent (creates loops), only sends ids (not send the roster again)

func (*Tree) Marshal

func (t *Tree) Marshal() ([]byte, error)

Marshal creates a simple binary-representation of the tree containing only the ids of the elements. Use NewTreeFromMarshal to get back the original tree

func (*Tree) Search

func (t *Tree) Search(tn TreeNodeID) (ret *TreeNode)

Search searches the Tree for the given TreeNodeID and returns the corresponding TreeNode

func (*Tree) Size

func (t *Tree) Size() int

Size returns the number of all TreeNodes

func (*Tree) String

func (t *Tree) String() string

String writes the definition of the tree

func (*Tree) UsesList

func (t *Tree) UsesList() bool

UsesList returns true if all ServerIdentities of the list are used at least once in the tree

type TreeID

type TreeID uuid.UUID

TreeID uniquely identifies a Tree struct in the onet framework.

func (TreeID) Equal

func (tId TreeID) Equal(tID2 TreeID) bool

Equal returns true if and only if tID2 equals this TreeID.

func (TreeID) Equals

func (tId TreeID) Equals(tID2 TreeID) bool

Equals will be removed!

func (TreeID) IsNil

func (tId TreeID) IsNil() bool

IsNil returns true iff the TreeID is Nil

func (TreeID) String

func (tId TreeID) String() string

String returns a canonical representation of the TreeID.

type TreeMarshal

type TreeMarshal struct {
	// This is the UUID of the corresponding TreeNode
	TreeNodeID TreeNodeID
	// TreeId identifies the Tree for the top-node
	TreeID TreeID
	// This is the UUID of the ServerIdentity, except
	ServerIdentityID network.ServerIdentityID
	// for the top-node this contains the Roster's ID
	RosterID RosterID
	// All children from this tree. The top-node only has one child, which is
	// the root
	Children []*TreeMarshal
}

TreeMarshal is used to send and receive a tree-structure without having to copy the whole nodelist

func TreeMarshalCopyTree

func TreeMarshalCopyTree(tr *TreeNode) *TreeMarshal

TreeMarshalCopyTree takes a TreeNode and returns a corresponding TreeMarshal

func (TreeMarshal) MakeTree

func (tm TreeMarshal) MakeTree(ro *Roster) (*Tree, error)

MakeTree creates a tree given an Roster

func (*TreeMarshal) MakeTreeFromList

func (tm *TreeMarshal) MakeTreeFromList(parent *TreeNode, ro *Roster) (*TreeNode, error)

MakeTreeFromList creates a sub-tree given an Roster

func (*TreeMarshal) String

func (tm *TreeMarshal) String() string

type TreeNode

type TreeNode struct {
	// The Id represents that node of the tree
	ID TreeNodeID
	// The ServerIdentity points to the corresponding host. One given host
	// can be used more than once in a tree.
	ServerIdentity *network.ServerIdentity
	// RosterIndex is the index in the Roster where the `ServerIdentity` is located
	RosterIndex int
	// Parent link
	Parent *TreeNode
	// Children links
	Children []*TreeNode
	// Aggregate public key for *this* subtree,i.e. this node's public key + the
	// aggregate of all its children's aggregate public key
	PublicAggregateSubTree kyber.Point
}

TreeNode is one node in the tree

func NewTreeNode

func NewTreeNode(entityIdx int, ni *network.ServerIdentity) *TreeNode

NewTreeNode creates a new TreeNode with the proper Id

func (*TreeNode) AddChild

func (t *TreeNode) AddChild(c *TreeNode)

AddChild adds a child to this tree-node.

func (*TreeNode) AggregatePublic

func (t *TreeNode) AggregatePublic(s network.Suite) kyber.Point

AggregatePublic will return the aggregate public key of the TreeNode and all it's children

func (*TreeNode) Equal

func (t *TreeNode) Equal(t2 *TreeNode) bool

Equal tests if that node is equal to the given node

func (*TreeNode) IsConnectedTo

func (t *TreeNode) IsConnectedTo(si *network.ServerIdentity) bool

IsConnectedTo checks if the TreeNode can communicate with its parent or children.

func (*TreeNode) IsInTree

func (t *TreeNode) IsInTree(tree *Tree) bool

IsInTree - verifies if the TreeNode is in the given Tree

func (*TreeNode) IsLeaf

func (t *TreeNode) IsLeaf() bool

IsLeaf returns true for a node without children

func (*TreeNode) IsRoot

func (t *TreeNode) IsRoot() bool

IsRoot returns true for a node without a parent

func (*TreeNode) Name

func (t *TreeNode) Name() string

Name returns a human readable representation of the TreeNode (IP address).

func (*TreeNode) String

func (t *TreeNode) String() string

String returns the current treenode's Id as a string.

func (*TreeNode) SubtreeCount

func (t *TreeNode) SubtreeCount() int

SubtreeCount returns how many children are attached to that TreeNode.

func (*TreeNode) Visit

func (t *TreeNode) Visit(firstDepth int, fn func(depth int, n *TreeNode))

Visit is a recursive function that allows for depth-first calling on all nodes

type TreeNodeID

type TreeNodeID uuid.UUID

TreeNodeID identifies a given TreeNode struct in the onet framework.

func (TreeNodeID) Equal

func (tId TreeNodeID) Equal(tID2 TreeNodeID) bool

Equal returns true if and only if the given TreeNodeID equals tId.

func (TreeNodeID) IsNil

func (tId TreeNodeID) IsNil() bool

IsNil returns true iff the TreeNodID is Nil

func (TreeNodeID) String

func (tId TreeNodeID) String() string

String returns a canonical representation of the TreeNodeID.

type TreeNodeInfo

type TreeNodeInfo struct {
	To   *Token
	From *Token
}

TreeNodeInfo holds the sender and the destination of the message.

type TreeNodeInstance

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

TreeNodeInstance represents a protocol-instance in a given TreeNode. It embeds an Overlay where all the tree-structures are stored.

func (*TreeNodeInstance) Aggregate

func (n *TreeNodeInstance) Aggregate() kyber.Point

Aggregate returns the sum of all public key of the roster for this TreeNodeInstance, either the specific or the default if one or more of the nodes don't have the service-public key available.

func (*TreeNodeInstance) Broadcast

func (n *TreeNodeInstance) Broadcast(msg interface{}) []error

Broadcast sends a given message from the calling node directly to all other TreeNodes

func (*TreeNodeInstance) Children

func (n *TreeNodeInstance) Children() []*TreeNode

Children returns the children of ourselves

func (*TreeNodeInstance) CloseHost

func (n *TreeNodeInstance) CloseHost() error

CloseHost closes the underlying onet.Host (which closes the overlay and sends Shutdown to all protocol instances) NOTE: It is to be used VERY carefully and is likely to disappear in the next releases.

func (*TreeNodeInstance) CreateProtocol

func (n *TreeNodeInstance) CreateProtocol(name string, t *Tree) (ProtocolInstance, error)

CreateProtocol instantiates a new protocol of name "name" and returns it with any error that might have happened during the creation. If the TreeNodeInstance calling this is attached to a service, the new protocol will also be attached to this same service. Else the new protocol will only be handled by onet.

func (*TreeNodeInstance) Dispatch

func (n *TreeNodeInstance) Dispatch() error

Dispatch - the standard dispatching function is empty

func (*TreeNodeInstance) Done

func (n *TreeNodeInstance) Done()

Done calls onDoneCallback if available and only finishes when the return- value is true.

func (*TreeNodeInstance) Host

func (n *TreeNodeInstance) Host() *Server

Host returns the underlying Host of this node.

WARNING: you should not play with that feature unless you know what you are doing. This feature is meant to access the low level parts of the API. For example it is used to add a new tree config / new entity list to the Server.

func (*TreeNodeInstance) Index

func (n *TreeNodeInstance) Index() int

Index returns the index of the node in the Roster

func (*TreeNodeInstance) Info

func (n *TreeNodeInstance) Info() string

Info returns a human readable representation name of this Node (IP address and TokenID).

func (*TreeNodeInstance) IsLeaf

func (n *TreeNodeInstance) IsLeaf() bool

IsLeaf returns whether whether we are at the bottom of the tree

func (*TreeNodeInstance) IsRoot

func (n *TreeNodeInstance) IsRoot() bool

IsRoot returns whether whether we are at the top of the tree

func (*TreeNodeInstance) List

func (n *TreeNodeInstance) List() []*TreeNode

List returns the list of TreeNodes cached in the node (creating it if necessary)

func (*TreeNodeInstance) Multicast

func (n *TreeNodeInstance) Multicast(msg interface{}, nodes ...*TreeNode) []error

Multicast ... XXX: should probably have a parallel more robust version like "SendToChildrenInParallel"

func (*TreeNodeInstance) Name

func (n *TreeNodeInstance) Name() string

Name returns a human readable name of this Node (IP address).

func (*TreeNodeInstance) NodePublic

func (n *TreeNodeInstance) NodePublic(si *network.ServerIdentity) kyber.Point

NodePublic returns the public key associated with the node's service stored in the given server identity

func (*TreeNodeInstance) OnDoneCallback

func (n *TreeNodeInstance) OnDoneCallback(fn func() bool)

OnDoneCallback should be called if we want to control the Done() of the node. It is used by protocols that uses others protocols inside and that want to control when the final Done() should be called. the function should return true if the real Done() has to be called otherwise false.

func (*TreeNodeInstance) Parent

func (n *TreeNodeInstance) Parent() *TreeNode

Parent returns the parent-TreeNode of ourselves

func (*TreeNodeInstance) Private

func (n *TreeNodeInstance) Private() kyber.Scalar

Private returns the private key of the service entity

func (*TreeNodeInstance) ProcessProtocolMsg

func (n *TreeNodeInstance) ProcessProtocolMsg(msg *ProtocolMsg)

ProcessProtocolMsg takes a message and puts it into a queue for later processing. This allows a protocol to have a backlog of messages.

func (*TreeNodeInstance) ProtocolInstance

func (n *TreeNodeInstance) ProtocolInstance() ProtocolInstance

ProtocolInstance returns the instance of the running protocol

func (*TreeNodeInstance) ProtocolName

func (n *TreeNodeInstance) ProtocolName() string

ProtocolName will return the string representing that protocol

func (*TreeNodeInstance) Public

func (n *TreeNodeInstance) Public() kyber.Point

Public returns the public key of the service, either the specific or the default if not available

func (*TreeNodeInstance) Publics

func (n *TreeNodeInstance) Publics() []kyber.Point

Publics makes a list of public keys for the service associated with the instance

func (*TreeNodeInstance) RegisterChannel

func (n *TreeNodeInstance) RegisterChannel(c interface{}) error

RegisterChannel is a compatibility-method for RegisterChannelLength and setting up a channel with length 100.

func (*TreeNodeInstance) RegisterChannelLength

func (n *TreeNodeInstance) RegisterChannelLength(c interface{}, length int) error

RegisterChannelLength takes a channel with a struct that contains two elements: a TreeNode and a message. The second argument is the length of the channel. It will send every message that are the same type to this channel. This function handles also

  • registration of the message-type
  • aggregation or not of messages: if you give a channel of slices, the messages will be aggregated, else they will come one-by-one

func (*TreeNodeInstance) RegisterChannels

func (n *TreeNodeInstance) RegisterChannels(channels ...interface{}) error

RegisterChannels registers a list of given channels by calling RegisterChannel above

func (*TreeNodeInstance) RegisterChannelsLength

func (n *TreeNodeInstance) RegisterChannelsLength(length int, channels ...interface{}) error

RegisterChannelsLength is a convenience function to register a vararg of channels with a given length.

func (*TreeNodeInstance) RegisterHandler

func (n *TreeNodeInstance) RegisterHandler(c interface{}) error

RegisterHandler takes a function which takes a struct as argument that contains two elements: a TreeNode and a message. It will send every message that are the same type to this channel.

This function also handles:

  • registration of the message-type
  • aggregation or not of messages: if you give a channel of slices, the messages will be aggregated, otherwise they will come one by one

func (*TreeNodeInstance) RegisterHandlers

func (n *TreeNodeInstance) RegisterHandlers(handlers ...interface{}) error

RegisterHandlers registers a list of given handlers by calling RegisterHandler above

func (*TreeNodeInstance) Root

func (n *TreeNodeInstance) Root() *TreeNode

Root returns the root-node of that tree

func (*TreeNodeInstance) Roster

func (n *TreeNodeInstance) Roster() *Roster

Roster returns the entity-list

func (*TreeNodeInstance) Rx

func (n *TreeNodeInstance) Rx() uint64

Rx implements the CounterIO interface

func (*TreeNodeInstance) SendTo

func (n *TreeNodeInstance) SendTo(to *TreeNode, msg interface{}) error

SendTo sends to a given node

func (*TreeNodeInstance) SendToChildren

func (n *TreeNodeInstance) SendToChildren(msg interface{}) error

SendToChildren sends a given message to all children of the calling node. It stops sending if sending to one of the children fails. In that case it returns an error. If the underlying node is a leaf node this function does nothing.

func (*TreeNodeInstance) SendToChildrenInParallel

func (n *TreeNodeInstance) SendToChildrenInParallel(msg interface{}) []error

SendToChildrenInParallel sends a given message to all children of the calling node. It has the following differences to node.SendToChildren: The actual sending happens in a go routine (in parallel). It continues sending to the other nodes if sending to one of the children fails. In that case it will collect all errors in a slice. If the underlying node is a leaf node this function does nothing.

func (*TreeNodeInstance) SendToParent

func (n *TreeNodeInstance) SendToParent(msg interface{}) error

SendToParent sends a given message to the parent of the calling node (unless it is the root)

func (*TreeNodeInstance) ServerIdentity

func (n *TreeNodeInstance) ServerIdentity() *network.ServerIdentity

ServerIdentity returns our entity

func (*TreeNodeInstance) SetConfig

func (n *TreeNodeInstance) SetConfig(c *GenericConfig) error

SetConfig sets the GenericConfig c to be passed down in the first message alongside with the protocol if it is non nil. This config can later be read by Services in the NewProtocol method.

func (*TreeNodeInstance) Shutdown

func (n *TreeNodeInstance) Shutdown() error

Shutdown - standard Shutdown implementation. Define your own in your protocol (if necessary)

func (*TreeNodeInstance) Suite

func (n *TreeNodeInstance) Suite() network.Suite

Suite can be used to get the kyber.Suite associated with the service. It can be either the default suite or the one registered with the service.

func (*TreeNodeInstance) Token

func (n *TreeNodeInstance) Token() *Token

Token returns a CLONE of the underlying onet.Token struct. Useful for unit testing.

func (*TreeNodeInstance) TokenID

func (n *TreeNodeInstance) TokenID() TokenID

TokenID returns the TokenID of the given node (to uniquely identify it)

func (*TreeNodeInstance) Tree

func (n *TreeNodeInstance) Tree() *Tree

Tree returns the tree of that node. Because the storage keeps the tree around until the protocol is done, this will never return a nil value. It will panic if the tree is nil.

func (*TreeNodeInstance) TreeNode

func (n *TreeNodeInstance) TreeNode() *TreeNode

TreeNode gets the treeNode of this node. If there is no TreeNode for the Token of this node, the function will return nil

func (*TreeNodeInstance) TreeNodeInstance

func (n *TreeNodeInstance) TreeNodeInstance() *TreeNodeInstance

TreeNodeInstance returns itself (XXX quick hack for this services2 branch version for the tests)

func (*TreeNodeInstance) Tx

func (n *TreeNodeInstance) Tx() uint64

Tx implements the CounterIO interface

type WebSocket

type WebSocket struct {
	TLSConfig *tls.Config // can only be modified before Start is called
	sync.Mutex
	// contains filtered or unexported fields
}

WebSocket handles incoming client-requests using the websocket protocol. When making a new WebSocket, it will listen one port above the ServerIdentity-port-#. The websocket protocol has been chosen as smallest common denominator for languages including JavaScript.

func NewWebSocket

func NewWebSocket(si *network.ServerIdentity) *WebSocket

NewWebSocket opens a webservice-listener at the given si.URL.

func (*WebSocket) Listening

func (w *WebSocket) Listening() bool

Listening returns true if the server has been started and is listening on the ports for incoming connections.

Directories

Path Synopsis
dummy
Package Dummy's only purpose is to create a DB that can be tested by the dbadmin binary.
Package Dummy's only purpose is to create a DB that can be tested by the dbadmin binary.
Package log is an output-library that can print nicely formatted messages to the screen.
Package log is an output-library that can print nicely formatted messages to the screen.
Package simul allows for easy simulation on different platforms.
Package simul allows for easy simulation on different platforms.
monitor
Package monitor package handle the logging, collection and computation of statistical data.
Package monitor package handle the logging, collection and computation of statistical data.
platform
Package platform contains interface and implementation to run onet code amongst multiple platforms.
Package platform contains interface and implementation to run onet code amongst multiple platforms.

Jump to

Keyboard shortcuts

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