Documentation ¶
Overview ¶
Copyright (c) 2018-2020 The asimov developers Copyright (c) 2013-2017 The btcsuite developers Use of this source code is governed by an ISC license that can be found in the LICENSE file.
Index ¶
- func GroupKey(na *protos.NetAddress) string
- func IsIPv4(na *protos.NetAddress) bool
- func IsLocal(na *protos.NetAddress) bool
- func IsOnionCatTor(na *protos.NetAddress) bool
- func IsRFC1918(na *protos.NetAddress) bool
- func IsRFC2544(na *protos.NetAddress) bool
- func IsRFC3849(na *protos.NetAddress) bool
- func IsRFC3927(na *protos.NetAddress) bool
- func IsRFC3964(na *protos.NetAddress) bool
- func IsRFC4193(na *protos.NetAddress) bool
- func IsRFC4380(na *protos.NetAddress) bool
- func IsRFC4843(na *protos.NetAddress) bool
- func IsRFC4862(na *protos.NetAddress) bool
- func IsRFC5737(na *protos.NetAddress) bool
- func IsRFC6052(na *protos.NetAddress) bool
- func IsRFC6145(na *protos.NetAddress) bool
- func IsRFC6598(na *protos.NetAddress) bool
- func IsRoutable(na *protos.NetAddress) bool
- func IsValid(na *protos.NetAddress) bool
- func NetAddressKey(na *protos.NetAddress) string
- func ParseListeners(addrs []string) ([]net.Addr, error)
- type AddrManager
- func (a *AddrManager) AddAddress(addr, srcAddr *protos.NetAddress)
- func (a *AddrManager) AddAddressByIP(addrIP string) error
- func (a *AddrManager) AddAddresses(addrs []*protos.NetAddress, srcAddr *protos.NetAddress)
- func (a *AddrManager) AddLocalAddress(na *protos.NetAddress, priority AddressPriority) error
- func (a *AddrManager) AddrStringToNetAddr(addr string) (net.Addr, error)
- func (a *AddrManager) AddressCache() []*protos.NetAddress
- func (a *AddrManager) Attempt(addr *protos.NetAddress)
- func (a *AddrManager) Connected(addr *protos.NetAddress)
- func (a *AddrManager) DeserializeNetAddress(addr string, services common.ServiceFlag) (*protos.NetAddress, error)
- func (a *AddrManager) GetAddress() *KnownAddress
- func (a *AddrManager) GetBestLocalAddress(remoteAddr *protos.NetAddress) *protos.NetAddress
- func (a *AddrManager) Good(addr *protos.NetAddress)
- func (a *AddrManager) HostToNetAddress(host string, port uint16, services common.ServiceFlag) (*protos.NetAddress, error)
- func (a *AddrManager) NeedMoreAddresses() bool
- func (a *AddrManager) NumAddresses() int
- func (am *AddrManager) SeedFromDNS(chainParams *chaincfg.Params, reqServices common.ServiceFlag)
- func (a *AddrManager) SetServices(addr *protos.NetAddress, services common.ServiceFlag)
- func (a *AddrManager) Start()
- func (a *AddrManager) Stop() error
- type AddressPriority
- type KnownAddress
- type OnionAddr
- type SimpleAddr
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GroupKey ¶
func GroupKey(na *protos.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 IsIPv4 ¶
func IsIPv4(na *protos.NetAddress) bool
IsIPv4 returns whether or not the given address is an IPv4 address.
func IsLocal ¶
func IsLocal(na *protos.NetAddress) bool
IsLocal returns whether or not the given address is a local address.
func IsOnionCatTor ¶
func IsOnionCatTor(na *protos.NetAddress) bool
IsOnionCatTor returns whether or not the passed address is in the IPv6 range used by bitcoin to support Tor (fd87:d87e:eb43::/48). Note that this range is the same range used by OnionCat, which is part of the RFC4193 unique local IPv6 range.
func IsRFC1918 ¶
func IsRFC1918(na *protos.NetAddress) bool
IsRFC1918 returns whether or not the passed address is part of the IPv4 private network address space as defined by RFC1918 (10.0.0.0/8, 172.16.0.0/12, or 192.168.0.0/16).
func IsRFC2544 ¶
func IsRFC2544(na *protos.NetAddress) bool
IsRFC2544 returns whether or not the passed address is part of the IPv4 address space as defined by RFC2544 (198.18.0.0/15)
func IsRFC3849 ¶
func IsRFC3849(na *protos.NetAddress) bool
IsRFC3849 returns whether or not the passed address is part of the IPv6 documentation range as defined by RFC3849 (2001:DB8::/32).
func IsRFC3927 ¶
func IsRFC3927(na *protos.NetAddress) bool
IsRFC3927 returns whether or not the passed address is part of the IPv4 autoconfiguration range as defined by RFC3927 (169.254.0.0/16).
func IsRFC3964 ¶
func IsRFC3964(na *protos.NetAddress) bool
IsRFC3964 returns whether or not the passed address is part of the IPv6 to IPv4 encapsulation range as defined by RFC3964 (2002::/16).
func IsRFC4193 ¶
func IsRFC4193(na *protos.NetAddress) bool
IsRFC4193 returns whether or not the passed address is part of the IPv6 unique local range as defined by RFC4193 (FC00::/7).
func IsRFC4380 ¶
func IsRFC4380(na *protos.NetAddress) bool
IsRFC4380 returns whether or not the passed address is part of the IPv6 teredo tunneling over UDP range as defined by RFC4380 (2001::/32).
func IsRFC4843 ¶
func IsRFC4843(na *protos.NetAddress) bool
IsRFC4843 returns whether or not the passed address is part of the IPv6 ORCHID range as defined by RFC4843 (2001:10::/28).
func IsRFC4862 ¶
func IsRFC4862(na *protos.NetAddress) bool
IsRFC4862 returns whether or not the passed address is part of the IPv6 stateless address autoconfiguration range as defined by RFC4862 (FE80::/64).
func IsRFC5737 ¶
func IsRFC5737(na *protos.NetAddress) bool
IsRFC5737 returns whether or not the passed address is part of the IPv4 documentation address space as defined by RFC5737 (192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24)
func IsRFC6052 ¶
func IsRFC6052(na *protos.NetAddress) bool
IsRFC6052 returns whether or not the passed address is part of the IPv6 well-known prefix range as defined by RFC6052 (64:FF9B::/96).
func IsRFC6145 ¶
func IsRFC6145(na *protos.NetAddress) bool
IsRFC6145 returns whether or not the passed address is part of the IPv6 to IPv4 translated address range as defined by RFC6145 (::FFFF:0:0:0/96).
func IsRFC6598 ¶
func IsRFC6598(na *protos.NetAddress) bool
IsRFC6598 returns whether or not the passed address is part of the IPv4 shared address space specified by RFC6598 (100.64.0.0/10)
func IsRoutable ¶
func IsRoutable(na *protos.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 IsValid ¶
func IsValid(na *protos.NetAddress) bool
IsValid returns whether or not the passed address is valid. The address is considered invalid under the following circumstances: IPv4: It is either a zero or all bits set address. IPv6: It is either a zero or RFC3849 documentation address.
func NetAddressKey ¶
func NetAddressKey(na *protos.NetAddress) string
NetAddressKey returns a string key in the form of ip:port for IPv4 addresses or [ip]:port for IPv6 addresses.
func ParseListeners ¶
parseListeners determines whether each listen address is IPv4 and IPv6 and returns a slice of appropriate net.Addrs to listen on with TCP. It also properly detects addresses which apply to "all interfaces" and adds the address as both IPv4 and IPv6.
Types ¶
type AddrManager ¶
type AddrManager struct {
// contains filtered or unexported fields
}
AddrManager provides a concurrency safe address manager for caching potential peers on the bitcoin network.
func New ¶
func New(dataDir string, adapter fnet.NetAdapter) *AddrManager
New returns a new flow address manager. Use Start to begin processing asynchronous address updates.
func (*AddrManager) AddAddress ¶
func (a *AddrManager) AddAddress(addr, srcAddr *protos.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) AddAddressByIP ¶
func (a *AddrManager) AddAddressByIP(addrIP string) error
AddAddressByIP adds an address where we are given an ip:port and not a protos.NetAddress.
func (*AddrManager) AddAddresses ¶
func (a *AddrManager) AddAddresses(addrs []*protos.NetAddress, srcAddr *protos.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 *protos.NetAddress, priority AddressPriority) error
AddLocalAddress adds na to the list of known local addresses to advertise with the given priority.
func (*AddrManager) AddrStringToNetAddr ¶
func (a *AddrManager) AddrStringToNetAddr(addr string) (net.Addr, error)
addrStringToNetAddr takes an address in the form of 'host:port' and returns a net.Addr which maps to the original address with any host names resolved to IP addresses. It also handles tor addresses properly by returning a net.Addr that encapsulates the address.
func (*AddrManager) AddressCache ¶
func (a *AddrManager) AddressCache() []*protos.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 *protos.NetAddress)
Attempt increases the given address' attempt counter and updates the last attempt time.
func (*AddrManager) Connected ¶
func (a *AddrManager) Connected(addr *protos.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, services common.ServiceFlag) (*protos.NetAddress, error)
DeserializeNetAddress converts a given address string to a *protos.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 *protos.NetAddress) *protos.NetAddress
GetBestLocalAddress returns the most appropriate local address to use for the given remote address.
func (*AddrManager) Good ¶
func (a *AddrManager) Good(addr *protos.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 common.ServiceFlag) (*protos.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) NumAddresses ¶
func (a *AddrManager) NumAddresses() int
NumAddresses returns the number of addresses known to the address manager.
func (*AddrManager) SeedFromDNS ¶
func (am *AddrManager) SeedFromDNS(chainParams *chaincfg.Params, reqServices common.ServiceFlag)
SeedFromDNS uses DNS seeding to populate the address manager with peers.
func (*AddrManager) SetServices ¶
func (a *AddrManager) SetServices(addr *protos.NetAddress, services common.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) LastAttempt ¶
func (ka *KnownAddress) LastAttempt() time.Time
LastAttempt returns the last time the known address was attempted.
func (*KnownAddress) NetAddress ¶
func (ka *KnownAddress) NetAddress() *protos.NetAddress
NetAddress returns the underlying protos.NetAddress associated with the known address.
func (*KnownAddress) Services ¶
func (ka *KnownAddress) Services() common.ServiceFlag
Services returns the services supported by the peer with the known address.
type OnionAddr ¶
type OnionAddr struct {
// contains filtered or unexported fields
}
OnionAddr implements the net.Addr interface and represents a tor address.
type SimpleAddr ¶
type SimpleAddr struct {
// contains filtered or unexported fields
}
SimpleAddr implements the net.Addr interface with two struct fields
func (SimpleAddr) Network ¶
func (a SimpleAddr) Network() string
Network returns the network.
This is part of the net.Addr interface.
func (SimpleAddr) String ¶
func (a SimpleAddr) String() string
String returns the address.
This is part of the net.Addr interface.