Documentation ¶
Index ¶
- Variables
- type Address
- type AddressBook
- func (bk *AddressBook) Add(s PeerKey)
- func (bk *AddressBook) Blacklist(s PeerKey)
- func (bk *AddressBook) Count() int
- func (bk *AddressBook) DropFromBlacklist(s PeerKey)
- func (bk *AddressBook) IsBlacklisted(s PeerKey) bool
- func (bk *AddressBook) IsKnown(s PeerKey) bool
- func (bk *AddressBook) Redeem(s PeerKey)
- func (bk *AddressBook) Remove(s PeerKey)
- func (bk *AddressBook) Touch(s PeerKey)
- type PeerKey
- type PeerMap
- func (pm *PeerMap) Delete(key PeerKey)
- func (pm *PeerMap) Load(key PeerKey) (*peer.Peer, bool)
- func (pm *PeerMap) LoadOrStore(key PeerKey, value *peer.Peer) (*peer.Peer, bool)
- func (pm *PeerMap) Range(f func(key PeerKey, value *peer.Peer) bool)
- func (pm *PeerMap) Store(key PeerKey, value *peer.Peer)
- type Seeder
- func (s *Seeder) Addresses(n int) []net.IP
- func (s *Seeder) AddressesV6(n int) []net.IP
- func (s *Seeder) Connect(addr, port string) (*peer.Peer, error)
- func (s *Seeder) ConnectOnDefaultPort(addr string) error
- func (s *Seeder) DisconnectAllPeers()
- func (s *Seeder) DisconnectAndBlacklist(addr PeerKey) error
- func (s *Seeder) DisconnectPeer(addr PeerKey) error
- func (s *Seeder) GetNetworkDefaultPort() string
- func (s *Seeder) GetPeer(addr PeerKey) (*peer.Peer, error)
- func (s *Seeder) GetPeerCount() int
- func (s *Seeder) Ready() bool
- func (s *Seeder) RefreshAddresses(disconnect bool)
- func (s *Seeder) RequestAddresses() int
- func (s *Seeder) RetryBlacklist()
- func (s *Seeder) WaitForAddresses(n int, timeout time.Duration) error
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Address ¶
type Address struct {
// contains filtered or unexported fields
}
func (*Address) MarshalText ¶
type AddressBook ¶
type AddressBook struct {
// contains filtered or unexported fields
}
func NewAddressBook ¶
func NewAddressBook() *AddressBook
func (*AddressBook) Add ¶
func (bk *AddressBook) Add(s PeerKey)
func (*AddressBook) Blacklist ¶
func (bk *AddressBook) Blacklist(s PeerKey)
Blacklist adds an address to the blacklist so we won't try to connect to it again.
func (*AddressBook) Count ¶
func (bk *AddressBook) Count() int
func (*AddressBook) DropFromBlacklist ¶
func (bk *AddressBook) DropFromBlacklist(s PeerKey)
DropFromBlacklist removes an address from the blacklist.
func (*AddressBook) IsBlacklisted ¶
func (bk *AddressBook) IsBlacklisted(s PeerKey) bool
func (*AddressBook) IsKnown ¶
func (bk *AddressBook) IsKnown(s PeerKey) bool
IsKnown returns true if the peer is already in our address book, false if not.
func (*AddressBook) Redeem ¶
func (bk *AddressBook) Redeem(s PeerKey)
Redeem removes an address from the blacklist and adds it to the peer list.
func (*AddressBook) Remove ¶
func (bk *AddressBook) Remove(s PeerKey)
func (*AddressBook) Touch ¶
func (bk *AddressBook) Touch(s PeerKey)
Touch updates the last-seen timestamp if the peer is in the valid address book or does nothing if not.
type PeerKey ¶
type PeerKey string
PeerKey is a convenient marker type for the "host:port" format used throughout our maps and lists.
type PeerMap ¶
type PeerMap struct {
// contains filtered or unexported fields
}
PeerMap is a typed wrapper for a sync.Map. Its keys are PeerKeys (host:port format strings) and it stores a pointer to a btcsuite peer.Peer.
func (*PeerMap) Load ¶
Load returns the value stored in the map for a key, or nil if no value is present. The ok result indicates whether value was found in the map.
func (*PeerMap) LoadOrStore ¶
LoadOrStore returns the existing value for the key if present. Otherwise, it stores and returns the given value. The loaded result is true if the value was loaded, false if stored.
func (*PeerMap) Range ¶
Range calls f sequentially for each key and value present in the map. If f returns false, range stops the iteration.
Range does not necessarily correspond to any consistent snapshot of the Map's contents: no key will be visited more than once, but if the value for any key is stored or deleted concurrently, Range may reflect any mapping for that key from any point during the Range call.
Range may be O(N) with the number of elements in the map even if f returns false after a constant number of calls.
type Seeder ¶
type Seeder struct {
// contains filtered or unexported fields
}
Seeder contains all of the state and configuration needed to request addresses from peers and present them to a DNS provider.
func (*Seeder) Addresses ¶
Addresses returns a slice of n IPv4 addresses or as many as we have if it's less than that.
func (*Seeder) AddressesV6 ¶
AddressesV6 returns a slice of n IPv6 addresses or as many as we have if it's less than that.
func (*Seeder) Connect ¶
Connect attempts to connect to a peer at the given address and port. It will not connect to addresses known to be unusable. It returns a handle to the peer connection if the connection is successful or nil and an error if it fails.
func (*Seeder) ConnectOnDefaultPort ¶
ConnectOnDefaultPort attempts to connect to a peer on the default port at the specified address. It returns an error if it can't complete handshake with the peer. Otherwise it returns nil and adds the peer to the list of live connections and known-good addresses.
func (*Seeder) DisconnectAllPeers ¶
func (s *Seeder) DisconnectAllPeers()
DisconnectAllPeers terminates the connections to all live and pending peers.
func (*Seeder) DisconnectAndBlacklist ¶
DisconnectAndBlacklist disconnects from a live peer identified by "host:port" string. It returns an error if we aren't connected to that peer. It furthermore removes this peer from the list of known good addresses and adds them to a blacklist. to prevent future connections.
func (*Seeder) DisconnectPeer ¶
DisconnectPeer disconnects from a live peer identified by "host:port" string. It returns an error if we aren't connected to that peer.
func (*Seeder) GetNetworkDefaultPort ¶
GetNetworkDefaultPort returns the default port of the network this seeder is configured for.
func (*Seeder) GetPeer ¶
GetPeer returns a live peer identified by "host:port" string, or an error if we aren't connected to that peer.
func (*Seeder) GetPeerCount ¶
GetPeerCount returns how many valid peers we know about.
func (*Seeder) RefreshAddresses ¶
RefreshAddresses checks to make sure the addresses we think we know are still usable and removes them from the address book if they aren't. The call blocks until all addresses have been processed. If disconnect is true, we immediately disconnect from the peers after verifying them.
func (*Seeder) RequestAddresses ¶
RequestAddresses sends a request for more addresses to every peer we're connected to, then checks to make sure the addresses that come back are usable before adding them to the address book. The call attempts to block until all addresses have been processed, but since we can't know how many that will be it eventually times out. Therefore, while calling RequestAddresses synchronously is possible, it risks a major delay; most users will be better served by giving this its own goroutine and using WaitForAddresses with a timeout to pause only until a sufficient number of addresses are ready.
func (*Seeder) RetryBlacklist ¶
func (s *Seeder) RetryBlacklist()
RetryBlacklist checks if the addresses in our blacklist are usable again. If the trial connection succeeds, they're removed from the blacklist.