peers

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: May 22, 2024 License: ISC Imports: 28 Imported by: 0

Documentation

Index

Constants

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

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

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 BadResponse added in v1.0.21

type BadResponse struct {
	ID   uint64
	Time time.Time
	Err  *common.Error
}

func (*BadResponse) String added in v1.0.21

func (br *BadResponse) String() string

type P2P added in v1.0.21

type P2P interface {
	GetGenesisHash() *hash.Hash
	BlockChain() *blockchain.BlockChain
	Host() host.Host
	Disconnect(pid peer.ID) error
	Context() context.Context
	Encoding() encoder.NetworkEncoding
	Config() *common.Config
	TxMemPool() *mempool.TxPool
	Metadata() *pb.MetaData
	MetadataSeq() uint64
	TimeSource() model.MedianTimeSource
	Notify() model.Notify
	ConnectTo(node *qnode.Node)
	Resolve(n *qnode.Node) *qnode.Node
	Node() *qnode.Node
	RelayNodeInfo() *peer.AddrInfo
	IncreaseBytesSent(pid peer.ID, size int)
	IncreaseBytesRecv(pid peer.ID, size int)
	ConnectToPeer(qmaddr string, force bool) error
	RegainMempool()
	IsCurrent() bool
	Peers() *Status
	IsRunning() bool
	Consensus() model.Consensus
}

type P2PRPC added in v1.0.21

type P2PRPC interface {
	Host() host.Host
	Context() context.Context
	Encoding() encoder.NetworkEncoding
	Disconnect(pid peer.ID) error
	IncreaseBytesSent(pid peer.ID, size int)
	IncreaseBytesRecv(pid peer.ID, size int)
	Peers() *Status
	IsRunning() bool
	GetGenesisHash() *hash.Hash
}

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() []*BadResponse

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

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

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) 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

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

func (*Peer) GetID

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

func (*Peer) GetMempoolReqTime added in v1.0.21

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

func (*Peer) GetName

func (p *Peer) GetName() string

func (*Peer) GetNetwork

func (p *Peer) GetNetwork() string

func (*Peer) GetVersion

func (p *Peer) GetVersion() string

func (*Peer) GraphState

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

func (*Peer) HasBroadcast

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

func (*Peer) IDWithAddress

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) IncreaseReConnect added in v1.0.21

func (p *Peer) IncreaseReConnect()

func (*Peer) IncrementBadResponses

func (p *Peer) IncrementBadResponses(err *common.Error)

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

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

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

func (*Peer) Services

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

func (*Peer) SetBidChanCap

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) SetMempoolReqTime added in v1.0.21

func (p *Peer) SetMempoolReqTime(t time.Time)

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) SetStateRoot added in v1.0.21

func (p *Peer) SetStateRoot(stateRoot *hash.Hash, order uint64)

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

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         peer.ID
	QNR            string
	Address        string
	Protocol       uint32
	Genesis        *hash.Hash
	Services       protocol.ServiceFlag
	Name           string
	Version        string
	Network        string
	State          bool
	Direction      network.Direction
	GraphState     *meerdag.GraphState
	GraphStateDur  time.Duration
	TimeOffset     int64
	ConnTime       time.Duration
	LastSend       time.Time
	LastRecv       time.Time
	BytesSent      uint64
	BytesRecv      uint64
	IsCircuit      bool
	Bads           []string
	ReConnect      uint64
	StateRoot      string
	MempoolReqTime time.Time
	Tasks          int
	Broadcast      int
}

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

func (*StatsSnap) IsRelay

func (p *StatsSnap) IsRelay() bool

func (*StatsSnap) IsTheSameNetwork

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 P2PRPC) *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

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

func (*Status) Bad

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

Bad returns the peers that are bad.

func (*Status) CanConnect added in v1.0.21

func (p *Status) CanConnect(pid peer.ID) bool

func (*Status) CanSyncPeers added in v1.0.21

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

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) 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) GetByAddress added in v1.0.21

func (p *Status) GetByAddress(address ma.Multiaddr) *Peer

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, err *common.Error)

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

func (*Status) IsActive added in v1.0.21

func (p *Status) IsActive(pe *Peer) bool

func (*Status) IsActiveID added in v1.0.21

func (p *Status) IsActiveID(pid peer.ID) bool

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

func (p *Status) UpdateBroadcasts()

Jump to

Keyboard shortcuts

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