net

package
v1.4.7 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2022 License: Apache-2.0, MIT Imports: 31 Imported by: 3

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 RemoteAddress added in v1.0.0

func RemoteAddress(c 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 added in v0.3.7

type CallOption = grpc.CallOption

CallOption is simply a wrapper around the grpc options

type CertManager added in v0.3.7

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

CertManager is used to managed certificates. It is most commonly used for testing with self-signed certificate. By default, it returns the bundled set of certificates coming with the OS (Go's implementation).

func NewCertManager added in v0.3.7

func NewCertManager() *CertManager

NewCertManager returns a cert manager filled with the trusted certificates of the running system

func (*CertManager) Add added in v0.3.7

func (p *CertManager) Add(certPath string) error

Add tries to add the certificate at the given path to the pool and returns an error otherwise

func (*CertManager) Pool added in v0.3.7

func (p *CertManager) Pool() *x509.CertPool

Pool returns the pool of trusted certificates

type Client

type Client interface {
	ProtocolClient
	PublicClient
	HTTPClient
}

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

func NewGrpcClient

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

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

func NewGrpcClientFromCertManager added in v0.3.7

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

NewGrpcClientFromCertManager returns a Client using gRPC with the given trust store of certificates.

func NewGrpcClientWithTimeout added in v0.3.6

func NewGrpcClientWithTimeout(timeout time.Duration, opts ...grpc.DialOption) Client

NewGrpcClientWithTimeout returns a Client using gRPC using fixed timeout for method calls.

type ControlClient added in v0.4.0

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

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

func NewControlClient added in v0.4.0

func NewControlClient(addr string) (*ControlClient, error)

NewControlClient creates a client capable of issuing control commands to a localhost running drand node.

func (*ControlClient) BackupDB added in v1.2.6

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

BackupDB backs up the database to a file

func (*ControlClient) ChainInfo added in v1.0.0

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

ChainInfo returns the collective key of the remote node

func (*ControlClient) GroupFile added in v0.5.2

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

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

func (*ControlClient) InitDKG added in v0.4.0

func (c *ControlClient) InitDKG(leader Peer, entropy *control.EntropyInfo, secret, beaconID string) (*control.GroupPacket, error)

InitDKG sets up the node to be ready for a first DKG protocol.

func (*ControlClient) InitDKGLeader added in v0.7.1

func (c *ControlClient) InitDKGLeader(
	nodes, threshold int,
	beaconPeriod, catchupPeriod, timeout time.Duration,
	entropy *control.EntropyInfo,
	secret string,
	offset int,
	schemeID string,
	beaconID string) (*control.GroupPacket, error)

InitDKGLeader sets up the node to be ready for a first DKG protocol. groupPart NOTE: only group referral via filesystem path is supported at the moment. XXX Might be best to move to core/

func (*ControlClient) InitReshare added in v0.4.0

func (c *ControlClient) InitReshare(leader Peer, secret, oldPath string, force bool, beaconID string) (*control.GroupPacket, error)

InitReshare sets up the node to be ready for a resharing protocol.

func (*ControlClient) InitReshareLeader added in v0.7.1

func (c *ControlClient) InitReshareLeader(
	nodes, threshold int,
	timeout, catchupPeriod time.Duration,
	secret, oldPath string,
	offset int,
	beaconID string) (*control.GroupPacket, error)

InitReshareLeader sets up the node to be ready for a resharing protocol. NOTE: only group referral via filesystem path is supported at the moment. XXX Might be best to move to core/

func (*ControlClient) ListBeaconIDs added in v1.4.6

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

ListBeaconIDs

func (*ControlClient) ListSchemes added in v1.4.6

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

ListSchemes responds with the list of ids for the available schemes

func (*ControlClient) LoadBeacon added in v1.4.6

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

LoadBeacon

func (*ControlClient) Ping added in v0.4.0

func (c *ControlClient) Ping() error

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

func (*ControlClient) PrivateKey added in v0.4.0

func (c *ControlClient) PrivateKey(beaconID string) (*control.PrivateKeyResponse, error)

PrivateKey returns the private key of the remote node

func (*ControlClient) PublicKey added in v0.4.0

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

PublicKey returns the public key of the remote node

func (*ControlClient) RemoteStatus added in v1.4.6

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

func (*ControlClient) Share added in v0.4.0

func (c *ControlClient) Share(beaconID string) (*control.ShareResponse, error)

Share returns the share of the remote node

func (*ControlClient) Shutdown added in v0.5.4

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

Shutdown stops the daemon

func (*ControlClient) StartCheckChain added in v1.4.6

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

StartCheckChain initiates the check chain process

func (*ControlClient) StartFollowChain added in v1.0.2

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

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

func (*ControlClient) Status added in v1.4.6

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

Status gets the current daemon status

type ControlListener added in v0.4.0

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

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

func NewTCPGrpcControlListener added in v0.4.0

func NewTCPGrpcControlListener(s control.ControlServer, controlAddr string) (ControlListener, error)

NewTCPGrpcControlListener registers the pairing between a ControlServer and a grpc server

func (*ControlListener) Start added in v0.4.0

func (g *ControlListener) Start()

Start the listener for the control commands

func (*ControlListener) Stop added in v0.4.0

func (g *ControlListener) Stop()

Stop the listener and connections

type DefaultControlServer added in v0.4.0

type DefaultControlServer struct {
	C control.ControlServer
}

DefaultControlServer implements the functionalities of Control Service, and just as Default Service, it is used for testing.

func (*DefaultControlServer) ChainInfo added in v1.0.0

ChainInfo gets the current chain information from the ndoe

func (*DefaultControlServer) PingPong added in v0.4.0

func (s *DefaultControlServer) PingPong(c ctx.Context, in *control.Ping) (*control.Pong, error)

PingPong sends a ping to the server

func (*DefaultControlServer) PrivateKey added in v0.4.0

PrivateKey gets the node's private key

func (*DefaultControlServer) PublicKey added in v0.4.0

PublicKey gets the node's public key

func (*DefaultControlServer) RemoteStatus added in v1.4.6

func (*DefaultControlServer) Share added in v0.4.0

Share initiates a share request

func (*DefaultControlServer) Status added in v1.4.6

Status initiates a status request

type HTTPClient added in v1.0.0

type HTTPClient interface {
	HandleHTTP(p Peer) (http.Handler, error)
}

HTTPClient is an optional extension to the protocol client relaying of HTTP over the GRPC connection. it is currently used for relaying metrics between group members.

type HexJSON added in v0.4.0

type HexJSON struct{}

HexJSON transforms json into hex string instead of b64

func (*HexJSON) ContentType added in v0.4.0

func (*HexJSON) ContentType() string

ContentType always Returns "application/json".

func (*HexJSON) Delimiter added in v0.4.0

func (j *HexJSON) Delimiter() []byte

Delimiter for newline encoded JSON streams.

func (*HexJSON) Marshal added in v0.4.0

func (j *HexJSON) Marshal(v interface{}) ([]byte, error)

Marshal marshals "v" into JSON

func (*HexJSON) NewDecoder added in v0.4.0

func (j *HexJSON) NewDecoder(r io.Reader) runtime.Decoder

NewDecoder returns a Decoder which reads JSON stream from "r".

func (*HexJSON) NewEncoder added in v0.4.0

func (j *HexJSON) NewEncoder(w io.Writer) runtime.Encoder

NewEncoder returns an Encoder which writes JSON stream into "w".

func (*HexJSON) Unmarshal added in v0.4.0

func (j *HexJSON) Unmarshal(data []byte, v interface{}) error

Unmarshal unmarshals JSON data into "v".

type Listener

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

Listener is the active listener for incoming requests.

func NewGRPCListenerForPrivate added in v0.9.0

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

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

func NewRESTListenerForPublic added in v0.9.0

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

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

type Peer

type Peer interface {
	Address() string
	IsTLS() bool
}

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 added in v0.7.1

func CreatePeer(addr string, tls bool) Peer

CreatePeer creates a peer from an address

type PrivateGateway added in v0.9.0

type PrivateGateway struct {
	Listener
	ProtocolClient
	PublicClient
}

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 added in v1.0.0

func NewGRPCPrivateGateway(ctx context.Context,
	listen, certPath, keyPath string,
	certs *CertManager,
	s Service,
	insecure bool, 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 added in v0.9.0

func (g *PrivateGateway) StartAll()

StartAll starts the control and public functionalities of the node

func (*PrivateGateway) StopAll added in v0.9.0

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

StopAll stops the control and public functionalities of the node

type ProtocolClient added in v0.5.2

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
	BroadcastDKG(c context.Context, p Peer, in *drand.DKGPacket, opts ...CallOption) error
	SignalDKGParticipant(ctx context.Context, p Peer, in *drand.SignalDKGPacket, opts ...CallOption) error
	PushDKGInfo(ctx context.Context, p Peer, in *drand.DKGInfoPacket, opts ...grpc.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 added in v0.5.2

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)
}

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

type PublicGateway added in v0.9.0

type PublicGateway struct {
	Listener
}

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

func NewRESTPublicGateway added in v1.0.0

func NewRESTPublicGateway(
	ctx context.Context,
	listen, certPath, keyPath string,
	certs *CertManager,
	handler http.Handler,
	insecure bool) (*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 added in v0.9.0

func (g *PublicGateway) StartAll()

StartAll starts the control and public functionalities of the node

func (*PublicGateway) StopAll added in v0.9.0

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 added in v1.2.0

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