randchain

package
v0.0.0-...-c4ab804 Latest Latest
Warning

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

Go to latest
Published: May 6, 2021 License: Apache-2.0, MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRepeatConnection = errors.New("attempted repeat connection to existing peer")
	ErrNoSuchPeer       = errors.New("no record of requested peer")
	ErrAddressTimeout   = errors.New("wait for addresses timed out")
	ErrBlacklistedPeer  = errors.New("peer is blacklisted")
)

Functions

This section is empty.

Types

type Address

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

func (*Address) MarshalText

func (a *Address) MarshalText() (text []byte, err error)

func (*Address) String

func (a *Address) String() string

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.

func (PeerKey) String

func (p PeerKey) String() string

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 NewPeerMap

func NewPeerMap() *PeerMap

NewPeerMap returns a fresh, empty PeerMap.

func (*PeerMap) Delete

func (pm *PeerMap) Delete(key PeerKey)

Delete deletes the value for a key.

func (*PeerMap) Load

func (pm *PeerMap) Load(key PeerKey) (*peer.Peer, bool)

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

func (pm *PeerMap) LoadOrStore(key PeerKey, value *peer.Peer) (*peer.Peer, bool)

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

func (pm *PeerMap) Range(f func(key PeerKey, value *peer.Peer) bool)

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.

func (*PeerMap) Store

func (pm *PeerMap) Store(key PeerKey, value *peer.Peer)

Store sets the value for a key.

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 NewSeeder

func NewSeeder(network network.Network) (*Seeder, error)

func (*Seeder) Addresses

func (s *Seeder) Addresses(n int) []net.IP

Addresses returns a slice of n IPv4 addresses or as many as we have if it's less than that.

func (*Seeder) AddressesV6

func (s *Seeder) AddressesV6(n int) []net.IP

AddressesV6 returns a slice of n IPv6 addresses or as many as we have if it's less than that.

func (*Seeder) Connect

func (s *Seeder) Connect(addr, port string) (*peer.Peer, error)

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

func (s *Seeder) ConnectOnDefaultPort(addr string) error

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

func (s *Seeder) DisconnectAndBlacklist(addr PeerKey) error

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

func (s *Seeder) DisconnectPeer(addr PeerKey) error

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

func (s *Seeder) GetNetworkDefaultPort() string

GetNetworkDefaultPort returns the default port of the network this seeder is configured for.

func (*Seeder) GetPeer

func (s *Seeder) GetPeer(addr PeerKey) (*peer.Peer, error)

GetPeer returns a live peer identified by "host:port" string, or an error if we aren't connected to that peer.

func (*Seeder) GetPeerCount

func (s *Seeder) GetPeerCount() int

GetPeerCount returns how many valid peers we know about.

func (*Seeder) Ready

func (s *Seeder) Ready() bool

Ready reports if the seeder is ready to provide addresses.

func (*Seeder) RefreshAddresses

func (s *Seeder) RefreshAddresses(disconnect bool)

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

func (s *Seeder) RequestAddresses() int

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.

func (*Seeder) WaitForAddresses

func (s *Seeder) WaitForAddresses(n int, timeout time.Duration) error

WaitForAddresses waits for n addresses to be confirmed and available in the address book.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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