network

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2022 License: BSD-3-Clause Imports: 41 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMaxMessageSize uint32 = 2 * units.MiB
)

reasonable default values

Variables

This section is empty.

Functions

func TLSConfig

func TLSConfig(cert tls.Certificate) *tls.Config

Types

type Config

type Config struct {
	HealthConfig
	InboundConnThrottlerConfig throttling.InboundConnThrottlerConfig
	InboundThrottlerConfig     throttling.MsgThrottlerConfig
	OutboundThrottlerConfig    throttling.MsgThrottlerConfig
	timer.AdaptiveTimeoutConfig
	DialerConfig dialer.Config
	// [Registerer] is set in node's initMetricsAPI method
	MetricsRegisterer prometheus.Registerer
}

type HealthConfig

type HealthConfig struct {
	// Must be connected to at least this many peers to be considered healthy
	MinConnectedPeers uint

	// Must have received a message from the network within this duration
	// to be considered healthy. Must be positive
	MaxTimeSinceMsgReceived time.Duration

	// Must have sent a message over the network within this duration
	// to be considered healthy. Must be positive
	MaxTimeSinceMsgSent time.Duration

	// If greater than this portion of the pending send byte queue is full,
	// will report unhealthy. Must be in (0,1]
	MaxPortionSendQueueBytesFull float64

	// If greater than this portion of the attempts to send a message to a peer
	// fail, will return unhealthy. Does not include send attempts that were not
	// made due to benching. Must be in [0,1]
	MaxSendFailRate float64

	// Halflife of averager used to calculate the send fail rate
	// Must be > 0.
	// Larger value --> Drop rate affected less by recent messages
	MaxSendFailRateHalflife time.Duration
}

HealthConfig describes parameters for network layer health checks.

type Network

type Network interface {
	// All consensus messages can be sent through this interface. Thread safety
	// must be managed internally in the network.
	sender.ExternalSender

	// The network must be able to broadcast accepted decisions to random peers.
	// Thread safety must be managed internally in the network.
	triggers.Acceptor

	// Should only be called once, will run until either a fatal error occurs,
	// or the network is closed. Returns a non-nil error.
	Dispatch() error

	// Attempt to connect to this IP. Thread safety must be managed internally
	// to the network. The network will never stop attempting to connect to this
	// IP.
	TrackIP(ip utils.IPDesc)

	// Attempt to connect to this node ID at IP. Thread safety must be managed
	// internally to the network.
	Track(ip utils.IPDesc, nodeID ids.ShortID)

	// Returns the description of the specified [nodeIDs] this network is currently
	// connected to externally or all nodes this network is connected to if [nodeIDs]
	// is empty. Thread safety must be managed internally to the network.
	Peers(nodeIDs []ids.ShortID) []PeerID

	// Close this network and all existing connections it has. Thread safety
	// must be managed internally to the network. Calling close multiple times
	// will return a nil error.
	Close() error

	// Return the IP of the node
	IP() utils.IPDesc

	// Has a health check
	health.Checkable
}

Network defines the functionality of the networking library.

func NewDefaultNetwork

func NewDefaultNetwork(
	namespace string,
	registerer prometheus.Registerer,
	log logging.Logger,
	id ids.ShortID,
	ip utils.DynamicIPDesc,
	networkID uint32,
	versionCompatibility version.Compatibility,
	parser version.ApplicationParser,
	listener net.Listener,
	dialer dialer.Dialer,
	serverUpgrader,
	clientUpgrader Upgrader,
	vdrs validators.Set,
	beacons validators.Set,
	router router.Router,
	inboundConnThrottlerConfig throttling.InboundConnThrottlerConfig,
	healthConfig HealthConfig,
	benchlistManager benchlist.Manager,
	peerAliasTimeout time.Duration,
	tlsKey crypto.Signer,
	peerListSize int,
	peerListGossipSize int,
	peerListGossipFreq time.Duration,
	isFetchOnly bool,
	gossipAcceptedFrontierSize uint,
	gossipOnAcceptSize uint,
	compressionEnabled bool,
	inboundMsgThrottler throttling.InboundMsgThrottler,
	outboundMsgThrottler throttling.OutboundMsgThrottler,
) (Network, error)

NewDefaultNetwork returns a new Network implementation with the provided parameters and some reasonable default values.

func NewNetwork

func NewNetwork(
	namespace string,
	registerer prometheus.Registerer,
	log logging.Logger,
	id ids.ShortID,
	ip utils.DynamicIPDesc,
	networkID uint32,
	versionCompatibility version.Compatibility,
	parser version.ApplicationParser,
	listener net.Listener,
	dialer dialer.Dialer,
	serverUpgrader,
	clientUpgrader Upgrader,
	vdrs validators.Set,
	beacons validators.Set,
	router router.Router,
	initialReconnectDelay,
	maxReconnectDelay time.Duration,
	maxMessageSize uint32,
	maxClockDifference time.Duration,
	peerListSize int,
	peerListGossipFreq time.Duration,
	peerListGossipSize int,
	peerListStakerGossipFraction int,
	getVersionTimeout time.Duration,
	allowPrivateIPs bool,
	gossipAcceptedFrontierSize uint,
	gossipOnAcceptSize uint,
	pingPongTimeout time.Duration,
	pingFrequency time.Duration,
	readBufferSize uint32,
	readHandshakeTimeout time.Duration,
	inboundConnThrottlerConfig throttling.InboundConnThrottlerConfig,
	healthConfig HealthConfig,
	benchlistManager benchlist.Manager,
	peerAliasTimeout time.Duration,
	tlsKey crypto.Signer,
	isFetchOnly bool,
	compressionEnabled bool,
	inboundMsgThrottler throttling.InboundMsgThrottler,
	outboundMsgThrottler throttling.OutboundMsgThrottler,
) (Network, error)

NewNetwork returns a new Network implementation with the provided parameters.

type PeerElement

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

holds onto the peer object as a result of helper functions

type PeerID

type PeerID struct {
	IP           string    `json:"ip"`
	PublicIP     string    `json:"publicIP"`
	ID           string    `json:"nodeID"`
	Version      string    `json:"version"`
	LastSent     time.Time `json:"lastSent"`
	LastReceived time.Time `json:"lastReceived"`
	Benched      []ids.ID  `json:"benched"`
}

type Upgrader

type Upgrader interface {
	// Must be thread safe
	Upgrade(net.Conn) (ids.ShortID, net.Conn, *x509.Certificate, error)
}

func NewTLSClientUpgrader

func NewTLSClientUpgrader(config *tls.Config) Upgrader

func NewTLSServerUpgrader

func NewTLSServerUpgrader(config *tls.Config) Upgrader

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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