core

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2018 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultBeaconPeriod time.Duration = 1 * time.Minute

DefaultBeaconPeriod is the period in which the beacon logic creates new random beacon.

View Source
const DefaultConfigFolderName = ".drand"

DefaultConfigFolderName is the name of the folder containing all key materials (and the beacons db file by default). It is relative to the user's home directory.

View Source
const DefaultControlPort = "8888"

DefaultControlPort is the default port the functionnality control port communicate on.

View Source
const DefaultDbFolder = "db"

DefaultDbFolder is the name of the folder in which the db file is saved. By default it is relative to the DefaultConfigFolder path.

Variables

View Source
var DefaultSeed = []byte("Truth is like the sun. You can shut it out for a time, but it ain't goin' away.")

DefaultSeed is the message signed during the first beacon generation, alongside with the round number 0.

Functions

func DefaultConfigFolder

func DefaultConfigFolder() string

DefaultConfigFolder returns the default path of the configuration folder.

Types

type Client

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

Client is the endpoint logic, communicating with drand servers

func NewGrpcClient added in v0.3.7

func NewGrpcClient(opts ...grpc.DialOption) *Client

NewGrpcClient returns a Client able to talk to drand instances using gRPC communication method

func NewGrpcClientFromCert added in v0.3.7

func NewGrpcClientFromCert(c *net.CertManager, opts ...grpc.DialOption) *Client

NewGrpcClientFromCert returns a client that contact its peer over TLS

func NewRESTClient added in v0.3.7

func NewRESTClient() *Client

NewRESTClient returns a client that uses the HTTP Rest API delivered by drand nodes

func NewRESTClientFromCert added in v0.3.7

func NewRESTClientFromCert(c *net.CertManager) *Client

NewRESTClientFromCert returns a client that uses the HTTP Rest API delivered by drand nodes, using TLS connection for peers registered

func (*Client) DistKey added in v0.3.7

func (c *Client) DistKey(addr string, secure bool) (*crypto.Point, error)

DistKey returns the distributed key the node at this address is holding.

func (*Client) LastPublic

func (c *Client) LastPublic(addr string, pub *key.DistPublic, secure bool) (*drand.PublicRandResponse, error)

LastPublic returns the last randomness beacon from the server associated. It returns it if the randomness is valid. Secure indicates that the request must be made over a TLS protected channel.

func (*Client) Private

func (c *Client) Private(id *key.Identity) ([]byte, error)

Private retrieves a private random value from the server. It does that by generating an ephemeral key pair, sends it encrypted to the remote server, and decrypts the response, the randomness. Client will attempt a TLS connection to the address in the identity if id.IsTLS() returns true

func (*Client) Public added in v0.4.0

func (c *Client) Public(addr string, pub *key.DistPublic, secure bool, round int) (*drand.PublicRandResponse, error)

Public returns the random output of the specified beacon at a given index. It returns it if the randomness is valid. Secure indicates that the request must be made over a TLS protected channel.

type Config

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

Config holds all relevant information for a drand node to run.

func NewConfig

func NewConfig(opts ...ConfigOption) *Config

NewConfig returns the config to pass to drand with the default options set and the updated values given by the options.

func (*Config) Certs added in v0.3.7

func (d *Config) Certs() *net.CertManager

Certs returns all custom certs currently being trusted by drand.

func (*Config) ConfigFolder

func (d *Config) ConfigFolder() string

ConfigFolder returns the folder under which drand stores all its configuration.

func (*Config) ControlPort added in v0.4.0

func (d *Config) ControlPort() string

ControlPort returns the port used for control port communications which can be the default one or the port setup thanks to WithControlPort

func (*Config) DBFolder

func (d *Config) DBFolder() string

DBFolder returns the folder under which drand stores all generated beacons.

func (*Config) ListenAddress

func (d *Config) ListenAddress(defaultAddr string) string

ListenAddress returns the given default address or the listen address stored in the config thanks to WithListenAddress

type ConfigOption

type ConfigOption func(*Config)

ConfigOption is a function that applies a specific setting to a Config.

func WithBeaconCallback

func WithBeaconCallback(fn func(*beacon.Beacon)) ConfigOption

WithBeaconCallback sets a function that is called each time a new random beacon is generated.

func WithBoltOptions

func WithBoltOptions(opts *bolt.Options) ConfigOption

WithBoltOptions applies boltdb specific options when storing random beacons.

func WithCallOption added in v0.3.7

func WithCallOption(opts ...grpc.CallOption) ConfigOption

WithCallOption applies grpc options when drand calls a gRPC method.

func WithConfigFolder

func WithConfigFolder(folder string) ConfigOption

WithConfigFolder sets the base configuration folder to the given string.

func WithControlPort added in v0.4.0

func WithControlPort(port string) ConfigOption

WithControlPort specifies which port on localhost the ListenerControl should bind to.

func WithDbFolder

func WithDbFolder(folder string) ConfigOption

WithDbFolder sets the path folder for the db file. This path is NOT relative to the DrandFolder path if set.

func WithDkgTimeout

func WithDkgTimeout(t time.Duration) ConfigOption

WithDkgTimeout sets the timeout under which the DKG must finish.

func WithGrpcOptions

func WithGrpcOptions(opts ...grpc.DialOption) ConfigOption

WithGrpcOptions applies grpc dialling option used when a drand node actively contacts another.

func WithInsecure added in v0.3.7

func WithInsecure() ConfigOption

WithInsecure allows drand to listen on standard non-encrypted port and to contact other nodes over non-encrypted TCP connections.

func WithListenAddress

func WithListenAddress(addr string) ConfigOption

WithListenAddress specifies the address the drand instance should bind to. It is useful if you want to advertise a public proxy address and the drand instance runs behind your network.

func WithTLS added in v0.3.7

func WithTLS(certPath, keyPath string) ConfigOption

WithTLS registers the certificates and private key path so drand can accept and issue connections using TLS.

func WithTrustedCerts added in v0.3.7

func WithTrustedCerts(certPaths ...string) ConfigOption

WithTrustedCerts saves the certificates at the given paths and forces drand to trust them. Mostly useful for testing.

type Drand

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

Drand is the main logic of the program. It reads the keys / group file, it can start the DKG, read/write shars to files and can initiate/respond to TBlS signature requests.

func LoadDrand

func LoadDrand(s key.Store, c *Config) (*Drand, error)

LoadDrand restores a drand instance that is ready to serve randomness, with a pre-existing distributed share.

func NewDrand

func NewDrand(s key.Store, c *Config) (*Drand, error)

NewDrand returns an drand struct. It assumes the private key pair has been generated and saved already.

func (*Drand) BeaconLoop

func (d *Drand) BeaconLoop() error

BeaconLoop starts periodically the TBLS protocol. The seed is the first message signed alongside with the current timestamp. All subsequent signatures are chained: s_i+1 = SIG(s_i || timestamp) For the moment, each resulting signature is stored in a file named beacons/<timestamp>.sig. The period is determined according the group.toml this node belongs to.

func (*Drand) CollectiveKey added in v0.4.0

func (d *Drand) CollectiveKey(ctx context.Context, in *control.CokeyRequest) (*control.CokeyResponse, error)

CollectiveKey replies with the distributed key in the response

func (*Drand) DistKey added in v0.3.7

DistKey returns the distributed key corresponding to the current group

func (*Drand) Group added in v0.4.0

Group replies with the current group of this drand node

func (*Drand) Home added in v0.4.1

Home ...

func (*Drand) InitDKG added in v0.4.0

InitDKG take a DKGRequest, extracts the informations needed and wait for the DKG protocol to finish. If the request specifies this node is a leader, it starts the DKG protocol.

func (*Drand) InitReshare added in v0.4.0

InitReshare receives information about the old and new group from which to operate the resharing protocol. It starts the resharing protocol if the received node is stated as a leader and is present in the old group. This function waits for the resharing DKG protocol to finish.

func (*Drand) NewBeacon

func (d *Drand) NewBeacon(c context.Context, in *drand.BeaconRequest) (*drand.BeaconResponse, error)

NewBeacon methods receives a beacon generation requests and answers with the partial signature from this drand node.

func (*Drand) PingPong added in v0.4.0

func (d *Drand) PingPong(c context.Context, in *control.Ping) (*control.Pong, error)

PingPong simply responds with an empty packet, proving that this drand node is up and alive.

func (*Drand) Private

Private returns an ECIES encrypted random blob of 32 bytes from /dev/urandom

func (*Drand) PrivateKey added in v0.4.0

PrivateKey is a functionality of Control Service defined in protobuf/control that requests the long term private key of the drand node running locally

func (*Drand) Public

Public returns a public random beacon according to the request. If the Round field is 0, then it returns the last one generated.

func (*Drand) PublicKey added in v0.4.0

PublicKey is a functionality of Control Service defined in protobuf/control that requests the long term public key of the drand node running locally

func (*Drand) Reshare added in v0.4.0

Reshare is called when a resharing protocol is in progress

func (*Drand) Setup

Setup is the public method to call during a DKG protocol.

func (*Drand) Share added in v0.4.0

Share is a functionality of Control Service defined in protobuf/control that requests the private share of the drand node running locally

func (*Drand) StartBeacon added in v0.4.0

func (d *Drand) StartBeacon() error

StartBeacon initializes the beacon if needed and launch a go routine that runs the generation loop.

func (*Drand) StartDKG

func (d *Drand) StartDKG() error

StartDKG starts the DKG protocol by sending the first packet of the DKG protocol to every other node in the group. It returns nil if the DKG protocol finished successfully or an error otherwise.

func (*Drand) Stop

func (d *Drand) Stop()

Stop simply stops all drand operations.

func (*Drand) StopBeacon added in v0.4.0

func (d *Drand) StopBeacon()

StopBeacon stops the beacon generation process and resets it.

func (*Drand) WaitDKG

func (d *Drand) WaitDKG() error

WaitDKG waits on the running dkg protocol. In case of an error, it returns it. In case of a finished DKG protocol, it saves the dist. public key and private share. These should be loadable by the store.

Jump to

Keyboard shortcuts

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