Documentation
¶
Index ¶
- Constants
- func MultiAddrString(i int, port int) string
- func ShortPeerIDString(id peer.ID) string
- type AddressFilter
- type Config
- type Peer
- type PeerConnections
- type Peers
- func (ps *Peers) DurationSinceLastMessageFromPeer() time.Duration
- func (ps *Peers) EvidenceInvalidTx(id peer.ID)
- func (ps *Peers) EvidenceValidTx(id peer.ID)
- func (ps *Peers) GetConnectivityMap() *api.ConnectivityMap
- func (ps *Peers) GetConnectivityMatrix() *api.ConnectivityMatrix
- func (ps *Peers) GetPeersInfo() *api.PeersInfo
- func (ps *Peers) GossipTxBytesToPeers(txBytes []byte, txid base.TransactionID, except ...peer.ID)
- func (ps *Peers) Host() host.Host
- func (ps *Peers) IsAlive(id peer.ID) (isAlive bool)
- func (ps *Peers) IsConnectedToNetwork() bool
- func (ps *Peers) NewStream(peerID peer.ID, pID protocol.ID, timeout time.Duration) (network.Stream, error)
- func (ps *Peers) NumAlive() (aliveStatic, aliveDynamic int)
- func (ps *Peers) OnReceivePullTxRequest(fun func(from peer.ID, txid base.TransactionID))
- func (ps *Peers) OnReceiveTxBytes(fun func(from peer.ID, txBytes []byte, txIDPrefix base.TransactionID))
- func (ps *Peers) PeerName(id peer.ID) string
- func (ps *Peers) PullTransactionsFromPeers(txid base.TransactionID) int
- func (ps *Peers) Run()
- func (ps *Peers) SelfPeerID() peer.ID
- func (ps *Peers) SendTxBytesToPeer(id peer.ID, txBytes []byte, txid base.TransactionID) bool
- func (ps *Peers) Stop()
Constants ¶
const BeginPort = 4000
const (
MaxPayloadSize = math.MaxUint16 - 4
)
MaxPayloadSize caps the message size. It includes 4 bytes of the size
const Name = "peers"
const PullTransactions = byte(iota)
Variables ¶
This section is empty.
Functions ¶
func MultiAddrString ¶
func ShortPeerIDString ¶
Types ¶
type AddressFilter ¶
func FilterAddresses ¶
func FilterAddresses(allowLocalNetworks bool, hostPort int, externalIPs []net.IP) AddressFilter
FilterAddresses builds the host's advertised address set (libp2p AddrsFactory). On top of whatever libp2p discovered, the node advertises itself at hostPort on:
- every local network interface IP, and
- every operator-declared external IP (peering.host.external_addresses).
The union is deduplicated and reduced to public addresses only (unless allowLocalNetworks). The interface IPs cover the common case where the public IP is bound to the host's NIC; declared external IPs cover NAT/port-mapping, where the public IP is on no local interface and cannot be auto-detected.
type Config ¶
type Config struct {
HostIDPrivateKey ed25519.PrivateKey
HostID peer.ID
HostPort int
// HostExternalIPs are operator-declared public IPs the node advertises itself
// at (peering.host.external_addresses), at HostPort. Needed when the node is
// reachable through NAT/port mapping and its public IP is on no local interface,
// so neither interface enumeration nor observed-address discovery can find it.
HostExternalIPs []net.IP
PreConfiguredPeers map[string]_multiaddr // name -> PeerAddr. Static peers used also for bootstrap
// MaxDynamicPeers is the maximum number of dynamic peers, whether dialled
// by autopeering or admitted when they opened a stream to us. Zero disables
// autopeering, in which case no dynamic peer is admitted either; a positive
// value below minDynamicPeers is raised to it. A quarter of the slots is kept
// for peers this node dials. When the slots peers may take are full, an
// inbound newcomer churns one existing inbound peer rather than being locked
// out; outbound peers are protected (see _makeRoomForInboundPeerLocked).
MaxDynamicPeers int
// Node info
IgnoreAllPullRequests bool
AcceptPullRequestsFromStaticPeersOnly bool
// AllowLocalIPs defines if local IPs are allowed to be used for autopeering.
AllowLocalIPs bool `default:"false" usage:"allow local IPs to be used for autopeering"`
// disable Quicreuse
DisableQuicreuse bool
// ConnectivityDisabled disables the lppConnectivity network-mapping overlay
// (peering.connectivity.disable). Default false (= enabled).
ConnectivityDisabled bool
}
func MakeConfigFor ¶
type PeerConnections ¶ added in v1.1.1
type PeerConnections struct {
Name string `json:"name"` // origin masked name, 16-hex
ConsensusContribution uint64 `json:"consensusContribution,omitempty"` // sequencer mass; 0/omitted for access nodes
ByPeer map[string]uint64 `json:"byPeer"` // peer masked name (16-hex) -> RTT microseconds
Timestamp int64 `json:"timestamp"` // unix nanos at origin
Seq uint64 `json:"seq"` // origin-monotone sequence number
}
PeerConnections is one node's local connectivity view, gossiped verbatim.
type Peers ¶
type Peers struct {
// contains filtered or unexported fields
}
func NewPeersDummy ¶
func NewPeersDummy() *Peers
func NewPeersDummyGossiping ¶ added in v1.6.4
func NewPeersDummyGossiping(fun func(txBytes []byte, txid base.TransactionID)) *Peers
NewPeersDummyGossiping is a dummy which hands every gossiped transaction to fun
func NewPeersFromConfig ¶
func (*Peers) DurationSinceLastMessageFromPeer ¶
DurationSinceLastMessageFromPeer is the silence since the last incoming gossip, pull or connectivity message; before Run it is 0.
func (*Peers) EvidenceInvalidTx ¶ added in v1.5.2
EvidenceInvalidTx records a transaction refused at parsing because its version does not match this node's library, or refused at the signature check. One is tolerated; after invalidTxLimit within invalidTxWindow the peer is on an incompatible version or is sending forged copies, so it is dropped and barred from churning for the flap cooldown.
func (*Peers) EvidenceValidTx ¶ added in v1.3.6
EvidenceValidTx records a peer transaction that parsed and passed the signature check. Churn activity is measured on this, not on raw gossip frames, so a peer sending an incompatible transaction version cannot look active by flooding transactions that are refused before validation.
func (*Peers) GetConnectivityMap ¶ added in v1.1.1
func (ps *Peers) GetConnectivityMap() *api.ConnectivityMap
GetConnectivityMap returns the whole stored connectivity map for the API.
func (*Peers) GetConnectivityMatrix ¶ added in v1.1.1
func (ps *Peers) GetConnectivityMatrix() *api.ConnectivityMatrix
GetConnectivityMatrix returns the symmetric pairwise distance metric d(i,j) derived from the connectivity map. The result is cached and lazily recomputed at most once per connMatrixRefreshInterval (the matrix is expensive for large N).
func (*Peers) GetPeersInfo ¶
func (*Peers) GossipTxBytesToPeers ¶
func (*Peers) IsConnectedToNetwork ¶ added in v1.1.1
IsConnectedToNetwork returns true if libp2p reports at least one peer currently connected. After the heartbeat protocol was removed, this is the authoritative "node has a working connection to the network" signal — the previous traffic-timestamp proxy is too quiet on low-load networks (e.g. a pair of just-restarted nodes with no transactions to gossip).
func (*Peers) NumAlive ¶
NumAlive returns counts of alive static / dynamic peers and pull targets. "Alive" is libp2p-Connectedness-driven (see _isAlive).
func (*Peers) OnReceivePullTxRequest ¶
func (ps *Peers) OnReceivePullTxRequest(fun func(from peer.ID, txid base.TransactionID))
func (*Peers) OnReceiveTxBytes ¶
func (*Peers) PullTransactionsFromPeers ¶
func (ps *Peers) PullTransactionsFromPeers(txid base.TransactionID) int
PullTransactionsFromPeers sends pull request to all peers that respond to pull requests