Documentation ¶
Index ¶
- Constants
- Variables
- func DefaultConfigFolder() string
- type Client
- func (c *Client) DistKey(addr string, secure bool) (*crypto.Point, error)
- func (c *Client) LastPublic(addr string, pub *key.DistPublic, secure bool) (*drand.PublicRandResponse, error)
- func (c *Client) Private(id *key.Identity) ([]byte, error)
- func (c *Client) Public(addr string, pub *key.DistPublic, secure bool, round int) (*drand.PublicRandResponse, error)
- type Config
- type ConfigOption
- func WithBeaconCallback(fn func(*beacon.Beacon)) ConfigOption
- func WithBoltOptions(opts *bolt.Options) ConfigOption
- func WithCallOption(opts ...grpc.CallOption) ConfigOption
- func WithConfigFolder(folder string) ConfigOption
- func WithControlPort(port string) ConfigOption
- func WithDbFolder(folder string) ConfigOption
- func WithDkgTimeout(t time.Duration) ConfigOption
- func WithGrpcOptions(opts ...grpc.DialOption) ConfigOption
- func WithInsecure() ConfigOption
- func WithListenAddress(addr string) ConfigOption
- func WithTLS(certPath, keyPath string) ConfigOption
- func WithTrustedCerts(certPaths ...string) ConfigOption
- type Drand
- func (d *Drand) BeaconLoop() error
- func (d *Drand) CollectiveKey(ctx context.Context, in *control.CokeyRequest) (*control.CokeyResponse, error)
- func (d *Drand) DistKey(context.Context, *drand.DistKeyRequest) (*drand.DistKeyResponse, error)
- func (d *Drand) Group(ctx context.Context, in *control.GroupRequest) (*control.GroupResponse, error)
- func (d *Drand) Home(c context.Context, in *drand.HomeRequest) (*drand.HomeResponse, error)
- func (d *Drand) InitDKG(c context.Context, in *control.DKGRequest) (*control.DKGResponse, error)
- func (d *Drand) InitReshare(c context.Context, in *control.ReshareRequest) (*control.ReshareResponse, error)
- func (d *Drand) NewBeacon(c context.Context, in *drand.BeaconRequest) (*drand.BeaconResponse, error)
- func (d *Drand) PingPong(c context.Context, in *control.Ping) (*control.Pong, error)
- func (d *Drand) Private(c context.Context, priv *drand.PrivateRandRequest) (*drand.PrivateRandResponse, error)
- func (d *Drand) PrivateKey(ctx context.Context, in *control.PrivateKeyRequest) (*control.PrivateKeyResponse, error)
- func (d *Drand) Public(c context.Context, in *drand.PublicRandRequest) (*drand.PublicRandResponse, error)
- func (d *Drand) PublicKey(ctx context.Context, in *control.PublicKeyRequest) (*control.PublicKeyResponse, error)
- func (d *Drand) Reshare(c context.Context, in *dkg_proto.ResharePacket) (*dkg_proto.ReshareResponse, error)
- func (d *Drand) Setup(c context.Context, in *dkg_proto.DKGPacket) (*dkg_proto.DKGResponse, error)
- func (d *Drand) Share(ctx context.Context, in *control.ShareRequest) (*control.ShareResponse, error)
- func (d *Drand) StartBeacon() error
- func (d *Drand) StartDKG() error
- func (d *Drand) Stop()
- func (d *Drand) StopBeacon()
- func (d *Drand) WaitDKG() error
Constants ¶
const DefaultBeaconPeriod time.Duration = 1 * time.Minute
DefaultBeaconPeriod is the period in which the beacon logic creates new random beacon.
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.
const DefaultControlPort = "8888"
DefaultControlPort is the default port the functionnality control port communicate on.
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 ¶
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
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 ¶
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 ¶
ConfigFolder returns the folder under which drand stores all its configuration.
func (*Config) ControlPort ¶ added in v0.4.0
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 ¶
DBFolder returns the folder under which drand stores all generated beacons.
func (*Config) ListenAddress ¶
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 ¶
LoadDrand restores a drand instance that is ready to serve randomness, with a pre-existing distributed share.
func NewDrand ¶
NewDrand returns an drand struct. It assumes the private key pair has been generated and saved already.
func (*Drand) BeaconLoop ¶
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
func (d *Drand) DistKey(context.Context, *drand.DistKeyRequest) (*drand.DistKeyResponse, error)
DistKey returns the distributed key corresponding to the current group
func (*Drand) Group ¶ added in v0.4.0
func (d *Drand) Group(ctx context.Context, in *control.GroupRequest) (*control.GroupResponse, error)
Group replies with the current group of this drand node
func (*Drand) Home ¶ added in v0.4.1
func (d *Drand) Home(c context.Context, in *drand.HomeRequest) (*drand.HomeResponse, error)
Home ...
func (*Drand) InitDKG ¶ added in v0.4.0
func (d *Drand) InitDKG(c context.Context, in *control.DKGRequest) (*control.DKGResponse, error)
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
func (d *Drand) InitReshare(c context.Context, in *control.ReshareRequest) (*control.ReshareResponse, error)
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
PingPong simply responds with an empty packet, proving that this drand node is up and alive.
func (*Drand) Private ¶
func (d *Drand) Private(c context.Context, priv *drand.PrivateRandRequest) (*drand.PrivateRandResponse, error)
Private returns an ECIES encrypted random blob of 32 bytes from /dev/urandom
func (*Drand) PrivateKey ¶ added in v0.4.0
func (d *Drand) PrivateKey(ctx context.Context, in *control.PrivateKeyRequest) (*control.PrivateKeyResponse, error)
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 ¶
func (d *Drand) Public(c context.Context, in *drand.PublicRandRequest) (*drand.PublicRandResponse, error)
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
func (d *Drand) PublicKey(ctx context.Context, in *control.PublicKeyRequest) (*control.PublicKeyResponse, error)
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
func (d *Drand) Reshare(c context.Context, in *dkg_proto.ResharePacket) (*dkg_proto.ReshareResponse, error)
Reshare is called when a resharing protocol is in progress
func (*Drand) Share ¶ added in v0.4.0
func (d *Drand) Share(ctx context.Context, in *control.ShareRequest) (*control.ShareResponse, error)
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
StartBeacon initializes the beacon if needed and launch a go routine that runs the generation loop.
func (*Drand) StartDKG ¶
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) StopBeacon ¶ added in v0.4.0
func (d *Drand) StopBeacon()
StopBeacon stops the beacon generation process and resets it.