peer

package
v0.6.5 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewPeerAddressFromMetadata

func NewPeerAddressFromMetadata(metadata []byte) (*net.UDPAddr, error)

The first 18 bytes of validator metadata, with the first 16 bytes being the IPv6 address and the latter 2 being a little endian representation of the port.

Types

type BlockAnnouncer

type BlockAnnouncer interface {
	// Add the rest of the functions when needed
	SendAnnouncement(header *block.Header) error
	Start() error
}

type Peer

type Peer struct {
	// ProtoConn handles protocol-specific operations
	ProtoConn *protocol.ProtocolConn
	Address   *net.UDPAddr

	Ed25519Key ed25519.PublicKey
	BAnnouncer BlockAnnouncer
	// Optional validator index if this peer is a validator
	ValidatorIndex *uint16
	// contains filtered or unexported fields
}

Peer represents a remote peer and provides high-level protocol operations. It wraps the underlying transport and protocol connections with a simpler interface.

func MergeValidators

func MergeValidators(a, b []*Peer) []*Peer

MergeValidators returns a deduplicated set of validator peers from slices a and b, including only peers that are validators (ValidatorIndex != nil) Deduplication is performed based on Ed25519 public keys

func NewPeer

func NewPeer(pConn *protocol.ProtocolConn) *Peer

NewPeer creates a new peer instance from an established transport connection.

func (*Peer) IsValidator

func (p *Peer) IsValidator() bool

IsValidator returns true if the peer is a validator, false otherwise A validator peer should have a non-nil ValidatorIndex field.

type PeerSet

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

PeerSet maintains mappings between peer identifiers (Ed25519 keys, network addresses, validator indices) and Peer objects.

func NewPeerSet

func NewPeerSet() *PeerSet

NewPeerSet creates a new PeerSet instance with initialized internal maps.

func (*PeerSet) AddPeer

func (ps *PeerSet) AddPeer(peer *Peer)

AddPeer adds a peer to all relevant lookup maps in the PeerSet. If the peer is a validator index, it will also have a validator index.

func (*PeerSet) GetAllPeers

func (ps *PeerSet) GetAllPeers() []*Peer

GetAllPeers returns all peers currently in the peer set

func (*PeerSet) GetByAddress

func (ps *PeerSet) GetByAddress(addr string) *Peer

GetByAddress looks up a peer by their network address. Returns nil if no peer is found with the given address.

func (*PeerSet) GetByEd25519Key

func (ps *PeerSet) GetByEd25519Key(key ed25519.PublicKey) *Peer

GetByEd25519Key looks up a peer by their Ed25519 public key. Returns nil if no peer is found with the given key.

func (*PeerSet) GetByValidatorIndex

func (ps *PeerSet) GetByValidatorIndex(index uint16) *Peer

GetByValidatorIndex looks up a peer by their validator index. Returns nil if no peer is found with the given validator index.

func (*PeerSet) RemovePeer

func (ps *PeerSet) RemovePeer(peer *Peer)

RemovePeer removes a peer from all lookup maps in the PeerSet.

Jump to

Keyboard shortcuts

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