net

package
v2.0.5-testnet Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2024 License: Apache-2.0, MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const MaxSyncBuffer = 500

MaxSyncBuffer is the maximum number of queued rounds when syncing

Variables

This section is empty.

Functions

func NewDKGControlClient

func NewDKGControlClient(l log.Logger, addr string) (pdkg.DKGControlClient, error)

func RemoteAddress

func RemoteAddress(ctx context.Context) string

RemoteAddress returns the address of the peer by first taking the address that gRPC returns. If that address is a reserved address, then it tries to read the "X-REAL-IP" header content. For example, a valid nginx config could include

```

location / {
      grpc_pass grpc://127.0.0.1:9091;
      grpc_set_header X-Real-IP $remote_addr;
}

```

Types

type CallOption

type CallOption = grpc.CallOption

CallOption is simply a wrapper around the grpc options

type Client

Client implements methods to call on the protocol API and the public API of a drand node

func NewGrpcClient

func NewGrpcClient(l log.Logger, opts ...grpc.DialOption) Client

NewGrpcClient returns an implementation of an InternalClient and ExternalClient using gRPC connections

type ControlClient

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

ControlClient is a struct that implement proto.ControlClient and is used to request a Share to a ControlListener on a specific port

func NewControlClient

func NewControlClient(l log.Logger, addr string) (*ControlClient, error)

NewControlClient creates a client capable of issuing proto commands to a 127.0.0.1 running drand node.

func (*ControlClient) BackupDB

func (c *ControlClient) BackupDB(outFile, beaconID string) error

BackupDB backs up the database to a file

func (*ControlClient) ChainInfo

func (c *ControlClient) ChainInfo(beaconID string) (*proto.ChainInfoPacket, error)

ChainInfo returns the collective key of the remote node

func (*ControlClient) Close

func (c *ControlClient) Close() error

func (*ControlClient) GroupFile

func (c *ControlClient) GroupFile(beaconID string) (*proto.GroupPacket, error)

GroupFile returns the group file that the drand instance uses at the current time

func (*ControlClient) ListBeaconIDs

func (c *ControlClient) ListBeaconIDs() (*proto.ListBeaconIDsResponse, error)

ListBeaconIDs returns a list of all beacon ids

func (*ControlClient) ListSchemes

func (c *ControlClient) ListSchemes() (*proto.ListSchemesResponse, error)

ListSchemes responds with the list of ids for the available schemes

func (*ControlClient) LoadBeacon

func (c *ControlClient) LoadBeacon(beaconID string) (*proto.LoadBeaconResponse, error)

LoadBeacon loads the beacon details

func (*ControlClient) Ping

func (c *ControlClient) Ping() error

Ping the drand daemon to check if it's up and running

func (*ControlClient) PublicKey

func (c *ControlClient) PublicKey(beaconID string) (*proto.PublicKeyResponse, error)

PublicKey returns the public key of the remote node

func (*ControlClient) RemoteStatus

func (c *ControlClient) RemoteStatus(ct context.Context,
	addresses []*proto.Address,
	beaconID string) (map[string]*proto.StatusResponse, error)

func (*ControlClient) Shutdown

func (c *ControlClient) Shutdown(beaconID string) (*proto.ShutdownResponse, error)

Shutdown stops the daemon

func (*ControlClient) StartCheckChain

func (c *ControlClient) StartCheckChain(cc context.Context,
	hashStr string,
	nodes []string,
	upTo uint64,
	beaconID string) (outCh chan *proto.SyncProgress, errCh chan error, e error)

StartCheckChain initiates the check chain process

func (*ControlClient) StartFollowChain

func (c *ControlClient) StartFollowChain(cc context.Context,
	hashStr string,
	nodes []string,
	upTo uint64,
	beaconID string) (outCh chan *proto.SyncProgress, errCh chan error, e error)

StartFollowChain initiates the client catching up on an existing chain it is not part of

func (*ControlClient) Status

func (c *ControlClient) Status(beaconID string) (*proto.StatusResponse, error)

Status gets the current daemon status

type ControlListener

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

ControlListener is used to keep state for the connections of our drand instance

func NewGRPCListener

func NewGRPCListener(l log.Logger, s Service, controlAddr string) (ControlListener, error)

NewGRPCListener registers the pairing between a ControlServer and a grpc server. Note that this is using a regular, non-TLS listener, this is assuming the node is behind a reverse proxy doing TLS termination.

func (*ControlListener) Start

func (g *ControlListener) Start()

Start the listener for the proto commands

func (*ControlListener) Stop

func (g *ControlListener) Stop()

Stop the listener and connections By default, the Stop call will try to terminate all connections nicely. However, after a timeout, it will forcefully close all connections and terminate.

type DKGClient

type DKGClient interface {
	Packet(ctx context.Context, p Peer, packet *pdkg.GossipPacket, opts ...grpc.CallOption) (*pdkg.EmptyDKGResponse, error)
	BroadcastDKG(ctx context.Context, p Peer, in *pdkg.DKGPacket, opts ...grpc.CallOption) (*pdkg.EmptyDKGResponse, error)
}

type Listener

type Listener interface {
	Start()
	Stop(ctx context.Context)
	Addr() string
}

Listener is the active listener for incoming requests.

func NewGRPCListenerForPrivate

func NewGRPCListenerForPrivate(ctx context.Context, bindingAddr string, s Service, opts ...grpc.ServerOption) (Listener, error)

NewGRPCListenerForPrivate creates a new listener for the Public and Protocol APIs over GRPC.

func NewRESTListenerForPublic

func NewRESTListenerForPublic(ctx context.Context, bindingAddr string, handler http.Handler) (Listener, error)

NewRESTListenerForPublic creates a new listener for the Public API over REST.

type MetricsClient

type MetricsClient interface {
	GetMetrics(ctx context.Context, addr string) (string, error)
}

type Peer

type Peer interface {
	Address() string
}

Peer is a simple interface that allows retrieving the address of a destination. It might further be enhanced with certificates properties and all.

func CreatePeer

func CreatePeer(addr string) Peer

CreatePeer creates a peer from an address

type PrivateGateway

PrivateGateway is the main interface to communicate to other drand nodes. It acts as a listener to receive incoming requests and acts a client connecting to drand participants. The gateway fixes all drand functionalities offered by drand.

func NewGRPCPrivateGateway

func NewGRPCPrivateGateway(ctx context.Context, listen string, s Service, opts ...grpc.DialOption) (*PrivateGateway, error)

NewGRPCPrivateGateway returns a grpc gateway listening on "listen" for the public methods, listening on "port" for the control methods, using the given Service s with the given options.

func (*PrivateGateway) StartAll

func (g *PrivateGateway) StartAll()

StartAll starts the control and public functionalities of the node

func (*PrivateGateway) StopAll

func (g *PrivateGateway) StopAll(ctx context.Context)

StopAll stops the control and public functionalities of the node

type ProtocolClient

type ProtocolClient interface {
	GetIdentity(ctx context.Context, p Peer, in *drand.IdentityRequest, opts ...CallOption) (*drand.IdentityResponse, error)
	SyncChain(ctx context.Context, p Peer, in *drand.SyncRequest, opts ...CallOption) (chan *drand.BeaconPacket, error)
	PartialBeacon(ctx context.Context, p Peer, in *drand.PartialBeaconPacket, opts ...CallOption) error
	Status(context.Context, Peer, *drand.StatusRequest, ...grpc.CallOption) (*drand.StatusResponse, error)
}

ProtocolClient holds all the methods of the protocol API that drand protocols use. See protobuf/drand/protocol.proto for more information.

type PublicClient

type PublicClient interface {
	PublicRandStream(ctx context.Context, p Peer, in *drand.PublicRandRequest, opts ...CallOption) (chan *drand.PublicRandResponse, error)
	PublicRand(ctx context.Context, p Peer, in *drand.PublicRandRequest) (*drand.PublicRandResponse, error)
	ChainInfo(ctx context.Context, p Peer, in *drand.ChainInfoRequest) (*drand.ChainInfoPacket, error)
	Home(ctx context.Context, p Peer, in *drand.HomeRequest) (*drand.HomeResponse, error)
	ListBeaconIDs(ctx context.Context, p Peer) (*drand.ListBeaconIDsResponse, error)
}

PublicClient holds all the methods of the public API . See `protobuf/drand/public.proto` for more information.

type PublicGateway

type PublicGateway struct {
	Listener
}

PublicGateway is the main interface to communicate to users. The gateway fixes all drand functionalities offered by drand.

func NewRESTPublicGateway

func NewRESTPublicGateway(ctx context.Context, listen string, handler http.Handler) (*PublicGateway, error)

NewRESTPublicGateway returns a grpc gateway listening on "listen" for the public methods, listening on "port" for the control methods, using the given Service s with the given options.

func (*PublicGateway) StartAll

func (g *PublicGateway) StartAll()

StartAll starts the control and public functionalities of the node

func (*PublicGateway) StopAll

func (g *PublicGateway) StopAll(ctx context.Context)

StopAll stops the control and public functionalities of the node

type Service

Service holds all functionalities that a drand node should implement

type Stoppable

type Stoppable interface {
	Stop()
}

Stoppable is an interface that some clients can implement to close their operations

Jump to

Keyboard shortcuts

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