addmgr

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2021 License: ISC Imports: 20 Imported by: 0

Documentation

Overview

Copyright (c) 2020-2021 The bitcoinpay developers Copyright (c) 2013-2014 The btcsuite developers Copyright (c) 2015-2018 The Decred developers Use of this source code is governed by an ISC license that can be found in the LICENSE file.

Copyright (c) 2020-2021 The bitcoinpay developers Copyright (c) 2013-2014 The btcsuite developers Copyright (c) 2015-2016 The Decred developers Use of this source code is governed by an ISC license that can be found in the LICENSE file.

Index

Constants

View Source
const PeersFilename = "peers.json"

PeersFilename is the default filename to store serialized peers.

Variables

This section is empty.

Functions

func GroupKey

func GroupKey(na *types.NetAddress) string

GroupKey returns a string representing the network group an address is part of. This is the /16 for IPv4, the /32 (/36 for he.net) for IPv6, the string "local" for a local address, the string "tor:key" where key is the /4 of the onion address for Tor address, and the string "unroutable" for an unroutable address.

func IsRoutable

func IsRoutable(na *types.NetAddress) bool

IsRoutable returns whether or not the passed address is routable over the public internet. This is true as long as the address is valid and is not in any reserved ranges.

func NetAddressKey

func NetAddressKey(na *types.NetAddress) string

NetAddressKey returns a string key in the form of ip:port for IPv4 addresses or [ip]:port for IPv6 addresses.

Types

type AddrManager

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

AddrManager provides a concurrency safe address manager for caching potential peers on the bitcoinpay network.

func New

func New(dataDir string, getAddrPer int, lookupFunc func(string) ([]net.IP, error)) *AddrManager

New returns a new address manager. Use Start to begin processing asynchronous address updates. The address manager uses lookupFunc for necessary DNS lookups.

func (*AddrManager) AddAddress

func (a *AddrManager) AddAddress(addr, srcAddr *types.NetAddress)

AddAddress adds a new address to the address manager. It enforces a max number of addresses and silently ignores duplicate addresses. It is safe for concurrent access.

func (*AddrManager) AddAddresses

func (a *AddrManager) AddAddresses(addrs []*types.NetAddress, srcAddr *types.NetAddress)

AddAddresses adds new addresses to the address manager. It enforces a max number of addresses and silently ignores duplicate addresses. It is safe for concurrent access.

func (*AddrManager) AddLocalAddress

func (a *AddrManager) AddLocalAddress(na *types.NetAddress, priority AddressPriority) error

AddLocalAddress adds na to the list of known local addresses to advertise with the given priority.

func (*AddrManager) AddressCache

func (a *AddrManager) AddressCache() []*types.NetAddress

AddressCache returns the current address cache. It must be treated as read-only (but since it is a copy now, this is not as dangerous).

func (*AddrManager) Attempt

func (a *AddrManager) Attempt(addr *types.NetAddress)

Attempt increases the given address' attempt counter and updates the last attempt time.

func (*AddrManager) Connected

func (a *AddrManager) Connected(addr *types.NetAddress)

Connected Marks the given address as currently connected and working at the current time. The address must already be known to AddrManager else it will be ignored.

func (*AddrManager) DeserializeNetAddress

func (a *AddrManager) DeserializeNetAddress(addr string) (*types.NetAddress, error)

DeserializeNetAddress converts a given address string to a *types.NetAddress

func (*AddrManager) GetAddress

func (a *AddrManager) GetAddress() *KnownAddress

GetAddress returns a single address that should be routable. It picks a random one from the possible addresses with preference given to ones that have not been used recently and should not pick 'close' addresses consecutively.

func (*AddrManager) GetBestLocalAddress

func (a *AddrManager) GetBestLocalAddress(remoteAddr *types.NetAddress) *types.NetAddress

GetBestLocalAddress returns the most appropriate local address to use for the given remote address.

func (*AddrManager) Good

func (a *AddrManager) Good(addr *types.NetAddress)

Good marks the given address as good. To be called after a successful connection and version exchange. If the address is unknown to the address manager it will be ignored.

func (*AddrManager) HostToNetAddress

func (a *AddrManager) HostToNetAddress(host string, port uint16, services protocol.ServiceFlag) (*types.NetAddress, error)

HostToNetAddress returns a netaddress given a host address. If the address is a Tor .onion address this will be taken care of. Else if the host is not an IP address it will be resolved (via Tor if required).

func (*AddrManager) NeedMoreAddresses

func (a *AddrManager) NeedMoreAddresses() bool

NeedMoreAddresses returns whether or not the address manager needs more addresses.

func (*AddrManager) SetServices

func (a *AddrManager) SetServices(addr *types.NetAddress, services protocol.ServiceFlag)

SetServices sets the services for the giiven address to the provided value.

func (*AddrManager) Start

func (a *AddrManager) Start()

Start begins the core address handler which manages a pool of known addresses, timeouts, and interval based writes.

func (*AddrManager) Stop

func (a *AddrManager) Stop() error

Stop gracefully shuts down the address manager by stopping the main handler.

type AddressPriority

type AddressPriority int

AddressPriority type is used to describe the hierarchy of local address discovery methods.

const (
	// InterfacePrio signifies the address is on a local interface
	InterfacePrio AddressPriority = iota

	// BoundPrio signifies the address has been explicitly bounded to.
	BoundPrio

	// UpnpPrio signifies the address was obtained from UPnP.
	UpnpPrio

	// HTTPPrio signifies the address was obtained from an external HTTP service.
	HTTPPrio

	// ManualPrio signifies the address was provided by --externalip.
	ManualPrio
)

type KnownAddress

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

KnownAddress tracks information about a known network address that is used to determine how viable an address is.

func (*KnownAddress) GetAttempts

func (ka *KnownAddress) GetAttempts() int

func (*KnownAddress) LastAttempt

func (ka *KnownAddress) LastAttempt() time.Time

LastAttempt returns the last time the known address was attempted.

func (*KnownAddress) NetAddress

func (ka *KnownAddress) NetAddress() *types.NetAddress

NetAddress returns the underlying types.NetAddress associated with the known address.

func (*KnownAddress) String

func (ka *KnownAddress) String() string

Jump to

Keyboard shortcuts

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