network

package
v0.0.0-...-bca9f57 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2022 License: BSD-3-Clause Imports: 43 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TLSConfig

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

Types

type Config

type Config struct {
	HealthConfig         `json:"healthConfig"`
	PeerListGossipConfig `json:"peerListGossipConfig"`
	GossipConfig         `json:"gossipConfig"`
	TimeoutConfig        `json:"timeoutConfigs"`
	DelayConfig          `json:"delayConfig"`
	ThrottlerConfig      ThrottlerConfig `json:"throttlerConfig"`

	DialerConfig dialer.Config `json:"dialerConfig"`
	TLSConfig    *tls.Config   `json:"-"`

	Namespace          string              `json:"namespace"`
	MyNodeID           ids.ShortID         `json:"myNodeID"`
	MyIP               utils.DynamicIPDesc `json:"myIP"`
	NetworkID          uint32              `json:"networkID"`
	MaxClockDifference time.Duration       `json:"maxClockDifference"`
	PingFrequency      time.Duration       `json:"pingFrequency"`
	AllowPrivateIPs    bool                `json:"allowPrivateIPs"`
	CompressionEnabled bool                `json:"compressionEnabled"`
	// This node's TLS key
	TLSKey crypto.Signer `json:"-"`
	// WhitelistedSubnets of the node
	WhitelistedSubnets ids.Set        `json:"whitelistedSubnets"`
	Beacons            validators.Set `json:"beacons"`
	// Current validators in the Avalanche network
	Validators        validators.Manager `json:"validators"`
	UptimeCalculator  uptime.Calculator  `json:"-"`
	UptimeMetricFreq  time.Duration      `json:"uptimeMetricFreq"`
	UptimeRequirement float64            `json:"uptimeRequirement"`

	// Require that all connections must have at least one validator between the
	// 2 peers. This can be useful to enable if the node wants to connect to the
	// minimum number of nodes without impacting the network negatively.
	RequireValidatorToConnect bool `json:"requireValidatorToConnect"`
}

type DelayConfig

type DelayConfig struct {
	InitialReconnectDelay time.Duration `json:"initialReconnectDelay"`
	MaxReconnectDelay     time.Duration `json:"maxReconnectDelay"`
}

type GossipConfig

type GossipConfig struct {
	GossipAcceptedFrontierSize uint `json:"gossipAcceptedFrontierSize"`
	GossipOnAcceptSize         uint `json:"gossipOnAcceptSize"`
	AppGossipNonValidatorSize  uint `json:"appGossipNonValidatorSize"`
	AppGossipValidatorSize     uint `json:"appGossipValidatorSize"`
}

type HealthConfig

type HealthConfig struct {
	// Must be connected to at least this many peers to be considered healthy
	MinConnectedPeers uint `json:"minConnectedPeers"`

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

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

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

	// 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 `json:"maxSendFailRate"`

	// 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 `json:"maxSendFailRateHalflife"`
}

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.
	snow.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) []PeerInfo

	// 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

	NodeUptime() (UptimeResult, bool)

	// Has a health check
	health.Checkable
}

Network defines the functionality of the networking library.

func NewNetwork

func NewNetwork(
	config *Config,
	msgCreator message.Creator,
	metricsRegisterer prometheus.Registerer,
	log logging.Logger,
	listener net.Listener,
	router router.Router,
	benchlistManager benchlist.Manager,
) (Network, error)

NewNetwork returns a new Network implementation with the provided parameters.

type PeerInfo

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

type PeerListGossipConfig

type PeerListGossipConfig struct {
	PeerListSize                 uint32        `json:"peerListSize"`
	PeerListGossipSize           uint32        `json:"peerListGossipSize"`
	PeerListStakerGossipFraction uint32        `json:"peerListStakerGossipFraction"`
	PeerListGossipFreq           time.Duration `json:"peerListGossipFreq"`
}

type ThrottlerConfig

type ThrottlerConfig struct {
	InboundConnUpgradeThrottlerConfig throttling.InboundConnUpgradeThrottlerConfig `json:"inboundConnUpgradeThrottlerConfig"`
	InboundMsgThrottlerConfig         throttling.InboundMsgThrottlerConfig         `json:"inboundMsgThrottlerConfig"`
	OutboundMsgThrottlerConfig        throttling.MsgByteThrottlerConfig            `json:"outboundMsgThrottlerConfig"`
	MaxIncomingConnsPerSec            float64                                      `json:"maxIncomingConnsPerSec"`
}

type TimeoutConfig

type TimeoutConfig struct {
	GetVersionTimeout    time.Duration `json:"getVersionTimeout"`
	PingPongTimeout      time.Duration `json:"pingPongTimeout"`
	ReadHandshakeTimeout time.Duration `json:"readHandshakeTimeout"`
	// peerAliasTimeout is the age a peer alias must
	// be before we attempt to release it (so that we
	// attempt to dial the IP again if gossiped to us).
	PeerAliasTimeout time.Duration `json:"peerAliasTimeout"`
}

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

type UptimeResult

type UptimeResult struct {
	WeightedAveragePercentage float64
	RewardingStakePercentage  float64
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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