Documentation ¶
Index ¶
- Constants
- Variables
- type Builder
- func (m Builder) Accepted(chainID ids.ID, requestID uint32, containerIDs ids.Set) (Msg, error)
- func (m Builder) AcceptedFrontier(chainID ids.ID, requestID uint32, containerIDs ids.Set) (Msg, error)
- func (m Builder) Chits(chainID ids.ID, requestID uint32, containerIDs ids.Set) (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.Set) (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(ipDescs []utils.IPDesc) (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 Dialer
- type Field
- type Handler
- type Msg
- type Network
- type Op
- type PeerID
- type Upgrader
Constants ¶
const (
DefaultMaxMessageSize uint32 = 1 << 21
)
reasonable default values
Variables ¶
var ( Messages = map[Op][]Field{ GetVersion: {}, Version: {NetworkID, NodeID, MyTime, IP, VersionStr}, GetPeerList: {}, PeerList: {Peers}, 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 ¶
This section is empty.
Types ¶
type Builder ¶
type Builder struct{ Codec }
Builder extends a Codec to build messages safely
func (Builder) AcceptedFrontier ¶
func (m Builder) AcceptedFrontier(chainID ids.ID, requestID uint32, containerIDs ids.Set) (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.Set) (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 ¶ added in v0.5.3
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 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 )
Fields that may be packed. These values are not sent over the wire.
type Handler ¶
type Handler interface { // returns true if the handler should be removed Connected(id ids.ShortID) bool Disconnected(id ids.ShortID) bool }
Handler represents a handler that is called when a connection is marked as connected or disconnected
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 // The network should be able to report the last time the network interacted // with a peer health.Heartbeater // 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. Track(ip utils.IPDesc) // Register a new handler that is called whenever a peer is connected to or // disconnected to. If the handler returns true, then it will never be // called again. Thread safety must be managed internally in the network. // The handler will initially be called with this local node's ID. RegisterHandler(h Handler) // Returns the description of the nodes this network is currently connected // to externally. Thread safety must be managed internally to the network. Peers() []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 }
Network defines the functionality of the networking library.
func NewDefaultNetwork ¶
func NewDefaultNetwork( registerer prometheus.Registerer, log logging.Logger, id ids.ShortID, ip utils.IPDesc, networkID uint32, version version.Version, parser version.Parser, listener net.Listener, dialer Dialer, serverUpgrader, clientUpgrader Upgrader, vdrs validators.Set, beacons validators.Set, router router.Router, ) 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.IPDesc, networkID uint32, version version.Version, parser version.Parser, listener net.Listener, dialer Dialer, serverUpgrader, clientUpgrader Upgrader, vdrs validators.Set, beacons validators.Set, router router.Router, initialReconnectDelay, maxReconnectDelay time.Duration, maxMessageSize uint32, sendQueueSize int, maxNetworkPendingSendBytes int, networkPendingSendBytesToRateLimit int, maxClockDifference time.Duration, peerListGossipSpacing time.Duration, peerListGossipSize int, peerListStakerGossipFraction int, getVersionTimeout time.Duration, allowPrivateIPs bool, gossipSize int, pingPongTimeout time.Duration, pingFrequency time.Duration, ) Network
NewNetwork returns a new Network implementation with the provided parameters.
type Op ¶
type Op byte
Op is an opcode
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"` }
PeerID ...
type Upgrader ¶
Upgrader ...
func NewTLSClientUpgrader ¶
NewTLSClientUpgrader ...
func NewTLSServerUpgrader ¶
NewTLSServerUpgrader ...