Documentation ¶
Index ¶
- Constants
- Variables
- func TLSConfig(cert tls.Certificate) *tls.Config
- type Builder
- func (m Builder) Accepted(chainID ids.ID, requestID uint32, containerIDs []ids.ID) (Msg, error)
- func (m Builder) AcceptedFrontier(chainID ids.ID, requestID uint32, containerIDs []ids.ID) (Msg, error)
- func (m Builder) Chits(chainID ids.ID, requestID uint32, containerIDs []ids.ID) (Msg, error)
- func (m Builder) Get(chainID ids.ID, requestID uint32, deadline uint64, containerID ids.ID) (Msg, error)
- func (m Builder) GetAccepted(chainID ids.ID, requestID uint32, deadline uint64, containerIDs []ids.ID) (Msg, error)
- func (m Builder) GetAcceptedFrontier(chainID ids.ID, requestID uint32, deadline uint64) (Msg, error)
- func (m Builder) GetAncestors(chainID ids.ID, requestID uint32, deadline uint64, containerID ids.ID) (Msg, error)
- func (m Builder) GetPeerList() (Msg, error)
- func (m Builder) GetVersion() (Msg, error)
- func (m Builder) MultiPut(chainID ids.ID, requestID uint32, containers [][]byte) (Msg, error)
- func (m Builder) PeerList(peers []utils.IPCertDesc) (Msg, error)
- func (m Builder) Ping() (Msg, error)
- func (m Builder) Pong() (Msg, error)
- func (m Builder) PullQuery(chainID ids.ID, requestID uint32, deadline uint64, containerID ids.ID) (Msg, error)
- func (m Builder) PushQuery(chainID ids.ID, requestID uint32, deadline uint64, containerID ids.ID, ...) (Msg, error)
- func (m Builder) Put(chainID ids.ID, requestID uint32, containerID ids.ID, container []byte) (Msg, error)
- func (m Builder) Version(networkID, nodeID uint32, myTime uint64, ip utils.IPDesc, myVersion string, ...) (Msg, error)
- type Codec
- type ConnMeter
- type Dialer
- type DialerConfig
- type Field
- type HealthConfig
- type Msg
- type Network
- type Op
- type PeerElement
- type PeerID
- type Throttler
- type Upgrader
Constants ¶
const (
DefaultMaxMessageSize uint32 = 2 * 1024 * 1024 // 2 MB
)
reasonable default values
Variables ¶
var ( Messages = map[Op][]Field{ GetVersion: {}, Version: {NetworkID, NodeID, MyTime, IP, VersionStr, VersionTime, SigBytes}, GetPeerList: {}, PeerList: {SignedPeers}, Ping: {}, Pong: {}, GetAcceptedFrontier: {ChainID, RequestID, Deadline}, AcceptedFrontier: {ChainID, RequestID, ContainerIDs}, GetAccepted: {ChainID, RequestID, Deadline, ContainerIDs}, Accepted: {ChainID, RequestID, ContainerIDs}, GetAncestors: {ChainID, RequestID, Deadline, ContainerID}, MultiPut: {ChainID, RequestID, MultiContainerBytes}, Get: {ChainID, RequestID, Deadline, ContainerID}, Put: {ChainID, RequestID, ContainerID, ContainerBytes}, PushQuery: {ChainID, RequestID, Deadline, ContainerID, ContainerBytes}, PullQuery: {ChainID, RequestID, Deadline, ContainerID}, Chits: {ChainID, RequestID, ContainerIDs}, } )
Defines the messages that can be sent/received with this network
Functions ¶
Types ¶
type Builder ¶
type Builder struct { Codec // contains filtered or unexported fields }
Builder extends a Codec to build messages safely
func (Builder) AcceptedFrontier ¶
func (m Builder) AcceptedFrontier(chainID ids.ID, requestID uint32, containerIDs []ids.ID) (Msg, error)
AcceptedFrontier message
func (Builder) Get ¶
func (m Builder) Get(chainID ids.ID, requestID uint32, deadline uint64, containerID ids.ID) (Msg, error)
Get message
func (Builder) GetAccepted ¶
func (m Builder) GetAccepted(chainID ids.ID, requestID uint32, deadline uint64, containerIDs []ids.ID) (Msg, error)
GetAccepted message
func (Builder) GetAcceptedFrontier ¶
func (m Builder) GetAcceptedFrontier(chainID ids.ID, requestID uint32, deadline uint64) (Msg, error)
GetAcceptedFrontier message
func (Builder) GetAncestors ¶
func (m Builder) GetAncestors(chainID ids.ID, requestID uint32, deadline uint64, containerID ids.ID) (Msg, error)
GetAncestors message
func (Builder) PullQuery ¶
func (m Builder) PullQuery(chainID ids.ID, requestID uint32, deadline uint64, containerID ids.ID) (Msg, error)
PullQuery message
func (Builder) PushQuery ¶
func (m Builder) PushQuery(chainID ids.ID, requestID uint32, deadline uint64, containerID ids.ID, container []byte) (Msg, error)
PushQuery message
type Codec ¶
type Codec struct{}
Codec defines the serialization and deserialization of network messages
type ConnMeter ¶ added in v1.0.3
type ConnMeter interface { // Returns whether we should allow an incoming connection from [ipStr] Allow(ipStr string) bool }
ConnMeter keeps track of how many times a peer from a given address have attempted to connect to us in a given time period.
func NewConnMeter ¶ added in v1.0.3
Return a new connection meter that allows an incoming connection if we've allowed <= [maxConns] incoming connections from that address in the last [resetDuration]. Keeps the counters in a cache of size [connCacheSize]. If any argument is 0, returns a ConnMeter that allows all incoming connections.
type Dialer ¶
type Dialer interface { // If [ctx] is canceled, gives up trying to connect to [ip] // and returns an error. Dial(ctx context.Context, ip utils.IPDesc) (net.Conn, error) }
Dialer attempts to create a connection with the provided IP/port pair
func NewDialer ¶
func NewDialer(network string, dialerConfig DialerConfig, log logging.Logger) Dialer
NewDialer returns a new Dialer that calls net.Dial with the provided network. network is the network passed into Dial. Should probably be "TCP". [dialerConfig.connectionTimeout] gives the timeout when dialing an IP. [dialerConfig.throttleRps] gives the max number of outgoing connection attempts/second. If [dialerConfig.throttleRps] == 0, outgoing connections aren't rate-limited.
type DialerConfig ¶ added in v1.4.8
type DialerConfig struct {
// contains filtered or unexported fields
}
func NewDialerConfig ¶ added in v1.4.8
func NewDialerConfig(throttleRps uint32, dialTimeout time.Duration) DialerConfig
type Field ¶
type Field uint32
Field that may be packed into a message
const ( VersionStr Field = iota // Used in handshake NetworkID // Used in handshake NodeID // Used in handshake MyTime // Used in handshake IP // Used in handshake Peers // Used in handshake ChainID // Used for dispatching RequestID // Used for all messages Deadline // Used for request messages ContainerID // Used for querying ContainerBytes // Used for gossiping ContainerIDs // Used for querying MultiContainerBytes // Used in MultiPut SigBytes // Used in handshake / peer gossiping VersionTime // Used in handshake / peer gossiping SignedPeers // Used in peer gossiping )
Fields that may be packed. These values are not sent over the wire.
type HealthConfig ¶ added in v1.2.1
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( 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, serverUpgrader, clientUpgrader Upgrader, vdrs validators.Set, beacons validators.Set, router router.Router, connMeterResetDuration time.Duration, connMeterMaxConns int, sendQueueSize uint32, healthConfig HealthConfig, benchlistManager benchlist.Manager, peerAliasTimeout time.Duration, tlsKey crypto.Signer, peerListSize int, peerListGossipSize int, peerListGossipFreq time.Duration, dialerConfig DialerConfig, isFetchOnly bool, gossipAcceptedFrontierSize uint, gossipOnAcceptSize uint, ) Network
NewDefaultNetwork returns a new Network implementation with the provided parameters and some reasonable default values.
func NewNetwork ¶
func NewNetwork( 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, serverUpgrader, clientUpgrader Upgrader, vdrs validators.Set, beacons validators.Set, router router.Router, initialReconnectDelay, maxReconnectDelay time.Duration, maxMessageSize uint32, sendQueueSize uint32, maxNetworkPendingSendBytes int, networkPendingSendBytesToRateLimit int, 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, connMeterResetDuration time.Duration, connMeterCacheSize int, connMeterMaxConns int, healthConfig HealthConfig, benchlistManager benchlist.Manager, peerAliasTimeout time.Duration, dialerConfig DialerConfig, tlsKey crypto.Signer, isFetchOnly bool, ) Network
NewNetwork returns a new Network implementation with the provided parameters.
type Op ¶
type Op byte
Op is an opcode
const ( // Handshake: GetVersion Op = iota GetPeerList Ping Pong // Bootstrapping: GetAcceptedFrontier AcceptedFrontier GetAccepted Accepted GetAncestors MultiPut // Consensus: Get Put PushQuery PullQuery Chits // Handshake / peer gossiping Version PeerList )
Public commands that may be sent between stakers
type PeerElement ¶ added in v1.0.3
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"` }
PeerID ...
type Throttler ¶ added in v1.4.8
type Throttler interface { // Block until the event associated with this Acquire can happen. // If [ctx] is canceled, gives up and returns an error. Acquire(ctx context.Context) error }
func NewNoThrottler ¶ added in v1.4.8
func NewNoThrottler() Throttler
func NewThrottler ¶ added in v1.4.8
type Upgrader ¶
type Upgrader interface { // Must be thread safe Upgrade(net.Conn) (ids.ShortID, net.Conn, *x509.Certificate, error) }
Upgrader ...
func NewTLSClientUpgrader ¶
NewTLSClientUpgrader ...
func NewTLSServerUpgrader ¶
NewTLSServerUpgrader ...