peers

package
v0.10.6 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2021 License: ISC Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MinBroadcastRecord  = 10
	BroadcastRecordLife = 30 * time.Minute
)

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")
)
View Source
var (
	// maxBadResponses is the maximum number of bad responses from a peer before we stop talking to it.
	MaxBadResponses = 50
)

Functions

func HasConsensusService

func HasConsensusService(services protocol.ServiceFlag) bool

func ParseUserAgent added in v0.10.2

func ParseUserAgent(data string) (error, string, string, string)

func UseLogger

func UseLogger(logger l.Logger)

UseLogger uses a specified Logger to output package logging info.

Types

type Peer

type Peer struct {
	HSlock *sync.RWMutex
	// contains filtered or unexported fields
}

Peer represents a connected p2p network remote node.

func NewPeer

func NewPeer(pid peer.ID, point *hash.Hash) *Peer

func (*Peer) Address

func (p *Peer) Address() ma.Multiaddr

Address returns the multiaddress of the given remote peer. This will error if the peer does not exist.

func (*Peer) BadResponses

func (p *Peer) BadResponses() int

BadResponses obtains the number of bad responses we have received from the given remote peer. This will error if the peer does not exist.

func (*Peer) Broadcast added in v0.10.5

func (p *Peer) Broadcast(key string, record interface{})

func (*Peer) BytesRecv

func (p *Peer) BytesRecv() uint64

func (*Peer) BytesSent

func (p *Peer) BytesSent() uint64

func (*Peer) CanConnectWithNetwork added in v0.10.2

func (p *Peer) CanConnectWithNetwork() bool

func (*Peer) ChainState

func (p *Peer) ChainState() *pb.ChainState

ChainState gets the chain state of the given remote peer. This can return nil if there is no known chain state for the peer. This will error if the peer does not exist.

func (*Peer) ChainStateLastUpdated

func (p *Peer) ChainStateLastUpdated() time.Time

ChainStateLastUpdated gets the last time the chain state of the given remote peer was updated. This will error if the peer does not exist.

func (*Peer) CommitteeIndices

func (p *Peer) CommitteeIndices() []uint64

CommitteeIndices retrieves the committee subnets the peer is subscribed to.

func (*Peer) ConnectionState

func (p *Peer) ConnectionState() PeerConnectionState

ConnectionState gets the connection state of the given remote peer. This will error if the peer does not exist.

func (*Peer) ConnectionTime

func (p *Peer) ConnectionTime() time.Time

func (*Peer) Decay

func (p *Peer) Decay()

func (*Peer) Direction

func (p *Peer) Direction() network.Direction

Direction returns the direction of the given remote peer. This will error if the peer does not exist.

func (*Peer) DisableRelayTx

func (p *Peer) DisableRelayTx() bool

func (*Peer) FeeFilter

func (p *Peer) FeeFilter() int64

func (*Peer) Filter

func (p *Peer) Filter() *bloom.Filter

func (*Peer) GetBidChanCap added in v0.10.3

func (p *Peer) GetBidChanCap() time.Time

func (*Peer) GetID

func (p *Peer) GetID() peer.ID

func (*Peer) GetName added in v0.10.2

func (p *Peer) GetName() string

func (*Peer) GetNetwork added in v0.10.2

func (p *Peer) GetNetwork() string

func (*Peer) GetVersion added in v0.10.2

func (p *Peer) GetVersion() string

func (*Peer) GraphState

func (p *Peer) GraphState() *blockdag.GraphState

func (*Peer) HasBroadcast added in v0.10.5

func (p *Peer) HasBroadcast(key string) bool

func (*Peer) IDWithAddress added in v0.10.3

func (p *Peer) IDWithAddress() string

IDWithAddress returns the printable id and address of the remote peer. It's useful on printing out the trace log messages.

func (*Peer) IncreaseBytesRecv

func (p *Peer) IncreaseBytesRecv(size int)

func (*Peer) IncreaseBytesSent

func (p *Peer) IncreaseBytesSent(size int)

func (*Peer) IncrementBadResponses

func (p *Peer) IncrementBadResponses(reason string)

IncrementBadResponses increments the number of bad responses we have received from the given remote peer.

func (*Peer) IsActive

func (p *Peer) IsActive() bool

IsActive checks if a peers is active and returns the result appropriately.

func (*Peer) IsBad

func (p *Peer) IsBad() bool

IsBad states if the peer is to be considered bad. If the peer is unknown this will return `false`, which makes using this function easier than returning an error.

func (*Peer) IsConnected added in v0.10.3

func (p *Peer) IsConnected() bool

func (*Peer) IsConsensus

func (p *Peer) IsConsensus() bool

func (*Peer) IsRelay

func (p *Peer) IsRelay() bool

func (*Peer) Metadata

func (p *Peer) Metadata() *pb.MetaData

Metadata returns a copy of the metadata corresponding to the provided peer id.

func (*Peer) Node

func (p *Peer) Node() *qnode.Node

func (*Peer) QAddress

func (p *Peer) QAddress() common.QMultiaddr

func (*Peer) QNR

func (p *Peer) QNR() *qnr.Record

QNR returns the enr for the corresponding peer id.

func (*Peer) ResetBad

func (p *Peer) ResetBad()

func (*Peer) RunRate added in v0.10.3

func (p *Peer) RunRate(task string, delay time.Duration, f func())

func (*Peer) Services

func (p *Peer) Services() protocol.ServiceFlag

func (*Peer) SetBidChanCap added in v0.10.3

func (p *Peer) SetBidChanCap(life time.Time)

func (*Peer) SetChainState

func (p *Peer) SetChainState(chainState *pb.ChainState)

SetChainState sets the chain state of the given remote peer.

func (*Peer) SetConnectionState

func (p *Peer) SetConnectionState(state PeerConnectionState)

SetConnectionState sets the connection state of the given remote peer.

func (*Peer) SetMetadata

func (p *Peer) SetMetadata(metaData *pb.MetaData)

SetMetadata sets the metadata of the given remote peer.

func (*Peer) SetQNR

func (p *Peer) SetQNR(record *qnr.Record)

func (*Peer) StatsSnapshot

func (p *Peer) StatsSnapshot() (*StatsSnap, error)

func (*Peer) SyncPoint

func (p *Peer) SyncPoint() *hash.Hash

func (*Peer) Timestamp

func (p *Peer) Timestamp() time.Time

func (*Peer) UpdateAddrDir

func (p *Peer) UpdateAddrDir(record *qnr.Record, address ma.Multiaddr, direction network.Direction)

func (*Peer) UpdateBroadcast added in v0.10.5

func (p *Peer) UpdateBroadcast()

func (*Peer) UpdateGraphState

func (p *Peer) UpdateGraphState(gs *pb.GraphState)

func (*Peer) UpdateSyncPoint

func (p *Peer) UpdateSyncPoint(point *hash.Hash)

type PeerConnectionState

type PeerConnectionState int32

PeerConnectionState is the state of the connection.

const (
	// PeerDisconnected means there is no connection to the peer.
	PeerDisconnected PeerConnectionState = iota
	// PeerDisconnecting means there is an on-going attempt to disconnect from the peer.
	PeerDisconnecting
	// PeerConnected means the peer has an active connection.
	PeerConnected
	// PeerConnecting means there is an on-going attempt to connect to the peer.
	PeerConnecting
)

func (PeerConnectionState) IsConnected

func (pcs PeerConnectionState) IsConnected() bool

func (PeerConnectionState) IsConnecting

func (pcs PeerConnectionState) IsConnecting() bool

func (PeerConnectionState) IsDisconnected

func (pcs PeerConnectionState) IsDisconnected() bool

func (PeerConnectionState) IsDisconnecting

func (pcs PeerConnectionState) IsDisconnecting() bool

func (PeerConnectionState) String

func (pcs PeerConnectionState) String() string

type StatsSnap

type StatsSnap struct {
	NodeID        string
	PeerID        string
	QNR           string
	Address       string
	Protocol      uint32
	Genesis       *hash.Hash
	Services      protocol.ServiceFlag
	Name          string
	Version       string
	Network       string
	State         PeerConnectionState
	Direction     network.Direction
	GraphState    *blockdag.GraphState
	GraphStateDur time.Duration
	TimeOffset    int64
	ConnTime      time.Duration
	LastSend      time.Time
	LastRecv      time.Time
	BytesSent     uint64
	BytesRecv     uint64
	IsCircuit     bool
	Bads          int
}

StatsSnap is a snapshot of peer stats at a point in time.

func (*StatsSnap) IsRelay

func (p *StatsSnap) IsRelay() bool

func (*StatsSnap) IsTheSameNetwork added in v0.10.2

func (p *StatsSnap) IsTheSameNetwork() bool

type Status

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

Status is the structure holding the peer status information.

func NewStatus

func NewStatus(p2p common.P2P) *Status

NewStatus creates a new status entity.

func (*Status) Active

func (p *Status) Active() []peer.ID

Active returns the peers that are connecting or connected.

func (*Status) Add

func (p *Status) Add(record *qnr.Record, pid peer.ID, address ma.Multiaddr, direction network.Direction)

Add adds a peer. If a peer already exists with this ID its address and direction are updated with the supplied data.

func (*Status) All

func (p *Status) All() []peer.ID

All returns all the peers regardless of state.

func (*Status) AllPeers added in v0.10.5

func (p *Status) AllPeers() []*Peer

func (*Status) Bad

func (p *Status) Bad() []peer.ID

Bad returns the peers that are bad.

func (*Status) Connected

func (p *Status) Connected() []peer.ID

Connected returns the peers that are connected.

func (*Status) ConnectedPeers

func (p *Status) ConnectedPeers() []*Peer

func (*Status) Connecting

func (p *Status) Connecting() []peer.ID

Connecting returns the peers that are connecting.

func (*Status) Decay

func (p *Status) Decay()

Decay reduces the bad responses of all peers, giving reformed peers a chance to join the network. This can be run periodically, although note that each time it runs it does give all bad peers another chance as well to clog up the network with bad responses, so should not be run too frequently; once an hour would be reasonable.

func (*Status) DirInbound

func (p *Status) DirInbound() []peer.ID

func (*Status) Disconnected

func (p *Status) Disconnected() []peer.ID

Disconnected returns the peers that are disconnected.

func (*Status) Disconnecting

func (p *Status) Disconnecting() []peer.ID

Disconnecting returns the peers that are disconnecting.

func (*Status) Fetch

func (p *Status) Fetch(pid peer.ID) *Peer

fetch is a helper function that fetches a peer, possibly creating it.

func (*Status) ForPeers

func (p *Status) ForPeers(state PeerConnectionState, closure func(pe *Peer))

func (*Status) Get

func (p *Status) Get(pid peer.ID) *Peer

fetch is a helper function that fetches a peer, possibly creating it.

func (*Status) Inactive

func (p *Status) Inactive() []peer.ID

Inactive returns the peers that are disconnecting or disconnected.

func (*Status) IncrementBadResponses

func (p *Status) IncrementBadResponses(pid peer.ID, reason string)

IncrementBadResponses increments the number of bad responses we have received from the given remote peer.

func (*Status) StatsSnapshots

func (p *Status) StatsSnapshots() []*StatsSnap

func (*Status) SubscribedToSubnet

func (p *Status) SubscribedToSubnet(index uint64) []peer.ID

SubscribedToSubnet retrieves the peers subscribed to the given committee subnet.

func (*Status) UpdateBroadcasts added in v0.10.5

func (p *Status) UpdateBroadcasts()

Jump to

Keyboard shortcuts

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