network

package
v1.9.2-rc.1 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2022 License: BSD-3-Clause Imports: 35 Imported by: 25

Documentation

Overview

Package network is a generated GoMock package.

Index

Constants

View Source
const (
	ConnectedPeersKey           = "connectedPeers"
	TimeSinceLastMsgReceivedKey = "timeSinceLastMsgReceived"
	TimeSinceLastMsgSentKey     = "timeSinceLastMsgSent"
	SendFailRateKey             = "sendFailRate"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config added in v1.4.10

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

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

	TLSKeyLogFile string `json:"tlsKeyLogFile"`

	Namespace          string            `json:"namespace"`
	MyNodeID           ids.NodeID        `json:"myNodeID"`
	MyIPPort           ips.DynamicIPPort `json:"myIP"`
	NetworkID          uint32            `json:"networkID"`
	MaxClockDifference time.Duration     `json:"maxClockDifference"`
	PingFrequency      time.Duration     `json:"pingFrequency"`
	AllowPrivateIPs    bool              `json:"allowPrivateIPs"`

	// CompressionEnabled will compress available outbound messages when set to
	// true.
	CompressionEnabled bool `json:"compressionEnabled"`

	// TLSKey is this node's TLS key that is used to sign IPs.
	TLSKey crypto.Signer `json:"-"`

	// WhitelistedSubnets of the node.
	WhitelistedSubnets ids.Set        `json:"-"`
	Beacons            validators.Set `json:"-"`

	// Validators are the current validators in the Avalanche network
	Validators validators.Manager `json:"-"`

	UptimeCalculator uptime.Calculator `json:"-"`

	// UptimeMetricFreq marks how frequently this node will recalculate the
	// observed average uptime metrics.
	UptimeMetricFreq time.Duration `json:"uptimeMetricFreq"`

	// UptimeRequirement is the fraction of time a validator must be online and
	// responsive for us to vote that they should receive a staking reward.
	UptimeRequirement float64 `json:"-"`

	// RequireValidatorToConnect 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"`

	// MaximumInboundMessageTimeout is the maximum deadline duration in a
	// message. Messages sent by clients setting values higher than this value
	// will be reset to this value.
	MaximumInboundMessageTimeout time.Duration `json:"maximumInboundMessageTimeout"`

	// Size, in bytes, of the buffer that we read peer messages into
	// (there is one buffer per peer)
	PeerReadBufferSize int `json:"peerReadBufferSize"`

	// Size, in bytes, of the buffer that we write peer messages into
	// (there is one buffer per peer)
	PeerWriteBufferSize int `json:"peerWriteBufferSize"`

	// Tracks the CPU/disk usage caused by processing messages of each peer.
	ResourceTracker tracker.ResourceTracker `json:"-"`

	// Specifies how much CPU usage each peer can cause before
	// we rate-limit them.
	CPUTargeter tracker.Targeter `json:"-"`

	// Specifies how much disk usage each peer can cause before
	// we rate-limit them.
	DiskTargeter tracker.Targeter `json:"-"`
}

type DelayConfig added in v1.6.1

type DelayConfig struct {
	// InitialReconnectDelay is the minimum amount of time the node will delay a
	// reconnection to a peer. This value is used to start the exponential
	// backoff.
	InitialReconnectDelay time.Duration `json:"initialReconnectDelay"`

	// MaxReconnectDelay is the maximum amount of time the node will delay a
	// reconnection to a peer.
	MaxReconnectDelay time.Duration `json:"maxReconnectDelay"`
}

type GossipTracker

type GossipTracker interface {
	// Contains returns if a peer is being tracked
	// Returns:
	// 	[ok]: False if [id] is not tracked. True otherwise.
	Contains(id ids.NodeID) (ok bool)
	// Add starts tracking a peer
	// Returns :
	// 	[ok]: False if [id] is tracked. True otherwise.
	Add(id ids.NodeID) (ok bool)
	// Remove stops tracking a given peer
	// Returns:
	// 	[ok]: False if [id] is not tracked. True otherwise.
	Remove(id ids.NodeID) (ok bool)
	// UpdateKnown adds [learned] to the peers known by [id]
	// Returns:
	// 	[ok]: False if [id] is not tracked. True otherwise.
	UpdateKnown(id ids.NodeID, learned []ids.NodeID) (ok bool)
	// GetUnknown gets the peers that we haven't sent to this peer
	// Returns:
	// 	[unknown]: a slice of [limit] peers that [id] doesn't know about
	// 	[ok]: False if [id] is not tracked. True otherwise.
	GetUnknown(id ids.NodeID, limit int) (unknown []ids.NodeID, ok bool)
}

GossipTracker tracks the peers that we're currently aware of, as well as the peers we've told other peers about. This data is stored in a bitset to optimize space, where only N (num peers) bits will be used.

This is done by recording some state information of both what peers this node is aware of, and what peers we've told each peer about. As an example, say we track three peers (most-significant-bit first):

local: 		[1, 1, 1] // [p3, p2, p1] we always know about everyone
knownPeers:	{
	p1: [1, 1, 1] // we have already told [p1] about all peers
	p2: [0, 1, 1] // [p2] doesn't know about [p3]
	p3: [0, 0, 1] // [p3] knows only about [p3]
}

GetUnknown computes the information we haven't sent to a given peer (using the bitwise AND NOT operator). Ex:

GetUnknown(p1) -  [0, 0, 0]
GetUnknown(p2) -  [1, 0, 0]
GetUnknown(p3) -  [1, 1, 0]

Using the gossipTracker, we can quickly compute the peers each peer doesn't know about using GetUnknown so that in subsequent PeerList gossip messages we only send information that this peer (most likely) doesn't already know about. The only edge-case where we'll send a redundant set of bytes is if another remote peer gossips to the same peer we're trying to gossip to first.

func NewGossipTracker

func NewGossipTracker(config GossipTrackerConfig) (GossipTracker, error)

NewGossipTracker returns an instance of gossipTracker

type GossipTrackerConfig

type GossipTrackerConfig struct {
	ValidatorManager validators.Manager
	Registerer       prometheus.Registerer
	Namespace        string
}

type HealthConfig added in v1.2.1

type HealthConfig struct {
	// MinConnectedPeers is the minimum number of peers that the network should
	// be connected to to be considered healthy.
	MinConnectedPeers uint `json:"minConnectedPeers"`

	// MaxTimeSinceMsgReceived is the maximum amount of time since the network
	// last received a message to be considered healthy.
	MaxTimeSinceMsgReceived time.Duration `json:"maxTimeSinceMsgReceived"`

	// MaxTimeSinceMsgSent is the maximum amount of time since the network last
	// sent a message to be considered healthy.
	MaxTimeSinceMsgSent time.Duration `json:"maxTimeSinceMsgSent"`

	// MaxPortionSendQueueBytesFull is the maximum percentage of the pending
	// send byte queue that should be used for the network to be considered
	// healthy. Should be in (0,1].
	MaxPortionSendQueueBytesFull float64 `json:"maxPortionSendQueueBytesFull"`

	// MaxSendFailRate is the maximum percentage of send attempts that should be
	// failing for the network to be considered healthy. This does not include
	// send attempts that were not made due to benching. Should be in [0,1].
	MaxSendFailRate float64 `json:"maxSendFailRate"`

	// SendFailRateHalflife is the halflife of the averager used to calculate
	// the send fail rate percentage. Should be > 0. Larger values mean that the
	// fail rate is affected less by recently dropped messages.
	SendFailRateHalflife time.Duration `json:"sendFailRateHalflife"`
}

HealthConfig describes parameters for network layer health checks.

type MockGossipTracker

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

MockGossipTracker is a mock of GossipTracker interface.

func NewMockGossipTracker

func NewMockGossipTracker(ctrl *gomock.Controller) *MockGossipTracker

NewMockGossipTracker creates a new mock instance.

func (*MockGossipTracker) Add

func (m *MockGossipTracker) Add(id ids.NodeID) bool

Add mocks base method.

func (*MockGossipTracker) Contains

func (m *MockGossipTracker) Contains(id ids.NodeID) bool

Contains mocks base method.

func (*MockGossipTracker) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockGossipTracker) GetUnknown

func (m *MockGossipTracker) GetUnknown(id ids.NodeID, limit int) ([]ids.NodeID, bool)

GetUnknown mocks base method.

func (*MockGossipTracker) Remove

func (m *MockGossipTracker) Remove(id ids.NodeID) bool

Remove mocks base method.

func (*MockGossipTracker) UpdateKnown

func (m *MockGossipTracker) UpdateKnown(id ids.NodeID, learned []ids.NodeID) bool

UpdateKnown mocks base method.

type MockGossipTrackerMockRecorder

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

MockGossipTrackerMockRecorder is the mock recorder for MockGossipTracker.

func (*MockGossipTrackerMockRecorder) Add

func (mr *MockGossipTrackerMockRecorder) Add(id interface{}) *gomock.Call

Add indicates an expected call of Add.

func (*MockGossipTrackerMockRecorder) Contains

func (mr *MockGossipTrackerMockRecorder) Contains(id interface{}) *gomock.Call

Contains indicates an expected call of Contains.

func (*MockGossipTrackerMockRecorder) GetUnknown

func (mr *MockGossipTrackerMockRecorder) GetUnknown(id, limit interface{}) *gomock.Call

GetUnknown indicates an expected call of GetUnknown.

func (*MockGossipTrackerMockRecorder) Remove

func (mr *MockGossipTrackerMockRecorder) Remove(id interface{}) *gomock.Call

Remove indicates an expected call of Remove.

func (*MockGossipTrackerMockRecorder) UpdateKnown

func (mr *MockGossipTrackerMockRecorder) UpdateKnown(id, learned interface{}) *gomock.Call

UpdateKnown indicates an expected call of UpdateKnown.

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

	// Has a health check
	health.Checker

	peer.Network
	common.SubnetTracker

	// StartClose this network and all existing connections it has. Calling
	// StartClose multiple times is handled gracefully.
	StartClose()

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

	// WantsConnection returns true if this node is willing to attempt to
	// connect to the provided nodeID. If the node is attempting to connect to
	// the minimum number of peers, then it should only connect if the peer is a
	// validator or beacon.
	WantsConnection(ids.NodeID) bool

	// Attempt to connect to this IP. The network will never stop attempting to
	// connect to this ID.
	ManuallyTrack(nodeID ids.NodeID, ip ips.IPPort)

	// PeerInfo returns information about peers. If [nodeIDs] is empty, returns
	// info about all peers that have finished the handshake. Otherwise, returns
	// info about the peers in [nodeIDs] that have finished the handshake.
	PeerInfo(nodeIDs []ids.NodeID) []peer.Info

	NodeUptime() (UptimeResult, bool)
}

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,
	dialer dialer.Dialer,
	router router.ExternalHandler,
) (Network, error)

NewNetwork returns a new Network implementation with the provided parameters.

type PeerListGossipConfig added in v1.6.1

type PeerListGossipConfig struct {
	// PeerListNumValidatorIPs is the number of validator IPs to gossip in every
	// gossip event.
	PeerListNumValidatorIPs uint32 `json:"peerListNumValidatorIPs"`

	// PeerListValidatorGossipSize is the number of validators to gossip the IPs
	// to in every IP gossip event.
	PeerListValidatorGossipSize uint32 `json:"peerListValidatorGossipSize"`

	// PeerListNonValidatorGossipSize is the number of non-validators to gossip
	// the IPs to in every IP gossip event.
	PeerListNonValidatorGossipSize uint32 `json:"peerListNonValidatorGossipSize"`

	// PeerListPeersGossipSize is the number of peers to gossip
	// the IPs to in every IP gossip event.
	PeerListPeersGossipSize uint32 `json:"peerListPeersGossipSize"`

	// PeerListGossipFreq is the frequency that this node will attempt to gossip
	// signed IPs to its peers.
	PeerListGossipFreq time.Duration `json:"peerListGossipFreq"`
}

type ThrottlerConfig added in v1.6.1

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

type TimeoutConfig added in v1.6.1

type TimeoutConfig struct {
	// PingPongTimeout is the maximum amount of time to wait for a Pong response
	// from a peer we sent a Ping to.
	PingPongTimeout time.Duration `json:"pingPongTimeout"`

	// ReadHandshakeTimeout is the maximum amount of time to wait for the peer's
	// connection upgrade to finish before starting the p2p handshake.
	ReadHandshakeTimeout time.Duration `json:"readHandshakeTimeout"`
}

type UptimeResult added in v1.7.0

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