Documentation ¶
Index ¶
- Constants
- func NewAddrBook(filePath string, routabilityStrict bool) *addrBook
- func RegisterPexMessage(cdc *amino.Codec)
- type AddrBook
- type ErrAddrBookNilAddr
- type ErrAddrBookNonRoutable
- type ErrAddrBookPrivate
- type ErrAddrBookSelf
- type PEXReactor
- func (r *PEXReactor) AddPeer(p Peer)
- func (r *PEXReactor) AttemptsToDial(addr *p2p.NetAddress) int
- func (r *PEXReactor) GetChannels() []*conn.ChannelDescriptor
- func (r *PEXReactor) OnStart() error
- func (r *PEXReactor) OnStop()
- func (r *PEXReactor) Receive(chID byte, src Peer, msgBytes []byte)
- func (r *PEXReactor) ReceiveAddrs(addrs []*p2p.NetAddress, src Peer) error
- func (r *PEXReactor) RemovePeer(p Peer, reason interface{})
- func (r *PEXReactor) RequestAddrs(p Peer)
- func (r *PEXReactor) SendAddrs(p Peer, netAddrs []*p2p.NetAddress)
- func (r *PEXReactor) SetEnsurePeersPeriod(d time.Duration)
- type PEXReactorConfig
- type Peer
- type PexMessage
Constants ¶
const ( // PexChannel is a channel for PEX messages PexChannel = byte(0x00) )
Variables ¶
This section is empty.
Functions ¶
func NewAddrBook ¶
NewAddrBook creates a new address book. Use Start to begin processing asynchronous address updates.
func RegisterPexMessage ¶ added in v0.19.0
Types ¶
type AddrBook ¶
type AddrBook interface { cmn.Service // Add our own addresses so we don't later add ourselves AddOurAddress(*p2p.NetAddress) // Check if it is our address OurAddress(*p2p.NetAddress) bool AddPrivateIDs([]string) // Add and remove an address AddAddress(addr *p2p.NetAddress, src *p2p.NetAddress) error RemoveAddress(*p2p.NetAddress) // Check if the address is in the book HasAddress(*p2p.NetAddress) bool // Do we need more peers? NeedMoreAddrs() bool // Pick an address to dial PickAddress(biasTowardsNewAddrs int) *p2p.NetAddress // Mark address MarkGood(*p2p.NetAddress) MarkAttempt(*p2p.NetAddress) MarkBad(*p2p.NetAddress) IsGood(*p2p.NetAddress) bool // Send a selection of addresses to peers GetSelection() []*p2p.NetAddress // Send a selection of addresses with bias GetSelectionWithBias(biasTowardsNewAddrs int) []*p2p.NetAddress // TODO: remove ListOfKnownAddresses() []*knownAddress // Persist to disk Save() }
AddrBook is an address book used for tracking peers so we can gossip about them to others and select peers to dial. TODO: break this up?
type ErrAddrBookNilAddr ¶ added in v0.19.2
type ErrAddrBookNilAddr struct { Addr *p2p.NetAddress Src *p2p.NetAddress }
func (ErrAddrBookNilAddr) Error ¶ added in v0.19.2
func (err ErrAddrBookNilAddr) Error() string
type ErrAddrBookNonRoutable ¶ added in v0.19.2
type ErrAddrBookNonRoutable struct {
Addr *p2p.NetAddress
}
func (ErrAddrBookNonRoutable) Error ¶ added in v0.19.2
func (err ErrAddrBookNonRoutable) Error() string
type ErrAddrBookPrivate ¶ added in v0.22.5
type ErrAddrBookPrivate struct {
Addr *p2p.NetAddress
}
func (ErrAddrBookPrivate) Error ¶ added in v0.22.5
func (err ErrAddrBookPrivate) Error() string
type ErrAddrBookSelf ¶ added in v0.19.2
type ErrAddrBookSelf struct {
Addr *p2p.NetAddress
}
func (ErrAddrBookSelf) Error ¶ added in v0.19.2
func (err ErrAddrBookSelf) Error() string
type PEXReactor ¶
type PEXReactor struct { p2p.BaseReactor // contains filtered or unexported fields }
PEXReactor handles PEX (peer exchange) and ensures that an adequate number of peers are connected to the switch.
It uses `AddrBook` (address book) to store `NetAddress`es of the peers.
## Preventing abuse
Only accept pexAddrsMsg from peers we sent a corresponding pexRequestMsg too. Only accept one pexRequestMsg every ~defaultEnsurePeersPeriod.
func NewPEXReactor ¶
func NewPEXReactor(b AddrBook, config *PEXReactorConfig) *PEXReactor
NewPEXReactor creates new PEX reactor.
func (*PEXReactor) AddPeer ¶
func (r *PEXReactor) AddPeer(p Peer)
AddPeer implements Reactor by adding peer to the address book (if inbound) or by requesting more addresses (if outbound).
func (*PEXReactor) AttemptsToDial ¶ added in v0.17.0
func (r *PEXReactor) AttemptsToDial(addr *p2p.NetAddress) int
AttemptsToDial returns the number of attempts to dial specific address. It returns 0 if never attempted or successfully connected.
func (*PEXReactor) GetChannels ¶
func (r *PEXReactor) GetChannels() []*conn.ChannelDescriptor
GetChannels implements Reactor
func (*PEXReactor) Receive ¶
func (r *PEXReactor) Receive(chID byte, src Peer, msgBytes []byte)
Receive implements Reactor by handling incoming PEX messages.
func (*PEXReactor) ReceiveAddrs ¶
func (r *PEXReactor) ReceiveAddrs(addrs []*p2p.NetAddress, src Peer) error
ReceiveAddrs adds the given addrs to the addrbook if theres an open request for this peer and deletes the open request. If there's no open request for the src peer, it returns an error.
func (*PEXReactor) RemovePeer ¶
func (r *PEXReactor) RemovePeer(p Peer, reason interface{})
RemovePeer implements Reactor.
func (*PEXReactor) RequestAddrs ¶
func (r *PEXReactor) RequestAddrs(p Peer)
RequestAddrs asks peer for more addresses if we do not already have a request out for this peer.
func (*PEXReactor) SendAddrs ¶
func (r *PEXReactor) SendAddrs(p Peer, netAddrs []*p2p.NetAddress)
SendAddrs sends addrs to the peer.
func (*PEXReactor) SetEnsurePeersPeriod ¶
func (r *PEXReactor) SetEnsurePeersPeriod(d time.Duration)
SetEnsurePeersPeriod sets period to ensure peers connected.
type PEXReactorConfig ¶
type PEXReactorConfig struct { // Seed/Crawler mode SeedMode bool // Seeds is a list of addresses reactor may use // if it can't connect to peers in the addrbook. Seeds []string }
PEXReactorConfig holds reactor specific configuration data.
type PexMessage ¶
type PexMessage interface{}
PexMessage is a primary type for PEX messages. Underneath, it could contain either pexRequestMessage, or pexAddrsMessage messages.