peerdata

package
v5.0.1-rc.4 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2024 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrPeerUnknown is returned when there is an attempt to obtain data from a peer that is not known.
	ErrPeerUnknown = errors.New("peer unknown")
	// ErrNoPeerStatus is returned when there is a map entry for a given peer but there is no chain
	// status for that peer. This should happen in rare circumstances only, but is a very possible
	// scenario in a chaotic and adversarial network.
	ErrNoPeerStatus = errors.New("no chain status for peer")
)

Functions

This section is empty.

Types

type PeerConnectionState

type PeerConnectionState ethpb.ConnectionState

PeerConnectionState is the state of the connection.

type PeerData

type PeerData struct {
	// Network related data.
	Address       ma.Multiaddr
	Direction     network.Direction
	ConnState     PeerConnectionState
	Enr           *enr.Record
	NextValidTime time.Time
	// Chain related data.
	MetaData                  metadata.Metadata
	ChainState                *ethpb.Status
	ChainStateLastUpdated     time.Time
	ChainStateValidationError error
	// Scorers internal data.
	BadResponses         int
	ProcessedBlocks      uint64
	BlockProviderUpdated time.Time
	// Gossip Scoring data.
	TopicScores      map[string]*ethpb.TopicScoreSnapshot
	GossipScore      float64
	BehaviourPenalty float64
}

PeerData aggregates protocol and application level info about a single peer.

type Store

type Store struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Store is a container for various peer related data (both protocol and app level). Container implements RWMutex, so data access can be restricted on the container level. This allows different components rely on the very same peer map container. Note: access to data is controlled by clients i.e. client code is responsible for locking/unlocking the mutex when accessing data.

func NewStore

func NewStore(ctx context.Context, config *StoreConfig) *Store

NewStore creates new peer data store.

func (*Store) Config

func (s *Store) Config() *StoreConfig

Config exposes store configuration params.

func (*Store) DeletePeerData

func (s *Store) DeletePeerData(pid peer.ID)

DeletePeerData removes data associated with a given peer. Important: it is assumed that store mutex is locked when calling this method.

func (*Store) DeleteTrustedPeers

func (s *Store) DeleteTrustedPeers(peers []peer.ID)

DeleteTrustedPeers removes peers from trusted peer set. Important: it is assumed that store mutex is locked when calling this method.

func (*Store) GetTrustedPeers

func (s *Store) GetTrustedPeers() []peer.ID

GetTrustedPeers gets our desired trusted peer ids. Important: it is assumed that store mutex is locked when calling this method.

func (*Store) IsTrustedPeer

func (s *Store) IsTrustedPeer(p peer.ID) bool

IsTrustedPeer checks that the provided peer is in our trusted peer set.

func (*Store) PeerData

func (s *Store) PeerData(pid peer.ID) (*PeerData, bool)

PeerData returns data associated with a given peer, if any. Important: it is assumed that store mutex is locked when calling this method.

func (*Store) PeerDataGetOrCreate

func (s *Store) PeerDataGetOrCreate(pid peer.ID) *PeerData

PeerDataGetOrCreate returns data associated with a given peer. If no data has been associated yet, newly created and associated data object is returned. Important: it is assumed that store mutex is locked when calling this method.

func (*Store) Peers

func (s *Store) Peers() map[peer.ID]*PeerData

Peers returns map of peer data objects. Important: it is assumed that store mutex is locked when calling this method.

func (*Store) SetPeerData

func (s *Store) SetPeerData(pid peer.ID, data *PeerData)

SetPeerData updates data associated with a given peer. Important: it is assumed that store mutex is locked when calling this method.

func (*Store) SetTrustedPeers

func (s *Store) SetTrustedPeers(peers []peer.ID)

SetTrustedPeers sets our desired trusted peer set. Important: it is assumed that store mutex is locked when calling this method.

type StoreConfig

type StoreConfig struct {
	MaxPeers int
}

StoreConfig holds peer store parameters.

Jump to

Keyboard shortcuts

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