networking

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2020 License: BSD-3-Clause Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Handshake:
	GetVersion salticidae.Opcode = iota
	Version
	GetPeerList
	PeerList
	// Bootstrapping:
	GetAcceptedFrontier
	AcceptedFrontier
	GetAccepted
	Accepted
	// Consensus:
	Get
	Put
	PushQuery
	PullQuery
	Chits
	// Pinging:
	Ping
	Pong
	// Arbitrary data message:
	Data
	// Throughput test:
	IssueTx
	DecidedTx
)

Public commands that may be sent between stakers

View Source
const (
	// CurrentVersion this avalanche instance is executing.
	CurrentVersion = "avalanche/0.0.1"
	// MaxClockDifference allowed between connected nodes.
	MaxClockDifference = time.Minute
	// PeerListGossipSpacing is the amount of time to wait between pushing this
	// node's peer list to other nodes.
	PeerListGossipSpacing = time.Minute
	// PeerListGossipSize is the number of peers to gossip each period.
	PeerListGossipSize = 100
	// PeerListStakerGossipFraction calculates the fraction of stakers that are
	// gossiped to. If set to 1, then only stakers will be gossiped to.
	PeerListStakerGossipFraction = 2
	// GetVersionTimeout is the amount of time to wait before sending a
	// getVersion message to a partially connected peer
	GetVersionTimeout = 2 * time.Second
	// ReconnectTimeout is the amount of time to wait to reconnect to a staker
	// before giving up
	ReconnectTimeout = 10 * time.Minute
)

Variables

View Source
var (
	HandshakeNet = Handshake{}
)

Manager is the struct that will be accessed on event calls

Defines the messages that can be sent/received with this network

View Source
var (
	// VotingNet implements the SenderExternal interface.
	VotingNet = Voting{}
)

Functions

func ToIPDesc

func ToIPDesc(addr salticidae.NetAddr) (utils.IPDesc, error)

ToIPDesc converts an address to an IP

Types

type Builder

type Builder struct{ Codec }

Builder extends a Codec to build messages safely

func (Builder) Accepted

func (m Builder) Accepted(chainID ids.ID, requestID uint32, containerIDs ids.Set) (Msg, error)

Accepted message

func (Builder) AcceptedFrontier

func (m Builder) AcceptedFrontier(chainID ids.ID, requestID uint32, containerIDs ids.Set) (Msg, error)

AcceptedFrontier message

func (Builder) Chits

func (m Builder) Chits(chainID ids.ID, requestID uint32, containerIDs ids.Set) (Msg, error)

Chits message

func (Builder) Data

func (m Builder) Data(b []byte) (Msg, error)

Data message

func (Builder) DecidedTx

func (m Builder) DecidedTx(txID ids.ID, status choices.Status) (Msg, error)

DecidedTx message

func (Builder) Get

func (m Builder) Get(chainID ids.ID, requestID uint32, containerID ids.ID) (Msg, error)

Get message

func (Builder) GetAccepted

func (m Builder) GetAccepted(chainID ids.ID, requestID uint32, containerIDs ids.Set) (Msg, error)

GetAccepted message

func (Builder) GetAcceptedFrontier

func (m Builder) GetAcceptedFrontier(chainID ids.ID, requestID uint32) (Msg, error)

GetAcceptedFrontier message

func (Builder) GetPeerList

func (m Builder) GetPeerList() (Msg, error)

GetPeerList message

func (Builder) GetVersion

func (m Builder) GetVersion() (Msg, error)

GetVersion message

func (Builder) IssueTx

func (m Builder) IssueTx(chainID ids.ID, tx []byte) (Msg, error)

IssueTx message

func (Builder) PeerList

func (m Builder) PeerList(ipDescs []utils.IPDesc) (Msg, error)

PeerList message

func (Builder) Ping

func (m Builder) Ping() (Msg, error)

Ping message

func (Builder) Pong

func (m Builder) Pong() (Msg, error)

Pong message

func (Builder) PullQuery

func (m Builder) PullQuery(chainID ids.ID, requestID uint32, containerID ids.ID) (Msg, error)

PullQuery message

func (Builder) PushQuery

func (m Builder) PushQuery(chainID ids.ID, requestID uint32, containerID ids.ID, container []byte) (Msg, error)

PushQuery message

func (Builder) Put

func (m Builder) Put(chainID ids.ID, requestID uint32, containerID ids.ID, container []byte) (Msg, error)

Put message

func (Builder) Version

func (m Builder) Version(networkID uint32, myTime uint64, ip utils.IPDesc, myVersion string) (Msg, error)

Version message

type Codec

type Codec struct{}

Codec defines the serialization and deserialization of network messages

func (Codec) Pack

func (Codec) Pack(op salticidae.Opcode, fields map[Field]interface{}) (Msg, error)

Pack attempts to pack a map of fields into a message.

func (Codec) Parse

func (Codec) Parse(op salticidae.Opcode, ds salticidae.DataStream) (Msg, error)

Parse attempts to convert a byte stream into a message.

type Connections

type Connections interface {
	Add(salticidae.PeerID, ids.ShortID, utils.IPDesc)

	GetPeerID(ids.ShortID) (salticidae.PeerID, bool)
	GetID(salticidae.PeerID) (ids.ShortID, bool)

	ContainsPeerID(salticidae.PeerID) bool
	ContainsID(ids.ShortID) bool
	ContainsIP(utils.IPDesc) bool

	Remove(salticidae.PeerID, ids.ShortID)
	RemovePeerID(salticidae.PeerID)
	RemoveID(ids.ShortID)

	PeerIDs() []salticidae.PeerID
	IDs() ids.ShortSet
	IPs() []utils.IPDesc
	Conns() ([]salticidae.PeerID, []ids.ShortID, []utils.IPDesc)

	Len() int
}

Connections provides an interface for what a group of connections will support.

func NewConnections

func NewConnections() Connections

NewConnections returns a new and empty connections object

type Field

type Field uint32

Field that may be packed into a message

const (
	VersionStr     Field = iota // Used in handshake
	NetworkID                   // Used in handshake
	MyTime                      // Used in handshake
	IP                          // Used in handshake
	Peers                       // Used in handshake
	ChainID                     // Used for dispatching
	RequestID                   // Used for all messages
	ContainerID                 // Used for querying
	ContainerBytes              // Used for gossiping
	ContainerIDs                // Used for querying
	Bytes                       // Used as arbitrary data
	TxID                        // Used for throughput tests
	Tx                          // Used for throughput tests
	Status                      // Used for throughput tests
)

Fields that may be packed. These values are not sent over the wire.

func (Field) Packer

func (f Field) Packer() func(*wrappers.Packer, interface{})

Packer returns the packer function that can be used to pack this field.

func (Field) String

func (f Field) String() string

func (Field) Unpacker

func (f Field) Unpacker() func(*wrappers.Packer) interface{}

Unpacker returns the unpacker function that can be used to unpack this field.

type Handshake

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

Handshake handles the authentication of new peers. Only valid stakers will appear connected.

func (*Handshake) AwaitConnections

func (nm *Handshake) AwaitConnections(awaiting *networking.AwaitingConnections)

AwaitConnections ...

func (*Handshake) Connect

func (nm *Handshake) Connect(addr salticidae.NetAddr)

Connect ...

func (*Handshake) Connections

func (nm *Handshake) Connections() Connections

Connections returns the object that tracks the nodes that are currently connected to this node.

func (*Handshake) Initialize

func (nm *Handshake) Initialize(
	log logging.Logger,
	vdrs validators.Set,
	myAddr salticidae.NetAddr,
	myID ids.ShortID,
	peerNet salticidae.PeerNetwork,
	registerer prometheus.Registerer,
	enableStaking bool,
	networkID uint32,
)

Initialize to the c networking library. This should only be done once during node setup.

func (*Handshake) SendGetVersion

func (nm *Handshake) SendGetVersion(peer salticidae.PeerID)

SendGetVersion to the requested peer

func (*Handshake) SendPeerList

func (nm *Handshake) SendPeerList(peers ...salticidae.PeerID) error

SendPeerList to the requested peer

func (*Handshake) SendVersion

func (nm *Handshake) SendVersion(peer salticidae.PeerID) error

SendVersion to the requested peer

func (*Handshake) Shutdown

func (nm *Handshake) Shutdown()

Shutdown the network

type Msg

type Msg interface {
	Op() salticidae.Opcode
	Get(Field) interface{}
	DataStream() salticidae.DataStream
}

Msg represents a set of fields that can be serialized into a byte stream

type Voting

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

Voting implements the SenderExternal interface with a c++ library.

func (*Voting) Accept

func (s *Voting) Accept(chainID, containerID ids.ID, container []byte) error

Accept is called after every consensus decision

func (*Voting) Accepted

func (s *Voting) Accepted(validatorID ids.ShortID, chainID ids.ID, requestID uint32, containerIDs ids.Set)

Accepted implements the Sender interface.

func (*Voting) AcceptedFrontier

func (s *Voting) AcceptedFrontier(validatorID ids.ShortID, chainID ids.ID, requestID uint32, containerIDs ids.Set)

AcceptedFrontier implements the Sender interface.

func (*Voting) Chits

func (s *Voting) Chits(validatorID ids.ShortID, chainID ids.ID, requestID uint32, votes ids.Set)

Chits implements the Sender interface.

func (*Voting) Get

func (s *Voting) Get(validatorID ids.ShortID, chainID ids.ID, requestID uint32, containerID ids.ID)

Get implements the Sender interface.

func (*Voting) GetAccepted

func (s *Voting) GetAccepted(validatorIDs ids.ShortSet, chainID ids.ID, requestID uint32, containerIDs ids.Set)

GetAccepted implements the Sender interface.

func (*Voting) GetAcceptedFrontier

func (s *Voting) GetAcceptedFrontier(validatorIDs ids.ShortSet, chainID ids.ID, requestID uint32)

GetAcceptedFrontier implements the Sender interface.

func (*Voting) Initialize

func (s *Voting) Initialize(log logging.Logger, vdrs validators.Set, peerNet salticidae.PeerNetwork, conns Connections, router router.Router, registerer prometheus.Registerer)

Initialize to the c networking library. Should only be called once ever.

func (*Voting) PullQuery

func (s *Voting) PullQuery(validatorIDs ids.ShortSet, chainID ids.ID, requestID uint32, containerID ids.ID)

PullQuery implements the Sender interface.

func (*Voting) PushQuery

func (s *Voting) PushQuery(validatorIDs ids.ShortSet, chainID ids.ID, requestID uint32, containerID ids.ID, container []byte)

PushQuery implements the Sender interface.

func (*Voting) Put

func (s *Voting) Put(validatorID ids.ShortID, chainID ids.ID, requestID uint32, containerID ids.ID, container []byte)

Put implements the Sender interface.

func (*Voting) Shutdown

func (s *Voting) Shutdown()

Shutdown threads

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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